xref: /dpdk/app/test/test_cryptodev.c (revision 77f46cda)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #ifndef RTE_EXEC_ENV_WINDOWS
7 
8 #include <time.h>
9 
10 #include <rte_common.h>
11 #include <rte_hexdump.h>
12 #include <rte_mbuf.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_pause.h>
16 #include <rte_bus_vdev.h>
17 #include <rte_ether.h>
18 
19 #include <rte_crypto.h>
20 #include <rte_cryptodev.h>
21 #include <rte_ip.h>
22 #include <rte_string_fns.h>
23 #include <rte_tcp.h>
24 #include <rte_udp.h>
25 
26 #ifdef RTE_CRYPTO_SCHEDULER
27 #include <rte_cryptodev_scheduler.h>
28 #include <rte_cryptodev_scheduler_operations.h>
29 #endif
30 
31 #include <rte_lcore.h>
32 
33 #include "test.h"
34 #include "test_cryptodev.h"
35 
36 #include "test_cryptodev_blockcipher.h"
37 #include "test_cryptodev_aes_test_vectors.h"
38 #include "test_cryptodev_des_test_vectors.h"
39 #include "test_cryptodev_hash_test_vectors.h"
40 #include "test_cryptodev_kasumi_test_vectors.h"
41 #include "test_cryptodev_kasumi_hash_test_vectors.h"
42 #include "test_cryptodev_snow3g_test_vectors.h"
43 #include "test_cryptodev_snow3g_hash_test_vectors.h"
44 #include "test_cryptodev_zuc_test_vectors.h"
45 #include "test_cryptodev_aead_test_vectors.h"
46 #include "test_cryptodev_hmac_test_vectors.h"
47 #include "test_cryptodev_mixed_test_vectors.h"
48 #ifdef RTE_LIB_SECURITY
49 #include "test_cryptodev_security_ipsec.h"
50 #include "test_cryptodev_security_ipsec_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_vectors.h"
52 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
53 #include "test_cryptodev_security_pdcp_test_func.h"
54 #include "test_cryptodev_security_docsis_test_vectors.h"
55 
56 #define SDAP_DISABLED	0
57 #define SDAP_ENABLED	1
58 #endif
59 
60 #define VDEV_ARGS_SIZE 100
61 #define MAX_NB_SESSIONS 4
62 
63 #define MAX_DRV_SERVICE_CTX_SIZE 256
64 
65 #define MAX_RAW_DEQUEUE_COUNT	65535
66 
67 #define IN_PLACE 0
68 #define OUT_OF_PLACE 1
69 
70 static int gbl_driver_id;
71 
72 static enum rte_security_session_action_type gbl_action_type =
73 	RTE_SECURITY_ACTION_TYPE_NONE;
74 
75 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
76 
77 struct crypto_unittest_params {
78 	struct rte_crypto_sym_xform cipher_xform;
79 	struct rte_crypto_sym_xform auth_xform;
80 	struct rte_crypto_sym_xform aead_xform;
81 #ifdef RTE_LIB_SECURITY
82 	struct rte_security_docsis_xform docsis_xform;
83 #endif
84 
85 	union {
86 		struct rte_cryptodev_sym_session *sess;
87 #ifdef RTE_LIB_SECURITY
88 		struct rte_security_session *sec_session;
89 #endif
90 	};
91 #ifdef RTE_LIB_SECURITY
92 	enum rte_security_session_action_type type;
93 #endif
94 	struct rte_crypto_op *op;
95 
96 	struct rte_mbuf *obuf, *ibuf;
97 
98 	uint8_t *digest;
99 };
100 
101 #define ALIGN_POW2_ROUNDUP(num, align) \
102 	(((num) + (align) - 1) & ~((align) - 1))
103 
104 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
105 	for (j = 0; j < num_child_ts; index++, j++)			\
106 		parent_ts.unit_test_suites[index] = child_ts[j]
107 
108 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
109 	for (j = 0; j < num_blk_types; index++, j++)				\
110 		parent_ts.unit_test_suites[index] =				\
111 				build_blockcipher_test_suite(blk_types[j])
112 
113 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
114 	for (j = index; j < index + num_blk_types; j++)				\
115 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
116 
117 /*
118  * Forward declarations.
119  */
120 static int
121 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
122 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
123 		uint8_t *hmac_key);
124 
125 static int
126 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
127 		struct crypto_unittest_params *ut_params,
128 		struct crypto_testsuite_params *ts_param,
129 		const uint8_t *cipher,
130 		const uint8_t *digest,
131 		const uint8_t *iv);
132 
133 static int
134 security_proto_supported(enum rte_security_session_action_type action,
135 	enum rte_security_session_protocol proto);
136 
137 static int
138 dev_configure_and_start(uint64_t ff_disable);
139 
140 static struct rte_mbuf *
141 setup_test_string(struct rte_mempool *mpool,
142 		const char *string, size_t len, uint8_t blocksize)
143 {
144 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
145 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
146 
147 	if (m) {
148 		char *dst;
149 
150 		memset(m->buf_addr, 0, m->buf_len);
151 		dst = rte_pktmbuf_append(m, t_len);
152 		if (!dst) {
153 			rte_pktmbuf_free(m);
154 			return NULL;
155 		}
156 		if (string != NULL)
157 			rte_memcpy(dst, string, t_len);
158 		else
159 			memset(dst, 0, t_len);
160 	}
161 
162 	return m;
163 }
164 
165 /* Get number of bytes in X bits (rounding up) */
166 static uint32_t
167 ceil_byte_length(uint32_t num_bits)
168 {
169 	if (num_bits % 8)
170 		return ((num_bits >> 3) + 1);
171 	else
172 		return (num_bits >> 3);
173 }
174 
175 static void
176 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
177 		uint8_t is_op_success)
178 {
179 	struct rte_crypto_op *op = user_data;
180 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
181 			RTE_CRYPTO_OP_STATUS_ERROR;
182 }
183 
184 static struct crypto_testsuite_params testsuite_params = { NULL };
185 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
186 static struct crypto_unittest_params unittest_params;
187 
188 void
189 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
190 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
191 		uint8_t len_in_bits, uint8_t cipher_iv_len)
192 {
193 	struct rte_crypto_sym_op *sop = op->sym;
194 	struct rte_crypto_op *ret_op = NULL;
195 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
196 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
197 	union rte_crypto_sym_ofs ofs;
198 	struct rte_crypto_sym_vec vec;
199 	struct rte_crypto_sgl sgl, dest_sgl;
200 	uint32_t max_len;
201 	union rte_cryptodev_session_ctx sess;
202 	uint64_t auth_end_iova;
203 	uint32_t count = 0;
204 	struct rte_crypto_raw_dp_ctx *ctx;
205 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
206 			auth_len = 0;
207 	int32_t n;
208 	uint32_t n_success;
209 	int ctx_service_size;
210 	int32_t status = 0;
211 	int enqueue_status, dequeue_status;
212 	struct crypto_unittest_params *ut_params = &unittest_params;
213 	int is_sgl = sop->m_src->nb_segs > 1;
214 	int is_oop = 0;
215 
216 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
217 	if (ctx_service_size < 0) {
218 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
219 		return;
220 	}
221 
222 	ctx = malloc(ctx_service_size);
223 	if (!ctx) {
224 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
225 		return;
226 	}
227 
228 	/* Both are enums, setting crypto_sess will suit any session type */
229 	sess.crypto_sess = op->sym->session;
230 
231 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
232 			op->sess_type, sess, 0) < 0) {
233 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
234 		goto exit;
235 	}
236 
237 	cipher_iv.iova = 0;
238 	cipher_iv.va = NULL;
239 	aad_auth_iv.iova = 0;
240 	aad_auth_iv.va = NULL;
241 	digest.iova = 0;
242 	digest.va = NULL;
243 	sgl.vec = data_vec;
244 	vec.num = 1;
245 	vec.src_sgl = &sgl;
246 	vec.iv = &cipher_iv;
247 	vec.digest = &digest;
248 	vec.aad = &aad_auth_iv;
249 	vec.status = &status;
250 
251 	ofs.raw = 0;
252 
253 	if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src))
254 		is_oop = 1;
255 
256 	if (is_cipher && is_auth) {
257 		cipher_offset = sop->cipher.data.offset;
258 		cipher_len = sop->cipher.data.length;
259 		auth_offset = sop->auth.data.offset;
260 		auth_len = sop->auth.data.length;
261 		max_len = RTE_MAX(cipher_offset + cipher_len,
262 				auth_offset + auth_len);
263 		if (len_in_bits) {
264 			max_len = max_len >> 3;
265 			cipher_offset = cipher_offset >> 3;
266 			auth_offset = auth_offset >> 3;
267 			cipher_len = cipher_len >> 3;
268 			auth_len = auth_len >> 3;
269 		}
270 		ofs.ofs.cipher.head = cipher_offset;
271 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
272 		ofs.ofs.auth.head = auth_offset;
273 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
274 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
275 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
276 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
277 				op, void *, IV_OFFSET + cipher_iv_len);
278 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
279 				cipher_iv_len);
280 		digest.va = (void *)sop->auth.digest.data;
281 		digest.iova = sop->auth.digest.phys_addr;
282 
283 		if (is_sgl) {
284 			uint32_t remaining_off = auth_offset + auth_len;
285 			struct rte_mbuf *sgl_buf = sop->m_src;
286 			if (is_oop)
287 				sgl_buf = sop->m_dst;
288 
289 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
290 					&& sgl_buf->next != NULL) {
291 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
292 				sgl_buf = sgl_buf->next;
293 			}
294 
295 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
296 				sgl_buf, remaining_off);
297 		} else {
298 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
299 							 auth_offset + auth_len;
300 		}
301 		/* Then check if digest-encrypted conditions are met */
302 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
303 				(digest.iova == auth_end_iova) && is_sgl)
304 			max_len = RTE_MAX(max_len,
305 				auth_offset + auth_len +
306 				ut_params->auth_xform.auth.digest_length);
307 
308 	} else if (is_cipher) {
309 		cipher_offset = sop->cipher.data.offset;
310 		cipher_len = sop->cipher.data.length;
311 		max_len = cipher_len + cipher_offset;
312 		if (len_in_bits) {
313 			max_len = max_len >> 3;
314 			cipher_offset = cipher_offset >> 3;
315 			cipher_len = cipher_len >> 3;
316 		}
317 		ofs.ofs.cipher.head = cipher_offset;
318 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
319 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
320 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
321 
322 	} else if (is_auth) {
323 		auth_offset = sop->auth.data.offset;
324 		auth_len = sop->auth.data.length;
325 		max_len = auth_len + auth_offset;
326 		if (len_in_bits) {
327 			max_len = max_len >> 3;
328 			auth_offset = auth_offset >> 3;
329 			auth_len = auth_len >> 3;
330 		}
331 		ofs.ofs.auth.head = auth_offset;
332 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
333 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
334 				op, void *, IV_OFFSET + cipher_iv_len);
335 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
336 				cipher_iv_len);
337 		digest.va = (void *)sop->auth.digest.data;
338 		digest.iova = sop->auth.digest.phys_addr;
339 
340 	} else { /* aead */
341 		cipher_offset = sop->aead.data.offset;
342 		cipher_len = sop->aead.data.length;
343 		max_len = cipher_len + cipher_offset;
344 		if (len_in_bits) {
345 			max_len = max_len >> 3;
346 			cipher_offset = cipher_offset >> 3;
347 			cipher_len = cipher_len >> 3;
348 		}
349 		ofs.ofs.cipher.head = cipher_offset;
350 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
351 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
352 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
353 		aad_auth_iv.va = (void *)sop->aead.aad.data;
354 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
355 		digest.va = (void *)sop->aead.digest.data;
356 		digest.iova = sop->aead.digest.phys_addr;
357 	}
358 
359 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
360 			data_vec, RTE_DIM(data_vec));
361 	if (n < 0 || n > sop->m_src->nb_segs) {
362 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
363 		goto exit;
364 	}
365 
366 	sgl.num = n;
367 	/* Out of place */
368 	if (is_oop) {
369 		dest_sgl.vec = dest_data_vec;
370 		vec.dest_sgl = &dest_sgl;
371 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
372 				dest_data_vec, RTE_DIM(dest_data_vec));
373 		if (n < 0 || n > sop->m_dst->nb_segs) {
374 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
375 			goto exit;
376 		}
377 		dest_sgl.num = n;
378 	} else
379 		vec.dest_sgl = NULL;
380 
381 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
382 			&enqueue_status) < 1) {
383 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
384 		goto exit;
385 	}
386 
387 	if (enqueue_status == 0) {
388 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
389 		if (status < 0) {
390 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
391 			goto exit;
392 		}
393 	} else if (enqueue_status < 0) {
394 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
395 		goto exit;
396 	}
397 
398 	n = n_success = 0;
399 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
400 		n = rte_cryptodev_raw_dequeue_burst(ctx,
401 			NULL, 1, post_process_raw_dp_op,
402 				(void **)&ret_op, 0, &n_success,
403 				&dequeue_status);
404 		if (dequeue_status < 0) {
405 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
406 			goto exit;
407 		}
408 		if (n == 0)
409 			rte_pause();
410 	}
411 
412 	if (n == 1 && dequeue_status == 0) {
413 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
414 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
415 			goto exit;
416 		}
417 	}
418 
419 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
420 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
421 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
422 					RTE_CRYPTO_OP_STATUS_SUCCESS;
423 
424 exit:
425 	free(ctx);
426 }
427 
428 static void
429 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
430 {
431 	int32_t n, st;
432 	struct rte_crypto_sym_op *sop;
433 	union rte_crypto_sym_ofs ofs;
434 	struct rte_crypto_sgl sgl;
435 	struct rte_crypto_sym_vec symvec;
436 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
437 	struct rte_crypto_vec vec[UINT8_MAX];
438 
439 	sop = op->sym;
440 
441 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
442 		sop->aead.data.length, vec, RTE_DIM(vec));
443 
444 	if (n < 0 || n != sop->m_src->nb_segs) {
445 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
446 		return;
447 	}
448 
449 	sgl.vec = vec;
450 	sgl.num = n;
451 	symvec.src_sgl = &sgl;
452 	symvec.iv = &iv_ptr;
453 	symvec.digest = &digest_ptr;
454 	symvec.aad = &aad_ptr;
455 	symvec.status = &st;
456 	symvec.num = 1;
457 
458 	/* for CPU crypto the IOVA address is not required */
459 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
460 	digest_ptr.va = (void *)sop->aead.digest.data;
461 	aad_ptr.va = (void *)sop->aead.aad.data;
462 
463 	ofs.raw = 0;
464 
465 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
466 		&symvec);
467 
468 	if (n != 1)
469 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
470 	else
471 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
472 }
473 
474 static void
475 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
476 {
477 	int32_t n, st;
478 	struct rte_crypto_sym_op *sop;
479 	union rte_crypto_sym_ofs ofs;
480 	struct rte_crypto_sgl sgl;
481 	struct rte_crypto_sym_vec symvec;
482 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
483 	struct rte_crypto_vec vec[UINT8_MAX];
484 
485 	sop = op->sym;
486 
487 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
488 		sop->auth.data.length, vec, RTE_DIM(vec));
489 
490 	if (n < 0 || n != sop->m_src->nb_segs) {
491 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
492 		return;
493 	}
494 
495 	sgl.vec = vec;
496 	sgl.num = n;
497 	symvec.src_sgl = &sgl;
498 	symvec.iv = &iv_ptr;
499 	symvec.digest = &digest_ptr;
500 	symvec.status = &st;
501 	symvec.num = 1;
502 
503 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
504 	digest_ptr.va = (void *)sop->auth.digest.data;
505 
506 	ofs.raw = 0;
507 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
508 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
509 		(sop->cipher.data.offset + sop->cipher.data.length);
510 
511 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
512 		&symvec);
513 
514 	if (n != 1)
515 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
516 	else
517 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
518 }
519 
520 static struct rte_crypto_op *
521 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
522 {
523 
524 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
525 
526 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
527 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
528 		return NULL;
529 	}
530 
531 	op = NULL;
532 
533 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
534 		rte_pause();
535 
536 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
537 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
538 		return NULL;
539 	}
540 
541 	return op;
542 }
543 
544 static int
545 testsuite_setup(void)
546 {
547 	struct crypto_testsuite_params *ts_params = &testsuite_params;
548 	struct rte_cryptodev_info info;
549 	uint32_t i = 0, nb_devs, dev_id;
550 	uint16_t qp_id;
551 
552 	memset(ts_params, 0, sizeof(*ts_params));
553 
554 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
555 	if (ts_params->mbuf_pool == NULL) {
556 		/* Not already created so create */
557 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
558 				"CRYPTO_MBUFPOOL",
559 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
560 				rte_socket_id());
561 		if (ts_params->mbuf_pool == NULL) {
562 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
563 			return TEST_FAILED;
564 		}
565 	}
566 
567 	ts_params->large_mbuf_pool = rte_mempool_lookup(
568 			"CRYPTO_LARGE_MBUFPOOL");
569 	if (ts_params->large_mbuf_pool == NULL) {
570 		/* Not already created so create */
571 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
572 				"CRYPTO_LARGE_MBUFPOOL",
573 				1, 0, 0, UINT16_MAX,
574 				rte_socket_id());
575 		if (ts_params->large_mbuf_pool == NULL) {
576 			RTE_LOG(ERR, USER1,
577 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
578 			return TEST_FAILED;
579 		}
580 	}
581 
582 	ts_params->op_mpool = rte_crypto_op_pool_create(
583 			"MBUF_CRYPTO_SYM_OP_POOL",
584 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
585 			NUM_MBUFS, MBUF_CACHE_SIZE,
586 			DEFAULT_NUM_XFORMS *
587 			sizeof(struct rte_crypto_sym_xform) +
588 			MAXIMUM_IV_LENGTH,
589 			rte_socket_id());
590 	if (ts_params->op_mpool == NULL) {
591 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
592 		return TEST_FAILED;
593 	}
594 
595 	nb_devs = rte_cryptodev_count();
596 	if (nb_devs < 1) {
597 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
598 		return TEST_SKIPPED;
599 	}
600 
601 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
602 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
603 				rte_cryptodev_driver_name_get(gbl_driver_id));
604 		return TEST_SKIPPED;
605 	}
606 
607 	/* Create list of valid crypto devs */
608 	for (i = 0; i < nb_devs; i++) {
609 		rte_cryptodev_info_get(i, &info);
610 		if (info.driver_id == gbl_driver_id)
611 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
612 	}
613 
614 	if (ts_params->valid_dev_count < 1)
615 		return TEST_FAILED;
616 
617 	/* Set up all the qps on the first of the valid devices found */
618 
619 	dev_id = ts_params->valid_devs[0];
620 
621 	rte_cryptodev_info_get(dev_id, &info);
622 
623 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
624 	ts_params->conf.socket_id = SOCKET_ID_ANY;
625 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
626 
627 	unsigned int session_size =
628 		rte_cryptodev_sym_get_private_session_size(dev_id);
629 
630 #ifdef RTE_LIB_SECURITY
631 	unsigned int security_session_size = rte_security_session_get_size(
632 			rte_cryptodev_get_sec_ctx(dev_id));
633 
634 	if (session_size < security_session_size)
635 		session_size = security_session_size;
636 #endif
637 	/*
638 	 * Create mempool with maximum number of sessions.
639 	 */
640 	if (info.sym.max_nb_sessions != 0 &&
641 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
642 		RTE_LOG(ERR, USER1, "Device does not support "
643 				"at least %u sessions\n",
644 				MAX_NB_SESSIONS);
645 		return TEST_FAILED;
646 	}
647 
648 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
649 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
650 			SOCKET_ID_ANY);
651 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
652 			"session mempool allocation failed");
653 
654 	ts_params->session_priv_mpool = rte_mempool_create(
655 			"test_sess_mp_priv",
656 			MAX_NB_SESSIONS,
657 			session_size,
658 			0, 0, NULL, NULL, NULL,
659 			NULL, SOCKET_ID_ANY,
660 			0);
661 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
662 			"session mempool allocation failed");
663 
664 
665 
666 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
667 			&ts_params->conf),
668 			"Failed to configure cryptodev %u with %u qps",
669 			dev_id, ts_params->conf.nb_queue_pairs);
670 
671 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
672 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
673 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
674 
675 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
676 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
677 			dev_id, qp_id, &ts_params->qp_conf,
678 			rte_cryptodev_socket_id(dev_id)),
679 			"Failed to setup queue pair %u on cryptodev %u",
680 			qp_id, dev_id);
681 	}
682 
683 	return TEST_SUCCESS;
684 }
685 
686 static void
687 testsuite_teardown(void)
688 {
689 	struct crypto_testsuite_params *ts_params = &testsuite_params;
690 	int res;
691 
692 	if (ts_params->mbuf_pool != NULL) {
693 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
694 		rte_mempool_avail_count(ts_params->mbuf_pool));
695 	}
696 
697 	if (ts_params->op_mpool != NULL) {
698 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
699 		rte_mempool_avail_count(ts_params->op_mpool));
700 	}
701 
702 	/* Free session mempools */
703 	if (ts_params->session_priv_mpool != NULL) {
704 		rte_mempool_free(ts_params->session_priv_mpool);
705 		ts_params->session_priv_mpool = NULL;
706 	}
707 
708 	if (ts_params->session_mpool != NULL) {
709 		rte_mempool_free(ts_params->session_mpool);
710 		ts_params->session_mpool = NULL;
711 	}
712 
713 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
714 	if (res)
715 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
716 }
717 
718 static int
719 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
720 		const int *algs, uint16_t num_algs)
721 {
722 	uint8_t dev_id = testsuite_params.valid_devs[0];
723 	bool some_alg_supported = FALSE;
724 	uint16_t i;
725 
726 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
727 		struct rte_cryptodev_sym_capability_idx alg = {
728 			type, {algs[i]}
729 		};
730 		if (rte_cryptodev_sym_capability_get(dev_id,
731 				&alg) != NULL)
732 			some_alg_supported = TRUE;
733 	}
734 	if (!some_alg_supported)
735 		return TEST_SKIPPED;
736 
737 	return 0;
738 }
739 
740 int
741 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
742 		uint16_t num_ciphers)
743 {
744 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
745 			(const int *) ciphers, num_ciphers);
746 }
747 
748 int
749 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
750 		uint16_t num_auths)
751 {
752 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
753 			(const int *) auths, num_auths);
754 }
755 
756 int
757 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
758 		uint16_t num_aeads)
759 {
760 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
761 			(const int *) aeads, num_aeads);
762 }
763 
764 static int
765 null_testsuite_setup(void)
766 {
767 	struct crypto_testsuite_params *ts_params = &testsuite_params;
768 	uint8_t dev_id = ts_params->valid_devs[0];
769 	struct rte_cryptodev_info dev_info;
770 	const enum rte_crypto_cipher_algorithm ciphers[] = {
771 		RTE_CRYPTO_CIPHER_NULL
772 	};
773 	const enum rte_crypto_auth_algorithm auths[] = {
774 		RTE_CRYPTO_AUTH_NULL
775 	};
776 
777 	rte_cryptodev_info_get(dev_id, &dev_info);
778 
779 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
780 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
781 				"testsuite not met\n");
782 		return TEST_SKIPPED;
783 	}
784 
785 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
786 			&& check_auth_capabilities_supported(auths,
787 			RTE_DIM(auths)) != 0) {
788 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
789 				"testsuite not met\n");
790 		return TEST_SKIPPED;
791 	}
792 
793 	return 0;
794 }
795 
796 static int
797 crypto_gen_testsuite_setup(void)
798 {
799 	struct crypto_testsuite_params *ts_params = &testsuite_params;
800 	uint8_t dev_id = ts_params->valid_devs[0];
801 	struct rte_cryptodev_info dev_info;
802 
803 	rte_cryptodev_info_get(dev_id, &dev_info);
804 
805 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
806 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
807 				"testsuite not met\n");
808 		return TEST_SKIPPED;
809 	}
810 
811 	return 0;
812 }
813 
814 #ifdef RTE_LIB_SECURITY
815 static int
816 ipsec_proto_testsuite_setup(void)
817 {
818 	struct crypto_testsuite_params *ts_params = &testsuite_params;
819 	struct crypto_unittest_params *ut_params = &unittest_params;
820 	struct rte_cryptodev_info dev_info;
821 	int ret = 0;
822 
823 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
824 
825 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
826 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
827 				"testsuite not met\n");
828 		return TEST_SKIPPED;
829 	}
830 
831 	/* Reconfigure to enable security */
832 	ret = dev_configure_and_start(0);
833 	if (ret != TEST_SUCCESS)
834 		return ret;
835 
836 	/* Set action type */
837 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
838 
839 	if (security_proto_supported(
840 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
841 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
842 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
843 				"test not met\n");
844 		ret = TEST_SKIPPED;
845 	}
846 
847 	test_ipsec_alg_list_populate();
848 	test_ipsec_ah_alg_list_populate();
849 
850 	/*
851 	 * Stop the device. Device would be started again by individual test
852 	 * case setup routine.
853 	 */
854 	rte_cryptodev_stop(ts_params->valid_devs[0]);
855 
856 	return ret;
857 }
858 
859 static int
860 pdcp_proto_testsuite_setup(void)
861 {
862 	struct crypto_testsuite_params *ts_params = &testsuite_params;
863 	uint8_t dev_id = ts_params->valid_devs[0];
864 	struct rte_cryptodev_info dev_info;
865 	const enum rte_crypto_cipher_algorithm ciphers[] = {
866 		RTE_CRYPTO_CIPHER_NULL,
867 		RTE_CRYPTO_CIPHER_AES_CTR,
868 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
869 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
870 	};
871 	const enum rte_crypto_auth_algorithm auths[] = {
872 		RTE_CRYPTO_AUTH_NULL,
873 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
874 		RTE_CRYPTO_AUTH_AES_CMAC,
875 		RTE_CRYPTO_AUTH_ZUC_EIA3
876 	};
877 
878 	rte_cryptodev_info_get(dev_id, &dev_info);
879 
880 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
881 			!(dev_info.feature_flags &
882 			RTE_CRYPTODEV_FF_SECURITY)) {
883 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
884 				"testsuite not met\n");
885 		return TEST_SKIPPED;
886 	}
887 
888 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
889 			&& check_auth_capabilities_supported(auths,
890 			RTE_DIM(auths)) != 0) {
891 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
892 				"testsuite not met\n");
893 		return TEST_SKIPPED;
894 	}
895 
896 	return 0;
897 }
898 
899 static int
900 docsis_proto_testsuite_setup(void)
901 {
902 	struct crypto_testsuite_params *ts_params = &testsuite_params;
903 	uint8_t dev_id = ts_params->valid_devs[0];
904 	struct rte_cryptodev_info dev_info;
905 	const enum rte_crypto_cipher_algorithm ciphers[] = {
906 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
907 	};
908 
909 	rte_cryptodev_info_get(dev_id, &dev_info);
910 
911 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
912 			!(dev_info.feature_flags &
913 			RTE_CRYPTODEV_FF_SECURITY)) {
914 		RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS "
915 				"Proto testsuite not met\n");
916 		return TEST_SKIPPED;
917 	}
918 
919 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
920 		RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto "
921 				"testsuite not met\n");
922 		return TEST_SKIPPED;
923 	}
924 
925 	return 0;
926 }
927 #endif
928 
929 static int
930 aes_ccm_auth_testsuite_setup(void)
931 {
932 	struct crypto_testsuite_params *ts_params = &testsuite_params;
933 	uint8_t dev_id = ts_params->valid_devs[0];
934 	struct rte_cryptodev_info dev_info;
935 	const enum rte_crypto_aead_algorithm aeads[] = {
936 		RTE_CRYPTO_AEAD_AES_CCM
937 	};
938 
939 	rte_cryptodev_info_get(dev_id, &dev_info);
940 
941 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
942 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
943 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
944 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
945 				"testsuite not met\n");
946 		return TEST_SKIPPED;
947 	}
948 
949 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
950 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
951 				"testsuite not met\n");
952 		return TEST_SKIPPED;
953 	}
954 
955 	return 0;
956 }
957 
958 static int
959 aes_gcm_auth_testsuite_setup(void)
960 {
961 	struct crypto_testsuite_params *ts_params = &testsuite_params;
962 	uint8_t dev_id = ts_params->valid_devs[0];
963 	struct rte_cryptodev_info dev_info;
964 	const enum rte_crypto_aead_algorithm aeads[] = {
965 		RTE_CRYPTO_AEAD_AES_GCM
966 	};
967 
968 	rte_cryptodev_info_get(dev_id, &dev_info);
969 
970 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
971 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
972 				"testsuite not met\n");
973 		return TEST_SKIPPED;
974 	}
975 
976 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
977 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
978 				"testsuite not met\n");
979 		return TEST_SKIPPED;
980 	}
981 
982 	return 0;
983 }
984 
985 static int
986 aes_gmac_auth_testsuite_setup(void)
987 {
988 	struct crypto_testsuite_params *ts_params = &testsuite_params;
989 	uint8_t dev_id = ts_params->valid_devs[0];
990 	struct rte_cryptodev_info dev_info;
991 	const enum rte_crypto_auth_algorithm auths[] = {
992 		RTE_CRYPTO_AUTH_AES_GMAC
993 	};
994 
995 	rte_cryptodev_info_get(dev_id, &dev_info);
996 
997 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
998 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
999 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1000 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
1001 				"testsuite not met\n");
1002 		return TEST_SKIPPED;
1003 	}
1004 
1005 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1006 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
1007 				"testsuite not met\n");
1008 		return TEST_SKIPPED;
1009 	}
1010 
1011 	return 0;
1012 }
1013 
1014 static int
1015 chacha20_poly1305_testsuite_setup(void)
1016 {
1017 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1018 	uint8_t dev_id = ts_params->valid_devs[0];
1019 	struct rte_cryptodev_info dev_info;
1020 	const enum rte_crypto_aead_algorithm aeads[] = {
1021 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
1022 	};
1023 
1024 	rte_cryptodev_info_get(dev_id, &dev_info);
1025 
1026 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1027 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1028 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1029 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
1030 				"Chacha20-Poly1305 testsuite not met\n");
1031 		return TEST_SKIPPED;
1032 	}
1033 
1034 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1035 		RTE_LOG(INFO, USER1, "Capability requirements for "
1036 				"Chacha20-Poly1305 testsuite not met\n");
1037 		return TEST_SKIPPED;
1038 	}
1039 
1040 	return 0;
1041 }
1042 
1043 static int
1044 snow3g_testsuite_setup(void)
1045 {
1046 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1047 	uint8_t dev_id = ts_params->valid_devs[0];
1048 	struct rte_cryptodev_info dev_info;
1049 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1050 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1051 
1052 	};
1053 	const enum rte_crypto_auth_algorithm auths[] = {
1054 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1055 	};
1056 
1057 	rte_cryptodev_info_get(dev_id, &dev_info);
1058 
1059 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1060 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1061 				"testsuite not met\n");
1062 		return TEST_SKIPPED;
1063 	}
1064 
1065 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1066 			&& check_auth_capabilities_supported(auths,
1067 			RTE_DIM(auths)) != 0) {
1068 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1069 				"testsuite not met\n");
1070 		return TEST_SKIPPED;
1071 	}
1072 
1073 	return 0;
1074 }
1075 
1076 static int
1077 zuc_testsuite_setup(void)
1078 {
1079 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1080 	uint8_t dev_id = ts_params->valid_devs[0];
1081 	struct rte_cryptodev_info dev_info;
1082 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1083 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1084 	};
1085 	const enum rte_crypto_auth_algorithm auths[] = {
1086 		RTE_CRYPTO_AUTH_ZUC_EIA3
1087 	};
1088 
1089 	rte_cryptodev_info_get(dev_id, &dev_info);
1090 
1091 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1092 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1093 				"testsuite not met\n");
1094 		return TEST_SKIPPED;
1095 	}
1096 
1097 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1098 			&& check_auth_capabilities_supported(auths,
1099 			RTE_DIM(auths)) != 0) {
1100 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1101 				"testsuite not met\n");
1102 		return TEST_SKIPPED;
1103 	}
1104 
1105 	return 0;
1106 }
1107 
1108 static int
1109 hmac_md5_auth_testsuite_setup(void)
1110 {
1111 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1112 	uint8_t dev_id = ts_params->valid_devs[0];
1113 	struct rte_cryptodev_info dev_info;
1114 	const enum rte_crypto_auth_algorithm auths[] = {
1115 		RTE_CRYPTO_AUTH_MD5_HMAC
1116 	};
1117 
1118 	rte_cryptodev_info_get(dev_id, &dev_info);
1119 
1120 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1121 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1122 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1123 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1124 				"Auth testsuite not met\n");
1125 		return TEST_SKIPPED;
1126 	}
1127 
1128 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1129 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1130 				"testsuite not met\n");
1131 		return TEST_SKIPPED;
1132 	}
1133 
1134 	return 0;
1135 }
1136 
1137 static int
1138 kasumi_testsuite_setup(void)
1139 {
1140 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1141 	uint8_t dev_id = ts_params->valid_devs[0];
1142 	struct rte_cryptodev_info dev_info;
1143 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1144 		RTE_CRYPTO_CIPHER_KASUMI_F8
1145 	};
1146 	const enum rte_crypto_auth_algorithm auths[] = {
1147 		RTE_CRYPTO_AUTH_KASUMI_F9
1148 	};
1149 
1150 	rte_cryptodev_info_get(dev_id, &dev_info);
1151 
1152 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1153 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1154 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1155 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1156 				"testsuite not met\n");
1157 		return TEST_SKIPPED;
1158 	}
1159 
1160 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1161 			&& check_auth_capabilities_supported(auths,
1162 			RTE_DIM(auths)) != 0) {
1163 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1164 				"testsuite not met\n");
1165 		return TEST_SKIPPED;
1166 	}
1167 
1168 	return 0;
1169 }
1170 
1171 static int
1172 negative_aes_gcm_testsuite_setup(void)
1173 {
1174 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1175 	uint8_t dev_id = ts_params->valid_devs[0];
1176 	struct rte_cryptodev_info dev_info;
1177 	const enum rte_crypto_aead_algorithm aeads[] = {
1178 		RTE_CRYPTO_AEAD_AES_GCM
1179 	};
1180 
1181 	rte_cryptodev_info_get(dev_id, &dev_info);
1182 
1183 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1184 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1185 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1186 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1187 				"AES GCM testsuite not met\n");
1188 		return TEST_SKIPPED;
1189 	}
1190 
1191 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1192 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1193 				"AES GCM testsuite not met\n");
1194 		return TEST_SKIPPED;
1195 	}
1196 
1197 	return 0;
1198 }
1199 
1200 static int
1201 negative_aes_gmac_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_auth_algorithm auths[] = {
1207 		RTE_CRYPTO_AUTH_AES_GMAC
1208 	};
1209 
1210 	rte_cryptodev_info_get(dev_id, &dev_info);
1211 
1212 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1213 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1214 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1215 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1216 				"AES GMAC testsuite not met\n");
1217 		return TEST_SKIPPED;
1218 	}
1219 
1220 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1221 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1222 				"AES GMAC testsuite not met\n");
1223 		return TEST_SKIPPED;
1224 	}
1225 
1226 	return 0;
1227 }
1228 
1229 static int
1230 mixed_cipher_hash_testsuite_setup(void)
1231 {
1232 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1233 	uint8_t dev_id = ts_params->valid_devs[0];
1234 	struct rte_cryptodev_info dev_info;
1235 	uint64_t feat_flags;
1236 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1237 		RTE_CRYPTO_CIPHER_NULL,
1238 		RTE_CRYPTO_CIPHER_AES_CTR,
1239 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1240 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1241 	};
1242 	const enum rte_crypto_auth_algorithm auths[] = {
1243 		RTE_CRYPTO_AUTH_NULL,
1244 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1245 		RTE_CRYPTO_AUTH_AES_CMAC,
1246 		RTE_CRYPTO_AUTH_ZUC_EIA3
1247 	};
1248 
1249 	rte_cryptodev_info_get(dev_id, &dev_info);
1250 	feat_flags = dev_info.feature_flags;
1251 
1252 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1253 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1254 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1255 				"Cipher Hash testsuite not met\n");
1256 		return TEST_SKIPPED;
1257 	}
1258 
1259 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1260 			&& check_auth_capabilities_supported(auths,
1261 			RTE_DIM(auths)) != 0) {
1262 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1263 				"Cipher Hash testsuite not met\n");
1264 		return TEST_SKIPPED;
1265 	}
1266 
1267 	return 0;
1268 }
1269 
1270 static int
1271 esn_testsuite_setup(void)
1272 {
1273 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1274 	uint8_t dev_id = ts_params->valid_devs[0];
1275 	struct rte_cryptodev_info dev_info;
1276 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1277 		RTE_CRYPTO_CIPHER_AES_CBC
1278 	};
1279 	const enum rte_crypto_auth_algorithm auths[] = {
1280 		RTE_CRYPTO_AUTH_SHA1_HMAC
1281 	};
1282 
1283 	rte_cryptodev_info_get(dev_id, &dev_info);
1284 
1285 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1286 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1287 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1288 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1289 				"testsuite not met\n");
1290 		return TEST_SKIPPED;
1291 	}
1292 
1293 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1294 			&& check_auth_capabilities_supported(auths,
1295 			RTE_DIM(auths)) != 0) {
1296 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1297 				"testsuite not met\n");
1298 		return TEST_SKIPPED;
1299 	}
1300 
1301 	return 0;
1302 }
1303 
1304 static int
1305 multi_session_testsuite_setup(void)
1306 {
1307 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1308 	uint8_t dev_id = ts_params->valid_devs[0];
1309 	struct rte_cryptodev_info dev_info;
1310 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1311 		RTE_CRYPTO_CIPHER_AES_CBC
1312 	};
1313 	const enum rte_crypto_auth_algorithm auths[] = {
1314 		RTE_CRYPTO_AUTH_SHA512_HMAC
1315 	};
1316 
1317 	rte_cryptodev_info_get(dev_id, &dev_info);
1318 
1319 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1320 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1321 				"Session testsuite not met\n");
1322 		return TEST_SKIPPED;
1323 	}
1324 
1325 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1326 			&& check_auth_capabilities_supported(auths,
1327 			RTE_DIM(auths)) != 0) {
1328 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1329 				"Session testsuite not met\n");
1330 		return TEST_SKIPPED;
1331 	}
1332 
1333 	return 0;
1334 }
1335 
1336 static int
1337 negative_hmac_sha1_testsuite_setup(void)
1338 {
1339 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1340 	uint8_t dev_id = ts_params->valid_devs[0];
1341 	struct rte_cryptodev_info dev_info;
1342 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1343 		RTE_CRYPTO_CIPHER_AES_CBC
1344 	};
1345 	const enum rte_crypto_auth_algorithm auths[] = {
1346 		RTE_CRYPTO_AUTH_SHA1_HMAC
1347 	};
1348 
1349 	rte_cryptodev_info_get(dev_id, &dev_info);
1350 
1351 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1352 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1353 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1354 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1355 				"HMAC SHA1 testsuite not met\n");
1356 		return TEST_SKIPPED;
1357 	}
1358 
1359 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1360 			&& check_auth_capabilities_supported(auths,
1361 			RTE_DIM(auths)) != 0) {
1362 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1363 				"HMAC SHA1 testsuite not met\n");
1364 		return TEST_SKIPPED;
1365 	}
1366 
1367 	return 0;
1368 }
1369 
1370 static int
1371 dev_configure_and_start(uint64_t ff_disable)
1372 {
1373 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1374 	struct crypto_unittest_params *ut_params = &unittest_params;
1375 
1376 	uint16_t qp_id;
1377 
1378 	/* Clear unit test parameters before running test */
1379 	memset(ut_params, 0, sizeof(*ut_params));
1380 
1381 	/* Reconfigure device to default parameters */
1382 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1383 	ts_params->conf.ff_disable = ff_disable;
1384 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1385 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1386 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1387 
1388 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1389 			&ts_params->conf),
1390 			"Failed to configure cryptodev %u",
1391 			ts_params->valid_devs[0]);
1392 
1393 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1394 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1395 			ts_params->valid_devs[0], qp_id,
1396 			&ts_params->qp_conf,
1397 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1398 			"Failed to setup queue pair %u on cryptodev %u",
1399 			qp_id, ts_params->valid_devs[0]);
1400 	}
1401 
1402 
1403 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1404 
1405 	/* Start the device */
1406 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1407 			"Failed to start cryptodev %u",
1408 			ts_params->valid_devs[0]);
1409 
1410 	return TEST_SUCCESS;
1411 }
1412 
1413 int
1414 ut_setup(void)
1415 {
1416 	/* Configure and start the device with security feature disabled */
1417 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1418 }
1419 
1420 static int
1421 ut_setup_security(void)
1422 {
1423 	/* Configure and start the device with no features disabled */
1424 	return dev_configure_and_start(0);
1425 }
1426 
1427 void
1428 ut_teardown(void)
1429 {
1430 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1431 	struct crypto_unittest_params *ut_params = &unittest_params;
1432 
1433 	/* free crypto session structure */
1434 #ifdef RTE_LIB_SECURITY
1435 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1436 		if (ut_params->sec_session) {
1437 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1438 						(ts_params->valid_devs[0]),
1439 						ut_params->sec_session);
1440 			ut_params->sec_session = NULL;
1441 		}
1442 	} else
1443 #endif
1444 	{
1445 		if (ut_params->sess) {
1446 			rte_cryptodev_sym_session_clear(
1447 					ts_params->valid_devs[0],
1448 					ut_params->sess);
1449 			rte_cryptodev_sym_session_free(ut_params->sess);
1450 			ut_params->sess = NULL;
1451 		}
1452 	}
1453 
1454 	/* free crypto operation structure */
1455 	if (ut_params->op)
1456 		rte_crypto_op_free(ut_params->op);
1457 
1458 	/*
1459 	 * free mbuf - both obuf and ibuf are usually the same,
1460 	 * so check if they point at the same address is necessary,
1461 	 * to avoid freeing the mbuf twice.
1462 	 */
1463 	if (ut_params->obuf) {
1464 		rte_pktmbuf_free(ut_params->obuf);
1465 		if (ut_params->ibuf == ut_params->obuf)
1466 			ut_params->ibuf = 0;
1467 		ut_params->obuf = 0;
1468 	}
1469 	if (ut_params->ibuf) {
1470 		rte_pktmbuf_free(ut_params->ibuf);
1471 		ut_params->ibuf = 0;
1472 	}
1473 
1474 	if (ts_params->mbuf_pool != NULL)
1475 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1476 			rte_mempool_avail_count(ts_params->mbuf_pool));
1477 
1478 	/* Stop the device */
1479 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1480 }
1481 
1482 static int
1483 test_device_configure_invalid_dev_id(void)
1484 {
1485 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1486 	uint16_t dev_id, num_devs = 0;
1487 
1488 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1489 			"Need at least %d devices for test", 1);
1490 
1491 	/* valid dev_id values */
1492 	dev_id = ts_params->valid_devs[0];
1493 
1494 	/* Stop the device in case it's started so it can be configured */
1495 	rte_cryptodev_stop(dev_id);
1496 
1497 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1498 			"Failed test for rte_cryptodev_configure: "
1499 			"invalid dev_num %u", dev_id);
1500 
1501 	/* invalid dev_id values */
1502 	dev_id = num_devs;
1503 
1504 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1505 			"Failed test for rte_cryptodev_configure: "
1506 			"invalid dev_num %u", dev_id);
1507 
1508 	dev_id = 0xff;
1509 
1510 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1511 			"Failed test for rte_cryptodev_configure:"
1512 			"invalid dev_num %u", dev_id);
1513 
1514 	return TEST_SUCCESS;
1515 }
1516 
1517 static int
1518 test_device_configure_invalid_queue_pair_ids(void)
1519 {
1520 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1521 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1522 
1523 	/* Stop the device in case it's started so it can be configured */
1524 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1525 
1526 	/* valid - max value queue pairs */
1527 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1528 
1529 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1530 			&ts_params->conf),
1531 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1532 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1533 
1534 	/* valid - one queue pairs */
1535 	ts_params->conf.nb_queue_pairs = 1;
1536 
1537 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1538 			&ts_params->conf),
1539 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1540 			ts_params->valid_devs[0],
1541 			ts_params->conf.nb_queue_pairs);
1542 
1543 
1544 	/* invalid - zero queue pairs */
1545 	ts_params->conf.nb_queue_pairs = 0;
1546 
1547 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1548 			&ts_params->conf),
1549 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1550 			" invalid qps: %u",
1551 			ts_params->valid_devs[0],
1552 			ts_params->conf.nb_queue_pairs);
1553 
1554 
1555 	/* invalid - max value supported by field queue pairs */
1556 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1557 
1558 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1559 			&ts_params->conf),
1560 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1561 			" invalid qps: %u",
1562 			ts_params->valid_devs[0],
1563 			ts_params->conf.nb_queue_pairs);
1564 
1565 
1566 	/* invalid - max value + 1 queue pairs */
1567 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1568 
1569 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1570 			&ts_params->conf),
1571 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1572 			" invalid qps: %u",
1573 			ts_params->valid_devs[0],
1574 			ts_params->conf.nb_queue_pairs);
1575 
1576 	/* revert to original testsuite value */
1577 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1578 
1579 	return TEST_SUCCESS;
1580 }
1581 
1582 static int
1583 test_queue_pair_descriptor_setup(void)
1584 {
1585 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1586 	struct rte_cryptodev_qp_conf qp_conf = {
1587 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1588 	};
1589 	uint16_t qp_id;
1590 
1591 	/* Stop the device in case it's started so it can be configured */
1592 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1593 
1594 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1595 			&ts_params->conf),
1596 			"Failed to configure cryptodev %u",
1597 			ts_params->valid_devs[0]);
1598 
1599 	/*
1600 	 * Test various ring sizes on this device. memzones can't be
1601 	 * freed so are re-used if ring is released and re-created.
1602 	 */
1603 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1604 	qp_conf.mp_session = ts_params->session_mpool;
1605 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1606 
1607 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1608 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1609 				ts_params->valid_devs[0], qp_id, &qp_conf,
1610 				rte_cryptodev_socket_id(
1611 						ts_params->valid_devs[0])),
1612 				"Failed test for "
1613 				"rte_cryptodev_queue_pair_setup: num_inflights "
1614 				"%u on qp %u on cryptodev %u",
1615 				qp_conf.nb_descriptors, qp_id,
1616 				ts_params->valid_devs[0]);
1617 	}
1618 
1619 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1620 
1621 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1622 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1623 				ts_params->valid_devs[0], qp_id, &qp_conf,
1624 				rte_cryptodev_socket_id(
1625 						ts_params->valid_devs[0])),
1626 				"Failed test for"
1627 				" rte_cryptodev_queue_pair_setup: num_inflights"
1628 				" %u on qp %u on cryptodev %u",
1629 				qp_conf.nb_descriptors, qp_id,
1630 				ts_params->valid_devs[0]);
1631 	}
1632 
1633 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1634 
1635 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1636 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1637 				ts_params->valid_devs[0], qp_id, &qp_conf,
1638 				rte_cryptodev_socket_id(
1639 						ts_params->valid_devs[0])),
1640 				"Failed test for "
1641 				"rte_cryptodev_queue_pair_setup: num_inflights"
1642 				" %u on qp %u on cryptodev %u",
1643 				qp_conf.nb_descriptors, qp_id,
1644 				ts_params->valid_devs[0]);
1645 	}
1646 
1647 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1648 
1649 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1650 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1651 				ts_params->valid_devs[0], qp_id, &qp_conf,
1652 				rte_cryptodev_socket_id(
1653 						ts_params->valid_devs[0])),
1654 				"Failed test for"
1655 				" rte_cryptodev_queue_pair_setup:"
1656 				"num_inflights %u on qp %u on cryptodev %u",
1657 				qp_conf.nb_descriptors, qp_id,
1658 				ts_params->valid_devs[0]);
1659 	}
1660 
1661 	/* test invalid queue pair id */
1662 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1663 
1664 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1665 
1666 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1667 			ts_params->valid_devs[0],
1668 			qp_id, &qp_conf,
1669 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1670 			"Failed test for rte_cryptodev_queue_pair_setup:"
1671 			"invalid qp %u on cryptodev %u",
1672 			qp_id, ts_params->valid_devs[0]);
1673 
1674 	qp_id = 0xffff; /*invalid*/
1675 
1676 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1677 			ts_params->valid_devs[0],
1678 			qp_id, &qp_conf,
1679 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1680 			"Failed test for rte_cryptodev_queue_pair_setup:"
1681 			"invalid qp %u on cryptodev %u",
1682 			qp_id, ts_params->valid_devs[0]);
1683 
1684 	return TEST_SUCCESS;
1685 }
1686 
1687 /* ***** Plaintext data for tests ***** */
1688 
1689 const char catch_22_quote_1[] =
1690 		"There was only one catch and that was Catch-22, which "
1691 		"specified that a concern for one's safety in the face of "
1692 		"dangers that were real and immediate was the process of a "
1693 		"rational mind. Orr was crazy and could be grounded. All he "
1694 		"had to do was ask; and as soon as he did, he would no longer "
1695 		"be crazy and would have to fly more missions. Orr would be "
1696 		"crazy to fly more missions and sane if he didn't, but if he "
1697 		"was sane he had to fly them. If he flew them he was crazy "
1698 		"and didn't have to; but if he didn't want to he was sane and "
1699 		"had to. Yossarian was moved very deeply by the absolute "
1700 		"simplicity of this clause of Catch-22 and let out a "
1701 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1702 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1703 
1704 const char catch_22_quote[] =
1705 		"What a lousy earth! He wondered how many people were "
1706 		"destitute that same night even in his own prosperous country, "
1707 		"how many homes were shanties, how many husbands were drunk "
1708 		"and wives socked, and how many children were bullied, abused, "
1709 		"or abandoned. How many families hungered for food they could "
1710 		"not afford to buy? How many hearts were broken? How many "
1711 		"suicides would take place that same night, how many people "
1712 		"would go insane? How many cockroaches and landlords would "
1713 		"triumph? How many winners were losers, successes failures, "
1714 		"and rich men poor men? How many wise guys were stupid? How "
1715 		"many happy endings were unhappy endings? How many honest men "
1716 		"were liars, brave men cowards, loyal men traitors, how many "
1717 		"sainted men were corrupt, how many people in positions of "
1718 		"trust had sold their souls to bodyguards, how many had never "
1719 		"had souls? How many straight-and-narrow paths were crooked "
1720 		"paths? How many best families were worst families and how "
1721 		"many good people were bad people? When you added them all up "
1722 		"and then subtracted, you might be left with only the children, "
1723 		"and perhaps with Albert Einstein and an old violinist or "
1724 		"sculptor somewhere.";
1725 
1726 #define QUOTE_480_BYTES		(480)
1727 #define QUOTE_512_BYTES		(512)
1728 #define QUOTE_768_BYTES		(768)
1729 #define QUOTE_1024_BYTES	(1024)
1730 
1731 
1732 
1733 /* ***** SHA1 Hash Tests ***** */
1734 
1735 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1736 
1737 static uint8_t hmac_sha1_key[] = {
1738 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1739 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1740 	0xDE, 0xF4, 0xDE, 0xAD };
1741 
1742 /* ***** SHA224 Hash Tests ***** */
1743 
1744 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1745 
1746 
1747 /* ***** AES-CBC Cipher Tests ***** */
1748 
1749 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1750 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1751 
1752 static uint8_t aes_cbc_key[] = {
1753 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1754 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1755 
1756 static uint8_t aes_cbc_iv[] = {
1757 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1758 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1759 
1760 
1761 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1762 
1763 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1764 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1765 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1766 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1767 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1768 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1769 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1770 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1771 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1772 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1773 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1774 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1775 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1776 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1777 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1778 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1779 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1780 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1781 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1782 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1783 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1784 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1785 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1786 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1787 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1788 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1789 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1790 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1791 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1792 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1793 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1794 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1795 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1796 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1797 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1798 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1799 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1800 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1801 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1802 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1803 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1804 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1805 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1806 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1807 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1808 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1809 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1810 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1811 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1812 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1813 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1814 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1815 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1816 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1817 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1818 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1819 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1820 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1821 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1822 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1823 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1824 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1825 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1826 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1827 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1828 };
1829 
1830 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1831 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1832 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1833 	0x18, 0x8c, 0x1d, 0x32
1834 };
1835 
1836 
1837 /* Multisession Vector context Test */
1838 /*Begin Session 0 */
1839 static uint8_t ms_aes_cbc_key0[] = {
1840 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1841 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1842 };
1843 
1844 static uint8_t ms_aes_cbc_iv0[] = {
1845 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1846 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1847 };
1848 
1849 static const uint8_t ms_aes_cbc_cipher0[] = {
1850 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1851 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1852 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1853 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1854 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1855 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1856 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1857 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1858 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1859 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1860 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1861 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1862 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1863 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1864 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1865 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1866 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1867 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1868 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1869 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1870 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1871 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1872 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1873 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1874 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1875 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1876 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1877 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1878 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1879 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1880 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1881 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1882 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1883 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1884 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1885 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1886 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1887 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1888 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1889 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1890 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1891 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1892 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1893 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1894 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1895 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1896 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1897 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1898 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1899 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1900 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1901 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1902 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1903 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1904 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1905 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1906 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1907 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1908 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1909 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1910 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1911 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1912 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1913 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1914 };
1915 
1916 
1917 static  uint8_t ms_hmac_key0[] = {
1918 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1919 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1920 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1921 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1922 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1923 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1924 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1925 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1926 };
1927 
1928 static const uint8_t ms_hmac_digest0[] = {
1929 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1930 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1931 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1932 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1933 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1934 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1935 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1936 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1937 		};
1938 
1939 /* End Session 0 */
1940 /* Begin session 1 */
1941 
1942 static  uint8_t ms_aes_cbc_key1[] = {
1943 		0xf1, 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_iv1[] = {
1948 	0xf1, 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_cipher1[] = {
1953 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1954 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1955 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1956 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1957 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1958 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1959 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1960 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1961 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1962 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1963 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1964 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1965 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1966 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1967 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1968 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1969 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1970 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1971 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1972 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1973 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1974 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1975 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1976 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1977 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1978 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1979 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1980 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1981 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1982 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1983 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1984 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1985 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1986 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1987 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1988 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1989 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1990 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1991 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1992 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1993 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1994 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1995 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1996 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1997 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1998 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1999 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
2000 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
2001 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
2002 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
2003 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
2004 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
2005 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
2006 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
2007 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
2008 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
2009 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2010 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2011 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2012 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2013 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2014 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2015 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2016 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2017 
2018 };
2019 
2020 static uint8_t ms_hmac_key1[] = {
2021 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2022 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2023 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2024 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2025 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2026 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2027 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2028 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2029 };
2030 
2031 static const uint8_t ms_hmac_digest1[] = {
2032 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2033 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2034 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2035 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2036 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2037 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2038 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2039 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2040 };
2041 /* End Session 1  */
2042 /* Begin Session 2 */
2043 static  uint8_t ms_aes_cbc_key2[] = {
2044 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2045 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2046 };
2047 
2048 static  uint8_t ms_aes_cbc_iv2[] = {
2049 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2050 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2051 };
2052 
2053 static const uint8_t ms_aes_cbc_cipher2[] = {
2054 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2055 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2056 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2057 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2058 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2059 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2060 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2061 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2062 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2063 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2064 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2065 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2066 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2067 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2068 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2069 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2070 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2071 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2072 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2073 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2074 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2075 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2076 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2077 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2078 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2079 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2080 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2081 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2082 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2083 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2084 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2085 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2086 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2087 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2088 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2089 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2090 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2091 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2092 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2093 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2094 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2095 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2096 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2097 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2098 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2099 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2100 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2101 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2102 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2103 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2104 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2105 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2106 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2107 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2108 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2109 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2110 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2111 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2112 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2113 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2114 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2115 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2116 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2117 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2118 };
2119 
2120 static  uint8_t ms_hmac_key2[] = {
2121 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2122 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2123 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2124 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2125 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2126 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2127 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2128 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2129 };
2130 
2131 static const uint8_t ms_hmac_digest2[] = {
2132 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2133 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2134 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2135 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2136 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2137 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2138 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2139 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2140 };
2141 
2142 /* End Session 2 */
2143 
2144 
2145 static int
2146 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2147 {
2148 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2149 	struct crypto_unittest_params *ut_params = &unittest_params;
2150 	int status;
2151 
2152 	/* Verify the capabilities */
2153 	struct rte_cryptodev_sym_capability_idx cap_idx;
2154 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2155 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2156 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2157 			&cap_idx) == NULL)
2158 		return TEST_SKIPPED;
2159 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2160 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2161 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2162 			&cap_idx) == NULL)
2163 		return TEST_SKIPPED;
2164 
2165 	/* Generate test mbuf data and space for digest */
2166 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2167 			catch_22_quote,	QUOTE_512_BYTES, 0);
2168 
2169 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2170 			DIGEST_BYTE_LENGTH_SHA1);
2171 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2172 
2173 	/* Setup Cipher Parameters */
2174 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2175 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2176 
2177 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2178 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2179 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2180 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2181 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2182 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2183 
2184 	/* Setup HMAC Parameters */
2185 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2186 
2187 	ut_params->auth_xform.next = NULL;
2188 
2189 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2190 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2191 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2192 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2193 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2194 
2195 	ut_params->sess = rte_cryptodev_sym_session_create(
2196 			ts_params->session_mpool);
2197 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2198 
2199 	/* Create crypto session*/
2200 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2201 			ut_params->sess, &ut_params->cipher_xform,
2202 			ts_params->session_priv_mpool);
2203 
2204 	if (status == -ENOTSUP)
2205 		return TEST_SKIPPED;
2206 
2207 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
2208 
2209 	/* Generate crypto op data structure */
2210 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2211 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2212 	TEST_ASSERT_NOT_NULL(ut_params->op,
2213 			"Failed to allocate symmetric crypto operation struct");
2214 
2215 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2216 
2217 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2218 
2219 	/* set crypto operation source mbuf */
2220 	sym_op->m_src = ut_params->ibuf;
2221 
2222 	/* Set crypto operation authentication parameters */
2223 	sym_op->auth.digest.data = ut_params->digest;
2224 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2225 			ut_params->ibuf, QUOTE_512_BYTES);
2226 
2227 	sym_op->auth.data.offset = 0;
2228 	sym_op->auth.data.length = QUOTE_512_BYTES;
2229 
2230 	/* Copy IV at the end of the crypto operation */
2231 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2232 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2233 
2234 	/* Set crypto operation cipher parameters */
2235 	sym_op->cipher.data.offset = 0;
2236 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2237 
2238 	/* Process crypto operation */
2239 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2240 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2241 			ut_params->op);
2242 	else
2243 		TEST_ASSERT_NOT_NULL(
2244 			process_crypto_request(ts_params->valid_devs[0],
2245 				ut_params->op),
2246 				"failed to process sym crypto op");
2247 
2248 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2249 			"crypto op processing failed");
2250 
2251 	/* Validate obuf */
2252 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2253 			uint8_t *);
2254 
2255 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2256 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2257 			QUOTE_512_BYTES,
2258 			"ciphertext data not as expected");
2259 
2260 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2261 
2262 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2263 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2264 			gbl_driver_id == rte_cryptodev_driver_id_get(
2265 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2266 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2267 					DIGEST_BYTE_LENGTH_SHA1,
2268 			"Generated digest data not as expected");
2269 
2270 	return TEST_SUCCESS;
2271 }
2272 
2273 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2274 
2275 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2276 
2277 static uint8_t hmac_sha512_key[] = {
2278 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2279 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2280 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2281 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2282 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2283 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2284 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2285 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2286 
2287 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2288 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2289 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2290 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2291 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2292 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2293 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2294 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2295 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2296 
2297 
2298 
2299 static int
2300 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2301 		struct crypto_unittest_params *ut_params,
2302 		uint8_t *cipher_key,
2303 		uint8_t *hmac_key);
2304 
2305 static int
2306 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2307 		struct crypto_unittest_params *ut_params,
2308 		struct crypto_testsuite_params *ts_params,
2309 		const uint8_t *cipher,
2310 		const uint8_t *digest,
2311 		const uint8_t *iv);
2312 
2313 
2314 static int
2315 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2316 		struct crypto_unittest_params *ut_params,
2317 		uint8_t *cipher_key,
2318 		uint8_t *hmac_key)
2319 {
2320 
2321 	/* Setup Cipher Parameters */
2322 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2323 	ut_params->cipher_xform.next = NULL;
2324 
2325 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2326 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2327 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2328 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2329 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2330 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2331 
2332 	/* Setup HMAC Parameters */
2333 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2334 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2335 
2336 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2337 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2338 	ut_params->auth_xform.auth.key.data = hmac_key;
2339 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2340 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2341 
2342 	return TEST_SUCCESS;
2343 }
2344 
2345 
2346 static int
2347 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2348 		struct crypto_unittest_params *ut_params,
2349 		struct crypto_testsuite_params *ts_params,
2350 		const uint8_t *cipher,
2351 		const uint8_t *digest,
2352 		const uint8_t *iv)
2353 {
2354 	/* Generate test mbuf data and digest */
2355 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2356 			(const char *)
2357 			cipher,
2358 			QUOTE_512_BYTES, 0);
2359 
2360 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2361 			DIGEST_BYTE_LENGTH_SHA512);
2362 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2363 
2364 	rte_memcpy(ut_params->digest,
2365 			digest,
2366 			DIGEST_BYTE_LENGTH_SHA512);
2367 
2368 	/* Generate Crypto op data structure */
2369 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2370 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2371 	TEST_ASSERT_NOT_NULL(ut_params->op,
2372 			"Failed to allocate symmetric crypto operation struct");
2373 
2374 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2375 
2376 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2377 
2378 	/* set crypto operation source mbuf */
2379 	sym_op->m_src = ut_params->ibuf;
2380 
2381 	sym_op->auth.digest.data = ut_params->digest;
2382 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2383 			ut_params->ibuf, QUOTE_512_BYTES);
2384 
2385 	sym_op->auth.data.offset = 0;
2386 	sym_op->auth.data.length = QUOTE_512_BYTES;
2387 
2388 	/* Copy IV at the end of the crypto operation */
2389 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2390 			iv, CIPHER_IV_LENGTH_AES_CBC);
2391 
2392 	sym_op->cipher.data.offset = 0;
2393 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2394 
2395 	/* Process crypto operation */
2396 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2397 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2398 			ut_params->op);
2399 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2400 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2401 				ut_params->op, 1, 1, 0, 0);
2402 	else
2403 		TEST_ASSERT_NOT_NULL(
2404 				process_crypto_request(ts_params->valid_devs[0],
2405 					ut_params->op),
2406 					"failed to process sym crypto op");
2407 
2408 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2409 			"crypto op processing failed");
2410 
2411 	ut_params->obuf = ut_params->op->sym->m_src;
2412 
2413 	/* Validate obuf */
2414 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2415 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2416 			catch_22_quote,
2417 			QUOTE_512_BYTES,
2418 			"Plaintext data not as expected");
2419 
2420 	/* Validate obuf */
2421 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2422 			"Digest verification failed");
2423 
2424 	return TEST_SUCCESS;
2425 }
2426 
2427 /* ***** SNOW 3G Tests ***** */
2428 static int
2429 create_wireless_algo_hash_session(uint8_t dev_id,
2430 	const uint8_t *key, const uint8_t key_len,
2431 	const uint8_t iv_len, const uint8_t auth_len,
2432 	enum rte_crypto_auth_operation op,
2433 	enum rte_crypto_auth_algorithm algo)
2434 {
2435 	uint8_t hash_key[key_len];
2436 	int status;
2437 
2438 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2439 	struct crypto_unittest_params *ut_params = &unittest_params;
2440 
2441 	memcpy(hash_key, key, key_len);
2442 
2443 	debug_hexdump(stdout, "key:", key, key_len);
2444 
2445 	/* Setup Authentication Parameters */
2446 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2447 	ut_params->auth_xform.next = NULL;
2448 
2449 	ut_params->auth_xform.auth.op = op;
2450 	ut_params->auth_xform.auth.algo = algo;
2451 	ut_params->auth_xform.auth.key.length = key_len;
2452 	ut_params->auth_xform.auth.key.data = hash_key;
2453 	ut_params->auth_xform.auth.digest_length = auth_len;
2454 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2455 	ut_params->auth_xform.auth.iv.length = iv_len;
2456 	ut_params->sess = rte_cryptodev_sym_session_create(
2457 			ts_params->session_mpool);
2458 
2459 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2460 			&ut_params->auth_xform,
2461 			ts_params->session_priv_mpool);
2462 	if (status == -ENOTSUP)
2463 		return TEST_SKIPPED;
2464 
2465 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2466 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2467 	return 0;
2468 }
2469 
2470 static int
2471 create_wireless_algo_cipher_session(uint8_t dev_id,
2472 			enum rte_crypto_cipher_operation op,
2473 			enum rte_crypto_cipher_algorithm algo,
2474 			const uint8_t *key, const uint8_t key_len,
2475 			uint8_t iv_len)
2476 {
2477 	uint8_t cipher_key[key_len];
2478 	int status;
2479 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2480 	struct crypto_unittest_params *ut_params = &unittest_params;
2481 
2482 	memcpy(cipher_key, key, key_len);
2483 
2484 	/* Setup Cipher Parameters */
2485 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2486 	ut_params->cipher_xform.next = NULL;
2487 
2488 	ut_params->cipher_xform.cipher.algo = algo;
2489 	ut_params->cipher_xform.cipher.op = op;
2490 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2491 	ut_params->cipher_xform.cipher.key.length = key_len;
2492 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2493 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2494 
2495 	debug_hexdump(stdout, "key:", key, key_len);
2496 
2497 	/* Create Crypto session */
2498 	ut_params->sess = rte_cryptodev_sym_session_create(
2499 			ts_params->session_mpool);
2500 
2501 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2502 			&ut_params->cipher_xform,
2503 			ts_params->session_priv_mpool);
2504 	if (status == -ENOTSUP)
2505 		return TEST_SKIPPED;
2506 
2507 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2508 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2509 	return 0;
2510 }
2511 
2512 static int
2513 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2514 			unsigned int cipher_len,
2515 			unsigned int cipher_offset)
2516 {
2517 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2518 	struct crypto_unittest_params *ut_params = &unittest_params;
2519 
2520 	/* Generate Crypto op data structure */
2521 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2522 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2523 	TEST_ASSERT_NOT_NULL(ut_params->op,
2524 				"Failed to allocate pktmbuf offload");
2525 
2526 	/* Set crypto operation data parameters */
2527 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2528 
2529 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2530 
2531 	/* set crypto operation source mbuf */
2532 	sym_op->m_src = ut_params->ibuf;
2533 
2534 	/* iv */
2535 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2536 			iv, iv_len);
2537 	sym_op->cipher.data.length = cipher_len;
2538 	sym_op->cipher.data.offset = cipher_offset;
2539 	return 0;
2540 }
2541 
2542 static int
2543 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2544 			unsigned int cipher_len,
2545 			unsigned int cipher_offset)
2546 {
2547 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2548 	struct crypto_unittest_params *ut_params = &unittest_params;
2549 
2550 	/* Generate Crypto op data structure */
2551 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2552 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2553 	TEST_ASSERT_NOT_NULL(ut_params->op,
2554 				"Failed to allocate pktmbuf offload");
2555 
2556 	/* Set crypto operation data parameters */
2557 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2558 
2559 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2560 
2561 	/* set crypto operation source mbuf */
2562 	sym_op->m_src = ut_params->ibuf;
2563 	sym_op->m_dst = ut_params->obuf;
2564 
2565 	/* iv */
2566 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2567 			iv, iv_len);
2568 	sym_op->cipher.data.length = cipher_len;
2569 	sym_op->cipher.data.offset = cipher_offset;
2570 	return 0;
2571 }
2572 
2573 static int
2574 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2575 		enum rte_crypto_cipher_operation cipher_op,
2576 		enum rte_crypto_auth_operation auth_op,
2577 		enum rte_crypto_auth_algorithm auth_algo,
2578 		enum rte_crypto_cipher_algorithm cipher_algo,
2579 		const uint8_t *key, uint8_t key_len,
2580 		uint8_t auth_iv_len, uint8_t auth_len,
2581 		uint8_t cipher_iv_len)
2582 
2583 {
2584 	uint8_t cipher_auth_key[key_len];
2585 	int status;
2586 
2587 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2588 	struct crypto_unittest_params *ut_params = &unittest_params;
2589 
2590 	memcpy(cipher_auth_key, key, key_len);
2591 
2592 	/* Setup Authentication Parameters */
2593 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2594 	ut_params->auth_xform.next = NULL;
2595 
2596 	ut_params->auth_xform.auth.op = auth_op;
2597 	ut_params->auth_xform.auth.algo = auth_algo;
2598 	ut_params->auth_xform.auth.key.length = key_len;
2599 	/* Hash key = cipher key */
2600 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2601 	ut_params->auth_xform.auth.digest_length = auth_len;
2602 	/* Auth IV will be after cipher IV */
2603 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2604 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2605 
2606 	/* Setup Cipher Parameters */
2607 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2608 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2609 
2610 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2611 	ut_params->cipher_xform.cipher.op = cipher_op;
2612 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2613 	ut_params->cipher_xform.cipher.key.length = key_len;
2614 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2615 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2616 
2617 	debug_hexdump(stdout, "key:", key, key_len);
2618 
2619 	/* Create Crypto session*/
2620 	ut_params->sess = rte_cryptodev_sym_session_create(
2621 			ts_params->session_mpool);
2622 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2623 
2624 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2625 			&ut_params->cipher_xform,
2626 			ts_params->session_priv_mpool);
2627 	if (status == -ENOTSUP)
2628 		return TEST_SKIPPED;
2629 
2630 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2631 	return 0;
2632 }
2633 
2634 static int
2635 create_wireless_cipher_auth_session(uint8_t dev_id,
2636 		enum rte_crypto_cipher_operation cipher_op,
2637 		enum rte_crypto_auth_operation auth_op,
2638 		enum rte_crypto_auth_algorithm auth_algo,
2639 		enum rte_crypto_cipher_algorithm cipher_algo,
2640 		const struct wireless_test_data *tdata)
2641 {
2642 	const uint8_t key_len = tdata->key.len;
2643 	uint8_t cipher_auth_key[key_len];
2644 	int status;
2645 
2646 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2647 	struct crypto_unittest_params *ut_params = &unittest_params;
2648 	const uint8_t *key = tdata->key.data;
2649 	const uint8_t auth_len = tdata->digest.len;
2650 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2651 	uint8_t auth_iv_len = tdata->auth_iv.len;
2652 
2653 	memcpy(cipher_auth_key, key, key_len);
2654 
2655 	/* Setup Authentication Parameters */
2656 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2657 	ut_params->auth_xform.next = NULL;
2658 
2659 	ut_params->auth_xform.auth.op = auth_op;
2660 	ut_params->auth_xform.auth.algo = auth_algo;
2661 	ut_params->auth_xform.auth.key.length = key_len;
2662 	/* Hash key = cipher key */
2663 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2664 	ut_params->auth_xform.auth.digest_length = auth_len;
2665 	/* Auth IV will be after cipher IV */
2666 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2667 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2668 
2669 	/* Setup Cipher Parameters */
2670 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2671 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2672 
2673 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2674 	ut_params->cipher_xform.cipher.op = cipher_op;
2675 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2676 	ut_params->cipher_xform.cipher.key.length = key_len;
2677 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2678 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2679 
2680 
2681 	debug_hexdump(stdout, "key:", key, key_len);
2682 
2683 	/* Create Crypto session*/
2684 	ut_params->sess = rte_cryptodev_sym_session_create(
2685 			ts_params->session_mpool);
2686 
2687 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2688 			&ut_params->cipher_xform,
2689 			ts_params->session_priv_mpool);
2690 	if (status == -ENOTSUP)
2691 		return TEST_SKIPPED;
2692 
2693 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2694 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2695 	return 0;
2696 }
2697 
2698 static int
2699 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2700 		const struct wireless_test_data *tdata)
2701 {
2702 	return create_wireless_cipher_auth_session(dev_id,
2703 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2704 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2705 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2706 }
2707 
2708 static int
2709 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2710 		enum rte_crypto_cipher_operation cipher_op,
2711 		enum rte_crypto_auth_operation auth_op,
2712 		enum rte_crypto_auth_algorithm auth_algo,
2713 		enum rte_crypto_cipher_algorithm cipher_algo,
2714 		const uint8_t *key, const uint8_t key_len,
2715 		uint8_t auth_iv_len, uint8_t auth_len,
2716 		uint8_t cipher_iv_len)
2717 {
2718 	uint8_t auth_cipher_key[key_len];
2719 	int status;
2720 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2721 	struct crypto_unittest_params *ut_params = &unittest_params;
2722 
2723 	memcpy(auth_cipher_key, key, key_len);
2724 
2725 	/* Setup Authentication Parameters */
2726 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2727 	ut_params->auth_xform.auth.op = auth_op;
2728 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2729 	ut_params->auth_xform.auth.algo = auth_algo;
2730 	ut_params->auth_xform.auth.key.length = key_len;
2731 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2732 	ut_params->auth_xform.auth.digest_length = auth_len;
2733 	/* Auth IV will be after cipher IV */
2734 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2735 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2736 
2737 	/* Setup Cipher Parameters */
2738 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2739 	ut_params->cipher_xform.next = NULL;
2740 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2741 	ut_params->cipher_xform.cipher.op = cipher_op;
2742 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2743 	ut_params->cipher_xform.cipher.key.length = key_len;
2744 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2745 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2746 
2747 	debug_hexdump(stdout, "key:", key, key_len);
2748 
2749 	/* Create Crypto session*/
2750 	ut_params->sess = rte_cryptodev_sym_session_create(
2751 			ts_params->session_mpool);
2752 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2753 
2754 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2755 		ut_params->auth_xform.next = NULL;
2756 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2757 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2758 				&ut_params->cipher_xform,
2759 				ts_params->session_priv_mpool);
2760 
2761 	} else
2762 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2763 				&ut_params->auth_xform,
2764 				ts_params->session_priv_mpool);
2765 
2766 	if (status == -ENOTSUP)
2767 		return TEST_SKIPPED;
2768 
2769 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2770 
2771 	return 0;
2772 }
2773 
2774 static int
2775 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2776 		unsigned int auth_tag_len,
2777 		const uint8_t *iv, unsigned int iv_len,
2778 		unsigned int data_pad_len,
2779 		enum rte_crypto_auth_operation op,
2780 		unsigned int auth_len, unsigned int auth_offset)
2781 {
2782 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2783 
2784 	struct crypto_unittest_params *ut_params = &unittest_params;
2785 
2786 	/* Generate Crypto op data structure */
2787 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2788 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2789 	TEST_ASSERT_NOT_NULL(ut_params->op,
2790 		"Failed to allocate pktmbuf offload");
2791 
2792 	/* Set crypto operation data parameters */
2793 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2794 
2795 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2796 
2797 	/* set crypto operation source mbuf */
2798 	sym_op->m_src = ut_params->ibuf;
2799 
2800 	/* iv */
2801 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2802 			iv, iv_len);
2803 	/* digest */
2804 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2805 					ut_params->ibuf, auth_tag_len);
2806 
2807 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2808 				"no room to append auth tag");
2809 	ut_params->digest = sym_op->auth.digest.data;
2810 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2811 			ut_params->ibuf, data_pad_len);
2812 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2813 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2814 	else
2815 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2816 
2817 	debug_hexdump(stdout, "digest:",
2818 		sym_op->auth.digest.data,
2819 		auth_tag_len);
2820 
2821 	sym_op->auth.data.length = auth_len;
2822 	sym_op->auth.data.offset = auth_offset;
2823 
2824 	return 0;
2825 }
2826 
2827 static int
2828 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2829 	enum rte_crypto_auth_operation op)
2830 {
2831 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2832 	struct crypto_unittest_params *ut_params = &unittest_params;
2833 
2834 	const uint8_t *auth_tag = tdata->digest.data;
2835 	const unsigned int auth_tag_len = tdata->digest.len;
2836 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2837 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2838 
2839 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2840 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2841 	const uint8_t *auth_iv = tdata->auth_iv.data;
2842 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2843 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2844 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2845 
2846 	/* Generate Crypto op data structure */
2847 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2848 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2849 	TEST_ASSERT_NOT_NULL(ut_params->op,
2850 			"Failed to allocate pktmbuf offload");
2851 	/* Set crypto operation data parameters */
2852 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2853 
2854 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2855 
2856 	/* set crypto operation source mbuf */
2857 	sym_op->m_src = ut_params->ibuf;
2858 
2859 	/* digest */
2860 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2861 			ut_params->ibuf, auth_tag_len);
2862 
2863 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2864 			"no room to append auth tag");
2865 	ut_params->digest = sym_op->auth.digest.data;
2866 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2867 			ut_params->ibuf, data_pad_len);
2868 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2869 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2870 	else
2871 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2872 
2873 	debug_hexdump(stdout, "digest:",
2874 		sym_op->auth.digest.data,
2875 		auth_tag_len);
2876 
2877 	/* Copy cipher and auth IVs at the end of the crypto operation */
2878 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2879 						IV_OFFSET);
2880 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2881 	iv_ptr += cipher_iv_len;
2882 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2883 
2884 	sym_op->cipher.data.length = cipher_len;
2885 	sym_op->cipher.data.offset = 0;
2886 	sym_op->auth.data.length = auth_len;
2887 	sym_op->auth.data.offset = 0;
2888 
2889 	return 0;
2890 }
2891 
2892 static int
2893 create_zuc_cipher_hash_generate_operation(
2894 		const struct wireless_test_data *tdata)
2895 {
2896 	return create_wireless_cipher_hash_operation(tdata,
2897 		RTE_CRYPTO_AUTH_OP_GENERATE);
2898 }
2899 
2900 static int
2901 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2902 		const unsigned auth_tag_len,
2903 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2904 		unsigned data_pad_len,
2905 		enum rte_crypto_auth_operation op,
2906 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2907 		const unsigned cipher_len, const unsigned cipher_offset,
2908 		const unsigned auth_len, const unsigned auth_offset)
2909 {
2910 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2911 	struct crypto_unittest_params *ut_params = &unittest_params;
2912 
2913 	enum rte_crypto_cipher_algorithm cipher_algo =
2914 			ut_params->cipher_xform.cipher.algo;
2915 	enum rte_crypto_auth_algorithm auth_algo =
2916 			ut_params->auth_xform.auth.algo;
2917 
2918 	/* Generate Crypto op data structure */
2919 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2920 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2921 	TEST_ASSERT_NOT_NULL(ut_params->op,
2922 			"Failed to allocate pktmbuf offload");
2923 	/* Set crypto operation data parameters */
2924 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2925 
2926 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2927 
2928 	/* set crypto operation source mbuf */
2929 	sym_op->m_src = ut_params->ibuf;
2930 
2931 	/* digest */
2932 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2933 			ut_params->ibuf, auth_tag_len);
2934 
2935 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2936 			"no room to append auth tag");
2937 	ut_params->digest = sym_op->auth.digest.data;
2938 
2939 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2940 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2941 				ut_params->ibuf, data_pad_len);
2942 	} else {
2943 		struct rte_mbuf *m = ut_params->ibuf;
2944 		unsigned int offset = data_pad_len;
2945 
2946 		while (offset > m->data_len && m->next != NULL) {
2947 			offset -= m->data_len;
2948 			m = m->next;
2949 		}
2950 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2951 			m, offset);
2952 	}
2953 
2954 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2955 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2956 	else
2957 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2958 
2959 	debug_hexdump(stdout, "digest:",
2960 		sym_op->auth.digest.data,
2961 		auth_tag_len);
2962 
2963 	/* Copy cipher and auth IVs at the end of the crypto operation */
2964 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2965 						IV_OFFSET);
2966 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2967 	iv_ptr += cipher_iv_len;
2968 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2969 
2970 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2971 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2972 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2973 		sym_op->cipher.data.length = cipher_len;
2974 		sym_op->cipher.data.offset = cipher_offset;
2975 	} else {
2976 		sym_op->cipher.data.length = cipher_len >> 3;
2977 		sym_op->cipher.data.offset = cipher_offset >> 3;
2978 	}
2979 
2980 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2981 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2982 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2983 		sym_op->auth.data.length = auth_len;
2984 		sym_op->auth.data.offset = auth_offset;
2985 	} else {
2986 		sym_op->auth.data.length = auth_len >> 3;
2987 		sym_op->auth.data.offset = auth_offset >> 3;
2988 	}
2989 
2990 	return 0;
2991 }
2992 
2993 static int
2994 create_wireless_algo_auth_cipher_operation(
2995 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2996 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2997 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2998 		unsigned int data_pad_len,
2999 		unsigned int cipher_len, unsigned int cipher_offset,
3000 		unsigned int auth_len, unsigned int auth_offset,
3001 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
3002 {
3003 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3004 	struct crypto_unittest_params *ut_params = &unittest_params;
3005 
3006 	enum rte_crypto_cipher_algorithm cipher_algo =
3007 			ut_params->cipher_xform.cipher.algo;
3008 	enum rte_crypto_auth_algorithm auth_algo =
3009 			ut_params->auth_xform.auth.algo;
3010 
3011 	/* Generate Crypto op data structure */
3012 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3013 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3014 	TEST_ASSERT_NOT_NULL(ut_params->op,
3015 			"Failed to allocate pktmbuf offload");
3016 
3017 	/* Set crypto operation data parameters */
3018 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3019 
3020 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3021 
3022 	/* set crypto operation mbufs */
3023 	sym_op->m_src = ut_params->ibuf;
3024 	if (op_mode == OUT_OF_PLACE)
3025 		sym_op->m_dst = ut_params->obuf;
3026 
3027 	/* digest */
3028 	if (!do_sgl) {
3029 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
3030 			(op_mode == IN_PLACE ?
3031 				ut_params->ibuf : ut_params->obuf),
3032 			uint8_t *, data_pad_len);
3033 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3034 			(op_mode == IN_PLACE ?
3035 				ut_params->ibuf : ut_params->obuf),
3036 			data_pad_len);
3037 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3038 	} else {
3039 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3040 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3041 				sym_op->m_src : sym_op->m_dst);
3042 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3043 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3044 			sgl_buf = sgl_buf->next;
3045 		}
3046 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3047 				uint8_t *, remaining_off);
3048 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3049 				remaining_off);
3050 		memset(sym_op->auth.digest.data, 0, remaining_off);
3051 		while (sgl_buf->next != NULL) {
3052 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3053 				0, rte_pktmbuf_data_len(sgl_buf));
3054 			sgl_buf = sgl_buf->next;
3055 		}
3056 	}
3057 
3058 	/* Copy digest for the verification */
3059 	if (verify)
3060 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3061 
3062 	/* Copy cipher and auth IVs at the end of the crypto operation */
3063 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3064 			ut_params->op, uint8_t *, IV_OFFSET);
3065 
3066 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3067 	iv_ptr += cipher_iv_len;
3068 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3069 
3070 	/* Only copy over the offset data needed from src to dst in OOP,
3071 	 * if the auth and cipher offsets are not aligned
3072 	 */
3073 	if (op_mode == OUT_OF_PLACE) {
3074 		if (cipher_offset > auth_offset)
3075 			rte_memcpy(
3076 				rte_pktmbuf_mtod_offset(
3077 					sym_op->m_dst,
3078 					uint8_t *, auth_offset >> 3),
3079 				rte_pktmbuf_mtod_offset(
3080 					sym_op->m_src,
3081 					uint8_t *, auth_offset >> 3),
3082 				((cipher_offset >> 3) - (auth_offset >> 3)));
3083 	}
3084 
3085 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3086 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3087 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3088 		sym_op->cipher.data.length = cipher_len;
3089 		sym_op->cipher.data.offset = cipher_offset;
3090 	} else {
3091 		sym_op->cipher.data.length = cipher_len >> 3;
3092 		sym_op->cipher.data.offset = cipher_offset >> 3;
3093 	}
3094 
3095 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3096 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3097 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3098 		sym_op->auth.data.length = auth_len;
3099 		sym_op->auth.data.offset = auth_offset;
3100 	} else {
3101 		sym_op->auth.data.length = auth_len >> 3;
3102 		sym_op->auth.data.offset = auth_offset >> 3;
3103 	}
3104 
3105 	return 0;
3106 }
3107 
3108 static int
3109 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3110 {
3111 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3112 	struct crypto_unittest_params *ut_params = &unittest_params;
3113 
3114 	int retval;
3115 	unsigned plaintext_pad_len;
3116 	unsigned plaintext_len;
3117 	uint8_t *plaintext;
3118 	struct rte_cryptodev_info dev_info;
3119 
3120 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3121 	uint64_t feat_flags = dev_info.feature_flags;
3122 
3123 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3124 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3125 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3126 		return TEST_SKIPPED;
3127 	}
3128 
3129 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3130 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3131 		printf("Device doesn't support RAW data-path APIs.\n");
3132 		return TEST_SKIPPED;
3133 	}
3134 
3135 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3136 		return TEST_SKIPPED;
3137 
3138 	/* Verify the capabilities */
3139 	struct rte_cryptodev_sym_capability_idx cap_idx;
3140 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3141 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3142 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3143 			&cap_idx) == NULL)
3144 		return TEST_SKIPPED;
3145 
3146 	/* Create SNOW 3G session */
3147 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3148 			tdata->key.data, tdata->key.len,
3149 			tdata->auth_iv.len, tdata->digest.len,
3150 			RTE_CRYPTO_AUTH_OP_GENERATE,
3151 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3152 	if (retval < 0)
3153 		return retval;
3154 
3155 	/* alloc mbuf and set payload */
3156 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3157 
3158 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3159 	rte_pktmbuf_tailroom(ut_params->ibuf));
3160 
3161 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3162 	/* Append data which is padded to a multiple of */
3163 	/* the algorithms block size */
3164 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3165 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3166 				plaintext_pad_len);
3167 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3168 
3169 	/* Create SNOW 3G operation */
3170 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3171 			tdata->auth_iv.data, tdata->auth_iv.len,
3172 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3173 			tdata->validAuthLenInBits.len,
3174 			0);
3175 	if (retval < 0)
3176 		return retval;
3177 
3178 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3179 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3180 				ut_params->op, 0, 1, 1, 0);
3181 	else
3182 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3183 				ut_params->op);
3184 	ut_params->obuf = ut_params->op->sym->m_src;
3185 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3186 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3187 			+ plaintext_pad_len;
3188 
3189 	/* Validate obuf */
3190 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3191 	ut_params->digest,
3192 	tdata->digest.data,
3193 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3194 	"SNOW 3G Generated auth tag not as expected");
3195 
3196 	return 0;
3197 }
3198 
3199 static int
3200 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3201 {
3202 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3203 	struct crypto_unittest_params *ut_params = &unittest_params;
3204 
3205 	int retval;
3206 	unsigned plaintext_pad_len;
3207 	unsigned plaintext_len;
3208 	uint8_t *plaintext;
3209 	struct rte_cryptodev_info dev_info;
3210 
3211 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3212 	uint64_t feat_flags = dev_info.feature_flags;
3213 
3214 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3215 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3216 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3217 		return TEST_SKIPPED;
3218 	}
3219 
3220 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3221 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3222 		printf("Device doesn't support RAW data-path APIs.\n");
3223 		return TEST_SKIPPED;
3224 	}
3225 
3226 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3227 		return TEST_SKIPPED;
3228 
3229 	/* Verify the capabilities */
3230 	struct rte_cryptodev_sym_capability_idx cap_idx;
3231 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3232 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3233 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3234 			&cap_idx) == NULL)
3235 		return TEST_SKIPPED;
3236 
3237 	/* Create SNOW 3G session */
3238 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3239 				tdata->key.data, tdata->key.len,
3240 				tdata->auth_iv.len, tdata->digest.len,
3241 				RTE_CRYPTO_AUTH_OP_VERIFY,
3242 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3243 	if (retval < 0)
3244 		return retval;
3245 	/* alloc mbuf and set payload */
3246 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3247 
3248 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3249 	rte_pktmbuf_tailroom(ut_params->ibuf));
3250 
3251 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3252 	/* Append data which is padded to a multiple of */
3253 	/* the algorithms block size */
3254 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3255 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3256 				plaintext_pad_len);
3257 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3258 
3259 	/* Create SNOW 3G operation */
3260 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3261 			tdata->digest.len,
3262 			tdata->auth_iv.data, tdata->auth_iv.len,
3263 			plaintext_pad_len,
3264 			RTE_CRYPTO_AUTH_OP_VERIFY,
3265 			tdata->validAuthLenInBits.len,
3266 			0);
3267 	if (retval < 0)
3268 		return retval;
3269 
3270 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3271 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3272 				ut_params->op, 0, 1, 1, 0);
3273 	else
3274 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3275 				ut_params->op);
3276 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3277 	ut_params->obuf = ut_params->op->sym->m_src;
3278 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3279 				+ plaintext_pad_len;
3280 
3281 	/* Validate obuf */
3282 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3283 		return 0;
3284 	else
3285 		return -1;
3286 
3287 	return 0;
3288 }
3289 
3290 static int
3291 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3292 {
3293 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3294 	struct crypto_unittest_params *ut_params = &unittest_params;
3295 
3296 	int retval;
3297 	unsigned plaintext_pad_len;
3298 	unsigned plaintext_len;
3299 	uint8_t *plaintext;
3300 	struct rte_cryptodev_info dev_info;
3301 
3302 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3303 	uint64_t feat_flags = dev_info.feature_flags;
3304 
3305 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3306 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3307 		printf("Device doesn't support RAW data-path APIs.\n");
3308 		return TEST_SKIPPED;
3309 	}
3310 
3311 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3312 		return TEST_SKIPPED;
3313 
3314 	/* Verify the capabilities */
3315 	struct rte_cryptodev_sym_capability_idx cap_idx;
3316 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3317 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3318 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3319 			&cap_idx) == NULL)
3320 		return TEST_SKIPPED;
3321 
3322 	/* Create KASUMI session */
3323 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3324 			tdata->key.data, tdata->key.len,
3325 			0, tdata->digest.len,
3326 			RTE_CRYPTO_AUTH_OP_GENERATE,
3327 			RTE_CRYPTO_AUTH_KASUMI_F9);
3328 	if (retval < 0)
3329 		return retval;
3330 
3331 	/* alloc mbuf and set payload */
3332 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3333 
3334 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3335 	rte_pktmbuf_tailroom(ut_params->ibuf));
3336 
3337 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3338 	/* Append data which is padded to a multiple of */
3339 	/* the algorithms block size */
3340 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3341 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3342 				plaintext_pad_len);
3343 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3344 
3345 	/* Create KASUMI operation */
3346 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3347 			NULL, 0,
3348 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3349 			tdata->plaintext.len,
3350 			0);
3351 	if (retval < 0)
3352 		return retval;
3353 
3354 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3355 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3356 			ut_params->op);
3357 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3358 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3359 				ut_params->op, 0, 1, 1, 0);
3360 	else
3361 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3362 			ut_params->op);
3363 
3364 	ut_params->obuf = ut_params->op->sym->m_src;
3365 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3366 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3367 			+ plaintext_pad_len;
3368 
3369 	/* Validate obuf */
3370 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3371 	ut_params->digest,
3372 	tdata->digest.data,
3373 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3374 	"KASUMI Generated auth tag not as expected");
3375 
3376 	return 0;
3377 }
3378 
3379 static int
3380 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3381 {
3382 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3383 	struct crypto_unittest_params *ut_params = &unittest_params;
3384 
3385 	int retval;
3386 	unsigned plaintext_pad_len;
3387 	unsigned plaintext_len;
3388 	uint8_t *plaintext;
3389 	struct rte_cryptodev_info dev_info;
3390 
3391 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3392 	uint64_t feat_flags = dev_info.feature_flags;
3393 
3394 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3395 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3396 		printf("Device doesn't support RAW data-path APIs.\n");
3397 		return TEST_SKIPPED;
3398 	}
3399 
3400 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3401 		return TEST_SKIPPED;
3402 
3403 	/* Verify the capabilities */
3404 	struct rte_cryptodev_sym_capability_idx cap_idx;
3405 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3406 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3407 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3408 			&cap_idx) == NULL)
3409 		return TEST_SKIPPED;
3410 
3411 	/* Create KASUMI session */
3412 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3413 				tdata->key.data, tdata->key.len,
3414 				0, tdata->digest.len,
3415 				RTE_CRYPTO_AUTH_OP_VERIFY,
3416 				RTE_CRYPTO_AUTH_KASUMI_F9);
3417 	if (retval < 0)
3418 		return retval;
3419 	/* alloc mbuf and set payload */
3420 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3421 
3422 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3423 	rte_pktmbuf_tailroom(ut_params->ibuf));
3424 
3425 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3426 	/* Append data which is padded to a multiple */
3427 	/* of the algorithms block size */
3428 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3429 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3430 				plaintext_pad_len);
3431 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3432 
3433 	/* Create KASUMI operation */
3434 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3435 			tdata->digest.len,
3436 			NULL, 0,
3437 			plaintext_pad_len,
3438 			RTE_CRYPTO_AUTH_OP_VERIFY,
3439 			tdata->plaintext.len,
3440 			0);
3441 	if (retval < 0)
3442 		return retval;
3443 
3444 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3445 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3446 				ut_params->op, 0, 1, 1, 0);
3447 	else
3448 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3449 				ut_params->op);
3450 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3451 	ut_params->obuf = ut_params->op->sym->m_src;
3452 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3453 				+ plaintext_pad_len;
3454 
3455 	/* Validate obuf */
3456 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3457 		return 0;
3458 	else
3459 		return -1;
3460 
3461 	return 0;
3462 }
3463 
3464 static int
3465 test_snow3g_hash_generate_test_case_1(void)
3466 {
3467 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3468 }
3469 
3470 static int
3471 test_snow3g_hash_generate_test_case_2(void)
3472 {
3473 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3474 }
3475 
3476 static int
3477 test_snow3g_hash_generate_test_case_3(void)
3478 {
3479 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3480 }
3481 
3482 static int
3483 test_snow3g_hash_generate_test_case_4(void)
3484 {
3485 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3486 }
3487 
3488 static int
3489 test_snow3g_hash_generate_test_case_5(void)
3490 {
3491 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3492 }
3493 
3494 static int
3495 test_snow3g_hash_generate_test_case_6(void)
3496 {
3497 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3498 }
3499 
3500 static int
3501 test_snow3g_hash_verify_test_case_1(void)
3502 {
3503 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3504 
3505 }
3506 
3507 static int
3508 test_snow3g_hash_verify_test_case_2(void)
3509 {
3510 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3511 }
3512 
3513 static int
3514 test_snow3g_hash_verify_test_case_3(void)
3515 {
3516 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3517 }
3518 
3519 static int
3520 test_snow3g_hash_verify_test_case_4(void)
3521 {
3522 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3523 }
3524 
3525 static int
3526 test_snow3g_hash_verify_test_case_5(void)
3527 {
3528 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3529 }
3530 
3531 static int
3532 test_snow3g_hash_verify_test_case_6(void)
3533 {
3534 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3535 }
3536 
3537 static int
3538 test_kasumi_hash_generate_test_case_1(void)
3539 {
3540 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3541 }
3542 
3543 static int
3544 test_kasumi_hash_generate_test_case_2(void)
3545 {
3546 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3547 }
3548 
3549 static int
3550 test_kasumi_hash_generate_test_case_3(void)
3551 {
3552 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3553 }
3554 
3555 static int
3556 test_kasumi_hash_generate_test_case_4(void)
3557 {
3558 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3559 }
3560 
3561 static int
3562 test_kasumi_hash_generate_test_case_5(void)
3563 {
3564 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3565 }
3566 
3567 static int
3568 test_kasumi_hash_generate_test_case_6(void)
3569 {
3570 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3571 }
3572 
3573 static int
3574 test_kasumi_hash_verify_test_case_1(void)
3575 {
3576 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3577 }
3578 
3579 static int
3580 test_kasumi_hash_verify_test_case_2(void)
3581 {
3582 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3583 }
3584 
3585 static int
3586 test_kasumi_hash_verify_test_case_3(void)
3587 {
3588 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3589 }
3590 
3591 static int
3592 test_kasumi_hash_verify_test_case_4(void)
3593 {
3594 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3595 }
3596 
3597 static int
3598 test_kasumi_hash_verify_test_case_5(void)
3599 {
3600 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3601 }
3602 
3603 static int
3604 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3605 {
3606 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3607 	struct crypto_unittest_params *ut_params = &unittest_params;
3608 
3609 	int retval;
3610 	uint8_t *plaintext, *ciphertext;
3611 	unsigned plaintext_pad_len;
3612 	unsigned plaintext_len;
3613 	struct rte_cryptodev_info dev_info;
3614 
3615 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3616 	uint64_t feat_flags = dev_info.feature_flags;
3617 
3618 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3619 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3620 		printf("Device doesn't support RAW data-path APIs.\n");
3621 		return TEST_SKIPPED;
3622 	}
3623 
3624 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3625 		return TEST_SKIPPED;
3626 
3627 	/* Verify the capabilities */
3628 	struct rte_cryptodev_sym_capability_idx cap_idx;
3629 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3630 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3631 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3632 			&cap_idx) == NULL)
3633 		return TEST_SKIPPED;
3634 
3635 	/* Create KASUMI session */
3636 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3637 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3638 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3639 					tdata->key.data, tdata->key.len,
3640 					tdata->cipher_iv.len);
3641 	if (retval < 0)
3642 		return retval;
3643 
3644 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3645 
3646 	/* Clear mbuf payload */
3647 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3648 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3649 
3650 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3651 	/* Append data which is padded to a multiple */
3652 	/* of the algorithms block size */
3653 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3654 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3655 				plaintext_pad_len);
3656 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3657 
3658 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3659 
3660 	/* Create KASUMI operation */
3661 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3662 				tdata->cipher_iv.len,
3663 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3664 				tdata->validCipherOffsetInBits.len);
3665 	if (retval < 0)
3666 		return retval;
3667 
3668 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3669 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3670 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3671 	else
3672 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3673 				ut_params->op);
3674 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3675 
3676 	ut_params->obuf = ut_params->op->sym->m_dst;
3677 	if (ut_params->obuf)
3678 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3679 	else
3680 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3681 
3682 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3683 
3684 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3685 				(tdata->validCipherOffsetInBits.len >> 3);
3686 	/* Validate obuf */
3687 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3688 		ciphertext,
3689 		reference_ciphertext,
3690 		tdata->validCipherLenInBits.len,
3691 		"KASUMI Ciphertext data not as expected");
3692 	return 0;
3693 }
3694 
3695 static int
3696 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3697 {
3698 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3699 	struct crypto_unittest_params *ut_params = &unittest_params;
3700 
3701 	int retval;
3702 
3703 	unsigned int plaintext_pad_len;
3704 	unsigned int plaintext_len;
3705 
3706 	uint8_t buffer[10000];
3707 	const uint8_t *ciphertext;
3708 
3709 	struct rte_cryptodev_info dev_info;
3710 
3711 	/* Verify the capabilities */
3712 	struct rte_cryptodev_sym_capability_idx cap_idx;
3713 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3714 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3715 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3716 			&cap_idx) == NULL)
3717 		return TEST_SKIPPED;
3718 
3719 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3720 
3721 	uint64_t feat_flags = dev_info.feature_flags;
3722 
3723 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3724 		printf("Device doesn't support in-place scatter-gather. "
3725 				"Test Skipped.\n");
3726 		return TEST_SKIPPED;
3727 	}
3728 
3729 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3730 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3731 		printf("Device doesn't support RAW data-path APIs.\n");
3732 		return TEST_SKIPPED;
3733 	}
3734 
3735 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3736 		return TEST_SKIPPED;
3737 
3738 	/* Create KASUMI session */
3739 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3740 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3741 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3742 					tdata->key.data, tdata->key.len,
3743 					tdata->cipher_iv.len);
3744 	if (retval < 0)
3745 		return retval;
3746 
3747 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3748 
3749 
3750 	/* Append data which is padded to a multiple */
3751 	/* of the algorithms block size */
3752 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3753 
3754 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3755 			plaintext_pad_len, 10, 0);
3756 
3757 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3758 
3759 	/* Create KASUMI operation */
3760 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3761 				tdata->cipher_iv.len,
3762 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3763 				tdata->validCipherOffsetInBits.len);
3764 	if (retval < 0)
3765 		return retval;
3766 
3767 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3768 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3769 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3770 	else
3771 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3772 						ut_params->op);
3773 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3774 
3775 	ut_params->obuf = ut_params->op->sym->m_dst;
3776 
3777 	if (ut_params->obuf)
3778 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3779 				plaintext_len, buffer);
3780 	else
3781 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3782 				tdata->validCipherOffsetInBits.len >> 3,
3783 				plaintext_len, buffer);
3784 
3785 	/* Validate obuf */
3786 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3787 
3788 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3789 				(tdata->validCipherOffsetInBits.len >> 3);
3790 	/* Validate obuf */
3791 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3792 		ciphertext,
3793 		reference_ciphertext,
3794 		tdata->validCipherLenInBits.len,
3795 		"KASUMI Ciphertext data not as expected");
3796 	return 0;
3797 }
3798 
3799 static int
3800 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3801 {
3802 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3803 	struct crypto_unittest_params *ut_params = &unittest_params;
3804 
3805 	int retval;
3806 	uint8_t *plaintext, *ciphertext;
3807 	unsigned plaintext_pad_len;
3808 	unsigned plaintext_len;
3809 
3810 	/* Verify the capabilities */
3811 	struct rte_cryptodev_sym_capability_idx cap_idx;
3812 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3813 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3814 	/* Data-path service does not support OOP */
3815 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3816 			&cap_idx) == NULL)
3817 		return TEST_SKIPPED;
3818 
3819 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3820 		return TEST_SKIPPED;
3821 
3822 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3823 		return TEST_SKIPPED;
3824 
3825 	/* Create KASUMI session */
3826 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3827 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3828 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3829 					tdata->key.data, tdata->key.len,
3830 					tdata->cipher_iv.len);
3831 	if (retval < 0)
3832 		return retval;
3833 
3834 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3835 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3836 
3837 	/* Clear mbuf payload */
3838 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3839 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3840 
3841 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3842 	/* Append data which is padded to a multiple */
3843 	/* of the algorithms block size */
3844 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3845 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3846 				plaintext_pad_len);
3847 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3848 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3849 
3850 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3851 
3852 	/* Create KASUMI operation */
3853 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3854 				tdata->cipher_iv.len,
3855 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3856 				tdata->validCipherOffsetInBits.len);
3857 	if (retval < 0)
3858 		return retval;
3859 
3860 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3861 						ut_params->op);
3862 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3863 
3864 	ut_params->obuf = ut_params->op->sym->m_dst;
3865 	if (ut_params->obuf)
3866 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3867 	else
3868 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3869 
3870 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3871 
3872 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3873 				(tdata->validCipherOffsetInBits.len >> 3);
3874 	/* Validate obuf */
3875 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3876 		ciphertext,
3877 		reference_ciphertext,
3878 		tdata->validCipherLenInBits.len,
3879 		"KASUMI Ciphertext data not as expected");
3880 	return 0;
3881 }
3882 
3883 static int
3884 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3885 {
3886 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3887 	struct crypto_unittest_params *ut_params = &unittest_params;
3888 
3889 	int retval;
3890 	unsigned int plaintext_pad_len;
3891 	unsigned int plaintext_len;
3892 
3893 	const uint8_t *ciphertext;
3894 	uint8_t buffer[2048];
3895 
3896 	struct rte_cryptodev_info dev_info;
3897 
3898 	/* Verify the capabilities */
3899 	struct rte_cryptodev_sym_capability_idx cap_idx;
3900 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3901 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3902 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3903 			&cap_idx) == NULL)
3904 		return TEST_SKIPPED;
3905 
3906 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3907 		return TEST_SKIPPED;
3908 
3909 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3910 		return TEST_SKIPPED;
3911 
3912 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3913 
3914 	uint64_t feat_flags = dev_info.feature_flags;
3915 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3916 		printf("Device doesn't support out-of-place scatter-gather "
3917 				"in both input and output mbufs. "
3918 				"Test Skipped.\n");
3919 		return TEST_SKIPPED;
3920 	}
3921 
3922 	/* Create KASUMI session */
3923 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3924 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3925 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3926 					tdata->key.data, tdata->key.len,
3927 					tdata->cipher_iv.len);
3928 	if (retval < 0)
3929 		return retval;
3930 
3931 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3932 	/* Append data which is padded to a multiple */
3933 	/* of the algorithms block size */
3934 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3935 
3936 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3937 			plaintext_pad_len, 10, 0);
3938 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3939 			plaintext_pad_len, 3, 0);
3940 
3941 	/* Append data which is padded to a multiple */
3942 	/* of the algorithms block size */
3943 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3944 
3945 	/* Create KASUMI operation */
3946 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3947 				tdata->cipher_iv.len,
3948 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3949 				tdata->validCipherOffsetInBits.len);
3950 	if (retval < 0)
3951 		return retval;
3952 
3953 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3954 						ut_params->op);
3955 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3956 
3957 	ut_params->obuf = ut_params->op->sym->m_dst;
3958 	if (ut_params->obuf)
3959 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3960 				plaintext_pad_len, buffer);
3961 	else
3962 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3963 				tdata->validCipherOffsetInBits.len >> 3,
3964 				plaintext_pad_len, buffer);
3965 
3966 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3967 				(tdata->validCipherOffsetInBits.len >> 3);
3968 	/* Validate obuf */
3969 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3970 		ciphertext,
3971 		reference_ciphertext,
3972 		tdata->validCipherLenInBits.len,
3973 		"KASUMI Ciphertext data not as expected");
3974 	return 0;
3975 }
3976 
3977 
3978 static int
3979 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3980 {
3981 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3982 	struct crypto_unittest_params *ut_params = &unittest_params;
3983 
3984 	int retval;
3985 	uint8_t *ciphertext, *plaintext;
3986 	unsigned ciphertext_pad_len;
3987 	unsigned ciphertext_len;
3988 
3989 	/* Verify the capabilities */
3990 	struct rte_cryptodev_sym_capability_idx cap_idx;
3991 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3992 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3993 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3994 			&cap_idx) == NULL)
3995 		return TEST_SKIPPED;
3996 
3997 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3998 		return TEST_SKIPPED;
3999 
4000 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4001 		return TEST_SKIPPED;
4002 
4003 	/* Create KASUMI session */
4004 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4005 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4006 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4007 					tdata->key.data, tdata->key.len,
4008 					tdata->cipher_iv.len);
4009 	if (retval < 0)
4010 		return retval;
4011 
4012 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4013 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4014 
4015 	/* Clear mbuf payload */
4016 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4017 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4018 
4019 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4020 	/* Append data which is padded to a multiple */
4021 	/* of the algorithms block size */
4022 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4023 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4024 				ciphertext_pad_len);
4025 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4026 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4027 
4028 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4029 
4030 	/* Create KASUMI operation */
4031 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4032 				tdata->cipher_iv.len,
4033 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4034 				tdata->validCipherOffsetInBits.len);
4035 	if (retval < 0)
4036 		return retval;
4037 
4038 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4039 						ut_params->op);
4040 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4041 
4042 	ut_params->obuf = ut_params->op->sym->m_dst;
4043 	if (ut_params->obuf)
4044 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4045 	else
4046 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4047 
4048 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4049 
4050 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4051 				(tdata->validCipherOffsetInBits.len >> 3);
4052 	/* Validate obuf */
4053 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4054 		plaintext,
4055 		reference_plaintext,
4056 		tdata->validCipherLenInBits.len,
4057 		"KASUMI Plaintext data not as expected");
4058 	return 0;
4059 }
4060 
4061 static int
4062 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4063 {
4064 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4065 	struct crypto_unittest_params *ut_params = &unittest_params;
4066 
4067 	int retval;
4068 	uint8_t *ciphertext, *plaintext;
4069 	unsigned ciphertext_pad_len;
4070 	unsigned ciphertext_len;
4071 	struct rte_cryptodev_info dev_info;
4072 
4073 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4074 	uint64_t feat_flags = dev_info.feature_flags;
4075 
4076 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4077 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4078 		printf("Device doesn't support RAW data-path APIs.\n");
4079 		return TEST_SKIPPED;
4080 	}
4081 
4082 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4083 		return TEST_SKIPPED;
4084 
4085 	/* Verify the capabilities */
4086 	struct rte_cryptodev_sym_capability_idx cap_idx;
4087 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4088 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4089 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4090 			&cap_idx) == NULL)
4091 		return TEST_SKIPPED;
4092 
4093 	/* Create KASUMI session */
4094 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4095 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4096 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4097 					tdata->key.data, tdata->key.len,
4098 					tdata->cipher_iv.len);
4099 	if (retval < 0)
4100 		return retval;
4101 
4102 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4103 
4104 	/* Clear mbuf payload */
4105 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4106 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4107 
4108 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4109 	/* Append data which is padded to a multiple */
4110 	/* of the algorithms block size */
4111 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4112 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4113 				ciphertext_pad_len);
4114 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4115 
4116 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4117 
4118 	/* Create KASUMI operation */
4119 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4120 			tdata->cipher_iv.len,
4121 			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4122 			tdata->validCipherOffsetInBits.len);
4123 	if (retval < 0)
4124 		return retval;
4125 
4126 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4127 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4128 				ut_params->op, 1, 0, 1, 0);
4129 	else
4130 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4131 						ut_params->op);
4132 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4133 
4134 	ut_params->obuf = ut_params->op->sym->m_dst;
4135 	if (ut_params->obuf)
4136 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4137 	else
4138 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4139 
4140 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4141 
4142 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4143 				(tdata->validCipherOffsetInBits.len >> 3);
4144 	/* Validate obuf */
4145 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4146 		plaintext,
4147 		reference_plaintext,
4148 		tdata->validCipherLenInBits.len,
4149 		"KASUMI Plaintext data not as expected");
4150 	return 0;
4151 }
4152 
4153 static int
4154 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4155 {
4156 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4157 	struct crypto_unittest_params *ut_params = &unittest_params;
4158 
4159 	int retval;
4160 	uint8_t *plaintext, *ciphertext;
4161 	unsigned plaintext_pad_len;
4162 	unsigned plaintext_len;
4163 	struct rte_cryptodev_info dev_info;
4164 
4165 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4166 	uint64_t feat_flags = dev_info.feature_flags;
4167 
4168 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4169 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4170 		printf("Device doesn't support RAW data-path APIs.\n");
4171 		return TEST_SKIPPED;
4172 	}
4173 
4174 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4175 		return TEST_SKIPPED;
4176 
4177 	/* Verify the capabilities */
4178 	struct rte_cryptodev_sym_capability_idx cap_idx;
4179 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4180 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4181 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4182 			&cap_idx) == NULL)
4183 		return TEST_SKIPPED;
4184 
4185 	/* Create SNOW 3G session */
4186 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4187 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4188 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4189 					tdata->key.data, tdata->key.len,
4190 					tdata->cipher_iv.len);
4191 	if (retval < 0)
4192 		return retval;
4193 
4194 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4195 
4196 	/* Clear mbuf payload */
4197 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4198 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4199 
4200 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4201 	/* Append data which is padded to a multiple of */
4202 	/* the algorithms block size */
4203 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4204 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4205 				plaintext_pad_len);
4206 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4207 
4208 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4209 
4210 	/* Create SNOW 3G operation */
4211 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4212 					tdata->cipher_iv.len,
4213 					tdata->validCipherLenInBits.len,
4214 					0);
4215 	if (retval < 0)
4216 		return retval;
4217 
4218 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4219 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4220 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4221 	else
4222 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4223 						ut_params->op);
4224 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4225 
4226 	ut_params->obuf = ut_params->op->sym->m_dst;
4227 	if (ut_params->obuf)
4228 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4229 	else
4230 		ciphertext = plaintext;
4231 
4232 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4233 
4234 	/* Validate obuf */
4235 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4236 		ciphertext,
4237 		tdata->ciphertext.data,
4238 		tdata->validDataLenInBits.len,
4239 		"SNOW 3G Ciphertext data not as expected");
4240 	return 0;
4241 }
4242 
4243 
4244 static int
4245 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4246 {
4247 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4248 	struct crypto_unittest_params *ut_params = &unittest_params;
4249 	uint8_t *plaintext, *ciphertext;
4250 
4251 	int retval;
4252 	unsigned plaintext_pad_len;
4253 	unsigned plaintext_len;
4254 	struct rte_cryptodev_info dev_info;
4255 
4256 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4257 	uint64_t feat_flags = dev_info.feature_flags;
4258 
4259 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4260 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4261 		printf("Device does not support RAW data-path APIs.\n");
4262 		return -ENOTSUP;
4263 	}
4264 
4265 	/* Verify the capabilities */
4266 	struct rte_cryptodev_sym_capability_idx cap_idx;
4267 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4268 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4269 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4270 			&cap_idx) == NULL)
4271 		return TEST_SKIPPED;
4272 
4273 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4274 		return TEST_SKIPPED;
4275 
4276 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4277 		return TEST_SKIPPED;
4278 
4279 	/* Create SNOW 3G session */
4280 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4281 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4282 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4283 					tdata->key.data, tdata->key.len,
4284 					tdata->cipher_iv.len);
4285 	if (retval < 0)
4286 		return retval;
4287 
4288 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4289 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4290 
4291 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4292 			"Failed to allocate input buffer in mempool");
4293 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4294 			"Failed to allocate output buffer in mempool");
4295 
4296 	/* Clear mbuf payload */
4297 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4298 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4299 
4300 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4301 	/* Append data which is padded to a multiple of */
4302 	/* the algorithms block size */
4303 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4304 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4305 				plaintext_pad_len);
4306 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4307 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4308 
4309 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4310 
4311 	/* Create SNOW 3G operation */
4312 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4313 					tdata->cipher_iv.len,
4314 					tdata->validCipherLenInBits.len,
4315 					0);
4316 	if (retval < 0)
4317 		return retval;
4318 
4319 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4320 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4321 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4322 	else
4323 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4324 						ut_params->op);
4325 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4326 
4327 	ut_params->obuf = ut_params->op->sym->m_dst;
4328 	if (ut_params->obuf)
4329 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4330 	else
4331 		ciphertext = plaintext;
4332 
4333 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4334 
4335 	/* Validate obuf */
4336 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4337 		ciphertext,
4338 		tdata->ciphertext.data,
4339 		tdata->validDataLenInBits.len,
4340 		"SNOW 3G Ciphertext data not as expected");
4341 	return 0;
4342 }
4343 
4344 static int
4345 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4346 {
4347 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4348 	struct crypto_unittest_params *ut_params = &unittest_params;
4349 
4350 	int retval;
4351 	unsigned int plaintext_pad_len;
4352 	unsigned int plaintext_len;
4353 	uint8_t buffer[10000];
4354 	const uint8_t *ciphertext;
4355 
4356 	struct rte_cryptodev_info dev_info;
4357 
4358 	/* Verify the capabilities */
4359 	struct rte_cryptodev_sym_capability_idx cap_idx;
4360 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4361 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4362 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4363 			&cap_idx) == NULL)
4364 		return TEST_SKIPPED;
4365 
4366 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4367 		return TEST_SKIPPED;
4368 
4369 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4370 		return TEST_SKIPPED;
4371 
4372 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4373 
4374 	uint64_t feat_flags = dev_info.feature_flags;
4375 
4376 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4377 		printf("Device doesn't support out-of-place scatter-gather "
4378 				"in both input and output mbufs. "
4379 				"Test Skipped.\n");
4380 		return TEST_SKIPPED;
4381 	}
4382 
4383 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4384 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4385 		printf("Device does not support RAW data-path APIs.\n");
4386 		return -ENOTSUP;
4387 	}
4388 
4389 	/* Create SNOW 3G session */
4390 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4391 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4392 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4393 					tdata->key.data, tdata->key.len,
4394 					tdata->cipher_iv.len);
4395 	if (retval < 0)
4396 		return retval;
4397 
4398 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4399 	/* Append data which is padded to a multiple of */
4400 	/* the algorithms block size */
4401 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4402 
4403 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4404 			plaintext_pad_len, 10, 0);
4405 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4406 			plaintext_pad_len, 3, 0);
4407 
4408 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4409 			"Failed to allocate input buffer in mempool");
4410 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4411 			"Failed to allocate output buffer in mempool");
4412 
4413 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4414 
4415 	/* Create SNOW 3G operation */
4416 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4417 					tdata->cipher_iv.len,
4418 					tdata->validCipherLenInBits.len,
4419 					0);
4420 	if (retval < 0)
4421 		return retval;
4422 
4423 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4424 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4425 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4426 	else
4427 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4428 						ut_params->op);
4429 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4430 
4431 	ut_params->obuf = ut_params->op->sym->m_dst;
4432 	if (ut_params->obuf)
4433 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4434 				plaintext_len, buffer);
4435 	else
4436 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4437 				plaintext_len, buffer);
4438 
4439 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4440 
4441 	/* Validate obuf */
4442 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4443 		ciphertext,
4444 		tdata->ciphertext.data,
4445 		tdata->validDataLenInBits.len,
4446 		"SNOW 3G Ciphertext data not as expected");
4447 
4448 	return 0;
4449 }
4450 
4451 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4452 static void
4453 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4454 {
4455 	uint8_t curr_byte, prev_byte;
4456 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4457 	uint8_t lower_byte_mask = (1 << offset) - 1;
4458 	unsigned i;
4459 
4460 	prev_byte = buffer[0];
4461 	buffer[0] >>= offset;
4462 
4463 	for (i = 1; i < length_in_bytes; i++) {
4464 		curr_byte = buffer[i];
4465 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4466 				(curr_byte >> offset);
4467 		prev_byte = curr_byte;
4468 	}
4469 }
4470 
4471 static int
4472 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4473 {
4474 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4475 	struct crypto_unittest_params *ut_params = &unittest_params;
4476 	uint8_t *plaintext, *ciphertext;
4477 	int retval;
4478 	uint32_t plaintext_len;
4479 	uint32_t plaintext_pad_len;
4480 	uint8_t extra_offset = 4;
4481 	uint8_t *expected_ciphertext_shifted;
4482 	struct rte_cryptodev_info dev_info;
4483 
4484 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4485 	uint64_t feat_flags = dev_info.feature_flags;
4486 
4487 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4488 			((tdata->validDataLenInBits.len % 8) != 0)) {
4489 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4490 		return TEST_SKIPPED;
4491 	}
4492 
4493 	/* Verify the capabilities */
4494 	struct rte_cryptodev_sym_capability_idx cap_idx;
4495 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4496 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4497 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4498 			&cap_idx) == NULL)
4499 		return TEST_SKIPPED;
4500 
4501 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4502 		return TEST_SKIPPED;
4503 
4504 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4505 		return TEST_SKIPPED;
4506 
4507 	/* Create SNOW 3G session */
4508 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4509 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4510 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4511 					tdata->key.data, tdata->key.len,
4512 					tdata->cipher_iv.len);
4513 	if (retval < 0)
4514 		return retval;
4515 
4516 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4517 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4518 
4519 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4520 			"Failed to allocate input buffer in mempool");
4521 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4522 			"Failed to allocate output buffer in mempool");
4523 
4524 	/* Clear mbuf payload */
4525 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4526 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4527 
4528 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4529 	/*
4530 	 * Append data which is padded to a
4531 	 * multiple of the algorithms block size
4532 	 */
4533 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4534 
4535 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4536 						plaintext_pad_len);
4537 
4538 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4539 
4540 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4541 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4542 
4543 #ifdef RTE_APP_TEST_DEBUG
4544 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4545 #endif
4546 	/* Create SNOW 3G operation */
4547 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4548 					tdata->cipher_iv.len,
4549 					tdata->validCipherLenInBits.len,
4550 					extra_offset);
4551 	if (retval < 0)
4552 		return retval;
4553 
4554 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4555 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4556 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4557 	else
4558 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4559 						ut_params->op);
4560 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4561 
4562 	ut_params->obuf = ut_params->op->sym->m_dst;
4563 	if (ut_params->obuf)
4564 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4565 	else
4566 		ciphertext = plaintext;
4567 
4568 #ifdef RTE_APP_TEST_DEBUG
4569 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4570 #endif
4571 
4572 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4573 
4574 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4575 			"failed to reserve memory for ciphertext shifted\n");
4576 
4577 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4578 			ceil_byte_length(tdata->ciphertext.len));
4579 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4580 			extra_offset);
4581 	/* Validate obuf */
4582 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4583 		ciphertext,
4584 		expected_ciphertext_shifted,
4585 		tdata->validDataLenInBits.len,
4586 		extra_offset,
4587 		"SNOW 3G Ciphertext data not as expected");
4588 	return 0;
4589 }
4590 
4591 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4592 {
4593 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4594 	struct crypto_unittest_params *ut_params = &unittest_params;
4595 
4596 	int retval;
4597 
4598 	uint8_t *plaintext, *ciphertext;
4599 	unsigned ciphertext_pad_len;
4600 	unsigned ciphertext_len;
4601 	struct rte_cryptodev_info dev_info;
4602 
4603 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4604 	uint64_t feat_flags = dev_info.feature_flags;
4605 
4606 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4607 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4608 		printf("Device doesn't support RAW data-path APIs.\n");
4609 		return TEST_SKIPPED;
4610 	}
4611 
4612 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4613 		return TEST_SKIPPED;
4614 
4615 	/* Verify the capabilities */
4616 	struct rte_cryptodev_sym_capability_idx cap_idx;
4617 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4618 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4619 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4620 			&cap_idx) == NULL)
4621 		return TEST_SKIPPED;
4622 
4623 	/* Create SNOW 3G session */
4624 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4625 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4626 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4627 					tdata->key.data, tdata->key.len,
4628 					tdata->cipher_iv.len);
4629 	if (retval < 0)
4630 		return retval;
4631 
4632 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4633 
4634 	/* Clear mbuf payload */
4635 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4636 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4637 
4638 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4639 	/* Append data which is padded to a multiple of */
4640 	/* the algorithms block size */
4641 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4642 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4643 				ciphertext_pad_len);
4644 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4645 
4646 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4647 
4648 	/* Create SNOW 3G operation */
4649 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4650 					tdata->cipher_iv.len,
4651 					tdata->validCipherLenInBits.len,
4652 					tdata->cipher.offset_bits);
4653 	if (retval < 0)
4654 		return retval;
4655 
4656 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4657 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4658 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4659 	else
4660 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4661 						ut_params->op);
4662 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4663 	ut_params->obuf = ut_params->op->sym->m_dst;
4664 	if (ut_params->obuf)
4665 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4666 	else
4667 		plaintext = ciphertext;
4668 
4669 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4670 
4671 	/* Validate obuf */
4672 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4673 				tdata->plaintext.data,
4674 				tdata->validDataLenInBits.len,
4675 				"SNOW 3G Plaintext data not as expected");
4676 	return 0;
4677 }
4678 
4679 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4680 {
4681 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4682 	struct crypto_unittest_params *ut_params = &unittest_params;
4683 
4684 	int retval;
4685 
4686 	uint8_t *plaintext, *ciphertext;
4687 	unsigned ciphertext_pad_len;
4688 	unsigned ciphertext_len;
4689 	struct rte_cryptodev_info dev_info;
4690 
4691 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4692 	uint64_t feat_flags = dev_info.feature_flags;
4693 
4694 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4695 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4696 		printf("Device does not support RAW data-path APIs.\n");
4697 		return -ENOTSUP;
4698 	}
4699 	/* Verify the capabilities */
4700 	struct rte_cryptodev_sym_capability_idx cap_idx;
4701 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4702 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4703 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4704 			&cap_idx) == NULL)
4705 		return TEST_SKIPPED;
4706 
4707 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4708 		return TEST_SKIPPED;
4709 
4710 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4711 		return TEST_SKIPPED;
4712 
4713 	/* Create SNOW 3G session */
4714 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4715 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4716 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4717 					tdata->key.data, tdata->key.len,
4718 					tdata->cipher_iv.len);
4719 	if (retval < 0)
4720 		return retval;
4721 
4722 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4723 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4724 
4725 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4726 			"Failed to allocate input buffer");
4727 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4728 			"Failed to allocate output buffer");
4729 
4730 	/* Clear mbuf payload */
4731 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4732 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4733 
4734 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4735 		       rte_pktmbuf_tailroom(ut_params->obuf));
4736 
4737 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4738 	/* Append data which is padded to a multiple of */
4739 	/* the algorithms block size */
4740 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4741 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4742 				ciphertext_pad_len);
4743 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4744 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4745 
4746 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4747 
4748 	/* Create SNOW 3G operation */
4749 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4750 					tdata->cipher_iv.len,
4751 					tdata->validCipherLenInBits.len,
4752 					0);
4753 	if (retval < 0)
4754 		return retval;
4755 
4756 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4757 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4758 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4759 	else
4760 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4761 						ut_params->op);
4762 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4763 	ut_params->obuf = ut_params->op->sym->m_dst;
4764 	if (ut_params->obuf)
4765 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4766 	else
4767 		plaintext = ciphertext;
4768 
4769 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4770 
4771 	/* Validate obuf */
4772 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4773 				tdata->plaintext.data,
4774 				tdata->validDataLenInBits.len,
4775 				"SNOW 3G Plaintext data not as expected");
4776 	return 0;
4777 }
4778 
4779 static int
4780 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4781 {
4782 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4783 	struct crypto_unittest_params *ut_params = &unittest_params;
4784 
4785 	int retval;
4786 
4787 	uint8_t *plaintext, *ciphertext;
4788 	unsigned int plaintext_pad_len;
4789 	unsigned int plaintext_len;
4790 
4791 	struct rte_cryptodev_info dev_info;
4792 	struct rte_cryptodev_sym_capability_idx cap_idx;
4793 
4794 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4795 	uint64_t feat_flags = dev_info.feature_flags;
4796 
4797 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4798 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4799 			(tdata->validDataLenInBits.len % 8 != 0))) {
4800 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4801 		return TEST_SKIPPED;
4802 	}
4803 
4804 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4805 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4806 		printf("Device doesn't support RAW data-path APIs.\n");
4807 		return TEST_SKIPPED;
4808 	}
4809 
4810 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4811 		return TEST_SKIPPED;
4812 
4813 	/* Check if device supports ZUC EEA3 */
4814 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4815 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4816 
4817 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4818 			&cap_idx) == NULL)
4819 		return TEST_SKIPPED;
4820 
4821 	/* Check if device supports ZUC EIA3 */
4822 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4823 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4824 
4825 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4826 			&cap_idx) == NULL)
4827 		return TEST_SKIPPED;
4828 
4829 	/* Create ZUC session */
4830 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4831 			ts_params->valid_devs[0],
4832 			tdata);
4833 	if (retval != 0)
4834 		return retval;
4835 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4836 
4837 	/* clear mbuf payload */
4838 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4839 			rte_pktmbuf_tailroom(ut_params->ibuf));
4840 
4841 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4842 	/* Append data which is padded to a multiple of */
4843 	/* the algorithms block size */
4844 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4845 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4846 				plaintext_pad_len);
4847 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4848 
4849 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4850 
4851 	/* Create ZUC operation */
4852 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4853 	if (retval < 0)
4854 		return retval;
4855 
4856 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4857 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4858 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4859 	else
4860 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4861 			ut_params->op);
4862 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4863 	ut_params->obuf = ut_params->op->sym->m_src;
4864 	if (ut_params->obuf)
4865 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4866 	else
4867 		ciphertext = plaintext;
4868 
4869 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4870 	/* Validate obuf */
4871 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4872 			ciphertext,
4873 			tdata->ciphertext.data,
4874 			tdata->validDataLenInBits.len,
4875 			"ZUC Ciphertext data not as expected");
4876 
4877 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4878 	    + plaintext_pad_len;
4879 
4880 	/* Validate obuf */
4881 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4882 			ut_params->digest,
4883 			tdata->digest.data,
4884 			4,
4885 			"ZUC Generated auth tag not as expected");
4886 	return 0;
4887 }
4888 
4889 static int
4890 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4891 {
4892 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4893 	struct crypto_unittest_params *ut_params = &unittest_params;
4894 
4895 	int retval;
4896 
4897 	uint8_t *plaintext, *ciphertext;
4898 	unsigned plaintext_pad_len;
4899 	unsigned plaintext_len;
4900 	struct rte_cryptodev_info dev_info;
4901 
4902 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4903 	uint64_t feat_flags = dev_info.feature_flags;
4904 
4905 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4906 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4907 		printf("Device doesn't support RAW data-path APIs.\n");
4908 		return TEST_SKIPPED;
4909 	}
4910 
4911 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4912 		return TEST_SKIPPED;
4913 
4914 	/* Verify the capabilities */
4915 	struct rte_cryptodev_sym_capability_idx cap_idx;
4916 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4917 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4918 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4919 			&cap_idx) == NULL)
4920 		return TEST_SKIPPED;
4921 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4922 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4923 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4924 			&cap_idx) == NULL)
4925 		return TEST_SKIPPED;
4926 
4927 	/* Create SNOW 3G session */
4928 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4929 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4930 			RTE_CRYPTO_AUTH_OP_GENERATE,
4931 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4932 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4933 			tdata->key.data, tdata->key.len,
4934 			tdata->auth_iv.len, tdata->digest.len,
4935 			tdata->cipher_iv.len);
4936 	if (retval != 0)
4937 		return retval;
4938 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4939 
4940 	/* clear mbuf payload */
4941 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4942 			rte_pktmbuf_tailroom(ut_params->ibuf));
4943 
4944 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4945 	/* Append data which is padded to a multiple of */
4946 	/* the algorithms block size */
4947 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4948 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4949 				plaintext_pad_len);
4950 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4951 
4952 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4953 
4954 	/* Create SNOW 3G operation */
4955 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4956 			tdata->digest.len, tdata->auth_iv.data,
4957 			tdata->auth_iv.len,
4958 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4959 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4960 			tdata->validCipherLenInBits.len,
4961 			0,
4962 			tdata->validAuthLenInBits.len,
4963 			0
4964 			);
4965 	if (retval < 0)
4966 		return retval;
4967 
4968 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4969 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4970 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4971 	else
4972 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4973 			ut_params->op);
4974 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4975 	ut_params->obuf = ut_params->op->sym->m_src;
4976 	if (ut_params->obuf)
4977 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4978 	else
4979 		ciphertext = plaintext;
4980 
4981 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4982 	/* Validate obuf */
4983 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4984 			ciphertext,
4985 			tdata->ciphertext.data,
4986 			tdata->validDataLenInBits.len,
4987 			"SNOW 3G Ciphertext data not as expected");
4988 
4989 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4990 	    + plaintext_pad_len;
4991 
4992 	/* Validate obuf */
4993 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4994 			ut_params->digest,
4995 			tdata->digest.data,
4996 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4997 			"SNOW 3G Generated auth tag not as expected");
4998 	return 0;
4999 }
5000 
5001 static int
5002 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
5003 	uint8_t op_mode, uint8_t verify)
5004 {
5005 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5006 	struct crypto_unittest_params *ut_params = &unittest_params;
5007 
5008 	int retval;
5009 
5010 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5011 	unsigned int plaintext_pad_len;
5012 	unsigned int plaintext_len;
5013 	unsigned int ciphertext_pad_len;
5014 	unsigned int ciphertext_len;
5015 
5016 	struct rte_cryptodev_info dev_info;
5017 
5018 	/* Verify the capabilities */
5019 	struct rte_cryptodev_sym_capability_idx cap_idx;
5020 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5021 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5022 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5023 			&cap_idx) == NULL)
5024 		return TEST_SKIPPED;
5025 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5026 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5027 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5028 			&cap_idx) == NULL)
5029 		return TEST_SKIPPED;
5030 
5031 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5032 		return TEST_SKIPPED;
5033 
5034 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5035 
5036 	uint64_t feat_flags = dev_info.feature_flags;
5037 
5038 	if (op_mode == OUT_OF_PLACE) {
5039 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5040 			printf("Device doesn't support digest encrypted.\n");
5041 			return TEST_SKIPPED;
5042 		}
5043 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5044 			return TEST_SKIPPED;
5045 	}
5046 
5047 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5048 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5049 		printf("Device doesn't support RAW data-path APIs.\n");
5050 		return TEST_SKIPPED;
5051 	}
5052 
5053 	/* Create SNOW 3G session */
5054 	retval = create_wireless_algo_auth_cipher_session(
5055 			ts_params->valid_devs[0],
5056 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5057 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5058 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5059 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5060 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5061 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5062 			tdata->key.data, tdata->key.len,
5063 			tdata->auth_iv.len, tdata->digest.len,
5064 			tdata->cipher_iv.len);
5065 	if (retval != 0)
5066 		return retval;
5067 
5068 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5069 	if (op_mode == OUT_OF_PLACE)
5070 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5071 
5072 	/* clear mbuf payload */
5073 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5074 		rte_pktmbuf_tailroom(ut_params->ibuf));
5075 	if (op_mode == OUT_OF_PLACE)
5076 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5077 			rte_pktmbuf_tailroom(ut_params->obuf));
5078 
5079 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5080 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5081 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5082 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5083 
5084 	if (verify) {
5085 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5086 					ciphertext_pad_len);
5087 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5088 		if (op_mode == OUT_OF_PLACE)
5089 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5090 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5091 			ciphertext_len);
5092 	} else {
5093 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5094 					plaintext_pad_len);
5095 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5096 		if (op_mode == OUT_OF_PLACE)
5097 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5098 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5099 	}
5100 
5101 	/* Create SNOW 3G operation */
5102 	retval = create_wireless_algo_auth_cipher_operation(
5103 		tdata->digest.data, tdata->digest.len,
5104 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5105 		tdata->auth_iv.data, tdata->auth_iv.len,
5106 		(tdata->digest.offset_bytes == 0 ?
5107 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5108 			: tdata->digest.offset_bytes),
5109 		tdata->validCipherLenInBits.len,
5110 		tdata->cipher.offset_bits,
5111 		tdata->validAuthLenInBits.len,
5112 		tdata->auth.offset_bits,
5113 		op_mode, 0, verify);
5114 
5115 	if (retval < 0)
5116 		return retval;
5117 
5118 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5119 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5120 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5121 	else
5122 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5123 			ut_params->op);
5124 
5125 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5126 
5127 	ut_params->obuf = (op_mode == IN_PLACE ?
5128 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5129 
5130 	if (verify) {
5131 		if (ut_params->obuf)
5132 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5133 							uint8_t *);
5134 		else
5135 			plaintext = ciphertext +
5136 				(tdata->cipher.offset_bits >> 3);
5137 
5138 		debug_hexdump(stdout, "plaintext:", plaintext,
5139 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5140 		debug_hexdump(stdout, "plaintext expected:",
5141 			tdata->plaintext.data,
5142 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5143 	} else {
5144 		if (ut_params->obuf)
5145 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5146 							uint8_t *);
5147 		else
5148 			ciphertext = plaintext;
5149 
5150 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5151 			ciphertext_len);
5152 		debug_hexdump(stdout, "ciphertext expected:",
5153 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5154 
5155 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5156 			+ (tdata->digest.offset_bytes == 0 ?
5157 		plaintext_pad_len : tdata->digest.offset_bytes);
5158 
5159 		debug_hexdump(stdout, "digest:", ut_params->digest,
5160 			tdata->digest.len);
5161 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5162 				tdata->digest.len);
5163 	}
5164 
5165 	/* Validate obuf */
5166 	if (verify) {
5167 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5168 			plaintext,
5169 			tdata->plaintext.data,
5170 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5171 			 (tdata->digest.len << 3)),
5172 			tdata->cipher.offset_bits,
5173 			"SNOW 3G Plaintext data not as expected");
5174 	} else {
5175 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5176 			ciphertext,
5177 			tdata->ciphertext.data,
5178 			(tdata->validDataLenInBits.len -
5179 			 tdata->cipher.offset_bits),
5180 			tdata->cipher.offset_bits,
5181 			"SNOW 3G Ciphertext data not as expected");
5182 
5183 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5184 			ut_params->digest,
5185 			tdata->digest.data,
5186 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5187 			"SNOW 3G Generated auth tag not as expected");
5188 	}
5189 	return 0;
5190 }
5191 
5192 static int
5193 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5194 	uint8_t op_mode, uint8_t verify)
5195 {
5196 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5197 	struct crypto_unittest_params *ut_params = &unittest_params;
5198 
5199 	int retval;
5200 
5201 	const uint8_t *plaintext = NULL;
5202 	const uint8_t *ciphertext = NULL;
5203 	const uint8_t *digest = NULL;
5204 	unsigned int plaintext_pad_len;
5205 	unsigned int plaintext_len;
5206 	unsigned int ciphertext_pad_len;
5207 	unsigned int ciphertext_len;
5208 	uint8_t buffer[10000];
5209 	uint8_t digest_buffer[10000];
5210 
5211 	struct rte_cryptodev_info dev_info;
5212 
5213 	/* Verify the capabilities */
5214 	struct rte_cryptodev_sym_capability_idx cap_idx;
5215 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5216 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5217 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5218 			&cap_idx) == NULL)
5219 		return TEST_SKIPPED;
5220 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5221 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5222 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5223 			&cap_idx) == NULL)
5224 		return TEST_SKIPPED;
5225 
5226 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5227 		return TEST_SKIPPED;
5228 
5229 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5230 
5231 	uint64_t feat_flags = dev_info.feature_flags;
5232 
5233 	if (op_mode == IN_PLACE) {
5234 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5235 			printf("Device doesn't support in-place scatter-gather "
5236 					"in both input and output mbufs.\n");
5237 			return TEST_SKIPPED;
5238 		}
5239 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5240 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5241 			printf("Device doesn't support RAW data-path APIs.\n");
5242 			return TEST_SKIPPED;
5243 		}
5244 	} else {
5245 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5246 			return TEST_SKIPPED;
5247 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5248 			printf("Device doesn't support out-of-place scatter-gather "
5249 					"in both input and output mbufs.\n");
5250 			return TEST_SKIPPED;
5251 		}
5252 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5253 			printf("Device doesn't support digest encrypted.\n");
5254 			return TEST_SKIPPED;
5255 		}
5256 	}
5257 
5258 	/* Create SNOW 3G session */
5259 	retval = create_wireless_algo_auth_cipher_session(
5260 			ts_params->valid_devs[0],
5261 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5262 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5263 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5264 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5265 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5266 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5267 			tdata->key.data, tdata->key.len,
5268 			tdata->auth_iv.len, tdata->digest.len,
5269 			tdata->cipher_iv.len);
5270 
5271 	if (retval != 0)
5272 		return retval;
5273 
5274 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5275 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5276 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5277 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5278 
5279 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5280 			plaintext_pad_len, 15, 0);
5281 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5282 			"Failed to allocate input buffer in mempool");
5283 
5284 	if (op_mode == OUT_OF_PLACE) {
5285 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5286 				plaintext_pad_len, 15, 0);
5287 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5288 				"Failed to allocate output buffer in mempool");
5289 	}
5290 
5291 	if (verify) {
5292 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5293 			tdata->ciphertext.data);
5294 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5295 					ciphertext_len, buffer);
5296 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5297 			ciphertext_len);
5298 	} else {
5299 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5300 			tdata->plaintext.data);
5301 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5302 					plaintext_len, buffer);
5303 		debug_hexdump(stdout, "plaintext:", plaintext,
5304 			plaintext_len);
5305 	}
5306 	memset(buffer, 0, sizeof(buffer));
5307 
5308 	/* Create SNOW 3G operation */
5309 	retval = create_wireless_algo_auth_cipher_operation(
5310 		tdata->digest.data, tdata->digest.len,
5311 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5312 		tdata->auth_iv.data, tdata->auth_iv.len,
5313 		(tdata->digest.offset_bytes == 0 ?
5314 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5315 			: tdata->digest.offset_bytes),
5316 		tdata->validCipherLenInBits.len,
5317 		tdata->cipher.offset_bits,
5318 		tdata->validAuthLenInBits.len,
5319 		tdata->auth.offset_bits,
5320 		op_mode, 1, verify);
5321 
5322 	if (retval < 0)
5323 		return retval;
5324 
5325 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5326 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5327 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5328 	else
5329 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5330 			ut_params->op);
5331 
5332 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5333 
5334 	ut_params->obuf = (op_mode == IN_PLACE ?
5335 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5336 
5337 	if (verify) {
5338 		if (ut_params->obuf)
5339 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5340 					plaintext_len, buffer);
5341 		else
5342 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5343 					plaintext_len, buffer);
5344 
5345 		debug_hexdump(stdout, "plaintext:", plaintext,
5346 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5347 		debug_hexdump(stdout, "plaintext expected:",
5348 			tdata->plaintext.data,
5349 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5350 	} else {
5351 		if (ut_params->obuf)
5352 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5353 					ciphertext_len, buffer);
5354 		else
5355 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5356 					ciphertext_len, buffer);
5357 
5358 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5359 			ciphertext_len);
5360 		debug_hexdump(stdout, "ciphertext expected:",
5361 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5362 
5363 		if (ut_params->obuf)
5364 			digest = rte_pktmbuf_read(ut_params->obuf,
5365 				(tdata->digest.offset_bytes == 0 ?
5366 				plaintext_pad_len : tdata->digest.offset_bytes),
5367 				tdata->digest.len, digest_buffer);
5368 		else
5369 			digest = rte_pktmbuf_read(ut_params->ibuf,
5370 				(tdata->digest.offset_bytes == 0 ?
5371 				plaintext_pad_len : tdata->digest.offset_bytes),
5372 				tdata->digest.len, digest_buffer);
5373 
5374 		debug_hexdump(stdout, "digest:", digest,
5375 			tdata->digest.len);
5376 		debug_hexdump(stdout, "digest expected:",
5377 			tdata->digest.data, tdata->digest.len);
5378 	}
5379 
5380 	/* Validate obuf */
5381 	if (verify) {
5382 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5383 			plaintext,
5384 			tdata->plaintext.data,
5385 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5386 			 (tdata->digest.len << 3)),
5387 			tdata->cipher.offset_bits,
5388 			"SNOW 3G Plaintext data not as expected");
5389 	} else {
5390 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5391 			ciphertext,
5392 			tdata->ciphertext.data,
5393 			(tdata->validDataLenInBits.len -
5394 			 tdata->cipher.offset_bits),
5395 			tdata->cipher.offset_bits,
5396 			"SNOW 3G Ciphertext data not as expected");
5397 
5398 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5399 			digest,
5400 			tdata->digest.data,
5401 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5402 			"SNOW 3G Generated auth tag not as expected");
5403 	}
5404 	return 0;
5405 }
5406 
5407 static int
5408 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5409 	uint8_t op_mode, uint8_t verify)
5410 {
5411 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5412 	struct crypto_unittest_params *ut_params = &unittest_params;
5413 
5414 	int retval;
5415 
5416 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5417 	unsigned int plaintext_pad_len;
5418 	unsigned int plaintext_len;
5419 	unsigned int ciphertext_pad_len;
5420 	unsigned int ciphertext_len;
5421 
5422 	struct rte_cryptodev_info dev_info;
5423 
5424 	/* Verify the capabilities */
5425 	struct rte_cryptodev_sym_capability_idx cap_idx;
5426 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5427 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5428 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5429 			&cap_idx) == NULL)
5430 		return TEST_SKIPPED;
5431 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5432 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5433 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5434 			&cap_idx) == NULL)
5435 		return TEST_SKIPPED;
5436 
5437 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5438 
5439 	uint64_t feat_flags = dev_info.feature_flags;
5440 
5441 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5442 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5443 		printf("Device doesn't support RAW data-path APIs.\n");
5444 		return TEST_SKIPPED;
5445 	}
5446 
5447 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5448 		return TEST_SKIPPED;
5449 
5450 	if (op_mode == OUT_OF_PLACE) {
5451 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5452 			return TEST_SKIPPED;
5453 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5454 			printf("Device doesn't support digest encrypted.\n");
5455 			return TEST_SKIPPED;
5456 		}
5457 	}
5458 
5459 	/* Create KASUMI session */
5460 	retval = create_wireless_algo_auth_cipher_session(
5461 			ts_params->valid_devs[0],
5462 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5463 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5464 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5465 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5466 			RTE_CRYPTO_AUTH_KASUMI_F9,
5467 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5468 			tdata->key.data, tdata->key.len,
5469 			0, tdata->digest.len,
5470 			tdata->cipher_iv.len);
5471 
5472 	if (retval != 0)
5473 		return retval;
5474 
5475 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5476 	if (op_mode == OUT_OF_PLACE)
5477 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5478 
5479 	/* clear mbuf payload */
5480 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5481 		rte_pktmbuf_tailroom(ut_params->ibuf));
5482 	if (op_mode == OUT_OF_PLACE)
5483 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5484 			rte_pktmbuf_tailroom(ut_params->obuf));
5485 
5486 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5487 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5488 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5489 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5490 
5491 	if (verify) {
5492 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5493 					ciphertext_pad_len);
5494 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5495 		if (op_mode == OUT_OF_PLACE)
5496 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5497 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5498 			ciphertext_len);
5499 	} else {
5500 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5501 					plaintext_pad_len);
5502 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5503 		if (op_mode == OUT_OF_PLACE)
5504 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5505 		debug_hexdump(stdout, "plaintext:", plaintext,
5506 			plaintext_len);
5507 	}
5508 
5509 	/* Create KASUMI operation */
5510 	retval = create_wireless_algo_auth_cipher_operation(
5511 		tdata->digest.data, tdata->digest.len,
5512 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5513 		NULL, 0,
5514 		(tdata->digest.offset_bytes == 0 ?
5515 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5516 			: tdata->digest.offset_bytes),
5517 		tdata->validCipherLenInBits.len,
5518 		tdata->validCipherOffsetInBits.len,
5519 		tdata->validAuthLenInBits.len,
5520 		0,
5521 		op_mode, 0, verify);
5522 
5523 	if (retval < 0)
5524 		return retval;
5525 
5526 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5527 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5528 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5529 	else
5530 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5531 			ut_params->op);
5532 
5533 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5534 
5535 	ut_params->obuf = (op_mode == IN_PLACE ?
5536 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5537 
5538 
5539 	if (verify) {
5540 		if (ut_params->obuf)
5541 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5542 							uint8_t *);
5543 		else
5544 			plaintext = ciphertext;
5545 
5546 		debug_hexdump(stdout, "plaintext:", plaintext,
5547 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5548 		debug_hexdump(stdout, "plaintext expected:",
5549 			tdata->plaintext.data,
5550 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5551 	} else {
5552 		if (ut_params->obuf)
5553 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5554 							uint8_t *);
5555 		else
5556 			ciphertext = plaintext;
5557 
5558 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5559 			ciphertext_len);
5560 		debug_hexdump(stdout, "ciphertext expected:",
5561 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5562 
5563 		ut_params->digest = rte_pktmbuf_mtod(
5564 			ut_params->obuf, uint8_t *) +
5565 			(tdata->digest.offset_bytes == 0 ?
5566 			plaintext_pad_len : tdata->digest.offset_bytes);
5567 
5568 		debug_hexdump(stdout, "digest:", ut_params->digest,
5569 			tdata->digest.len);
5570 		debug_hexdump(stdout, "digest expected:",
5571 			tdata->digest.data, tdata->digest.len);
5572 	}
5573 
5574 	/* Validate obuf */
5575 	if (verify) {
5576 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5577 			plaintext,
5578 			tdata->plaintext.data,
5579 			tdata->plaintext.len >> 3,
5580 			"KASUMI Plaintext data not as expected");
5581 	} else {
5582 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5583 			ciphertext,
5584 			tdata->ciphertext.data,
5585 			tdata->ciphertext.len >> 3,
5586 			"KASUMI Ciphertext data not as expected");
5587 
5588 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5589 			ut_params->digest,
5590 			tdata->digest.data,
5591 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5592 			"KASUMI Generated auth tag not as expected");
5593 	}
5594 	return 0;
5595 }
5596 
5597 static int
5598 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5599 	uint8_t op_mode, uint8_t verify)
5600 {
5601 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5602 	struct crypto_unittest_params *ut_params = &unittest_params;
5603 
5604 	int retval;
5605 
5606 	const uint8_t *plaintext = NULL;
5607 	const uint8_t *ciphertext = NULL;
5608 	const uint8_t *digest = NULL;
5609 	unsigned int plaintext_pad_len;
5610 	unsigned int plaintext_len;
5611 	unsigned int ciphertext_pad_len;
5612 	unsigned int ciphertext_len;
5613 	uint8_t buffer[10000];
5614 	uint8_t digest_buffer[10000];
5615 
5616 	struct rte_cryptodev_info dev_info;
5617 
5618 	/* Verify the capabilities */
5619 	struct rte_cryptodev_sym_capability_idx cap_idx;
5620 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5621 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5622 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5623 			&cap_idx) == NULL)
5624 		return TEST_SKIPPED;
5625 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5626 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5627 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5628 			&cap_idx) == NULL)
5629 		return TEST_SKIPPED;
5630 
5631 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5632 		return TEST_SKIPPED;
5633 
5634 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5635 
5636 	uint64_t feat_flags = dev_info.feature_flags;
5637 
5638 	if (op_mode == IN_PLACE) {
5639 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5640 			printf("Device doesn't support in-place scatter-gather "
5641 					"in both input and output mbufs.\n");
5642 			return TEST_SKIPPED;
5643 		}
5644 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5645 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5646 			printf("Device doesn't support RAW data-path APIs.\n");
5647 			return TEST_SKIPPED;
5648 		}
5649 	} else {
5650 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5651 			return TEST_SKIPPED;
5652 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5653 			printf("Device doesn't support out-of-place scatter-gather "
5654 					"in both input and output mbufs.\n");
5655 			return TEST_SKIPPED;
5656 		}
5657 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5658 			printf("Device doesn't support digest encrypted.\n");
5659 			return TEST_SKIPPED;
5660 		}
5661 	}
5662 
5663 	/* Create KASUMI session */
5664 	retval = create_wireless_algo_auth_cipher_session(
5665 			ts_params->valid_devs[0],
5666 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5667 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5668 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5669 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5670 			RTE_CRYPTO_AUTH_KASUMI_F9,
5671 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5672 			tdata->key.data, tdata->key.len,
5673 			0, tdata->digest.len,
5674 			tdata->cipher_iv.len);
5675 
5676 	if (retval != 0)
5677 		return retval;
5678 
5679 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5680 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5681 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5682 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5683 
5684 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5685 			plaintext_pad_len, 15, 0);
5686 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5687 			"Failed to allocate input buffer in mempool");
5688 
5689 	if (op_mode == OUT_OF_PLACE) {
5690 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5691 				plaintext_pad_len, 15, 0);
5692 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5693 				"Failed to allocate output buffer in mempool");
5694 	}
5695 
5696 	if (verify) {
5697 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5698 			tdata->ciphertext.data);
5699 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5700 					ciphertext_len, buffer);
5701 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5702 			ciphertext_len);
5703 	} else {
5704 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5705 			tdata->plaintext.data);
5706 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5707 					plaintext_len, buffer);
5708 		debug_hexdump(stdout, "plaintext:", plaintext,
5709 			plaintext_len);
5710 	}
5711 	memset(buffer, 0, sizeof(buffer));
5712 
5713 	/* Create KASUMI operation */
5714 	retval = create_wireless_algo_auth_cipher_operation(
5715 		tdata->digest.data, tdata->digest.len,
5716 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5717 		NULL, 0,
5718 		(tdata->digest.offset_bytes == 0 ?
5719 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5720 			: tdata->digest.offset_bytes),
5721 		tdata->validCipherLenInBits.len,
5722 		tdata->validCipherOffsetInBits.len,
5723 		tdata->validAuthLenInBits.len,
5724 		0,
5725 		op_mode, 1, verify);
5726 
5727 	if (retval < 0)
5728 		return retval;
5729 
5730 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5731 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5732 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5733 	else
5734 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5735 			ut_params->op);
5736 
5737 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5738 
5739 	ut_params->obuf = (op_mode == IN_PLACE ?
5740 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5741 
5742 	if (verify) {
5743 		if (ut_params->obuf)
5744 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5745 					plaintext_len, buffer);
5746 		else
5747 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5748 					plaintext_len, buffer);
5749 
5750 		debug_hexdump(stdout, "plaintext:", plaintext,
5751 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5752 		debug_hexdump(stdout, "plaintext expected:",
5753 			tdata->plaintext.data,
5754 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5755 	} else {
5756 		if (ut_params->obuf)
5757 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5758 					ciphertext_len, buffer);
5759 		else
5760 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5761 					ciphertext_len, buffer);
5762 
5763 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5764 			ciphertext_len);
5765 		debug_hexdump(stdout, "ciphertext expected:",
5766 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5767 
5768 		if (ut_params->obuf)
5769 			digest = rte_pktmbuf_read(ut_params->obuf,
5770 				(tdata->digest.offset_bytes == 0 ?
5771 				plaintext_pad_len : tdata->digest.offset_bytes),
5772 				tdata->digest.len, digest_buffer);
5773 		else
5774 			digest = rte_pktmbuf_read(ut_params->ibuf,
5775 				(tdata->digest.offset_bytes == 0 ?
5776 				plaintext_pad_len : tdata->digest.offset_bytes),
5777 				tdata->digest.len, digest_buffer);
5778 
5779 		debug_hexdump(stdout, "digest:", digest,
5780 			tdata->digest.len);
5781 		debug_hexdump(stdout, "digest expected:",
5782 			tdata->digest.data, tdata->digest.len);
5783 	}
5784 
5785 	/* Validate obuf */
5786 	if (verify) {
5787 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5788 			plaintext,
5789 			tdata->plaintext.data,
5790 			tdata->plaintext.len >> 3,
5791 			"KASUMI Plaintext data not as expected");
5792 	} else {
5793 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5794 			ciphertext,
5795 			tdata->ciphertext.data,
5796 			tdata->validDataLenInBits.len,
5797 			"KASUMI Ciphertext data not as expected");
5798 
5799 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5800 			digest,
5801 			tdata->digest.data,
5802 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5803 			"KASUMI Generated auth tag not as expected");
5804 	}
5805 	return 0;
5806 }
5807 
5808 static int
5809 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5810 {
5811 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5812 	struct crypto_unittest_params *ut_params = &unittest_params;
5813 
5814 	int retval;
5815 
5816 	uint8_t *plaintext, *ciphertext;
5817 	unsigned plaintext_pad_len;
5818 	unsigned plaintext_len;
5819 	struct rte_cryptodev_info dev_info;
5820 
5821 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5822 	uint64_t feat_flags = dev_info.feature_flags;
5823 
5824 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5825 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5826 		printf("Device doesn't support RAW data-path APIs.\n");
5827 		return TEST_SKIPPED;
5828 	}
5829 
5830 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5831 		return TEST_SKIPPED;
5832 
5833 	/* Verify the capabilities */
5834 	struct rte_cryptodev_sym_capability_idx cap_idx;
5835 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5836 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5837 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5838 			&cap_idx) == NULL)
5839 		return TEST_SKIPPED;
5840 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5841 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5842 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5843 			&cap_idx) == NULL)
5844 		return TEST_SKIPPED;
5845 
5846 	/* Create KASUMI session */
5847 	retval = create_wireless_algo_cipher_auth_session(
5848 			ts_params->valid_devs[0],
5849 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5850 			RTE_CRYPTO_AUTH_OP_GENERATE,
5851 			RTE_CRYPTO_AUTH_KASUMI_F9,
5852 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5853 			tdata->key.data, tdata->key.len,
5854 			0, tdata->digest.len,
5855 			tdata->cipher_iv.len);
5856 	if (retval != 0)
5857 		return retval;
5858 
5859 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5860 
5861 	/* clear mbuf payload */
5862 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5863 			rte_pktmbuf_tailroom(ut_params->ibuf));
5864 
5865 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5866 	/* Append data which is padded to a multiple of */
5867 	/* the algorithms block size */
5868 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5869 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5870 				plaintext_pad_len);
5871 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5872 
5873 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5874 
5875 	/* Create KASUMI operation */
5876 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5877 				tdata->digest.len, NULL, 0,
5878 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5879 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5880 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5881 				tdata->validCipherOffsetInBits.len,
5882 				tdata->validAuthLenInBits.len,
5883 				0
5884 				);
5885 	if (retval < 0)
5886 		return retval;
5887 
5888 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5889 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5890 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5891 	else
5892 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5893 			ut_params->op);
5894 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5895 
5896 	if (ut_params->op->sym->m_dst)
5897 		ut_params->obuf = ut_params->op->sym->m_dst;
5898 	else
5899 		ut_params->obuf = ut_params->op->sym->m_src;
5900 
5901 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5902 				tdata->validCipherOffsetInBits.len >> 3);
5903 
5904 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5905 			+ plaintext_pad_len;
5906 
5907 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5908 				(tdata->validCipherOffsetInBits.len >> 3);
5909 	/* Validate obuf */
5910 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5911 		ciphertext,
5912 		reference_ciphertext,
5913 		tdata->validCipherLenInBits.len,
5914 		"KASUMI Ciphertext data not as expected");
5915 
5916 	/* Validate obuf */
5917 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5918 		ut_params->digest,
5919 		tdata->digest.data,
5920 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5921 		"KASUMI Generated auth tag not as expected");
5922 	return 0;
5923 }
5924 
5925 static int
5926 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5927 			const enum rte_crypto_cipher_algorithm cipher_algo,
5928 			const uint16_t key_size, const uint16_t iv_size)
5929 {
5930 	struct rte_cryptodev_sym_capability_idx cap_idx;
5931 	const struct rte_cryptodev_symmetric_capability *cap;
5932 
5933 	/* Check if device supports the algorithm */
5934 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5935 	cap_idx.algo.cipher = cipher_algo;
5936 
5937 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5938 			&cap_idx);
5939 
5940 	if (cap == NULL)
5941 		return -1;
5942 
5943 	/* Check if device supports key size and IV size */
5944 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5945 			iv_size) < 0) {
5946 		return -1;
5947 	}
5948 
5949 	return 0;
5950 }
5951 
5952 static int
5953 check_auth_capability(const struct crypto_testsuite_params *ts_params,
5954 			const enum rte_crypto_auth_algorithm auth_algo,
5955 			const uint16_t key_size, const uint16_t iv_size,
5956 			const uint16_t tag_size)
5957 {
5958 	struct rte_cryptodev_sym_capability_idx cap_idx;
5959 	const struct rte_cryptodev_symmetric_capability *cap;
5960 
5961 	/* Check if device supports the algorithm */
5962 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5963 	cap_idx.algo.auth = auth_algo;
5964 
5965 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5966 			&cap_idx);
5967 
5968 	if (cap == NULL)
5969 		return -1;
5970 
5971 	/* Check if device supports key size and IV size */
5972 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
5973 			tag_size, iv_size) < 0) {
5974 		return -1;
5975 	}
5976 
5977 	return 0;
5978 }
5979 
5980 static int
5981 test_zuc_encryption(const struct wireless_test_data *tdata)
5982 {
5983 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5984 	struct crypto_unittest_params *ut_params = &unittest_params;
5985 
5986 	int retval;
5987 	uint8_t *plaintext, *ciphertext;
5988 	unsigned plaintext_pad_len;
5989 	unsigned plaintext_len;
5990 	struct rte_cryptodev_info dev_info;
5991 
5992 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5993 	uint64_t feat_flags = dev_info.feature_flags;
5994 
5995 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5996 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5997 		printf("Device doesn't support RAW data-path APIs.\n");
5998 		return TEST_SKIPPED;
5999 	}
6000 
6001 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6002 		return TEST_SKIPPED;
6003 
6004 	/* Check if device supports ZUC EEA3 */
6005 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6006 			tdata->key.len, tdata->cipher_iv.len) < 0)
6007 		return TEST_SKIPPED;
6008 
6009 	/* Create ZUC session */
6010 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6011 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6012 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
6013 					tdata->key.data, tdata->key.len,
6014 					tdata->cipher_iv.len);
6015 	if (retval != 0)
6016 		return retval;
6017 
6018 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6019 
6020 	/* Clear mbuf payload */
6021 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6022 	       rte_pktmbuf_tailroom(ut_params->ibuf));
6023 
6024 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6025 	/* Append data which is padded to a multiple */
6026 	/* of the algorithms block size */
6027 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6028 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6029 				plaintext_pad_len);
6030 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6031 
6032 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6033 
6034 	/* Create ZUC operation */
6035 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6036 					tdata->cipher_iv.len,
6037 					tdata->plaintext.len,
6038 					0);
6039 	if (retval < 0)
6040 		return retval;
6041 
6042 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6043 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6044 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6045 	else
6046 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6047 						ut_params->op);
6048 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6049 
6050 	ut_params->obuf = ut_params->op->sym->m_dst;
6051 	if (ut_params->obuf)
6052 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6053 	else
6054 		ciphertext = plaintext;
6055 
6056 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6057 
6058 	/* Validate obuf */
6059 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6060 		ciphertext,
6061 		tdata->ciphertext.data,
6062 		tdata->validCipherLenInBits.len,
6063 		"ZUC Ciphertext data not as expected");
6064 	return 0;
6065 }
6066 
6067 static int
6068 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
6069 {
6070 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6071 	struct crypto_unittest_params *ut_params = &unittest_params;
6072 
6073 	int retval;
6074 
6075 	unsigned int plaintext_pad_len;
6076 	unsigned int plaintext_len;
6077 	const uint8_t *ciphertext;
6078 	uint8_t ciphertext_buffer[2048];
6079 	struct rte_cryptodev_info dev_info;
6080 
6081 	/* Check if device supports ZUC EEA3 */
6082 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6083 			tdata->key.len, tdata->cipher_iv.len) < 0)
6084 		return TEST_SKIPPED;
6085 
6086 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6087 		return TEST_SKIPPED;
6088 
6089 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6090 
6091 	uint64_t feat_flags = dev_info.feature_flags;
6092 
6093 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6094 		printf("Device doesn't support in-place scatter-gather. "
6095 				"Test Skipped.\n");
6096 		return TEST_SKIPPED;
6097 	}
6098 
6099 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6100 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6101 		printf("Device doesn't support RAW data-path APIs.\n");
6102 		return TEST_SKIPPED;
6103 	}
6104 
6105 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6106 
6107 	/* Append data which is padded to a multiple */
6108 	/* of the algorithms block size */
6109 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6110 
6111 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6112 			plaintext_pad_len, 10, 0);
6113 
6114 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6115 			tdata->plaintext.data);
6116 
6117 	/* Create ZUC session */
6118 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6119 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6120 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6121 			tdata->key.data, tdata->key.len,
6122 			tdata->cipher_iv.len);
6123 	if (retval < 0)
6124 		return retval;
6125 
6126 	/* Clear mbuf payload */
6127 
6128 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6129 
6130 	/* Create ZUC operation */
6131 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6132 			tdata->cipher_iv.len, tdata->plaintext.len,
6133 			0);
6134 	if (retval < 0)
6135 		return retval;
6136 
6137 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6138 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6139 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6140 	else
6141 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6142 						ut_params->op);
6143 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6144 
6145 	ut_params->obuf = ut_params->op->sym->m_dst;
6146 	if (ut_params->obuf)
6147 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6148 			0, plaintext_len, ciphertext_buffer);
6149 	else
6150 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6151 			0, plaintext_len, ciphertext_buffer);
6152 
6153 	/* Validate obuf */
6154 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6155 
6156 	/* Validate obuf */
6157 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6158 		ciphertext,
6159 		tdata->ciphertext.data,
6160 		tdata->validCipherLenInBits.len,
6161 		"ZUC Ciphertext data not as expected");
6162 
6163 	return 0;
6164 }
6165 
6166 static int
6167 test_zuc_authentication(const struct wireless_test_data *tdata)
6168 {
6169 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6170 	struct crypto_unittest_params *ut_params = &unittest_params;
6171 
6172 	int retval;
6173 	unsigned plaintext_pad_len;
6174 	unsigned plaintext_len;
6175 	uint8_t *plaintext;
6176 
6177 	struct rte_cryptodev_info dev_info;
6178 
6179 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6180 	uint64_t feat_flags = dev_info.feature_flags;
6181 
6182 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6183 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6184 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6185 		return TEST_SKIPPED;
6186 	}
6187 
6188 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6189 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6190 		printf("Device doesn't support RAW data-path APIs.\n");
6191 		return TEST_SKIPPED;
6192 	}
6193 
6194 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6195 		return TEST_SKIPPED;
6196 
6197 	/* Check if device supports ZUC EIA3 */
6198 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6199 			tdata->key.len, tdata->auth_iv.len,
6200 			tdata->digest.len) < 0)
6201 		return TEST_SKIPPED;
6202 
6203 	/* Create ZUC session */
6204 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6205 			tdata->key.data, tdata->key.len,
6206 			tdata->auth_iv.len, tdata->digest.len,
6207 			RTE_CRYPTO_AUTH_OP_GENERATE,
6208 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6209 	if (retval != 0)
6210 		return retval;
6211 
6212 	/* alloc mbuf and set payload */
6213 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6214 
6215 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6216 	rte_pktmbuf_tailroom(ut_params->ibuf));
6217 
6218 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6219 	/* Append data which is padded to a multiple of */
6220 	/* the algorithms block size */
6221 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6222 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6223 				plaintext_pad_len);
6224 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6225 
6226 	/* Create ZUC operation */
6227 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6228 			tdata->auth_iv.data, tdata->auth_iv.len,
6229 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6230 			tdata->validAuthLenInBits.len,
6231 			0);
6232 	if (retval < 0)
6233 		return retval;
6234 
6235 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6236 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6237 				ut_params->op, 0, 1, 1, 0);
6238 	else
6239 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6240 				ut_params->op);
6241 	ut_params->obuf = ut_params->op->sym->m_src;
6242 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6243 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6244 			+ plaintext_pad_len;
6245 
6246 	/* Validate obuf */
6247 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6248 	ut_params->digest,
6249 	tdata->digest.data,
6250 	tdata->digest.len,
6251 	"ZUC Generated auth tag not as expected");
6252 
6253 	return 0;
6254 }
6255 
6256 static int
6257 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6258 	uint8_t op_mode, uint8_t verify)
6259 {
6260 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6261 	struct crypto_unittest_params *ut_params = &unittest_params;
6262 
6263 	int retval;
6264 
6265 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6266 	unsigned int plaintext_pad_len;
6267 	unsigned int plaintext_len;
6268 	unsigned int ciphertext_pad_len;
6269 	unsigned int ciphertext_len;
6270 
6271 	struct rte_cryptodev_info dev_info;
6272 
6273 	/* Check if device supports ZUC EEA3 */
6274 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6275 			tdata->key.len, tdata->cipher_iv.len) < 0)
6276 		return TEST_SKIPPED;
6277 
6278 	/* Check if device supports ZUC EIA3 */
6279 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6280 			tdata->key.len, tdata->auth_iv.len,
6281 			tdata->digest.len) < 0)
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 (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6289 		printf("Device doesn't support digest encrypted.\n");
6290 		return TEST_SKIPPED;
6291 	}
6292 	if (op_mode == IN_PLACE) {
6293 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6294 			printf("Device doesn't support in-place scatter-gather "
6295 					"in both input and output mbufs.\n");
6296 			return TEST_SKIPPED;
6297 		}
6298 
6299 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6300 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6301 			printf("Device doesn't support RAW data-path APIs.\n");
6302 			return TEST_SKIPPED;
6303 		}
6304 	} else {
6305 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6306 			return TEST_SKIPPED;
6307 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6308 			printf("Device doesn't support out-of-place scatter-gather "
6309 					"in both input and output mbufs.\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 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6331 	if (op_mode == OUT_OF_PLACE)
6332 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6333 
6334 	/* clear mbuf payload */
6335 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6336 		rte_pktmbuf_tailroom(ut_params->ibuf));
6337 	if (op_mode == OUT_OF_PLACE)
6338 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6339 			rte_pktmbuf_tailroom(ut_params->obuf));
6340 
6341 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6342 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6343 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6344 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6345 
6346 	if (verify) {
6347 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6348 					ciphertext_pad_len);
6349 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6350 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6351 			ciphertext_len);
6352 	} else {
6353 		/* make sure enough space to cover partial digest verify case */
6354 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6355 					ciphertext_pad_len);
6356 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6357 		debug_hexdump(stdout, "plaintext:", plaintext,
6358 			plaintext_len);
6359 	}
6360 
6361 	if (op_mode == OUT_OF_PLACE)
6362 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
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 		tdata->auth_iv.data, tdata->auth_iv.len,
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, 0, 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 
6394 	if (verify) {
6395 		if (ut_params->obuf)
6396 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6397 							uint8_t *);
6398 		else
6399 			plaintext = ciphertext;
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_mtod(ut_params->obuf,
6409 							uint8_t *);
6410 		else
6411 			ciphertext = plaintext;
6412 
6413 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6414 			ciphertext_len);
6415 		debug_hexdump(stdout, "ciphertext expected:",
6416 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6417 
6418 		ut_params->digest = rte_pktmbuf_mtod(
6419 			ut_params->obuf, uint8_t *) +
6420 			(tdata->digest.offset_bytes == 0 ?
6421 			plaintext_pad_len : tdata->digest.offset_bytes);
6422 
6423 		debug_hexdump(stdout, "digest:", ut_params->digest,
6424 			tdata->digest.len);
6425 		debug_hexdump(stdout, "digest expected:",
6426 			tdata->digest.data, tdata->digest.len);
6427 	}
6428 
6429 	/* Validate obuf */
6430 	if (verify) {
6431 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6432 			plaintext,
6433 			tdata->plaintext.data,
6434 			tdata->plaintext.len >> 3,
6435 			"ZUC Plaintext data not as expected");
6436 	} else {
6437 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6438 			ciphertext,
6439 			tdata->ciphertext.data,
6440 			tdata->ciphertext.len >> 3,
6441 			"ZUC Ciphertext data not as expected");
6442 
6443 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6444 			ut_params->digest,
6445 			tdata->digest.data,
6446 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6447 			"ZUC Generated auth tag not as expected");
6448 	}
6449 	return 0;
6450 }
6451 
6452 static int
6453 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6454 	uint8_t op_mode, uint8_t verify)
6455 {
6456 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6457 	struct crypto_unittest_params *ut_params = &unittest_params;
6458 
6459 	int retval;
6460 
6461 	const uint8_t *plaintext = NULL;
6462 	const uint8_t *ciphertext = NULL;
6463 	const uint8_t *digest = NULL;
6464 	unsigned int plaintext_pad_len;
6465 	unsigned int plaintext_len;
6466 	unsigned int ciphertext_pad_len;
6467 	unsigned int ciphertext_len;
6468 	uint8_t buffer[10000];
6469 	uint8_t digest_buffer[10000];
6470 
6471 	struct rte_cryptodev_info dev_info;
6472 
6473 	/* Check if device supports ZUC EEA3 */
6474 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6475 			tdata->key.len, tdata->cipher_iv.len) < 0)
6476 		return TEST_SKIPPED;
6477 
6478 	/* Check if device supports ZUC EIA3 */
6479 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6480 			tdata->key.len, tdata->auth_iv.len,
6481 			tdata->digest.len) < 0)
6482 		return TEST_SKIPPED;
6483 
6484 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6485 
6486 	uint64_t feat_flags = dev_info.feature_flags;
6487 
6488 	if (op_mode == IN_PLACE) {
6489 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6490 			printf("Device doesn't support in-place scatter-gather "
6491 					"in both input and output mbufs.\n");
6492 			return TEST_SKIPPED;
6493 		}
6494 
6495 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6496 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6497 			printf("Device doesn't support RAW data-path APIs.\n");
6498 			return TEST_SKIPPED;
6499 		}
6500 	} else {
6501 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6502 			return TEST_SKIPPED;
6503 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6504 			printf("Device doesn't support out-of-place scatter-gather "
6505 					"in both input and output mbufs.\n");
6506 			return TEST_SKIPPED;
6507 		}
6508 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6509 			printf("Device doesn't support digest encrypted.\n");
6510 			return TEST_SKIPPED;
6511 		}
6512 	}
6513 
6514 	/* Create ZUC session */
6515 	retval = create_wireless_algo_auth_cipher_session(
6516 			ts_params->valid_devs[0],
6517 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6518 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6519 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6520 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6521 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6522 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6523 			tdata->key.data, tdata->key.len,
6524 			tdata->auth_iv.len, tdata->digest.len,
6525 			tdata->cipher_iv.len);
6526 
6527 	if (retval != 0)
6528 		return retval;
6529 
6530 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6531 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6532 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6533 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6534 
6535 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6536 			plaintext_pad_len, 15, 0);
6537 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6538 			"Failed to allocate input buffer in mempool");
6539 
6540 	if (op_mode == OUT_OF_PLACE) {
6541 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6542 				plaintext_pad_len, 15, 0);
6543 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6544 				"Failed to allocate output buffer in mempool");
6545 	}
6546 
6547 	if (verify) {
6548 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6549 			tdata->ciphertext.data);
6550 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6551 					ciphertext_len, buffer);
6552 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6553 			ciphertext_len);
6554 	} else {
6555 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6556 			tdata->plaintext.data);
6557 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6558 					plaintext_len, buffer);
6559 		debug_hexdump(stdout, "plaintext:", plaintext,
6560 			plaintext_len);
6561 	}
6562 	memset(buffer, 0, sizeof(buffer));
6563 
6564 	/* Create ZUC operation */
6565 	retval = create_wireless_algo_auth_cipher_operation(
6566 		tdata->digest.data, tdata->digest.len,
6567 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6568 		NULL, 0,
6569 		(tdata->digest.offset_bytes == 0 ?
6570 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6571 			: tdata->digest.offset_bytes),
6572 		tdata->validCipherLenInBits.len,
6573 		tdata->validCipherOffsetInBits.len,
6574 		tdata->validAuthLenInBits.len,
6575 		0,
6576 		op_mode, 1, verify);
6577 
6578 	if (retval < 0)
6579 		return retval;
6580 
6581 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6582 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6583 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6584 	else
6585 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6586 			ut_params->op);
6587 
6588 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6589 
6590 	ut_params->obuf = (op_mode == IN_PLACE ?
6591 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6592 
6593 	if (verify) {
6594 		if (ut_params->obuf)
6595 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6596 					plaintext_len, buffer);
6597 		else
6598 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6599 					plaintext_len, buffer);
6600 
6601 		debug_hexdump(stdout, "plaintext:", plaintext,
6602 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6603 		debug_hexdump(stdout, "plaintext expected:",
6604 			tdata->plaintext.data,
6605 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6606 	} else {
6607 		if (ut_params->obuf)
6608 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6609 					ciphertext_len, buffer);
6610 		else
6611 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6612 					ciphertext_len, buffer);
6613 
6614 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6615 			ciphertext_len);
6616 		debug_hexdump(stdout, "ciphertext expected:",
6617 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6618 
6619 		if (ut_params->obuf)
6620 			digest = rte_pktmbuf_read(ut_params->obuf,
6621 				(tdata->digest.offset_bytes == 0 ?
6622 				plaintext_pad_len : tdata->digest.offset_bytes),
6623 				tdata->digest.len, digest_buffer);
6624 		else
6625 			digest = rte_pktmbuf_read(ut_params->ibuf,
6626 				(tdata->digest.offset_bytes == 0 ?
6627 				plaintext_pad_len : tdata->digest.offset_bytes),
6628 				tdata->digest.len, digest_buffer);
6629 
6630 		debug_hexdump(stdout, "digest:", digest,
6631 			tdata->digest.len);
6632 		debug_hexdump(stdout, "digest expected:",
6633 			tdata->digest.data, tdata->digest.len);
6634 	}
6635 
6636 	/* Validate obuf */
6637 	if (verify) {
6638 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6639 			plaintext,
6640 			tdata->plaintext.data,
6641 			tdata->plaintext.len >> 3,
6642 			"ZUC Plaintext data not as expected");
6643 	} else {
6644 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6645 			ciphertext,
6646 			tdata->ciphertext.data,
6647 			tdata->validDataLenInBits.len,
6648 			"ZUC Ciphertext data not as expected");
6649 
6650 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6651 			digest,
6652 			tdata->digest.data,
6653 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6654 			"ZUC Generated auth tag not as expected");
6655 	}
6656 	return 0;
6657 }
6658 
6659 static int
6660 test_kasumi_encryption_test_case_1(void)
6661 {
6662 	return test_kasumi_encryption(&kasumi_test_case_1);
6663 }
6664 
6665 static int
6666 test_kasumi_encryption_test_case_1_sgl(void)
6667 {
6668 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6669 }
6670 
6671 static int
6672 test_kasumi_encryption_test_case_1_oop(void)
6673 {
6674 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6675 }
6676 
6677 static int
6678 test_kasumi_encryption_test_case_1_oop_sgl(void)
6679 {
6680 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6681 }
6682 
6683 static int
6684 test_kasumi_encryption_test_case_2(void)
6685 {
6686 	return test_kasumi_encryption(&kasumi_test_case_2);
6687 }
6688 
6689 static int
6690 test_kasumi_encryption_test_case_3(void)
6691 {
6692 	return test_kasumi_encryption(&kasumi_test_case_3);
6693 }
6694 
6695 static int
6696 test_kasumi_encryption_test_case_4(void)
6697 {
6698 	return test_kasumi_encryption(&kasumi_test_case_4);
6699 }
6700 
6701 static int
6702 test_kasumi_encryption_test_case_5(void)
6703 {
6704 	return test_kasumi_encryption(&kasumi_test_case_5);
6705 }
6706 
6707 static int
6708 test_kasumi_decryption_test_case_1(void)
6709 {
6710 	return test_kasumi_decryption(&kasumi_test_case_1);
6711 }
6712 
6713 static int
6714 test_kasumi_decryption_test_case_1_oop(void)
6715 {
6716 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6717 }
6718 
6719 static int
6720 test_kasumi_decryption_test_case_2(void)
6721 {
6722 	return test_kasumi_decryption(&kasumi_test_case_2);
6723 }
6724 
6725 static int
6726 test_kasumi_decryption_test_case_3(void)
6727 {
6728 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6729 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6730 		return TEST_SKIPPED;
6731 	return test_kasumi_decryption(&kasumi_test_case_3);
6732 }
6733 
6734 static int
6735 test_kasumi_decryption_test_case_4(void)
6736 {
6737 	return test_kasumi_decryption(&kasumi_test_case_4);
6738 }
6739 
6740 static int
6741 test_kasumi_decryption_test_case_5(void)
6742 {
6743 	return test_kasumi_decryption(&kasumi_test_case_5);
6744 }
6745 static int
6746 test_snow3g_encryption_test_case_1(void)
6747 {
6748 	return test_snow3g_encryption(&snow3g_test_case_1);
6749 }
6750 
6751 static int
6752 test_snow3g_encryption_test_case_1_oop(void)
6753 {
6754 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6755 }
6756 
6757 static int
6758 test_snow3g_encryption_test_case_1_oop_sgl(void)
6759 {
6760 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6761 }
6762 
6763 
6764 static int
6765 test_snow3g_encryption_test_case_1_offset_oop(void)
6766 {
6767 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6768 }
6769 
6770 static int
6771 test_snow3g_encryption_test_case_2(void)
6772 {
6773 	return test_snow3g_encryption(&snow3g_test_case_2);
6774 }
6775 
6776 static int
6777 test_snow3g_encryption_test_case_3(void)
6778 {
6779 	return test_snow3g_encryption(&snow3g_test_case_3);
6780 }
6781 
6782 static int
6783 test_snow3g_encryption_test_case_4(void)
6784 {
6785 	return test_snow3g_encryption(&snow3g_test_case_4);
6786 }
6787 
6788 static int
6789 test_snow3g_encryption_test_case_5(void)
6790 {
6791 	return test_snow3g_encryption(&snow3g_test_case_5);
6792 }
6793 
6794 static int
6795 test_snow3g_decryption_test_case_1(void)
6796 {
6797 	return test_snow3g_decryption(&snow3g_test_case_1);
6798 }
6799 
6800 static int
6801 test_snow3g_decryption_test_case_1_oop(void)
6802 {
6803 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6804 }
6805 
6806 static int
6807 test_snow3g_decryption_test_case_2(void)
6808 {
6809 	return test_snow3g_decryption(&snow3g_test_case_2);
6810 }
6811 
6812 static int
6813 test_snow3g_decryption_test_case_3(void)
6814 {
6815 	return test_snow3g_decryption(&snow3g_test_case_3);
6816 }
6817 
6818 static int
6819 test_snow3g_decryption_test_case_4(void)
6820 {
6821 	return test_snow3g_decryption(&snow3g_test_case_4);
6822 }
6823 
6824 static int
6825 test_snow3g_decryption_test_case_5(void)
6826 {
6827 	return test_snow3g_decryption(&snow3g_test_case_5);
6828 }
6829 
6830 /*
6831  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6832  * Pattern digest from snow3g_test_data must be allocated as
6833  * 4 last bytes in plaintext.
6834  */
6835 static void
6836 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6837 		struct snow3g_hash_test_data *output)
6838 {
6839 	if ((pattern != NULL) && (output != NULL)) {
6840 		output->key.len = pattern->key.len;
6841 
6842 		memcpy(output->key.data,
6843 		pattern->key.data, pattern->key.len);
6844 
6845 		output->auth_iv.len = pattern->auth_iv.len;
6846 
6847 		memcpy(output->auth_iv.data,
6848 		pattern->auth_iv.data, pattern->auth_iv.len);
6849 
6850 		output->plaintext.len = pattern->plaintext.len;
6851 
6852 		memcpy(output->plaintext.data,
6853 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6854 
6855 		output->digest.len = pattern->digest.len;
6856 
6857 		memcpy(output->digest.data,
6858 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6859 		pattern->digest.len);
6860 
6861 		output->validAuthLenInBits.len =
6862 		pattern->validAuthLenInBits.len;
6863 	}
6864 }
6865 
6866 /*
6867  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6868  */
6869 static int
6870 test_snow3g_decryption_with_digest_test_case_1(void)
6871 {
6872 	struct snow3g_hash_test_data snow3g_hash_data;
6873 	struct rte_cryptodev_info dev_info;
6874 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6875 
6876 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6877 	uint64_t feat_flags = dev_info.feature_flags;
6878 
6879 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6880 		printf("Device doesn't support encrypted digest operations.\n");
6881 		return TEST_SKIPPED;
6882 	}
6883 
6884 	/*
6885 	 * Function prepare data for hash verification test case.
6886 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6887 	 */
6888 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6889 
6890 	return test_snow3g_decryption(&snow3g_test_case_7) &
6891 			test_snow3g_authentication_verify(&snow3g_hash_data);
6892 }
6893 
6894 static int
6895 test_snow3g_cipher_auth_test_case_1(void)
6896 {
6897 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6898 }
6899 
6900 static int
6901 test_snow3g_auth_cipher_test_case_1(void)
6902 {
6903 	return test_snow3g_auth_cipher(
6904 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6905 }
6906 
6907 static int
6908 test_snow3g_auth_cipher_test_case_2(void)
6909 {
6910 	return test_snow3g_auth_cipher(
6911 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6912 }
6913 
6914 static int
6915 test_snow3g_auth_cipher_test_case_2_oop(void)
6916 {
6917 	return test_snow3g_auth_cipher(
6918 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6919 }
6920 
6921 static int
6922 test_snow3g_auth_cipher_part_digest_enc(void)
6923 {
6924 	return test_snow3g_auth_cipher(
6925 		&snow3g_auth_cipher_partial_digest_encryption,
6926 			IN_PLACE, 0);
6927 }
6928 
6929 static int
6930 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6931 {
6932 	return test_snow3g_auth_cipher(
6933 		&snow3g_auth_cipher_partial_digest_encryption,
6934 			OUT_OF_PLACE, 0);
6935 }
6936 
6937 static int
6938 test_snow3g_auth_cipher_test_case_3_sgl(void)
6939 {
6940 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6941 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6942 		return TEST_SKIPPED;
6943 	return test_snow3g_auth_cipher_sgl(
6944 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6945 }
6946 
6947 static int
6948 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6949 {
6950 	return test_snow3g_auth_cipher_sgl(
6951 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6952 }
6953 
6954 static int
6955 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6956 {
6957 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6958 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6959 		return TEST_SKIPPED;
6960 	return test_snow3g_auth_cipher_sgl(
6961 		&snow3g_auth_cipher_partial_digest_encryption,
6962 			IN_PLACE, 0);
6963 }
6964 
6965 static int
6966 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6967 {
6968 	return test_snow3g_auth_cipher_sgl(
6969 		&snow3g_auth_cipher_partial_digest_encryption,
6970 			OUT_OF_PLACE, 0);
6971 }
6972 
6973 static int
6974 test_snow3g_auth_cipher_verify_test_case_1(void)
6975 {
6976 	return test_snow3g_auth_cipher(
6977 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6978 }
6979 
6980 static int
6981 test_snow3g_auth_cipher_verify_test_case_2(void)
6982 {
6983 	return test_snow3g_auth_cipher(
6984 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6985 }
6986 
6987 static int
6988 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6989 {
6990 	return test_snow3g_auth_cipher(
6991 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6992 }
6993 
6994 static int
6995 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6996 {
6997 	return test_snow3g_auth_cipher(
6998 		&snow3g_auth_cipher_partial_digest_encryption,
6999 			IN_PLACE, 1);
7000 }
7001 
7002 static int
7003 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
7004 {
7005 	return test_snow3g_auth_cipher(
7006 		&snow3g_auth_cipher_partial_digest_encryption,
7007 			OUT_OF_PLACE, 1);
7008 }
7009 
7010 static int
7011 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
7012 {
7013 	return test_snow3g_auth_cipher_sgl(
7014 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
7015 }
7016 
7017 static int
7018 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7019 {
7020 	return test_snow3g_auth_cipher_sgl(
7021 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7022 }
7023 
7024 static int
7025 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7026 {
7027 	return test_snow3g_auth_cipher_sgl(
7028 		&snow3g_auth_cipher_partial_digest_encryption,
7029 			IN_PLACE, 1);
7030 }
7031 
7032 static int
7033 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7034 {
7035 	return test_snow3g_auth_cipher_sgl(
7036 		&snow3g_auth_cipher_partial_digest_encryption,
7037 			OUT_OF_PLACE, 1);
7038 }
7039 
7040 static int
7041 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7042 {
7043 	return test_snow3g_auth_cipher(
7044 		&snow3g_test_case_7, IN_PLACE, 0);
7045 }
7046 
7047 static int
7048 test_kasumi_auth_cipher_test_case_1(void)
7049 {
7050 	return test_kasumi_auth_cipher(
7051 		&kasumi_test_case_3, IN_PLACE, 0);
7052 }
7053 
7054 static int
7055 test_kasumi_auth_cipher_test_case_2(void)
7056 {
7057 	return test_kasumi_auth_cipher(
7058 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7059 }
7060 
7061 static int
7062 test_kasumi_auth_cipher_test_case_2_oop(void)
7063 {
7064 	return test_kasumi_auth_cipher(
7065 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7066 }
7067 
7068 static int
7069 test_kasumi_auth_cipher_test_case_2_sgl(void)
7070 {
7071 	return test_kasumi_auth_cipher_sgl(
7072 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7073 }
7074 
7075 static int
7076 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7077 {
7078 	return test_kasumi_auth_cipher_sgl(
7079 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7080 }
7081 
7082 static int
7083 test_kasumi_auth_cipher_verify_test_case_1(void)
7084 {
7085 	return test_kasumi_auth_cipher(
7086 		&kasumi_test_case_3, IN_PLACE, 1);
7087 }
7088 
7089 static int
7090 test_kasumi_auth_cipher_verify_test_case_2(void)
7091 {
7092 	return test_kasumi_auth_cipher(
7093 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7094 }
7095 
7096 static int
7097 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7098 {
7099 	return test_kasumi_auth_cipher(
7100 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7101 }
7102 
7103 static int
7104 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7105 {
7106 	return test_kasumi_auth_cipher_sgl(
7107 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7108 }
7109 
7110 static int
7111 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7112 {
7113 	return test_kasumi_auth_cipher_sgl(
7114 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7115 }
7116 
7117 static int
7118 test_kasumi_cipher_auth_test_case_1(void)
7119 {
7120 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7121 }
7122 
7123 static int
7124 test_zuc_encryption_test_case_1(void)
7125 {
7126 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
7127 }
7128 
7129 static int
7130 test_zuc_encryption_test_case_2(void)
7131 {
7132 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
7133 }
7134 
7135 static int
7136 test_zuc_encryption_test_case_3(void)
7137 {
7138 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7139 }
7140 
7141 static int
7142 test_zuc_encryption_test_case_4(void)
7143 {
7144 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7145 }
7146 
7147 static int
7148 test_zuc_encryption_test_case_5(void)
7149 {
7150 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7151 }
7152 
7153 static int
7154 test_zuc_encryption_test_case_6_sgl(void)
7155 {
7156 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7157 }
7158 
7159 static int
7160 test_zuc_hash_generate_test_case_1(void)
7161 {
7162 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7163 }
7164 
7165 static int
7166 test_zuc_hash_generate_test_case_2(void)
7167 {
7168 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7169 }
7170 
7171 static int
7172 test_zuc_hash_generate_test_case_3(void)
7173 {
7174 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7175 }
7176 
7177 static int
7178 test_zuc_hash_generate_test_case_4(void)
7179 {
7180 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7181 }
7182 
7183 static int
7184 test_zuc_hash_generate_test_case_5(void)
7185 {
7186 	return test_zuc_authentication(&zuc_test_auth_5670b);
7187 }
7188 
7189 static int
7190 test_zuc_hash_generate_test_case_6(void)
7191 {
7192 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7193 }
7194 
7195 static int
7196 test_zuc_hash_generate_test_case_7(void)
7197 {
7198 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7199 }
7200 
7201 static int
7202 test_zuc_hash_generate_test_case_8(void)
7203 {
7204 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7205 }
7206 
7207 static int
7208 test_zuc_hash_generate_test_case_9(void)
7209 {
7210 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b);
7211 }
7212 
7213 static int
7214 test_zuc_hash_generate_test_case_10(void)
7215 {
7216 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b);
7217 }
7218 
7219 static int
7220 test_zuc_hash_generate_test_case_11(void)
7221 {
7222 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b);
7223 }
7224 
7225 static int
7226 test_zuc_cipher_auth_test_case_1(void)
7227 {
7228 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7229 }
7230 
7231 static int
7232 test_zuc_cipher_auth_test_case_2(void)
7233 {
7234 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7235 }
7236 
7237 static int
7238 test_zuc_auth_cipher_test_case_1(void)
7239 {
7240 	return test_zuc_auth_cipher(
7241 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7242 }
7243 
7244 static int
7245 test_zuc_auth_cipher_test_case_1_oop(void)
7246 {
7247 	return test_zuc_auth_cipher(
7248 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7249 }
7250 
7251 static int
7252 test_zuc_auth_cipher_test_case_1_sgl(void)
7253 {
7254 	return test_zuc_auth_cipher_sgl(
7255 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7256 }
7257 
7258 static int
7259 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7260 {
7261 	return test_zuc_auth_cipher_sgl(
7262 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7263 }
7264 
7265 static int
7266 test_zuc_auth_cipher_verify_test_case_1(void)
7267 {
7268 	return test_zuc_auth_cipher(
7269 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7270 }
7271 
7272 static int
7273 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7274 {
7275 	return test_zuc_auth_cipher(
7276 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7277 }
7278 
7279 static int
7280 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7281 {
7282 	return test_zuc_auth_cipher_sgl(
7283 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7284 }
7285 
7286 static int
7287 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7288 {
7289 	return test_zuc_auth_cipher_sgl(
7290 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7291 }
7292 
7293 static int
7294 test_zuc256_encryption_test_case_1(void)
7295 {
7296 	return test_zuc_encryption(&zuc256_test_case_cipher_1);
7297 }
7298 
7299 static int
7300 test_zuc256_encryption_test_case_2(void)
7301 {
7302 	return test_zuc_encryption(&zuc256_test_case_cipher_2);
7303 }
7304 
7305 static int
7306 test_zuc256_authentication_test_case_1(void)
7307 {
7308 	return test_zuc_authentication(&zuc256_test_case_auth_1);
7309 }
7310 
7311 static int
7312 test_zuc256_authentication_test_case_2(void)
7313 {
7314 	return test_zuc_authentication(&zuc256_test_case_auth_2);
7315 }
7316 
7317 static int
7318 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7319 {
7320 	uint8_t dev_id = testsuite_params.valid_devs[0];
7321 
7322 	struct rte_cryptodev_sym_capability_idx cap_idx;
7323 
7324 	/* Check if device supports particular cipher algorithm */
7325 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7326 	cap_idx.algo.cipher = tdata->cipher_algo;
7327 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7328 		return TEST_SKIPPED;
7329 
7330 	/* Check if device supports particular hash algorithm */
7331 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7332 	cap_idx.algo.auth = tdata->auth_algo;
7333 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7334 		return TEST_SKIPPED;
7335 
7336 	return 0;
7337 }
7338 
7339 static int
7340 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7341 	uint8_t op_mode, uint8_t verify)
7342 {
7343 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7344 	struct crypto_unittest_params *ut_params = &unittest_params;
7345 
7346 	int retval;
7347 
7348 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7349 	unsigned int plaintext_pad_len;
7350 	unsigned int plaintext_len;
7351 	unsigned int ciphertext_pad_len;
7352 	unsigned int ciphertext_len;
7353 
7354 	struct rte_cryptodev_info dev_info;
7355 	struct rte_crypto_op *op;
7356 
7357 	/* Check if device supports particular algorithms separately */
7358 	if (test_mixed_check_if_unsupported(tdata))
7359 		return TEST_SKIPPED;
7360 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7361 		return TEST_SKIPPED;
7362 
7363 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7364 
7365 	uint64_t feat_flags = dev_info.feature_flags;
7366 
7367 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7368 		printf("Device doesn't support digest encrypted.\n");
7369 		return TEST_SKIPPED;
7370 	}
7371 
7372 	/* Create the session */
7373 	if (verify)
7374 		retval = create_wireless_algo_cipher_auth_session(
7375 				ts_params->valid_devs[0],
7376 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7377 				RTE_CRYPTO_AUTH_OP_VERIFY,
7378 				tdata->auth_algo,
7379 				tdata->cipher_algo,
7380 				tdata->auth_key.data, tdata->auth_key.len,
7381 				tdata->auth_iv.len, tdata->digest_enc.len,
7382 				tdata->cipher_iv.len);
7383 	else
7384 		retval = create_wireless_algo_auth_cipher_session(
7385 				ts_params->valid_devs[0],
7386 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7387 				RTE_CRYPTO_AUTH_OP_GENERATE,
7388 				tdata->auth_algo,
7389 				tdata->cipher_algo,
7390 				tdata->auth_key.data, tdata->auth_key.len,
7391 				tdata->auth_iv.len, tdata->digest_enc.len,
7392 				tdata->cipher_iv.len);
7393 	if (retval != 0)
7394 		return retval;
7395 
7396 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7397 	if (op_mode == OUT_OF_PLACE)
7398 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7399 
7400 	/* clear mbuf payload */
7401 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7402 		rte_pktmbuf_tailroom(ut_params->ibuf));
7403 	if (op_mode == OUT_OF_PLACE) {
7404 
7405 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7406 				rte_pktmbuf_tailroom(ut_params->obuf));
7407 	}
7408 
7409 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7410 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7411 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7412 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7413 
7414 	if (verify) {
7415 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7416 				ciphertext_pad_len);
7417 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7418 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7419 				ciphertext_len);
7420 	} else {
7421 		/* make sure enough space to cover partial digest verify case */
7422 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7423 				ciphertext_pad_len);
7424 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7425 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7426 	}
7427 
7428 	if (op_mode == OUT_OF_PLACE)
7429 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7430 
7431 	/* Create the operation */
7432 	retval = create_wireless_algo_auth_cipher_operation(
7433 			tdata->digest_enc.data, tdata->digest_enc.len,
7434 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7435 			tdata->auth_iv.data, tdata->auth_iv.len,
7436 			(tdata->digest_enc.offset == 0 ?
7437 				plaintext_pad_len
7438 				: tdata->digest_enc.offset),
7439 			tdata->validCipherLen.len_bits,
7440 			tdata->cipher.offset_bits,
7441 			tdata->validAuthLen.len_bits,
7442 			tdata->auth.offset_bits,
7443 			op_mode, 0, verify);
7444 
7445 	if (retval < 0)
7446 		return retval;
7447 
7448 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7449 
7450 	/* Check if the op failed because the device doesn't */
7451 	/* support this particular combination of algorithms */
7452 	if (op == NULL && ut_params->op->status ==
7453 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7454 		printf("Device doesn't support this mixed combination. "
7455 				"Test Skipped.\n");
7456 		return TEST_SKIPPED;
7457 	}
7458 	ut_params->op = op;
7459 
7460 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7461 
7462 	ut_params->obuf = (op_mode == IN_PLACE ?
7463 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7464 
7465 	if (verify) {
7466 		if (ut_params->obuf)
7467 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7468 							uint8_t *);
7469 		else
7470 			plaintext = ciphertext +
7471 					(tdata->cipher.offset_bits >> 3);
7472 
7473 		debug_hexdump(stdout, "plaintext:", plaintext,
7474 				tdata->plaintext.len_bits >> 3);
7475 		debug_hexdump(stdout, "plaintext expected:",
7476 				tdata->plaintext.data,
7477 				tdata->plaintext.len_bits >> 3);
7478 	} else {
7479 		if (ut_params->obuf)
7480 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7481 					uint8_t *);
7482 		else
7483 			ciphertext = plaintext;
7484 
7485 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7486 				ciphertext_len);
7487 		debug_hexdump(stdout, "ciphertext expected:",
7488 				tdata->ciphertext.data,
7489 				tdata->ciphertext.len_bits >> 3);
7490 
7491 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7492 				+ (tdata->digest_enc.offset == 0 ?
7493 		plaintext_pad_len : tdata->digest_enc.offset);
7494 
7495 		debug_hexdump(stdout, "digest:", ut_params->digest,
7496 				tdata->digest_enc.len);
7497 		debug_hexdump(stdout, "digest expected:",
7498 				tdata->digest_enc.data,
7499 				tdata->digest_enc.len);
7500 	}
7501 
7502 	if (!verify) {
7503 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7504 				ut_params->digest,
7505 				tdata->digest_enc.data,
7506 				tdata->digest_enc.len,
7507 				"Generated auth tag not as expected");
7508 	}
7509 
7510 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7511 		if (verify) {
7512 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7513 					plaintext,
7514 					tdata->plaintext.data,
7515 					tdata->plaintext.len_bits >> 3,
7516 					"Plaintext data not as expected");
7517 		} else {
7518 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7519 					ciphertext,
7520 					tdata->ciphertext.data,
7521 					tdata->validDataLen.len_bits,
7522 					"Ciphertext data not as expected");
7523 		}
7524 	}
7525 
7526 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7527 			"crypto op processing failed");
7528 
7529 	return 0;
7530 }
7531 
7532 static int
7533 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7534 	uint8_t op_mode, uint8_t verify)
7535 {
7536 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7537 	struct crypto_unittest_params *ut_params = &unittest_params;
7538 
7539 	int retval;
7540 
7541 	const uint8_t *plaintext = NULL;
7542 	const uint8_t *ciphertext = NULL;
7543 	const uint8_t *digest = NULL;
7544 	unsigned int plaintext_pad_len;
7545 	unsigned int plaintext_len;
7546 	unsigned int ciphertext_pad_len;
7547 	unsigned int ciphertext_len;
7548 	uint8_t buffer[10000];
7549 	uint8_t digest_buffer[10000];
7550 
7551 	struct rte_cryptodev_info dev_info;
7552 	struct rte_crypto_op *op;
7553 
7554 	/* Check if device supports particular algorithms */
7555 	if (test_mixed_check_if_unsupported(tdata))
7556 		return TEST_SKIPPED;
7557 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7558 		return TEST_SKIPPED;
7559 
7560 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7561 
7562 	uint64_t feat_flags = dev_info.feature_flags;
7563 
7564 	if (op_mode == IN_PLACE) {
7565 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7566 			printf("Device doesn't support in-place scatter-gather "
7567 					"in both input and output mbufs.\n");
7568 			return TEST_SKIPPED;
7569 		}
7570 	} else {
7571 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7572 			printf("Device doesn't support out-of-place scatter-gather "
7573 					"in both input and output mbufs.\n");
7574 			return TEST_SKIPPED;
7575 		}
7576 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7577 			printf("Device doesn't support digest encrypted.\n");
7578 			return TEST_SKIPPED;
7579 		}
7580 	}
7581 
7582 	/* Create the session */
7583 	if (verify)
7584 		retval = create_wireless_algo_cipher_auth_session(
7585 				ts_params->valid_devs[0],
7586 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7587 				RTE_CRYPTO_AUTH_OP_VERIFY,
7588 				tdata->auth_algo,
7589 				tdata->cipher_algo,
7590 				tdata->auth_key.data, tdata->auth_key.len,
7591 				tdata->auth_iv.len, tdata->digest_enc.len,
7592 				tdata->cipher_iv.len);
7593 	else
7594 		retval = create_wireless_algo_auth_cipher_session(
7595 				ts_params->valid_devs[0],
7596 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7597 				RTE_CRYPTO_AUTH_OP_GENERATE,
7598 				tdata->auth_algo,
7599 				tdata->cipher_algo,
7600 				tdata->auth_key.data, tdata->auth_key.len,
7601 				tdata->auth_iv.len, tdata->digest_enc.len,
7602 				tdata->cipher_iv.len);
7603 	if (retval != 0)
7604 		return retval;
7605 
7606 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7607 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7608 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7609 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7610 
7611 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7612 			ciphertext_pad_len, 15, 0);
7613 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7614 			"Failed to allocate input buffer in mempool");
7615 
7616 	if (op_mode == OUT_OF_PLACE) {
7617 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7618 				plaintext_pad_len, 15, 0);
7619 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7620 				"Failed to allocate output buffer in mempool");
7621 	}
7622 
7623 	if (verify) {
7624 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7625 			tdata->ciphertext.data);
7626 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7627 					ciphertext_len, buffer);
7628 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7629 			ciphertext_len);
7630 	} else {
7631 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7632 			tdata->plaintext.data);
7633 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7634 					plaintext_len, buffer);
7635 		debug_hexdump(stdout, "plaintext:", plaintext,
7636 			plaintext_len);
7637 	}
7638 	memset(buffer, 0, sizeof(buffer));
7639 
7640 	/* Create the operation */
7641 	retval = create_wireless_algo_auth_cipher_operation(
7642 			tdata->digest_enc.data, tdata->digest_enc.len,
7643 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7644 			tdata->auth_iv.data, tdata->auth_iv.len,
7645 			(tdata->digest_enc.offset == 0 ?
7646 				plaintext_pad_len
7647 				: tdata->digest_enc.offset),
7648 			tdata->validCipherLen.len_bits,
7649 			tdata->cipher.offset_bits,
7650 			tdata->validAuthLen.len_bits,
7651 			tdata->auth.offset_bits,
7652 			op_mode, 1, verify);
7653 
7654 	if (retval < 0)
7655 		return retval;
7656 
7657 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7658 
7659 	/* Check if the op failed because the device doesn't */
7660 	/* support this particular combination of algorithms */
7661 	if (op == NULL && ut_params->op->status ==
7662 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7663 		printf("Device doesn't support this mixed combination. "
7664 				"Test Skipped.\n");
7665 		return TEST_SKIPPED;
7666 	}
7667 	ut_params->op = op;
7668 
7669 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7670 
7671 	ut_params->obuf = (op_mode == IN_PLACE ?
7672 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7673 
7674 	if (verify) {
7675 		if (ut_params->obuf)
7676 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7677 					plaintext_len, buffer);
7678 		else
7679 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7680 					plaintext_len, buffer);
7681 
7682 		debug_hexdump(stdout, "plaintext:", plaintext,
7683 				(tdata->plaintext.len_bits >> 3) -
7684 				tdata->digest_enc.len);
7685 		debug_hexdump(stdout, "plaintext expected:",
7686 				tdata->plaintext.data,
7687 				(tdata->plaintext.len_bits >> 3) -
7688 				tdata->digest_enc.len);
7689 	} else {
7690 		if (ut_params->obuf)
7691 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7692 					ciphertext_len, buffer);
7693 		else
7694 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7695 					ciphertext_len, buffer);
7696 
7697 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7698 			ciphertext_len);
7699 		debug_hexdump(stdout, "ciphertext expected:",
7700 			tdata->ciphertext.data,
7701 			tdata->ciphertext.len_bits >> 3);
7702 
7703 		if (ut_params->obuf)
7704 			digest = rte_pktmbuf_read(ut_params->obuf,
7705 					(tdata->digest_enc.offset == 0 ?
7706 						plaintext_pad_len :
7707 						tdata->digest_enc.offset),
7708 					tdata->digest_enc.len, digest_buffer);
7709 		else
7710 			digest = rte_pktmbuf_read(ut_params->ibuf,
7711 					(tdata->digest_enc.offset == 0 ?
7712 						plaintext_pad_len :
7713 						tdata->digest_enc.offset),
7714 					tdata->digest_enc.len, digest_buffer);
7715 
7716 		debug_hexdump(stdout, "digest:", digest,
7717 				tdata->digest_enc.len);
7718 		debug_hexdump(stdout, "digest expected:",
7719 				tdata->digest_enc.data, tdata->digest_enc.len);
7720 	}
7721 
7722 	if (!verify) {
7723 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7724 				digest,
7725 				tdata->digest_enc.data,
7726 				tdata->digest_enc.len,
7727 				"Generated auth tag not as expected");
7728 	}
7729 
7730 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7731 		if (verify) {
7732 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7733 					plaintext,
7734 					tdata->plaintext.data,
7735 					tdata->plaintext.len_bits >> 3,
7736 					"Plaintext data not as expected");
7737 		} else {
7738 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7739 					ciphertext,
7740 					tdata->ciphertext.data,
7741 					tdata->validDataLen.len_bits,
7742 					"Ciphertext data not as expected");
7743 		}
7744 	}
7745 
7746 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7747 			"crypto op processing failed");
7748 
7749 	return 0;
7750 }
7751 
7752 /** AUTH AES CMAC + CIPHER AES CTR */
7753 
7754 static int
7755 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7756 {
7757 	return test_mixed_auth_cipher(
7758 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7759 }
7760 
7761 static int
7762 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7763 {
7764 	return test_mixed_auth_cipher(
7765 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7766 }
7767 
7768 static int
7769 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7770 {
7771 	return test_mixed_auth_cipher_sgl(
7772 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7773 }
7774 
7775 static int
7776 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7777 {
7778 	return test_mixed_auth_cipher_sgl(
7779 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7780 }
7781 
7782 static int
7783 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7784 {
7785 	return test_mixed_auth_cipher(
7786 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7787 }
7788 
7789 static int
7790 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7791 {
7792 	return test_mixed_auth_cipher(
7793 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7794 }
7795 
7796 static int
7797 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7798 {
7799 	return test_mixed_auth_cipher_sgl(
7800 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7801 }
7802 
7803 static int
7804 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7805 {
7806 	return test_mixed_auth_cipher_sgl(
7807 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7808 }
7809 
7810 /** MIXED AUTH + CIPHER */
7811 
7812 static int
7813 test_auth_zuc_cipher_snow_test_case_1(void)
7814 {
7815 	return test_mixed_auth_cipher(
7816 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7817 }
7818 
7819 static int
7820 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7821 {
7822 	return test_mixed_auth_cipher(
7823 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7824 }
7825 
7826 static int
7827 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7828 {
7829 	return test_mixed_auth_cipher(
7830 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7831 }
7832 
7833 static int
7834 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7835 {
7836 	return test_mixed_auth_cipher(
7837 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7838 }
7839 
7840 static int
7841 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7842 {
7843 	return test_mixed_auth_cipher(
7844 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7845 }
7846 
7847 static int
7848 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7849 {
7850 	return test_mixed_auth_cipher(
7851 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7852 }
7853 
7854 static int
7855 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7856 {
7857 	return test_mixed_auth_cipher(
7858 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7859 }
7860 
7861 static int
7862 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7863 {
7864 	return test_mixed_auth_cipher(
7865 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7866 }
7867 
7868 static int
7869 test_auth_snow_cipher_zuc_test_case_1(void)
7870 {
7871 	return test_mixed_auth_cipher(
7872 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7873 }
7874 
7875 static int
7876 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7877 {
7878 	return test_mixed_auth_cipher(
7879 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7880 }
7881 
7882 static int
7883 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7884 {
7885 	return test_mixed_auth_cipher(
7886 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7887 }
7888 
7889 static int
7890 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7891 {
7892 	return test_mixed_auth_cipher(
7893 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7894 }
7895 
7896 static int
7897 test_auth_null_cipher_snow_test_case_1(void)
7898 {
7899 	return test_mixed_auth_cipher(
7900 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7901 }
7902 
7903 static int
7904 test_verify_auth_null_cipher_snow_test_case_1(void)
7905 {
7906 	return test_mixed_auth_cipher(
7907 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7908 }
7909 
7910 static int
7911 test_auth_null_cipher_zuc_test_case_1(void)
7912 {
7913 	return test_mixed_auth_cipher(
7914 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7915 }
7916 
7917 static int
7918 test_verify_auth_null_cipher_zuc_test_case_1(void)
7919 {
7920 	return test_mixed_auth_cipher(
7921 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7922 }
7923 
7924 static int
7925 test_auth_snow_cipher_null_test_case_1(void)
7926 {
7927 	return test_mixed_auth_cipher(
7928 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7929 }
7930 
7931 static int
7932 test_verify_auth_snow_cipher_null_test_case_1(void)
7933 {
7934 	return test_mixed_auth_cipher(
7935 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7936 }
7937 
7938 static int
7939 test_auth_zuc_cipher_null_test_case_1(void)
7940 {
7941 	return test_mixed_auth_cipher(
7942 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7943 }
7944 
7945 static int
7946 test_verify_auth_zuc_cipher_null_test_case_1(void)
7947 {
7948 	return test_mixed_auth_cipher(
7949 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7950 }
7951 
7952 static int
7953 test_auth_null_cipher_aes_ctr_test_case_1(void)
7954 {
7955 	return test_mixed_auth_cipher(
7956 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7957 }
7958 
7959 static int
7960 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7961 {
7962 	return test_mixed_auth_cipher(
7963 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7964 }
7965 
7966 static int
7967 test_auth_aes_cmac_cipher_null_test_case_1(void)
7968 {
7969 	return test_mixed_auth_cipher(
7970 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7971 }
7972 
7973 static int
7974 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7975 {
7976 	return test_mixed_auth_cipher(
7977 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7978 }
7979 
7980 /* ***** AEAD algorithm Tests ***** */
7981 
7982 static int
7983 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7984 		enum rte_crypto_aead_operation op,
7985 		const uint8_t *key, const uint8_t key_len,
7986 		const uint16_t aad_len, const uint8_t auth_len,
7987 		uint8_t iv_len)
7988 {
7989 	uint8_t aead_key[key_len];
7990 	int status;
7991 
7992 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7993 	struct crypto_unittest_params *ut_params = &unittest_params;
7994 
7995 	memcpy(aead_key, key, key_len);
7996 
7997 	/* Setup AEAD Parameters */
7998 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7999 	ut_params->aead_xform.next = NULL;
8000 	ut_params->aead_xform.aead.algo = algo;
8001 	ut_params->aead_xform.aead.op = op;
8002 	ut_params->aead_xform.aead.key.data = aead_key;
8003 	ut_params->aead_xform.aead.key.length = key_len;
8004 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8005 	ut_params->aead_xform.aead.iv.length = iv_len;
8006 	ut_params->aead_xform.aead.digest_length = auth_len;
8007 	ut_params->aead_xform.aead.aad_length = aad_len;
8008 
8009 	debug_hexdump(stdout, "key:", key, key_len);
8010 
8011 	/* Create Crypto session*/
8012 	ut_params->sess = rte_cryptodev_sym_session_create(
8013 			ts_params->session_mpool);
8014 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8015 
8016 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
8017 			&ut_params->aead_xform,
8018 			ts_params->session_priv_mpool);
8019 
8020 	return status;
8021 }
8022 
8023 static int
8024 create_aead_xform(struct rte_crypto_op *op,
8025 		enum rte_crypto_aead_algorithm algo,
8026 		enum rte_crypto_aead_operation aead_op,
8027 		uint8_t *key, const uint8_t key_len,
8028 		const uint8_t aad_len, const uint8_t auth_len,
8029 		uint8_t iv_len)
8030 {
8031 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
8032 			"failed to allocate space for crypto transform");
8033 
8034 	struct rte_crypto_sym_op *sym_op = op->sym;
8035 
8036 	/* Setup AEAD Parameters */
8037 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
8038 	sym_op->xform->next = NULL;
8039 	sym_op->xform->aead.algo = algo;
8040 	sym_op->xform->aead.op = aead_op;
8041 	sym_op->xform->aead.key.data = key;
8042 	sym_op->xform->aead.key.length = key_len;
8043 	sym_op->xform->aead.iv.offset = IV_OFFSET;
8044 	sym_op->xform->aead.iv.length = iv_len;
8045 	sym_op->xform->aead.digest_length = auth_len;
8046 	sym_op->xform->aead.aad_length = aad_len;
8047 
8048 	debug_hexdump(stdout, "key:", key, key_len);
8049 
8050 	return 0;
8051 }
8052 
8053 static int
8054 create_aead_operation(enum rte_crypto_aead_operation op,
8055 		const struct aead_test_data *tdata)
8056 {
8057 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8058 	struct crypto_unittest_params *ut_params = &unittest_params;
8059 
8060 	uint8_t *plaintext, *ciphertext;
8061 	unsigned int aad_pad_len, plaintext_pad_len;
8062 
8063 	/* Generate Crypto op data structure */
8064 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8065 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8066 	TEST_ASSERT_NOT_NULL(ut_params->op,
8067 			"Failed to allocate symmetric crypto operation struct");
8068 
8069 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8070 
8071 	/* Append aad data */
8072 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8073 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
8074 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8075 				aad_pad_len);
8076 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8077 				"no room to append aad");
8078 
8079 		sym_op->aead.aad.phys_addr =
8080 				rte_pktmbuf_iova(ut_params->ibuf);
8081 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
8082 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
8083 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8084 			tdata->aad.len);
8085 
8086 		/* Append IV at the end of the crypto operation*/
8087 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8088 				uint8_t *, IV_OFFSET);
8089 
8090 		/* Copy IV 1 byte after the IV pointer, according to the API */
8091 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8092 		debug_hexdump(stdout, "iv:", iv_ptr,
8093 			tdata->iv.len);
8094 	} else {
8095 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
8096 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8097 				aad_pad_len);
8098 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8099 				"no room to append aad");
8100 
8101 		sym_op->aead.aad.phys_addr =
8102 				rte_pktmbuf_iova(ut_params->ibuf);
8103 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8104 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8105 			tdata->aad.len);
8106 
8107 		/* Append IV at the end of the crypto operation*/
8108 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8109 				uint8_t *, IV_OFFSET);
8110 
8111 		if (tdata->iv.len == 0) {
8112 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8113 			debug_hexdump(stdout, "iv:", iv_ptr,
8114 				AES_GCM_J0_LENGTH);
8115 		} else {
8116 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8117 			debug_hexdump(stdout, "iv:", iv_ptr,
8118 				tdata->iv.len);
8119 		}
8120 	}
8121 
8122 	/* Append plaintext/ciphertext */
8123 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8124 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8125 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8126 				plaintext_pad_len);
8127 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8128 
8129 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8130 		debug_hexdump(stdout, "plaintext:", plaintext,
8131 				tdata->plaintext.len);
8132 
8133 		if (ut_params->obuf) {
8134 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8135 					ut_params->obuf,
8136 					plaintext_pad_len + aad_pad_len);
8137 			TEST_ASSERT_NOT_NULL(ciphertext,
8138 					"no room to append ciphertext");
8139 
8140 			memset(ciphertext + aad_pad_len, 0,
8141 					tdata->ciphertext.len);
8142 		}
8143 	} else {
8144 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8145 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8146 				plaintext_pad_len);
8147 		TEST_ASSERT_NOT_NULL(ciphertext,
8148 				"no room to append ciphertext");
8149 
8150 		memcpy(ciphertext, tdata->ciphertext.data,
8151 				tdata->ciphertext.len);
8152 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8153 				tdata->ciphertext.len);
8154 
8155 		if (ut_params->obuf) {
8156 			plaintext = (uint8_t *)rte_pktmbuf_append(
8157 					ut_params->obuf,
8158 					plaintext_pad_len + aad_pad_len);
8159 			TEST_ASSERT_NOT_NULL(plaintext,
8160 					"no room to append plaintext");
8161 
8162 			memset(plaintext + aad_pad_len, 0,
8163 					tdata->plaintext.len);
8164 		}
8165 	}
8166 
8167 	/* Append digest data */
8168 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8169 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8170 				ut_params->obuf ? ut_params->obuf :
8171 						ut_params->ibuf,
8172 						tdata->auth_tag.len);
8173 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8174 				"no room to append digest");
8175 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8176 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8177 				ut_params->obuf ? ut_params->obuf :
8178 						ut_params->ibuf,
8179 						plaintext_pad_len +
8180 						aad_pad_len);
8181 	} else {
8182 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8183 				ut_params->ibuf, tdata->auth_tag.len);
8184 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8185 				"no room to append digest");
8186 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8187 				ut_params->ibuf,
8188 				plaintext_pad_len + aad_pad_len);
8189 
8190 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8191 			tdata->auth_tag.len);
8192 		debug_hexdump(stdout, "digest:",
8193 			sym_op->aead.digest.data,
8194 			tdata->auth_tag.len);
8195 	}
8196 
8197 	sym_op->aead.data.length = tdata->plaintext.len;
8198 	sym_op->aead.data.offset = aad_pad_len;
8199 
8200 	return 0;
8201 }
8202 
8203 static int
8204 test_authenticated_encryption(const struct aead_test_data *tdata)
8205 {
8206 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8207 	struct crypto_unittest_params *ut_params = &unittest_params;
8208 
8209 	int retval;
8210 	uint8_t *ciphertext, *auth_tag;
8211 	uint16_t plaintext_pad_len;
8212 	uint32_t i;
8213 	struct rte_cryptodev_info dev_info;
8214 
8215 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8216 	uint64_t feat_flags = dev_info.feature_flags;
8217 
8218 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8219 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8220 		printf("Device doesn't support RAW data-path APIs.\n");
8221 		return TEST_SKIPPED;
8222 	}
8223 
8224 	/* Verify the capabilities */
8225 	struct rte_cryptodev_sym_capability_idx cap_idx;
8226 	const struct rte_cryptodev_symmetric_capability *capability;
8227 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8228 	cap_idx.algo.aead = tdata->algo;
8229 	capability = rte_cryptodev_sym_capability_get(
8230 			ts_params->valid_devs[0], &cap_idx);
8231 	if (capability == NULL)
8232 		return TEST_SKIPPED;
8233 	if (rte_cryptodev_sym_capability_check_aead(
8234 			capability, tdata->key.len, tdata->auth_tag.len,
8235 			tdata->aad.len, tdata->iv.len))
8236 		return TEST_SKIPPED;
8237 
8238 	/* Create AEAD session */
8239 	retval = create_aead_session(ts_params->valid_devs[0],
8240 			tdata->algo,
8241 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8242 			tdata->key.data, tdata->key.len,
8243 			tdata->aad.len, tdata->auth_tag.len,
8244 			tdata->iv.len);
8245 	if (retval < 0)
8246 		return retval;
8247 
8248 	if (tdata->aad.len > MBUF_SIZE) {
8249 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8250 		/* Populate full size of add data */
8251 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8252 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8253 	} else
8254 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8255 
8256 	/* clear mbuf payload */
8257 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8258 			rte_pktmbuf_tailroom(ut_params->ibuf));
8259 
8260 	/* Create AEAD operation */
8261 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8262 	if (retval < 0)
8263 		return retval;
8264 
8265 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8266 
8267 	ut_params->op->sym->m_src = ut_params->ibuf;
8268 
8269 	/* Process crypto operation */
8270 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8271 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8272 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8273 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8274 				ut_params->op, 0, 0, 0, 0);
8275 	else
8276 		TEST_ASSERT_NOT_NULL(
8277 			process_crypto_request(ts_params->valid_devs[0],
8278 			ut_params->op), "failed to process sym crypto op");
8279 
8280 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8281 			"crypto op processing failed");
8282 
8283 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8284 
8285 	if (ut_params->op->sym->m_dst) {
8286 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8287 				uint8_t *);
8288 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8289 				uint8_t *, plaintext_pad_len);
8290 	} else {
8291 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8292 				uint8_t *,
8293 				ut_params->op->sym->cipher.data.offset);
8294 		auth_tag = ciphertext + plaintext_pad_len;
8295 	}
8296 
8297 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8298 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8299 
8300 	/* Validate obuf */
8301 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8302 			ciphertext,
8303 			tdata->ciphertext.data,
8304 			tdata->ciphertext.len,
8305 			"Ciphertext data not as expected");
8306 
8307 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8308 			auth_tag,
8309 			tdata->auth_tag.data,
8310 			tdata->auth_tag.len,
8311 			"Generated auth tag not as expected");
8312 
8313 	return 0;
8314 
8315 }
8316 
8317 #ifdef RTE_LIB_SECURITY
8318 static int
8319 security_proto_supported(enum rte_security_session_action_type action,
8320 	enum rte_security_session_protocol proto)
8321 {
8322 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8323 
8324 	const struct rte_security_capability *capabilities;
8325 	const struct rte_security_capability *capability;
8326 	uint16_t i = 0;
8327 
8328 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8329 				rte_cryptodev_get_sec_ctx(
8330 				ts_params->valid_devs[0]);
8331 
8332 
8333 	capabilities = rte_security_capabilities_get(ctx);
8334 
8335 	if (capabilities == NULL)
8336 		return -ENOTSUP;
8337 
8338 	while ((capability = &capabilities[i++])->action !=
8339 			RTE_SECURITY_ACTION_TYPE_NONE) {
8340 		if (capability->action == action &&
8341 				capability->protocol == proto)
8342 			return 0;
8343 	}
8344 
8345 	return -ENOTSUP;
8346 }
8347 
8348 /* Basic algorithm run function for async inplace mode.
8349  * Creates a session from input parameters and runs one operation
8350  * on input_vec. Checks the output of the crypto operation against
8351  * output_vec.
8352  */
8353 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8354 			   enum rte_crypto_auth_operation opa,
8355 			   const uint8_t *input_vec, unsigned int input_vec_len,
8356 			   const uint8_t *output_vec,
8357 			   unsigned int output_vec_len,
8358 			   enum rte_crypto_cipher_algorithm cipher_alg,
8359 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8360 			   enum rte_crypto_auth_algorithm auth_alg,
8361 			   const uint8_t *auth_key, uint32_t auth_key_len,
8362 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8363 			   uint8_t packet_direction, uint8_t sn_size,
8364 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8365 {
8366 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8367 	struct crypto_unittest_params *ut_params = &unittest_params;
8368 	uint8_t *plaintext;
8369 	int ret = TEST_SUCCESS;
8370 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8371 				rte_cryptodev_get_sec_ctx(
8372 				ts_params->valid_devs[0]);
8373 
8374 	/* Verify the capabilities */
8375 	struct rte_security_capability_idx sec_cap_idx;
8376 
8377 	sec_cap_idx.action = ut_params->type;
8378 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8379 	sec_cap_idx.pdcp.domain = domain;
8380 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8381 		return TEST_SKIPPED;
8382 
8383 	/* Generate test mbuf data */
8384 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8385 
8386 	/* clear mbuf payload */
8387 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8388 			rte_pktmbuf_tailroom(ut_params->ibuf));
8389 
8390 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8391 						  input_vec_len);
8392 	memcpy(plaintext, input_vec, input_vec_len);
8393 
8394 	/* Out of place support */
8395 	if (oop) {
8396 		/*
8397 		 * For out-op-place we need to alloc another mbuf
8398 		 */
8399 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8400 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8401 	}
8402 
8403 	/* Setup Cipher Parameters */
8404 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8405 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8406 	ut_params->cipher_xform.cipher.op = opc;
8407 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8408 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8409 	ut_params->cipher_xform.cipher.iv.length =
8410 				packet_direction ? 4 : 0;
8411 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8412 
8413 	/* Setup HMAC Parameters if ICV header is required */
8414 	if (auth_alg != 0) {
8415 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8416 		ut_params->auth_xform.next = NULL;
8417 		ut_params->auth_xform.auth.algo = auth_alg;
8418 		ut_params->auth_xform.auth.op = opa;
8419 		ut_params->auth_xform.auth.key.data = auth_key;
8420 		ut_params->auth_xform.auth.key.length = auth_key_len;
8421 
8422 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8423 	} else {
8424 		ut_params->cipher_xform.next = NULL;
8425 	}
8426 
8427 	struct rte_security_session_conf sess_conf = {
8428 		.action_type = ut_params->type,
8429 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8430 		{.pdcp = {
8431 			.bearer = bearer,
8432 			.domain = domain,
8433 			.pkt_dir = packet_direction,
8434 			.sn_size = sn_size,
8435 			.hfn = packet_direction ? 0 : hfn,
8436 			/**
8437 			 * hfn can be set as pdcp_test_hfn[i]
8438 			 * if hfn_ovrd is not set. Here, PDCP
8439 			 * packet direction is just used to
8440 			 * run half of the cases with session
8441 			 * HFN and other half with per packet
8442 			 * HFN.
8443 			 */
8444 			.hfn_threshold = hfn_threshold,
8445 			.hfn_ovrd = packet_direction ? 1 : 0,
8446 			.sdap_enabled = sdap,
8447 		} },
8448 		.crypto_xform = &ut_params->cipher_xform
8449 	};
8450 
8451 	/* Create security session */
8452 	ut_params->sec_session = rte_security_session_create(ctx,
8453 				&sess_conf, ts_params->session_mpool,
8454 				ts_params->session_priv_mpool);
8455 
8456 	if (!ut_params->sec_session) {
8457 		printf("TestCase %s()-%d line %d failed %s: ",
8458 			__func__, i, __LINE__, "Failed to allocate session");
8459 		ret = TEST_FAILED;
8460 		goto on_err;
8461 	}
8462 
8463 	/* Generate crypto op data structure */
8464 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8465 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8466 	if (!ut_params->op) {
8467 		printf("TestCase %s()-%d line %d failed %s: ",
8468 			__func__, i, __LINE__,
8469 			"Failed to allocate symmetric crypto operation struct");
8470 		ret = TEST_FAILED;
8471 		goto on_err;
8472 	}
8473 
8474 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8475 					uint32_t *, IV_OFFSET);
8476 	*per_pkt_hfn = packet_direction ? hfn : 0;
8477 
8478 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8479 
8480 	/* set crypto operation source mbuf */
8481 	ut_params->op->sym->m_src = ut_params->ibuf;
8482 	if (oop)
8483 		ut_params->op->sym->m_dst = ut_params->obuf;
8484 
8485 	/* Process crypto operation */
8486 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8487 		== NULL) {
8488 		printf("TestCase %s()-%d line %d failed %s: ",
8489 			__func__, i, __LINE__,
8490 			"failed to process sym crypto op");
8491 		ret = TEST_FAILED;
8492 		goto on_err;
8493 	}
8494 
8495 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8496 		printf("TestCase %s()-%d line %d failed %s: ",
8497 			__func__, i, __LINE__, "crypto op processing failed");
8498 		ret = TEST_FAILED;
8499 		goto on_err;
8500 	}
8501 
8502 	/* Validate obuf */
8503 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8504 			uint8_t *);
8505 	if (oop) {
8506 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8507 				uint8_t *);
8508 	}
8509 
8510 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8511 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8512 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8513 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8514 		ret = TEST_FAILED;
8515 		goto on_err;
8516 	}
8517 
8518 on_err:
8519 	rte_crypto_op_free(ut_params->op);
8520 	ut_params->op = NULL;
8521 
8522 	if (ut_params->sec_session)
8523 		rte_security_session_destroy(ctx, ut_params->sec_session);
8524 	ut_params->sec_session = NULL;
8525 
8526 	rte_pktmbuf_free(ut_params->ibuf);
8527 	ut_params->ibuf = NULL;
8528 	if (oop) {
8529 		rte_pktmbuf_free(ut_params->obuf);
8530 		ut_params->obuf = NULL;
8531 	}
8532 
8533 	return ret;
8534 }
8535 
8536 static int
8537 test_pdcp_proto_SGL(int i, int oop,
8538 	enum rte_crypto_cipher_operation opc,
8539 	enum rte_crypto_auth_operation opa,
8540 	uint8_t *input_vec,
8541 	unsigned int input_vec_len,
8542 	uint8_t *output_vec,
8543 	unsigned int output_vec_len,
8544 	uint32_t fragsz,
8545 	uint32_t fragsz_oop)
8546 {
8547 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8548 	struct crypto_unittest_params *ut_params = &unittest_params;
8549 	uint8_t *plaintext;
8550 	struct rte_mbuf *buf, *buf_oop = NULL;
8551 	int ret = TEST_SUCCESS;
8552 	int to_trn = 0;
8553 	int to_trn_tbl[16];
8554 	int segs = 1;
8555 	unsigned int trn_data = 0;
8556 	struct rte_cryptodev_info dev_info;
8557 	uint64_t feat_flags;
8558 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8559 				rte_cryptodev_get_sec_ctx(
8560 				ts_params->valid_devs[0]);
8561 	struct rte_mbuf *temp_mbuf;
8562 
8563 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8564 	feat_flags = dev_info.feature_flags;
8565 
8566 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8567 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8568 		printf("Device does not support RAW data-path APIs.\n");
8569 		return -ENOTSUP;
8570 	}
8571 	/* Verify the capabilities */
8572 	struct rte_security_capability_idx sec_cap_idx;
8573 
8574 	sec_cap_idx.action = ut_params->type;
8575 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8576 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8577 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8578 		return TEST_SKIPPED;
8579 
8580 	if (fragsz > input_vec_len)
8581 		fragsz = input_vec_len;
8582 
8583 	uint16_t plaintext_len = fragsz;
8584 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8585 
8586 	if (fragsz_oop > output_vec_len)
8587 		frag_size_oop = output_vec_len;
8588 
8589 	int ecx = 0;
8590 	if (input_vec_len % fragsz != 0) {
8591 		if (input_vec_len / fragsz + 1 > 16)
8592 			return 1;
8593 	} else if (input_vec_len / fragsz > 16)
8594 		return 1;
8595 
8596 	/* Out of place support */
8597 	if (oop) {
8598 		/*
8599 		 * For out-op-place we need to alloc another mbuf
8600 		 */
8601 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8602 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8603 		buf_oop = ut_params->obuf;
8604 	}
8605 
8606 	/* Generate test mbuf data */
8607 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8608 
8609 	/* clear mbuf payload */
8610 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8611 			rte_pktmbuf_tailroom(ut_params->ibuf));
8612 
8613 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8614 						  plaintext_len);
8615 	memcpy(plaintext, input_vec, plaintext_len);
8616 	trn_data += plaintext_len;
8617 
8618 	buf = ut_params->ibuf;
8619 
8620 	/*
8621 	 * Loop until no more fragments
8622 	 */
8623 
8624 	while (trn_data < input_vec_len) {
8625 		++segs;
8626 		to_trn = (input_vec_len - trn_data < fragsz) ?
8627 				(input_vec_len - trn_data) : fragsz;
8628 
8629 		to_trn_tbl[ecx++] = to_trn;
8630 
8631 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8632 		buf = buf->next;
8633 
8634 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8635 				rte_pktmbuf_tailroom(buf));
8636 
8637 		/* OOP */
8638 		if (oop && !fragsz_oop) {
8639 			buf_oop->next =
8640 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8641 			buf_oop = buf_oop->next;
8642 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8643 					0, rte_pktmbuf_tailroom(buf_oop));
8644 			rte_pktmbuf_append(buf_oop, to_trn);
8645 		}
8646 
8647 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8648 				to_trn);
8649 
8650 		memcpy(plaintext, input_vec + trn_data, to_trn);
8651 		trn_data += to_trn;
8652 	}
8653 
8654 	ut_params->ibuf->nb_segs = segs;
8655 
8656 	segs = 1;
8657 	if (fragsz_oop && oop) {
8658 		to_trn = 0;
8659 		ecx = 0;
8660 
8661 		trn_data = frag_size_oop;
8662 		while (trn_data < output_vec_len) {
8663 			++segs;
8664 			to_trn =
8665 				(output_vec_len - trn_data <
8666 						frag_size_oop) ?
8667 				(output_vec_len - trn_data) :
8668 						frag_size_oop;
8669 
8670 			to_trn_tbl[ecx++] = to_trn;
8671 
8672 			buf_oop->next =
8673 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8674 			buf_oop = buf_oop->next;
8675 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8676 					0, rte_pktmbuf_tailroom(buf_oop));
8677 			rte_pktmbuf_append(buf_oop, to_trn);
8678 
8679 			trn_data += to_trn;
8680 		}
8681 		ut_params->obuf->nb_segs = segs;
8682 	}
8683 
8684 	/* Setup Cipher Parameters */
8685 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8686 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8687 	ut_params->cipher_xform.cipher.op = opc;
8688 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8689 	ut_params->cipher_xform.cipher.key.length =
8690 					pdcp_test_params[i].cipher_key_len;
8691 	ut_params->cipher_xform.cipher.iv.length = 0;
8692 
8693 	/* Setup HMAC Parameters if ICV header is required */
8694 	if (pdcp_test_params[i].auth_alg != 0) {
8695 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8696 		ut_params->auth_xform.next = NULL;
8697 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8698 		ut_params->auth_xform.auth.op = opa;
8699 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8700 		ut_params->auth_xform.auth.key.length =
8701 					pdcp_test_params[i].auth_key_len;
8702 
8703 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8704 	} else {
8705 		ut_params->cipher_xform.next = NULL;
8706 	}
8707 
8708 	struct rte_security_session_conf sess_conf = {
8709 		.action_type = ut_params->type,
8710 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8711 		{.pdcp = {
8712 			.bearer = pdcp_test_bearer[i],
8713 			.domain = pdcp_test_params[i].domain,
8714 			.pkt_dir = pdcp_test_packet_direction[i],
8715 			.sn_size = pdcp_test_data_sn_size[i],
8716 			.hfn = pdcp_test_hfn[i],
8717 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8718 			.hfn_ovrd = 0,
8719 		} },
8720 		.crypto_xform = &ut_params->cipher_xform
8721 	};
8722 
8723 	/* Create security session */
8724 	ut_params->sec_session = rte_security_session_create(ctx,
8725 				&sess_conf, ts_params->session_mpool,
8726 				ts_params->session_priv_mpool);
8727 
8728 	if (!ut_params->sec_session) {
8729 		printf("TestCase %s()-%d line %d failed %s: ",
8730 			__func__, i, __LINE__, "Failed to allocate session");
8731 		ret = TEST_FAILED;
8732 		goto on_err;
8733 	}
8734 
8735 	/* Generate crypto op data structure */
8736 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8737 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8738 	if (!ut_params->op) {
8739 		printf("TestCase %s()-%d line %d failed %s: ",
8740 			__func__, i, __LINE__,
8741 			"Failed to allocate symmetric crypto operation struct");
8742 		ret = TEST_FAILED;
8743 		goto on_err;
8744 	}
8745 
8746 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8747 
8748 	/* set crypto operation source mbuf */
8749 	ut_params->op->sym->m_src = ut_params->ibuf;
8750 	if (oop)
8751 		ut_params->op->sym->m_dst = ut_params->obuf;
8752 
8753 	/* Process crypto operation */
8754 	temp_mbuf = ut_params->op->sym->m_src;
8755 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8756 		/* filling lengths */
8757 		while (temp_mbuf) {
8758 			ut_params->op->sym->cipher.data.length
8759 				+= temp_mbuf->pkt_len;
8760 			ut_params->op->sym->auth.data.length
8761 				+= temp_mbuf->pkt_len;
8762 			temp_mbuf = temp_mbuf->next;
8763 		}
8764 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8765 			ut_params->op, 1, 1, 0, 0);
8766 	} else {
8767 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8768 							ut_params->op);
8769 	}
8770 	if (ut_params->op == NULL) {
8771 		printf("TestCase %s()-%d line %d failed %s: ",
8772 			__func__, i, __LINE__,
8773 			"failed to process sym crypto op");
8774 		ret = TEST_FAILED;
8775 		goto on_err;
8776 	}
8777 
8778 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8779 		printf("TestCase %s()-%d line %d failed %s: ",
8780 			__func__, i, __LINE__, "crypto op processing failed");
8781 		ret = TEST_FAILED;
8782 		goto on_err;
8783 	}
8784 
8785 	/* Validate obuf */
8786 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8787 			uint8_t *);
8788 	if (oop) {
8789 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8790 				uint8_t *);
8791 	}
8792 	if (fragsz_oop)
8793 		fragsz = frag_size_oop;
8794 	if (memcmp(ciphertext, output_vec, fragsz)) {
8795 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8796 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8797 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8798 		ret = TEST_FAILED;
8799 		goto on_err;
8800 	}
8801 
8802 	buf = ut_params->op->sym->m_src->next;
8803 	if (oop)
8804 		buf = ut_params->op->sym->m_dst->next;
8805 
8806 	unsigned int off = fragsz;
8807 
8808 	ecx = 0;
8809 	while (buf) {
8810 		ciphertext = rte_pktmbuf_mtod(buf,
8811 				uint8_t *);
8812 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8813 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8814 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8815 			rte_hexdump(stdout, "reference", output_vec + off,
8816 					to_trn_tbl[ecx]);
8817 			ret = TEST_FAILED;
8818 			goto on_err;
8819 		}
8820 		off += to_trn_tbl[ecx++];
8821 		buf = buf->next;
8822 	}
8823 on_err:
8824 	rte_crypto_op_free(ut_params->op);
8825 	ut_params->op = NULL;
8826 
8827 	if (ut_params->sec_session)
8828 		rte_security_session_destroy(ctx, ut_params->sec_session);
8829 	ut_params->sec_session = NULL;
8830 
8831 	rte_pktmbuf_free(ut_params->ibuf);
8832 	ut_params->ibuf = NULL;
8833 	if (oop) {
8834 		rte_pktmbuf_free(ut_params->obuf);
8835 		ut_params->obuf = NULL;
8836 	}
8837 
8838 	return ret;
8839 }
8840 
8841 int
8842 test_pdcp_proto_cplane_encap(int i)
8843 {
8844 	return test_pdcp_proto(
8845 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8846 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8847 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8848 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8849 		pdcp_test_params[i].cipher_key_len,
8850 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8851 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8852 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8853 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8854 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8855 }
8856 
8857 int
8858 test_pdcp_proto_uplane_encap(int i)
8859 {
8860 	return test_pdcp_proto(
8861 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8862 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8863 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8864 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8865 		pdcp_test_params[i].cipher_key_len,
8866 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8867 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8868 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8869 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8870 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8871 }
8872 
8873 int
8874 test_pdcp_proto_uplane_encap_with_int(int i)
8875 {
8876 	return test_pdcp_proto(
8877 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8878 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8879 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8880 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8881 		pdcp_test_params[i].cipher_key_len,
8882 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8883 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8884 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8885 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8886 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8887 }
8888 
8889 int
8890 test_pdcp_proto_cplane_decap(int i)
8891 {
8892 	return test_pdcp_proto(
8893 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8894 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8895 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8896 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8897 		pdcp_test_params[i].cipher_key_len,
8898 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8899 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8900 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8901 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8902 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8903 }
8904 
8905 int
8906 test_pdcp_proto_uplane_decap(int i)
8907 {
8908 	return test_pdcp_proto(
8909 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8910 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8911 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8912 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8913 		pdcp_test_params[i].cipher_key_len,
8914 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8915 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8916 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8917 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8918 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8919 }
8920 
8921 int
8922 test_pdcp_proto_uplane_decap_with_int(int i)
8923 {
8924 	return test_pdcp_proto(
8925 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8926 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8927 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8928 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8929 		pdcp_test_params[i].cipher_key_len,
8930 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8931 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8932 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8933 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8934 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8935 }
8936 
8937 static int
8938 test_PDCP_PROTO_SGL_in_place_32B(void)
8939 {
8940 	/* i can be used for running any PDCP case
8941 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8942 	 */
8943 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8944 	return test_pdcp_proto_SGL(i, IN_PLACE,
8945 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8946 			RTE_CRYPTO_AUTH_OP_GENERATE,
8947 			pdcp_test_data_in[i],
8948 			pdcp_test_data_in_len[i],
8949 			pdcp_test_data_out[i],
8950 			pdcp_test_data_in_len[i]+4,
8951 			32, 0);
8952 }
8953 static int
8954 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8955 {
8956 	/* i can be used for running any PDCP case
8957 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8958 	 */
8959 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8960 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8961 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8962 			RTE_CRYPTO_AUTH_OP_GENERATE,
8963 			pdcp_test_data_in[i],
8964 			pdcp_test_data_in_len[i],
8965 			pdcp_test_data_out[i],
8966 			pdcp_test_data_in_len[i]+4,
8967 			32, 128);
8968 }
8969 static int
8970 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8971 {
8972 	/* i can be used for running any PDCP case
8973 	 * In this case it is uplane 18-bit AES DL encap
8974 	 */
8975 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8976 			+ DOWNLINK;
8977 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8978 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8979 			RTE_CRYPTO_AUTH_OP_GENERATE,
8980 			pdcp_test_data_in[i],
8981 			pdcp_test_data_in_len[i],
8982 			pdcp_test_data_out[i],
8983 			pdcp_test_data_in_len[i],
8984 			32, 40);
8985 }
8986 static int
8987 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8988 {
8989 	/* i can be used for running any PDCP case
8990 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8991 	 */
8992 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8993 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8994 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8995 			RTE_CRYPTO_AUTH_OP_GENERATE,
8996 			pdcp_test_data_in[i],
8997 			pdcp_test_data_in_len[i],
8998 			pdcp_test_data_out[i],
8999 			pdcp_test_data_in_len[i]+4,
9000 			128, 32);
9001 }
9002 
9003 static int
9004 test_PDCP_SDAP_PROTO_encap_all(void)
9005 {
9006 	int i = 0, size = 0;
9007 	int err, all_err = TEST_SUCCESS;
9008 	const struct pdcp_sdap_test *cur_test;
9009 
9010 	size = RTE_DIM(list_pdcp_sdap_tests);
9011 
9012 	for (i = 0; i < size; i++) {
9013 		cur_test = &list_pdcp_sdap_tests[i];
9014 		err = test_pdcp_proto(
9015 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9016 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9017 			cur_test->in_len, cur_test->data_out,
9018 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9019 			cur_test->param.cipher_alg, cur_test->cipher_key,
9020 			cur_test->param.cipher_key_len,
9021 			cur_test->param.auth_alg,
9022 			cur_test->auth_key, cur_test->param.auth_key_len,
9023 			cur_test->bearer, cur_test->param.domain,
9024 			cur_test->packet_direction, cur_test->sn_size,
9025 			cur_test->hfn,
9026 			cur_test->hfn_threshold, SDAP_ENABLED);
9027 		if (err) {
9028 			printf("\t%d) %s: Encapsulation failed\n",
9029 					cur_test->test_idx,
9030 					cur_test->param.name);
9031 			err = TEST_FAILED;
9032 		} else {
9033 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
9034 					cur_test->param.name);
9035 			err = TEST_SUCCESS;
9036 		}
9037 		all_err += err;
9038 	}
9039 
9040 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9041 
9042 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9043 }
9044 
9045 static int
9046 test_PDCP_PROTO_short_mac(void)
9047 {
9048 	int i = 0, size = 0;
9049 	int err, all_err = TEST_SUCCESS;
9050 	const struct pdcp_short_mac_test *cur_test;
9051 
9052 	size = RTE_DIM(list_pdcp_smac_tests);
9053 
9054 	for (i = 0; i < size; i++) {
9055 		cur_test = &list_pdcp_smac_tests[i];
9056 		err = test_pdcp_proto(
9057 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9058 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9059 			cur_test->in_len, cur_test->data_out,
9060 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9061 			RTE_CRYPTO_CIPHER_NULL, NULL,
9062 			0, cur_test->param.auth_alg,
9063 			cur_test->auth_key, cur_test->param.auth_key_len,
9064 			0, cur_test->param.domain, 0, 0,
9065 			0, 0, 0);
9066 		if (err) {
9067 			printf("\t%d) %s: Short MAC test failed\n",
9068 					cur_test->test_idx,
9069 					cur_test->param.name);
9070 			err = TEST_FAILED;
9071 		} else {
9072 			printf("\t%d) %s: Short MAC test PASS\n",
9073 					cur_test->test_idx,
9074 					cur_test->param.name);
9075 			rte_hexdump(stdout, "MAC I",
9076 				    cur_test->data_out + cur_test->in_len + 2,
9077 				    2);
9078 			err = TEST_SUCCESS;
9079 		}
9080 		all_err += err;
9081 	}
9082 
9083 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9084 
9085 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9086 
9087 }
9088 
9089 static int
9090 test_PDCP_SDAP_PROTO_decap_all(void)
9091 {
9092 	int i = 0, size = 0;
9093 	int err, all_err = TEST_SUCCESS;
9094 	const struct pdcp_sdap_test *cur_test;
9095 
9096 	size = RTE_DIM(list_pdcp_sdap_tests);
9097 
9098 	for (i = 0; i < size; i++) {
9099 		cur_test = &list_pdcp_sdap_tests[i];
9100 		err = test_pdcp_proto(
9101 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9102 			RTE_CRYPTO_AUTH_OP_VERIFY,
9103 			cur_test->data_out,
9104 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9105 			cur_test->data_in, cur_test->in_len,
9106 			cur_test->param.cipher_alg,
9107 			cur_test->cipher_key, cur_test->param.cipher_key_len,
9108 			cur_test->param.auth_alg, cur_test->auth_key,
9109 			cur_test->param.auth_key_len, cur_test->bearer,
9110 			cur_test->param.domain, cur_test->packet_direction,
9111 			cur_test->sn_size, cur_test->hfn,
9112 			cur_test->hfn_threshold, SDAP_ENABLED);
9113 		if (err) {
9114 			printf("\t%d) %s: Decapsulation failed\n",
9115 					cur_test->test_idx,
9116 					cur_test->param.name);
9117 			err = TEST_FAILED;
9118 		} else {
9119 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9120 					cur_test->param.name);
9121 			err = TEST_SUCCESS;
9122 		}
9123 		all_err += err;
9124 	}
9125 
9126 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9127 
9128 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9129 }
9130 
9131 static int
9132 test_ipsec_proto_process(const struct ipsec_test_data td[],
9133 			 struct ipsec_test_data res_d[],
9134 			 int nb_td,
9135 			 bool silent,
9136 			 const struct ipsec_test_flags *flags)
9137 {
9138 	uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
9139 				0x0000, 0x001a};
9140 	uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
9141 				0xe82c, 0x4887};
9142 	const struct rte_ipv4_hdr *ipv4 =
9143 			(const struct rte_ipv4_hdr *)td[0].output_text.data;
9144 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9145 	struct crypto_unittest_params *ut_params = &unittest_params;
9146 	struct rte_security_capability_idx sec_cap_idx;
9147 	const struct rte_security_capability *sec_cap;
9148 	struct rte_security_ipsec_xform ipsec_xform;
9149 	uint8_t dev_id = ts_params->valid_devs[0];
9150 	enum rte_security_ipsec_sa_direction dir;
9151 	struct ipsec_test_data *res_d_tmp = NULL;
9152 	int salt_len, i, ret = TEST_SUCCESS;
9153 	struct rte_security_ctx *ctx;
9154 	uint8_t *input_text;
9155 	uint32_t src, dst;
9156 	uint32_t verify;
9157 
9158 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9159 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9160 
9161 	/* Use first test data to create session */
9162 
9163 	/* Copy IPsec xform */
9164 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9165 
9166 	dir = ipsec_xform.direction;
9167 	verify = flags->tunnel_hdr_verify;
9168 
9169 	memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr));
9170 	memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr));
9171 
9172 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9173 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9174 			src += 1;
9175 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9176 			dst += 1;
9177 	}
9178 
9179 	if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
9180 		if (td->ipsec_xform.tunnel.type ==
9181 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
9182 			memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src,
9183 			       sizeof(src));
9184 			memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst,
9185 			       sizeof(dst));
9186 
9187 			if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
9188 				ipsec_xform.tunnel.ipv4.df = 0;
9189 
9190 			if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
9191 				ipsec_xform.tunnel.ipv4.df = 1;
9192 
9193 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9194 				ipsec_xform.tunnel.ipv4.dscp = 0;
9195 
9196 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9197 				ipsec_xform.tunnel.ipv4.dscp =
9198 						TEST_IPSEC_DSCP_VAL;
9199 
9200 		} else {
9201 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9202 				ipsec_xform.tunnel.ipv6.dscp = 0;
9203 
9204 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9205 				ipsec_xform.tunnel.ipv6.dscp =
9206 						TEST_IPSEC_DSCP_VAL;
9207 
9208 			memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
9209 			       sizeof(v6_src));
9210 			memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
9211 			       sizeof(v6_dst));
9212 		}
9213 	}
9214 
9215 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9216 
9217 	sec_cap_idx.action = ut_params->type;
9218 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9219 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9220 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9221 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9222 
9223 	if (flags->udp_encap)
9224 		ipsec_xform.options.udp_encap = 1;
9225 
9226 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9227 	if (sec_cap == NULL)
9228 		return TEST_SKIPPED;
9229 
9230 	/* Copy cipher session parameters */
9231 	if (td[0].aead) {
9232 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9233 		       sizeof(ut_params->aead_xform));
9234 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9235 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9236 
9237 		/* Verify crypto capabilities */
9238 		if (test_ipsec_crypto_caps_aead_verify(
9239 				sec_cap,
9240 				&ut_params->aead_xform) != 0) {
9241 			if (!silent)
9242 				RTE_LOG(INFO, USER1,
9243 					"Crypto capabilities not supported\n");
9244 			return TEST_SKIPPED;
9245 		}
9246 	} else if (td[0].auth_only) {
9247 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9248 		       sizeof(ut_params->auth_xform));
9249 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9250 
9251 		if (test_ipsec_crypto_caps_auth_verify(
9252 				sec_cap,
9253 				&ut_params->auth_xform) != 0) {
9254 			if (!silent)
9255 				RTE_LOG(INFO, USER1,
9256 					"Auth crypto capabilities not supported\n");
9257 			return TEST_SKIPPED;
9258 		}
9259 	} else {
9260 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
9261 		       sizeof(ut_params->cipher_xform));
9262 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9263 		       sizeof(ut_params->auth_xform));
9264 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
9265 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9266 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9267 
9268 		/* Verify crypto capabilities */
9269 
9270 		if (test_ipsec_crypto_caps_cipher_verify(
9271 				sec_cap,
9272 				&ut_params->cipher_xform) != 0) {
9273 			if (!silent)
9274 				RTE_LOG(INFO, USER1,
9275 					"Cipher crypto capabilities not supported\n");
9276 			return TEST_SKIPPED;
9277 		}
9278 
9279 		if (test_ipsec_crypto_caps_auth_verify(
9280 				sec_cap,
9281 				&ut_params->auth_xform) != 0) {
9282 			if (!silent)
9283 				RTE_LOG(INFO, USER1,
9284 					"Auth crypto capabilities not supported\n");
9285 			return TEST_SKIPPED;
9286 		}
9287 	}
9288 
9289 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9290 		return TEST_SKIPPED;
9291 
9292 	struct rte_security_session_conf sess_conf = {
9293 		.action_type = ut_params->type,
9294 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9295 	};
9296 
9297 	if (td[0].aead) {
9298 		salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9299 		memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9300 		sess_conf.ipsec = ipsec_xform;
9301 		sess_conf.crypto_xform = &ut_params->aead_xform;
9302 	} else if (td[0].auth_only) {
9303 		sess_conf.ipsec = ipsec_xform;
9304 		sess_conf.crypto_xform = &ut_params->auth_xform;
9305 	} else {
9306 		sess_conf.ipsec = ipsec_xform;
9307 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
9308 			sess_conf.crypto_xform = &ut_params->cipher_xform;
9309 			ut_params->cipher_xform.next = &ut_params->auth_xform;
9310 		} else {
9311 			sess_conf.crypto_xform = &ut_params->auth_xform;
9312 			ut_params->auth_xform.next = &ut_params->cipher_xform;
9313 		}
9314 	}
9315 
9316 	/* Create security session */
9317 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9318 					ts_params->session_mpool,
9319 					ts_params->session_priv_mpool);
9320 
9321 	if (ut_params->sec_session == NULL)
9322 		return TEST_SKIPPED;
9323 
9324 	for (i = 0; i < nb_td; i++) {
9325 		if (flags->antireplay &&
9326 		    (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) {
9327 			sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value;
9328 			ret = rte_security_session_update(ctx,
9329 				ut_params->sec_session, &sess_conf);
9330 			if (ret) {
9331 				printf("Could not update sequence number in "
9332 				       "session\n");
9333 				return TEST_SKIPPED;
9334 			}
9335 		}
9336 
9337 		/* Setup source mbuf payload */
9338 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9339 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9340 				rte_pktmbuf_tailroom(ut_params->ibuf));
9341 
9342 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9343 				td[i].input_text.len);
9344 
9345 		memcpy(input_text, td[i].input_text.data,
9346 		       td[i].input_text.len);
9347 
9348 		if (test_ipsec_pkt_update(input_text, flags))
9349 			return TEST_FAILED;
9350 
9351 		/* Generate crypto op data structure */
9352 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9353 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9354 		if (!ut_params->op) {
9355 			printf("TestCase %s line %d: %s\n",
9356 				__func__, __LINE__,
9357 				"failed to allocate crypto op");
9358 			ret = TEST_FAILED;
9359 			goto crypto_op_free;
9360 		}
9361 
9362 		/* Attach session to operation */
9363 		rte_security_attach_session(ut_params->op,
9364 					    ut_params->sec_session);
9365 
9366 		/* Set crypto operation mbufs */
9367 		ut_params->op->sym->m_src = ut_params->ibuf;
9368 		ut_params->op->sym->m_dst = NULL;
9369 
9370 		/* Copy IV in crypto operation when IV generation is disabled */
9371 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9372 		    ipsec_xform.options.iv_gen_disable == 1) {
9373 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9374 								uint8_t *,
9375 								IV_OFFSET);
9376 			int len;
9377 
9378 			if (td[i].aead)
9379 				len = td[i].xform.aead.aead.iv.length;
9380 			else
9381 				len = td[i].xform.chain.cipher.cipher.iv.length;
9382 
9383 			memcpy(iv, td[i].iv.data, len);
9384 		}
9385 
9386 		/* Process crypto operation */
9387 		process_crypto_request(dev_id, ut_params->op);
9388 
9389 		ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir,
9390 					      i + 1);
9391 		if (ret != TEST_SUCCESS)
9392 			goto crypto_op_free;
9393 
9394 		if (res_d != NULL)
9395 			res_d_tmp = &res_d[i];
9396 
9397 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9398 					      res_d_tmp, silent, flags);
9399 		if (ret != TEST_SUCCESS)
9400 			goto crypto_op_free;
9401 
9402 		ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
9403 					      flags, dir);
9404 		if (ret != TEST_SUCCESS)
9405 			goto crypto_op_free;
9406 
9407 		rte_crypto_op_free(ut_params->op);
9408 		ut_params->op = NULL;
9409 
9410 		rte_pktmbuf_free(ut_params->ibuf);
9411 		ut_params->ibuf = NULL;
9412 	}
9413 
9414 crypto_op_free:
9415 	rte_crypto_op_free(ut_params->op);
9416 	ut_params->op = NULL;
9417 
9418 	rte_pktmbuf_free(ut_params->ibuf);
9419 	ut_params->ibuf = NULL;
9420 
9421 	if (ut_params->sec_session)
9422 		rte_security_session_destroy(ctx, ut_params->sec_session);
9423 	ut_params->sec_session = NULL;
9424 
9425 	return ret;
9426 }
9427 
9428 static int
9429 test_ipsec_proto_known_vec(const void *test_data)
9430 {
9431 	struct ipsec_test_data td_outb;
9432 	struct ipsec_test_flags flags;
9433 
9434 	memset(&flags, 0, sizeof(flags));
9435 
9436 	memcpy(&td_outb, test_data, sizeof(td_outb));
9437 
9438 	if ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) &&
9439 	    (td_outb.aead || (td_outb.xform.chain.cipher.cipher.algo !=
9440 			RTE_CRYPTO_CIPHER_NULL))) {
9441 		/* Disable IV gen to be able to test with known vectors */
9442 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
9443 	}
9444 
9445 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9446 }
9447 
9448 static int
9449 test_ipsec_proto_known_vec_inb(const void *test_data)
9450 {
9451 	const struct ipsec_test_data *td = test_data;
9452 	struct ipsec_test_flags flags;
9453 	struct ipsec_test_data td_inb;
9454 
9455 	memset(&flags, 0, sizeof(flags));
9456 
9457 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
9458 		test_ipsec_td_in_from_out(td, &td_inb);
9459 	else
9460 		memcpy(&td_inb, td, sizeof(td_inb));
9461 
9462 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9463 }
9464 
9465 static int
9466 test_ipsec_proto_known_vec_fragmented(const void *test_data)
9467 {
9468 	struct ipsec_test_data td_outb;
9469 	struct ipsec_test_flags flags;
9470 
9471 	memset(&flags, 0, sizeof(flags));
9472 	flags.fragment = true;
9473 
9474 	memcpy(&td_outb, test_data, sizeof(td_outb));
9475 
9476 	/* Disable IV gen to be able to test with known vectors */
9477 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9478 
9479 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9480 }
9481 
9482 static int
9483 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9484 {
9485 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9486 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9487 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9488 	int ret;
9489 
9490 	if (flags->iv_gen ||
9491 	    flags->sa_expiry_pkts_soft ||
9492 	    flags->sa_expiry_pkts_hard)
9493 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9494 
9495 	for (i = 0; i < RTE_DIM(alg_list); i++) {
9496 		test_ipsec_td_prepare(alg_list[i].param1,
9497 				      alg_list[i].param2,
9498 				      flags,
9499 				      td_outb,
9500 				      nb_pkts);
9501 
9502 		if (!td_outb->aead) {
9503 			enum rte_crypto_cipher_algorithm cipher_alg;
9504 			enum rte_crypto_auth_algorithm auth_alg;
9505 
9506 			cipher_alg = td_outb->xform.chain.cipher.cipher.algo;
9507 			auth_alg = td_outb->xform.chain.auth.auth.algo;
9508 
9509 			/* ICV is not applicable for NULL auth */
9510 			if (flags->icv_corrupt &&
9511 			    auth_alg == RTE_CRYPTO_AUTH_NULL)
9512 				continue;
9513 
9514 			/* IV is not applicable for NULL cipher */
9515 			if (flags->iv_gen &&
9516 			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
9517 				continue;
9518 		}
9519 
9520 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9521 					       flags);
9522 		if (ret == TEST_SKIPPED)
9523 			continue;
9524 
9525 		if (ret == TEST_FAILED)
9526 			return TEST_FAILED;
9527 
9528 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9529 
9530 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9531 					       flags);
9532 		if (ret == TEST_SKIPPED)
9533 			continue;
9534 
9535 		if (ret == TEST_FAILED)
9536 			return TEST_FAILED;
9537 
9538 		if (flags->display_alg)
9539 			test_ipsec_display_alg(alg_list[i].param1,
9540 					       alg_list[i].param2);
9541 
9542 		pass_cnt++;
9543 	}
9544 
9545 	if (pass_cnt > 0)
9546 		return TEST_SUCCESS;
9547 	else
9548 		return TEST_SKIPPED;
9549 }
9550 
9551 static int
9552 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags)
9553 {
9554 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9555 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9556 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9557 	int ret;
9558 
9559 	for (i = 0; i < RTE_DIM(ah_alg_list); i++) {
9560 		test_ipsec_td_prepare(ah_alg_list[i].param1,
9561 				      ah_alg_list[i].param2,
9562 				      flags,
9563 				      td_outb,
9564 				      nb_pkts);
9565 
9566 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9567 					       flags);
9568 		if (ret == TEST_SKIPPED)
9569 			continue;
9570 
9571 		if (ret == TEST_FAILED)
9572 			return TEST_FAILED;
9573 
9574 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9575 
9576 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9577 					       flags);
9578 		if (ret == TEST_SKIPPED)
9579 			continue;
9580 
9581 		if (ret == TEST_FAILED)
9582 			return TEST_FAILED;
9583 
9584 		if (flags->display_alg)
9585 			test_ipsec_display_alg(ah_alg_list[i].param1,
9586 					       ah_alg_list[i].param2);
9587 
9588 		pass_cnt++;
9589 	}
9590 
9591 	if (pass_cnt > 0)
9592 		return TEST_SUCCESS;
9593 	else
9594 		return TEST_SKIPPED;
9595 }
9596 
9597 static int
9598 test_ipsec_proto_display_list(const void *data __rte_unused)
9599 {
9600 	struct ipsec_test_flags flags;
9601 
9602 	memset(&flags, 0, sizeof(flags));
9603 
9604 	flags.display_alg = true;
9605 
9606 	return test_ipsec_proto_all(&flags);
9607 }
9608 
9609 static int
9610 test_ipsec_proto_ah_tunnel_ipv4(const void *data __rte_unused)
9611 {
9612 	struct ipsec_test_flags flags;
9613 
9614 	memset(&flags, 0, sizeof(flags));
9615 
9616 	flags.ah = true;
9617 	flags.display_alg = true;
9618 
9619 	return test_ipsec_ah_proto_all(&flags);
9620 }
9621 
9622 static int
9623 test_ipsec_proto_ah_transport_ipv4(const void *data __rte_unused)
9624 {
9625 	struct ipsec_test_flags flags;
9626 
9627 	memset(&flags, 0, sizeof(flags));
9628 
9629 	flags.ah = true;
9630 	flags.transport = true;
9631 
9632 	return test_ipsec_ah_proto_all(&flags);
9633 }
9634 
9635 static int
9636 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9637 {
9638 	struct ipsec_test_flags flags;
9639 
9640 	memset(&flags, 0, sizeof(flags));
9641 
9642 	flags.iv_gen = true;
9643 
9644 	return test_ipsec_proto_all(&flags);
9645 }
9646 
9647 static int
9648 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9649 {
9650 	struct ipsec_test_flags flags;
9651 
9652 	memset(&flags, 0, sizeof(flags));
9653 
9654 	flags.sa_expiry_pkts_soft = true;
9655 
9656 	return test_ipsec_proto_all(&flags);
9657 }
9658 
9659 static int
9660 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9661 {
9662 	struct ipsec_test_flags flags;
9663 
9664 	memset(&flags, 0, sizeof(flags));
9665 
9666 	flags.sa_expiry_pkts_hard = true;
9667 
9668 	return test_ipsec_proto_all(&flags);
9669 }
9670 
9671 static int
9672 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9673 {
9674 	struct ipsec_test_flags flags;
9675 
9676 	memset(&flags, 0, sizeof(flags));
9677 
9678 	flags.icv_corrupt = true;
9679 
9680 	return test_ipsec_proto_all(&flags);
9681 }
9682 
9683 static int
9684 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9685 {
9686 	struct ipsec_test_flags flags;
9687 
9688 	memset(&flags, 0, sizeof(flags));
9689 
9690 	flags.udp_encap = true;
9691 
9692 	return test_ipsec_proto_all(&flags);
9693 }
9694 
9695 static int
9696 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9697 {
9698 	struct ipsec_test_flags flags;
9699 
9700 	memset(&flags, 0, sizeof(flags));
9701 
9702 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9703 
9704 	return test_ipsec_proto_all(&flags);
9705 }
9706 
9707 static int
9708 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9709 {
9710 	struct ipsec_test_flags flags;
9711 
9712 	memset(&flags, 0, sizeof(flags));
9713 
9714 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9715 
9716 	return test_ipsec_proto_all(&flags);
9717 }
9718 
9719 static int
9720 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9721 {
9722 	struct ipsec_test_flags flags;
9723 
9724 	memset(&flags, 0, sizeof(flags));
9725 
9726 	flags.udp_encap = true;
9727 	flags.udp_ports_verify = true;
9728 
9729 	return test_ipsec_proto_all(&flags);
9730 }
9731 
9732 static int
9733 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9734 {
9735 	struct ipsec_test_flags flags;
9736 
9737 	memset(&flags, 0, sizeof(flags));
9738 
9739 	flags.ip_csum = true;
9740 
9741 	return test_ipsec_proto_all(&flags);
9742 }
9743 
9744 static int
9745 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9746 {
9747 	struct ipsec_test_flags flags;
9748 
9749 	memset(&flags, 0, sizeof(flags));
9750 
9751 	flags.l4_csum = true;
9752 
9753 	return test_ipsec_proto_all(&flags);
9754 }
9755 
9756 static int
9757 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused)
9758 {
9759 	struct ipsec_test_flags flags;
9760 
9761 	memset(&flags, 0, sizeof(flags));
9762 
9763 	flags.ipv6 = false;
9764 	flags.tunnel_ipv6 = false;
9765 
9766 	return test_ipsec_proto_all(&flags);
9767 }
9768 
9769 static int
9770 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused)
9771 {
9772 	struct ipsec_test_flags flags;
9773 
9774 	memset(&flags, 0, sizeof(flags));
9775 
9776 	flags.ipv6 = true;
9777 	flags.tunnel_ipv6 = true;
9778 
9779 	return test_ipsec_proto_all(&flags);
9780 }
9781 
9782 static int
9783 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused)
9784 {
9785 	struct ipsec_test_flags flags;
9786 
9787 	memset(&flags, 0, sizeof(flags));
9788 
9789 	flags.ipv6 = false;
9790 	flags.tunnel_ipv6 = true;
9791 
9792 	return test_ipsec_proto_all(&flags);
9793 }
9794 
9795 static int
9796 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused)
9797 {
9798 	struct ipsec_test_flags flags;
9799 
9800 	memset(&flags, 0, sizeof(flags));
9801 
9802 	flags.ipv6 = true;
9803 	flags.tunnel_ipv6 = false;
9804 
9805 	return test_ipsec_proto_all(&flags);
9806 }
9807 
9808 static int
9809 test_ipsec_proto_transport_v4(const void *data __rte_unused)
9810 {
9811 	struct ipsec_test_flags flags;
9812 
9813 	memset(&flags, 0, sizeof(flags));
9814 
9815 	flags.ipv6 = false;
9816 	flags.transport = true;
9817 
9818 	return test_ipsec_proto_all(&flags);
9819 }
9820 
9821 static int
9822 test_ipsec_proto_transport_l4_csum(const void *data __rte_unused)
9823 {
9824 	struct ipsec_test_flags flags = {
9825 		.l4_csum = true,
9826 		.transport = true,
9827 	};
9828 
9829 	return test_ipsec_proto_all(&flags);
9830 }
9831 
9832 static int
9833 test_ipsec_proto_stats(const void *data __rte_unused)
9834 {
9835 	struct ipsec_test_flags flags;
9836 
9837 	memset(&flags, 0, sizeof(flags));
9838 
9839 	flags.stats_success = true;
9840 
9841 	return test_ipsec_proto_all(&flags);
9842 }
9843 
9844 static int
9845 test_ipsec_proto_pkt_fragment(const void *data __rte_unused)
9846 {
9847 	struct ipsec_test_flags flags;
9848 
9849 	memset(&flags, 0, sizeof(flags));
9850 
9851 	flags.fragment = true;
9852 
9853 	return test_ipsec_proto_all(&flags);
9854 
9855 }
9856 
9857 static int
9858 test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused)
9859 {
9860 	struct ipsec_test_flags flags;
9861 
9862 	memset(&flags, 0, sizeof(flags));
9863 
9864 	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
9865 
9866 	return test_ipsec_proto_all(&flags);
9867 }
9868 
9869 static int
9870 test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused)
9871 {
9872 	struct ipsec_test_flags flags;
9873 
9874 	memset(&flags, 0, sizeof(flags));
9875 
9876 	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
9877 
9878 	return test_ipsec_proto_all(&flags);
9879 }
9880 
9881 static int
9882 test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused)
9883 {
9884 	struct ipsec_test_flags flags;
9885 
9886 	memset(&flags, 0, sizeof(flags));
9887 
9888 	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
9889 
9890 	return test_ipsec_proto_all(&flags);
9891 }
9892 
9893 static int
9894 test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused)
9895 {
9896 	struct ipsec_test_flags flags;
9897 
9898 	memset(&flags, 0, sizeof(flags));
9899 
9900 	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
9901 
9902 	return test_ipsec_proto_all(&flags);
9903 }
9904 
9905 static int
9906 test_ipsec_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused)
9907 {
9908 	struct ipsec_test_flags flags;
9909 
9910 	memset(&flags, 0, sizeof(flags));
9911 
9912 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
9913 
9914 	return test_ipsec_proto_all(&flags);
9915 }
9916 
9917 static int
9918 test_ipsec_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused)
9919 {
9920 	struct ipsec_test_flags flags;
9921 
9922 	memset(&flags, 0, sizeof(flags));
9923 
9924 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
9925 
9926 	return test_ipsec_proto_all(&flags);
9927 }
9928 
9929 static int
9930 test_ipsec_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused)
9931 {
9932 	struct ipsec_test_flags flags;
9933 
9934 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9935 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9936 		return TEST_SKIPPED;
9937 
9938 	memset(&flags, 0, sizeof(flags));
9939 
9940 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
9941 
9942 	return test_ipsec_proto_all(&flags);
9943 }
9944 
9945 static int
9946 test_ipsec_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused)
9947 {
9948 	struct ipsec_test_flags flags;
9949 
9950 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9951 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9952 		return TEST_SKIPPED;
9953 
9954 	memset(&flags, 0, sizeof(flags));
9955 
9956 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
9957 
9958 	return test_ipsec_proto_all(&flags);
9959 }
9960 
9961 static int
9962 test_ipsec_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused)
9963 {
9964 	struct ipsec_test_flags flags;
9965 
9966 	memset(&flags, 0, sizeof(flags));
9967 
9968 	flags.ipv6 = true;
9969 	flags.tunnel_ipv6 = true;
9970 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
9971 
9972 	return test_ipsec_proto_all(&flags);
9973 }
9974 
9975 static int
9976 test_ipsec_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused)
9977 {
9978 	struct ipsec_test_flags flags;
9979 
9980 	memset(&flags, 0, sizeof(flags));
9981 
9982 	flags.ipv6 = true;
9983 	flags.tunnel_ipv6 = true;
9984 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
9985 
9986 	return test_ipsec_proto_all(&flags);
9987 }
9988 
9989 static int
9990 test_ipsec_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused)
9991 {
9992 	struct ipsec_test_flags flags;
9993 
9994 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9995 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9996 		return TEST_SKIPPED;
9997 
9998 	memset(&flags, 0, sizeof(flags));
9999 
10000 	flags.ipv6 = true;
10001 	flags.tunnel_ipv6 = true;
10002 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
10003 
10004 	return test_ipsec_proto_all(&flags);
10005 }
10006 
10007 static int
10008 test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)
10009 {
10010 	struct ipsec_test_flags flags;
10011 
10012 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10013 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10014 		return TEST_SKIPPED;
10015 
10016 	memset(&flags, 0, sizeof(flags));
10017 
10018 	flags.ipv6 = true;
10019 	flags.tunnel_ipv6 = true;
10020 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
10021 
10022 	return test_ipsec_proto_all(&flags);
10023 }
10024 
10025 static int
10026 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[],
10027 		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
10028 		      uint64_t winsz)
10029 {
10030 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
10031 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
10032 	struct ipsec_test_flags flags;
10033 	uint32_t i = 0, ret = 0;
10034 
10035 	memset(&flags, 0, sizeof(flags));
10036 	flags.antireplay = true;
10037 
10038 	for (i = 0; i < nb_pkts; i++) {
10039 		memcpy(&td_outb[i], test_data, sizeof(td_outb[i]));
10040 		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
10041 		td_outb[i].ipsec_xform.replay_win_sz = winsz;
10042 		td_outb[i].ipsec_xform.options.esn = esn_en;
10043 	}
10044 
10045 	for (i = 0; i < nb_pkts; i++)
10046 		td_outb[i].ipsec_xform.esn.value = esn[i];
10047 
10048 	ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10049 				       &flags);
10050 	if (ret != TEST_SUCCESS)
10051 		return ret;
10052 
10053 	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
10054 
10055 	for (i = 0; i < nb_pkts; i++) {
10056 		td_inb[i].ipsec_xform.options.esn = esn_en;
10057 		/* Set antireplay flag for packets to be dropped */
10058 		td_inb[i].ar_packet = replayed_pkt[i];
10059 	}
10060 
10061 	ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10062 				       &flags);
10063 
10064 	return ret;
10065 }
10066 
10067 static int
10068 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
10069 {
10070 
10071 	uint32_t nb_pkts = 5;
10072 	bool replayed_pkt[5];
10073 	uint64_t esn[5];
10074 
10075 	/* 1. Advance the TOP of the window to WS * 2 */
10076 	esn[0] = winsz * 2;
10077 	/* 2. Test sequence number within the new window(WS + 1) */
10078 	esn[1] = winsz + 1;
10079 	/* 3. Test sequence number less than the window BOTTOM */
10080 	esn[2] = winsz;
10081 	/* 4. Test sequence number in the middle of the window */
10082 	esn[3] = winsz + (winsz / 2);
10083 	/* 5. Test replay of the packet in the middle of the window */
10084 	esn[4] = winsz + (winsz / 2);
10085 
10086 	replayed_pkt[0] = false;
10087 	replayed_pkt[1] = false;
10088 	replayed_pkt[2] = true;
10089 	replayed_pkt[3] = false;
10090 	replayed_pkt[4] = true;
10091 
10092 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10093 				     false, winsz);
10094 }
10095 
10096 static int
10097 test_ipsec_proto_pkt_antireplay1024(const void *test_data)
10098 {
10099 	return test_ipsec_proto_pkt_antireplay(test_data, 1024);
10100 }
10101 
10102 static int
10103 test_ipsec_proto_pkt_antireplay2048(const void *test_data)
10104 {
10105 	return test_ipsec_proto_pkt_antireplay(test_data, 2048);
10106 }
10107 
10108 static int
10109 test_ipsec_proto_pkt_antireplay4096(const void *test_data)
10110 {
10111 	return test_ipsec_proto_pkt_antireplay(test_data, 4096);
10112 }
10113 
10114 static int
10115 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
10116 {
10117 
10118 	uint32_t nb_pkts = 7;
10119 	bool replayed_pkt[7];
10120 	uint64_t esn[7];
10121 
10122 	/* Set the initial sequence number */
10123 	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
10124 	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
10125 	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
10126 	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
10127 	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
10128 	/* 3. Test with sequence number within window (1<<32 - 1) */
10129 	esn[3] = (uint64_t)((1ULL << 32) - 1);
10130 	/* 4. Test with sequence number within window (1<<32 - 1) */
10131 	esn[4] = (uint64_t)(1ULL << 32);
10132 	/* 5. Test with duplicate sequence number within
10133 	 * new window (1<<32 - 1)
10134 	 */
10135 	esn[5] = (uint64_t)((1ULL << 32) - 1);
10136 	/* 6. Test with duplicate sequence number within new window (1<<32) */
10137 	esn[6] = (uint64_t)(1ULL << 32);
10138 
10139 	replayed_pkt[0] = false;
10140 	replayed_pkt[1] = false;
10141 	replayed_pkt[2] = false;
10142 	replayed_pkt[3] = false;
10143 	replayed_pkt[4] = false;
10144 	replayed_pkt[5] = true;
10145 	replayed_pkt[6] = true;
10146 
10147 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10148 				     true, winsz);
10149 }
10150 
10151 static int
10152 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data)
10153 {
10154 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024);
10155 }
10156 
10157 static int
10158 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data)
10159 {
10160 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048);
10161 }
10162 
10163 static int
10164 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data)
10165 {
10166 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096);
10167 }
10168 
10169 static int
10170 test_PDCP_PROTO_all(void)
10171 {
10172 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10173 	struct crypto_unittest_params *ut_params = &unittest_params;
10174 	struct rte_cryptodev_info dev_info;
10175 	int status;
10176 
10177 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10178 	uint64_t feat_flags = dev_info.feature_flags;
10179 
10180 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
10181 		return TEST_SKIPPED;
10182 
10183 	/* Set action type */
10184 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10185 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10186 		gbl_action_type;
10187 
10188 	if (security_proto_supported(ut_params->type,
10189 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
10190 		return TEST_SKIPPED;
10191 
10192 	status = test_PDCP_PROTO_cplane_encap_all();
10193 	status += test_PDCP_PROTO_cplane_decap_all();
10194 	status += test_PDCP_PROTO_uplane_encap_all();
10195 	status += test_PDCP_PROTO_uplane_decap_all();
10196 	status += test_PDCP_PROTO_SGL_in_place_32B();
10197 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
10198 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
10199 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
10200 	status += test_PDCP_SDAP_PROTO_encap_all();
10201 	status += test_PDCP_SDAP_PROTO_decap_all();
10202 	status += test_PDCP_PROTO_short_mac();
10203 
10204 	if (status)
10205 		return TEST_FAILED;
10206 	else
10207 		return TEST_SUCCESS;
10208 }
10209 
10210 static int
10211 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused)
10212 {
10213 	struct ipsec_test_flags flags = {
10214 		.dec_ttl_or_hop_limit = true
10215 	};
10216 
10217 	return test_ipsec_proto_all(&flags);
10218 }
10219 
10220 static int
10221 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused)
10222 {
10223 	struct ipsec_test_flags flags = {
10224 		.ipv6 = true,
10225 		.dec_ttl_or_hop_limit = true
10226 	};
10227 
10228 	return test_ipsec_proto_all(&flags);
10229 }
10230 
10231 static int
10232 test_docsis_proto_uplink(const void *data)
10233 {
10234 	const struct docsis_test_data *d_td = data;
10235 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10236 	struct crypto_unittest_params *ut_params = &unittest_params;
10237 	uint8_t *plaintext = NULL;
10238 	uint8_t *ciphertext = NULL;
10239 	uint8_t *iv_ptr;
10240 	int32_t cipher_len, crc_len;
10241 	uint32_t crc_data_len;
10242 	int ret = TEST_SUCCESS;
10243 
10244 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
10245 					rte_cryptodev_get_sec_ctx(
10246 						ts_params->valid_devs[0]);
10247 
10248 	/* Verify the capabilities */
10249 	struct rte_security_capability_idx sec_cap_idx;
10250 	const struct rte_security_capability *sec_cap;
10251 	const struct rte_cryptodev_capabilities *crypto_cap;
10252 	const struct rte_cryptodev_symmetric_capability *sym_cap;
10253 	int j = 0;
10254 
10255 	/* Set action type */
10256 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10257 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10258 		gbl_action_type;
10259 
10260 	if (security_proto_supported(ut_params->type,
10261 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10262 		return TEST_SKIPPED;
10263 
10264 	sec_cap_idx.action = ut_params->type;
10265 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
10266 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
10267 
10268 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10269 	if (sec_cap == NULL)
10270 		return TEST_SKIPPED;
10271 
10272 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
10273 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
10274 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
10275 				crypto_cap->sym.xform_type ==
10276 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
10277 				crypto_cap->sym.cipher.algo ==
10278 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
10279 			sym_cap = &crypto_cap->sym;
10280 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
10281 						d_td->key.len,
10282 						d_td->iv.len) == 0)
10283 				break;
10284 		}
10285 	}
10286 
10287 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
10288 		return TEST_SKIPPED;
10289 
10290 	/* Setup source mbuf payload */
10291 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10292 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10293 			rte_pktmbuf_tailroom(ut_params->ibuf));
10294 
10295 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10296 			d_td->ciphertext.len);
10297 
10298 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
10299 
10300 	/* Setup cipher session parameters */
10301 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10302 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
10303 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
10304 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
10305 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
10306 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
10307 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10308 	ut_params->cipher_xform.next = NULL;
10309 
10310 	/* Setup DOCSIS session parameters */
10311 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
10312 
10313 	struct rte_security_session_conf sess_conf = {
10314 		.action_type = ut_params->type,
10315 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
10316 		.docsis = ut_params->docsis_xform,
10317 		.crypto_xform = &ut_params->cipher_xform,
10318 	};
10319 
10320 	/* Create security session */
10321 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10322 					ts_params->session_mpool,
10323 					ts_params->session_priv_mpool);
10324 
10325 	if (!ut_params->sec_session) {
10326 		printf("Test function %s line %u: failed to allocate session\n",
10327 			__func__, __LINE__);
10328 		ret = TEST_FAILED;
10329 		goto on_err;
10330 	}
10331 
10332 	/* Generate crypto op data structure */
10333 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10334 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10335 	if (!ut_params->op) {
10336 		printf("Test function %s line %u: failed to allocate symmetric "
10337 			"crypto operation\n", __func__, __LINE__);
10338 		ret = TEST_FAILED;
10339 		goto on_err;
10340 	}
10341 
10342 	/* Setup CRC operation parameters */
10343 	crc_len = d_td->ciphertext.no_crc == false ?
10344 			(d_td->ciphertext.len -
10345 				d_td->ciphertext.crc_offset -
10346 				RTE_ETHER_CRC_LEN) :
10347 			0;
10348 	crc_len = crc_len > 0 ? crc_len : 0;
10349 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
10350 	ut_params->op->sym->auth.data.length = crc_len;
10351 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
10352 
10353 	/* Setup cipher operation parameters */
10354 	cipher_len = d_td->ciphertext.no_cipher == false ?
10355 			(d_td->ciphertext.len -
10356 				d_td->ciphertext.cipher_offset) :
10357 			0;
10358 	cipher_len = cipher_len > 0 ? cipher_len : 0;
10359 	ut_params->op->sym->cipher.data.length = cipher_len;
10360 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
10361 
10362 	/* Setup cipher IV */
10363 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
10364 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
10365 
10366 	/* Attach session to operation */
10367 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10368 
10369 	/* Set crypto operation mbufs */
10370 	ut_params->op->sym->m_src = ut_params->ibuf;
10371 	ut_params->op->sym->m_dst = NULL;
10372 
10373 	/* Process crypto operation */
10374 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10375 			NULL) {
10376 		printf("Test function %s line %u: failed to process security "
10377 			"crypto op\n", __func__, __LINE__);
10378 		ret = TEST_FAILED;
10379 		goto on_err;
10380 	}
10381 
10382 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10383 		printf("Test function %s line %u: failed to process crypto op\n",
10384 			__func__, __LINE__);
10385 		ret = TEST_FAILED;
10386 		goto on_err;
10387 	}
10388 
10389 	/* Validate plaintext */
10390 	plaintext = ciphertext;
10391 
10392 	if (memcmp(plaintext, d_td->plaintext.data,
10393 			d_td->plaintext.len - crc_data_len)) {
10394 		printf("Test function %s line %u: plaintext not as expected\n",
10395 			__func__, __LINE__);
10396 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
10397 				d_td->plaintext.len);
10398 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
10399 		ret = TEST_FAILED;
10400 		goto on_err;
10401 	}
10402 
10403 on_err:
10404 	rte_crypto_op_free(ut_params->op);
10405 	ut_params->op = NULL;
10406 
10407 	if (ut_params->sec_session)
10408 		rte_security_session_destroy(ctx, ut_params->sec_session);
10409 	ut_params->sec_session = NULL;
10410 
10411 	rte_pktmbuf_free(ut_params->ibuf);
10412 	ut_params->ibuf = NULL;
10413 
10414 	return ret;
10415 }
10416 
10417 static int
10418 test_docsis_proto_downlink(const void *data)
10419 {
10420 	const struct docsis_test_data *d_td = data;
10421 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10422 	struct crypto_unittest_params *ut_params = &unittest_params;
10423 	uint8_t *plaintext = NULL;
10424 	uint8_t *ciphertext = NULL;
10425 	uint8_t *iv_ptr;
10426 	int32_t cipher_len, crc_len;
10427 	int ret = TEST_SUCCESS;
10428 
10429 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
10430 					rte_cryptodev_get_sec_ctx(
10431 						ts_params->valid_devs[0]);
10432 
10433 	/* Verify the capabilities */
10434 	struct rte_security_capability_idx sec_cap_idx;
10435 	const struct rte_security_capability *sec_cap;
10436 	const struct rte_cryptodev_capabilities *crypto_cap;
10437 	const struct rte_cryptodev_symmetric_capability *sym_cap;
10438 	int j = 0;
10439 
10440 	/* Set action type */
10441 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10442 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10443 		gbl_action_type;
10444 
10445 	if (security_proto_supported(ut_params->type,
10446 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10447 		return TEST_SKIPPED;
10448 
10449 	sec_cap_idx.action = ut_params->type;
10450 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
10451 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
10452 
10453 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10454 	if (sec_cap == NULL)
10455 		return TEST_SKIPPED;
10456 
10457 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
10458 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
10459 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
10460 				crypto_cap->sym.xform_type ==
10461 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
10462 				crypto_cap->sym.cipher.algo ==
10463 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
10464 			sym_cap = &crypto_cap->sym;
10465 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
10466 						d_td->key.len,
10467 						d_td->iv.len) == 0)
10468 				break;
10469 		}
10470 	}
10471 
10472 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
10473 		return TEST_SKIPPED;
10474 
10475 	/* Setup source mbuf payload */
10476 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10477 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10478 			rte_pktmbuf_tailroom(ut_params->ibuf));
10479 
10480 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10481 			d_td->plaintext.len);
10482 
10483 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
10484 
10485 	/* Setup cipher session parameters */
10486 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10487 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
10488 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10489 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
10490 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
10491 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
10492 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10493 	ut_params->cipher_xform.next = NULL;
10494 
10495 	/* Setup DOCSIS session parameters */
10496 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
10497 
10498 	struct rte_security_session_conf sess_conf = {
10499 		.action_type = ut_params->type,
10500 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
10501 		.docsis = ut_params->docsis_xform,
10502 		.crypto_xform = &ut_params->cipher_xform,
10503 	};
10504 
10505 	/* Create security session */
10506 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10507 					ts_params->session_mpool,
10508 					ts_params->session_priv_mpool);
10509 
10510 	if (!ut_params->sec_session) {
10511 		printf("Test function %s line %u: failed to allocate session\n",
10512 			__func__, __LINE__);
10513 		ret = TEST_FAILED;
10514 		goto on_err;
10515 	}
10516 
10517 	/* Generate crypto op data structure */
10518 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10519 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10520 	if (!ut_params->op) {
10521 		printf("Test function %s line %u: failed to allocate symmetric "
10522 			"crypto operation\n", __func__, __LINE__);
10523 		ret = TEST_FAILED;
10524 		goto on_err;
10525 	}
10526 
10527 	/* Setup CRC operation parameters */
10528 	crc_len = d_td->plaintext.no_crc == false ?
10529 			(d_td->plaintext.len -
10530 				d_td->plaintext.crc_offset -
10531 				RTE_ETHER_CRC_LEN) :
10532 			0;
10533 	crc_len = crc_len > 0 ? crc_len : 0;
10534 	ut_params->op->sym->auth.data.length = crc_len;
10535 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
10536 
10537 	/* Setup cipher operation parameters */
10538 	cipher_len = d_td->plaintext.no_cipher == false ?
10539 			(d_td->plaintext.len -
10540 				d_td->plaintext.cipher_offset) :
10541 			0;
10542 	cipher_len = cipher_len > 0 ? cipher_len : 0;
10543 	ut_params->op->sym->cipher.data.length = cipher_len;
10544 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
10545 
10546 	/* Setup cipher IV */
10547 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
10548 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
10549 
10550 	/* Attach session to operation */
10551 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10552 
10553 	/* Set crypto operation mbufs */
10554 	ut_params->op->sym->m_src = ut_params->ibuf;
10555 	ut_params->op->sym->m_dst = NULL;
10556 
10557 	/* Process crypto operation */
10558 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10559 			NULL) {
10560 		printf("Test function %s line %u: failed to process crypto op\n",
10561 			__func__, __LINE__);
10562 		ret = TEST_FAILED;
10563 		goto on_err;
10564 	}
10565 
10566 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10567 		printf("Test function %s line %u: crypto op processing failed\n",
10568 			__func__, __LINE__);
10569 		ret = TEST_FAILED;
10570 		goto on_err;
10571 	}
10572 
10573 	/* Validate ciphertext */
10574 	ciphertext = plaintext;
10575 
10576 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
10577 		printf("Test function %s line %u: plaintext not as expected\n",
10578 			__func__, __LINE__);
10579 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
10580 				d_td->ciphertext.len);
10581 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
10582 		ret = TEST_FAILED;
10583 		goto on_err;
10584 	}
10585 
10586 on_err:
10587 	rte_crypto_op_free(ut_params->op);
10588 	ut_params->op = NULL;
10589 
10590 	if (ut_params->sec_session)
10591 		rte_security_session_destroy(ctx, ut_params->sec_session);
10592 	ut_params->sec_session = NULL;
10593 
10594 	rte_pktmbuf_free(ut_params->ibuf);
10595 	ut_params->ibuf = NULL;
10596 
10597 	return ret;
10598 }
10599 #endif
10600 
10601 static int
10602 test_AES_GCM_authenticated_encryption_test_case_1(void)
10603 {
10604 	return test_authenticated_encryption(&gcm_test_case_1);
10605 }
10606 
10607 static int
10608 test_AES_GCM_authenticated_encryption_test_case_2(void)
10609 {
10610 	return test_authenticated_encryption(&gcm_test_case_2);
10611 }
10612 
10613 static int
10614 test_AES_GCM_authenticated_encryption_test_case_3(void)
10615 {
10616 	return test_authenticated_encryption(&gcm_test_case_3);
10617 }
10618 
10619 static int
10620 test_AES_GCM_authenticated_encryption_test_case_4(void)
10621 {
10622 	return test_authenticated_encryption(&gcm_test_case_4);
10623 }
10624 
10625 static int
10626 test_AES_GCM_authenticated_encryption_test_case_5(void)
10627 {
10628 	return test_authenticated_encryption(&gcm_test_case_5);
10629 }
10630 
10631 static int
10632 test_AES_GCM_authenticated_encryption_test_case_6(void)
10633 {
10634 	return test_authenticated_encryption(&gcm_test_case_6);
10635 }
10636 
10637 static int
10638 test_AES_GCM_authenticated_encryption_test_case_7(void)
10639 {
10640 	return test_authenticated_encryption(&gcm_test_case_7);
10641 }
10642 
10643 static int
10644 test_AES_GCM_authenticated_encryption_test_case_8(void)
10645 {
10646 	return test_authenticated_encryption(&gcm_test_case_8);
10647 }
10648 
10649 static int
10650 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
10651 {
10652 	return test_authenticated_encryption(&gcm_J0_test_case_1);
10653 }
10654 
10655 static int
10656 test_AES_GCM_auth_encryption_test_case_192_1(void)
10657 {
10658 	return test_authenticated_encryption(&gcm_test_case_192_1);
10659 }
10660 
10661 static int
10662 test_AES_GCM_auth_encryption_test_case_192_2(void)
10663 {
10664 	return test_authenticated_encryption(&gcm_test_case_192_2);
10665 }
10666 
10667 static int
10668 test_AES_GCM_auth_encryption_test_case_192_3(void)
10669 {
10670 	return test_authenticated_encryption(&gcm_test_case_192_3);
10671 }
10672 
10673 static int
10674 test_AES_GCM_auth_encryption_test_case_192_4(void)
10675 {
10676 	return test_authenticated_encryption(&gcm_test_case_192_4);
10677 }
10678 
10679 static int
10680 test_AES_GCM_auth_encryption_test_case_192_5(void)
10681 {
10682 	return test_authenticated_encryption(&gcm_test_case_192_5);
10683 }
10684 
10685 static int
10686 test_AES_GCM_auth_encryption_test_case_192_6(void)
10687 {
10688 	return test_authenticated_encryption(&gcm_test_case_192_6);
10689 }
10690 
10691 static int
10692 test_AES_GCM_auth_encryption_test_case_192_7(void)
10693 {
10694 	return test_authenticated_encryption(&gcm_test_case_192_7);
10695 }
10696 
10697 static int
10698 test_AES_GCM_auth_encryption_test_case_256_1(void)
10699 {
10700 	return test_authenticated_encryption(&gcm_test_case_256_1);
10701 }
10702 
10703 static int
10704 test_AES_GCM_auth_encryption_test_case_256_2(void)
10705 {
10706 	return test_authenticated_encryption(&gcm_test_case_256_2);
10707 }
10708 
10709 static int
10710 test_AES_GCM_auth_encryption_test_case_256_3(void)
10711 {
10712 	return test_authenticated_encryption(&gcm_test_case_256_3);
10713 }
10714 
10715 static int
10716 test_AES_GCM_auth_encryption_test_case_256_4(void)
10717 {
10718 	return test_authenticated_encryption(&gcm_test_case_256_4);
10719 }
10720 
10721 static int
10722 test_AES_GCM_auth_encryption_test_case_256_5(void)
10723 {
10724 	return test_authenticated_encryption(&gcm_test_case_256_5);
10725 }
10726 
10727 static int
10728 test_AES_GCM_auth_encryption_test_case_256_6(void)
10729 {
10730 	return test_authenticated_encryption(&gcm_test_case_256_6);
10731 }
10732 
10733 static int
10734 test_AES_GCM_auth_encryption_test_case_256_7(void)
10735 {
10736 	return test_authenticated_encryption(&gcm_test_case_256_7);
10737 }
10738 
10739 static int
10740 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10741 {
10742 	return test_authenticated_encryption(&gcm_test_case_aad_1);
10743 }
10744 
10745 static int
10746 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10747 {
10748 	return test_authenticated_encryption(&gcm_test_case_aad_2);
10749 }
10750 
10751 static int
10752 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10753 {
10754 	struct aead_test_data tdata;
10755 	int res;
10756 
10757 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10758 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10759 	tdata.iv.data[0] += 1;
10760 	res = test_authenticated_encryption(&tdata);
10761 	if (res == TEST_SKIPPED)
10762 		return res;
10763 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10764 	return TEST_SUCCESS;
10765 }
10766 
10767 static int
10768 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10769 {
10770 	struct aead_test_data tdata;
10771 	int res;
10772 
10773 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10774 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10775 	tdata.plaintext.data[0] += 1;
10776 	res = test_authenticated_encryption(&tdata);
10777 	if (res == TEST_SKIPPED)
10778 		return res;
10779 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10780 	return TEST_SUCCESS;
10781 }
10782 
10783 static int
10784 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10785 {
10786 	struct aead_test_data tdata;
10787 	int res;
10788 
10789 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10790 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10791 	tdata.ciphertext.data[0] += 1;
10792 	res = test_authenticated_encryption(&tdata);
10793 	if (res == TEST_SKIPPED)
10794 		return res;
10795 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10796 	return TEST_SUCCESS;
10797 }
10798 
10799 static int
10800 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10801 {
10802 	struct aead_test_data tdata;
10803 	int res;
10804 
10805 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10806 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10807 	tdata.aad.len += 1;
10808 	res = test_authenticated_encryption(&tdata);
10809 	if (res == TEST_SKIPPED)
10810 		return res;
10811 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10812 	return TEST_SUCCESS;
10813 }
10814 
10815 static int
10816 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10817 {
10818 	struct aead_test_data tdata;
10819 	uint8_t aad[gcm_test_case_7.aad.len];
10820 	int res;
10821 
10822 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10823 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10824 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10825 	aad[0] += 1;
10826 	tdata.aad.data = aad;
10827 	res = test_authenticated_encryption(&tdata);
10828 	if (res == TEST_SKIPPED)
10829 		return res;
10830 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10831 	return TEST_SUCCESS;
10832 }
10833 
10834 static int
10835 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10836 {
10837 	struct aead_test_data tdata;
10838 	int res;
10839 
10840 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10841 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10842 	tdata.auth_tag.data[0] += 1;
10843 	res = test_authenticated_encryption(&tdata);
10844 	if (res == TEST_SKIPPED)
10845 		return res;
10846 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10847 	return TEST_SUCCESS;
10848 }
10849 
10850 static int
10851 test_authenticated_decryption(const struct aead_test_data *tdata)
10852 {
10853 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10854 	struct crypto_unittest_params *ut_params = &unittest_params;
10855 
10856 	int retval;
10857 	uint8_t *plaintext;
10858 	uint32_t i;
10859 	struct rte_cryptodev_info dev_info;
10860 
10861 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10862 	uint64_t feat_flags = dev_info.feature_flags;
10863 
10864 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10865 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10866 		printf("Device doesn't support RAW data-path APIs.\n");
10867 		return TEST_SKIPPED;
10868 	}
10869 
10870 	/* Verify the capabilities */
10871 	struct rte_cryptodev_sym_capability_idx cap_idx;
10872 	const struct rte_cryptodev_symmetric_capability *capability;
10873 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10874 	cap_idx.algo.aead = tdata->algo;
10875 	capability = rte_cryptodev_sym_capability_get(
10876 			ts_params->valid_devs[0], &cap_idx);
10877 	if (capability == NULL)
10878 		return TEST_SKIPPED;
10879 	if (rte_cryptodev_sym_capability_check_aead(
10880 			capability, tdata->key.len, tdata->auth_tag.len,
10881 			tdata->aad.len, tdata->iv.len))
10882 		return TEST_SKIPPED;
10883 
10884 	/* Create AEAD session */
10885 	retval = create_aead_session(ts_params->valid_devs[0],
10886 			tdata->algo,
10887 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10888 			tdata->key.data, tdata->key.len,
10889 			tdata->aad.len, tdata->auth_tag.len,
10890 			tdata->iv.len);
10891 	if (retval < 0)
10892 		return retval;
10893 
10894 	/* alloc mbuf and set payload */
10895 	if (tdata->aad.len > MBUF_SIZE) {
10896 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10897 		/* Populate full size of add data */
10898 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10899 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10900 	} else
10901 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10902 
10903 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10904 			rte_pktmbuf_tailroom(ut_params->ibuf));
10905 
10906 	/* Create AEAD operation */
10907 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10908 	if (retval < 0)
10909 		return retval;
10910 
10911 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10912 
10913 	ut_params->op->sym->m_src = ut_params->ibuf;
10914 
10915 	/* Process crypto operation */
10916 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10917 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10918 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10919 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10920 				ut_params->op, 0, 0, 0, 0);
10921 	else
10922 		TEST_ASSERT_NOT_NULL(
10923 			process_crypto_request(ts_params->valid_devs[0],
10924 			ut_params->op), "failed to process sym crypto op");
10925 
10926 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10927 			"crypto op processing failed");
10928 
10929 	if (ut_params->op->sym->m_dst)
10930 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10931 				uint8_t *);
10932 	else
10933 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10934 				uint8_t *,
10935 				ut_params->op->sym->cipher.data.offset);
10936 
10937 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10938 
10939 	/* Validate obuf */
10940 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10941 			plaintext,
10942 			tdata->plaintext.data,
10943 			tdata->plaintext.len,
10944 			"Plaintext data not as expected");
10945 
10946 	TEST_ASSERT_EQUAL(ut_params->op->status,
10947 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10948 			"Authentication failed");
10949 
10950 	return 0;
10951 }
10952 
10953 static int
10954 test_AES_GCM_authenticated_decryption_test_case_1(void)
10955 {
10956 	return test_authenticated_decryption(&gcm_test_case_1);
10957 }
10958 
10959 static int
10960 test_AES_GCM_authenticated_decryption_test_case_2(void)
10961 {
10962 	return test_authenticated_decryption(&gcm_test_case_2);
10963 }
10964 
10965 static int
10966 test_AES_GCM_authenticated_decryption_test_case_3(void)
10967 {
10968 	return test_authenticated_decryption(&gcm_test_case_3);
10969 }
10970 
10971 static int
10972 test_AES_GCM_authenticated_decryption_test_case_4(void)
10973 {
10974 	return test_authenticated_decryption(&gcm_test_case_4);
10975 }
10976 
10977 static int
10978 test_AES_GCM_authenticated_decryption_test_case_5(void)
10979 {
10980 	return test_authenticated_decryption(&gcm_test_case_5);
10981 }
10982 
10983 static int
10984 test_AES_GCM_authenticated_decryption_test_case_6(void)
10985 {
10986 	return test_authenticated_decryption(&gcm_test_case_6);
10987 }
10988 
10989 static int
10990 test_AES_GCM_authenticated_decryption_test_case_7(void)
10991 {
10992 	return test_authenticated_decryption(&gcm_test_case_7);
10993 }
10994 
10995 static int
10996 test_AES_GCM_authenticated_decryption_test_case_8(void)
10997 {
10998 	return test_authenticated_decryption(&gcm_test_case_8);
10999 }
11000 
11001 static int
11002 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
11003 {
11004 	return test_authenticated_decryption(&gcm_J0_test_case_1);
11005 }
11006 
11007 static int
11008 test_AES_GCM_auth_decryption_test_case_192_1(void)
11009 {
11010 	return test_authenticated_decryption(&gcm_test_case_192_1);
11011 }
11012 
11013 static int
11014 test_AES_GCM_auth_decryption_test_case_192_2(void)
11015 {
11016 	return test_authenticated_decryption(&gcm_test_case_192_2);
11017 }
11018 
11019 static int
11020 test_AES_GCM_auth_decryption_test_case_192_3(void)
11021 {
11022 	return test_authenticated_decryption(&gcm_test_case_192_3);
11023 }
11024 
11025 static int
11026 test_AES_GCM_auth_decryption_test_case_192_4(void)
11027 {
11028 	return test_authenticated_decryption(&gcm_test_case_192_4);
11029 }
11030 
11031 static int
11032 test_AES_GCM_auth_decryption_test_case_192_5(void)
11033 {
11034 	return test_authenticated_decryption(&gcm_test_case_192_5);
11035 }
11036 
11037 static int
11038 test_AES_GCM_auth_decryption_test_case_192_6(void)
11039 {
11040 	return test_authenticated_decryption(&gcm_test_case_192_6);
11041 }
11042 
11043 static int
11044 test_AES_GCM_auth_decryption_test_case_192_7(void)
11045 {
11046 	return test_authenticated_decryption(&gcm_test_case_192_7);
11047 }
11048 
11049 static int
11050 test_AES_GCM_auth_decryption_test_case_256_1(void)
11051 {
11052 	return test_authenticated_decryption(&gcm_test_case_256_1);
11053 }
11054 
11055 static int
11056 test_AES_GCM_auth_decryption_test_case_256_2(void)
11057 {
11058 	return test_authenticated_decryption(&gcm_test_case_256_2);
11059 }
11060 
11061 static int
11062 test_AES_GCM_auth_decryption_test_case_256_3(void)
11063 {
11064 	return test_authenticated_decryption(&gcm_test_case_256_3);
11065 }
11066 
11067 static int
11068 test_AES_GCM_auth_decryption_test_case_256_4(void)
11069 {
11070 	return test_authenticated_decryption(&gcm_test_case_256_4);
11071 }
11072 
11073 static int
11074 test_AES_GCM_auth_decryption_test_case_256_5(void)
11075 {
11076 	return test_authenticated_decryption(&gcm_test_case_256_5);
11077 }
11078 
11079 static int
11080 test_AES_GCM_auth_decryption_test_case_256_6(void)
11081 {
11082 	return test_authenticated_decryption(&gcm_test_case_256_6);
11083 }
11084 
11085 static int
11086 test_AES_GCM_auth_decryption_test_case_256_7(void)
11087 {
11088 	return test_authenticated_decryption(&gcm_test_case_256_7);
11089 }
11090 
11091 static int
11092 test_AES_GCM_auth_decryption_test_case_aad_1(void)
11093 {
11094 	return test_authenticated_decryption(&gcm_test_case_aad_1);
11095 }
11096 
11097 static int
11098 test_AES_GCM_auth_decryption_test_case_aad_2(void)
11099 {
11100 	return test_authenticated_decryption(&gcm_test_case_aad_2);
11101 }
11102 
11103 static int
11104 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
11105 {
11106 	struct aead_test_data tdata;
11107 	int res;
11108 
11109 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11110 	tdata.iv.data[0] += 1;
11111 	res = test_authenticated_decryption(&tdata);
11112 	if (res == TEST_SKIPPED)
11113 		return res;
11114 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11115 	return TEST_SUCCESS;
11116 }
11117 
11118 static int
11119 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
11120 {
11121 	struct aead_test_data tdata;
11122 	int res;
11123 
11124 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11125 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11126 	tdata.plaintext.data[0] += 1;
11127 	res = test_authenticated_decryption(&tdata);
11128 	if (res == TEST_SKIPPED)
11129 		return res;
11130 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11131 	return TEST_SUCCESS;
11132 }
11133 
11134 static int
11135 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
11136 {
11137 	struct aead_test_data tdata;
11138 	int res;
11139 
11140 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11141 	tdata.ciphertext.data[0] += 1;
11142 	res = test_authenticated_decryption(&tdata);
11143 	if (res == TEST_SKIPPED)
11144 		return res;
11145 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11146 	return TEST_SUCCESS;
11147 }
11148 
11149 static int
11150 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
11151 {
11152 	struct aead_test_data tdata;
11153 	int res;
11154 
11155 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11156 	tdata.aad.len += 1;
11157 	res = test_authenticated_decryption(&tdata);
11158 	if (res == TEST_SKIPPED)
11159 		return res;
11160 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11161 	return TEST_SUCCESS;
11162 }
11163 
11164 static int
11165 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
11166 {
11167 	struct aead_test_data tdata;
11168 	uint8_t aad[gcm_test_case_7.aad.len];
11169 	int res;
11170 
11171 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11172 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
11173 	aad[0] += 1;
11174 	tdata.aad.data = aad;
11175 	res = test_authenticated_decryption(&tdata);
11176 	if (res == TEST_SKIPPED)
11177 		return res;
11178 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11179 	return TEST_SUCCESS;
11180 }
11181 
11182 static int
11183 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
11184 {
11185 	struct aead_test_data tdata;
11186 	int res;
11187 
11188 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11189 	tdata.auth_tag.data[0] += 1;
11190 	res = test_authenticated_decryption(&tdata);
11191 	if (res == TEST_SKIPPED)
11192 		return res;
11193 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
11194 	return TEST_SUCCESS;
11195 }
11196 
11197 static int
11198 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
11199 {
11200 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11201 	struct crypto_unittest_params *ut_params = &unittest_params;
11202 
11203 	int retval;
11204 	uint8_t *ciphertext, *auth_tag;
11205 	uint16_t plaintext_pad_len;
11206 	struct rte_cryptodev_info dev_info;
11207 
11208 	/* Verify the capabilities */
11209 	struct rte_cryptodev_sym_capability_idx cap_idx;
11210 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11211 	cap_idx.algo.aead = tdata->algo;
11212 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11213 			&cap_idx) == NULL)
11214 		return TEST_SKIPPED;
11215 
11216 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11217 	uint64_t feat_flags = dev_info.feature_flags;
11218 
11219 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11220 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
11221 		return TEST_SKIPPED;
11222 
11223 	/* not supported with CPU crypto */
11224 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11225 		return TEST_SKIPPED;
11226 
11227 	/* Create AEAD session */
11228 	retval = create_aead_session(ts_params->valid_devs[0],
11229 			tdata->algo,
11230 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
11231 			tdata->key.data, tdata->key.len,
11232 			tdata->aad.len, tdata->auth_tag.len,
11233 			tdata->iv.len);
11234 	if (retval < 0)
11235 		return retval;
11236 
11237 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11238 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11239 
11240 	/* clear mbuf payload */
11241 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11242 			rte_pktmbuf_tailroom(ut_params->ibuf));
11243 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
11244 			rte_pktmbuf_tailroom(ut_params->obuf));
11245 
11246 	/* Create AEAD operation */
11247 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
11248 	if (retval < 0)
11249 		return retval;
11250 
11251 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11252 
11253 	ut_params->op->sym->m_src = ut_params->ibuf;
11254 	ut_params->op->sym->m_dst = ut_params->obuf;
11255 
11256 	/* Process crypto operation */
11257 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11258 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11259 			ut_params->op, 0, 0, 0, 0);
11260 	else
11261 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11262 			ut_params->op), "failed to process sym crypto op");
11263 
11264 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11265 			"crypto op processing failed");
11266 
11267 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11268 
11269 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
11270 			ut_params->op->sym->cipher.data.offset);
11271 	auth_tag = ciphertext + plaintext_pad_len;
11272 
11273 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
11274 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
11275 
11276 	/* Validate obuf */
11277 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11278 			ciphertext,
11279 			tdata->ciphertext.data,
11280 			tdata->ciphertext.len,
11281 			"Ciphertext data not as expected");
11282 
11283 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11284 			auth_tag,
11285 			tdata->auth_tag.data,
11286 			tdata->auth_tag.len,
11287 			"Generated auth tag not as expected");
11288 
11289 	return 0;
11290 
11291 }
11292 
11293 static int
11294 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
11295 {
11296 	return test_authenticated_encryption_oop(&gcm_test_case_5);
11297 }
11298 
11299 static int
11300 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
11301 {
11302 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11303 	struct crypto_unittest_params *ut_params = &unittest_params;
11304 
11305 	int retval;
11306 	uint8_t *plaintext;
11307 	struct rte_cryptodev_info dev_info;
11308 
11309 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11310 	uint64_t feat_flags = dev_info.feature_flags;
11311 
11312 	/* Verify the capabilities */
11313 	struct rte_cryptodev_sym_capability_idx cap_idx;
11314 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11315 	cap_idx.algo.aead = tdata->algo;
11316 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11317 			&cap_idx) == NULL)
11318 		return TEST_SKIPPED;
11319 
11320 	/* not supported with CPU crypto and raw data-path APIs*/
11321 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
11322 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
11323 		return TEST_SKIPPED;
11324 
11325 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11326 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11327 		printf("Device does not support RAW data-path APIs.\n");
11328 		return TEST_SKIPPED;
11329 	}
11330 
11331 	/* Create AEAD session */
11332 	retval = create_aead_session(ts_params->valid_devs[0],
11333 			tdata->algo,
11334 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11335 			tdata->key.data, tdata->key.len,
11336 			tdata->aad.len, tdata->auth_tag.len,
11337 			tdata->iv.len);
11338 	if (retval < 0)
11339 		return retval;
11340 
11341 	/* alloc mbuf and set payload */
11342 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11343 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11344 
11345 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11346 			rte_pktmbuf_tailroom(ut_params->ibuf));
11347 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
11348 			rte_pktmbuf_tailroom(ut_params->obuf));
11349 
11350 	/* Create AEAD operation */
11351 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11352 	if (retval < 0)
11353 		return retval;
11354 
11355 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11356 
11357 	ut_params->op->sym->m_src = ut_params->ibuf;
11358 	ut_params->op->sym->m_dst = ut_params->obuf;
11359 
11360 	/* Process crypto operation */
11361 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11362 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11363 				ut_params->op, 0, 0, 0, 0);
11364 	else
11365 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11366 			ut_params->op), "failed to process sym crypto op");
11367 
11368 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11369 			"crypto op processing failed");
11370 
11371 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
11372 			ut_params->op->sym->cipher.data.offset);
11373 
11374 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11375 
11376 	/* Validate obuf */
11377 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11378 			plaintext,
11379 			tdata->plaintext.data,
11380 			tdata->plaintext.len,
11381 			"Plaintext data not as expected");
11382 
11383 	TEST_ASSERT_EQUAL(ut_params->op->status,
11384 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11385 			"Authentication failed");
11386 	return 0;
11387 }
11388 
11389 static int
11390 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
11391 {
11392 	return test_authenticated_decryption_oop(&gcm_test_case_5);
11393 }
11394 
11395 static int
11396 test_authenticated_encryption_sessionless(
11397 		const struct aead_test_data *tdata)
11398 {
11399 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11400 	struct crypto_unittest_params *ut_params = &unittest_params;
11401 
11402 	int retval;
11403 	uint8_t *ciphertext, *auth_tag;
11404 	uint16_t plaintext_pad_len;
11405 	uint8_t key[tdata->key.len + 1];
11406 	struct rte_cryptodev_info dev_info;
11407 
11408 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11409 	uint64_t feat_flags = dev_info.feature_flags;
11410 
11411 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
11412 		printf("Device doesn't support Sessionless ops.\n");
11413 		return TEST_SKIPPED;
11414 	}
11415 
11416 	/* not supported with CPU crypto */
11417 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11418 		return TEST_SKIPPED;
11419 
11420 	/* Verify the capabilities */
11421 	struct rte_cryptodev_sym_capability_idx cap_idx;
11422 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11423 	cap_idx.algo.aead = tdata->algo;
11424 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11425 			&cap_idx) == NULL)
11426 		return TEST_SKIPPED;
11427 
11428 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11429 
11430 	/* clear mbuf payload */
11431 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11432 			rte_pktmbuf_tailroom(ut_params->ibuf));
11433 
11434 	/* Create AEAD operation */
11435 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
11436 	if (retval < 0)
11437 		return retval;
11438 
11439 	/* Create GCM xform */
11440 	memcpy(key, tdata->key.data, tdata->key.len);
11441 	retval = create_aead_xform(ut_params->op,
11442 			tdata->algo,
11443 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
11444 			key, tdata->key.len,
11445 			tdata->aad.len, tdata->auth_tag.len,
11446 			tdata->iv.len);
11447 	if (retval < 0)
11448 		return retval;
11449 
11450 	ut_params->op->sym->m_src = ut_params->ibuf;
11451 
11452 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11453 			RTE_CRYPTO_OP_SESSIONLESS,
11454 			"crypto op session type not sessionless");
11455 
11456 	/* Process crypto operation */
11457 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11458 			ut_params->op), "failed to process sym crypto op");
11459 
11460 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11461 
11462 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11463 			"crypto op status not success");
11464 
11465 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11466 
11467 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11468 			ut_params->op->sym->cipher.data.offset);
11469 	auth_tag = ciphertext + plaintext_pad_len;
11470 
11471 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
11472 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
11473 
11474 	/* Validate obuf */
11475 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11476 			ciphertext,
11477 			tdata->ciphertext.data,
11478 			tdata->ciphertext.len,
11479 			"Ciphertext data not as expected");
11480 
11481 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11482 			auth_tag,
11483 			tdata->auth_tag.data,
11484 			tdata->auth_tag.len,
11485 			"Generated auth tag not as expected");
11486 
11487 	return 0;
11488 
11489 }
11490 
11491 static int
11492 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
11493 {
11494 	return test_authenticated_encryption_sessionless(
11495 			&gcm_test_case_5);
11496 }
11497 
11498 static int
11499 test_authenticated_decryption_sessionless(
11500 		const struct aead_test_data *tdata)
11501 {
11502 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11503 	struct crypto_unittest_params *ut_params = &unittest_params;
11504 
11505 	int retval;
11506 	uint8_t *plaintext;
11507 	uint8_t key[tdata->key.len + 1];
11508 	struct rte_cryptodev_info dev_info;
11509 
11510 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11511 	uint64_t feat_flags = dev_info.feature_flags;
11512 
11513 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
11514 		printf("Device doesn't support Sessionless ops.\n");
11515 		return TEST_SKIPPED;
11516 	}
11517 
11518 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11519 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11520 		printf("Device doesn't support RAW data-path APIs.\n");
11521 		return TEST_SKIPPED;
11522 	}
11523 
11524 	/* not supported with CPU crypto */
11525 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11526 		return TEST_SKIPPED;
11527 
11528 	/* Verify the capabilities */
11529 	struct rte_cryptodev_sym_capability_idx cap_idx;
11530 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11531 	cap_idx.algo.aead = tdata->algo;
11532 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11533 			&cap_idx) == NULL)
11534 		return TEST_SKIPPED;
11535 
11536 	/* alloc mbuf and set payload */
11537 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11538 
11539 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11540 			rte_pktmbuf_tailroom(ut_params->ibuf));
11541 
11542 	/* Create AEAD operation */
11543 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11544 	if (retval < 0)
11545 		return retval;
11546 
11547 	/* Create AEAD xform */
11548 	memcpy(key, tdata->key.data, tdata->key.len);
11549 	retval = create_aead_xform(ut_params->op,
11550 			tdata->algo,
11551 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11552 			key, tdata->key.len,
11553 			tdata->aad.len, tdata->auth_tag.len,
11554 			tdata->iv.len);
11555 	if (retval < 0)
11556 		return retval;
11557 
11558 	ut_params->op->sym->m_src = ut_params->ibuf;
11559 
11560 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11561 			RTE_CRYPTO_OP_SESSIONLESS,
11562 			"crypto op session type not sessionless");
11563 
11564 	/* Process crypto operation */
11565 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11566 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11567 				ut_params->op, 0, 0, 0, 0);
11568 	else
11569 		TEST_ASSERT_NOT_NULL(process_crypto_request(
11570 			ts_params->valid_devs[0], ut_params->op),
11571 				"failed to process sym crypto op");
11572 
11573 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11574 
11575 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11576 			"crypto op status not success");
11577 
11578 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11579 			ut_params->op->sym->cipher.data.offset);
11580 
11581 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11582 
11583 	/* Validate obuf */
11584 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11585 			plaintext,
11586 			tdata->plaintext.data,
11587 			tdata->plaintext.len,
11588 			"Plaintext data not as expected");
11589 
11590 	TEST_ASSERT_EQUAL(ut_params->op->status,
11591 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11592 			"Authentication failed");
11593 	return 0;
11594 }
11595 
11596 static int
11597 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
11598 {
11599 	return test_authenticated_decryption_sessionless(
11600 			&gcm_test_case_5);
11601 }
11602 
11603 static int
11604 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
11605 {
11606 	return test_authenticated_encryption(&ccm_test_case_128_1);
11607 }
11608 
11609 static int
11610 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
11611 {
11612 	return test_authenticated_encryption(&ccm_test_case_128_2);
11613 }
11614 
11615 static int
11616 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
11617 {
11618 	return test_authenticated_encryption(&ccm_test_case_128_3);
11619 }
11620 
11621 static int
11622 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
11623 {
11624 	return test_authenticated_decryption(&ccm_test_case_128_1);
11625 }
11626 
11627 static int
11628 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
11629 {
11630 	return test_authenticated_decryption(&ccm_test_case_128_2);
11631 }
11632 
11633 static int
11634 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
11635 {
11636 	return test_authenticated_decryption(&ccm_test_case_128_3);
11637 }
11638 
11639 static int
11640 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
11641 {
11642 	return test_authenticated_encryption(&ccm_test_case_192_1);
11643 }
11644 
11645 static int
11646 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
11647 {
11648 	return test_authenticated_encryption(&ccm_test_case_192_2);
11649 }
11650 
11651 static int
11652 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
11653 {
11654 	return test_authenticated_encryption(&ccm_test_case_192_3);
11655 }
11656 
11657 static int
11658 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
11659 {
11660 	return test_authenticated_decryption(&ccm_test_case_192_1);
11661 }
11662 
11663 static int
11664 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
11665 {
11666 	return test_authenticated_decryption(&ccm_test_case_192_2);
11667 }
11668 
11669 static int
11670 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
11671 {
11672 	return test_authenticated_decryption(&ccm_test_case_192_3);
11673 }
11674 
11675 static int
11676 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11677 {
11678 	return test_authenticated_encryption(&ccm_test_case_256_1);
11679 }
11680 
11681 static int
11682 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11683 {
11684 	return test_authenticated_encryption(&ccm_test_case_256_2);
11685 }
11686 
11687 static int
11688 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11689 {
11690 	return test_authenticated_encryption(&ccm_test_case_256_3);
11691 }
11692 
11693 static int
11694 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11695 {
11696 	return test_authenticated_decryption(&ccm_test_case_256_1);
11697 }
11698 
11699 static int
11700 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11701 {
11702 	return test_authenticated_decryption(&ccm_test_case_256_2);
11703 }
11704 
11705 static int
11706 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11707 {
11708 	return test_authenticated_decryption(&ccm_test_case_256_3);
11709 }
11710 
11711 static int
11712 test_stats(void)
11713 {
11714 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11715 	struct rte_cryptodev_stats stats;
11716 
11717 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11718 		return TEST_SKIPPED;
11719 
11720 	/* Verify the capabilities */
11721 	struct rte_cryptodev_sym_capability_idx cap_idx;
11722 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11723 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11724 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11725 			&cap_idx) == NULL)
11726 		return TEST_SKIPPED;
11727 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11728 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11729 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11730 			&cap_idx) == NULL)
11731 		return TEST_SKIPPED;
11732 
11733 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11734 			== -ENOTSUP)
11735 		return TEST_SKIPPED;
11736 
11737 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11738 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11739 			&stats) == -ENODEV),
11740 		"rte_cryptodev_stats_get invalid dev failed");
11741 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11742 		"rte_cryptodev_stats_get invalid Param failed");
11743 
11744 	/* Test expected values */
11745 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
11746 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11747 			&stats),
11748 		"rte_cryptodev_stats_get failed");
11749 	TEST_ASSERT((stats.enqueued_count == 1),
11750 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11751 	TEST_ASSERT((stats.dequeued_count == 1),
11752 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11753 	TEST_ASSERT((stats.enqueue_err_count == 0),
11754 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11755 	TEST_ASSERT((stats.dequeue_err_count == 0),
11756 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11757 
11758 	/* invalid device but should ignore and not reset device stats*/
11759 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11760 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11761 			&stats),
11762 		"rte_cryptodev_stats_get failed");
11763 	TEST_ASSERT((stats.enqueued_count == 1),
11764 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11765 
11766 	/* check that a valid reset clears stats */
11767 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11768 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11769 			&stats),
11770 					  "rte_cryptodev_stats_get failed");
11771 	TEST_ASSERT((stats.enqueued_count == 0),
11772 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11773 	TEST_ASSERT((stats.dequeued_count == 0),
11774 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11775 
11776 	return TEST_SUCCESS;
11777 }
11778 
11779 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11780 				   struct crypto_unittest_params *ut_params,
11781 				   enum rte_crypto_auth_operation op,
11782 				   const struct HMAC_MD5_vector *test_case)
11783 {
11784 	uint8_t key[64];
11785 	int status;
11786 
11787 	memcpy(key, test_case->key.data, test_case->key.len);
11788 
11789 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11790 	ut_params->auth_xform.next = NULL;
11791 	ut_params->auth_xform.auth.op = op;
11792 
11793 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11794 
11795 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11796 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11797 	ut_params->auth_xform.auth.key.data = key;
11798 
11799 	ut_params->sess = rte_cryptodev_sym_session_create(
11800 			ts_params->session_mpool);
11801 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11802 	if (ut_params->sess == NULL)
11803 		return TEST_FAILED;
11804 
11805 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11806 			ut_params->sess, &ut_params->auth_xform,
11807 			ts_params->session_priv_mpool);
11808 	if (status == -ENOTSUP)
11809 		return TEST_SKIPPED;
11810 
11811 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11812 
11813 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11814 			rte_pktmbuf_tailroom(ut_params->ibuf));
11815 
11816 	return 0;
11817 }
11818 
11819 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11820 			      const struct HMAC_MD5_vector *test_case,
11821 			      uint8_t **plaintext)
11822 {
11823 	uint16_t plaintext_pad_len;
11824 
11825 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11826 
11827 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11828 				16);
11829 
11830 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11831 			plaintext_pad_len);
11832 	memcpy(*plaintext, test_case->plaintext.data,
11833 			test_case->plaintext.len);
11834 
11835 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11836 			ut_params->ibuf, MD5_DIGEST_LEN);
11837 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11838 			"no room to append digest");
11839 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11840 			ut_params->ibuf, plaintext_pad_len);
11841 
11842 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11843 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11844 			   test_case->auth_tag.len);
11845 	}
11846 
11847 	sym_op->auth.data.offset = 0;
11848 	sym_op->auth.data.length = test_case->plaintext.len;
11849 
11850 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11851 	ut_params->op->sym->m_src = ut_params->ibuf;
11852 
11853 	return 0;
11854 }
11855 
11856 static int
11857 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11858 {
11859 	uint16_t plaintext_pad_len;
11860 	uint8_t *plaintext, *auth_tag;
11861 
11862 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11863 	struct crypto_unittest_params *ut_params = &unittest_params;
11864 	struct rte_cryptodev_info dev_info;
11865 
11866 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11867 	uint64_t feat_flags = dev_info.feature_flags;
11868 
11869 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11870 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11871 		printf("Device doesn't support RAW data-path APIs.\n");
11872 		return TEST_SKIPPED;
11873 	}
11874 
11875 	/* Verify the capabilities */
11876 	struct rte_cryptodev_sym_capability_idx cap_idx;
11877 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11878 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11879 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11880 			&cap_idx) == NULL)
11881 		return TEST_SKIPPED;
11882 
11883 	if (MD5_HMAC_create_session(ts_params, ut_params,
11884 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11885 		return TEST_FAILED;
11886 
11887 	/* Generate Crypto op data structure */
11888 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11889 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11890 	TEST_ASSERT_NOT_NULL(ut_params->op,
11891 			"Failed to allocate symmetric crypto operation struct");
11892 
11893 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11894 				16);
11895 
11896 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11897 		return TEST_FAILED;
11898 
11899 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11900 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11901 			ut_params->op);
11902 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11903 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11904 				ut_params->op, 0, 1, 0, 0);
11905 	else
11906 		TEST_ASSERT_NOT_NULL(
11907 			process_crypto_request(ts_params->valid_devs[0],
11908 				ut_params->op),
11909 				"failed to process sym crypto op");
11910 
11911 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11912 			"crypto op processing failed");
11913 
11914 	if (ut_params->op->sym->m_dst) {
11915 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11916 				uint8_t *, plaintext_pad_len);
11917 	} else {
11918 		auth_tag = plaintext + plaintext_pad_len;
11919 	}
11920 
11921 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11922 			auth_tag,
11923 			test_case->auth_tag.data,
11924 			test_case->auth_tag.len,
11925 			"HMAC_MD5 generated tag not as expected");
11926 
11927 	return TEST_SUCCESS;
11928 }
11929 
11930 static int
11931 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11932 {
11933 	uint8_t *plaintext;
11934 
11935 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11936 	struct crypto_unittest_params *ut_params = &unittest_params;
11937 	struct rte_cryptodev_info dev_info;
11938 
11939 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11940 	uint64_t feat_flags = dev_info.feature_flags;
11941 
11942 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11943 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11944 		printf("Device doesn't support RAW data-path APIs.\n");
11945 		return TEST_SKIPPED;
11946 	}
11947 
11948 	/* Verify the capabilities */
11949 	struct rte_cryptodev_sym_capability_idx cap_idx;
11950 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11951 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11952 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11953 			&cap_idx) == NULL)
11954 		return TEST_SKIPPED;
11955 
11956 	if (MD5_HMAC_create_session(ts_params, ut_params,
11957 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11958 		return TEST_FAILED;
11959 	}
11960 
11961 	/* Generate Crypto op data structure */
11962 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11963 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11964 	TEST_ASSERT_NOT_NULL(ut_params->op,
11965 			"Failed to allocate symmetric crypto operation struct");
11966 
11967 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11968 		return TEST_FAILED;
11969 
11970 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11971 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11972 			ut_params->op);
11973 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11974 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11975 				ut_params->op, 0, 1, 0, 0);
11976 	else
11977 		TEST_ASSERT_NOT_NULL(
11978 			process_crypto_request(ts_params->valid_devs[0],
11979 				ut_params->op),
11980 				"failed to process sym crypto op");
11981 
11982 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11983 			"HMAC_MD5 crypto op processing failed");
11984 
11985 	return TEST_SUCCESS;
11986 }
11987 
11988 static int
11989 test_MD5_HMAC_generate_case_1(void)
11990 {
11991 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11992 }
11993 
11994 static int
11995 test_MD5_HMAC_verify_case_1(void)
11996 {
11997 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11998 }
11999 
12000 static int
12001 test_MD5_HMAC_generate_case_2(void)
12002 {
12003 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
12004 }
12005 
12006 static int
12007 test_MD5_HMAC_verify_case_2(void)
12008 {
12009 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
12010 }
12011 
12012 static int
12013 test_multi_session(void)
12014 {
12015 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12016 	struct crypto_unittest_params *ut_params = &unittest_params;
12017 
12018 	struct rte_cryptodev_info dev_info;
12019 	struct rte_cryptodev_sym_session **sessions;
12020 
12021 	uint16_t i;
12022 	int status;
12023 
12024 	/* Verify the capabilities */
12025 	struct rte_cryptodev_sym_capability_idx cap_idx;
12026 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12027 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
12028 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12029 			&cap_idx) == NULL)
12030 		return TEST_SKIPPED;
12031 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12032 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12033 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12034 			&cap_idx) == NULL)
12035 		return TEST_SKIPPED;
12036 
12037 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
12038 			aes_cbc_key, hmac_sha512_key);
12039 
12040 
12041 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12042 
12043 	sessions = rte_malloc(NULL,
12044 			sizeof(struct rte_cryptodev_sym_session *) *
12045 			(MAX_NB_SESSIONS + 1), 0);
12046 
12047 	/* Create multiple crypto sessions*/
12048 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
12049 
12050 		sessions[i] = rte_cryptodev_sym_session_create(
12051 				ts_params->session_mpool);
12052 		TEST_ASSERT_NOT_NULL(sessions[i],
12053 				"Session creation failed at session number %u",
12054 				i);
12055 
12056 		status = rte_cryptodev_sym_session_init(
12057 				ts_params->valid_devs[0],
12058 				sessions[i], &ut_params->auth_xform,
12059 				ts_params->session_priv_mpool);
12060 		if (status == -ENOTSUP)
12061 			return TEST_SKIPPED;
12062 
12063 		/* Attempt to send a request on each session */
12064 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
12065 			sessions[i],
12066 			ut_params,
12067 			ts_params,
12068 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
12069 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
12070 			aes_cbc_iv),
12071 			"Failed to perform decrypt on request number %u.", i);
12072 		/* free crypto operation structure */
12073 		if (ut_params->op)
12074 			rte_crypto_op_free(ut_params->op);
12075 
12076 		/*
12077 		 * free mbuf - both obuf and ibuf are usually the same,
12078 		 * so check if they point at the same address is necessary,
12079 		 * to avoid freeing the mbuf twice.
12080 		 */
12081 		if (ut_params->obuf) {
12082 			rte_pktmbuf_free(ut_params->obuf);
12083 			if (ut_params->ibuf == ut_params->obuf)
12084 				ut_params->ibuf = 0;
12085 			ut_params->obuf = 0;
12086 		}
12087 		if (ut_params->ibuf) {
12088 			rte_pktmbuf_free(ut_params->ibuf);
12089 			ut_params->ibuf = 0;
12090 		}
12091 	}
12092 
12093 	sessions[i] = NULL;
12094 	/* Next session create should fail */
12095 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12096 			sessions[i], &ut_params->auth_xform,
12097 			ts_params->session_priv_mpool);
12098 	TEST_ASSERT_NULL(sessions[i],
12099 			"Session creation succeeded unexpectedly!");
12100 
12101 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
12102 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
12103 				sessions[i]);
12104 		rte_cryptodev_sym_session_free(sessions[i]);
12105 	}
12106 
12107 	rte_free(sessions);
12108 
12109 	return TEST_SUCCESS;
12110 }
12111 
12112 struct multi_session_params {
12113 	struct crypto_unittest_params ut_params;
12114 	uint8_t *cipher_key;
12115 	uint8_t *hmac_key;
12116 	const uint8_t *cipher;
12117 	const uint8_t *digest;
12118 	uint8_t *iv;
12119 };
12120 
12121 #define MB_SESSION_NUMBER 3
12122 
12123 static int
12124 test_multi_session_random_usage(void)
12125 {
12126 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12127 	struct rte_cryptodev_info dev_info;
12128 	struct rte_cryptodev_sym_session **sessions;
12129 	uint32_t i, j;
12130 	struct multi_session_params ut_paramz[] = {
12131 
12132 		{
12133 			.cipher_key = ms_aes_cbc_key0,
12134 			.hmac_key = ms_hmac_key0,
12135 			.cipher = ms_aes_cbc_cipher0,
12136 			.digest = ms_hmac_digest0,
12137 			.iv = ms_aes_cbc_iv0
12138 		},
12139 		{
12140 			.cipher_key = ms_aes_cbc_key1,
12141 			.hmac_key = ms_hmac_key1,
12142 			.cipher = ms_aes_cbc_cipher1,
12143 			.digest = ms_hmac_digest1,
12144 			.iv = ms_aes_cbc_iv1
12145 		},
12146 		{
12147 			.cipher_key = ms_aes_cbc_key2,
12148 			.hmac_key = ms_hmac_key2,
12149 			.cipher = ms_aes_cbc_cipher2,
12150 			.digest = ms_hmac_digest2,
12151 			.iv = ms_aes_cbc_iv2
12152 		},
12153 
12154 	};
12155 	int status;
12156 
12157 	/* Verify the capabilities */
12158 	struct rte_cryptodev_sym_capability_idx cap_idx;
12159 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12160 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
12161 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12162 			&cap_idx) == NULL)
12163 		return TEST_SKIPPED;
12164 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12165 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12166 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12167 			&cap_idx) == NULL)
12168 		return TEST_SKIPPED;
12169 
12170 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12171 
12172 	sessions = rte_malloc(NULL,
12173 			(sizeof(struct rte_cryptodev_sym_session *)
12174 					* MAX_NB_SESSIONS) + 1, 0);
12175 
12176 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
12177 		sessions[i] = rte_cryptodev_sym_session_create(
12178 				ts_params->session_mpool);
12179 		TEST_ASSERT_NOT_NULL(sessions[i],
12180 				"Session creation failed at session number %u",
12181 				i);
12182 
12183 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
12184 				sizeof(struct crypto_unittest_params));
12185 
12186 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
12187 				&ut_paramz[i].ut_params,
12188 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
12189 
12190 		/* Create multiple crypto sessions*/
12191 		status = rte_cryptodev_sym_session_init(
12192 				ts_params->valid_devs[0],
12193 				sessions[i],
12194 				&ut_paramz[i].ut_params.auth_xform,
12195 				ts_params->session_priv_mpool);
12196 
12197 		if (status == -ENOTSUP)
12198 			return TEST_SKIPPED;
12199 
12200 		TEST_ASSERT_EQUAL(status, 0, "Session init failed");
12201 	}
12202 
12203 	srand(time(NULL));
12204 	for (i = 0; i < 40000; i++) {
12205 
12206 		j = rand() % MB_SESSION_NUMBER;
12207 
12208 		TEST_ASSERT_SUCCESS(
12209 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
12210 					sessions[j],
12211 					&ut_paramz[j].ut_params,
12212 					ts_params, ut_paramz[j].cipher,
12213 					ut_paramz[j].digest,
12214 					ut_paramz[j].iv),
12215 			"Failed to perform decrypt on request number %u.", i);
12216 
12217 		if (ut_paramz[j].ut_params.op)
12218 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
12219 
12220 		/*
12221 		 * free mbuf - both obuf and ibuf are usually the same,
12222 		 * so check if they point at the same address is necessary,
12223 		 * to avoid freeing the mbuf twice.
12224 		 */
12225 		if (ut_paramz[j].ut_params.obuf) {
12226 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
12227 			if (ut_paramz[j].ut_params.ibuf
12228 					== ut_paramz[j].ut_params.obuf)
12229 				ut_paramz[j].ut_params.ibuf = 0;
12230 			ut_paramz[j].ut_params.obuf = 0;
12231 		}
12232 		if (ut_paramz[j].ut_params.ibuf) {
12233 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
12234 			ut_paramz[j].ut_params.ibuf = 0;
12235 		}
12236 	}
12237 
12238 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
12239 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
12240 				sessions[i]);
12241 		rte_cryptodev_sym_session_free(sessions[i]);
12242 	}
12243 
12244 	rte_free(sessions);
12245 
12246 	return TEST_SUCCESS;
12247 }
12248 
12249 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
12250 			0xab, 0xab, 0xab, 0xab,
12251 			0xab, 0xab, 0xab, 0xab,
12252 			0xab, 0xab, 0xab, 0xab};
12253 
12254 static int
12255 test_null_invalid_operation(void)
12256 {
12257 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12258 	struct crypto_unittest_params *ut_params = &unittest_params;
12259 	int ret;
12260 
12261 	/* This test is for NULL PMD only */
12262 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
12263 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
12264 		return TEST_SKIPPED;
12265 
12266 	/* Setup Cipher Parameters */
12267 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12268 	ut_params->cipher_xform.next = NULL;
12269 
12270 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
12271 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12272 
12273 	ut_params->sess = rte_cryptodev_sym_session_create(
12274 			ts_params->session_mpool);
12275 
12276 	/* Create Crypto session*/
12277 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12278 			ut_params->sess, &ut_params->cipher_xform,
12279 			ts_params->session_priv_mpool);
12280 	TEST_ASSERT(ret < 0,
12281 			"Session creation succeeded unexpectedly");
12282 
12283 
12284 	/* Setup HMAC Parameters */
12285 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12286 	ut_params->auth_xform.next = NULL;
12287 
12288 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
12289 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12290 
12291 	ut_params->sess = rte_cryptodev_sym_session_create(
12292 			ts_params->session_mpool);
12293 
12294 	/* Create Crypto session*/
12295 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12296 			ut_params->sess, &ut_params->auth_xform,
12297 			ts_params->session_priv_mpool);
12298 	TEST_ASSERT(ret < 0,
12299 			"Session creation succeeded unexpectedly");
12300 
12301 	return TEST_SUCCESS;
12302 }
12303 
12304 
12305 #define NULL_BURST_LENGTH (32)
12306 
12307 static int
12308 test_null_burst_operation(void)
12309 {
12310 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12311 	struct crypto_unittest_params *ut_params = &unittest_params;
12312 	int status;
12313 
12314 	unsigned i, burst_len = NULL_BURST_LENGTH;
12315 
12316 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
12317 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
12318 
12319 	/* This test is for NULL PMD only */
12320 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
12321 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
12322 		return TEST_SKIPPED;
12323 
12324 	/* Setup Cipher Parameters */
12325 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12326 	ut_params->cipher_xform.next = &ut_params->auth_xform;
12327 
12328 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
12329 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12330 
12331 	/* Setup HMAC Parameters */
12332 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12333 	ut_params->auth_xform.next = NULL;
12334 
12335 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
12336 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12337 
12338 	ut_params->sess = rte_cryptodev_sym_session_create(
12339 			ts_params->session_mpool);
12340 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12341 
12342 	/* Create Crypto session*/
12343 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12344 			ut_params->sess, &ut_params->cipher_xform,
12345 			ts_params->session_priv_mpool);
12346 
12347 	if (status == -ENOTSUP)
12348 		return TEST_SKIPPED;
12349 
12350 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
12351 
12352 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
12353 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
12354 			burst_len, "failed to generate burst of crypto ops");
12355 
12356 	/* Generate an operation for each mbuf in burst */
12357 	for (i = 0; i < burst_len; i++) {
12358 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12359 
12360 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
12361 
12362 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
12363 				sizeof(unsigned));
12364 		*data = i;
12365 
12366 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
12367 
12368 		burst[i]->sym->m_src = m;
12369 	}
12370 
12371 	/* Process crypto operation */
12372 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
12373 			0, burst, burst_len),
12374 			burst_len,
12375 			"Error enqueuing burst");
12376 
12377 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
12378 			0, burst_dequeued, burst_len),
12379 			burst_len,
12380 			"Error dequeuing burst");
12381 
12382 
12383 	for (i = 0; i < burst_len; i++) {
12384 		TEST_ASSERT_EQUAL(
12385 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
12386 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
12387 					uint32_t *),
12388 			"data not as expected");
12389 
12390 		rte_pktmbuf_free(burst[i]->sym->m_src);
12391 		rte_crypto_op_free(burst[i]);
12392 	}
12393 
12394 	return TEST_SUCCESS;
12395 }
12396 
12397 static uint16_t
12398 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
12399 		  uint16_t nb_ops, void *user_param)
12400 {
12401 	RTE_SET_USED(dev_id);
12402 	RTE_SET_USED(qp_id);
12403 	RTE_SET_USED(ops);
12404 	RTE_SET_USED(user_param);
12405 
12406 	printf("crypto enqueue callback called\n");
12407 	return nb_ops;
12408 }
12409 
12410 static uint16_t
12411 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
12412 		  uint16_t nb_ops, void *user_param)
12413 {
12414 	RTE_SET_USED(dev_id);
12415 	RTE_SET_USED(qp_id);
12416 	RTE_SET_USED(ops);
12417 	RTE_SET_USED(user_param);
12418 
12419 	printf("crypto dequeue callback called\n");
12420 	return nb_ops;
12421 }
12422 
12423 /*
12424  * Thread using enqueue/dequeue callback with RCU.
12425  */
12426 static int
12427 test_enqdeq_callback_thread(void *arg)
12428 {
12429 	RTE_SET_USED(arg);
12430 	/* DP thread calls rte_cryptodev_enqueue_burst()/
12431 	 * rte_cryptodev_dequeue_burst() and invokes callback.
12432 	 */
12433 	test_null_burst_operation();
12434 	return 0;
12435 }
12436 
12437 static int
12438 test_enq_callback_setup(void)
12439 {
12440 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12441 	struct rte_cryptodev_info dev_info;
12442 	struct rte_cryptodev_qp_conf qp_conf = {
12443 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
12444 	};
12445 
12446 	struct rte_cryptodev_cb *cb;
12447 	uint16_t qp_id = 0;
12448 
12449 	/* Stop the device in case it's started so it can be configured */
12450 	rte_cryptodev_stop(ts_params->valid_devs[0]);
12451 
12452 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12453 
12454 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12455 			&ts_params->conf),
12456 			"Failed to configure cryptodev %u",
12457 			ts_params->valid_devs[0]);
12458 
12459 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12460 	qp_conf.mp_session = ts_params->session_mpool;
12461 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
12462 
12463 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12464 			ts_params->valid_devs[0], qp_id, &qp_conf,
12465 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12466 			"Failed test for "
12467 			"rte_cryptodev_queue_pair_setup: num_inflights "
12468 			"%u on qp %u on cryptodev %u",
12469 			qp_conf.nb_descriptors, qp_id,
12470 			ts_params->valid_devs[0]);
12471 
12472 	/* Test with invalid crypto device */
12473 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
12474 			qp_id, test_enq_callback, NULL);
12475 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12476 			"cryptodev %u did not fail",
12477 			qp_id, RTE_CRYPTO_MAX_DEVS);
12478 
12479 	/* Test with invalid queue pair */
12480 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12481 			dev_info.max_nb_queue_pairs + 1,
12482 			test_enq_callback, NULL);
12483 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12484 			"cryptodev %u did not fail",
12485 			dev_info.max_nb_queue_pairs + 1,
12486 			ts_params->valid_devs[0]);
12487 
12488 	/* Test with NULL callback */
12489 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12490 			qp_id, NULL, NULL);
12491 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12492 			"cryptodev %u did not fail",
12493 			qp_id, ts_params->valid_devs[0]);
12494 
12495 	/* Test with valid configuration */
12496 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12497 			qp_id, test_enq_callback, NULL);
12498 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12499 			"qp %u on cryptodev %u",
12500 			qp_id, ts_params->valid_devs[0]);
12501 
12502 	rte_cryptodev_start(ts_params->valid_devs[0]);
12503 
12504 	/* Launch a thread */
12505 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12506 				rte_get_next_lcore(-1, 1, 0));
12507 
12508 	/* Wait until reader exited. */
12509 	rte_eal_mp_wait_lcore();
12510 
12511 	/* Test with invalid crypto device */
12512 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12513 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12514 			"Expected call to fail as crypto device is invalid");
12515 
12516 	/* Test with invalid queue pair */
12517 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12518 			ts_params->valid_devs[0],
12519 			dev_info.max_nb_queue_pairs + 1, cb),
12520 			"Expected call to fail as queue pair is invalid");
12521 
12522 	/* Test with NULL callback */
12523 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12524 			ts_params->valid_devs[0], qp_id, NULL),
12525 			"Expected call to fail as callback is NULL");
12526 
12527 	/* Test with valid configuration */
12528 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
12529 			ts_params->valid_devs[0], qp_id, cb),
12530 			"Failed test to remove callback on "
12531 			"qp %u on cryptodev %u",
12532 			qp_id, ts_params->valid_devs[0]);
12533 
12534 	return TEST_SUCCESS;
12535 }
12536 
12537 static int
12538 test_deq_callback_setup(void)
12539 {
12540 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12541 	struct rte_cryptodev_info dev_info;
12542 	struct rte_cryptodev_qp_conf qp_conf = {
12543 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
12544 	};
12545 
12546 	struct rte_cryptodev_cb *cb;
12547 	uint16_t qp_id = 0;
12548 
12549 	/* Stop the device in case it's started so it can be configured */
12550 	rte_cryptodev_stop(ts_params->valid_devs[0]);
12551 
12552 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12553 
12554 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12555 			&ts_params->conf),
12556 			"Failed to configure cryptodev %u",
12557 			ts_params->valid_devs[0]);
12558 
12559 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12560 	qp_conf.mp_session = ts_params->session_mpool;
12561 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
12562 
12563 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12564 			ts_params->valid_devs[0], qp_id, &qp_conf,
12565 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12566 			"Failed test for "
12567 			"rte_cryptodev_queue_pair_setup: num_inflights "
12568 			"%u on qp %u on cryptodev %u",
12569 			qp_conf.nb_descriptors, qp_id,
12570 			ts_params->valid_devs[0]);
12571 
12572 	/* Test with invalid crypto device */
12573 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
12574 			qp_id, test_deq_callback, NULL);
12575 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12576 			"cryptodev %u did not fail",
12577 			qp_id, RTE_CRYPTO_MAX_DEVS);
12578 
12579 	/* Test with invalid queue pair */
12580 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12581 			dev_info.max_nb_queue_pairs + 1,
12582 			test_deq_callback, NULL);
12583 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12584 			"cryptodev %u did not fail",
12585 			dev_info.max_nb_queue_pairs + 1,
12586 			ts_params->valid_devs[0]);
12587 
12588 	/* Test with NULL callback */
12589 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12590 			qp_id, NULL, NULL);
12591 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12592 			"cryptodev %u did not fail",
12593 			qp_id, ts_params->valid_devs[0]);
12594 
12595 	/* Test with valid configuration */
12596 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12597 			qp_id, test_deq_callback, NULL);
12598 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12599 			"qp %u on cryptodev %u",
12600 			qp_id, ts_params->valid_devs[0]);
12601 
12602 	rte_cryptodev_start(ts_params->valid_devs[0]);
12603 
12604 	/* Launch a thread */
12605 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12606 				rte_get_next_lcore(-1, 1, 0));
12607 
12608 	/* Wait until reader exited. */
12609 	rte_eal_mp_wait_lcore();
12610 
12611 	/* Test with invalid crypto device */
12612 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12613 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12614 			"Expected call to fail as crypto device is invalid");
12615 
12616 	/* Test with invalid queue pair */
12617 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12618 			ts_params->valid_devs[0],
12619 			dev_info.max_nb_queue_pairs + 1, cb),
12620 			"Expected call to fail as queue pair is invalid");
12621 
12622 	/* Test with NULL callback */
12623 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12624 			ts_params->valid_devs[0], qp_id, NULL),
12625 			"Expected call to fail as callback is NULL");
12626 
12627 	/* Test with valid configuration */
12628 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
12629 			ts_params->valid_devs[0], qp_id, cb),
12630 			"Failed test to remove callback on "
12631 			"qp %u on cryptodev %u",
12632 			qp_id, ts_params->valid_devs[0]);
12633 
12634 	return TEST_SUCCESS;
12635 }
12636 
12637 static void
12638 generate_gmac_large_plaintext(uint8_t *data)
12639 {
12640 	uint16_t i;
12641 
12642 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
12643 		memcpy(&data[i], &data[0], 32);
12644 }
12645 
12646 static int
12647 create_gmac_operation(enum rte_crypto_auth_operation op,
12648 		const struct gmac_test_data *tdata)
12649 {
12650 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12651 	struct crypto_unittest_params *ut_params = &unittest_params;
12652 	struct rte_crypto_sym_op *sym_op;
12653 
12654 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12655 
12656 	/* Generate Crypto op data structure */
12657 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12658 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12659 	TEST_ASSERT_NOT_NULL(ut_params->op,
12660 			"Failed to allocate symmetric crypto operation struct");
12661 
12662 	sym_op = ut_params->op->sym;
12663 
12664 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12665 			ut_params->ibuf, tdata->gmac_tag.len);
12666 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12667 			"no room to append digest");
12668 
12669 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12670 			ut_params->ibuf, plaintext_pad_len);
12671 
12672 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12673 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12674 				tdata->gmac_tag.len);
12675 		debug_hexdump(stdout, "digest:",
12676 				sym_op->auth.digest.data,
12677 				tdata->gmac_tag.len);
12678 	}
12679 
12680 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12681 			uint8_t *, IV_OFFSET);
12682 
12683 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12684 
12685 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12686 
12687 	sym_op->cipher.data.length = 0;
12688 	sym_op->cipher.data.offset = 0;
12689 
12690 	sym_op->auth.data.offset = 0;
12691 	sym_op->auth.data.length = tdata->plaintext.len;
12692 
12693 	return 0;
12694 }
12695 
12696 static int
12697 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12698 		const struct gmac_test_data *tdata,
12699 		void *digest_mem, uint64_t digest_phys)
12700 {
12701 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12702 	struct crypto_unittest_params *ut_params = &unittest_params;
12703 	struct rte_crypto_sym_op *sym_op;
12704 
12705 	/* Generate Crypto op data structure */
12706 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12707 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12708 	TEST_ASSERT_NOT_NULL(ut_params->op,
12709 			"Failed to allocate symmetric crypto operation struct");
12710 
12711 	sym_op = ut_params->op->sym;
12712 
12713 	sym_op->auth.digest.data = digest_mem;
12714 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12715 			"no room to append digest");
12716 
12717 	sym_op->auth.digest.phys_addr = digest_phys;
12718 
12719 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12720 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12721 				tdata->gmac_tag.len);
12722 		debug_hexdump(stdout, "digest:",
12723 				sym_op->auth.digest.data,
12724 				tdata->gmac_tag.len);
12725 	}
12726 
12727 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12728 			uint8_t *, IV_OFFSET);
12729 
12730 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12731 
12732 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12733 
12734 	sym_op->cipher.data.length = 0;
12735 	sym_op->cipher.data.offset = 0;
12736 
12737 	sym_op->auth.data.offset = 0;
12738 	sym_op->auth.data.length = tdata->plaintext.len;
12739 
12740 	return 0;
12741 }
12742 
12743 static int create_gmac_session(uint8_t dev_id,
12744 		const struct gmac_test_data *tdata,
12745 		enum rte_crypto_auth_operation auth_op)
12746 {
12747 	uint8_t auth_key[tdata->key.len];
12748 	int status;
12749 
12750 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12751 	struct crypto_unittest_params *ut_params = &unittest_params;
12752 
12753 	memcpy(auth_key, tdata->key.data, tdata->key.len);
12754 
12755 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12756 	ut_params->auth_xform.next = NULL;
12757 
12758 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12759 	ut_params->auth_xform.auth.op = auth_op;
12760 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12761 	ut_params->auth_xform.auth.key.length = tdata->key.len;
12762 	ut_params->auth_xform.auth.key.data = auth_key;
12763 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12764 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12765 
12766 
12767 	ut_params->sess = rte_cryptodev_sym_session_create(
12768 			ts_params->session_mpool);
12769 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12770 
12771 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12772 			&ut_params->auth_xform,
12773 			ts_params->session_priv_mpool);
12774 
12775 	return status;
12776 }
12777 
12778 static int
12779 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12780 {
12781 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12782 	struct crypto_unittest_params *ut_params = &unittest_params;
12783 	struct rte_cryptodev_info dev_info;
12784 
12785 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12786 	uint64_t feat_flags = dev_info.feature_flags;
12787 
12788 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12789 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12790 		printf("Device doesn't support RAW data-path APIs.\n");
12791 		return TEST_SKIPPED;
12792 	}
12793 
12794 	int retval;
12795 
12796 	uint8_t *auth_tag, *plaintext;
12797 	uint16_t plaintext_pad_len;
12798 
12799 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12800 			      "No GMAC length in the source data");
12801 
12802 	/* Verify the capabilities */
12803 	struct rte_cryptodev_sym_capability_idx cap_idx;
12804 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12805 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12806 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12807 			&cap_idx) == NULL)
12808 		return TEST_SKIPPED;
12809 
12810 	retval = create_gmac_session(ts_params->valid_devs[0],
12811 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12812 
12813 	if (retval == -ENOTSUP)
12814 		return TEST_SKIPPED;
12815 	if (retval < 0)
12816 		return retval;
12817 
12818 	if (tdata->plaintext.len > MBUF_SIZE)
12819 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12820 	else
12821 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12822 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12823 			"Failed to allocate input buffer in mempool");
12824 
12825 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12826 			rte_pktmbuf_tailroom(ut_params->ibuf));
12827 
12828 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12829 	/*
12830 	 * Runtime generate the large plain text instead of use hard code
12831 	 * plain text vector. It is done to avoid create huge source file
12832 	 * with the test vector.
12833 	 */
12834 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12835 		generate_gmac_large_plaintext(tdata->plaintext.data);
12836 
12837 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12838 				plaintext_pad_len);
12839 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12840 
12841 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12842 	debug_hexdump(stdout, "plaintext:", plaintext,
12843 			tdata->plaintext.len);
12844 
12845 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12846 			tdata);
12847 
12848 	if (retval < 0)
12849 		return retval;
12850 
12851 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12852 
12853 	ut_params->op->sym->m_src = ut_params->ibuf;
12854 
12855 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12856 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12857 			ut_params->op);
12858 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12859 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12860 				ut_params->op, 0, 1, 0, 0);
12861 	else
12862 		TEST_ASSERT_NOT_NULL(
12863 			process_crypto_request(ts_params->valid_devs[0],
12864 			ut_params->op), "failed to process sym crypto op");
12865 
12866 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12867 			"crypto op processing failed");
12868 
12869 	if (ut_params->op->sym->m_dst) {
12870 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12871 				uint8_t *, plaintext_pad_len);
12872 	} else {
12873 		auth_tag = plaintext + plaintext_pad_len;
12874 	}
12875 
12876 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12877 
12878 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12879 			auth_tag,
12880 			tdata->gmac_tag.data,
12881 			tdata->gmac_tag.len,
12882 			"GMAC Generated auth tag not as expected");
12883 
12884 	return 0;
12885 }
12886 
12887 static int
12888 test_AES_GMAC_authentication_test_case_1(void)
12889 {
12890 	return test_AES_GMAC_authentication(&gmac_test_case_1);
12891 }
12892 
12893 static int
12894 test_AES_GMAC_authentication_test_case_2(void)
12895 {
12896 	return test_AES_GMAC_authentication(&gmac_test_case_2);
12897 }
12898 
12899 static int
12900 test_AES_GMAC_authentication_test_case_3(void)
12901 {
12902 	return test_AES_GMAC_authentication(&gmac_test_case_3);
12903 }
12904 
12905 static int
12906 test_AES_GMAC_authentication_test_case_4(void)
12907 {
12908 	return test_AES_GMAC_authentication(&gmac_test_case_4);
12909 }
12910 
12911 static int
12912 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12913 {
12914 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12915 	struct crypto_unittest_params *ut_params = &unittest_params;
12916 	int retval;
12917 	uint32_t plaintext_pad_len;
12918 	uint8_t *plaintext;
12919 	struct rte_cryptodev_info dev_info;
12920 
12921 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12922 	uint64_t feat_flags = dev_info.feature_flags;
12923 
12924 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12925 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12926 		printf("Device doesn't support RAW data-path APIs.\n");
12927 		return TEST_SKIPPED;
12928 	}
12929 
12930 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12931 			      "No GMAC length in the source data");
12932 
12933 	/* Verify the capabilities */
12934 	struct rte_cryptodev_sym_capability_idx cap_idx;
12935 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12936 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12937 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12938 			&cap_idx) == NULL)
12939 		return TEST_SKIPPED;
12940 
12941 	retval = create_gmac_session(ts_params->valid_devs[0],
12942 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12943 
12944 	if (retval == -ENOTSUP)
12945 		return TEST_SKIPPED;
12946 	if (retval < 0)
12947 		return retval;
12948 
12949 	if (tdata->plaintext.len > MBUF_SIZE)
12950 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12951 	else
12952 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12953 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12954 			"Failed to allocate input buffer in mempool");
12955 
12956 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12957 			rte_pktmbuf_tailroom(ut_params->ibuf));
12958 
12959 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12960 
12961 	/*
12962 	 * Runtime generate the large plain text instead of use hard code
12963 	 * plain text vector. It is done to avoid create huge source file
12964 	 * with the test vector.
12965 	 */
12966 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12967 		generate_gmac_large_plaintext(tdata->plaintext.data);
12968 
12969 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12970 				plaintext_pad_len);
12971 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12972 
12973 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12974 	debug_hexdump(stdout, "plaintext:", plaintext,
12975 			tdata->plaintext.len);
12976 
12977 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12978 			tdata);
12979 
12980 	if (retval < 0)
12981 		return retval;
12982 
12983 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12984 
12985 	ut_params->op->sym->m_src = ut_params->ibuf;
12986 
12987 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12988 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12989 			ut_params->op);
12990 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12991 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12992 				ut_params->op, 0, 1, 0, 0);
12993 	else
12994 		TEST_ASSERT_NOT_NULL(
12995 			process_crypto_request(ts_params->valid_devs[0],
12996 			ut_params->op), "failed to process sym crypto op");
12997 
12998 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12999 			"crypto op processing failed");
13000 
13001 	return 0;
13002 
13003 }
13004 
13005 static int
13006 test_AES_GMAC_authentication_verify_test_case_1(void)
13007 {
13008 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
13009 }
13010 
13011 static int
13012 test_AES_GMAC_authentication_verify_test_case_2(void)
13013 {
13014 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
13015 }
13016 
13017 static int
13018 test_AES_GMAC_authentication_verify_test_case_3(void)
13019 {
13020 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
13021 }
13022 
13023 static int
13024 test_AES_GMAC_authentication_verify_test_case_4(void)
13025 {
13026 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
13027 }
13028 
13029 static int
13030 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
13031 				uint32_t fragsz)
13032 {
13033 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13034 	struct crypto_unittest_params *ut_params = &unittest_params;
13035 	struct rte_cryptodev_info dev_info;
13036 	uint64_t feature_flags;
13037 	unsigned int trn_data = 0;
13038 	void *digest_mem = NULL;
13039 	uint32_t segs = 1;
13040 	unsigned int to_trn = 0;
13041 	struct rte_mbuf *buf = NULL;
13042 	uint8_t *auth_tag, *plaintext;
13043 	int retval;
13044 
13045 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
13046 			      "No GMAC length in the source data");
13047 
13048 	/* Verify the capabilities */
13049 	struct rte_cryptodev_sym_capability_idx cap_idx;
13050 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13051 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
13052 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13053 			&cap_idx) == NULL)
13054 		return TEST_SKIPPED;
13055 
13056 	/* Check for any input SGL support */
13057 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13058 	feature_flags = dev_info.feature_flags;
13059 
13060 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
13061 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
13062 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
13063 		return TEST_SKIPPED;
13064 
13065 	if (fragsz > tdata->plaintext.len)
13066 		fragsz = tdata->plaintext.len;
13067 
13068 	uint16_t plaintext_len = fragsz;
13069 
13070 	retval = create_gmac_session(ts_params->valid_devs[0],
13071 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
13072 
13073 	if (retval == -ENOTSUP)
13074 		return TEST_SKIPPED;
13075 	if (retval < 0)
13076 		return retval;
13077 
13078 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13079 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13080 			"Failed to allocate input buffer in mempool");
13081 
13082 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13083 			rte_pktmbuf_tailroom(ut_params->ibuf));
13084 
13085 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13086 				plaintext_len);
13087 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13088 
13089 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13090 
13091 	trn_data += plaintext_len;
13092 
13093 	buf = ut_params->ibuf;
13094 
13095 	/*
13096 	 * Loop until no more fragments
13097 	 */
13098 
13099 	while (trn_data < tdata->plaintext.len) {
13100 		++segs;
13101 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13102 				(tdata->plaintext.len - trn_data) : fragsz;
13103 
13104 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13105 		buf = buf->next;
13106 
13107 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13108 				rte_pktmbuf_tailroom(buf));
13109 
13110 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13111 				to_trn);
13112 
13113 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13114 				to_trn);
13115 		trn_data += to_trn;
13116 		if (trn_data  == tdata->plaintext.len)
13117 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13118 					tdata->gmac_tag.len);
13119 	}
13120 	ut_params->ibuf->nb_segs = segs;
13121 
13122 	/*
13123 	 * Place digest at the end of the last buffer
13124 	 */
13125 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13126 
13127 	if (!digest_mem) {
13128 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13129 				+ tdata->gmac_tag.len);
13130 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13131 				tdata->plaintext.len);
13132 	}
13133 
13134 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
13135 			tdata, digest_mem, digest_phys);
13136 
13137 	if (retval < 0)
13138 		return retval;
13139 
13140 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13141 
13142 	ut_params->op->sym->m_src = ut_params->ibuf;
13143 
13144 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13145 		return TEST_SKIPPED;
13146 
13147 	TEST_ASSERT_NOT_NULL(
13148 		process_crypto_request(ts_params->valid_devs[0],
13149 		ut_params->op), "failed to process sym crypto op");
13150 
13151 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13152 			"crypto op processing failed");
13153 
13154 	auth_tag = digest_mem;
13155 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
13156 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13157 			auth_tag,
13158 			tdata->gmac_tag.data,
13159 			tdata->gmac_tag.len,
13160 			"GMAC Generated auth tag not as expected");
13161 
13162 	return 0;
13163 }
13164 
13165 /* Segment size not multiple of block size (16B) */
13166 static int
13167 test_AES_GMAC_authentication_SGL_40B(void)
13168 {
13169 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
13170 }
13171 
13172 static int
13173 test_AES_GMAC_authentication_SGL_80B(void)
13174 {
13175 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
13176 }
13177 
13178 static int
13179 test_AES_GMAC_authentication_SGL_2048B(void)
13180 {
13181 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
13182 }
13183 
13184 /* Segment size not multiple of block size (16B) */
13185 static int
13186 test_AES_GMAC_authentication_SGL_2047B(void)
13187 {
13188 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
13189 }
13190 
13191 struct test_crypto_vector {
13192 	enum rte_crypto_cipher_algorithm crypto_algo;
13193 	unsigned int cipher_offset;
13194 	unsigned int cipher_len;
13195 
13196 	struct {
13197 		uint8_t data[64];
13198 		unsigned int len;
13199 	} cipher_key;
13200 
13201 	struct {
13202 		uint8_t data[64];
13203 		unsigned int len;
13204 	} iv;
13205 
13206 	struct {
13207 		const uint8_t *data;
13208 		unsigned int len;
13209 	} plaintext;
13210 
13211 	struct {
13212 		const uint8_t *data;
13213 		unsigned int len;
13214 	} ciphertext;
13215 
13216 	enum rte_crypto_auth_algorithm auth_algo;
13217 	unsigned int auth_offset;
13218 
13219 	struct {
13220 		uint8_t data[128];
13221 		unsigned int len;
13222 	} auth_key;
13223 
13224 	struct {
13225 		const uint8_t *data;
13226 		unsigned int len;
13227 	} aad;
13228 
13229 	struct {
13230 		uint8_t data[128];
13231 		unsigned int len;
13232 	} digest;
13233 };
13234 
13235 static const struct test_crypto_vector
13236 hmac_sha1_test_crypto_vector = {
13237 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13238 	.plaintext = {
13239 		.data = plaintext_hash,
13240 		.len = 512
13241 	},
13242 	.auth_key = {
13243 		.data = {
13244 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13245 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13246 			0xDE, 0xF4, 0xDE, 0xAD
13247 		},
13248 		.len = 20
13249 	},
13250 	.digest = {
13251 		.data = {
13252 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
13253 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
13254 			0x3F, 0x91, 0x64, 0x59
13255 		},
13256 		.len = 20
13257 	}
13258 };
13259 
13260 static const struct test_crypto_vector
13261 aes128_gmac_test_vector = {
13262 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
13263 	.plaintext = {
13264 		.data = plaintext_hash,
13265 		.len = 512
13266 	},
13267 	.iv = {
13268 		.data = {
13269 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13270 			0x08, 0x09, 0x0A, 0x0B
13271 		},
13272 		.len = 12
13273 	},
13274 	.auth_key = {
13275 		.data = {
13276 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
13277 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
13278 		},
13279 		.len = 16
13280 	},
13281 	.digest = {
13282 		.data = {
13283 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
13284 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
13285 		},
13286 		.len = 16
13287 	}
13288 };
13289 
13290 static const struct test_crypto_vector
13291 aes128cbc_hmac_sha1_test_vector = {
13292 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
13293 	.cipher_offset = 0,
13294 	.cipher_len = 512,
13295 	.cipher_key = {
13296 		.data = {
13297 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
13298 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
13299 		},
13300 		.len = 16
13301 	},
13302 	.iv = {
13303 		.data = {
13304 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13305 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
13306 		},
13307 		.len = 16
13308 	},
13309 	.plaintext = {
13310 		.data = plaintext_hash,
13311 		.len = 512
13312 	},
13313 	.ciphertext = {
13314 		.data = ciphertext512_aes128cbc,
13315 		.len = 512
13316 	},
13317 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13318 	.auth_offset = 0,
13319 	.auth_key = {
13320 		.data = {
13321 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13322 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13323 			0xDE, 0xF4, 0xDE, 0xAD
13324 		},
13325 		.len = 20
13326 	},
13327 	.digest = {
13328 		.data = {
13329 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
13330 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
13331 			0x18, 0x8C, 0x1D, 0x32
13332 		},
13333 		.len = 20
13334 	}
13335 };
13336 
13337 static const struct test_crypto_vector
13338 aes128cbc_hmac_sha1_aad_test_vector = {
13339 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
13340 	.cipher_offset = 8,
13341 	.cipher_len = 496,
13342 	.cipher_key = {
13343 		.data = {
13344 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
13345 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
13346 		},
13347 		.len = 16
13348 	},
13349 	.iv = {
13350 		.data = {
13351 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13352 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
13353 		},
13354 		.len = 16
13355 	},
13356 	.plaintext = {
13357 		.data = plaintext_hash,
13358 		.len = 512
13359 	},
13360 	.ciphertext = {
13361 		.data = ciphertext512_aes128cbc_aad,
13362 		.len = 512
13363 	},
13364 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13365 	.auth_offset = 0,
13366 	.auth_key = {
13367 		.data = {
13368 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13369 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13370 			0xDE, 0xF4, 0xDE, 0xAD
13371 		},
13372 		.len = 20
13373 	},
13374 	.digest = {
13375 		.data = {
13376 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
13377 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
13378 			0x62, 0x0F, 0xFB, 0x10
13379 		},
13380 		.len = 20
13381 	}
13382 };
13383 
13384 static void
13385 data_corruption(uint8_t *data)
13386 {
13387 	data[0] += 1;
13388 }
13389 
13390 static void
13391 tag_corruption(uint8_t *data, unsigned int tag_offset)
13392 {
13393 	data[tag_offset] += 1;
13394 }
13395 
13396 static int
13397 create_auth_session(struct crypto_unittest_params *ut_params,
13398 		uint8_t dev_id,
13399 		const struct test_crypto_vector *reference,
13400 		enum rte_crypto_auth_operation auth_op)
13401 {
13402 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13403 	uint8_t auth_key[reference->auth_key.len + 1];
13404 	int status;
13405 
13406 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13407 
13408 	/* Setup Authentication Parameters */
13409 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13410 	ut_params->auth_xform.auth.op = auth_op;
13411 	ut_params->auth_xform.next = NULL;
13412 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13413 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13414 	ut_params->auth_xform.auth.key.data = auth_key;
13415 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13416 
13417 	/* Create Crypto session*/
13418 	ut_params->sess = rte_cryptodev_sym_session_create(
13419 			ts_params->session_mpool);
13420 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13421 
13422 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
13423 				&ut_params->auth_xform,
13424 				ts_params->session_priv_mpool);
13425 
13426 	return status;
13427 }
13428 
13429 static int
13430 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
13431 		uint8_t dev_id,
13432 		const struct test_crypto_vector *reference,
13433 		enum rte_crypto_auth_operation auth_op,
13434 		enum rte_crypto_cipher_operation cipher_op)
13435 {
13436 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13437 	uint8_t cipher_key[reference->cipher_key.len + 1];
13438 	uint8_t auth_key[reference->auth_key.len + 1];
13439 	int status;
13440 
13441 	memcpy(cipher_key, reference->cipher_key.data,
13442 			reference->cipher_key.len);
13443 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13444 
13445 	/* Setup Authentication Parameters */
13446 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13447 	ut_params->auth_xform.auth.op = auth_op;
13448 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13449 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13450 	ut_params->auth_xform.auth.key.data = auth_key;
13451 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13452 
13453 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
13454 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
13455 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
13456 	} else {
13457 		ut_params->auth_xform.next = &ut_params->cipher_xform;
13458 
13459 		/* Setup Cipher Parameters */
13460 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13461 		ut_params->cipher_xform.next = NULL;
13462 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13463 		ut_params->cipher_xform.cipher.op = cipher_op;
13464 		ut_params->cipher_xform.cipher.key.data = cipher_key;
13465 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13466 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13467 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13468 	}
13469 
13470 	/* Create Crypto session*/
13471 	ut_params->sess = rte_cryptodev_sym_session_create(
13472 			ts_params->session_mpool);
13473 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13474 
13475 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
13476 				&ut_params->auth_xform,
13477 				ts_params->session_priv_mpool);
13478 
13479 	return status;
13480 }
13481 
13482 static int
13483 create_auth_operation(struct crypto_testsuite_params *ts_params,
13484 		struct crypto_unittest_params *ut_params,
13485 		const struct test_crypto_vector *reference,
13486 		unsigned int auth_generate)
13487 {
13488 	/* Generate Crypto op data structure */
13489 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13490 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13491 	TEST_ASSERT_NOT_NULL(ut_params->op,
13492 			"Failed to allocate pktmbuf offload");
13493 
13494 	/* Set crypto operation data parameters */
13495 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13496 
13497 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13498 
13499 	/* set crypto operation source mbuf */
13500 	sym_op->m_src = ut_params->ibuf;
13501 
13502 	/* digest */
13503 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13504 			ut_params->ibuf, reference->digest.len);
13505 
13506 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13507 			"no room to append auth tag");
13508 
13509 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13510 			ut_params->ibuf, reference->plaintext.len);
13511 
13512 	if (auth_generate)
13513 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13514 	else
13515 		memcpy(sym_op->auth.digest.data,
13516 				reference->digest.data,
13517 				reference->digest.len);
13518 
13519 	debug_hexdump(stdout, "digest:",
13520 			sym_op->auth.digest.data,
13521 			reference->digest.len);
13522 
13523 	sym_op->auth.data.length = reference->plaintext.len;
13524 	sym_op->auth.data.offset = 0;
13525 
13526 	return 0;
13527 }
13528 
13529 static int
13530 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
13531 		struct crypto_unittest_params *ut_params,
13532 		const struct test_crypto_vector *reference,
13533 		unsigned int auth_generate)
13534 {
13535 	/* Generate Crypto op data structure */
13536 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13537 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13538 	TEST_ASSERT_NOT_NULL(ut_params->op,
13539 			"Failed to allocate pktmbuf offload");
13540 
13541 	/* Set crypto operation data parameters */
13542 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13543 
13544 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13545 
13546 	/* set crypto operation source mbuf */
13547 	sym_op->m_src = ut_params->ibuf;
13548 
13549 	/* digest */
13550 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13551 			ut_params->ibuf, reference->digest.len);
13552 
13553 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13554 			"no room to append auth tag");
13555 
13556 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13557 			ut_params->ibuf, reference->ciphertext.len);
13558 
13559 	if (auth_generate)
13560 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13561 	else
13562 		memcpy(sym_op->auth.digest.data,
13563 				reference->digest.data,
13564 				reference->digest.len);
13565 
13566 	debug_hexdump(stdout, "digest:",
13567 			sym_op->auth.digest.data,
13568 			reference->digest.len);
13569 
13570 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13571 			reference->iv.data, reference->iv.len);
13572 
13573 	sym_op->cipher.data.length = 0;
13574 	sym_op->cipher.data.offset = 0;
13575 
13576 	sym_op->auth.data.length = reference->plaintext.len;
13577 	sym_op->auth.data.offset = 0;
13578 
13579 	return 0;
13580 }
13581 
13582 static int
13583 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
13584 		struct crypto_unittest_params *ut_params,
13585 		const struct test_crypto_vector *reference,
13586 		unsigned int auth_generate)
13587 {
13588 	/* Generate Crypto op data structure */
13589 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13590 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13591 	TEST_ASSERT_NOT_NULL(ut_params->op,
13592 			"Failed to allocate pktmbuf offload");
13593 
13594 	/* Set crypto operation data parameters */
13595 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13596 
13597 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13598 
13599 	/* set crypto operation source mbuf */
13600 	sym_op->m_src = ut_params->ibuf;
13601 
13602 	/* digest */
13603 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13604 			ut_params->ibuf, reference->digest.len);
13605 
13606 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13607 			"no room to append auth tag");
13608 
13609 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13610 			ut_params->ibuf, reference->ciphertext.len);
13611 
13612 	if (auth_generate)
13613 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13614 	else
13615 		memcpy(sym_op->auth.digest.data,
13616 				reference->digest.data,
13617 				reference->digest.len);
13618 
13619 	debug_hexdump(stdout, "digest:",
13620 			sym_op->auth.digest.data,
13621 			reference->digest.len);
13622 
13623 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13624 			reference->iv.data, reference->iv.len);
13625 
13626 	sym_op->cipher.data.length = reference->cipher_len;
13627 	sym_op->cipher.data.offset = reference->cipher_offset;
13628 
13629 	sym_op->auth.data.length = reference->plaintext.len;
13630 	sym_op->auth.data.offset = reference->auth_offset;
13631 
13632 	return 0;
13633 }
13634 
13635 static int
13636 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13637 		struct crypto_unittest_params *ut_params,
13638 		const struct test_crypto_vector *reference)
13639 {
13640 	return create_auth_operation(ts_params, ut_params, reference, 0);
13641 }
13642 
13643 static int
13644 create_auth_verify_GMAC_operation(
13645 		struct crypto_testsuite_params *ts_params,
13646 		struct crypto_unittest_params *ut_params,
13647 		const struct test_crypto_vector *reference)
13648 {
13649 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
13650 }
13651 
13652 static int
13653 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13654 		struct crypto_unittest_params *ut_params,
13655 		const struct test_crypto_vector *reference)
13656 {
13657 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
13658 }
13659 
13660 static int
13661 test_authentication_verify_fail_when_data_corruption(
13662 		struct crypto_testsuite_params *ts_params,
13663 		struct crypto_unittest_params *ut_params,
13664 		const struct test_crypto_vector *reference,
13665 		unsigned int data_corrupted)
13666 {
13667 	int retval;
13668 
13669 	uint8_t *plaintext;
13670 	struct rte_cryptodev_info dev_info;
13671 
13672 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13673 	uint64_t feat_flags = dev_info.feature_flags;
13674 
13675 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13676 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13677 		printf("Device doesn't support RAW data-path APIs.\n");
13678 		return TEST_SKIPPED;
13679 	}
13680 
13681 	/* Verify the capabilities */
13682 	struct rte_cryptodev_sym_capability_idx cap_idx;
13683 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13684 	cap_idx.algo.auth = reference->auth_algo;
13685 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13686 			&cap_idx) == NULL)
13687 		return TEST_SKIPPED;
13688 
13689 
13690 	/* Create session */
13691 	retval = create_auth_session(ut_params,
13692 			ts_params->valid_devs[0],
13693 			reference,
13694 			RTE_CRYPTO_AUTH_OP_VERIFY);
13695 
13696 	if (retval == -ENOTSUP)
13697 		return TEST_SKIPPED;
13698 	if (retval < 0)
13699 		return retval;
13700 
13701 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13702 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13703 			"Failed to allocate input buffer in mempool");
13704 
13705 	/* clear mbuf payload */
13706 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13707 			rte_pktmbuf_tailroom(ut_params->ibuf));
13708 
13709 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13710 			reference->plaintext.len);
13711 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13712 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13713 
13714 	debug_hexdump(stdout, "plaintext:", plaintext,
13715 		reference->plaintext.len);
13716 
13717 	/* Create operation */
13718 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
13719 
13720 	if (retval < 0)
13721 		return retval;
13722 
13723 	if (data_corrupted)
13724 		data_corruption(plaintext);
13725 	else
13726 		tag_corruption(plaintext, reference->plaintext.len);
13727 
13728 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13729 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13730 			ut_params->op);
13731 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13732 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13733 			"authentication not failed");
13734 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13735 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13736 				ut_params->op, 0, 1, 0, 0);
13737 	else {
13738 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13739 			ut_params->op);
13740 	}
13741 	if (ut_params->op == NULL)
13742 		return 0;
13743 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13744 		return 0;
13745 
13746 	return -1;
13747 }
13748 
13749 static int
13750 test_authentication_verify_GMAC_fail_when_corruption(
13751 		struct crypto_testsuite_params *ts_params,
13752 		struct crypto_unittest_params *ut_params,
13753 		const struct test_crypto_vector *reference,
13754 		unsigned int data_corrupted)
13755 {
13756 	int retval;
13757 	uint8_t *plaintext;
13758 	struct rte_cryptodev_info dev_info;
13759 
13760 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13761 	uint64_t feat_flags = dev_info.feature_flags;
13762 
13763 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13764 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13765 		printf("Device doesn't support RAW data-path APIs.\n");
13766 		return TEST_SKIPPED;
13767 	}
13768 
13769 	/* Verify the capabilities */
13770 	struct rte_cryptodev_sym_capability_idx cap_idx;
13771 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13772 	cap_idx.algo.auth = reference->auth_algo;
13773 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13774 			&cap_idx) == NULL)
13775 		return TEST_SKIPPED;
13776 
13777 	/* Create session */
13778 	retval = create_auth_cipher_session(ut_params,
13779 			ts_params->valid_devs[0],
13780 			reference,
13781 			RTE_CRYPTO_AUTH_OP_VERIFY,
13782 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13783 	if (retval < 0)
13784 		return retval;
13785 
13786 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13787 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13788 			"Failed to allocate input buffer in mempool");
13789 
13790 	/* clear mbuf payload */
13791 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13792 			rte_pktmbuf_tailroom(ut_params->ibuf));
13793 
13794 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13795 			reference->plaintext.len);
13796 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13797 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13798 
13799 	debug_hexdump(stdout, "plaintext:", plaintext,
13800 		reference->plaintext.len);
13801 
13802 	/* Create operation */
13803 	retval = create_auth_verify_GMAC_operation(ts_params,
13804 			ut_params,
13805 			reference);
13806 
13807 	if (retval < 0)
13808 		return retval;
13809 
13810 	if (data_corrupted)
13811 		data_corruption(plaintext);
13812 	else
13813 		tag_corruption(plaintext, reference->aad.len);
13814 
13815 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13816 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13817 			ut_params->op);
13818 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13819 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13820 			"authentication not failed");
13821 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13822 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13823 				ut_params->op, 0, 1, 0, 0);
13824 	else {
13825 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13826 			ut_params->op);
13827 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13828 	}
13829 
13830 	return 0;
13831 }
13832 
13833 static int
13834 test_authenticated_decryption_fail_when_corruption(
13835 		struct crypto_testsuite_params *ts_params,
13836 		struct crypto_unittest_params *ut_params,
13837 		const struct test_crypto_vector *reference,
13838 		unsigned int data_corrupted)
13839 {
13840 	int retval;
13841 
13842 	uint8_t *ciphertext;
13843 	struct rte_cryptodev_info dev_info;
13844 
13845 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13846 	uint64_t feat_flags = dev_info.feature_flags;
13847 
13848 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13849 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13850 		printf("Device doesn't support RAW data-path APIs.\n");
13851 		return TEST_SKIPPED;
13852 	}
13853 
13854 	/* Verify the capabilities */
13855 	struct rte_cryptodev_sym_capability_idx cap_idx;
13856 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13857 	cap_idx.algo.auth = reference->auth_algo;
13858 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13859 			&cap_idx) == NULL)
13860 		return TEST_SKIPPED;
13861 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13862 	cap_idx.algo.cipher = reference->crypto_algo;
13863 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13864 			&cap_idx) == NULL)
13865 		return TEST_SKIPPED;
13866 
13867 	/* Create session */
13868 	retval = create_auth_cipher_session(ut_params,
13869 			ts_params->valid_devs[0],
13870 			reference,
13871 			RTE_CRYPTO_AUTH_OP_VERIFY,
13872 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13873 
13874 	if (retval == -ENOTSUP)
13875 		return TEST_SKIPPED;
13876 	if (retval < 0)
13877 		return retval;
13878 
13879 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13880 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13881 			"Failed to allocate input buffer in mempool");
13882 
13883 	/* clear mbuf payload */
13884 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13885 			rte_pktmbuf_tailroom(ut_params->ibuf));
13886 
13887 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13888 			reference->ciphertext.len);
13889 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13890 	memcpy(ciphertext, reference->ciphertext.data,
13891 			reference->ciphertext.len);
13892 
13893 	/* Create operation */
13894 	retval = create_cipher_auth_verify_operation(ts_params,
13895 			ut_params,
13896 			reference);
13897 
13898 	if (retval < 0)
13899 		return retval;
13900 
13901 	if (data_corrupted)
13902 		data_corruption(ciphertext);
13903 	else
13904 		tag_corruption(ciphertext, reference->ciphertext.len);
13905 
13906 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13907 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13908 			ut_params->op);
13909 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13910 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13911 			"authentication not failed");
13912 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13913 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13914 				ut_params->op, 1, 1, 0, 0);
13915 	else {
13916 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13917 			ut_params->op);
13918 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13919 	}
13920 
13921 	return 0;
13922 }
13923 
13924 static int
13925 test_authenticated_encrypt_with_esn(
13926 		struct crypto_testsuite_params *ts_params,
13927 		struct crypto_unittest_params *ut_params,
13928 		const struct test_crypto_vector *reference)
13929 {
13930 	int retval;
13931 
13932 	uint8_t *authciphertext, *plaintext, *auth_tag;
13933 	uint16_t plaintext_pad_len;
13934 	uint8_t cipher_key[reference->cipher_key.len + 1];
13935 	uint8_t auth_key[reference->auth_key.len + 1];
13936 	struct rte_cryptodev_info dev_info;
13937 	int status;
13938 
13939 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13940 	uint64_t feat_flags = dev_info.feature_flags;
13941 
13942 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13943 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13944 		printf("Device doesn't support RAW data-path APIs.\n");
13945 		return TEST_SKIPPED;
13946 	}
13947 
13948 	/* Verify the capabilities */
13949 	struct rte_cryptodev_sym_capability_idx cap_idx;
13950 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13951 	cap_idx.algo.auth = reference->auth_algo;
13952 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13953 			&cap_idx) == NULL)
13954 		return TEST_SKIPPED;
13955 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13956 	cap_idx.algo.cipher = reference->crypto_algo;
13957 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13958 			&cap_idx) == NULL)
13959 		return TEST_SKIPPED;
13960 
13961 	/* Create session */
13962 	memcpy(cipher_key, reference->cipher_key.data,
13963 			reference->cipher_key.len);
13964 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13965 
13966 	/* Setup Cipher Parameters */
13967 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13968 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13969 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13970 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13971 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13972 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13973 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13974 
13975 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13976 
13977 	/* Setup Authentication Parameters */
13978 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13979 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13980 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13981 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13982 	ut_params->auth_xform.auth.key.data = auth_key;
13983 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13984 	ut_params->auth_xform.next = NULL;
13985 
13986 	/* Create Crypto session*/
13987 	ut_params->sess = rte_cryptodev_sym_session_create(
13988 			ts_params->session_mpool);
13989 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13990 
13991 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13992 				ut_params->sess,
13993 				&ut_params->cipher_xform,
13994 				ts_params->session_priv_mpool);
13995 
13996 	if (status == -ENOTSUP)
13997 		return TEST_SKIPPED;
13998 
13999 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
14000 
14001 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14002 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14003 			"Failed to allocate input buffer in mempool");
14004 
14005 	/* clear mbuf payload */
14006 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14007 			rte_pktmbuf_tailroom(ut_params->ibuf));
14008 
14009 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14010 			reference->plaintext.len);
14011 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
14012 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
14013 
14014 	/* Create operation */
14015 	retval = create_cipher_auth_operation(ts_params,
14016 			ut_params,
14017 			reference, 0);
14018 
14019 	if (retval < 0)
14020 		return retval;
14021 
14022 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14023 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14024 			ut_params->op);
14025 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14026 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14027 				ut_params->op, 1, 1, 0, 0);
14028 	else
14029 		ut_params->op = process_crypto_request(
14030 			ts_params->valid_devs[0], ut_params->op);
14031 
14032 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
14033 
14034 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14035 			"crypto op processing failed");
14036 
14037 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
14038 
14039 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
14040 			ut_params->op->sym->auth.data.offset);
14041 	auth_tag = authciphertext + plaintext_pad_len;
14042 	debug_hexdump(stdout, "ciphertext:", authciphertext,
14043 			reference->ciphertext.len);
14044 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
14045 
14046 	/* Validate obuf */
14047 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14048 			authciphertext,
14049 			reference->ciphertext.data,
14050 			reference->ciphertext.len,
14051 			"Ciphertext data not as expected");
14052 
14053 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14054 			auth_tag,
14055 			reference->digest.data,
14056 			reference->digest.len,
14057 			"Generated digest not as expected");
14058 
14059 	return TEST_SUCCESS;
14060 
14061 }
14062 
14063 static int
14064 test_authenticated_decrypt_with_esn(
14065 		struct crypto_testsuite_params *ts_params,
14066 		struct crypto_unittest_params *ut_params,
14067 		const struct test_crypto_vector *reference)
14068 {
14069 	int retval;
14070 
14071 	uint8_t *ciphertext;
14072 	uint8_t cipher_key[reference->cipher_key.len + 1];
14073 	uint8_t auth_key[reference->auth_key.len + 1];
14074 	struct rte_cryptodev_info dev_info;
14075 
14076 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14077 	uint64_t feat_flags = dev_info.feature_flags;
14078 
14079 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14080 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14081 		printf("Device doesn't support RAW data-path APIs.\n");
14082 		return TEST_SKIPPED;
14083 	}
14084 
14085 	/* Verify the capabilities */
14086 	struct rte_cryptodev_sym_capability_idx cap_idx;
14087 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14088 	cap_idx.algo.auth = reference->auth_algo;
14089 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14090 			&cap_idx) == NULL)
14091 		return TEST_SKIPPED;
14092 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14093 	cap_idx.algo.cipher = reference->crypto_algo;
14094 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14095 			&cap_idx) == NULL)
14096 		return TEST_SKIPPED;
14097 
14098 	/* Create session */
14099 	memcpy(cipher_key, reference->cipher_key.data,
14100 			reference->cipher_key.len);
14101 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14102 
14103 	/* Setup Authentication Parameters */
14104 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14105 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
14106 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14107 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14108 	ut_params->auth_xform.auth.key.data = auth_key;
14109 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14110 	ut_params->auth_xform.next = &ut_params->cipher_xform;
14111 
14112 	/* Setup Cipher Parameters */
14113 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14114 	ut_params->cipher_xform.next = NULL;
14115 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
14116 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
14117 	ut_params->cipher_xform.cipher.key.data = cipher_key;
14118 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
14119 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
14120 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
14121 
14122 	/* Create Crypto session*/
14123 	ut_params->sess = rte_cryptodev_sym_session_create(
14124 			ts_params->session_mpool);
14125 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14126 
14127 	retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
14128 				ut_params->sess,
14129 				&ut_params->auth_xform,
14130 				ts_params->session_priv_mpool);
14131 
14132 	if (retval == -ENOTSUP)
14133 		return TEST_SKIPPED;
14134 
14135 	TEST_ASSERT_EQUAL(retval, 0, "Session init failed");
14136 
14137 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14138 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14139 			"Failed to allocate input buffer in mempool");
14140 
14141 	/* clear mbuf payload */
14142 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14143 			rte_pktmbuf_tailroom(ut_params->ibuf));
14144 
14145 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14146 			reference->ciphertext.len);
14147 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
14148 	memcpy(ciphertext, reference->ciphertext.data,
14149 			reference->ciphertext.len);
14150 
14151 	/* Create operation */
14152 	retval = create_cipher_auth_verify_operation(ts_params,
14153 			ut_params,
14154 			reference);
14155 
14156 	if (retval < 0)
14157 		return retval;
14158 
14159 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14160 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14161 			ut_params->op);
14162 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14163 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14164 				ut_params->op, 1, 1, 0, 0);
14165 	else
14166 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14167 			ut_params->op);
14168 
14169 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
14170 	TEST_ASSERT_EQUAL(ut_params->op->status,
14171 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14172 			"crypto op processing passed");
14173 
14174 	ut_params->obuf = ut_params->op->sym->m_src;
14175 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
14176 
14177 	return 0;
14178 }
14179 
14180 static int
14181 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
14182 		const struct aead_test_data *tdata,
14183 		void *digest_mem, uint64_t digest_phys)
14184 {
14185 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14186 	struct crypto_unittest_params *ut_params = &unittest_params;
14187 
14188 	const unsigned int auth_tag_len = tdata->auth_tag.len;
14189 	const unsigned int iv_len = tdata->iv.len;
14190 	unsigned int aad_len = tdata->aad.len;
14191 	unsigned int aad_len_pad = 0;
14192 
14193 	/* Generate Crypto op data structure */
14194 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14195 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14196 	TEST_ASSERT_NOT_NULL(ut_params->op,
14197 		"Failed to allocate symmetric crypto operation struct");
14198 
14199 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14200 
14201 	sym_op->aead.digest.data = digest_mem;
14202 
14203 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
14204 			"no room to append digest");
14205 
14206 	sym_op->aead.digest.phys_addr = digest_phys;
14207 
14208 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
14209 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
14210 				auth_tag_len);
14211 		debug_hexdump(stdout, "digest:",
14212 				sym_op->aead.digest.data,
14213 				auth_tag_len);
14214 	}
14215 
14216 	/* Append aad data */
14217 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
14218 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
14219 				uint8_t *, IV_OFFSET);
14220 
14221 		/* Copy IV 1 byte after the IV pointer, according to the API */
14222 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
14223 
14224 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
14225 
14226 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
14227 				ut_params->ibuf, aad_len);
14228 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
14229 				"no room to prepend aad");
14230 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
14231 				ut_params->ibuf);
14232 
14233 		memset(sym_op->aead.aad.data, 0, aad_len);
14234 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
14235 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
14236 
14237 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
14238 		debug_hexdump(stdout, "aad:",
14239 				sym_op->aead.aad.data, aad_len);
14240 	} else {
14241 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
14242 				uint8_t *, IV_OFFSET);
14243 
14244 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
14245 
14246 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
14247 
14248 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
14249 				ut_params->ibuf, aad_len_pad);
14250 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
14251 				"no room to prepend aad");
14252 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
14253 				ut_params->ibuf);
14254 
14255 		memset(sym_op->aead.aad.data, 0, aad_len);
14256 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
14257 
14258 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
14259 		debug_hexdump(stdout, "aad:",
14260 				sym_op->aead.aad.data, aad_len);
14261 	}
14262 
14263 	sym_op->aead.data.length = tdata->plaintext.len;
14264 	sym_op->aead.data.offset = aad_len_pad;
14265 
14266 	return 0;
14267 }
14268 
14269 #define SGL_MAX_NO	16
14270 
14271 static int
14272 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
14273 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
14274 {
14275 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14276 	struct crypto_unittest_params *ut_params = &unittest_params;
14277 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
14278 	int retval;
14279 	int to_trn = 0;
14280 	int to_trn_tbl[SGL_MAX_NO];
14281 	int segs = 1;
14282 	unsigned int trn_data = 0;
14283 	uint8_t *plaintext, *ciphertext, *auth_tag;
14284 	struct rte_cryptodev_info dev_info;
14285 
14286 	/* Verify the capabilities */
14287 	struct rte_cryptodev_sym_capability_idx cap_idx;
14288 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
14289 	cap_idx.algo.aead = tdata->algo;
14290 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14291 			&cap_idx) == NULL)
14292 		return TEST_SKIPPED;
14293 
14294 	/* OOP not supported with CPU crypto */
14295 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14296 		return TEST_SKIPPED;
14297 
14298 	/* Detailed check for the particular SGL support flag */
14299 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14300 	if (!oop) {
14301 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
14302 		if (sgl_in && (!(dev_info.feature_flags &
14303 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
14304 			return TEST_SKIPPED;
14305 
14306 		uint64_t feat_flags = dev_info.feature_flags;
14307 
14308 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14309 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14310 			printf("Device doesn't support RAW data-path APIs.\n");
14311 			return TEST_SKIPPED;
14312 		}
14313 	} else {
14314 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
14315 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
14316 				tdata->plaintext.len;
14317 		/* Raw data path API does not support OOP */
14318 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14319 			return TEST_SKIPPED;
14320 		if (sgl_in && !sgl_out) {
14321 			if (!(dev_info.feature_flags &
14322 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
14323 				return TEST_SKIPPED;
14324 		} else if (!sgl_in && sgl_out) {
14325 			if (!(dev_info.feature_flags &
14326 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
14327 				return TEST_SKIPPED;
14328 		} else if (sgl_in && sgl_out) {
14329 			if (!(dev_info.feature_flags &
14330 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
14331 				return TEST_SKIPPED;
14332 		}
14333 	}
14334 
14335 	if (fragsz > tdata->plaintext.len)
14336 		fragsz = tdata->plaintext.len;
14337 
14338 	uint16_t plaintext_len = fragsz;
14339 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
14340 
14341 	if (fragsz_oop > tdata->plaintext.len)
14342 		frag_size_oop = tdata->plaintext.len;
14343 
14344 	int ecx = 0;
14345 	void *digest_mem = NULL;
14346 
14347 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
14348 
14349 	if (tdata->plaintext.len % fragsz != 0) {
14350 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
14351 			return 1;
14352 	}	else {
14353 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
14354 			return 1;
14355 	}
14356 
14357 	/*
14358 	 * For out-op-place we need to alloc another mbuf
14359 	 */
14360 	if (oop) {
14361 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14362 		rte_pktmbuf_append(ut_params->obuf,
14363 				frag_size_oop + prepend_len);
14364 		buf_oop = ut_params->obuf;
14365 	}
14366 
14367 	/* Create AEAD session */
14368 	retval = create_aead_session(ts_params->valid_devs[0],
14369 			tdata->algo,
14370 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
14371 			tdata->key.data, tdata->key.len,
14372 			tdata->aad.len, tdata->auth_tag.len,
14373 			tdata->iv.len);
14374 	if (retval < 0)
14375 		return retval;
14376 
14377 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14378 
14379 	/* clear mbuf payload */
14380 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14381 			rte_pktmbuf_tailroom(ut_params->ibuf));
14382 
14383 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14384 			plaintext_len);
14385 
14386 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
14387 
14388 	trn_data += plaintext_len;
14389 
14390 	buf = ut_params->ibuf;
14391 
14392 	/*
14393 	 * Loop until no more fragments
14394 	 */
14395 
14396 	while (trn_data < tdata->plaintext.len) {
14397 		++segs;
14398 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
14399 				(tdata->plaintext.len - trn_data) : fragsz;
14400 
14401 		to_trn_tbl[ecx++] = to_trn;
14402 
14403 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14404 		buf = buf->next;
14405 
14406 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
14407 				rte_pktmbuf_tailroom(buf));
14408 
14409 		/* OOP */
14410 		if (oop && !fragsz_oop) {
14411 			buf_last_oop = buf_oop->next =
14412 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
14413 			buf_oop = buf_oop->next;
14414 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
14415 					0, rte_pktmbuf_tailroom(buf_oop));
14416 			rte_pktmbuf_append(buf_oop, to_trn);
14417 		}
14418 
14419 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
14420 				to_trn);
14421 
14422 		memcpy(plaintext, tdata->plaintext.data + trn_data,
14423 				to_trn);
14424 		trn_data += to_trn;
14425 		if (trn_data  == tdata->plaintext.len) {
14426 			if (oop) {
14427 				if (!fragsz_oop)
14428 					digest_mem = rte_pktmbuf_append(buf_oop,
14429 						tdata->auth_tag.len);
14430 			} else
14431 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
14432 					tdata->auth_tag.len);
14433 		}
14434 	}
14435 
14436 	uint64_t digest_phys = 0;
14437 
14438 	ut_params->ibuf->nb_segs = segs;
14439 
14440 	segs = 1;
14441 	if (fragsz_oop && oop) {
14442 		to_trn = 0;
14443 		ecx = 0;
14444 
14445 		if (frag_size_oop == tdata->plaintext.len) {
14446 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
14447 				tdata->auth_tag.len);
14448 
14449 			digest_phys = rte_pktmbuf_iova_offset(
14450 					ut_params->obuf,
14451 					tdata->plaintext.len + prepend_len);
14452 		}
14453 
14454 		trn_data = frag_size_oop;
14455 		while (trn_data < tdata->plaintext.len) {
14456 			++segs;
14457 			to_trn =
14458 				(tdata->plaintext.len - trn_data <
14459 						frag_size_oop) ?
14460 				(tdata->plaintext.len - trn_data) :
14461 						frag_size_oop;
14462 
14463 			to_trn_tbl[ecx++] = to_trn;
14464 
14465 			buf_last_oop = buf_oop->next =
14466 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
14467 			buf_oop = buf_oop->next;
14468 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
14469 					0, rte_pktmbuf_tailroom(buf_oop));
14470 			rte_pktmbuf_append(buf_oop, to_trn);
14471 
14472 			trn_data += to_trn;
14473 
14474 			if (trn_data  == tdata->plaintext.len) {
14475 				digest_mem = rte_pktmbuf_append(buf_oop,
14476 					tdata->auth_tag.len);
14477 			}
14478 		}
14479 
14480 		ut_params->obuf->nb_segs = segs;
14481 	}
14482 
14483 	/*
14484 	 * Place digest at the end of the last buffer
14485 	 */
14486 	if (!digest_phys)
14487 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
14488 	if (oop && buf_last_oop)
14489 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
14490 
14491 	if (!digest_mem && !oop) {
14492 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14493 				+ tdata->auth_tag.len);
14494 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
14495 				tdata->plaintext.len);
14496 	}
14497 
14498 	/* Create AEAD operation */
14499 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
14500 			tdata, digest_mem, digest_phys);
14501 
14502 	if (retval < 0)
14503 		return retval;
14504 
14505 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14506 
14507 	ut_params->op->sym->m_src = ut_params->ibuf;
14508 	if (oop)
14509 		ut_params->op->sym->m_dst = ut_params->obuf;
14510 
14511 	/* Process crypto operation */
14512 	if (oop == IN_PLACE &&
14513 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14514 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
14515 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14516 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14517 				ut_params->op, 0, 0, 0, 0);
14518 	else
14519 		TEST_ASSERT_NOT_NULL(
14520 			process_crypto_request(ts_params->valid_devs[0],
14521 			ut_params->op), "failed to process sym crypto op");
14522 
14523 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14524 			"crypto op processing failed");
14525 
14526 
14527 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
14528 			uint8_t *, prepend_len);
14529 	if (oop) {
14530 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
14531 				uint8_t *, prepend_len);
14532 	}
14533 
14534 	if (fragsz_oop)
14535 		fragsz = fragsz_oop;
14536 
14537 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14538 			ciphertext,
14539 			tdata->ciphertext.data,
14540 			fragsz,
14541 			"Ciphertext data not as expected");
14542 
14543 	buf = ut_params->op->sym->m_src->next;
14544 	if (oop)
14545 		buf = ut_params->op->sym->m_dst->next;
14546 
14547 	unsigned int off = fragsz;
14548 
14549 	ecx = 0;
14550 	while (buf) {
14551 		ciphertext = rte_pktmbuf_mtod(buf,
14552 				uint8_t *);
14553 
14554 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
14555 				ciphertext,
14556 				tdata->ciphertext.data + off,
14557 				to_trn_tbl[ecx],
14558 				"Ciphertext data not as expected");
14559 
14560 		off += to_trn_tbl[ecx++];
14561 		buf = buf->next;
14562 	}
14563 
14564 	auth_tag = digest_mem;
14565 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14566 			auth_tag,
14567 			tdata->auth_tag.data,
14568 			tdata->auth_tag.len,
14569 			"Generated auth tag not as expected");
14570 
14571 	return 0;
14572 }
14573 
14574 static int
14575 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
14576 {
14577 	return test_authenticated_encryption_SGL(
14578 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
14579 }
14580 
14581 static int
14582 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
14583 {
14584 	return test_authenticated_encryption_SGL(
14585 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
14586 }
14587 
14588 static int
14589 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
14590 {
14591 	return test_authenticated_encryption_SGL(
14592 			&gcm_test_case_8, OUT_OF_PLACE, 400,
14593 			gcm_test_case_8.plaintext.len);
14594 }
14595 
14596 static int
14597 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
14598 {
14599 	/* This test is not for OPENSSL PMD */
14600 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14601 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
14602 		return TEST_SKIPPED;
14603 
14604 	return test_authenticated_encryption_SGL(
14605 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
14606 }
14607 
14608 static int
14609 test_authentication_verify_fail_when_data_corrupted(
14610 		struct crypto_testsuite_params *ts_params,
14611 		struct crypto_unittest_params *ut_params,
14612 		const struct test_crypto_vector *reference)
14613 {
14614 	return test_authentication_verify_fail_when_data_corruption(
14615 			ts_params, ut_params, reference, 1);
14616 }
14617 
14618 static int
14619 test_authentication_verify_fail_when_tag_corrupted(
14620 		struct crypto_testsuite_params *ts_params,
14621 		struct crypto_unittest_params *ut_params,
14622 		const struct test_crypto_vector *reference)
14623 {
14624 	return test_authentication_verify_fail_when_data_corruption(
14625 			ts_params, ut_params, reference, 0);
14626 }
14627 
14628 static int
14629 test_authentication_verify_GMAC_fail_when_data_corrupted(
14630 		struct crypto_testsuite_params *ts_params,
14631 		struct crypto_unittest_params *ut_params,
14632 		const struct test_crypto_vector *reference)
14633 {
14634 	return test_authentication_verify_GMAC_fail_when_corruption(
14635 			ts_params, ut_params, reference, 1);
14636 }
14637 
14638 static int
14639 test_authentication_verify_GMAC_fail_when_tag_corrupted(
14640 		struct crypto_testsuite_params *ts_params,
14641 		struct crypto_unittest_params *ut_params,
14642 		const struct test_crypto_vector *reference)
14643 {
14644 	return test_authentication_verify_GMAC_fail_when_corruption(
14645 			ts_params, ut_params, reference, 0);
14646 }
14647 
14648 static int
14649 test_authenticated_decryption_fail_when_data_corrupted(
14650 		struct crypto_testsuite_params *ts_params,
14651 		struct crypto_unittest_params *ut_params,
14652 		const struct test_crypto_vector *reference)
14653 {
14654 	return test_authenticated_decryption_fail_when_corruption(
14655 			ts_params, ut_params, reference, 1);
14656 }
14657 
14658 static int
14659 test_authenticated_decryption_fail_when_tag_corrupted(
14660 		struct crypto_testsuite_params *ts_params,
14661 		struct crypto_unittest_params *ut_params,
14662 		const struct test_crypto_vector *reference)
14663 {
14664 	return test_authenticated_decryption_fail_when_corruption(
14665 			ts_params, ut_params, reference, 0);
14666 }
14667 
14668 static int
14669 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
14670 {
14671 	return test_authentication_verify_fail_when_data_corrupted(
14672 			&testsuite_params, &unittest_params,
14673 			&hmac_sha1_test_crypto_vector);
14674 }
14675 
14676 static int
14677 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
14678 {
14679 	return test_authentication_verify_fail_when_tag_corrupted(
14680 			&testsuite_params, &unittest_params,
14681 			&hmac_sha1_test_crypto_vector);
14682 }
14683 
14684 static int
14685 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
14686 {
14687 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
14688 			&testsuite_params, &unittest_params,
14689 			&aes128_gmac_test_vector);
14690 }
14691 
14692 static int
14693 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
14694 {
14695 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
14696 			&testsuite_params, &unittest_params,
14697 			&aes128_gmac_test_vector);
14698 }
14699 
14700 static int
14701 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
14702 {
14703 	return test_authenticated_decryption_fail_when_data_corrupted(
14704 			&testsuite_params,
14705 			&unittest_params,
14706 			&aes128cbc_hmac_sha1_test_vector);
14707 }
14708 
14709 static int
14710 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14711 {
14712 	return test_authenticated_decryption_fail_when_tag_corrupted(
14713 			&testsuite_params,
14714 			&unittest_params,
14715 			&aes128cbc_hmac_sha1_test_vector);
14716 }
14717 
14718 static int
14719 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14720 {
14721 	return test_authenticated_encrypt_with_esn(
14722 			&testsuite_params,
14723 			&unittest_params,
14724 			&aes128cbc_hmac_sha1_aad_test_vector);
14725 }
14726 
14727 static int
14728 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14729 {
14730 	return test_authenticated_decrypt_with_esn(
14731 			&testsuite_params,
14732 			&unittest_params,
14733 			&aes128cbc_hmac_sha1_aad_test_vector);
14734 }
14735 
14736 static int
14737 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14738 {
14739 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14740 }
14741 
14742 static int
14743 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14744 {
14745 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14746 }
14747 
14748 static int
14749 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
14750 {
14751 	return test_authenticated_encryption_SGL(
14752 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
14753 		chacha20_poly1305_case_2.plaintext.len);
14754 }
14755 
14756 #ifdef RTE_CRYPTO_SCHEDULER
14757 
14758 /* global AESNI worker IDs for the scheduler test */
14759 uint8_t aesni_ids[2];
14760 
14761 static int
14762 scheduler_testsuite_setup(void)
14763 {
14764 	uint32_t i = 0;
14765 	int32_t nb_devs, ret;
14766 	char vdev_args[VDEV_ARGS_SIZE] = {""};
14767 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14768 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
14769 	uint16_t worker_core_count = 0;
14770 	uint16_t socket_id = 0;
14771 
14772 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14773 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14774 
14775 		/* Identify the Worker Cores
14776 		 * Use 2 worker cores for the device args
14777 		 */
14778 		RTE_LCORE_FOREACH_WORKER(i) {
14779 			if (worker_core_count > 1)
14780 				break;
14781 			snprintf(vdev_args, sizeof(vdev_args),
14782 					"%s%d", temp_str, i);
14783 			strcpy(temp_str, vdev_args);
14784 			strlcat(temp_str, ";", sizeof(temp_str));
14785 			worker_core_count++;
14786 			socket_id = rte_lcore_to_socket_id(i);
14787 		}
14788 		if (worker_core_count != 2) {
14789 			RTE_LOG(ERR, USER1,
14790 				"Cryptodev scheduler test require at least "
14791 				"two worker cores to run. "
14792 				"Please use the correct coremask.\n");
14793 			return TEST_FAILED;
14794 		}
14795 		strcpy(temp_str, vdev_args);
14796 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14797 				temp_str, socket_id);
14798 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14799 		nb_devs = rte_cryptodev_device_count_by_driver(
14800 				rte_cryptodev_driver_id_get(
14801 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14802 		if (nb_devs < 1) {
14803 			ret = rte_vdev_init(
14804 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14805 					vdev_args);
14806 			TEST_ASSERT(ret == 0,
14807 				"Failed to create instance %u of pmd : %s",
14808 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14809 		}
14810 	}
14811 	return testsuite_setup();
14812 }
14813 
14814 static int
14815 test_scheduler_attach_worker_op(void)
14816 {
14817 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14818 	uint8_t sched_id = ts_params->valid_devs[0];
14819 	uint32_t i, nb_devs_attached = 0;
14820 	int ret;
14821 	char vdev_name[32];
14822 	unsigned int count = rte_cryptodev_count();
14823 
14824 	/* create 2 AESNI_MB vdevs on top of existing devices */
14825 	for (i = count; i < count + 2; i++) {
14826 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14827 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14828 				i);
14829 		ret = rte_vdev_init(vdev_name, NULL);
14830 
14831 		TEST_ASSERT(ret == 0,
14832 			"Failed to create instance %u of"
14833 			" pmd : %s",
14834 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14835 
14836 		if (ret < 0) {
14837 			RTE_LOG(ERR, USER1,
14838 				"Failed to create 2 AESNI MB PMDs.\n");
14839 			return TEST_SKIPPED;
14840 		}
14841 	}
14842 
14843 	/* attach 2 AESNI_MB cdevs */
14844 	for (i = count; i < count + 2; i++) {
14845 		struct rte_cryptodev_info info;
14846 		unsigned int session_size;
14847 
14848 		rte_cryptodev_info_get(i, &info);
14849 		if (info.driver_id != rte_cryptodev_driver_id_get(
14850 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14851 			continue;
14852 
14853 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14854 		/*
14855 		 * Create the session mempool again, since now there are new devices
14856 		 * to use the mempool.
14857 		 */
14858 		if (ts_params->session_mpool) {
14859 			rte_mempool_free(ts_params->session_mpool);
14860 			ts_params->session_mpool = NULL;
14861 		}
14862 		if (ts_params->session_priv_mpool) {
14863 			rte_mempool_free(ts_params->session_priv_mpool);
14864 			ts_params->session_priv_mpool = NULL;
14865 		}
14866 
14867 		if (info.sym.max_nb_sessions != 0 &&
14868 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14869 			RTE_LOG(ERR, USER1,
14870 					"Device does not support "
14871 					"at least %u sessions\n",
14872 					MAX_NB_SESSIONS);
14873 			return TEST_FAILED;
14874 		}
14875 		/*
14876 		 * Create mempool with maximum number of sessions,
14877 		 * to include the session headers
14878 		 */
14879 		if (ts_params->session_mpool == NULL) {
14880 			ts_params->session_mpool =
14881 				rte_cryptodev_sym_session_pool_create(
14882 						"test_sess_mp",
14883 						MAX_NB_SESSIONS, 0, 0, 0,
14884 						SOCKET_ID_ANY);
14885 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14886 					"session mempool allocation failed");
14887 		}
14888 
14889 		/*
14890 		 * Create mempool with maximum number of sessions,
14891 		 * to include device specific session private data
14892 		 */
14893 		if (ts_params->session_priv_mpool == NULL) {
14894 			ts_params->session_priv_mpool = rte_mempool_create(
14895 					"test_sess_mp_priv",
14896 					MAX_NB_SESSIONS,
14897 					session_size,
14898 					0, 0, NULL, NULL, NULL,
14899 					NULL, SOCKET_ID_ANY,
14900 					0);
14901 
14902 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14903 					"session mempool allocation failed");
14904 		}
14905 
14906 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
14907 		ts_params->qp_conf.mp_session_private =
14908 				ts_params->session_priv_mpool;
14909 
14910 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14911 				(uint8_t)i);
14912 
14913 		TEST_ASSERT(ret == 0,
14914 			"Failed to attach device %u of pmd : %s", i,
14915 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14916 
14917 		aesni_ids[nb_devs_attached] = (uint8_t)i;
14918 
14919 		nb_devs_attached++;
14920 	}
14921 
14922 	return 0;
14923 }
14924 
14925 static int
14926 test_scheduler_detach_worker_op(void)
14927 {
14928 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14929 	uint8_t sched_id = ts_params->valid_devs[0];
14930 	uint32_t i;
14931 	int ret;
14932 
14933 	for (i = 0; i < 2; i++) {
14934 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14935 				aesni_ids[i]);
14936 		TEST_ASSERT(ret == 0,
14937 			"Failed to detach device %u", aesni_ids[i]);
14938 	}
14939 
14940 	return 0;
14941 }
14942 
14943 static int
14944 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14945 {
14946 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14947 	uint8_t sched_id = ts_params->valid_devs[0];
14948 	/* set mode */
14949 	return rte_cryptodev_scheduler_mode_set(sched_id,
14950 		scheduler_mode);
14951 }
14952 
14953 static int
14954 test_scheduler_mode_roundrobin_op(void)
14955 {
14956 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14957 			0, "Failed to set roundrobin mode");
14958 	return 0;
14959 
14960 }
14961 
14962 static int
14963 test_scheduler_mode_multicore_op(void)
14964 {
14965 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14966 			0, "Failed to set multicore mode");
14967 
14968 	return 0;
14969 }
14970 
14971 static int
14972 test_scheduler_mode_failover_op(void)
14973 {
14974 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14975 			0, "Failed to set failover mode");
14976 
14977 	return 0;
14978 }
14979 
14980 static int
14981 test_scheduler_mode_pkt_size_distr_op(void)
14982 {
14983 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14984 			0, "Failed to set pktsize mode");
14985 
14986 	return 0;
14987 }
14988 
14989 static int
14990 scheduler_multicore_testsuite_setup(void)
14991 {
14992 	if (test_scheduler_attach_worker_op() < 0)
14993 		return TEST_SKIPPED;
14994 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14995 		return TEST_SKIPPED;
14996 	return 0;
14997 }
14998 
14999 static int
15000 scheduler_roundrobin_testsuite_setup(void)
15001 {
15002 	if (test_scheduler_attach_worker_op() < 0)
15003 		return TEST_SKIPPED;
15004 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
15005 		return TEST_SKIPPED;
15006 	return 0;
15007 }
15008 
15009 static int
15010 scheduler_failover_testsuite_setup(void)
15011 {
15012 	if (test_scheduler_attach_worker_op() < 0)
15013 		return TEST_SKIPPED;
15014 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
15015 		return TEST_SKIPPED;
15016 	return 0;
15017 }
15018 
15019 static int
15020 scheduler_pkt_size_distr_testsuite_setup(void)
15021 {
15022 	if (test_scheduler_attach_worker_op() < 0)
15023 		return TEST_SKIPPED;
15024 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
15025 		return TEST_SKIPPED;
15026 	return 0;
15027 }
15028 
15029 static void
15030 scheduler_mode_testsuite_teardown(void)
15031 {
15032 	test_scheduler_detach_worker_op();
15033 }
15034 
15035 #endif /* RTE_CRYPTO_SCHEDULER */
15036 
15037 static struct unit_test_suite end_testsuite = {
15038 	.suite_name = NULL,
15039 	.setup = NULL,
15040 	.teardown = NULL,
15041 	.unit_test_suites = NULL
15042 };
15043 
15044 #ifdef RTE_LIB_SECURITY
15045 static struct unit_test_suite ipsec_proto_testsuite  = {
15046 	.suite_name = "IPsec Proto Unit Test Suite",
15047 	.setup = ipsec_proto_testsuite_setup,
15048 	.unit_test_cases = {
15049 		TEST_CASE_NAMED_WITH_DATA(
15050 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
15051 			ut_setup_security, ut_teardown,
15052 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
15053 		TEST_CASE_NAMED_WITH_DATA(
15054 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
15055 			ut_setup_security, ut_teardown,
15056 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
15057 		TEST_CASE_NAMED_WITH_DATA(
15058 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
15059 			ut_setup_security, ut_teardown,
15060 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
15061 		TEST_CASE_NAMED_WITH_DATA(
15062 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15063 			ut_setup_security, ut_teardown,
15064 			test_ipsec_proto_known_vec,
15065 			&pkt_aes_128_cbc_hmac_sha256),
15066 		TEST_CASE_NAMED_WITH_DATA(
15067 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
15068 			ut_setup_security, ut_teardown,
15069 			test_ipsec_proto_known_vec,
15070 			&pkt_aes_128_cbc_hmac_sha384),
15071 		TEST_CASE_NAMED_WITH_DATA(
15072 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
15073 			ut_setup_security, ut_teardown,
15074 			test_ipsec_proto_known_vec,
15075 			&pkt_aes_128_cbc_hmac_sha512),
15076 		TEST_CASE_NAMED_WITH_DATA(
15077 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
15078 			ut_setup_security, ut_teardown,
15079 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6),
15080 		TEST_CASE_NAMED_WITH_DATA(
15081 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15082 			ut_setup_security, ut_teardown,
15083 			test_ipsec_proto_known_vec,
15084 			&pkt_aes_128_cbc_hmac_sha256_v6),
15085 		TEST_CASE_NAMED_WITH_DATA(
15086 			"Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
15087 			ut_setup_security, ut_teardown,
15088 			test_ipsec_proto_known_vec,
15089 			&pkt_null_aes_xcbc),
15090 		TEST_CASE_NAMED_WITH_DATA(
15091 			"Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
15092 			ut_setup_security, ut_teardown,
15093 			test_ipsec_proto_known_vec,
15094 			&pkt_ah_tunnel_sha256),
15095 		TEST_CASE_NAMED_WITH_DATA(
15096 			"Outbound known vector (AH transport mode IPv4 HMAC-SHA256)",
15097 			ut_setup_security, ut_teardown,
15098 			test_ipsec_proto_known_vec,
15099 			&pkt_ah_transport_sha256),
15100 		TEST_CASE_NAMED_WITH_DATA(
15101 			"Outbound fragmented packet",
15102 			ut_setup_security, ut_teardown,
15103 			test_ipsec_proto_known_vec_fragmented,
15104 			&pkt_aes_128_gcm_frag),
15105 		TEST_CASE_NAMED_WITH_DATA(
15106 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
15107 			ut_setup_security, ut_teardown,
15108 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
15109 		TEST_CASE_NAMED_WITH_DATA(
15110 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
15111 			ut_setup_security, ut_teardown,
15112 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
15113 		TEST_CASE_NAMED_WITH_DATA(
15114 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
15115 			ut_setup_security, ut_teardown,
15116 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
15117 		TEST_CASE_NAMED_WITH_DATA(
15118 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
15119 			ut_setup_security, ut_teardown,
15120 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null),
15121 		TEST_CASE_NAMED_WITH_DATA(
15122 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15123 			ut_setup_security, ut_teardown,
15124 			test_ipsec_proto_known_vec_inb,
15125 			&pkt_aes_128_cbc_hmac_sha256),
15126 		TEST_CASE_NAMED_WITH_DATA(
15127 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
15128 			ut_setup_security, ut_teardown,
15129 			test_ipsec_proto_known_vec_inb,
15130 			&pkt_aes_128_cbc_hmac_sha384),
15131 		TEST_CASE_NAMED_WITH_DATA(
15132 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
15133 			ut_setup_security, ut_teardown,
15134 			test_ipsec_proto_known_vec_inb,
15135 			&pkt_aes_128_cbc_hmac_sha512),
15136 		TEST_CASE_NAMED_WITH_DATA(
15137 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
15138 			ut_setup_security, ut_teardown,
15139 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
15140 		TEST_CASE_NAMED_WITH_DATA(
15141 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15142 			ut_setup_security, ut_teardown,
15143 			test_ipsec_proto_known_vec_inb,
15144 			&pkt_aes_128_cbc_hmac_sha256_v6),
15145 		TEST_CASE_NAMED_WITH_DATA(
15146 			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
15147 			ut_setup_security, ut_teardown,
15148 			test_ipsec_proto_known_vec_inb,
15149 			&pkt_null_aes_xcbc),
15150 		TEST_CASE_NAMED_WITH_DATA(
15151 			"Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
15152 			ut_setup_security, ut_teardown,
15153 			test_ipsec_proto_known_vec_inb,
15154 			&pkt_ah_tunnel_sha256),
15155 		TEST_CASE_NAMED_WITH_DATA(
15156 			"Inbound known vector (AH transport mode IPv4 HMAC-SHA256)",
15157 			ut_setup_security, ut_teardown,
15158 			test_ipsec_proto_known_vec_inb,
15159 			&pkt_ah_transport_sha256),
15160 		TEST_CASE_NAMED_ST(
15161 			"Combined test alg list",
15162 			ut_setup_security, ut_teardown,
15163 			test_ipsec_proto_display_list),
15164 		TEST_CASE_NAMED_ST(
15165 			"Combined test alg list (AH)",
15166 			ut_setup_security, ut_teardown,
15167 			test_ipsec_proto_ah_tunnel_ipv4),
15168 		TEST_CASE_NAMED_ST(
15169 			"IV generation",
15170 			ut_setup_security, ut_teardown,
15171 			test_ipsec_proto_iv_gen),
15172 		TEST_CASE_NAMED_ST(
15173 			"UDP encapsulation",
15174 			ut_setup_security, ut_teardown,
15175 			test_ipsec_proto_udp_encap),
15176 		TEST_CASE_NAMED_ST(
15177 			"UDP encapsulation ports verification test",
15178 			ut_setup_security, ut_teardown,
15179 			test_ipsec_proto_udp_ports_verify),
15180 		TEST_CASE_NAMED_ST(
15181 			"SA expiry packets soft",
15182 			ut_setup_security, ut_teardown,
15183 			test_ipsec_proto_sa_exp_pkts_soft),
15184 		TEST_CASE_NAMED_ST(
15185 			"SA expiry packets hard",
15186 			ut_setup_security, ut_teardown,
15187 			test_ipsec_proto_sa_exp_pkts_hard),
15188 		TEST_CASE_NAMED_ST(
15189 			"Negative test: ICV corruption",
15190 			ut_setup_security, ut_teardown,
15191 			test_ipsec_proto_err_icv_corrupt),
15192 		TEST_CASE_NAMED_ST(
15193 			"Tunnel dst addr verification",
15194 			ut_setup_security, ut_teardown,
15195 			test_ipsec_proto_tunnel_dst_addr_verify),
15196 		TEST_CASE_NAMED_ST(
15197 			"Tunnel src and dst addr verification",
15198 			ut_setup_security, ut_teardown,
15199 			test_ipsec_proto_tunnel_src_dst_addr_verify),
15200 		TEST_CASE_NAMED_ST(
15201 			"Inner IP checksum",
15202 			ut_setup_security, ut_teardown,
15203 			test_ipsec_proto_inner_ip_csum),
15204 		TEST_CASE_NAMED_ST(
15205 			"Inner L4 checksum",
15206 			ut_setup_security, ut_teardown,
15207 			test_ipsec_proto_inner_l4_csum),
15208 		TEST_CASE_NAMED_ST(
15209 			"Tunnel IPv4 in IPv4",
15210 			ut_setup_security, ut_teardown,
15211 			test_ipsec_proto_tunnel_v4_in_v4),
15212 		TEST_CASE_NAMED_ST(
15213 			"Tunnel IPv6 in IPv6",
15214 			ut_setup_security, ut_teardown,
15215 			test_ipsec_proto_tunnel_v6_in_v6),
15216 		TEST_CASE_NAMED_ST(
15217 			"Tunnel IPv4 in IPv6",
15218 			ut_setup_security, ut_teardown,
15219 			test_ipsec_proto_tunnel_v4_in_v6),
15220 		TEST_CASE_NAMED_ST(
15221 			"Tunnel IPv6 in IPv4",
15222 			ut_setup_security, ut_teardown,
15223 			test_ipsec_proto_tunnel_v6_in_v4),
15224 		TEST_CASE_NAMED_ST(
15225 			"Transport IPv4",
15226 			ut_setup_security, ut_teardown,
15227 			test_ipsec_proto_transport_v4),
15228 		TEST_CASE_NAMED_ST(
15229 			"AH transport IPv4",
15230 			ut_setup_security, ut_teardown,
15231 			test_ipsec_proto_ah_transport_ipv4),
15232 		TEST_CASE_NAMED_ST(
15233 			"Transport l4 checksum",
15234 			ut_setup_security, ut_teardown,
15235 			test_ipsec_proto_transport_l4_csum),
15236 		TEST_CASE_NAMED_ST(
15237 			"Statistics: success",
15238 			ut_setup_security, ut_teardown,
15239 			test_ipsec_proto_stats),
15240 		TEST_CASE_NAMED_ST(
15241 			"Fragmented packet",
15242 			ut_setup_security, ut_teardown,
15243 			test_ipsec_proto_pkt_fragment),
15244 		TEST_CASE_NAMED_ST(
15245 			"Tunnel header copy DF (inner 0)",
15246 			ut_setup_security, ut_teardown,
15247 			test_ipsec_proto_copy_df_inner_0),
15248 		TEST_CASE_NAMED_ST(
15249 			"Tunnel header copy DF (inner 1)",
15250 			ut_setup_security, ut_teardown,
15251 			test_ipsec_proto_copy_df_inner_1),
15252 		TEST_CASE_NAMED_ST(
15253 			"Tunnel header set DF 0 (inner 1)",
15254 			ut_setup_security, ut_teardown,
15255 			test_ipsec_proto_set_df_0_inner_1),
15256 		TEST_CASE_NAMED_ST(
15257 			"Tunnel header set DF 1 (inner 0)",
15258 			ut_setup_security, ut_teardown,
15259 			test_ipsec_proto_set_df_1_inner_0),
15260 		TEST_CASE_NAMED_ST(
15261 			"Tunnel header IPv4 copy DSCP (inner 0)",
15262 			ut_setup_security, ut_teardown,
15263 			test_ipsec_proto_ipv4_copy_dscp_inner_0),
15264 		TEST_CASE_NAMED_ST(
15265 			"Tunnel header IPv4 copy DSCP (inner 1)",
15266 			ut_setup_security, ut_teardown,
15267 			test_ipsec_proto_ipv4_copy_dscp_inner_1),
15268 		TEST_CASE_NAMED_ST(
15269 			"Tunnel header IPv4 set DSCP 0 (inner 1)",
15270 			ut_setup_security, ut_teardown,
15271 			test_ipsec_proto_ipv4_set_dscp_0_inner_1),
15272 		TEST_CASE_NAMED_ST(
15273 			"Tunnel header IPv4 set DSCP 1 (inner 0)",
15274 			ut_setup_security, ut_teardown,
15275 			test_ipsec_proto_ipv4_set_dscp_1_inner_0),
15276 		TEST_CASE_NAMED_ST(
15277 			"Tunnel header IPv6 copy DSCP (inner 0)",
15278 			ut_setup_security, ut_teardown,
15279 			test_ipsec_proto_ipv6_copy_dscp_inner_0),
15280 		TEST_CASE_NAMED_ST(
15281 			"Tunnel header IPv6 copy DSCP (inner 1)",
15282 			ut_setup_security, ut_teardown,
15283 			test_ipsec_proto_ipv6_copy_dscp_inner_1),
15284 		TEST_CASE_NAMED_ST(
15285 			"Tunnel header IPv6 set DSCP 0 (inner 1)",
15286 			ut_setup_security, ut_teardown,
15287 			test_ipsec_proto_ipv6_set_dscp_0_inner_1),
15288 		TEST_CASE_NAMED_ST(
15289 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
15290 			ut_setup_security, ut_teardown,
15291 			test_ipsec_proto_ipv6_set_dscp_1_inner_0),
15292 		TEST_CASE_NAMED_WITH_DATA(
15293 			"Antireplay with window size 1024",
15294 			ut_setup_security, ut_teardown,
15295 			test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm),
15296 		TEST_CASE_NAMED_WITH_DATA(
15297 			"Antireplay with window size 2048",
15298 			ut_setup_security, ut_teardown,
15299 			test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm),
15300 		TEST_CASE_NAMED_WITH_DATA(
15301 			"Antireplay with window size 4096",
15302 			ut_setup_security, ut_teardown,
15303 			test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm),
15304 		TEST_CASE_NAMED_WITH_DATA(
15305 			"ESN and Antireplay with window size 1024",
15306 			ut_setup_security, ut_teardown,
15307 			test_ipsec_proto_pkt_esn_antireplay1024,
15308 			&pkt_aes_128_gcm),
15309 		TEST_CASE_NAMED_WITH_DATA(
15310 			"ESN and Antireplay with window size 2048",
15311 			ut_setup_security, ut_teardown,
15312 			test_ipsec_proto_pkt_esn_antireplay2048,
15313 			&pkt_aes_128_gcm),
15314 		TEST_CASE_NAMED_WITH_DATA(
15315 			"ESN and Antireplay with window size 4096",
15316 			ut_setup_security, ut_teardown,
15317 			test_ipsec_proto_pkt_esn_antireplay4096,
15318 			&pkt_aes_128_gcm),
15319 		TEST_CASE_NAMED_ST(
15320 			"Tunnel header IPv4 decrement inner TTL",
15321 			ut_setup_security, ut_teardown,
15322 			test_ipsec_proto_ipv4_ttl_decrement),
15323 		TEST_CASE_NAMED_ST(
15324 			"Tunnel header IPv6 decrement inner hop limit",
15325 			ut_setup_security, ut_teardown,
15326 			test_ipsec_proto_ipv6_hop_limit_decrement),
15327 		TEST_CASES_END() /**< NULL terminate unit test array */
15328 	}
15329 };
15330 
15331 static struct unit_test_suite pdcp_proto_testsuite  = {
15332 	.suite_name = "PDCP Proto Unit Test Suite",
15333 	.setup = pdcp_proto_testsuite_setup,
15334 	.unit_test_cases = {
15335 		TEST_CASE_ST(ut_setup_security, ut_teardown,
15336 			test_PDCP_PROTO_all),
15337 		TEST_CASES_END() /**< NULL terminate unit test array */
15338 	}
15339 };
15340 
15341 #define ADD_UPLINK_TESTCASE(data)						\
15342 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security,	\
15343 	ut_teardown, test_docsis_proto_uplink, (const void *) &data),		\
15344 
15345 #define ADD_DOWNLINK_TESTCASE(data)						\
15346 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security,	\
15347 	ut_teardown, test_docsis_proto_downlink, (const void *) &data),		\
15348 
15349 static struct unit_test_suite docsis_proto_testsuite  = {
15350 	.suite_name = "DOCSIS Proto Unit Test Suite",
15351 	.setup = docsis_proto_testsuite_setup,
15352 	.unit_test_cases = {
15353 		/* Uplink */
15354 		ADD_UPLINK_TESTCASE(docsis_test_case_1)
15355 		ADD_UPLINK_TESTCASE(docsis_test_case_2)
15356 		ADD_UPLINK_TESTCASE(docsis_test_case_3)
15357 		ADD_UPLINK_TESTCASE(docsis_test_case_4)
15358 		ADD_UPLINK_TESTCASE(docsis_test_case_5)
15359 		ADD_UPLINK_TESTCASE(docsis_test_case_6)
15360 		ADD_UPLINK_TESTCASE(docsis_test_case_7)
15361 		ADD_UPLINK_TESTCASE(docsis_test_case_8)
15362 		ADD_UPLINK_TESTCASE(docsis_test_case_9)
15363 		ADD_UPLINK_TESTCASE(docsis_test_case_10)
15364 		ADD_UPLINK_TESTCASE(docsis_test_case_11)
15365 		ADD_UPLINK_TESTCASE(docsis_test_case_12)
15366 		ADD_UPLINK_TESTCASE(docsis_test_case_13)
15367 		ADD_UPLINK_TESTCASE(docsis_test_case_14)
15368 		ADD_UPLINK_TESTCASE(docsis_test_case_15)
15369 		ADD_UPLINK_TESTCASE(docsis_test_case_16)
15370 		ADD_UPLINK_TESTCASE(docsis_test_case_17)
15371 		ADD_UPLINK_TESTCASE(docsis_test_case_18)
15372 		ADD_UPLINK_TESTCASE(docsis_test_case_19)
15373 		ADD_UPLINK_TESTCASE(docsis_test_case_20)
15374 		ADD_UPLINK_TESTCASE(docsis_test_case_21)
15375 		ADD_UPLINK_TESTCASE(docsis_test_case_22)
15376 		ADD_UPLINK_TESTCASE(docsis_test_case_23)
15377 		ADD_UPLINK_TESTCASE(docsis_test_case_24)
15378 		ADD_UPLINK_TESTCASE(docsis_test_case_25)
15379 		ADD_UPLINK_TESTCASE(docsis_test_case_26)
15380 		/* Downlink */
15381 		ADD_DOWNLINK_TESTCASE(docsis_test_case_1)
15382 		ADD_DOWNLINK_TESTCASE(docsis_test_case_2)
15383 		ADD_DOWNLINK_TESTCASE(docsis_test_case_3)
15384 		ADD_DOWNLINK_TESTCASE(docsis_test_case_4)
15385 		ADD_DOWNLINK_TESTCASE(docsis_test_case_5)
15386 		ADD_DOWNLINK_TESTCASE(docsis_test_case_6)
15387 		ADD_DOWNLINK_TESTCASE(docsis_test_case_7)
15388 		ADD_DOWNLINK_TESTCASE(docsis_test_case_8)
15389 		ADD_DOWNLINK_TESTCASE(docsis_test_case_9)
15390 		ADD_DOWNLINK_TESTCASE(docsis_test_case_10)
15391 		ADD_DOWNLINK_TESTCASE(docsis_test_case_11)
15392 		ADD_DOWNLINK_TESTCASE(docsis_test_case_12)
15393 		ADD_DOWNLINK_TESTCASE(docsis_test_case_13)
15394 		ADD_DOWNLINK_TESTCASE(docsis_test_case_14)
15395 		ADD_DOWNLINK_TESTCASE(docsis_test_case_15)
15396 		ADD_DOWNLINK_TESTCASE(docsis_test_case_16)
15397 		ADD_DOWNLINK_TESTCASE(docsis_test_case_17)
15398 		ADD_DOWNLINK_TESTCASE(docsis_test_case_18)
15399 		ADD_DOWNLINK_TESTCASE(docsis_test_case_19)
15400 		ADD_DOWNLINK_TESTCASE(docsis_test_case_20)
15401 		ADD_DOWNLINK_TESTCASE(docsis_test_case_21)
15402 		ADD_DOWNLINK_TESTCASE(docsis_test_case_22)
15403 		ADD_DOWNLINK_TESTCASE(docsis_test_case_23)
15404 		ADD_DOWNLINK_TESTCASE(docsis_test_case_24)
15405 		ADD_DOWNLINK_TESTCASE(docsis_test_case_25)
15406 		ADD_DOWNLINK_TESTCASE(docsis_test_case_26)
15407 		TEST_CASES_END() /**< NULL terminate unit test array */
15408 	}
15409 };
15410 #endif
15411 
15412 static struct unit_test_suite cryptodev_gen_testsuite  = {
15413 	.suite_name = "Crypto General Unit Test Suite",
15414 	.setup = crypto_gen_testsuite_setup,
15415 	.unit_test_cases = {
15416 		TEST_CASE_ST(ut_setup, ut_teardown,
15417 				test_device_configure_invalid_dev_id),
15418 		TEST_CASE_ST(ut_setup, ut_teardown,
15419 				test_queue_pair_descriptor_setup),
15420 		TEST_CASE_ST(ut_setup, ut_teardown,
15421 				test_device_configure_invalid_queue_pair_ids),
15422 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
15423 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
15424 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
15425 		TEST_CASES_END() /**< NULL terminate unit test array */
15426 	}
15427 };
15428 
15429 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
15430 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
15431 	.setup = negative_hmac_sha1_testsuite_setup,
15432 	.unit_test_cases = {
15433 		/** Negative tests */
15434 		TEST_CASE_ST(ut_setup, ut_teardown,
15435 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
15436 		TEST_CASE_ST(ut_setup, ut_teardown,
15437 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
15438 		TEST_CASE_ST(ut_setup, ut_teardown,
15439 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
15440 		TEST_CASE_ST(ut_setup, ut_teardown,
15441 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
15442 
15443 		TEST_CASES_END() /**< NULL terminate unit test array */
15444 	}
15445 };
15446 
15447 static struct unit_test_suite cryptodev_multi_session_testsuite = {
15448 	.suite_name = "Multi Session Unit Test Suite",
15449 	.setup = multi_session_testsuite_setup,
15450 	.unit_test_cases = {
15451 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
15452 		TEST_CASE_ST(ut_setup, ut_teardown,
15453 				test_multi_session_random_usage),
15454 
15455 		TEST_CASES_END() /**< NULL terminate unit test array */
15456 	}
15457 };
15458 
15459 static struct unit_test_suite cryptodev_null_testsuite  = {
15460 	.suite_name = "NULL Test Suite",
15461 	.setup = null_testsuite_setup,
15462 	.unit_test_cases = {
15463 		TEST_CASE_ST(ut_setup, ut_teardown,
15464 			test_null_invalid_operation),
15465 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
15466 		TEST_CASES_END()
15467 	}
15468 };
15469 
15470 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
15471 	.suite_name = "AES CCM Authenticated Test Suite",
15472 	.setup = aes_ccm_auth_testsuite_setup,
15473 	.unit_test_cases = {
15474 		/** AES CCM Authenticated Encryption 128 bits key*/
15475 		TEST_CASE_ST(ut_setup, ut_teardown,
15476 			test_AES_CCM_authenticated_encryption_test_case_128_1),
15477 		TEST_CASE_ST(ut_setup, ut_teardown,
15478 			test_AES_CCM_authenticated_encryption_test_case_128_2),
15479 		TEST_CASE_ST(ut_setup, ut_teardown,
15480 			test_AES_CCM_authenticated_encryption_test_case_128_3),
15481 
15482 		/** AES CCM Authenticated Decryption 128 bits key*/
15483 		TEST_CASE_ST(ut_setup, ut_teardown,
15484 			test_AES_CCM_authenticated_decryption_test_case_128_1),
15485 		TEST_CASE_ST(ut_setup, ut_teardown,
15486 			test_AES_CCM_authenticated_decryption_test_case_128_2),
15487 		TEST_CASE_ST(ut_setup, ut_teardown,
15488 			test_AES_CCM_authenticated_decryption_test_case_128_3),
15489 
15490 		/** AES CCM Authenticated Encryption 192 bits key */
15491 		TEST_CASE_ST(ut_setup, ut_teardown,
15492 			test_AES_CCM_authenticated_encryption_test_case_192_1),
15493 		TEST_CASE_ST(ut_setup, ut_teardown,
15494 			test_AES_CCM_authenticated_encryption_test_case_192_2),
15495 		TEST_CASE_ST(ut_setup, ut_teardown,
15496 			test_AES_CCM_authenticated_encryption_test_case_192_3),
15497 
15498 		/** AES CCM Authenticated Decryption 192 bits key*/
15499 		TEST_CASE_ST(ut_setup, ut_teardown,
15500 			test_AES_CCM_authenticated_decryption_test_case_192_1),
15501 		TEST_CASE_ST(ut_setup, ut_teardown,
15502 			test_AES_CCM_authenticated_decryption_test_case_192_2),
15503 		TEST_CASE_ST(ut_setup, ut_teardown,
15504 			test_AES_CCM_authenticated_decryption_test_case_192_3),
15505 
15506 		/** AES CCM Authenticated Encryption 256 bits key */
15507 		TEST_CASE_ST(ut_setup, ut_teardown,
15508 			test_AES_CCM_authenticated_encryption_test_case_256_1),
15509 		TEST_CASE_ST(ut_setup, ut_teardown,
15510 			test_AES_CCM_authenticated_encryption_test_case_256_2),
15511 		TEST_CASE_ST(ut_setup, ut_teardown,
15512 			test_AES_CCM_authenticated_encryption_test_case_256_3),
15513 
15514 		/** AES CCM Authenticated Decryption 256 bits key*/
15515 		TEST_CASE_ST(ut_setup, ut_teardown,
15516 			test_AES_CCM_authenticated_decryption_test_case_256_1),
15517 		TEST_CASE_ST(ut_setup, ut_teardown,
15518 			test_AES_CCM_authenticated_decryption_test_case_256_2),
15519 		TEST_CASE_ST(ut_setup, ut_teardown,
15520 			test_AES_CCM_authenticated_decryption_test_case_256_3),
15521 		TEST_CASES_END()
15522 	}
15523 };
15524 
15525 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
15526 	.suite_name = "AES GCM Authenticated Test Suite",
15527 	.setup = aes_gcm_auth_testsuite_setup,
15528 	.unit_test_cases = {
15529 		/** AES GCM Authenticated Encryption */
15530 		TEST_CASE_ST(ut_setup, ut_teardown,
15531 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
15532 		TEST_CASE_ST(ut_setup, ut_teardown,
15533 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
15534 		TEST_CASE_ST(ut_setup, ut_teardown,
15535 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
15536 		TEST_CASE_ST(ut_setup, ut_teardown,
15537 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
15538 		TEST_CASE_ST(ut_setup, ut_teardown,
15539 			test_AES_GCM_authenticated_encryption_test_case_1),
15540 		TEST_CASE_ST(ut_setup, ut_teardown,
15541 			test_AES_GCM_authenticated_encryption_test_case_2),
15542 		TEST_CASE_ST(ut_setup, ut_teardown,
15543 			test_AES_GCM_authenticated_encryption_test_case_3),
15544 		TEST_CASE_ST(ut_setup, ut_teardown,
15545 			test_AES_GCM_authenticated_encryption_test_case_4),
15546 		TEST_CASE_ST(ut_setup, ut_teardown,
15547 			test_AES_GCM_authenticated_encryption_test_case_5),
15548 		TEST_CASE_ST(ut_setup, ut_teardown,
15549 			test_AES_GCM_authenticated_encryption_test_case_6),
15550 		TEST_CASE_ST(ut_setup, ut_teardown,
15551 			test_AES_GCM_authenticated_encryption_test_case_7),
15552 		TEST_CASE_ST(ut_setup, ut_teardown,
15553 			test_AES_GCM_authenticated_encryption_test_case_8),
15554 		TEST_CASE_ST(ut_setup, ut_teardown,
15555 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
15556 
15557 		/** AES GCM Authenticated Decryption */
15558 		TEST_CASE_ST(ut_setup, ut_teardown,
15559 			test_AES_GCM_authenticated_decryption_test_case_1),
15560 		TEST_CASE_ST(ut_setup, ut_teardown,
15561 			test_AES_GCM_authenticated_decryption_test_case_2),
15562 		TEST_CASE_ST(ut_setup, ut_teardown,
15563 			test_AES_GCM_authenticated_decryption_test_case_3),
15564 		TEST_CASE_ST(ut_setup, ut_teardown,
15565 			test_AES_GCM_authenticated_decryption_test_case_4),
15566 		TEST_CASE_ST(ut_setup, ut_teardown,
15567 			test_AES_GCM_authenticated_decryption_test_case_5),
15568 		TEST_CASE_ST(ut_setup, ut_teardown,
15569 			test_AES_GCM_authenticated_decryption_test_case_6),
15570 		TEST_CASE_ST(ut_setup, ut_teardown,
15571 			test_AES_GCM_authenticated_decryption_test_case_7),
15572 		TEST_CASE_ST(ut_setup, ut_teardown,
15573 			test_AES_GCM_authenticated_decryption_test_case_8),
15574 		TEST_CASE_ST(ut_setup, ut_teardown,
15575 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
15576 
15577 		/** AES GCM Authenticated Encryption 192 bits key */
15578 		TEST_CASE_ST(ut_setup, ut_teardown,
15579 			test_AES_GCM_auth_encryption_test_case_192_1),
15580 		TEST_CASE_ST(ut_setup, ut_teardown,
15581 			test_AES_GCM_auth_encryption_test_case_192_2),
15582 		TEST_CASE_ST(ut_setup, ut_teardown,
15583 			test_AES_GCM_auth_encryption_test_case_192_3),
15584 		TEST_CASE_ST(ut_setup, ut_teardown,
15585 			test_AES_GCM_auth_encryption_test_case_192_4),
15586 		TEST_CASE_ST(ut_setup, ut_teardown,
15587 			test_AES_GCM_auth_encryption_test_case_192_5),
15588 		TEST_CASE_ST(ut_setup, ut_teardown,
15589 			test_AES_GCM_auth_encryption_test_case_192_6),
15590 		TEST_CASE_ST(ut_setup, ut_teardown,
15591 			test_AES_GCM_auth_encryption_test_case_192_7),
15592 
15593 		/** AES GCM Authenticated Decryption 192 bits key */
15594 		TEST_CASE_ST(ut_setup, ut_teardown,
15595 			test_AES_GCM_auth_decryption_test_case_192_1),
15596 		TEST_CASE_ST(ut_setup, ut_teardown,
15597 			test_AES_GCM_auth_decryption_test_case_192_2),
15598 		TEST_CASE_ST(ut_setup, ut_teardown,
15599 			test_AES_GCM_auth_decryption_test_case_192_3),
15600 		TEST_CASE_ST(ut_setup, ut_teardown,
15601 			test_AES_GCM_auth_decryption_test_case_192_4),
15602 		TEST_CASE_ST(ut_setup, ut_teardown,
15603 			test_AES_GCM_auth_decryption_test_case_192_5),
15604 		TEST_CASE_ST(ut_setup, ut_teardown,
15605 			test_AES_GCM_auth_decryption_test_case_192_6),
15606 		TEST_CASE_ST(ut_setup, ut_teardown,
15607 			test_AES_GCM_auth_decryption_test_case_192_7),
15608 
15609 		/** AES GCM Authenticated Encryption 256 bits key */
15610 		TEST_CASE_ST(ut_setup, ut_teardown,
15611 			test_AES_GCM_auth_encryption_test_case_256_1),
15612 		TEST_CASE_ST(ut_setup, ut_teardown,
15613 			test_AES_GCM_auth_encryption_test_case_256_2),
15614 		TEST_CASE_ST(ut_setup, ut_teardown,
15615 			test_AES_GCM_auth_encryption_test_case_256_3),
15616 		TEST_CASE_ST(ut_setup, ut_teardown,
15617 			test_AES_GCM_auth_encryption_test_case_256_4),
15618 		TEST_CASE_ST(ut_setup, ut_teardown,
15619 			test_AES_GCM_auth_encryption_test_case_256_5),
15620 		TEST_CASE_ST(ut_setup, ut_teardown,
15621 			test_AES_GCM_auth_encryption_test_case_256_6),
15622 		TEST_CASE_ST(ut_setup, ut_teardown,
15623 			test_AES_GCM_auth_encryption_test_case_256_7),
15624 
15625 		/** AES GCM Authenticated Decryption 256 bits key */
15626 		TEST_CASE_ST(ut_setup, ut_teardown,
15627 			test_AES_GCM_auth_decryption_test_case_256_1),
15628 		TEST_CASE_ST(ut_setup, ut_teardown,
15629 			test_AES_GCM_auth_decryption_test_case_256_2),
15630 		TEST_CASE_ST(ut_setup, ut_teardown,
15631 			test_AES_GCM_auth_decryption_test_case_256_3),
15632 		TEST_CASE_ST(ut_setup, ut_teardown,
15633 			test_AES_GCM_auth_decryption_test_case_256_4),
15634 		TEST_CASE_ST(ut_setup, ut_teardown,
15635 			test_AES_GCM_auth_decryption_test_case_256_5),
15636 		TEST_CASE_ST(ut_setup, ut_teardown,
15637 			test_AES_GCM_auth_decryption_test_case_256_6),
15638 		TEST_CASE_ST(ut_setup, ut_teardown,
15639 			test_AES_GCM_auth_decryption_test_case_256_7),
15640 
15641 		/** AES GCM Authenticated Encryption big aad size */
15642 		TEST_CASE_ST(ut_setup, ut_teardown,
15643 			test_AES_GCM_auth_encryption_test_case_aad_1),
15644 		TEST_CASE_ST(ut_setup, ut_teardown,
15645 			test_AES_GCM_auth_encryption_test_case_aad_2),
15646 
15647 		/** AES GCM Authenticated Decryption big aad size */
15648 		TEST_CASE_ST(ut_setup, ut_teardown,
15649 			test_AES_GCM_auth_decryption_test_case_aad_1),
15650 		TEST_CASE_ST(ut_setup, ut_teardown,
15651 			test_AES_GCM_auth_decryption_test_case_aad_2),
15652 
15653 		/** Out of place tests */
15654 		TEST_CASE_ST(ut_setup, ut_teardown,
15655 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
15656 		TEST_CASE_ST(ut_setup, ut_teardown,
15657 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
15658 
15659 		/** Session-less tests */
15660 		TEST_CASE_ST(ut_setup, ut_teardown,
15661 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
15662 		TEST_CASE_ST(ut_setup, ut_teardown,
15663 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
15664 
15665 		TEST_CASES_END()
15666 	}
15667 };
15668 
15669 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
15670 	.suite_name = "AES GMAC Authentication Test Suite",
15671 	.setup = aes_gmac_auth_testsuite_setup,
15672 	.unit_test_cases = {
15673 		TEST_CASE_ST(ut_setup, ut_teardown,
15674 			test_AES_GMAC_authentication_test_case_1),
15675 		TEST_CASE_ST(ut_setup, ut_teardown,
15676 			test_AES_GMAC_authentication_verify_test_case_1),
15677 		TEST_CASE_ST(ut_setup, ut_teardown,
15678 			test_AES_GMAC_authentication_test_case_2),
15679 		TEST_CASE_ST(ut_setup, ut_teardown,
15680 			test_AES_GMAC_authentication_verify_test_case_2),
15681 		TEST_CASE_ST(ut_setup, ut_teardown,
15682 			test_AES_GMAC_authentication_test_case_3),
15683 		TEST_CASE_ST(ut_setup, ut_teardown,
15684 			test_AES_GMAC_authentication_verify_test_case_3),
15685 		TEST_CASE_ST(ut_setup, ut_teardown,
15686 			test_AES_GMAC_authentication_test_case_4),
15687 		TEST_CASE_ST(ut_setup, ut_teardown,
15688 			test_AES_GMAC_authentication_verify_test_case_4),
15689 		TEST_CASE_ST(ut_setup, ut_teardown,
15690 			test_AES_GMAC_authentication_SGL_40B),
15691 		TEST_CASE_ST(ut_setup, ut_teardown,
15692 			test_AES_GMAC_authentication_SGL_80B),
15693 		TEST_CASE_ST(ut_setup, ut_teardown,
15694 			test_AES_GMAC_authentication_SGL_2048B),
15695 		TEST_CASE_ST(ut_setup, ut_teardown,
15696 			test_AES_GMAC_authentication_SGL_2047B),
15697 
15698 		TEST_CASES_END()
15699 	}
15700 };
15701 
15702 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
15703 	.suite_name = "Chacha20-Poly1305 Test Suite",
15704 	.setup = chacha20_poly1305_testsuite_setup,
15705 	.unit_test_cases = {
15706 		TEST_CASE_ST(ut_setup, ut_teardown,
15707 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
15708 		TEST_CASE_ST(ut_setup, ut_teardown,
15709 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
15710 		TEST_CASE_ST(ut_setup, ut_teardown,
15711 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
15712 		TEST_CASES_END()
15713 	}
15714 };
15715 
15716 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
15717 	.suite_name = "SNOW 3G Test Suite",
15718 	.setup = snow3g_testsuite_setup,
15719 	.unit_test_cases = {
15720 		/** SNOW 3G encrypt only (UEA2) */
15721 		TEST_CASE_ST(ut_setup, ut_teardown,
15722 			test_snow3g_encryption_test_case_1),
15723 		TEST_CASE_ST(ut_setup, ut_teardown,
15724 			test_snow3g_encryption_test_case_2),
15725 		TEST_CASE_ST(ut_setup, ut_teardown,
15726 			test_snow3g_encryption_test_case_3),
15727 		TEST_CASE_ST(ut_setup, ut_teardown,
15728 			test_snow3g_encryption_test_case_4),
15729 		TEST_CASE_ST(ut_setup, ut_teardown,
15730 			test_snow3g_encryption_test_case_5),
15731 
15732 		TEST_CASE_ST(ut_setup, ut_teardown,
15733 			test_snow3g_encryption_test_case_1_oop),
15734 		TEST_CASE_ST(ut_setup, ut_teardown,
15735 			test_snow3g_encryption_test_case_1_oop_sgl),
15736 		TEST_CASE_ST(ut_setup, ut_teardown,
15737 			test_snow3g_encryption_test_case_1_offset_oop),
15738 		TEST_CASE_ST(ut_setup, ut_teardown,
15739 			test_snow3g_decryption_test_case_1_oop),
15740 
15741 		/** SNOW 3G generate auth, then encrypt (UEA2) */
15742 		TEST_CASE_ST(ut_setup, ut_teardown,
15743 			test_snow3g_auth_cipher_test_case_1),
15744 		TEST_CASE_ST(ut_setup, ut_teardown,
15745 			test_snow3g_auth_cipher_test_case_2),
15746 		TEST_CASE_ST(ut_setup, ut_teardown,
15747 			test_snow3g_auth_cipher_test_case_2_oop),
15748 		TEST_CASE_ST(ut_setup, ut_teardown,
15749 			test_snow3g_auth_cipher_part_digest_enc),
15750 		TEST_CASE_ST(ut_setup, ut_teardown,
15751 			test_snow3g_auth_cipher_part_digest_enc_oop),
15752 		TEST_CASE_ST(ut_setup, ut_teardown,
15753 			test_snow3g_auth_cipher_test_case_3_sgl),
15754 		TEST_CASE_ST(ut_setup, ut_teardown,
15755 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
15756 		TEST_CASE_ST(ut_setup, ut_teardown,
15757 			test_snow3g_auth_cipher_part_digest_enc_sgl),
15758 		TEST_CASE_ST(ut_setup, ut_teardown,
15759 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
15760 
15761 		/** SNOW 3G decrypt (UEA2), then verify auth */
15762 		TEST_CASE_ST(ut_setup, ut_teardown,
15763 			test_snow3g_auth_cipher_verify_test_case_1),
15764 		TEST_CASE_ST(ut_setup, ut_teardown,
15765 			test_snow3g_auth_cipher_verify_test_case_2),
15766 		TEST_CASE_ST(ut_setup, ut_teardown,
15767 			test_snow3g_auth_cipher_verify_test_case_2_oop),
15768 		TEST_CASE_ST(ut_setup, ut_teardown,
15769 			test_snow3g_auth_cipher_verify_part_digest_enc),
15770 		TEST_CASE_ST(ut_setup, ut_teardown,
15771 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
15772 		TEST_CASE_ST(ut_setup, ut_teardown,
15773 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
15774 		TEST_CASE_ST(ut_setup, ut_teardown,
15775 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
15776 		TEST_CASE_ST(ut_setup, ut_teardown,
15777 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
15778 		TEST_CASE_ST(ut_setup, ut_teardown,
15779 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
15780 
15781 		/** SNOW 3G decrypt only (UEA2) */
15782 		TEST_CASE_ST(ut_setup, ut_teardown,
15783 			test_snow3g_decryption_test_case_1),
15784 		TEST_CASE_ST(ut_setup, ut_teardown,
15785 			test_snow3g_decryption_test_case_2),
15786 		TEST_CASE_ST(ut_setup, ut_teardown,
15787 			test_snow3g_decryption_test_case_3),
15788 		TEST_CASE_ST(ut_setup, ut_teardown,
15789 			test_snow3g_decryption_test_case_4),
15790 		TEST_CASE_ST(ut_setup, ut_teardown,
15791 			test_snow3g_decryption_test_case_5),
15792 		TEST_CASE_ST(ut_setup, ut_teardown,
15793 			test_snow3g_decryption_with_digest_test_case_1),
15794 		TEST_CASE_ST(ut_setup, ut_teardown,
15795 			test_snow3g_hash_generate_test_case_1),
15796 		TEST_CASE_ST(ut_setup, ut_teardown,
15797 			test_snow3g_hash_generate_test_case_2),
15798 		TEST_CASE_ST(ut_setup, ut_teardown,
15799 			test_snow3g_hash_generate_test_case_3),
15800 
15801 		/* Tests with buffers which length is not byte-aligned */
15802 		TEST_CASE_ST(ut_setup, ut_teardown,
15803 			test_snow3g_hash_generate_test_case_4),
15804 		TEST_CASE_ST(ut_setup, ut_teardown,
15805 			test_snow3g_hash_generate_test_case_5),
15806 		TEST_CASE_ST(ut_setup, ut_teardown,
15807 			test_snow3g_hash_generate_test_case_6),
15808 		TEST_CASE_ST(ut_setup, ut_teardown,
15809 			test_snow3g_hash_verify_test_case_1),
15810 		TEST_CASE_ST(ut_setup, ut_teardown,
15811 			test_snow3g_hash_verify_test_case_2),
15812 		TEST_CASE_ST(ut_setup, ut_teardown,
15813 			test_snow3g_hash_verify_test_case_3),
15814 
15815 		/* Tests with buffers which length is not byte-aligned */
15816 		TEST_CASE_ST(ut_setup, ut_teardown,
15817 			test_snow3g_hash_verify_test_case_4),
15818 		TEST_CASE_ST(ut_setup, ut_teardown,
15819 			test_snow3g_hash_verify_test_case_5),
15820 		TEST_CASE_ST(ut_setup, ut_teardown,
15821 			test_snow3g_hash_verify_test_case_6),
15822 		TEST_CASE_ST(ut_setup, ut_teardown,
15823 			test_snow3g_cipher_auth_test_case_1),
15824 		TEST_CASE_ST(ut_setup, ut_teardown,
15825 			test_snow3g_auth_cipher_with_digest_test_case_1),
15826 		TEST_CASES_END()
15827 	}
15828 };
15829 
15830 static struct unit_test_suite cryptodev_zuc_testsuite  = {
15831 	.suite_name = "ZUC Test Suite",
15832 	.setup = zuc_testsuite_setup,
15833 	.unit_test_cases = {
15834 		/** ZUC encrypt only (EEA3) */
15835 		TEST_CASE_ST(ut_setup, ut_teardown,
15836 			test_zuc_encryption_test_case_1),
15837 		TEST_CASE_ST(ut_setup, ut_teardown,
15838 			test_zuc_encryption_test_case_2),
15839 		TEST_CASE_ST(ut_setup, ut_teardown,
15840 			test_zuc_encryption_test_case_3),
15841 		TEST_CASE_ST(ut_setup, ut_teardown,
15842 			test_zuc_encryption_test_case_4),
15843 		TEST_CASE_ST(ut_setup, ut_teardown,
15844 			test_zuc_encryption_test_case_5),
15845 		TEST_CASE_ST(ut_setup, ut_teardown,
15846 			test_zuc_encryption_test_case_6_sgl),
15847 
15848 		/** ZUC authenticate (EIA3) */
15849 		TEST_CASE_ST(ut_setup, ut_teardown,
15850 			test_zuc_hash_generate_test_case_1),
15851 		TEST_CASE_ST(ut_setup, ut_teardown,
15852 			test_zuc_hash_generate_test_case_2),
15853 		TEST_CASE_ST(ut_setup, ut_teardown,
15854 			test_zuc_hash_generate_test_case_3),
15855 		TEST_CASE_ST(ut_setup, ut_teardown,
15856 			test_zuc_hash_generate_test_case_4),
15857 		TEST_CASE_ST(ut_setup, ut_teardown,
15858 			test_zuc_hash_generate_test_case_5),
15859 		TEST_CASE_ST(ut_setup, ut_teardown,
15860 			test_zuc_hash_generate_test_case_6),
15861 		TEST_CASE_ST(ut_setup, ut_teardown,
15862 			test_zuc_hash_generate_test_case_7),
15863 		TEST_CASE_ST(ut_setup, ut_teardown,
15864 			test_zuc_hash_generate_test_case_8),
15865 		TEST_CASE_ST(ut_setup, ut_teardown,
15866 			test_zuc_hash_generate_test_case_9),
15867 		TEST_CASE_ST(ut_setup, ut_teardown,
15868 			test_zuc_hash_generate_test_case_10),
15869 		TEST_CASE_ST(ut_setup, ut_teardown,
15870 			test_zuc_hash_generate_test_case_11),
15871 
15872 
15873 		/** ZUC alg-chain (EEA3/EIA3) */
15874 		TEST_CASE_ST(ut_setup, ut_teardown,
15875 			test_zuc_cipher_auth_test_case_1),
15876 		TEST_CASE_ST(ut_setup, ut_teardown,
15877 			test_zuc_cipher_auth_test_case_2),
15878 
15879 		/** ZUC generate auth, then encrypt (EEA3) */
15880 		TEST_CASE_ST(ut_setup, ut_teardown,
15881 			test_zuc_auth_cipher_test_case_1),
15882 		TEST_CASE_ST(ut_setup, ut_teardown,
15883 			test_zuc_auth_cipher_test_case_1_oop),
15884 		TEST_CASE_ST(ut_setup, ut_teardown,
15885 			test_zuc_auth_cipher_test_case_1_sgl),
15886 		TEST_CASE_ST(ut_setup, ut_teardown,
15887 			test_zuc_auth_cipher_test_case_1_oop_sgl),
15888 
15889 		/** ZUC decrypt (EEA3), then verify auth */
15890 		TEST_CASE_ST(ut_setup, ut_teardown,
15891 			test_zuc_auth_cipher_verify_test_case_1),
15892 		TEST_CASE_ST(ut_setup, ut_teardown,
15893 			test_zuc_auth_cipher_verify_test_case_1_oop),
15894 		TEST_CASE_ST(ut_setup, ut_teardown,
15895 			test_zuc_auth_cipher_verify_test_case_1_sgl),
15896 		TEST_CASE_ST(ut_setup, ut_teardown,
15897 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
15898 
15899 		/** ZUC-256 encrypt only **/
15900 		TEST_CASE_ST(ut_setup, ut_teardown,
15901 			test_zuc256_encryption_test_case_1),
15902 		TEST_CASE_ST(ut_setup, ut_teardown,
15903 			test_zuc256_encryption_test_case_2),
15904 
15905 		/** ZUC-256 authentication only **/
15906 		TEST_CASE_ST(ut_setup, ut_teardown,
15907 			test_zuc256_authentication_test_case_1),
15908 		TEST_CASE_ST(ut_setup, ut_teardown,
15909 			test_zuc256_authentication_test_case_2),
15910 
15911 		TEST_CASES_END()
15912 	}
15913 };
15914 
15915 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
15916 	.suite_name = "HMAC_MD5 Authentication Test Suite",
15917 	.setup = hmac_md5_auth_testsuite_setup,
15918 	.unit_test_cases = {
15919 		TEST_CASE_ST(ut_setup, ut_teardown,
15920 			test_MD5_HMAC_generate_case_1),
15921 		TEST_CASE_ST(ut_setup, ut_teardown,
15922 			test_MD5_HMAC_verify_case_1),
15923 		TEST_CASE_ST(ut_setup, ut_teardown,
15924 			test_MD5_HMAC_generate_case_2),
15925 		TEST_CASE_ST(ut_setup, ut_teardown,
15926 			test_MD5_HMAC_verify_case_2),
15927 		TEST_CASES_END()
15928 	}
15929 };
15930 
15931 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
15932 	.suite_name = "Kasumi Test Suite",
15933 	.setup = kasumi_testsuite_setup,
15934 	.unit_test_cases = {
15935 		/** KASUMI hash only (UIA1) */
15936 		TEST_CASE_ST(ut_setup, ut_teardown,
15937 			test_kasumi_hash_generate_test_case_1),
15938 		TEST_CASE_ST(ut_setup, ut_teardown,
15939 			test_kasumi_hash_generate_test_case_2),
15940 		TEST_CASE_ST(ut_setup, ut_teardown,
15941 			test_kasumi_hash_generate_test_case_3),
15942 		TEST_CASE_ST(ut_setup, ut_teardown,
15943 			test_kasumi_hash_generate_test_case_4),
15944 		TEST_CASE_ST(ut_setup, ut_teardown,
15945 			test_kasumi_hash_generate_test_case_5),
15946 		TEST_CASE_ST(ut_setup, ut_teardown,
15947 			test_kasumi_hash_generate_test_case_6),
15948 
15949 		TEST_CASE_ST(ut_setup, ut_teardown,
15950 			test_kasumi_hash_verify_test_case_1),
15951 		TEST_CASE_ST(ut_setup, ut_teardown,
15952 			test_kasumi_hash_verify_test_case_2),
15953 		TEST_CASE_ST(ut_setup, ut_teardown,
15954 			test_kasumi_hash_verify_test_case_3),
15955 		TEST_CASE_ST(ut_setup, ut_teardown,
15956 			test_kasumi_hash_verify_test_case_4),
15957 		TEST_CASE_ST(ut_setup, ut_teardown,
15958 			test_kasumi_hash_verify_test_case_5),
15959 
15960 		/** KASUMI encrypt only (UEA1) */
15961 		TEST_CASE_ST(ut_setup, ut_teardown,
15962 			test_kasumi_encryption_test_case_1),
15963 		TEST_CASE_ST(ut_setup, ut_teardown,
15964 			test_kasumi_encryption_test_case_1_sgl),
15965 		TEST_CASE_ST(ut_setup, ut_teardown,
15966 			test_kasumi_encryption_test_case_1_oop),
15967 		TEST_CASE_ST(ut_setup, ut_teardown,
15968 			test_kasumi_encryption_test_case_1_oop_sgl),
15969 		TEST_CASE_ST(ut_setup, ut_teardown,
15970 			test_kasumi_encryption_test_case_2),
15971 		TEST_CASE_ST(ut_setup, ut_teardown,
15972 			test_kasumi_encryption_test_case_3),
15973 		TEST_CASE_ST(ut_setup, ut_teardown,
15974 			test_kasumi_encryption_test_case_4),
15975 		TEST_CASE_ST(ut_setup, ut_teardown,
15976 			test_kasumi_encryption_test_case_5),
15977 
15978 		/** KASUMI decrypt only (UEA1) */
15979 		TEST_CASE_ST(ut_setup, ut_teardown,
15980 			test_kasumi_decryption_test_case_1),
15981 		TEST_CASE_ST(ut_setup, ut_teardown,
15982 			test_kasumi_decryption_test_case_2),
15983 		TEST_CASE_ST(ut_setup, ut_teardown,
15984 			test_kasumi_decryption_test_case_3),
15985 		TEST_CASE_ST(ut_setup, ut_teardown,
15986 			test_kasumi_decryption_test_case_4),
15987 		TEST_CASE_ST(ut_setup, ut_teardown,
15988 			test_kasumi_decryption_test_case_5),
15989 		TEST_CASE_ST(ut_setup, ut_teardown,
15990 			test_kasumi_decryption_test_case_1_oop),
15991 		TEST_CASE_ST(ut_setup, ut_teardown,
15992 			test_kasumi_cipher_auth_test_case_1),
15993 
15994 		/** KASUMI generate auth, then encrypt (F8) */
15995 		TEST_CASE_ST(ut_setup, ut_teardown,
15996 			test_kasumi_auth_cipher_test_case_1),
15997 		TEST_CASE_ST(ut_setup, ut_teardown,
15998 			test_kasumi_auth_cipher_test_case_2),
15999 		TEST_CASE_ST(ut_setup, ut_teardown,
16000 			test_kasumi_auth_cipher_test_case_2_oop),
16001 		TEST_CASE_ST(ut_setup, ut_teardown,
16002 			test_kasumi_auth_cipher_test_case_2_sgl),
16003 		TEST_CASE_ST(ut_setup, ut_teardown,
16004 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
16005 
16006 		/** KASUMI decrypt (F8), then verify auth */
16007 		TEST_CASE_ST(ut_setup, ut_teardown,
16008 			test_kasumi_auth_cipher_verify_test_case_1),
16009 		TEST_CASE_ST(ut_setup, ut_teardown,
16010 			test_kasumi_auth_cipher_verify_test_case_2),
16011 		TEST_CASE_ST(ut_setup, ut_teardown,
16012 			test_kasumi_auth_cipher_verify_test_case_2_oop),
16013 		TEST_CASE_ST(ut_setup, ut_teardown,
16014 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
16015 		TEST_CASE_ST(ut_setup, ut_teardown,
16016 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
16017 
16018 		TEST_CASES_END()
16019 	}
16020 };
16021 
16022 static struct unit_test_suite cryptodev_esn_testsuite  = {
16023 	.suite_name = "ESN Test Suite",
16024 	.setup = esn_testsuite_setup,
16025 	.unit_test_cases = {
16026 		TEST_CASE_ST(ut_setup, ut_teardown,
16027 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
16028 		TEST_CASE_ST(ut_setup, ut_teardown,
16029 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
16030 		TEST_CASES_END()
16031 	}
16032 };
16033 
16034 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
16035 	.suite_name = "Negative AES GCM Test Suite",
16036 	.setup = negative_aes_gcm_testsuite_setup,
16037 	.unit_test_cases = {
16038 		TEST_CASE_ST(ut_setup, ut_teardown,
16039 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
16040 		TEST_CASE_ST(ut_setup, ut_teardown,
16041 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
16042 		TEST_CASE_ST(ut_setup, ut_teardown,
16043 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
16044 		TEST_CASE_ST(ut_setup, ut_teardown,
16045 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
16046 		TEST_CASE_ST(ut_setup, ut_teardown,
16047 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
16048 		TEST_CASE_ST(ut_setup, ut_teardown,
16049 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
16050 		TEST_CASE_ST(ut_setup, ut_teardown,
16051 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
16052 		TEST_CASE_ST(ut_setup, ut_teardown,
16053 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
16054 		TEST_CASE_ST(ut_setup, ut_teardown,
16055 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
16056 		TEST_CASE_ST(ut_setup, ut_teardown,
16057 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
16058 		TEST_CASE_ST(ut_setup, ut_teardown,
16059 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
16060 		TEST_CASE_ST(ut_setup, ut_teardown,
16061 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
16062 
16063 		TEST_CASES_END()
16064 	}
16065 };
16066 
16067 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
16068 	.suite_name = "Negative AES GMAC Test Suite",
16069 	.setup = negative_aes_gmac_testsuite_setup,
16070 	.unit_test_cases = {
16071 		TEST_CASE_ST(ut_setup, ut_teardown,
16072 			authentication_verify_AES128_GMAC_fail_data_corrupt),
16073 		TEST_CASE_ST(ut_setup, ut_teardown,
16074 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
16075 
16076 		TEST_CASES_END()
16077 	}
16078 };
16079 
16080 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
16081 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
16082 	.setup = mixed_cipher_hash_testsuite_setup,
16083 	.unit_test_cases = {
16084 		/** AUTH AES CMAC + CIPHER AES CTR */
16085 		TEST_CASE_ST(ut_setup, ut_teardown,
16086 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
16087 		TEST_CASE_ST(ut_setup, ut_teardown,
16088 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
16089 		TEST_CASE_ST(ut_setup, ut_teardown,
16090 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
16091 		TEST_CASE_ST(ut_setup, ut_teardown,
16092 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
16093 		TEST_CASE_ST(ut_setup, ut_teardown,
16094 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
16095 		TEST_CASE_ST(ut_setup, ut_teardown,
16096 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
16097 		TEST_CASE_ST(ut_setup, ut_teardown,
16098 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
16099 		TEST_CASE_ST(ut_setup, ut_teardown,
16100 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
16101 
16102 		/** AUTH ZUC + CIPHER SNOW3G */
16103 		TEST_CASE_ST(ut_setup, ut_teardown,
16104 			test_auth_zuc_cipher_snow_test_case_1),
16105 		TEST_CASE_ST(ut_setup, ut_teardown,
16106 			test_verify_auth_zuc_cipher_snow_test_case_1),
16107 		/** AUTH AES CMAC + CIPHER SNOW3G */
16108 		TEST_CASE_ST(ut_setup, ut_teardown,
16109 			test_auth_aes_cmac_cipher_snow_test_case_1),
16110 		TEST_CASE_ST(ut_setup, ut_teardown,
16111 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
16112 		/** AUTH ZUC + CIPHER AES CTR */
16113 		TEST_CASE_ST(ut_setup, ut_teardown,
16114 			test_auth_zuc_cipher_aes_ctr_test_case_1),
16115 		TEST_CASE_ST(ut_setup, ut_teardown,
16116 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
16117 		/** AUTH SNOW3G + CIPHER AES CTR */
16118 		TEST_CASE_ST(ut_setup, ut_teardown,
16119 			test_auth_snow_cipher_aes_ctr_test_case_1),
16120 		TEST_CASE_ST(ut_setup, ut_teardown,
16121 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
16122 		/** AUTH SNOW3G + CIPHER ZUC */
16123 		TEST_CASE_ST(ut_setup, ut_teardown,
16124 			test_auth_snow_cipher_zuc_test_case_1),
16125 		TEST_CASE_ST(ut_setup, ut_teardown,
16126 			test_verify_auth_snow_cipher_zuc_test_case_1),
16127 		/** AUTH AES CMAC + CIPHER ZUC */
16128 		TEST_CASE_ST(ut_setup, ut_teardown,
16129 			test_auth_aes_cmac_cipher_zuc_test_case_1),
16130 		TEST_CASE_ST(ut_setup, ut_teardown,
16131 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
16132 
16133 		/** AUTH NULL + CIPHER SNOW3G */
16134 		TEST_CASE_ST(ut_setup, ut_teardown,
16135 			test_auth_null_cipher_snow_test_case_1),
16136 		TEST_CASE_ST(ut_setup, ut_teardown,
16137 			test_verify_auth_null_cipher_snow_test_case_1),
16138 		/** AUTH NULL + CIPHER ZUC */
16139 		TEST_CASE_ST(ut_setup, ut_teardown,
16140 			test_auth_null_cipher_zuc_test_case_1),
16141 		TEST_CASE_ST(ut_setup, ut_teardown,
16142 			test_verify_auth_null_cipher_zuc_test_case_1),
16143 		/** AUTH SNOW3G + CIPHER NULL */
16144 		TEST_CASE_ST(ut_setup, ut_teardown,
16145 			test_auth_snow_cipher_null_test_case_1),
16146 		TEST_CASE_ST(ut_setup, ut_teardown,
16147 			test_verify_auth_snow_cipher_null_test_case_1),
16148 		/** AUTH ZUC + CIPHER NULL */
16149 		TEST_CASE_ST(ut_setup, ut_teardown,
16150 			test_auth_zuc_cipher_null_test_case_1),
16151 		TEST_CASE_ST(ut_setup, ut_teardown,
16152 			test_verify_auth_zuc_cipher_null_test_case_1),
16153 		/** AUTH NULL + CIPHER AES CTR */
16154 		TEST_CASE_ST(ut_setup, ut_teardown,
16155 			test_auth_null_cipher_aes_ctr_test_case_1),
16156 		TEST_CASE_ST(ut_setup, ut_teardown,
16157 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
16158 		/** AUTH AES CMAC + CIPHER NULL */
16159 		TEST_CASE_ST(ut_setup, ut_teardown,
16160 			test_auth_aes_cmac_cipher_null_test_case_1),
16161 		TEST_CASE_ST(ut_setup, ut_teardown,
16162 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
16163 		TEST_CASES_END()
16164 	}
16165 };
16166 
16167 static int
16168 run_cryptodev_testsuite(const char *pmd_name)
16169 {
16170 	uint8_t ret, j, i = 0, blk_start_idx = 0;
16171 	const enum blockcipher_test_type blk_suites[] = {
16172 		BLKCIPHER_AES_CHAIN_TYPE,
16173 		BLKCIPHER_AES_CIPHERONLY_TYPE,
16174 		BLKCIPHER_AES_DOCSIS_TYPE,
16175 		BLKCIPHER_3DES_CHAIN_TYPE,
16176 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
16177 		BLKCIPHER_DES_CIPHERONLY_TYPE,
16178 		BLKCIPHER_DES_DOCSIS_TYPE,
16179 		BLKCIPHER_AUTHONLY_TYPE};
16180 	struct unit_test_suite *static_suites[] = {
16181 		&cryptodev_multi_session_testsuite,
16182 		&cryptodev_null_testsuite,
16183 		&cryptodev_aes_ccm_auth_testsuite,
16184 		&cryptodev_aes_gcm_auth_testsuite,
16185 		&cryptodev_aes_gmac_auth_testsuite,
16186 		&cryptodev_snow3g_testsuite,
16187 		&cryptodev_chacha20_poly1305_testsuite,
16188 		&cryptodev_zuc_testsuite,
16189 		&cryptodev_hmac_md5_auth_testsuite,
16190 		&cryptodev_kasumi_testsuite,
16191 		&cryptodev_esn_testsuite,
16192 		&cryptodev_negative_aes_gcm_testsuite,
16193 		&cryptodev_negative_aes_gmac_testsuite,
16194 		&cryptodev_mixed_cipher_hash_testsuite,
16195 		&cryptodev_negative_hmac_sha1_testsuite,
16196 		&cryptodev_gen_testsuite,
16197 #ifdef RTE_LIB_SECURITY
16198 		&ipsec_proto_testsuite,
16199 		&pdcp_proto_testsuite,
16200 		&docsis_proto_testsuite,
16201 #endif
16202 		&end_testsuite
16203 	};
16204 	static struct unit_test_suite ts = {
16205 		.suite_name = "Cryptodev Unit Test Suite",
16206 		.setup = testsuite_setup,
16207 		.teardown = testsuite_teardown,
16208 		.unit_test_cases = {TEST_CASES_END()}
16209 	};
16210 
16211 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
16212 
16213 	if (gbl_driver_id == -1) {
16214 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
16215 		return TEST_SKIPPED;
16216 	}
16217 
16218 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
16219 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
16220 
16221 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
16222 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
16223 	ret = unit_test_suite_runner(&ts);
16224 
16225 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
16226 	free(ts.unit_test_suites);
16227 	return ret;
16228 }
16229 
16230 static int
16231 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
16232 {
16233 	struct rte_cryptodev_info dev_info;
16234 	uint8_t i, nb_devs;
16235 	int driver_id;
16236 
16237 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
16238 	if (driver_id == -1) {
16239 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
16240 		return TEST_SKIPPED;
16241 	}
16242 
16243 	nb_devs = rte_cryptodev_count();
16244 	if (nb_devs < 1) {
16245 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
16246 		return TEST_SKIPPED;
16247 	}
16248 
16249 	for (i = 0; i < nb_devs; i++) {
16250 		rte_cryptodev_info_get(i, &dev_info);
16251 		if (dev_info.driver_id == driver_id) {
16252 			if (!(dev_info.feature_flags & flag)) {
16253 				RTE_LOG(INFO, USER1, "%s not supported\n",
16254 						flag_name);
16255 				return TEST_SKIPPED;
16256 			}
16257 			return 0; /* found */
16258 		}
16259 	}
16260 
16261 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
16262 	return TEST_SKIPPED;
16263 }
16264 
16265 static int
16266 test_cryptodev_qat(void)
16267 {
16268 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
16269 }
16270 
16271 static int
16272 test_cryptodev_virtio(void)
16273 {
16274 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
16275 }
16276 
16277 static int
16278 test_cryptodev_aesni_mb(void)
16279 {
16280 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
16281 }
16282 
16283 static int
16284 test_cryptodev_cpu_aesni_mb(void)
16285 {
16286 	int32_t rc;
16287 	enum rte_security_session_action_type at = gbl_action_type;
16288 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
16289 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
16290 	gbl_action_type = at;
16291 	return rc;
16292 }
16293 
16294 static int
16295 test_cryptodev_chacha_poly_mb(void)
16296 {
16297 	int32_t rc;
16298 	enum rte_security_session_action_type at = gbl_action_type;
16299 	rc = run_cryptodev_testsuite(
16300 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
16301 	gbl_action_type = at;
16302 	return rc;
16303 }
16304 
16305 static int
16306 test_cryptodev_openssl(void)
16307 {
16308 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
16309 }
16310 
16311 static int
16312 test_cryptodev_aesni_gcm(void)
16313 {
16314 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
16315 }
16316 
16317 static int
16318 test_cryptodev_cpu_aesni_gcm(void)
16319 {
16320 	int32_t rc;
16321 	enum rte_security_session_action_type at = gbl_action_type;
16322 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
16323 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
16324 	gbl_action_type = at;
16325 	return rc;
16326 }
16327 
16328 static int
16329 test_cryptodev_mlx5(void)
16330 {
16331 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
16332 }
16333 
16334 static int
16335 test_cryptodev_null(void)
16336 {
16337 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
16338 }
16339 
16340 static int
16341 test_cryptodev_sw_snow3g(void)
16342 {
16343 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
16344 }
16345 
16346 static int
16347 test_cryptodev_sw_kasumi(void)
16348 {
16349 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
16350 }
16351 
16352 static int
16353 test_cryptodev_sw_zuc(void)
16354 {
16355 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
16356 }
16357 
16358 static int
16359 test_cryptodev_armv8(void)
16360 {
16361 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
16362 }
16363 
16364 static int
16365 test_cryptodev_mrvl(void)
16366 {
16367 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
16368 }
16369 
16370 #ifdef RTE_CRYPTO_SCHEDULER
16371 
16372 static int
16373 test_cryptodev_scheduler(void)
16374 {
16375 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
16376 	const enum blockcipher_test_type blk_suites[] = {
16377 		BLKCIPHER_AES_CHAIN_TYPE,
16378 		BLKCIPHER_AES_CIPHERONLY_TYPE,
16379 		BLKCIPHER_AUTHONLY_TYPE
16380 	};
16381 	static struct unit_test_suite scheduler_multicore = {
16382 		.suite_name = "Scheduler Multicore Unit Test Suite",
16383 		.setup = scheduler_multicore_testsuite_setup,
16384 		.teardown = scheduler_mode_testsuite_teardown,
16385 		.unit_test_cases = {TEST_CASES_END()}
16386 	};
16387 	static struct unit_test_suite scheduler_round_robin = {
16388 		.suite_name = "Scheduler Round Robin Unit Test Suite",
16389 		.setup = scheduler_roundrobin_testsuite_setup,
16390 		.teardown = scheduler_mode_testsuite_teardown,
16391 		.unit_test_cases = {TEST_CASES_END()}
16392 	};
16393 	static struct unit_test_suite scheduler_failover = {
16394 		.suite_name = "Scheduler Failover Unit Test Suite",
16395 		.setup = scheduler_failover_testsuite_setup,
16396 		.teardown = scheduler_mode_testsuite_teardown,
16397 		.unit_test_cases = {TEST_CASES_END()}
16398 	};
16399 	static struct unit_test_suite scheduler_pkt_size_distr = {
16400 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
16401 		.setup = scheduler_pkt_size_distr_testsuite_setup,
16402 		.teardown = scheduler_mode_testsuite_teardown,
16403 		.unit_test_cases = {TEST_CASES_END()}
16404 	};
16405 	struct unit_test_suite *sched_mode_suites[] = {
16406 		&scheduler_multicore,
16407 		&scheduler_round_robin,
16408 		&scheduler_failover,
16409 		&scheduler_pkt_size_distr
16410 	};
16411 	static struct unit_test_suite scheduler_config = {
16412 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
16413 		.unit_test_cases = {
16414 			TEST_CASE(test_scheduler_attach_worker_op),
16415 			TEST_CASE(test_scheduler_mode_multicore_op),
16416 			TEST_CASE(test_scheduler_mode_roundrobin_op),
16417 			TEST_CASE(test_scheduler_mode_failover_op),
16418 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
16419 			TEST_CASE(test_scheduler_detach_worker_op),
16420 
16421 			TEST_CASES_END() /**< NULL terminate array */
16422 		}
16423 	};
16424 	struct unit_test_suite *static_suites[] = {
16425 		&scheduler_config,
16426 		&end_testsuite
16427 	};
16428 	static struct unit_test_suite ts = {
16429 		.suite_name = "Scheduler Unit Test Suite",
16430 		.setup = scheduler_testsuite_setup,
16431 		.teardown = testsuite_teardown,
16432 		.unit_test_cases = {TEST_CASES_END()}
16433 	};
16434 
16435 	gbl_driver_id =	rte_cryptodev_driver_id_get(
16436 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
16437 
16438 	if (gbl_driver_id == -1) {
16439 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
16440 		return TEST_SKIPPED;
16441 	}
16442 
16443 	if (rte_cryptodev_driver_id_get(
16444 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
16445 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
16446 		return TEST_SKIPPED;
16447 	}
16448 
16449 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
16450 		uint8_t blk_i = 0;
16451 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
16452 				(struct unit_test_suite *) *
16453 				(RTE_DIM(blk_suites) + 1));
16454 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
16455 				blk_suites, RTE_DIM(blk_suites));
16456 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
16457 	}
16458 
16459 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
16460 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
16461 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
16462 			RTE_DIM(sched_mode_suites));
16463 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
16464 	ret = unit_test_suite_runner(&ts);
16465 
16466 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
16467 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
16468 				(*sched_mode_suites[sched_i]),
16469 				RTE_DIM(blk_suites));
16470 		free(sched_mode_suites[sched_i]->unit_test_suites);
16471 	}
16472 	free(ts.unit_test_suites);
16473 	return ret;
16474 }
16475 
16476 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
16477 
16478 #endif
16479 
16480 static int
16481 test_cryptodev_dpaa2_sec(void)
16482 {
16483 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
16484 }
16485 
16486 static int
16487 test_cryptodev_dpaa_sec(void)
16488 {
16489 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
16490 }
16491 
16492 static int
16493 test_cryptodev_ccp(void)
16494 {
16495 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
16496 }
16497 
16498 static int
16499 test_cryptodev_octeontx(void)
16500 {
16501 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
16502 }
16503 
16504 static int
16505 test_cryptodev_caam_jr(void)
16506 {
16507 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
16508 }
16509 
16510 static int
16511 test_cryptodev_nitrox(void)
16512 {
16513 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
16514 }
16515 
16516 static int
16517 test_cryptodev_bcmfs(void)
16518 {
16519 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
16520 }
16521 
16522 static int
16523 test_cryptodev_qat_raw_api(void)
16524 {
16525 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
16526 	int ret;
16527 
16528 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16529 			"RAW API");
16530 	if (ret)
16531 		return ret;
16532 
16533 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16534 	ret = run_cryptodev_testsuite(pmd_name);
16535 	global_api_test_type = CRYPTODEV_API_TEST;
16536 
16537 	return ret;
16538 }
16539 
16540 static int
16541 test_cryptodev_cn9k(void)
16542 {
16543 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
16544 }
16545 
16546 static int
16547 test_cryptodev_cn10k(void)
16548 {
16549 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
16550 }
16551 
16552 static int
16553 test_cryptodev_dpaa2_sec_raw_api(void)
16554 {
16555 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
16556 	int ret;
16557 
16558 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16559 			"RAW API");
16560 	if (ret)
16561 		return ret;
16562 
16563 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16564 	ret = run_cryptodev_testsuite(pmd_name);
16565 	global_api_test_type = CRYPTODEV_API_TEST;
16566 
16567 	return ret;
16568 }
16569 
16570 static int
16571 test_cryptodev_dpaa_sec_raw_api(void)
16572 {
16573 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
16574 	int ret;
16575 
16576 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16577 			"RAW API");
16578 	if (ret)
16579 		return ret;
16580 
16581 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16582 	ret = run_cryptodev_testsuite(pmd_name);
16583 	global_api_test_type = CRYPTODEV_API_TEST;
16584 
16585 	return ret;
16586 }
16587 
16588 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
16589 		test_cryptodev_dpaa2_sec_raw_api);
16590 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
16591 		test_cryptodev_dpaa_sec_raw_api);
16592 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
16593 		test_cryptodev_qat_raw_api);
16594 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
16595 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
16596 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
16597 	test_cryptodev_cpu_aesni_mb);
16598 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest,
16599 	test_cryptodev_chacha_poly_mb);
16600 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
16601 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
16602 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
16603 	test_cryptodev_cpu_aesni_gcm);
16604 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
16605 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
16606 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
16607 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
16608 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
16609 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
16610 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
16611 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
16612 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
16613 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
16614 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
16615 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
16616 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
16617 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
16618 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
16619 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
16620 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
16621 
16622 #endif /* !RTE_EXEC_ENV_WINDOWS */
16623