xref: /dpdk/app/test/test_cryptodev.c (revision 1345c5ba)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #include <time.h>
7 
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16 
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_ip.h>
20 #include <rte_string_fns.h>
21 #include <rte_tcp.h>
22 #include <rte_udp.h>
23 
24 #ifdef RTE_CRYPTO_SCHEDULER
25 #include <rte_cryptodev_scheduler.h>
26 #include <rte_cryptodev_scheduler_operations.h>
27 #endif
28 
29 #include <rte_lcore.h>
30 
31 #include "test.h"
32 #include "test_cryptodev.h"
33 
34 #include "test_cryptodev_blockcipher.h"
35 #include "test_cryptodev_aes_test_vectors.h"
36 #include "test_cryptodev_des_test_vectors.h"
37 #include "test_cryptodev_hash_test_vectors.h"
38 #include "test_cryptodev_kasumi_test_vectors.h"
39 #include "test_cryptodev_kasumi_hash_test_vectors.h"
40 #include "test_cryptodev_snow3g_test_vectors.h"
41 #include "test_cryptodev_snow3g_hash_test_vectors.h"
42 #include "test_cryptodev_zuc_test_vectors.h"
43 #include "test_cryptodev_aead_test_vectors.h"
44 #include "test_cryptodev_hmac_test_vectors.h"
45 #include "test_cryptodev_mixed_test_vectors.h"
46 #ifdef RTE_LIB_SECURITY
47 #include "test_cryptodev_security_ipsec.h"
48 #include "test_cryptodev_security_ipsec_test_vectors.h"
49 #include "test_cryptodev_security_pdcp_test_vectors.h"
50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_func.h"
52 #include "test_cryptodev_security_docsis_test_vectors.h"
53 
54 #define SDAP_DISABLED	0
55 #define SDAP_ENABLED	1
56 #endif
57 
58 #define VDEV_ARGS_SIZE 100
59 #define MAX_NB_SESSIONS 4
60 
61 #define MAX_DRV_SERVICE_CTX_SIZE 256
62 
63 #define MAX_RAW_DEQUEUE_COUNT	65535
64 
65 #define IN_PLACE 0
66 #define OUT_OF_PLACE 1
67 
68 static int gbl_driver_id;
69 
70 static enum rte_security_session_action_type gbl_action_type =
71 	RTE_SECURITY_ACTION_TYPE_NONE;
72 
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74 
75 struct crypto_unittest_params {
76 	struct rte_crypto_sym_xform cipher_xform;
77 	struct rte_crypto_sym_xform auth_xform;
78 	struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80 	struct rte_security_docsis_xform docsis_xform;
81 #endif
82 
83 	union {
84 		struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86 		struct rte_security_session *sec_session;
87 #endif
88 	};
89 #ifdef RTE_LIB_SECURITY
90 	enum rte_security_session_action_type type;
91 #endif
92 	struct rte_crypto_op *op;
93 
94 	struct rte_mbuf *obuf, *ibuf;
95 
96 	uint8_t *digest;
97 };
98 
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100 	(((num) + (align) - 1) & ~((align) - 1))
101 
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
103 	for (j = 0; j < num_child_ts; index++, j++)			\
104 		parent_ts.unit_test_suites[index] = child_ts[j]
105 
106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
107 	for (j = 0; j < num_blk_types; index++, j++)				\
108 		parent_ts.unit_test_suites[index] =				\
109 				build_blockcipher_test_suite(blk_types[j])
110 
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
112 	for (j = index; j < index + num_blk_types; j++)				\
113 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114 
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121 		uint8_t *hmac_key);
122 
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125 		struct crypto_unittest_params *ut_params,
126 		struct crypto_testsuite_params *ts_param,
127 		const uint8_t *cipher,
128 		const uint8_t *digest,
129 		const uint8_t *iv);
130 
131 static int
132 security_proto_supported(enum rte_security_session_action_type action,
133 	enum rte_security_session_protocol proto);
134 
135 static int
136 dev_configure_and_start(uint64_t ff_disable);
137 
138 static struct rte_mbuf *
139 setup_test_string(struct rte_mempool *mpool,
140 		const char *string, size_t len, uint8_t blocksize)
141 {
142 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
143 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
144 
145 	if (m) {
146 		char *dst;
147 
148 		memset(m->buf_addr, 0, m->buf_len);
149 		dst = rte_pktmbuf_append(m, t_len);
150 		if (!dst) {
151 			rte_pktmbuf_free(m);
152 			return NULL;
153 		}
154 		if (string != NULL)
155 			rte_memcpy(dst, string, t_len);
156 		else
157 			memset(dst, 0, t_len);
158 	}
159 
160 	return m;
161 }
162 
163 /* Get number of bytes in X bits (rounding up) */
164 static uint32_t
165 ceil_byte_length(uint32_t num_bits)
166 {
167 	if (num_bits % 8)
168 		return ((num_bits >> 3) + 1);
169 	else
170 		return (num_bits >> 3);
171 }
172 
173 static void
174 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
175 		uint8_t is_op_success)
176 {
177 	struct rte_crypto_op *op = user_data;
178 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
179 			RTE_CRYPTO_OP_STATUS_ERROR;
180 }
181 
182 static struct crypto_testsuite_params testsuite_params = { NULL };
183 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
184 static struct crypto_unittest_params unittest_params;
185 
186 void
187 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
188 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
189 		uint8_t len_in_bits, uint8_t cipher_iv_len)
190 {
191 	struct rte_crypto_sym_op *sop = op->sym;
192 	struct rte_crypto_op *ret_op = NULL;
193 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
194 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
195 	union rte_crypto_sym_ofs ofs;
196 	struct rte_crypto_sym_vec vec;
197 	struct rte_crypto_sgl sgl, dest_sgl;
198 	uint32_t max_len;
199 	union rte_cryptodev_session_ctx sess;
200 	uint64_t auth_end_iova;
201 	uint32_t count = 0;
202 	struct rte_crypto_raw_dp_ctx *ctx;
203 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
204 			auth_len = 0;
205 	int32_t n;
206 	uint32_t n_success;
207 	int ctx_service_size;
208 	int32_t status = 0;
209 	int enqueue_status, dequeue_status;
210 	struct crypto_unittest_params *ut_params = &unittest_params;
211 	int is_sgl = sop->m_src->nb_segs > 1;
212 
213 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
214 	if (ctx_service_size < 0) {
215 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
216 		return;
217 	}
218 
219 	ctx = malloc(ctx_service_size);
220 	if (!ctx) {
221 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
222 		return;
223 	}
224 
225 	/* Both are enums, setting crypto_sess will suit any session type */
226 	sess.crypto_sess = op->sym->session;
227 
228 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
229 			op->sess_type, sess, 0) < 0) {
230 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
231 		goto exit;
232 	}
233 
234 	cipher_iv.iova = 0;
235 	cipher_iv.va = NULL;
236 	aad_auth_iv.iova = 0;
237 	aad_auth_iv.va = NULL;
238 	digest.iova = 0;
239 	digest.va = NULL;
240 	sgl.vec = data_vec;
241 	vec.num = 1;
242 	vec.src_sgl = &sgl;
243 	vec.iv = &cipher_iv;
244 	vec.digest = &digest;
245 	vec.aad = &aad_auth_iv;
246 	vec.status = &status;
247 
248 	ofs.raw = 0;
249 
250 	if (is_cipher && is_auth) {
251 		cipher_offset = sop->cipher.data.offset;
252 		cipher_len = sop->cipher.data.length;
253 		auth_offset = sop->auth.data.offset;
254 		auth_len = sop->auth.data.length;
255 		max_len = RTE_MAX(cipher_offset + cipher_len,
256 				auth_offset + auth_len);
257 		if (len_in_bits) {
258 			max_len = max_len >> 3;
259 			cipher_offset = cipher_offset >> 3;
260 			auth_offset = auth_offset >> 3;
261 			cipher_len = cipher_len >> 3;
262 			auth_len = auth_len >> 3;
263 		}
264 		ofs.ofs.cipher.head = cipher_offset;
265 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
266 		ofs.ofs.auth.head = auth_offset;
267 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
268 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
269 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
270 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
271 				op, void *, IV_OFFSET + cipher_iv_len);
272 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
273 				cipher_iv_len);
274 		digest.va = (void *)sop->auth.digest.data;
275 		digest.iova = sop->auth.digest.phys_addr;
276 
277 		if (is_sgl) {
278 			uint32_t remaining_off = auth_offset + auth_len;
279 			struct rte_mbuf *sgl_buf = sop->m_src;
280 
281 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
282 					&& sgl_buf->next != NULL) {
283 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
284 				sgl_buf = sgl_buf->next;
285 			}
286 
287 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
288 				sgl_buf, remaining_off);
289 		} else {
290 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
291 							 auth_offset + auth_len;
292 		}
293 		/* Then check if digest-encrypted conditions are met */
294 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
295 				(digest.iova == auth_end_iova) && is_sgl)
296 			max_len = RTE_MAX(max_len, auth_offset + auth_len +
297 				ut_params->auth_xform.auth.digest_length);
298 
299 	} else if (is_cipher) {
300 		cipher_offset = sop->cipher.data.offset;
301 		cipher_len = sop->cipher.data.length;
302 		max_len = cipher_len + cipher_offset;
303 		if (len_in_bits) {
304 			max_len = max_len >> 3;
305 			cipher_offset = cipher_offset >> 3;
306 			cipher_len = cipher_len >> 3;
307 		}
308 		ofs.ofs.cipher.head = cipher_offset;
309 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
310 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
311 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
312 
313 	} else if (is_auth) {
314 		auth_offset = sop->auth.data.offset;
315 		auth_len = sop->auth.data.length;
316 		max_len = auth_len + auth_offset;
317 		if (len_in_bits) {
318 			max_len = max_len >> 3;
319 			auth_offset = auth_offset >> 3;
320 			auth_len = auth_len >> 3;
321 		}
322 		ofs.ofs.auth.head = auth_offset;
323 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
324 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
325 				op, void *, IV_OFFSET + cipher_iv_len);
326 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
327 				cipher_iv_len);
328 		digest.va = (void *)sop->auth.digest.data;
329 		digest.iova = sop->auth.digest.phys_addr;
330 
331 	} else { /* aead */
332 		cipher_offset = sop->aead.data.offset;
333 		cipher_len = sop->aead.data.length;
334 		max_len = cipher_len + cipher_offset;
335 		if (len_in_bits) {
336 			max_len = max_len >> 3;
337 			cipher_offset = cipher_offset >> 3;
338 			cipher_len = cipher_len >> 3;
339 		}
340 		ofs.ofs.cipher.head = cipher_offset;
341 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
342 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
343 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
344 		aad_auth_iv.va = (void *)sop->aead.aad.data;
345 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
346 		digest.va = (void *)sop->aead.digest.data;
347 		digest.iova = sop->aead.digest.phys_addr;
348 	}
349 
350 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
351 			data_vec, RTE_DIM(data_vec));
352 	if (n < 0 || n > sop->m_src->nb_segs) {
353 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
354 		goto exit;
355 	}
356 
357 	sgl.num = n;
358 	/* Out of place */
359 	if (sop->m_dst != NULL) {
360 		dest_sgl.vec = dest_data_vec;
361 		vec.dest_sgl = &dest_sgl;
362 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
363 				dest_data_vec, RTE_DIM(dest_data_vec));
364 		if (n < 0 || n > sop->m_dst->nb_segs) {
365 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
366 			goto exit;
367 		}
368 		dest_sgl.num = n;
369 	} else
370 		vec.dest_sgl = NULL;
371 
372 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
373 			&enqueue_status) < 1) {
374 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
375 		goto exit;
376 	}
377 
378 	if (enqueue_status == 0) {
379 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
380 		if (status < 0) {
381 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
382 			goto exit;
383 		}
384 	} else if (enqueue_status < 0) {
385 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
386 		goto exit;
387 	}
388 
389 	n = n_success = 0;
390 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
391 		n = rte_cryptodev_raw_dequeue_burst(ctx,
392 			NULL, 1, post_process_raw_dp_op,
393 				(void **)&ret_op, 0, &n_success,
394 				&dequeue_status);
395 		if (dequeue_status < 0) {
396 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
397 			goto exit;
398 		}
399 		if (n == 0)
400 			rte_pause();
401 	}
402 
403 	if (n == 1 && dequeue_status == 0) {
404 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
405 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
406 			goto exit;
407 		}
408 	}
409 
410 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
411 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
412 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
413 					RTE_CRYPTO_OP_STATUS_SUCCESS;
414 
415 exit:
416 	free(ctx);
417 }
418 
419 static void
420 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
421 {
422 	int32_t n, st;
423 	struct rte_crypto_sym_op *sop;
424 	union rte_crypto_sym_ofs ofs;
425 	struct rte_crypto_sgl sgl;
426 	struct rte_crypto_sym_vec symvec;
427 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
428 	struct rte_crypto_vec vec[UINT8_MAX];
429 
430 	sop = op->sym;
431 
432 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
433 		sop->aead.data.length, vec, RTE_DIM(vec));
434 
435 	if (n < 0 || n != sop->m_src->nb_segs) {
436 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
437 		return;
438 	}
439 
440 	sgl.vec = vec;
441 	sgl.num = n;
442 	symvec.src_sgl = &sgl;
443 	symvec.iv = &iv_ptr;
444 	symvec.digest = &digest_ptr;
445 	symvec.aad = &aad_ptr;
446 	symvec.status = &st;
447 	symvec.num = 1;
448 
449 	/* for CPU crypto the IOVA address is not required */
450 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
451 	digest_ptr.va = (void *)sop->aead.digest.data;
452 	aad_ptr.va = (void *)sop->aead.aad.data;
453 
454 	ofs.raw = 0;
455 
456 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
457 		&symvec);
458 
459 	if (n != 1)
460 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
461 	else
462 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
463 }
464 
465 static void
466 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
467 {
468 	int32_t n, st;
469 	struct rte_crypto_sym_op *sop;
470 	union rte_crypto_sym_ofs ofs;
471 	struct rte_crypto_sgl sgl;
472 	struct rte_crypto_sym_vec symvec;
473 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
474 	struct rte_crypto_vec vec[UINT8_MAX];
475 
476 	sop = op->sym;
477 
478 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
479 		sop->auth.data.length, vec, RTE_DIM(vec));
480 
481 	if (n < 0 || n != sop->m_src->nb_segs) {
482 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
483 		return;
484 	}
485 
486 	sgl.vec = vec;
487 	sgl.num = n;
488 	symvec.src_sgl = &sgl;
489 	symvec.iv = &iv_ptr;
490 	symvec.digest = &digest_ptr;
491 	symvec.status = &st;
492 	symvec.num = 1;
493 
494 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
495 	digest_ptr.va = (void *)sop->auth.digest.data;
496 
497 	ofs.raw = 0;
498 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
499 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
500 		(sop->cipher.data.offset + sop->cipher.data.length);
501 
502 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
503 		&symvec);
504 
505 	if (n != 1)
506 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
507 	else
508 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
509 }
510 
511 static struct rte_crypto_op *
512 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
513 {
514 
515 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
516 
517 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
518 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
519 		return NULL;
520 	}
521 
522 	op = NULL;
523 
524 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
525 		rte_pause();
526 
527 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
528 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
529 		return NULL;
530 	}
531 
532 	return op;
533 }
534 
535 static int
536 testsuite_setup(void)
537 {
538 	struct crypto_testsuite_params *ts_params = &testsuite_params;
539 	struct rte_cryptodev_info info;
540 	uint32_t i = 0, nb_devs, dev_id;
541 	uint16_t qp_id;
542 
543 	memset(ts_params, 0, sizeof(*ts_params));
544 
545 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
546 	if (ts_params->mbuf_pool == NULL) {
547 		/* Not already created so create */
548 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
549 				"CRYPTO_MBUFPOOL",
550 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
551 				rte_socket_id());
552 		if (ts_params->mbuf_pool == NULL) {
553 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
554 			return TEST_FAILED;
555 		}
556 	}
557 
558 	ts_params->large_mbuf_pool = rte_mempool_lookup(
559 			"CRYPTO_LARGE_MBUFPOOL");
560 	if (ts_params->large_mbuf_pool == NULL) {
561 		/* Not already created so create */
562 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
563 				"CRYPTO_LARGE_MBUFPOOL",
564 				1, 0, 0, UINT16_MAX,
565 				rte_socket_id());
566 		if (ts_params->large_mbuf_pool == NULL) {
567 			RTE_LOG(ERR, USER1,
568 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
569 			return TEST_FAILED;
570 		}
571 	}
572 
573 	ts_params->op_mpool = rte_crypto_op_pool_create(
574 			"MBUF_CRYPTO_SYM_OP_POOL",
575 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
576 			NUM_MBUFS, MBUF_CACHE_SIZE,
577 			DEFAULT_NUM_XFORMS *
578 			sizeof(struct rte_crypto_sym_xform) +
579 			MAXIMUM_IV_LENGTH,
580 			rte_socket_id());
581 	if (ts_params->op_mpool == NULL) {
582 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
583 		return TEST_FAILED;
584 	}
585 
586 	nb_devs = rte_cryptodev_count();
587 	if (nb_devs < 1) {
588 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
589 		return TEST_SKIPPED;
590 	}
591 
592 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
593 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
594 				rte_cryptodev_driver_name_get(gbl_driver_id));
595 		return TEST_SKIPPED;
596 	}
597 
598 	/* Create list of valid crypto devs */
599 	for (i = 0; i < nb_devs; i++) {
600 		rte_cryptodev_info_get(i, &info);
601 		if (info.driver_id == gbl_driver_id)
602 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
603 	}
604 
605 	if (ts_params->valid_dev_count < 1)
606 		return TEST_FAILED;
607 
608 	/* Set up all the qps on the first of the valid devices found */
609 
610 	dev_id = ts_params->valid_devs[0];
611 
612 	rte_cryptodev_info_get(dev_id, &info);
613 
614 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
615 	ts_params->conf.socket_id = SOCKET_ID_ANY;
616 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
617 
618 	unsigned int session_size =
619 		rte_cryptodev_sym_get_private_session_size(dev_id);
620 
621 #ifdef RTE_LIB_SECURITY
622 	unsigned int security_session_size = rte_security_session_get_size(
623 			rte_cryptodev_get_sec_ctx(dev_id));
624 
625 	if (session_size < security_session_size)
626 		session_size = security_session_size;
627 #endif
628 	/*
629 	 * Create mempool with maximum number of sessions.
630 	 */
631 	if (info.sym.max_nb_sessions != 0 &&
632 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
633 		RTE_LOG(ERR, USER1, "Device does not support "
634 				"at least %u sessions\n",
635 				MAX_NB_SESSIONS);
636 		return TEST_FAILED;
637 	}
638 
639 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
640 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
641 			SOCKET_ID_ANY);
642 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
643 			"session mempool allocation failed");
644 
645 	ts_params->session_priv_mpool = rte_mempool_create(
646 			"test_sess_mp_priv",
647 			MAX_NB_SESSIONS,
648 			session_size,
649 			0, 0, NULL, NULL, NULL,
650 			NULL, SOCKET_ID_ANY,
651 			0);
652 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
653 			"session mempool allocation failed");
654 
655 
656 
657 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
658 			&ts_params->conf),
659 			"Failed to configure cryptodev %u with %u qps",
660 			dev_id, ts_params->conf.nb_queue_pairs);
661 
662 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
663 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
664 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
665 
666 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
667 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
668 			dev_id, qp_id, &ts_params->qp_conf,
669 			rte_cryptodev_socket_id(dev_id)),
670 			"Failed to setup queue pair %u on cryptodev %u",
671 			qp_id, dev_id);
672 	}
673 
674 	return TEST_SUCCESS;
675 }
676 
677 static void
678 testsuite_teardown(void)
679 {
680 	struct crypto_testsuite_params *ts_params = &testsuite_params;
681 	int res;
682 
683 	if (ts_params->mbuf_pool != NULL) {
684 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
685 		rte_mempool_avail_count(ts_params->mbuf_pool));
686 	}
687 
688 	if (ts_params->op_mpool != NULL) {
689 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
690 		rte_mempool_avail_count(ts_params->op_mpool));
691 	}
692 
693 	/* Free session mempools */
694 	if (ts_params->session_priv_mpool != NULL) {
695 		rte_mempool_free(ts_params->session_priv_mpool);
696 		ts_params->session_priv_mpool = NULL;
697 	}
698 
699 	if (ts_params->session_mpool != NULL) {
700 		rte_mempool_free(ts_params->session_mpool);
701 		ts_params->session_mpool = NULL;
702 	}
703 
704 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
705 	if (res)
706 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
707 }
708 
709 static int
710 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
711 		const int *algs, uint16_t num_algs)
712 {
713 	uint8_t dev_id = testsuite_params.valid_devs[0];
714 	bool some_alg_supported = FALSE;
715 	uint16_t i;
716 
717 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
718 		struct rte_cryptodev_sym_capability_idx alg = {
719 			type, {algs[i]}
720 		};
721 		if (rte_cryptodev_sym_capability_get(dev_id,
722 				&alg) != NULL)
723 			some_alg_supported = TRUE;
724 	}
725 	if (!some_alg_supported)
726 		return TEST_SKIPPED;
727 
728 	return 0;
729 }
730 
731 int
732 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
733 		uint16_t num_ciphers)
734 {
735 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
736 			(const int *) ciphers, num_ciphers);
737 }
738 
739 int
740 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
741 		uint16_t num_auths)
742 {
743 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
744 			(const int *) auths, num_auths);
745 }
746 
747 int
748 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
749 		uint16_t num_aeads)
750 {
751 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
752 			(const int *) aeads, num_aeads);
753 }
754 
755 static int
756 null_testsuite_setup(void)
757 {
758 	struct crypto_testsuite_params *ts_params = &testsuite_params;
759 	uint8_t dev_id = ts_params->valid_devs[0];
760 	struct rte_cryptodev_info dev_info;
761 	const enum rte_crypto_cipher_algorithm ciphers[] = {
762 		RTE_CRYPTO_CIPHER_NULL
763 	};
764 	const enum rte_crypto_auth_algorithm auths[] = {
765 		RTE_CRYPTO_AUTH_NULL
766 	};
767 
768 	rte_cryptodev_info_get(dev_id, &dev_info);
769 
770 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
771 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
772 				"testsuite not met\n");
773 		return TEST_SKIPPED;
774 	}
775 
776 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
777 			&& check_auth_capabilities_supported(auths,
778 			RTE_DIM(auths)) != 0) {
779 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
780 				"testsuite not met\n");
781 		return TEST_SKIPPED;
782 	}
783 
784 	return 0;
785 }
786 
787 static int
788 crypto_gen_testsuite_setup(void)
789 {
790 	struct crypto_testsuite_params *ts_params = &testsuite_params;
791 	uint8_t dev_id = ts_params->valid_devs[0];
792 	struct rte_cryptodev_info dev_info;
793 
794 	rte_cryptodev_info_get(dev_id, &dev_info);
795 
796 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
797 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
798 				"testsuite not met\n");
799 		return TEST_SKIPPED;
800 	}
801 
802 	return 0;
803 }
804 
805 #ifdef RTE_LIB_SECURITY
806 static int
807 ipsec_proto_testsuite_setup(void)
808 {
809 	struct crypto_testsuite_params *ts_params = &testsuite_params;
810 	struct crypto_unittest_params *ut_params = &unittest_params;
811 	struct rte_cryptodev_info dev_info;
812 	int ret = 0;
813 
814 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
815 
816 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
817 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
818 				"testsuite not met\n");
819 		return TEST_SKIPPED;
820 	}
821 
822 	/* Reconfigure to enable security */
823 	ret = dev_configure_and_start(0);
824 	if (ret != TEST_SUCCESS)
825 		return ret;
826 
827 	/* Set action type */
828 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
829 
830 	if (security_proto_supported(
831 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
832 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
833 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
834 				"test not met\n");
835 		ret = TEST_SKIPPED;
836 	}
837 
838 	/*
839 	 * Stop the device. Device would be started again by individual test
840 	 * case setup routine.
841 	 */
842 	rte_cryptodev_stop(ts_params->valid_devs[0]);
843 
844 	return ret;
845 }
846 
847 static int
848 pdcp_proto_testsuite_setup(void)
849 {
850 	struct crypto_testsuite_params *ts_params = &testsuite_params;
851 	uint8_t dev_id = ts_params->valid_devs[0];
852 	struct rte_cryptodev_info dev_info;
853 	const enum rte_crypto_cipher_algorithm ciphers[] = {
854 		RTE_CRYPTO_CIPHER_NULL,
855 		RTE_CRYPTO_CIPHER_AES_CTR,
856 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
857 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
858 	};
859 	const enum rte_crypto_auth_algorithm auths[] = {
860 		RTE_CRYPTO_AUTH_NULL,
861 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
862 		RTE_CRYPTO_AUTH_AES_CMAC,
863 		RTE_CRYPTO_AUTH_ZUC_EIA3
864 	};
865 
866 	rte_cryptodev_info_get(dev_id, &dev_info);
867 
868 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
869 			!(dev_info.feature_flags &
870 			RTE_CRYPTODEV_FF_SECURITY)) {
871 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
872 				"testsuite not met\n");
873 		return TEST_SKIPPED;
874 	}
875 
876 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
877 			&& check_auth_capabilities_supported(auths,
878 			RTE_DIM(auths)) != 0) {
879 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
880 				"testsuite not met\n");
881 		return TEST_SKIPPED;
882 	}
883 
884 	return 0;
885 }
886 
887 static int
888 docsis_proto_testsuite_setup(void)
889 {
890 	struct crypto_testsuite_params *ts_params = &testsuite_params;
891 	uint8_t dev_id = ts_params->valid_devs[0];
892 	struct rte_cryptodev_info dev_info;
893 	const enum rte_crypto_cipher_algorithm ciphers[] = {
894 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
895 	};
896 
897 	rte_cryptodev_info_get(dev_id, &dev_info);
898 
899 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
900 			!(dev_info.feature_flags &
901 			RTE_CRYPTODEV_FF_SECURITY)) {
902 		RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
903 				"Proto testsuite not met\n");
904 		return TEST_SKIPPED;
905 	}
906 
907 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
908 		RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
909 				"testsuite not met\n");
910 		return TEST_SKIPPED;
911 	}
912 
913 	return 0;
914 }
915 #endif
916 
917 static int
918 aes_ccm_auth_testsuite_setup(void)
919 {
920 	struct crypto_testsuite_params *ts_params = &testsuite_params;
921 	uint8_t dev_id = ts_params->valid_devs[0];
922 	struct rte_cryptodev_info dev_info;
923 	const enum rte_crypto_aead_algorithm aeads[] = {
924 		RTE_CRYPTO_AEAD_AES_CCM
925 	};
926 
927 	rte_cryptodev_info_get(dev_id, &dev_info);
928 
929 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
930 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
931 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
932 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
933 				"testsuite not met\n");
934 		return TEST_SKIPPED;
935 	}
936 
937 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
938 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
939 				"testsuite not met\n");
940 		return TEST_SKIPPED;
941 	}
942 
943 	return 0;
944 }
945 
946 static int
947 aes_gcm_auth_testsuite_setup(void)
948 {
949 	struct crypto_testsuite_params *ts_params = &testsuite_params;
950 	uint8_t dev_id = ts_params->valid_devs[0];
951 	struct rte_cryptodev_info dev_info;
952 	const enum rte_crypto_aead_algorithm aeads[] = {
953 		RTE_CRYPTO_AEAD_AES_GCM
954 	};
955 
956 	rte_cryptodev_info_get(dev_id, &dev_info);
957 
958 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
959 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
960 				"testsuite not met\n");
961 		return TEST_SKIPPED;
962 	}
963 
964 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
965 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
966 				"testsuite not met\n");
967 		return TEST_SKIPPED;
968 	}
969 
970 	return 0;
971 }
972 
973 static int
974 aes_gmac_auth_testsuite_setup(void)
975 {
976 	struct crypto_testsuite_params *ts_params = &testsuite_params;
977 	uint8_t dev_id = ts_params->valid_devs[0];
978 	struct rte_cryptodev_info dev_info;
979 	const enum rte_crypto_auth_algorithm auths[] = {
980 		RTE_CRYPTO_AUTH_AES_GMAC
981 	};
982 
983 	rte_cryptodev_info_get(dev_id, &dev_info);
984 
985 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
986 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
987 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
988 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
989 				"testsuite not met\n");
990 		return TEST_SKIPPED;
991 	}
992 
993 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
994 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
995 				"testsuite not met\n");
996 		return TEST_SKIPPED;
997 	}
998 
999 	return 0;
1000 }
1001 
1002 static int
1003 chacha20_poly1305_testsuite_setup(void)
1004 {
1005 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1006 	uint8_t dev_id = ts_params->valid_devs[0];
1007 	struct rte_cryptodev_info dev_info;
1008 	const enum rte_crypto_aead_algorithm aeads[] = {
1009 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
1010 	};
1011 
1012 	rte_cryptodev_info_get(dev_id, &dev_info);
1013 
1014 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1015 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1016 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1017 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
1018 				"Chacha20-Poly1305 testsuite not met\n");
1019 		return TEST_SKIPPED;
1020 	}
1021 
1022 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1023 		RTE_LOG(INFO, USER1, "Capability requirements for "
1024 				"Chacha20-Poly1305 testsuite not met\n");
1025 		return TEST_SKIPPED;
1026 	}
1027 
1028 	return 0;
1029 }
1030 
1031 static int
1032 snow3g_testsuite_setup(void)
1033 {
1034 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1035 	uint8_t dev_id = ts_params->valid_devs[0];
1036 	struct rte_cryptodev_info dev_info;
1037 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1038 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1039 
1040 	};
1041 	const enum rte_crypto_auth_algorithm auths[] = {
1042 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1043 	};
1044 
1045 	rte_cryptodev_info_get(dev_id, &dev_info);
1046 
1047 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1048 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1049 				"testsuite not met\n");
1050 		return TEST_SKIPPED;
1051 	}
1052 
1053 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1054 			&& check_auth_capabilities_supported(auths,
1055 			RTE_DIM(auths)) != 0) {
1056 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1057 				"testsuite not met\n");
1058 		return TEST_SKIPPED;
1059 	}
1060 
1061 	return 0;
1062 }
1063 
1064 static int
1065 zuc_testsuite_setup(void)
1066 {
1067 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1068 	uint8_t dev_id = ts_params->valid_devs[0];
1069 	struct rte_cryptodev_info dev_info;
1070 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1071 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1072 	};
1073 	const enum rte_crypto_auth_algorithm auths[] = {
1074 		RTE_CRYPTO_AUTH_ZUC_EIA3
1075 	};
1076 
1077 	rte_cryptodev_info_get(dev_id, &dev_info);
1078 
1079 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1080 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1081 				"testsuite not met\n");
1082 		return TEST_SKIPPED;
1083 	}
1084 
1085 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1086 			&& check_auth_capabilities_supported(auths,
1087 			RTE_DIM(auths)) != 0) {
1088 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1089 				"testsuite not met\n");
1090 		return TEST_SKIPPED;
1091 	}
1092 
1093 	return 0;
1094 }
1095 
1096 static int
1097 hmac_md5_auth_testsuite_setup(void)
1098 {
1099 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1100 	uint8_t dev_id = ts_params->valid_devs[0];
1101 	struct rte_cryptodev_info dev_info;
1102 	const enum rte_crypto_auth_algorithm auths[] = {
1103 		RTE_CRYPTO_AUTH_MD5_HMAC
1104 	};
1105 
1106 	rte_cryptodev_info_get(dev_id, &dev_info);
1107 
1108 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1109 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1110 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1111 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1112 				"Auth testsuite not met\n");
1113 		return TEST_SKIPPED;
1114 	}
1115 
1116 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1117 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1118 				"testsuite not met\n");
1119 		return TEST_SKIPPED;
1120 	}
1121 
1122 	return 0;
1123 }
1124 
1125 static int
1126 kasumi_testsuite_setup(void)
1127 {
1128 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1129 	uint8_t dev_id = ts_params->valid_devs[0];
1130 	struct rte_cryptodev_info dev_info;
1131 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1132 		RTE_CRYPTO_CIPHER_KASUMI_F8
1133 	};
1134 	const enum rte_crypto_auth_algorithm auths[] = {
1135 		RTE_CRYPTO_AUTH_KASUMI_F9
1136 	};
1137 
1138 	rte_cryptodev_info_get(dev_id, &dev_info);
1139 
1140 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1141 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1142 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1143 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1144 				"testsuite not met\n");
1145 		return TEST_SKIPPED;
1146 	}
1147 
1148 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1149 			&& check_auth_capabilities_supported(auths,
1150 			RTE_DIM(auths)) != 0) {
1151 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1152 				"testsuite not met\n");
1153 		return TEST_SKIPPED;
1154 	}
1155 
1156 	return 0;
1157 }
1158 
1159 static int
1160 negative_aes_gcm_testsuite_setup(void)
1161 {
1162 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1163 	uint8_t dev_id = ts_params->valid_devs[0];
1164 	struct rte_cryptodev_info dev_info;
1165 	const enum rte_crypto_aead_algorithm aeads[] = {
1166 		RTE_CRYPTO_AEAD_AES_GCM
1167 	};
1168 
1169 	rte_cryptodev_info_get(dev_id, &dev_info);
1170 
1171 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1172 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1173 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1174 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1175 				"AES GCM testsuite not met\n");
1176 		return TEST_SKIPPED;
1177 	}
1178 
1179 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1180 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1181 				"AES GCM testsuite not met\n");
1182 		return TEST_SKIPPED;
1183 	}
1184 
1185 	return 0;
1186 }
1187 
1188 static int
1189 negative_aes_gmac_testsuite_setup(void)
1190 {
1191 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1192 	uint8_t dev_id = ts_params->valid_devs[0];
1193 	struct rte_cryptodev_info dev_info;
1194 	const enum rte_crypto_auth_algorithm auths[] = {
1195 		RTE_CRYPTO_AUTH_AES_GMAC
1196 	};
1197 
1198 	rte_cryptodev_info_get(dev_id, &dev_info);
1199 
1200 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1201 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1202 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1203 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1204 				"AES GMAC testsuite not met\n");
1205 		return TEST_SKIPPED;
1206 	}
1207 
1208 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1209 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1210 				"AES GMAC testsuite not met\n");
1211 		return TEST_SKIPPED;
1212 	}
1213 
1214 	return 0;
1215 }
1216 
1217 static int
1218 mixed_cipher_hash_testsuite_setup(void)
1219 {
1220 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1221 	uint8_t dev_id = ts_params->valid_devs[0];
1222 	struct rte_cryptodev_info dev_info;
1223 	uint64_t feat_flags;
1224 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1225 		RTE_CRYPTO_CIPHER_NULL,
1226 		RTE_CRYPTO_CIPHER_AES_CTR,
1227 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1228 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1229 	};
1230 	const enum rte_crypto_auth_algorithm auths[] = {
1231 		RTE_CRYPTO_AUTH_NULL,
1232 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1233 		RTE_CRYPTO_AUTH_AES_CMAC,
1234 		RTE_CRYPTO_AUTH_ZUC_EIA3
1235 	};
1236 
1237 	rte_cryptodev_info_get(dev_id, &dev_info);
1238 	feat_flags = dev_info.feature_flags;
1239 
1240 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1241 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1242 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1243 				"Cipher Hash testsuite not met\n");
1244 		return TEST_SKIPPED;
1245 	}
1246 
1247 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1248 			&& check_auth_capabilities_supported(auths,
1249 			RTE_DIM(auths)) != 0) {
1250 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1251 				"Cipher Hash testsuite not met\n");
1252 		return TEST_SKIPPED;
1253 	}
1254 
1255 	return 0;
1256 }
1257 
1258 static int
1259 esn_testsuite_setup(void)
1260 {
1261 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1262 	uint8_t dev_id = ts_params->valid_devs[0];
1263 	struct rte_cryptodev_info dev_info;
1264 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1265 		RTE_CRYPTO_CIPHER_AES_CBC
1266 	};
1267 	const enum rte_crypto_auth_algorithm auths[] = {
1268 		RTE_CRYPTO_AUTH_SHA1_HMAC
1269 	};
1270 
1271 	rte_cryptodev_info_get(dev_id, &dev_info);
1272 
1273 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1274 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1275 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1276 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1277 				"testsuite not met\n");
1278 		return TEST_SKIPPED;
1279 	}
1280 
1281 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1282 			&& check_auth_capabilities_supported(auths,
1283 			RTE_DIM(auths)) != 0) {
1284 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1285 				"testsuite not met\n");
1286 		return TEST_SKIPPED;
1287 	}
1288 
1289 	return 0;
1290 }
1291 
1292 static int
1293 multi_session_testsuite_setup(void)
1294 {
1295 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1296 	uint8_t dev_id = ts_params->valid_devs[0];
1297 	struct rte_cryptodev_info dev_info;
1298 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1299 		RTE_CRYPTO_CIPHER_AES_CBC
1300 	};
1301 	const enum rte_crypto_auth_algorithm auths[] = {
1302 		RTE_CRYPTO_AUTH_SHA512_HMAC
1303 	};
1304 
1305 	rte_cryptodev_info_get(dev_id, &dev_info);
1306 
1307 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1308 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1309 				"Session testsuite not met\n");
1310 		return TEST_SKIPPED;
1311 	}
1312 
1313 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1314 			&& check_auth_capabilities_supported(auths,
1315 			RTE_DIM(auths)) != 0) {
1316 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1317 				"Session testsuite not met\n");
1318 		return TEST_SKIPPED;
1319 	}
1320 
1321 	return 0;
1322 }
1323 
1324 static int
1325 negative_hmac_sha1_testsuite_setup(void)
1326 {
1327 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1328 	uint8_t dev_id = ts_params->valid_devs[0];
1329 	struct rte_cryptodev_info dev_info;
1330 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1331 		RTE_CRYPTO_CIPHER_AES_CBC
1332 	};
1333 	const enum rte_crypto_auth_algorithm auths[] = {
1334 		RTE_CRYPTO_AUTH_SHA1_HMAC
1335 	};
1336 
1337 	rte_cryptodev_info_get(dev_id, &dev_info);
1338 
1339 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1340 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1341 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1342 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1343 				"HMAC SHA1 testsuite not met\n");
1344 		return TEST_SKIPPED;
1345 	}
1346 
1347 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1348 			&& check_auth_capabilities_supported(auths,
1349 			RTE_DIM(auths)) != 0) {
1350 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1351 				"HMAC SHA1 testsuite not met\n");
1352 		return TEST_SKIPPED;
1353 	}
1354 
1355 	return 0;
1356 }
1357 
1358 static int
1359 dev_configure_and_start(uint64_t ff_disable)
1360 {
1361 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1362 	struct crypto_unittest_params *ut_params = &unittest_params;
1363 
1364 	uint16_t qp_id;
1365 
1366 	/* Clear unit test parameters before running test */
1367 	memset(ut_params, 0, sizeof(*ut_params));
1368 
1369 	/* Reconfigure device to default parameters */
1370 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1371 	ts_params->conf.ff_disable = ff_disable;
1372 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1373 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1374 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1375 
1376 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1377 			&ts_params->conf),
1378 			"Failed to configure cryptodev %u",
1379 			ts_params->valid_devs[0]);
1380 
1381 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1382 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1383 			ts_params->valid_devs[0], qp_id,
1384 			&ts_params->qp_conf,
1385 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1386 			"Failed to setup queue pair %u on cryptodev %u",
1387 			qp_id, ts_params->valid_devs[0]);
1388 	}
1389 
1390 
1391 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1392 
1393 	/* Start the device */
1394 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1395 			"Failed to start cryptodev %u",
1396 			ts_params->valid_devs[0]);
1397 
1398 	return TEST_SUCCESS;
1399 }
1400 
1401 int
1402 ut_setup(void)
1403 {
1404 	/* Configure and start the device with security feature disabled */
1405 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1406 }
1407 
1408 static int
1409 ut_setup_security(void)
1410 {
1411 	/* Configure and start the device with no features disabled */
1412 	return dev_configure_and_start(0);
1413 }
1414 
1415 void
1416 ut_teardown(void)
1417 {
1418 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1419 	struct crypto_unittest_params *ut_params = &unittest_params;
1420 	struct rte_cryptodev_stats stats;
1421 
1422 	/* free crypto session structure */
1423 #ifdef RTE_LIB_SECURITY
1424 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1425 		if (ut_params->sec_session) {
1426 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1427 						(ts_params->valid_devs[0]),
1428 						ut_params->sec_session);
1429 			ut_params->sec_session = NULL;
1430 		}
1431 	} else
1432 #endif
1433 	{
1434 		if (ut_params->sess) {
1435 			rte_cryptodev_sym_session_clear(
1436 					ts_params->valid_devs[0],
1437 					ut_params->sess);
1438 			rte_cryptodev_sym_session_free(ut_params->sess);
1439 			ut_params->sess = NULL;
1440 		}
1441 	}
1442 
1443 	/* free crypto operation structure */
1444 	if (ut_params->op)
1445 		rte_crypto_op_free(ut_params->op);
1446 
1447 	/*
1448 	 * free mbuf - both obuf and ibuf are usually the same,
1449 	 * so check if they point at the same address is necessary,
1450 	 * to avoid freeing the mbuf twice.
1451 	 */
1452 	if (ut_params->obuf) {
1453 		rte_pktmbuf_free(ut_params->obuf);
1454 		if (ut_params->ibuf == ut_params->obuf)
1455 			ut_params->ibuf = 0;
1456 		ut_params->obuf = 0;
1457 	}
1458 	if (ut_params->ibuf) {
1459 		rte_pktmbuf_free(ut_params->ibuf);
1460 		ut_params->ibuf = 0;
1461 	}
1462 
1463 	if (ts_params->mbuf_pool != NULL)
1464 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1465 			rte_mempool_avail_count(ts_params->mbuf_pool));
1466 
1467 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1468 
1469 	/* Stop the device */
1470 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1471 }
1472 
1473 static int
1474 test_device_configure_invalid_dev_id(void)
1475 {
1476 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1477 	uint16_t dev_id, num_devs = 0;
1478 
1479 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1480 			"Need at least %d devices for test", 1);
1481 
1482 	/* valid dev_id values */
1483 	dev_id = ts_params->valid_devs[0];
1484 
1485 	/* Stop the device in case it's started so it can be configured */
1486 	rte_cryptodev_stop(dev_id);
1487 
1488 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1489 			"Failed test for rte_cryptodev_configure: "
1490 			"invalid dev_num %u", dev_id);
1491 
1492 	/* invalid dev_id values */
1493 	dev_id = num_devs;
1494 
1495 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1496 			"Failed test for rte_cryptodev_configure: "
1497 			"invalid dev_num %u", dev_id);
1498 
1499 	dev_id = 0xff;
1500 
1501 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1502 			"Failed test for rte_cryptodev_configure:"
1503 			"invalid dev_num %u", dev_id);
1504 
1505 	return TEST_SUCCESS;
1506 }
1507 
1508 static int
1509 test_device_configure_invalid_queue_pair_ids(void)
1510 {
1511 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1512 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1513 
1514 	/* Stop the device in case it's started so it can be configured */
1515 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1516 
1517 	/* valid - max value queue pairs */
1518 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1519 
1520 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1521 			&ts_params->conf),
1522 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1523 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1524 
1525 	/* valid - one queue pairs */
1526 	ts_params->conf.nb_queue_pairs = 1;
1527 
1528 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1529 			&ts_params->conf),
1530 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1531 			ts_params->valid_devs[0],
1532 			ts_params->conf.nb_queue_pairs);
1533 
1534 
1535 	/* invalid - zero queue pairs */
1536 	ts_params->conf.nb_queue_pairs = 0;
1537 
1538 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1539 			&ts_params->conf),
1540 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1541 			" invalid qps: %u",
1542 			ts_params->valid_devs[0],
1543 			ts_params->conf.nb_queue_pairs);
1544 
1545 
1546 	/* invalid - max value supported by field queue pairs */
1547 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1548 
1549 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1550 			&ts_params->conf),
1551 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1552 			" invalid qps: %u",
1553 			ts_params->valid_devs[0],
1554 			ts_params->conf.nb_queue_pairs);
1555 
1556 
1557 	/* invalid - max value + 1 queue pairs */
1558 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1559 
1560 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1561 			&ts_params->conf),
1562 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1563 			" invalid qps: %u",
1564 			ts_params->valid_devs[0],
1565 			ts_params->conf.nb_queue_pairs);
1566 
1567 	/* revert to original testsuite value */
1568 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1569 
1570 	return TEST_SUCCESS;
1571 }
1572 
1573 static int
1574 test_queue_pair_descriptor_setup(void)
1575 {
1576 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1577 	struct rte_cryptodev_qp_conf qp_conf = {
1578 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1579 	};
1580 	uint16_t qp_id;
1581 
1582 	/* Stop the device in case it's started so it can be configured */
1583 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1584 
1585 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1586 			&ts_params->conf),
1587 			"Failed to configure cryptodev %u",
1588 			ts_params->valid_devs[0]);
1589 
1590 	/*
1591 	 * Test various ring sizes on this device. memzones can't be
1592 	 * freed so are re-used if ring is released and re-created.
1593 	 */
1594 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1595 	qp_conf.mp_session = ts_params->session_mpool;
1596 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1597 
1598 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1599 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1600 				ts_params->valid_devs[0], qp_id, &qp_conf,
1601 				rte_cryptodev_socket_id(
1602 						ts_params->valid_devs[0])),
1603 				"Failed test for "
1604 				"rte_cryptodev_queue_pair_setup: num_inflights "
1605 				"%u on qp %u on cryptodev %u",
1606 				qp_conf.nb_descriptors, qp_id,
1607 				ts_params->valid_devs[0]);
1608 	}
1609 
1610 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1611 
1612 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1613 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1614 				ts_params->valid_devs[0], qp_id, &qp_conf,
1615 				rte_cryptodev_socket_id(
1616 						ts_params->valid_devs[0])),
1617 				"Failed test for"
1618 				" rte_cryptodev_queue_pair_setup: num_inflights"
1619 				" %u on qp %u on cryptodev %u",
1620 				qp_conf.nb_descriptors, qp_id,
1621 				ts_params->valid_devs[0]);
1622 	}
1623 
1624 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1625 
1626 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1627 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1628 				ts_params->valid_devs[0], qp_id, &qp_conf,
1629 				rte_cryptodev_socket_id(
1630 						ts_params->valid_devs[0])),
1631 				"Failed test for "
1632 				"rte_cryptodev_queue_pair_setup: num_inflights"
1633 				" %u on qp %u on cryptodev %u",
1634 				qp_conf.nb_descriptors, qp_id,
1635 				ts_params->valid_devs[0]);
1636 	}
1637 
1638 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1639 
1640 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1641 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1642 				ts_params->valid_devs[0], qp_id, &qp_conf,
1643 				rte_cryptodev_socket_id(
1644 						ts_params->valid_devs[0])),
1645 				"Failed test for"
1646 				" rte_cryptodev_queue_pair_setup:"
1647 				"num_inflights %u on qp %u on cryptodev %u",
1648 				qp_conf.nb_descriptors, qp_id,
1649 				ts_params->valid_devs[0]);
1650 	}
1651 
1652 	/* test invalid queue pair id */
1653 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1654 
1655 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1656 
1657 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1658 			ts_params->valid_devs[0],
1659 			qp_id, &qp_conf,
1660 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1661 			"Failed test for rte_cryptodev_queue_pair_setup:"
1662 			"invalid qp %u on cryptodev %u",
1663 			qp_id, ts_params->valid_devs[0]);
1664 
1665 	qp_id = 0xffff; /*invalid*/
1666 
1667 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1668 			ts_params->valid_devs[0],
1669 			qp_id, &qp_conf,
1670 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1671 			"Failed test for rte_cryptodev_queue_pair_setup:"
1672 			"invalid qp %u on cryptodev %u",
1673 			qp_id, ts_params->valid_devs[0]);
1674 
1675 	return TEST_SUCCESS;
1676 }
1677 
1678 /* ***** Plaintext data for tests ***** */
1679 
1680 const char catch_22_quote_1[] =
1681 		"There was only one catch and that was Catch-22, which "
1682 		"specified that a concern for one's safety in the face of "
1683 		"dangers that were real and immediate was the process of a "
1684 		"rational mind. Orr was crazy and could be grounded. All he "
1685 		"had to do was ask; and as soon as he did, he would no longer "
1686 		"be crazy and would have to fly more missions. Orr would be "
1687 		"crazy to fly more missions and sane if he didn't, but if he "
1688 		"was sane he had to fly them. If he flew them he was crazy "
1689 		"and didn't have to; but if he didn't want to he was sane and "
1690 		"had to. Yossarian was moved very deeply by the absolute "
1691 		"simplicity of this clause of Catch-22 and let out a "
1692 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1693 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1694 
1695 const char catch_22_quote[] =
1696 		"What a lousy earth! He wondered how many people were "
1697 		"destitute that same night even in his own prosperous country, "
1698 		"how many homes were shanties, how many husbands were drunk "
1699 		"and wives socked, and how many children were bullied, abused, "
1700 		"or abandoned. How many families hungered for food they could "
1701 		"not afford to buy? How many hearts were broken? How many "
1702 		"suicides would take place that same night, how many people "
1703 		"would go insane? How many cockroaches and landlords would "
1704 		"triumph? How many winners were losers, successes failures, "
1705 		"and rich men poor men? How many wise guys were stupid? How "
1706 		"many happy endings were unhappy endings? How many honest men "
1707 		"were liars, brave men cowards, loyal men traitors, how many "
1708 		"sainted men were corrupt, how many people in positions of "
1709 		"trust had sold their souls to bodyguards, how many had never "
1710 		"had souls? How many straight-and-narrow paths were crooked "
1711 		"paths? How many best families were worst families and how "
1712 		"many good people were bad people? When you added them all up "
1713 		"and then subtracted, you might be left with only the children, "
1714 		"and perhaps with Albert Einstein and an old violinist or "
1715 		"sculptor somewhere.";
1716 
1717 #define QUOTE_480_BYTES		(480)
1718 #define QUOTE_512_BYTES		(512)
1719 #define QUOTE_768_BYTES		(768)
1720 #define QUOTE_1024_BYTES	(1024)
1721 
1722 
1723 
1724 /* ***** SHA1 Hash Tests ***** */
1725 
1726 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1727 
1728 static uint8_t hmac_sha1_key[] = {
1729 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1730 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1731 	0xDE, 0xF4, 0xDE, 0xAD };
1732 
1733 /* ***** SHA224 Hash Tests ***** */
1734 
1735 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1736 
1737 
1738 /* ***** AES-CBC Cipher Tests ***** */
1739 
1740 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1741 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1742 
1743 static uint8_t aes_cbc_key[] = {
1744 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1745 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1746 
1747 static uint8_t aes_cbc_iv[] = {
1748 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1749 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1750 
1751 
1752 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1753 
1754 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1755 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1756 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1757 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1758 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1759 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1760 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1761 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1762 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1763 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1764 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1765 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1766 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1767 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1768 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1769 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1770 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1771 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1772 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1773 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1774 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1775 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1776 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1777 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1778 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1779 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1780 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1781 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1782 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1783 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1784 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1785 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1786 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1787 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1788 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1789 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1790 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1791 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1792 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1793 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1794 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1795 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1796 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1797 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1798 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1799 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1800 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1801 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1802 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1803 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1804 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1805 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1806 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1807 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1808 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1809 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1810 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1811 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1812 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1813 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1814 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1815 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1816 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1817 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1818 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1819 };
1820 
1821 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1822 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1823 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1824 	0x18, 0x8c, 0x1d, 0x32
1825 };
1826 
1827 
1828 /* Multisession Vector context Test */
1829 /*Begin Session 0 */
1830 static uint8_t ms_aes_cbc_key0[] = {
1831 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1832 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1833 };
1834 
1835 static uint8_t ms_aes_cbc_iv0[] = {
1836 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1837 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1838 };
1839 
1840 static const uint8_t ms_aes_cbc_cipher0[] = {
1841 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1842 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1843 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1844 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1845 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1846 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1847 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1848 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1849 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1850 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1851 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1852 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1853 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1854 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1855 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1856 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1857 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1858 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1859 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1860 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1861 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1862 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1863 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1864 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1865 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1866 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1867 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1868 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1869 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1870 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1871 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1872 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1873 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1874 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1875 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1876 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1877 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1878 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1879 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1880 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1881 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1882 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1883 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1884 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1885 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1886 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1887 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1888 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1889 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1890 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1891 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1892 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1893 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1894 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1895 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1896 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1897 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1898 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1899 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1900 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1901 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1902 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1903 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1904 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1905 };
1906 
1907 
1908 static  uint8_t ms_hmac_key0[] = {
1909 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1910 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1911 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1912 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1913 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1914 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1915 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1916 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1917 };
1918 
1919 static const uint8_t ms_hmac_digest0[] = {
1920 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1921 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1922 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1923 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1924 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1925 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1926 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1927 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1928 		};
1929 
1930 /* End Session 0 */
1931 /* Begin session 1 */
1932 
1933 static  uint8_t ms_aes_cbc_key1[] = {
1934 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1935 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1936 };
1937 
1938 static  uint8_t ms_aes_cbc_iv1[] = {
1939 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1940 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1941 };
1942 
1943 static const uint8_t ms_aes_cbc_cipher1[] = {
1944 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1945 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1946 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1947 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1948 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1949 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1950 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1951 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1952 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1953 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1954 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1955 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1956 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1957 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1958 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1959 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1960 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1961 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1962 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1963 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1964 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1965 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1966 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1967 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1968 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1969 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1970 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1971 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1972 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1973 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1974 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1975 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1976 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1977 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1978 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1979 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1980 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1981 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1982 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1983 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1984 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1985 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1986 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1987 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1988 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1989 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1990 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1991 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1992 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1993 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1994 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1995 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1996 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1997 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1998 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1999 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
2000 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2001 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2002 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2003 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2004 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2005 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2006 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2007 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2008 
2009 };
2010 
2011 static uint8_t ms_hmac_key1[] = {
2012 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2013 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2014 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2015 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2016 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2017 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2018 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2019 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2020 };
2021 
2022 static const uint8_t ms_hmac_digest1[] = {
2023 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2024 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2025 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2026 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2027 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2028 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2029 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2030 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2031 };
2032 /* End Session 1  */
2033 /* Begin Session 2 */
2034 static  uint8_t ms_aes_cbc_key2[] = {
2035 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2036 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2037 };
2038 
2039 static  uint8_t ms_aes_cbc_iv2[] = {
2040 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2041 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2042 };
2043 
2044 static const uint8_t ms_aes_cbc_cipher2[] = {
2045 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2046 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2047 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2048 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2049 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2050 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2051 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2052 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2053 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2054 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2055 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2056 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2057 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2058 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2059 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2060 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2061 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2062 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2063 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2064 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2065 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2066 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2067 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2068 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2069 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2070 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2071 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2072 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2073 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2074 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2075 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2076 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2077 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2078 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2079 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2080 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2081 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2082 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2083 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2084 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2085 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2086 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2087 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2088 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2089 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2090 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2091 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2092 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2093 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2094 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2095 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2096 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2097 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2098 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2099 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2100 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2101 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2102 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2103 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2104 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2105 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2106 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2107 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2108 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2109 };
2110 
2111 static  uint8_t ms_hmac_key2[] = {
2112 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2113 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2114 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2115 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2116 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2117 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2118 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2119 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2120 };
2121 
2122 static const uint8_t ms_hmac_digest2[] = {
2123 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2124 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2125 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2126 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2127 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2128 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2129 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2130 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2131 };
2132 
2133 /* End Session 2 */
2134 
2135 
2136 static int
2137 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2138 {
2139 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2140 	struct crypto_unittest_params *ut_params = &unittest_params;
2141 
2142 	/* Verify the capabilities */
2143 	struct rte_cryptodev_sym_capability_idx cap_idx;
2144 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2145 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2146 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2147 			&cap_idx) == NULL)
2148 		return TEST_SKIPPED;
2149 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2150 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2151 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2152 			&cap_idx) == NULL)
2153 		return TEST_SKIPPED;
2154 
2155 	/* Generate test mbuf data and space for digest */
2156 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2157 			catch_22_quote,	QUOTE_512_BYTES, 0);
2158 
2159 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2160 			DIGEST_BYTE_LENGTH_SHA1);
2161 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2162 
2163 	/* Setup Cipher Parameters */
2164 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2165 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2166 
2167 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2168 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2169 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2170 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2171 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2172 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2173 
2174 	/* Setup HMAC Parameters */
2175 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2176 
2177 	ut_params->auth_xform.next = NULL;
2178 
2179 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2180 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2181 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2182 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2183 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2184 
2185 	ut_params->sess = rte_cryptodev_sym_session_create(
2186 			ts_params->session_mpool);
2187 
2188 	/* Create crypto session*/
2189 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2190 			ut_params->sess, &ut_params->cipher_xform,
2191 			ts_params->session_priv_mpool);
2192 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2193 
2194 	/* Generate crypto op data structure */
2195 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2196 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2197 	TEST_ASSERT_NOT_NULL(ut_params->op,
2198 			"Failed to allocate symmetric crypto operation struct");
2199 
2200 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2201 
2202 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2203 
2204 	/* set crypto operation source mbuf */
2205 	sym_op->m_src = ut_params->ibuf;
2206 
2207 	/* Set crypto operation authentication parameters */
2208 	sym_op->auth.digest.data = ut_params->digest;
2209 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2210 			ut_params->ibuf, QUOTE_512_BYTES);
2211 
2212 	sym_op->auth.data.offset = 0;
2213 	sym_op->auth.data.length = QUOTE_512_BYTES;
2214 
2215 	/* Copy IV at the end of the crypto operation */
2216 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2217 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2218 
2219 	/* Set crypto operation cipher parameters */
2220 	sym_op->cipher.data.offset = 0;
2221 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2222 
2223 	/* Process crypto operation */
2224 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2225 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2226 			ut_params->op);
2227 	else
2228 		TEST_ASSERT_NOT_NULL(
2229 			process_crypto_request(ts_params->valid_devs[0],
2230 				ut_params->op),
2231 				"failed to process sym crypto op");
2232 
2233 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2234 			"crypto op processing failed");
2235 
2236 	/* Validate obuf */
2237 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2238 			uint8_t *);
2239 
2240 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2241 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2242 			QUOTE_512_BYTES,
2243 			"ciphertext data not as expected");
2244 
2245 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2246 
2247 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2248 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2249 			gbl_driver_id == rte_cryptodev_driver_id_get(
2250 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2251 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2252 					DIGEST_BYTE_LENGTH_SHA1,
2253 			"Generated digest data not as expected");
2254 
2255 	return TEST_SUCCESS;
2256 }
2257 
2258 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2259 
2260 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2261 
2262 static uint8_t hmac_sha512_key[] = {
2263 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2264 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2265 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2266 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2267 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2268 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2269 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2270 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2271 
2272 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2273 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2274 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2275 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2276 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2277 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2278 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2279 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2280 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2281 
2282 
2283 
2284 static int
2285 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2286 		struct crypto_unittest_params *ut_params,
2287 		uint8_t *cipher_key,
2288 		uint8_t *hmac_key);
2289 
2290 static int
2291 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2292 		struct crypto_unittest_params *ut_params,
2293 		struct crypto_testsuite_params *ts_params,
2294 		const uint8_t *cipher,
2295 		const uint8_t *digest,
2296 		const uint8_t *iv);
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 
2306 	/* Setup Cipher Parameters */
2307 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2308 	ut_params->cipher_xform.next = NULL;
2309 
2310 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2311 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2312 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2313 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2314 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2315 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2316 
2317 	/* Setup HMAC Parameters */
2318 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2319 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2320 
2321 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2322 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2323 	ut_params->auth_xform.auth.key.data = hmac_key;
2324 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2325 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2326 
2327 	return TEST_SUCCESS;
2328 }
2329 
2330 
2331 static int
2332 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2333 		struct crypto_unittest_params *ut_params,
2334 		struct crypto_testsuite_params *ts_params,
2335 		const uint8_t *cipher,
2336 		const uint8_t *digest,
2337 		const uint8_t *iv)
2338 {
2339 	/* Generate test mbuf data and digest */
2340 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2341 			(const char *)
2342 			cipher,
2343 			QUOTE_512_BYTES, 0);
2344 
2345 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2346 			DIGEST_BYTE_LENGTH_SHA512);
2347 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2348 
2349 	rte_memcpy(ut_params->digest,
2350 			digest,
2351 			DIGEST_BYTE_LENGTH_SHA512);
2352 
2353 	/* Generate Crypto op data structure */
2354 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2355 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2356 	TEST_ASSERT_NOT_NULL(ut_params->op,
2357 			"Failed to allocate symmetric crypto operation struct");
2358 
2359 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2360 
2361 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2362 
2363 	/* set crypto operation source mbuf */
2364 	sym_op->m_src = ut_params->ibuf;
2365 
2366 	sym_op->auth.digest.data = ut_params->digest;
2367 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2368 			ut_params->ibuf, QUOTE_512_BYTES);
2369 
2370 	sym_op->auth.data.offset = 0;
2371 	sym_op->auth.data.length = QUOTE_512_BYTES;
2372 
2373 	/* Copy IV at the end of the crypto operation */
2374 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2375 			iv, CIPHER_IV_LENGTH_AES_CBC);
2376 
2377 	sym_op->cipher.data.offset = 0;
2378 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2379 
2380 	/* Process crypto operation */
2381 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2382 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2383 			ut_params->op);
2384 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2385 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2386 				ut_params->op, 1, 1, 0, 0);
2387 	else
2388 		TEST_ASSERT_NOT_NULL(
2389 				process_crypto_request(ts_params->valid_devs[0],
2390 					ut_params->op),
2391 					"failed to process sym crypto op");
2392 
2393 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2394 			"crypto op processing failed");
2395 
2396 	ut_params->obuf = ut_params->op->sym->m_src;
2397 
2398 	/* Validate obuf */
2399 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2400 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2401 			catch_22_quote,
2402 			QUOTE_512_BYTES,
2403 			"Plaintext data not as expected");
2404 
2405 	/* Validate obuf */
2406 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2407 			"Digest verification failed");
2408 
2409 	return TEST_SUCCESS;
2410 }
2411 
2412 /* ***** SNOW 3G Tests ***** */
2413 static int
2414 create_wireless_algo_hash_session(uint8_t dev_id,
2415 	const uint8_t *key, const uint8_t key_len,
2416 	const uint8_t iv_len, const uint8_t auth_len,
2417 	enum rte_crypto_auth_operation op,
2418 	enum rte_crypto_auth_algorithm algo)
2419 {
2420 	uint8_t hash_key[key_len];
2421 	int status;
2422 
2423 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2424 	struct crypto_unittest_params *ut_params = &unittest_params;
2425 
2426 	memcpy(hash_key, key, key_len);
2427 
2428 	debug_hexdump(stdout, "key:", key, key_len);
2429 
2430 	/* Setup Authentication Parameters */
2431 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2432 	ut_params->auth_xform.next = NULL;
2433 
2434 	ut_params->auth_xform.auth.op = op;
2435 	ut_params->auth_xform.auth.algo = algo;
2436 	ut_params->auth_xform.auth.key.length = key_len;
2437 	ut_params->auth_xform.auth.key.data = hash_key;
2438 	ut_params->auth_xform.auth.digest_length = auth_len;
2439 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2440 	ut_params->auth_xform.auth.iv.length = iv_len;
2441 	ut_params->sess = rte_cryptodev_sym_session_create(
2442 			ts_params->session_mpool);
2443 
2444 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2445 			&ut_params->auth_xform,
2446 			ts_params->session_priv_mpool);
2447 	if (status == -ENOTSUP)
2448 		return TEST_SKIPPED;
2449 
2450 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2451 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2452 	return 0;
2453 }
2454 
2455 static int
2456 create_wireless_algo_cipher_session(uint8_t dev_id,
2457 			enum rte_crypto_cipher_operation op,
2458 			enum rte_crypto_cipher_algorithm algo,
2459 			const uint8_t *key, const uint8_t key_len,
2460 			uint8_t iv_len)
2461 {
2462 	uint8_t cipher_key[key_len];
2463 	int status;
2464 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2465 	struct crypto_unittest_params *ut_params = &unittest_params;
2466 
2467 	memcpy(cipher_key, key, key_len);
2468 
2469 	/* Setup Cipher Parameters */
2470 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2471 	ut_params->cipher_xform.next = NULL;
2472 
2473 	ut_params->cipher_xform.cipher.algo = algo;
2474 	ut_params->cipher_xform.cipher.op = op;
2475 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2476 	ut_params->cipher_xform.cipher.key.length = key_len;
2477 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2478 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2479 
2480 	debug_hexdump(stdout, "key:", key, key_len);
2481 
2482 	/* Create Crypto session */
2483 	ut_params->sess = rte_cryptodev_sym_session_create(
2484 			ts_params->session_mpool);
2485 
2486 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2487 			&ut_params->cipher_xform,
2488 			ts_params->session_priv_mpool);
2489 	if (status == -ENOTSUP)
2490 		return TEST_SKIPPED;
2491 
2492 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2493 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2494 	return 0;
2495 }
2496 
2497 static int
2498 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2499 			unsigned int cipher_len,
2500 			unsigned int cipher_offset)
2501 {
2502 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2503 	struct crypto_unittest_params *ut_params = &unittest_params;
2504 
2505 	/* Generate Crypto op data structure */
2506 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2507 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2508 	TEST_ASSERT_NOT_NULL(ut_params->op,
2509 				"Failed to allocate pktmbuf offload");
2510 
2511 	/* Set crypto operation data parameters */
2512 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2513 
2514 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2515 
2516 	/* set crypto operation source mbuf */
2517 	sym_op->m_src = ut_params->ibuf;
2518 
2519 	/* iv */
2520 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2521 			iv, iv_len);
2522 	sym_op->cipher.data.length = cipher_len;
2523 	sym_op->cipher.data.offset = cipher_offset;
2524 	return 0;
2525 }
2526 
2527 static int
2528 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2529 			unsigned int cipher_len,
2530 			unsigned int cipher_offset)
2531 {
2532 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2533 	struct crypto_unittest_params *ut_params = &unittest_params;
2534 
2535 	/* Generate Crypto op data structure */
2536 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2537 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2538 	TEST_ASSERT_NOT_NULL(ut_params->op,
2539 				"Failed to allocate pktmbuf offload");
2540 
2541 	/* Set crypto operation data parameters */
2542 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2543 
2544 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2545 
2546 	/* set crypto operation source mbuf */
2547 	sym_op->m_src = ut_params->ibuf;
2548 	sym_op->m_dst = ut_params->obuf;
2549 
2550 	/* iv */
2551 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2552 			iv, iv_len);
2553 	sym_op->cipher.data.length = cipher_len;
2554 	sym_op->cipher.data.offset = cipher_offset;
2555 	return 0;
2556 }
2557 
2558 static int
2559 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2560 		enum rte_crypto_cipher_operation cipher_op,
2561 		enum rte_crypto_auth_operation auth_op,
2562 		enum rte_crypto_auth_algorithm auth_algo,
2563 		enum rte_crypto_cipher_algorithm cipher_algo,
2564 		const uint8_t *key, uint8_t key_len,
2565 		uint8_t auth_iv_len, uint8_t auth_len,
2566 		uint8_t cipher_iv_len)
2567 
2568 {
2569 	uint8_t cipher_auth_key[key_len];
2570 	int status;
2571 
2572 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2573 	struct crypto_unittest_params *ut_params = &unittest_params;
2574 
2575 	memcpy(cipher_auth_key, key, key_len);
2576 
2577 	/* Setup Authentication Parameters */
2578 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2579 	ut_params->auth_xform.next = NULL;
2580 
2581 	ut_params->auth_xform.auth.op = auth_op;
2582 	ut_params->auth_xform.auth.algo = auth_algo;
2583 	ut_params->auth_xform.auth.key.length = key_len;
2584 	/* Hash key = cipher key */
2585 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2586 	ut_params->auth_xform.auth.digest_length = auth_len;
2587 	/* Auth IV will be after cipher IV */
2588 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2589 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2590 
2591 	/* Setup Cipher Parameters */
2592 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2593 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2594 
2595 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2596 	ut_params->cipher_xform.cipher.op = cipher_op;
2597 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2598 	ut_params->cipher_xform.cipher.key.length = key_len;
2599 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2600 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2601 
2602 	debug_hexdump(stdout, "key:", key, key_len);
2603 
2604 	/* Create Crypto session*/
2605 	ut_params->sess = rte_cryptodev_sym_session_create(
2606 			ts_params->session_mpool);
2607 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2608 
2609 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2610 			&ut_params->cipher_xform,
2611 			ts_params->session_priv_mpool);
2612 	if (status == -ENOTSUP)
2613 		return TEST_SKIPPED;
2614 
2615 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2616 	return 0;
2617 }
2618 
2619 static int
2620 create_wireless_cipher_auth_session(uint8_t dev_id,
2621 		enum rte_crypto_cipher_operation cipher_op,
2622 		enum rte_crypto_auth_operation auth_op,
2623 		enum rte_crypto_auth_algorithm auth_algo,
2624 		enum rte_crypto_cipher_algorithm cipher_algo,
2625 		const struct wireless_test_data *tdata)
2626 {
2627 	const uint8_t key_len = tdata->key.len;
2628 	uint8_t cipher_auth_key[key_len];
2629 	int status;
2630 
2631 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2632 	struct crypto_unittest_params *ut_params = &unittest_params;
2633 	const uint8_t *key = tdata->key.data;
2634 	const uint8_t auth_len = tdata->digest.len;
2635 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2636 	uint8_t auth_iv_len = tdata->auth_iv.len;
2637 
2638 	memcpy(cipher_auth_key, key, key_len);
2639 
2640 	/* Setup Authentication Parameters */
2641 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2642 	ut_params->auth_xform.next = NULL;
2643 
2644 	ut_params->auth_xform.auth.op = auth_op;
2645 	ut_params->auth_xform.auth.algo = auth_algo;
2646 	ut_params->auth_xform.auth.key.length = key_len;
2647 	/* Hash key = cipher key */
2648 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2649 	ut_params->auth_xform.auth.digest_length = auth_len;
2650 	/* Auth IV will be after cipher IV */
2651 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2652 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2653 
2654 	/* Setup Cipher Parameters */
2655 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2656 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2657 
2658 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2659 	ut_params->cipher_xform.cipher.op = cipher_op;
2660 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2661 	ut_params->cipher_xform.cipher.key.length = key_len;
2662 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2663 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2664 
2665 
2666 	debug_hexdump(stdout, "key:", key, key_len);
2667 
2668 	/* Create Crypto session*/
2669 	ut_params->sess = rte_cryptodev_sym_session_create(
2670 			ts_params->session_mpool);
2671 
2672 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2673 			&ut_params->cipher_xform,
2674 			ts_params->session_priv_mpool);
2675 	if (status == -ENOTSUP)
2676 		return TEST_SKIPPED;
2677 
2678 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2679 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2680 	return 0;
2681 }
2682 
2683 static int
2684 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2685 		const struct wireless_test_data *tdata)
2686 {
2687 	return create_wireless_cipher_auth_session(dev_id,
2688 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2689 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2690 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2691 }
2692 
2693 static int
2694 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2695 		enum rte_crypto_cipher_operation cipher_op,
2696 		enum rte_crypto_auth_operation auth_op,
2697 		enum rte_crypto_auth_algorithm auth_algo,
2698 		enum rte_crypto_cipher_algorithm cipher_algo,
2699 		const uint8_t *key, const uint8_t key_len,
2700 		uint8_t auth_iv_len, uint8_t auth_len,
2701 		uint8_t cipher_iv_len)
2702 {
2703 	uint8_t auth_cipher_key[key_len];
2704 	int status;
2705 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2706 	struct crypto_unittest_params *ut_params = &unittest_params;
2707 
2708 	memcpy(auth_cipher_key, key, key_len);
2709 
2710 	/* Setup Authentication Parameters */
2711 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2712 	ut_params->auth_xform.auth.op = auth_op;
2713 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2714 	ut_params->auth_xform.auth.algo = auth_algo;
2715 	ut_params->auth_xform.auth.key.length = key_len;
2716 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2717 	ut_params->auth_xform.auth.digest_length = auth_len;
2718 	/* Auth IV will be after cipher IV */
2719 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2720 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2721 
2722 	/* Setup Cipher Parameters */
2723 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2724 	ut_params->cipher_xform.next = NULL;
2725 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2726 	ut_params->cipher_xform.cipher.op = cipher_op;
2727 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2728 	ut_params->cipher_xform.cipher.key.length = key_len;
2729 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2730 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2731 
2732 	debug_hexdump(stdout, "key:", key, key_len);
2733 
2734 	/* Create Crypto session*/
2735 	ut_params->sess = rte_cryptodev_sym_session_create(
2736 			ts_params->session_mpool);
2737 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2738 
2739 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2740 		ut_params->auth_xform.next = NULL;
2741 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2742 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2743 				&ut_params->cipher_xform,
2744 				ts_params->session_priv_mpool);
2745 
2746 	} else
2747 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2748 				&ut_params->auth_xform,
2749 				ts_params->session_priv_mpool);
2750 
2751 	if (status == -ENOTSUP)
2752 		return TEST_SKIPPED;
2753 
2754 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2755 
2756 	return 0;
2757 }
2758 
2759 static int
2760 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2761 		unsigned int auth_tag_len,
2762 		const uint8_t *iv, unsigned int iv_len,
2763 		unsigned int data_pad_len,
2764 		enum rte_crypto_auth_operation op,
2765 		unsigned int auth_len, unsigned int auth_offset)
2766 {
2767 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2768 
2769 	struct crypto_unittest_params *ut_params = &unittest_params;
2770 
2771 	/* Generate Crypto op data structure */
2772 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2773 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2774 	TEST_ASSERT_NOT_NULL(ut_params->op,
2775 		"Failed to allocate pktmbuf offload");
2776 
2777 	/* Set crypto operation data parameters */
2778 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2779 
2780 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2781 
2782 	/* set crypto operation source mbuf */
2783 	sym_op->m_src = ut_params->ibuf;
2784 
2785 	/* iv */
2786 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2787 			iv, iv_len);
2788 	/* digest */
2789 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2790 					ut_params->ibuf, auth_tag_len);
2791 
2792 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2793 				"no room to append auth tag");
2794 	ut_params->digest = sym_op->auth.digest.data;
2795 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2796 			ut_params->ibuf, data_pad_len);
2797 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2798 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2799 	else
2800 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2801 
2802 	debug_hexdump(stdout, "digest:",
2803 		sym_op->auth.digest.data,
2804 		auth_tag_len);
2805 
2806 	sym_op->auth.data.length = auth_len;
2807 	sym_op->auth.data.offset = auth_offset;
2808 
2809 	return 0;
2810 }
2811 
2812 static int
2813 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2814 	enum rte_crypto_auth_operation op)
2815 {
2816 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2817 	struct crypto_unittest_params *ut_params = &unittest_params;
2818 
2819 	const uint8_t *auth_tag = tdata->digest.data;
2820 	const unsigned int auth_tag_len = tdata->digest.len;
2821 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2822 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2823 
2824 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2825 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2826 	const uint8_t *auth_iv = tdata->auth_iv.data;
2827 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2828 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2829 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2830 
2831 	/* Generate Crypto op data structure */
2832 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2833 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2834 	TEST_ASSERT_NOT_NULL(ut_params->op,
2835 			"Failed to allocate pktmbuf offload");
2836 	/* Set crypto operation data parameters */
2837 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2838 
2839 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2840 
2841 	/* set crypto operation source mbuf */
2842 	sym_op->m_src = ut_params->ibuf;
2843 
2844 	/* digest */
2845 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2846 			ut_params->ibuf, auth_tag_len);
2847 
2848 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2849 			"no room to append auth tag");
2850 	ut_params->digest = sym_op->auth.digest.data;
2851 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2852 			ut_params->ibuf, data_pad_len);
2853 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2854 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2855 	else
2856 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2857 
2858 	debug_hexdump(stdout, "digest:",
2859 		sym_op->auth.digest.data,
2860 		auth_tag_len);
2861 
2862 	/* Copy cipher and auth IVs at the end of the crypto operation */
2863 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2864 						IV_OFFSET);
2865 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2866 	iv_ptr += cipher_iv_len;
2867 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2868 
2869 	sym_op->cipher.data.length = cipher_len;
2870 	sym_op->cipher.data.offset = 0;
2871 	sym_op->auth.data.length = auth_len;
2872 	sym_op->auth.data.offset = 0;
2873 
2874 	return 0;
2875 }
2876 
2877 static int
2878 create_zuc_cipher_hash_generate_operation(
2879 		const struct wireless_test_data *tdata)
2880 {
2881 	return create_wireless_cipher_hash_operation(tdata,
2882 		RTE_CRYPTO_AUTH_OP_GENERATE);
2883 }
2884 
2885 static int
2886 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2887 		const unsigned auth_tag_len,
2888 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2889 		unsigned data_pad_len,
2890 		enum rte_crypto_auth_operation op,
2891 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2892 		const unsigned cipher_len, const unsigned cipher_offset,
2893 		const unsigned auth_len, const unsigned auth_offset)
2894 {
2895 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2896 	struct crypto_unittest_params *ut_params = &unittest_params;
2897 
2898 	enum rte_crypto_cipher_algorithm cipher_algo =
2899 			ut_params->cipher_xform.cipher.algo;
2900 	enum rte_crypto_auth_algorithm auth_algo =
2901 			ut_params->auth_xform.auth.algo;
2902 
2903 	/* Generate Crypto op data structure */
2904 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2905 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2906 	TEST_ASSERT_NOT_NULL(ut_params->op,
2907 			"Failed to allocate pktmbuf offload");
2908 	/* Set crypto operation data parameters */
2909 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2910 
2911 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2912 
2913 	/* set crypto operation source mbuf */
2914 	sym_op->m_src = ut_params->ibuf;
2915 
2916 	/* digest */
2917 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2918 			ut_params->ibuf, auth_tag_len);
2919 
2920 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2921 			"no room to append auth tag");
2922 	ut_params->digest = sym_op->auth.digest.data;
2923 
2924 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2925 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2926 				ut_params->ibuf, data_pad_len);
2927 	} else {
2928 		struct rte_mbuf *m = ut_params->ibuf;
2929 		unsigned int offset = data_pad_len;
2930 
2931 		while (offset > m->data_len && m->next != NULL) {
2932 			offset -= m->data_len;
2933 			m = m->next;
2934 		}
2935 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2936 			m, offset);
2937 	}
2938 
2939 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2940 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2941 	else
2942 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2943 
2944 	debug_hexdump(stdout, "digest:",
2945 		sym_op->auth.digest.data,
2946 		auth_tag_len);
2947 
2948 	/* Copy cipher and auth IVs at the end of the crypto operation */
2949 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2950 						IV_OFFSET);
2951 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2952 	iv_ptr += cipher_iv_len;
2953 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2954 
2955 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2956 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2957 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2958 		sym_op->cipher.data.length = cipher_len;
2959 		sym_op->cipher.data.offset = cipher_offset;
2960 	} else {
2961 		sym_op->cipher.data.length = cipher_len >> 3;
2962 		sym_op->cipher.data.offset = cipher_offset >> 3;
2963 	}
2964 
2965 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2966 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2967 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2968 		sym_op->auth.data.length = auth_len;
2969 		sym_op->auth.data.offset = auth_offset;
2970 	} else {
2971 		sym_op->auth.data.length = auth_len >> 3;
2972 		sym_op->auth.data.offset = auth_offset >> 3;
2973 	}
2974 
2975 	return 0;
2976 }
2977 
2978 static int
2979 create_wireless_algo_auth_cipher_operation(
2980 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2981 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2982 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2983 		unsigned int data_pad_len,
2984 		unsigned int cipher_len, unsigned int cipher_offset,
2985 		unsigned int auth_len, unsigned int auth_offset,
2986 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2987 {
2988 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2989 	struct crypto_unittest_params *ut_params = &unittest_params;
2990 
2991 	enum rte_crypto_cipher_algorithm cipher_algo =
2992 			ut_params->cipher_xform.cipher.algo;
2993 	enum rte_crypto_auth_algorithm auth_algo =
2994 			ut_params->auth_xform.auth.algo;
2995 
2996 	/* Generate Crypto op data structure */
2997 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2998 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2999 	TEST_ASSERT_NOT_NULL(ut_params->op,
3000 			"Failed to allocate pktmbuf offload");
3001 
3002 	/* Set crypto operation data parameters */
3003 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3004 
3005 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3006 
3007 	/* set crypto operation mbufs */
3008 	sym_op->m_src = ut_params->ibuf;
3009 	if (op_mode == OUT_OF_PLACE)
3010 		sym_op->m_dst = ut_params->obuf;
3011 
3012 	/* digest */
3013 	if (!do_sgl) {
3014 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
3015 			(op_mode == IN_PLACE ?
3016 				ut_params->ibuf : ut_params->obuf),
3017 			uint8_t *, data_pad_len);
3018 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3019 			(op_mode == IN_PLACE ?
3020 				ut_params->ibuf : ut_params->obuf),
3021 			data_pad_len);
3022 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3023 	} else {
3024 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3025 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3026 				sym_op->m_src : sym_op->m_dst);
3027 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3028 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3029 			sgl_buf = sgl_buf->next;
3030 		}
3031 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3032 				uint8_t *, remaining_off);
3033 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3034 				remaining_off);
3035 		memset(sym_op->auth.digest.data, 0, remaining_off);
3036 		while (sgl_buf->next != NULL) {
3037 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3038 				0, rte_pktmbuf_data_len(sgl_buf));
3039 			sgl_buf = sgl_buf->next;
3040 		}
3041 	}
3042 
3043 	/* Copy digest for the verification */
3044 	if (verify)
3045 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3046 
3047 	/* Copy cipher and auth IVs at the end of the crypto operation */
3048 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3049 			ut_params->op, uint8_t *, IV_OFFSET);
3050 
3051 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3052 	iv_ptr += cipher_iv_len;
3053 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3054 
3055 	/* Only copy over the offset data needed from src to dst in OOP,
3056 	 * if the auth and cipher offsets are not aligned
3057 	 */
3058 	if (op_mode == OUT_OF_PLACE) {
3059 		if (cipher_offset > auth_offset)
3060 			rte_memcpy(
3061 				rte_pktmbuf_mtod_offset(
3062 					sym_op->m_dst,
3063 					uint8_t *, auth_offset >> 3),
3064 				rte_pktmbuf_mtod_offset(
3065 					sym_op->m_src,
3066 					uint8_t *, auth_offset >> 3),
3067 				((cipher_offset >> 3) - (auth_offset >> 3)));
3068 	}
3069 
3070 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3071 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3072 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3073 		sym_op->cipher.data.length = cipher_len;
3074 		sym_op->cipher.data.offset = cipher_offset;
3075 	} else {
3076 		sym_op->cipher.data.length = cipher_len >> 3;
3077 		sym_op->cipher.data.offset = cipher_offset >> 3;
3078 	}
3079 
3080 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3081 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3082 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3083 		sym_op->auth.data.length = auth_len;
3084 		sym_op->auth.data.offset = auth_offset;
3085 	} else {
3086 		sym_op->auth.data.length = auth_len >> 3;
3087 		sym_op->auth.data.offset = auth_offset >> 3;
3088 	}
3089 
3090 	return 0;
3091 }
3092 
3093 static int
3094 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3095 {
3096 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3097 	struct crypto_unittest_params *ut_params = &unittest_params;
3098 
3099 	int retval;
3100 	unsigned plaintext_pad_len;
3101 	unsigned plaintext_len;
3102 	uint8_t *plaintext;
3103 	struct rte_cryptodev_info dev_info;
3104 
3105 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3106 	uint64_t feat_flags = dev_info.feature_flags;
3107 
3108 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3109 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3110 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3111 		return TEST_SKIPPED;
3112 	}
3113 
3114 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3115 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3116 		printf("Device doesn't support RAW data-path APIs.\n");
3117 		return TEST_SKIPPED;
3118 	}
3119 
3120 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3121 		return TEST_SKIPPED;
3122 
3123 	/* Verify the capabilities */
3124 	struct rte_cryptodev_sym_capability_idx cap_idx;
3125 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3126 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3127 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3128 			&cap_idx) == NULL)
3129 		return TEST_SKIPPED;
3130 
3131 	/* Create SNOW 3G session */
3132 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3133 			tdata->key.data, tdata->key.len,
3134 			tdata->auth_iv.len, tdata->digest.len,
3135 			RTE_CRYPTO_AUTH_OP_GENERATE,
3136 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3137 	if (retval < 0)
3138 		return retval;
3139 
3140 	/* alloc mbuf and set payload */
3141 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3142 
3143 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3144 	rte_pktmbuf_tailroom(ut_params->ibuf));
3145 
3146 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3147 	/* Append data which is padded to a multiple of */
3148 	/* the algorithms block size */
3149 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3150 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3151 				plaintext_pad_len);
3152 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3153 
3154 	/* Create SNOW 3G operation */
3155 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3156 			tdata->auth_iv.data, tdata->auth_iv.len,
3157 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3158 			tdata->validAuthLenInBits.len,
3159 			0);
3160 	if (retval < 0)
3161 		return retval;
3162 
3163 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3164 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3165 				ut_params->op, 0, 1, 1, 0);
3166 	else
3167 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3168 				ut_params->op);
3169 	ut_params->obuf = ut_params->op->sym->m_src;
3170 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3171 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3172 			+ plaintext_pad_len;
3173 
3174 	/* Validate obuf */
3175 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3176 	ut_params->digest,
3177 	tdata->digest.data,
3178 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3179 	"SNOW 3G Generated auth tag not as expected");
3180 
3181 	return 0;
3182 }
3183 
3184 static int
3185 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3186 {
3187 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3188 	struct crypto_unittest_params *ut_params = &unittest_params;
3189 
3190 	int retval;
3191 	unsigned plaintext_pad_len;
3192 	unsigned plaintext_len;
3193 	uint8_t *plaintext;
3194 	struct rte_cryptodev_info dev_info;
3195 
3196 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3197 	uint64_t feat_flags = dev_info.feature_flags;
3198 
3199 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3200 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3201 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3202 		return TEST_SKIPPED;
3203 	}
3204 
3205 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3206 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3207 		printf("Device doesn't support RAW data-path APIs.\n");
3208 		return TEST_SKIPPED;
3209 	}
3210 
3211 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3212 		return TEST_SKIPPED;
3213 
3214 	/* Verify the capabilities */
3215 	struct rte_cryptodev_sym_capability_idx cap_idx;
3216 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3217 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3218 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3219 			&cap_idx) == NULL)
3220 		return TEST_SKIPPED;
3221 
3222 	/* Create SNOW 3G session */
3223 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3224 				tdata->key.data, tdata->key.len,
3225 				tdata->auth_iv.len, tdata->digest.len,
3226 				RTE_CRYPTO_AUTH_OP_VERIFY,
3227 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3228 	if (retval < 0)
3229 		return retval;
3230 	/* alloc mbuf and set payload */
3231 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3232 
3233 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3234 	rte_pktmbuf_tailroom(ut_params->ibuf));
3235 
3236 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3237 	/* Append data which is padded to a multiple of */
3238 	/* the algorithms block size */
3239 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3240 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3241 				plaintext_pad_len);
3242 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3243 
3244 	/* Create SNOW 3G operation */
3245 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3246 			tdata->digest.len,
3247 			tdata->auth_iv.data, tdata->auth_iv.len,
3248 			plaintext_pad_len,
3249 			RTE_CRYPTO_AUTH_OP_VERIFY,
3250 			tdata->validAuthLenInBits.len,
3251 			0);
3252 	if (retval < 0)
3253 		return retval;
3254 
3255 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3256 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3257 				ut_params->op, 0, 1, 1, 0);
3258 	else
3259 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3260 				ut_params->op);
3261 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3262 	ut_params->obuf = ut_params->op->sym->m_src;
3263 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3264 				+ plaintext_pad_len;
3265 
3266 	/* Validate obuf */
3267 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3268 		return 0;
3269 	else
3270 		return -1;
3271 
3272 	return 0;
3273 }
3274 
3275 static int
3276 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3277 {
3278 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3279 	struct crypto_unittest_params *ut_params = &unittest_params;
3280 
3281 	int retval;
3282 	unsigned plaintext_pad_len;
3283 	unsigned plaintext_len;
3284 	uint8_t *plaintext;
3285 	struct rte_cryptodev_info dev_info;
3286 
3287 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3288 	uint64_t feat_flags = dev_info.feature_flags;
3289 
3290 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3291 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3292 		printf("Device doesn't support RAW data-path APIs.\n");
3293 		return TEST_SKIPPED;
3294 	}
3295 
3296 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3297 		return TEST_SKIPPED;
3298 
3299 	/* Verify the capabilities */
3300 	struct rte_cryptodev_sym_capability_idx cap_idx;
3301 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3302 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3303 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3304 			&cap_idx) == NULL)
3305 		return TEST_SKIPPED;
3306 
3307 	/* Create KASUMI session */
3308 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3309 			tdata->key.data, tdata->key.len,
3310 			0, tdata->digest.len,
3311 			RTE_CRYPTO_AUTH_OP_GENERATE,
3312 			RTE_CRYPTO_AUTH_KASUMI_F9);
3313 	if (retval < 0)
3314 		return retval;
3315 
3316 	/* alloc mbuf and set payload */
3317 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3318 
3319 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3320 	rte_pktmbuf_tailroom(ut_params->ibuf));
3321 
3322 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3323 	/* Append data which is padded to a multiple of */
3324 	/* the algorithms block size */
3325 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3326 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3327 				plaintext_pad_len);
3328 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3329 
3330 	/* Create KASUMI operation */
3331 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3332 			NULL, 0,
3333 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3334 			tdata->plaintext.len,
3335 			0);
3336 	if (retval < 0)
3337 		return retval;
3338 
3339 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3340 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3341 			ut_params->op);
3342 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3343 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3344 				ut_params->op, 0, 1, 1, 0);
3345 	else
3346 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3347 			ut_params->op);
3348 
3349 	ut_params->obuf = ut_params->op->sym->m_src;
3350 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3351 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3352 			+ plaintext_pad_len;
3353 
3354 	/* Validate obuf */
3355 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3356 	ut_params->digest,
3357 	tdata->digest.data,
3358 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3359 	"KASUMI Generated auth tag not as expected");
3360 
3361 	return 0;
3362 }
3363 
3364 static int
3365 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3366 {
3367 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3368 	struct crypto_unittest_params *ut_params = &unittest_params;
3369 
3370 	int retval;
3371 	unsigned plaintext_pad_len;
3372 	unsigned plaintext_len;
3373 	uint8_t *plaintext;
3374 	struct rte_cryptodev_info dev_info;
3375 
3376 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3377 	uint64_t feat_flags = dev_info.feature_flags;
3378 
3379 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3380 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3381 		printf("Device doesn't support RAW data-path APIs.\n");
3382 		return TEST_SKIPPED;
3383 	}
3384 
3385 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3386 		return TEST_SKIPPED;
3387 
3388 	/* Verify the capabilities */
3389 	struct rte_cryptodev_sym_capability_idx cap_idx;
3390 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3391 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3392 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3393 			&cap_idx) == NULL)
3394 		return TEST_SKIPPED;
3395 
3396 	/* Create KASUMI session */
3397 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3398 				tdata->key.data, tdata->key.len,
3399 				0, tdata->digest.len,
3400 				RTE_CRYPTO_AUTH_OP_VERIFY,
3401 				RTE_CRYPTO_AUTH_KASUMI_F9);
3402 	if (retval < 0)
3403 		return retval;
3404 	/* alloc mbuf and set payload */
3405 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3406 
3407 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3408 	rte_pktmbuf_tailroom(ut_params->ibuf));
3409 
3410 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3411 	/* Append data which is padded to a multiple */
3412 	/* of the algorithms block size */
3413 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3414 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3415 				plaintext_pad_len);
3416 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3417 
3418 	/* Create KASUMI operation */
3419 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3420 			tdata->digest.len,
3421 			NULL, 0,
3422 			plaintext_pad_len,
3423 			RTE_CRYPTO_AUTH_OP_VERIFY,
3424 			tdata->plaintext.len,
3425 			0);
3426 	if (retval < 0)
3427 		return retval;
3428 
3429 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3430 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3431 				ut_params->op, 0, 1, 1, 0);
3432 	else
3433 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3434 				ut_params->op);
3435 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3436 	ut_params->obuf = ut_params->op->sym->m_src;
3437 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3438 				+ plaintext_pad_len;
3439 
3440 	/* Validate obuf */
3441 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3442 		return 0;
3443 	else
3444 		return -1;
3445 
3446 	return 0;
3447 }
3448 
3449 static int
3450 test_snow3g_hash_generate_test_case_1(void)
3451 {
3452 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3453 }
3454 
3455 static int
3456 test_snow3g_hash_generate_test_case_2(void)
3457 {
3458 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3459 }
3460 
3461 static int
3462 test_snow3g_hash_generate_test_case_3(void)
3463 {
3464 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3465 }
3466 
3467 static int
3468 test_snow3g_hash_generate_test_case_4(void)
3469 {
3470 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3471 }
3472 
3473 static int
3474 test_snow3g_hash_generate_test_case_5(void)
3475 {
3476 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3477 }
3478 
3479 static int
3480 test_snow3g_hash_generate_test_case_6(void)
3481 {
3482 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3483 }
3484 
3485 static int
3486 test_snow3g_hash_verify_test_case_1(void)
3487 {
3488 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3489 
3490 }
3491 
3492 static int
3493 test_snow3g_hash_verify_test_case_2(void)
3494 {
3495 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3496 }
3497 
3498 static int
3499 test_snow3g_hash_verify_test_case_3(void)
3500 {
3501 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3502 }
3503 
3504 static int
3505 test_snow3g_hash_verify_test_case_4(void)
3506 {
3507 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3508 }
3509 
3510 static int
3511 test_snow3g_hash_verify_test_case_5(void)
3512 {
3513 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3514 }
3515 
3516 static int
3517 test_snow3g_hash_verify_test_case_6(void)
3518 {
3519 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3520 }
3521 
3522 static int
3523 test_kasumi_hash_generate_test_case_1(void)
3524 {
3525 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3526 }
3527 
3528 static int
3529 test_kasumi_hash_generate_test_case_2(void)
3530 {
3531 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3532 }
3533 
3534 static int
3535 test_kasumi_hash_generate_test_case_3(void)
3536 {
3537 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3538 }
3539 
3540 static int
3541 test_kasumi_hash_generate_test_case_4(void)
3542 {
3543 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3544 }
3545 
3546 static int
3547 test_kasumi_hash_generate_test_case_5(void)
3548 {
3549 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3550 }
3551 
3552 static int
3553 test_kasumi_hash_generate_test_case_6(void)
3554 {
3555 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3556 }
3557 
3558 static int
3559 test_kasumi_hash_verify_test_case_1(void)
3560 {
3561 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3562 }
3563 
3564 static int
3565 test_kasumi_hash_verify_test_case_2(void)
3566 {
3567 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3568 }
3569 
3570 static int
3571 test_kasumi_hash_verify_test_case_3(void)
3572 {
3573 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3574 }
3575 
3576 static int
3577 test_kasumi_hash_verify_test_case_4(void)
3578 {
3579 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3580 }
3581 
3582 static int
3583 test_kasumi_hash_verify_test_case_5(void)
3584 {
3585 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3586 }
3587 
3588 static int
3589 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3590 {
3591 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3592 	struct crypto_unittest_params *ut_params = &unittest_params;
3593 
3594 	int retval;
3595 	uint8_t *plaintext, *ciphertext;
3596 	unsigned plaintext_pad_len;
3597 	unsigned plaintext_len;
3598 	struct rte_cryptodev_info dev_info;
3599 
3600 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3601 	uint64_t feat_flags = dev_info.feature_flags;
3602 
3603 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3604 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3605 		printf("Device doesn't support RAW data-path APIs.\n");
3606 		return TEST_SKIPPED;
3607 	}
3608 
3609 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3610 		return TEST_SKIPPED;
3611 
3612 	/* Verify the capabilities */
3613 	struct rte_cryptodev_sym_capability_idx cap_idx;
3614 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3615 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3616 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3617 			&cap_idx) == NULL)
3618 		return TEST_SKIPPED;
3619 
3620 	/* Create KASUMI session */
3621 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3622 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3623 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3624 					tdata->key.data, tdata->key.len,
3625 					tdata->cipher_iv.len);
3626 	if (retval < 0)
3627 		return retval;
3628 
3629 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3630 
3631 	/* Clear mbuf payload */
3632 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3633 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3634 
3635 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3636 	/* Append data which is padded to a multiple */
3637 	/* of the algorithms block size */
3638 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3639 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3640 				plaintext_pad_len);
3641 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3642 
3643 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3644 
3645 	/* Create KASUMI operation */
3646 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3647 				tdata->cipher_iv.len,
3648 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3649 				tdata->validCipherOffsetInBits.len);
3650 	if (retval < 0)
3651 		return retval;
3652 
3653 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3654 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3655 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3656 	else
3657 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3658 				ut_params->op);
3659 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3660 
3661 	ut_params->obuf = ut_params->op->sym->m_dst;
3662 	if (ut_params->obuf)
3663 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3664 	else
3665 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3666 
3667 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3668 
3669 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3670 				(tdata->validCipherOffsetInBits.len >> 3);
3671 	/* Validate obuf */
3672 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3673 		ciphertext,
3674 		reference_ciphertext,
3675 		tdata->validCipherLenInBits.len,
3676 		"KASUMI Ciphertext data not as expected");
3677 	return 0;
3678 }
3679 
3680 static int
3681 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3682 {
3683 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3684 	struct crypto_unittest_params *ut_params = &unittest_params;
3685 
3686 	int retval;
3687 
3688 	unsigned int plaintext_pad_len;
3689 	unsigned int plaintext_len;
3690 
3691 	uint8_t buffer[10000];
3692 	const uint8_t *ciphertext;
3693 
3694 	struct rte_cryptodev_info dev_info;
3695 
3696 	/* Verify the capabilities */
3697 	struct rte_cryptodev_sym_capability_idx cap_idx;
3698 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3699 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3700 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3701 			&cap_idx) == NULL)
3702 		return TEST_SKIPPED;
3703 
3704 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3705 
3706 	uint64_t feat_flags = dev_info.feature_flags;
3707 
3708 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3709 		printf("Device doesn't support in-place scatter-gather. "
3710 				"Test Skipped.\n");
3711 		return TEST_SKIPPED;
3712 	}
3713 
3714 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3715 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3716 		printf("Device doesn't support RAW data-path APIs.\n");
3717 		return TEST_SKIPPED;
3718 	}
3719 
3720 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3721 		return TEST_SKIPPED;
3722 
3723 	/* Create KASUMI session */
3724 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3725 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3726 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3727 					tdata->key.data, tdata->key.len,
3728 					tdata->cipher_iv.len);
3729 	if (retval < 0)
3730 		return retval;
3731 
3732 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3733 
3734 
3735 	/* Append data which is padded to a multiple */
3736 	/* of the algorithms block size */
3737 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3738 
3739 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3740 			plaintext_pad_len, 10, 0);
3741 
3742 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3743 
3744 	/* Create KASUMI operation */
3745 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3746 				tdata->cipher_iv.len,
3747 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3748 				tdata->validCipherOffsetInBits.len);
3749 	if (retval < 0)
3750 		return retval;
3751 
3752 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3753 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3754 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3755 	else
3756 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3757 						ut_params->op);
3758 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3759 
3760 	ut_params->obuf = ut_params->op->sym->m_dst;
3761 
3762 	if (ut_params->obuf)
3763 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3764 				plaintext_len, buffer);
3765 	else
3766 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3767 				tdata->validCipherOffsetInBits.len >> 3,
3768 				plaintext_len, buffer);
3769 
3770 	/* Validate obuf */
3771 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3772 
3773 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3774 				(tdata->validCipherOffsetInBits.len >> 3);
3775 	/* Validate obuf */
3776 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3777 		ciphertext,
3778 		reference_ciphertext,
3779 		tdata->validCipherLenInBits.len,
3780 		"KASUMI Ciphertext data not as expected");
3781 	return 0;
3782 }
3783 
3784 static int
3785 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3786 {
3787 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3788 	struct crypto_unittest_params *ut_params = &unittest_params;
3789 
3790 	int retval;
3791 	uint8_t *plaintext, *ciphertext;
3792 	unsigned plaintext_pad_len;
3793 	unsigned plaintext_len;
3794 
3795 	/* Verify the capabilities */
3796 	struct rte_cryptodev_sym_capability_idx cap_idx;
3797 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3798 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3799 	/* Data-path service does not support OOP */
3800 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3801 			&cap_idx) == NULL)
3802 		return TEST_SKIPPED;
3803 
3804 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3805 		return TEST_SKIPPED;
3806 
3807 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3808 		return TEST_SKIPPED;
3809 
3810 	/* Create KASUMI session */
3811 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3812 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3813 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3814 					tdata->key.data, tdata->key.len,
3815 					tdata->cipher_iv.len);
3816 	if (retval < 0)
3817 		return retval;
3818 
3819 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3820 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3821 
3822 	/* Clear mbuf payload */
3823 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3824 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3825 
3826 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3827 	/* Append data which is padded to a multiple */
3828 	/* of the algorithms block size */
3829 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3830 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3831 				plaintext_pad_len);
3832 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3833 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3834 
3835 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3836 
3837 	/* Create KASUMI operation */
3838 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3839 				tdata->cipher_iv.len,
3840 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3841 				tdata->validCipherOffsetInBits.len);
3842 	if (retval < 0)
3843 		return retval;
3844 
3845 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3846 						ut_params->op);
3847 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3848 
3849 	ut_params->obuf = ut_params->op->sym->m_dst;
3850 	if (ut_params->obuf)
3851 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3852 	else
3853 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3854 
3855 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3856 
3857 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3858 				(tdata->validCipherOffsetInBits.len >> 3);
3859 	/* Validate obuf */
3860 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3861 		ciphertext,
3862 		reference_ciphertext,
3863 		tdata->validCipherLenInBits.len,
3864 		"KASUMI Ciphertext data not as expected");
3865 	return 0;
3866 }
3867 
3868 static int
3869 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3870 {
3871 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3872 	struct crypto_unittest_params *ut_params = &unittest_params;
3873 
3874 	int retval;
3875 	unsigned int plaintext_pad_len;
3876 	unsigned int plaintext_len;
3877 
3878 	const uint8_t *ciphertext;
3879 	uint8_t buffer[2048];
3880 
3881 	struct rte_cryptodev_info dev_info;
3882 
3883 	/* Verify the capabilities */
3884 	struct rte_cryptodev_sym_capability_idx cap_idx;
3885 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3886 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3887 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3888 			&cap_idx) == NULL)
3889 		return TEST_SKIPPED;
3890 
3891 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3892 		return TEST_SKIPPED;
3893 
3894 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3895 		return TEST_SKIPPED;
3896 
3897 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3898 
3899 	uint64_t feat_flags = dev_info.feature_flags;
3900 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3901 		printf("Device doesn't support out-of-place scatter-gather "
3902 				"in both input and output mbufs. "
3903 				"Test Skipped.\n");
3904 		return TEST_SKIPPED;
3905 	}
3906 
3907 	/* Create KASUMI session */
3908 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3909 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3910 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3911 					tdata->key.data, tdata->key.len,
3912 					tdata->cipher_iv.len);
3913 	if (retval < 0)
3914 		return retval;
3915 
3916 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3917 	/* Append data which is padded to a multiple */
3918 	/* of the algorithms block size */
3919 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3920 
3921 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3922 			plaintext_pad_len, 10, 0);
3923 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3924 			plaintext_pad_len, 3, 0);
3925 
3926 	/* Append data which is padded to a multiple */
3927 	/* of the algorithms block size */
3928 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3929 
3930 	/* Create KASUMI operation */
3931 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3932 				tdata->cipher_iv.len,
3933 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3934 				tdata->validCipherOffsetInBits.len);
3935 	if (retval < 0)
3936 		return retval;
3937 
3938 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3939 						ut_params->op);
3940 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3941 
3942 	ut_params->obuf = ut_params->op->sym->m_dst;
3943 	if (ut_params->obuf)
3944 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3945 				plaintext_pad_len, buffer);
3946 	else
3947 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3948 				tdata->validCipherOffsetInBits.len >> 3,
3949 				plaintext_pad_len, buffer);
3950 
3951 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3952 				(tdata->validCipherOffsetInBits.len >> 3);
3953 	/* Validate obuf */
3954 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3955 		ciphertext,
3956 		reference_ciphertext,
3957 		tdata->validCipherLenInBits.len,
3958 		"KASUMI Ciphertext data not as expected");
3959 	return 0;
3960 }
3961 
3962 
3963 static int
3964 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3965 {
3966 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3967 	struct crypto_unittest_params *ut_params = &unittest_params;
3968 
3969 	int retval;
3970 	uint8_t *ciphertext, *plaintext;
3971 	unsigned ciphertext_pad_len;
3972 	unsigned ciphertext_len;
3973 
3974 	/* Verify the capabilities */
3975 	struct rte_cryptodev_sym_capability_idx cap_idx;
3976 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3977 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3978 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3979 			&cap_idx) == NULL)
3980 		return TEST_SKIPPED;
3981 
3982 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3983 		return TEST_SKIPPED;
3984 
3985 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3986 		return TEST_SKIPPED;
3987 
3988 	/* Create KASUMI session */
3989 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3990 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3991 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3992 					tdata->key.data, tdata->key.len,
3993 					tdata->cipher_iv.len);
3994 	if (retval < 0)
3995 		return retval;
3996 
3997 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3998 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3999 
4000 	/* Clear mbuf payload */
4001 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4002 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4003 
4004 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4005 	/* Append data which is padded to a multiple */
4006 	/* of the algorithms block size */
4007 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4008 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4009 				ciphertext_pad_len);
4010 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4011 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4012 
4013 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4014 
4015 	/* Create KASUMI operation */
4016 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4017 				tdata->cipher_iv.len,
4018 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4019 				tdata->validCipherOffsetInBits.len);
4020 	if (retval < 0)
4021 		return retval;
4022 
4023 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4024 						ut_params->op);
4025 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4026 
4027 	ut_params->obuf = ut_params->op->sym->m_dst;
4028 	if (ut_params->obuf)
4029 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4030 	else
4031 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4032 
4033 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4034 
4035 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4036 				(tdata->validCipherOffsetInBits.len >> 3);
4037 	/* Validate obuf */
4038 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4039 		plaintext,
4040 		reference_plaintext,
4041 		tdata->validCipherLenInBits.len,
4042 		"KASUMI Plaintext data not as expected");
4043 	return 0;
4044 }
4045 
4046 static int
4047 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4048 {
4049 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4050 	struct crypto_unittest_params *ut_params = &unittest_params;
4051 
4052 	int retval;
4053 	uint8_t *ciphertext, *plaintext;
4054 	unsigned ciphertext_pad_len;
4055 	unsigned ciphertext_len;
4056 	struct rte_cryptodev_info dev_info;
4057 
4058 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4059 	uint64_t feat_flags = dev_info.feature_flags;
4060 
4061 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4062 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4063 		printf("Device doesn't support RAW data-path APIs.\n");
4064 		return TEST_SKIPPED;
4065 	}
4066 
4067 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4068 		return TEST_SKIPPED;
4069 
4070 	/* Verify the capabilities */
4071 	struct rte_cryptodev_sym_capability_idx cap_idx;
4072 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4073 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4074 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4075 			&cap_idx) == NULL)
4076 		return TEST_SKIPPED;
4077 
4078 	/* Create KASUMI session */
4079 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4080 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4081 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4082 					tdata->key.data, tdata->key.len,
4083 					tdata->cipher_iv.len);
4084 	if (retval < 0)
4085 		return retval;
4086 
4087 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4088 
4089 	/* Clear mbuf payload */
4090 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4091 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4092 
4093 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4094 	/* Append data which is padded to a multiple */
4095 	/* of the algorithms block size */
4096 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4097 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4098 				ciphertext_pad_len);
4099 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4100 
4101 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4102 
4103 	/* Create KASUMI operation */
4104 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4105 					tdata->cipher_iv.len,
4106 					tdata->ciphertext.len,
4107 					tdata->validCipherOffsetInBits.len);
4108 	if (retval < 0)
4109 		return retval;
4110 
4111 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4112 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4113 				ut_params->op, 1, 0, 1, 0);
4114 	else
4115 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4116 						ut_params->op);
4117 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4118 
4119 	ut_params->obuf = ut_params->op->sym->m_dst;
4120 	if (ut_params->obuf)
4121 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4122 	else
4123 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4124 
4125 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4126 
4127 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4128 				(tdata->validCipherOffsetInBits.len >> 3);
4129 	/* Validate obuf */
4130 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4131 		plaintext,
4132 		reference_plaintext,
4133 		tdata->validCipherLenInBits.len,
4134 		"KASUMI Plaintext data not as expected");
4135 	return 0;
4136 }
4137 
4138 static int
4139 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4140 {
4141 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4142 	struct crypto_unittest_params *ut_params = &unittest_params;
4143 
4144 	int retval;
4145 	uint8_t *plaintext, *ciphertext;
4146 	unsigned plaintext_pad_len;
4147 	unsigned plaintext_len;
4148 	struct rte_cryptodev_info dev_info;
4149 
4150 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4151 	uint64_t feat_flags = dev_info.feature_flags;
4152 
4153 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4154 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4155 		printf("Device doesn't support RAW data-path APIs.\n");
4156 		return TEST_SKIPPED;
4157 	}
4158 
4159 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4160 		return TEST_SKIPPED;
4161 
4162 	/* Verify the capabilities */
4163 	struct rte_cryptodev_sym_capability_idx cap_idx;
4164 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4165 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4166 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4167 			&cap_idx) == NULL)
4168 		return TEST_SKIPPED;
4169 
4170 	/* Create SNOW 3G session */
4171 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4172 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4173 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4174 					tdata->key.data, tdata->key.len,
4175 					tdata->cipher_iv.len);
4176 	if (retval < 0)
4177 		return retval;
4178 
4179 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4180 
4181 	/* Clear mbuf payload */
4182 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4183 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4184 
4185 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4186 	/* Append data which is padded to a multiple of */
4187 	/* the algorithms block size */
4188 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4189 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4190 				plaintext_pad_len);
4191 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4192 
4193 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4194 
4195 	/* Create SNOW 3G operation */
4196 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4197 					tdata->cipher_iv.len,
4198 					tdata->validCipherLenInBits.len,
4199 					0);
4200 	if (retval < 0)
4201 		return retval;
4202 
4203 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4204 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4205 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4206 	else
4207 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4208 						ut_params->op);
4209 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4210 
4211 	ut_params->obuf = ut_params->op->sym->m_dst;
4212 	if (ut_params->obuf)
4213 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4214 	else
4215 		ciphertext = plaintext;
4216 
4217 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4218 
4219 	/* Validate obuf */
4220 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4221 		ciphertext,
4222 		tdata->ciphertext.data,
4223 		tdata->validDataLenInBits.len,
4224 		"SNOW 3G Ciphertext data not as expected");
4225 	return 0;
4226 }
4227 
4228 
4229 static int
4230 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4231 {
4232 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4233 	struct crypto_unittest_params *ut_params = &unittest_params;
4234 	uint8_t *plaintext, *ciphertext;
4235 
4236 	int retval;
4237 	unsigned plaintext_pad_len;
4238 	unsigned plaintext_len;
4239 	struct rte_cryptodev_info dev_info;
4240 
4241 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4242 	uint64_t feat_flags = dev_info.feature_flags;
4243 
4244 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4245 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4246 		printf("Device does not support RAW data-path APIs.\n");
4247 		return -ENOTSUP;
4248 	}
4249 
4250 	/* Verify the capabilities */
4251 	struct rte_cryptodev_sym_capability_idx cap_idx;
4252 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4253 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4254 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4255 			&cap_idx) == NULL)
4256 		return TEST_SKIPPED;
4257 
4258 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4259 		return TEST_SKIPPED;
4260 
4261 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4262 		return TEST_SKIPPED;
4263 
4264 	/* Create SNOW 3G session */
4265 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4266 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4267 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4268 					tdata->key.data, tdata->key.len,
4269 					tdata->cipher_iv.len);
4270 	if (retval < 0)
4271 		return retval;
4272 
4273 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4274 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4275 
4276 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4277 			"Failed to allocate input buffer in mempool");
4278 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4279 			"Failed to allocate output buffer in mempool");
4280 
4281 	/* Clear mbuf payload */
4282 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4283 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4284 
4285 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4286 	/* Append data which is padded to a multiple of */
4287 	/* the algorithms block size */
4288 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4289 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4290 				plaintext_pad_len);
4291 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4292 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4293 
4294 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4295 
4296 	/* Create SNOW 3G operation */
4297 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4298 					tdata->cipher_iv.len,
4299 					tdata->validCipherLenInBits.len,
4300 					0);
4301 	if (retval < 0)
4302 		return retval;
4303 
4304 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4305 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4306 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4307 	else
4308 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4309 						ut_params->op);
4310 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4311 
4312 	ut_params->obuf = ut_params->op->sym->m_dst;
4313 	if (ut_params->obuf)
4314 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4315 	else
4316 		ciphertext = plaintext;
4317 
4318 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4319 
4320 	/* Validate obuf */
4321 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4322 		ciphertext,
4323 		tdata->ciphertext.data,
4324 		tdata->validDataLenInBits.len,
4325 		"SNOW 3G Ciphertext data not as expected");
4326 	return 0;
4327 }
4328 
4329 static int
4330 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4331 {
4332 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4333 	struct crypto_unittest_params *ut_params = &unittest_params;
4334 
4335 	int retval;
4336 	unsigned int plaintext_pad_len;
4337 	unsigned int plaintext_len;
4338 	uint8_t buffer[10000];
4339 	const uint8_t *ciphertext;
4340 
4341 	struct rte_cryptodev_info dev_info;
4342 
4343 	/* Verify the capabilities */
4344 	struct rte_cryptodev_sym_capability_idx cap_idx;
4345 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4346 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4347 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4348 			&cap_idx) == NULL)
4349 		return TEST_SKIPPED;
4350 
4351 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4352 		return TEST_SKIPPED;
4353 
4354 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4355 		return TEST_SKIPPED;
4356 
4357 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4358 
4359 	uint64_t feat_flags = dev_info.feature_flags;
4360 
4361 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4362 		printf("Device doesn't support out-of-place scatter-gather "
4363 				"in both input and output mbufs. "
4364 				"Test Skipped.\n");
4365 		return TEST_SKIPPED;
4366 	}
4367 
4368 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4369 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4370 		printf("Device does not support RAW data-path APIs.\n");
4371 		return -ENOTSUP;
4372 	}
4373 
4374 	/* Create SNOW 3G session */
4375 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4376 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4377 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4378 					tdata->key.data, tdata->key.len,
4379 					tdata->cipher_iv.len);
4380 	if (retval < 0)
4381 		return retval;
4382 
4383 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4384 	/* Append data which is padded to a multiple of */
4385 	/* the algorithms block size */
4386 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4387 
4388 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4389 			plaintext_pad_len, 10, 0);
4390 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4391 			plaintext_pad_len, 3, 0);
4392 
4393 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4394 			"Failed to allocate input buffer in mempool");
4395 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4396 			"Failed to allocate output buffer in mempool");
4397 
4398 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4399 
4400 	/* Create SNOW 3G operation */
4401 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4402 					tdata->cipher_iv.len,
4403 					tdata->validCipherLenInBits.len,
4404 					0);
4405 	if (retval < 0)
4406 		return retval;
4407 
4408 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4409 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4410 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4411 	else
4412 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4413 						ut_params->op);
4414 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4415 
4416 	ut_params->obuf = ut_params->op->sym->m_dst;
4417 	if (ut_params->obuf)
4418 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4419 				plaintext_len, buffer);
4420 	else
4421 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4422 				plaintext_len, buffer);
4423 
4424 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4425 
4426 	/* Validate obuf */
4427 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4428 		ciphertext,
4429 		tdata->ciphertext.data,
4430 		tdata->validDataLenInBits.len,
4431 		"SNOW 3G Ciphertext data not as expected");
4432 
4433 	return 0;
4434 }
4435 
4436 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4437 static void
4438 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4439 {
4440 	uint8_t curr_byte, prev_byte;
4441 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4442 	uint8_t lower_byte_mask = (1 << offset) - 1;
4443 	unsigned i;
4444 
4445 	prev_byte = buffer[0];
4446 	buffer[0] >>= offset;
4447 
4448 	for (i = 1; i < length_in_bytes; i++) {
4449 		curr_byte = buffer[i];
4450 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4451 				(curr_byte >> offset);
4452 		prev_byte = curr_byte;
4453 	}
4454 }
4455 
4456 static int
4457 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4458 {
4459 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4460 	struct crypto_unittest_params *ut_params = &unittest_params;
4461 	uint8_t *plaintext, *ciphertext;
4462 	int retval;
4463 	uint32_t plaintext_len;
4464 	uint32_t plaintext_pad_len;
4465 	uint8_t extra_offset = 4;
4466 	uint8_t *expected_ciphertext_shifted;
4467 	struct rte_cryptodev_info dev_info;
4468 
4469 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4470 	uint64_t feat_flags = dev_info.feature_flags;
4471 
4472 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4473 			((tdata->validDataLenInBits.len % 8) != 0)) {
4474 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4475 		return TEST_SKIPPED;
4476 	}
4477 
4478 	/* Verify the capabilities */
4479 	struct rte_cryptodev_sym_capability_idx cap_idx;
4480 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4481 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4482 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4483 			&cap_idx) == NULL)
4484 		return TEST_SKIPPED;
4485 
4486 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4487 		return TEST_SKIPPED;
4488 
4489 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4490 		return TEST_SKIPPED;
4491 
4492 	/* Create SNOW 3G session */
4493 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4494 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4495 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4496 					tdata->key.data, tdata->key.len,
4497 					tdata->cipher_iv.len);
4498 	if (retval < 0)
4499 		return retval;
4500 
4501 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4502 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4503 
4504 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4505 			"Failed to allocate input buffer in mempool");
4506 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4507 			"Failed to allocate output buffer in mempool");
4508 
4509 	/* Clear mbuf payload */
4510 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4511 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4512 
4513 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4514 	/*
4515 	 * Append data which is padded to a
4516 	 * multiple of the algorithms block size
4517 	 */
4518 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4519 
4520 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4521 						plaintext_pad_len);
4522 
4523 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4524 
4525 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4526 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4527 
4528 #ifdef RTE_APP_TEST_DEBUG
4529 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4530 #endif
4531 	/* Create SNOW 3G operation */
4532 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4533 					tdata->cipher_iv.len,
4534 					tdata->validCipherLenInBits.len,
4535 					extra_offset);
4536 	if (retval < 0)
4537 		return retval;
4538 
4539 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4540 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4541 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4542 	else
4543 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4544 						ut_params->op);
4545 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4546 
4547 	ut_params->obuf = ut_params->op->sym->m_dst;
4548 	if (ut_params->obuf)
4549 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4550 	else
4551 		ciphertext = plaintext;
4552 
4553 #ifdef RTE_APP_TEST_DEBUG
4554 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4555 #endif
4556 
4557 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4558 
4559 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4560 			"failed to reserve memory for ciphertext shifted\n");
4561 
4562 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4563 			ceil_byte_length(tdata->ciphertext.len));
4564 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4565 			extra_offset);
4566 	/* Validate obuf */
4567 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4568 		ciphertext,
4569 		expected_ciphertext_shifted,
4570 		tdata->validDataLenInBits.len,
4571 		extra_offset,
4572 		"SNOW 3G Ciphertext data not as expected");
4573 	return 0;
4574 }
4575 
4576 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4577 {
4578 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4579 	struct crypto_unittest_params *ut_params = &unittest_params;
4580 
4581 	int retval;
4582 
4583 	uint8_t *plaintext, *ciphertext;
4584 	unsigned ciphertext_pad_len;
4585 	unsigned ciphertext_len;
4586 	struct rte_cryptodev_info dev_info;
4587 
4588 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4589 	uint64_t feat_flags = dev_info.feature_flags;
4590 
4591 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4592 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4593 		printf("Device doesn't support RAW data-path APIs.\n");
4594 		return TEST_SKIPPED;
4595 	}
4596 
4597 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4598 		return TEST_SKIPPED;
4599 
4600 	/* Verify the capabilities */
4601 	struct rte_cryptodev_sym_capability_idx cap_idx;
4602 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4603 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4604 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4605 			&cap_idx) == NULL)
4606 		return TEST_SKIPPED;
4607 
4608 	/* Create SNOW 3G session */
4609 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4610 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4611 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4612 					tdata->key.data, tdata->key.len,
4613 					tdata->cipher_iv.len);
4614 	if (retval < 0)
4615 		return retval;
4616 
4617 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4618 
4619 	/* Clear mbuf payload */
4620 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4621 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4622 
4623 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4624 	/* Append data which is padded to a multiple of */
4625 	/* the algorithms block size */
4626 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4627 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4628 				ciphertext_pad_len);
4629 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4630 
4631 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4632 
4633 	/* Create SNOW 3G operation */
4634 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4635 					tdata->cipher_iv.len,
4636 					tdata->validCipherLenInBits.len,
4637 					tdata->cipher.offset_bits);
4638 	if (retval < 0)
4639 		return retval;
4640 
4641 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4642 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4643 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4644 	else
4645 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4646 						ut_params->op);
4647 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4648 	ut_params->obuf = ut_params->op->sym->m_dst;
4649 	if (ut_params->obuf)
4650 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4651 	else
4652 		plaintext = ciphertext;
4653 
4654 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4655 
4656 	/* Validate obuf */
4657 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4658 				tdata->plaintext.data,
4659 				tdata->validDataLenInBits.len,
4660 				"SNOW 3G Plaintext data not as expected");
4661 	return 0;
4662 }
4663 
4664 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4665 {
4666 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4667 	struct crypto_unittest_params *ut_params = &unittest_params;
4668 
4669 	int retval;
4670 
4671 	uint8_t *plaintext, *ciphertext;
4672 	unsigned ciphertext_pad_len;
4673 	unsigned ciphertext_len;
4674 	struct rte_cryptodev_info dev_info;
4675 
4676 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4677 	uint64_t feat_flags = dev_info.feature_flags;
4678 
4679 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4680 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4681 		printf("Device does not support RAW data-path APIs.\n");
4682 		return -ENOTSUP;
4683 	}
4684 	/* Verify the capabilities */
4685 	struct rte_cryptodev_sym_capability_idx cap_idx;
4686 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4687 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4688 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4689 			&cap_idx) == NULL)
4690 		return TEST_SKIPPED;
4691 
4692 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4693 		return TEST_SKIPPED;
4694 
4695 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4696 		return TEST_SKIPPED;
4697 
4698 	/* Create SNOW 3G session */
4699 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4700 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4701 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4702 					tdata->key.data, tdata->key.len,
4703 					tdata->cipher_iv.len);
4704 	if (retval < 0)
4705 		return retval;
4706 
4707 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4708 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4709 
4710 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4711 			"Failed to allocate input buffer");
4712 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4713 			"Failed to allocate output buffer");
4714 
4715 	/* Clear mbuf payload */
4716 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4717 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4718 
4719 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4720 		       rte_pktmbuf_tailroom(ut_params->obuf));
4721 
4722 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4723 	/* Append data which is padded to a multiple of */
4724 	/* the algorithms block size */
4725 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4726 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4727 				ciphertext_pad_len);
4728 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4729 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4730 
4731 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4732 
4733 	/* Create SNOW 3G operation */
4734 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4735 					tdata->cipher_iv.len,
4736 					tdata->validCipherLenInBits.len,
4737 					0);
4738 	if (retval < 0)
4739 		return retval;
4740 
4741 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4742 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4743 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4744 	else
4745 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4746 						ut_params->op);
4747 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4748 	ut_params->obuf = ut_params->op->sym->m_dst;
4749 	if (ut_params->obuf)
4750 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4751 	else
4752 		plaintext = ciphertext;
4753 
4754 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4755 
4756 	/* Validate obuf */
4757 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4758 				tdata->plaintext.data,
4759 				tdata->validDataLenInBits.len,
4760 				"SNOW 3G Plaintext data not as expected");
4761 	return 0;
4762 }
4763 
4764 static int
4765 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4766 {
4767 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4768 	struct crypto_unittest_params *ut_params = &unittest_params;
4769 
4770 	int retval;
4771 
4772 	uint8_t *plaintext, *ciphertext;
4773 	unsigned int plaintext_pad_len;
4774 	unsigned int plaintext_len;
4775 
4776 	struct rte_cryptodev_info dev_info;
4777 	struct rte_cryptodev_sym_capability_idx cap_idx;
4778 
4779 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4780 	uint64_t feat_flags = dev_info.feature_flags;
4781 
4782 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4783 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4784 			(tdata->validDataLenInBits.len % 8 != 0))) {
4785 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4786 		return TEST_SKIPPED;
4787 	}
4788 
4789 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4790 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4791 		printf("Device doesn't support RAW data-path APIs.\n");
4792 		return TEST_SKIPPED;
4793 	}
4794 
4795 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4796 		return TEST_SKIPPED;
4797 
4798 	/* Check if device supports ZUC EEA3 */
4799 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4800 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4801 
4802 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4803 			&cap_idx) == NULL)
4804 		return TEST_SKIPPED;
4805 
4806 	/* Check if device supports ZUC EIA3 */
4807 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4808 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4809 
4810 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4811 			&cap_idx) == NULL)
4812 		return TEST_SKIPPED;
4813 
4814 	/* Create ZUC session */
4815 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4816 			ts_params->valid_devs[0],
4817 			tdata);
4818 	if (retval != 0)
4819 		return retval;
4820 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4821 
4822 	/* clear mbuf payload */
4823 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4824 			rte_pktmbuf_tailroom(ut_params->ibuf));
4825 
4826 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4827 	/* Append data which is padded to a multiple of */
4828 	/* the algorithms block size */
4829 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4830 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4831 				plaintext_pad_len);
4832 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4833 
4834 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4835 
4836 	/* Create ZUC operation */
4837 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4838 	if (retval < 0)
4839 		return retval;
4840 
4841 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4842 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4843 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4844 	else
4845 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4846 			ut_params->op);
4847 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4848 	ut_params->obuf = ut_params->op->sym->m_src;
4849 	if (ut_params->obuf)
4850 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4851 	else
4852 		ciphertext = plaintext;
4853 
4854 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4855 	/* Validate obuf */
4856 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4857 			ciphertext,
4858 			tdata->ciphertext.data,
4859 			tdata->validDataLenInBits.len,
4860 			"ZUC Ciphertext data not as expected");
4861 
4862 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4863 	    + plaintext_pad_len;
4864 
4865 	/* Validate obuf */
4866 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4867 			ut_params->digest,
4868 			tdata->digest.data,
4869 			4,
4870 			"ZUC Generated auth tag not as expected");
4871 	return 0;
4872 }
4873 
4874 static int
4875 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4876 {
4877 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4878 	struct crypto_unittest_params *ut_params = &unittest_params;
4879 
4880 	int retval;
4881 
4882 	uint8_t *plaintext, *ciphertext;
4883 	unsigned plaintext_pad_len;
4884 	unsigned plaintext_len;
4885 	struct rte_cryptodev_info dev_info;
4886 
4887 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4888 	uint64_t feat_flags = dev_info.feature_flags;
4889 
4890 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4891 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4892 		printf("Device doesn't support RAW data-path APIs.\n");
4893 		return TEST_SKIPPED;
4894 	}
4895 
4896 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4897 		return TEST_SKIPPED;
4898 
4899 	/* Verify the capabilities */
4900 	struct rte_cryptodev_sym_capability_idx cap_idx;
4901 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4902 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4903 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4904 			&cap_idx) == NULL)
4905 		return TEST_SKIPPED;
4906 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4907 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4908 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4909 			&cap_idx) == NULL)
4910 		return TEST_SKIPPED;
4911 
4912 	/* Create SNOW 3G session */
4913 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4914 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4915 			RTE_CRYPTO_AUTH_OP_GENERATE,
4916 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4917 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4918 			tdata->key.data, tdata->key.len,
4919 			tdata->auth_iv.len, tdata->digest.len,
4920 			tdata->cipher_iv.len);
4921 	if (retval != 0)
4922 		return retval;
4923 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4924 
4925 	/* clear mbuf payload */
4926 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4927 			rte_pktmbuf_tailroom(ut_params->ibuf));
4928 
4929 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4930 	/* Append data which is padded to a multiple of */
4931 	/* the algorithms block size */
4932 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4933 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4934 				plaintext_pad_len);
4935 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4936 
4937 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4938 
4939 	/* Create SNOW 3G operation */
4940 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4941 			tdata->digest.len, tdata->auth_iv.data,
4942 			tdata->auth_iv.len,
4943 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4944 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4945 			tdata->validCipherLenInBits.len,
4946 			0,
4947 			tdata->validAuthLenInBits.len,
4948 			0
4949 			);
4950 	if (retval < 0)
4951 		return retval;
4952 
4953 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4954 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4955 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4956 	else
4957 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4958 			ut_params->op);
4959 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4960 	ut_params->obuf = ut_params->op->sym->m_src;
4961 	if (ut_params->obuf)
4962 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4963 	else
4964 		ciphertext = plaintext;
4965 
4966 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4967 	/* Validate obuf */
4968 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4969 			ciphertext,
4970 			tdata->ciphertext.data,
4971 			tdata->validDataLenInBits.len,
4972 			"SNOW 3G Ciphertext data not as expected");
4973 
4974 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4975 	    + plaintext_pad_len;
4976 
4977 	/* Validate obuf */
4978 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4979 			ut_params->digest,
4980 			tdata->digest.data,
4981 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4982 			"SNOW 3G Generated auth tag not as expected");
4983 	return 0;
4984 }
4985 
4986 static int
4987 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4988 	uint8_t op_mode, uint8_t verify)
4989 {
4990 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4991 	struct crypto_unittest_params *ut_params = &unittest_params;
4992 
4993 	int retval;
4994 
4995 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4996 	unsigned int plaintext_pad_len;
4997 	unsigned int plaintext_len;
4998 	unsigned int ciphertext_pad_len;
4999 	unsigned int ciphertext_len;
5000 
5001 	struct rte_cryptodev_info dev_info;
5002 
5003 	/* Verify the capabilities */
5004 	struct rte_cryptodev_sym_capability_idx cap_idx;
5005 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5006 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5007 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5008 			&cap_idx) == NULL)
5009 		return TEST_SKIPPED;
5010 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5011 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5012 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5013 			&cap_idx) == NULL)
5014 		return TEST_SKIPPED;
5015 
5016 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5017 		return TEST_SKIPPED;
5018 
5019 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5020 
5021 	uint64_t feat_flags = dev_info.feature_flags;
5022 
5023 	if (op_mode == OUT_OF_PLACE) {
5024 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5025 			printf("Device doesn't support digest encrypted.\n");
5026 			return TEST_SKIPPED;
5027 		}
5028 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5029 			return TEST_SKIPPED;
5030 	}
5031 
5032 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5033 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5034 		printf("Device doesn't support RAW data-path APIs.\n");
5035 		return TEST_SKIPPED;
5036 	}
5037 
5038 	/* Create SNOW 3G session */
5039 	retval = create_wireless_algo_auth_cipher_session(
5040 			ts_params->valid_devs[0],
5041 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5042 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5043 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5044 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5045 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5046 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5047 			tdata->key.data, tdata->key.len,
5048 			tdata->auth_iv.len, tdata->digest.len,
5049 			tdata->cipher_iv.len);
5050 	if (retval != 0)
5051 		return retval;
5052 
5053 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5054 	if (op_mode == OUT_OF_PLACE)
5055 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5056 
5057 	/* clear mbuf payload */
5058 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5059 		rte_pktmbuf_tailroom(ut_params->ibuf));
5060 	if (op_mode == OUT_OF_PLACE)
5061 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5062 			rte_pktmbuf_tailroom(ut_params->obuf));
5063 
5064 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5065 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5066 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5067 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5068 
5069 	if (verify) {
5070 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5071 					ciphertext_pad_len);
5072 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5073 		if (op_mode == OUT_OF_PLACE)
5074 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5075 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5076 			ciphertext_len);
5077 	} else {
5078 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5079 					plaintext_pad_len);
5080 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5081 		if (op_mode == OUT_OF_PLACE)
5082 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5083 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5084 	}
5085 
5086 	/* Create SNOW 3G operation */
5087 	retval = create_wireless_algo_auth_cipher_operation(
5088 		tdata->digest.data, tdata->digest.len,
5089 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5090 		tdata->auth_iv.data, tdata->auth_iv.len,
5091 		(tdata->digest.offset_bytes == 0 ?
5092 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5093 			: tdata->digest.offset_bytes),
5094 		tdata->validCipherLenInBits.len,
5095 		tdata->cipher.offset_bits,
5096 		tdata->validAuthLenInBits.len,
5097 		tdata->auth.offset_bits,
5098 		op_mode, 0, verify);
5099 
5100 	if (retval < 0)
5101 		return retval;
5102 
5103 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5104 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5105 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5106 	else
5107 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5108 			ut_params->op);
5109 
5110 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5111 
5112 	ut_params->obuf = (op_mode == IN_PLACE ?
5113 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5114 
5115 	if (verify) {
5116 		if (ut_params->obuf)
5117 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5118 							uint8_t *);
5119 		else
5120 			plaintext = ciphertext +
5121 				(tdata->cipher.offset_bits >> 3);
5122 
5123 		debug_hexdump(stdout, "plaintext:", plaintext,
5124 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5125 		debug_hexdump(stdout, "plaintext expected:",
5126 			tdata->plaintext.data,
5127 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5128 	} else {
5129 		if (ut_params->obuf)
5130 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5131 							uint8_t *);
5132 		else
5133 			ciphertext = plaintext;
5134 
5135 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5136 			ciphertext_len);
5137 		debug_hexdump(stdout, "ciphertext expected:",
5138 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5139 
5140 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5141 			+ (tdata->digest.offset_bytes == 0 ?
5142 		plaintext_pad_len : tdata->digest.offset_bytes);
5143 
5144 		debug_hexdump(stdout, "digest:", ut_params->digest,
5145 			tdata->digest.len);
5146 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5147 				tdata->digest.len);
5148 	}
5149 
5150 	/* Validate obuf */
5151 	if (verify) {
5152 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5153 			plaintext,
5154 			tdata->plaintext.data,
5155 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5156 			 (tdata->digest.len << 3)),
5157 			tdata->cipher.offset_bits,
5158 			"SNOW 3G Plaintext data not as expected");
5159 	} else {
5160 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5161 			ciphertext,
5162 			tdata->ciphertext.data,
5163 			(tdata->validDataLenInBits.len -
5164 			 tdata->cipher.offset_bits),
5165 			tdata->cipher.offset_bits,
5166 			"SNOW 3G Ciphertext data not as expected");
5167 
5168 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5169 			ut_params->digest,
5170 			tdata->digest.data,
5171 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5172 			"SNOW 3G Generated auth tag not as expected");
5173 	}
5174 	return 0;
5175 }
5176 
5177 static int
5178 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5179 	uint8_t op_mode, uint8_t verify)
5180 {
5181 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5182 	struct crypto_unittest_params *ut_params = &unittest_params;
5183 
5184 	int retval;
5185 
5186 	const uint8_t *plaintext = NULL;
5187 	const uint8_t *ciphertext = NULL;
5188 	const uint8_t *digest = NULL;
5189 	unsigned int plaintext_pad_len;
5190 	unsigned int plaintext_len;
5191 	unsigned int ciphertext_pad_len;
5192 	unsigned int ciphertext_len;
5193 	uint8_t buffer[10000];
5194 	uint8_t digest_buffer[10000];
5195 
5196 	struct rte_cryptodev_info dev_info;
5197 
5198 	/* Verify the capabilities */
5199 	struct rte_cryptodev_sym_capability_idx cap_idx;
5200 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5201 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5202 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5203 			&cap_idx) == NULL)
5204 		return TEST_SKIPPED;
5205 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5206 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5207 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5208 			&cap_idx) == NULL)
5209 		return TEST_SKIPPED;
5210 
5211 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5212 		return TEST_SKIPPED;
5213 
5214 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5215 
5216 	uint64_t feat_flags = dev_info.feature_flags;
5217 
5218 	if (op_mode == IN_PLACE) {
5219 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5220 			printf("Device doesn't support in-place scatter-gather "
5221 					"in both input and output mbufs.\n");
5222 			return TEST_SKIPPED;
5223 		}
5224 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5225 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5226 			printf("Device doesn't support RAW data-path APIs.\n");
5227 			return TEST_SKIPPED;
5228 		}
5229 	} else {
5230 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5231 			return TEST_SKIPPED;
5232 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5233 			printf("Device doesn't support out-of-place scatter-gather "
5234 					"in both input and output mbufs.\n");
5235 			return TEST_SKIPPED;
5236 		}
5237 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5238 			printf("Device doesn't support digest encrypted.\n");
5239 			return TEST_SKIPPED;
5240 		}
5241 	}
5242 
5243 	/* Create SNOW 3G session */
5244 	retval = create_wireless_algo_auth_cipher_session(
5245 			ts_params->valid_devs[0],
5246 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5247 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5248 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5249 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5250 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5251 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5252 			tdata->key.data, tdata->key.len,
5253 			tdata->auth_iv.len, tdata->digest.len,
5254 			tdata->cipher_iv.len);
5255 
5256 	if (retval != 0)
5257 		return retval;
5258 
5259 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5260 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5261 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5262 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5263 
5264 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5265 			plaintext_pad_len, 15, 0);
5266 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5267 			"Failed to allocate input buffer in mempool");
5268 
5269 	if (op_mode == OUT_OF_PLACE) {
5270 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5271 				plaintext_pad_len, 15, 0);
5272 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5273 				"Failed to allocate output buffer in mempool");
5274 	}
5275 
5276 	if (verify) {
5277 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5278 			tdata->ciphertext.data);
5279 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5280 					ciphertext_len, buffer);
5281 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5282 			ciphertext_len);
5283 	} else {
5284 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5285 			tdata->plaintext.data);
5286 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5287 					plaintext_len, buffer);
5288 		debug_hexdump(stdout, "plaintext:", plaintext,
5289 			plaintext_len);
5290 	}
5291 	memset(buffer, 0, sizeof(buffer));
5292 
5293 	/* Create SNOW 3G operation */
5294 	retval = create_wireless_algo_auth_cipher_operation(
5295 		tdata->digest.data, tdata->digest.len,
5296 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5297 		tdata->auth_iv.data, tdata->auth_iv.len,
5298 		(tdata->digest.offset_bytes == 0 ?
5299 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5300 			: tdata->digest.offset_bytes),
5301 		tdata->validCipherLenInBits.len,
5302 		tdata->cipher.offset_bits,
5303 		tdata->validAuthLenInBits.len,
5304 		tdata->auth.offset_bits,
5305 		op_mode, 1, verify);
5306 
5307 	if (retval < 0)
5308 		return retval;
5309 
5310 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5311 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5312 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5313 	else
5314 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5315 			ut_params->op);
5316 
5317 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5318 
5319 	ut_params->obuf = (op_mode == IN_PLACE ?
5320 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5321 
5322 	if (verify) {
5323 		if (ut_params->obuf)
5324 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5325 					plaintext_len, buffer);
5326 		else
5327 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5328 					plaintext_len, buffer);
5329 
5330 		debug_hexdump(stdout, "plaintext:", plaintext,
5331 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5332 		debug_hexdump(stdout, "plaintext expected:",
5333 			tdata->plaintext.data,
5334 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5335 	} else {
5336 		if (ut_params->obuf)
5337 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5338 					ciphertext_len, buffer);
5339 		else
5340 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5341 					ciphertext_len, buffer);
5342 
5343 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5344 			ciphertext_len);
5345 		debug_hexdump(stdout, "ciphertext expected:",
5346 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5347 
5348 		if (ut_params->obuf)
5349 			digest = rte_pktmbuf_read(ut_params->obuf,
5350 				(tdata->digest.offset_bytes == 0 ?
5351 				plaintext_pad_len : tdata->digest.offset_bytes),
5352 				tdata->digest.len, digest_buffer);
5353 		else
5354 			digest = rte_pktmbuf_read(ut_params->ibuf,
5355 				(tdata->digest.offset_bytes == 0 ?
5356 				plaintext_pad_len : tdata->digest.offset_bytes),
5357 				tdata->digest.len, digest_buffer);
5358 
5359 		debug_hexdump(stdout, "digest:", digest,
5360 			tdata->digest.len);
5361 		debug_hexdump(stdout, "digest expected:",
5362 			tdata->digest.data, tdata->digest.len);
5363 	}
5364 
5365 	/* Validate obuf */
5366 	if (verify) {
5367 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5368 			plaintext,
5369 			tdata->plaintext.data,
5370 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5371 			 (tdata->digest.len << 3)),
5372 			tdata->cipher.offset_bits,
5373 			"SNOW 3G Plaintext data not as expected");
5374 	} else {
5375 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5376 			ciphertext,
5377 			tdata->ciphertext.data,
5378 			(tdata->validDataLenInBits.len -
5379 			 tdata->cipher.offset_bits),
5380 			tdata->cipher.offset_bits,
5381 			"SNOW 3G Ciphertext data not as expected");
5382 
5383 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5384 			digest,
5385 			tdata->digest.data,
5386 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5387 			"SNOW 3G Generated auth tag not as expected");
5388 	}
5389 	return 0;
5390 }
5391 
5392 static int
5393 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5394 	uint8_t op_mode, uint8_t verify)
5395 {
5396 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5397 	struct crypto_unittest_params *ut_params = &unittest_params;
5398 
5399 	int retval;
5400 
5401 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5402 	unsigned int plaintext_pad_len;
5403 	unsigned int plaintext_len;
5404 	unsigned int ciphertext_pad_len;
5405 	unsigned int ciphertext_len;
5406 
5407 	struct rte_cryptodev_info dev_info;
5408 
5409 	/* Verify the capabilities */
5410 	struct rte_cryptodev_sym_capability_idx cap_idx;
5411 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5412 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5413 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5414 			&cap_idx) == NULL)
5415 		return TEST_SKIPPED;
5416 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5417 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5418 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5419 			&cap_idx) == NULL)
5420 		return TEST_SKIPPED;
5421 
5422 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5423 
5424 	uint64_t feat_flags = dev_info.feature_flags;
5425 
5426 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5427 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5428 		printf("Device doesn't support RAW data-path APIs.\n");
5429 		return TEST_SKIPPED;
5430 	}
5431 
5432 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5433 		return TEST_SKIPPED;
5434 
5435 	if (op_mode == OUT_OF_PLACE) {
5436 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5437 			return TEST_SKIPPED;
5438 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5439 			printf("Device doesn't support digest encrypted.\n");
5440 			return TEST_SKIPPED;
5441 		}
5442 	}
5443 
5444 	/* Create KASUMI session */
5445 	retval = create_wireless_algo_auth_cipher_session(
5446 			ts_params->valid_devs[0],
5447 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5448 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5449 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5450 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5451 			RTE_CRYPTO_AUTH_KASUMI_F9,
5452 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5453 			tdata->key.data, tdata->key.len,
5454 			0, tdata->digest.len,
5455 			tdata->cipher_iv.len);
5456 
5457 	if (retval != 0)
5458 		return retval;
5459 
5460 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5461 	if (op_mode == OUT_OF_PLACE)
5462 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5463 
5464 	/* clear mbuf payload */
5465 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5466 		rte_pktmbuf_tailroom(ut_params->ibuf));
5467 	if (op_mode == OUT_OF_PLACE)
5468 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5469 			rte_pktmbuf_tailroom(ut_params->obuf));
5470 
5471 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5472 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5473 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5474 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5475 
5476 	if (verify) {
5477 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5478 					ciphertext_pad_len);
5479 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5480 		if (op_mode == OUT_OF_PLACE)
5481 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5482 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5483 			ciphertext_len);
5484 	} else {
5485 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5486 					plaintext_pad_len);
5487 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5488 		if (op_mode == OUT_OF_PLACE)
5489 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5490 		debug_hexdump(stdout, "plaintext:", plaintext,
5491 			plaintext_len);
5492 	}
5493 
5494 	/* Create KASUMI operation */
5495 	retval = create_wireless_algo_auth_cipher_operation(
5496 		tdata->digest.data, tdata->digest.len,
5497 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5498 		NULL, 0,
5499 		(tdata->digest.offset_bytes == 0 ?
5500 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5501 			: tdata->digest.offset_bytes),
5502 		tdata->validCipherLenInBits.len,
5503 		tdata->validCipherOffsetInBits.len,
5504 		tdata->validAuthLenInBits.len,
5505 		0,
5506 		op_mode, 0, verify);
5507 
5508 	if (retval < 0)
5509 		return retval;
5510 
5511 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5512 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5513 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5514 	else
5515 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5516 			ut_params->op);
5517 
5518 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5519 
5520 	ut_params->obuf = (op_mode == IN_PLACE ?
5521 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5522 
5523 
5524 	if (verify) {
5525 		if (ut_params->obuf)
5526 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5527 							uint8_t *);
5528 		else
5529 			plaintext = ciphertext;
5530 
5531 		debug_hexdump(stdout, "plaintext:", plaintext,
5532 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5533 		debug_hexdump(stdout, "plaintext expected:",
5534 			tdata->plaintext.data,
5535 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5536 	} else {
5537 		if (ut_params->obuf)
5538 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5539 							uint8_t *);
5540 		else
5541 			ciphertext = plaintext;
5542 
5543 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5544 			ciphertext_len);
5545 		debug_hexdump(stdout, "ciphertext expected:",
5546 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5547 
5548 		ut_params->digest = rte_pktmbuf_mtod(
5549 			ut_params->obuf, uint8_t *) +
5550 			(tdata->digest.offset_bytes == 0 ?
5551 			plaintext_pad_len : tdata->digest.offset_bytes);
5552 
5553 		debug_hexdump(stdout, "digest:", ut_params->digest,
5554 			tdata->digest.len);
5555 		debug_hexdump(stdout, "digest expected:",
5556 			tdata->digest.data, tdata->digest.len);
5557 	}
5558 
5559 	/* Validate obuf */
5560 	if (verify) {
5561 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5562 			plaintext,
5563 			tdata->plaintext.data,
5564 			tdata->plaintext.len >> 3,
5565 			"KASUMI Plaintext data not as expected");
5566 	} else {
5567 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5568 			ciphertext,
5569 			tdata->ciphertext.data,
5570 			tdata->ciphertext.len >> 3,
5571 			"KASUMI Ciphertext data not as expected");
5572 
5573 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5574 			ut_params->digest,
5575 			tdata->digest.data,
5576 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5577 			"KASUMI Generated auth tag not as expected");
5578 	}
5579 	return 0;
5580 }
5581 
5582 static int
5583 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5584 	uint8_t op_mode, uint8_t verify)
5585 {
5586 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5587 	struct crypto_unittest_params *ut_params = &unittest_params;
5588 
5589 	int retval;
5590 
5591 	const uint8_t *plaintext = NULL;
5592 	const uint8_t *ciphertext = NULL;
5593 	const uint8_t *digest = NULL;
5594 	unsigned int plaintext_pad_len;
5595 	unsigned int plaintext_len;
5596 	unsigned int ciphertext_pad_len;
5597 	unsigned int ciphertext_len;
5598 	uint8_t buffer[10000];
5599 	uint8_t digest_buffer[10000];
5600 
5601 	struct rte_cryptodev_info dev_info;
5602 
5603 	/* Verify the capabilities */
5604 	struct rte_cryptodev_sym_capability_idx cap_idx;
5605 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5606 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5607 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5608 			&cap_idx) == NULL)
5609 		return TEST_SKIPPED;
5610 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5611 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5612 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5613 			&cap_idx) == NULL)
5614 		return TEST_SKIPPED;
5615 
5616 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5617 		return TEST_SKIPPED;
5618 
5619 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5620 
5621 	uint64_t feat_flags = dev_info.feature_flags;
5622 
5623 	if (op_mode == IN_PLACE) {
5624 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5625 			printf("Device doesn't support in-place scatter-gather "
5626 					"in both input and output mbufs.\n");
5627 			return TEST_SKIPPED;
5628 		}
5629 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5630 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5631 			printf("Device doesn't support RAW data-path APIs.\n");
5632 			return TEST_SKIPPED;
5633 		}
5634 	} else {
5635 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5636 			return TEST_SKIPPED;
5637 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5638 			printf("Device doesn't support out-of-place scatter-gather "
5639 					"in both input and output mbufs.\n");
5640 			return TEST_SKIPPED;
5641 		}
5642 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5643 			printf("Device doesn't support digest encrypted.\n");
5644 			return TEST_SKIPPED;
5645 		}
5646 	}
5647 
5648 	/* Create KASUMI session */
5649 	retval = create_wireless_algo_auth_cipher_session(
5650 			ts_params->valid_devs[0],
5651 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5652 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5653 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5654 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5655 			RTE_CRYPTO_AUTH_KASUMI_F9,
5656 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5657 			tdata->key.data, tdata->key.len,
5658 			0, tdata->digest.len,
5659 			tdata->cipher_iv.len);
5660 
5661 	if (retval != 0)
5662 		return retval;
5663 
5664 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5665 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5666 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5667 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5668 
5669 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5670 			plaintext_pad_len, 15, 0);
5671 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5672 			"Failed to allocate input buffer in mempool");
5673 
5674 	if (op_mode == OUT_OF_PLACE) {
5675 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5676 				plaintext_pad_len, 15, 0);
5677 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5678 				"Failed to allocate output buffer in mempool");
5679 	}
5680 
5681 	if (verify) {
5682 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5683 			tdata->ciphertext.data);
5684 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5685 					ciphertext_len, buffer);
5686 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5687 			ciphertext_len);
5688 	} else {
5689 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5690 			tdata->plaintext.data);
5691 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5692 					plaintext_len, buffer);
5693 		debug_hexdump(stdout, "plaintext:", plaintext,
5694 			plaintext_len);
5695 	}
5696 	memset(buffer, 0, sizeof(buffer));
5697 
5698 	/* Create KASUMI operation */
5699 	retval = create_wireless_algo_auth_cipher_operation(
5700 		tdata->digest.data, tdata->digest.len,
5701 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5702 		NULL, 0,
5703 		(tdata->digest.offset_bytes == 0 ?
5704 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5705 			: tdata->digest.offset_bytes),
5706 		tdata->validCipherLenInBits.len,
5707 		tdata->validCipherOffsetInBits.len,
5708 		tdata->validAuthLenInBits.len,
5709 		0,
5710 		op_mode, 1, verify);
5711 
5712 	if (retval < 0)
5713 		return retval;
5714 
5715 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5716 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5717 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5718 	else
5719 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5720 			ut_params->op);
5721 
5722 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5723 
5724 	ut_params->obuf = (op_mode == IN_PLACE ?
5725 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5726 
5727 	if (verify) {
5728 		if (ut_params->obuf)
5729 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5730 					plaintext_len, buffer);
5731 		else
5732 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5733 					plaintext_len, buffer);
5734 
5735 		debug_hexdump(stdout, "plaintext:", plaintext,
5736 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5737 		debug_hexdump(stdout, "plaintext expected:",
5738 			tdata->plaintext.data,
5739 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5740 	} else {
5741 		if (ut_params->obuf)
5742 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5743 					ciphertext_len, buffer);
5744 		else
5745 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5746 					ciphertext_len, buffer);
5747 
5748 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5749 			ciphertext_len);
5750 		debug_hexdump(stdout, "ciphertext expected:",
5751 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5752 
5753 		if (ut_params->obuf)
5754 			digest = rte_pktmbuf_read(ut_params->obuf,
5755 				(tdata->digest.offset_bytes == 0 ?
5756 				plaintext_pad_len : tdata->digest.offset_bytes),
5757 				tdata->digest.len, digest_buffer);
5758 		else
5759 			digest = rte_pktmbuf_read(ut_params->ibuf,
5760 				(tdata->digest.offset_bytes == 0 ?
5761 				plaintext_pad_len : tdata->digest.offset_bytes),
5762 				tdata->digest.len, digest_buffer);
5763 
5764 		debug_hexdump(stdout, "digest:", digest,
5765 			tdata->digest.len);
5766 		debug_hexdump(stdout, "digest expected:",
5767 			tdata->digest.data, tdata->digest.len);
5768 	}
5769 
5770 	/* Validate obuf */
5771 	if (verify) {
5772 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5773 			plaintext,
5774 			tdata->plaintext.data,
5775 			tdata->plaintext.len >> 3,
5776 			"KASUMI Plaintext data not as expected");
5777 	} else {
5778 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5779 			ciphertext,
5780 			tdata->ciphertext.data,
5781 			tdata->validDataLenInBits.len,
5782 			"KASUMI Ciphertext data not as expected");
5783 
5784 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5785 			digest,
5786 			tdata->digest.data,
5787 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5788 			"KASUMI Generated auth tag not as expected");
5789 	}
5790 	return 0;
5791 }
5792 
5793 static int
5794 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5795 {
5796 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5797 	struct crypto_unittest_params *ut_params = &unittest_params;
5798 
5799 	int retval;
5800 
5801 	uint8_t *plaintext, *ciphertext;
5802 	unsigned plaintext_pad_len;
5803 	unsigned plaintext_len;
5804 	struct rte_cryptodev_info dev_info;
5805 
5806 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5807 	uint64_t feat_flags = dev_info.feature_flags;
5808 
5809 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5810 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5811 		printf("Device doesn't support RAW data-path APIs.\n");
5812 		return TEST_SKIPPED;
5813 	}
5814 
5815 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5816 		return TEST_SKIPPED;
5817 
5818 	/* Verify the capabilities */
5819 	struct rte_cryptodev_sym_capability_idx cap_idx;
5820 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5821 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5822 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5823 			&cap_idx) == NULL)
5824 		return TEST_SKIPPED;
5825 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5826 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5827 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5828 			&cap_idx) == NULL)
5829 		return TEST_SKIPPED;
5830 
5831 	/* Create KASUMI session */
5832 	retval = create_wireless_algo_cipher_auth_session(
5833 			ts_params->valid_devs[0],
5834 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5835 			RTE_CRYPTO_AUTH_OP_GENERATE,
5836 			RTE_CRYPTO_AUTH_KASUMI_F9,
5837 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5838 			tdata->key.data, tdata->key.len,
5839 			0, tdata->digest.len,
5840 			tdata->cipher_iv.len);
5841 	if (retval != 0)
5842 		return retval;
5843 
5844 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5845 
5846 	/* clear mbuf payload */
5847 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5848 			rte_pktmbuf_tailroom(ut_params->ibuf));
5849 
5850 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5851 	/* Append data which is padded to a multiple of */
5852 	/* the algorithms block size */
5853 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5854 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5855 				plaintext_pad_len);
5856 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5857 
5858 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5859 
5860 	/* Create KASUMI operation */
5861 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5862 				tdata->digest.len, NULL, 0,
5863 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5864 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5865 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5866 				tdata->validCipherOffsetInBits.len,
5867 				tdata->validAuthLenInBits.len,
5868 				0
5869 				);
5870 	if (retval < 0)
5871 		return retval;
5872 
5873 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5874 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5875 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5876 	else
5877 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5878 			ut_params->op);
5879 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5880 
5881 	if (ut_params->op->sym->m_dst)
5882 		ut_params->obuf = ut_params->op->sym->m_dst;
5883 	else
5884 		ut_params->obuf = ut_params->op->sym->m_src;
5885 
5886 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5887 				tdata->validCipherOffsetInBits.len >> 3);
5888 
5889 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5890 			+ plaintext_pad_len;
5891 
5892 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5893 				(tdata->validCipherOffsetInBits.len >> 3);
5894 	/* Validate obuf */
5895 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5896 		ciphertext,
5897 		reference_ciphertext,
5898 		tdata->validCipherLenInBits.len,
5899 		"KASUMI Ciphertext data not as expected");
5900 
5901 	/* Validate obuf */
5902 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5903 		ut_params->digest,
5904 		tdata->digest.data,
5905 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5906 		"KASUMI Generated auth tag not as expected");
5907 	return 0;
5908 }
5909 
5910 static int
5911 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5912 			const enum rte_crypto_cipher_algorithm cipher_algo,
5913 			const uint16_t key_size, const uint16_t iv_size)
5914 {
5915 	struct rte_cryptodev_sym_capability_idx cap_idx;
5916 	const struct rte_cryptodev_symmetric_capability *cap;
5917 
5918 	/* Check if device supports the algorithm */
5919 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5920 	cap_idx.algo.cipher = cipher_algo;
5921 
5922 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5923 			&cap_idx);
5924 
5925 	if (cap == NULL)
5926 		return -1;
5927 
5928 	/* Check if device supports key size and IV size */
5929 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5930 			iv_size) < 0) {
5931 		return -1;
5932 	}
5933 
5934 	return 0;
5935 }
5936 
5937 static int
5938 check_auth_capability(const struct crypto_testsuite_params *ts_params,
5939 			const enum rte_crypto_auth_algorithm auth_algo,
5940 			const uint16_t key_size, const uint16_t iv_size,
5941 			const uint16_t tag_size)
5942 {
5943 	struct rte_cryptodev_sym_capability_idx cap_idx;
5944 	const struct rte_cryptodev_symmetric_capability *cap;
5945 
5946 	/* Check if device supports the algorithm */
5947 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5948 	cap_idx.algo.auth = auth_algo;
5949 
5950 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5951 			&cap_idx);
5952 
5953 	if (cap == NULL)
5954 		return -1;
5955 
5956 	/* Check if device supports key size and IV size */
5957 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
5958 			tag_size, iv_size) < 0) {
5959 		return -1;
5960 	}
5961 
5962 	return 0;
5963 }
5964 
5965 static int
5966 test_zuc_encryption(const struct wireless_test_data *tdata)
5967 {
5968 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5969 	struct crypto_unittest_params *ut_params = &unittest_params;
5970 
5971 	int retval;
5972 	uint8_t *plaintext, *ciphertext;
5973 	unsigned plaintext_pad_len;
5974 	unsigned plaintext_len;
5975 	struct rte_cryptodev_info dev_info;
5976 
5977 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5978 	uint64_t feat_flags = dev_info.feature_flags;
5979 
5980 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5981 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5982 		printf("Device doesn't support RAW data-path APIs.\n");
5983 		return TEST_SKIPPED;
5984 	}
5985 
5986 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5987 		return TEST_SKIPPED;
5988 
5989 	/* Check if device supports ZUC EEA3 */
5990 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
5991 			tdata->key.len, tdata->cipher_iv.len) < 0)
5992 		return TEST_SKIPPED;
5993 
5994 	/* Create ZUC session */
5995 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5996 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5997 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5998 					tdata->key.data, tdata->key.len,
5999 					tdata->cipher_iv.len);
6000 	if (retval != 0)
6001 		return retval;
6002 
6003 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6004 
6005 	/* Clear mbuf payload */
6006 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6007 	       rte_pktmbuf_tailroom(ut_params->ibuf));
6008 
6009 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6010 	/* Append data which is padded to a multiple */
6011 	/* of the algorithms block size */
6012 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6013 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6014 				plaintext_pad_len);
6015 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6016 
6017 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6018 
6019 	/* Create ZUC operation */
6020 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6021 					tdata->cipher_iv.len,
6022 					tdata->plaintext.len,
6023 					0);
6024 	if (retval < 0)
6025 		return retval;
6026 
6027 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6028 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6029 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6030 	else
6031 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6032 						ut_params->op);
6033 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6034 
6035 	ut_params->obuf = ut_params->op->sym->m_dst;
6036 	if (ut_params->obuf)
6037 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6038 	else
6039 		ciphertext = plaintext;
6040 
6041 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6042 
6043 	/* Validate obuf */
6044 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6045 		ciphertext,
6046 		tdata->ciphertext.data,
6047 		tdata->validCipherLenInBits.len,
6048 		"ZUC Ciphertext data not as expected");
6049 	return 0;
6050 }
6051 
6052 static int
6053 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
6054 {
6055 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6056 	struct crypto_unittest_params *ut_params = &unittest_params;
6057 
6058 	int retval;
6059 
6060 	unsigned int plaintext_pad_len;
6061 	unsigned int plaintext_len;
6062 	const uint8_t *ciphertext;
6063 	uint8_t ciphertext_buffer[2048];
6064 	struct rte_cryptodev_info dev_info;
6065 
6066 	/* Check if device supports ZUC EEA3 */
6067 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6068 			tdata->key.len, tdata->cipher_iv.len) < 0)
6069 		return TEST_SKIPPED;
6070 
6071 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6072 		return TEST_SKIPPED;
6073 
6074 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6075 
6076 	uint64_t feat_flags = dev_info.feature_flags;
6077 
6078 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6079 		printf("Device doesn't support in-place scatter-gather. "
6080 				"Test Skipped.\n");
6081 		return TEST_SKIPPED;
6082 	}
6083 
6084 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6085 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6086 		printf("Device doesn't support RAW data-path APIs.\n");
6087 		return TEST_SKIPPED;
6088 	}
6089 
6090 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6091 
6092 	/* Append data which is padded to a multiple */
6093 	/* of the algorithms block size */
6094 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6095 
6096 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6097 			plaintext_pad_len, 10, 0);
6098 
6099 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6100 			tdata->plaintext.data);
6101 
6102 	/* Create ZUC session */
6103 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6104 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6105 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6106 			tdata->key.data, tdata->key.len,
6107 			tdata->cipher_iv.len);
6108 	if (retval < 0)
6109 		return retval;
6110 
6111 	/* Clear mbuf payload */
6112 
6113 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6114 
6115 	/* Create ZUC operation */
6116 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6117 			tdata->cipher_iv.len, tdata->plaintext.len,
6118 			0);
6119 	if (retval < 0)
6120 		return retval;
6121 
6122 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6123 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6124 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6125 	else
6126 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6127 						ut_params->op);
6128 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6129 
6130 	ut_params->obuf = ut_params->op->sym->m_dst;
6131 	if (ut_params->obuf)
6132 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6133 			0, plaintext_len, ciphertext_buffer);
6134 	else
6135 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6136 			0, plaintext_len, ciphertext_buffer);
6137 
6138 	/* Validate obuf */
6139 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6140 
6141 	/* Validate obuf */
6142 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6143 		ciphertext,
6144 		tdata->ciphertext.data,
6145 		tdata->validCipherLenInBits.len,
6146 		"ZUC Ciphertext data not as expected");
6147 
6148 	return 0;
6149 }
6150 
6151 static int
6152 test_zuc_authentication(const struct wireless_test_data *tdata)
6153 {
6154 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6155 	struct crypto_unittest_params *ut_params = &unittest_params;
6156 
6157 	int retval;
6158 	unsigned plaintext_pad_len;
6159 	unsigned plaintext_len;
6160 	uint8_t *plaintext;
6161 
6162 	struct rte_cryptodev_info dev_info;
6163 
6164 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6165 	uint64_t feat_flags = dev_info.feature_flags;
6166 
6167 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6168 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6169 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6170 		return TEST_SKIPPED;
6171 	}
6172 
6173 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6174 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6175 		printf("Device doesn't support RAW data-path APIs.\n");
6176 		return TEST_SKIPPED;
6177 	}
6178 
6179 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6180 		return TEST_SKIPPED;
6181 
6182 	/* Check if device supports ZUC EIA3 */
6183 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6184 			tdata->key.len, tdata->auth_iv.len,
6185 			tdata->digest.len) < 0)
6186 		return TEST_SKIPPED;
6187 
6188 	/* Create ZUC session */
6189 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6190 			tdata->key.data, tdata->key.len,
6191 			tdata->auth_iv.len, tdata->digest.len,
6192 			RTE_CRYPTO_AUTH_OP_GENERATE,
6193 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6194 	if (retval != 0)
6195 		return retval;
6196 
6197 	/* alloc mbuf and set payload */
6198 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6199 
6200 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6201 	rte_pktmbuf_tailroom(ut_params->ibuf));
6202 
6203 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6204 	/* Append data which is padded to a multiple of */
6205 	/* the algorithms block size */
6206 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6207 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6208 				plaintext_pad_len);
6209 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6210 
6211 	/* Create ZUC operation */
6212 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6213 			tdata->auth_iv.data, tdata->auth_iv.len,
6214 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6215 			tdata->validAuthLenInBits.len,
6216 			0);
6217 	if (retval < 0)
6218 		return retval;
6219 
6220 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6221 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6222 				ut_params->op, 0, 1, 1, 0);
6223 	else
6224 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6225 				ut_params->op);
6226 	ut_params->obuf = ut_params->op->sym->m_src;
6227 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6228 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6229 			+ plaintext_pad_len;
6230 
6231 	/* Validate obuf */
6232 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6233 	ut_params->digest,
6234 	tdata->digest.data,
6235 	tdata->digest.len,
6236 	"ZUC Generated auth tag not as expected");
6237 
6238 	return 0;
6239 }
6240 
6241 static int
6242 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6243 	uint8_t op_mode, uint8_t verify)
6244 {
6245 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6246 	struct crypto_unittest_params *ut_params = &unittest_params;
6247 
6248 	int retval;
6249 
6250 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6251 	unsigned int plaintext_pad_len;
6252 	unsigned int plaintext_len;
6253 	unsigned int ciphertext_pad_len;
6254 	unsigned int ciphertext_len;
6255 
6256 	struct rte_cryptodev_info dev_info;
6257 
6258 	/* Check if device supports ZUC EEA3 */
6259 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6260 			tdata->key.len, tdata->cipher_iv.len) < 0)
6261 		return TEST_SKIPPED;
6262 
6263 	/* Check if device supports ZUC EIA3 */
6264 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6265 			tdata->key.len, tdata->auth_iv.len,
6266 			tdata->digest.len) < 0)
6267 		return TEST_SKIPPED;
6268 
6269 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6270 
6271 	uint64_t feat_flags = dev_info.feature_flags;
6272 
6273 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6274 		printf("Device doesn't support digest encrypted.\n");
6275 		return TEST_SKIPPED;
6276 	}
6277 	if (op_mode == IN_PLACE) {
6278 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6279 			printf("Device doesn't support in-place scatter-gather "
6280 					"in both input and output mbufs.\n");
6281 			return TEST_SKIPPED;
6282 		}
6283 
6284 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6285 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6286 			printf("Device doesn't support RAW data-path APIs.\n");
6287 			return TEST_SKIPPED;
6288 		}
6289 	} else {
6290 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6291 			return TEST_SKIPPED;
6292 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6293 			printf("Device doesn't support out-of-place scatter-gather "
6294 					"in both input and output mbufs.\n");
6295 			return TEST_SKIPPED;
6296 		}
6297 	}
6298 
6299 	/* Create ZUC session */
6300 	retval = create_wireless_algo_auth_cipher_session(
6301 			ts_params->valid_devs[0],
6302 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6303 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6304 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6305 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6306 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6307 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6308 			tdata->key.data, tdata->key.len,
6309 			tdata->auth_iv.len, tdata->digest.len,
6310 			tdata->cipher_iv.len);
6311 
6312 	if (retval != 0)
6313 		return retval;
6314 
6315 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6316 	if (op_mode == OUT_OF_PLACE)
6317 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6318 
6319 	/* clear mbuf payload */
6320 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6321 		rte_pktmbuf_tailroom(ut_params->ibuf));
6322 	if (op_mode == OUT_OF_PLACE)
6323 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6324 			rte_pktmbuf_tailroom(ut_params->obuf));
6325 
6326 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6327 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6328 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6329 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6330 
6331 	if (verify) {
6332 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6333 					ciphertext_pad_len);
6334 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6335 		if (op_mode == OUT_OF_PLACE)
6336 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6337 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6338 			ciphertext_len);
6339 	} else {
6340 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6341 					plaintext_pad_len);
6342 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6343 		if (op_mode == OUT_OF_PLACE)
6344 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6345 		debug_hexdump(stdout, "plaintext:", plaintext,
6346 			plaintext_len);
6347 	}
6348 
6349 	/* Create ZUC operation */
6350 	retval = create_wireless_algo_auth_cipher_operation(
6351 		tdata->digest.data, tdata->digest.len,
6352 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6353 		tdata->auth_iv.data, tdata->auth_iv.len,
6354 		(tdata->digest.offset_bytes == 0 ?
6355 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6356 			: tdata->digest.offset_bytes),
6357 		tdata->validCipherLenInBits.len,
6358 		tdata->validCipherOffsetInBits.len,
6359 		tdata->validAuthLenInBits.len,
6360 		0,
6361 		op_mode, 0, verify);
6362 
6363 	if (retval < 0)
6364 		return retval;
6365 
6366 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6367 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6368 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6369 	else
6370 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6371 			ut_params->op);
6372 
6373 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6374 
6375 	ut_params->obuf = (op_mode == IN_PLACE ?
6376 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6377 
6378 
6379 	if (verify) {
6380 		if (ut_params->obuf)
6381 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6382 							uint8_t *);
6383 		else
6384 			plaintext = ciphertext;
6385 
6386 		debug_hexdump(stdout, "plaintext:", plaintext,
6387 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6388 		debug_hexdump(stdout, "plaintext expected:",
6389 			tdata->plaintext.data,
6390 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6391 	} else {
6392 		if (ut_params->obuf)
6393 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6394 							uint8_t *);
6395 		else
6396 			ciphertext = plaintext;
6397 
6398 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6399 			ciphertext_len);
6400 		debug_hexdump(stdout, "ciphertext expected:",
6401 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6402 
6403 		ut_params->digest = rte_pktmbuf_mtod(
6404 			ut_params->obuf, uint8_t *) +
6405 			(tdata->digest.offset_bytes == 0 ?
6406 			plaintext_pad_len : tdata->digest.offset_bytes);
6407 
6408 		debug_hexdump(stdout, "digest:", ut_params->digest,
6409 			tdata->digest.len);
6410 		debug_hexdump(stdout, "digest expected:",
6411 			tdata->digest.data, tdata->digest.len);
6412 	}
6413 
6414 	/* Validate obuf */
6415 	if (verify) {
6416 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6417 			plaintext,
6418 			tdata->plaintext.data,
6419 			tdata->plaintext.len >> 3,
6420 			"ZUC Plaintext data not as expected");
6421 	} else {
6422 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6423 			ciphertext,
6424 			tdata->ciphertext.data,
6425 			tdata->ciphertext.len >> 3,
6426 			"ZUC Ciphertext data not as expected");
6427 
6428 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6429 			ut_params->digest,
6430 			tdata->digest.data,
6431 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6432 			"ZUC Generated auth tag not as expected");
6433 	}
6434 	return 0;
6435 }
6436 
6437 static int
6438 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6439 	uint8_t op_mode, uint8_t verify)
6440 {
6441 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6442 	struct crypto_unittest_params *ut_params = &unittest_params;
6443 
6444 	int retval;
6445 
6446 	const uint8_t *plaintext = NULL;
6447 	const uint8_t *ciphertext = NULL;
6448 	const uint8_t *digest = NULL;
6449 	unsigned int plaintext_pad_len;
6450 	unsigned int plaintext_len;
6451 	unsigned int ciphertext_pad_len;
6452 	unsigned int ciphertext_len;
6453 	uint8_t buffer[10000];
6454 	uint8_t digest_buffer[10000];
6455 
6456 	struct rte_cryptodev_info dev_info;
6457 
6458 	/* Check if device supports ZUC EEA3 */
6459 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6460 			tdata->key.len, tdata->cipher_iv.len) < 0)
6461 		return TEST_SKIPPED;
6462 
6463 	/* Check if device supports ZUC EIA3 */
6464 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6465 			tdata->key.len, tdata->auth_iv.len,
6466 			tdata->digest.len) < 0)
6467 		return TEST_SKIPPED;
6468 
6469 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6470 
6471 	uint64_t feat_flags = dev_info.feature_flags;
6472 
6473 	if (op_mode == IN_PLACE) {
6474 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6475 			printf("Device doesn't support in-place scatter-gather "
6476 					"in both input and output mbufs.\n");
6477 			return TEST_SKIPPED;
6478 		}
6479 
6480 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6481 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6482 			printf("Device doesn't support RAW data-path APIs.\n");
6483 			return TEST_SKIPPED;
6484 		}
6485 	} else {
6486 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6487 			return TEST_SKIPPED;
6488 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6489 			printf("Device doesn't support out-of-place scatter-gather "
6490 					"in both input and output mbufs.\n");
6491 			return TEST_SKIPPED;
6492 		}
6493 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6494 			printf("Device doesn't support digest encrypted.\n");
6495 			return TEST_SKIPPED;
6496 		}
6497 	}
6498 
6499 	/* Create ZUC session */
6500 	retval = create_wireless_algo_auth_cipher_session(
6501 			ts_params->valid_devs[0],
6502 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6503 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6504 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6505 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6506 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6507 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6508 			tdata->key.data, tdata->key.len,
6509 			tdata->auth_iv.len, tdata->digest.len,
6510 			tdata->cipher_iv.len);
6511 
6512 	if (retval != 0)
6513 		return retval;
6514 
6515 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6516 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6517 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6518 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6519 
6520 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6521 			plaintext_pad_len, 15, 0);
6522 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6523 			"Failed to allocate input buffer in mempool");
6524 
6525 	if (op_mode == OUT_OF_PLACE) {
6526 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6527 				plaintext_pad_len, 15, 0);
6528 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6529 				"Failed to allocate output buffer in mempool");
6530 	}
6531 
6532 	if (verify) {
6533 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6534 			tdata->ciphertext.data);
6535 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6536 					ciphertext_len, buffer);
6537 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6538 			ciphertext_len);
6539 	} else {
6540 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6541 			tdata->plaintext.data);
6542 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6543 					plaintext_len, buffer);
6544 		debug_hexdump(stdout, "plaintext:", plaintext,
6545 			plaintext_len);
6546 	}
6547 	memset(buffer, 0, sizeof(buffer));
6548 
6549 	/* Create ZUC operation */
6550 	retval = create_wireless_algo_auth_cipher_operation(
6551 		tdata->digest.data, tdata->digest.len,
6552 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6553 		NULL, 0,
6554 		(tdata->digest.offset_bytes == 0 ?
6555 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6556 			: tdata->digest.offset_bytes),
6557 		tdata->validCipherLenInBits.len,
6558 		tdata->validCipherOffsetInBits.len,
6559 		tdata->validAuthLenInBits.len,
6560 		0,
6561 		op_mode, 1, verify);
6562 
6563 	if (retval < 0)
6564 		return retval;
6565 
6566 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6567 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6568 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6569 	else
6570 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6571 			ut_params->op);
6572 
6573 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6574 
6575 	ut_params->obuf = (op_mode == IN_PLACE ?
6576 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6577 
6578 	if (verify) {
6579 		if (ut_params->obuf)
6580 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6581 					plaintext_len, buffer);
6582 		else
6583 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6584 					plaintext_len, buffer);
6585 
6586 		debug_hexdump(stdout, "plaintext:", plaintext,
6587 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6588 		debug_hexdump(stdout, "plaintext expected:",
6589 			tdata->plaintext.data,
6590 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6591 	} else {
6592 		if (ut_params->obuf)
6593 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6594 					ciphertext_len, buffer);
6595 		else
6596 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6597 					ciphertext_len, buffer);
6598 
6599 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6600 			ciphertext_len);
6601 		debug_hexdump(stdout, "ciphertext expected:",
6602 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6603 
6604 		if (ut_params->obuf)
6605 			digest = rte_pktmbuf_read(ut_params->obuf,
6606 				(tdata->digest.offset_bytes == 0 ?
6607 				plaintext_pad_len : tdata->digest.offset_bytes),
6608 				tdata->digest.len, digest_buffer);
6609 		else
6610 			digest = rte_pktmbuf_read(ut_params->ibuf,
6611 				(tdata->digest.offset_bytes == 0 ?
6612 				plaintext_pad_len : tdata->digest.offset_bytes),
6613 				tdata->digest.len, digest_buffer);
6614 
6615 		debug_hexdump(stdout, "digest:", digest,
6616 			tdata->digest.len);
6617 		debug_hexdump(stdout, "digest expected:",
6618 			tdata->digest.data, tdata->digest.len);
6619 	}
6620 
6621 	/* Validate obuf */
6622 	if (verify) {
6623 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6624 			plaintext,
6625 			tdata->plaintext.data,
6626 			tdata->plaintext.len >> 3,
6627 			"ZUC Plaintext data not as expected");
6628 	} else {
6629 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6630 			ciphertext,
6631 			tdata->ciphertext.data,
6632 			tdata->validDataLenInBits.len,
6633 			"ZUC Ciphertext data not as expected");
6634 
6635 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6636 			digest,
6637 			tdata->digest.data,
6638 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6639 			"ZUC Generated auth tag not as expected");
6640 	}
6641 	return 0;
6642 }
6643 
6644 static int
6645 test_kasumi_encryption_test_case_1(void)
6646 {
6647 	return test_kasumi_encryption(&kasumi_test_case_1);
6648 }
6649 
6650 static int
6651 test_kasumi_encryption_test_case_1_sgl(void)
6652 {
6653 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6654 }
6655 
6656 static int
6657 test_kasumi_encryption_test_case_1_oop(void)
6658 {
6659 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6660 }
6661 
6662 static int
6663 test_kasumi_encryption_test_case_1_oop_sgl(void)
6664 {
6665 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6666 }
6667 
6668 static int
6669 test_kasumi_encryption_test_case_2(void)
6670 {
6671 	return test_kasumi_encryption(&kasumi_test_case_2);
6672 }
6673 
6674 static int
6675 test_kasumi_encryption_test_case_3(void)
6676 {
6677 	return test_kasumi_encryption(&kasumi_test_case_3);
6678 }
6679 
6680 static int
6681 test_kasumi_encryption_test_case_4(void)
6682 {
6683 	return test_kasumi_encryption(&kasumi_test_case_4);
6684 }
6685 
6686 static int
6687 test_kasumi_encryption_test_case_5(void)
6688 {
6689 	return test_kasumi_encryption(&kasumi_test_case_5);
6690 }
6691 
6692 static int
6693 test_kasumi_decryption_test_case_1(void)
6694 {
6695 	return test_kasumi_decryption(&kasumi_test_case_1);
6696 }
6697 
6698 static int
6699 test_kasumi_decryption_test_case_1_oop(void)
6700 {
6701 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6702 }
6703 
6704 static int
6705 test_kasumi_decryption_test_case_2(void)
6706 {
6707 	return test_kasumi_decryption(&kasumi_test_case_2);
6708 }
6709 
6710 static int
6711 test_kasumi_decryption_test_case_3(void)
6712 {
6713 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6714 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6715 		return TEST_SKIPPED;
6716 	return test_kasumi_decryption(&kasumi_test_case_3);
6717 }
6718 
6719 static int
6720 test_kasumi_decryption_test_case_4(void)
6721 {
6722 	return test_kasumi_decryption(&kasumi_test_case_4);
6723 }
6724 
6725 static int
6726 test_kasumi_decryption_test_case_5(void)
6727 {
6728 	return test_kasumi_decryption(&kasumi_test_case_5);
6729 }
6730 static int
6731 test_snow3g_encryption_test_case_1(void)
6732 {
6733 	return test_snow3g_encryption(&snow3g_test_case_1);
6734 }
6735 
6736 static int
6737 test_snow3g_encryption_test_case_1_oop(void)
6738 {
6739 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6740 }
6741 
6742 static int
6743 test_snow3g_encryption_test_case_1_oop_sgl(void)
6744 {
6745 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6746 }
6747 
6748 
6749 static int
6750 test_snow3g_encryption_test_case_1_offset_oop(void)
6751 {
6752 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6753 }
6754 
6755 static int
6756 test_snow3g_encryption_test_case_2(void)
6757 {
6758 	return test_snow3g_encryption(&snow3g_test_case_2);
6759 }
6760 
6761 static int
6762 test_snow3g_encryption_test_case_3(void)
6763 {
6764 	return test_snow3g_encryption(&snow3g_test_case_3);
6765 }
6766 
6767 static int
6768 test_snow3g_encryption_test_case_4(void)
6769 {
6770 	return test_snow3g_encryption(&snow3g_test_case_4);
6771 }
6772 
6773 static int
6774 test_snow3g_encryption_test_case_5(void)
6775 {
6776 	return test_snow3g_encryption(&snow3g_test_case_5);
6777 }
6778 
6779 static int
6780 test_snow3g_decryption_test_case_1(void)
6781 {
6782 	return test_snow3g_decryption(&snow3g_test_case_1);
6783 }
6784 
6785 static int
6786 test_snow3g_decryption_test_case_1_oop(void)
6787 {
6788 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6789 }
6790 
6791 static int
6792 test_snow3g_decryption_test_case_2(void)
6793 {
6794 	return test_snow3g_decryption(&snow3g_test_case_2);
6795 }
6796 
6797 static int
6798 test_snow3g_decryption_test_case_3(void)
6799 {
6800 	return test_snow3g_decryption(&snow3g_test_case_3);
6801 }
6802 
6803 static int
6804 test_snow3g_decryption_test_case_4(void)
6805 {
6806 	return test_snow3g_decryption(&snow3g_test_case_4);
6807 }
6808 
6809 static int
6810 test_snow3g_decryption_test_case_5(void)
6811 {
6812 	return test_snow3g_decryption(&snow3g_test_case_5);
6813 }
6814 
6815 /*
6816  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6817  * Pattern digest from snow3g_test_data must be allocated as
6818  * 4 last bytes in plaintext.
6819  */
6820 static void
6821 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6822 		struct snow3g_hash_test_data *output)
6823 {
6824 	if ((pattern != NULL) && (output != NULL)) {
6825 		output->key.len = pattern->key.len;
6826 
6827 		memcpy(output->key.data,
6828 		pattern->key.data, pattern->key.len);
6829 
6830 		output->auth_iv.len = pattern->auth_iv.len;
6831 
6832 		memcpy(output->auth_iv.data,
6833 		pattern->auth_iv.data, pattern->auth_iv.len);
6834 
6835 		output->plaintext.len = pattern->plaintext.len;
6836 
6837 		memcpy(output->plaintext.data,
6838 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6839 
6840 		output->digest.len = pattern->digest.len;
6841 
6842 		memcpy(output->digest.data,
6843 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6844 		pattern->digest.len);
6845 
6846 		output->validAuthLenInBits.len =
6847 		pattern->validAuthLenInBits.len;
6848 	}
6849 }
6850 
6851 /*
6852  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6853  */
6854 static int
6855 test_snow3g_decryption_with_digest_test_case_1(void)
6856 {
6857 	struct snow3g_hash_test_data snow3g_hash_data;
6858 	struct rte_cryptodev_info dev_info;
6859 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6860 
6861 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6862 	uint64_t feat_flags = dev_info.feature_flags;
6863 
6864 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6865 		printf("Device doesn't support encrypted digest operations.\n");
6866 		return TEST_SKIPPED;
6867 	}
6868 
6869 	/*
6870 	 * Function prepare data for hash veryfication test case.
6871 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6872 	 */
6873 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6874 
6875 	return test_snow3g_decryption(&snow3g_test_case_7) &
6876 			test_snow3g_authentication_verify(&snow3g_hash_data);
6877 }
6878 
6879 static int
6880 test_snow3g_cipher_auth_test_case_1(void)
6881 {
6882 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6883 }
6884 
6885 static int
6886 test_snow3g_auth_cipher_test_case_1(void)
6887 {
6888 	return test_snow3g_auth_cipher(
6889 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6890 }
6891 
6892 static int
6893 test_snow3g_auth_cipher_test_case_2(void)
6894 {
6895 	return test_snow3g_auth_cipher(
6896 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6897 }
6898 
6899 static int
6900 test_snow3g_auth_cipher_test_case_2_oop(void)
6901 {
6902 	return test_snow3g_auth_cipher(
6903 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6904 }
6905 
6906 static int
6907 test_snow3g_auth_cipher_part_digest_enc(void)
6908 {
6909 	return test_snow3g_auth_cipher(
6910 		&snow3g_auth_cipher_partial_digest_encryption,
6911 			IN_PLACE, 0);
6912 }
6913 
6914 static int
6915 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6916 {
6917 	return test_snow3g_auth_cipher(
6918 		&snow3g_auth_cipher_partial_digest_encryption,
6919 			OUT_OF_PLACE, 0);
6920 }
6921 
6922 static int
6923 test_snow3g_auth_cipher_test_case_3_sgl(void)
6924 {
6925 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6926 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6927 		return TEST_SKIPPED;
6928 	return test_snow3g_auth_cipher_sgl(
6929 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6930 }
6931 
6932 static int
6933 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6934 {
6935 	return test_snow3g_auth_cipher_sgl(
6936 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6937 }
6938 
6939 static int
6940 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6941 {
6942 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6943 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6944 		return TEST_SKIPPED;
6945 	return test_snow3g_auth_cipher_sgl(
6946 		&snow3g_auth_cipher_partial_digest_encryption,
6947 			IN_PLACE, 0);
6948 }
6949 
6950 static int
6951 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6952 {
6953 	return test_snow3g_auth_cipher_sgl(
6954 		&snow3g_auth_cipher_partial_digest_encryption,
6955 			OUT_OF_PLACE, 0);
6956 }
6957 
6958 static int
6959 test_snow3g_auth_cipher_verify_test_case_1(void)
6960 {
6961 	return test_snow3g_auth_cipher(
6962 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6963 }
6964 
6965 static int
6966 test_snow3g_auth_cipher_verify_test_case_2(void)
6967 {
6968 	return test_snow3g_auth_cipher(
6969 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6970 }
6971 
6972 static int
6973 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6974 {
6975 	return test_snow3g_auth_cipher(
6976 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6977 }
6978 
6979 static int
6980 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6981 {
6982 	return test_snow3g_auth_cipher(
6983 		&snow3g_auth_cipher_partial_digest_encryption,
6984 			IN_PLACE, 1);
6985 }
6986 
6987 static int
6988 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6989 {
6990 	return test_snow3g_auth_cipher(
6991 		&snow3g_auth_cipher_partial_digest_encryption,
6992 			OUT_OF_PLACE, 1);
6993 }
6994 
6995 static int
6996 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6997 {
6998 	return test_snow3g_auth_cipher_sgl(
6999 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
7000 }
7001 
7002 static int
7003 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7004 {
7005 	return test_snow3g_auth_cipher_sgl(
7006 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7007 }
7008 
7009 static int
7010 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7011 {
7012 	return test_snow3g_auth_cipher_sgl(
7013 		&snow3g_auth_cipher_partial_digest_encryption,
7014 			IN_PLACE, 1);
7015 }
7016 
7017 static int
7018 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7019 {
7020 	return test_snow3g_auth_cipher_sgl(
7021 		&snow3g_auth_cipher_partial_digest_encryption,
7022 			OUT_OF_PLACE, 1);
7023 }
7024 
7025 static int
7026 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7027 {
7028 	return test_snow3g_auth_cipher(
7029 		&snow3g_test_case_7, IN_PLACE, 0);
7030 }
7031 
7032 static int
7033 test_kasumi_auth_cipher_test_case_1(void)
7034 {
7035 	return test_kasumi_auth_cipher(
7036 		&kasumi_test_case_3, IN_PLACE, 0);
7037 }
7038 
7039 static int
7040 test_kasumi_auth_cipher_test_case_2(void)
7041 {
7042 	return test_kasumi_auth_cipher(
7043 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7044 }
7045 
7046 static int
7047 test_kasumi_auth_cipher_test_case_2_oop(void)
7048 {
7049 	return test_kasumi_auth_cipher(
7050 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7051 }
7052 
7053 static int
7054 test_kasumi_auth_cipher_test_case_2_sgl(void)
7055 {
7056 	return test_kasumi_auth_cipher_sgl(
7057 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7058 }
7059 
7060 static int
7061 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7062 {
7063 	return test_kasumi_auth_cipher_sgl(
7064 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7065 }
7066 
7067 static int
7068 test_kasumi_auth_cipher_verify_test_case_1(void)
7069 {
7070 	return test_kasumi_auth_cipher(
7071 		&kasumi_test_case_3, IN_PLACE, 1);
7072 }
7073 
7074 static int
7075 test_kasumi_auth_cipher_verify_test_case_2(void)
7076 {
7077 	return test_kasumi_auth_cipher(
7078 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7079 }
7080 
7081 static int
7082 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7083 {
7084 	return test_kasumi_auth_cipher(
7085 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7086 }
7087 
7088 static int
7089 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7090 {
7091 	return test_kasumi_auth_cipher_sgl(
7092 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7093 }
7094 
7095 static int
7096 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7097 {
7098 	return test_kasumi_auth_cipher_sgl(
7099 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7100 }
7101 
7102 static int
7103 test_kasumi_cipher_auth_test_case_1(void)
7104 {
7105 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7106 }
7107 
7108 static int
7109 test_zuc_encryption_test_case_1(void)
7110 {
7111 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
7112 }
7113 
7114 static int
7115 test_zuc_encryption_test_case_2(void)
7116 {
7117 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
7118 }
7119 
7120 static int
7121 test_zuc_encryption_test_case_3(void)
7122 {
7123 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7124 }
7125 
7126 static int
7127 test_zuc_encryption_test_case_4(void)
7128 {
7129 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7130 }
7131 
7132 static int
7133 test_zuc_encryption_test_case_5(void)
7134 {
7135 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7136 }
7137 
7138 static int
7139 test_zuc_encryption_test_case_6_sgl(void)
7140 {
7141 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7142 }
7143 
7144 static int
7145 test_zuc_encryption_test_case_7(void)
7146 {
7147 	return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b);
7148 }
7149 
7150 static int
7151 test_zuc_hash_generate_test_case_1(void)
7152 {
7153 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7154 }
7155 
7156 static int
7157 test_zuc_hash_generate_test_case_2(void)
7158 {
7159 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7160 }
7161 
7162 static int
7163 test_zuc_hash_generate_test_case_3(void)
7164 {
7165 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7166 }
7167 
7168 static int
7169 test_zuc_hash_generate_test_case_4(void)
7170 {
7171 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7172 }
7173 
7174 static int
7175 test_zuc_hash_generate_test_case_5(void)
7176 {
7177 	return test_zuc_authentication(&zuc_test_auth_5670b);
7178 }
7179 
7180 static int
7181 test_zuc_hash_generate_test_case_6(void)
7182 {
7183 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7184 }
7185 
7186 static int
7187 test_zuc_hash_generate_test_case_7(void)
7188 {
7189 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7190 }
7191 
7192 static int
7193 test_zuc_hash_generate_test_case_8(void)
7194 {
7195 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7196 }
7197 
7198 static int
7199 test_zuc_hash_generate_test_case_9(void)
7200 {
7201 	return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b);
7202 }
7203 
7204 static int
7205 test_zuc_hash_generate_test_case_10(void)
7206 {
7207 	return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b);
7208 }
7209 
7210 static int
7211 test_zuc_cipher_auth_test_case_1(void)
7212 {
7213 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7214 }
7215 
7216 static int
7217 test_zuc_cipher_auth_test_case_2(void)
7218 {
7219 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7220 }
7221 
7222 static int
7223 test_zuc_auth_cipher_test_case_1(void)
7224 {
7225 	return test_zuc_auth_cipher(
7226 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7227 }
7228 
7229 static int
7230 test_zuc_auth_cipher_test_case_1_oop(void)
7231 {
7232 	return test_zuc_auth_cipher(
7233 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7234 }
7235 
7236 static int
7237 test_zuc_auth_cipher_test_case_1_sgl(void)
7238 {
7239 	return test_zuc_auth_cipher_sgl(
7240 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7241 }
7242 
7243 static int
7244 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7245 {
7246 	return test_zuc_auth_cipher_sgl(
7247 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7248 }
7249 
7250 static int
7251 test_zuc_auth_cipher_verify_test_case_1(void)
7252 {
7253 	return test_zuc_auth_cipher(
7254 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7255 }
7256 
7257 static int
7258 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7259 {
7260 	return test_zuc_auth_cipher(
7261 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7262 }
7263 
7264 static int
7265 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7266 {
7267 	return test_zuc_auth_cipher_sgl(
7268 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7269 }
7270 
7271 static int
7272 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7273 {
7274 	return test_zuc_auth_cipher_sgl(
7275 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7276 }
7277 
7278 static int
7279 test_zuc256_encryption_test_case_1(void)
7280 {
7281 	return test_zuc_encryption(&zuc256_test_case_cipher_1);
7282 }
7283 
7284 static int
7285 test_zuc256_encryption_test_case_2(void)
7286 {
7287 	return test_zuc_encryption(&zuc256_test_case_cipher_2);
7288 }
7289 
7290 static int
7291 test_zuc256_authentication_test_case_1(void)
7292 {
7293 	return test_zuc_authentication(&zuc256_test_case_auth_1);
7294 }
7295 
7296 static int
7297 test_zuc256_authentication_test_case_2(void)
7298 {
7299 	return test_zuc_authentication(&zuc256_test_case_auth_2);
7300 }
7301 
7302 static int
7303 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7304 {
7305 	uint8_t dev_id = testsuite_params.valid_devs[0];
7306 
7307 	struct rte_cryptodev_sym_capability_idx cap_idx;
7308 
7309 	/* Check if device supports particular cipher algorithm */
7310 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7311 	cap_idx.algo.cipher = tdata->cipher_algo;
7312 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7313 		return TEST_SKIPPED;
7314 
7315 	/* Check if device supports particular hash algorithm */
7316 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7317 	cap_idx.algo.auth = tdata->auth_algo;
7318 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7319 		return TEST_SKIPPED;
7320 
7321 	return 0;
7322 }
7323 
7324 static int
7325 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7326 	uint8_t op_mode, uint8_t verify)
7327 {
7328 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7329 	struct crypto_unittest_params *ut_params = &unittest_params;
7330 
7331 	int retval;
7332 
7333 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7334 	unsigned int plaintext_pad_len;
7335 	unsigned int plaintext_len;
7336 	unsigned int ciphertext_pad_len;
7337 	unsigned int ciphertext_len;
7338 
7339 	struct rte_cryptodev_info dev_info;
7340 	struct rte_crypto_op *op;
7341 
7342 	/* Check if device supports particular algorithms separately */
7343 	if (test_mixed_check_if_unsupported(tdata))
7344 		return TEST_SKIPPED;
7345 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7346 		return TEST_SKIPPED;
7347 
7348 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7349 
7350 	uint64_t feat_flags = dev_info.feature_flags;
7351 
7352 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7353 		printf("Device doesn't support digest encrypted.\n");
7354 		return TEST_SKIPPED;
7355 	}
7356 
7357 	/* Create the session */
7358 	if (verify)
7359 		retval = create_wireless_algo_cipher_auth_session(
7360 				ts_params->valid_devs[0],
7361 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7362 				RTE_CRYPTO_AUTH_OP_VERIFY,
7363 				tdata->auth_algo,
7364 				tdata->cipher_algo,
7365 				tdata->auth_key.data, tdata->auth_key.len,
7366 				tdata->auth_iv.len, tdata->digest_enc.len,
7367 				tdata->cipher_iv.len);
7368 	else
7369 		retval = create_wireless_algo_auth_cipher_session(
7370 				ts_params->valid_devs[0],
7371 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7372 				RTE_CRYPTO_AUTH_OP_GENERATE,
7373 				tdata->auth_algo,
7374 				tdata->cipher_algo,
7375 				tdata->auth_key.data, tdata->auth_key.len,
7376 				tdata->auth_iv.len, tdata->digest_enc.len,
7377 				tdata->cipher_iv.len);
7378 	if (retval != 0)
7379 		return retval;
7380 
7381 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7382 	if (op_mode == OUT_OF_PLACE)
7383 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7384 
7385 	/* clear mbuf payload */
7386 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7387 		rte_pktmbuf_tailroom(ut_params->ibuf));
7388 	if (op_mode == OUT_OF_PLACE) {
7389 
7390 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7391 				rte_pktmbuf_tailroom(ut_params->obuf));
7392 	}
7393 
7394 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7395 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7396 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7397 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7398 
7399 	if (verify) {
7400 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7401 				ciphertext_pad_len);
7402 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7403 		if (op_mode == OUT_OF_PLACE)
7404 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7405 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7406 				ciphertext_len);
7407 	} else {
7408 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7409 				plaintext_pad_len);
7410 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7411 		if (op_mode == OUT_OF_PLACE)
7412 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7413 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7414 	}
7415 
7416 	/* Create the operation */
7417 	retval = create_wireless_algo_auth_cipher_operation(
7418 			tdata->digest_enc.data, tdata->digest_enc.len,
7419 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7420 			tdata->auth_iv.data, tdata->auth_iv.len,
7421 			(tdata->digest_enc.offset == 0 ?
7422 				plaintext_pad_len
7423 				: tdata->digest_enc.offset),
7424 			tdata->validCipherLen.len_bits,
7425 			tdata->cipher.offset_bits,
7426 			tdata->validAuthLen.len_bits,
7427 			tdata->auth.offset_bits,
7428 			op_mode, 0, verify);
7429 
7430 	if (retval < 0)
7431 		return retval;
7432 
7433 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7434 
7435 	/* Check if the op failed because the device doesn't */
7436 	/* support this particular combination of algorithms */
7437 	if (op == NULL && ut_params->op->status ==
7438 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7439 		printf("Device doesn't support this mixed combination. "
7440 				"Test Skipped.\n");
7441 		return TEST_SKIPPED;
7442 	}
7443 	ut_params->op = op;
7444 
7445 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7446 
7447 	ut_params->obuf = (op_mode == IN_PLACE ?
7448 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7449 
7450 	if (verify) {
7451 		if (ut_params->obuf)
7452 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7453 							uint8_t *);
7454 		else
7455 			plaintext = ciphertext +
7456 					(tdata->cipher.offset_bits >> 3);
7457 
7458 		debug_hexdump(stdout, "plaintext:", plaintext,
7459 				tdata->plaintext.len_bits >> 3);
7460 		debug_hexdump(stdout, "plaintext expected:",
7461 				tdata->plaintext.data,
7462 				tdata->plaintext.len_bits >> 3);
7463 	} else {
7464 		if (ut_params->obuf)
7465 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7466 					uint8_t *);
7467 		else
7468 			ciphertext = plaintext;
7469 
7470 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7471 				ciphertext_len);
7472 		debug_hexdump(stdout, "ciphertext expected:",
7473 				tdata->ciphertext.data,
7474 				tdata->ciphertext.len_bits >> 3);
7475 
7476 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7477 				+ (tdata->digest_enc.offset == 0 ?
7478 		plaintext_pad_len : tdata->digest_enc.offset);
7479 
7480 		debug_hexdump(stdout, "digest:", ut_params->digest,
7481 				tdata->digest_enc.len);
7482 		debug_hexdump(stdout, "digest expected:",
7483 				tdata->digest_enc.data,
7484 				tdata->digest_enc.len);
7485 	}
7486 
7487 	/* Validate obuf */
7488 	if (verify) {
7489 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7490 				plaintext,
7491 				tdata->plaintext.data,
7492 				tdata->plaintext.len_bits >> 3,
7493 				"Plaintext data not as expected");
7494 	} else {
7495 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7496 				ciphertext,
7497 				tdata->ciphertext.data,
7498 				tdata->validDataLen.len_bits,
7499 				"Ciphertext data not as expected");
7500 
7501 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7502 				ut_params->digest,
7503 				tdata->digest_enc.data,
7504 				DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7505 				"Generated auth tag not as expected");
7506 	}
7507 
7508 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7509 			"crypto op processing failed");
7510 
7511 	return 0;
7512 }
7513 
7514 static int
7515 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7516 	uint8_t op_mode, uint8_t verify)
7517 {
7518 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7519 	struct crypto_unittest_params *ut_params = &unittest_params;
7520 
7521 	int retval;
7522 
7523 	const uint8_t *plaintext = NULL;
7524 	const uint8_t *ciphertext = NULL;
7525 	const uint8_t *digest = NULL;
7526 	unsigned int plaintext_pad_len;
7527 	unsigned int plaintext_len;
7528 	unsigned int ciphertext_pad_len;
7529 	unsigned int ciphertext_len;
7530 	uint8_t buffer[10000];
7531 	uint8_t digest_buffer[10000];
7532 
7533 	struct rte_cryptodev_info dev_info;
7534 	struct rte_crypto_op *op;
7535 
7536 	/* Check if device supports particular algorithms */
7537 	if (test_mixed_check_if_unsupported(tdata))
7538 		return TEST_SKIPPED;
7539 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7540 		return TEST_SKIPPED;
7541 
7542 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7543 
7544 	uint64_t feat_flags = dev_info.feature_flags;
7545 
7546 	if (op_mode == IN_PLACE) {
7547 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7548 			printf("Device doesn't support in-place scatter-gather "
7549 					"in both input and output mbufs.\n");
7550 			return TEST_SKIPPED;
7551 		}
7552 	} else {
7553 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7554 			printf("Device doesn't support out-of-place scatter-gather "
7555 					"in both input and output mbufs.\n");
7556 			return TEST_SKIPPED;
7557 		}
7558 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7559 			printf("Device doesn't support digest encrypted.\n");
7560 			return TEST_SKIPPED;
7561 		}
7562 	}
7563 
7564 	/* Create the session */
7565 	if (verify)
7566 		retval = create_wireless_algo_cipher_auth_session(
7567 				ts_params->valid_devs[0],
7568 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7569 				RTE_CRYPTO_AUTH_OP_VERIFY,
7570 				tdata->auth_algo,
7571 				tdata->cipher_algo,
7572 				tdata->auth_key.data, tdata->auth_key.len,
7573 				tdata->auth_iv.len, tdata->digest_enc.len,
7574 				tdata->cipher_iv.len);
7575 	else
7576 		retval = create_wireless_algo_auth_cipher_session(
7577 				ts_params->valid_devs[0],
7578 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7579 				RTE_CRYPTO_AUTH_OP_GENERATE,
7580 				tdata->auth_algo,
7581 				tdata->cipher_algo,
7582 				tdata->auth_key.data, tdata->auth_key.len,
7583 				tdata->auth_iv.len, tdata->digest_enc.len,
7584 				tdata->cipher_iv.len);
7585 	if (retval != 0)
7586 		return retval;
7587 
7588 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7589 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7590 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7591 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7592 
7593 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7594 			ciphertext_pad_len, 15, 0);
7595 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7596 			"Failed to allocate input buffer in mempool");
7597 
7598 	if (op_mode == OUT_OF_PLACE) {
7599 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7600 				plaintext_pad_len, 15, 0);
7601 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7602 				"Failed to allocate output buffer in mempool");
7603 	}
7604 
7605 	if (verify) {
7606 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7607 			tdata->ciphertext.data);
7608 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7609 					ciphertext_len, buffer);
7610 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7611 			ciphertext_len);
7612 	} else {
7613 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7614 			tdata->plaintext.data);
7615 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7616 					plaintext_len, buffer);
7617 		debug_hexdump(stdout, "plaintext:", plaintext,
7618 			plaintext_len);
7619 	}
7620 	memset(buffer, 0, sizeof(buffer));
7621 
7622 	/* Create the operation */
7623 	retval = create_wireless_algo_auth_cipher_operation(
7624 			tdata->digest_enc.data, tdata->digest_enc.len,
7625 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7626 			tdata->auth_iv.data, tdata->auth_iv.len,
7627 			(tdata->digest_enc.offset == 0 ?
7628 				plaintext_pad_len
7629 				: tdata->digest_enc.offset),
7630 			tdata->validCipherLen.len_bits,
7631 			tdata->cipher.offset_bits,
7632 			tdata->validAuthLen.len_bits,
7633 			tdata->auth.offset_bits,
7634 			op_mode, 1, verify);
7635 
7636 	if (retval < 0)
7637 		return retval;
7638 
7639 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7640 
7641 	/* Check if the op failed because the device doesn't */
7642 	/* support this particular combination of algorithms */
7643 	if (op == NULL && ut_params->op->status ==
7644 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7645 		printf("Device doesn't support this mixed combination. "
7646 				"Test Skipped.\n");
7647 		return TEST_SKIPPED;
7648 	}
7649 	ut_params->op = op;
7650 
7651 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7652 
7653 	ut_params->obuf = (op_mode == IN_PLACE ?
7654 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7655 
7656 	if (verify) {
7657 		if (ut_params->obuf)
7658 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7659 					plaintext_len, buffer);
7660 		else
7661 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7662 					plaintext_len, buffer);
7663 
7664 		debug_hexdump(stdout, "plaintext:", plaintext,
7665 				(tdata->plaintext.len_bits >> 3) -
7666 				tdata->digest_enc.len);
7667 		debug_hexdump(stdout, "plaintext expected:",
7668 				tdata->plaintext.data,
7669 				(tdata->plaintext.len_bits >> 3) -
7670 				tdata->digest_enc.len);
7671 	} else {
7672 		if (ut_params->obuf)
7673 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7674 					ciphertext_len, buffer);
7675 		else
7676 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7677 					ciphertext_len, buffer);
7678 
7679 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7680 			ciphertext_len);
7681 		debug_hexdump(stdout, "ciphertext expected:",
7682 			tdata->ciphertext.data,
7683 			tdata->ciphertext.len_bits >> 3);
7684 
7685 		if (ut_params->obuf)
7686 			digest = rte_pktmbuf_read(ut_params->obuf,
7687 					(tdata->digest_enc.offset == 0 ?
7688 						plaintext_pad_len :
7689 						tdata->digest_enc.offset),
7690 					tdata->digest_enc.len, digest_buffer);
7691 		else
7692 			digest = rte_pktmbuf_read(ut_params->ibuf,
7693 					(tdata->digest_enc.offset == 0 ?
7694 						plaintext_pad_len :
7695 						tdata->digest_enc.offset),
7696 					tdata->digest_enc.len, digest_buffer);
7697 
7698 		debug_hexdump(stdout, "digest:", digest,
7699 				tdata->digest_enc.len);
7700 		debug_hexdump(stdout, "digest expected:",
7701 				tdata->digest_enc.data, tdata->digest_enc.len);
7702 	}
7703 
7704 	/* Validate obuf */
7705 	if (verify) {
7706 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7707 				plaintext,
7708 				tdata->plaintext.data,
7709 				tdata->plaintext.len_bits >> 3,
7710 				"Plaintext data not as expected");
7711 	} else {
7712 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7713 				ciphertext,
7714 				tdata->ciphertext.data,
7715 				tdata->validDataLen.len_bits,
7716 				"Ciphertext data not as expected");
7717 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7718 				digest,
7719 				tdata->digest_enc.data,
7720 				tdata->digest_enc.len,
7721 				"Generated auth tag not as expected");
7722 	}
7723 
7724 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7725 			"crypto op processing failed");
7726 
7727 	return 0;
7728 }
7729 
7730 /** AUTH AES CMAC + CIPHER AES CTR */
7731 
7732 static int
7733 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7734 {
7735 	return test_mixed_auth_cipher(
7736 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7737 }
7738 
7739 static int
7740 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7741 {
7742 	return test_mixed_auth_cipher(
7743 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7744 }
7745 
7746 static int
7747 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7748 {
7749 	return test_mixed_auth_cipher_sgl(
7750 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7751 }
7752 
7753 static int
7754 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7755 {
7756 	return test_mixed_auth_cipher_sgl(
7757 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7758 }
7759 
7760 static int
7761 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7762 {
7763 	return test_mixed_auth_cipher(
7764 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7765 }
7766 
7767 static int
7768 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7769 {
7770 	return test_mixed_auth_cipher(
7771 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7772 }
7773 
7774 static int
7775 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7776 {
7777 	return test_mixed_auth_cipher_sgl(
7778 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7779 }
7780 
7781 static int
7782 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7783 {
7784 	return test_mixed_auth_cipher_sgl(
7785 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7786 }
7787 
7788 /** MIXED AUTH + CIPHER */
7789 
7790 static int
7791 test_auth_zuc_cipher_snow_test_case_1(void)
7792 {
7793 	return test_mixed_auth_cipher(
7794 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7795 }
7796 
7797 static int
7798 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7799 {
7800 	return test_mixed_auth_cipher(
7801 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7802 }
7803 
7804 static int
7805 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7806 {
7807 	return test_mixed_auth_cipher(
7808 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7809 }
7810 
7811 static int
7812 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7813 {
7814 	return test_mixed_auth_cipher(
7815 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7816 }
7817 
7818 static int
7819 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7820 {
7821 	return test_mixed_auth_cipher(
7822 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7823 }
7824 
7825 static int
7826 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7827 {
7828 	return test_mixed_auth_cipher(
7829 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7830 }
7831 
7832 static int
7833 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7834 {
7835 	return test_mixed_auth_cipher(
7836 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7837 }
7838 
7839 static int
7840 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7841 {
7842 	return test_mixed_auth_cipher(
7843 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7844 }
7845 
7846 static int
7847 test_auth_snow_cipher_zuc_test_case_1(void)
7848 {
7849 	return test_mixed_auth_cipher(
7850 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7851 }
7852 
7853 static int
7854 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7855 {
7856 	return test_mixed_auth_cipher(
7857 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7858 }
7859 
7860 static int
7861 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7862 {
7863 	return test_mixed_auth_cipher(
7864 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7865 }
7866 
7867 static int
7868 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7869 {
7870 	return test_mixed_auth_cipher(
7871 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7872 }
7873 
7874 static int
7875 test_auth_null_cipher_snow_test_case_1(void)
7876 {
7877 	return test_mixed_auth_cipher(
7878 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7879 }
7880 
7881 static int
7882 test_verify_auth_null_cipher_snow_test_case_1(void)
7883 {
7884 	return test_mixed_auth_cipher(
7885 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7886 }
7887 
7888 static int
7889 test_auth_null_cipher_zuc_test_case_1(void)
7890 {
7891 	return test_mixed_auth_cipher(
7892 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7893 }
7894 
7895 static int
7896 test_verify_auth_null_cipher_zuc_test_case_1(void)
7897 {
7898 	return test_mixed_auth_cipher(
7899 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7900 }
7901 
7902 static int
7903 test_auth_snow_cipher_null_test_case_1(void)
7904 {
7905 	return test_mixed_auth_cipher(
7906 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7907 }
7908 
7909 static int
7910 test_verify_auth_snow_cipher_null_test_case_1(void)
7911 {
7912 	return test_mixed_auth_cipher(
7913 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7914 }
7915 
7916 static int
7917 test_auth_zuc_cipher_null_test_case_1(void)
7918 {
7919 	return test_mixed_auth_cipher(
7920 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7921 }
7922 
7923 static int
7924 test_verify_auth_zuc_cipher_null_test_case_1(void)
7925 {
7926 	return test_mixed_auth_cipher(
7927 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7928 }
7929 
7930 static int
7931 test_auth_null_cipher_aes_ctr_test_case_1(void)
7932 {
7933 	return test_mixed_auth_cipher(
7934 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7935 }
7936 
7937 static int
7938 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7939 {
7940 	return test_mixed_auth_cipher(
7941 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7942 }
7943 
7944 static int
7945 test_auth_aes_cmac_cipher_null_test_case_1(void)
7946 {
7947 	return test_mixed_auth_cipher(
7948 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7949 }
7950 
7951 static int
7952 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7953 {
7954 	return test_mixed_auth_cipher(
7955 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7956 }
7957 
7958 /* ***** AEAD algorithm Tests ***** */
7959 
7960 static int
7961 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7962 		enum rte_crypto_aead_operation op,
7963 		const uint8_t *key, const uint8_t key_len,
7964 		const uint16_t aad_len, const uint8_t auth_len,
7965 		uint8_t iv_len)
7966 {
7967 	uint8_t aead_key[key_len];
7968 
7969 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7970 	struct crypto_unittest_params *ut_params = &unittest_params;
7971 
7972 	memcpy(aead_key, key, key_len);
7973 
7974 	/* Setup AEAD Parameters */
7975 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7976 	ut_params->aead_xform.next = NULL;
7977 	ut_params->aead_xform.aead.algo = algo;
7978 	ut_params->aead_xform.aead.op = op;
7979 	ut_params->aead_xform.aead.key.data = aead_key;
7980 	ut_params->aead_xform.aead.key.length = key_len;
7981 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7982 	ut_params->aead_xform.aead.iv.length = iv_len;
7983 	ut_params->aead_xform.aead.digest_length = auth_len;
7984 	ut_params->aead_xform.aead.aad_length = aad_len;
7985 
7986 	debug_hexdump(stdout, "key:", key, key_len);
7987 
7988 	/* Create Crypto session*/
7989 	ut_params->sess = rte_cryptodev_sym_session_create(
7990 			ts_params->session_mpool);
7991 
7992 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7993 			&ut_params->aead_xform,
7994 			ts_params->session_priv_mpool);
7995 
7996 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7997 
7998 	return 0;
7999 }
8000 
8001 static int
8002 create_aead_xform(struct rte_crypto_op *op,
8003 		enum rte_crypto_aead_algorithm algo,
8004 		enum rte_crypto_aead_operation aead_op,
8005 		uint8_t *key, const uint8_t key_len,
8006 		const uint8_t aad_len, const uint8_t auth_len,
8007 		uint8_t iv_len)
8008 {
8009 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
8010 			"failed to allocate space for crypto transform");
8011 
8012 	struct rte_crypto_sym_op *sym_op = op->sym;
8013 
8014 	/* Setup AEAD Parameters */
8015 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
8016 	sym_op->xform->next = NULL;
8017 	sym_op->xform->aead.algo = algo;
8018 	sym_op->xform->aead.op = aead_op;
8019 	sym_op->xform->aead.key.data = key;
8020 	sym_op->xform->aead.key.length = key_len;
8021 	sym_op->xform->aead.iv.offset = IV_OFFSET;
8022 	sym_op->xform->aead.iv.length = iv_len;
8023 	sym_op->xform->aead.digest_length = auth_len;
8024 	sym_op->xform->aead.aad_length = aad_len;
8025 
8026 	debug_hexdump(stdout, "key:", key, key_len);
8027 
8028 	return 0;
8029 }
8030 
8031 static int
8032 create_aead_operation(enum rte_crypto_aead_operation op,
8033 		const struct aead_test_data *tdata)
8034 {
8035 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8036 	struct crypto_unittest_params *ut_params = &unittest_params;
8037 
8038 	uint8_t *plaintext, *ciphertext;
8039 	unsigned int aad_pad_len, plaintext_pad_len;
8040 
8041 	/* Generate Crypto op data structure */
8042 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8043 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8044 	TEST_ASSERT_NOT_NULL(ut_params->op,
8045 			"Failed to allocate symmetric crypto operation struct");
8046 
8047 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8048 
8049 	/* Append aad data */
8050 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8051 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
8052 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8053 				aad_pad_len);
8054 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8055 				"no room to append aad");
8056 
8057 		sym_op->aead.aad.phys_addr =
8058 				rte_pktmbuf_iova(ut_params->ibuf);
8059 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
8060 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
8061 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8062 			tdata->aad.len);
8063 
8064 		/* Append IV at the end of the crypto operation*/
8065 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8066 				uint8_t *, IV_OFFSET);
8067 
8068 		/* Copy IV 1 byte after the IV pointer, according to the API */
8069 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8070 		debug_hexdump(stdout, "iv:", iv_ptr,
8071 			tdata->iv.len);
8072 	} else {
8073 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 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 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8082 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8083 			tdata->aad.len);
8084 
8085 		/* Append IV at the end of the crypto operation*/
8086 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8087 				uint8_t *, IV_OFFSET);
8088 
8089 		if (tdata->iv.len == 0) {
8090 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8091 			debug_hexdump(stdout, "iv:", iv_ptr,
8092 				AES_GCM_J0_LENGTH);
8093 		} else {
8094 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8095 			debug_hexdump(stdout, "iv:", iv_ptr,
8096 				tdata->iv.len);
8097 		}
8098 	}
8099 
8100 	/* Append plaintext/ciphertext */
8101 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8102 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8103 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8104 				plaintext_pad_len);
8105 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8106 
8107 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8108 		debug_hexdump(stdout, "plaintext:", plaintext,
8109 				tdata->plaintext.len);
8110 
8111 		if (ut_params->obuf) {
8112 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8113 					ut_params->obuf,
8114 					plaintext_pad_len + aad_pad_len);
8115 			TEST_ASSERT_NOT_NULL(ciphertext,
8116 					"no room to append ciphertext");
8117 
8118 			memset(ciphertext + aad_pad_len, 0,
8119 					tdata->ciphertext.len);
8120 		}
8121 	} else {
8122 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8123 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8124 				plaintext_pad_len);
8125 		TEST_ASSERT_NOT_NULL(ciphertext,
8126 				"no room to append ciphertext");
8127 
8128 		memcpy(ciphertext, tdata->ciphertext.data,
8129 				tdata->ciphertext.len);
8130 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8131 				tdata->ciphertext.len);
8132 
8133 		if (ut_params->obuf) {
8134 			plaintext = (uint8_t *)rte_pktmbuf_append(
8135 					ut_params->obuf,
8136 					plaintext_pad_len + aad_pad_len);
8137 			TEST_ASSERT_NOT_NULL(plaintext,
8138 					"no room to append plaintext");
8139 
8140 			memset(plaintext + aad_pad_len, 0,
8141 					tdata->plaintext.len);
8142 		}
8143 	}
8144 
8145 	/* Append digest data */
8146 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8147 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8148 				ut_params->obuf ? ut_params->obuf :
8149 						ut_params->ibuf,
8150 						tdata->auth_tag.len);
8151 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8152 				"no room to append digest");
8153 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8154 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8155 				ut_params->obuf ? ut_params->obuf :
8156 						ut_params->ibuf,
8157 						plaintext_pad_len +
8158 						aad_pad_len);
8159 	} else {
8160 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8161 				ut_params->ibuf, tdata->auth_tag.len);
8162 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8163 				"no room to append digest");
8164 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8165 				ut_params->ibuf,
8166 				plaintext_pad_len + aad_pad_len);
8167 
8168 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8169 			tdata->auth_tag.len);
8170 		debug_hexdump(stdout, "digest:",
8171 			sym_op->aead.digest.data,
8172 			tdata->auth_tag.len);
8173 	}
8174 
8175 	sym_op->aead.data.length = tdata->plaintext.len;
8176 	sym_op->aead.data.offset = aad_pad_len;
8177 
8178 	return 0;
8179 }
8180 
8181 static int
8182 test_authenticated_encryption(const struct aead_test_data *tdata)
8183 {
8184 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8185 	struct crypto_unittest_params *ut_params = &unittest_params;
8186 
8187 	int retval;
8188 	uint8_t *ciphertext, *auth_tag;
8189 	uint16_t plaintext_pad_len;
8190 	uint32_t i;
8191 	struct rte_cryptodev_info dev_info;
8192 
8193 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8194 	uint64_t feat_flags = dev_info.feature_flags;
8195 
8196 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8197 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8198 		printf("Device doesn't support RAW data-path APIs.\n");
8199 		return TEST_SKIPPED;
8200 	}
8201 
8202 	/* Verify the capabilities */
8203 	struct rte_cryptodev_sym_capability_idx cap_idx;
8204 	const struct rte_cryptodev_symmetric_capability *capability;
8205 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8206 	cap_idx.algo.aead = tdata->algo;
8207 	capability = rte_cryptodev_sym_capability_get(
8208 			ts_params->valid_devs[0], &cap_idx);
8209 	if (capability == NULL)
8210 		return TEST_SKIPPED;
8211 	if (rte_cryptodev_sym_capability_check_aead(
8212 			capability, tdata->key.len, tdata->auth_tag.len,
8213 			tdata->aad.len, tdata->iv.len))
8214 		return TEST_SKIPPED;
8215 
8216 	/* Create AEAD session */
8217 	retval = create_aead_session(ts_params->valid_devs[0],
8218 			tdata->algo,
8219 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8220 			tdata->key.data, tdata->key.len,
8221 			tdata->aad.len, tdata->auth_tag.len,
8222 			tdata->iv.len);
8223 	if (retval < 0)
8224 		return retval;
8225 
8226 	if (tdata->aad.len > MBUF_SIZE) {
8227 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8228 		/* Populate full size of add data */
8229 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8230 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8231 	} else
8232 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8233 
8234 	/* clear mbuf payload */
8235 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8236 			rte_pktmbuf_tailroom(ut_params->ibuf));
8237 
8238 	/* Create AEAD operation */
8239 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8240 	if (retval < 0)
8241 		return retval;
8242 
8243 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8244 
8245 	ut_params->op->sym->m_src = ut_params->ibuf;
8246 
8247 	/* Process crypto operation */
8248 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8249 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8250 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8251 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8252 				ut_params->op, 0, 0, 0, 0);
8253 	else
8254 		TEST_ASSERT_NOT_NULL(
8255 			process_crypto_request(ts_params->valid_devs[0],
8256 			ut_params->op), "failed to process sym crypto op");
8257 
8258 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8259 			"crypto op processing failed");
8260 
8261 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8262 
8263 	if (ut_params->op->sym->m_dst) {
8264 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8265 				uint8_t *);
8266 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8267 				uint8_t *, plaintext_pad_len);
8268 	} else {
8269 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8270 				uint8_t *,
8271 				ut_params->op->sym->cipher.data.offset);
8272 		auth_tag = ciphertext + plaintext_pad_len;
8273 	}
8274 
8275 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8276 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8277 
8278 	/* Validate obuf */
8279 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8280 			ciphertext,
8281 			tdata->ciphertext.data,
8282 			tdata->ciphertext.len,
8283 			"Ciphertext data not as expected");
8284 
8285 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8286 			auth_tag,
8287 			tdata->auth_tag.data,
8288 			tdata->auth_tag.len,
8289 			"Generated auth tag not as expected");
8290 
8291 	return 0;
8292 
8293 }
8294 
8295 #ifdef RTE_LIB_SECURITY
8296 static int
8297 security_proto_supported(enum rte_security_session_action_type action,
8298 	enum rte_security_session_protocol proto)
8299 {
8300 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8301 
8302 	const struct rte_security_capability *capabilities;
8303 	const struct rte_security_capability *capability;
8304 	uint16_t i = 0;
8305 
8306 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8307 				rte_cryptodev_get_sec_ctx(
8308 				ts_params->valid_devs[0]);
8309 
8310 
8311 	capabilities = rte_security_capabilities_get(ctx);
8312 
8313 	if (capabilities == NULL)
8314 		return -ENOTSUP;
8315 
8316 	while ((capability = &capabilities[i++])->action !=
8317 			RTE_SECURITY_ACTION_TYPE_NONE) {
8318 		if (capability->action == action &&
8319 				capability->protocol == proto)
8320 			return 0;
8321 	}
8322 
8323 	return -ENOTSUP;
8324 }
8325 
8326 /* Basic algorithm run function for async inplace mode.
8327  * Creates a session from input parameters and runs one operation
8328  * on input_vec. Checks the output of the crypto operation against
8329  * output_vec.
8330  */
8331 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8332 			   enum rte_crypto_auth_operation opa,
8333 			   const uint8_t *input_vec, unsigned int input_vec_len,
8334 			   const uint8_t *output_vec,
8335 			   unsigned int output_vec_len,
8336 			   enum rte_crypto_cipher_algorithm cipher_alg,
8337 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8338 			   enum rte_crypto_auth_algorithm auth_alg,
8339 			   const uint8_t *auth_key, uint32_t auth_key_len,
8340 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8341 			   uint8_t packet_direction, uint8_t sn_size,
8342 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8343 {
8344 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8345 	struct crypto_unittest_params *ut_params = &unittest_params;
8346 	uint8_t *plaintext;
8347 	int ret = TEST_SUCCESS;
8348 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8349 				rte_cryptodev_get_sec_ctx(
8350 				ts_params->valid_devs[0]);
8351 
8352 	/* Verify the capabilities */
8353 	struct rte_security_capability_idx sec_cap_idx;
8354 
8355 	sec_cap_idx.action = ut_params->type;
8356 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8357 	sec_cap_idx.pdcp.domain = domain;
8358 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8359 		return TEST_SKIPPED;
8360 
8361 	/* Generate test mbuf data */
8362 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8363 
8364 	/* clear mbuf payload */
8365 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8366 			rte_pktmbuf_tailroom(ut_params->ibuf));
8367 
8368 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8369 						  input_vec_len);
8370 	memcpy(plaintext, input_vec, input_vec_len);
8371 
8372 	/* Out of place support */
8373 	if (oop) {
8374 		/*
8375 		 * For out-op-place we need to alloc another mbuf
8376 		 */
8377 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8378 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8379 	}
8380 
8381 	/* Setup Cipher Parameters */
8382 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8383 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8384 	ut_params->cipher_xform.cipher.op = opc;
8385 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8386 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8387 	ut_params->cipher_xform.cipher.iv.length =
8388 				packet_direction ? 4 : 0;
8389 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8390 
8391 	/* Setup HMAC Parameters if ICV header is required */
8392 	if (auth_alg != 0) {
8393 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8394 		ut_params->auth_xform.next = NULL;
8395 		ut_params->auth_xform.auth.algo = auth_alg;
8396 		ut_params->auth_xform.auth.op = opa;
8397 		ut_params->auth_xform.auth.key.data = auth_key;
8398 		ut_params->auth_xform.auth.key.length = auth_key_len;
8399 
8400 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8401 	} else {
8402 		ut_params->cipher_xform.next = NULL;
8403 	}
8404 
8405 	struct rte_security_session_conf sess_conf = {
8406 		.action_type = ut_params->type,
8407 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8408 		{.pdcp = {
8409 			.bearer = bearer,
8410 			.domain = domain,
8411 			.pkt_dir = packet_direction,
8412 			.sn_size = sn_size,
8413 			.hfn = packet_direction ? 0 : hfn,
8414 			/**
8415 			 * hfn can be set as pdcp_test_hfn[i]
8416 			 * if hfn_ovrd is not set. Here, PDCP
8417 			 * packet direction is just used to
8418 			 * run half of the cases with session
8419 			 * HFN and other half with per packet
8420 			 * HFN.
8421 			 */
8422 			.hfn_threshold = hfn_threshold,
8423 			.hfn_ovrd = packet_direction ? 1 : 0,
8424 			.sdap_enabled = sdap,
8425 		} },
8426 		.crypto_xform = &ut_params->cipher_xform
8427 	};
8428 
8429 	/* Create security session */
8430 	ut_params->sec_session = rte_security_session_create(ctx,
8431 				&sess_conf, ts_params->session_mpool,
8432 				ts_params->session_priv_mpool);
8433 
8434 	if (!ut_params->sec_session) {
8435 		printf("TestCase %s()-%d line %d failed %s: ",
8436 			__func__, i, __LINE__, "Failed to allocate session");
8437 		ret = TEST_FAILED;
8438 		goto on_err;
8439 	}
8440 
8441 	/* Generate crypto op data structure */
8442 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8443 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8444 	if (!ut_params->op) {
8445 		printf("TestCase %s()-%d line %d failed %s: ",
8446 			__func__, i, __LINE__,
8447 			"Failed to allocate symmetric crypto operation struct");
8448 		ret = TEST_FAILED;
8449 		goto on_err;
8450 	}
8451 
8452 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8453 					uint32_t *, IV_OFFSET);
8454 	*per_pkt_hfn = packet_direction ? hfn : 0;
8455 
8456 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8457 
8458 	/* set crypto operation source mbuf */
8459 	ut_params->op->sym->m_src = ut_params->ibuf;
8460 	if (oop)
8461 		ut_params->op->sym->m_dst = ut_params->obuf;
8462 
8463 	/* Process crypto operation */
8464 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8465 		== NULL) {
8466 		printf("TestCase %s()-%d line %d failed %s: ",
8467 			__func__, i, __LINE__,
8468 			"failed to process sym crypto op");
8469 		ret = TEST_FAILED;
8470 		goto on_err;
8471 	}
8472 
8473 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8474 		printf("TestCase %s()-%d line %d failed %s: ",
8475 			__func__, i, __LINE__, "crypto op processing failed");
8476 		ret = TEST_FAILED;
8477 		goto on_err;
8478 	}
8479 
8480 	/* Validate obuf */
8481 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8482 			uint8_t *);
8483 	if (oop) {
8484 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8485 				uint8_t *);
8486 	}
8487 
8488 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8489 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8490 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8491 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8492 		ret = TEST_FAILED;
8493 		goto on_err;
8494 	}
8495 
8496 on_err:
8497 	rte_crypto_op_free(ut_params->op);
8498 	ut_params->op = NULL;
8499 
8500 	if (ut_params->sec_session)
8501 		rte_security_session_destroy(ctx, ut_params->sec_session);
8502 	ut_params->sec_session = NULL;
8503 
8504 	rte_pktmbuf_free(ut_params->ibuf);
8505 	ut_params->ibuf = NULL;
8506 	if (oop) {
8507 		rte_pktmbuf_free(ut_params->obuf);
8508 		ut_params->obuf = NULL;
8509 	}
8510 
8511 	return ret;
8512 }
8513 
8514 static int
8515 test_pdcp_proto_SGL(int i, int oop,
8516 	enum rte_crypto_cipher_operation opc,
8517 	enum rte_crypto_auth_operation opa,
8518 	uint8_t *input_vec,
8519 	unsigned int input_vec_len,
8520 	uint8_t *output_vec,
8521 	unsigned int output_vec_len,
8522 	uint32_t fragsz,
8523 	uint32_t fragsz_oop)
8524 {
8525 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8526 	struct crypto_unittest_params *ut_params = &unittest_params;
8527 	uint8_t *plaintext;
8528 	struct rte_mbuf *buf, *buf_oop = NULL;
8529 	int ret = TEST_SUCCESS;
8530 	int to_trn = 0;
8531 	int to_trn_tbl[16];
8532 	int segs = 1;
8533 	unsigned int trn_data = 0;
8534 	struct rte_cryptodev_info dev_info;
8535 	uint64_t feat_flags;
8536 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8537 				rte_cryptodev_get_sec_ctx(
8538 				ts_params->valid_devs[0]);
8539 	struct rte_mbuf *temp_mbuf;
8540 
8541 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8542 	feat_flags = dev_info.feature_flags;
8543 
8544 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8545 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8546 		printf("Device does not support RAW data-path APIs.\n");
8547 		return -ENOTSUP;
8548 	}
8549 	/* Verify the capabilities */
8550 	struct rte_security_capability_idx sec_cap_idx;
8551 
8552 	sec_cap_idx.action = ut_params->type;
8553 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8554 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8555 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8556 		return TEST_SKIPPED;
8557 
8558 	if (fragsz > input_vec_len)
8559 		fragsz = input_vec_len;
8560 
8561 	uint16_t plaintext_len = fragsz;
8562 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8563 
8564 	if (fragsz_oop > output_vec_len)
8565 		frag_size_oop = output_vec_len;
8566 
8567 	int ecx = 0;
8568 	if (input_vec_len % fragsz != 0) {
8569 		if (input_vec_len / fragsz + 1 > 16)
8570 			return 1;
8571 	} else if (input_vec_len / fragsz > 16)
8572 		return 1;
8573 
8574 	/* Out of place support */
8575 	if (oop) {
8576 		/*
8577 		 * For out-op-place we need to alloc another mbuf
8578 		 */
8579 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8580 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8581 		buf_oop = ut_params->obuf;
8582 	}
8583 
8584 	/* Generate test mbuf data */
8585 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8586 
8587 	/* clear mbuf payload */
8588 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8589 			rte_pktmbuf_tailroom(ut_params->ibuf));
8590 
8591 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8592 						  plaintext_len);
8593 	memcpy(plaintext, input_vec, plaintext_len);
8594 	trn_data += plaintext_len;
8595 
8596 	buf = ut_params->ibuf;
8597 
8598 	/*
8599 	 * Loop until no more fragments
8600 	 */
8601 
8602 	while (trn_data < input_vec_len) {
8603 		++segs;
8604 		to_trn = (input_vec_len - trn_data < fragsz) ?
8605 				(input_vec_len - trn_data) : fragsz;
8606 
8607 		to_trn_tbl[ecx++] = to_trn;
8608 
8609 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8610 		buf = buf->next;
8611 
8612 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8613 				rte_pktmbuf_tailroom(buf));
8614 
8615 		/* OOP */
8616 		if (oop && !fragsz_oop) {
8617 			buf_oop->next =
8618 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8619 			buf_oop = buf_oop->next;
8620 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8621 					0, rte_pktmbuf_tailroom(buf_oop));
8622 			rte_pktmbuf_append(buf_oop, to_trn);
8623 		}
8624 
8625 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8626 				to_trn);
8627 
8628 		memcpy(plaintext, input_vec + trn_data, to_trn);
8629 		trn_data += to_trn;
8630 	}
8631 
8632 	ut_params->ibuf->nb_segs = segs;
8633 
8634 	segs = 1;
8635 	if (fragsz_oop && oop) {
8636 		to_trn = 0;
8637 		ecx = 0;
8638 
8639 		trn_data = frag_size_oop;
8640 		while (trn_data < output_vec_len) {
8641 			++segs;
8642 			to_trn =
8643 				(output_vec_len - trn_data <
8644 						frag_size_oop) ?
8645 				(output_vec_len - trn_data) :
8646 						frag_size_oop;
8647 
8648 			to_trn_tbl[ecx++] = to_trn;
8649 
8650 			buf_oop->next =
8651 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8652 			buf_oop = buf_oop->next;
8653 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8654 					0, rte_pktmbuf_tailroom(buf_oop));
8655 			rte_pktmbuf_append(buf_oop, to_trn);
8656 
8657 			trn_data += to_trn;
8658 		}
8659 		ut_params->obuf->nb_segs = segs;
8660 	}
8661 
8662 	/* Setup Cipher Parameters */
8663 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8664 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8665 	ut_params->cipher_xform.cipher.op = opc;
8666 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8667 	ut_params->cipher_xform.cipher.key.length =
8668 					pdcp_test_params[i].cipher_key_len;
8669 	ut_params->cipher_xform.cipher.iv.length = 0;
8670 
8671 	/* Setup HMAC Parameters if ICV header is required */
8672 	if (pdcp_test_params[i].auth_alg != 0) {
8673 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8674 		ut_params->auth_xform.next = NULL;
8675 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8676 		ut_params->auth_xform.auth.op = opa;
8677 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8678 		ut_params->auth_xform.auth.key.length =
8679 					pdcp_test_params[i].auth_key_len;
8680 
8681 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8682 	} else {
8683 		ut_params->cipher_xform.next = NULL;
8684 	}
8685 
8686 	struct rte_security_session_conf sess_conf = {
8687 		.action_type = ut_params->type,
8688 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8689 		{.pdcp = {
8690 			.bearer = pdcp_test_bearer[i],
8691 			.domain = pdcp_test_params[i].domain,
8692 			.pkt_dir = pdcp_test_packet_direction[i],
8693 			.sn_size = pdcp_test_data_sn_size[i],
8694 			.hfn = pdcp_test_hfn[i],
8695 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8696 			.hfn_ovrd = 0,
8697 		} },
8698 		.crypto_xform = &ut_params->cipher_xform
8699 	};
8700 
8701 	/* Create security session */
8702 	ut_params->sec_session = rte_security_session_create(ctx,
8703 				&sess_conf, ts_params->session_mpool,
8704 				ts_params->session_priv_mpool);
8705 
8706 	if (!ut_params->sec_session) {
8707 		printf("TestCase %s()-%d line %d failed %s: ",
8708 			__func__, i, __LINE__, "Failed to allocate session");
8709 		ret = TEST_FAILED;
8710 		goto on_err;
8711 	}
8712 
8713 	/* Generate crypto op data structure */
8714 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8715 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8716 	if (!ut_params->op) {
8717 		printf("TestCase %s()-%d line %d failed %s: ",
8718 			__func__, i, __LINE__,
8719 			"Failed to allocate symmetric crypto operation struct");
8720 		ret = TEST_FAILED;
8721 		goto on_err;
8722 	}
8723 
8724 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8725 
8726 	/* set crypto operation source mbuf */
8727 	ut_params->op->sym->m_src = ut_params->ibuf;
8728 	if (oop)
8729 		ut_params->op->sym->m_dst = ut_params->obuf;
8730 
8731 	/* Process crypto operation */
8732 	temp_mbuf = ut_params->op->sym->m_src;
8733 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8734 		/* filling lengths */
8735 		while (temp_mbuf) {
8736 			ut_params->op->sym->cipher.data.length
8737 				+= temp_mbuf->pkt_len;
8738 			ut_params->op->sym->auth.data.length
8739 				+= temp_mbuf->pkt_len;
8740 			temp_mbuf = temp_mbuf->next;
8741 		}
8742 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8743 			ut_params->op, 1, 1, 0, 0);
8744 	} else {
8745 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8746 							ut_params->op);
8747 	}
8748 	if (ut_params->op == NULL) {
8749 		printf("TestCase %s()-%d line %d failed %s: ",
8750 			__func__, i, __LINE__,
8751 			"failed to process sym crypto op");
8752 		ret = TEST_FAILED;
8753 		goto on_err;
8754 	}
8755 
8756 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8757 		printf("TestCase %s()-%d line %d failed %s: ",
8758 			__func__, i, __LINE__, "crypto op processing failed");
8759 		ret = TEST_FAILED;
8760 		goto on_err;
8761 	}
8762 
8763 	/* Validate obuf */
8764 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8765 			uint8_t *);
8766 	if (oop) {
8767 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8768 				uint8_t *);
8769 	}
8770 	if (fragsz_oop)
8771 		fragsz = frag_size_oop;
8772 	if (memcmp(ciphertext, output_vec, fragsz)) {
8773 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8774 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8775 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8776 		ret = TEST_FAILED;
8777 		goto on_err;
8778 	}
8779 
8780 	buf = ut_params->op->sym->m_src->next;
8781 	if (oop)
8782 		buf = ut_params->op->sym->m_dst->next;
8783 
8784 	unsigned int off = fragsz;
8785 
8786 	ecx = 0;
8787 	while (buf) {
8788 		ciphertext = rte_pktmbuf_mtod(buf,
8789 				uint8_t *);
8790 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8791 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8792 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8793 			rte_hexdump(stdout, "reference", output_vec + off,
8794 					to_trn_tbl[ecx]);
8795 			ret = TEST_FAILED;
8796 			goto on_err;
8797 		}
8798 		off += to_trn_tbl[ecx++];
8799 		buf = buf->next;
8800 	}
8801 on_err:
8802 	rte_crypto_op_free(ut_params->op);
8803 	ut_params->op = NULL;
8804 
8805 	if (ut_params->sec_session)
8806 		rte_security_session_destroy(ctx, ut_params->sec_session);
8807 	ut_params->sec_session = NULL;
8808 
8809 	rte_pktmbuf_free(ut_params->ibuf);
8810 	ut_params->ibuf = NULL;
8811 	if (oop) {
8812 		rte_pktmbuf_free(ut_params->obuf);
8813 		ut_params->obuf = NULL;
8814 	}
8815 
8816 	return ret;
8817 }
8818 
8819 int
8820 test_pdcp_proto_cplane_encap(int i)
8821 {
8822 	return test_pdcp_proto(
8823 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8824 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8825 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8826 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8827 		pdcp_test_params[i].cipher_key_len,
8828 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8829 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8830 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8831 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8832 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8833 }
8834 
8835 int
8836 test_pdcp_proto_uplane_encap(int i)
8837 {
8838 	return test_pdcp_proto(
8839 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8840 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8841 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8842 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8843 		pdcp_test_params[i].cipher_key_len,
8844 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8845 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8846 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8847 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8848 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8849 }
8850 
8851 int
8852 test_pdcp_proto_uplane_encap_with_int(int i)
8853 {
8854 	return test_pdcp_proto(
8855 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8856 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8857 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8858 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8859 		pdcp_test_params[i].cipher_key_len,
8860 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8861 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8862 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8863 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8864 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8865 }
8866 
8867 int
8868 test_pdcp_proto_cplane_decap(int i)
8869 {
8870 	return test_pdcp_proto(
8871 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8872 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8873 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8874 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8875 		pdcp_test_params[i].cipher_key_len,
8876 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8877 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8878 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8879 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8880 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8881 }
8882 
8883 int
8884 test_pdcp_proto_uplane_decap(int i)
8885 {
8886 	return test_pdcp_proto(
8887 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8888 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8889 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8890 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8891 		pdcp_test_params[i].cipher_key_len,
8892 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8893 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8894 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8895 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8896 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8897 }
8898 
8899 int
8900 test_pdcp_proto_uplane_decap_with_int(int i)
8901 {
8902 	return test_pdcp_proto(
8903 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8904 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8905 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8906 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8907 		pdcp_test_params[i].cipher_key_len,
8908 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8909 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8910 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8911 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8912 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8913 }
8914 
8915 static int
8916 test_PDCP_PROTO_SGL_in_place_32B(void)
8917 {
8918 	/* i can be used for running any PDCP case
8919 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8920 	 */
8921 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8922 	return test_pdcp_proto_SGL(i, IN_PLACE,
8923 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8924 			RTE_CRYPTO_AUTH_OP_GENERATE,
8925 			pdcp_test_data_in[i],
8926 			pdcp_test_data_in_len[i],
8927 			pdcp_test_data_out[i],
8928 			pdcp_test_data_in_len[i]+4,
8929 			32, 0);
8930 }
8931 static int
8932 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8933 {
8934 	/* i can be used for running any PDCP case
8935 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8936 	 */
8937 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8938 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8939 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8940 			RTE_CRYPTO_AUTH_OP_GENERATE,
8941 			pdcp_test_data_in[i],
8942 			pdcp_test_data_in_len[i],
8943 			pdcp_test_data_out[i],
8944 			pdcp_test_data_in_len[i]+4,
8945 			32, 128);
8946 }
8947 static int
8948 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8949 {
8950 	/* i can be used for running any PDCP case
8951 	 * In this case it is uplane 18-bit AES DL encap
8952 	 */
8953 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8954 			+ DOWNLINK;
8955 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8956 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8957 			RTE_CRYPTO_AUTH_OP_GENERATE,
8958 			pdcp_test_data_in[i],
8959 			pdcp_test_data_in_len[i],
8960 			pdcp_test_data_out[i],
8961 			pdcp_test_data_in_len[i],
8962 			32, 40);
8963 }
8964 static int
8965 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8966 {
8967 	/* i can be used for running any PDCP case
8968 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8969 	 */
8970 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8971 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8972 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8973 			RTE_CRYPTO_AUTH_OP_GENERATE,
8974 			pdcp_test_data_in[i],
8975 			pdcp_test_data_in_len[i],
8976 			pdcp_test_data_out[i],
8977 			pdcp_test_data_in_len[i]+4,
8978 			128, 32);
8979 }
8980 
8981 static int
8982 test_PDCP_SDAP_PROTO_encap_all(void)
8983 {
8984 	int i = 0, size = 0;
8985 	int err, all_err = TEST_SUCCESS;
8986 	const struct pdcp_sdap_test *cur_test;
8987 
8988 	size = RTE_DIM(list_pdcp_sdap_tests);
8989 
8990 	for (i = 0; i < size; i++) {
8991 		cur_test = &list_pdcp_sdap_tests[i];
8992 		err = test_pdcp_proto(
8993 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8994 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8995 			cur_test->in_len, cur_test->data_out,
8996 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8997 			cur_test->param.cipher_alg, cur_test->cipher_key,
8998 			cur_test->param.cipher_key_len,
8999 			cur_test->param.auth_alg,
9000 			cur_test->auth_key, cur_test->param.auth_key_len,
9001 			cur_test->bearer, cur_test->param.domain,
9002 			cur_test->packet_direction, cur_test->sn_size,
9003 			cur_test->hfn,
9004 			cur_test->hfn_threshold, SDAP_ENABLED);
9005 		if (err) {
9006 			printf("\t%d) %s: Encapsulation failed\n",
9007 					cur_test->test_idx,
9008 					cur_test->param.name);
9009 			err = TEST_FAILED;
9010 		} else {
9011 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
9012 					cur_test->param.name);
9013 			err = TEST_SUCCESS;
9014 		}
9015 		all_err += err;
9016 	}
9017 
9018 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9019 
9020 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9021 }
9022 
9023 static int
9024 test_PDCP_PROTO_short_mac(void)
9025 {
9026 	int i = 0, size = 0;
9027 	int err, all_err = TEST_SUCCESS;
9028 	const struct pdcp_short_mac_test *cur_test;
9029 
9030 	size = RTE_DIM(list_pdcp_smac_tests);
9031 
9032 	for (i = 0; i < size; i++) {
9033 		cur_test = &list_pdcp_smac_tests[i];
9034 		err = test_pdcp_proto(
9035 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9036 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9037 			cur_test->in_len, cur_test->data_out,
9038 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9039 			RTE_CRYPTO_CIPHER_NULL, NULL,
9040 			0, cur_test->param.auth_alg,
9041 			cur_test->auth_key, cur_test->param.auth_key_len,
9042 			0, cur_test->param.domain, 0, 0,
9043 			0, 0, 0);
9044 		if (err) {
9045 			printf("\t%d) %s: Short MAC test failed\n",
9046 					cur_test->test_idx,
9047 					cur_test->param.name);
9048 			err = TEST_FAILED;
9049 		} else {
9050 			printf("\t%d) %s: Short MAC test PASS\n",
9051 					cur_test->test_idx,
9052 					cur_test->param.name);
9053 			rte_hexdump(stdout, "MAC I",
9054 				    cur_test->data_out + cur_test->in_len + 2,
9055 				    2);
9056 			err = TEST_SUCCESS;
9057 		}
9058 		all_err += err;
9059 	}
9060 
9061 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9062 
9063 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9064 
9065 }
9066 
9067 static int
9068 test_PDCP_SDAP_PROTO_decap_all(void)
9069 {
9070 	int i = 0, size = 0;
9071 	int err, all_err = TEST_SUCCESS;
9072 	const struct pdcp_sdap_test *cur_test;
9073 
9074 	size = RTE_DIM(list_pdcp_sdap_tests);
9075 
9076 	for (i = 0; i < size; i++) {
9077 		cur_test = &list_pdcp_sdap_tests[i];
9078 		err = test_pdcp_proto(
9079 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9080 			RTE_CRYPTO_AUTH_OP_VERIFY,
9081 			cur_test->data_out,
9082 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9083 			cur_test->data_in, cur_test->in_len,
9084 			cur_test->param.cipher_alg,
9085 			cur_test->cipher_key, cur_test->param.cipher_key_len,
9086 			cur_test->param.auth_alg, cur_test->auth_key,
9087 			cur_test->param.auth_key_len, cur_test->bearer,
9088 			cur_test->param.domain, cur_test->packet_direction,
9089 			cur_test->sn_size, cur_test->hfn,
9090 			cur_test->hfn_threshold, SDAP_ENABLED);
9091 		if (err) {
9092 			printf("\t%d) %s: Decapsulation failed\n",
9093 					cur_test->test_idx,
9094 					cur_test->param.name);
9095 			err = TEST_FAILED;
9096 		} else {
9097 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9098 					cur_test->param.name);
9099 			err = TEST_SUCCESS;
9100 		}
9101 		all_err += err;
9102 	}
9103 
9104 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9105 
9106 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9107 }
9108 
9109 static int
9110 test_ipsec_proto_process(const struct ipsec_test_data td[],
9111 			 struct ipsec_test_data res_d[],
9112 			 int nb_td,
9113 			 bool silent,
9114 			 const struct ipsec_test_flags *flags)
9115 {
9116 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9117 	struct crypto_unittest_params *ut_params = &unittest_params;
9118 	struct rte_security_capability_idx sec_cap_idx;
9119 	const struct rte_security_capability *sec_cap;
9120 	struct rte_security_ipsec_xform ipsec_xform;
9121 	uint8_t dev_id = ts_params->valid_devs[0];
9122 	enum rte_security_ipsec_sa_direction dir;
9123 	struct ipsec_test_data *res_d_tmp = NULL;
9124 	uint32_t src = RTE_IPV4(192, 168, 1, 0);
9125 	uint32_t dst = RTE_IPV4(192, 168, 1, 1);
9126 	int salt_len, i, ret = TEST_SUCCESS;
9127 	struct rte_security_ctx *ctx;
9128 	uint8_t *input_text;
9129 	uint32_t verify;
9130 
9131 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9132 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9133 
9134 	/* Use first test data to create session */
9135 
9136 	/* Copy IPsec xform */
9137 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9138 
9139 	dir = ipsec_xform.direction;
9140 	verify = flags->tunnel_hdr_verify;
9141 
9142 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9143 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9144 			src += 1;
9145 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9146 			dst += 1;
9147 	}
9148 
9149 	memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
9150 	memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
9151 
9152 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9153 
9154 	sec_cap_idx.action = ut_params->type;
9155 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9156 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9157 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9158 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9159 
9160 	if (flags->udp_encap)
9161 		ipsec_xform.options.udp_encap = 1;
9162 
9163 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9164 	if (sec_cap == NULL)
9165 		return TEST_SKIPPED;
9166 
9167 	/* Copy cipher session parameters */
9168 	if (td[0].aead) {
9169 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9170 		       sizeof(ut_params->aead_xform));
9171 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9172 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9173 
9174 		/* Verify crypto capabilities */
9175 		if (test_ipsec_crypto_caps_aead_verify(
9176 				sec_cap,
9177 				&ut_params->aead_xform) != 0) {
9178 			if (!silent)
9179 				RTE_LOG(INFO, USER1,
9180 					"Crypto capabilities not supported\n");
9181 			return TEST_SKIPPED;
9182 		}
9183 	} else {
9184 		/* Only AEAD supported now */
9185 		return TEST_SKIPPED;
9186 	}
9187 
9188 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9189 		return TEST_SKIPPED;
9190 
9191 	salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9192 	memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9193 
9194 	struct rte_security_session_conf sess_conf = {
9195 		.action_type = ut_params->type,
9196 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9197 		.ipsec = ipsec_xform,
9198 		.crypto_xform = &ut_params->aead_xform,
9199 	};
9200 
9201 	/* Create security session */
9202 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9203 					ts_params->session_mpool,
9204 					ts_params->session_priv_mpool);
9205 
9206 	if (ut_params->sec_session == NULL)
9207 		return TEST_SKIPPED;
9208 
9209 	for (i = 0; i < nb_td; i++) {
9210 		/* Setup source mbuf payload */
9211 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9212 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9213 				rte_pktmbuf_tailroom(ut_params->ibuf));
9214 
9215 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9216 				td[i].input_text.len);
9217 
9218 		memcpy(input_text, td[i].input_text.data,
9219 		       td[i].input_text.len);
9220 
9221 		/* Generate crypto op data structure */
9222 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9223 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9224 		if (!ut_params->op) {
9225 			printf("TestCase %s line %d: %s\n",
9226 				__func__, __LINE__,
9227 				"failed to allocate crypto op");
9228 			ret = TEST_FAILED;
9229 			goto crypto_op_free;
9230 		}
9231 
9232 		/* Attach session to operation */
9233 		rte_security_attach_session(ut_params->op,
9234 					    ut_params->sec_session);
9235 
9236 		/* Set crypto operation mbufs */
9237 		ut_params->op->sym->m_src = ut_params->ibuf;
9238 		ut_params->op->sym->m_dst = NULL;
9239 
9240 		/* Copy IV in crypto operation when IV generation is disabled */
9241 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9242 		    ipsec_xform.options.iv_gen_disable == 1) {
9243 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9244 								uint8_t *,
9245 								IV_OFFSET);
9246 			int len;
9247 
9248 			if (td[i].aead)
9249 				len = td[i].xform.aead.aead.iv.length;
9250 			else
9251 				len = td[i].xform.chain.cipher.cipher.iv.length;
9252 
9253 			memcpy(iv, td[i].iv.data, len);
9254 		}
9255 
9256 		/* Process crypto operation */
9257 		process_crypto_request(dev_id, ut_params->op);
9258 
9259 		ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9260 		if (ret != TEST_SUCCESS)
9261 			goto crypto_op_free;
9262 
9263 		if (res_d != NULL)
9264 			res_d_tmp = &res_d[i];
9265 
9266 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9267 					      res_d_tmp, silent, flags);
9268 		if (ret != TEST_SUCCESS)
9269 			goto crypto_op_free;
9270 
9271 		rte_crypto_op_free(ut_params->op);
9272 		ut_params->op = NULL;
9273 
9274 		rte_pktmbuf_free(ut_params->ibuf);
9275 		ut_params->ibuf = NULL;
9276 	}
9277 
9278 crypto_op_free:
9279 	rte_crypto_op_free(ut_params->op);
9280 	ut_params->op = NULL;
9281 
9282 	rte_pktmbuf_free(ut_params->ibuf);
9283 	ut_params->ibuf = NULL;
9284 
9285 	if (ut_params->sec_session)
9286 		rte_security_session_destroy(ctx, ut_params->sec_session);
9287 	ut_params->sec_session = NULL;
9288 
9289 	return ret;
9290 }
9291 
9292 static int
9293 test_ipsec_proto_known_vec(const void *test_data)
9294 {
9295 	struct ipsec_test_data td_outb;
9296 	struct ipsec_test_flags flags;
9297 
9298 	memset(&flags, 0, sizeof(flags));
9299 
9300 	memcpy(&td_outb, test_data, sizeof(td_outb));
9301 
9302 	/* Disable IV gen to be able to test with known vectors */
9303 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9304 
9305 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9306 }
9307 
9308 static int
9309 test_ipsec_proto_known_vec_inb(const void *td_outb)
9310 {
9311 	struct ipsec_test_flags flags;
9312 	struct ipsec_test_data td_inb;
9313 
9314 	memset(&flags, 0, sizeof(flags));
9315 
9316 	test_ipsec_td_in_from_out(td_outb, &td_inb);
9317 
9318 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9319 }
9320 
9321 static int
9322 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9323 {
9324 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9325 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9326 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9327 	int ret;
9328 
9329 	if (flags->iv_gen ||
9330 	    flags->sa_expiry_pkts_soft ||
9331 	    flags->sa_expiry_pkts_hard)
9332 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9333 
9334 	for (i = 0; i < RTE_DIM(aead_list); i++) {
9335 		test_ipsec_td_prepare(&aead_list[i],
9336 				      NULL,
9337 				      flags,
9338 				      td_outb,
9339 				      nb_pkts);
9340 
9341 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9342 					       flags);
9343 		if (ret == TEST_SKIPPED)
9344 			continue;
9345 
9346 		if (ret == TEST_FAILED)
9347 			return TEST_FAILED;
9348 
9349 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9350 
9351 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9352 					       flags);
9353 		if (ret == TEST_SKIPPED)
9354 			continue;
9355 
9356 		if (ret == TEST_FAILED)
9357 			return TEST_FAILED;
9358 
9359 		if (flags->display_alg)
9360 			test_ipsec_display_alg(&aead_list[i], NULL);
9361 
9362 		pass_cnt++;
9363 	}
9364 
9365 	if (pass_cnt > 0)
9366 		return TEST_SUCCESS;
9367 	else
9368 		return TEST_SKIPPED;
9369 }
9370 
9371 static int
9372 test_ipsec_proto_display_list(const void *data __rte_unused)
9373 {
9374 	struct ipsec_test_flags flags;
9375 
9376 	memset(&flags, 0, sizeof(flags));
9377 
9378 	flags.display_alg = true;
9379 
9380 	return test_ipsec_proto_all(&flags);
9381 }
9382 
9383 static int
9384 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9385 {
9386 	struct ipsec_test_flags flags;
9387 
9388 	memset(&flags, 0, sizeof(flags));
9389 
9390 	flags.iv_gen = true;
9391 
9392 	return test_ipsec_proto_all(&flags);
9393 }
9394 
9395 static int
9396 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9397 {
9398 	struct ipsec_test_flags flags;
9399 
9400 	memset(&flags, 0, sizeof(flags));
9401 
9402 	flags.sa_expiry_pkts_soft = true;
9403 
9404 	return test_ipsec_proto_all(&flags);
9405 }
9406 
9407 static int
9408 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9409 {
9410 	struct ipsec_test_flags flags;
9411 
9412 	memset(&flags, 0, sizeof(flags));
9413 
9414 	flags.sa_expiry_pkts_hard = true;
9415 
9416 	return test_ipsec_proto_all(&flags);
9417 }
9418 
9419 static int
9420 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9421 {
9422 	struct ipsec_test_flags flags;
9423 
9424 	memset(&flags, 0, sizeof(flags));
9425 
9426 	flags.icv_corrupt = true;
9427 
9428 	return test_ipsec_proto_all(&flags);
9429 }
9430 
9431 static int
9432 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9433 {
9434 	struct ipsec_test_flags flags;
9435 
9436 	memset(&flags, 0, sizeof(flags));
9437 
9438 	flags.udp_encap = true;
9439 
9440 	return test_ipsec_proto_all(&flags);
9441 }
9442 
9443 static int
9444 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9445 {
9446 	struct ipsec_test_flags flags;
9447 
9448 	memset(&flags, 0, sizeof(flags));
9449 
9450 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9451 
9452 	return test_ipsec_proto_all(&flags);
9453 }
9454 
9455 static int
9456 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9457 {
9458 	struct ipsec_test_flags flags;
9459 
9460 	memset(&flags, 0, sizeof(flags));
9461 
9462 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9463 
9464 	return test_ipsec_proto_all(&flags);
9465 }
9466 
9467 static int
9468 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9469 {
9470 	struct ipsec_test_flags flags;
9471 
9472 	memset(&flags, 0, sizeof(flags));
9473 
9474 	flags.udp_encap = true;
9475 	flags.udp_ports_verify = true;
9476 
9477 	return test_ipsec_proto_all(&flags);
9478 }
9479 
9480 static int
9481 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9482 {
9483 	struct ipsec_test_flags flags;
9484 
9485 	memset(&flags, 0, sizeof(flags));
9486 
9487 	flags.ip_csum = true;
9488 
9489 	return test_ipsec_proto_all(&flags);
9490 }
9491 
9492 static int
9493 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9494 {
9495 	struct ipsec_test_flags flags;
9496 
9497 	memset(&flags, 0, sizeof(flags));
9498 
9499 	flags.l4_csum = true;
9500 
9501 	return test_ipsec_proto_all(&flags);
9502 }
9503 
9504 static int
9505 test_PDCP_PROTO_all(void)
9506 {
9507 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9508 	struct crypto_unittest_params *ut_params = &unittest_params;
9509 	struct rte_cryptodev_info dev_info;
9510 	int status;
9511 
9512 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9513 	uint64_t feat_flags = dev_info.feature_flags;
9514 
9515 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9516 		return TEST_SKIPPED;
9517 
9518 	/* Set action type */
9519 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9520 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9521 		gbl_action_type;
9522 
9523 	if (security_proto_supported(ut_params->type,
9524 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
9525 		return TEST_SKIPPED;
9526 
9527 	status = test_PDCP_PROTO_cplane_encap_all();
9528 	status += test_PDCP_PROTO_cplane_decap_all();
9529 	status += test_PDCP_PROTO_uplane_encap_all();
9530 	status += test_PDCP_PROTO_uplane_decap_all();
9531 	status += test_PDCP_PROTO_SGL_in_place_32B();
9532 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
9533 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
9534 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
9535 	status += test_PDCP_SDAP_PROTO_encap_all();
9536 	status += test_PDCP_SDAP_PROTO_decap_all();
9537 	status += test_PDCP_PROTO_short_mac();
9538 
9539 	if (status)
9540 		return TEST_FAILED;
9541 	else
9542 		return TEST_SUCCESS;
9543 }
9544 
9545 static int
9546 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9547 {
9548 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9549 	struct crypto_unittest_params *ut_params = &unittest_params;
9550 	uint8_t *plaintext, *ciphertext;
9551 	uint8_t *iv_ptr;
9552 	int32_t cipher_len, crc_len;
9553 	uint32_t crc_data_len;
9554 	int ret = TEST_SUCCESS;
9555 
9556 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9557 					rte_cryptodev_get_sec_ctx(
9558 						ts_params->valid_devs[0]);
9559 
9560 	/* Verify the capabilities */
9561 	struct rte_security_capability_idx sec_cap_idx;
9562 	const struct rte_security_capability *sec_cap;
9563 	const struct rte_cryptodev_capabilities *crypto_cap;
9564 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9565 	int j = 0;
9566 
9567 	sec_cap_idx.action = ut_params->type;
9568 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9569 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9570 
9571 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9572 	if (sec_cap == NULL)
9573 		return TEST_SKIPPED;
9574 
9575 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9576 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9577 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9578 				crypto_cap->sym.xform_type ==
9579 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9580 				crypto_cap->sym.cipher.algo ==
9581 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9582 			sym_cap = &crypto_cap->sym;
9583 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9584 						d_td->key.len,
9585 						d_td->iv.len) == 0)
9586 				break;
9587 		}
9588 	}
9589 
9590 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9591 		return TEST_SKIPPED;
9592 
9593 	/* Setup source mbuf payload */
9594 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9595 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9596 			rte_pktmbuf_tailroom(ut_params->ibuf));
9597 
9598 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9599 			d_td->ciphertext.len);
9600 
9601 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9602 
9603 	/* Setup cipher session parameters */
9604 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9605 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9606 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9607 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9608 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9609 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9610 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9611 	ut_params->cipher_xform.next = NULL;
9612 
9613 	/* Setup DOCSIS session parameters */
9614 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9615 
9616 	struct rte_security_session_conf sess_conf = {
9617 		.action_type = ut_params->type,
9618 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9619 		.docsis = ut_params->docsis_xform,
9620 		.crypto_xform = &ut_params->cipher_xform,
9621 	};
9622 
9623 	/* Create security session */
9624 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9625 					ts_params->session_mpool,
9626 					ts_params->session_priv_mpool);
9627 
9628 	if (!ut_params->sec_session) {
9629 		printf("TestCase %s(%d) line %d: %s\n",
9630 			__func__, i, __LINE__, "failed to allocate session");
9631 		ret = TEST_FAILED;
9632 		goto on_err;
9633 	}
9634 
9635 	/* Generate crypto op data structure */
9636 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9637 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9638 	if (!ut_params->op) {
9639 		printf("TestCase %s(%d) line %d: %s\n",
9640 			__func__, i, __LINE__,
9641 			"failed to allocate symmetric crypto operation");
9642 		ret = TEST_FAILED;
9643 		goto on_err;
9644 	}
9645 
9646 	/* Setup CRC operation parameters */
9647 	crc_len = d_td->ciphertext.no_crc == false ?
9648 			(d_td->ciphertext.len -
9649 				d_td->ciphertext.crc_offset -
9650 				RTE_ETHER_CRC_LEN) :
9651 			0;
9652 	crc_len = crc_len > 0 ? crc_len : 0;
9653 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9654 	ut_params->op->sym->auth.data.length = crc_len;
9655 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9656 
9657 	/* Setup cipher operation parameters */
9658 	cipher_len = d_td->ciphertext.no_cipher == false ?
9659 			(d_td->ciphertext.len -
9660 				d_td->ciphertext.cipher_offset) :
9661 			0;
9662 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9663 	ut_params->op->sym->cipher.data.length = cipher_len;
9664 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9665 
9666 	/* Setup cipher IV */
9667 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9668 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9669 
9670 	/* Attach session to operation */
9671 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9672 
9673 	/* Set crypto operation mbufs */
9674 	ut_params->op->sym->m_src = ut_params->ibuf;
9675 	ut_params->op->sym->m_dst = NULL;
9676 
9677 	/* Process crypto operation */
9678 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9679 			NULL) {
9680 		printf("TestCase %s(%d) line %d: %s\n",
9681 			__func__, i, __LINE__,
9682 			"failed to process security crypto op");
9683 		ret = TEST_FAILED;
9684 		goto on_err;
9685 	}
9686 
9687 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9688 		printf("TestCase %s(%d) line %d: %s\n",
9689 			__func__, i, __LINE__, "crypto op processing failed");
9690 		ret = TEST_FAILED;
9691 		goto on_err;
9692 	}
9693 
9694 	/* Validate plaintext */
9695 	plaintext = ciphertext;
9696 
9697 	if (memcmp(plaintext, d_td->plaintext.data,
9698 			d_td->plaintext.len - crc_data_len)) {
9699 		printf("TestCase %s(%d) line %d: %s\n",
9700 			__func__, i, __LINE__, "plaintext not as expected\n");
9701 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
9702 				d_td->plaintext.len);
9703 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9704 		ret = TEST_FAILED;
9705 		goto on_err;
9706 	}
9707 
9708 on_err:
9709 	rte_crypto_op_free(ut_params->op);
9710 	ut_params->op = NULL;
9711 
9712 	if (ut_params->sec_session)
9713 		rte_security_session_destroy(ctx, ut_params->sec_session);
9714 	ut_params->sec_session = NULL;
9715 
9716 	rte_pktmbuf_free(ut_params->ibuf);
9717 	ut_params->ibuf = NULL;
9718 
9719 	return ret;
9720 }
9721 
9722 static int
9723 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9724 {
9725 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9726 	struct crypto_unittest_params *ut_params = &unittest_params;
9727 	uint8_t *plaintext, *ciphertext;
9728 	uint8_t *iv_ptr;
9729 	int32_t cipher_len, crc_len;
9730 	int ret = TEST_SUCCESS;
9731 
9732 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9733 					rte_cryptodev_get_sec_ctx(
9734 						ts_params->valid_devs[0]);
9735 
9736 	/* Verify the capabilities */
9737 	struct rte_security_capability_idx sec_cap_idx;
9738 	const struct rte_security_capability *sec_cap;
9739 	const struct rte_cryptodev_capabilities *crypto_cap;
9740 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9741 	int j = 0;
9742 
9743 	sec_cap_idx.action = ut_params->type;
9744 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9745 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9746 
9747 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9748 	if (sec_cap == NULL)
9749 		return TEST_SKIPPED;
9750 
9751 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9752 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9753 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9754 				crypto_cap->sym.xform_type ==
9755 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9756 				crypto_cap->sym.cipher.algo ==
9757 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9758 			sym_cap = &crypto_cap->sym;
9759 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9760 						d_td->key.len,
9761 						d_td->iv.len) == 0)
9762 				break;
9763 		}
9764 	}
9765 
9766 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9767 		return TEST_SKIPPED;
9768 
9769 	/* Setup source mbuf payload */
9770 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9771 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9772 			rte_pktmbuf_tailroom(ut_params->ibuf));
9773 
9774 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9775 			d_td->plaintext.len);
9776 
9777 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9778 
9779 	/* Setup cipher session parameters */
9780 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9781 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9782 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9783 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9784 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9785 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9786 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9787 	ut_params->cipher_xform.next = NULL;
9788 
9789 	/* Setup DOCSIS session parameters */
9790 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9791 
9792 	struct rte_security_session_conf sess_conf = {
9793 		.action_type = ut_params->type,
9794 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9795 		.docsis = ut_params->docsis_xform,
9796 		.crypto_xform = &ut_params->cipher_xform,
9797 	};
9798 
9799 	/* Create security session */
9800 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9801 					ts_params->session_mpool,
9802 					ts_params->session_priv_mpool);
9803 
9804 	if (!ut_params->sec_session) {
9805 		printf("TestCase %s(%d) line %d: %s\n",
9806 			__func__, i, __LINE__, "failed to allocate session");
9807 		ret = TEST_FAILED;
9808 		goto on_err;
9809 	}
9810 
9811 	/* Generate crypto op data structure */
9812 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9813 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9814 	if (!ut_params->op) {
9815 		printf("TestCase %s(%d) line %d: %s\n",
9816 			__func__, i, __LINE__,
9817 			"failed to allocate security crypto operation");
9818 		ret = TEST_FAILED;
9819 		goto on_err;
9820 	}
9821 
9822 	/* Setup CRC operation parameters */
9823 	crc_len = d_td->plaintext.no_crc == false ?
9824 			(d_td->plaintext.len -
9825 				d_td->plaintext.crc_offset -
9826 				RTE_ETHER_CRC_LEN) :
9827 			0;
9828 	crc_len = crc_len > 0 ? crc_len : 0;
9829 	ut_params->op->sym->auth.data.length = crc_len;
9830 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9831 
9832 	/* Setup cipher operation parameters */
9833 	cipher_len = d_td->plaintext.no_cipher == false ?
9834 			(d_td->plaintext.len -
9835 				d_td->plaintext.cipher_offset) :
9836 			0;
9837 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9838 	ut_params->op->sym->cipher.data.length = cipher_len;
9839 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9840 
9841 	/* Setup cipher IV */
9842 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9843 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9844 
9845 	/* Attach session to operation */
9846 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9847 
9848 	/* Set crypto operation mbufs */
9849 	ut_params->op->sym->m_src = ut_params->ibuf;
9850 	ut_params->op->sym->m_dst = NULL;
9851 
9852 	/* Process crypto operation */
9853 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9854 			NULL) {
9855 		printf("TestCase %s(%d) line %d: %s\n",
9856 			__func__, i, __LINE__,
9857 			"failed to process security crypto op");
9858 		ret = TEST_FAILED;
9859 		goto on_err;
9860 	}
9861 
9862 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9863 		printf("TestCase %s(%d) line %d: %s\n",
9864 			__func__, i, __LINE__, "crypto op processing failed");
9865 		ret = TEST_FAILED;
9866 		goto on_err;
9867 	}
9868 
9869 	/* Validate ciphertext */
9870 	ciphertext = plaintext;
9871 
9872 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9873 		printf("TestCase %s(%d) line %d: %s\n",
9874 			__func__, i, __LINE__, "ciphertext not as expected\n");
9875 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9876 				d_td->ciphertext.len);
9877 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9878 		ret = TEST_FAILED;
9879 		goto on_err;
9880 	}
9881 
9882 on_err:
9883 	rte_crypto_op_free(ut_params->op);
9884 	ut_params->op = NULL;
9885 
9886 	if (ut_params->sec_session)
9887 		rte_security_session_destroy(ctx, ut_params->sec_session);
9888 	ut_params->sec_session = NULL;
9889 
9890 	rte_pktmbuf_free(ut_params->ibuf);
9891 	ut_params->ibuf = NULL;
9892 
9893 	return ret;
9894 }
9895 
9896 #define TEST_DOCSIS_COUNT(func) do {			\
9897 	int ret = func;					\
9898 	if (ret == TEST_SUCCESS)  {			\
9899 		printf("\t%2d)", n++);			\
9900 		printf("+++++ PASSED:" #func"\n");	\
9901 		p++;					\
9902 	} else if (ret == TEST_SKIPPED) {		\
9903 		printf("\t%2d)", n++);			\
9904 		printf("~~~~~ SKIPPED:" #func"\n");	\
9905 		s++;					\
9906 	} else {					\
9907 		printf("\t%2d)", n++);			\
9908 		printf("----- FAILED:" #func"\n");	\
9909 		f++;					\
9910 	}						\
9911 } while (0)
9912 
9913 static int
9914 test_DOCSIS_PROTO_uplink_all(void)
9915 {
9916 	int p = 0, s = 0, f = 0, n = 0;
9917 
9918 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9919 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9920 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9921 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9922 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9923 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9924 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9925 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9926 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9927 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9928 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9929 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9930 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9931 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9932 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9933 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9934 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9935 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9936 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9937 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9938 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9939 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9940 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9941 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9942 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9943 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9944 
9945 	if (f)
9946 		printf("## %s: %d passed out of %d (%d skipped)\n",
9947 			__func__, p, n, s);
9948 
9949 	return f;
9950 };
9951 
9952 static int
9953 test_DOCSIS_PROTO_downlink_all(void)
9954 {
9955 	int p = 0, s = 0, f = 0, n = 0;
9956 
9957 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9958 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9959 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9960 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9961 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9962 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9963 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9964 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9965 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9966 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9967 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9968 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9969 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9970 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9971 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9972 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9973 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9974 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9975 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9976 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9977 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9978 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9979 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9980 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9981 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9982 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9983 
9984 	if (f)
9985 		printf("## %s: %d passed out of %d (%d skipped)\n",
9986 			__func__, p, n, s);
9987 
9988 	return f;
9989 };
9990 
9991 static int
9992 test_DOCSIS_PROTO_all(void)
9993 {
9994 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9995 	struct crypto_unittest_params *ut_params = &unittest_params;
9996 	struct rte_cryptodev_info dev_info;
9997 	int status;
9998 
9999 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10000 	uint64_t feat_flags = dev_info.feature_flags;
10001 
10002 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
10003 		return TEST_SKIPPED;
10004 
10005 	/* Set action type */
10006 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10007 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10008 		gbl_action_type;
10009 
10010 	if (security_proto_supported(ut_params->type,
10011 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10012 		return TEST_SKIPPED;
10013 
10014 	status = test_DOCSIS_PROTO_uplink_all();
10015 	status += test_DOCSIS_PROTO_downlink_all();
10016 
10017 	if (status)
10018 		return TEST_FAILED;
10019 	else
10020 		return TEST_SUCCESS;
10021 }
10022 #endif
10023 
10024 static int
10025 test_AES_GCM_authenticated_encryption_test_case_1(void)
10026 {
10027 	return test_authenticated_encryption(&gcm_test_case_1);
10028 }
10029 
10030 static int
10031 test_AES_GCM_authenticated_encryption_test_case_2(void)
10032 {
10033 	return test_authenticated_encryption(&gcm_test_case_2);
10034 }
10035 
10036 static int
10037 test_AES_GCM_authenticated_encryption_test_case_3(void)
10038 {
10039 	return test_authenticated_encryption(&gcm_test_case_3);
10040 }
10041 
10042 static int
10043 test_AES_GCM_authenticated_encryption_test_case_4(void)
10044 {
10045 	return test_authenticated_encryption(&gcm_test_case_4);
10046 }
10047 
10048 static int
10049 test_AES_GCM_authenticated_encryption_test_case_5(void)
10050 {
10051 	return test_authenticated_encryption(&gcm_test_case_5);
10052 }
10053 
10054 static int
10055 test_AES_GCM_authenticated_encryption_test_case_6(void)
10056 {
10057 	return test_authenticated_encryption(&gcm_test_case_6);
10058 }
10059 
10060 static int
10061 test_AES_GCM_authenticated_encryption_test_case_7(void)
10062 {
10063 	return test_authenticated_encryption(&gcm_test_case_7);
10064 }
10065 
10066 static int
10067 test_AES_GCM_authenticated_encryption_test_case_8(void)
10068 {
10069 	return test_authenticated_encryption(&gcm_test_case_8);
10070 }
10071 
10072 static int
10073 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
10074 {
10075 	return test_authenticated_encryption(&gcm_J0_test_case_1);
10076 }
10077 
10078 static int
10079 test_AES_GCM_auth_encryption_test_case_192_1(void)
10080 {
10081 	return test_authenticated_encryption(&gcm_test_case_192_1);
10082 }
10083 
10084 static int
10085 test_AES_GCM_auth_encryption_test_case_192_2(void)
10086 {
10087 	return test_authenticated_encryption(&gcm_test_case_192_2);
10088 }
10089 
10090 static int
10091 test_AES_GCM_auth_encryption_test_case_192_3(void)
10092 {
10093 	return test_authenticated_encryption(&gcm_test_case_192_3);
10094 }
10095 
10096 static int
10097 test_AES_GCM_auth_encryption_test_case_192_4(void)
10098 {
10099 	return test_authenticated_encryption(&gcm_test_case_192_4);
10100 }
10101 
10102 static int
10103 test_AES_GCM_auth_encryption_test_case_192_5(void)
10104 {
10105 	return test_authenticated_encryption(&gcm_test_case_192_5);
10106 }
10107 
10108 static int
10109 test_AES_GCM_auth_encryption_test_case_192_6(void)
10110 {
10111 	return test_authenticated_encryption(&gcm_test_case_192_6);
10112 }
10113 
10114 static int
10115 test_AES_GCM_auth_encryption_test_case_192_7(void)
10116 {
10117 	return test_authenticated_encryption(&gcm_test_case_192_7);
10118 }
10119 
10120 static int
10121 test_AES_GCM_auth_encryption_test_case_256_1(void)
10122 {
10123 	return test_authenticated_encryption(&gcm_test_case_256_1);
10124 }
10125 
10126 static int
10127 test_AES_GCM_auth_encryption_test_case_256_2(void)
10128 {
10129 	return test_authenticated_encryption(&gcm_test_case_256_2);
10130 }
10131 
10132 static int
10133 test_AES_GCM_auth_encryption_test_case_256_3(void)
10134 {
10135 	return test_authenticated_encryption(&gcm_test_case_256_3);
10136 }
10137 
10138 static int
10139 test_AES_GCM_auth_encryption_test_case_256_4(void)
10140 {
10141 	return test_authenticated_encryption(&gcm_test_case_256_4);
10142 }
10143 
10144 static int
10145 test_AES_GCM_auth_encryption_test_case_256_5(void)
10146 {
10147 	return test_authenticated_encryption(&gcm_test_case_256_5);
10148 }
10149 
10150 static int
10151 test_AES_GCM_auth_encryption_test_case_256_6(void)
10152 {
10153 	return test_authenticated_encryption(&gcm_test_case_256_6);
10154 }
10155 
10156 static int
10157 test_AES_GCM_auth_encryption_test_case_256_7(void)
10158 {
10159 	return test_authenticated_encryption(&gcm_test_case_256_7);
10160 }
10161 
10162 static int
10163 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10164 {
10165 	return test_authenticated_encryption(&gcm_test_case_aad_1);
10166 }
10167 
10168 static int
10169 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10170 {
10171 	return test_authenticated_encryption(&gcm_test_case_aad_2);
10172 }
10173 
10174 static int
10175 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10176 {
10177 	struct aead_test_data tdata;
10178 	int res;
10179 
10180 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10181 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10182 	tdata.iv.data[0] += 1;
10183 	res = test_authenticated_encryption(&tdata);
10184 	if (res == TEST_SKIPPED)
10185 		return res;
10186 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10187 	return TEST_SUCCESS;
10188 }
10189 
10190 static int
10191 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10192 {
10193 	struct aead_test_data tdata;
10194 	int res;
10195 
10196 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10197 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10198 	tdata.plaintext.data[0] += 1;
10199 	res = test_authenticated_encryption(&tdata);
10200 	if (res == TEST_SKIPPED)
10201 		return res;
10202 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10203 	return TEST_SUCCESS;
10204 }
10205 
10206 static int
10207 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10208 {
10209 	struct aead_test_data tdata;
10210 	int res;
10211 
10212 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10213 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10214 	tdata.ciphertext.data[0] += 1;
10215 	res = test_authenticated_encryption(&tdata);
10216 	if (res == TEST_SKIPPED)
10217 		return res;
10218 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10219 	return TEST_SUCCESS;
10220 }
10221 
10222 static int
10223 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10224 {
10225 	struct aead_test_data tdata;
10226 	int res;
10227 
10228 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10229 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10230 	tdata.aad.len += 1;
10231 	res = test_authenticated_encryption(&tdata);
10232 	if (res == TEST_SKIPPED)
10233 		return res;
10234 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10235 	return TEST_SUCCESS;
10236 }
10237 
10238 static int
10239 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10240 {
10241 	struct aead_test_data tdata;
10242 	uint8_t aad[gcm_test_case_7.aad.len];
10243 	int res;
10244 
10245 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10246 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10247 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10248 	aad[0] += 1;
10249 	tdata.aad.data = aad;
10250 	res = test_authenticated_encryption(&tdata);
10251 	if (res == TEST_SKIPPED)
10252 		return res;
10253 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10254 	return TEST_SUCCESS;
10255 }
10256 
10257 static int
10258 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10259 {
10260 	struct aead_test_data tdata;
10261 	int res;
10262 
10263 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10264 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10265 	tdata.auth_tag.data[0] += 1;
10266 	res = test_authenticated_encryption(&tdata);
10267 	if (res == TEST_SKIPPED)
10268 		return res;
10269 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10270 	return TEST_SUCCESS;
10271 }
10272 
10273 static int
10274 test_authenticated_decryption(const struct aead_test_data *tdata)
10275 {
10276 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10277 	struct crypto_unittest_params *ut_params = &unittest_params;
10278 
10279 	int retval;
10280 	uint8_t *plaintext;
10281 	uint32_t i;
10282 	struct rte_cryptodev_info dev_info;
10283 
10284 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10285 	uint64_t feat_flags = dev_info.feature_flags;
10286 
10287 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10288 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10289 		printf("Device doesn't support RAW data-path APIs.\n");
10290 		return TEST_SKIPPED;
10291 	}
10292 
10293 	/* Verify the capabilities */
10294 	struct rte_cryptodev_sym_capability_idx cap_idx;
10295 	const struct rte_cryptodev_symmetric_capability *capability;
10296 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10297 	cap_idx.algo.aead = tdata->algo;
10298 	capability = rte_cryptodev_sym_capability_get(
10299 			ts_params->valid_devs[0], &cap_idx);
10300 	if (capability == NULL)
10301 		return TEST_SKIPPED;
10302 	if (rte_cryptodev_sym_capability_check_aead(
10303 			capability, tdata->key.len, tdata->auth_tag.len,
10304 			tdata->aad.len, tdata->iv.len))
10305 		return TEST_SKIPPED;
10306 
10307 	/* Create AEAD session */
10308 	retval = create_aead_session(ts_params->valid_devs[0],
10309 			tdata->algo,
10310 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10311 			tdata->key.data, tdata->key.len,
10312 			tdata->aad.len, tdata->auth_tag.len,
10313 			tdata->iv.len);
10314 	if (retval < 0)
10315 		return retval;
10316 
10317 	/* alloc mbuf and set payload */
10318 	if (tdata->aad.len > MBUF_SIZE) {
10319 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10320 		/* Populate full size of add data */
10321 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10322 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10323 	} else
10324 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10325 
10326 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10327 			rte_pktmbuf_tailroom(ut_params->ibuf));
10328 
10329 	/* Create AEAD operation */
10330 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10331 	if (retval < 0)
10332 		return retval;
10333 
10334 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10335 
10336 	ut_params->op->sym->m_src = ut_params->ibuf;
10337 
10338 	/* Process crypto operation */
10339 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10340 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10341 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10342 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10343 				ut_params->op, 0, 0, 0, 0);
10344 	else
10345 		TEST_ASSERT_NOT_NULL(
10346 			process_crypto_request(ts_params->valid_devs[0],
10347 			ut_params->op), "failed to process sym crypto op");
10348 
10349 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10350 			"crypto op processing failed");
10351 
10352 	if (ut_params->op->sym->m_dst)
10353 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10354 				uint8_t *);
10355 	else
10356 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10357 				uint8_t *,
10358 				ut_params->op->sym->cipher.data.offset);
10359 
10360 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10361 
10362 	/* Validate obuf */
10363 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10364 			plaintext,
10365 			tdata->plaintext.data,
10366 			tdata->plaintext.len,
10367 			"Plaintext data not as expected");
10368 
10369 	TEST_ASSERT_EQUAL(ut_params->op->status,
10370 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10371 			"Authentication failed");
10372 
10373 	return 0;
10374 }
10375 
10376 static int
10377 test_AES_GCM_authenticated_decryption_test_case_1(void)
10378 {
10379 	return test_authenticated_decryption(&gcm_test_case_1);
10380 }
10381 
10382 static int
10383 test_AES_GCM_authenticated_decryption_test_case_2(void)
10384 {
10385 	return test_authenticated_decryption(&gcm_test_case_2);
10386 }
10387 
10388 static int
10389 test_AES_GCM_authenticated_decryption_test_case_3(void)
10390 {
10391 	return test_authenticated_decryption(&gcm_test_case_3);
10392 }
10393 
10394 static int
10395 test_AES_GCM_authenticated_decryption_test_case_4(void)
10396 {
10397 	return test_authenticated_decryption(&gcm_test_case_4);
10398 }
10399 
10400 static int
10401 test_AES_GCM_authenticated_decryption_test_case_5(void)
10402 {
10403 	return test_authenticated_decryption(&gcm_test_case_5);
10404 }
10405 
10406 static int
10407 test_AES_GCM_authenticated_decryption_test_case_6(void)
10408 {
10409 	return test_authenticated_decryption(&gcm_test_case_6);
10410 }
10411 
10412 static int
10413 test_AES_GCM_authenticated_decryption_test_case_7(void)
10414 {
10415 	return test_authenticated_decryption(&gcm_test_case_7);
10416 }
10417 
10418 static int
10419 test_AES_GCM_authenticated_decryption_test_case_8(void)
10420 {
10421 	return test_authenticated_decryption(&gcm_test_case_8);
10422 }
10423 
10424 static int
10425 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10426 {
10427 	return test_authenticated_decryption(&gcm_J0_test_case_1);
10428 }
10429 
10430 static int
10431 test_AES_GCM_auth_decryption_test_case_192_1(void)
10432 {
10433 	return test_authenticated_decryption(&gcm_test_case_192_1);
10434 }
10435 
10436 static int
10437 test_AES_GCM_auth_decryption_test_case_192_2(void)
10438 {
10439 	return test_authenticated_decryption(&gcm_test_case_192_2);
10440 }
10441 
10442 static int
10443 test_AES_GCM_auth_decryption_test_case_192_3(void)
10444 {
10445 	return test_authenticated_decryption(&gcm_test_case_192_3);
10446 }
10447 
10448 static int
10449 test_AES_GCM_auth_decryption_test_case_192_4(void)
10450 {
10451 	return test_authenticated_decryption(&gcm_test_case_192_4);
10452 }
10453 
10454 static int
10455 test_AES_GCM_auth_decryption_test_case_192_5(void)
10456 {
10457 	return test_authenticated_decryption(&gcm_test_case_192_5);
10458 }
10459 
10460 static int
10461 test_AES_GCM_auth_decryption_test_case_192_6(void)
10462 {
10463 	return test_authenticated_decryption(&gcm_test_case_192_6);
10464 }
10465 
10466 static int
10467 test_AES_GCM_auth_decryption_test_case_192_7(void)
10468 {
10469 	return test_authenticated_decryption(&gcm_test_case_192_7);
10470 }
10471 
10472 static int
10473 test_AES_GCM_auth_decryption_test_case_256_1(void)
10474 {
10475 	return test_authenticated_decryption(&gcm_test_case_256_1);
10476 }
10477 
10478 static int
10479 test_AES_GCM_auth_decryption_test_case_256_2(void)
10480 {
10481 	return test_authenticated_decryption(&gcm_test_case_256_2);
10482 }
10483 
10484 static int
10485 test_AES_GCM_auth_decryption_test_case_256_3(void)
10486 {
10487 	return test_authenticated_decryption(&gcm_test_case_256_3);
10488 }
10489 
10490 static int
10491 test_AES_GCM_auth_decryption_test_case_256_4(void)
10492 {
10493 	return test_authenticated_decryption(&gcm_test_case_256_4);
10494 }
10495 
10496 static int
10497 test_AES_GCM_auth_decryption_test_case_256_5(void)
10498 {
10499 	return test_authenticated_decryption(&gcm_test_case_256_5);
10500 }
10501 
10502 static int
10503 test_AES_GCM_auth_decryption_test_case_256_6(void)
10504 {
10505 	return test_authenticated_decryption(&gcm_test_case_256_6);
10506 }
10507 
10508 static int
10509 test_AES_GCM_auth_decryption_test_case_256_7(void)
10510 {
10511 	return test_authenticated_decryption(&gcm_test_case_256_7);
10512 }
10513 
10514 static int
10515 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10516 {
10517 	return test_authenticated_decryption(&gcm_test_case_aad_1);
10518 }
10519 
10520 static int
10521 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10522 {
10523 	return test_authenticated_decryption(&gcm_test_case_aad_2);
10524 }
10525 
10526 static int
10527 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10528 {
10529 	struct aead_test_data tdata;
10530 	int res;
10531 
10532 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10533 	tdata.iv.data[0] += 1;
10534 	res = test_authenticated_decryption(&tdata);
10535 	if (res == TEST_SKIPPED)
10536 		return res;
10537 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10538 	return TEST_SUCCESS;
10539 }
10540 
10541 static int
10542 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10543 {
10544 	struct aead_test_data tdata;
10545 	int res;
10546 
10547 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10548 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10549 	tdata.plaintext.data[0] += 1;
10550 	res = test_authenticated_decryption(&tdata);
10551 	if (res == TEST_SKIPPED)
10552 		return res;
10553 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10554 	return TEST_SUCCESS;
10555 }
10556 
10557 static int
10558 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10559 {
10560 	struct aead_test_data tdata;
10561 	int res;
10562 
10563 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10564 	tdata.ciphertext.data[0] += 1;
10565 	res = test_authenticated_decryption(&tdata);
10566 	if (res == TEST_SKIPPED)
10567 		return res;
10568 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10569 	return TEST_SUCCESS;
10570 }
10571 
10572 static int
10573 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10574 {
10575 	struct aead_test_data tdata;
10576 	int res;
10577 
10578 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10579 	tdata.aad.len += 1;
10580 	res = test_authenticated_decryption(&tdata);
10581 	if (res == TEST_SKIPPED)
10582 		return res;
10583 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10584 	return TEST_SUCCESS;
10585 }
10586 
10587 static int
10588 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10589 {
10590 	struct aead_test_data tdata;
10591 	uint8_t aad[gcm_test_case_7.aad.len];
10592 	int res;
10593 
10594 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10595 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10596 	aad[0] += 1;
10597 	tdata.aad.data = aad;
10598 	res = test_authenticated_decryption(&tdata);
10599 	if (res == TEST_SKIPPED)
10600 		return res;
10601 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10602 	return TEST_SUCCESS;
10603 }
10604 
10605 static int
10606 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10607 {
10608 	struct aead_test_data tdata;
10609 	int res;
10610 
10611 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10612 	tdata.auth_tag.data[0] += 1;
10613 	res = test_authenticated_decryption(&tdata);
10614 	if (res == TEST_SKIPPED)
10615 		return res;
10616 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10617 	return TEST_SUCCESS;
10618 }
10619 
10620 static int
10621 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10622 {
10623 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10624 	struct crypto_unittest_params *ut_params = &unittest_params;
10625 
10626 	int retval;
10627 	uint8_t *ciphertext, *auth_tag;
10628 	uint16_t plaintext_pad_len;
10629 	struct rte_cryptodev_info dev_info;
10630 
10631 	/* Verify the capabilities */
10632 	struct rte_cryptodev_sym_capability_idx cap_idx;
10633 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10634 	cap_idx.algo.aead = tdata->algo;
10635 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10636 			&cap_idx) == NULL)
10637 		return TEST_SKIPPED;
10638 
10639 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10640 	uint64_t feat_flags = dev_info.feature_flags;
10641 
10642 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10643 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
10644 		return TEST_SKIPPED;
10645 
10646 	/* not supported with CPU crypto */
10647 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10648 		return TEST_SKIPPED;
10649 
10650 	/* Create AEAD session */
10651 	retval = create_aead_session(ts_params->valid_devs[0],
10652 			tdata->algo,
10653 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10654 			tdata->key.data, tdata->key.len,
10655 			tdata->aad.len, tdata->auth_tag.len,
10656 			tdata->iv.len);
10657 	if (retval < 0)
10658 		return retval;
10659 
10660 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10661 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10662 
10663 	/* clear mbuf payload */
10664 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10665 			rte_pktmbuf_tailroom(ut_params->ibuf));
10666 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10667 			rte_pktmbuf_tailroom(ut_params->obuf));
10668 
10669 	/* Create AEAD operation */
10670 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10671 	if (retval < 0)
10672 		return retval;
10673 
10674 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10675 
10676 	ut_params->op->sym->m_src = ut_params->ibuf;
10677 	ut_params->op->sym->m_dst = ut_params->obuf;
10678 
10679 	/* Process crypto operation */
10680 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10681 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10682 			ut_params->op, 0, 0, 0, 0);
10683 	else
10684 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10685 			ut_params->op), "failed to process sym crypto op");
10686 
10687 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10688 			"crypto op processing failed");
10689 
10690 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10691 
10692 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10693 			ut_params->op->sym->cipher.data.offset);
10694 	auth_tag = ciphertext + plaintext_pad_len;
10695 
10696 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10697 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10698 
10699 	/* Validate obuf */
10700 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10701 			ciphertext,
10702 			tdata->ciphertext.data,
10703 			tdata->ciphertext.len,
10704 			"Ciphertext data not as expected");
10705 
10706 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10707 			auth_tag,
10708 			tdata->auth_tag.data,
10709 			tdata->auth_tag.len,
10710 			"Generated auth tag not as expected");
10711 
10712 	return 0;
10713 
10714 }
10715 
10716 static int
10717 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10718 {
10719 	return test_authenticated_encryption_oop(&gcm_test_case_5);
10720 }
10721 
10722 static int
10723 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10724 {
10725 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10726 	struct crypto_unittest_params *ut_params = &unittest_params;
10727 
10728 	int retval;
10729 	uint8_t *plaintext;
10730 	struct rte_cryptodev_info dev_info;
10731 
10732 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10733 	uint64_t feat_flags = dev_info.feature_flags;
10734 
10735 	/* Verify the capabilities */
10736 	struct rte_cryptodev_sym_capability_idx cap_idx;
10737 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10738 	cap_idx.algo.aead = tdata->algo;
10739 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10740 			&cap_idx) == NULL)
10741 		return TEST_SKIPPED;
10742 
10743 	/* not supported with CPU crypto and raw data-path APIs*/
10744 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10745 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
10746 		return TEST_SKIPPED;
10747 
10748 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10749 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10750 		printf("Device does not support RAW data-path APIs.\n");
10751 		return TEST_SKIPPED;
10752 	}
10753 
10754 	/* Create AEAD session */
10755 	retval = create_aead_session(ts_params->valid_devs[0],
10756 			tdata->algo,
10757 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10758 			tdata->key.data, tdata->key.len,
10759 			tdata->aad.len, tdata->auth_tag.len,
10760 			tdata->iv.len);
10761 	if (retval < 0)
10762 		return retval;
10763 
10764 	/* alloc mbuf and set payload */
10765 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10766 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10767 
10768 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10769 			rte_pktmbuf_tailroom(ut_params->ibuf));
10770 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10771 			rte_pktmbuf_tailroom(ut_params->obuf));
10772 
10773 	/* Create AEAD operation */
10774 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10775 	if (retval < 0)
10776 		return retval;
10777 
10778 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10779 
10780 	ut_params->op->sym->m_src = ut_params->ibuf;
10781 	ut_params->op->sym->m_dst = ut_params->obuf;
10782 
10783 	/* Process crypto operation */
10784 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10785 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10786 				ut_params->op, 0, 0, 0, 0);
10787 	else
10788 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10789 			ut_params->op), "failed to process sym crypto op");
10790 
10791 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10792 			"crypto op processing failed");
10793 
10794 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10795 			ut_params->op->sym->cipher.data.offset);
10796 
10797 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10798 
10799 	/* Validate obuf */
10800 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10801 			plaintext,
10802 			tdata->plaintext.data,
10803 			tdata->plaintext.len,
10804 			"Plaintext data not as expected");
10805 
10806 	TEST_ASSERT_EQUAL(ut_params->op->status,
10807 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10808 			"Authentication failed");
10809 	return 0;
10810 }
10811 
10812 static int
10813 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10814 {
10815 	return test_authenticated_decryption_oop(&gcm_test_case_5);
10816 }
10817 
10818 static int
10819 test_authenticated_encryption_sessionless(
10820 		const struct aead_test_data *tdata)
10821 {
10822 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10823 	struct crypto_unittest_params *ut_params = &unittest_params;
10824 
10825 	int retval;
10826 	uint8_t *ciphertext, *auth_tag;
10827 	uint16_t plaintext_pad_len;
10828 	uint8_t key[tdata->key.len + 1];
10829 	struct rte_cryptodev_info dev_info;
10830 
10831 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10832 	uint64_t feat_flags = dev_info.feature_flags;
10833 
10834 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10835 		printf("Device doesn't support Sessionless ops.\n");
10836 		return TEST_SKIPPED;
10837 	}
10838 
10839 	/* not supported with CPU crypto */
10840 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10841 		return TEST_SKIPPED;
10842 
10843 	/* Verify the capabilities */
10844 	struct rte_cryptodev_sym_capability_idx cap_idx;
10845 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10846 	cap_idx.algo.aead = tdata->algo;
10847 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10848 			&cap_idx) == NULL)
10849 		return TEST_SKIPPED;
10850 
10851 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10852 
10853 	/* clear mbuf payload */
10854 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10855 			rte_pktmbuf_tailroom(ut_params->ibuf));
10856 
10857 	/* Create AEAD operation */
10858 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10859 	if (retval < 0)
10860 		return retval;
10861 
10862 	/* Create GCM xform */
10863 	memcpy(key, tdata->key.data, tdata->key.len);
10864 	retval = create_aead_xform(ut_params->op,
10865 			tdata->algo,
10866 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10867 			key, tdata->key.len,
10868 			tdata->aad.len, tdata->auth_tag.len,
10869 			tdata->iv.len);
10870 	if (retval < 0)
10871 		return retval;
10872 
10873 	ut_params->op->sym->m_src = ut_params->ibuf;
10874 
10875 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10876 			RTE_CRYPTO_OP_SESSIONLESS,
10877 			"crypto op session type not sessionless");
10878 
10879 	/* Process crypto operation */
10880 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10881 			ut_params->op), "failed to process sym crypto op");
10882 
10883 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10884 
10885 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10886 			"crypto op status not success");
10887 
10888 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10889 
10890 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10891 			ut_params->op->sym->cipher.data.offset);
10892 	auth_tag = ciphertext + plaintext_pad_len;
10893 
10894 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10895 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10896 
10897 	/* Validate obuf */
10898 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10899 			ciphertext,
10900 			tdata->ciphertext.data,
10901 			tdata->ciphertext.len,
10902 			"Ciphertext data not as expected");
10903 
10904 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10905 			auth_tag,
10906 			tdata->auth_tag.data,
10907 			tdata->auth_tag.len,
10908 			"Generated auth tag not as expected");
10909 
10910 	return 0;
10911 
10912 }
10913 
10914 static int
10915 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10916 {
10917 	return test_authenticated_encryption_sessionless(
10918 			&gcm_test_case_5);
10919 }
10920 
10921 static int
10922 test_authenticated_decryption_sessionless(
10923 		const struct aead_test_data *tdata)
10924 {
10925 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10926 	struct crypto_unittest_params *ut_params = &unittest_params;
10927 
10928 	int retval;
10929 	uint8_t *plaintext;
10930 	uint8_t key[tdata->key.len + 1];
10931 	struct rte_cryptodev_info dev_info;
10932 
10933 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10934 	uint64_t feat_flags = dev_info.feature_flags;
10935 
10936 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10937 		printf("Device doesn't support Sessionless ops.\n");
10938 		return TEST_SKIPPED;
10939 	}
10940 
10941 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10942 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10943 		printf("Device doesn't support RAW data-path APIs.\n");
10944 		return TEST_SKIPPED;
10945 	}
10946 
10947 	/* not supported with CPU crypto */
10948 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10949 		return TEST_SKIPPED;
10950 
10951 	/* Verify the capabilities */
10952 	struct rte_cryptodev_sym_capability_idx cap_idx;
10953 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10954 	cap_idx.algo.aead = tdata->algo;
10955 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10956 			&cap_idx) == NULL)
10957 		return TEST_SKIPPED;
10958 
10959 	/* alloc mbuf and set payload */
10960 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10961 
10962 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10963 			rte_pktmbuf_tailroom(ut_params->ibuf));
10964 
10965 	/* Create AEAD operation */
10966 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10967 	if (retval < 0)
10968 		return retval;
10969 
10970 	/* Create AEAD xform */
10971 	memcpy(key, tdata->key.data, tdata->key.len);
10972 	retval = create_aead_xform(ut_params->op,
10973 			tdata->algo,
10974 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10975 			key, tdata->key.len,
10976 			tdata->aad.len, tdata->auth_tag.len,
10977 			tdata->iv.len);
10978 	if (retval < 0)
10979 		return retval;
10980 
10981 	ut_params->op->sym->m_src = ut_params->ibuf;
10982 
10983 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10984 			RTE_CRYPTO_OP_SESSIONLESS,
10985 			"crypto op session type not sessionless");
10986 
10987 	/* Process crypto operation */
10988 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10989 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10990 				ut_params->op, 0, 0, 0, 0);
10991 	else
10992 		TEST_ASSERT_NOT_NULL(process_crypto_request(
10993 			ts_params->valid_devs[0], ut_params->op),
10994 				"failed to process sym crypto op");
10995 
10996 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10997 
10998 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10999 			"crypto op status not success");
11000 
11001 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11002 			ut_params->op->sym->cipher.data.offset);
11003 
11004 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11005 
11006 	/* Validate obuf */
11007 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11008 			plaintext,
11009 			tdata->plaintext.data,
11010 			tdata->plaintext.len,
11011 			"Plaintext data not as expected");
11012 
11013 	TEST_ASSERT_EQUAL(ut_params->op->status,
11014 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11015 			"Authentication failed");
11016 	return 0;
11017 }
11018 
11019 static int
11020 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
11021 {
11022 	return test_authenticated_decryption_sessionless(
11023 			&gcm_test_case_5);
11024 }
11025 
11026 static int
11027 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
11028 {
11029 	return test_authenticated_encryption(&ccm_test_case_128_1);
11030 }
11031 
11032 static int
11033 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
11034 {
11035 	return test_authenticated_encryption(&ccm_test_case_128_2);
11036 }
11037 
11038 static int
11039 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
11040 {
11041 	return test_authenticated_encryption(&ccm_test_case_128_3);
11042 }
11043 
11044 static int
11045 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
11046 {
11047 	return test_authenticated_decryption(&ccm_test_case_128_1);
11048 }
11049 
11050 static int
11051 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
11052 {
11053 	return test_authenticated_decryption(&ccm_test_case_128_2);
11054 }
11055 
11056 static int
11057 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
11058 {
11059 	return test_authenticated_decryption(&ccm_test_case_128_3);
11060 }
11061 
11062 static int
11063 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
11064 {
11065 	return test_authenticated_encryption(&ccm_test_case_192_1);
11066 }
11067 
11068 static int
11069 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
11070 {
11071 	return test_authenticated_encryption(&ccm_test_case_192_2);
11072 }
11073 
11074 static int
11075 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
11076 {
11077 	return test_authenticated_encryption(&ccm_test_case_192_3);
11078 }
11079 
11080 static int
11081 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
11082 {
11083 	return test_authenticated_decryption(&ccm_test_case_192_1);
11084 }
11085 
11086 static int
11087 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
11088 {
11089 	return test_authenticated_decryption(&ccm_test_case_192_2);
11090 }
11091 
11092 static int
11093 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
11094 {
11095 	return test_authenticated_decryption(&ccm_test_case_192_3);
11096 }
11097 
11098 static int
11099 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11100 {
11101 	return test_authenticated_encryption(&ccm_test_case_256_1);
11102 }
11103 
11104 static int
11105 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11106 {
11107 	return test_authenticated_encryption(&ccm_test_case_256_2);
11108 }
11109 
11110 static int
11111 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11112 {
11113 	return test_authenticated_encryption(&ccm_test_case_256_3);
11114 }
11115 
11116 static int
11117 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11118 {
11119 	return test_authenticated_decryption(&ccm_test_case_256_1);
11120 }
11121 
11122 static int
11123 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11124 {
11125 	return test_authenticated_decryption(&ccm_test_case_256_2);
11126 }
11127 
11128 static int
11129 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11130 {
11131 	return test_authenticated_decryption(&ccm_test_case_256_3);
11132 }
11133 
11134 static int
11135 test_stats(void)
11136 {
11137 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11138 	struct rte_cryptodev_stats stats;
11139 
11140 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11141 		return TEST_SKIPPED;
11142 
11143 	/* Verify the capabilities */
11144 	struct rte_cryptodev_sym_capability_idx cap_idx;
11145 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11146 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11147 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11148 			&cap_idx) == NULL)
11149 		return TEST_SKIPPED;
11150 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11151 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11152 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11153 			&cap_idx) == NULL)
11154 		return TEST_SKIPPED;
11155 
11156 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11157 			== -ENOTSUP)
11158 		return TEST_SKIPPED;
11159 
11160 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11161 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11162 			&stats) == -ENODEV),
11163 		"rte_cryptodev_stats_get invalid dev failed");
11164 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11165 		"rte_cryptodev_stats_get invalid Param failed");
11166 
11167 	/* Test expected values */
11168 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
11169 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11170 			&stats),
11171 		"rte_cryptodev_stats_get failed");
11172 	TEST_ASSERT((stats.enqueued_count == 1),
11173 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11174 	TEST_ASSERT((stats.dequeued_count == 1),
11175 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11176 	TEST_ASSERT((stats.enqueue_err_count == 0),
11177 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11178 	TEST_ASSERT((stats.dequeue_err_count == 0),
11179 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11180 
11181 	/* invalid device but should ignore and not reset device stats*/
11182 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11183 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11184 			&stats),
11185 		"rte_cryptodev_stats_get failed");
11186 	TEST_ASSERT((stats.enqueued_count == 1),
11187 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11188 
11189 	/* check that a valid reset clears stats */
11190 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11191 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11192 			&stats),
11193 					  "rte_cryptodev_stats_get failed");
11194 	TEST_ASSERT((stats.enqueued_count == 0),
11195 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11196 	TEST_ASSERT((stats.dequeued_count == 0),
11197 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11198 
11199 	return TEST_SUCCESS;
11200 }
11201 
11202 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11203 				   struct crypto_unittest_params *ut_params,
11204 				   enum rte_crypto_auth_operation op,
11205 				   const struct HMAC_MD5_vector *test_case)
11206 {
11207 	uint8_t key[64];
11208 
11209 	memcpy(key, test_case->key.data, test_case->key.len);
11210 
11211 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11212 	ut_params->auth_xform.next = NULL;
11213 	ut_params->auth_xform.auth.op = op;
11214 
11215 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11216 
11217 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11218 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11219 	ut_params->auth_xform.auth.key.data = key;
11220 
11221 	ut_params->sess = rte_cryptodev_sym_session_create(
11222 			ts_params->session_mpool);
11223 
11224 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11225 			ut_params->sess, &ut_params->auth_xform,
11226 			ts_params->session_priv_mpool);
11227 
11228 	if (ut_params->sess == NULL)
11229 		return TEST_FAILED;
11230 
11231 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11232 
11233 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11234 			rte_pktmbuf_tailroom(ut_params->ibuf));
11235 
11236 	return 0;
11237 }
11238 
11239 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11240 			      const struct HMAC_MD5_vector *test_case,
11241 			      uint8_t **plaintext)
11242 {
11243 	uint16_t plaintext_pad_len;
11244 
11245 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11246 
11247 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11248 				16);
11249 
11250 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11251 			plaintext_pad_len);
11252 	memcpy(*plaintext, test_case->plaintext.data,
11253 			test_case->plaintext.len);
11254 
11255 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11256 			ut_params->ibuf, MD5_DIGEST_LEN);
11257 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11258 			"no room to append digest");
11259 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11260 			ut_params->ibuf, plaintext_pad_len);
11261 
11262 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11263 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11264 			   test_case->auth_tag.len);
11265 	}
11266 
11267 	sym_op->auth.data.offset = 0;
11268 	sym_op->auth.data.length = test_case->plaintext.len;
11269 
11270 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11271 	ut_params->op->sym->m_src = ut_params->ibuf;
11272 
11273 	return 0;
11274 }
11275 
11276 static int
11277 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11278 {
11279 	uint16_t plaintext_pad_len;
11280 	uint8_t *plaintext, *auth_tag;
11281 
11282 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11283 	struct crypto_unittest_params *ut_params = &unittest_params;
11284 	struct rte_cryptodev_info dev_info;
11285 
11286 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11287 	uint64_t feat_flags = dev_info.feature_flags;
11288 
11289 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11290 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11291 		printf("Device doesn't support RAW data-path APIs.\n");
11292 		return TEST_SKIPPED;
11293 	}
11294 
11295 	/* Verify the capabilities */
11296 	struct rte_cryptodev_sym_capability_idx cap_idx;
11297 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11298 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11299 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11300 			&cap_idx) == NULL)
11301 		return TEST_SKIPPED;
11302 
11303 	if (MD5_HMAC_create_session(ts_params, ut_params,
11304 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11305 		return TEST_FAILED;
11306 
11307 	/* Generate Crypto op data structure */
11308 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11309 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11310 	TEST_ASSERT_NOT_NULL(ut_params->op,
11311 			"Failed to allocate symmetric crypto operation struct");
11312 
11313 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11314 				16);
11315 
11316 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11317 		return TEST_FAILED;
11318 
11319 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11320 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11321 			ut_params->op);
11322 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11323 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11324 				ut_params->op, 0, 1, 0, 0);
11325 	else
11326 		TEST_ASSERT_NOT_NULL(
11327 			process_crypto_request(ts_params->valid_devs[0],
11328 				ut_params->op),
11329 				"failed to process sym crypto op");
11330 
11331 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11332 			"crypto op processing failed");
11333 
11334 	if (ut_params->op->sym->m_dst) {
11335 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11336 				uint8_t *, plaintext_pad_len);
11337 	} else {
11338 		auth_tag = plaintext + plaintext_pad_len;
11339 	}
11340 
11341 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11342 			auth_tag,
11343 			test_case->auth_tag.data,
11344 			test_case->auth_tag.len,
11345 			"HMAC_MD5 generated tag not as expected");
11346 
11347 	return TEST_SUCCESS;
11348 }
11349 
11350 static int
11351 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11352 {
11353 	uint8_t *plaintext;
11354 
11355 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11356 	struct crypto_unittest_params *ut_params = &unittest_params;
11357 	struct rte_cryptodev_info dev_info;
11358 
11359 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11360 	uint64_t feat_flags = dev_info.feature_flags;
11361 
11362 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11363 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11364 		printf("Device doesn't support RAW data-path APIs.\n");
11365 		return TEST_SKIPPED;
11366 	}
11367 
11368 	/* Verify the capabilities */
11369 	struct rte_cryptodev_sym_capability_idx cap_idx;
11370 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11371 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11372 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11373 			&cap_idx) == NULL)
11374 		return TEST_SKIPPED;
11375 
11376 	if (MD5_HMAC_create_session(ts_params, ut_params,
11377 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11378 		return TEST_FAILED;
11379 	}
11380 
11381 	/* Generate Crypto op data structure */
11382 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11383 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11384 	TEST_ASSERT_NOT_NULL(ut_params->op,
11385 			"Failed to allocate symmetric crypto operation struct");
11386 
11387 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11388 		return TEST_FAILED;
11389 
11390 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11391 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11392 			ut_params->op);
11393 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11394 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11395 				ut_params->op, 0, 1, 0, 0);
11396 	else
11397 		TEST_ASSERT_NOT_NULL(
11398 			process_crypto_request(ts_params->valid_devs[0],
11399 				ut_params->op),
11400 				"failed to process sym crypto op");
11401 
11402 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11403 			"HMAC_MD5 crypto op processing failed");
11404 
11405 	return TEST_SUCCESS;
11406 }
11407 
11408 static int
11409 test_MD5_HMAC_generate_case_1(void)
11410 {
11411 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11412 }
11413 
11414 static int
11415 test_MD5_HMAC_verify_case_1(void)
11416 {
11417 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11418 }
11419 
11420 static int
11421 test_MD5_HMAC_generate_case_2(void)
11422 {
11423 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11424 }
11425 
11426 static int
11427 test_MD5_HMAC_verify_case_2(void)
11428 {
11429 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11430 }
11431 
11432 static int
11433 test_multi_session(void)
11434 {
11435 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11436 	struct crypto_unittest_params *ut_params = &unittest_params;
11437 
11438 	struct rte_cryptodev_info dev_info;
11439 	struct rte_cryptodev_sym_session **sessions;
11440 
11441 	uint16_t i;
11442 
11443 	/* Verify the capabilities */
11444 	struct rte_cryptodev_sym_capability_idx cap_idx;
11445 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11446 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11447 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11448 			&cap_idx) == NULL)
11449 		return TEST_SKIPPED;
11450 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11451 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11452 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11453 			&cap_idx) == NULL)
11454 		return TEST_SKIPPED;
11455 
11456 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11457 			aes_cbc_key, hmac_sha512_key);
11458 
11459 
11460 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11461 
11462 	sessions = rte_malloc(NULL,
11463 			sizeof(struct rte_cryptodev_sym_session *) *
11464 			(MAX_NB_SESSIONS + 1), 0);
11465 
11466 	/* Create multiple crypto sessions*/
11467 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11468 
11469 		sessions[i] = rte_cryptodev_sym_session_create(
11470 				ts_params->session_mpool);
11471 
11472 		rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11473 				sessions[i], &ut_params->auth_xform,
11474 				ts_params->session_priv_mpool);
11475 		TEST_ASSERT_NOT_NULL(sessions[i],
11476 				"Session creation failed at session number %u",
11477 				i);
11478 
11479 		/* Attempt to send a request on each session */
11480 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11481 			sessions[i],
11482 			ut_params,
11483 			ts_params,
11484 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11485 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11486 			aes_cbc_iv),
11487 			"Failed to perform decrypt on request number %u.", i);
11488 		/* free crypto operation structure */
11489 		if (ut_params->op)
11490 			rte_crypto_op_free(ut_params->op);
11491 
11492 		/*
11493 		 * free mbuf - both obuf and ibuf are usually the same,
11494 		 * so check if they point at the same address is necessary,
11495 		 * to avoid freeing the mbuf twice.
11496 		 */
11497 		if (ut_params->obuf) {
11498 			rte_pktmbuf_free(ut_params->obuf);
11499 			if (ut_params->ibuf == ut_params->obuf)
11500 				ut_params->ibuf = 0;
11501 			ut_params->obuf = 0;
11502 		}
11503 		if (ut_params->ibuf) {
11504 			rte_pktmbuf_free(ut_params->ibuf);
11505 			ut_params->ibuf = 0;
11506 		}
11507 	}
11508 
11509 	sessions[i] = NULL;
11510 	/* Next session create should fail */
11511 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11512 			sessions[i], &ut_params->auth_xform,
11513 			ts_params->session_priv_mpool);
11514 	TEST_ASSERT_NULL(sessions[i],
11515 			"Session creation succeeded unexpectedly!");
11516 
11517 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11518 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11519 				sessions[i]);
11520 		rte_cryptodev_sym_session_free(sessions[i]);
11521 	}
11522 
11523 	rte_free(sessions);
11524 
11525 	return TEST_SUCCESS;
11526 }
11527 
11528 struct multi_session_params {
11529 	struct crypto_unittest_params ut_params;
11530 	uint8_t *cipher_key;
11531 	uint8_t *hmac_key;
11532 	const uint8_t *cipher;
11533 	const uint8_t *digest;
11534 	uint8_t *iv;
11535 };
11536 
11537 #define MB_SESSION_NUMBER 3
11538 
11539 static int
11540 test_multi_session_random_usage(void)
11541 {
11542 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11543 	struct rte_cryptodev_info dev_info;
11544 	struct rte_cryptodev_sym_session **sessions;
11545 	uint32_t i, j;
11546 	struct multi_session_params ut_paramz[] = {
11547 
11548 		{
11549 			.cipher_key = ms_aes_cbc_key0,
11550 			.hmac_key = ms_hmac_key0,
11551 			.cipher = ms_aes_cbc_cipher0,
11552 			.digest = ms_hmac_digest0,
11553 			.iv = ms_aes_cbc_iv0
11554 		},
11555 		{
11556 			.cipher_key = ms_aes_cbc_key1,
11557 			.hmac_key = ms_hmac_key1,
11558 			.cipher = ms_aes_cbc_cipher1,
11559 			.digest = ms_hmac_digest1,
11560 			.iv = ms_aes_cbc_iv1
11561 		},
11562 		{
11563 			.cipher_key = ms_aes_cbc_key2,
11564 			.hmac_key = ms_hmac_key2,
11565 			.cipher = ms_aes_cbc_cipher2,
11566 			.digest = ms_hmac_digest2,
11567 			.iv = ms_aes_cbc_iv2
11568 		},
11569 
11570 	};
11571 
11572 	/* Verify the capabilities */
11573 	struct rte_cryptodev_sym_capability_idx cap_idx;
11574 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11575 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11576 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11577 			&cap_idx) == NULL)
11578 		return TEST_SKIPPED;
11579 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11580 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11581 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11582 			&cap_idx) == NULL)
11583 		return TEST_SKIPPED;
11584 
11585 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11586 
11587 	sessions = rte_malloc(NULL,
11588 			(sizeof(struct rte_cryptodev_sym_session *)
11589 					* MAX_NB_SESSIONS) + 1, 0);
11590 
11591 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11592 		sessions[i] = rte_cryptodev_sym_session_create(
11593 				ts_params->session_mpool);
11594 
11595 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11596 				sizeof(struct crypto_unittest_params));
11597 
11598 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11599 				&ut_paramz[i].ut_params,
11600 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11601 
11602 		/* Create multiple crypto sessions*/
11603 		rte_cryptodev_sym_session_init(
11604 				ts_params->valid_devs[0],
11605 				sessions[i],
11606 				&ut_paramz[i].ut_params.auth_xform,
11607 				ts_params->session_priv_mpool);
11608 
11609 		TEST_ASSERT_NOT_NULL(sessions[i],
11610 				"Session creation failed at session number %u",
11611 				i);
11612 
11613 	}
11614 
11615 	srand(time(NULL));
11616 	for (i = 0; i < 40000; i++) {
11617 
11618 		j = rand() % MB_SESSION_NUMBER;
11619 
11620 		TEST_ASSERT_SUCCESS(
11621 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
11622 					sessions[j],
11623 					&ut_paramz[j].ut_params,
11624 					ts_params, ut_paramz[j].cipher,
11625 					ut_paramz[j].digest,
11626 					ut_paramz[j].iv),
11627 			"Failed to perform decrypt on request number %u.", i);
11628 
11629 		if (ut_paramz[j].ut_params.op)
11630 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
11631 
11632 		/*
11633 		 * free mbuf - both obuf and ibuf are usually the same,
11634 		 * so check if they point at the same address is necessary,
11635 		 * to avoid freeing the mbuf twice.
11636 		 */
11637 		if (ut_paramz[j].ut_params.obuf) {
11638 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11639 			if (ut_paramz[j].ut_params.ibuf
11640 					== ut_paramz[j].ut_params.obuf)
11641 				ut_paramz[j].ut_params.ibuf = 0;
11642 			ut_paramz[j].ut_params.obuf = 0;
11643 		}
11644 		if (ut_paramz[j].ut_params.ibuf) {
11645 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11646 			ut_paramz[j].ut_params.ibuf = 0;
11647 		}
11648 	}
11649 
11650 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11651 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11652 				sessions[i]);
11653 		rte_cryptodev_sym_session_free(sessions[i]);
11654 	}
11655 
11656 	rte_free(sessions);
11657 
11658 	return TEST_SUCCESS;
11659 }
11660 
11661 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11662 			0xab, 0xab, 0xab, 0xab,
11663 			0xab, 0xab, 0xab, 0xab,
11664 			0xab, 0xab, 0xab, 0xab};
11665 
11666 static int
11667 test_null_invalid_operation(void)
11668 {
11669 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11670 	struct crypto_unittest_params *ut_params = &unittest_params;
11671 	int ret;
11672 
11673 	/* This test is for NULL PMD only */
11674 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11675 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11676 		return TEST_SKIPPED;
11677 
11678 	/* Setup Cipher Parameters */
11679 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11680 	ut_params->cipher_xform.next = NULL;
11681 
11682 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11683 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11684 
11685 	ut_params->sess = rte_cryptodev_sym_session_create(
11686 			ts_params->session_mpool);
11687 
11688 	/* Create Crypto session*/
11689 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11690 			ut_params->sess, &ut_params->cipher_xform,
11691 			ts_params->session_priv_mpool);
11692 	TEST_ASSERT(ret < 0,
11693 			"Session creation succeeded unexpectedly");
11694 
11695 
11696 	/* Setup HMAC Parameters */
11697 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11698 	ut_params->auth_xform.next = NULL;
11699 
11700 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11701 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11702 
11703 	ut_params->sess = rte_cryptodev_sym_session_create(
11704 			ts_params->session_mpool);
11705 
11706 	/* Create Crypto session*/
11707 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11708 			ut_params->sess, &ut_params->auth_xform,
11709 			ts_params->session_priv_mpool);
11710 	TEST_ASSERT(ret < 0,
11711 			"Session creation succeeded unexpectedly");
11712 
11713 	return TEST_SUCCESS;
11714 }
11715 
11716 
11717 #define NULL_BURST_LENGTH (32)
11718 
11719 static int
11720 test_null_burst_operation(void)
11721 {
11722 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11723 	struct crypto_unittest_params *ut_params = &unittest_params;
11724 
11725 	unsigned i, burst_len = NULL_BURST_LENGTH;
11726 
11727 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11728 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11729 
11730 	/* This test is for NULL PMD only */
11731 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11732 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11733 		return TEST_SKIPPED;
11734 
11735 	/* Setup Cipher Parameters */
11736 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11737 	ut_params->cipher_xform.next = &ut_params->auth_xform;
11738 
11739 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11740 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11741 
11742 	/* Setup HMAC Parameters */
11743 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11744 	ut_params->auth_xform.next = NULL;
11745 
11746 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11747 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11748 
11749 	ut_params->sess = rte_cryptodev_sym_session_create(
11750 			ts_params->session_mpool);
11751 
11752 	/* Create Crypto session*/
11753 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11754 			ut_params->sess, &ut_params->cipher_xform,
11755 			ts_params->session_priv_mpool);
11756 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11757 
11758 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11759 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11760 			burst_len, "failed to generate burst of crypto ops");
11761 
11762 	/* Generate an operation for each mbuf in burst */
11763 	for (i = 0; i < burst_len; i++) {
11764 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11765 
11766 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11767 
11768 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11769 				sizeof(unsigned));
11770 		*data = i;
11771 
11772 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11773 
11774 		burst[i]->sym->m_src = m;
11775 	}
11776 
11777 	/* Process crypto operation */
11778 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11779 			0, burst, burst_len),
11780 			burst_len,
11781 			"Error enqueuing burst");
11782 
11783 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11784 			0, burst_dequeued, burst_len),
11785 			burst_len,
11786 			"Error dequeuing burst");
11787 
11788 
11789 	for (i = 0; i < burst_len; i++) {
11790 		TEST_ASSERT_EQUAL(
11791 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11792 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11793 					uint32_t *),
11794 			"data not as expected");
11795 
11796 		rte_pktmbuf_free(burst[i]->sym->m_src);
11797 		rte_crypto_op_free(burst[i]);
11798 	}
11799 
11800 	return TEST_SUCCESS;
11801 }
11802 
11803 static uint16_t
11804 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11805 		  uint16_t nb_ops, void *user_param)
11806 {
11807 	RTE_SET_USED(dev_id);
11808 	RTE_SET_USED(qp_id);
11809 	RTE_SET_USED(ops);
11810 	RTE_SET_USED(user_param);
11811 
11812 	printf("crypto enqueue callback called\n");
11813 	return nb_ops;
11814 }
11815 
11816 static uint16_t
11817 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11818 		  uint16_t nb_ops, void *user_param)
11819 {
11820 	RTE_SET_USED(dev_id);
11821 	RTE_SET_USED(qp_id);
11822 	RTE_SET_USED(ops);
11823 	RTE_SET_USED(user_param);
11824 
11825 	printf("crypto dequeue callback called\n");
11826 	return nb_ops;
11827 }
11828 
11829 /*
11830  * Thread using enqueue/dequeue callback with RCU.
11831  */
11832 static int
11833 test_enqdeq_callback_thread(void *arg)
11834 {
11835 	RTE_SET_USED(arg);
11836 	/* DP thread calls rte_cryptodev_enqueue_burst()/
11837 	 * rte_cryptodev_dequeue_burst() and invokes callback.
11838 	 */
11839 	test_null_burst_operation();
11840 	return 0;
11841 }
11842 
11843 static int
11844 test_enq_callback_setup(void)
11845 {
11846 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11847 	struct rte_cryptodev_info dev_info;
11848 	struct rte_cryptodev_qp_conf qp_conf = {
11849 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11850 	};
11851 
11852 	struct rte_cryptodev_cb *cb;
11853 	uint16_t qp_id = 0;
11854 
11855 	/* Stop the device in case it's started so it can be configured */
11856 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11857 
11858 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11859 
11860 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11861 			&ts_params->conf),
11862 			"Failed to configure cryptodev %u",
11863 			ts_params->valid_devs[0]);
11864 
11865 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11866 	qp_conf.mp_session = ts_params->session_mpool;
11867 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11868 
11869 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11870 			ts_params->valid_devs[0], qp_id, &qp_conf,
11871 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11872 			"Failed test for "
11873 			"rte_cryptodev_queue_pair_setup: num_inflights "
11874 			"%u on qp %u on cryptodev %u",
11875 			qp_conf.nb_descriptors, qp_id,
11876 			ts_params->valid_devs[0]);
11877 
11878 	/* Test with invalid crypto device */
11879 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11880 			qp_id, test_enq_callback, NULL);
11881 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11882 			"cryptodev %u did not fail",
11883 			qp_id, RTE_CRYPTO_MAX_DEVS);
11884 
11885 	/* Test with invalid queue pair */
11886 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11887 			dev_info.max_nb_queue_pairs + 1,
11888 			test_enq_callback, NULL);
11889 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11890 			"cryptodev %u did not fail",
11891 			dev_info.max_nb_queue_pairs + 1,
11892 			ts_params->valid_devs[0]);
11893 
11894 	/* Test with NULL callback */
11895 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11896 			qp_id, NULL, NULL);
11897 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11898 			"cryptodev %u did not fail",
11899 			qp_id, ts_params->valid_devs[0]);
11900 
11901 	/* Test with valid configuration */
11902 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11903 			qp_id, test_enq_callback, NULL);
11904 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11905 			"qp %u on cryptodev %u",
11906 			qp_id, ts_params->valid_devs[0]);
11907 
11908 	rte_cryptodev_start(ts_params->valid_devs[0]);
11909 
11910 	/* Launch a thread */
11911 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11912 				rte_get_next_lcore(-1, 1, 0));
11913 
11914 	/* Wait until reader exited. */
11915 	rte_eal_mp_wait_lcore();
11916 
11917 	/* Test with invalid crypto device */
11918 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11919 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11920 			"Expected call to fail as crypto device is invalid");
11921 
11922 	/* Test with invalid queue pair */
11923 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11924 			ts_params->valid_devs[0],
11925 			dev_info.max_nb_queue_pairs + 1, cb),
11926 			"Expected call to fail as queue pair is invalid");
11927 
11928 	/* Test with NULL callback */
11929 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11930 			ts_params->valid_devs[0], qp_id, NULL),
11931 			"Expected call to fail as callback is NULL");
11932 
11933 	/* Test with valid configuration */
11934 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11935 			ts_params->valid_devs[0], qp_id, cb),
11936 			"Failed test to remove callback on "
11937 			"qp %u on cryptodev %u",
11938 			qp_id, ts_params->valid_devs[0]);
11939 
11940 	return TEST_SUCCESS;
11941 }
11942 
11943 static int
11944 test_deq_callback_setup(void)
11945 {
11946 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11947 	struct rte_cryptodev_info dev_info;
11948 	struct rte_cryptodev_qp_conf qp_conf = {
11949 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11950 	};
11951 
11952 	struct rte_cryptodev_cb *cb;
11953 	uint16_t qp_id = 0;
11954 
11955 	/* Stop the device in case it's started so it can be configured */
11956 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11957 
11958 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11959 
11960 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11961 			&ts_params->conf),
11962 			"Failed to configure cryptodev %u",
11963 			ts_params->valid_devs[0]);
11964 
11965 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11966 	qp_conf.mp_session = ts_params->session_mpool;
11967 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11968 
11969 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11970 			ts_params->valid_devs[0], qp_id, &qp_conf,
11971 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11972 			"Failed test for "
11973 			"rte_cryptodev_queue_pair_setup: num_inflights "
11974 			"%u on qp %u on cryptodev %u",
11975 			qp_conf.nb_descriptors, qp_id,
11976 			ts_params->valid_devs[0]);
11977 
11978 	/* Test with invalid crypto device */
11979 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11980 			qp_id, test_deq_callback, NULL);
11981 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11982 			"cryptodev %u did not fail",
11983 			qp_id, RTE_CRYPTO_MAX_DEVS);
11984 
11985 	/* Test with invalid queue pair */
11986 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11987 			dev_info.max_nb_queue_pairs + 1,
11988 			test_deq_callback, NULL);
11989 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11990 			"cryptodev %u did not fail",
11991 			dev_info.max_nb_queue_pairs + 1,
11992 			ts_params->valid_devs[0]);
11993 
11994 	/* Test with NULL callback */
11995 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11996 			qp_id, NULL, NULL);
11997 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11998 			"cryptodev %u did not fail",
11999 			qp_id, ts_params->valid_devs[0]);
12000 
12001 	/* Test with valid configuration */
12002 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12003 			qp_id, test_deq_callback, NULL);
12004 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12005 			"qp %u on cryptodev %u",
12006 			qp_id, ts_params->valid_devs[0]);
12007 
12008 	rte_cryptodev_start(ts_params->valid_devs[0]);
12009 
12010 	/* Launch a thread */
12011 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12012 				rte_get_next_lcore(-1, 1, 0));
12013 
12014 	/* Wait until reader exited. */
12015 	rte_eal_mp_wait_lcore();
12016 
12017 	/* Test with invalid crypto device */
12018 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12019 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12020 			"Expected call to fail as crypto device is invalid");
12021 
12022 	/* Test with invalid queue pair */
12023 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12024 			ts_params->valid_devs[0],
12025 			dev_info.max_nb_queue_pairs + 1, cb),
12026 			"Expected call to fail as queue pair is invalid");
12027 
12028 	/* Test with NULL callback */
12029 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12030 			ts_params->valid_devs[0], qp_id, NULL),
12031 			"Expected call to fail as callback is NULL");
12032 
12033 	/* Test with valid configuration */
12034 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
12035 			ts_params->valid_devs[0], qp_id, cb),
12036 			"Failed test to remove callback on "
12037 			"qp %u on cryptodev %u",
12038 			qp_id, ts_params->valid_devs[0]);
12039 
12040 	return TEST_SUCCESS;
12041 }
12042 
12043 static void
12044 generate_gmac_large_plaintext(uint8_t *data)
12045 {
12046 	uint16_t i;
12047 
12048 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
12049 		memcpy(&data[i], &data[0], 32);
12050 }
12051 
12052 static int
12053 create_gmac_operation(enum rte_crypto_auth_operation op,
12054 		const struct gmac_test_data *tdata)
12055 {
12056 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12057 	struct crypto_unittest_params *ut_params = &unittest_params;
12058 	struct rte_crypto_sym_op *sym_op;
12059 
12060 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12061 
12062 	/* Generate Crypto op data structure */
12063 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12064 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12065 	TEST_ASSERT_NOT_NULL(ut_params->op,
12066 			"Failed to allocate symmetric crypto operation struct");
12067 
12068 	sym_op = ut_params->op->sym;
12069 
12070 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12071 			ut_params->ibuf, tdata->gmac_tag.len);
12072 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12073 			"no room to append digest");
12074 
12075 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12076 			ut_params->ibuf, plaintext_pad_len);
12077 
12078 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12079 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12080 				tdata->gmac_tag.len);
12081 		debug_hexdump(stdout, "digest:",
12082 				sym_op->auth.digest.data,
12083 				tdata->gmac_tag.len);
12084 	}
12085 
12086 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12087 			uint8_t *, IV_OFFSET);
12088 
12089 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12090 
12091 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12092 
12093 	sym_op->cipher.data.length = 0;
12094 	sym_op->cipher.data.offset = 0;
12095 
12096 	sym_op->auth.data.offset = 0;
12097 	sym_op->auth.data.length = tdata->plaintext.len;
12098 
12099 	return 0;
12100 }
12101 
12102 static int
12103 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12104 		const struct gmac_test_data *tdata,
12105 		void *digest_mem, uint64_t digest_phys)
12106 {
12107 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12108 	struct crypto_unittest_params *ut_params = &unittest_params;
12109 	struct rte_crypto_sym_op *sym_op;
12110 
12111 	/* Generate Crypto op data structure */
12112 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12113 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12114 	TEST_ASSERT_NOT_NULL(ut_params->op,
12115 			"Failed to allocate symmetric crypto operation struct");
12116 
12117 	sym_op = ut_params->op->sym;
12118 
12119 	sym_op->auth.digest.data = digest_mem;
12120 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12121 			"no room to append digest");
12122 
12123 	sym_op->auth.digest.phys_addr = digest_phys;
12124 
12125 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12126 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12127 				tdata->gmac_tag.len);
12128 		debug_hexdump(stdout, "digest:",
12129 				sym_op->auth.digest.data,
12130 				tdata->gmac_tag.len);
12131 	}
12132 
12133 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12134 			uint8_t *, IV_OFFSET);
12135 
12136 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12137 
12138 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12139 
12140 	sym_op->cipher.data.length = 0;
12141 	sym_op->cipher.data.offset = 0;
12142 
12143 	sym_op->auth.data.offset = 0;
12144 	sym_op->auth.data.length = tdata->plaintext.len;
12145 
12146 	return 0;
12147 }
12148 
12149 static int create_gmac_session(uint8_t dev_id,
12150 		const struct gmac_test_data *tdata,
12151 		enum rte_crypto_auth_operation auth_op)
12152 {
12153 	uint8_t auth_key[tdata->key.len];
12154 
12155 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12156 	struct crypto_unittest_params *ut_params = &unittest_params;
12157 
12158 	memcpy(auth_key, tdata->key.data, tdata->key.len);
12159 
12160 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12161 	ut_params->auth_xform.next = NULL;
12162 
12163 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12164 	ut_params->auth_xform.auth.op = auth_op;
12165 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12166 	ut_params->auth_xform.auth.key.length = tdata->key.len;
12167 	ut_params->auth_xform.auth.key.data = auth_key;
12168 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12169 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12170 
12171 
12172 	ut_params->sess = rte_cryptodev_sym_session_create(
12173 			ts_params->session_mpool);
12174 
12175 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12176 			&ut_params->auth_xform,
12177 			ts_params->session_priv_mpool);
12178 
12179 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12180 
12181 	return 0;
12182 }
12183 
12184 static int
12185 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12186 {
12187 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12188 	struct crypto_unittest_params *ut_params = &unittest_params;
12189 	struct rte_cryptodev_info dev_info;
12190 
12191 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12192 	uint64_t feat_flags = dev_info.feature_flags;
12193 
12194 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12195 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12196 		printf("Device doesn't support RAW data-path APIs.\n");
12197 		return TEST_SKIPPED;
12198 	}
12199 
12200 	int retval;
12201 
12202 	uint8_t *auth_tag, *plaintext;
12203 	uint16_t plaintext_pad_len;
12204 
12205 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12206 			      "No GMAC length in the source data");
12207 
12208 	/* Verify the capabilities */
12209 	struct rte_cryptodev_sym_capability_idx cap_idx;
12210 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12211 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12212 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12213 			&cap_idx) == NULL)
12214 		return TEST_SKIPPED;
12215 
12216 	retval = create_gmac_session(ts_params->valid_devs[0],
12217 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12218 
12219 	if (retval < 0)
12220 		return retval;
12221 
12222 	if (tdata->plaintext.len > MBUF_SIZE)
12223 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12224 	else
12225 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12226 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12227 			"Failed to allocate input buffer in mempool");
12228 
12229 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12230 			rte_pktmbuf_tailroom(ut_params->ibuf));
12231 
12232 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12233 	/*
12234 	 * Runtime generate the large plain text instead of use hard code
12235 	 * plain text vector. It is done to avoid create huge source file
12236 	 * with the test vector.
12237 	 */
12238 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12239 		generate_gmac_large_plaintext(tdata->plaintext.data);
12240 
12241 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12242 				plaintext_pad_len);
12243 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12244 
12245 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12246 	debug_hexdump(stdout, "plaintext:", plaintext,
12247 			tdata->plaintext.len);
12248 
12249 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12250 			tdata);
12251 
12252 	if (retval < 0)
12253 		return retval;
12254 
12255 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12256 
12257 	ut_params->op->sym->m_src = ut_params->ibuf;
12258 
12259 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12260 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12261 			ut_params->op);
12262 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12263 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12264 				ut_params->op, 0, 1, 0, 0);
12265 	else
12266 		TEST_ASSERT_NOT_NULL(
12267 			process_crypto_request(ts_params->valid_devs[0],
12268 			ut_params->op), "failed to process sym crypto op");
12269 
12270 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12271 			"crypto op processing failed");
12272 
12273 	if (ut_params->op->sym->m_dst) {
12274 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12275 				uint8_t *, plaintext_pad_len);
12276 	} else {
12277 		auth_tag = plaintext + plaintext_pad_len;
12278 	}
12279 
12280 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12281 
12282 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12283 			auth_tag,
12284 			tdata->gmac_tag.data,
12285 			tdata->gmac_tag.len,
12286 			"GMAC Generated auth tag not as expected");
12287 
12288 	return 0;
12289 }
12290 
12291 static int
12292 test_AES_GMAC_authentication_test_case_1(void)
12293 {
12294 	return test_AES_GMAC_authentication(&gmac_test_case_1);
12295 }
12296 
12297 static int
12298 test_AES_GMAC_authentication_test_case_2(void)
12299 {
12300 	return test_AES_GMAC_authentication(&gmac_test_case_2);
12301 }
12302 
12303 static int
12304 test_AES_GMAC_authentication_test_case_3(void)
12305 {
12306 	return test_AES_GMAC_authentication(&gmac_test_case_3);
12307 }
12308 
12309 static int
12310 test_AES_GMAC_authentication_test_case_4(void)
12311 {
12312 	return test_AES_GMAC_authentication(&gmac_test_case_4);
12313 }
12314 
12315 static int
12316 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12317 {
12318 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12319 	struct crypto_unittest_params *ut_params = &unittest_params;
12320 	int retval;
12321 	uint32_t plaintext_pad_len;
12322 	uint8_t *plaintext;
12323 	struct rte_cryptodev_info dev_info;
12324 
12325 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12326 	uint64_t feat_flags = dev_info.feature_flags;
12327 
12328 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12329 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12330 		printf("Device doesn't support RAW data-path APIs.\n");
12331 		return TEST_SKIPPED;
12332 	}
12333 
12334 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12335 			      "No GMAC length in the source data");
12336 
12337 	/* Verify the capabilities */
12338 	struct rte_cryptodev_sym_capability_idx cap_idx;
12339 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12340 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12341 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12342 			&cap_idx) == NULL)
12343 		return TEST_SKIPPED;
12344 
12345 	retval = create_gmac_session(ts_params->valid_devs[0],
12346 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12347 
12348 	if (retval < 0)
12349 		return retval;
12350 
12351 	if (tdata->plaintext.len > MBUF_SIZE)
12352 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12353 	else
12354 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12355 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12356 			"Failed to allocate input buffer in mempool");
12357 
12358 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12359 			rte_pktmbuf_tailroom(ut_params->ibuf));
12360 
12361 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12362 
12363 	/*
12364 	 * Runtime generate the large plain text instead of use hard code
12365 	 * plain text vector. It is done to avoid create huge source file
12366 	 * with the test vector.
12367 	 */
12368 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12369 		generate_gmac_large_plaintext(tdata->plaintext.data);
12370 
12371 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12372 				plaintext_pad_len);
12373 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12374 
12375 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12376 	debug_hexdump(stdout, "plaintext:", plaintext,
12377 			tdata->plaintext.len);
12378 
12379 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12380 			tdata);
12381 
12382 	if (retval < 0)
12383 		return retval;
12384 
12385 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12386 
12387 	ut_params->op->sym->m_src = ut_params->ibuf;
12388 
12389 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12390 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12391 			ut_params->op);
12392 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12393 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12394 				ut_params->op, 0, 1, 0, 0);
12395 	else
12396 		TEST_ASSERT_NOT_NULL(
12397 			process_crypto_request(ts_params->valid_devs[0],
12398 			ut_params->op), "failed to process sym crypto op");
12399 
12400 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12401 			"crypto op processing failed");
12402 
12403 	return 0;
12404 
12405 }
12406 
12407 static int
12408 test_AES_GMAC_authentication_verify_test_case_1(void)
12409 {
12410 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12411 }
12412 
12413 static int
12414 test_AES_GMAC_authentication_verify_test_case_2(void)
12415 {
12416 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12417 }
12418 
12419 static int
12420 test_AES_GMAC_authentication_verify_test_case_3(void)
12421 {
12422 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12423 }
12424 
12425 static int
12426 test_AES_GMAC_authentication_verify_test_case_4(void)
12427 {
12428 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12429 }
12430 
12431 static int
12432 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12433 				uint32_t fragsz)
12434 {
12435 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12436 	struct crypto_unittest_params *ut_params = &unittest_params;
12437 	struct rte_cryptodev_info dev_info;
12438 	uint64_t feature_flags;
12439 	unsigned int trn_data = 0;
12440 	void *digest_mem = NULL;
12441 	uint32_t segs = 1;
12442 	unsigned int to_trn = 0;
12443 	struct rte_mbuf *buf = NULL;
12444 	uint8_t *auth_tag, *plaintext;
12445 	int retval;
12446 
12447 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12448 			      "No GMAC length in the source data");
12449 
12450 	/* Verify the capabilities */
12451 	struct rte_cryptodev_sym_capability_idx cap_idx;
12452 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12453 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12454 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12455 			&cap_idx) == NULL)
12456 		return TEST_SKIPPED;
12457 
12458 	/* Check for any input SGL support */
12459 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12460 	feature_flags = dev_info.feature_flags;
12461 
12462 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12463 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12464 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12465 		return TEST_SKIPPED;
12466 
12467 	if (fragsz > tdata->plaintext.len)
12468 		fragsz = tdata->plaintext.len;
12469 
12470 	uint16_t plaintext_len = fragsz;
12471 
12472 	retval = create_gmac_session(ts_params->valid_devs[0],
12473 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12474 
12475 	if (retval < 0)
12476 		return retval;
12477 
12478 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12479 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12480 			"Failed to allocate input buffer in mempool");
12481 
12482 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12483 			rte_pktmbuf_tailroom(ut_params->ibuf));
12484 
12485 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12486 				plaintext_len);
12487 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12488 
12489 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12490 
12491 	trn_data += plaintext_len;
12492 
12493 	buf = ut_params->ibuf;
12494 
12495 	/*
12496 	 * Loop until no more fragments
12497 	 */
12498 
12499 	while (trn_data < tdata->plaintext.len) {
12500 		++segs;
12501 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12502 				(tdata->plaintext.len - trn_data) : fragsz;
12503 
12504 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12505 		buf = buf->next;
12506 
12507 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12508 				rte_pktmbuf_tailroom(buf));
12509 
12510 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12511 				to_trn);
12512 
12513 		memcpy(plaintext, tdata->plaintext.data + trn_data,
12514 				to_trn);
12515 		trn_data += to_trn;
12516 		if (trn_data  == tdata->plaintext.len)
12517 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12518 					tdata->gmac_tag.len);
12519 	}
12520 	ut_params->ibuf->nb_segs = segs;
12521 
12522 	/*
12523 	 * Place digest at the end of the last buffer
12524 	 */
12525 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12526 
12527 	if (!digest_mem) {
12528 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12529 				+ tdata->gmac_tag.len);
12530 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12531 				tdata->plaintext.len);
12532 	}
12533 
12534 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12535 			tdata, digest_mem, digest_phys);
12536 
12537 	if (retval < 0)
12538 		return retval;
12539 
12540 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12541 
12542 	ut_params->op->sym->m_src = ut_params->ibuf;
12543 
12544 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12545 		return TEST_SKIPPED;
12546 
12547 	TEST_ASSERT_NOT_NULL(
12548 		process_crypto_request(ts_params->valid_devs[0],
12549 		ut_params->op), "failed to process sym crypto op");
12550 
12551 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12552 			"crypto op processing failed");
12553 
12554 	auth_tag = digest_mem;
12555 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12556 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12557 			auth_tag,
12558 			tdata->gmac_tag.data,
12559 			tdata->gmac_tag.len,
12560 			"GMAC Generated auth tag not as expected");
12561 
12562 	return 0;
12563 }
12564 
12565 /* Segment size not multiple of block size (16B) */
12566 static int
12567 test_AES_GMAC_authentication_SGL_40B(void)
12568 {
12569 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12570 }
12571 
12572 static int
12573 test_AES_GMAC_authentication_SGL_80B(void)
12574 {
12575 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12576 }
12577 
12578 static int
12579 test_AES_GMAC_authentication_SGL_2048B(void)
12580 {
12581 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12582 }
12583 
12584 /* Segment size not multiple of block size (16B) */
12585 static int
12586 test_AES_GMAC_authentication_SGL_2047B(void)
12587 {
12588 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12589 }
12590 
12591 struct test_crypto_vector {
12592 	enum rte_crypto_cipher_algorithm crypto_algo;
12593 	unsigned int cipher_offset;
12594 	unsigned int cipher_len;
12595 
12596 	struct {
12597 		uint8_t data[64];
12598 		unsigned int len;
12599 	} cipher_key;
12600 
12601 	struct {
12602 		uint8_t data[64];
12603 		unsigned int len;
12604 	} iv;
12605 
12606 	struct {
12607 		const uint8_t *data;
12608 		unsigned int len;
12609 	} plaintext;
12610 
12611 	struct {
12612 		const uint8_t *data;
12613 		unsigned int len;
12614 	} ciphertext;
12615 
12616 	enum rte_crypto_auth_algorithm auth_algo;
12617 	unsigned int auth_offset;
12618 
12619 	struct {
12620 		uint8_t data[128];
12621 		unsigned int len;
12622 	} auth_key;
12623 
12624 	struct {
12625 		const uint8_t *data;
12626 		unsigned int len;
12627 	} aad;
12628 
12629 	struct {
12630 		uint8_t data[128];
12631 		unsigned int len;
12632 	} digest;
12633 };
12634 
12635 static const struct test_crypto_vector
12636 hmac_sha1_test_crypto_vector = {
12637 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12638 	.plaintext = {
12639 		.data = plaintext_hash,
12640 		.len = 512
12641 	},
12642 	.auth_key = {
12643 		.data = {
12644 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12645 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12646 			0xDE, 0xF4, 0xDE, 0xAD
12647 		},
12648 		.len = 20
12649 	},
12650 	.digest = {
12651 		.data = {
12652 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12653 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12654 			0x3F, 0x91, 0x64, 0x59
12655 		},
12656 		.len = 20
12657 	}
12658 };
12659 
12660 static const struct test_crypto_vector
12661 aes128_gmac_test_vector = {
12662 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12663 	.plaintext = {
12664 		.data = plaintext_hash,
12665 		.len = 512
12666 	},
12667 	.iv = {
12668 		.data = {
12669 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12670 			0x08, 0x09, 0x0A, 0x0B
12671 		},
12672 		.len = 12
12673 	},
12674 	.auth_key = {
12675 		.data = {
12676 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12677 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12678 		},
12679 		.len = 16
12680 	},
12681 	.digest = {
12682 		.data = {
12683 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12684 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12685 		},
12686 		.len = 16
12687 	}
12688 };
12689 
12690 static const struct test_crypto_vector
12691 aes128cbc_hmac_sha1_test_vector = {
12692 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12693 	.cipher_offset = 0,
12694 	.cipher_len = 512,
12695 	.cipher_key = {
12696 		.data = {
12697 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12698 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12699 		},
12700 		.len = 16
12701 	},
12702 	.iv = {
12703 		.data = {
12704 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12705 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12706 		},
12707 		.len = 16
12708 	},
12709 	.plaintext = {
12710 		.data = plaintext_hash,
12711 		.len = 512
12712 	},
12713 	.ciphertext = {
12714 		.data = ciphertext512_aes128cbc,
12715 		.len = 512
12716 	},
12717 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12718 	.auth_offset = 0,
12719 	.auth_key = {
12720 		.data = {
12721 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12722 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12723 			0xDE, 0xF4, 0xDE, 0xAD
12724 		},
12725 		.len = 20
12726 	},
12727 	.digest = {
12728 		.data = {
12729 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12730 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12731 			0x18, 0x8C, 0x1D, 0x32
12732 		},
12733 		.len = 20
12734 	}
12735 };
12736 
12737 static const struct test_crypto_vector
12738 aes128cbc_hmac_sha1_aad_test_vector = {
12739 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12740 	.cipher_offset = 8,
12741 	.cipher_len = 496,
12742 	.cipher_key = {
12743 		.data = {
12744 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12745 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12746 		},
12747 		.len = 16
12748 	},
12749 	.iv = {
12750 		.data = {
12751 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12752 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12753 		},
12754 		.len = 16
12755 	},
12756 	.plaintext = {
12757 		.data = plaintext_hash,
12758 		.len = 512
12759 	},
12760 	.ciphertext = {
12761 		.data = ciphertext512_aes128cbc_aad,
12762 		.len = 512
12763 	},
12764 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12765 	.auth_offset = 0,
12766 	.auth_key = {
12767 		.data = {
12768 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12769 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12770 			0xDE, 0xF4, 0xDE, 0xAD
12771 		},
12772 		.len = 20
12773 	},
12774 	.digest = {
12775 		.data = {
12776 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12777 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12778 			0x62, 0x0F, 0xFB, 0x10
12779 		},
12780 		.len = 20
12781 	}
12782 };
12783 
12784 static void
12785 data_corruption(uint8_t *data)
12786 {
12787 	data[0] += 1;
12788 }
12789 
12790 static void
12791 tag_corruption(uint8_t *data, unsigned int tag_offset)
12792 {
12793 	data[tag_offset] += 1;
12794 }
12795 
12796 static int
12797 create_auth_session(struct crypto_unittest_params *ut_params,
12798 		uint8_t dev_id,
12799 		const struct test_crypto_vector *reference,
12800 		enum rte_crypto_auth_operation auth_op)
12801 {
12802 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12803 	uint8_t auth_key[reference->auth_key.len + 1];
12804 
12805 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12806 
12807 	/* Setup Authentication Parameters */
12808 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12809 	ut_params->auth_xform.auth.op = auth_op;
12810 	ut_params->auth_xform.next = NULL;
12811 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12812 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12813 	ut_params->auth_xform.auth.key.data = auth_key;
12814 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12815 
12816 	/* Create Crypto session*/
12817 	ut_params->sess = rte_cryptodev_sym_session_create(
12818 			ts_params->session_mpool);
12819 
12820 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12821 				&ut_params->auth_xform,
12822 				ts_params->session_priv_mpool);
12823 
12824 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12825 
12826 	return 0;
12827 }
12828 
12829 static int
12830 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12831 		uint8_t dev_id,
12832 		const struct test_crypto_vector *reference,
12833 		enum rte_crypto_auth_operation auth_op,
12834 		enum rte_crypto_cipher_operation cipher_op)
12835 {
12836 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12837 	uint8_t cipher_key[reference->cipher_key.len + 1];
12838 	uint8_t auth_key[reference->auth_key.len + 1];
12839 
12840 	memcpy(cipher_key, reference->cipher_key.data,
12841 			reference->cipher_key.len);
12842 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12843 
12844 	/* Setup Authentication Parameters */
12845 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12846 	ut_params->auth_xform.auth.op = auth_op;
12847 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12848 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12849 	ut_params->auth_xform.auth.key.data = auth_key;
12850 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12851 
12852 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12853 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12854 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
12855 	} else {
12856 		ut_params->auth_xform.next = &ut_params->cipher_xform;
12857 
12858 		/* Setup Cipher Parameters */
12859 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12860 		ut_params->cipher_xform.next = NULL;
12861 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12862 		ut_params->cipher_xform.cipher.op = cipher_op;
12863 		ut_params->cipher_xform.cipher.key.data = cipher_key;
12864 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12865 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12866 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12867 	}
12868 
12869 	/* Create Crypto session*/
12870 	ut_params->sess = rte_cryptodev_sym_session_create(
12871 			ts_params->session_mpool);
12872 
12873 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12874 				&ut_params->auth_xform,
12875 				ts_params->session_priv_mpool);
12876 
12877 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12878 
12879 	return 0;
12880 }
12881 
12882 static int
12883 create_auth_operation(struct crypto_testsuite_params *ts_params,
12884 		struct crypto_unittest_params *ut_params,
12885 		const struct test_crypto_vector *reference,
12886 		unsigned int auth_generate)
12887 {
12888 	/* Generate Crypto op data structure */
12889 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12890 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12891 	TEST_ASSERT_NOT_NULL(ut_params->op,
12892 			"Failed to allocate pktmbuf offload");
12893 
12894 	/* Set crypto operation data parameters */
12895 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12896 
12897 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12898 
12899 	/* set crypto operation source mbuf */
12900 	sym_op->m_src = ut_params->ibuf;
12901 
12902 	/* digest */
12903 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12904 			ut_params->ibuf, reference->digest.len);
12905 
12906 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12907 			"no room to append auth tag");
12908 
12909 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12910 			ut_params->ibuf, reference->plaintext.len);
12911 
12912 	if (auth_generate)
12913 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12914 	else
12915 		memcpy(sym_op->auth.digest.data,
12916 				reference->digest.data,
12917 				reference->digest.len);
12918 
12919 	debug_hexdump(stdout, "digest:",
12920 			sym_op->auth.digest.data,
12921 			reference->digest.len);
12922 
12923 	sym_op->auth.data.length = reference->plaintext.len;
12924 	sym_op->auth.data.offset = 0;
12925 
12926 	return 0;
12927 }
12928 
12929 static int
12930 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12931 		struct crypto_unittest_params *ut_params,
12932 		const struct test_crypto_vector *reference,
12933 		unsigned int auth_generate)
12934 {
12935 	/* Generate Crypto op data structure */
12936 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12937 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12938 	TEST_ASSERT_NOT_NULL(ut_params->op,
12939 			"Failed to allocate pktmbuf offload");
12940 
12941 	/* Set crypto operation data parameters */
12942 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12943 
12944 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12945 
12946 	/* set crypto operation source mbuf */
12947 	sym_op->m_src = ut_params->ibuf;
12948 
12949 	/* digest */
12950 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12951 			ut_params->ibuf, reference->digest.len);
12952 
12953 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12954 			"no room to append auth tag");
12955 
12956 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12957 			ut_params->ibuf, reference->ciphertext.len);
12958 
12959 	if (auth_generate)
12960 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12961 	else
12962 		memcpy(sym_op->auth.digest.data,
12963 				reference->digest.data,
12964 				reference->digest.len);
12965 
12966 	debug_hexdump(stdout, "digest:",
12967 			sym_op->auth.digest.data,
12968 			reference->digest.len);
12969 
12970 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12971 			reference->iv.data, reference->iv.len);
12972 
12973 	sym_op->cipher.data.length = 0;
12974 	sym_op->cipher.data.offset = 0;
12975 
12976 	sym_op->auth.data.length = reference->plaintext.len;
12977 	sym_op->auth.data.offset = 0;
12978 
12979 	return 0;
12980 }
12981 
12982 static int
12983 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12984 		struct crypto_unittest_params *ut_params,
12985 		const struct test_crypto_vector *reference,
12986 		unsigned int auth_generate)
12987 {
12988 	/* Generate Crypto op data structure */
12989 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12990 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12991 	TEST_ASSERT_NOT_NULL(ut_params->op,
12992 			"Failed to allocate pktmbuf offload");
12993 
12994 	/* Set crypto operation data parameters */
12995 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12996 
12997 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12998 
12999 	/* set crypto operation source mbuf */
13000 	sym_op->m_src = ut_params->ibuf;
13001 
13002 	/* digest */
13003 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13004 			ut_params->ibuf, reference->digest.len);
13005 
13006 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13007 			"no room to append auth tag");
13008 
13009 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13010 			ut_params->ibuf, reference->ciphertext.len);
13011 
13012 	if (auth_generate)
13013 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13014 	else
13015 		memcpy(sym_op->auth.digest.data,
13016 				reference->digest.data,
13017 				reference->digest.len);
13018 
13019 	debug_hexdump(stdout, "digest:",
13020 			sym_op->auth.digest.data,
13021 			reference->digest.len);
13022 
13023 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13024 			reference->iv.data, reference->iv.len);
13025 
13026 	sym_op->cipher.data.length = reference->cipher_len;
13027 	sym_op->cipher.data.offset = reference->cipher_offset;
13028 
13029 	sym_op->auth.data.length = reference->plaintext.len;
13030 	sym_op->auth.data.offset = reference->auth_offset;
13031 
13032 	return 0;
13033 }
13034 
13035 static int
13036 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13037 		struct crypto_unittest_params *ut_params,
13038 		const struct test_crypto_vector *reference)
13039 {
13040 	return create_auth_operation(ts_params, ut_params, reference, 0);
13041 }
13042 
13043 static int
13044 create_auth_verify_GMAC_operation(
13045 		struct crypto_testsuite_params *ts_params,
13046 		struct crypto_unittest_params *ut_params,
13047 		const struct test_crypto_vector *reference)
13048 {
13049 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
13050 }
13051 
13052 static int
13053 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13054 		struct crypto_unittest_params *ut_params,
13055 		const struct test_crypto_vector *reference)
13056 {
13057 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
13058 }
13059 
13060 static int
13061 test_authentication_verify_fail_when_data_corruption(
13062 		struct crypto_testsuite_params *ts_params,
13063 		struct crypto_unittest_params *ut_params,
13064 		const struct test_crypto_vector *reference,
13065 		unsigned int data_corrupted)
13066 {
13067 	int retval;
13068 
13069 	uint8_t *plaintext;
13070 	struct rte_cryptodev_info dev_info;
13071 
13072 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13073 	uint64_t feat_flags = dev_info.feature_flags;
13074 
13075 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13076 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13077 		printf("Device doesn't support RAW data-path APIs.\n");
13078 		return TEST_SKIPPED;
13079 	}
13080 
13081 	/* Verify the capabilities */
13082 	struct rte_cryptodev_sym_capability_idx cap_idx;
13083 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13084 	cap_idx.algo.auth = reference->auth_algo;
13085 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13086 			&cap_idx) == NULL)
13087 		return TEST_SKIPPED;
13088 
13089 
13090 	/* Create session */
13091 	retval = create_auth_session(ut_params,
13092 			ts_params->valid_devs[0],
13093 			reference,
13094 			RTE_CRYPTO_AUTH_OP_VERIFY);
13095 	if (retval < 0)
13096 		return retval;
13097 
13098 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13099 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13100 			"Failed to allocate input buffer in mempool");
13101 
13102 	/* clear mbuf payload */
13103 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13104 			rte_pktmbuf_tailroom(ut_params->ibuf));
13105 
13106 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13107 			reference->plaintext.len);
13108 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13109 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13110 
13111 	debug_hexdump(stdout, "plaintext:", plaintext,
13112 		reference->plaintext.len);
13113 
13114 	/* Create operation */
13115 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
13116 
13117 	if (retval < 0)
13118 		return retval;
13119 
13120 	if (data_corrupted)
13121 		data_corruption(plaintext);
13122 	else
13123 		tag_corruption(plaintext, reference->plaintext.len);
13124 
13125 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13126 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13127 			ut_params->op);
13128 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13129 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13130 			"authentication not failed");
13131 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13132 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13133 				ut_params->op, 0, 1, 0, 0);
13134 	else {
13135 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13136 			ut_params->op);
13137 	}
13138 	if (ut_params->op == NULL)
13139 		return 0;
13140 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13141 		return 0;
13142 
13143 	return -1;
13144 }
13145 
13146 static int
13147 test_authentication_verify_GMAC_fail_when_corruption(
13148 		struct crypto_testsuite_params *ts_params,
13149 		struct crypto_unittest_params *ut_params,
13150 		const struct test_crypto_vector *reference,
13151 		unsigned int data_corrupted)
13152 {
13153 	int retval;
13154 	uint8_t *plaintext;
13155 	struct rte_cryptodev_info dev_info;
13156 
13157 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13158 	uint64_t feat_flags = dev_info.feature_flags;
13159 
13160 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13161 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13162 		printf("Device doesn't support RAW data-path APIs.\n");
13163 		return TEST_SKIPPED;
13164 	}
13165 
13166 	/* Verify the capabilities */
13167 	struct rte_cryptodev_sym_capability_idx cap_idx;
13168 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13169 	cap_idx.algo.auth = reference->auth_algo;
13170 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13171 			&cap_idx) == NULL)
13172 		return TEST_SKIPPED;
13173 
13174 	/* Create session */
13175 	retval = create_auth_cipher_session(ut_params,
13176 			ts_params->valid_devs[0],
13177 			reference,
13178 			RTE_CRYPTO_AUTH_OP_VERIFY,
13179 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13180 	if (retval < 0)
13181 		return retval;
13182 
13183 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13184 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13185 			"Failed to allocate input buffer in mempool");
13186 
13187 	/* clear mbuf payload */
13188 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13189 			rte_pktmbuf_tailroom(ut_params->ibuf));
13190 
13191 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13192 			reference->plaintext.len);
13193 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13194 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13195 
13196 	debug_hexdump(stdout, "plaintext:", plaintext,
13197 		reference->plaintext.len);
13198 
13199 	/* Create operation */
13200 	retval = create_auth_verify_GMAC_operation(ts_params,
13201 			ut_params,
13202 			reference);
13203 
13204 	if (retval < 0)
13205 		return retval;
13206 
13207 	if (data_corrupted)
13208 		data_corruption(plaintext);
13209 	else
13210 		tag_corruption(plaintext, reference->aad.len);
13211 
13212 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13213 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13214 			ut_params->op);
13215 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13216 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13217 			"authentication not failed");
13218 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13219 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13220 				ut_params->op, 0, 1, 0, 0);
13221 	else {
13222 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13223 			ut_params->op);
13224 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13225 	}
13226 
13227 	return 0;
13228 }
13229 
13230 static int
13231 test_authenticated_decryption_fail_when_corruption(
13232 		struct crypto_testsuite_params *ts_params,
13233 		struct crypto_unittest_params *ut_params,
13234 		const struct test_crypto_vector *reference,
13235 		unsigned int data_corrupted)
13236 {
13237 	int retval;
13238 
13239 	uint8_t *ciphertext;
13240 	struct rte_cryptodev_info dev_info;
13241 
13242 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13243 	uint64_t feat_flags = dev_info.feature_flags;
13244 
13245 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13246 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13247 		printf("Device doesn't support RAW data-path APIs.\n");
13248 		return TEST_SKIPPED;
13249 	}
13250 
13251 	/* Verify the capabilities */
13252 	struct rte_cryptodev_sym_capability_idx cap_idx;
13253 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13254 	cap_idx.algo.auth = reference->auth_algo;
13255 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13256 			&cap_idx) == NULL)
13257 		return TEST_SKIPPED;
13258 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13259 	cap_idx.algo.cipher = reference->crypto_algo;
13260 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13261 			&cap_idx) == NULL)
13262 		return TEST_SKIPPED;
13263 
13264 	/* Create session */
13265 	retval = create_auth_cipher_session(ut_params,
13266 			ts_params->valid_devs[0],
13267 			reference,
13268 			RTE_CRYPTO_AUTH_OP_VERIFY,
13269 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13270 	if (retval < 0)
13271 		return retval;
13272 
13273 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13274 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13275 			"Failed to allocate input buffer in mempool");
13276 
13277 	/* clear mbuf payload */
13278 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13279 			rte_pktmbuf_tailroom(ut_params->ibuf));
13280 
13281 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13282 			reference->ciphertext.len);
13283 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13284 	memcpy(ciphertext, reference->ciphertext.data,
13285 			reference->ciphertext.len);
13286 
13287 	/* Create operation */
13288 	retval = create_cipher_auth_verify_operation(ts_params,
13289 			ut_params,
13290 			reference);
13291 
13292 	if (retval < 0)
13293 		return retval;
13294 
13295 	if (data_corrupted)
13296 		data_corruption(ciphertext);
13297 	else
13298 		tag_corruption(ciphertext, reference->ciphertext.len);
13299 
13300 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13301 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13302 			ut_params->op);
13303 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13304 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13305 			"authentication not failed");
13306 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13307 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13308 				ut_params->op, 1, 1, 0, 0);
13309 	else {
13310 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13311 			ut_params->op);
13312 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13313 	}
13314 
13315 	return 0;
13316 }
13317 
13318 static int
13319 test_authenticated_encrypt_with_esn(
13320 		struct crypto_testsuite_params *ts_params,
13321 		struct crypto_unittest_params *ut_params,
13322 		const struct test_crypto_vector *reference)
13323 {
13324 	int retval;
13325 
13326 	uint8_t *authciphertext, *plaintext, *auth_tag;
13327 	uint16_t plaintext_pad_len;
13328 	uint8_t cipher_key[reference->cipher_key.len + 1];
13329 	uint8_t auth_key[reference->auth_key.len + 1];
13330 	struct rte_cryptodev_info dev_info;
13331 
13332 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13333 	uint64_t feat_flags = dev_info.feature_flags;
13334 
13335 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13336 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13337 		printf("Device doesn't support RAW data-path APIs.\n");
13338 		return TEST_SKIPPED;
13339 	}
13340 
13341 	/* Verify the capabilities */
13342 	struct rte_cryptodev_sym_capability_idx cap_idx;
13343 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13344 	cap_idx.algo.auth = reference->auth_algo;
13345 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13346 			&cap_idx) == NULL)
13347 		return TEST_SKIPPED;
13348 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13349 	cap_idx.algo.cipher = reference->crypto_algo;
13350 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13351 			&cap_idx) == NULL)
13352 		return TEST_SKIPPED;
13353 
13354 	/* Create session */
13355 	memcpy(cipher_key, reference->cipher_key.data,
13356 			reference->cipher_key.len);
13357 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13358 
13359 	/* Setup Cipher Parameters */
13360 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13361 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13362 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13363 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13364 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13365 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13366 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13367 
13368 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13369 
13370 	/* Setup Authentication Parameters */
13371 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13372 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13373 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13374 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13375 	ut_params->auth_xform.auth.key.data = auth_key;
13376 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13377 	ut_params->auth_xform.next = NULL;
13378 
13379 	/* Create Crypto session*/
13380 	ut_params->sess = rte_cryptodev_sym_session_create(
13381 			ts_params->session_mpool);
13382 
13383 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13384 				ut_params->sess,
13385 				&ut_params->cipher_xform,
13386 				ts_params->session_priv_mpool);
13387 
13388 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13389 
13390 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13391 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13392 			"Failed to allocate input buffer in mempool");
13393 
13394 	/* clear mbuf payload */
13395 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13396 			rte_pktmbuf_tailroom(ut_params->ibuf));
13397 
13398 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13399 			reference->plaintext.len);
13400 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13401 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13402 
13403 	/* Create operation */
13404 	retval = create_cipher_auth_operation(ts_params,
13405 			ut_params,
13406 			reference, 0);
13407 
13408 	if (retval < 0)
13409 		return retval;
13410 
13411 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13412 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13413 			ut_params->op);
13414 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13415 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13416 				ut_params->op, 1, 1, 0, 0);
13417 	else
13418 		ut_params->op = process_crypto_request(
13419 			ts_params->valid_devs[0], ut_params->op);
13420 
13421 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13422 
13423 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13424 			"crypto op processing failed");
13425 
13426 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13427 
13428 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13429 			ut_params->op->sym->auth.data.offset);
13430 	auth_tag = authciphertext + plaintext_pad_len;
13431 	debug_hexdump(stdout, "ciphertext:", authciphertext,
13432 			reference->ciphertext.len);
13433 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13434 
13435 	/* Validate obuf */
13436 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13437 			authciphertext,
13438 			reference->ciphertext.data,
13439 			reference->ciphertext.len,
13440 			"Ciphertext data not as expected");
13441 
13442 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13443 			auth_tag,
13444 			reference->digest.data,
13445 			reference->digest.len,
13446 			"Generated digest not as expected");
13447 
13448 	return TEST_SUCCESS;
13449 
13450 }
13451 
13452 static int
13453 test_authenticated_decrypt_with_esn(
13454 		struct crypto_testsuite_params *ts_params,
13455 		struct crypto_unittest_params *ut_params,
13456 		const struct test_crypto_vector *reference)
13457 {
13458 	int retval;
13459 
13460 	uint8_t *ciphertext;
13461 	uint8_t cipher_key[reference->cipher_key.len + 1];
13462 	uint8_t auth_key[reference->auth_key.len + 1];
13463 	struct rte_cryptodev_info dev_info;
13464 
13465 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13466 	uint64_t feat_flags = dev_info.feature_flags;
13467 
13468 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13469 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13470 		printf("Device doesn't support RAW data-path APIs.\n");
13471 		return TEST_SKIPPED;
13472 	}
13473 
13474 	/* Verify the capabilities */
13475 	struct rte_cryptodev_sym_capability_idx cap_idx;
13476 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13477 	cap_idx.algo.auth = reference->auth_algo;
13478 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13479 			&cap_idx) == NULL)
13480 		return TEST_SKIPPED;
13481 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13482 	cap_idx.algo.cipher = reference->crypto_algo;
13483 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13484 			&cap_idx) == NULL)
13485 		return TEST_SKIPPED;
13486 
13487 	/* Create session */
13488 	memcpy(cipher_key, reference->cipher_key.data,
13489 			reference->cipher_key.len);
13490 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13491 
13492 	/* Setup Authentication Parameters */
13493 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13494 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13495 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13496 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13497 	ut_params->auth_xform.auth.key.data = auth_key;
13498 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13499 	ut_params->auth_xform.next = &ut_params->cipher_xform;
13500 
13501 	/* Setup Cipher Parameters */
13502 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13503 	ut_params->cipher_xform.next = NULL;
13504 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13505 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13506 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13507 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13508 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13509 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13510 
13511 	/* Create Crypto session*/
13512 	ut_params->sess = rte_cryptodev_sym_session_create(
13513 			ts_params->session_mpool);
13514 
13515 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13516 				ut_params->sess,
13517 				&ut_params->auth_xform,
13518 				ts_params->session_priv_mpool);
13519 
13520 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13521 
13522 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13523 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13524 			"Failed to allocate input buffer in mempool");
13525 
13526 	/* clear mbuf payload */
13527 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13528 			rte_pktmbuf_tailroom(ut_params->ibuf));
13529 
13530 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13531 			reference->ciphertext.len);
13532 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13533 	memcpy(ciphertext, reference->ciphertext.data,
13534 			reference->ciphertext.len);
13535 
13536 	/* Create operation */
13537 	retval = create_cipher_auth_verify_operation(ts_params,
13538 			ut_params,
13539 			reference);
13540 
13541 	if (retval < 0)
13542 		return retval;
13543 
13544 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13545 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13546 			ut_params->op);
13547 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13548 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13549 				ut_params->op, 1, 1, 0, 0);
13550 	else
13551 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13552 			ut_params->op);
13553 
13554 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13555 	TEST_ASSERT_EQUAL(ut_params->op->status,
13556 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13557 			"crypto op processing passed");
13558 
13559 	ut_params->obuf = ut_params->op->sym->m_src;
13560 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13561 
13562 	return 0;
13563 }
13564 
13565 static int
13566 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13567 		const struct aead_test_data *tdata,
13568 		void *digest_mem, uint64_t digest_phys)
13569 {
13570 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13571 	struct crypto_unittest_params *ut_params = &unittest_params;
13572 
13573 	const unsigned int auth_tag_len = tdata->auth_tag.len;
13574 	const unsigned int iv_len = tdata->iv.len;
13575 	unsigned int aad_len = tdata->aad.len;
13576 	unsigned int aad_len_pad = 0;
13577 
13578 	/* Generate Crypto op data structure */
13579 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13580 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13581 	TEST_ASSERT_NOT_NULL(ut_params->op,
13582 		"Failed to allocate symmetric crypto operation struct");
13583 
13584 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13585 
13586 	sym_op->aead.digest.data = digest_mem;
13587 
13588 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13589 			"no room to append digest");
13590 
13591 	sym_op->aead.digest.phys_addr = digest_phys;
13592 
13593 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13594 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13595 				auth_tag_len);
13596 		debug_hexdump(stdout, "digest:",
13597 				sym_op->aead.digest.data,
13598 				auth_tag_len);
13599 	}
13600 
13601 	/* Append aad data */
13602 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13603 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13604 				uint8_t *, IV_OFFSET);
13605 
13606 		/* Copy IV 1 byte after the IV pointer, according to the API */
13607 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13608 
13609 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13610 
13611 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13612 				ut_params->ibuf, aad_len);
13613 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13614 				"no room to prepend aad");
13615 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13616 				ut_params->ibuf);
13617 
13618 		memset(sym_op->aead.aad.data, 0, aad_len);
13619 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
13620 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13621 
13622 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13623 		debug_hexdump(stdout, "aad:",
13624 				sym_op->aead.aad.data, aad_len);
13625 	} else {
13626 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13627 				uint8_t *, IV_OFFSET);
13628 
13629 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13630 
13631 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13632 
13633 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13634 				ut_params->ibuf, aad_len_pad);
13635 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13636 				"no room to prepend aad");
13637 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13638 				ut_params->ibuf);
13639 
13640 		memset(sym_op->aead.aad.data, 0, aad_len);
13641 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13642 
13643 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13644 		debug_hexdump(stdout, "aad:",
13645 				sym_op->aead.aad.data, aad_len);
13646 	}
13647 
13648 	sym_op->aead.data.length = tdata->plaintext.len;
13649 	sym_op->aead.data.offset = aad_len_pad;
13650 
13651 	return 0;
13652 }
13653 
13654 #define SGL_MAX_NO	16
13655 
13656 static int
13657 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13658 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13659 {
13660 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13661 	struct crypto_unittest_params *ut_params = &unittest_params;
13662 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13663 	int retval;
13664 	int to_trn = 0;
13665 	int to_trn_tbl[SGL_MAX_NO];
13666 	int segs = 1;
13667 	unsigned int trn_data = 0;
13668 	uint8_t *plaintext, *ciphertext, *auth_tag;
13669 	struct rte_cryptodev_info dev_info;
13670 
13671 	/* Verify the capabilities */
13672 	struct rte_cryptodev_sym_capability_idx cap_idx;
13673 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13674 	cap_idx.algo.aead = tdata->algo;
13675 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13676 			&cap_idx) == NULL)
13677 		return TEST_SKIPPED;
13678 
13679 	/* OOP not supported with CPU crypto */
13680 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13681 		return TEST_SKIPPED;
13682 
13683 	/* Detailed check for the particular SGL support flag */
13684 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13685 	if (!oop) {
13686 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13687 		if (sgl_in && (!(dev_info.feature_flags &
13688 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13689 			return TEST_SKIPPED;
13690 
13691 		uint64_t feat_flags = dev_info.feature_flags;
13692 
13693 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13694 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13695 			printf("Device doesn't support RAW data-path APIs.\n");
13696 			return TEST_SKIPPED;
13697 		}
13698 	} else {
13699 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13700 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13701 				tdata->plaintext.len;
13702 		/* Raw data path API does not support OOP */
13703 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13704 			return TEST_SKIPPED;
13705 		if (sgl_in && !sgl_out) {
13706 			if (!(dev_info.feature_flags &
13707 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13708 				return TEST_SKIPPED;
13709 		} else if (!sgl_in && sgl_out) {
13710 			if (!(dev_info.feature_flags &
13711 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13712 				return TEST_SKIPPED;
13713 		} else if (sgl_in && sgl_out) {
13714 			if (!(dev_info.feature_flags &
13715 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13716 				return TEST_SKIPPED;
13717 		}
13718 	}
13719 
13720 	if (fragsz > tdata->plaintext.len)
13721 		fragsz = tdata->plaintext.len;
13722 
13723 	uint16_t plaintext_len = fragsz;
13724 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13725 
13726 	if (fragsz_oop > tdata->plaintext.len)
13727 		frag_size_oop = tdata->plaintext.len;
13728 
13729 	int ecx = 0;
13730 	void *digest_mem = NULL;
13731 
13732 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13733 
13734 	if (tdata->plaintext.len % fragsz != 0) {
13735 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13736 			return 1;
13737 	}	else {
13738 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13739 			return 1;
13740 	}
13741 
13742 	/*
13743 	 * For out-op-place we need to alloc another mbuf
13744 	 */
13745 	if (oop) {
13746 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13747 		rte_pktmbuf_append(ut_params->obuf,
13748 				frag_size_oop + prepend_len);
13749 		buf_oop = ut_params->obuf;
13750 	}
13751 
13752 	/* Create AEAD session */
13753 	retval = create_aead_session(ts_params->valid_devs[0],
13754 			tdata->algo,
13755 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13756 			tdata->key.data, tdata->key.len,
13757 			tdata->aad.len, tdata->auth_tag.len,
13758 			tdata->iv.len);
13759 	if (retval < 0)
13760 		return retval;
13761 
13762 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13763 
13764 	/* clear mbuf payload */
13765 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13766 			rte_pktmbuf_tailroom(ut_params->ibuf));
13767 
13768 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13769 			plaintext_len);
13770 
13771 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13772 
13773 	trn_data += plaintext_len;
13774 
13775 	buf = ut_params->ibuf;
13776 
13777 	/*
13778 	 * Loop until no more fragments
13779 	 */
13780 
13781 	while (trn_data < tdata->plaintext.len) {
13782 		++segs;
13783 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13784 				(tdata->plaintext.len - trn_data) : fragsz;
13785 
13786 		to_trn_tbl[ecx++] = to_trn;
13787 
13788 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13789 		buf = buf->next;
13790 
13791 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13792 				rte_pktmbuf_tailroom(buf));
13793 
13794 		/* OOP */
13795 		if (oop && !fragsz_oop) {
13796 			buf_last_oop = buf_oop->next =
13797 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13798 			buf_oop = buf_oop->next;
13799 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13800 					0, rte_pktmbuf_tailroom(buf_oop));
13801 			rte_pktmbuf_append(buf_oop, to_trn);
13802 		}
13803 
13804 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13805 				to_trn);
13806 
13807 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13808 				to_trn);
13809 		trn_data += to_trn;
13810 		if (trn_data  == tdata->plaintext.len) {
13811 			if (oop) {
13812 				if (!fragsz_oop)
13813 					digest_mem = rte_pktmbuf_append(buf_oop,
13814 						tdata->auth_tag.len);
13815 			} else
13816 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13817 					tdata->auth_tag.len);
13818 		}
13819 	}
13820 
13821 	uint64_t digest_phys = 0;
13822 
13823 	ut_params->ibuf->nb_segs = segs;
13824 
13825 	segs = 1;
13826 	if (fragsz_oop && oop) {
13827 		to_trn = 0;
13828 		ecx = 0;
13829 
13830 		if (frag_size_oop == tdata->plaintext.len) {
13831 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
13832 				tdata->auth_tag.len);
13833 
13834 			digest_phys = rte_pktmbuf_iova_offset(
13835 					ut_params->obuf,
13836 					tdata->plaintext.len + prepend_len);
13837 		}
13838 
13839 		trn_data = frag_size_oop;
13840 		while (trn_data < tdata->plaintext.len) {
13841 			++segs;
13842 			to_trn =
13843 				(tdata->plaintext.len - trn_data <
13844 						frag_size_oop) ?
13845 				(tdata->plaintext.len - trn_data) :
13846 						frag_size_oop;
13847 
13848 			to_trn_tbl[ecx++] = to_trn;
13849 
13850 			buf_last_oop = buf_oop->next =
13851 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13852 			buf_oop = buf_oop->next;
13853 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13854 					0, rte_pktmbuf_tailroom(buf_oop));
13855 			rte_pktmbuf_append(buf_oop, to_trn);
13856 
13857 			trn_data += to_trn;
13858 
13859 			if (trn_data  == tdata->plaintext.len) {
13860 				digest_mem = rte_pktmbuf_append(buf_oop,
13861 					tdata->auth_tag.len);
13862 			}
13863 		}
13864 
13865 		ut_params->obuf->nb_segs = segs;
13866 	}
13867 
13868 	/*
13869 	 * Place digest at the end of the last buffer
13870 	 */
13871 	if (!digest_phys)
13872 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13873 	if (oop && buf_last_oop)
13874 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13875 
13876 	if (!digest_mem && !oop) {
13877 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13878 				+ tdata->auth_tag.len);
13879 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13880 				tdata->plaintext.len);
13881 	}
13882 
13883 	/* Create AEAD operation */
13884 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13885 			tdata, digest_mem, digest_phys);
13886 
13887 	if (retval < 0)
13888 		return retval;
13889 
13890 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13891 
13892 	ut_params->op->sym->m_src = ut_params->ibuf;
13893 	if (oop)
13894 		ut_params->op->sym->m_dst = ut_params->obuf;
13895 
13896 	/* Process crypto operation */
13897 	if (oop == IN_PLACE &&
13898 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13899 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13900 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13901 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13902 				ut_params->op, 0, 0, 0, 0);
13903 	else
13904 		TEST_ASSERT_NOT_NULL(
13905 			process_crypto_request(ts_params->valid_devs[0],
13906 			ut_params->op), "failed to process sym crypto op");
13907 
13908 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13909 			"crypto op processing failed");
13910 
13911 
13912 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13913 			uint8_t *, prepend_len);
13914 	if (oop) {
13915 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13916 				uint8_t *, prepend_len);
13917 	}
13918 
13919 	if (fragsz_oop)
13920 		fragsz = fragsz_oop;
13921 
13922 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13923 			ciphertext,
13924 			tdata->ciphertext.data,
13925 			fragsz,
13926 			"Ciphertext data not as expected");
13927 
13928 	buf = ut_params->op->sym->m_src->next;
13929 	if (oop)
13930 		buf = ut_params->op->sym->m_dst->next;
13931 
13932 	unsigned int off = fragsz;
13933 
13934 	ecx = 0;
13935 	while (buf) {
13936 		ciphertext = rte_pktmbuf_mtod(buf,
13937 				uint8_t *);
13938 
13939 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
13940 				ciphertext,
13941 				tdata->ciphertext.data + off,
13942 				to_trn_tbl[ecx],
13943 				"Ciphertext data not as expected");
13944 
13945 		off += to_trn_tbl[ecx++];
13946 		buf = buf->next;
13947 	}
13948 
13949 	auth_tag = digest_mem;
13950 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13951 			auth_tag,
13952 			tdata->auth_tag.data,
13953 			tdata->auth_tag.len,
13954 			"Generated auth tag not as expected");
13955 
13956 	return 0;
13957 }
13958 
13959 static int
13960 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13961 {
13962 	return test_authenticated_encryption_SGL(
13963 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13964 }
13965 
13966 static int
13967 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13968 {
13969 	return test_authenticated_encryption_SGL(
13970 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13971 }
13972 
13973 static int
13974 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13975 {
13976 	return test_authenticated_encryption_SGL(
13977 			&gcm_test_case_8, OUT_OF_PLACE, 400,
13978 			gcm_test_case_8.plaintext.len);
13979 }
13980 
13981 static int
13982 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13983 {
13984 	/* This test is not for OPENSSL PMD */
13985 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
13986 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13987 		return TEST_SKIPPED;
13988 
13989 	return test_authenticated_encryption_SGL(
13990 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13991 }
13992 
13993 static int
13994 test_authentication_verify_fail_when_data_corrupted(
13995 		struct crypto_testsuite_params *ts_params,
13996 		struct crypto_unittest_params *ut_params,
13997 		const struct test_crypto_vector *reference)
13998 {
13999 	return test_authentication_verify_fail_when_data_corruption(
14000 			ts_params, ut_params, reference, 1);
14001 }
14002 
14003 static int
14004 test_authentication_verify_fail_when_tag_corrupted(
14005 		struct crypto_testsuite_params *ts_params,
14006 		struct crypto_unittest_params *ut_params,
14007 		const struct test_crypto_vector *reference)
14008 {
14009 	return test_authentication_verify_fail_when_data_corruption(
14010 			ts_params, ut_params, reference, 0);
14011 }
14012 
14013 static int
14014 test_authentication_verify_GMAC_fail_when_data_corrupted(
14015 		struct crypto_testsuite_params *ts_params,
14016 		struct crypto_unittest_params *ut_params,
14017 		const struct test_crypto_vector *reference)
14018 {
14019 	return test_authentication_verify_GMAC_fail_when_corruption(
14020 			ts_params, ut_params, reference, 1);
14021 }
14022 
14023 static int
14024 test_authentication_verify_GMAC_fail_when_tag_corrupted(
14025 		struct crypto_testsuite_params *ts_params,
14026 		struct crypto_unittest_params *ut_params,
14027 		const struct test_crypto_vector *reference)
14028 {
14029 	return test_authentication_verify_GMAC_fail_when_corruption(
14030 			ts_params, ut_params, reference, 0);
14031 }
14032 
14033 static int
14034 test_authenticated_decryption_fail_when_data_corrupted(
14035 		struct crypto_testsuite_params *ts_params,
14036 		struct crypto_unittest_params *ut_params,
14037 		const struct test_crypto_vector *reference)
14038 {
14039 	return test_authenticated_decryption_fail_when_corruption(
14040 			ts_params, ut_params, reference, 1);
14041 }
14042 
14043 static int
14044 test_authenticated_decryption_fail_when_tag_corrupted(
14045 		struct crypto_testsuite_params *ts_params,
14046 		struct crypto_unittest_params *ut_params,
14047 		const struct test_crypto_vector *reference)
14048 {
14049 	return test_authenticated_decryption_fail_when_corruption(
14050 			ts_params, ut_params, reference, 0);
14051 }
14052 
14053 static int
14054 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
14055 {
14056 	return test_authentication_verify_fail_when_data_corrupted(
14057 			&testsuite_params, &unittest_params,
14058 			&hmac_sha1_test_crypto_vector);
14059 }
14060 
14061 static int
14062 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
14063 {
14064 	return test_authentication_verify_fail_when_tag_corrupted(
14065 			&testsuite_params, &unittest_params,
14066 			&hmac_sha1_test_crypto_vector);
14067 }
14068 
14069 static int
14070 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
14071 {
14072 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
14073 			&testsuite_params, &unittest_params,
14074 			&aes128_gmac_test_vector);
14075 }
14076 
14077 static int
14078 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
14079 {
14080 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
14081 			&testsuite_params, &unittest_params,
14082 			&aes128_gmac_test_vector);
14083 }
14084 
14085 static int
14086 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
14087 {
14088 	return test_authenticated_decryption_fail_when_data_corrupted(
14089 			&testsuite_params,
14090 			&unittest_params,
14091 			&aes128cbc_hmac_sha1_test_vector);
14092 }
14093 
14094 static int
14095 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14096 {
14097 	return test_authenticated_decryption_fail_when_tag_corrupted(
14098 			&testsuite_params,
14099 			&unittest_params,
14100 			&aes128cbc_hmac_sha1_test_vector);
14101 }
14102 
14103 static int
14104 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14105 {
14106 	return test_authenticated_encrypt_with_esn(
14107 			&testsuite_params,
14108 			&unittest_params,
14109 			&aes128cbc_hmac_sha1_aad_test_vector);
14110 }
14111 
14112 static int
14113 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14114 {
14115 	return test_authenticated_decrypt_with_esn(
14116 			&testsuite_params,
14117 			&unittest_params,
14118 			&aes128cbc_hmac_sha1_aad_test_vector);
14119 }
14120 
14121 static int
14122 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14123 {
14124 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14125 }
14126 
14127 static int
14128 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14129 {
14130 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14131 }
14132 
14133 static int
14134 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
14135 {
14136 	return test_authenticated_encryption_SGL(
14137 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
14138 		chacha20_poly1305_case_2.plaintext.len);
14139 }
14140 
14141 #ifdef RTE_CRYPTO_SCHEDULER
14142 
14143 /* global AESNI worker IDs for the scheduler test */
14144 uint8_t aesni_ids[2];
14145 
14146 static int
14147 scheduler_testsuite_setup(void)
14148 {
14149 	uint32_t i = 0;
14150 	int32_t nb_devs, ret;
14151 	char vdev_args[VDEV_ARGS_SIZE] = {""};
14152 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14153 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
14154 	uint16_t worker_core_count = 0;
14155 	uint16_t socket_id = 0;
14156 
14157 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14158 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14159 
14160 		/* Identify the Worker Cores
14161 		 * Use 2 worker cores for the device args
14162 		 */
14163 		RTE_LCORE_FOREACH_WORKER(i) {
14164 			if (worker_core_count > 1)
14165 				break;
14166 			snprintf(vdev_args, sizeof(vdev_args),
14167 					"%s%d", temp_str, i);
14168 			strcpy(temp_str, vdev_args);
14169 			strlcat(temp_str, ";", sizeof(temp_str));
14170 			worker_core_count++;
14171 			socket_id = rte_lcore_to_socket_id(i);
14172 		}
14173 		if (worker_core_count != 2) {
14174 			RTE_LOG(ERR, USER1,
14175 				"Cryptodev scheduler test require at least "
14176 				"two worker cores to run. "
14177 				"Please use the correct coremask.\n");
14178 			return TEST_FAILED;
14179 		}
14180 		strcpy(temp_str, vdev_args);
14181 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14182 				temp_str, socket_id);
14183 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14184 		nb_devs = rte_cryptodev_device_count_by_driver(
14185 				rte_cryptodev_driver_id_get(
14186 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14187 		if (nb_devs < 1) {
14188 			ret = rte_vdev_init(
14189 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14190 					vdev_args);
14191 			TEST_ASSERT(ret == 0,
14192 				"Failed to create instance %u of pmd : %s",
14193 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14194 		}
14195 	}
14196 	return testsuite_setup();
14197 }
14198 
14199 static int
14200 test_scheduler_attach_worker_op(void)
14201 {
14202 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14203 	uint8_t sched_id = ts_params->valid_devs[0];
14204 	uint32_t i, nb_devs_attached = 0;
14205 	int ret;
14206 	char vdev_name[32];
14207 	unsigned int count = rte_cryptodev_count();
14208 
14209 	/* create 2 AESNI_MB vdevs on top of existing devices */
14210 	for (i = count; i < count + 2; i++) {
14211 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14212 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14213 				i);
14214 		ret = rte_vdev_init(vdev_name, NULL);
14215 
14216 		TEST_ASSERT(ret == 0,
14217 			"Failed to create instance %u of"
14218 			" pmd : %s",
14219 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14220 
14221 		if (ret < 0) {
14222 			RTE_LOG(ERR, USER1,
14223 				"Failed to create 2 AESNI MB PMDs.\n");
14224 			return TEST_SKIPPED;
14225 		}
14226 	}
14227 
14228 	/* attach 2 AESNI_MB cdevs */
14229 	for (i = count; i < count + 2; i++) {
14230 		struct rte_cryptodev_info info;
14231 		unsigned int session_size;
14232 
14233 		rte_cryptodev_info_get(i, &info);
14234 		if (info.driver_id != rte_cryptodev_driver_id_get(
14235 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14236 			continue;
14237 
14238 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14239 		/*
14240 		 * Create the session mempool again, since now there are new devices
14241 		 * to use the mempool.
14242 		 */
14243 		if (ts_params->session_mpool) {
14244 			rte_mempool_free(ts_params->session_mpool);
14245 			ts_params->session_mpool = NULL;
14246 		}
14247 		if (ts_params->session_priv_mpool) {
14248 			rte_mempool_free(ts_params->session_priv_mpool);
14249 			ts_params->session_priv_mpool = NULL;
14250 		}
14251 
14252 		if (info.sym.max_nb_sessions != 0 &&
14253 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14254 			RTE_LOG(ERR, USER1,
14255 					"Device does not support "
14256 					"at least %u sessions\n",
14257 					MAX_NB_SESSIONS);
14258 			return TEST_FAILED;
14259 		}
14260 		/*
14261 		 * Create mempool with maximum number of sessions,
14262 		 * to include the session headers
14263 		 */
14264 		if (ts_params->session_mpool == NULL) {
14265 			ts_params->session_mpool =
14266 				rte_cryptodev_sym_session_pool_create(
14267 						"test_sess_mp",
14268 						MAX_NB_SESSIONS, 0, 0, 0,
14269 						SOCKET_ID_ANY);
14270 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14271 					"session mempool allocation failed");
14272 		}
14273 
14274 		/*
14275 		 * Create mempool with maximum number of sessions,
14276 		 * to include device specific session private data
14277 		 */
14278 		if (ts_params->session_priv_mpool == NULL) {
14279 			ts_params->session_priv_mpool = rte_mempool_create(
14280 					"test_sess_mp_priv",
14281 					MAX_NB_SESSIONS,
14282 					session_size,
14283 					0, 0, NULL, NULL, NULL,
14284 					NULL, SOCKET_ID_ANY,
14285 					0);
14286 
14287 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14288 					"session mempool allocation failed");
14289 		}
14290 
14291 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
14292 		ts_params->qp_conf.mp_session_private =
14293 				ts_params->session_priv_mpool;
14294 
14295 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14296 				(uint8_t)i);
14297 
14298 		TEST_ASSERT(ret == 0,
14299 			"Failed to attach device %u of pmd : %s", i,
14300 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14301 
14302 		aesni_ids[nb_devs_attached] = (uint8_t)i;
14303 
14304 		nb_devs_attached++;
14305 	}
14306 
14307 	return 0;
14308 }
14309 
14310 static int
14311 test_scheduler_detach_worker_op(void)
14312 {
14313 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14314 	uint8_t sched_id = ts_params->valid_devs[0];
14315 	uint32_t i;
14316 	int ret;
14317 
14318 	for (i = 0; i < 2; i++) {
14319 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14320 				aesni_ids[i]);
14321 		TEST_ASSERT(ret == 0,
14322 			"Failed to detach device %u", aesni_ids[i]);
14323 	}
14324 
14325 	return 0;
14326 }
14327 
14328 static int
14329 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14330 {
14331 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14332 	uint8_t sched_id = ts_params->valid_devs[0];
14333 	/* set mode */
14334 	return rte_cryptodev_scheduler_mode_set(sched_id,
14335 		scheduler_mode);
14336 }
14337 
14338 static int
14339 test_scheduler_mode_roundrobin_op(void)
14340 {
14341 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14342 			0, "Failed to set roundrobin mode");
14343 	return 0;
14344 
14345 }
14346 
14347 static int
14348 test_scheduler_mode_multicore_op(void)
14349 {
14350 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14351 			0, "Failed to set multicore mode");
14352 
14353 	return 0;
14354 }
14355 
14356 static int
14357 test_scheduler_mode_failover_op(void)
14358 {
14359 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14360 			0, "Failed to set failover mode");
14361 
14362 	return 0;
14363 }
14364 
14365 static int
14366 test_scheduler_mode_pkt_size_distr_op(void)
14367 {
14368 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14369 			0, "Failed to set pktsize mode");
14370 
14371 	return 0;
14372 }
14373 
14374 static int
14375 scheduler_multicore_testsuite_setup(void)
14376 {
14377 	if (test_scheduler_attach_worker_op() < 0)
14378 		return TEST_SKIPPED;
14379 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14380 		return TEST_SKIPPED;
14381 	return 0;
14382 }
14383 
14384 static int
14385 scheduler_roundrobin_testsuite_setup(void)
14386 {
14387 	if (test_scheduler_attach_worker_op() < 0)
14388 		return TEST_SKIPPED;
14389 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14390 		return TEST_SKIPPED;
14391 	return 0;
14392 }
14393 
14394 static int
14395 scheduler_failover_testsuite_setup(void)
14396 {
14397 	if (test_scheduler_attach_worker_op() < 0)
14398 		return TEST_SKIPPED;
14399 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14400 		return TEST_SKIPPED;
14401 	return 0;
14402 }
14403 
14404 static int
14405 scheduler_pkt_size_distr_testsuite_setup(void)
14406 {
14407 	if (test_scheduler_attach_worker_op() < 0)
14408 		return TEST_SKIPPED;
14409 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14410 		return TEST_SKIPPED;
14411 	return 0;
14412 }
14413 
14414 static void
14415 scheduler_mode_testsuite_teardown(void)
14416 {
14417 	test_scheduler_detach_worker_op();
14418 }
14419 
14420 #endif /* RTE_CRYPTO_SCHEDULER */
14421 
14422 static struct unit_test_suite end_testsuite = {
14423 	.suite_name = NULL,
14424 	.setup = NULL,
14425 	.teardown = NULL,
14426 	.unit_test_suites = NULL
14427 };
14428 
14429 #ifdef RTE_LIB_SECURITY
14430 static struct unit_test_suite ipsec_proto_testsuite  = {
14431 	.suite_name = "IPsec Proto Unit Test Suite",
14432 	.setup = ipsec_proto_testsuite_setup,
14433 	.unit_test_cases = {
14434 		TEST_CASE_NAMED_WITH_DATA(
14435 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14436 			ut_setup_security, ut_teardown,
14437 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14438 		TEST_CASE_NAMED_WITH_DATA(
14439 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14440 			ut_setup_security, ut_teardown,
14441 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14442 		TEST_CASE_NAMED_WITH_DATA(
14443 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14444 			ut_setup_security, ut_teardown,
14445 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14446 		TEST_CASE_NAMED_WITH_DATA(
14447 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14448 			ut_setup_security, ut_teardown,
14449 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14450 		TEST_CASE_NAMED_WITH_DATA(
14451 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14452 			ut_setup_security, ut_teardown,
14453 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14454 		TEST_CASE_NAMED_WITH_DATA(
14455 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14456 			ut_setup_security, ut_teardown,
14457 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14458 		TEST_CASE_NAMED_ST(
14459 			"Combined test alg list",
14460 			ut_setup_security, ut_teardown,
14461 			test_ipsec_proto_display_list),
14462 		TEST_CASE_NAMED_ST(
14463 			"IV generation",
14464 			ut_setup_security, ut_teardown,
14465 			test_ipsec_proto_iv_gen),
14466 		TEST_CASE_NAMED_ST(
14467 			"UDP encapsulation",
14468 			ut_setup_security, ut_teardown,
14469 			test_ipsec_proto_udp_encap),
14470 		TEST_CASE_NAMED_ST(
14471 			"UDP encapsulation ports verification test",
14472 			ut_setup_security, ut_teardown,
14473 			test_ipsec_proto_udp_ports_verify),
14474 		TEST_CASE_NAMED_ST(
14475 			"SA expiry packets soft",
14476 			ut_setup_security, ut_teardown,
14477 			test_ipsec_proto_sa_exp_pkts_soft),
14478 		TEST_CASE_NAMED_ST(
14479 			"SA expiry packets hard",
14480 			ut_setup_security, ut_teardown,
14481 			test_ipsec_proto_sa_exp_pkts_hard),
14482 		TEST_CASE_NAMED_ST(
14483 			"Negative test: ICV corruption",
14484 			ut_setup_security, ut_teardown,
14485 			test_ipsec_proto_err_icv_corrupt),
14486 		TEST_CASE_NAMED_ST(
14487 			"Tunnel dst addr verification",
14488 			ut_setup_security, ut_teardown,
14489 			test_ipsec_proto_tunnel_dst_addr_verify),
14490 		TEST_CASE_NAMED_ST(
14491 			"Tunnel src and dst addr verification",
14492 			ut_setup_security, ut_teardown,
14493 			test_ipsec_proto_tunnel_src_dst_addr_verify),
14494 		TEST_CASE_NAMED_ST(
14495 			"Inner IP checksum",
14496 			ut_setup_security, ut_teardown,
14497 			test_ipsec_proto_inner_ip_csum),
14498 		TEST_CASE_NAMED_ST(
14499 			"Inner L4 checksum",
14500 			ut_setup_security, ut_teardown,
14501 			test_ipsec_proto_inner_l4_csum),
14502 		TEST_CASES_END() /**< NULL terminate unit test array */
14503 	}
14504 };
14505 
14506 static struct unit_test_suite pdcp_proto_testsuite  = {
14507 	.suite_name = "PDCP Proto Unit Test Suite",
14508 	.setup = pdcp_proto_testsuite_setup,
14509 	.unit_test_cases = {
14510 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14511 			test_PDCP_PROTO_all),
14512 		TEST_CASES_END() /**< NULL terminate unit test array */
14513 	}
14514 };
14515 
14516 static struct unit_test_suite docsis_proto_testsuite  = {
14517 	.suite_name = "Docsis Proto Unit Test Suite",
14518 	.setup = docsis_proto_testsuite_setup,
14519 	.unit_test_cases = {
14520 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14521 			test_DOCSIS_PROTO_all),
14522 		TEST_CASES_END() /**< NULL terminate unit test array */
14523 	}
14524 };
14525 #endif
14526 
14527 static struct unit_test_suite cryptodev_gen_testsuite  = {
14528 	.suite_name = "Crypto General Unit Test Suite",
14529 	.setup = crypto_gen_testsuite_setup,
14530 	.unit_test_cases = {
14531 		TEST_CASE_ST(ut_setup, ut_teardown,
14532 				test_device_configure_invalid_dev_id),
14533 		TEST_CASE_ST(ut_setup, ut_teardown,
14534 				test_queue_pair_descriptor_setup),
14535 		TEST_CASE_ST(ut_setup, ut_teardown,
14536 				test_device_configure_invalid_queue_pair_ids),
14537 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14538 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14539 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14540 		TEST_CASES_END() /**< NULL terminate unit test array */
14541 	}
14542 };
14543 
14544 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14545 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
14546 	.setup = negative_hmac_sha1_testsuite_setup,
14547 	.unit_test_cases = {
14548 		/** Negative tests */
14549 		TEST_CASE_ST(ut_setup, ut_teardown,
14550 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
14551 		TEST_CASE_ST(ut_setup, ut_teardown,
14552 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14553 		TEST_CASE_ST(ut_setup, ut_teardown,
14554 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14555 		TEST_CASE_ST(ut_setup, ut_teardown,
14556 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14557 
14558 		TEST_CASES_END() /**< NULL terminate unit test array */
14559 	}
14560 };
14561 
14562 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14563 	.suite_name = "Multi Session Unit Test Suite",
14564 	.setup = multi_session_testsuite_setup,
14565 	.unit_test_cases = {
14566 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14567 		TEST_CASE_ST(ut_setup, ut_teardown,
14568 				test_multi_session_random_usage),
14569 
14570 		TEST_CASES_END() /**< NULL terminate unit test array */
14571 	}
14572 };
14573 
14574 static struct unit_test_suite cryptodev_null_testsuite  = {
14575 	.suite_name = "NULL Test Suite",
14576 	.setup = null_testsuite_setup,
14577 	.unit_test_cases = {
14578 		TEST_CASE_ST(ut_setup, ut_teardown,
14579 			test_null_invalid_operation),
14580 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14581 		TEST_CASES_END()
14582 	}
14583 };
14584 
14585 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14586 	.suite_name = "AES CCM Authenticated Test Suite",
14587 	.setup = aes_ccm_auth_testsuite_setup,
14588 	.unit_test_cases = {
14589 		/** AES CCM Authenticated Encryption 128 bits key*/
14590 		TEST_CASE_ST(ut_setup, ut_teardown,
14591 			test_AES_CCM_authenticated_encryption_test_case_128_1),
14592 		TEST_CASE_ST(ut_setup, ut_teardown,
14593 			test_AES_CCM_authenticated_encryption_test_case_128_2),
14594 		TEST_CASE_ST(ut_setup, ut_teardown,
14595 			test_AES_CCM_authenticated_encryption_test_case_128_3),
14596 
14597 		/** AES CCM Authenticated Decryption 128 bits key*/
14598 		TEST_CASE_ST(ut_setup, ut_teardown,
14599 			test_AES_CCM_authenticated_decryption_test_case_128_1),
14600 		TEST_CASE_ST(ut_setup, ut_teardown,
14601 			test_AES_CCM_authenticated_decryption_test_case_128_2),
14602 		TEST_CASE_ST(ut_setup, ut_teardown,
14603 			test_AES_CCM_authenticated_decryption_test_case_128_3),
14604 
14605 		/** AES CCM Authenticated Encryption 192 bits key */
14606 		TEST_CASE_ST(ut_setup, ut_teardown,
14607 			test_AES_CCM_authenticated_encryption_test_case_192_1),
14608 		TEST_CASE_ST(ut_setup, ut_teardown,
14609 			test_AES_CCM_authenticated_encryption_test_case_192_2),
14610 		TEST_CASE_ST(ut_setup, ut_teardown,
14611 			test_AES_CCM_authenticated_encryption_test_case_192_3),
14612 
14613 		/** AES CCM Authenticated Decryption 192 bits key*/
14614 		TEST_CASE_ST(ut_setup, ut_teardown,
14615 			test_AES_CCM_authenticated_decryption_test_case_192_1),
14616 		TEST_CASE_ST(ut_setup, ut_teardown,
14617 			test_AES_CCM_authenticated_decryption_test_case_192_2),
14618 		TEST_CASE_ST(ut_setup, ut_teardown,
14619 			test_AES_CCM_authenticated_decryption_test_case_192_3),
14620 
14621 		/** AES CCM Authenticated Encryption 256 bits key */
14622 		TEST_CASE_ST(ut_setup, ut_teardown,
14623 			test_AES_CCM_authenticated_encryption_test_case_256_1),
14624 		TEST_CASE_ST(ut_setup, ut_teardown,
14625 			test_AES_CCM_authenticated_encryption_test_case_256_2),
14626 		TEST_CASE_ST(ut_setup, ut_teardown,
14627 			test_AES_CCM_authenticated_encryption_test_case_256_3),
14628 
14629 		/** AES CCM Authenticated Decryption 256 bits key*/
14630 		TEST_CASE_ST(ut_setup, ut_teardown,
14631 			test_AES_CCM_authenticated_decryption_test_case_256_1),
14632 		TEST_CASE_ST(ut_setup, ut_teardown,
14633 			test_AES_CCM_authenticated_decryption_test_case_256_2),
14634 		TEST_CASE_ST(ut_setup, ut_teardown,
14635 			test_AES_CCM_authenticated_decryption_test_case_256_3),
14636 		TEST_CASES_END()
14637 	}
14638 };
14639 
14640 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14641 	.suite_name = "AES GCM Authenticated Test Suite",
14642 	.setup = aes_gcm_auth_testsuite_setup,
14643 	.unit_test_cases = {
14644 		/** AES GCM Authenticated Encryption */
14645 		TEST_CASE_ST(ut_setup, ut_teardown,
14646 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14647 		TEST_CASE_ST(ut_setup, ut_teardown,
14648 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14649 		TEST_CASE_ST(ut_setup, ut_teardown,
14650 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14651 		TEST_CASE_ST(ut_setup, ut_teardown,
14652 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14653 		TEST_CASE_ST(ut_setup, ut_teardown,
14654 			test_AES_GCM_authenticated_encryption_test_case_1),
14655 		TEST_CASE_ST(ut_setup, ut_teardown,
14656 			test_AES_GCM_authenticated_encryption_test_case_2),
14657 		TEST_CASE_ST(ut_setup, ut_teardown,
14658 			test_AES_GCM_authenticated_encryption_test_case_3),
14659 		TEST_CASE_ST(ut_setup, ut_teardown,
14660 			test_AES_GCM_authenticated_encryption_test_case_4),
14661 		TEST_CASE_ST(ut_setup, ut_teardown,
14662 			test_AES_GCM_authenticated_encryption_test_case_5),
14663 		TEST_CASE_ST(ut_setup, ut_teardown,
14664 			test_AES_GCM_authenticated_encryption_test_case_6),
14665 		TEST_CASE_ST(ut_setup, ut_teardown,
14666 			test_AES_GCM_authenticated_encryption_test_case_7),
14667 		TEST_CASE_ST(ut_setup, ut_teardown,
14668 			test_AES_GCM_authenticated_encryption_test_case_8),
14669 		TEST_CASE_ST(ut_setup, ut_teardown,
14670 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
14671 
14672 		/** AES GCM Authenticated Decryption */
14673 		TEST_CASE_ST(ut_setup, ut_teardown,
14674 			test_AES_GCM_authenticated_decryption_test_case_1),
14675 		TEST_CASE_ST(ut_setup, ut_teardown,
14676 			test_AES_GCM_authenticated_decryption_test_case_2),
14677 		TEST_CASE_ST(ut_setup, ut_teardown,
14678 			test_AES_GCM_authenticated_decryption_test_case_3),
14679 		TEST_CASE_ST(ut_setup, ut_teardown,
14680 			test_AES_GCM_authenticated_decryption_test_case_4),
14681 		TEST_CASE_ST(ut_setup, ut_teardown,
14682 			test_AES_GCM_authenticated_decryption_test_case_5),
14683 		TEST_CASE_ST(ut_setup, ut_teardown,
14684 			test_AES_GCM_authenticated_decryption_test_case_6),
14685 		TEST_CASE_ST(ut_setup, ut_teardown,
14686 			test_AES_GCM_authenticated_decryption_test_case_7),
14687 		TEST_CASE_ST(ut_setup, ut_teardown,
14688 			test_AES_GCM_authenticated_decryption_test_case_8),
14689 		TEST_CASE_ST(ut_setup, ut_teardown,
14690 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
14691 
14692 		/** AES GCM Authenticated Encryption 192 bits key */
14693 		TEST_CASE_ST(ut_setup, ut_teardown,
14694 			test_AES_GCM_auth_encryption_test_case_192_1),
14695 		TEST_CASE_ST(ut_setup, ut_teardown,
14696 			test_AES_GCM_auth_encryption_test_case_192_2),
14697 		TEST_CASE_ST(ut_setup, ut_teardown,
14698 			test_AES_GCM_auth_encryption_test_case_192_3),
14699 		TEST_CASE_ST(ut_setup, ut_teardown,
14700 			test_AES_GCM_auth_encryption_test_case_192_4),
14701 		TEST_CASE_ST(ut_setup, ut_teardown,
14702 			test_AES_GCM_auth_encryption_test_case_192_5),
14703 		TEST_CASE_ST(ut_setup, ut_teardown,
14704 			test_AES_GCM_auth_encryption_test_case_192_6),
14705 		TEST_CASE_ST(ut_setup, ut_teardown,
14706 			test_AES_GCM_auth_encryption_test_case_192_7),
14707 
14708 		/** AES GCM Authenticated Decryption 192 bits key */
14709 		TEST_CASE_ST(ut_setup, ut_teardown,
14710 			test_AES_GCM_auth_decryption_test_case_192_1),
14711 		TEST_CASE_ST(ut_setup, ut_teardown,
14712 			test_AES_GCM_auth_decryption_test_case_192_2),
14713 		TEST_CASE_ST(ut_setup, ut_teardown,
14714 			test_AES_GCM_auth_decryption_test_case_192_3),
14715 		TEST_CASE_ST(ut_setup, ut_teardown,
14716 			test_AES_GCM_auth_decryption_test_case_192_4),
14717 		TEST_CASE_ST(ut_setup, ut_teardown,
14718 			test_AES_GCM_auth_decryption_test_case_192_5),
14719 		TEST_CASE_ST(ut_setup, ut_teardown,
14720 			test_AES_GCM_auth_decryption_test_case_192_6),
14721 		TEST_CASE_ST(ut_setup, ut_teardown,
14722 			test_AES_GCM_auth_decryption_test_case_192_7),
14723 
14724 		/** AES GCM Authenticated Encryption 256 bits key */
14725 		TEST_CASE_ST(ut_setup, ut_teardown,
14726 			test_AES_GCM_auth_encryption_test_case_256_1),
14727 		TEST_CASE_ST(ut_setup, ut_teardown,
14728 			test_AES_GCM_auth_encryption_test_case_256_2),
14729 		TEST_CASE_ST(ut_setup, ut_teardown,
14730 			test_AES_GCM_auth_encryption_test_case_256_3),
14731 		TEST_CASE_ST(ut_setup, ut_teardown,
14732 			test_AES_GCM_auth_encryption_test_case_256_4),
14733 		TEST_CASE_ST(ut_setup, ut_teardown,
14734 			test_AES_GCM_auth_encryption_test_case_256_5),
14735 		TEST_CASE_ST(ut_setup, ut_teardown,
14736 			test_AES_GCM_auth_encryption_test_case_256_6),
14737 		TEST_CASE_ST(ut_setup, ut_teardown,
14738 			test_AES_GCM_auth_encryption_test_case_256_7),
14739 
14740 		/** AES GCM Authenticated Decryption 256 bits key */
14741 		TEST_CASE_ST(ut_setup, ut_teardown,
14742 			test_AES_GCM_auth_decryption_test_case_256_1),
14743 		TEST_CASE_ST(ut_setup, ut_teardown,
14744 			test_AES_GCM_auth_decryption_test_case_256_2),
14745 		TEST_CASE_ST(ut_setup, ut_teardown,
14746 			test_AES_GCM_auth_decryption_test_case_256_3),
14747 		TEST_CASE_ST(ut_setup, ut_teardown,
14748 			test_AES_GCM_auth_decryption_test_case_256_4),
14749 		TEST_CASE_ST(ut_setup, ut_teardown,
14750 			test_AES_GCM_auth_decryption_test_case_256_5),
14751 		TEST_CASE_ST(ut_setup, ut_teardown,
14752 			test_AES_GCM_auth_decryption_test_case_256_6),
14753 		TEST_CASE_ST(ut_setup, ut_teardown,
14754 			test_AES_GCM_auth_decryption_test_case_256_7),
14755 
14756 		/** AES GCM Authenticated Encryption big aad size */
14757 		TEST_CASE_ST(ut_setup, ut_teardown,
14758 			test_AES_GCM_auth_encryption_test_case_aad_1),
14759 		TEST_CASE_ST(ut_setup, ut_teardown,
14760 			test_AES_GCM_auth_encryption_test_case_aad_2),
14761 
14762 		/** AES GCM Authenticated Decryption big aad size */
14763 		TEST_CASE_ST(ut_setup, ut_teardown,
14764 			test_AES_GCM_auth_decryption_test_case_aad_1),
14765 		TEST_CASE_ST(ut_setup, ut_teardown,
14766 			test_AES_GCM_auth_decryption_test_case_aad_2),
14767 
14768 		/** Out of place tests */
14769 		TEST_CASE_ST(ut_setup, ut_teardown,
14770 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
14771 		TEST_CASE_ST(ut_setup, ut_teardown,
14772 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
14773 
14774 		/** Session-less tests */
14775 		TEST_CASE_ST(ut_setup, ut_teardown,
14776 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14777 		TEST_CASE_ST(ut_setup, ut_teardown,
14778 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14779 
14780 		TEST_CASES_END()
14781 	}
14782 };
14783 
14784 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14785 	.suite_name = "AES GMAC Authentication Test Suite",
14786 	.setup = aes_gmac_auth_testsuite_setup,
14787 	.unit_test_cases = {
14788 		TEST_CASE_ST(ut_setup, ut_teardown,
14789 			test_AES_GMAC_authentication_test_case_1),
14790 		TEST_CASE_ST(ut_setup, ut_teardown,
14791 			test_AES_GMAC_authentication_verify_test_case_1),
14792 		TEST_CASE_ST(ut_setup, ut_teardown,
14793 			test_AES_GMAC_authentication_test_case_2),
14794 		TEST_CASE_ST(ut_setup, ut_teardown,
14795 			test_AES_GMAC_authentication_verify_test_case_2),
14796 		TEST_CASE_ST(ut_setup, ut_teardown,
14797 			test_AES_GMAC_authentication_test_case_3),
14798 		TEST_CASE_ST(ut_setup, ut_teardown,
14799 			test_AES_GMAC_authentication_verify_test_case_3),
14800 		TEST_CASE_ST(ut_setup, ut_teardown,
14801 			test_AES_GMAC_authentication_test_case_4),
14802 		TEST_CASE_ST(ut_setup, ut_teardown,
14803 			test_AES_GMAC_authentication_verify_test_case_4),
14804 		TEST_CASE_ST(ut_setup, ut_teardown,
14805 			test_AES_GMAC_authentication_SGL_40B),
14806 		TEST_CASE_ST(ut_setup, ut_teardown,
14807 			test_AES_GMAC_authentication_SGL_80B),
14808 		TEST_CASE_ST(ut_setup, ut_teardown,
14809 			test_AES_GMAC_authentication_SGL_2048B),
14810 		TEST_CASE_ST(ut_setup, ut_teardown,
14811 			test_AES_GMAC_authentication_SGL_2047B),
14812 
14813 		TEST_CASES_END()
14814 	}
14815 };
14816 
14817 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14818 	.suite_name = "Chacha20-Poly1305 Test Suite",
14819 	.setup = chacha20_poly1305_testsuite_setup,
14820 	.unit_test_cases = {
14821 		TEST_CASE_ST(ut_setup, ut_teardown,
14822 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
14823 		TEST_CASE_ST(ut_setup, ut_teardown,
14824 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
14825 		TEST_CASE_ST(ut_setup, ut_teardown,
14826 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
14827 		TEST_CASES_END()
14828 	}
14829 };
14830 
14831 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14832 	.suite_name = "SNOW 3G Test Suite",
14833 	.setup = snow3g_testsuite_setup,
14834 	.unit_test_cases = {
14835 		/** SNOW 3G encrypt only (UEA2) */
14836 		TEST_CASE_ST(ut_setup, ut_teardown,
14837 			test_snow3g_encryption_test_case_1),
14838 		TEST_CASE_ST(ut_setup, ut_teardown,
14839 			test_snow3g_encryption_test_case_2),
14840 		TEST_CASE_ST(ut_setup, ut_teardown,
14841 			test_snow3g_encryption_test_case_3),
14842 		TEST_CASE_ST(ut_setup, ut_teardown,
14843 			test_snow3g_encryption_test_case_4),
14844 		TEST_CASE_ST(ut_setup, ut_teardown,
14845 			test_snow3g_encryption_test_case_5),
14846 
14847 		TEST_CASE_ST(ut_setup, ut_teardown,
14848 			test_snow3g_encryption_test_case_1_oop),
14849 		TEST_CASE_ST(ut_setup, ut_teardown,
14850 			test_snow3g_encryption_test_case_1_oop_sgl),
14851 		TEST_CASE_ST(ut_setup, ut_teardown,
14852 			test_snow3g_encryption_test_case_1_offset_oop),
14853 		TEST_CASE_ST(ut_setup, ut_teardown,
14854 			test_snow3g_decryption_test_case_1_oop),
14855 
14856 		/** SNOW 3G generate auth, then encrypt (UEA2) */
14857 		TEST_CASE_ST(ut_setup, ut_teardown,
14858 			test_snow3g_auth_cipher_test_case_1),
14859 		TEST_CASE_ST(ut_setup, ut_teardown,
14860 			test_snow3g_auth_cipher_test_case_2),
14861 		TEST_CASE_ST(ut_setup, ut_teardown,
14862 			test_snow3g_auth_cipher_test_case_2_oop),
14863 		TEST_CASE_ST(ut_setup, ut_teardown,
14864 			test_snow3g_auth_cipher_part_digest_enc),
14865 		TEST_CASE_ST(ut_setup, ut_teardown,
14866 			test_snow3g_auth_cipher_part_digest_enc_oop),
14867 		TEST_CASE_ST(ut_setup, ut_teardown,
14868 			test_snow3g_auth_cipher_test_case_3_sgl),
14869 		TEST_CASE_ST(ut_setup, ut_teardown,
14870 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
14871 		TEST_CASE_ST(ut_setup, ut_teardown,
14872 			test_snow3g_auth_cipher_part_digest_enc_sgl),
14873 		TEST_CASE_ST(ut_setup, ut_teardown,
14874 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14875 
14876 		/** SNOW 3G decrypt (UEA2), then verify auth */
14877 		TEST_CASE_ST(ut_setup, ut_teardown,
14878 			test_snow3g_auth_cipher_verify_test_case_1),
14879 		TEST_CASE_ST(ut_setup, ut_teardown,
14880 			test_snow3g_auth_cipher_verify_test_case_2),
14881 		TEST_CASE_ST(ut_setup, ut_teardown,
14882 			test_snow3g_auth_cipher_verify_test_case_2_oop),
14883 		TEST_CASE_ST(ut_setup, ut_teardown,
14884 			test_snow3g_auth_cipher_verify_part_digest_enc),
14885 		TEST_CASE_ST(ut_setup, ut_teardown,
14886 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14887 		TEST_CASE_ST(ut_setup, ut_teardown,
14888 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
14889 		TEST_CASE_ST(ut_setup, ut_teardown,
14890 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14891 		TEST_CASE_ST(ut_setup, ut_teardown,
14892 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14893 		TEST_CASE_ST(ut_setup, ut_teardown,
14894 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14895 
14896 		/** SNOW 3G decrypt only (UEA2) */
14897 		TEST_CASE_ST(ut_setup, ut_teardown,
14898 			test_snow3g_decryption_test_case_1),
14899 		TEST_CASE_ST(ut_setup, ut_teardown,
14900 			test_snow3g_decryption_test_case_2),
14901 		TEST_CASE_ST(ut_setup, ut_teardown,
14902 			test_snow3g_decryption_test_case_3),
14903 		TEST_CASE_ST(ut_setup, ut_teardown,
14904 			test_snow3g_decryption_test_case_4),
14905 		TEST_CASE_ST(ut_setup, ut_teardown,
14906 			test_snow3g_decryption_test_case_5),
14907 		TEST_CASE_ST(ut_setup, ut_teardown,
14908 			test_snow3g_decryption_with_digest_test_case_1),
14909 		TEST_CASE_ST(ut_setup, ut_teardown,
14910 			test_snow3g_hash_generate_test_case_1),
14911 		TEST_CASE_ST(ut_setup, ut_teardown,
14912 			test_snow3g_hash_generate_test_case_2),
14913 		TEST_CASE_ST(ut_setup, ut_teardown,
14914 			test_snow3g_hash_generate_test_case_3),
14915 
14916 		/* Tests with buffers which length is not byte-aligned */
14917 		TEST_CASE_ST(ut_setup, ut_teardown,
14918 			test_snow3g_hash_generate_test_case_4),
14919 		TEST_CASE_ST(ut_setup, ut_teardown,
14920 			test_snow3g_hash_generate_test_case_5),
14921 		TEST_CASE_ST(ut_setup, ut_teardown,
14922 			test_snow3g_hash_generate_test_case_6),
14923 		TEST_CASE_ST(ut_setup, ut_teardown,
14924 			test_snow3g_hash_verify_test_case_1),
14925 		TEST_CASE_ST(ut_setup, ut_teardown,
14926 			test_snow3g_hash_verify_test_case_2),
14927 		TEST_CASE_ST(ut_setup, ut_teardown,
14928 			test_snow3g_hash_verify_test_case_3),
14929 
14930 		/* Tests with buffers which length is not byte-aligned */
14931 		TEST_CASE_ST(ut_setup, ut_teardown,
14932 			test_snow3g_hash_verify_test_case_4),
14933 		TEST_CASE_ST(ut_setup, ut_teardown,
14934 			test_snow3g_hash_verify_test_case_5),
14935 		TEST_CASE_ST(ut_setup, ut_teardown,
14936 			test_snow3g_hash_verify_test_case_6),
14937 		TEST_CASE_ST(ut_setup, ut_teardown,
14938 			test_snow3g_cipher_auth_test_case_1),
14939 		TEST_CASE_ST(ut_setup, ut_teardown,
14940 			test_snow3g_auth_cipher_with_digest_test_case_1),
14941 		TEST_CASES_END()
14942 	}
14943 };
14944 
14945 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14946 	.suite_name = "ZUC Test Suite",
14947 	.setup = zuc_testsuite_setup,
14948 	.unit_test_cases = {
14949 		/** ZUC encrypt only (EEA3) */
14950 		TEST_CASE_ST(ut_setup, ut_teardown,
14951 			test_zuc_encryption_test_case_1),
14952 		TEST_CASE_ST(ut_setup, ut_teardown,
14953 			test_zuc_encryption_test_case_2),
14954 		TEST_CASE_ST(ut_setup, ut_teardown,
14955 			test_zuc_encryption_test_case_3),
14956 		TEST_CASE_ST(ut_setup, ut_teardown,
14957 			test_zuc_encryption_test_case_4),
14958 		TEST_CASE_ST(ut_setup, ut_teardown,
14959 			test_zuc_encryption_test_case_5),
14960 		TEST_CASE_ST(ut_setup, ut_teardown,
14961 			test_zuc_encryption_test_case_6_sgl),
14962 		TEST_CASE_ST(ut_setup, ut_teardown,
14963 			test_zuc_encryption_test_case_7),
14964 
14965 		/** ZUC authenticate (EIA3) */
14966 		TEST_CASE_ST(ut_setup, ut_teardown,
14967 			test_zuc_hash_generate_test_case_1),
14968 		TEST_CASE_ST(ut_setup, ut_teardown,
14969 			test_zuc_hash_generate_test_case_2),
14970 		TEST_CASE_ST(ut_setup, ut_teardown,
14971 			test_zuc_hash_generate_test_case_3),
14972 		TEST_CASE_ST(ut_setup, ut_teardown,
14973 			test_zuc_hash_generate_test_case_4),
14974 		TEST_CASE_ST(ut_setup, ut_teardown,
14975 			test_zuc_hash_generate_test_case_5),
14976 		TEST_CASE_ST(ut_setup, ut_teardown,
14977 			test_zuc_hash_generate_test_case_6),
14978 		TEST_CASE_ST(ut_setup, ut_teardown,
14979 			test_zuc_hash_generate_test_case_7),
14980 		TEST_CASE_ST(ut_setup, ut_teardown,
14981 			test_zuc_hash_generate_test_case_8),
14982 		TEST_CASE_ST(ut_setup, ut_teardown,
14983 			test_zuc_hash_generate_test_case_9),
14984 		TEST_CASE_ST(ut_setup, ut_teardown,
14985 			test_zuc_hash_generate_test_case_10),
14986 
14987 
14988 		/** ZUC alg-chain (EEA3/EIA3) */
14989 		TEST_CASE_ST(ut_setup, ut_teardown,
14990 			test_zuc_cipher_auth_test_case_1),
14991 		TEST_CASE_ST(ut_setup, ut_teardown,
14992 			test_zuc_cipher_auth_test_case_2),
14993 
14994 		/** ZUC generate auth, then encrypt (EEA3) */
14995 		TEST_CASE_ST(ut_setup, ut_teardown,
14996 			test_zuc_auth_cipher_test_case_1),
14997 		TEST_CASE_ST(ut_setup, ut_teardown,
14998 			test_zuc_auth_cipher_test_case_1_oop),
14999 		TEST_CASE_ST(ut_setup, ut_teardown,
15000 			test_zuc_auth_cipher_test_case_1_sgl),
15001 		TEST_CASE_ST(ut_setup, ut_teardown,
15002 			test_zuc_auth_cipher_test_case_1_oop_sgl),
15003 
15004 		/** ZUC decrypt (EEA3), then verify auth */
15005 		TEST_CASE_ST(ut_setup, ut_teardown,
15006 			test_zuc_auth_cipher_verify_test_case_1),
15007 		TEST_CASE_ST(ut_setup, ut_teardown,
15008 			test_zuc_auth_cipher_verify_test_case_1_oop),
15009 		TEST_CASE_ST(ut_setup, ut_teardown,
15010 			test_zuc_auth_cipher_verify_test_case_1_sgl),
15011 		TEST_CASE_ST(ut_setup, ut_teardown,
15012 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
15013 
15014 		/** ZUC-256 encrypt only **/
15015 		TEST_CASE_ST(ut_setup, ut_teardown,
15016 			test_zuc256_encryption_test_case_1),
15017 		TEST_CASE_ST(ut_setup, ut_teardown,
15018 			test_zuc256_encryption_test_case_2),
15019 
15020 		/** ZUC-256 authentication only **/
15021 		TEST_CASE_ST(ut_setup, ut_teardown,
15022 			test_zuc256_authentication_test_case_1),
15023 		TEST_CASE_ST(ut_setup, ut_teardown,
15024 			test_zuc256_authentication_test_case_2),
15025 
15026 		TEST_CASES_END()
15027 	}
15028 };
15029 
15030 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
15031 	.suite_name = "HMAC_MD5 Authentication Test Suite",
15032 	.setup = hmac_md5_auth_testsuite_setup,
15033 	.unit_test_cases = {
15034 		TEST_CASE_ST(ut_setup, ut_teardown,
15035 			test_MD5_HMAC_generate_case_1),
15036 		TEST_CASE_ST(ut_setup, ut_teardown,
15037 			test_MD5_HMAC_verify_case_1),
15038 		TEST_CASE_ST(ut_setup, ut_teardown,
15039 			test_MD5_HMAC_generate_case_2),
15040 		TEST_CASE_ST(ut_setup, ut_teardown,
15041 			test_MD5_HMAC_verify_case_2),
15042 		TEST_CASES_END()
15043 	}
15044 };
15045 
15046 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
15047 	.suite_name = "Kasumi Test Suite",
15048 	.setup = kasumi_testsuite_setup,
15049 	.unit_test_cases = {
15050 		/** KASUMI hash only (UIA1) */
15051 		TEST_CASE_ST(ut_setup, ut_teardown,
15052 			test_kasumi_hash_generate_test_case_1),
15053 		TEST_CASE_ST(ut_setup, ut_teardown,
15054 			test_kasumi_hash_generate_test_case_2),
15055 		TEST_CASE_ST(ut_setup, ut_teardown,
15056 			test_kasumi_hash_generate_test_case_3),
15057 		TEST_CASE_ST(ut_setup, ut_teardown,
15058 			test_kasumi_hash_generate_test_case_4),
15059 		TEST_CASE_ST(ut_setup, ut_teardown,
15060 			test_kasumi_hash_generate_test_case_5),
15061 		TEST_CASE_ST(ut_setup, ut_teardown,
15062 			test_kasumi_hash_generate_test_case_6),
15063 
15064 		TEST_CASE_ST(ut_setup, ut_teardown,
15065 			test_kasumi_hash_verify_test_case_1),
15066 		TEST_CASE_ST(ut_setup, ut_teardown,
15067 			test_kasumi_hash_verify_test_case_2),
15068 		TEST_CASE_ST(ut_setup, ut_teardown,
15069 			test_kasumi_hash_verify_test_case_3),
15070 		TEST_CASE_ST(ut_setup, ut_teardown,
15071 			test_kasumi_hash_verify_test_case_4),
15072 		TEST_CASE_ST(ut_setup, ut_teardown,
15073 			test_kasumi_hash_verify_test_case_5),
15074 
15075 		/** KASUMI encrypt only (UEA1) */
15076 		TEST_CASE_ST(ut_setup, ut_teardown,
15077 			test_kasumi_encryption_test_case_1),
15078 		TEST_CASE_ST(ut_setup, ut_teardown,
15079 			test_kasumi_encryption_test_case_1_sgl),
15080 		TEST_CASE_ST(ut_setup, ut_teardown,
15081 			test_kasumi_encryption_test_case_1_oop),
15082 		TEST_CASE_ST(ut_setup, ut_teardown,
15083 			test_kasumi_encryption_test_case_1_oop_sgl),
15084 		TEST_CASE_ST(ut_setup, ut_teardown,
15085 			test_kasumi_encryption_test_case_2),
15086 		TEST_CASE_ST(ut_setup, ut_teardown,
15087 			test_kasumi_encryption_test_case_3),
15088 		TEST_CASE_ST(ut_setup, ut_teardown,
15089 			test_kasumi_encryption_test_case_4),
15090 		TEST_CASE_ST(ut_setup, ut_teardown,
15091 			test_kasumi_encryption_test_case_5),
15092 
15093 		/** KASUMI decrypt only (UEA1) */
15094 		TEST_CASE_ST(ut_setup, ut_teardown,
15095 			test_kasumi_decryption_test_case_1),
15096 		TEST_CASE_ST(ut_setup, ut_teardown,
15097 			test_kasumi_decryption_test_case_2),
15098 		TEST_CASE_ST(ut_setup, ut_teardown,
15099 			test_kasumi_decryption_test_case_3),
15100 		TEST_CASE_ST(ut_setup, ut_teardown,
15101 			test_kasumi_decryption_test_case_4),
15102 		TEST_CASE_ST(ut_setup, ut_teardown,
15103 			test_kasumi_decryption_test_case_5),
15104 		TEST_CASE_ST(ut_setup, ut_teardown,
15105 			test_kasumi_decryption_test_case_1_oop),
15106 		TEST_CASE_ST(ut_setup, ut_teardown,
15107 			test_kasumi_cipher_auth_test_case_1),
15108 
15109 		/** KASUMI generate auth, then encrypt (F8) */
15110 		TEST_CASE_ST(ut_setup, ut_teardown,
15111 			test_kasumi_auth_cipher_test_case_1),
15112 		TEST_CASE_ST(ut_setup, ut_teardown,
15113 			test_kasumi_auth_cipher_test_case_2),
15114 		TEST_CASE_ST(ut_setup, ut_teardown,
15115 			test_kasumi_auth_cipher_test_case_2_oop),
15116 		TEST_CASE_ST(ut_setup, ut_teardown,
15117 			test_kasumi_auth_cipher_test_case_2_sgl),
15118 		TEST_CASE_ST(ut_setup, ut_teardown,
15119 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
15120 
15121 		/** KASUMI decrypt (F8), then verify auth */
15122 		TEST_CASE_ST(ut_setup, ut_teardown,
15123 			test_kasumi_auth_cipher_verify_test_case_1),
15124 		TEST_CASE_ST(ut_setup, ut_teardown,
15125 			test_kasumi_auth_cipher_verify_test_case_2),
15126 		TEST_CASE_ST(ut_setup, ut_teardown,
15127 			test_kasumi_auth_cipher_verify_test_case_2_oop),
15128 		TEST_CASE_ST(ut_setup, ut_teardown,
15129 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
15130 		TEST_CASE_ST(ut_setup, ut_teardown,
15131 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
15132 
15133 		TEST_CASES_END()
15134 	}
15135 };
15136 
15137 static struct unit_test_suite cryptodev_esn_testsuite  = {
15138 	.suite_name = "ESN Test Suite",
15139 	.setup = esn_testsuite_setup,
15140 	.unit_test_cases = {
15141 		TEST_CASE_ST(ut_setup, ut_teardown,
15142 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
15143 		TEST_CASE_ST(ut_setup, ut_teardown,
15144 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
15145 		TEST_CASES_END()
15146 	}
15147 };
15148 
15149 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
15150 	.suite_name = "Negative AES GCM Test Suite",
15151 	.setup = negative_aes_gcm_testsuite_setup,
15152 	.unit_test_cases = {
15153 		TEST_CASE_ST(ut_setup, ut_teardown,
15154 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
15155 		TEST_CASE_ST(ut_setup, ut_teardown,
15156 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
15157 		TEST_CASE_ST(ut_setup, ut_teardown,
15158 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
15159 		TEST_CASE_ST(ut_setup, ut_teardown,
15160 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
15161 		TEST_CASE_ST(ut_setup, ut_teardown,
15162 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
15163 		TEST_CASE_ST(ut_setup, ut_teardown,
15164 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
15165 		TEST_CASE_ST(ut_setup, ut_teardown,
15166 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
15167 		TEST_CASE_ST(ut_setup, ut_teardown,
15168 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
15169 		TEST_CASE_ST(ut_setup, ut_teardown,
15170 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
15171 		TEST_CASE_ST(ut_setup, ut_teardown,
15172 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
15173 		TEST_CASE_ST(ut_setup, ut_teardown,
15174 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
15175 		TEST_CASE_ST(ut_setup, ut_teardown,
15176 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
15177 
15178 		TEST_CASES_END()
15179 	}
15180 };
15181 
15182 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
15183 	.suite_name = "Negative AES GMAC Test Suite",
15184 	.setup = negative_aes_gmac_testsuite_setup,
15185 	.unit_test_cases = {
15186 		TEST_CASE_ST(ut_setup, ut_teardown,
15187 			authentication_verify_AES128_GMAC_fail_data_corrupt),
15188 		TEST_CASE_ST(ut_setup, ut_teardown,
15189 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
15190 
15191 		TEST_CASES_END()
15192 	}
15193 };
15194 
15195 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
15196 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
15197 	.setup = mixed_cipher_hash_testsuite_setup,
15198 	.unit_test_cases = {
15199 		/** AUTH AES CMAC + CIPHER AES CTR */
15200 		TEST_CASE_ST(ut_setup, ut_teardown,
15201 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
15202 		TEST_CASE_ST(ut_setup, ut_teardown,
15203 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15204 		TEST_CASE_ST(ut_setup, ut_teardown,
15205 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15206 		TEST_CASE_ST(ut_setup, ut_teardown,
15207 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15208 		TEST_CASE_ST(ut_setup, ut_teardown,
15209 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
15210 		TEST_CASE_ST(ut_setup, ut_teardown,
15211 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15212 		TEST_CASE_ST(ut_setup, ut_teardown,
15213 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15214 		TEST_CASE_ST(ut_setup, ut_teardown,
15215 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15216 
15217 		/** AUTH ZUC + CIPHER SNOW3G */
15218 		TEST_CASE_ST(ut_setup, ut_teardown,
15219 			test_auth_zuc_cipher_snow_test_case_1),
15220 		TEST_CASE_ST(ut_setup, ut_teardown,
15221 			test_verify_auth_zuc_cipher_snow_test_case_1),
15222 		/** AUTH AES CMAC + CIPHER SNOW3G */
15223 		TEST_CASE_ST(ut_setup, ut_teardown,
15224 			test_auth_aes_cmac_cipher_snow_test_case_1),
15225 		TEST_CASE_ST(ut_setup, ut_teardown,
15226 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15227 		/** AUTH ZUC + CIPHER AES CTR */
15228 		TEST_CASE_ST(ut_setup, ut_teardown,
15229 			test_auth_zuc_cipher_aes_ctr_test_case_1),
15230 		TEST_CASE_ST(ut_setup, ut_teardown,
15231 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15232 		/** AUTH SNOW3G + CIPHER AES CTR */
15233 		TEST_CASE_ST(ut_setup, ut_teardown,
15234 			test_auth_snow_cipher_aes_ctr_test_case_1),
15235 		TEST_CASE_ST(ut_setup, ut_teardown,
15236 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
15237 		/** AUTH SNOW3G + CIPHER ZUC */
15238 		TEST_CASE_ST(ut_setup, ut_teardown,
15239 			test_auth_snow_cipher_zuc_test_case_1),
15240 		TEST_CASE_ST(ut_setup, ut_teardown,
15241 			test_verify_auth_snow_cipher_zuc_test_case_1),
15242 		/** AUTH AES CMAC + CIPHER ZUC */
15243 		TEST_CASE_ST(ut_setup, ut_teardown,
15244 			test_auth_aes_cmac_cipher_zuc_test_case_1),
15245 		TEST_CASE_ST(ut_setup, ut_teardown,
15246 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
15247 
15248 		/** AUTH NULL + CIPHER SNOW3G */
15249 		TEST_CASE_ST(ut_setup, ut_teardown,
15250 			test_auth_null_cipher_snow_test_case_1),
15251 		TEST_CASE_ST(ut_setup, ut_teardown,
15252 			test_verify_auth_null_cipher_snow_test_case_1),
15253 		/** AUTH NULL + CIPHER ZUC */
15254 		TEST_CASE_ST(ut_setup, ut_teardown,
15255 			test_auth_null_cipher_zuc_test_case_1),
15256 		TEST_CASE_ST(ut_setup, ut_teardown,
15257 			test_verify_auth_null_cipher_zuc_test_case_1),
15258 		/** AUTH SNOW3G + CIPHER NULL */
15259 		TEST_CASE_ST(ut_setup, ut_teardown,
15260 			test_auth_snow_cipher_null_test_case_1),
15261 		TEST_CASE_ST(ut_setup, ut_teardown,
15262 			test_verify_auth_snow_cipher_null_test_case_1),
15263 		/** AUTH ZUC + CIPHER NULL */
15264 		TEST_CASE_ST(ut_setup, ut_teardown,
15265 			test_auth_zuc_cipher_null_test_case_1),
15266 		TEST_CASE_ST(ut_setup, ut_teardown,
15267 			test_verify_auth_zuc_cipher_null_test_case_1),
15268 		/** AUTH NULL + CIPHER AES CTR */
15269 		TEST_CASE_ST(ut_setup, ut_teardown,
15270 			test_auth_null_cipher_aes_ctr_test_case_1),
15271 		TEST_CASE_ST(ut_setup, ut_teardown,
15272 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
15273 		/** AUTH AES CMAC + CIPHER NULL */
15274 		TEST_CASE_ST(ut_setup, ut_teardown,
15275 			test_auth_aes_cmac_cipher_null_test_case_1),
15276 		TEST_CASE_ST(ut_setup, ut_teardown,
15277 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
15278 		TEST_CASES_END()
15279 	}
15280 };
15281 
15282 static int
15283 run_cryptodev_testsuite(const char *pmd_name)
15284 {
15285 	uint8_t ret, j, i = 0, blk_start_idx = 0;
15286 	const enum blockcipher_test_type blk_suites[] = {
15287 		BLKCIPHER_AES_CHAIN_TYPE,
15288 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15289 		BLKCIPHER_AES_DOCSIS_TYPE,
15290 		BLKCIPHER_3DES_CHAIN_TYPE,
15291 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
15292 		BLKCIPHER_DES_CIPHERONLY_TYPE,
15293 		BLKCIPHER_DES_DOCSIS_TYPE,
15294 		BLKCIPHER_AUTHONLY_TYPE};
15295 	struct unit_test_suite *static_suites[] = {
15296 		&cryptodev_multi_session_testsuite,
15297 		&cryptodev_null_testsuite,
15298 		&cryptodev_aes_ccm_auth_testsuite,
15299 		&cryptodev_aes_gcm_auth_testsuite,
15300 		&cryptodev_aes_gmac_auth_testsuite,
15301 		&cryptodev_snow3g_testsuite,
15302 		&cryptodev_chacha20_poly1305_testsuite,
15303 		&cryptodev_zuc_testsuite,
15304 		&cryptodev_hmac_md5_auth_testsuite,
15305 		&cryptodev_kasumi_testsuite,
15306 		&cryptodev_esn_testsuite,
15307 		&cryptodev_negative_aes_gcm_testsuite,
15308 		&cryptodev_negative_aes_gmac_testsuite,
15309 		&cryptodev_mixed_cipher_hash_testsuite,
15310 		&cryptodev_negative_hmac_sha1_testsuite,
15311 		&cryptodev_gen_testsuite,
15312 #ifdef RTE_LIB_SECURITY
15313 		&ipsec_proto_testsuite,
15314 		&pdcp_proto_testsuite,
15315 		&docsis_proto_testsuite,
15316 #endif
15317 		&end_testsuite
15318 	};
15319 	static struct unit_test_suite ts = {
15320 		.suite_name = "Cryptodev Unit Test Suite",
15321 		.setup = testsuite_setup,
15322 		.teardown = testsuite_teardown,
15323 		.unit_test_cases = {TEST_CASES_END()}
15324 	};
15325 
15326 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15327 
15328 	if (gbl_driver_id == -1) {
15329 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15330 		return TEST_SKIPPED;
15331 	}
15332 
15333 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15334 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15335 
15336 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15337 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15338 	ret = unit_test_suite_runner(&ts);
15339 
15340 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15341 	free(ts.unit_test_suites);
15342 	return ret;
15343 }
15344 
15345 static int
15346 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15347 {
15348 	struct rte_cryptodev_info dev_info;
15349 	uint8_t i, nb_devs;
15350 	int driver_id;
15351 
15352 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
15353 	if (driver_id == -1) {
15354 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15355 		return TEST_SKIPPED;
15356 	}
15357 
15358 	nb_devs = rte_cryptodev_count();
15359 	if (nb_devs < 1) {
15360 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15361 		return TEST_SKIPPED;
15362 	}
15363 
15364 	for (i = 0; i < nb_devs; i++) {
15365 		rte_cryptodev_info_get(i, &dev_info);
15366 		if (dev_info.driver_id == driver_id) {
15367 			if (!(dev_info.feature_flags & flag)) {
15368 				RTE_LOG(INFO, USER1, "%s not supported\n",
15369 						flag_name);
15370 				return TEST_SKIPPED;
15371 			}
15372 			return 0; /* found */
15373 		}
15374 	}
15375 
15376 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15377 	return TEST_SKIPPED;
15378 }
15379 
15380 static int
15381 test_cryptodev_qat(void)
15382 {
15383 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15384 }
15385 
15386 static int
15387 test_cryptodev_virtio(void)
15388 {
15389 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15390 }
15391 
15392 static int
15393 test_cryptodev_aesni_mb(void)
15394 {
15395 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15396 }
15397 
15398 static int
15399 test_cryptodev_cpu_aesni_mb(void)
15400 {
15401 	int32_t rc;
15402 	enum rte_security_session_action_type at = gbl_action_type;
15403 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15404 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15405 	gbl_action_type = at;
15406 	return rc;
15407 }
15408 
15409 static int
15410 test_cryptodev_chacha_poly_mb(void)
15411 {
15412 	int32_t rc;
15413 	enum rte_security_session_action_type at = gbl_action_type;
15414 	rc = run_cryptodev_testsuite(
15415 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
15416 	gbl_action_type = at;
15417 	return rc;
15418 }
15419 
15420 static int
15421 test_cryptodev_openssl(void)
15422 {
15423 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15424 }
15425 
15426 static int
15427 test_cryptodev_aesni_gcm(void)
15428 {
15429 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15430 }
15431 
15432 static int
15433 test_cryptodev_cpu_aesni_gcm(void)
15434 {
15435 	int32_t rc;
15436 	enum rte_security_session_action_type at = gbl_action_type;
15437 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15438 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15439 	gbl_action_type = at;
15440 	return rc;
15441 }
15442 
15443 static int
15444 test_cryptodev_mlx5(void)
15445 {
15446 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15447 }
15448 
15449 static int
15450 test_cryptodev_null(void)
15451 {
15452 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15453 }
15454 
15455 static int
15456 test_cryptodev_sw_snow3g(void)
15457 {
15458 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15459 }
15460 
15461 static int
15462 test_cryptodev_sw_kasumi(void)
15463 {
15464 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15465 }
15466 
15467 static int
15468 test_cryptodev_sw_zuc(void)
15469 {
15470 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15471 }
15472 
15473 static int
15474 test_cryptodev_armv8(void)
15475 {
15476 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15477 }
15478 
15479 static int
15480 test_cryptodev_mrvl(void)
15481 {
15482 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15483 }
15484 
15485 #ifdef RTE_CRYPTO_SCHEDULER
15486 
15487 static int
15488 test_cryptodev_scheduler(void)
15489 {
15490 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15491 	const enum blockcipher_test_type blk_suites[] = {
15492 		BLKCIPHER_AES_CHAIN_TYPE,
15493 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15494 		BLKCIPHER_AUTHONLY_TYPE
15495 	};
15496 	static struct unit_test_suite scheduler_multicore = {
15497 		.suite_name = "Scheduler Multicore Unit Test Suite",
15498 		.setup = scheduler_multicore_testsuite_setup,
15499 		.teardown = scheduler_mode_testsuite_teardown,
15500 		.unit_test_cases = {TEST_CASES_END()}
15501 	};
15502 	static struct unit_test_suite scheduler_round_robin = {
15503 		.suite_name = "Scheduler Round Robin Unit Test Suite",
15504 		.setup = scheduler_roundrobin_testsuite_setup,
15505 		.teardown = scheduler_mode_testsuite_teardown,
15506 		.unit_test_cases = {TEST_CASES_END()}
15507 	};
15508 	static struct unit_test_suite scheduler_failover = {
15509 		.suite_name = "Scheduler Failover Unit Test Suite",
15510 		.setup = scheduler_failover_testsuite_setup,
15511 		.teardown = scheduler_mode_testsuite_teardown,
15512 		.unit_test_cases = {TEST_CASES_END()}
15513 	};
15514 	static struct unit_test_suite scheduler_pkt_size_distr = {
15515 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15516 		.setup = scheduler_pkt_size_distr_testsuite_setup,
15517 		.teardown = scheduler_mode_testsuite_teardown,
15518 		.unit_test_cases = {TEST_CASES_END()}
15519 	};
15520 	struct unit_test_suite *sched_mode_suites[] = {
15521 		&scheduler_multicore,
15522 		&scheduler_round_robin,
15523 		&scheduler_failover,
15524 		&scheduler_pkt_size_distr
15525 	};
15526 	static struct unit_test_suite scheduler_config = {
15527 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15528 		.unit_test_cases = {
15529 			TEST_CASE(test_scheduler_attach_worker_op),
15530 			TEST_CASE(test_scheduler_mode_multicore_op),
15531 			TEST_CASE(test_scheduler_mode_roundrobin_op),
15532 			TEST_CASE(test_scheduler_mode_failover_op),
15533 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15534 			TEST_CASE(test_scheduler_detach_worker_op),
15535 
15536 			TEST_CASES_END() /**< NULL terminate array */
15537 		}
15538 	};
15539 	struct unit_test_suite *static_suites[] = {
15540 		&scheduler_config,
15541 		&end_testsuite
15542 	};
15543 	static struct unit_test_suite ts = {
15544 		.suite_name = "Scheduler Unit Test Suite",
15545 		.setup = scheduler_testsuite_setup,
15546 		.teardown = testsuite_teardown,
15547 		.unit_test_cases = {TEST_CASES_END()}
15548 	};
15549 
15550 	gbl_driver_id =	rte_cryptodev_driver_id_get(
15551 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15552 
15553 	if (gbl_driver_id == -1) {
15554 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15555 		return TEST_SKIPPED;
15556 	}
15557 
15558 	if (rte_cryptodev_driver_id_get(
15559 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15560 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15561 		return TEST_SKIPPED;
15562 	}
15563 
15564 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15565 		uint8_t blk_i = 0;
15566 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15567 				(struct unit_test_suite *) *
15568 				(RTE_DIM(blk_suites) + 1));
15569 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15570 				blk_suites, RTE_DIM(blk_suites));
15571 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15572 	}
15573 
15574 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15575 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15576 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15577 			RTE_DIM(sched_mode_suites));
15578 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15579 	ret = unit_test_suite_runner(&ts);
15580 
15581 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15582 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15583 				(*sched_mode_suites[sched_i]),
15584 				RTE_DIM(blk_suites));
15585 		free(sched_mode_suites[sched_i]->unit_test_suites);
15586 	}
15587 	free(ts.unit_test_suites);
15588 	return ret;
15589 }
15590 
15591 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15592 
15593 #endif
15594 
15595 static int
15596 test_cryptodev_dpaa2_sec(void)
15597 {
15598 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15599 }
15600 
15601 static int
15602 test_cryptodev_dpaa_sec(void)
15603 {
15604 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15605 }
15606 
15607 static int
15608 test_cryptodev_ccp(void)
15609 {
15610 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15611 }
15612 
15613 static int
15614 test_cryptodev_octeontx(void)
15615 {
15616 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15617 }
15618 
15619 static int
15620 test_cryptodev_octeontx2(void)
15621 {
15622 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15623 }
15624 
15625 static int
15626 test_cryptodev_caam_jr(void)
15627 {
15628 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15629 }
15630 
15631 static int
15632 test_cryptodev_nitrox(void)
15633 {
15634 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15635 }
15636 
15637 static int
15638 test_cryptodev_bcmfs(void)
15639 {
15640 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15641 }
15642 
15643 static int
15644 test_cryptodev_qat_raw_api(void)
15645 {
15646 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15647 	int ret;
15648 
15649 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15650 			"RAW API");
15651 	if (ret)
15652 		return ret;
15653 
15654 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15655 	ret = run_cryptodev_testsuite(pmd_name);
15656 	global_api_test_type = CRYPTODEV_API_TEST;
15657 
15658 	return ret;
15659 }
15660 
15661 static int
15662 test_cryptodev_cn9k(void)
15663 {
15664 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15665 }
15666 
15667 static int
15668 test_cryptodev_cn10k(void)
15669 {
15670 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15671 }
15672 
15673 static int
15674 test_cryptodev_dpaa2_sec_raw_api(void)
15675 {
15676 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15677 	int ret;
15678 
15679 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15680 			"RAW API");
15681 	if (ret)
15682 		return ret;
15683 
15684 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15685 	ret = run_cryptodev_testsuite(pmd_name);
15686 	global_api_test_type = CRYPTODEV_API_TEST;
15687 
15688 	return ret;
15689 }
15690 
15691 static int
15692 test_cryptodev_dpaa_sec_raw_api(void)
15693 {
15694 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15695 	int ret;
15696 
15697 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15698 			"RAW API");
15699 	if (ret)
15700 		return ret;
15701 
15702 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15703 	ret = run_cryptodev_testsuite(pmd_name);
15704 	global_api_test_type = CRYPTODEV_API_TEST;
15705 
15706 	return ret;
15707 }
15708 
15709 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
15710 		test_cryptodev_dpaa2_sec_raw_api);
15711 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
15712 		test_cryptodev_dpaa_sec_raw_api);
15713 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15714 		test_cryptodev_qat_raw_api);
15715 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15716 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15717 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15718 	test_cryptodev_cpu_aesni_mb);
15719 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest,
15720 	test_cryptodev_chacha_poly_mb);
15721 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15722 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15723 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15724 	test_cryptodev_cpu_aesni_gcm);
15725 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15726 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15727 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15728 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15729 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15730 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15731 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15732 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15733 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15734 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15735 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15736 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15737 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15738 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15739 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15740 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15741 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15742 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
15743