xref: /dpdk/app/test/test_cryptodev.c (revision 0f6bbf4e)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #ifndef RTE_EXEC_ENV_WINDOWS
7 
8 #include <time.h>
9 
10 #include <rte_common.h>
11 #include <rte_hexdump.h>
12 #include <rte_mbuf.h>
13 #include <rte_malloc.h>
14 #include <rte_memcpy.h>
15 #include <rte_pause.h>
16 #include <rte_bus_vdev.h>
17 #include <rte_ether.h>
18 
19 #include <rte_crypto.h>
20 #include <rte_cryptodev.h>
21 #include <rte_ip.h>
22 #include <rte_string_fns.h>
23 #include <rte_tcp.h>
24 #include <rte_udp.h>
25 
26 #ifdef RTE_CRYPTO_SCHEDULER
27 #include <rte_cryptodev_scheduler.h>
28 #include <rte_cryptodev_scheduler_operations.h>
29 #endif
30 
31 #include <rte_lcore.h>
32 
33 #include "test.h"
34 #include "test_cryptodev.h"
35 
36 #include "test_cryptodev_blockcipher.h"
37 #include "test_cryptodev_aes_test_vectors.h"
38 #include "test_cryptodev_des_test_vectors.h"
39 #include "test_cryptodev_hash_test_vectors.h"
40 #include "test_cryptodev_kasumi_test_vectors.h"
41 #include "test_cryptodev_kasumi_hash_test_vectors.h"
42 #include "test_cryptodev_snow3g_test_vectors.h"
43 #include "test_cryptodev_snow3g_hash_test_vectors.h"
44 #include "test_cryptodev_zuc_test_vectors.h"
45 #include "test_cryptodev_aead_test_vectors.h"
46 #include "test_cryptodev_hmac_test_vectors.h"
47 #include "test_cryptodev_mixed_test_vectors.h"
48 #ifdef RTE_LIB_SECURITY
49 #include "test_cryptodev_security_ipsec.h"
50 #include "test_cryptodev_security_ipsec_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_vectors.h"
52 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
53 #include "test_cryptodev_security_pdcp_test_func.h"
54 #include "test_cryptodev_security_docsis_test_vectors.h"
55 
56 #define SDAP_DISABLED	0
57 #define SDAP_ENABLED	1
58 #endif
59 
60 #define VDEV_ARGS_SIZE 100
61 #define MAX_NB_SESSIONS 4
62 
63 #define MAX_DRV_SERVICE_CTX_SIZE 256
64 
65 #define MAX_RAW_DEQUEUE_COUNT	65535
66 
67 #define IN_PLACE 0
68 #define OUT_OF_PLACE 1
69 
70 static int gbl_driver_id;
71 
72 static enum rte_security_session_action_type gbl_action_type =
73 	RTE_SECURITY_ACTION_TYPE_NONE;
74 
75 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
76 
77 struct crypto_unittest_params {
78 	struct rte_crypto_sym_xform cipher_xform;
79 	struct rte_crypto_sym_xform auth_xform;
80 	struct rte_crypto_sym_xform aead_xform;
81 #ifdef RTE_LIB_SECURITY
82 	struct rte_security_docsis_xform docsis_xform;
83 #endif
84 
85 	union {
86 		struct rte_cryptodev_sym_session *sess;
87 #ifdef RTE_LIB_SECURITY
88 		struct rte_security_session *sec_session;
89 #endif
90 	};
91 #ifdef RTE_LIB_SECURITY
92 	enum rte_security_session_action_type type;
93 #endif
94 	struct rte_crypto_op *op;
95 
96 	struct rte_mbuf *obuf, *ibuf;
97 
98 	uint8_t *digest;
99 };
100 
101 #define ALIGN_POW2_ROUNDUP(num, align) \
102 	(((num) + (align) - 1) & ~((align) - 1))
103 
104 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
105 	for (j = 0; j < num_child_ts; index++, j++)			\
106 		parent_ts.unit_test_suites[index] = child_ts[j]
107 
108 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
109 	for (j = 0; j < num_blk_types; index++, j++)				\
110 		parent_ts.unit_test_suites[index] =				\
111 				build_blockcipher_test_suite(blk_types[j])
112 
113 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
114 	for (j = index; j < index + num_blk_types; j++)				\
115 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
116 
117 /*
118  * Forward declarations.
119  */
120 static int
121 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
122 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
123 		uint8_t *hmac_key);
124 
125 static int
126 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
127 		struct crypto_unittest_params *ut_params,
128 		struct crypto_testsuite_params *ts_param,
129 		const uint8_t *cipher,
130 		const uint8_t *digest,
131 		const uint8_t *iv);
132 
133 static int
134 security_proto_supported(enum rte_security_session_action_type action,
135 	enum rte_security_session_protocol proto);
136 
137 static int
138 dev_configure_and_start(uint64_t ff_disable);
139 
140 static struct rte_mbuf *
141 setup_test_string(struct rte_mempool *mpool,
142 		const char *string, size_t len, uint8_t blocksize)
143 {
144 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
145 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
146 
147 	if (m) {
148 		char *dst;
149 
150 		memset(m->buf_addr, 0, m->buf_len);
151 		dst = rte_pktmbuf_append(m, t_len);
152 		if (!dst) {
153 			rte_pktmbuf_free(m);
154 			return NULL;
155 		}
156 		if (string != NULL)
157 			rte_memcpy(dst, string, t_len);
158 		else
159 			memset(dst, 0, t_len);
160 	}
161 
162 	return m;
163 }
164 
165 /* Get number of bytes in X bits (rounding up) */
166 static uint32_t
167 ceil_byte_length(uint32_t num_bits)
168 {
169 	if (num_bits % 8)
170 		return ((num_bits >> 3) + 1);
171 	else
172 		return (num_bits >> 3);
173 }
174 
175 static void
176 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
177 		uint8_t is_op_success)
178 {
179 	struct rte_crypto_op *op = user_data;
180 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
181 			RTE_CRYPTO_OP_STATUS_ERROR;
182 }
183 
184 static struct crypto_testsuite_params testsuite_params = { NULL };
185 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
186 static struct crypto_unittest_params unittest_params;
187 
188 void
189 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
190 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
191 		uint8_t len_in_bits, uint8_t cipher_iv_len)
192 {
193 	struct rte_crypto_sym_op *sop = op->sym;
194 	struct rte_crypto_op *ret_op = NULL;
195 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
196 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
197 	union rte_crypto_sym_ofs ofs;
198 	struct rte_crypto_sym_vec vec;
199 	struct rte_crypto_sgl sgl, dest_sgl;
200 	uint32_t max_len;
201 	union rte_cryptodev_session_ctx sess;
202 	uint64_t auth_end_iova;
203 	uint32_t count = 0;
204 	struct rte_crypto_raw_dp_ctx *ctx;
205 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
206 			auth_len = 0;
207 	int32_t n;
208 	uint32_t n_success;
209 	int ctx_service_size;
210 	int32_t status = 0;
211 	int enqueue_status, dequeue_status;
212 	struct crypto_unittest_params *ut_params = &unittest_params;
213 	int is_sgl = sop->m_src->nb_segs > 1;
214 	int is_oop = 0;
215 
216 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
217 	if (ctx_service_size < 0) {
218 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
219 		return;
220 	}
221 
222 	ctx = malloc(ctx_service_size);
223 	if (!ctx) {
224 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
225 		return;
226 	}
227 
228 	/* Both are enums, setting crypto_sess will suit any session type */
229 	sess.crypto_sess = op->sym->session;
230 
231 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
232 			op->sess_type, sess, 0) < 0) {
233 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
234 		goto exit;
235 	}
236 
237 	cipher_iv.iova = 0;
238 	cipher_iv.va = NULL;
239 	aad_auth_iv.iova = 0;
240 	aad_auth_iv.va = NULL;
241 	digest.iova = 0;
242 	digest.va = NULL;
243 	sgl.vec = data_vec;
244 	vec.num = 1;
245 	vec.src_sgl = &sgl;
246 	vec.iv = &cipher_iv;
247 	vec.digest = &digest;
248 	vec.aad = &aad_auth_iv;
249 	vec.status = &status;
250 
251 	ofs.raw = 0;
252 
253 	if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src))
254 		is_oop = 1;
255 
256 	if (is_cipher && is_auth) {
257 		cipher_offset = sop->cipher.data.offset;
258 		cipher_len = sop->cipher.data.length;
259 		auth_offset = sop->auth.data.offset;
260 		auth_len = sop->auth.data.length;
261 		max_len = RTE_MAX(cipher_offset + cipher_len,
262 				auth_offset + auth_len);
263 		if (len_in_bits) {
264 			max_len = max_len >> 3;
265 			cipher_offset = cipher_offset >> 3;
266 			auth_offset = auth_offset >> 3;
267 			cipher_len = cipher_len >> 3;
268 			auth_len = auth_len >> 3;
269 		}
270 		ofs.ofs.cipher.head = cipher_offset;
271 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
272 		ofs.ofs.auth.head = auth_offset;
273 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
274 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
275 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
276 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
277 				op, void *, IV_OFFSET + cipher_iv_len);
278 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
279 				cipher_iv_len);
280 		digest.va = (void *)sop->auth.digest.data;
281 		digest.iova = sop->auth.digest.phys_addr;
282 
283 		if (is_sgl) {
284 			uint32_t remaining_off = auth_offset + auth_len;
285 			struct rte_mbuf *sgl_buf = sop->m_src;
286 			if (is_oop)
287 				sgl_buf = sop->m_dst;
288 
289 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
290 					&& sgl_buf->next != NULL) {
291 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
292 				sgl_buf = sgl_buf->next;
293 			}
294 
295 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
296 				sgl_buf, remaining_off);
297 		} else {
298 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
299 							 auth_offset + auth_len;
300 		}
301 		/* Then check if digest-encrypted conditions are met */
302 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
303 				(digest.iova == auth_end_iova) && is_sgl)
304 			max_len = RTE_MAX(max_len,
305 				auth_offset + auth_len +
306 				ut_params->auth_xform.auth.digest_length);
307 
308 	} else if (is_cipher) {
309 		cipher_offset = sop->cipher.data.offset;
310 		cipher_len = sop->cipher.data.length;
311 		max_len = cipher_len + cipher_offset;
312 		if (len_in_bits) {
313 			max_len = max_len >> 3;
314 			cipher_offset = cipher_offset >> 3;
315 			cipher_len = cipher_len >> 3;
316 		}
317 		ofs.ofs.cipher.head = cipher_offset;
318 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
319 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
320 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
321 
322 	} else if (is_auth) {
323 		auth_offset = sop->auth.data.offset;
324 		auth_len = sop->auth.data.length;
325 		max_len = auth_len + auth_offset;
326 		if (len_in_bits) {
327 			max_len = max_len >> 3;
328 			auth_offset = auth_offset >> 3;
329 			auth_len = auth_len >> 3;
330 		}
331 		ofs.ofs.auth.head = auth_offset;
332 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
333 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
334 				op, void *, IV_OFFSET + cipher_iv_len);
335 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
336 				cipher_iv_len);
337 		digest.va = (void *)sop->auth.digest.data;
338 		digest.iova = sop->auth.digest.phys_addr;
339 
340 	} else { /* aead */
341 		cipher_offset = sop->aead.data.offset;
342 		cipher_len = sop->aead.data.length;
343 		max_len = cipher_len + cipher_offset;
344 		if (len_in_bits) {
345 			max_len = max_len >> 3;
346 			cipher_offset = cipher_offset >> 3;
347 			cipher_len = cipher_len >> 3;
348 		}
349 		ofs.ofs.cipher.head = cipher_offset;
350 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
351 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
352 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
353 		aad_auth_iv.va = (void *)sop->aead.aad.data;
354 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
355 		digest.va = (void *)sop->aead.digest.data;
356 		digest.iova = sop->aead.digest.phys_addr;
357 	}
358 
359 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
360 			data_vec, RTE_DIM(data_vec));
361 	if (n < 0 || n > sop->m_src->nb_segs) {
362 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
363 		goto exit;
364 	}
365 
366 	sgl.num = n;
367 	/* Out of place */
368 	if (is_oop) {
369 		dest_sgl.vec = dest_data_vec;
370 		vec.dest_sgl = &dest_sgl;
371 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
372 				dest_data_vec, RTE_DIM(dest_data_vec));
373 		if (n < 0 || n > sop->m_dst->nb_segs) {
374 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
375 			goto exit;
376 		}
377 		dest_sgl.num = n;
378 	} else
379 		vec.dest_sgl = NULL;
380 
381 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
382 			&enqueue_status) < 1) {
383 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
384 		goto exit;
385 	}
386 
387 	if (enqueue_status == 0) {
388 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
389 		if (status < 0) {
390 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
391 			goto exit;
392 		}
393 	} else if (enqueue_status < 0) {
394 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
395 		goto exit;
396 	}
397 
398 	n = n_success = 0;
399 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
400 		n = rte_cryptodev_raw_dequeue_burst(ctx,
401 			NULL, 1, post_process_raw_dp_op,
402 				(void **)&ret_op, 0, &n_success,
403 				&dequeue_status);
404 		if (dequeue_status < 0) {
405 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
406 			goto exit;
407 		}
408 		if (n == 0)
409 			rte_pause();
410 	}
411 
412 	if (n == 1 && dequeue_status == 0) {
413 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
414 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
415 			goto exit;
416 		}
417 	}
418 
419 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
420 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
421 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
422 					RTE_CRYPTO_OP_STATUS_SUCCESS;
423 
424 exit:
425 	free(ctx);
426 }
427 
428 static void
429 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
430 {
431 	int32_t n, st;
432 	struct rte_crypto_sym_op *sop;
433 	union rte_crypto_sym_ofs ofs;
434 	struct rte_crypto_sgl sgl;
435 	struct rte_crypto_sym_vec symvec;
436 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
437 	struct rte_crypto_vec vec[UINT8_MAX];
438 
439 	sop = op->sym;
440 
441 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
442 		sop->aead.data.length, vec, RTE_DIM(vec));
443 
444 	if (n < 0 || n != sop->m_src->nb_segs) {
445 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
446 		return;
447 	}
448 
449 	sgl.vec = vec;
450 	sgl.num = n;
451 	symvec.src_sgl = &sgl;
452 	symvec.iv = &iv_ptr;
453 	symvec.digest = &digest_ptr;
454 	symvec.aad = &aad_ptr;
455 	symvec.status = &st;
456 	symvec.num = 1;
457 
458 	/* for CPU crypto the IOVA address is not required */
459 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
460 	digest_ptr.va = (void *)sop->aead.digest.data;
461 	aad_ptr.va = (void *)sop->aead.aad.data;
462 
463 	ofs.raw = 0;
464 
465 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
466 		&symvec);
467 
468 	if (n != 1)
469 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
470 	else
471 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
472 }
473 
474 static void
475 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
476 {
477 	int32_t n, st;
478 	struct rte_crypto_sym_op *sop;
479 	union rte_crypto_sym_ofs ofs;
480 	struct rte_crypto_sgl sgl;
481 	struct rte_crypto_sym_vec symvec;
482 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
483 	struct rte_crypto_vec vec[UINT8_MAX];
484 
485 	sop = op->sym;
486 
487 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
488 		sop->auth.data.length, vec, RTE_DIM(vec));
489 
490 	if (n < 0 || n != sop->m_src->nb_segs) {
491 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
492 		return;
493 	}
494 
495 	sgl.vec = vec;
496 	sgl.num = n;
497 	symvec.src_sgl = &sgl;
498 	symvec.iv = &iv_ptr;
499 	symvec.digest = &digest_ptr;
500 	symvec.status = &st;
501 	symvec.num = 1;
502 
503 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
504 	digest_ptr.va = (void *)sop->auth.digest.data;
505 
506 	ofs.raw = 0;
507 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
508 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
509 		(sop->cipher.data.offset + sop->cipher.data.length);
510 
511 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
512 		&symvec);
513 
514 	if (n != 1)
515 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
516 	else
517 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
518 }
519 
520 static struct rte_crypto_op *
521 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
522 {
523 
524 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
525 
526 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
527 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
528 		return NULL;
529 	}
530 
531 	op = NULL;
532 
533 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
534 		rte_pause();
535 
536 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
537 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
538 		return NULL;
539 	}
540 
541 	return op;
542 }
543 
544 static int
545 testsuite_setup(void)
546 {
547 	struct crypto_testsuite_params *ts_params = &testsuite_params;
548 	struct rte_cryptodev_info info;
549 	uint32_t i = 0, nb_devs, dev_id;
550 	uint16_t qp_id;
551 
552 	memset(ts_params, 0, sizeof(*ts_params));
553 
554 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
555 	if (ts_params->mbuf_pool == NULL) {
556 		/* Not already created so create */
557 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
558 				"CRYPTO_MBUFPOOL",
559 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
560 				rte_socket_id());
561 		if (ts_params->mbuf_pool == NULL) {
562 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
563 			return TEST_FAILED;
564 		}
565 	}
566 
567 	ts_params->large_mbuf_pool = rte_mempool_lookup(
568 			"CRYPTO_LARGE_MBUFPOOL");
569 	if (ts_params->large_mbuf_pool == NULL) {
570 		/* Not already created so create */
571 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
572 				"CRYPTO_LARGE_MBUFPOOL",
573 				1, 0, 0, UINT16_MAX,
574 				rte_socket_id());
575 		if (ts_params->large_mbuf_pool == NULL) {
576 			RTE_LOG(ERR, USER1,
577 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
578 			return TEST_FAILED;
579 		}
580 	}
581 
582 	ts_params->op_mpool = rte_crypto_op_pool_create(
583 			"MBUF_CRYPTO_SYM_OP_POOL",
584 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
585 			NUM_MBUFS, MBUF_CACHE_SIZE,
586 			DEFAULT_NUM_XFORMS *
587 			sizeof(struct rte_crypto_sym_xform) +
588 			MAXIMUM_IV_LENGTH,
589 			rte_socket_id());
590 	if (ts_params->op_mpool == NULL) {
591 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
592 		return TEST_FAILED;
593 	}
594 
595 	nb_devs = rte_cryptodev_count();
596 	if (nb_devs < 1) {
597 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
598 		return TEST_SKIPPED;
599 	}
600 
601 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
602 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
603 				rte_cryptodev_driver_name_get(gbl_driver_id));
604 		return TEST_SKIPPED;
605 	}
606 
607 	/* Create list of valid crypto devs */
608 	for (i = 0; i < nb_devs; i++) {
609 		rte_cryptodev_info_get(i, &info);
610 		if (info.driver_id == gbl_driver_id)
611 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
612 	}
613 
614 	if (ts_params->valid_dev_count < 1)
615 		return TEST_FAILED;
616 
617 	/* Set up all the qps on the first of the valid devices found */
618 
619 	dev_id = ts_params->valid_devs[0];
620 
621 	rte_cryptodev_info_get(dev_id, &info);
622 
623 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
624 	ts_params->conf.socket_id = SOCKET_ID_ANY;
625 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
626 
627 	unsigned int session_size =
628 		rte_cryptodev_sym_get_private_session_size(dev_id);
629 
630 #ifdef RTE_LIB_SECURITY
631 	unsigned int security_session_size = rte_security_session_get_size(
632 			rte_cryptodev_get_sec_ctx(dev_id));
633 
634 	if (session_size < security_session_size)
635 		session_size = security_session_size;
636 #endif
637 	/*
638 	 * Create mempool with maximum number of sessions.
639 	 */
640 	if (info.sym.max_nb_sessions != 0 &&
641 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
642 		RTE_LOG(ERR, USER1, "Device does not support "
643 				"at least %u sessions\n",
644 				MAX_NB_SESSIONS);
645 		return TEST_FAILED;
646 	}
647 
648 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
649 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
650 			SOCKET_ID_ANY);
651 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
652 			"session mempool allocation failed");
653 
654 	ts_params->session_priv_mpool = rte_mempool_create(
655 			"test_sess_mp_priv",
656 			MAX_NB_SESSIONS,
657 			session_size,
658 			0, 0, NULL, NULL, NULL,
659 			NULL, SOCKET_ID_ANY,
660 			0);
661 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
662 			"session mempool allocation failed");
663 
664 
665 
666 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
667 			&ts_params->conf),
668 			"Failed to configure cryptodev %u with %u qps",
669 			dev_id, ts_params->conf.nb_queue_pairs);
670 
671 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
672 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
673 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
674 
675 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
676 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
677 			dev_id, qp_id, &ts_params->qp_conf,
678 			rte_cryptodev_socket_id(dev_id)),
679 			"Failed to setup queue pair %u on cryptodev %u",
680 			qp_id, dev_id);
681 	}
682 
683 	return TEST_SUCCESS;
684 }
685 
686 static void
687 testsuite_teardown(void)
688 {
689 	struct crypto_testsuite_params *ts_params = &testsuite_params;
690 	int res;
691 
692 	if (ts_params->mbuf_pool != NULL) {
693 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
694 		rte_mempool_avail_count(ts_params->mbuf_pool));
695 	}
696 
697 	if (ts_params->op_mpool != NULL) {
698 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
699 		rte_mempool_avail_count(ts_params->op_mpool));
700 	}
701 
702 	/* Free session mempools */
703 	if (ts_params->session_priv_mpool != NULL) {
704 		rte_mempool_free(ts_params->session_priv_mpool);
705 		ts_params->session_priv_mpool = NULL;
706 	}
707 
708 	if (ts_params->session_mpool != NULL) {
709 		rte_mempool_free(ts_params->session_mpool);
710 		ts_params->session_mpool = NULL;
711 	}
712 
713 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
714 	if (res)
715 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
716 }
717 
718 static int
719 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
720 		const int *algs, uint16_t num_algs)
721 {
722 	uint8_t dev_id = testsuite_params.valid_devs[0];
723 	bool some_alg_supported = FALSE;
724 	uint16_t i;
725 
726 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
727 		struct rte_cryptodev_sym_capability_idx alg = {
728 			type, {algs[i]}
729 		};
730 		if (rte_cryptodev_sym_capability_get(dev_id,
731 				&alg) != NULL)
732 			some_alg_supported = TRUE;
733 	}
734 	if (!some_alg_supported)
735 		return TEST_SKIPPED;
736 
737 	return 0;
738 }
739 
740 int
741 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
742 		uint16_t num_ciphers)
743 {
744 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
745 			(const int *) ciphers, num_ciphers);
746 }
747 
748 int
749 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
750 		uint16_t num_auths)
751 {
752 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
753 			(const int *) auths, num_auths);
754 }
755 
756 int
757 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
758 		uint16_t num_aeads)
759 {
760 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
761 			(const int *) aeads, num_aeads);
762 }
763 
764 static int
765 null_testsuite_setup(void)
766 {
767 	struct crypto_testsuite_params *ts_params = &testsuite_params;
768 	uint8_t dev_id = ts_params->valid_devs[0];
769 	struct rte_cryptodev_info dev_info;
770 	const enum rte_crypto_cipher_algorithm ciphers[] = {
771 		RTE_CRYPTO_CIPHER_NULL
772 	};
773 	const enum rte_crypto_auth_algorithm auths[] = {
774 		RTE_CRYPTO_AUTH_NULL
775 	};
776 
777 	rte_cryptodev_info_get(dev_id, &dev_info);
778 
779 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
780 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
781 				"testsuite not met\n");
782 		return TEST_SKIPPED;
783 	}
784 
785 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
786 			&& check_auth_capabilities_supported(auths,
787 			RTE_DIM(auths)) != 0) {
788 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
789 				"testsuite not met\n");
790 		return TEST_SKIPPED;
791 	}
792 
793 	return 0;
794 }
795 
796 static int
797 crypto_gen_testsuite_setup(void)
798 {
799 	struct crypto_testsuite_params *ts_params = &testsuite_params;
800 	uint8_t dev_id = ts_params->valid_devs[0];
801 	struct rte_cryptodev_info dev_info;
802 
803 	rte_cryptodev_info_get(dev_id, &dev_info);
804 
805 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
806 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
807 				"testsuite not met\n");
808 		return TEST_SKIPPED;
809 	}
810 
811 	return 0;
812 }
813 
814 #ifdef RTE_LIB_SECURITY
815 static int
816 ipsec_proto_testsuite_setup(void)
817 {
818 	struct crypto_testsuite_params *ts_params = &testsuite_params;
819 	struct crypto_unittest_params *ut_params = &unittest_params;
820 	struct rte_cryptodev_info dev_info;
821 	int ret = 0;
822 
823 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
824 
825 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
826 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
827 				"testsuite not met\n");
828 		return TEST_SKIPPED;
829 	}
830 
831 	/* Reconfigure to enable security */
832 	ret = dev_configure_and_start(0);
833 	if (ret != TEST_SUCCESS)
834 		return ret;
835 
836 	/* Set action type */
837 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
838 
839 	if (security_proto_supported(
840 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
841 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
842 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
843 				"test not met\n");
844 		ret = TEST_SKIPPED;
845 	}
846 
847 	test_ipsec_alg_list_populate();
848 
849 	/*
850 	 * Stop the device. Device would be started again by individual test
851 	 * case setup routine.
852 	 */
853 	rte_cryptodev_stop(ts_params->valid_devs[0]);
854 
855 	return ret;
856 }
857 
858 static int
859 pdcp_proto_testsuite_setup(void)
860 {
861 	struct crypto_testsuite_params *ts_params = &testsuite_params;
862 	uint8_t dev_id = ts_params->valid_devs[0];
863 	struct rte_cryptodev_info dev_info;
864 	const enum rte_crypto_cipher_algorithm ciphers[] = {
865 		RTE_CRYPTO_CIPHER_NULL,
866 		RTE_CRYPTO_CIPHER_AES_CTR,
867 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
868 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
869 	};
870 	const enum rte_crypto_auth_algorithm auths[] = {
871 		RTE_CRYPTO_AUTH_NULL,
872 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
873 		RTE_CRYPTO_AUTH_AES_CMAC,
874 		RTE_CRYPTO_AUTH_ZUC_EIA3
875 	};
876 
877 	rte_cryptodev_info_get(dev_id, &dev_info);
878 
879 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
880 			!(dev_info.feature_flags &
881 			RTE_CRYPTODEV_FF_SECURITY)) {
882 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
883 				"testsuite not met\n");
884 		return TEST_SKIPPED;
885 	}
886 
887 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
888 			&& check_auth_capabilities_supported(auths,
889 			RTE_DIM(auths)) != 0) {
890 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
891 				"testsuite not met\n");
892 		return TEST_SKIPPED;
893 	}
894 
895 	return 0;
896 }
897 
898 static int
899 docsis_proto_testsuite_setup(void)
900 {
901 	struct crypto_testsuite_params *ts_params = &testsuite_params;
902 	uint8_t dev_id = ts_params->valid_devs[0];
903 	struct rte_cryptodev_info dev_info;
904 	const enum rte_crypto_cipher_algorithm ciphers[] = {
905 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
906 	};
907 
908 	rte_cryptodev_info_get(dev_id, &dev_info);
909 
910 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
911 			!(dev_info.feature_flags &
912 			RTE_CRYPTODEV_FF_SECURITY)) {
913 		RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS "
914 				"Proto testsuite not met\n");
915 		return TEST_SKIPPED;
916 	}
917 
918 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
919 		RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto "
920 				"testsuite not met\n");
921 		return TEST_SKIPPED;
922 	}
923 
924 	return 0;
925 }
926 #endif
927 
928 static int
929 aes_ccm_auth_testsuite_setup(void)
930 {
931 	struct crypto_testsuite_params *ts_params = &testsuite_params;
932 	uint8_t dev_id = ts_params->valid_devs[0];
933 	struct rte_cryptodev_info dev_info;
934 	const enum rte_crypto_aead_algorithm aeads[] = {
935 		RTE_CRYPTO_AEAD_AES_CCM
936 	};
937 
938 	rte_cryptodev_info_get(dev_id, &dev_info);
939 
940 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
941 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
942 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
943 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
944 				"testsuite not met\n");
945 		return TEST_SKIPPED;
946 	}
947 
948 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
949 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
950 				"testsuite not met\n");
951 		return TEST_SKIPPED;
952 	}
953 
954 	return 0;
955 }
956 
957 static int
958 aes_gcm_auth_testsuite_setup(void)
959 {
960 	struct crypto_testsuite_params *ts_params = &testsuite_params;
961 	uint8_t dev_id = ts_params->valid_devs[0];
962 	struct rte_cryptodev_info dev_info;
963 	const enum rte_crypto_aead_algorithm aeads[] = {
964 		RTE_CRYPTO_AEAD_AES_GCM
965 	};
966 
967 	rte_cryptodev_info_get(dev_id, &dev_info);
968 
969 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
970 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
971 				"testsuite not met\n");
972 		return TEST_SKIPPED;
973 	}
974 
975 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
976 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
977 				"testsuite not met\n");
978 		return TEST_SKIPPED;
979 	}
980 
981 	return 0;
982 }
983 
984 static int
985 aes_gmac_auth_testsuite_setup(void)
986 {
987 	struct crypto_testsuite_params *ts_params = &testsuite_params;
988 	uint8_t dev_id = ts_params->valid_devs[0];
989 	struct rte_cryptodev_info dev_info;
990 	const enum rte_crypto_auth_algorithm auths[] = {
991 		RTE_CRYPTO_AUTH_AES_GMAC
992 	};
993 
994 	rte_cryptodev_info_get(dev_id, &dev_info);
995 
996 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
997 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
998 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
999 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
1000 				"testsuite not met\n");
1001 		return TEST_SKIPPED;
1002 	}
1003 
1004 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1005 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
1006 				"testsuite not met\n");
1007 		return TEST_SKIPPED;
1008 	}
1009 
1010 	return 0;
1011 }
1012 
1013 static int
1014 chacha20_poly1305_testsuite_setup(void)
1015 {
1016 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1017 	uint8_t dev_id = ts_params->valid_devs[0];
1018 	struct rte_cryptodev_info dev_info;
1019 	const enum rte_crypto_aead_algorithm aeads[] = {
1020 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
1021 	};
1022 
1023 	rte_cryptodev_info_get(dev_id, &dev_info);
1024 
1025 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1026 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1027 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1028 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
1029 				"Chacha20-Poly1305 testsuite not met\n");
1030 		return TEST_SKIPPED;
1031 	}
1032 
1033 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1034 		RTE_LOG(INFO, USER1, "Capability requirements for "
1035 				"Chacha20-Poly1305 testsuite not met\n");
1036 		return TEST_SKIPPED;
1037 	}
1038 
1039 	return 0;
1040 }
1041 
1042 static int
1043 snow3g_testsuite_setup(void)
1044 {
1045 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1046 	uint8_t dev_id = ts_params->valid_devs[0];
1047 	struct rte_cryptodev_info dev_info;
1048 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1049 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1050 
1051 	};
1052 	const enum rte_crypto_auth_algorithm auths[] = {
1053 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1054 	};
1055 
1056 	rte_cryptodev_info_get(dev_id, &dev_info);
1057 
1058 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1059 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1060 				"testsuite not met\n");
1061 		return TEST_SKIPPED;
1062 	}
1063 
1064 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1065 			&& check_auth_capabilities_supported(auths,
1066 			RTE_DIM(auths)) != 0) {
1067 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1068 				"testsuite not met\n");
1069 		return TEST_SKIPPED;
1070 	}
1071 
1072 	return 0;
1073 }
1074 
1075 static int
1076 zuc_testsuite_setup(void)
1077 {
1078 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1079 	uint8_t dev_id = ts_params->valid_devs[0];
1080 	struct rte_cryptodev_info dev_info;
1081 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1082 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1083 	};
1084 	const enum rte_crypto_auth_algorithm auths[] = {
1085 		RTE_CRYPTO_AUTH_ZUC_EIA3
1086 	};
1087 
1088 	rte_cryptodev_info_get(dev_id, &dev_info);
1089 
1090 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1091 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1092 				"testsuite not met\n");
1093 		return TEST_SKIPPED;
1094 	}
1095 
1096 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1097 			&& check_auth_capabilities_supported(auths,
1098 			RTE_DIM(auths)) != 0) {
1099 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1100 				"testsuite not met\n");
1101 		return TEST_SKIPPED;
1102 	}
1103 
1104 	return 0;
1105 }
1106 
1107 static int
1108 hmac_md5_auth_testsuite_setup(void)
1109 {
1110 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1111 	uint8_t dev_id = ts_params->valid_devs[0];
1112 	struct rte_cryptodev_info dev_info;
1113 	const enum rte_crypto_auth_algorithm auths[] = {
1114 		RTE_CRYPTO_AUTH_MD5_HMAC
1115 	};
1116 
1117 	rte_cryptodev_info_get(dev_id, &dev_info);
1118 
1119 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1120 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1121 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1122 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1123 				"Auth testsuite not met\n");
1124 		return TEST_SKIPPED;
1125 	}
1126 
1127 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1128 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1129 				"testsuite not met\n");
1130 		return TEST_SKIPPED;
1131 	}
1132 
1133 	return 0;
1134 }
1135 
1136 static int
1137 kasumi_testsuite_setup(void)
1138 {
1139 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1140 	uint8_t dev_id = ts_params->valid_devs[0];
1141 	struct rte_cryptodev_info dev_info;
1142 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1143 		RTE_CRYPTO_CIPHER_KASUMI_F8
1144 	};
1145 	const enum rte_crypto_auth_algorithm auths[] = {
1146 		RTE_CRYPTO_AUTH_KASUMI_F9
1147 	};
1148 
1149 	rte_cryptodev_info_get(dev_id, &dev_info);
1150 
1151 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1152 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1153 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1154 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1155 				"testsuite not met\n");
1156 		return TEST_SKIPPED;
1157 	}
1158 
1159 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1160 			&& check_auth_capabilities_supported(auths,
1161 			RTE_DIM(auths)) != 0) {
1162 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1163 				"testsuite not met\n");
1164 		return TEST_SKIPPED;
1165 	}
1166 
1167 	return 0;
1168 }
1169 
1170 static int
1171 negative_aes_gcm_testsuite_setup(void)
1172 {
1173 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1174 	uint8_t dev_id = ts_params->valid_devs[0];
1175 	struct rte_cryptodev_info dev_info;
1176 	const enum rte_crypto_aead_algorithm aeads[] = {
1177 		RTE_CRYPTO_AEAD_AES_GCM
1178 	};
1179 
1180 	rte_cryptodev_info_get(dev_id, &dev_info);
1181 
1182 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1183 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1184 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1185 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1186 				"AES GCM testsuite not met\n");
1187 		return TEST_SKIPPED;
1188 	}
1189 
1190 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1191 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1192 				"AES GCM testsuite not met\n");
1193 		return TEST_SKIPPED;
1194 	}
1195 
1196 	return 0;
1197 }
1198 
1199 static int
1200 negative_aes_gmac_testsuite_setup(void)
1201 {
1202 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1203 	uint8_t dev_id = ts_params->valid_devs[0];
1204 	struct rte_cryptodev_info dev_info;
1205 	const enum rte_crypto_auth_algorithm auths[] = {
1206 		RTE_CRYPTO_AUTH_AES_GMAC
1207 	};
1208 
1209 	rte_cryptodev_info_get(dev_id, &dev_info);
1210 
1211 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1212 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1213 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1214 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1215 				"AES GMAC testsuite not met\n");
1216 		return TEST_SKIPPED;
1217 	}
1218 
1219 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1220 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1221 				"AES GMAC testsuite not met\n");
1222 		return TEST_SKIPPED;
1223 	}
1224 
1225 	return 0;
1226 }
1227 
1228 static int
1229 mixed_cipher_hash_testsuite_setup(void)
1230 {
1231 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1232 	uint8_t dev_id = ts_params->valid_devs[0];
1233 	struct rte_cryptodev_info dev_info;
1234 	uint64_t feat_flags;
1235 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1236 		RTE_CRYPTO_CIPHER_NULL,
1237 		RTE_CRYPTO_CIPHER_AES_CTR,
1238 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1239 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1240 	};
1241 	const enum rte_crypto_auth_algorithm auths[] = {
1242 		RTE_CRYPTO_AUTH_NULL,
1243 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1244 		RTE_CRYPTO_AUTH_AES_CMAC,
1245 		RTE_CRYPTO_AUTH_ZUC_EIA3
1246 	};
1247 
1248 	rte_cryptodev_info_get(dev_id, &dev_info);
1249 	feat_flags = dev_info.feature_flags;
1250 
1251 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1252 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1253 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1254 				"Cipher Hash testsuite not met\n");
1255 		return TEST_SKIPPED;
1256 	}
1257 
1258 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1259 			&& check_auth_capabilities_supported(auths,
1260 			RTE_DIM(auths)) != 0) {
1261 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1262 				"Cipher Hash testsuite not met\n");
1263 		return TEST_SKIPPED;
1264 	}
1265 
1266 	return 0;
1267 }
1268 
1269 static int
1270 esn_testsuite_setup(void)
1271 {
1272 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1273 	uint8_t dev_id = ts_params->valid_devs[0];
1274 	struct rte_cryptodev_info dev_info;
1275 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1276 		RTE_CRYPTO_CIPHER_AES_CBC
1277 	};
1278 	const enum rte_crypto_auth_algorithm auths[] = {
1279 		RTE_CRYPTO_AUTH_SHA1_HMAC
1280 	};
1281 
1282 	rte_cryptodev_info_get(dev_id, &dev_info);
1283 
1284 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1285 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1286 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1287 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1288 				"testsuite not met\n");
1289 		return TEST_SKIPPED;
1290 	}
1291 
1292 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1293 			&& check_auth_capabilities_supported(auths,
1294 			RTE_DIM(auths)) != 0) {
1295 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1296 				"testsuite not met\n");
1297 		return TEST_SKIPPED;
1298 	}
1299 
1300 	return 0;
1301 }
1302 
1303 static int
1304 multi_session_testsuite_setup(void)
1305 {
1306 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1307 	uint8_t dev_id = ts_params->valid_devs[0];
1308 	struct rte_cryptodev_info dev_info;
1309 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1310 		RTE_CRYPTO_CIPHER_AES_CBC
1311 	};
1312 	const enum rte_crypto_auth_algorithm auths[] = {
1313 		RTE_CRYPTO_AUTH_SHA512_HMAC
1314 	};
1315 
1316 	rte_cryptodev_info_get(dev_id, &dev_info);
1317 
1318 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1319 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1320 				"Session testsuite not met\n");
1321 		return TEST_SKIPPED;
1322 	}
1323 
1324 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1325 			&& check_auth_capabilities_supported(auths,
1326 			RTE_DIM(auths)) != 0) {
1327 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1328 				"Session testsuite not met\n");
1329 		return TEST_SKIPPED;
1330 	}
1331 
1332 	return 0;
1333 }
1334 
1335 static int
1336 negative_hmac_sha1_testsuite_setup(void)
1337 {
1338 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1339 	uint8_t dev_id = ts_params->valid_devs[0];
1340 	struct rte_cryptodev_info dev_info;
1341 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1342 		RTE_CRYPTO_CIPHER_AES_CBC
1343 	};
1344 	const enum rte_crypto_auth_algorithm auths[] = {
1345 		RTE_CRYPTO_AUTH_SHA1_HMAC
1346 	};
1347 
1348 	rte_cryptodev_info_get(dev_id, &dev_info);
1349 
1350 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1351 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1352 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1353 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1354 				"HMAC SHA1 testsuite not met\n");
1355 		return TEST_SKIPPED;
1356 	}
1357 
1358 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1359 			&& check_auth_capabilities_supported(auths,
1360 			RTE_DIM(auths)) != 0) {
1361 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1362 				"HMAC SHA1 testsuite not met\n");
1363 		return TEST_SKIPPED;
1364 	}
1365 
1366 	return 0;
1367 }
1368 
1369 static int
1370 dev_configure_and_start(uint64_t ff_disable)
1371 {
1372 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1373 	struct crypto_unittest_params *ut_params = &unittest_params;
1374 
1375 	uint16_t qp_id;
1376 
1377 	/* Clear unit test parameters before running test */
1378 	memset(ut_params, 0, sizeof(*ut_params));
1379 
1380 	/* Reconfigure device to default parameters */
1381 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1382 	ts_params->conf.ff_disable = ff_disable;
1383 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1384 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1385 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1386 
1387 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1388 			&ts_params->conf),
1389 			"Failed to configure cryptodev %u",
1390 			ts_params->valid_devs[0]);
1391 
1392 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1393 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1394 			ts_params->valid_devs[0], qp_id,
1395 			&ts_params->qp_conf,
1396 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1397 			"Failed to setup queue pair %u on cryptodev %u",
1398 			qp_id, ts_params->valid_devs[0]);
1399 	}
1400 
1401 
1402 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1403 
1404 	/* Start the device */
1405 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1406 			"Failed to start cryptodev %u",
1407 			ts_params->valid_devs[0]);
1408 
1409 	return TEST_SUCCESS;
1410 }
1411 
1412 int
1413 ut_setup(void)
1414 {
1415 	/* Configure and start the device with security feature disabled */
1416 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1417 }
1418 
1419 static int
1420 ut_setup_security(void)
1421 {
1422 	/* Configure and start the device with no features disabled */
1423 	return dev_configure_and_start(0);
1424 }
1425 
1426 void
1427 ut_teardown(void)
1428 {
1429 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1430 	struct crypto_unittest_params *ut_params = &unittest_params;
1431 
1432 	/* free crypto session structure */
1433 #ifdef RTE_LIB_SECURITY
1434 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1435 		if (ut_params->sec_session) {
1436 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1437 						(ts_params->valid_devs[0]),
1438 						ut_params->sec_session);
1439 			ut_params->sec_session = NULL;
1440 		}
1441 	} else
1442 #endif
1443 	{
1444 		if (ut_params->sess) {
1445 			rte_cryptodev_sym_session_clear(
1446 					ts_params->valid_devs[0],
1447 					ut_params->sess);
1448 			rte_cryptodev_sym_session_free(ut_params->sess);
1449 			ut_params->sess = NULL;
1450 		}
1451 	}
1452 
1453 	/* free crypto operation structure */
1454 	if (ut_params->op)
1455 		rte_crypto_op_free(ut_params->op);
1456 
1457 	/*
1458 	 * free mbuf - both obuf and ibuf are usually the same,
1459 	 * so check if they point at the same address is necessary,
1460 	 * to avoid freeing the mbuf twice.
1461 	 */
1462 	if (ut_params->obuf) {
1463 		rte_pktmbuf_free(ut_params->obuf);
1464 		if (ut_params->ibuf == ut_params->obuf)
1465 			ut_params->ibuf = 0;
1466 		ut_params->obuf = 0;
1467 	}
1468 	if (ut_params->ibuf) {
1469 		rte_pktmbuf_free(ut_params->ibuf);
1470 		ut_params->ibuf = 0;
1471 	}
1472 
1473 	if (ts_params->mbuf_pool != NULL)
1474 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1475 			rte_mempool_avail_count(ts_params->mbuf_pool));
1476 
1477 	/* Stop the device */
1478 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1479 }
1480 
1481 static int
1482 test_device_configure_invalid_dev_id(void)
1483 {
1484 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1485 	uint16_t dev_id, num_devs = 0;
1486 
1487 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1488 			"Need at least %d devices for test", 1);
1489 
1490 	/* valid dev_id values */
1491 	dev_id = ts_params->valid_devs[0];
1492 
1493 	/* Stop the device in case it's started so it can be configured */
1494 	rte_cryptodev_stop(dev_id);
1495 
1496 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1497 			"Failed test for rte_cryptodev_configure: "
1498 			"invalid dev_num %u", dev_id);
1499 
1500 	/* invalid dev_id values */
1501 	dev_id = num_devs;
1502 
1503 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1504 			"Failed test for rte_cryptodev_configure: "
1505 			"invalid dev_num %u", dev_id);
1506 
1507 	dev_id = 0xff;
1508 
1509 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1510 			"Failed test for rte_cryptodev_configure:"
1511 			"invalid dev_num %u", dev_id);
1512 
1513 	return TEST_SUCCESS;
1514 }
1515 
1516 static int
1517 test_device_configure_invalid_queue_pair_ids(void)
1518 {
1519 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1520 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1521 
1522 	/* Stop the device in case it's started so it can be configured */
1523 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1524 
1525 	/* valid - max value queue pairs */
1526 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
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], ts_params->conf.nb_queue_pairs);
1532 
1533 	/* valid - one queue pairs */
1534 	ts_params->conf.nb_queue_pairs = 1;
1535 
1536 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1537 			&ts_params->conf),
1538 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1539 			ts_params->valid_devs[0],
1540 			ts_params->conf.nb_queue_pairs);
1541 
1542 
1543 	/* invalid - zero queue pairs */
1544 	ts_params->conf.nb_queue_pairs = 0;
1545 
1546 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1547 			&ts_params->conf),
1548 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1549 			" invalid qps: %u",
1550 			ts_params->valid_devs[0],
1551 			ts_params->conf.nb_queue_pairs);
1552 
1553 
1554 	/* invalid - max value supported by field queue pairs */
1555 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1556 
1557 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1558 			&ts_params->conf),
1559 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1560 			" invalid qps: %u",
1561 			ts_params->valid_devs[0],
1562 			ts_params->conf.nb_queue_pairs);
1563 
1564 
1565 	/* invalid - max value + 1 queue pairs */
1566 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1567 
1568 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1569 			&ts_params->conf),
1570 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1571 			" invalid qps: %u",
1572 			ts_params->valid_devs[0],
1573 			ts_params->conf.nb_queue_pairs);
1574 
1575 	/* revert to original testsuite value */
1576 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1577 
1578 	return TEST_SUCCESS;
1579 }
1580 
1581 static int
1582 test_queue_pair_descriptor_setup(void)
1583 {
1584 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1585 	struct rte_cryptodev_qp_conf qp_conf = {
1586 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1587 	};
1588 	uint16_t qp_id;
1589 
1590 	/* Stop the device in case it's started so it can be configured */
1591 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1592 
1593 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1594 			&ts_params->conf),
1595 			"Failed to configure cryptodev %u",
1596 			ts_params->valid_devs[0]);
1597 
1598 	/*
1599 	 * Test various ring sizes on this device. memzones can't be
1600 	 * freed so are re-used if ring is released and re-created.
1601 	 */
1602 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1603 	qp_conf.mp_session = ts_params->session_mpool;
1604 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1605 
1606 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1607 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1608 				ts_params->valid_devs[0], qp_id, &qp_conf,
1609 				rte_cryptodev_socket_id(
1610 						ts_params->valid_devs[0])),
1611 				"Failed test for "
1612 				"rte_cryptodev_queue_pair_setup: num_inflights "
1613 				"%u on qp %u on cryptodev %u",
1614 				qp_conf.nb_descriptors, qp_id,
1615 				ts_params->valid_devs[0]);
1616 	}
1617 
1618 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1619 
1620 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1621 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1622 				ts_params->valid_devs[0], qp_id, &qp_conf,
1623 				rte_cryptodev_socket_id(
1624 						ts_params->valid_devs[0])),
1625 				"Failed test for"
1626 				" rte_cryptodev_queue_pair_setup: num_inflights"
1627 				" %u on qp %u on cryptodev %u",
1628 				qp_conf.nb_descriptors, qp_id,
1629 				ts_params->valid_devs[0]);
1630 	}
1631 
1632 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1633 
1634 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1635 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1636 				ts_params->valid_devs[0], qp_id, &qp_conf,
1637 				rte_cryptodev_socket_id(
1638 						ts_params->valid_devs[0])),
1639 				"Failed test for "
1640 				"rte_cryptodev_queue_pair_setup: num_inflights"
1641 				" %u on qp %u on cryptodev %u",
1642 				qp_conf.nb_descriptors, qp_id,
1643 				ts_params->valid_devs[0]);
1644 	}
1645 
1646 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1647 
1648 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1649 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1650 				ts_params->valid_devs[0], qp_id, &qp_conf,
1651 				rte_cryptodev_socket_id(
1652 						ts_params->valid_devs[0])),
1653 				"Failed test for"
1654 				" rte_cryptodev_queue_pair_setup:"
1655 				"num_inflights %u on qp %u on cryptodev %u",
1656 				qp_conf.nb_descriptors, qp_id,
1657 				ts_params->valid_devs[0]);
1658 	}
1659 
1660 	/* test invalid queue pair id */
1661 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1662 
1663 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1664 
1665 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1666 			ts_params->valid_devs[0],
1667 			qp_id, &qp_conf,
1668 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1669 			"Failed test for rte_cryptodev_queue_pair_setup:"
1670 			"invalid qp %u on cryptodev %u",
1671 			qp_id, ts_params->valid_devs[0]);
1672 
1673 	qp_id = 0xffff; /*invalid*/
1674 
1675 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1676 			ts_params->valid_devs[0],
1677 			qp_id, &qp_conf,
1678 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1679 			"Failed test for rte_cryptodev_queue_pair_setup:"
1680 			"invalid qp %u on cryptodev %u",
1681 			qp_id, ts_params->valid_devs[0]);
1682 
1683 	return TEST_SUCCESS;
1684 }
1685 
1686 /* ***** Plaintext data for tests ***** */
1687 
1688 const char catch_22_quote_1[] =
1689 		"There was only one catch and that was Catch-22, which "
1690 		"specified that a concern for one's safety in the face of "
1691 		"dangers that were real and immediate was the process of a "
1692 		"rational mind. Orr was crazy and could be grounded. All he "
1693 		"had to do was ask; and as soon as he did, he would no longer "
1694 		"be crazy and would have to fly more missions. Orr would be "
1695 		"crazy to fly more missions and sane if he didn't, but if he "
1696 		"was sane he had to fly them. If he flew them he was crazy "
1697 		"and didn't have to; but if he didn't want to he was sane and "
1698 		"had to. Yossarian was moved very deeply by the absolute "
1699 		"simplicity of this clause of Catch-22 and let out a "
1700 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1701 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1702 
1703 const char catch_22_quote[] =
1704 		"What a lousy earth! He wondered how many people were "
1705 		"destitute that same night even in his own prosperous country, "
1706 		"how many homes were shanties, how many husbands were drunk "
1707 		"and wives socked, and how many children were bullied, abused, "
1708 		"or abandoned. How many families hungered for food they could "
1709 		"not afford to buy? How many hearts were broken? How many "
1710 		"suicides would take place that same night, how many people "
1711 		"would go insane? How many cockroaches and landlords would "
1712 		"triumph? How many winners were losers, successes failures, "
1713 		"and rich men poor men? How many wise guys were stupid? How "
1714 		"many happy endings were unhappy endings? How many honest men "
1715 		"were liars, brave men cowards, loyal men traitors, how many "
1716 		"sainted men were corrupt, how many people in positions of "
1717 		"trust had sold their souls to bodyguards, how many had never "
1718 		"had souls? How many straight-and-narrow paths were crooked "
1719 		"paths? How many best families were worst families and how "
1720 		"many good people were bad people? When you added them all up "
1721 		"and then subtracted, you might be left with only the children, "
1722 		"and perhaps with Albert Einstein and an old violinist or "
1723 		"sculptor somewhere.";
1724 
1725 #define QUOTE_480_BYTES		(480)
1726 #define QUOTE_512_BYTES		(512)
1727 #define QUOTE_768_BYTES		(768)
1728 #define QUOTE_1024_BYTES	(1024)
1729 
1730 
1731 
1732 /* ***** SHA1 Hash Tests ***** */
1733 
1734 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1735 
1736 static uint8_t hmac_sha1_key[] = {
1737 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1738 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1739 	0xDE, 0xF4, 0xDE, 0xAD };
1740 
1741 /* ***** SHA224 Hash Tests ***** */
1742 
1743 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1744 
1745 
1746 /* ***** AES-CBC Cipher Tests ***** */
1747 
1748 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1749 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1750 
1751 static uint8_t aes_cbc_key[] = {
1752 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1753 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1754 
1755 static uint8_t aes_cbc_iv[] = {
1756 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1757 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1758 
1759 
1760 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1761 
1762 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1763 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1764 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1765 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1766 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1767 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1768 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1769 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1770 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1771 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1772 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1773 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1774 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1775 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1776 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1777 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1778 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1779 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1780 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1781 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1782 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1783 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1784 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1785 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1786 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1787 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1788 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1789 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1790 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1791 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1792 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1793 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1794 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1795 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1796 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1797 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1798 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1799 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1800 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1801 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1802 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1803 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1804 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1805 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1806 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1807 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1808 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1809 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1810 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1811 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1812 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1813 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1814 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1815 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1816 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1817 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1818 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1819 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1820 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1821 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1822 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1823 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1824 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1825 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1826 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1827 };
1828 
1829 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1830 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1831 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1832 	0x18, 0x8c, 0x1d, 0x32
1833 };
1834 
1835 
1836 /* Multisession Vector context Test */
1837 /*Begin Session 0 */
1838 static uint8_t ms_aes_cbc_key0[] = {
1839 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1840 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1841 };
1842 
1843 static uint8_t ms_aes_cbc_iv0[] = {
1844 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1845 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1846 };
1847 
1848 static const uint8_t ms_aes_cbc_cipher0[] = {
1849 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1850 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1851 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1852 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1853 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1854 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1855 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1856 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1857 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1858 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1859 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1860 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1861 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1862 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1863 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1864 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1865 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1866 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1867 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1868 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1869 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1870 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1871 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1872 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1873 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1874 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1875 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1876 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1877 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1878 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1879 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1880 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1881 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1882 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1883 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1884 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1885 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1886 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1887 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1888 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1889 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1890 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1891 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1892 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1893 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1894 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1895 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1896 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1897 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1898 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1899 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1900 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1901 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1902 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1903 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1904 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1905 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1906 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1907 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1908 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1909 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1910 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1911 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1912 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1913 };
1914 
1915 
1916 static  uint8_t ms_hmac_key0[] = {
1917 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1918 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1919 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1920 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1921 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1922 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1923 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1924 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1925 };
1926 
1927 static const uint8_t ms_hmac_digest0[] = {
1928 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1929 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1930 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1931 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1932 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1933 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1934 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1935 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1936 		};
1937 
1938 /* End Session 0 */
1939 /* Begin session 1 */
1940 
1941 static  uint8_t ms_aes_cbc_key1[] = {
1942 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1943 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1944 };
1945 
1946 static  uint8_t ms_aes_cbc_iv1[] = {
1947 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1948 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1949 };
1950 
1951 static const uint8_t ms_aes_cbc_cipher1[] = {
1952 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1953 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1954 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1955 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1956 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1957 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1958 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1959 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1960 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1961 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1962 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1963 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1964 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1965 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1966 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1967 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1968 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1969 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1970 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1971 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1972 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1973 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1974 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1975 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1976 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1977 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1978 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1979 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1980 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1981 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1982 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1983 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1984 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1985 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1986 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1987 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1988 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1989 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1990 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1991 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1992 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1993 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1994 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1995 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1996 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1997 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1998 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1999 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
2000 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
2001 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
2002 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
2003 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
2004 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
2005 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
2006 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
2007 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
2008 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2009 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2010 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2011 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2012 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2013 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2014 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2015 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2016 
2017 };
2018 
2019 static uint8_t ms_hmac_key1[] = {
2020 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2021 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2022 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2023 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2024 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2025 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2026 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2027 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2028 };
2029 
2030 static const uint8_t ms_hmac_digest1[] = {
2031 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2032 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2033 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2034 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2035 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2036 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2037 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2038 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2039 };
2040 /* End Session 1  */
2041 /* Begin Session 2 */
2042 static  uint8_t ms_aes_cbc_key2[] = {
2043 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2044 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2045 };
2046 
2047 static  uint8_t ms_aes_cbc_iv2[] = {
2048 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2049 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2050 };
2051 
2052 static const uint8_t ms_aes_cbc_cipher2[] = {
2053 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2054 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2055 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2056 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2057 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2058 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2059 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2060 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2061 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2062 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2063 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2064 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2065 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2066 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2067 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2068 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2069 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2070 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2071 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2072 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2073 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2074 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2075 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2076 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2077 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2078 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2079 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2080 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2081 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2082 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2083 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2084 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2085 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2086 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2087 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2088 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2089 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2090 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2091 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2092 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2093 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2094 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2095 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2096 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2097 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2098 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2099 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2100 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2101 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2102 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2103 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2104 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2105 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2106 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2107 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2108 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2109 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2110 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2111 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2112 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2113 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2114 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2115 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2116 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2117 };
2118 
2119 static  uint8_t ms_hmac_key2[] = {
2120 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2121 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2122 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2123 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2124 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2125 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2126 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2127 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2128 };
2129 
2130 static const uint8_t ms_hmac_digest2[] = {
2131 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2132 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2133 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2134 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2135 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2136 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2137 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2138 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2139 };
2140 
2141 /* End Session 2 */
2142 
2143 
2144 static int
2145 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2146 {
2147 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2148 	struct crypto_unittest_params *ut_params = &unittest_params;
2149 	int status;
2150 
2151 	/* Verify the capabilities */
2152 	struct rte_cryptodev_sym_capability_idx cap_idx;
2153 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2154 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2155 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2156 			&cap_idx) == NULL)
2157 		return TEST_SKIPPED;
2158 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2159 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2160 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2161 			&cap_idx) == NULL)
2162 		return TEST_SKIPPED;
2163 
2164 	/* Generate test mbuf data and space for digest */
2165 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2166 			catch_22_quote,	QUOTE_512_BYTES, 0);
2167 
2168 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2169 			DIGEST_BYTE_LENGTH_SHA1);
2170 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2171 
2172 	/* Setup Cipher Parameters */
2173 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2174 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2175 
2176 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2177 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2178 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2179 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2180 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2181 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2182 
2183 	/* Setup HMAC Parameters */
2184 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2185 
2186 	ut_params->auth_xform.next = NULL;
2187 
2188 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2189 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2190 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2191 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2192 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2193 
2194 	ut_params->sess = rte_cryptodev_sym_session_create(
2195 			ts_params->session_mpool);
2196 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2197 
2198 	/* Create crypto session*/
2199 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2200 			ut_params->sess, &ut_params->cipher_xform,
2201 			ts_params->session_priv_mpool);
2202 
2203 	if (status == -ENOTSUP)
2204 		return TEST_SKIPPED;
2205 
2206 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
2207 
2208 	/* Generate crypto op data structure */
2209 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2210 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2211 	TEST_ASSERT_NOT_NULL(ut_params->op,
2212 			"Failed to allocate symmetric crypto operation struct");
2213 
2214 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2215 
2216 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2217 
2218 	/* set crypto operation source mbuf */
2219 	sym_op->m_src = ut_params->ibuf;
2220 
2221 	/* Set crypto operation authentication parameters */
2222 	sym_op->auth.digest.data = ut_params->digest;
2223 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2224 			ut_params->ibuf, QUOTE_512_BYTES);
2225 
2226 	sym_op->auth.data.offset = 0;
2227 	sym_op->auth.data.length = QUOTE_512_BYTES;
2228 
2229 	/* Copy IV at the end of the crypto operation */
2230 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2231 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2232 
2233 	/* Set crypto operation cipher parameters */
2234 	sym_op->cipher.data.offset = 0;
2235 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2236 
2237 	/* Process crypto operation */
2238 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2239 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2240 			ut_params->op);
2241 	else
2242 		TEST_ASSERT_NOT_NULL(
2243 			process_crypto_request(ts_params->valid_devs[0],
2244 				ut_params->op),
2245 				"failed to process sym crypto op");
2246 
2247 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2248 			"crypto op processing failed");
2249 
2250 	/* Validate obuf */
2251 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2252 			uint8_t *);
2253 
2254 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2255 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2256 			QUOTE_512_BYTES,
2257 			"ciphertext data not as expected");
2258 
2259 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2260 
2261 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2262 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2263 			gbl_driver_id == rte_cryptodev_driver_id_get(
2264 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2265 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2266 					DIGEST_BYTE_LENGTH_SHA1,
2267 			"Generated digest data not as expected");
2268 
2269 	return TEST_SUCCESS;
2270 }
2271 
2272 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2273 
2274 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2275 
2276 static uint8_t hmac_sha512_key[] = {
2277 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2278 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2279 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2280 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2281 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2282 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2283 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2284 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2285 
2286 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2287 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2288 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2289 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2290 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2291 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2292 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2293 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2294 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2295 
2296 
2297 
2298 static int
2299 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2300 		struct crypto_unittest_params *ut_params,
2301 		uint8_t *cipher_key,
2302 		uint8_t *hmac_key);
2303 
2304 static int
2305 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2306 		struct crypto_unittest_params *ut_params,
2307 		struct crypto_testsuite_params *ts_params,
2308 		const uint8_t *cipher,
2309 		const uint8_t *digest,
2310 		const uint8_t *iv);
2311 
2312 
2313 static int
2314 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2315 		struct crypto_unittest_params *ut_params,
2316 		uint8_t *cipher_key,
2317 		uint8_t *hmac_key)
2318 {
2319 
2320 	/* Setup Cipher Parameters */
2321 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2322 	ut_params->cipher_xform.next = NULL;
2323 
2324 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2325 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2326 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2327 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2328 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2329 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2330 
2331 	/* Setup HMAC Parameters */
2332 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2333 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2334 
2335 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2336 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2337 	ut_params->auth_xform.auth.key.data = hmac_key;
2338 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2339 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2340 
2341 	return TEST_SUCCESS;
2342 }
2343 
2344 
2345 static int
2346 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2347 		struct crypto_unittest_params *ut_params,
2348 		struct crypto_testsuite_params *ts_params,
2349 		const uint8_t *cipher,
2350 		const uint8_t *digest,
2351 		const uint8_t *iv)
2352 {
2353 	/* Generate test mbuf data and digest */
2354 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2355 			(const char *)
2356 			cipher,
2357 			QUOTE_512_BYTES, 0);
2358 
2359 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2360 			DIGEST_BYTE_LENGTH_SHA512);
2361 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2362 
2363 	rte_memcpy(ut_params->digest,
2364 			digest,
2365 			DIGEST_BYTE_LENGTH_SHA512);
2366 
2367 	/* Generate Crypto op data structure */
2368 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2369 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2370 	TEST_ASSERT_NOT_NULL(ut_params->op,
2371 			"Failed to allocate symmetric crypto operation struct");
2372 
2373 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2374 
2375 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2376 
2377 	/* set crypto operation source mbuf */
2378 	sym_op->m_src = ut_params->ibuf;
2379 
2380 	sym_op->auth.digest.data = ut_params->digest;
2381 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2382 			ut_params->ibuf, QUOTE_512_BYTES);
2383 
2384 	sym_op->auth.data.offset = 0;
2385 	sym_op->auth.data.length = QUOTE_512_BYTES;
2386 
2387 	/* Copy IV at the end of the crypto operation */
2388 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2389 			iv, CIPHER_IV_LENGTH_AES_CBC);
2390 
2391 	sym_op->cipher.data.offset = 0;
2392 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2393 
2394 	/* Process crypto operation */
2395 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2396 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2397 			ut_params->op);
2398 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2399 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2400 				ut_params->op, 1, 1, 0, 0);
2401 	else
2402 		TEST_ASSERT_NOT_NULL(
2403 				process_crypto_request(ts_params->valid_devs[0],
2404 					ut_params->op),
2405 					"failed to process sym crypto op");
2406 
2407 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2408 			"crypto op processing failed");
2409 
2410 	ut_params->obuf = ut_params->op->sym->m_src;
2411 
2412 	/* Validate obuf */
2413 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2414 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2415 			catch_22_quote,
2416 			QUOTE_512_BYTES,
2417 			"Plaintext data not as expected");
2418 
2419 	/* Validate obuf */
2420 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2421 			"Digest verification failed");
2422 
2423 	return TEST_SUCCESS;
2424 }
2425 
2426 /* ***** SNOW 3G Tests ***** */
2427 static int
2428 create_wireless_algo_hash_session(uint8_t dev_id,
2429 	const uint8_t *key, const uint8_t key_len,
2430 	const uint8_t iv_len, const uint8_t auth_len,
2431 	enum rte_crypto_auth_operation op,
2432 	enum rte_crypto_auth_algorithm algo)
2433 {
2434 	uint8_t hash_key[key_len];
2435 	int status;
2436 
2437 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2438 	struct crypto_unittest_params *ut_params = &unittest_params;
2439 
2440 	memcpy(hash_key, key, key_len);
2441 
2442 	debug_hexdump(stdout, "key:", key, key_len);
2443 
2444 	/* Setup Authentication Parameters */
2445 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2446 	ut_params->auth_xform.next = NULL;
2447 
2448 	ut_params->auth_xform.auth.op = op;
2449 	ut_params->auth_xform.auth.algo = algo;
2450 	ut_params->auth_xform.auth.key.length = key_len;
2451 	ut_params->auth_xform.auth.key.data = hash_key;
2452 	ut_params->auth_xform.auth.digest_length = auth_len;
2453 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2454 	ut_params->auth_xform.auth.iv.length = iv_len;
2455 	ut_params->sess = rte_cryptodev_sym_session_create(
2456 			ts_params->session_mpool);
2457 
2458 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2459 			&ut_params->auth_xform,
2460 			ts_params->session_priv_mpool);
2461 	if (status == -ENOTSUP)
2462 		return TEST_SKIPPED;
2463 
2464 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2465 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2466 	return 0;
2467 }
2468 
2469 static int
2470 create_wireless_algo_cipher_session(uint8_t dev_id,
2471 			enum rte_crypto_cipher_operation op,
2472 			enum rte_crypto_cipher_algorithm algo,
2473 			const uint8_t *key, const uint8_t key_len,
2474 			uint8_t iv_len)
2475 {
2476 	uint8_t cipher_key[key_len];
2477 	int status;
2478 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2479 	struct crypto_unittest_params *ut_params = &unittest_params;
2480 
2481 	memcpy(cipher_key, key, key_len);
2482 
2483 	/* Setup Cipher Parameters */
2484 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2485 	ut_params->cipher_xform.next = NULL;
2486 
2487 	ut_params->cipher_xform.cipher.algo = algo;
2488 	ut_params->cipher_xform.cipher.op = op;
2489 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2490 	ut_params->cipher_xform.cipher.key.length = key_len;
2491 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2492 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2493 
2494 	debug_hexdump(stdout, "key:", key, key_len);
2495 
2496 	/* Create Crypto session */
2497 	ut_params->sess = rte_cryptodev_sym_session_create(
2498 			ts_params->session_mpool);
2499 
2500 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2501 			&ut_params->cipher_xform,
2502 			ts_params->session_priv_mpool);
2503 	if (status == -ENOTSUP)
2504 		return TEST_SKIPPED;
2505 
2506 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2507 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2508 	return 0;
2509 }
2510 
2511 static int
2512 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2513 			unsigned int cipher_len,
2514 			unsigned int cipher_offset)
2515 {
2516 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2517 	struct crypto_unittest_params *ut_params = &unittest_params;
2518 
2519 	/* Generate Crypto op data structure */
2520 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2521 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2522 	TEST_ASSERT_NOT_NULL(ut_params->op,
2523 				"Failed to allocate pktmbuf offload");
2524 
2525 	/* Set crypto operation data parameters */
2526 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2527 
2528 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2529 
2530 	/* set crypto operation source mbuf */
2531 	sym_op->m_src = ut_params->ibuf;
2532 
2533 	/* iv */
2534 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2535 			iv, iv_len);
2536 	sym_op->cipher.data.length = cipher_len;
2537 	sym_op->cipher.data.offset = cipher_offset;
2538 	return 0;
2539 }
2540 
2541 static int
2542 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2543 			unsigned int cipher_len,
2544 			unsigned int cipher_offset)
2545 {
2546 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2547 	struct crypto_unittest_params *ut_params = &unittest_params;
2548 
2549 	/* Generate Crypto op data structure */
2550 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2551 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2552 	TEST_ASSERT_NOT_NULL(ut_params->op,
2553 				"Failed to allocate pktmbuf offload");
2554 
2555 	/* Set crypto operation data parameters */
2556 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2557 
2558 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2559 
2560 	/* set crypto operation source mbuf */
2561 	sym_op->m_src = ut_params->ibuf;
2562 	sym_op->m_dst = ut_params->obuf;
2563 
2564 	/* iv */
2565 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2566 			iv, iv_len);
2567 	sym_op->cipher.data.length = cipher_len;
2568 	sym_op->cipher.data.offset = cipher_offset;
2569 	return 0;
2570 }
2571 
2572 static int
2573 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2574 		enum rte_crypto_cipher_operation cipher_op,
2575 		enum rte_crypto_auth_operation auth_op,
2576 		enum rte_crypto_auth_algorithm auth_algo,
2577 		enum rte_crypto_cipher_algorithm cipher_algo,
2578 		const uint8_t *key, uint8_t key_len,
2579 		uint8_t auth_iv_len, uint8_t auth_len,
2580 		uint8_t cipher_iv_len)
2581 
2582 {
2583 	uint8_t cipher_auth_key[key_len];
2584 	int status;
2585 
2586 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2587 	struct crypto_unittest_params *ut_params = &unittest_params;
2588 
2589 	memcpy(cipher_auth_key, key, key_len);
2590 
2591 	/* Setup Authentication Parameters */
2592 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2593 	ut_params->auth_xform.next = NULL;
2594 
2595 	ut_params->auth_xform.auth.op = auth_op;
2596 	ut_params->auth_xform.auth.algo = auth_algo;
2597 	ut_params->auth_xform.auth.key.length = key_len;
2598 	/* Hash key = cipher key */
2599 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2600 	ut_params->auth_xform.auth.digest_length = auth_len;
2601 	/* Auth IV will be after cipher IV */
2602 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2603 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2604 
2605 	/* Setup Cipher Parameters */
2606 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2607 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2608 
2609 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2610 	ut_params->cipher_xform.cipher.op = cipher_op;
2611 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2612 	ut_params->cipher_xform.cipher.key.length = key_len;
2613 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2614 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2615 
2616 	debug_hexdump(stdout, "key:", key, key_len);
2617 
2618 	/* Create Crypto session*/
2619 	ut_params->sess = rte_cryptodev_sym_session_create(
2620 			ts_params->session_mpool);
2621 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2622 
2623 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2624 			&ut_params->cipher_xform,
2625 			ts_params->session_priv_mpool);
2626 	if (status == -ENOTSUP)
2627 		return TEST_SKIPPED;
2628 
2629 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2630 	return 0;
2631 }
2632 
2633 static int
2634 create_wireless_cipher_auth_session(uint8_t dev_id,
2635 		enum rte_crypto_cipher_operation cipher_op,
2636 		enum rte_crypto_auth_operation auth_op,
2637 		enum rte_crypto_auth_algorithm auth_algo,
2638 		enum rte_crypto_cipher_algorithm cipher_algo,
2639 		const struct wireless_test_data *tdata)
2640 {
2641 	const uint8_t key_len = tdata->key.len;
2642 	uint8_t cipher_auth_key[key_len];
2643 	int status;
2644 
2645 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2646 	struct crypto_unittest_params *ut_params = &unittest_params;
2647 	const uint8_t *key = tdata->key.data;
2648 	const uint8_t auth_len = tdata->digest.len;
2649 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2650 	uint8_t auth_iv_len = tdata->auth_iv.len;
2651 
2652 	memcpy(cipher_auth_key, key, key_len);
2653 
2654 	/* Setup Authentication Parameters */
2655 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2656 	ut_params->auth_xform.next = NULL;
2657 
2658 	ut_params->auth_xform.auth.op = auth_op;
2659 	ut_params->auth_xform.auth.algo = auth_algo;
2660 	ut_params->auth_xform.auth.key.length = key_len;
2661 	/* Hash key = cipher key */
2662 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2663 	ut_params->auth_xform.auth.digest_length = auth_len;
2664 	/* Auth IV will be after cipher IV */
2665 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2666 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2667 
2668 	/* Setup Cipher Parameters */
2669 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2670 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2671 
2672 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2673 	ut_params->cipher_xform.cipher.op = cipher_op;
2674 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2675 	ut_params->cipher_xform.cipher.key.length = key_len;
2676 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2677 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2678 
2679 
2680 	debug_hexdump(stdout, "key:", key, key_len);
2681 
2682 	/* Create Crypto session*/
2683 	ut_params->sess = rte_cryptodev_sym_session_create(
2684 			ts_params->session_mpool);
2685 
2686 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2687 			&ut_params->cipher_xform,
2688 			ts_params->session_priv_mpool);
2689 	if (status == -ENOTSUP)
2690 		return TEST_SKIPPED;
2691 
2692 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2693 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2694 	return 0;
2695 }
2696 
2697 static int
2698 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2699 		const struct wireless_test_data *tdata)
2700 {
2701 	return create_wireless_cipher_auth_session(dev_id,
2702 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2703 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2704 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2705 }
2706 
2707 static int
2708 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2709 		enum rte_crypto_cipher_operation cipher_op,
2710 		enum rte_crypto_auth_operation auth_op,
2711 		enum rte_crypto_auth_algorithm auth_algo,
2712 		enum rte_crypto_cipher_algorithm cipher_algo,
2713 		const uint8_t *key, const uint8_t key_len,
2714 		uint8_t auth_iv_len, uint8_t auth_len,
2715 		uint8_t cipher_iv_len)
2716 {
2717 	uint8_t auth_cipher_key[key_len];
2718 	int status;
2719 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2720 	struct crypto_unittest_params *ut_params = &unittest_params;
2721 
2722 	memcpy(auth_cipher_key, key, key_len);
2723 
2724 	/* Setup Authentication Parameters */
2725 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2726 	ut_params->auth_xform.auth.op = auth_op;
2727 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2728 	ut_params->auth_xform.auth.algo = auth_algo;
2729 	ut_params->auth_xform.auth.key.length = key_len;
2730 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2731 	ut_params->auth_xform.auth.digest_length = auth_len;
2732 	/* Auth IV will be after cipher IV */
2733 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2734 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2735 
2736 	/* Setup Cipher Parameters */
2737 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2738 	ut_params->cipher_xform.next = NULL;
2739 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2740 	ut_params->cipher_xform.cipher.op = cipher_op;
2741 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2742 	ut_params->cipher_xform.cipher.key.length = key_len;
2743 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2744 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2745 
2746 	debug_hexdump(stdout, "key:", key, key_len);
2747 
2748 	/* Create Crypto session*/
2749 	ut_params->sess = rte_cryptodev_sym_session_create(
2750 			ts_params->session_mpool);
2751 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2752 
2753 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2754 		ut_params->auth_xform.next = NULL;
2755 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2756 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2757 				&ut_params->cipher_xform,
2758 				ts_params->session_priv_mpool);
2759 
2760 	} else
2761 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2762 				&ut_params->auth_xform,
2763 				ts_params->session_priv_mpool);
2764 
2765 	if (status == -ENOTSUP)
2766 		return TEST_SKIPPED;
2767 
2768 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2769 
2770 	return 0;
2771 }
2772 
2773 static int
2774 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2775 		unsigned int auth_tag_len,
2776 		const uint8_t *iv, unsigned int iv_len,
2777 		unsigned int data_pad_len,
2778 		enum rte_crypto_auth_operation op,
2779 		unsigned int auth_len, unsigned int auth_offset)
2780 {
2781 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2782 
2783 	struct crypto_unittest_params *ut_params = &unittest_params;
2784 
2785 	/* Generate Crypto op data structure */
2786 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2787 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2788 	TEST_ASSERT_NOT_NULL(ut_params->op,
2789 		"Failed to allocate pktmbuf offload");
2790 
2791 	/* Set crypto operation data parameters */
2792 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2793 
2794 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2795 
2796 	/* set crypto operation source mbuf */
2797 	sym_op->m_src = ut_params->ibuf;
2798 
2799 	/* iv */
2800 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2801 			iv, iv_len);
2802 	/* digest */
2803 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2804 					ut_params->ibuf, auth_tag_len);
2805 
2806 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2807 				"no room to append auth tag");
2808 	ut_params->digest = sym_op->auth.digest.data;
2809 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2810 			ut_params->ibuf, data_pad_len);
2811 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2812 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2813 	else
2814 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2815 
2816 	debug_hexdump(stdout, "digest:",
2817 		sym_op->auth.digest.data,
2818 		auth_tag_len);
2819 
2820 	sym_op->auth.data.length = auth_len;
2821 	sym_op->auth.data.offset = auth_offset;
2822 
2823 	return 0;
2824 }
2825 
2826 static int
2827 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2828 	enum rte_crypto_auth_operation op)
2829 {
2830 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2831 	struct crypto_unittest_params *ut_params = &unittest_params;
2832 
2833 	const uint8_t *auth_tag = tdata->digest.data;
2834 	const unsigned int auth_tag_len = tdata->digest.len;
2835 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2836 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2837 
2838 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2839 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2840 	const uint8_t *auth_iv = tdata->auth_iv.data;
2841 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2842 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2843 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2844 
2845 	/* Generate Crypto op data structure */
2846 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2847 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2848 	TEST_ASSERT_NOT_NULL(ut_params->op,
2849 			"Failed to allocate pktmbuf offload");
2850 	/* Set crypto operation data parameters */
2851 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2852 
2853 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2854 
2855 	/* set crypto operation source mbuf */
2856 	sym_op->m_src = ut_params->ibuf;
2857 
2858 	/* digest */
2859 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2860 			ut_params->ibuf, auth_tag_len);
2861 
2862 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2863 			"no room to append auth tag");
2864 	ut_params->digest = sym_op->auth.digest.data;
2865 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2866 			ut_params->ibuf, data_pad_len);
2867 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2868 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2869 	else
2870 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2871 
2872 	debug_hexdump(stdout, "digest:",
2873 		sym_op->auth.digest.data,
2874 		auth_tag_len);
2875 
2876 	/* Copy cipher and auth IVs at the end of the crypto operation */
2877 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2878 						IV_OFFSET);
2879 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2880 	iv_ptr += cipher_iv_len;
2881 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2882 
2883 	sym_op->cipher.data.length = cipher_len;
2884 	sym_op->cipher.data.offset = 0;
2885 	sym_op->auth.data.length = auth_len;
2886 	sym_op->auth.data.offset = 0;
2887 
2888 	return 0;
2889 }
2890 
2891 static int
2892 create_zuc_cipher_hash_generate_operation(
2893 		const struct wireless_test_data *tdata)
2894 {
2895 	return create_wireless_cipher_hash_operation(tdata,
2896 		RTE_CRYPTO_AUTH_OP_GENERATE);
2897 }
2898 
2899 static int
2900 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2901 		const unsigned auth_tag_len,
2902 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2903 		unsigned data_pad_len,
2904 		enum rte_crypto_auth_operation op,
2905 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2906 		const unsigned cipher_len, const unsigned cipher_offset,
2907 		const unsigned auth_len, const unsigned auth_offset)
2908 {
2909 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2910 	struct crypto_unittest_params *ut_params = &unittest_params;
2911 
2912 	enum rte_crypto_cipher_algorithm cipher_algo =
2913 			ut_params->cipher_xform.cipher.algo;
2914 	enum rte_crypto_auth_algorithm auth_algo =
2915 			ut_params->auth_xform.auth.algo;
2916 
2917 	/* Generate Crypto op data structure */
2918 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2919 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2920 	TEST_ASSERT_NOT_NULL(ut_params->op,
2921 			"Failed to allocate pktmbuf offload");
2922 	/* Set crypto operation data parameters */
2923 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2924 
2925 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2926 
2927 	/* set crypto operation source mbuf */
2928 	sym_op->m_src = ut_params->ibuf;
2929 
2930 	/* digest */
2931 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2932 			ut_params->ibuf, auth_tag_len);
2933 
2934 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2935 			"no room to append auth tag");
2936 	ut_params->digest = sym_op->auth.digest.data;
2937 
2938 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2939 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2940 				ut_params->ibuf, data_pad_len);
2941 	} else {
2942 		struct rte_mbuf *m = ut_params->ibuf;
2943 		unsigned int offset = data_pad_len;
2944 
2945 		while (offset > m->data_len && m->next != NULL) {
2946 			offset -= m->data_len;
2947 			m = m->next;
2948 		}
2949 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2950 			m, offset);
2951 	}
2952 
2953 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2954 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2955 	else
2956 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2957 
2958 	debug_hexdump(stdout, "digest:",
2959 		sym_op->auth.digest.data,
2960 		auth_tag_len);
2961 
2962 	/* Copy cipher and auth IVs at the end of the crypto operation */
2963 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2964 						IV_OFFSET);
2965 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2966 	iv_ptr += cipher_iv_len;
2967 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2968 
2969 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2970 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2971 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2972 		sym_op->cipher.data.length = cipher_len;
2973 		sym_op->cipher.data.offset = cipher_offset;
2974 	} else {
2975 		sym_op->cipher.data.length = cipher_len >> 3;
2976 		sym_op->cipher.data.offset = cipher_offset >> 3;
2977 	}
2978 
2979 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2980 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2981 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2982 		sym_op->auth.data.length = auth_len;
2983 		sym_op->auth.data.offset = auth_offset;
2984 	} else {
2985 		sym_op->auth.data.length = auth_len >> 3;
2986 		sym_op->auth.data.offset = auth_offset >> 3;
2987 	}
2988 
2989 	return 0;
2990 }
2991 
2992 static int
2993 create_wireless_algo_auth_cipher_operation(
2994 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2995 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2996 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2997 		unsigned int data_pad_len,
2998 		unsigned int cipher_len, unsigned int cipher_offset,
2999 		unsigned int auth_len, unsigned int auth_offset,
3000 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
3001 {
3002 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3003 	struct crypto_unittest_params *ut_params = &unittest_params;
3004 
3005 	enum rte_crypto_cipher_algorithm cipher_algo =
3006 			ut_params->cipher_xform.cipher.algo;
3007 	enum rte_crypto_auth_algorithm auth_algo =
3008 			ut_params->auth_xform.auth.algo;
3009 
3010 	/* Generate Crypto op data structure */
3011 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3012 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3013 	TEST_ASSERT_NOT_NULL(ut_params->op,
3014 			"Failed to allocate pktmbuf offload");
3015 
3016 	/* Set crypto operation data parameters */
3017 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3018 
3019 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3020 
3021 	/* set crypto operation mbufs */
3022 	sym_op->m_src = ut_params->ibuf;
3023 	if (op_mode == OUT_OF_PLACE)
3024 		sym_op->m_dst = ut_params->obuf;
3025 
3026 	/* digest */
3027 	if (!do_sgl) {
3028 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
3029 			(op_mode == IN_PLACE ?
3030 				ut_params->ibuf : ut_params->obuf),
3031 			uint8_t *, data_pad_len);
3032 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3033 			(op_mode == IN_PLACE ?
3034 				ut_params->ibuf : ut_params->obuf),
3035 			data_pad_len);
3036 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3037 	} else {
3038 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3039 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3040 				sym_op->m_src : sym_op->m_dst);
3041 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3042 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3043 			sgl_buf = sgl_buf->next;
3044 		}
3045 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3046 				uint8_t *, remaining_off);
3047 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3048 				remaining_off);
3049 		memset(sym_op->auth.digest.data, 0, remaining_off);
3050 		while (sgl_buf->next != NULL) {
3051 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3052 				0, rte_pktmbuf_data_len(sgl_buf));
3053 			sgl_buf = sgl_buf->next;
3054 		}
3055 	}
3056 
3057 	/* Copy digest for the verification */
3058 	if (verify)
3059 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3060 
3061 	/* Copy cipher and auth IVs at the end of the crypto operation */
3062 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3063 			ut_params->op, uint8_t *, IV_OFFSET);
3064 
3065 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3066 	iv_ptr += cipher_iv_len;
3067 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3068 
3069 	/* Only copy over the offset data needed from src to dst in OOP,
3070 	 * if the auth and cipher offsets are not aligned
3071 	 */
3072 	if (op_mode == OUT_OF_PLACE) {
3073 		if (cipher_offset > auth_offset)
3074 			rte_memcpy(
3075 				rte_pktmbuf_mtod_offset(
3076 					sym_op->m_dst,
3077 					uint8_t *, auth_offset >> 3),
3078 				rte_pktmbuf_mtod_offset(
3079 					sym_op->m_src,
3080 					uint8_t *, auth_offset >> 3),
3081 				((cipher_offset >> 3) - (auth_offset >> 3)));
3082 	}
3083 
3084 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3085 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3086 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3087 		sym_op->cipher.data.length = cipher_len;
3088 		sym_op->cipher.data.offset = cipher_offset;
3089 	} else {
3090 		sym_op->cipher.data.length = cipher_len >> 3;
3091 		sym_op->cipher.data.offset = cipher_offset >> 3;
3092 	}
3093 
3094 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3095 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3096 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3097 		sym_op->auth.data.length = auth_len;
3098 		sym_op->auth.data.offset = auth_offset;
3099 	} else {
3100 		sym_op->auth.data.length = auth_len >> 3;
3101 		sym_op->auth.data.offset = auth_offset >> 3;
3102 	}
3103 
3104 	return 0;
3105 }
3106 
3107 static int
3108 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3109 {
3110 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3111 	struct crypto_unittest_params *ut_params = &unittest_params;
3112 
3113 	int retval;
3114 	unsigned plaintext_pad_len;
3115 	unsigned plaintext_len;
3116 	uint8_t *plaintext;
3117 	struct rte_cryptodev_info dev_info;
3118 
3119 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3120 	uint64_t feat_flags = dev_info.feature_flags;
3121 
3122 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3123 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3124 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3125 		return TEST_SKIPPED;
3126 	}
3127 
3128 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3129 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3130 		printf("Device doesn't support RAW data-path APIs.\n");
3131 		return TEST_SKIPPED;
3132 	}
3133 
3134 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3135 		return TEST_SKIPPED;
3136 
3137 	/* Verify the capabilities */
3138 	struct rte_cryptodev_sym_capability_idx cap_idx;
3139 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3140 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3141 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3142 			&cap_idx) == NULL)
3143 		return TEST_SKIPPED;
3144 
3145 	/* Create SNOW 3G session */
3146 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3147 			tdata->key.data, tdata->key.len,
3148 			tdata->auth_iv.len, tdata->digest.len,
3149 			RTE_CRYPTO_AUTH_OP_GENERATE,
3150 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3151 	if (retval < 0)
3152 		return retval;
3153 
3154 	/* alloc mbuf and set payload */
3155 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3156 
3157 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3158 	rte_pktmbuf_tailroom(ut_params->ibuf));
3159 
3160 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3161 	/* Append data which is padded to a multiple of */
3162 	/* the algorithms block size */
3163 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3164 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3165 				plaintext_pad_len);
3166 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3167 
3168 	/* Create SNOW 3G operation */
3169 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3170 			tdata->auth_iv.data, tdata->auth_iv.len,
3171 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3172 			tdata->validAuthLenInBits.len,
3173 			0);
3174 	if (retval < 0)
3175 		return retval;
3176 
3177 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3178 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3179 				ut_params->op, 0, 1, 1, 0);
3180 	else
3181 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3182 				ut_params->op);
3183 	ut_params->obuf = ut_params->op->sym->m_src;
3184 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3185 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3186 			+ plaintext_pad_len;
3187 
3188 	/* Validate obuf */
3189 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3190 	ut_params->digest,
3191 	tdata->digest.data,
3192 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3193 	"SNOW 3G Generated auth tag not as expected");
3194 
3195 	return 0;
3196 }
3197 
3198 static int
3199 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3200 {
3201 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3202 	struct crypto_unittest_params *ut_params = &unittest_params;
3203 
3204 	int retval;
3205 	unsigned plaintext_pad_len;
3206 	unsigned plaintext_len;
3207 	uint8_t *plaintext;
3208 	struct rte_cryptodev_info dev_info;
3209 
3210 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3211 	uint64_t feat_flags = dev_info.feature_flags;
3212 
3213 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3214 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3215 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3216 		return TEST_SKIPPED;
3217 	}
3218 
3219 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3220 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3221 		printf("Device doesn't support RAW data-path APIs.\n");
3222 		return TEST_SKIPPED;
3223 	}
3224 
3225 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3226 		return TEST_SKIPPED;
3227 
3228 	/* Verify the capabilities */
3229 	struct rte_cryptodev_sym_capability_idx cap_idx;
3230 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3231 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3232 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3233 			&cap_idx) == NULL)
3234 		return TEST_SKIPPED;
3235 
3236 	/* Create SNOW 3G session */
3237 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3238 				tdata->key.data, tdata->key.len,
3239 				tdata->auth_iv.len, tdata->digest.len,
3240 				RTE_CRYPTO_AUTH_OP_VERIFY,
3241 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3242 	if (retval < 0)
3243 		return retval;
3244 	/* alloc mbuf and set payload */
3245 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3246 
3247 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3248 	rte_pktmbuf_tailroom(ut_params->ibuf));
3249 
3250 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3251 	/* Append data which is padded to a multiple of */
3252 	/* the algorithms block size */
3253 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3254 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3255 				plaintext_pad_len);
3256 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3257 
3258 	/* Create SNOW 3G operation */
3259 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3260 			tdata->digest.len,
3261 			tdata->auth_iv.data, tdata->auth_iv.len,
3262 			plaintext_pad_len,
3263 			RTE_CRYPTO_AUTH_OP_VERIFY,
3264 			tdata->validAuthLenInBits.len,
3265 			0);
3266 	if (retval < 0)
3267 		return retval;
3268 
3269 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3270 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3271 				ut_params->op, 0, 1, 1, 0);
3272 	else
3273 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3274 				ut_params->op);
3275 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3276 	ut_params->obuf = ut_params->op->sym->m_src;
3277 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3278 				+ plaintext_pad_len;
3279 
3280 	/* Validate obuf */
3281 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3282 		return 0;
3283 	else
3284 		return -1;
3285 
3286 	return 0;
3287 }
3288 
3289 static int
3290 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3291 {
3292 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3293 	struct crypto_unittest_params *ut_params = &unittest_params;
3294 
3295 	int retval;
3296 	unsigned plaintext_pad_len;
3297 	unsigned plaintext_len;
3298 	uint8_t *plaintext;
3299 	struct rte_cryptodev_info dev_info;
3300 
3301 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3302 	uint64_t feat_flags = dev_info.feature_flags;
3303 
3304 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3305 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3306 		printf("Device doesn't support RAW data-path APIs.\n");
3307 		return TEST_SKIPPED;
3308 	}
3309 
3310 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3311 		return TEST_SKIPPED;
3312 
3313 	/* Verify the capabilities */
3314 	struct rte_cryptodev_sym_capability_idx cap_idx;
3315 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3316 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3317 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3318 			&cap_idx) == NULL)
3319 		return TEST_SKIPPED;
3320 
3321 	/* Create KASUMI session */
3322 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3323 			tdata->key.data, tdata->key.len,
3324 			0, tdata->digest.len,
3325 			RTE_CRYPTO_AUTH_OP_GENERATE,
3326 			RTE_CRYPTO_AUTH_KASUMI_F9);
3327 	if (retval < 0)
3328 		return retval;
3329 
3330 	/* alloc mbuf and set payload */
3331 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3332 
3333 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3334 	rte_pktmbuf_tailroom(ut_params->ibuf));
3335 
3336 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3337 	/* Append data which is padded to a multiple of */
3338 	/* the algorithms block size */
3339 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3340 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3341 				plaintext_pad_len);
3342 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3343 
3344 	/* Create KASUMI operation */
3345 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3346 			NULL, 0,
3347 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3348 			tdata->plaintext.len,
3349 			0);
3350 	if (retval < 0)
3351 		return retval;
3352 
3353 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3354 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3355 			ut_params->op);
3356 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3357 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3358 				ut_params->op, 0, 1, 1, 0);
3359 	else
3360 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3361 			ut_params->op);
3362 
3363 	ut_params->obuf = ut_params->op->sym->m_src;
3364 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3365 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3366 			+ plaintext_pad_len;
3367 
3368 	/* Validate obuf */
3369 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3370 	ut_params->digest,
3371 	tdata->digest.data,
3372 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3373 	"KASUMI Generated auth tag not as expected");
3374 
3375 	return 0;
3376 }
3377 
3378 static int
3379 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3380 {
3381 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3382 	struct crypto_unittest_params *ut_params = &unittest_params;
3383 
3384 	int retval;
3385 	unsigned plaintext_pad_len;
3386 	unsigned plaintext_len;
3387 	uint8_t *plaintext;
3388 	struct rte_cryptodev_info dev_info;
3389 
3390 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3391 	uint64_t feat_flags = dev_info.feature_flags;
3392 
3393 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3394 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3395 		printf("Device doesn't support RAW data-path APIs.\n");
3396 		return TEST_SKIPPED;
3397 	}
3398 
3399 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3400 		return TEST_SKIPPED;
3401 
3402 	/* Verify the capabilities */
3403 	struct rte_cryptodev_sym_capability_idx cap_idx;
3404 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3405 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3406 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3407 			&cap_idx) == NULL)
3408 		return TEST_SKIPPED;
3409 
3410 	/* Create KASUMI session */
3411 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3412 				tdata->key.data, tdata->key.len,
3413 				0, tdata->digest.len,
3414 				RTE_CRYPTO_AUTH_OP_VERIFY,
3415 				RTE_CRYPTO_AUTH_KASUMI_F9);
3416 	if (retval < 0)
3417 		return retval;
3418 	/* alloc mbuf and set payload */
3419 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3420 
3421 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3422 	rte_pktmbuf_tailroom(ut_params->ibuf));
3423 
3424 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3425 	/* Append data which is padded to a multiple */
3426 	/* of the algorithms block size */
3427 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3428 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3429 				plaintext_pad_len);
3430 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3431 
3432 	/* Create KASUMI operation */
3433 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3434 			tdata->digest.len,
3435 			NULL, 0,
3436 			plaintext_pad_len,
3437 			RTE_CRYPTO_AUTH_OP_VERIFY,
3438 			tdata->plaintext.len,
3439 			0);
3440 	if (retval < 0)
3441 		return retval;
3442 
3443 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3444 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3445 				ut_params->op, 0, 1, 1, 0);
3446 	else
3447 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3448 				ut_params->op);
3449 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3450 	ut_params->obuf = ut_params->op->sym->m_src;
3451 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3452 				+ plaintext_pad_len;
3453 
3454 	/* Validate obuf */
3455 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3456 		return 0;
3457 	else
3458 		return -1;
3459 
3460 	return 0;
3461 }
3462 
3463 static int
3464 test_snow3g_hash_generate_test_case_1(void)
3465 {
3466 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3467 }
3468 
3469 static int
3470 test_snow3g_hash_generate_test_case_2(void)
3471 {
3472 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3473 }
3474 
3475 static int
3476 test_snow3g_hash_generate_test_case_3(void)
3477 {
3478 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3479 }
3480 
3481 static int
3482 test_snow3g_hash_generate_test_case_4(void)
3483 {
3484 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3485 }
3486 
3487 static int
3488 test_snow3g_hash_generate_test_case_5(void)
3489 {
3490 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3491 }
3492 
3493 static int
3494 test_snow3g_hash_generate_test_case_6(void)
3495 {
3496 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3497 }
3498 
3499 static int
3500 test_snow3g_hash_verify_test_case_1(void)
3501 {
3502 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3503 
3504 }
3505 
3506 static int
3507 test_snow3g_hash_verify_test_case_2(void)
3508 {
3509 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3510 }
3511 
3512 static int
3513 test_snow3g_hash_verify_test_case_3(void)
3514 {
3515 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3516 }
3517 
3518 static int
3519 test_snow3g_hash_verify_test_case_4(void)
3520 {
3521 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3522 }
3523 
3524 static int
3525 test_snow3g_hash_verify_test_case_5(void)
3526 {
3527 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3528 }
3529 
3530 static int
3531 test_snow3g_hash_verify_test_case_6(void)
3532 {
3533 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3534 }
3535 
3536 static int
3537 test_kasumi_hash_generate_test_case_1(void)
3538 {
3539 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3540 }
3541 
3542 static int
3543 test_kasumi_hash_generate_test_case_2(void)
3544 {
3545 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3546 }
3547 
3548 static int
3549 test_kasumi_hash_generate_test_case_3(void)
3550 {
3551 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3552 }
3553 
3554 static int
3555 test_kasumi_hash_generate_test_case_4(void)
3556 {
3557 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3558 }
3559 
3560 static int
3561 test_kasumi_hash_generate_test_case_5(void)
3562 {
3563 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3564 }
3565 
3566 static int
3567 test_kasumi_hash_generate_test_case_6(void)
3568 {
3569 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3570 }
3571 
3572 static int
3573 test_kasumi_hash_verify_test_case_1(void)
3574 {
3575 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3576 }
3577 
3578 static int
3579 test_kasumi_hash_verify_test_case_2(void)
3580 {
3581 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3582 }
3583 
3584 static int
3585 test_kasumi_hash_verify_test_case_3(void)
3586 {
3587 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3588 }
3589 
3590 static int
3591 test_kasumi_hash_verify_test_case_4(void)
3592 {
3593 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3594 }
3595 
3596 static int
3597 test_kasumi_hash_verify_test_case_5(void)
3598 {
3599 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3600 }
3601 
3602 static int
3603 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3604 {
3605 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3606 	struct crypto_unittest_params *ut_params = &unittest_params;
3607 
3608 	int retval;
3609 	uint8_t *plaintext, *ciphertext;
3610 	unsigned plaintext_pad_len;
3611 	unsigned plaintext_len;
3612 	struct rte_cryptodev_info dev_info;
3613 
3614 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3615 	uint64_t feat_flags = dev_info.feature_flags;
3616 
3617 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3618 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3619 		printf("Device doesn't support RAW data-path APIs.\n");
3620 		return TEST_SKIPPED;
3621 	}
3622 
3623 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3624 		return TEST_SKIPPED;
3625 
3626 	/* Verify the capabilities */
3627 	struct rte_cryptodev_sym_capability_idx cap_idx;
3628 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3629 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3630 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3631 			&cap_idx) == NULL)
3632 		return TEST_SKIPPED;
3633 
3634 	/* Create KASUMI session */
3635 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3636 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3637 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3638 					tdata->key.data, tdata->key.len,
3639 					tdata->cipher_iv.len);
3640 	if (retval < 0)
3641 		return retval;
3642 
3643 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3644 
3645 	/* Clear mbuf payload */
3646 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3647 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3648 
3649 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3650 	/* Append data which is padded to a multiple */
3651 	/* of the algorithms block size */
3652 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3653 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3654 				plaintext_pad_len);
3655 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3656 
3657 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3658 
3659 	/* Create KASUMI operation */
3660 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3661 				tdata->cipher_iv.len,
3662 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3663 				tdata->validCipherOffsetInBits.len);
3664 	if (retval < 0)
3665 		return retval;
3666 
3667 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3668 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3669 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3670 	else
3671 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3672 				ut_params->op);
3673 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3674 
3675 	ut_params->obuf = ut_params->op->sym->m_dst;
3676 	if (ut_params->obuf)
3677 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3678 	else
3679 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3680 
3681 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3682 
3683 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3684 				(tdata->validCipherOffsetInBits.len >> 3);
3685 	/* Validate obuf */
3686 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3687 		ciphertext,
3688 		reference_ciphertext,
3689 		tdata->validCipherLenInBits.len,
3690 		"KASUMI Ciphertext data not as expected");
3691 	return 0;
3692 }
3693 
3694 static int
3695 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3696 {
3697 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3698 	struct crypto_unittest_params *ut_params = &unittest_params;
3699 
3700 	int retval;
3701 
3702 	unsigned int plaintext_pad_len;
3703 	unsigned int plaintext_len;
3704 
3705 	uint8_t buffer[10000];
3706 	const uint8_t *ciphertext;
3707 
3708 	struct rte_cryptodev_info dev_info;
3709 
3710 	/* Verify the capabilities */
3711 	struct rte_cryptodev_sym_capability_idx cap_idx;
3712 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3713 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3714 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3715 			&cap_idx) == NULL)
3716 		return TEST_SKIPPED;
3717 
3718 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3719 
3720 	uint64_t feat_flags = dev_info.feature_flags;
3721 
3722 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3723 		printf("Device doesn't support in-place scatter-gather. "
3724 				"Test Skipped.\n");
3725 		return TEST_SKIPPED;
3726 	}
3727 
3728 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3729 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3730 		printf("Device doesn't support RAW data-path APIs.\n");
3731 		return TEST_SKIPPED;
3732 	}
3733 
3734 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3735 		return TEST_SKIPPED;
3736 
3737 	/* Create KASUMI session */
3738 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3739 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3740 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3741 					tdata->key.data, tdata->key.len,
3742 					tdata->cipher_iv.len);
3743 	if (retval < 0)
3744 		return retval;
3745 
3746 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3747 
3748 
3749 	/* Append data which is padded to a multiple */
3750 	/* of the algorithms block size */
3751 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3752 
3753 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3754 			plaintext_pad_len, 10, 0);
3755 
3756 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3757 
3758 	/* Create KASUMI operation */
3759 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3760 				tdata->cipher_iv.len,
3761 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3762 				tdata->validCipherOffsetInBits.len);
3763 	if (retval < 0)
3764 		return retval;
3765 
3766 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3767 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3768 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3769 	else
3770 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3771 						ut_params->op);
3772 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3773 
3774 	ut_params->obuf = ut_params->op->sym->m_dst;
3775 
3776 	if (ut_params->obuf)
3777 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3778 				plaintext_len, buffer);
3779 	else
3780 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3781 				tdata->validCipherOffsetInBits.len >> 3,
3782 				plaintext_len, buffer);
3783 
3784 	/* Validate obuf */
3785 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3786 
3787 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3788 				(tdata->validCipherOffsetInBits.len >> 3);
3789 	/* Validate obuf */
3790 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3791 		ciphertext,
3792 		reference_ciphertext,
3793 		tdata->validCipherLenInBits.len,
3794 		"KASUMI Ciphertext data not as expected");
3795 	return 0;
3796 }
3797 
3798 static int
3799 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3800 {
3801 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3802 	struct crypto_unittest_params *ut_params = &unittest_params;
3803 
3804 	int retval;
3805 	uint8_t *plaintext, *ciphertext;
3806 	unsigned plaintext_pad_len;
3807 	unsigned plaintext_len;
3808 
3809 	/* Verify the capabilities */
3810 	struct rte_cryptodev_sym_capability_idx cap_idx;
3811 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3812 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3813 	/* Data-path service does not support OOP */
3814 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3815 			&cap_idx) == NULL)
3816 		return TEST_SKIPPED;
3817 
3818 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3819 		return TEST_SKIPPED;
3820 
3821 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3822 		return TEST_SKIPPED;
3823 
3824 	/* Create KASUMI session */
3825 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3826 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3827 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3828 					tdata->key.data, tdata->key.len,
3829 					tdata->cipher_iv.len);
3830 	if (retval < 0)
3831 		return retval;
3832 
3833 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3834 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3835 
3836 	/* Clear mbuf payload */
3837 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3838 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3839 
3840 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3841 	/* Append data which is padded to a multiple */
3842 	/* of the algorithms block size */
3843 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3844 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3845 				plaintext_pad_len);
3846 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3847 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3848 
3849 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3850 
3851 	/* Create KASUMI operation */
3852 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3853 				tdata->cipher_iv.len,
3854 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3855 				tdata->validCipherOffsetInBits.len);
3856 	if (retval < 0)
3857 		return retval;
3858 
3859 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3860 						ut_params->op);
3861 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3862 
3863 	ut_params->obuf = ut_params->op->sym->m_dst;
3864 	if (ut_params->obuf)
3865 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3866 	else
3867 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3868 
3869 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3870 
3871 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3872 				(tdata->validCipherOffsetInBits.len >> 3);
3873 	/* Validate obuf */
3874 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3875 		ciphertext,
3876 		reference_ciphertext,
3877 		tdata->validCipherLenInBits.len,
3878 		"KASUMI Ciphertext data not as expected");
3879 	return 0;
3880 }
3881 
3882 static int
3883 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3884 {
3885 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3886 	struct crypto_unittest_params *ut_params = &unittest_params;
3887 
3888 	int retval;
3889 	unsigned int plaintext_pad_len;
3890 	unsigned int plaintext_len;
3891 
3892 	const uint8_t *ciphertext;
3893 	uint8_t buffer[2048];
3894 
3895 	struct rte_cryptodev_info dev_info;
3896 
3897 	/* Verify the capabilities */
3898 	struct rte_cryptodev_sym_capability_idx cap_idx;
3899 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3900 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3901 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3902 			&cap_idx) == NULL)
3903 		return TEST_SKIPPED;
3904 
3905 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3906 		return TEST_SKIPPED;
3907 
3908 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3909 		return TEST_SKIPPED;
3910 
3911 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3912 
3913 	uint64_t feat_flags = dev_info.feature_flags;
3914 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3915 		printf("Device doesn't support out-of-place scatter-gather "
3916 				"in both input and output mbufs. "
3917 				"Test Skipped.\n");
3918 		return TEST_SKIPPED;
3919 	}
3920 
3921 	/* Create KASUMI session */
3922 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3923 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3924 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3925 					tdata->key.data, tdata->key.len,
3926 					tdata->cipher_iv.len);
3927 	if (retval < 0)
3928 		return retval;
3929 
3930 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3931 	/* Append data which is padded to a multiple */
3932 	/* of the algorithms block size */
3933 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3934 
3935 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3936 			plaintext_pad_len, 10, 0);
3937 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3938 			plaintext_pad_len, 3, 0);
3939 
3940 	/* Append data which is padded to a multiple */
3941 	/* of the algorithms block size */
3942 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3943 
3944 	/* Create KASUMI operation */
3945 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3946 				tdata->cipher_iv.len,
3947 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3948 				tdata->validCipherOffsetInBits.len);
3949 	if (retval < 0)
3950 		return retval;
3951 
3952 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3953 						ut_params->op);
3954 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3955 
3956 	ut_params->obuf = ut_params->op->sym->m_dst;
3957 	if (ut_params->obuf)
3958 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3959 				plaintext_pad_len, buffer);
3960 	else
3961 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3962 				tdata->validCipherOffsetInBits.len >> 3,
3963 				plaintext_pad_len, buffer);
3964 
3965 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3966 				(tdata->validCipherOffsetInBits.len >> 3);
3967 	/* Validate obuf */
3968 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3969 		ciphertext,
3970 		reference_ciphertext,
3971 		tdata->validCipherLenInBits.len,
3972 		"KASUMI Ciphertext data not as expected");
3973 	return 0;
3974 }
3975 
3976 
3977 static int
3978 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3979 {
3980 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3981 	struct crypto_unittest_params *ut_params = &unittest_params;
3982 
3983 	int retval;
3984 	uint8_t *ciphertext, *plaintext;
3985 	unsigned ciphertext_pad_len;
3986 	unsigned ciphertext_len;
3987 
3988 	/* Verify the capabilities */
3989 	struct rte_cryptodev_sym_capability_idx cap_idx;
3990 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3991 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3992 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3993 			&cap_idx) == NULL)
3994 		return TEST_SKIPPED;
3995 
3996 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3997 		return TEST_SKIPPED;
3998 
3999 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4000 		return TEST_SKIPPED;
4001 
4002 	/* Create KASUMI session */
4003 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4004 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4005 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4006 					tdata->key.data, tdata->key.len,
4007 					tdata->cipher_iv.len);
4008 	if (retval < 0)
4009 		return retval;
4010 
4011 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4012 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4013 
4014 	/* Clear mbuf payload */
4015 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4016 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4017 
4018 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4019 	/* Append data which is padded to a multiple */
4020 	/* of the algorithms block size */
4021 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4022 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4023 				ciphertext_pad_len);
4024 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4025 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4026 
4027 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4028 
4029 	/* Create KASUMI operation */
4030 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4031 				tdata->cipher_iv.len,
4032 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4033 				tdata->validCipherOffsetInBits.len);
4034 	if (retval < 0)
4035 		return retval;
4036 
4037 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4038 						ut_params->op);
4039 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4040 
4041 	ut_params->obuf = ut_params->op->sym->m_dst;
4042 	if (ut_params->obuf)
4043 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4044 	else
4045 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4046 
4047 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4048 
4049 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4050 				(tdata->validCipherOffsetInBits.len >> 3);
4051 	/* Validate obuf */
4052 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4053 		plaintext,
4054 		reference_plaintext,
4055 		tdata->validCipherLenInBits.len,
4056 		"KASUMI Plaintext data not as expected");
4057 	return 0;
4058 }
4059 
4060 static int
4061 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4062 {
4063 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4064 	struct crypto_unittest_params *ut_params = &unittest_params;
4065 
4066 	int retval;
4067 	uint8_t *ciphertext, *plaintext;
4068 	unsigned ciphertext_pad_len;
4069 	unsigned ciphertext_len;
4070 	struct rte_cryptodev_info dev_info;
4071 
4072 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4073 	uint64_t feat_flags = dev_info.feature_flags;
4074 
4075 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4076 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4077 		printf("Device doesn't support RAW data-path APIs.\n");
4078 		return TEST_SKIPPED;
4079 	}
4080 
4081 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4082 		return TEST_SKIPPED;
4083 
4084 	/* Verify the capabilities */
4085 	struct rte_cryptodev_sym_capability_idx cap_idx;
4086 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4087 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4088 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4089 			&cap_idx) == NULL)
4090 		return TEST_SKIPPED;
4091 
4092 	/* Create KASUMI session */
4093 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4094 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4095 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4096 					tdata->key.data, tdata->key.len,
4097 					tdata->cipher_iv.len);
4098 	if (retval < 0)
4099 		return retval;
4100 
4101 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4102 
4103 	/* Clear mbuf payload */
4104 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4105 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4106 
4107 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4108 	/* Append data which is padded to a multiple */
4109 	/* of the algorithms block size */
4110 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4111 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4112 				ciphertext_pad_len);
4113 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4114 
4115 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4116 
4117 	/* Create KASUMI operation */
4118 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4119 			tdata->cipher_iv.len,
4120 			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4121 			tdata->validCipherOffsetInBits.len);
4122 	if (retval < 0)
4123 		return retval;
4124 
4125 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4126 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4127 				ut_params->op, 1, 0, 1, 0);
4128 	else
4129 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4130 						ut_params->op);
4131 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4132 
4133 	ut_params->obuf = ut_params->op->sym->m_dst;
4134 	if (ut_params->obuf)
4135 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4136 	else
4137 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4138 
4139 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4140 
4141 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4142 				(tdata->validCipherOffsetInBits.len >> 3);
4143 	/* Validate obuf */
4144 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4145 		plaintext,
4146 		reference_plaintext,
4147 		tdata->validCipherLenInBits.len,
4148 		"KASUMI Plaintext data not as expected");
4149 	return 0;
4150 }
4151 
4152 static int
4153 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4154 {
4155 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4156 	struct crypto_unittest_params *ut_params = &unittest_params;
4157 
4158 	int retval;
4159 	uint8_t *plaintext, *ciphertext;
4160 	unsigned plaintext_pad_len;
4161 	unsigned plaintext_len;
4162 	struct rte_cryptodev_info dev_info;
4163 
4164 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4165 	uint64_t feat_flags = dev_info.feature_flags;
4166 
4167 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4168 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4169 		printf("Device doesn't support RAW data-path APIs.\n");
4170 		return TEST_SKIPPED;
4171 	}
4172 
4173 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4174 		return TEST_SKIPPED;
4175 
4176 	/* Verify the capabilities */
4177 	struct rte_cryptodev_sym_capability_idx cap_idx;
4178 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4179 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4180 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4181 			&cap_idx) == NULL)
4182 		return TEST_SKIPPED;
4183 
4184 	/* Create SNOW 3G session */
4185 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4186 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4187 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4188 					tdata->key.data, tdata->key.len,
4189 					tdata->cipher_iv.len);
4190 	if (retval < 0)
4191 		return retval;
4192 
4193 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4194 
4195 	/* Clear mbuf payload */
4196 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4197 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4198 
4199 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4200 	/* Append data which is padded to a multiple of */
4201 	/* the algorithms block size */
4202 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4203 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4204 				plaintext_pad_len);
4205 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4206 
4207 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4208 
4209 	/* Create SNOW 3G operation */
4210 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4211 					tdata->cipher_iv.len,
4212 					tdata->validCipherLenInBits.len,
4213 					0);
4214 	if (retval < 0)
4215 		return retval;
4216 
4217 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4218 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4219 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4220 	else
4221 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4222 						ut_params->op);
4223 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4224 
4225 	ut_params->obuf = ut_params->op->sym->m_dst;
4226 	if (ut_params->obuf)
4227 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4228 	else
4229 		ciphertext = plaintext;
4230 
4231 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4232 
4233 	/* Validate obuf */
4234 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4235 		ciphertext,
4236 		tdata->ciphertext.data,
4237 		tdata->validDataLenInBits.len,
4238 		"SNOW 3G Ciphertext data not as expected");
4239 	return 0;
4240 }
4241 
4242 
4243 static int
4244 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4245 {
4246 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4247 	struct crypto_unittest_params *ut_params = &unittest_params;
4248 	uint8_t *plaintext, *ciphertext;
4249 
4250 	int retval;
4251 	unsigned plaintext_pad_len;
4252 	unsigned plaintext_len;
4253 	struct rte_cryptodev_info dev_info;
4254 
4255 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4256 	uint64_t feat_flags = dev_info.feature_flags;
4257 
4258 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4259 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4260 		printf("Device does not support RAW data-path APIs.\n");
4261 		return -ENOTSUP;
4262 	}
4263 
4264 	/* Verify the capabilities */
4265 	struct rte_cryptodev_sym_capability_idx cap_idx;
4266 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4267 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4268 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4269 			&cap_idx) == NULL)
4270 		return TEST_SKIPPED;
4271 
4272 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4273 		return TEST_SKIPPED;
4274 
4275 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4276 		return TEST_SKIPPED;
4277 
4278 	/* Create SNOW 3G session */
4279 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4280 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4281 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4282 					tdata->key.data, tdata->key.len,
4283 					tdata->cipher_iv.len);
4284 	if (retval < 0)
4285 		return retval;
4286 
4287 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4288 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4289 
4290 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4291 			"Failed to allocate input buffer in mempool");
4292 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4293 			"Failed to allocate output buffer in mempool");
4294 
4295 	/* Clear mbuf payload */
4296 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4297 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4298 
4299 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4300 	/* Append data which is padded to a multiple of */
4301 	/* the algorithms block size */
4302 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4303 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4304 				plaintext_pad_len);
4305 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4306 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4307 
4308 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4309 
4310 	/* Create SNOW 3G operation */
4311 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4312 					tdata->cipher_iv.len,
4313 					tdata->validCipherLenInBits.len,
4314 					0);
4315 	if (retval < 0)
4316 		return retval;
4317 
4318 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4319 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4320 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4321 	else
4322 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4323 						ut_params->op);
4324 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4325 
4326 	ut_params->obuf = ut_params->op->sym->m_dst;
4327 	if (ut_params->obuf)
4328 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4329 	else
4330 		ciphertext = plaintext;
4331 
4332 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4333 
4334 	/* Validate obuf */
4335 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4336 		ciphertext,
4337 		tdata->ciphertext.data,
4338 		tdata->validDataLenInBits.len,
4339 		"SNOW 3G Ciphertext data not as expected");
4340 	return 0;
4341 }
4342 
4343 static int
4344 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4345 {
4346 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4347 	struct crypto_unittest_params *ut_params = &unittest_params;
4348 
4349 	int retval;
4350 	unsigned int plaintext_pad_len;
4351 	unsigned int plaintext_len;
4352 	uint8_t buffer[10000];
4353 	const uint8_t *ciphertext;
4354 
4355 	struct rte_cryptodev_info dev_info;
4356 
4357 	/* Verify the capabilities */
4358 	struct rte_cryptodev_sym_capability_idx cap_idx;
4359 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4360 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4361 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4362 			&cap_idx) == NULL)
4363 		return TEST_SKIPPED;
4364 
4365 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4366 		return TEST_SKIPPED;
4367 
4368 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4369 		return TEST_SKIPPED;
4370 
4371 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4372 
4373 	uint64_t feat_flags = dev_info.feature_flags;
4374 
4375 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4376 		printf("Device doesn't support out-of-place scatter-gather "
4377 				"in both input and output mbufs. "
4378 				"Test Skipped.\n");
4379 		return TEST_SKIPPED;
4380 	}
4381 
4382 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4383 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4384 		printf("Device does not support RAW data-path APIs.\n");
4385 		return -ENOTSUP;
4386 	}
4387 
4388 	/* Create SNOW 3G session */
4389 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4390 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4391 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4392 					tdata->key.data, tdata->key.len,
4393 					tdata->cipher_iv.len);
4394 	if (retval < 0)
4395 		return retval;
4396 
4397 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4398 	/* Append data which is padded to a multiple of */
4399 	/* the algorithms block size */
4400 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4401 
4402 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4403 			plaintext_pad_len, 10, 0);
4404 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4405 			plaintext_pad_len, 3, 0);
4406 
4407 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4408 			"Failed to allocate input buffer in mempool");
4409 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4410 			"Failed to allocate output buffer in mempool");
4411 
4412 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4413 
4414 	/* Create SNOW 3G operation */
4415 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4416 					tdata->cipher_iv.len,
4417 					tdata->validCipherLenInBits.len,
4418 					0);
4419 	if (retval < 0)
4420 		return retval;
4421 
4422 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4423 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4424 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4425 	else
4426 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4427 						ut_params->op);
4428 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4429 
4430 	ut_params->obuf = ut_params->op->sym->m_dst;
4431 	if (ut_params->obuf)
4432 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4433 				plaintext_len, buffer);
4434 	else
4435 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4436 				plaintext_len, buffer);
4437 
4438 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4439 
4440 	/* Validate obuf */
4441 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4442 		ciphertext,
4443 		tdata->ciphertext.data,
4444 		tdata->validDataLenInBits.len,
4445 		"SNOW 3G Ciphertext data not as expected");
4446 
4447 	return 0;
4448 }
4449 
4450 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4451 static void
4452 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4453 {
4454 	uint8_t curr_byte, prev_byte;
4455 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4456 	uint8_t lower_byte_mask = (1 << offset) - 1;
4457 	unsigned i;
4458 
4459 	prev_byte = buffer[0];
4460 	buffer[0] >>= offset;
4461 
4462 	for (i = 1; i < length_in_bytes; i++) {
4463 		curr_byte = buffer[i];
4464 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4465 				(curr_byte >> offset);
4466 		prev_byte = curr_byte;
4467 	}
4468 }
4469 
4470 static int
4471 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4472 {
4473 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4474 	struct crypto_unittest_params *ut_params = &unittest_params;
4475 	uint8_t *plaintext, *ciphertext;
4476 	int retval;
4477 	uint32_t plaintext_len;
4478 	uint32_t plaintext_pad_len;
4479 	uint8_t extra_offset = 4;
4480 	uint8_t *expected_ciphertext_shifted;
4481 	struct rte_cryptodev_info dev_info;
4482 
4483 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4484 	uint64_t feat_flags = dev_info.feature_flags;
4485 
4486 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4487 			((tdata->validDataLenInBits.len % 8) != 0)) {
4488 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4489 		return TEST_SKIPPED;
4490 	}
4491 
4492 	/* Verify the capabilities */
4493 	struct rte_cryptodev_sym_capability_idx cap_idx;
4494 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4495 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4496 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4497 			&cap_idx) == NULL)
4498 		return TEST_SKIPPED;
4499 
4500 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4501 		return TEST_SKIPPED;
4502 
4503 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4504 		return TEST_SKIPPED;
4505 
4506 	/* Create SNOW 3G session */
4507 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4508 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4509 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4510 					tdata->key.data, tdata->key.len,
4511 					tdata->cipher_iv.len);
4512 	if (retval < 0)
4513 		return retval;
4514 
4515 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4516 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4517 
4518 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4519 			"Failed to allocate input buffer in mempool");
4520 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4521 			"Failed to allocate output buffer in mempool");
4522 
4523 	/* Clear mbuf payload */
4524 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4525 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4526 
4527 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4528 	/*
4529 	 * Append data which is padded to a
4530 	 * multiple of the algorithms block size
4531 	 */
4532 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4533 
4534 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4535 						plaintext_pad_len);
4536 
4537 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4538 
4539 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4540 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4541 
4542 #ifdef RTE_APP_TEST_DEBUG
4543 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4544 #endif
4545 	/* Create SNOW 3G operation */
4546 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4547 					tdata->cipher_iv.len,
4548 					tdata->validCipherLenInBits.len,
4549 					extra_offset);
4550 	if (retval < 0)
4551 		return retval;
4552 
4553 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4554 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4555 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4556 	else
4557 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4558 						ut_params->op);
4559 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4560 
4561 	ut_params->obuf = ut_params->op->sym->m_dst;
4562 	if (ut_params->obuf)
4563 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4564 	else
4565 		ciphertext = plaintext;
4566 
4567 #ifdef RTE_APP_TEST_DEBUG
4568 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4569 #endif
4570 
4571 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4572 
4573 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4574 			"failed to reserve memory for ciphertext shifted\n");
4575 
4576 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4577 			ceil_byte_length(tdata->ciphertext.len));
4578 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4579 			extra_offset);
4580 	/* Validate obuf */
4581 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4582 		ciphertext,
4583 		expected_ciphertext_shifted,
4584 		tdata->validDataLenInBits.len,
4585 		extra_offset,
4586 		"SNOW 3G Ciphertext data not as expected");
4587 	return 0;
4588 }
4589 
4590 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4591 {
4592 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4593 	struct crypto_unittest_params *ut_params = &unittest_params;
4594 
4595 	int retval;
4596 
4597 	uint8_t *plaintext, *ciphertext;
4598 	unsigned ciphertext_pad_len;
4599 	unsigned ciphertext_len;
4600 	struct rte_cryptodev_info dev_info;
4601 
4602 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4603 	uint64_t feat_flags = dev_info.feature_flags;
4604 
4605 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4606 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4607 		printf("Device doesn't support RAW data-path APIs.\n");
4608 		return TEST_SKIPPED;
4609 	}
4610 
4611 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4612 		return TEST_SKIPPED;
4613 
4614 	/* Verify the capabilities */
4615 	struct rte_cryptodev_sym_capability_idx cap_idx;
4616 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4617 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4618 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4619 			&cap_idx) == NULL)
4620 		return TEST_SKIPPED;
4621 
4622 	/* Create SNOW 3G session */
4623 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4624 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4625 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4626 					tdata->key.data, tdata->key.len,
4627 					tdata->cipher_iv.len);
4628 	if (retval < 0)
4629 		return retval;
4630 
4631 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4632 
4633 	/* Clear mbuf payload */
4634 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4635 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4636 
4637 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4638 	/* Append data which is padded to a multiple of */
4639 	/* the algorithms block size */
4640 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4641 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4642 				ciphertext_pad_len);
4643 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4644 
4645 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4646 
4647 	/* Create SNOW 3G operation */
4648 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4649 					tdata->cipher_iv.len,
4650 					tdata->validCipherLenInBits.len,
4651 					tdata->cipher.offset_bits);
4652 	if (retval < 0)
4653 		return retval;
4654 
4655 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4656 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4657 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4658 	else
4659 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4660 						ut_params->op);
4661 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4662 	ut_params->obuf = ut_params->op->sym->m_dst;
4663 	if (ut_params->obuf)
4664 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4665 	else
4666 		plaintext = ciphertext;
4667 
4668 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4669 
4670 	/* Validate obuf */
4671 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4672 				tdata->plaintext.data,
4673 				tdata->validDataLenInBits.len,
4674 				"SNOW 3G Plaintext data not as expected");
4675 	return 0;
4676 }
4677 
4678 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4679 {
4680 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4681 	struct crypto_unittest_params *ut_params = &unittest_params;
4682 
4683 	int retval;
4684 
4685 	uint8_t *plaintext, *ciphertext;
4686 	unsigned ciphertext_pad_len;
4687 	unsigned ciphertext_len;
4688 	struct rte_cryptodev_info dev_info;
4689 
4690 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4691 	uint64_t feat_flags = dev_info.feature_flags;
4692 
4693 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4694 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4695 		printf("Device does not support RAW data-path APIs.\n");
4696 		return -ENOTSUP;
4697 	}
4698 	/* Verify the capabilities */
4699 	struct rte_cryptodev_sym_capability_idx cap_idx;
4700 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4701 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4702 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4703 			&cap_idx) == NULL)
4704 		return TEST_SKIPPED;
4705 
4706 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4707 		return TEST_SKIPPED;
4708 
4709 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4710 		return TEST_SKIPPED;
4711 
4712 	/* Create SNOW 3G session */
4713 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4714 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4715 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4716 					tdata->key.data, tdata->key.len,
4717 					tdata->cipher_iv.len);
4718 	if (retval < 0)
4719 		return retval;
4720 
4721 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4722 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4723 
4724 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4725 			"Failed to allocate input buffer");
4726 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4727 			"Failed to allocate output buffer");
4728 
4729 	/* Clear mbuf payload */
4730 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4731 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4732 
4733 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4734 		       rte_pktmbuf_tailroom(ut_params->obuf));
4735 
4736 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4737 	/* Append data which is padded to a multiple of */
4738 	/* the algorithms block size */
4739 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4740 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4741 				ciphertext_pad_len);
4742 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4743 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4744 
4745 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4746 
4747 	/* Create SNOW 3G operation */
4748 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4749 					tdata->cipher_iv.len,
4750 					tdata->validCipherLenInBits.len,
4751 					0);
4752 	if (retval < 0)
4753 		return retval;
4754 
4755 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4756 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4757 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4758 	else
4759 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4760 						ut_params->op);
4761 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4762 	ut_params->obuf = ut_params->op->sym->m_dst;
4763 	if (ut_params->obuf)
4764 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4765 	else
4766 		plaintext = ciphertext;
4767 
4768 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4769 
4770 	/* Validate obuf */
4771 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4772 				tdata->plaintext.data,
4773 				tdata->validDataLenInBits.len,
4774 				"SNOW 3G Plaintext data not as expected");
4775 	return 0;
4776 }
4777 
4778 static int
4779 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4780 {
4781 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4782 	struct crypto_unittest_params *ut_params = &unittest_params;
4783 
4784 	int retval;
4785 
4786 	uint8_t *plaintext, *ciphertext;
4787 	unsigned int plaintext_pad_len;
4788 	unsigned int plaintext_len;
4789 
4790 	struct rte_cryptodev_info dev_info;
4791 	struct rte_cryptodev_sym_capability_idx cap_idx;
4792 
4793 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4794 	uint64_t feat_flags = dev_info.feature_flags;
4795 
4796 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4797 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4798 			(tdata->validDataLenInBits.len % 8 != 0))) {
4799 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4800 		return TEST_SKIPPED;
4801 	}
4802 
4803 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4804 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4805 		printf("Device doesn't support RAW data-path APIs.\n");
4806 		return TEST_SKIPPED;
4807 	}
4808 
4809 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4810 		return TEST_SKIPPED;
4811 
4812 	/* Check if device supports ZUC EEA3 */
4813 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4814 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4815 
4816 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4817 			&cap_idx) == NULL)
4818 		return TEST_SKIPPED;
4819 
4820 	/* Check if device supports ZUC EIA3 */
4821 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4822 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4823 
4824 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4825 			&cap_idx) == NULL)
4826 		return TEST_SKIPPED;
4827 
4828 	/* Create ZUC session */
4829 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4830 			ts_params->valid_devs[0],
4831 			tdata);
4832 	if (retval != 0)
4833 		return retval;
4834 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4835 
4836 	/* clear mbuf payload */
4837 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4838 			rte_pktmbuf_tailroom(ut_params->ibuf));
4839 
4840 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4841 	/* Append data which is padded to a multiple of */
4842 	/* the algorithms block size */
4843 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4844 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4845 				plaintext_pad_len);
4846 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4847 
4848 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4849 
4850 	/* Create ZUC operation */
4851 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4852 	if (retval < 0)
4853 		return retval;
4854 
4855 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4856 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4857 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4858 	else
4859 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4860 			ut_params->op);
4861 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4862 	ut_params->obuf = ut_params->op->sym->m_src;
4863 	if (ut_params->obuf)
4864 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4865 	else
4866 		ciphertext = plaintext;
4867 
4868 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4869 	/* Validate obuf */
4870 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4871 			ciphertext,
4872 			tdata->ciphertext.data,
4873 			tdata->validDataLenInBits.len,
4874 			"ZUC Ciphertext data not as expected");
4875 
4876 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4877 	    + plaintext_pad_len;
4878 
4879 	/* Validate obuf */
4880 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4881 			ut_params->digest,
4882 			tdata->digest.data,
4883 			4,
4884 			"ZUC Generated auth tag not as expected");
4885 	return 0;
4886 }
4887 
4888 static int
4889 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4890 {
4891 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4892 	struct crypto_unittest_params *ut_params = &unittest_params;
4893 
4894 	int retval;
4895 
4896 	uint8_t *plaintext, *ciphertext;
4897 	unsigned plaintext_pad_len;
4898 	unsigned plaintext_len;
4899 	struct rte_cryptodev_info dev_info;
4900 
4901 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4902 	uint64_t feat_flags = dev_info.feature_flags;
4903 
4904 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4905 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4906 		printf("Device doesn't support RAW data-path APIs.\n");
4907 		return TEST_SKIPPED;
4908 	}
4909 
4910 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4911 		return TEST_SKIPPED;
4912 
4913 	/* Verify the capabilities */
4914 	struct rte_cryptodev_sym_capability_idx cap_idx;
4915 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4916 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4917 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4918 			&cap_idx) == NULL)
4919 		return TEST_SKIPPED;
4920 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4921 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4922 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4923 			&cap_idx) == NULL)
4924 		return TEST_SKIPPED;
4925 
4926 	/* Create SNOW 3G session */
4927 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4928 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4929 			RTE_CRYPTO_AUTH_OP_GENERATE,
4930 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4931 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4932 			tdata->key.data, tdata->key.len,
4933 			tdata->auth_iv.len, tdata->digest.len,
4934 			tdata->cipher_iv.len);
4935 	if (retval != 0)
4936 		return retval;
4937 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4938 
4939 	/* clear mbuf payload */
4940 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4941 			rte_pktmbuf_tailroom(ut_params->ibuf));
4942 
4943 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4944 	/* Append data which is padded to a multiple of */
4945 	/* the algorithms block size */
4946 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4947 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4948 				plaintext_pad_len);
4949 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4950 
4951 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4952 
4953 	/* Create SNOW 3G operation */
4954 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4955 			tdata->digest.len, tdata->auth_iv.data,
4956 			tdata->auth_iv.len,
4957 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4958 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4959 			tdata->validCipherLenInBits.len,
4960 			0,
4961 			tdata->validAuthLenInBits.len,
4962 			0
4963 			);
4964 	if (retval < 0)
4965 		return retval;
4966 
4967 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4968 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4969 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4970 	else
4971 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4972 			ut_params->op);
4973 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4974 	ut_params->obuf = ut_params->op->sym->m_src;
4975 	if (ut_params->obuf)
4976 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4977 	else
4978 		ciphertext = plaintext;
4979 
4980 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4981 	/* Validate obuf */
4982 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4983 			ciphertext,
4984 			tdata->ciphertext.data,
4985 			tdata->validDataLenInBits.len,
4986 			"SNOW 3G Ciphertext data not as expected");
4987 
4988 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4989 	    + plaintext_pad_len;
4990 
4991 	/* Validate obuf */
4992 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4993 			ut_params->digest,
4994 			tdata->digest.data,
4995 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4996 			"SNOW 3G Generated auth tag not as expected");
4997 	return 0;
4998 }
4999 
5000 static int
5001 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
5002 	uint8_t op_mode, uint8_t verify)
5003 {
5004 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5005 	struct crypto_unittest_params *ut_params = &unittest_params;
5006 
5007 	int retval;
5008 
5009 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5010 	unsigned int plaintext_pad_len;
5011 	unsigned int plaintext_len;
5012 	unsigned int ciphertext_pad_len;
5013 	unsigned int ciphertext_len;
5014 
5015 	struct rte_cryptodev_info dev_info;
5016 
5017 	/* Verify the capabilities */
5018 	struct rte_cryptodev_sym_capability_idx cap_idx;
5019 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5020 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5021 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5022 			&cap_idx) == NULL)
5023 		return TEST_SKIPPED;
5024 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5025 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5026 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5027 			&cap_idx) == NULL)
5028 		return TEST_SKIPPED;
5029 
5030 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5031 		return TEST_SKIPPED;
5032 
5033 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5034 
5035 	uint64_t feat_flags = dev_info.feature_flags;
5036 
5037 	if (op_mode == OUT_OF_PLACE) {
5038 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5039 			printf("Device doesn't support digest encrypted.\n");
5040 			return TEST_SKIPPED;
5041 		}
5042 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5043 			return TEST_SKIPPED;
5044 	}
5045 
5046 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5047 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5048 		printf("Device doesn't support RAW data-path APIs.\n");
5049 		return TEST_SKIPPED;
5050 	}
5051 
5052 	/* Create SNOW 3G session */
5053 	retval = create_wireless_algo_auth_cipher_session(
5054 			ts_params->valid_devs[0],
5055 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5056 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5057 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5058 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5059 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5060 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5061 			tdata->key.data, tdata->key.len,
5062 			tdata->auth_iv.len, tdata->digest.len,
5063 			tdata->cipher_iv.len);
5064 	if (retval != 0)
5065 		return retval;
5066 
5067 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5068 	if (op_mode == OUT_OF_PLACE)
5069 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5070 
5071 	/* clear mbuf payload */
5072 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5073 		rte_pktmbuf_tailroom(ut_params->ibuf));
5074 	if (op_mode == OUT_OF_PLACE)
5075 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5076 			rte_pktmbuf_tailroom(ut_params->obuf));
5077 
5078 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5079 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5080 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5081 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5082 
5083 	if (verify) {
5084 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5085 					ciphertext_pad_len);
5086 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5087 		if (op_mode == OUT_OF_PLACE)
5088 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5089 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5090 			ciphertext_len);
5091 	} else {
5092 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5093 					plaintext_pad_len);
5094 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5095 		if (op_mode == OUT_OF_PLACE)
5096 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5097 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5098 	}
5099 
5100 	/* Create SNOW 3G operation */
5101 	retval = create_wireless_algo_auth_cipher_operation(
5102 		tdata->digest.data, tdata->digest.len,
5103 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5104 		tdata->auth_iv.data, tdata->auth_iv.len,
5105 		(tdata->digest.offset_bytes == 0 ?
5106 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5107 			: tdata->digest.offset_bytes),
5108 		tdata->validCipherLenInBits.len,
5109 		tdata->cipher.offset_bits,
5110 		tdata->validAuthLenInBits.len,
5111 		tdata->auth.offset_bits,
5112 		op_mode, 0, verify);
5113 
5114 	if (retval < 0)
5115 		return retval;
5116 
5117 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5118 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5119 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5120 	else
5121 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5122 			ut_params->op);
5123 
5124 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5125 
5126 	ut_params->obuf = (op_mode == IN_PLACE ?
5127 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5128 
5129 	if (verify) {
5130 		if (ut_params->obuf)
5131 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5132 							uint8_t *);
5133 		else
5134 			plaintext = ciphertext +
5135 				(tdata->cipher.offset_bits >> 3);
5136 
5137 		debug_hexdump(stdout, "plaintext:", plaintext,
5138 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5139 		debug_hexdump(stdout, "plaintext expected:",
5140 			tdata->plaintext.data,
5141 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5142 	} else {
5143 		if (ut_params->obuf)
5144 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5145 							uint8_t *);
5146 		else
5147 			ciphertext = plaintext;
5148 
5149 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5150 			ciphertext_len);
5151 		debug_hexdump(stdout, "ciphertext expected:",
5152 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5153 
5154 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5155 			+ (tdata->digest.offset_bytes == 0 ?
5156 		plaintext_pad_len : tdata->digest.offset_bytes);
5157 
5158 		debug_hexdump(stdout, "digest:", ut_params->digest,
5159 			tdata->digest.len);
5160 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5161 				tdata->digest.len);
5162 	}
5163 
5164 	/* Validate obuf */
5165 	if (verify) {
5166 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5167 			plaintext,
5168 			tdata->plaintext.data,
5169 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5170 			 (tdata->digest.len << 3)),
5171 			tdata->cipher.offset_bits,
5172 			"SNOW 3G Plaintext data not as expected");
5173 	} else {
5174 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5175 			ciphertext,
5176 			tdata->ciphertext.data,
5177 			(tdata->validDataLenInBits.len -
5178 			 tdata->cipher.offset_bits),
5179 			tdata->cipher.offset_bits,
5180 			"SNOW 3G Ciphertext data not as expected");
5181 
5182 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5183 			ut_params->digest,
5184 			tdata->digest.data,
5185 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5186 			"SNOW 3G Generated auth tag not as expected");
5187 	}
5188 	return 0;
5189 }
5190 
5191 static int
5192 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5193 	uint8_t op_mode, uint8_t verify)
5194 {
5195 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5196 	struct crypto_unittest_params *ut_params = &unittest_params;
5197 
5198 	int retval;
5199 
5200 	const uint8_t *plaintext = NULL;
5201 	const uint8_t *ciphertext = NULL;
5202 	const uint8_t *digest = NULL;
5203 	unsigned int plaintext_pad_len;
5204 	unsigned int plaintext_len;
5205 	unsigned int ciphertext_pad_len;
5206 	unsigned int ciphertext_len;
5207 	uint8_t buffer[10000];
5208 	uint8_t digest_buffer[10000];
5209 
5210 	struct rte_cryptodev_info dev_info;
5211 
5212 	/* Verify the capabilities */
5213 	struct rte_cryptodev_sym_capability_idx cap_idx;
5214 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5215 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5216 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5217 			&cap_idx) == NULL)
5218 		return TEST_SKIPPED;
5219 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5220 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5221 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5222 			&cap_idx) == NULL)
5223 		return TEST_SKIPPED;
5224 
5225 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5226 		return TEST_SKIPPED;
5227 
5228 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5229 
5230 	uint64_t feat_flags = dev_info.feature_flags;
5231 
5232 	if (op_mode == IN_PLACE) {
5233 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5234 			printf("Device doesn't support in-place scatter-gather "
5235 					"in both input and output mbufs.\n");
5236 			return TEST_SKIPPED;
5237 		}
5238 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5239 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5240 			printf("Device doesn't support RAW data-path APIs.\n");
5241 			return TEST_SKIPPED;
5242 		}
5243 	} else {
5244 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5245 			return TEST_SKIPPED;
5246 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5247 			printf("Device doesn't support out-of-place scatter-gather "
5248 					"in both input and output mbufs.\n");
5249 			return TEST_SKIPPED;
5250 		}
5251 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5252 			printf("Device doesn't support digest encrypted.\n");
5253 			return TEST_SKIPPED;
5254 		}
5255 	}
5256 
5257 	/* Create SNOW 3G session */
5258 	retval = create_wireless_algo_auth_cipher_session(
5259 			ts_params->valid_devs[0],
5260 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5261 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5262 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5263 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5264 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5265 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5266 			tdata->key.data, tdata->key.len,
5267 			tdata->auth_iv.len, tdata->digest.len,
5268 			tdata->cipher_iv.len);
5269 
5270 	if (retval != 0)
5271 		return retval;
5272 
5273 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5274 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5275 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5276 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5277 
5278 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5279 			plaintext_pad_len, 15, 0);
5280 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5281 			"Failed to allocate input buffer in mempool");
5282 
5283 	if (op_mode == OUT_OF_PLACE) {
5284 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5285 				plaintext_pad_len, 15, 0);
5286 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5287 				"Failed to allocate output buffer in mempool");
5288 	}
5289 
5290 	if (verify) {
5291 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5292 			tdata->ciphertext.data);
5293 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5294 					ciphertext_len, buffer);
5295 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5296 			ciphertext_len);
5297 	} else {
5298 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5299 			tdata->plaintext.data);
5300 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5301 					plaintext_len, buffer);
5302 		debug_hexdump(stdout, "plaintext:", plaintext,
5303 			plaintext_len);
5304 	}
5305 	memset(buffer, 0, sizeof(buffer));
5306 
5307 	/* Create SNOW 3G operation */
5308 	retval = create_wireless_algo_auth_cipher_operation(
5309 		tdata->digest.data, tdata->digest.len,
5310 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5311 		tdata->auth_iv.data, tdata->auth_iv.len,
5312 		(tdata->digest.offset_bytes == 0 ?
5313 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5314 			: tdata->digest.offset_bytes),
5315 		tdata->validCipherLenInBits.len,
5316 		tdata->cipher.offset_bits,
5317 		tdata->validAuthLenInBits.len,
5318 		tdata->auth.offset_bits,
5319 		op_mode, 1, verify);
5320 
5321 	if (retval < 0)
5322 		return retval;
5323 
5324 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5325 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5326 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5327 	else
5328 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5329 			ut_params->op);
5330 
5331 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5332 
5333 	ut_params->obuf = (op_mode == IN_PLACE ?
5334 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5335 
5336 	if (verify) {
5337 		if (ut_params->obuf)
5338 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5339 					plaintext_len, buffer);
5340 		else
5341 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5342 					plaintext_len, buffer);
5343 
5344 		debug_hexdump(stdout, "plaintext:", plaintext,
5345 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5346 		debug_hexdump(stdout, "plaintext expected:",
5347 			tdata->plaintext.data,
5348 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5349 	} else {
5350 		if (ut_params->obuf)
5351 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5352 					ciphertext_len, buffer);
5353 		else
5354 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5355 					ciphertext_len, buffer);
5356 
5357 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5358 			ciphertext_len);
5359 		debug_hexdump(stdout, "ciphertext expected:",
5360 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5361 
5362 		if (ut_params->obuf)
5363 			digest = rte_pktmbuf_read(ut_params->obuf,
5364 				(tdata->digest.offset_bytes == 0 ?
5365 				plaintext_pad_len : tdata->digest.offset_bytes),
5366 				tdata->digest.len, digest_buffer);
5367 		else
5368 			digest = rte_pktmbuf_read(ut_params->ibuf,
5369 				(tdata->digest.offset_bytes == 0 ?
5370 				plaintext_pad_len : tdata->digest.offset_bytes),
5371 				tdata->digest.len, digest_buffer);
5372 
5373 		debug_hexdump(stdout, "digest:", digest,
5374 			tdata->digest.len);
5375 		debug_hexdump(stdout, "digest expected:",
5376 			tdata->digest.data, tdata->digest.len);
5377 	}
5378 
5379 	/* Validate obuf */
5380 	if (verify) {
5381 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5382 			plaintext,
5383 			tdata->plaintext.data,
5384 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5385 			 (tdata->digest.len << 3)),
5386 			tdata->cipher.offset_bits,
5387 			"SNOW 3G Plaintext data not as expected");
5388 	} else {
5389 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5390 			ciphertext,
5391 			tdata->ciphertext.data,
5392 			(tdata->validDataLenInBits.len -
5393 			 tdata->cipher.offset_bits),
5394 			tdata->cipher.offset_bits,
5395 			"SNOW 3G Ciphertext data not as expected");
5396 
5397 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5398 			digest,
5399 			tdata->digest.data,
5400 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5401 			"SNOW 3G Generated auth tag not as expected");
5402 	}
5403 	return 0;
5404 }
5405 
5406 static int
5407 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5408 	uint8_t op_mode, uint8_t verify)
5409 {
5410 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5411 	struct crypto_unittest_params *ut_params = &unittest_params;
5412 
5413 	int retval;
5414 
5415 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5416 	unsigned int plaintext_pad_len;
5417 	unsigned int plaintext_len;
5418 	unsigned int ciphertext_pad_len;
5419 	unsigned int ciphertext_len;
5420 
5421 	struct rte_cryptodev_info dev_info;
5422 
5423 	/* Verify the capabilities */
5424 	struct rte_cryptodev_sym_capability_idx cap_idx;
5425 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5426 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5427 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5428 			&cap_idx) == NULL)
5429 		return TEST_SKIPPED;
5430 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5431 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5432 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5433 			&cap_idx) == NULL)
5434 		return TEST_SKIPPED;
5435 
5436 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5437 
5438 	uint64_t feat_flags = dev_info.feature_flags;
5439 
5440 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5441 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5442 		printf("Device doesn't support RAW data-path APIs.\n");
5443 		return TEST_SKIPPED;
5444 	}
5445 
5446 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5447 		return TEST_SKIPPED;
5448 
5449 	if (op_mode == OUT_OF_PLACE) {
5450 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5451 			return TEST_SKIPPED;
5452 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5453 			printf("Device doesn't support digest encrypted.\n");
5454 			return TEST_SKIPPED;
5455 		}
5456 	}
5457 
5458 	/* Create KASUMI session */
5459 	retval = create_wireless_algo_auth_cipher_session(
5460 			ts_params->valid_devs[0],
5461 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5462 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5463 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5464 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5465 			RTE_CRYPTO_AUTH_KASUMI_F9,
5466 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5467 			tdata->key.data, tdata->key.len,
5468 			0, tdata->digest.len,
5469 			tdata->cipher_iv.len);
5470 
5471 	if (retval != 0)
5472 		return retval;
5473 
5474 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5475 	if (op_mode == OUT_OF_PLACE)
5476 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5477 
5478 	/* clear mbuf payload */
5479 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5480 		rte_pktmbuf_tailroom(ut_params->ibuf));
5481 	if (op_mode == OUT_OF_PLACE)
5482 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5483 			rte_pktmbuf_tailroom(ut_params->obuf));
5484 
5485 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5486 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5487 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5488 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5489 
5490 	if (verify) {
5491 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5492 					ciphertext_pad_len);
5493 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5494 		if (op_mode == OUT_OF_PLACE)
5495 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5496 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5497 			ciphertext_len);
5498 	} else {
5499 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5500 					plaintext_pad_len);
5501 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5502 		if (op_mode == OUT_OF_PLACE)
5503 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5504 		debug_hexdump(stdout, "plaintext:", plaintext,
5505 			plaintext_len);
5506 	}
5507 
5508 	/* Create KASUMI operation */
5509 	retval = create_wireless_algo_auth_cipher_operation(
5510 		tdata->digest.data, tdata->digest.len,
5511 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5512 		NULL, 0,
5513 		(tdata->digest.offset_bytes == 0 ?
5514 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5515 			: tdata->digest.offset_bytes),
5516 		tdata->validCipherLenInBits.len,
5517 		tdata->validCipherOffsetInBits.len,
5518 		tdata->validAuthLenInBits.len,
5519 		0,
5520 		op_mode, 0, verify);
5521 
5522 	if (retval < 0)
5523 		return retval;
5524 
5525 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5526 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5527 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5528 	else
5529 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5530 			ut_params->op);
5531 
5532 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5533 
5534 	ut_params->obuf = (op_mode == IN_PLACE ?
5535 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5536 
5537 
5538 	if (verify) {
5539 		if (ut_params->obuf)
5540 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5541 							uint8_t *);
5542 		else
5543 			plaintext = ciphertext;
5544 
5545 		debug_hexdump(stdout, "plaintext:", plaintext,
5546 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5547 		debug_hexdump(stdout, "plaintext expected:",
5548 			tdata->plaintext.data,
5549 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5550 	} else {
5551 		if (ut_params->obuf)
5552 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5553 							uint8_t *);
5554 		else
5555 			ciphertext = plaintext;
5556 
5557 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5558 			ciphertext_len);
5559 		debug_hexdump(stdout, "ciphertext expected:",
5560 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5561 
5562 		ut_params->digest = rte_pktmbuf_mtod(
5563 			ut_params->obuf, uint8_t *) +
5564 			(tdata->digest.offset_bytes == 0 ?
5565 			plaintext_pad_len : tdata->digest.offset_bytes);
5566 
5567 		debug_hexdump(stdout, "digest:", ut_params->digest,
5568 			tdata->digest.len);
5569 		debug_hexdump(stdout, "digest expected:",
5570 			tdata->digest.data, tdata->digest.len);
5571 	}
5572 
5573 	/* Validate obuf */
5574 	if (verify) {
5575 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5576 			plaintext,
5577 			tdata->plaintext.data,
5578 			tdata->plaintext.len >> 3,
5579 			"KASUMI Plaintext data not as expected");
5580 	} else {
5581 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5582 			ciphertext,
5583 			tdata->ciphertext.data,
5584 			tdata->ciphertext.len >> 3,
5585 			"KASUMI Ciphertext data not as expected");
5586 
5587 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5588 			ut_params->digest,
5589 			tdata->digest.data,
5590 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5591 			"KASUMI Generated auth tag not as expected");
5592 	}
5593 	return 0;
5594 }
5595 
5596 static int
5597 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5598 	uint8_t op_mode, uint8_t verify)
5599 {
5600 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5601 	struct crypto_unittest_params *ut_params = &unittest_params;
5602 
5603 	int retval;
5604 
5605 	const uint8_t *plaintext = NULL;
5606 	const uint8_t *ciphertext = NULL;
5607 	const uint8_t *digest = NULL;
5608 	unsigned int plaintext_pad_len;
5609 	unsigned int plaintext_len;
5610 	unsigned int ciphertext_pad_len;
5611 	unsigned int ciphertext_len;
5612 	uint8_t buffer[10000];
5613 	uint8_t digest_buffer[10000];
5614 
5615 	struct rte_cryptodev_info dev_info;
5616 
5617 	/* Verify the capabilities */
5618 	struct rte_cryptodev_sym_capability_idx cap_idx;
5619 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5620 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5621 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5622 			&cap_idx) == NULL)
5623 		return TEST_SKIPPED;
5624 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5625 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5626 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5627 			&cap_idx) == NULL)
5628 		return TEST_SKIPPED;
5629 
5630 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5631 		return TEST_SKIPPED;
5632 
5633 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5634 
5635 	uint64_t feat_flags = dev_info.feature_flags;
5636 
5637 	if (op_mode == IN_PLACE) {
5638 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5639 			printf("Device doesn't support in-place scatter-gather "
5640 					"in both input and output mbufs.\n");
5641 			return TEST_SKIPPED;
5642 		}
5643 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5644 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5645 			printf("Device doesn't support RAW data-path APIs.\n");
5646 			return TEST_SKIPPED;
5647 		}
5648 	} else {
5649 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5650 			return TEST_SKIPPED;
5651 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5652 			printf("Device doesn't support out-of-place scatter-gather "
5653 					"in both input and output mbufs.\n");
5654 			return TEST_SKIPPED;
5655 		}
5656 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5657 			printf("Device doesn't support digest encrypted.\n");
5658 			return TEST_SKIPPED;
5659 		}
5660 	}
5661 
5662 	/* Create KASUMI session */
5663 	retval = create_wireless_algo_auth_cipher_session(
5664 			ts_params->valid_devs[0],
5665 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5666 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5667 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5668 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5669 			RTE_CRYPTO_AUTH_KASUMI_F9,
5670 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5671 			tdata->key.data, tdata->key.len,
5672 			0, tdata->digest.len,
5673 			tdata->cipher_iv.len);
5674 
5675 	if (retval != 0)
5676 		return retval;
5677 
5678 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5679 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5680 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5681 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5682 
5683 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5684 			plaintext_pad_len, 15, 0);
5685 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5686 			"Failed to allocate input buffer in mempool");
5687 
5688 	if (op_mode == OUT_OF_PLACE) {
5689 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5690 				plaintext_pad_len, 15, 0);
5691 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5692 				"Failed to allocate output buffer in mempool");
5693 	}
5694 
5695 	if (verify) {
5696 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5697 			tdata->ciphertext.data);
5698 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5699 					ciphertext_len, buffer);
5700 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5701 			ciphertext_len);
5702 	} else {
5703 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5704 			tdata->plaintext.data);
5705 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5706 					plaintext_len, buffer);
5707 		debug_hexdump(stdout, "plaintext:", plaintext,
5708 			plaintext_len);
5709 	}
5710 	memset(buffer, 0, sizeof(buffer));
5711 
5712 	/* Create KASUMI operation */
5713 	retval = create_wireless_algo_auth_cipher_operation(
5714 		tdata->digest.data, tdata->digest.len,
5715 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5716 		NULL, 0,
5717 		(tdata->digest.offset_bytes == 0 ?
5718 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5719 			: tdata->digest.offset_bytes),
5720 		tdata->validCipherLenInBits.len,
5721 		tdata->validCipherOffsetInBits.len,
5722 		tdata->validAuthLenInBits.len,
5723 		0,
5724 		op_mode, 1, verify);
5725 
5726 	if (retval < 0)
5727 		return retval;
5728 
5729 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5730 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5731 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5732 	else
5733 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5734 			ut_params->op);
5735 
5736 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5737 
5738 	ut_params->obuf = (op_mode == IN_PLACE ?
5739 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5740 
5741 	if (verify) {
5742 		if (ut_params->obuf)
5743 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5744 					plaintext_len, buffer);
5745 		else
5746 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5747 					plaintext_len, buffer);
5748 
5749 		debug_hexdump(stdout, "plaintext:", plaintext,
5750 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5751 		debug_hexdump(stdout, "plaintext expected:",
5752 			tdata->plaintext.data,
5753 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5754 	} else {
5755 		if (ut_params->obuf)
5756 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5757 					ciphertext_len, buffer);
5758 		else
5759 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5760 					ciphertext_len, buffer);
5761 
5762 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5763 			ciphertext_len);
5764 		debug_hexdump(stdout, "ciphertext expected:",
5765 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5766 
5767 		if (ut_params->obuf)
5768 			digest = rte_pktmbuf_read(ut_params->obuf,
5769 				(tdata->digest.offset_bytes == 0 ?
5770 				plaintext_pad_len : tdata->digest.offset_bytes),
5771 				tdata->digest.len, digest_buffer);
5772 		else
5773 			digest = rte_pktmbuf_read(ut_params->ibuf,
5774 				(tdata->digest.offset_bytes == 0 ?
5775 				plaintext_pad_len : tdata->digest.offset_bytes),
5776 				tdata->digest.len, digest_buffer);
5777 
5778 		debug_hexdump(stdout, "digest:", digest,
5779 			tdata->digest.len);
5780 		debug_hexdump(stdout, "digest expected:",
5781 			tdata->digest.data, tdata->digest.len);
5782 	}
5783 
5784 	/* Validate obuf */
5785 	if (verify) {
5786 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5787 			plaintext,
5788 			tdata->plaintext.data,
5789 			tdata->plaintext.len >> 3,
5790 			"KASUMI Plaintext data not as expected");
5791 	} else {
5792 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5793 			ciphertext,
5794 			tdata->ciphertext.data,
5795 			tdata->validDataLenInBits.len,
5796 			"KASUMI Ciphertext data not as expected");
5797 
5798 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5799 			digest,
5800 			tdata->digest.data,
5801 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5802 			"KASUMI Generated auth tag not as expected");
5803 	}
5804 	return 0;
5805 }
5806 
5807 static int
5808 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5809 {
5810 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5811 	struct crypto_unittest_params *ut_params = &unittest_params;
5812 
5813 	int retval;
5814 
5815 	uint8_t *plaintext, *ciphertext;
5816 	unsigned plaintext_pad_len;
5817 	unsigned plaintext_len;
5818 	struct rte_cryptodev_info dev_info;
5819 
5820 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5821 	uint64_t feat_flags = dev_info.feature_flags;
5822 
5823 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5824 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5825 		printf("Device doesn't support RAW data-path APIs.\n");
5826 		return TEST_SKIPPED;
5827 	}
5828 
5829 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5830 		return TEST_SKIPPED;
5831 
5832 	/* Verify the capabilities */
5833 	struct rte_cryptodev_sym_capability_idx cap_idx;
5834 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5835 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5836 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5837 			&cap_idx) == NULL)
5838 		return TEST_SKIPPED;
5839 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5840 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5841 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5842 			&cap_idx) == NULL)
5843 		return TEST_SKIPPED;
5844 
5845 	/* Create KASUMI session */
5846 	retval = create_wireless_algo_cipher_auth_session(
5847 			ts_params->valid_devs[0],
5848 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5849 			RTE_CRYPTO_AUTH_OP_GENERATE,
5850 			RTE_CRYPTO_AUTH_KASUMI_F9,
5851 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5852 			tdata->key.data, tdata->key.len,
5853 			0, tdata->digest.len,
5854 			tdata->cipher_iv.len);
5855 	if (retval != 0)
5856 		return retval;
5857 
5858 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5859 
5860 	/* clear mbuf payload */
5861 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5862 			rte_pktmbuf_tailroom(ut_params->ibuf));
5863 
5864 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5865 	/* Append data which is padded to a multiple of */
5866 	/* the algorithms block size */
5867 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5868 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5869 				plaintext_pad_len);
5870 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5871 
5872 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5873 
5874 	/* Create KASUMI operation */
5875 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5876 				tdata->digest.len, NULL, 0,
5877 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5878 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5879 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5880 				tdata->validCipherOffsetInBits.len,
5881 				tdata->validAuthLenInBits.len,
5882 				0
5883 				);
5884 	if (retval < 0)
5885 		return retval;
5886 
5887 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5888 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5889 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5890 	else
5891 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5892 			ut_params->op);
5893 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5894 
5895 	if (ut_params->op->sym->m_dst)
5896 		ut_params->obuf = ut_params->op->sym->m_dst;
5897 	else
5898 		ut_params->obuf = ut_params->op->sym->m_src;
5899 
5900 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5901 				tdata->validCipherOffsetInBits.len >> 3);
5902 
5903 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5904 			+ plaintext_pad_len;
5905 
5906 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5907 				(tdata->validCipherOffsetInBits.len >> 3);
5908 	/* Validate obuf */
5909 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5910 		ciphertext,
5911 		reference_ciphertext,
5912 		tdata->validCipherLenInBits.len,
5913 		"KASUMI Ciphertext data not as expected");
5914 
5915 	/* Validate obuf */
5916 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5917 		ut_params->digest,
5918 		tdata->digest.data,
5919 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5920 		"KASUMI Generated auth tag not as expected");
5921 	return 0;
5922 }
5923 
5924 static int
5925 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5926 			const enum rte_crypto_cipher_algorithm cipher_algo,
5927 			const uint16_t key_size, const uint16_t iv_size)
5928 {
5929 	struct rte_cryptodev_sym_capability_idx cap_idx;
5930 	const struct rte_cryptodev_symmetric_capability *cap;
5931 
5932 	/* Check if device supports the algorithm */
5933 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5934 	cap_idx.algo.cipher = cipher_algo;
5935 
5936 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5937 			&cap_idx);
5938 
5939 	if (cap == NULL)
5940 		return -1;
5941 
5942 	/* Check if device supports key size and IV size */
5943 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5944 			iv_size) < 0) {
5945 		return -1;
5946 	}
5947 
5948 	return 0;
5949 }
5950 
5951 static int
5952 check_auth_capability(const struct crypto_testsuite_params *ts_params,
5953 			const enum rte_crypto_auth_algorithm auth_algo,
5954 			const uint16_t key_size, const uint16_t iv_size,
5955 			const uint16_t tag_size)
5956 {
5957 	struct rte_cryptodev_sym_capability_idx cap_idx;
5958 	const struct rte_cryptodev_symmetric_capability *cap;
5959 
5960 	/* Check if device supports the algorithm */
5961 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5962 	cap_idx.algo.auth = auth_algo;
5963 
5964 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5965 			&cap_idx);
5966 
5967 	if (cap == NULL)
5968 		return -1;
5969 
5970 	/* Check if device supports key size and IV size */
5971 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
5972 			tag_size, iv_size) < 0) {
5973 		return -1;
5974 	}
5975 
5976 	return 0;
5977 }
5978 
5979 static int
5980 test_zuc_encryption(const struct wireless_test_data *tdata)
5981 {
5982 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5983 	struct crypto_unittest_params *ut_params = &unittest_params;
5984 
5985 	int retval;
5986 	uint8_t *plaintext, *ciphertext;
5987 	unsigned plaintext_pad_len;
5988 	unsigned plaintext_len;
5989 	struct rte_cryptodev_info dev_info;
5990 
5991 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5992 	uint64_t feat_flags = dev_info.feature_flags;
5993 
5994 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5995 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5996 		printf("Device doesn't support RAW data-path APIs.\n");
5997 		return TEST_SKIPPED;
5998 	}
5999 
6000 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6001 		return TEST_SKIPPED;
6002 
6003 	/* Check if device supports ZUC EEA3 */
6004 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6005 			tdata->key.len, tdata->cipher_iv.len) < 0)
6006 		return TEST_SKIPPED;
6007 
6008 	/* Create ZUC session */
6009 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6010 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6011 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
6012 					tdata->key.data, tdata->key.len,
6013 					tdata->cipher_iv.len);
6014 	if (retval != 0)
6015 		return retval;
6016 
6017 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6018 
6019 	/* Clear mbuf payload */
6020 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6021 	       rte_pktmbuf_tailroom(ut_params->ibuf));
6022 
6023 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6024 	/* Append data which is padded to a multiple */
6025 	/* of the algorithms block size */
6026 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6027 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6028 				plaintext_pad_len);
6029 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6030 
6031 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6032 
6033 	/* Create ZUC operation */
6034 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6035 					tdata->cipher_iv.len,
6036 					tdata->plaintext.len,
6037 					0);
6038 	if (retval < 0)
6039 		return retval;
6040 
6041 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6042 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6043 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6044 	else
6045 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6046 						ut_params->op);
6047 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6048 
6049 	ut_params->obuf = ut_params->op->sym->m_dst;
6050 	if (ut_params->obuf)
6051 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6052 	else
6053 		ciphertext = plaintext;
6054 
6055 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6056 
6057 	/* Validate obuf */
6058 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6059 		ciphertext,
6060 		tdata->ciphertext.data,
6061 		tdata->validCipherLenInBits.len,
6062 		"ZUC Ciphertext data not as expected");
6063 	return 0;
6064 }
6065 
6066 static int
6067 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
6068 {
6069 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6070 	struct crypto_unittest_params *ut_params = &unittest_params;
6071 
6072 	int retval;
6073 
6074 	unsigned int plaintext_pad_len;
6075 	unsigned int plaintext_len;
6076 	const uint8_t *ciphertext;
6077 	uint8_t ciphertext_buffer[2048];
6078 	struct rte_cryptodev_info dev_info;
6079 
6080 	/* Check if device supports ZUC EEA3 */
6081 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6082 			tdata->key.len, tdata->cipher_iv.len) < 0)
6083 		return TEST_SKIPPED;
6084 
6085 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6086 		return TEST_SKIPPED;
6087 
6088 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6089 
6090 	uint64_t feat_flags = dev_info.feature_flags;
6091 
6092 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6093 		printf("Device doesn't support in-place scatter-gather. "
6094 				"Test Skipped.\n");
6095 		return TEST_SKIPPED;
6096 	}
6097 
6098 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6099 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6100 		printf("Device doesn't support RAW data-path APIs.\n");
6101 		return TEST_SKIPPED;
6102 	}
6103 
6104 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6105 
6106 	/* Append data which is padded to a multiple */
6107 	/* of the algorithms block size */
6108 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6109 
6110 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6111 			plaintext_pad_len, 10, 0);
6112 
6113 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6114 			tdata->plaintext.data);
6115 
6116 	/* Create ZUC session */
6117 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6118 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6119 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6120 			tdata->key.data, tdata->key.len,
6121 			tdata->cipher_iv.len);
6122 	if (retval < 0)
6123 		return retval;
6124 
6125 	/* Clear mbuf payload */
6126 
6127 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6128 
6129 	/* Create ZUC operation */
6130 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6131 			tdata->cipher_iv.len, tdata->plaintext.len,
6132 			0);
6133 	if (retval < 0)
6134 		return retval;
6135 
6136 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6137 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6138 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6139 	else
6140 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6141 						ut_params->op);
6142 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6143 
6144 	ut_params->obuf = ut_params->op->sym->m_dst;
6145 	if (ut_params->obuf)
6146 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6147 			0, plaintext_len, ciphertext_buffer);
6148 	else
6149 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6150 			0, plaintext_len, ciphertext_buffer);
6151 
6152 	/* Validate obuf */
6153 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6154 
6155 	/* Validate obuf */
6156 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6157 		ciphertext,
6158 		tdata->ciphertext.data,
6159 		tdata->validCipherLenInBits.len,
6160 		"ZUC Ciphertext data not as expected");
6161 
6162 	return 0;
6163 }
6164 
6165 static int
6166 test_zuc_authentication(const struct wireless_test_data *tdata)
6167 {
6168 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6169 	struct crypto_unittest_params *ut_params = &unittest_params;
6170 
6171 	int retval;
6172 	unsigned plaintext_pad_len;
6173 	unsigned plaintext_len;
6174 	uint8_t *plaintext;
6175 
6176 	struct rte_cryptodev_info dev_info;
6177 
6178 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6179 	uint64_t feat_flags = dev_info.feature_flags;
6180 
6181 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6182 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6183 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6184 		return TEST_SKIPPED;
6185 	}
6186 
6187 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6188 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6189 		printf("Device doesn't support RAW data-path APIs.\n");
6190 		return TEST_SKIPPED;
6191 	}
6192 
6193 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6194 		return TEST_SKIPPED;
6195 
6196 	/* Check if device supports ZUC EIA3 */
6197 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6198 			tdata->key.len, tdata->auth_iv.len,
6199 			tdata->digest.len) < 0)
6200 		return TEST_SKIPPED;
6201 
6202 	/* Create ZUC session */
6203 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6204 			tdata->key.data, tdata->key.len,
6205 			tdata->auth_iv.len, tdata->digest.len,
6206 			RTE_CRYPTO_AUTH_OP_GENERATE,
6207 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6208 	if (retval != 0)
6209 		return retval;
6210 
6211 	/* alloc mbuf and set payload */
6212 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6213 
6214 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6215 	rte_pktmbuf_tailroom(ut_params->ibuf));
6216 
6217 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6218 	/* Append data which is padded to a multiple of */
6219 	/* the algorithms block size */
6220 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6221 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6222 				plaintext_pad_len);
6223 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6224 
6225 	/* Create ZUC operation */
6226 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6227 			tdata->auth_iv.data, tdata->auth_iv.len,
6228 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6229 			tdata->validAuthLenInBits.len,
6230 			0);
6231 	if (retval < 0)
6232 		return retval;
6233 
6234 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6235 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6236 				ut_params->op, 0, 1, 1, 0);
6237 	else
6238 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6239 				ut_params->op);
6240 	ut_params->obuf = ut_params->op->sym->m_src;
6241 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6242 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6243 			+ plaintext_pad_len;
6244 
6245 	/* Validate obuf */
6246 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6247 	ut_params->digest,
6248 	tdata->digest.data,
6249 	tdata->digest.len,
6250 	"ZUC Generated auth tag not as expected");
6251 
6252 	return 0;
6253 }
6254 
6255 static int
6256 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6257 	uint8_t op_mode, uint8_t verify)
6258 {
6259 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6260 	struct crypto_unittest_params *ut_params = &unittest_params;
6261 
6262 	int retval;
6263 
6264 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6265 	unsigned int plaintext_pad_len;
6266 	unsigned int plaintext_len;
6267 	unsigned int ciphertext_pad_len;
6268 	unsigned int ciphertext_len;
6269 
6270 	struct rte_cryptodev_info dev_info;
6271 
6272 	/* Check if device supports ZUC EEA3 */
6273 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6274 			tdata->key.len, tdata->cipher_iv.len) < 0)
6275 		return TEST_SKIPPED;
6276 
6277 	/* Check if device supports ZUC EIA3 */
6278 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6279 			tdata->key.len, tdata->auth_iv.len,
6280 			tdata->digest.len) < 0)
6281 		return TEST_SKIPPED;
6282 
6283 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6284 
6285 	uint64_t feat_flags = dev_info.feature_flags;
6286 
6287 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6288 		printf("Device doesn't support digest encrypted.\n");
6289 		return TEST_SKIPPED;
6290 	}
6291 	if (op_mode == IN_PLACE) {
6292 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6293 			printf("Device doesn't support in-place scatter-gather "
6294 					"in both input and output mbufs.\n");
6295 			return TEST_SKIPPED;
6296 		}
6297 
6298 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6299 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6300 			printf("Device doesn't support RAW data-path APIs.\n");
6301 			return TEST_SKIPPED;
6302 		}
6303 	} else {
6304 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6305 			return TEST_SKIPPED;
6306 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6307 			printf("Device doesn't support out-of-place scatter-gather "
6308 					"in both input and output mbufs.\n");
6309 			return TEST_SKIPPED;
6310 		}
6311 	}
6312 
6313 	/* Create ZUC session */
6314 	retval = create_wireless_algo_auth_cipher_session(
6315 			ts_params->valid_devs[0],
6316 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6317 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6318 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6319 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6320 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6321 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6322 			tdata->key.data, tdata->key.len,
6323 			tdata->auth_iv.len, tdata->digest.len,
6324 			tdata->cipher_iv.len);
6325 
6326 	if (retval != 0)
6327 		return retval;
6328 
6329 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6330 	if (op_mode == OUT_OF_PLACE)
6331 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6332 
6333 	/* clear mbuf payload */
6334 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6335 		rte_pktmbuf_tailroom(ut_params->ibuf));
6336 	if (op_mode == OUT_OF_PLACE)
6337 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6338 			rte_pktmbuf_tailroom(ut_params->obuf));
6339 
6340 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6341 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6342 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6343 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6344 
6345 	if (verify) {
6346 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6347 					ciphertext_pad_len);
6348 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6349 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6350 			ciphertext_len);
6351 	} else {
6352 		/* make sure enough space to cover partial digest verify case */
6353 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6354 					ciphertext_pad_len);
6355 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6356 		debug_hexdump(stdout, "plaintext:", plaintext,
6357 			plaintext_len);
6358 	}
6359 
6360 	if (op_mode == OUT_OF_PLACE)
6361 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6362 
6363 	/* Create ZUC operation */
6364 	retval = create_wireless_algo_auth_cipher_operation(
6365 		tdata->digest.data, tdata->digest.len,
6366 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6367 		tdata->auth_iv.data, tdata->auth_iv.len,
6368 		(tdata->digest.offset_bytes == 0 ?
6369 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6370 			: tdata->digest.offset_bytes),
6371 		tdata->validCipherLenInBits.len,
6372 		tdata->validCipherOffsetInBits.len,
6373 		tdata->validAuthLenInBits.len,
6374 		0,
6375 		op_mode, 0, verify);
6376 
6377 	if (retval < 0)
6378 		return retval;
6379 
6380 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6381 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6382 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6383 	else
6384 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6385 			ut_params->op);
6386 
6387 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6388 
6389 	ut_params->obuf = (op_mode == IN_PLACE ?
6390 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6391 
6392 
6393 	if (verify) {
6394 		if (ut_params->obuf)
6395 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6396 							uint8_t *);
6397 		else
6398 			plaintext = ciphertext;
6399 
6400 		debug_hexdump(stdout, "plaintext:", plaintext,
6401 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6402 		debug_hexdump(stdout, "plaintext expected:",
6403 			tdata->plaintext.data,
6404 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6405 	} else {
6406 		if (ut_params->obuf)
6407 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6408 							uint8_t *);
6409 		else
6410 			ciphertext = plaintext;
6411 
6412 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6413 			ciphertext_len);
6414 		debug_hexdump(stdout, "ciphertext expected:",
6415 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6416 
6417 		ut_params->digest = rte_pktmbuf_mtod(
6418 			ut_params->obuf, uint8_t *) +
6419 			(tdata->digest.offset_bytes == 0 ?
6420 			plaintext_pad_len : tdata->digest.offset_bytes);
6421 
6422 		debug_hexdump(stdout, "digest:", ut_params->digest,
6423 			tdata->digest.len);
6424 		debug_hexdump(stdout, "digest expected:",
6425 			tdata->digest.data, tdata->digest.len);
6426 	}
6427 
6428 	/* Validate obuf */
6429 	if (verify) {
6430 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6431 			plaintext,
6432 			tdata->plaintext.data,
6433 			tdata->plaintext.len >> 3,
6434 			"ZUC Plaintext data not as expected");
6435 	} else {
6436 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6437 			ciphertext,
6438 			tdata->ciphertext.data,
6439 			tdata->ciphertext.len >> 3,
6440 			"ZUC Ciphertext data not as expected");
6441 
6442 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6443 			ut_params->digest,
6444 			tdata->digest.data,
6445 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6446 			"ZUC Generated auth tag not as expected");
6447 	}
6448 	return 0;
6449 }
6450 
6451 static int
6452 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6453 	uint8_t op_mode, uint8_t verify)
6454 {
6455 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6456 	struct crypto_unittest_params *ut_params = &unittest_params;
6457 
6458 	int retval;
6459 
6460 	const uint8_t *plaintext = NULL;
6461 	const uint8_t *ciphertext = NULL;
6462 	const uint8_t *digest = NULL;
6463 	unsigned int plaintext_pad_len;
6464 	unsigned int plaintext_len;
6465 	unsigned int ciphertext_pad_len;
6466 	unsigned int ciphertext_len;
6467 	uint8_t buffer[10000];
6468 	uint8_t digest_buffer[10000];
6469 
6470 	struct rte_cryptodev_info dev_info;
6471 
6472 	/* Check if device supports ZUC EEA3 */
6473 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6474 			tdata->key.len, tdata->cipher_iv.len) < 0)
6475 		return TEST_SKIPPED;
6476 
6477 	/* Check if device supports ZUC EIA3 */
6478 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6479 			tdata->key.len, tdata->auth_iv.len,
6480 			tdata->digest.len) < 0)
6481 		return TEST_SKIPPED;
6482 
6483 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6484 
6485 	uint64_t feat_flags = dev_info.feature_flags;
6486 
6487 	if (op_mode == IN_PLACE) {
6488 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6489 			printf("Device doesn't support in-place scatter-gather "
6490 					"in both input and output mbufs.\n");
6491 			return TEST_SKIPPED;
6492 		}
6493 
6494 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6495 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6496 			printf("Device doesn't support RAW data-path APIs.\n");
6497 			return TEST_SKIPPED;
6498 		}
6499 	} else {
6500 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6501 			return TEST_SKIPPED;
6502 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6503 			printf("Device doesn't support out-of-place scatter-gather "
6504 					"in both input and output mbufs.\n");
6505 			return TEST_SKIPPED;
6506 		}
6507 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6508 			printf("Device doesn't support digest encrypted.\n");
6509 			return TEST_SKIPPED;
6510 		}
6511 	}
6512 
6513 	/* Create ZUC session */
6514 	retval = create_wireless_algo_auth_cipher_session(
6515 			ts_params->valid_devs[0],
6516 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6517 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6518 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6519 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6520 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6521 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6522 			tdata->key.data, tdata->key.len,
6523 			tdata->auth_iv.len, tdata->digest.len,
6524 			tdata->cipher_iv.len);
6525 
6526 	if (retval != 0)
6527 		return retval;
6528 
6529 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6530 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6531 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6532 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6533 
6534 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6535 			plaintext_pad_len, 15, 0);
6536 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6537 			"Failed to allocate input buffer in mempool");
6538 
6539 	if (op_mode == OUT_OF_PLACE) {
6540 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6541 				plaintext_pad_len, 15, 0);
6542 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6543 				"Failed to allocate output buffer in mempool");
6544 	}
6545 
6546 	if (verify) {
6547 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6548 			tdata->ciphertext.data);
6549 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6550 					ciphertext_len, buffer);
6551 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6552 			ciphertext_len);
6553 	} else {
6554 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6555 			tdata->plaintext.data);
6556 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6557 					plaintext_len, buffer);
6558 		debug_hexdump(stdout, "plaintext:", plaintext,
6559 			plaintext_len);
6560 	}
6561 	memset(buffer, 0, sizeof(buffer));
6562 
6563 	/* Create ZUC operation */
6564 	retval = create_wireless_algo_auth_cipher_operation(
6565 		tdata->digest.data, tdata->digest.len,
6566 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6567 		NULL, 0,
6568 		(tdata->digest.offset_bytes == 0 ?
6569 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6570 			: tdata->digest.offset_bytes),
6571 		tdata->validCipherLenInBits.len,
6572 		tdata->validCipherOffsetInBits.len,
6573 		tdata->validAuthLenInBits.len,
6574 		0,
6575 		op_mode, 1, verify);
6576 
6577 	if (retval < 0)
6578 		return retval;
6579 
6580 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6581 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6582 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6583 	else
6584 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6585 			ut_params->op);
6586 
6587 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6588 
6589 	ut_params->obuf = (op_mode == IN_PLACE ?
6590 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6591 
6592 	if (verify) {
6593 		if (ut_params->obuf)
6594 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6595 					plaintext_len, buffer);
6596 		else
6597 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6598 					plaintext_len, buffer);
6599 
6600 		debug_hexdump(stdout, "plaintext:", plaintext,
6601 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6602 		debug_hexdump(stdout, "plaintext expected:",
6603 			tdata->plaintext.data,
6604 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6605 	} else {
6606 		if (ut_params->obuf)
6607 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6608 					ciphertext_len, buffer);
6609 		else
6610 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6611 					ciphertext_len, buffer);
6612 
6613 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6614 			ciphertext_len);
6615 		debug_hexdump(stdout, "ciphertext expected:",
6616 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6617 
6618 		if (ut_params->obuf)
6619 			digest = rte_pktmbuf_read(ut_params->obuf,
6620 				(tdata->digest.offset_bytes == 0 ?
6621 				plaintext_pad_len : tdata->digest.offset_bytes),
6622 				tdata->digest.len, digest_buffer);
6623 		else
6624 			digest = rte_pktmbuf_read(ut_params->ibuf,
6625 				(tdata->digest.offset_bytes == 0 ?
6626 				plaintext_pad_len : tdata->digest.offset_bytes),
6627 				tdata->digest.len, digest_buffer);
6628 
6629 		debug_hexdump(stdout, "digest:", digest,
6630 			tdata->digest.len);
6631 		debug_hexdump(stdout, "digest expected:",
6632 			tdata->digest.data, tdata->digest.len);
6633 	}
6634 
6635 	/* Validate obuf */
6636 	if (verify) {
6637 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6638 			plaintext,
6639 			tdata->plaintext.data,
6640 			tdata->plaintext.len >> 3,
6641 			"ZUC Plaintext data not as expected");
6642 	} else {
6643 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6644 			ciphertext,
6645 			tdata->ciphertext.data,
6646 			tdata->validDataLenInBits.len,
6647 			"ZUC Ciphertext data not as expected");
6648 
6649 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6650 			digest,
6651 			tdata->digest.data,
6652 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6653 			"ZUC Generated auth tag not as expected");
6654 	}
6655 	return 0;
6656 }
6657 
6658 static int
6659 test_kasumi_encryption_test_case_1(void)
6660 {
6661 	return test_kasumi_encryption(&kasumi_test_case_1);
6662 }
6663 
6664 static int
6665 test_kasumi_encryption_test_case_1_sgl(void)
6666 {
6667 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6668 }
6669 
6670 static int
6671 test_kasumi_encryption_test_case_1_oop(void)
6672 {
6673 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6674 }
6675 
6676 static int
6677 test_kasumi_encryption_test_case_1_oop_sgl(void)
6678 {
6679 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6680 }
6681 
6682 static int
6683 test_kasumi_encryption_test_case_2(void)
6684 {
6685 	return test_kasumi_encryption(&kasumi_test_case_2);
6686 }
6687 
6688 static int
6689 test_kasumi_encryption_test_case_3(void)
6690 {
6691 	return test_kasumi_encryption(&kasumi_test_case_3);
6692 }
6693 
6694 static int
6695 test_kasumi_encryption_test_case_4(void)
6696 {
6697 	return test_kasumi_encryption(&kasumi_test_case_4);
6698 }
6699 
6700 static int
6701 test_kasumi_encryption_test_case_5(void)
6702 {
6703 	return test_kasumi_encryption(&kasumi_test_case_5);
6704 }
6705 
6706 static int
6707 test_kasumi_decryption_test_case_1(void)
6708 {
6709 	return test_kasumi_decryption(&kasumi_test_case_1);
6710 }
6711 
6712 static int
6713 test_kasumi_decryption_test_case_1_oop(void)
6714 {
6715 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6716 }
6717 
6718 static int
6719 test_kasumi_decryption_test_case_2(void)
6720 {
6721 	return test_kasumi_decryption(&kasumi_test_case_2);
6722 }
6723 
6724 static int
6725 test_kasumi_decryption_test_case_3(void)
6726 {
6727 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6728 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6729 		return TEST_SKIPPED;
6730 	return test_kasumi_decryption(&kasumi_test_case_3);
6731 }
6732 
6733 static int
6734 test_kasumi_decryption_test_case_4(void)
6735 {
6736 	return test_kasumi_decryption(&kasumi_test_case_4);
6737 }
6738 
6739 static int
6740 test_kasumi_decryption_test_case_5(void)
6741 {
6742 	return test_kasumi_decryption(&kasumi_test_case_5);
6743 }
6744 static int
6745 test_snow3g_encryption_test_case_1(void)
6746 {
6747 	return test_snow3g_encryption(&snow3g_test_case_1);
6748 }
6749 
6750 static int
6751 test_snow3g_encryption_test_case_1_oop(void)
6752 {
6753 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6754 }
6755 
6756 static int
6757 test_snow3g_encryption_test_case_1_oop_sgl(void)
6758 {
6759 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6760 }
6761 
6762 
6763 static int
6764 test_snow3g_encryption_test_case_1_offset_oop(void)
6765 {
6766 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6767 }
6768 
6769 static int
6770 test_snow3g_encryption_test_case_2(void)
6771 {
6772 	return test_snow3g_encryption(&snow3g_test_case_2);
6773 }
6774 
6775 static int
6776 test_snow3g_encryption_test_case_3(void)
6777 {
6778 	return test_snow3g_encryption(&snow3g_test_case_3);
6779 }
6780 
6781 static int
6782 test_snow3g_encryption_test_case_4(void)
6783 {
6784 	return test_snow3g_encryption(&snow3g_test_case_4);
6785 }
6786 
6787 static int
6788 test_snow3g_encryption_test_case_5(void)
6789 {
6790 	return test_snow3g_encryption(&snow3g_test_case_5);
6791 }
6792 
6793 static int
6794 test_snow3g_decryption_test_case_1(void)
6795 {
6796 	return test_snow3g_decryption(&snow3g_test_case_1);
6797 }
6798 
6799 static int
6800 test_snow3g_decryption_test_case_1_oop(void)
6801 {
6802 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6803 }
6804 
6805 static int
6806 test_snow3g_decryption_test_case_2(void)
6807 {
6808 	return test_snow3g_decryption(&snow3g_test_case_2);
6809 }
6810 
6811 static int
6812 test_snow3g_decryption_test_case_3(void)
6813 {
6814 	return test_snow3g_decryption(&snow3g_test_case_3);
6815 }
6816 
6817 static int
6818 test_snow3g_decryption_test_case_4(void)
6819 {
6820 	return test_snow3g_decryption(&snow3g_test_case_4);
6821 }
6822 
6823 static int
6824 test_snow3g_decryption_test_case_5(void)
6825 {
6826 	return test_snow3g_decryption(&snow3g_test_case_5);
6827 }
6828 
6829 /*
6830  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6831  * Pattern digest from snow3g_test_data must be allocated as
6832  * 4 last bytes in plaintext.
6833  */
6834 static void
6835 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6836 		struct snow3g_hash_test_data *output)
6837 {
6838 	if ((pattern != NULL) && (output != NULL)) {
6839 		output->key.len = pattern->key.len;
6840 
6841 		memcpy(output->key.data,
6842 		pattern->key.data, pattern->key.len);
6843 
6844 		output->auth_iv.len = pattern->auth_iv.len;
6845 
6846 		memcpy(output->auth_iv.data,
6847 		pattern->auth_iv.data, pattern->auth_iv.len);
6848 
6849 		output->plaintext.len = pattern->plaintext.len;
6850 
6851 		memcpy(output->plaintext.data,
6852 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6853 
6854 		output->digest.len = pattern->digest.len;
6855 
6856 		memcpy(output->digest.data,
6857 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6858 		pattern->digest.len);
6859 
6860 		output->validAuthLenInBits.len =
6861 		pattern->validAuthLenInBits.len;
6862 	}
6863 }
6864 
6865 /*
6866  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6867  */
6868 static int
6869 test_snow3g_decryption_with_digest_test_case_1(void)
6870 {
6871 	struct snow3g_hash_test_data snow3g_hash_data;
6872 	struct rte_cryptodev_info dev_info;
6873 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6874 
6875 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6876 	uint64_t feat_flags = dev_info.feature_flags;
6877 
6878 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6879 		printf("Device doesn't support encrypted digest operations.\n");
6880 		return TEST_SKIPPED;
6881 	}
6882 
6883 	/*
6884 	 * Function prepare data for hash verification test case.
6885 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6886 	 */
6887 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6888 
6889 	return test_snow3g_decryption(&snow3g_test_case_7) &
6890 			test_snow3g_authentication_verify(&snow3g_hash_data);
6891 }
6892 
6893 static int
6894 test_snow3g_cipher_auth_test_case_1(void)
6895 {
6896 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6897 }
6898 
6899 static int
6900 test_snow3g_auth_cipher_test_case_1(void)
6901 {
6902 	return test_snow3g_auth_cipher(
6903 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6904 }
6905 
6906 static int
6907 test_snow3g_auth_cipher_test_case_2(void)
6908 {
6909 	return test_snow3g_auth_cipher(
6910 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6911 }
6912 
6913 static int
6914 test_snow3g_auth_cipher_test_case_2_oop(void)
6915 {
6916 	return test_snow3g_auth_cipher(
6917 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6918 }
6919 
6920 static int
6921 test_snow3g_auth_cipher_part_digest_enc(void)
6922 {
6923 	return test_snow3g_auth_cipher(
6924 		&snow3g_auth_cipher_partial_digest_encryption,
6925 			IN_PLACE, 0);
6926 }
6927 
6928 static int
6929 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6930 {
6931 	return test_snow3g_auth_cipher(
6932 		&snow3g_auth_cipher_partial_digest_encryption,
6933 			OUT_OF_PLACE, 0);
6934 }
6935 
6936 static int
6937 test_snow3g_auth_cipher_test_case_3_sgl(void)
6938 {
6939 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6940 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6941 		return TEST_SKIPPED;
6942 	return test_snow3g_auth_cipher_sgl(
6943 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6944 }
6945 
6946 static int
6947 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6948 {
6949 	return test_snow3g_auth_cipher_sgl(
6950 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6951 }
6952 
6953 static int
6954 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6955 {
6956 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6957 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6958 		return TEST_SKIPPED;
6959 	return test_snow3g_auth_cipher_sgl(
6960 		&snow3g_auth_cipher_partial_digest_encryption,
6961 			IN_PLACE, 0);
6962 }
6963 
6964 static int
6965 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6966 {
6967 	return test_snow3g_auth_cipher_sgl(
6968 		&snow3g_auth_cipher_partial_digest_encryption,
6969 			OUT_OF_PLACE, 0);
6970 }
6971 
6972 static int
6973 test_snow3g_auth_cipher_verify_test_case_1(void)
6974 {
6975 	return test_snow3g_auth_cipher(
6976 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6977 }
6978 
6979 static int
6980 test_snow3g_auth_cipher_verify_test_case_2(void)
6981 {
6982 	return test_snow3g_auth_cipher(
6983 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6984 }
6985 
6986 static int
6987 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6988 {
6989 	return test_snow3g_auth_cipher(
6990 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6991 }
6992 
6993 static int
6994 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6995 {
6996 	return test_snow3g_auth_cipher(
6997 		&snow3g_auth_cipher_partial_digest_encryption,
6998 			IN_PLACE, 1);
6999 }
7000 
7001 static int
7002 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
7003 {
7004 	return test_snow3g_auth_cipher(
7005 		&snow3g_auth_cipher_partial_digest_encryption,
7006 			OUT_OF_PLACE, 1);
7007 }
7008 
7009 static int
7010 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
7011 {
7012 	return test_snow3g_auth_cipher_sgl(
7013 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
7014 }
7015 
7016 static int
7017 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7018 {
7019 	return test_snow3g_auth_cipher_sgl(
7020 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7021 }
7022 
7023 static int
7024 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7025 {
7026 	return test_snow3g_auth_cipher_sgl(
7027 		&snow3g_auth_cipher_partial_digest_encryption,
7028 			IN_PLACE, 1);
7029 }
7030 
7031 static int
7032 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7033 {
7034 	return test_snow3g_auth_cipher_sgl(
7035 		&snow3g_auth_cipher_partial_digest_encryption,
7036 			OUT_OF_PLACE, 1);
7037 }
7038 
7039 static int
7040 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7041 {
7042 	return test_snow3g_auth_cipher(
7043 		&snow3g_test_case_7, IN_PLACE, 0);
7044 }
7045 
7046 static int
7047 test_kasumi_auth_cipher_test_case_1(void)
7048 {
7049 	return test_kasumi_auth_cipher(
7050 		&kasumi_test_case_3, IN_PLACE, 0);
7051 }
7052 
7053 static int
7054 test_kasumi_auth_cipher_test_case_2(void)
7055 {
7056 	return test_kasumi_auth_cipher(
7057 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7058 }
7059 
7060 static int
7061 test_kasumi_auth_cipher_test_case_2_oop(void)
7062 {
7063 	return test_kasumi_auth_cipher(
7064 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7065 }
7066 
7067 static int
7068 test_kasumi_auth_cipher_test_case_2_sgl(void)
7069 {
7070 	return test_kasumi_auth_cipher_sgl(
7071 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7072 }
7073 
7074 static int
7075 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7076 {
7077 	return test_kasumi_auth_cipher_sgl(
7078 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7079 }
7080 
7081 static int
7082 test_kasumi_auth_cipher_verify_test_case_1(void)
7083 {
7084 	return test_kasumi_auth_cipher(
7085 		&kasumi_test_case_3, IN_PLACE, 1);
7086 }
7087 
7088 static int
7089 test_kasumi_auth_cipher_verify_test_case_2(void)
7090 {
7091 	return test_kasumi_auth_cipher(
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(void)
7097 {
7098 	return test_kasumi_auth_cipher(
7099 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7100 }
7101 
7102 static int
7103 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7104 {
7105 	return test_kasumi_auth_cipher_sgl(
7106 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7107 }
7108 
7109 static int
7110 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7111 {
7112 	return test_kasumi_auth_cipher_sgl(
7113 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7114 }
7115 
7116 static int
7117 test_kasumi_cipher_auth_test_case_1(void)
7118 {
7119 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7120 }
7121 
7122 static int
7123 test_zuc_encryption_test_case_1(void)
7124 {
7125 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
7126 }
7127 
7128 static int
7129 test_zuc_encryption_test_case_2(void)
7130 {
7131 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
7132 }
7133 
7134 static int
7135 test_zuc_encryption_test_case_3(void)
7136 {
7137 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7138 }
7139 
7140 static int
7141 test_zuc_encryption_test_case_4(void)
7142 {
7143 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7144 }
7145 
7146 static int
7147 test_zuc_encryption_test_case_5(void)
7148 {
7149 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7150 }
7151 
7152 static int
7153 test_zuc_encryption_test_case_6_sgl(void)
7154 {
7155 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7156 }
7157 
7158 static int
7159 test_zuc_hash_generate_test_case_1(void)
7160 {
7161 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7162 }
7163 
7164 static int
7165 test_zuc_hash_generate_test_case_2(void)
7166 {
7167 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7168 }
7169 
7170 static int
7171 test_zuc_hash_generate_test_case_3(void)
7172 {
7173 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7174 }
7175 
7176 static int
7177 test_zuc_hash_generate_test_case_4(void)
7178 {
7179 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7180 }
7181 
7182 static int
7183 test_zuc_hash_generate_test_case_5(void)
7184 {
7185 	return test_zuc_authentication(&zuc_test_auth_5670b);
7186 }
7187 
7188 static int
7189 test_zuc_hash_generate_test_case_6(void)
7190 {
7191 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7192 }
7193 
7194 static int
7195 test_zuc_hash_generate_test_case_7(void)
7196 {
7197 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7198 }
7199 
7200 static int
7201 test_zuc_hash_generate_test_case_8(void)
7202 {
7203 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7204 }
7205 
7206 static int
7207 test_zuc_hash_generate_test_case_9(void)
7208 {
7209 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b);
7210 }
7211 
7212 static int
7213 test_zuc_hash_generate_test_case_10(void)
7214 {
7215 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b);
7216 }
7217 
7218 static int
7219 test_zuc_hash_generate_test_case_11(void)
7220 {
7221 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b);
7222 }
7223 
7224 static int
7225 test_zuc_cipher_auth_test_case_1(void)
7226 {
7227 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7228 }
7229 
7230 static int
7231 test_zuc_cipher_auth_test_case_2(void)
7232 {
7233 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7234 }
7235 
7236 static int
7237 test_zuc_auth_cipher_test_case_1(void)
7238 {
7239 	return test_zuc_auth_cipher(
7240 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7241 }
7242 
7243 static int
7244 test_zuc_auth_cipher_test_case_1_oop(void)
7245 {
7246 	return test_zuc_auth_cipher(
7247 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7248 }
7249 
7250 static int
7251 test_zuc_auth_cipher_test_case_1_sgl(void)
7252 {
7253 	return test_zuc_auth_cipher_sgl(
7254 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7255 }
7256 
7257 static int
7258 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7259 {
7260 	return test_zuc_auth_cipher_sgl(
7261 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7262 }
7263 
7264 static int
7265 test_zuc_auth_cipher_verify_test_case_1(void)
7266 {
7267 	return test_zuc_auth_cipher(
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(void)
7273 {
7274 	return test_zuc_auth_cipher(
7275 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7276 }
7277 
7278 static int
7279 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7280 {
7281 	return test_zuc_auth_cipher_sgl(
7282 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7283 }
7284 
7285 static int
7286 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7287 {
7288 	return test_zuc_auth_cipher_sgl(
7289 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7290 }
7291 
7292 static int
7293 test_zuc256_encryption_test_case_1(void)
7294 {
7295 	return test_zuc_encryption(&zuc256_test_case_cipher_1);
7296 }
7297 
7298 static int
7299 test_zuc256_encryption_test_case_2(void)
7300 {
7301 	return test_zuc_encryption(&zuc256_test_case_cipher_2);
7302 }
7303 
7304 static int
7305 test_zuc256_authentication_test_case_1(void)
7306 {
7307 	return test_zuc_authentication(&zuc256_test_case_auth_1);
7308 }
7309 
7310 static int
7311 test_zuc256_authentication_test_case_2(void)
7312 {
7313 	return test_zuc_authentication(&zuc256_test_case_auth_2);
7314 }
7315 
7316 static int
7317 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7318 {
7319 	uint8_t dev_id = testsuite_params.valid_devs[0];
7320 
7321 	struct rte_cryptodev_sym_capability_idx cap_idx;
7322 
7323 	/* Check if device supports particular cipher algorithm */
7324 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7325 	cap_idx.algo.cipher = tdata->cipher_algo;
7326 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7327 		return TEST_SKIPPED;
7328 
7329 	/* Check if device supports particular hash algorithm */
7330 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7331 	cap_idx.algo.auth = tdata->auth_algo;
7332 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7333 		return TEST_SKIPPED;
7334 
7335 	return 0;
7336 }
7337 
7338 static int
7339 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7340 	uint8_t op_mode, uint8_t verify)
7341 {
7342 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7343 	struct crypto_unittest_params *ut_params = &unittest_params;
7344 
7345 	int retval;
7346 
7347 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7348 	unsigned int plaintext_pad_len;
7349 	unsigned int plaintext_len;
7350 	unsigned int ciphertext_pad_len;
7351 	unsigned int ciphertext_len;
7352 
7353 	struct rte_cryptodev_info dev_info;
7354 	struct rte_crypto_op *op;
7355 
7356 	/* Check if device supports particular algorithms separately */
7357 	if (test_mixed_check_if_unsupported(tdata))
7358 		return TEST_SKIPPED;
7359 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7360 		return TEST_SKIPPED;
7361 
7362 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7363 
7364 	uint64_t feat_flags = dev_info.feature_flags;
7365 
7366 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7367 		printf("Device doesn't support digest encrypted.\n");
7368 		return TEST_SKIPPED;
7369 	}
7370 
7371 	/* Create the session */
7372 	if (verify)
7373 		retval = create_wireless_algo_cipher_auth_session(
7374 				ts_params->valid_devs[0],
7375 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7376 				RTE_CRYPTO_AUTH_OP_VERIFY,
7377 				tdata->auth_algo,
7378 				tdata->cipher_algo,
7379 				tdata->auth_key.data, tdata->auth_key.len,
7380 				tdata->auth_iv.len, tdata->digest_enc.len,
7381 				tdata->cipher_iv.len);
7382 	else
7383 		retval = create_wireless_algo_auth_cipher_session(
7384 				ts_params->valid_devs[0],
7385 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7386 				RTE_CRYPTO_AUTH_OP_GENERATE,
7387 				tdata->auth_algo,
7388 				tdata->cipher_algo,
7389 				tdata->auth_key.data, tdata->auth_key.len,
7390 				tdata->auth_iv.len, tdata->digest_enc.len,
7391 				tdata->cipher_iv.len);
7392 	if (retval != 0)
7393 		return retval;
7394 
7395 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7396 	if (op_mode == OUT_OF_PLACE)
7397 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7398 
7399 	/* clear mbuf payload */
7400 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7401 		rte_pktmbuf_tailroom(ut_params->ibuf));
7402 	if (op_mode == OUT_OF_PLACE) {
7403 
7404 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7405 				rte_pktmbuf_tailroom(ut_params->obuf));
7406 	}
7407 
7408 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7409 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7410 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7411 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7412 
7413 	if (verify) {
7414 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7415 				ciphertext_pad_len);
7416 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7417 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7418 				ciphertext_len);
7419 	} else {
7420 		/* make sure enough space to cover partial digest verify case */
7421 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7422 				ciphertext_pad_len);
7423 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7424 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7425 	}
7426 
7427 	if (op_mode == OUT_OF_PLACE)
7428 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7429 
7430 	/* Create the operation */
7431 	retval = create_wireless_algo_auth_cipher_operation(
7432 			tdata->digest_enc.data, tdata->digest_enc.len,
7433 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7434 			tdata->auth_iv.data, tdata->auth_iv.len,
7435 			(tdata->digest_enc.offset == 0 ?
7436 				plaintext_pad_len
7437 				: tdata->digest_enc.offset),
7438 			tdata->validCipherLen.len_bits,
7439 			tdata->cipher.offset_bits,
7440 			tdata->validAuthLen.len_bits,
7441 			tdata->auth.offset_bits,
7442 			op_mode, 0, verify);
7443 
7444 	if (retval < 0)
7445 		return retval;
7446 
7447 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7448 
7449 	/* Check if the op failed because the device doesn't */
7450 	/* support this particular combination of algorithms */
7451 	if (op == NULL && ut_params->op->status ==
7452 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7453 		printf("Device doesn't support this mixed combination. "
7454 				"Test Skipped.\n");
7455 		return TEST_SKIPPED;
7456 	}
7457 	ut_params->op = op;
7458 
7459 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7460 
7461 	ut_params->obuf = (op_mode == IN_PLACE ?
7462 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7463 
7464 	if (verify) {
7465 		if (ut_params->obuf)
7466 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7467 							uint8_t *);
7468 		else
7469 			plaintext = ciphertext +
7470 					(tdata->cipher.offset_bits >> 3);
7471 
7472 		debug_hexdump(stdout, "plaintext:", plaintext,
7473 				tdata->plaintext.len_bits >> 3);
7474 		debug_hexdump(stdout, "plaintext expected:",
7475 				tdata->plaintext.data,
7476 				tdata->plaintext.len_bits >> 3);
7477 	} else {
7478 		if (ut_params->obuf)
7479 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7480 					uint8_t *);
7481 		else
7482 			ciphertext = plaintext;
7483 
7484 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7485 				ciphertext_len);
7486 		debug_hexdump(stdout, "ciphertext expected:",
7487 				tdata->ciphertext.data,
7488 				tdata->ciphertext.len_bits >> 3);
7489 
7490 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7491 				+ (tdata->digest_enc.offset == 0 ?
7492 		plaintext_pad_len : tdata->digest_enc.offset);
7493 
7494 		debug_hexdump(stdout, "digest:", ut_params->digest,
7495 				tdata->digest_enc.len);
7496 		debug_hexdump(stdout, "digest expected:",
7497 				tdata->digest_enc.data,
7498 				tdata->digest_enc.len);
7499 	}
7500 
7501 	if (!verify) {
7502 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7503 				ut_params->digest,
7504 				tdata->digest_enc.data,
7505 				tdata->digest_enc.len,
7506 				"Generated auth tag not as expected");
7507 	}
7508 
7509 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7510 		if (verify) {
7511 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7512 					plaintext,
7513 					tdata->plaintext.data,
7514 					tdata->plaintext.len_bits >> 3,
7515 					"Plaintext data not as expected");
7516 		} else {
7517 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7518 					ciphertext,
7519 					tdata->ciphertext.data,
7520 					tdata->validDataLen.len_bits,
7521 					"Ciphertext data not as expected");
7522 		}
7523 	}
7524 
7525 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7526 			"crypto op processing failed");
7527 
7528 	return 0;
7529 }
7530 
7531 static int
7532 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7533 	uint8_t op_mode, uint8_t verify)
7534 {
7535 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7536 	struct crypto_unittest_params *ut_params = &unittest_params;
7537 
7538 	int retval;
7539 
7540 	const uint8_t *plaintext = NULL;
7541 	const uint8_t *ciphertext = NULL;
7542 	const uint8_t *digest = NULL;
7543 	unsigned int plaintext_pad_len;
7544 	unsigned int plaintext_len;
7545 	unsigned int ciphertext_pad_len;
7546 	unsigned int ciphertext_len;
7547 	uint8_t buffer[10000];
7548 	uint8_t digest_buffer[10000];
7549 
7550 	struct rte_cryptodev_info dev_info;
7551 	struct rte_crypto_op *op;
7552 
7553 	/* Check if device supports particular algorithms */
7554 	if (test_mixed_check_if_unsupported(tdata))
7555 		return TEST_SKIPPED;
7556 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7557 		return TEST_SKIPPED;
7558 
7559 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7560 
7561 	uint64_t feat_flags = dev_info.feature_flags;
7562 
7563 	if (op_mode == IN_PLACE) {
7564 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7565 			printf("Device doesn't support in-place scatter-gather "
7566 					"in both input and output mbufs.\n");
7567 			return TEST_SKIPPED;
7568 		}
7569 	} else {
7570 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7571 			printf("Device doesn't support out-of-place scatter-gather "
7572 					"in both input and output mbufs.\n");
7573 			return TEST_SKIPPED;
7574 		}
7575 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7576 			printf("Device doesn't support digest encrypted.\n");
7577 			return TEST_SKIPPED;
7578 		}
7579 	}
7580 
7581 	/* Create the session */
7582 	if (verify)
7583 		retval = create_wireless_algo_cipher_auth_session(
7584 				ts_params->valid_devs[0],
7585 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7586 				RTE_CRYPTO_AUTH_OP_VERIFY,
7587 				tdata->auth_algo,
7588 				tdata->cipher_algo,
7589 				tdata->auth_key.data, tdata->auth_key.len,
7590 				tdata->auth_iv.len, tdata->digest_enc.len,
7591 				tdata->cipher_iv.len);
7592 	else
7593 		retval = create_wireless_algo_auth_cipher_session(
7594 				ts_params->valid_devs[0],
7595 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7596 				RTE_CRYPTO_AUTH_OP_GENERATE,
7597 				tdata->auth_algo,
7598 				tdata->cipher_algo,
7599 				tdata->auth_key.data, tdata->auth_key.len,
7600 				tdata->auth_iv.len, tdata->digest_enc.len,
7601 				tdata->cipher_iv.len);
7602 	if (retval != 0)
7603 		return retval;
7604 
7605 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7606 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7607 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7608 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7609 
7610 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7611 			ciphertext_pad_len, 15, 0);
7612 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7613 			"Failed to allocate input buffer in mempool");
7614 
7615 	if (op_mode == OUT_OF_PLACE) {
7616 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7617 				plaintext_pad_len, 15, 0);
7618 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7619 				"Failed to allocate output buffer in mempool");
7620 	}
7621 
7622 	if (verify) {
7623 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7624 			tdata->ciphertext.data);
7625 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7626 					ciphertext_len, buffer);
7627 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7628 			ciphertext_len);
7629 	} else {
7630 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7631 			tdata->plaintext.data);
7632 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7633 					plaintext_len, buffer);
7634 		debug_hexdump(stdout, "plaintext:", plaintext,
7635 			plaintext_len);
7636 	}
7637 	memset(buffer, 0, sizeof(buffer));
7638 
7639 	/* Create the operation */
7640 	retval = create_wireless_algo_auth_cipher_operation(
7641 			tdata->digest_enc.data, tdata->digest_enc.len,
7642 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7643 			tdata->auth_iv.data, tdata->auth_iv.len,
7644 			(tdata->digest_enc.offset == 0 ?
7645 				plaintext_pad_len
7646 				: tdata->digest_enc.offset),
7647 			tdata->validCipherLen.len_bits,
7648 			tdata->cipher.offset_bits,
7649 			tdata->validAuthLen.len_bits,
7650 			tdata->auth.offset_bits,
7651 			op_mode, 1, verify);
7652 
7653 	if (retval < 0)
7654 		return retval;
7655 
7656 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7657 
7658 	/* Check if the op failed because the device doesn't */
7659 	/* support this particular combination of algorithms */
7660 	if (op == NULL && ut_params->op->status ==
7661 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7662 		printf("Device doesn't support this mixed combination. "
7663 				"Test Skipped.\n");
7664 		return TEST_SKIPPED;
7665 	}
7666 	ut_params->op = op;
7667 
7668 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7669 
7670 	ut_params->obuf = (op_mode == IN_PLACE ?
7671 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7672 
7673 	if (verify) {
7674 		if (ut_params->obuf)
7675 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7676 					plaintext_len, buffer);
7677 		else
7678 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7679 					plaintext_len, buffer);
7680 
7681 		debug_hexdump(stdout, "plaintext:", plaintext,
7682 				(tdata->plaintext.len_bits >> 3) -
7683 				tdata->digest_enc.len);
7684 		debug_hexdump(stdout, "plaintext expected:",
7685 				tdata->plaintext.data,
7686 				(tdata->plaintext.len_bits >> 3) -
7687 				tdata->digest_enc.len);
7688 	} else {
7689 		if (ut_params->obuf)
7690 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7691 					ciphertext_len, buffer);
7692 		else
7693 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7694 					ciphertext_len, buffer);
7695 
7696 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7697 			ciphertext_len);
7698 		debug_hexdump(stdout, "ciphertext expected:",
7699 			tdata->ciphertext.data,
7700 			tdata->ciphertext.len_bits >> 3);
7701 
7702 		if (ut_params->obuf)
7703 			digest = rte_pktmbuf_read(ut_params->obuf,
7704 					(tdata->digest_enc.offset == 0 ?
7705 						plaintext_pad_len :
7706 						tdata->digest_enc.offset),
7707 					tdata->digest_enc.len, digest_buffer);
7708 		else
7709 			digest = rte_pktmbuf_read(ut_params->ibuf,
7710 					(tdata->digest_enc.offset == 0 ?
7711 						plaintext_pad_len :
7712 						tdata->digest_enc.offset),
7713 					tdata->digest_enc.len, digest_buffer);
7714 
7715 		debug_hexdump(stdout, "digest:", digest,
7716 				tdata->digest_enc.len);
7717 		debug_hexdump(stdout, "digest expected:",
7718 				tdata->digest_enc.data, tdata->digest_enc.len);
7719 	}
7720 
7721 	if (!verify) {
7722 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7723 				digest,
7724 				tdata->digest_enc.data,
7725 				tdata->digest_enc.len,
7726 				"Generated auth tag not as expected");
7727 	}
7728 
7729 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7730 		if (verify) {
7731 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7732 					plaintext,
7733 					tdata->plaintext.data,
7734 					tdata->plaintext.len_bits >> 3,
7735 					"Plaintext data not as expected");
7736 		} else {
7737 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7738 					ciphertext,
7739 					tdata->ciphertext.data,
7740 					tdata->validDataLen.len_bits,
7741 					"Ciphertext data not as expected");
7742 		}
7743 	}
7744 
7745 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7746 			"crypto op processing failed");
7747 
7748 	return 0;
7749 }
7750 
7751 /** AUTH AES CMAC + CIPHER AES CTR */
7752 
7753 static int
7754 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7755 {
7756 	return test_mixed_auth_cipher(
7757 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7758 }
7759 
7760 static int
7761 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7762 {
7763 	return test_mixed_auth_cipher(
7764 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7765 }
7766 
7767 static int
7768 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7769 {
7770 	return test_mixed_auth_cipher_sgl(
7771 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7772 }
7773 
7774 static int
7775 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7776 {
7777 	return test_mixed_auth_cipher_sgl(
7778 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7779 }
7780 
7781 static int
7782 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7783 {
7784 	return test_mixed_auth_cipher(
7785 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7786 }
7787 
7788 static int
7789 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7790 {
7791 	return test_mixed_auth_cipher(
7792 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7793 }
7794 
7795 static int
7796 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7797 {
7798 	return test_mixed_auth_cipher_sgl(
7799 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7800 }
7801 
7802 static int
7803 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7804 {
7805 	return test_mixed_auth_cipher_sgl(
7806 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7807 }
7808 
7809 /** MIXED AUTH + CIPHER */
7810 
7811 static int
7812 test_auth_zuc_cipher_snow_test_case_1(void)
7813 {
7814 	return test_mixed_auth_cipher(
7815 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7816 }
7817 
7818 static int
7819 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7820 {
7821 	return test_mixed_auth_cipher(
7822 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7823 }
7824 
7825 static int
7826 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7827 {
7828 	return test_mixed_auth_cipher(
7829 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7830 }
7831 
7832 static int
7833 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7834 {
7835 	return test_mixed_auth_cipher(
7836 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7837 }
7838 
7839 static int
7840 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7841 {
7842 	return test_mixed_auth_cipher(
7843 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7844 }
7845 
7846 static int
7847 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7848 {
7849 	return test_mixed_auth_cipher(
7850 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7851 }
7852 
7853 static int
7854 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7855 {
7856 	return test_mixed_auth_cipher(
7857 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7858 }
7859 
7860 static int
7861 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7862 {
7863 	return test_mixed_auth_cipher(
7864 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7865 }
7866 
7867 static int
7868 test_auth_snow_cipher_zuc_test_case_1(void)
7869 {
7870 	return test_mixed_auth_cipher(
7871 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7872 }
7873 
7874 static int
7875 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7876 {
7877 	return test_mixed_auth_cipher(
7878 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7879 }
7880 
7881 static int
7882 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7883 {
7884 	return test_mixed_auth_cipher(
7885 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7886 }
7887 
7888 static int
7889 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7890 {
7891 	return test_mixed_auth_cipher(
7892 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7893 }
7894 
7895 static int
7896 test_auth_null_cipher_snow_test_case_1(void)
7897 {
7898 	return test_mixed_auth_cipher(
7899 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7900 }
7901 
7902 static int
7903 test_verify_auth_null_cipher_snow_test_case_1(void)
7904 {
7905 	return test_mixed_auth_cipher(
7906 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7907 }
7908 
7909 static int
7910 test_auth_null_cipher_zuc_test_case_1(void)
7911 {
7912 	return test_mixed_auth_cipher(
7913 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7914 }
7915 
7916 static int
7917 test_verify_auth_null_cipher_zuc_test_case_1(void)
7918 {
7919 	return test_mixed_auth_cipher(
7920 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7921 }
7922 
7923 static int
7924 test_auth_snow_cipher_null_test_case_1(void)
7925 {
7926 	return test_mixed_auth_cipher(
7927 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7928 }
7929 
7930 static int
7931 test_verify_auth_snow_cipher_null_test_case_1(void)
7932 {
7933 	return test_mixed_auth_cipher(
7934 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7935 }
7936 
7937 static int
7938 test_auth_zuc_cipher_null_test_case_1(void)
7939 {
7940 	return test_mixed_auth_cipher(
7941 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7942 }
7943 
7944 static int
7945 test_verify_auth_zuc_cipher_null_test_case_1(void)
7946 {
7947 	return test_mixed_auth_cipher(
7948 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7949 }
7950 
7951 static int
7952 test_auth_null_cipher_aes_ctr_test_case_1(void)
7953 {
7954 	return test_mixed_auth_cipher(
7955 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7956 }
7957 
7958 static int
7959 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7960 {
7961 	return test_mixed_auth_cipher(
7962 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7963 }
7964 
7965 static int
7966 test_auth_aes_cmac_cipher_null_test_case_1(void)
7967 {
7968 	return test_mixed_auth_cipher(
7969 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7970 }
7971 
7972 static int
7973 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7974 {
7975 	return test_mixed_auth_cipher(
7976 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7977 }
7978 
7979 /* ***** AEAD algorithm Tests ***** */
7980 
7981 static int
7982 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7983 		enum rte_crypto_aead_operation op,
7984 		const uint8_t *key, const uint8_t key_len,
7985 		const uint16_t aad_len, const uint8_t auth_len,
7986 		uint8_t iv_len)
7987 {
7988 	uint8_t aead_key[key_len];
7989 	int status;
7990 
7991 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7992 	struct crypto_unittest_params *ut_params = &unittest_params;
7993 
7994 	memcpy(aead_key, key, key_len);
7995 
7996 	/* Setup AEAD Parameters */
7997 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7998 	ut_params->aead_xform.next = NULL;
7999 	ut_params->aead_xform.aead.algo = algo;
8000 	ut_params->aead_xform.aead.op = op;
8001 	ut_params->aead_xform.aead.key.data = aead_key;
8002 	ut_params->aead_xform.aead.key.length = key_len;
8003 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8004 	ut_params->aead_xform.aead.iv.length = iv_len;
8005 	ut_params->aead_xform.aead.digest_length = auth_len;
8006 	ut_params->aead_xform.aead.aad_length = aad_len;
8007 
8008 	debug_hexdump(stdout, "key:", key, key_len);
8009 
8010 	/* Create Crypto session*/
8011 	ut_params->sess = rte_cryptodev_sym_session_create(
8012 			ts_params->session_mpool);
8013 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8014 
8015 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
8016 			&ut_params->aead_xform,
8017 			ts_params->session_priv_mpool);
8018 
8019 	return status;
8020 }
8021 
8022 static int
8023 create_aead_xform(struct rte_crypto_op *op,
8024 		enum rte_crypto_aead_algorithm algo,
8025 		enum rte_crypto_aead_operation aead_op,
8026 		uint8_t *key, const uint8_t key_len,
8027 		const uint8_t aad_len, const uint8_t auth_len,
8028 		uint8_t iv_len)
8029 {
8030 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
8031 			"failed to allocate space for crypto transform");
8032 
8033 	struct rte_crypto_sym_op *sym_op = op->sym;
8034 
8035 	/* Setup AEAD Parameters */
8036 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
8037 	sym_op->xform->next = NULL;
8038 	sym_op->xform->aead.algo = algo;
8039 	sym_op->xform->aead.op = aead_op;
8040 	sym_op->xform->aead.key.data = key;
8041 	sym_op->xform->aead.key.length = key_len;
8042 	sym_op->xform->aead.iv.offset = IV_OFFSET;
8043 	sym_op->xform->aead.iv.length = iv_len;
8044 	sym_op->xform->aead.digest_length = auth_len;
8045 	sym_op->xform->aead.aad_length = aad_len;
8046 
8047 	debug_hexdump(stdout, "key:", key, key_len);
8048 
8049 	return 0;
8050 }
8051 
8052 static int
8053 create_aead_operation(enum rte_crypto_aead_operation op,
8054 		const struct aead_test_data *tdata)
8055 {
8056 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8057 	struct crypto_unittest_params *ut_params = &unittest_params;
8058 
8059 	uint8_t *plaintext, *ciphertext;
8060 	unsigned int aad_pad_len, plaintext_pad_len;
8061 
8062 	/* Generate Crypto op data structure */
8063 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8064 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8065 	TEST_ASSERT_NOT_NULL(ut_params->op,
8066 			"Failed to allocate symmetric crypto operation struct");
8067 
8068 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8069 
8070 	/* Append aad data */
8071 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8072 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
8073 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8074 				aad_pad_len);
8075 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8076 				"no room to append aad");
8077 
8078 		sym_op->aead.aad.phys_addr =
8079 				rte_pktmbuf_iova(ut_params->ibuf);
8080 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
8081 		memcpy(sym_op->aead.aad.data + 18, 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 		/* Copy IV 1 byte after the IV pointer, according to the API */
8090 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8091 		debug_hexdump(stdout, "iv:", iv_ptr,
8092 			tdata->iv.len);
8093 	} else {
8094 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
8095 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8096 				aad_pad_len);
8097 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8098 				"no room to append aad");
8099 
8100 		sym_op->aead.aad.phys_addr =
8101 				rte_pktmbuf_iova(ut_params->ibuf);
8102 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8103 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8104 			tdata->aad.len);
8105 
8106 		/* Append IV at the end of the crypto operation*/
8107 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8108 				uint8_t *, IV_OFFSET);
8109 
8110 		if (tdata->iv.len == 0) {
8111 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8112 			debug_hexdump(stdout, "iv:", iv_ptr,
8113 				AES_GCM_J0_LENGTH);
8114 		} else {
8115 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8116 			debug_hexdump(stdout, "iv:", iv_ptr,
8117 				tdata->iv.len);
8118 		}
8119 	}
8120 
8121 	/* Append plaintext/ciphertext */
8122 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8123 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8124 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8125 				plaintext_pad_len);
8126 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8127 
8128 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8129 		debug_hexdump(stdout, "plaintext:", plaintext,
8130 				tdata->plaintext.len);
8131 
8132 		if (ut_params->obuf) {
8133 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8134 					ut_params->obuf,
8135 					plaintext_pad_len + aad_pad_len);
8136 			TEST_ASSERT_NOT_NULL(ciphertext,
8137 					"no room to append ciphertext");
8138 
8139 			memset(ciphertext + aad_pad_len, 0,
8140 					tdata->ciphertext.len);
8141 		}
8142 	} else {
8143 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8144 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8145 				plaintext_pad_len);
8146 		TEST_ASSERT_NOT_NULL(ciphertext,
8147 				"no room to append ciphertext");
8148 
8149 		memcpy(ciphertext, tdata->ciphertext.data,
8150 				tdata->ciphertext.len);
8151 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8152 				tdata->ciphertext.len);
8153 
8154 		if (ut_params->obuf) {
8155 			plaintext = (uint8_t *)rte_pktmbuf_append(
8156 					ut_params->obuf,
8157 					plaintext_pad_len + aad_pad_len);
8158 			TEST_ASSERT_NOT_NULL(plaintext,
8159 					"no room to append plaintext");
8160 
8161 			memset(plaintext + aad_pad_len, 0,
8162 					tdata->plaintext.len);
8163 		}
8164 	}
8165 
8166 	/* Append digest data */
8167 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8168 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8169 				ut_params->obuf ? ut_params->obuf :
8170 						ut_params->ibuf,
8171 						tdata->auth_tag.len);
8172 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8173 				"no room to append digest");
8174 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8175 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8176 				ut_params->obuf ? ut_params->obuf :
8177 						ut_params->ibuf,
8178 						plaintext_pad_len +
8179 						aad_pad_len);
8180 	} else {
8181 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8182 				ut_params->ibuf, tdata->auth_tag.len);
8183 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8184 				"no room to append digest");
8185 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8186 				ut_params->ibuf,
8187 				plaintext_pad_len + aad_pad_len);
8188 
8189 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8190 			tdata->auth_tag.len);
8191 		debug_hexdump(stdout, "digest:",
8192 			sym_op->aead.digest.data,
8193 			tdata->auth_tag.len);
8194 	}
8195 
8196 	sym_op->aead.data.length = tdata->plaintext.len;
8197 	sym_op->aead.data.offset = aad_pad_len;
8198 
8199 	return 0;
8200 }
8201 
8202 static int
8203 test_authenticated_encryption(const struct aead_test_data *tdata)
8204 {
8205 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8206 	struct crypto_unittest_params *ut_params = &unittest_params;
8207 
8208 	int retval;
8209 	uint8_t *ciphertext, *auth_tag;
8210 	uint16_t plaintext_pad_len;
8211 	uint32_t i;
8212 	struct rte_cryptodev_info dev_info;
8213 
8214 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8215 	uint64_t feat_flags = dev_info.feature_flags;
8216 
8217 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8218 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8219 		printf("Device doesn't support RAW data-path APIs.\n");
8220 		return TEST_SKIPPED;
8221 	}
8222 
8223 	/* Verify the capabilities */
8224 	struct rte_cryptodev_sym_capability_idx cap_idx;
8225 	const struct rte_cryptodev_symmetric_capability *capability;
8226 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8227 	cap_idx.algo.aead = tdata->algo;
8228 	capability = rte_cryptodev_sym_capability_get(
8229 			ts_params->valid_devs[0], &cap_idx);
8230 	if (capability == NULL)
8231 		return TEST_SKIPPED;
8232 	if (rte_cryptodev_sym_capability_check_aead(
8233 			capability, tdata->key.len, tdata->auth_tag.len,
8234 			tdata->aad.len, tdata->iv.len))
8235 		return TEST_SKIPPED;
8236 
8237 	/* Create AEAD session */
8238 	retval = create_aead_session(ts_params->valid_devs[0],
8239 			tdata->algo,
8240 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8241 			tdata->key.data, tdata->key.len,
8242 			tdata->aad.len, tdata->auth_tag.len,
8243 			tdata->iv.len);
8244 	if (retval < 0)
8245 		return retval;
8246 
8247 	if (tdata->aad.len > MBUF_SIZE) {
8248 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8249 		/* Populate full size of add data */
8250 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8251 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8252 	} else
8253 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8254 
8255 	/* clear mbuf payload */
8256 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8257 			rte_pktmbuf_tailroom(ut_params->ibuf));
8258 
8259 	/* Create AEAD operation */
8260 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8261 	if (retval < 0)
8262 		return retval;
8263 
8264 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8265 
8266 	ut_params->op->sym->m_src = ut_params->ibuf;
8267 
8268 	/* Process crypto operation */
8269 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8270 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8271 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8272 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8273 				ut_params->op, 0, 0, 0, 0);
8274 	else
8275 		TEST_ASSERT_NOT_NULL(
8276 			process_crypto_request(ts_params->valid_devs[0],
8277 			ut_params->op), "failed to process sym crypto op");
8278 
8279 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8280 			"crypto op processing failed");
8281 
8282 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8283 
8284 	if (ut_params->op->sym->m_dst) {
8285 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8286 				uint8_t *);
8287 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8288 				uint8_t *, plaintext_pad_len);
8289 	} else {
8290 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8291 				uint8_t *,
8292 				ut_params->op->sym->cipher.data.offset);
8293 		auth_tag = ciphertext + plaintext_pad_len;
8294 	}
8295 
8296 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8297 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8298 
8299 	/* Validate obuf */
8300 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8301 			ciphertext,
8302 			tdata->ciphertext.data,
8303 			tdata->ciphertext.len,
8304 			"Ciphertext data not as expected");
8305 
8306 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8307 			auth_tag,
8308 			tdata->auth_tag.data,
8309 			tdata->auth_tag.len,
8310 			"Generated auth tag not as expected");
8311 
8312 	return 0;
8313 
8314 }
8315 
8316 #ifdef RTE_LIB_SECURITY
8317 static int
8318 security_proto_supported(enum rte_security_session_action_type action,
8319 	enum rte_security_session_protocol proto)
8320 {
8321 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8322 
8323 	const struct rte_security_capability *capabilities;
8324 	const struct rte_security_capability *capability;
8325 	uint16_t i = 0;
8326 
8327 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8328 				rte_cryptodev_get_sec_ctx(
8329 				ts_params->valid_devs[0]);
8330 
8331 
8332 	capabilities = rte_security_capabilities_get(ctx);
8333 
8334 	if (capabilities == NULL)
8335 		return -ENOTSUP;
8336 
8337 	while ((capability = &capabilities[i++])->action !=
8338 			RTE_SECURITY_ACTION_TYPE_NONE) {
8339 		if (capability->action == action &&
8340 				capability->protocol == proto)
8341 			return 0;
8342 	}
8343 
8344 	return -ENOTSUP;
8345 }
8346 
8347 /* Basic algorithm run function for async inplace mode.
8348  * Creates a session from input parameters and runs one operation
8349  * on input_vec. Checks the output of the crypto operation against
8350  * output_vec.
8351  */
8352 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8353 			   enum rte_crypto_auth_operation opa,
8354 			   const uint8_t *input_vec, unsigned int input_vec_len,
8355 			   const uint8_t *output_vec,
8356 			   unsigned int output_vec_len,
8357 			   enum rte_crypto_cipher_algorithm cipher_alg,
8358 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8359 			   enum rte_crypto_auth_algorithm auth_alg,
8360 			   const uint8_t *auth_key, uint32_t auth_key_len,
8361 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8362 			   uint8_t packet_direction, uint8_t sn_size,
8363 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8364 {
8365 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8366 	struct crypto_unittest_params *ut_params = &unittest_params;
8367 	uint8_t *plaintext;
8368 	int ret = TEST_SUCCESS;
8369 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8370 				rte_cryptodev_get_sec_ctx(
8371 				ts_params->valid_devs[0]);
8372 
8373 	/* Verify the capabilities */
8374 	struct rte_security_capability_idx sec_cap_idx;
8375 
8376 	sec_cap_idx.action = ut_params->type;
8377 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8378 	sec_cap_idx.pdcp.domain = domain;
8379 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8380 		return TEST_SKIPPED;
8381 
8382 	/* Generate test mbuf data */
8383 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8384 
8385 	/* clear mbuf payload */
8386 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8387 			rte_pktmbuf_tailroom(ut_params->ibuf));
8388 
8389 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8390 						  input_vec_len);
8391 	memcpy(plaintext, input_vec, input_vec_len);
8392 
8393 	/* Out of place support */
8394 	if (oop) {
8395 		/*
8396 		 * For out-op-place we need to alloc another mbuf
8397 		 */
8398 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8399 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8400 	}
8401 
8402 	/* Setup Cipher Parameters */
8403 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8404 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8405 	ut_params->cipher_xform.cipher.op = opc;
8406 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8407 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8408 	ut_params->cipher_xform.cipher.iv.length =
8409 				packet_direction ? 4 : 0;
8410 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8411 
8412 	/* Setup HMAC Parameters if ICV header is required */
8413 	if (auth_alg != 0) {
8414 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8415 		ut_params->auth_xform.next = NULL;
8416 		ut_params->auth_xform.auth.algo = auth_alg;
8417 		ut_params->auth_xform.auth.op = opa;
8418 		ut_params->auth_xform.auth.key.data = auth_key;
8419 		ut_params->auth_xform.auth.key.length = auth_key_len;
8420 
8421 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8422 	} else {
8423 		ut_params->cipher_xform.next = NULL;
8424 	}
8425 
8426 	struct rte_security_session_conf sess_conf = {
8427 		.action_type = ut_params->type,
8428 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8429 		{.pdcp = {
8430 			.bearer = bearer,
8431 			.domain = domain,
8432 			.pkt_dir = packet_direction,
8433 			.sn_size = sn_size,
8434 			.hfn = packet_direction ? 0 : hfn,
8435 			/**
8436 			 * hfn can be set as pdcp_test_hfn[i]
8437 			 * if hfn_ovrd is not set. Here, PDCP
8438 			 * packet direction is just used to
8439 			 * run half of the cases with session
8440 			 * HFN and other half with per packet
8441 			 * HFN.
8442 			 */
8443 			.hfn_threshold = hfn_threshold,
8444 			.hfn_ovrd = packet_direction ? 1 : 0,
8445 			.sdap_enabled = sdap,
8446 		} },
8447 		.crypto_xform = &ut_params->cipher_xform
8448 	};
8449 
8450 	/* Create security session */
8451 	ut_params->sec_session = rte_security_session_create(ctx,
8452 				&sess_conf, ts_params->session_mpool,
8453 				ts_params->session_priv_mpool);
8454 
8455 	if (!ut_params->sec_session) {
8456 		printf("TestCase %s()-%d line %d failed %s: ",
8457 			__func__, i, __LINE__, "Failed to allocate session");
8458 		ret = TEST_FAILED;
8459 		goto on_err;
8460 	}
8461 
8462 	/* Generate crypto op data structure */
8463 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8464 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8465 	if (!ut_params->op) {
8466 		printf("TestCase %s()-%d line %d failed %s: ",
8467 			__func__, i, __LINE__,
8468 			"Failed to allocate symmetric crypto operation struct");
8469 		ret = TEST_FAILED;
8470 		goto on_err;
8471 	}
8472 
8473 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8474 					uint32_t *, IV_OFFSET);
8475 	*per_pkt_hfn = packet_direction ? hfn : 0;
8476 
8477 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8478 
8479 	/* set crypto operation source mbuf */
8480 	ut_params->op->sym->m_src = ut_params->ibuf;
8481 	if (oop)
8482 		ut_params->op->sym->m_dst = ut_params->obuf;
8483 
8484 	/* Process crypto operation */
8485 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8486 		== NULL) {
8487 		printf("TestCase %s()-%d line %d failed %s: ",
8488 			__func__, i, __LINE__,
8489 			"failed to process sym crypto op");
8490 		ret = TEST_FAILED;
8491 		goto on_err;
8492 	}
8493 
8494 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8495 		printf("TestCase %s()-%d line %d failed %s: ",
8496 			__func__, i, __LINE__, "crypto op processing failed");
8497 		ret = TEST_FAILED;
8498 		goto on_err;
8499 	}
8500 
8501 	/* Validate obuf */
8502 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8503 			uint8_t *);
8504 	if (oop) {
8505 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8506 				uint8_t *);
8507 	}
8508 
8509 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8510 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8511 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8512 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8513 		ret = TEST_FAILED;
8514 		goto on_err;
8515 	}
8516 
8517 on_err:
8518 	rte_crypto_op_free(ut_params->op);
8519 	ut_params->op = NULL;
8520 
8521 	if (ut_params->sec_session)
8522 		rte_security_session_destroy(ctx, ut_params->sec_session);
8523 	ut_params->sec_session = NULL;
8524 
8525 	rte_pktmbuf_free(ut_params->ibuf);
8526 	ut_params->ibuf = NULL;
8527 	if (oop) {
8528 		rte_pktmbuf_free(ut_params->obuf);
8529 		ut_params->obuf = NULL;
8530 	}
8531 
8532 	return ret;
8533 }
8534 
8535 static int
8536 test_pdcp_proto_SGL(int i, int oop,
8537 	enum rte_crypto_cipher_operation opc,
8538 	enum rte_crypto_auth_operation opa,
8539 	uint8_t *input_vec,
8540 	unsigned int input_vec_len,
8541 	uint8_t *output_vec,
8542 	unsigned int output_vec_len,
8543 	uint32_t fragsz,
8544 	uint32_t fragsz_oop)
8545 {
8546 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8547 	struct crypto_unittest_params *ut_params = &unittest_params;
8548 	uint8_t *plaintext;
8549 	struct rte_mbuf *buf, *buf_oop = NULL;
8550 	int ret = TEST_SUCCESS;
8551 	int to_trn = 0;
8552 	int to_trn_tbl[16];
8553 	int segs = 1;
8554 	unsigned int trn_data = 0;
8555 	struct rte_cryptodev_info dev_info;
8556 	uint64_t feat_flags;
8557 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8558 				rte_cryptodev_get_sec_ctx(
8559 				ts_params->valid_devs[0]);
8560 	struct rte_mbuf *temp_mbuf;
8561 
8562 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8563 	feat_flags = dev_info.feature_flags;
8564 
8565 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8566 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8567 		printf("Device does not support RAW data-path APIs.\n");
8568 		return -ENOTSUP;
8569 	}
8570 	/* Verify the capabilities */
8571 	struct rte_security_capability_idx sec_cap_idx;
8572 
8573 	sec_cap_idx.action = ut_params->type;
8574 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8575 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8576 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8577 		return TEST_SKIPPED;
8578 
8579 	if (fragsz > input_vec_len)
8580 		fragsz = input_vec_len;
8581 
8582 	uint16_t plaintext_len = fragsz;
8583 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8584 
8585 	if (fragsz_oop > output_vec_len)
8586 		frag_size_oop = output_vec_len;
8587 
8588 	int ecx = 0;
8589 	if (input_vec_len % fragsz != 0) {
8590 		if (input_vec_len / fragsz + 1 > 16)
8591 			return 1;
8592 	} else if (input_vec_len / fragsz > 16)
8593 		return 1;
8594 
8595 	/* Out of place support */
8596 	if (oop) {
8597 		/*
8598 		 * For out-op-place we need to alloc another mbuf
8599 		 */
8600 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8601 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8602 		buf_oop = ut_params->obuf;
8603 	}
8604 
8605 	/* Generate test mbuf data */
8606 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8607 
8608 	/* clear mbuf payload */
8609 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8610 			rte_pktmbuf_tailroom(ut_params->ibuf));
8611 
8612 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8613 						  plaintext_len);
8614 	memcpy(plaintext, input_vec, plaintext_len);
8615 	trn_data += plaintext_len;
8616 
8617 	buf = ut_params->ibuf;
8618 
8619 	/*
8620 	 * Loop until no more fragments
8621 	 */
8622 
8623 	while (trn_data < input_vec_len) {
8624 		++segs;
8625 		to_trn = (input_vec_len - trn_data < fragsz) ?
8626 				(input_vec_len - trn_data) : fragsz;
8627 
8628 		to_trn_tbl[ecx++] = to_trn;
8629 
8630 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8631 		buf = buf->next;
8632 
8633 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8634 				rte_pktmbuf_tailroom(buf));
8635 
8636 		/* OOP */
8637 		if (oop && !fragsz_oop) {
8638 			buf_oop->next =
8639 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8640 			buf_oop = buf_oop->next;
8641 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8642 					0, rte_pktmbuf_tailroom(buf_oop));
8643 			rte_pktmbuf_append(buf_oop, to_trn);
8644 		}
8645 
8646 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8647 				to_trn);
8648 
8649 		memcpy(plaintext, input_vec + trn_data, to_trn);
8650 		trn_data += to_trn;
8651 	}
8652 
8653 	ut_params->ibuf->nb_segs = segs;
8654 
8655 	segs = 1;
8656 	if (fragsz_oop && oop) {
8657 		to_trn = 0;
8658 		ecx = 0;
8659 
8660 		trn_data = frag_size_oop;
8661 		while (trn_data < output_vec_len) {
8662 			++segs;
8663 			to_trn =
8664 				(output_vec_len - trn_data <
8665 						frag_size_oop) ?
8666 				(output_vec_len - trn_data) :
8667 						frag_size_oop;
8668 
8669 			to_trn_tbl[ecx++] = to_trn;
8670 
8671 			buf_oop->next =
8672 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8673 			buf_oop = buf_oop->next;
8674 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8675 					0, rte_pktmbuf_tailroom(buf_oop));
8676 			rte_pktmbuf_append(buf_oop, to_trn);
8677 
8678 			trn_data += to_trn;
8679 		}
8680 		ut_params->obuf->nb_segs = segs;
8681 	}
8682 
8683 	/* Setup Cipher Parameters */
8684 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8685 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8686 	ut_params->cipher_xform.cipher.op = opc;
8687 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8688 	ut_params->cipher_xform.cipher.key.length =
8689 					pdcp_test_params[i].cipher_key_len;
8690 	ut_params->cipher_xform.cipher.iv.length = 0;
8691 
8692 	/* Setup HMAC Parameters if ICV header is required */
8693 	if (pdcp_test_params[i].auth_alg != 0) {
8694 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8695 		ut_params->auth_xform.next = NULL;
8696 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8697 		ut_params->auth_xform.auth.op = opa;
8698 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8699 		ut_params->auth_xform.auth.key.length =
8700 					pdcp_test_params[i].auth_key_len;
8701 
8702 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8703 	} else {
8704 		ut_params->cipher_xform.next = NULL;
8705 	}
8706 
8707 	struct rte_security_session_conf sess_conf = {
8708 		.action_type = ut_params->type,
8709 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8710 		{.pdcp = {
8711 			.bearer = pdcp_test_bearer[i],
8712 			.domain = pdcp_test_params[i].domain,
8713 			.pkt_dir = pdcp_test_packet_direction[i],
8714 			.sn_size = pdcp_test_data_sn_size[i],
8715 			.hfn = pdcp_test_hfn[i],
8716 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8717 			.hfn_ovrd = 0,
8718 		} },
8719 		.crypto_xform = &ut_params->cipher_xform
8720 	};
8721 
8722 	/* Create security session */
8723 	ut_params->sec_session = rte_security_session_create(ctx,
8724 				&sess_conf, ts_params->session_mpool,
8725 				ts_params->session_priv_mpool);
8726 
8727 	if (!ut_params->sec_session) {
8728 		printf("TestCase %s()-%d line %d failed %s: ",
8729 			__func__, i, __LINE__, "Failed to allocate session");
8730 		ret = TEST_FAILED;
8731 		goto on_err;
8732 	}
8733 
8734 	/* Generate crypto op data structure */
8735 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8736 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8737 	if (!ut_params->op) {
8738 		printf("TestCase %s()-%d line %d failed %s: ",
8739 			__func__, i, __LINE__,
8740 			"Failed to allocate symmetric crypto operation struct");
8741 		ret = TEST_FAILED;
8742 		goto on_err;
8743 	}
8744 
8745 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8746 
8747 	/* set crypto operation source mbuf */
8748 	ut_params->op->sym->m_src = ut_params->ibuf;
8749 	if (oop)
8750 		ut_params->op->sym->m_dst = ut_params->obuf;
8751 
8752 	/* Process crypto operation */
8753 	temp_mbuf = ut_params->op->sym->m_src;
8754 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8755 		/* filling lengths */
8756 		while (temp_mbuf) {
8757 			ut_params->op->sym->cipher.data.length
8758 				+= temp_mbuf->pkt_len;
8759 			ut_params->op->sym->auth.data.length
8760 				+= temp_mbuf->pkt_len;
8761 			temp_mbuf = temp_mbuf->next;
8762 		}
8763 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8764 			ut_params->op, 1, 1, 0, 0);
8765 	} else {
8766 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8767 							ut_params->op);
8768 	}
8769 	if (ut_params->op == NULL) {
8770 		printf("TestCase %s()-%d line %d failed %s: ",
8771 			__func__, i, __LINE__,
8772 			"failed to process sym crypto op");
8773 		ret = TEST_FAILED;
8774 		goto on_err;
8775 	}
8776 
8777 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8778 		printf("TestCase %s()-%d line %d failed %s: ",
8779 			__func__, i, __LINE__, "crypto op processing failed");
8780 		ret = TEST_FAILED;
8781 		goto on_err;
8782 	}
8783 
8784 	/* Validate obuf */
8785 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8786 			uint8_t *);
8787 	if (oop) {
8788 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8789 				uint8_t *);
8790 	}
8791 	if (fragsz_oop)
8792 		fragsz = frag_size_oop;
8793 	if (memcmp(ciphertext, output_vec, fragsz)) {
8794 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8795 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8796 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8797 		ret = TEST_FAILED;
8798 		goto on_err;
8799 	}
8800 
8801 	buf = ut_params->op->sym->m_src->next;
8802 	if (oop)
8803 		buf = ut_params->op->sym->m_dst->next;
8804 
8805 	unsigned int off = fragsz;
8806 
8807 	ecx = 0;
8808 	while (buf) {
8809 		ciphertext = rte_pktmbuf_mtod(buf,
8810 				uint8_t *);
8811 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8812 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8813 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8814 			rte_hexdump(stdout, "reference", output_vec + off,
8815 					to_trn_tbl[ecx]);
8816 			ret = TEST_FAILED;
8817 			goto on_err;
8818 		}
8819 		off += to_trn_tbl[ecx++];
8820 		buf = buf->next;
8821 	}
8822 on_err:
8823 	rte_crypto_op_free(ut_params->op);
8824 	ut_params->op = NULL;
8825 
8826 	if (ut_params->sec_session)
8827 		rte_security_session_destroy(ctx, ut_params->sec_session);
8828 	ut_params->sec_session = NULL;
8829 
8830 	rte_pktmbuf_free(ut_params->ibuf);
8831 	ut_params->ibuf = NULL;
8832 	if (oop) {
8833 		rte_pktmbuf_free(ut_params->obuf);
8834 		ut_params->obuf = NULL;
8835 	}
8836 
8837 	return ret;
8838 }
8839 
8840 int
8841 test_pdcp_proto_cplane_encap(int i)
8842 {
8843 	return test_pdcp_proto(
8844 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8845 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8846 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8847 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8848 		pdcp_test_params[i].cipher_key_len,
8849 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8850 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8851 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8852 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8853 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8854 }
8855 
8856 int
8857 test_pdcp_proto_uplane_encap(int i)
8858 {
8859 	return test_pdcp_proto(
8860 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8861 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8862 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8863 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8864 		pdcp_test_params[i].cipher_key_len,
8865 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8866 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8867 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8868 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8869 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8870 }
8871 
8872 int
8873 test_pdcp_proto_uplane_encap_with_int(int i)
8874 {
8875 	return test_pdcp_proto(
8876 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8877 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8878 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8879 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8880 		pdcp_test_params[i].cipher_key_len,
8881 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8882 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8883 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8884 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8885 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8886 }
8887 
8888 int
8889 test_pdcp_proto_cplane_decap(int i)
8890 {
8891 	return test_pdcp_proto(
8892 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8893 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8894 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8895 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8896 		pdcp_test_params[i].cipher_key_len,
8897 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8898 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8899 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8900 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8901 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8902 }
8903 
8904 int
8905 test_pdcp_proto_uplane_decap(int i)
8906 {
8907 	return test_pdcp_proto(
8908 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8909 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8910 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8911 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8912 		pdcp_test_params[i].cipher_key_len,
8913 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8914 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8915 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8916 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8917 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8918 }
8919 
8920 int
8921 test_pdcp_proto_uplane_decap_with_int(int i)
8922 {
8923 	return test_pdcp_proto(
8924 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8925 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8926 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8927 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8928 		pdcp_test_params[i].cipher_key_len,
8929 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8930 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8931 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8932 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8933 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8934 }
8935 
8936 static int
8937 test_PDCP_PROTO_SGL_in_place_32B(void)
8938 {
8939 	/* i can be used for running any PDCP case
8940 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8941 	 */
8942 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8943 	return test_pdcp_proto_SGL(i, IN_PLACE,
8944 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8945 			RTE_CRYPTO_AUTH_OP_GENERATE,
8946 			pdcp_test_data_in[i],
8947 			pdcp_test_data_in_len[i],
8948 			pdcp_test_data_out[i],
8949 			pdcp_test_data_in_len[i]+4,
8950 			32, 0);
8951 }
8952 static int
8953 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8954 {
8955 	/* i can be used for running any PDCP case
8956 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8957 	 */
8958 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8959 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8960 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8961 			RTE_CRYPTO_AUTH_OP_GENERATE,
8962 			pdcp_test_data_in[i],
8963 			pdcp_test_data_in_len[i],
8964 			pdcp_test_data_out[i],
8965 			pdcp_test_data_in_len[i]+4,
8966 			32, 128);
8967 }
8968 static int
8969 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8970 {
8971 	/* i can be used for running any PDCP case
8972 	 * In this case it is uplane 18-bit AES DL encap
8973 	 */
8974 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8975 			+ DOWNLINK;
8976 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8977 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8978 			RTE_CRYPTO_AUTH_OP_GENERATE,
8979 			pdcp_test_data_in[i],
8980 			pdcp_test_data_in_len[i],
8981 			pdcp_test_data_out[i],
8982 			pdcp_test_data_in_len[i],
8983 			32, 40);
8984 }
8985 static int
8986 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8987 {
8988 	/* i can be used for running any PDCP case
8989 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8990 	 */
8991 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8992 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8993 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8994 			RTE_CRYPTO_AUTH_OP_GENERATE,
8995 			pdcp_test_data_in[i],
8996 			pdcp_test_data_in_len[i],
8997 			pdcp_test_data_out[i],
8998 			pdcp_test_data_in_len[i]+4,
8999 			128, 32);
9000 }
9001 
9002 static int
9003 test_PDCP_SDAP_PROTO_encap_all(void)
9004 {
9005 	int i = 0, size = 0;
9006 	int err, all_err = TEST_SUCCESS;
9007 	const struct pdcp_sdap_test *cur_test;
9008 
9009 	size = RTE_DIM(list_pdcp_sdap_tests);
9010 
9011 	for (i = 0; i < size; i++) {
9012 		cur_test = &list_pdcp_sdap_tests[i];
9013 		err = test_pdcp_proto(
9014 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9015 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9016 			cur_test->in_len, cur_test->data_out,
9017 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9018 			cur_test->param.cipher_alg, cur_test->cipher_key,
9019 			cur_test->param.cipher_key_len,
9020 			cur_test->param.auth_alg,
9021 			cur_test->auth_key, cur_test->param.auth_key_len,
9022 			cur_test->bearer, cur_test->param.domain,
9023 			cur_test->packet_direction, cur_test->sn_size,
9024 			cur_test->hfn,
9025 			cur_test->hfn_threshold, SDAP_ENABLED);
9026 		if (err) {
9027 			printf("\t%d) %s: Encapsulation failed\n",
9028 					cur_test->test_idx,
9029 					cur_test->param.name);
9030 			err = TEST_FAILED;
9031 		} else {
9032 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
9033 					cur_test->param.name);
9034 			err = TEST_SUCCESS;
9035 		}
9036 		all_err += err;
9037 	}
9038 
9039 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9040 
9041 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9042 }
9043 
9044 static int
9045 test_PDCP_PROTO_short_mac(void)
9046 {
9047 	int i = 0, size = 0;
9048 	int err, all_err = TEST_SUCCESS;
9049 	const struct pdcp_short_mac_test *cur_test;
9050 
9051 	size = RTE_DIM(list_pdcp_smac_tests);
9052 
9053 	for (i = 0; i < size; i++) {
9054 		cur_test = &list_pdcp_smac_tests[i];
9055 		err = test_pdcp_proto(
9056 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9057 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9058 			cur_test->in_len, cur_test->data_out,
9059 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9060 			RTE_CRYPTO_CIPHER_NULL, NULL,
9061 			0, cur_test->param.auth_alg,
9062 			cur_test->auth_key, cur_test->param.auth_key_len,
9063 			0, cur_test->param.domain, 0, 0,
9064 			0, 0, 0);
9065 		if (err) {
9066 			printf("\t%d) %s: Short MAC test failed\n",
9067 					cur_test->test_idx,
9068 					cur_test->param.name);
9069 			err = TEST_FAILED;
9070 		} else {
9071 			printf("\t%d) %s: Short MAC test PASS\n",
9072 					cur_test->test_idx,
9073 					cur_test->param.name);
9074 			rte_hexdump(stdout, "MAC I",
9075 				    cur_test->data_out + cur_test->in_len + 2,
9076 				    2);
9077 			err = TEST_SUCCESS;
9078 		}
9079 		all_err += err;
9080 	}
9081 
9082 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9083 
9084 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9085 
9086 }
9087 
9088 static int
9089 test_PDCP_SDAP_PROTO_decap_all(void)
9090 {
9091 	int i = 0, size = 0;
9092 	int err, all_err = TEST_SUCCESS;
9093 	const struct pdcp_sdap_test *cur_test;
9094 
9095 	size = RTE_DIM(list_pdcp_sdap_tests);
9096 
9097 	for (i = 0; i < size; i++) {
9098 		cur_test = &list_pdcp_sdap_tests[i];
9099 		err = test_pdcp_proto(
9100 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9101 			RTE_CRYPTO_AUTH_OP_VERIFY,
9102 			cur_test->data_out,
9103 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9104 			cur_test->data_in, cur_test->in_len,
9105 			cur_test->param.cipher_alg,
9106 			cur_test->cipher_key, cur_test->param.cipher_key_len,
9107 			cur_test->param.auth_alg, cur_test->auth_key,
9108 			cur_test->param.auth_key_len, cur_test->bearer,
9109 			cur_test->param.domain, cur_test->packet_direction,
9110 			cur_test->sn_size, cur_test->hfn,
9111 			cur_test->hfn_threshold, SDAP_ENABLED);
9112 		if (err) {
9113 			printf("\t%d) %s: Decapsulation failed\n",
9114 					cur_test->test_idx,
9115 					cur_test->param.name);
9116 			err = TEST_FAILED;
9117 		} else {
9118 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9119 					cur_test->param.name);
9120 			err = TEST_SUCCESS;
9121 		}
9122 		all_err += err;
9123 	}
9124 
9125 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9126 
9127 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9128 }
9129 
9130 static int
9131 test_ipsec_proto_process(const struct ipsec_test_data td[],
9132 			 struct ipsec_test_data res_d[],
9133 			 int nb_td,
9134 			 bool silent,
9135 			 const struct ipsec_test_flags *flags)
9136 {
9137 	uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
9138 				0x0000, 0x001a};
9139 	uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
9140 				0xe82c, 0x4887};
9141 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9142 	struct crypto_unittest_params *ut_params = &unittest_params;
9143 	struct rte_security_capability_idx sec_cap_idx;
9144 	const struct rte_security_capability *sec_cap;
9145 	struct rte_security_ipsec_xform ipsec_xform;
9146 	uint8_t dev_id = ts_params->valid_devs[0];
9147 	enum rte_security_ipsec_sa_direction dir;
9148 	struct ipsec_test_data *res_d_tmp = NULL;
9149 	uint32_t src = RTE_IPV4(192, 168, 1, 0);
9150 	uint32_t dst = RTE_IPV4(192, 168, 1, 1);
9151 	int salt_len, i, ret = TEST_SUCCESS;
9152 	struct rte_security_ctx *ctx;
9153 	uint8_t *input_text;
9154 	uint32_t verify;
9155 
9156 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9157 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9158 
9159 	/* Use first test data to create session */
9160 
9161 	/* Copy IPsec xform */
9162 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9163 
9164 	dir = ipsec_xform.direction;
9165 	verify = flags->tunnel_hdr_verify;
9166 
9167 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9168 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9169 			src += 1;
9170 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9171 			dst += 1;
9172 	}
9173 
9174 	if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
9175 		if (td->ipsec_xform.tunnel.type ==
9176 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
9177 			memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src,
9178 			       sizeof(src));
9179 			memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst,
9180 			       sizeof(dst));
9181 
9182 			if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
9183 				ipsec_xform.tunnel.ipv4.df = 0;
9184 
9185 			if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
9186 				ipsec_xform.tunnel.ipv4.df = 1;
9187 
9188 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9189 				ipsec_xform.tunnel.ipv4.dscp = 0;
9190 
9191 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9192 				ipsec_xform.tunnel.ipv4.dscp =
9193 						TEST_IPSEC_DSCP_VAL;
9194 
9195 		} else {
9196 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9197 				ipsec_xform.tunnel.ipv6.dscp = 0;
9198 
9199 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9200 				ipsec_xform.tunnel.ipv6.dscp =
9201 						TEST_IPSEC_DSCP_VAL;
9202 
9203 			memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
9204 			       sizeof(v6_src));
9205 			memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
9206 			       sizeof(v6_dst));
9207 		}
9208 	}
9209 
9210 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9211 
9212 	sec_cap_idx.action = ut_params->type;
9213 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9214 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9215 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9216 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9217 
9218 	if (flags->udp_encap)
9219 		ipsec_xform.options.udp_encap = 1;
9220 
9221 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9222 	if (sec_cap == NULL)
9223 		return TEST_SKIPPED;
9224 
9225 	/* Copy cipher session parameters */
9226 	if (td[0].aead) {
9227 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9228 		       sizeof(ut_params->aead_xform));
9229 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9230 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9231 
9232 		/* Verify crypto capabilities */
9233 		if (test_ipsec_crypto_caps_aead_verify(
9234 				sec_cap,
9235 				&ut_params->aead_xform) != 0) {
9236 			if (!silent)
9237 				RTE_LOG(INFO, USER1,
9238 					"Crypto capabilities not supported\n");
9239 			return TEST_SKIPPED;
9240 		}
9241 	} else {
9242 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
9243 		       sizeof(ut_params->cipher_xform));
9244 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9245 		       sizeof(ut_params->auth_xform));
9246 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
9247 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9248 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9249 
9250 		/* Verify crypto capabilities */
9251 
9252 		if (test_ipsec_crypto_caps_cipher_verify(
9253 				sec_cap,
9254 				&ut_params->cipher_xform) != 0) {
9255 			if (!silent)
9256 				RTE_LOG(INFO, USER1,
9257 					"Cipher crypto capabilities not supported\n");
9258 			return TEST_SKIPPED;
9259 		}
9260 
9261 		if (test_ipsec_crypto_caps_auth_verify(
9262 				sec_cap,
9263 				&ut_params->auth_xform) != 0) {
9264 			if (!silent)
9265 				RTE_LOG(INFO, USER1,
9266 					"Auth crypto capabilities not supported\n");
9267 			return TEST_SKIPPED;
9268 		}
9269 	}
9270 
9271 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9272 		return TEST_SKIPPED;
9273 
9274 	struct rte_security_session_conf sess_conf = {
9275 		.action_type = ut_params->type,
9276 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9277 	};
9278 
9279 	if (td[0].aead) {
9280 		salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9281 		memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9282 		sess_conf.ipsec = ipsec_xform;
9283 		sess_conf.crypto_xform = &ut_params->aead_xform;
9284 	} else {
9285 		sess_conf.ipsec = ipsec_xform;
9286 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
9287 			sess_conf.crypto_xform = &ut_params->cipher_xform;
9288 			ut_params->cipher_xform.next = &ut_params->auth_xform;
9289 		} else {
9290 			sess_conf.crypto_xform = &ut_params->auth_xform;
9291 			ut_params->auth_xform.next = &ut_params->cipher_xform;
9292 		}
9293 	}
9294 
9295 	/* Create security session */
9296 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9297 					ts_params->session_mpool,
9298 					ts_params->session_priv_mpool);
9299 
9300 	if (ut_params->sec_session == NULL)
9301 		return TEST_SKIPPED;
9302 
9303 	for (i = 0; i < nb_td; i++) {
9304 		if (flags->antireplay &&
9305 		    (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) {
9306 			sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value;
9307 			ret = rte_security_session_update(ctx,
9308 				ut_params->sec_session, &sess_conf);
9309 			if (ret) {
9310 				printf("Could not update sequence number in "
9311 				       "session\n");
9312 				return TEST_SKIPPED;
9313 			}
9314 		}
9315 
9316 		/* Setup source mbuf payload */
9317 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9318 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9319 				rte_pktmbuf_tailroom(ut_params->ibuf));
9320 
9321 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9322 				td[i].input_text.len);
9323 
9324 		memcpy(input_text, td[i].input_text.data,
9325 		       td[i].input_text.len);
9326 
9327 		if (test_ipsec_pkt_update(input_text, flags))
9328 			return TEST_FAILED;
9329 
9330 		/* Generate crypto op data structure */
9331 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9332 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9333 		if (!ut_params->op) {
9334 			printf("TestCase %s line %d: %s\n",
9335 				__func__, __LINE__,
9336 				"failed to allocate crypto op");
9337 			ret = TEST_FAILED;
9338 			goto crypto_op_free;
9339 		}
9340 
9341 		/* Attach session to operation */
9342 		rte_security_attach_session(ut_params->op,
9343 					    ut_params->sec_session);
9344 
9345 		/* Set crypto operation mbufs */
9346 		ut_params->op->sym->m_src = ut_params->ibuf;
9347 		ut_params->op->sym->m_dst = NULL;
9348 
9349 		/* Copy IV in crypto operation when IV generation is disabled */
9350 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9351 		    ipsec_xform.options.iv_gen_disable == 1) {
9352 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9353 								uint8_t *,
9354 								IV_OFFSET);
9355 			int len;
9356 
9357 			if (td[i].aead)
9358 				len = td[i].xform.aead.aead.iv.length;
9359 			else
9360 				len = td[i].xform.chain.cipher.cipher.iv.length;
9361 
9362 			memcpy(iv, td[i].iv.data, len);
9363 		}
9364 
9365 		/* Process crypto operation */
9366 		process_crypto_request(dev_id, ut_params->op);
9367 
9368 		ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir,
9369 					      i + 1);
9370 		if (ret != TEST_SUCCESS)
9371 			goto crypto_op_free;
9372 
9373 		if (res_d != NULL)
9374 			res_d_tmp = &res_d[i];
9375 
9376 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9377 					      res_d_tmp, silent, flags);
9378 		if (ret != TEST_SUCCESS)
9379 			goto crypto_op_free;
9380 
9381 		ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
9382 					      flags, dir);
9383 		if (ret != TEST_SUCCESS)
9384 			goto crypto_op_free;
9385 
9386 		rte_crypto_op_free(ut_params->op);
9387 		ut_params->op = NULL;
9388 
9389 		rte_pktmbuf_free(ut_params->ibuf);
9390 		ut_params->ibuf = NULL;
9391 	}
9392 
9393 crypto_op_free:
9394 	rte_crypto_op_free(ut_params->op);
9395 	ut_params->op = NULL;
9396 
9397 	rte_pktmbuf_free(ut_params->ibuf);
9398 	ut_params->ibuf = NULL;
9399 
9400 	if (ut_params->sec_session)
9401 		rte_security_session_destroy(ctx, ut_params->sec_session);
9402 	ut_params->sec_session = NULL;
9403 
9404 	return ret;
9405 }
9406 
9407 static int
9408 test_ipsec_proto_known_vec(const void *test_data)
9409 {
9410 	struct ipsec_test_data td_outb;
9411 	struct ipsec_test_flags flags;
9412 
9413 	memset(&flags, 0, sizeof(flags));
9414 
9415 	memcpy(&td_outb, test_data, sizeof(td_outb));
9416 
9417 	if (td_outb.aead ||
9418 	    td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL) {
9419 		/* Disable IV gen to be able to test with known vectors */
9420 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
9421 	}
9422 
9423 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9424 }
9425 
9426 static int
9427 test_ipsec_proto_known_vec_inb(const void *test_data)
9428 {
9429 	const struct ipsec_test_data *td = test_data;
9430 	struct ipsec_test_flags flags;
9431 	struct ipsec_test_data td_inb;
9432 
9433 	memset(&flags, 0, sizeof(flags));
9434 
9435 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
9436 		test_ipsec_td_in_from_out(td, &td_inb);
9437 	else
9438 		memcpy(&td_inb, td, sizeof(td_inb));
9439 
9440 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9441 }
9442 
9443 static int
9444 test_ipsec_proto_known_vec_fragmented(const void *test_data)
9445 {
9446 	struct ipsec_test_data td_outb;
9447 	struct ipsec_test_flags flags;
9448 
9449 	memset(&flags, 0, sizeof(flags));
9450 	flags.fragment = true;
9451 
9452 	memcpy(&td_outb, test_data, sizeof(td_outb));
9453 
9454 	/* Disable IV gen to be able to test with known vectors */
9455 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9456 
9457 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9458 }
9459 
9460 static int
9461 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9462 {
9463 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9464 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9465 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9466 	int ret;
9467 
9468 	if (flags->iv_gen ||
9469 	    flags->sa_expiry_pkts_soft ||
9470 	    flags->sa_expiry_pkts_hard)
9471 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9472 
9473 	for (i = 0; i < RTE_DIM(alg_list); i++) {
9474 		test_ipsec_td_prepare(alg_list[i].param1,
9475 				      alg_list[i].param2,
9476 				      flags,
9477 				      td_outb,
9478 				      nb_pkts);
9479 
9480 		if (!td_outb->aead) {
9481 			enum rte_crypto_cipher_algorithm cipher_alg;
9482 			enum rte_crypto_auth_algorithm auth_alg;
9483 
9484 			cipher_alg = td_outb->xform.chain.cipher.cipher.algo;
9485 			auth_alg = td_outb->xform.chain.auth.auth.algo;
9486 
9487 			/* ICV is not applicable for NULL auth */
9488 			if (flags->icv_corrupt &&
9489 			    auth_alg == RTE_CRYPTO_AUTH_NULL)
9490 				continue;
9491 
9492 			/* IV is not applicable for NULL cipher */
9493 			if (flags->iv_gen &&
9494 			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
9495 				continue;
9496 		}
9497 
9498 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9499 					       flags);
9500 		if (ret == TEST_SKIPPED)
9501 			continue;
9502 
9503 		if (ret == TEST_FAILED)
9504 			return TEST_FAILED;
9505 
9506 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9507 
9508 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9509 					       flags);
9510 		if (ret == TEST_SKIPPED)
9511 			continue;
9512 
9513 		if (ret == TEST_FAILED)
9514 			return TEST_FAILED;
9515 
9516 		if (flags->display_alg)
9517 			test_ipsec_display_alg(alg_list[i].param1,
9518 					       alg_list[i].param2);
9519 
9520 		pass_cnt++;
9521 	}
9522 
9523 	if (pass_cnt > 0)
9524 		return TEST_SUCCESS;
9525 	else
9526 		return TEST_SKIPPED;
9527 }
9528 
9529 static int
9530 test_ipsec_proto_display_list(const void *data __rte_unused)
9531 {
9532 	struct ipsec_test_flags flags;
9533 
9534 	memset(&flags, 0, sizeof(flags));
9535 
9536 	flags.display_alg = true;
9537 
9538 	return test_ipsec_proto_all(&flags);
9539 }
9540 
9541 static int
9542 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9543 {
9544 	struct ipsec_test_flags flags;
9545 
9546 	memset(&flags, 0, sizeof(flags));
9547 
9548 	flags.iv_gen = true;
9549 
9550 	return test_ipsec_proto_all(&flags);
9551 }
9552 
9553 static int
9554 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9555 {
9556 	struct ipsec_test_flags flags;
9557 
9558 	memset(&flags, 0, sizeof(flags));
9559 
9560 	flags.sa_expiry_pkts_soft = true;
9561 
9562 	return test_ipsec_proto_all(&flags);
9563 }
9564 
9565 static int
9566 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9567 {
9568 	struct ipsec_test_flags flags;
9569 
9570 	memset(&flags, 0, sizeof(flags));
9571 
9572 	flags.sa_expiry_pkts_hard = true;
9573 
9574 	return test_ipsec_proto_all(&flags);
9575 }
9576 
9577 static int
9578 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9579 {
9580 	struct ipsec_test_flags flags;
9581 
9582 	memset(&flags, 0, sizeof(flags));
9583 
9584 	flags.icv_corrupt = true;
9585 
9586 	return test_ipsec_proto_all(&flags);
9587 }
9588 
9589 static int
9590 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9591 {
9592 	struct ipsec_test_flags flags;
9593 
9594 	memset(&flags, 0, sizeof(flags));
9595 
9596 	flags.udp_encap = true;
9597 
9598 	return test_ipsec_proto_all(&flags);
9599 }
9600 
9601 static int
9602 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9603 {
9604 	struct ipsec_test_flags flags;
9605 
9606 	memset(&flags, 0, sizeof(flags));
9607 
9608 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9609 
9610 	return test_ipsec_proto_all(&flags);
9611 }
9612 
9613 static int
9614 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9615 {
9616 	struct ipsec_test_flags flags;
9617 
9618 	memset(&flags, 0, sizeof(flags));
9619 
9620 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9621 
9622 	return test_ipsec_proto_all(&flags);
9623 }
9624 
9625 static int
9626 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9627 {
9628 	struct ipsec_test_flags flags;
9629 
9630 	memset(&flags, 0, sizeof(flags));
9631 
9632 	flags.udp_encap = true;
9633 	flags.udp_ports_verify = true;
9634 
9635 	return test_ipsec_proto_all(&flags);
9636 }
9637 
9638 static int
9639 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9640 {
9641 	struct ipsec_test_flags flags;
9642 
9643 	memset(&flags, 0, sizeof(flags));
9644 
9645 	flags.ip_csum = true;
9646 
9647 	return test_ipsec_proto_all(&flags);
9648 }
9649 
9650 static int
9651 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9652 {
9653 	struct ipsec_test_flags flags;
9654 
9655 	memset(&flags, 0, sizeof(flags));
9656 
9657 	flags.l4_csum = true;
9658 
9659 	return test_ipsec_proto_all(&flags);
9660 }
9661 
9662 static int
9663 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused)
9664 {
9665 	struct ipsec_test_flags flags;
9666 
9667 	memset(&flags, 0, sizeof(flags));
9668 
9669 	flags.ipv6 = false;
9670 	flags.tunnel_ipv6 = false;
9671 
9672 	return test_ipsec_proto_all(&flags);
9673 }
9674 
9675 static int
9676 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused)
9677 {
9678 	struct ipsec_test_flags flags;
9679 
9680 	memset(&flags, 0, sizeof(flags));
9681 
9682 	flags.ipv6 = true;
9683 	flags.tunnel_ipv6 = true;
9684 
9685 	return test_ipsec_proto_all(&flags);
9686 }
9687 
9688 static int
9689 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused)
9690 {
9691 	struct ipsec_test_flags flags;
9692 
9693 	memset(&flags, 0, sizeof(flags));
9694 
9695 	flags.ipv6 = false;
9696 	flags.tunnel_ipv6 = true;
9697 
9698 	return test_ipsec_proto_all(&flags);
9699 }
9700 
9701 static int
9702 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused)
9703 {
9704 	struct ipsec_test_flags flags;
9705 
9706 	memset(&flags, 0, sizeof(flags));
9707 
9708 	flags.ipv6 = true;
9709 	flags.tunnel_ipv6 = false;
9710 
9711 	return test_ipsec_proto_all(&flags);
9712 }
9713 
9714 static int
9715 test_ipsec_proto_transport_v4(const void *data __rte_unused)
9716 {
9717 	struct ipsec_test_flags flags;
9718 
9719 	memset(&flags, 0, sizeof(flags));
9720 
9721 	flags.ipv6 = false;
9722 	flags.transport = true;
9723 
9724 	return test_ipsec_proto_all(&flags);
9725 }
9726 
9727 static int
9728 test_ipsec_proto_transport_l4_csum(const void *data __rte_unused)
9729 {
9730 	struct ipsec_test_flags flags = {
9731 		.l4_csum = true,
9732 		.transport = true,
9733 	};
9734 
9735 	return test_ipsec_proto_all(&flags);
9736 }
9737 
9738 static int
9739 test_ipsec_proto_stats(const void *data __rte_unused)
9740 {
9741 	struct ipsec_test_flags flags;
9742 
9743 	memset(&flags, 0, sizeof(flags));
9744 
9745 	flags.stats_success = true;
9746 
9747 	return test_ipsec_proto_all(&flags);
9748 }
9749 
9750 static int
9751 test_ipsec_proto_pkt_fragment(const void *data __rte_unused)
9752 {
9753 	struct ipsec_test_flags flags;
9754 
9755 	memset(&flags, 0, sizeof(flags));
9756 
9757 	flags.fragment = true;
9758 
9759 	return test_ipsec_proto_all(&flags);
9760 
9761 }
9762 
9763 static int
9764 test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused)
9765 {
9766 	struct ipsec_test_flags flags;
9767 
9768 	memset(&flags, 0, sizeof(flags));
9769 
9770 	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
9771 
9772 	return test_ipsec_proto_all(&flags);
9773 }
9774 
9775 static int
9776 test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused)
9777 {
9778 	struct ipsec_test_flags flags;
9779 
9780 	memset(&flags, 0, sizeof(flags));
9781 
9782 	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
9783 
9784 	return test_ipsec_proto_all(&flags);
9785 }
9786 
9787 static int
9788 test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused)
9789 {
9790 	struct ipsec_test_flags flags;
9791 
9792 	memset(&flags, 0, sizeof(flags));
9793 
9794 	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
9795 
9796 	return test_ipsec_proto_all(&flags);
9797 }
9798 
9799 static int
9800 test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused)
9801 {
9802 	struct ipsec_test_flags flags;
9803 
9804 	memset(&flags, 0, sizeof(flags));
9805 
9806 	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
9807 
9808 	return test_ipsec_proto_all(&flags);
9809 }
9810 
9811 static int
9812 test_ipsec_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused)
9813 {
9814 	struct ipsec_test_flags flags;
9815 
9816 	memset(&flags, 0, sizeof(flags));
9817 
9818 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
9819 
9820 	return test_ipsec_proto_all(&flags);
9821 }
9822 
9823 static int
9824 test_ipsec_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused)
9825 {
9826 	struct ipsec_test_flags flags;
9827 
9828 	memset(&flags, 0, sizeof(flags));
9829 
9830 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
9831 
9832 	return test_ipsec_proto_all(&flags);
9833 }
9834 
9835 static int
9836 test_ipsec_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused)
9837 {
9838 	struct ipsec_test_flags flags;
9839 
9840 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9841 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9842 		return TEST_SKIPPED;
9843 
9844 	memset(&flags, 0, sizeof(flags));
9845 
9846 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
9847 
9848 	return test_ipsec_proto_all(&flags);
9849 }
9850 
9851 static int
9852 test_ipsec_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused)
9853 {
9854 	struct ipsec_test_flags flags;
9855 
9856 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9857 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9858 		return TEST_SKIPPED;
9859 
9860 	memset(&flags, 0, sizeof(flags));
9861 
9862 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
9863 
9864 	return test_ipsec_proto_all(&flags);
9865 }
9866 
9867 static int
9868 test_ipsec_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused)
9869 {
9870 	struct ipsec_test_flags flags;
9871 
9872 	memset(&flags, 0, sizeof(flags));
9873 
9874 	flags.ipv6 = true;
9875 	flags.tunnel_ipv6 = true;
9876 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
9877 
9878 	return test_ipsec_proto_all(&flags);
9879 }
9880 
9881 static int
9882 test_ipsec_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused)
9883 {
9884 	struct ipsec_test_flags flags;
9885 
9886 	memset(&flags, 0, sizeof(flags));
9887 
9888 	flags.ipv6 = true;
9889 	flags.tunnel_ipv6 = true;
9890 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
9891 
9892 	return test_ipsec_proto_all(&flags);
9893 }
9894 
9895 static int
9896 test_ipsec_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused)
9897 {
9898 	struct ipsec_test_flags flags;
9899 
9900 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9901 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9902 		return TEST_SKIPPED;
9903 
9904 	memset(&flags, 0, sizeof(flags));
9905 
9906 	flags.ipv6 = true;
9907 	flags.tunnel_ipv6 = true;
9908 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
9909 
9910 	return test_ipsec_proto_all(&flags);
9911 }
9912 
9913 static int
9914 test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)
9915 {
9916 	struct ipsec_test_flags flags;
9917 
9918 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
9919 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
9920 		return TEST_SKIPPED;
9921 
9922 	memset(&flags, 0, sizeof(flags));
9923 
9924 	flags.ipv6 = true;
9925 	flags.tunnel_ipv6 = true;
9926 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
9927 
9928 	return test_ipsec_proto_all(&flags);
9929 }
9930 
9931 static int
9932 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[],
9933 		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
9934 		      uint64_t winsz)
9935 {
9936 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9937 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9938 	struct ipsec_test_flags flags;
9939 	uint32_t i = 0, ret = 0;
9940 
9941 	memset(&flags, 0, sizeof(flags));
9942 	flags.antireplay = true;
9943 
9944 	for (i = 0; i < nb_pkts; i++) {
9945 		memcpy(&td_outb[i], test_data, sizeof(td_outb[i]));
9946 		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
9947 		td_outb[i].ipsec_xform.replay_win_sz = winsz;
9948 		td_outb[i].ipsec_xform.options.esn = esn_en;
9949 	}
9950 
9951 	for (i = 0; i < nb_pkts; i++)
9952 		td_outb[i].ipsec_xform.esn.value = esn[i];
9953 
9954 	ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9955 				       &flags);
9956 	if (ret != TEST_SUCCESS)
9957 		return ret;
9958 
9959 	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
9960 
9961 	for (i = 0; i < nb_pkts; i++) {
9962 		td_inb[i].ipsec_xform.options.esn = esn_en;
9963 		/* Set antireplay flag for packets to be dropped */
9964 		td_inb[i].ar_packet = replayed_pkt[i];
9965 	}
9966 
9967 	ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9968 				       &flags);
9969 
9970 	return ret;
9971 }
9972 
9973 static int
9974 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
9975 {
9976 
9977 	uint32_t nb_pkts = 5;
9978 	bool replayed_pkt[5];
9979 	uint64_t esn[5];
9980 
9981 	/* 1. Advance the TOP of the window to WS * 2 */
9982 	esn[0] = winsz * 2;
9983 	/* 2. Test sequence number within the new window(WS + 1) */
9984 	esn[1] = winsz + 1;
9985 	/* 3. Test sequence number less than the window BOTTOM */
9986 	esn[2] = winsz;
9987 	/* 4. Test sequence number in the middle of the window */
9988 	esn[3] = winsz + (winsz / 2);
9989 	/* 5. Test replay of the packet in the middle of the window */
9990 	esn[4] = winsz + (winsz / 2);
9991 
9992 	replayed_pkt[0] = false;
9993 	replayed_pkt[1] = false;
9994 	replayed_pkt[2] = true;
9995 	replayed_pkt[3] = false;
9996 	replayed_pkt[4] = true;
9997 
9998 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
9999 				     false, winsz);
10000 }
10001 
10002 static int
10003 test_ipsec_proto_pkt_antireplay1024(const void *test_data)
10004 {
10005 	return test_ipsec_proto_pkt_antireplay(test_data, 1024);
10006 }
10007 
10008 static int
10009 test_ipsec_proto_pkt_antireplay2048(const void *test_data)
10010 {
10011 	return test_ipsec_proto_pkt_antireplay(test_data, 2048);
10012 }
10013 
10014 static int
10015 test_ipsec_proto_pkt_antireplay4096(const void *test_data)
10016 {
10017 	return test_ipsec_proto_pkt_antireplay(test_data, 4096);
10018 }
10019 
10020 static int
10021 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
10022 {
10023 
10024 	uint32_t nb_pkts = 7;
10025 	bool replayed_pkt[7];
10026 	uint64_t esn[7];
10027 
10028 	/* Set the initial sequence number */
10029 	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
10030 	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
10031 	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
10032 	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
10033 	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
10034 	/* 3. Test with sequence number within window (1<<32 - 1) */
10035 	esn[3] = (uint64_t)((1ULL << 32) - 1);
10036 	/* 4. Test with sequence number within window (1<<32 - 1) */
10037 	esn[4] = (uint64_t)(1ULL << 32);
10038 	/* 5. Test with duplicate sequence number within
10039 	 * new window (1<<32 - 1)
10040 	 */
10041 	esn[5] = (uint64_t)((1ULL << 32) - 1);
10042 	/* 6. Test with duplicate sequence number within new window (1<<32) */
10043 	esn[6] = (uint64_t)(1ULL << 32);
10044 
10045 	replayed_pkt[0] = false;
10046 	replayed_pkt[1] = false;
10047 	replayed_pkt[2] = false;
10048 	replayed_pkt[3] = false;
10049 	replayed_pkt[4] = false;
10050 	replayed_pkt[5] = true;
10051 	replayed_pkt[6] = true;
10052 
10053 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10054 				     true, winsz);
10055 }
10056 
10057 static int
10058 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data)
10059 {
10060 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024);
10061 }
10062 
10063 static int
10064 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data)
10065 {
10066 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048);
10067 }
10068 
10069 static int
10070 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data)
10071 {
10072 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096);
10073 }
10074 
10075 static int
10076 test_PDCP_PROTO_all(void)
10077 {
10078 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10079 	struct crypto_unittest_params *ut_params = &unittest_params;
10080 	struct rte_cryptodev_info dev_info;
10081 	int status;
10082 
10083 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10084 	uint64_t feat_flags = dev_info.feature_flags;
10085 
10086 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
10087 		return TEST_SKIPPED;
10088 
10089 	/* Set action type */
10090 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10091 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10092 		gbl_action_type;
10093 
10094 	if (security_proto_supported(ut_params->type,
10095 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
10096 		return TEST_SKIPPED;
10097 
10098 	status = test_PDCP_PROTO_cplane_encap_all();
10099 	status += test_PDCP_PROTO_cplane_decap_all();
10100 	status += test_PDCP_PROTO_uplane_encap_all();
10101 	status += test_PDCP_PROTO_uplane_decap_all();
10102 	status += test_PDCP_PROTO_SGL_in_place_32B();
10103 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
10104 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
10105 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
10106 	status += test_PDCP_SDAP_PROTO_encap_all();
10107 	status += test_PDCP_SDAP_PROTO_decap_all();
10108 	status += test_PDCP_PROTO_short_mac();
10109 
10110 	if (status)
10111 		return TEST_FAILED;
10112 	else
10113 		return TEST_SUCCESS;
10114 }
10115 
10116 static int
10117 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused)
10118 {
10119 	struct ipsec_test_flags flags = {
10120 		.dec_ttl_or_hop_limit = true
10121 	};
10122 
10123 	return test_ipsec_proto_all(&flags);
10124 }
10125 
10126 static int
10127 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused)
10128 {
10129 	struct ipsec_test_flags flags = {
10130 		.ipv6 = true,
10131 		.dec_ttl_or_hop_limit = true
10132 	};
10133 
10134 	return test_ipsec_proto_all(&flags);
10135 }
10136 
10137 static int
10138 test_docsis_proto_uplink(const void *data)
10139 {
10140 	const struct docsis_test_data *d_td = data;
10141 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10142 	struct crypto_unittest_params *ut_params = &unittest_params;
10143 	uint8_t *plaintext = NULL;
10144 	uint8_t *ciphertext = NULL;
10145 	uint8_t *iv_ptr;
10146 	int32_t cipher_len, crc_len;
10147 	uint32_t crc_data_len;
10148 	int ret = TEST_SUCCESS;
10149 
10150 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
10151 					rte_cryptodev_get_sec_ctx(
10152 						ts_params->valid_devs[0]);
10153 
10154 	/* Verify the capabilities */
10155 	struct rte_security_capability_idx sec_cap_idx;
10156 	const struct rte_security_capability *sec_cap;
10157 	const struct rte_cryptodev_capabilities *crypto_cap;
10158 	const struct rte_cryptodev_symmetric_capability *sym_cap;
10159 	int j = 0;
10160 
10161 	/* Set action type */
10162 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10163 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10164 		gbl_action_type;
10165 
10166 	if (security_proto_supported(ut_params->type,
10167 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10168 		return TEST_SKIPPED;
10169 
10170 	sec_cap_idx.action = ut_params->type;
10171 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
10172 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
10173 
10174 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10175 	if (sec_cap == NULL)
10176 		return TEST_SKIPPED;
10177 
10178 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
10179 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
10180 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
10181 				crypto_cap->sym.xform_type ==
10182 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
10183 				crypto_cap->sym.cipher.algo ==
10184 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
10185 			sym_cap = &crypto_cap->sym;
10186 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
10187 						d_td->key.len,
10188 						d_td->iv.len) == 0)
10189 				break;
10190 		}
10191 	}
10192 
10193 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
10194 		return TEST_SKIPPED;
10195 
10196 	/* Setup source mbuf payload */
10197 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10198 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10199 			rte_pktmbuf_tailroom(ut_params->ibuf));
10200 
10201 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10202 			d_td->ciphertext.len);
10203 
10204 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
10205 
10206 	/* Setup cipher session parameters */
10207 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10208 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
10209 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
10210 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
10211 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
10212 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
10213 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10214 	ut_params->cipher_xform.next = NULL;
10215 
10216 	/* Setup DOCSIS session parameters */
10217 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
10218 
10219 	struct rte_security_session_conf sess_conf = {
10220 		.action_type = ut_params->type,
10221 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
10222 		.docsis = ut_params->docsis_xform,
10223 		.crypto_xform = &ut_params->cipher_xform,
10224 	};
10225 
10226 	/* Create security session */
10227 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10228 					ts_params->session_mpool,
10229 					ts_params->session_priv_mpool);
10230 
10231 	if (!ut_params->sec_session) {
10232 		printf("Test function %s line %u: failed to allocate session\n",
10233 			__func__, __LINE__);
10234 		ret = TEST_FAILED;
10235 		goto on_err;
10236 	}
10237 
10238 	/* Generate crypto op data structure */
10239 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10240 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10241 	if (!ut_params->op) {
10242 		printf("Test function %s line %u: failed to allocate symmetric "
10243 			"crypto operation\n", __func__, __LINE__);
10244 		ret = TEST_FAILED;
10245 		goto on_err;
10246 	}
10247 
10248 	/* Setup CRC operation parameters */
10249 	crc_len = d_td->ciphertext.no_crc == false ?
10250 			(d_td->ciphertext.len -
10251 				d_td->ciphertext.crc_offset -
10252 				RTE_ETHER_CRC_LEN) :
10253 			0;
10254 	crc_len = crc_len > 0 ? crc_len : 0;
10255 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
10256 	ut_params->op->sym->auth.data.length = crc_len;
10257 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
10258 
10259 	/* Setup cipher operation parameters */
10260 	cipher_len = d_td->ciphertext.no_cipher == false ?
10261 			(d_td->ciphertext.len -
10262 				d_td->ciphertext.cipher_offset) :
10263 			0;
10264 	cipher_len = cipher_len > 0 ? cipher_len : 0;
10265 	ut_params->op->sym->cipher.data.length = cipher_len;
10266 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
10267 
10268 	/* Setup cipher IV */
10269 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
10270 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
10271 
10272 	/* Attach session to operation */
10273 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10274 
10275 	/* Set crypto operation mbufs */
10276 	ut_params->op->sym->m_src = ut_params->ibuf;
10277 	ut_params->op->sym->m_dst = NULL;
10278 
10279 	/* Process crypto operation */
10280 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10281 			NULL) {
10282 		printf("Test function %s line %u: failed to process security "
10283 			"crypto op\n", __func__, __LINE__);
10284 		ret = TEST_FAILED;
10285 		goto on_err;
10286 	}
10287 
10288 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10289 		printf("Test function %s line %u: failed to process crypto op\n",
10290 			__func__, __LINE__);
10291 		ret = TEST_FAILED;
10292 		goto on_err;
10293 	}
10294 
10295 	/* Validate plaintext */
10296 	plaintext = ciphertext;
10297 
10298 	if (memcmp(plaintext, d_td->plaintext.data,
10299 			d_td->plaintext.len - crc_data_len)) {
10300 		printf("Test function %s line %u: plaintext not as expected\n",
10301 			__func__, __LINE__);
10302 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
10303 				d_td->plaintext.len);
10304 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
10305 		ret = TEST_FAILED;
10306 		goto on_err;
10307 	}
10308 
10309 on_err:
10310 	rte_crypto_op_free(ut_params->op);
10311 	ut_params->op = NULL;
10312 
10313 	if (ut_params->sec_session)
10314 		rte_security_session_destroy(ctx, ut_params->sec_session);
10315 	ut_params->sec_session = NULL;
10316 
10317 	rte_pktmbuf_free(ut_params->ibuf);
10318 	ut_params->ibuf = NULL;
10319 
10320 	return ret;
10321 }
10322 
10323 static int
10324 test_docsis_proto_downlink(const void *data)
10325 {
10326 	const struct docsis_test_data *d_td = data;
10327 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10328 	struct crypto_unittest_params *ut_params = &unittest_params;
10329 	uint8_t *plaintext = NULL;
10330 	uint8_t *ciphertext = NULL;
10331 	uint8_t *iv_ptr;
10332 	int32_t cipher_len, crc_len;
10333 	int ret = TEST_SUCCESS;
10334 
10335 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
10336 					rte_cryptodev_get_sec_ctx(
10337 						ts_params->valid_devs[0]);
10338 
10339 	/* Verify the capabilities */
10340 	struct rte_security_capability_idx sec_cap_idx;
10341 	const struct rte_security_capability *sec_cap;
10342 	const struct rte_cryptodev_capabilities *crypto_cap;
10343 	const struct rte_cryptodev_symmetric_capability *sym_cap;
10344 	int j = 0;
10345 
10346 	/* Set action type */
10347 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10348 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10349 		gbl_action_type;
10350 
10351 	if (security_proto_supported(ut_params->type,
10352 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10353 		return TEST_SKIPPED;
10354 
10355 	sec_cap_idx.action = ut_params->type;
10356 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
10357 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
10358 
10359 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10360 	if (sec_cap == NULL)
10361 		return TEST_SKIPPED;
10362 
10363 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
10364 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
10365 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
10366 				crypto_cap->sym.xform_type ==
10367 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
10368 				crypto_cap->sym.cipher.algo ==
10369 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
10370 			sym_cap = &crypto_cap->sym;
10371 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
10372 						d_td->key.len,
10373 						d_td->iv.len) == 0)
10374 				break;
10375 		}
10376 	}
10377 
10378 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
10379 		return TEST_SKIPPED;
10380 
10381 	/* Setup source mbuf payload */
10382 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10383 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10384 			rte_pktmbuf_tailroom(ut_params->ibuf));
10385 
10386 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10387 			d_td->plaintext.len);
10388 
10389 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
10390 
10391 	/* Setup cipher session parameters */
10392 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10393 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
10394 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10395 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
10396 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
10397 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
10398 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10399 	ut_params->cipher_xform.next = NULL;
10400 
10401 	/* Setup DOCSIS session parameters */
10402 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
10403 
10404 	struct rte_security_session_conf sess_conf = {
10405 		.action_type = ut_params->type,
10406 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
10407 		.docsis = ut_params->docsis_xform,
10408 		.crypto_xform = &ut_params->cipher_xform,
10409 	};
10410 
10411 	/* Create security session */
10412 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10413 					ts_params->session_mpool,
10414 					ts_params->session_priv_mpool);
10415 
10416 	if (!ut_params->sec_session) {
10417 		printf("Test function %s line %u: failed to allocate session\n",
10418 			__func__, __LINE__);
10419 		ret = TEST_FAILED;
10420 		goto on_err;
10421 	}
10422 
10423 	/* Generate crypto op data structure */
10424 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10425 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10426 	if (!ut_params->op) {
10427 		printf("Test function %s line %u: failed to allocate symmetric "
10428 			"crypto operation\n", __func__, __LINE__);
10429 		ret = TEST_FAILED;
10430 		goto on_err;
10431 	}
10432 
10433 	/* Setup CRC operation parameters */
10434 	crc_len = d_td->plaintext.no_crc == false ?
10435 			(d_td->plaintext.len -
10436 				d_td->plaintext.crc_offset -
10437 				RTE_ETHER_CRC_LEN) :
10438 			0;
10439 	crc_len = crc_len > 0 ? crc_len : 0;
10440 	ut_params->op->sym->auth.data.length = crc_len;
10441 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
10442 
10443 	/* Setup cipher operation parameters */
10444 	cipher_len = d_td->plaintext.no_cipher == false ?
10445 			(d_td->plaintext.len -
10446 				d_td->plaintext.cipher_offset) :
10447 			0;
10448 	cipher_len = cipher_len > 0 ? cipher_len : 0;
10449 	ut_params->op->sym->cipher.data.length = cipher_len;
10450 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
10451 
10452 	/* Setup cipher IV */
10453 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
10454 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
10455 
10456 	/* Attach session to operation */
10457 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10458 
10459 	/* Set crypto operation mbufs */
10460 	ut_params->op->sym->m_src = ut_params->ibuf;
10461 	ut_params->op->sym->m_dst = NULL;
10462 
10463 	/* Process crypto operation */
10464 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10465 			NULL) {
10466 		printf("Test function %s line %u: failed to process crypto op\n",
10467 			__func__, __LINE__);
10468 		ret = TEST_FAILED;
10469 		goto on_err;
10470 	}
10471 
10472 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10473 		printf("Test function %s line %u: crypto op processing failed\n",
10474 			__func__, __LINE__);
10475 		ret = TEST_FAILED;
10476 		goto on_err;
10477 	}
10478 
10479 	/* Validate ciphertext */
10480 	ciphertext = plaintext;
10481 
10482 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
10483 		printf("Test function %s line %u: plaintext not as expected\n",
10484 			__func__, __LINE__);
10485 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
10486 				d_td->ciphertext.len);
10487 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
10488 		ret = TEST_FAILED;
10489 		goto on_err;
10490 	}
10491 
10492 on_err:
10493 	rte_crypto_op_free(ut_params->op);
10494 	ut_params->op = NULL;
10495 
10496 	if (ut_params->sec_session)
10497 		rte_security_session_destroy(ctx, ut_params->sec_session);
10498 	ut_params->sec_session = NULL;
10499 
10500 	rte_pktmbuf_free(ut_params->ibuf);
10501 	ut_params->ibuf = NULL;
10502 
10503 	return ret;
10504 }
10505 #endif
10506 
10507 static int
10508 test_AES_GCM_authenticated_encryption_test_case_1(void)
10509 {
10510 	return test_authenticated_encryption(&gcm_test_case_1);
10511 }
10512 
10513 static int
10514 test_AES_GCM_authenticated_encryption_test_case_2(void)
10515 {
10516 	return test_authenticated_encryption(&gcm_test_case_2);
10517 }
10518 
10519 static int
10520 test_AES_GCM_authenticated_encryption_test_case_3(void)
10521 {
10522 	return test_authenticated_encryption(&gcm_test_case_3);
10523 }
10524 
10525 static int
10526 test_AES_GCM_authenticated_encryption_test_case_4(void)
10527 {
10528 	return test_authenticated_encryption(&gcm_test_case_4);
10529 }
10530 
10531 static int
10532 test_AES_GCM_authenticated_encryption_test_case_5(void)
10533 {
10534 	return test_authenticated_encryption(&gcm_test_case_5);
10535 }
10536 
10537 static int
10538 test_AES_GCM_authenticated_encryption_test_case_6(void)
10539 {
10540 	return test_authenticated_encryption(&gcm_test_case_6);
10541 }
10542 
10543 static int
10544 test_AES_GCM_authenticated_encryption_test_case_7(void)
10545 {
10546 	return test_authenticated_encryption(&gcm_test_case_7);
10547 }
10548 
10549 static int
10550 test_AES_GCM_authenticated_encryption_test_case_8(void)
10551 {
10552 	return test_authenticated_encryption(&gcm_test_case_8);
10553 }
10554 
10555 static int
10556 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
10557 {
10558 	return test_authenticated_encryption(&gcm_J0_test_case_1);
10559 }
10560 
10561 static int
10562 test_AES_GCM_auth_encryption_test_case_192_1(void)
10563 {
10564 	return test_authenticated_encryption(&gcm_test_case_192_1);
10565 }
10566 
10567 static int
10568 test_AES_GCM_auth_encryption_test_case_192_2(void)
10569 {
10570 	return test_authenticated_encryption(&gcm_test_case_192_2);
10571 }
10572 
10573 static int
10574 test_AES_GCM_auth_encryption_test_case_192_3(void)
10575 {
10576 	return test_authenticated_encryption(&gcm_test_case_192_3);
10577 }
10578 
10579 static int
10580 test_AES_GCM_auth_encryption_test_case_192_4(void)
10581 {
10582 	return test_authenticated_encryption(&gcm_test_case_192_4);
10583 }
10584 
10585 static int
10586 test_AES_GCM_auth_encryption_test_case_192_5(void)
10587 {
10588 	return test_authenticated_encryption(&gcm_test_case_192_5);
10589 }
10590 
10591 static int
10592 test_AES_GCM_auth_encryption_test_case_192_6(void)
10593 {
10594 	return test_authenticated_encryption(&gcm_test_case_192_6);
10595 }
10596 
10597 static int
10598 test_AES_GCM_auth_encryption_test_case_192_7(void)
10599 {
10600 	return test_authenticated_encryption(&gcm_test_case_192_7);
10601 }
10602 
10603 static int
10604 test_AES_GCM_auth_encryption_test_case_256_1(void)
10605 {
10606 	return test_authenticated_encryption(&gcm_test_case_256_1);
10607 }
10608 
10609 static int
10610 test_AES_GCM_auth_encryption_test_case_256_2(void)
10611 {
10612 	return test_authenticated_encryption(&gcm_test_case_256_2);
10613 }
10614 
10615 static int
10616 test_AES_GCM_auth_encryption_test_case_256_3(void)
10617 {
10618 	return test_authenticated_encryption(&gcm_test_case_256_3);
10619 }
10620 
10621 static int
10622 test_AES_GCM_auth_encryption_test_case_256_4(void)
10623 {
10624 	return test_authenticated_encryption(&gcm_test_case_256_4);
10625 }
10626 
10627 static int
10628 test_AES_GCM_auth_encryption_test_case_256_5(void)
10629 {
10630 	return test_authenticated_encryption(&gcm_test_case_256_5);
10631 }
10632 
10633 static int
10634 test_AES_GCM_auth_encryption_test_case_256_6(void)
10635 {
10636 	return test_authenticated_encryption(&gcm_test_case_256_6);
10637 }
10638 
10639 static int
10640 test_AES_GCM_auth_encryption_test_case_256_7(void)
10641 {
10642 	return test_authenticated_encryption(&gcm_test_case_256_7);
10643 }
10644 
10645 static int
10646 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10647 {
10648 	return test_authenticated_encryption(&gcm_test_case_aad_1);
10649 }
10650 
10651 static int
10652 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10653 {
10654 	return test_authenticated_encryption(&gcm_test_case_aad_2);
10655 }
10656 
10657 static int
10658 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10659 {
10660 	struct aead_test_data tdata;
10661 	int res;
10662 
10663 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10664 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10665 	tdata.iv.data[0] += 1;
10666 	res = test_authenticated_encryption(&tdata);
10667 	if (res == TEST_SKIPPED)
10668 		return res;
10669 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10670 	return TEST_SUCCESS;
10671 }
10672 
10673 static int
10674 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10675 {
10676 	struct aead_test_data tdata;
10677 	int res;
10678 
10679 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10680 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10681 	tdata.plaintext.data[0] += 1;
10682 	res = test_authenticated_encryption(&tdata);
10683 	if (res == TEST_SKIPPED)
10684 		return res;
10685 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10686 	return TEST_SUCCESS;
10687 }
10688 
10689 static int
10690 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10691 {
10692 	struct aead_test_data tdata;
10693 	int res;
10694 
10695 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10696 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10697 	tdata.ciphertext.data[0] += 1;
10698 	res = test_authenticated_encryption(&tdata);
10699 	if (res == TEST_SKIPPED)
10700 		return res;
10701 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10702 	return TEST_SUCCESS;
10703 }
10704 
10705 static int
10706 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10707 {
10708 	struct aead_test_data tdata;
10709 	int res;
10710 
10711 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10712 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10713 	tdata.aad.len += 1;
10714 	res = test_authenticated_encryption(&tdata);
10715 	if (res == TEST_SKIPPED)
10716 		return res;
10717 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10718 	return TEST_SUCCESS;
10719 }
10720 
10721 static int
10722 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10723 {
10724 	struct aead_test_data tdata;
10725 	uint8_t aad[gcm_test_case_7.aad.len];
10726 	int res;
10727 
10728 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10729 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10730 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10731 	aad[0] += 1;
10732 	tdata.aad.data = aad;
10733 	res = test_authenticated_encryption(&tdata);
10734 	if (res == TEST_SKIPPED)
10735 		return res;
10736 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10737 	return TEST_SUCCESS;
10738 }
10739 
10740 static int
10741 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10742 {
10743 	struct aead_test_data tdata;
10744 	int res;
10745 
10746 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10747 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10748 	tdata.auth_tag.data[0] += 1;
10749 	res = test_authenticated_encryption(&tdata);
10750 	if (res == TEST_SKIPPED)
10751 		return res;
10752 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10753 	return TEST_SUCCESS;
10754 }
10755 
10756 static int
10757 test_authenticated_decryption(const struct aead_test_data *tdata)
10758 {
10759 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10760 	struct crypto_unittest_params *ut_params = &unittest_params;
10761 
10762 	int retval;
10763 	uint8_t *plaintext;
10764 	uint32_t i;
10765 	struct rte_cryptodev_info dev_info;
10766 
10767 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10768 	uint64_t feat_flags = dev_info.feature_flags;
10769 
10770 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10771 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10772 		printf("Device doesn't support RAW data-path APIs.\n");
10773 		return TEST_SKIPPED;
10774 	}
10775 
10776 	/* Verify the capabilities */
10777 	struct rte_cryptodev_sym_capability_idx cap_idx;
10778 	const struct rte_cryptodev_symmetric_capability *capability;
10779 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10780 	cap_idx.algo.aead = tdata->algo;
10781 	capability = rte_cryptodev_sym_capability_get(
10782 			ts_params->valid_devs[0], &cap_idx);
10783 	if (capability == NULL)
10784 		return TEST_SKIPPED;
10785 	if (rte_cryptodev_sym_capability_check_aead(
10786 			capability, tdata->key.len, tdata->auth_tag.len,
10787 			tdata->aad.len, tdata->iv.len))
10788 		return TEST_SKIPPED;
10789 
10790 	/* Create AEAD session */
10791 	retval = create_aead_session(ts_params->valid_devs[0],
10792 			tdata->algo,
10793 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10794 			tdata->key.data, tdata->key.len,
10795 			tdata->aad.len, tdata->auth_tag.len,
10796 			tdata->iv.len);
10797 	if (retval < 0)
10798 		return retval;
10799 
10800 	/* alloc mbuf and set payload */
10801 	if (tdata->aad.len > MBUF_SIZE) {
10802 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10803 		/* Populate full size of add data */
10804 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10805 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10806 	} else
10807 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10808 
10809 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10810 			rte_pktmbuf_tailroom(ut_params->ibuf));
10811 
10812 	/* Create AEAD operation */
10813 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10814 	if (retval < 0)
10815 		return retval;
10816 
10817 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10818 
10819 	ut_params->op->sym->m_src = ut_params->ibuf;
10820 
10821 	/* Process crypto operation */
10822 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10823 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10824 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10825 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10826 				ut_params->op, 0, 0, 0, 0);
10827 	else
10828 		TEST_ASSERT_NOT_NULL(
10829 			process_crypto_request(ts_params->valid_devs[0],
10830 			ut_params->op), "failed to process sym crypto op");
10831 
10832 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10833 			"crypto op processing failed");
10834 
10835 	if (ut_params->op->sym->m_dst)
10836 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10837 				uint8_t *);
10838 	else
10839 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10840 				uint8_t *,
10841 				ut_params->op->sym->cipher.data.offset);
10842 
10843 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10844 
10845 	/* Validate obuf */
10846 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10847 			plaintext,
10848 			tdata->plaintext.data,
10849 			tdata->plaintext.len,
10850 			"Plaintext data not as expected");
10851 
10852 	TEST_ASSERT_EQUAL(ut_params->op->status,
10853 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10854 			"Authentication failed");
10855 
10856 	return 0;
10857 }
10858 
10859 static int
10860 test_AES_GCM_authenticated_decryption_test_case_1(void)
10861 {
10862 	return test_authenticated_decryption(&gcm_test_case_1);
10863 }
10864 
10865 static int
10866 test_AES_GCM_authenticated_decryption_test_case_2(void)
10867 {
10868 	return test_authenticated_decryption(&gcm_test_case_2);
10869 }
10870 
10871 static int
10872 test_AES_GCM_authenticated_decryption_test_case_3(void)
10873 {
10874 	return test_authenticated_decryption(&gcm_test_case_3);
10875 }
10876 
10877 static int
10878 test_AES_GCM_authenticated_decryption_test_case_4(void)
10879 {
10880 	return test_authenticated_decryption(&gcm_test_case_4);
10881 }
10882 
10883 static int
10884 test_AES_GCM_authenticated_decryption_test_case_5(void)
10885 {
10886 	return test_authenticated_decryption(&gcm_test_case_5);
10887 }
10888 
10889 static int
10890 test_AES_GCM_authenticated_decryption_test_case_6(void)
10891 {
10892 	return test_authenticated_decryption(&gcm_test_case_6);
10893 }
10894 
10895 static int
10896 test_AES_GCM_authenticated_decryption_test_case_7(void)
10897 {
10898 	return test_authenticated_decryption(&gcm_test_case_7);
10899 }
10900 
10901 static int
10902 test_AES_GCM_authenticated_decryption_test_case_8(void)
10903 {
10904 	return test_authenticated_decryption(&gcm_test_case_8);
10905 }
10906 
10907 static int
10908 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10909 {
10910 	return test_authenticated_decryption(&gcm_J0_test_case_1);
10911 }
10912 
10913 static int
10914 test_AES_GCM_auth_decryption_test_case_192_1(void)
10915 {
10916 	return test_authenticated_decryption(&gcm_test_case_192_1);
10917 }
10918 
10919 static int
10920 test_AES_GCM_auth_decryption_test_case_192_2(void)
10921 {
10922 	return test_authenticated_decryption(&gcm_test_case_192_2);
10923 }
10924 
10925 static int
10926 test_AES_GCM_auth_decryption_test_case_192_3(void)
10927 {
10928 	return test_authenticated_decryption(&gcm_test_case_192_3);
10929 }
10930 
10931 static int
10932 test_AES_GCM_auth_decryption_test_case_192_4(void)
10933 {
10934 	return test_authenticated_decryption(&gcm_test_case_192_4);
10935 }
10936 
10937 static int
10938 test_AES_GCM_auth_decryption_test_case_192_5(void)
10939 {
10940 	return test_authenticated_decryption(&gcm_test_case_192_5);
10941 }
10942 
10943 static int
10944 test_AES_GCM_auth_decryption_test_case_192_6(void)
10945 {
10946 	return test_authenticated_decryption(&gcm_test_case_192_6);
10947 }
10948 
10949 static int
10950 test_AES_GCM_auth_decryption_test_case_192_7(void)
10951 {
10952 	return test_authenticated_decryption(&gcm_test_case_192_7);
10953 }
10954 
10955 static int
10956 test_AES_GCM_auth_decryption_test_case_256_1(void)
10957 {
10958 	return test_authenticated_decryption(&gcm_test_case_256_1);
10959 }
10960 
10961 static int
10962 test_AES_GCM_auth_decryption_test_case_256_2(void)
10963 {
10964 	return test_authenticated_decryption(&gcm_test_case_256_2);
10965 }
10966 
10967 static int
10968 test_AES_GCM_auth_decryption_test_case_256_3(void)
10969 {
10970 	return test_authenticated_decryption(&gcm_test_case_256_3);
10971 }
10972 
10973 static int
10974 test_AES_GCM_auth_decryption_test_case_256_4(void)
10975 {
10976 	return test_authenticated_decryption(&gcm_test_case_256_4);
10977 }
10978 
10979 static int
10980 test_AES_GCM_auth_decryption_test_case_256_5(void)
10981 {
10982 	return test_authenticated_decryption(&gcm_test_case_256_5);
10983 }
10984 
10985 static int
10986 test_AES_GCM_auth_decryption_test_case_256_6(void)
10987 {
10988 	return test_authenticated_decryption(&gcm_test_case_256_6);
10989 }
10990 
10991 static int
10992 test_AES_GCM_auth_decryption_test_case_256_7(void)
10993 {
10994 	return test_authenticated_decryption(&gcm_test_case_256_7);
10995 }
10996 
10997 static int
10998 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10999 {
11000 	return test_authenticated_decryption(&gcm_test_case_aad_1);
11001 }
11002 
11003 static int
11004 test_AES_GCM_auth_decryption_test_case_aad_2(void)
11005 {
11006 	return test_authenticated_decryption(&gcm_test_case_aad_2);
11007 }
11008 
11009 static int
11010 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
11011 {
11012 	struct aead_test_data tdata;
11013 	int res;
11014 
11015 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11016 	tdata.iv.data[0] += 1;
11017 	res = test_authenticated_decryption(&tdata);
11018 	if (res == TEST_SKIPPED)
11019 		return res;
11020 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11021 	return TEST_SUCCESS;
11022 }
11023 
11024 static int
11025 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
11026 {
11027 	struct aead_test_data tdata;
11028 	int res;
11029 
11030 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11031 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11032 	tdata.plaintext.data[0] += 1;
11033 	res = test_authenticated_decryption(&tdata);
11034 	if (res == TEST_SKIPPED)
11035 		return res;
11036 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11037 	return TEST_SUCCESS;
11038 }
11039 
11040 static int
11041 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
11042 {
11043 	struct aead_test_data tdata;
11044 	int res;
11045 
11046 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11047 	tdata.ciphertext.data[0] += 1;
11048 	res = test_authenticated_decryption(&tdata);
11049 	if (res == TEST_SKIPPED)
11050 		return res;
11051 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11052 	return TEST_SUCCESS;
11053 }
11054 
11055 static int
11056 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
11057 {
11058 	struct aead_test_data tdata;
11059 	int res;
11060 
11061 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11062 	tdata.aad.len += 1;
11063 	res = test_authenticated_decryption(&tdata);
11064 	if (res == TEST_SKIPPED)
11065 		return res;
11066 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11067 	return TEST_SUCCESS;
11068 }
11069 
11070 static int
11071 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
11072 {
11073 	struct aead_test_data tdata;
11074 	uint8_t aad[gcm_test_case_7.aad.len];
11075 	int res;
11076 
11077 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11078 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
11079 	aad[0] += 1;
11080 	tdata.aad.data = aad;
11081 	res = test_authenticated_decryption(&tdata);
11082 	if (res == TEST_SKIPPED)
11083 		return res;
11084 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11085 	return TEST_SUCCESS;
11086 }
11087 
11088 static int
11089 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
11090 {
11091 	struct aead_test_data tdata;
11092 	int res;
11093 
11094 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11095 	tdata.auth_tag.data[0] += 1;
11096 	res = test_authenticated_decryption(&tdata);
11097 	if (res == TEST_SKIPPED)
11098 		return res;
11099 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
11100 	return TEST_SUCCESS;
11101 }
11102 
11103 static int
11104 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
11105 {
11106 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11107 	struct crypto_unittest_params *ut_params = &unittest_params;
11108 
11109 	int retval;
11110 	uint8_t *ciphertext, *auth_tag;
11111 	uint16_t plaintext_pad_len;
11112 	struct rte_cryptodev_info dev_info;
11113 
11114 	/* Verify the capabilities */
11115 	struct rte_cryptodev_sym_capability_idx cap_idx;
11116 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11117 	cap_idx.algo.aead = tdata->algo;
11118 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11119 			&cap_idx) == NULL)
11120 		return TEST_SKIPPED;
11121 
11122 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11123 	uint64_t feat_flags = dev_info.feature_flags;
11124 
11125 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11126 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
11127 		return TEST_SKIPPED;
11128 
11129 	/* not supported with CPU crypto */
11130 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11131 		return TEST_SKIPPED;
11132 
11133 	/* Create AEAD session */
11134 	retval = create_aead_session(ts_params->valid_devs[0],
11135 			tdata->algo,
11136 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
11137 			tdata->key.data, tdata->key.len,
11138 			tdata->aad.len, tdata->auth_tag.len,
11139 			tdata->iv.len);
11140 	if (retval < 0)
11141 		return retval;
11142 
11143 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11144 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11145 
11146 	/* clear mbuf payload */
11147 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11148 			rte_pktmbuf_tailroom(ut_params->ibuf));
11149 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
11150 			rte_pktmbuf_tailroom(ut_params->obuf));
11151 
11152 	/* Create AEAD operation */
11153 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
11154 	if (retval < 0)
11155 		return retval;
11156 
11157 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11158 
11159 	ut_params->op->sym->m_src = ut_params->ibuf;
11160 	ut_params->op->sym->m_dst = ut_params->obuf;
11161 
11162 	/* Process crypto operation */
11163 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11164 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11165 			ut_params->op, 0, 0, 0, 0);
11166 	else
11167 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11168 			ut_params->op), "failed to process sym crypto op");
11169 
11170 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11171 			"crypto op processing failed");
11172 
11173 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11174 
11175 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
11176 			ut_params->op->sym->cipher.data.offset);
11177 	auth_tag = ciphertext + plaintext_pad_len;
11178 
11179 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
11180 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
11181 
11182 	/* Validate obuf */
11183 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11184 			ciphertext,
11185 			tdata->ciphertext.data,
11186 			tdata->ciphertext.len,
11187 			"Ciphertext data not as expected");
11188 
11189 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11190 			auth_tag,
11191 			tdata->auth_tag.data,
11192 			tdata->auth_tag.len,
11193 			"Generated auth tag not as expected");
11194 
11195 	return 0;
11196 
11197 }
11198 
11199 static int
11200 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
11201 {
11202 	return test_authenticated_encryption_oop(&gcm_test_case_5);
11203 }
11204 
11205 static int
11206 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
11207 {
11208 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11209 	struct crypto_unittest_params *ut_params = &unittest_params;
11210 
11211 	int retval;
11212 	uint8_t *plaintext;
11213 	struct rte_cryptodev_info dev_info;
11214 
11215 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11216 	uint64_t feat_flags = dev_info.feature_flags;
11217 
11218 	/* Verify the capabilities */
11219 	struct rte_cryptodev_sym_capability_idx cap_idx;
11220 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11221 	cap_idx.algo.aead = tdata->algo;
11222 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11223 			&cap_idx) == NULL)
11224 		return TEST_SKIPPED;
11225 
11226 	/* not supported with CPU crypto and raw data-path APIs*/
11227 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
11228 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
11229 		return TEST_SKIPPED;
11230 
11231 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11232 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11233 		printf("Device does not support RAW data-path APIs.\n");
11234 		return TEST_SKIPPED;
11235 	}
11236 
11237 	/* Create AEAD session */
11238 	retval = create_aead_session(ts_params->valid_devs[0],
11239 			tdata->algo,
11240 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11241 			tdata->key.data, tdata->key.len,
11242 			tdata->aad.len, tdata->auth_tag.len,
11243 			tdata->iv.len);
11244 	if (retval < 0)
11245 		return retval;
11246 
11247 	/* alloc mbuf and set payload */
11248 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11249 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11250 
11251 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11252 			rte_pktmbuf_tailroom(ut_params->ibuf));
11253 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
11254 			rte_pktmbuf_tailroom(ut_params->obuf));
11255 
11256 	/* Create AEAD operation */
11257 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11258 	if (retval < 0)
11259 		return retval;
11260 
11261 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11262 
11263 	ut_params->op->sym->m_src = ut_params->ibuf;
11264 	ut_params->op->sym->m_dst = ut_params->obuf;
11265 
11266 	/* Process crypto operation */
11267 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11268 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11269 				ut_params->op, 0, 0, 0, 0);
11270 	else
11271 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11272 			ut_params->op), "failed to process sym crypto op");
11273 
11274 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11275 			"crypto op processing failed");
11276 
11277 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
11278 			ut_params->op->sym->cipher.data.offset);
11279 
11280 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11281 
11282 	/* Validate obuf */
11283 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11284 			plaintext,
11285 			tdata->plaintext.data,
11286 			tdata->plaintext.len,
11287 			"Plaintext data not as expected");
11288 
11289 	TEST_ASSERT_EQUAL(ut_params->op->status,
11290 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11291 			"Authentication failed");
11292 	return 0;
11293 }
11294 
11295 static int
11296 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
11297 {
11298 	return test_authenticated_decryption_oop(&gcm_test_case_5);
11299 }
11300 
11301 static int
11302 test_authenticated_encryption_sessionless(
11303 		const struct aead_test_data *tdata)
11304 {
11305 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11306 	struct crypto_unittest_params *ut_params = &unittest_params;
11307 
11308 	int retval;
11309 	uint8_t *ciphertext, *auth_tag;
11310 	uint16_t plaintext_pad_len;
11311 	uint8_t key[tdata->key.len + 1];
11312 	struct rte_cryptodev_info dev_info;
11313 
11314 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11315 	uint64_t feat_flags = dev_info.feature_flags;
11316 
11317 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
11318 		printf("Device doesn't support Sessionless ops.\n");
11319 		return TEST_SKIPPED;
11320 	}
11321 
11322 	/* not supported with CPU crypto */
11323 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11324 		return TEST_SKIPPED;
11325 
11326 	/* Verify the capabilities */
11327 	struct rte_cryptodev_sym_capability_idx cap_idx;
11328 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11329 	cap_idx.algo.aead = tdata->algo;
11330 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11331 			&cap_idx) == NULL)
11332 		return TEST_SKIPPED;
11333 
11334 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11335 
11336 	/* clear mbuf payload */
11337 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11338 			rte_pktmbuf_tailroom(ut_params->ibuf));
11339 
11340 	/* Create AEAD operation */
11341 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
11342 	if (retval < 0)
11343 		return retval;
11344 
11345 	/* Create GCM xform */
11346 	memcpy(key, tdata->key.data, tdata->key.len);
11347 	retval = create_aead_xform(ut_params->op,
11348 			tdata->algo,
11349 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
11350 			key, tdata->key.len,
11351 			tdata->aad.len, tdata->auth_tag.len,
11352 			tdata->iv.len);
11353 	if (retval < 0)
11354 		return retval;
11355 
11356 	ut_params->op->sym->m_src = ut_params->ibuf;
11357 
11358 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11359 			RTE_CRYPTO_OP_SESSIONLESS,
11360 			"crypto op session type not sessionless");
11361 
11362 	/* Process crypto operation */
11363 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11364 			ut_params->op), "failed to process sym crypto op");
11365 
11366 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11367 
11368 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11369 			"crypto op status not success");
11370 
11371 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11372 
11373 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11374 			ut_params->op->sym->cipher.data.offset);
11375 	auth_tag = ciphertext + plaintext_pad_len;
11376 
11377 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
11378 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
11379 
11380 	/* Validate obuf */
11381 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11382 			ciphertext,
11383 			tdata->ciphertext.data,
11384 			tdata->ciphertext.len,
11385 			"Ciphertext data not as expected");
11386 
11387 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11388 			auth_tag,
11389 			tdata->auth_tag.data,
11390 			tdata->auth_tag.len,
11391 			"Generated auth tag not as expected");
11392 
11393 	return 0;
11394 
11395 }
11396 
11397 static int
11398 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
11399 {
11400 	return test_authenticated_encryption_sessionless(
11401 			&gcm_test_case_5);
11402 }
11403 
11404 static int
11405 test_authenticated_decryption_sessionless(
11406 		const struct aead_test_data *tdata)
11407 {
11408 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11409 	struct crypto_unittest_params *ut_params = &unittest_params;
11410 
11411 	int retval;
11412 	uint8_t *plaintext;
11413 	uint8_t key[tdata->key.len + 1];
11414 	struct rte_cryptodev_info dev_info;
11415 
11416 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11417 	uint64_t feat_flags = dev_info.feature_flags;
11418 
11419 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
11420 		printf("Device doesn't support Sessionless ops.\n");
11421 		return TEST_SKIPPED;
11422 	}
11423 
11424 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11425 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11426 		printf("Device doesn't support RAW data-path APIs.\n");
11427 		return TEST_SKIPPED;
11428 	}
11429 
11430 	/* not supported with CPU crypto */
11431 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11432 		return TEST_SKIPPED;
11433 
11434 	/* Verify the capabilities */
11435 	struct rte_cryptodev_sym_capability_idx cap_idx;
11436 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11437 	cap_idx.algo.aead = tdata->algo;
11438 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11439 			&cap_idx) == NULL)
11440 		return TEST_SKIPPED;
11441 
11442 	/* alloc mbuf and set payload */
11443 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11444 
11445 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11446 			rte_pktmbuf_tailroom(ut_params->ibuf));
11447 
11448 	/* Create AEAD operation */
11449 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11450 	if (retval < 0)
11451 		return retval;
11452 
11453 	/* Create AEAD xform */
11454 	memcpy(key, tdata->key.data, tdata->key.len);
11455 	retval = create_aead_xform(ut_params->op,
11456 			tdata->algo,
11457 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11458 			key, tdata->key.len,
11459 			tdata->aad.len, tdata->auth_tag.len,
11460 			tdata->iv.len);
11461 	if (retval < 0)
11462 		return retval;
11463 
11464 	ut_params->op->sym->m_src = ut_params->ibuf;
11465 
11466 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11467 			RTE_CRYPTO_OP_SESSIONLESS,
11468 			"crypto op session type not sessionless");
11469 
11470 	/* Process crypto operation */
11471 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11472 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11473 				ut_params->op, 0, 0, 0, 0);
11474 	else
11475 		TEST_ASSERT_NOT_NULL(process_crypto_request(
11476 			ts_params->valid_devs[0], ut_params->op),
11477 				"failed to process sym crypto op");
11478 
11479 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11480 
11481 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11482 			"crypto op status not success");
11483 
11484 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11485 			ut_params->op->sym->cipher.data.offset);
11486 
11487 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11488 
11489 	/* Validate obuf */
11490 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11491 			plaintext,
11492 			tdata->plaintext.data,
11493 			tdata->plaintext.len,
11494 			"Plaintext data not as expected");
11495 
11496 	TEST_ASSERT_EQUAL(ut_params->op->status,
11497 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11498 			"Authentication failed");
11499 	return 0;
11500 }
11501 
11502 static int
11503 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
11504 {
11505 	return test_authenticated_decryption_sessionless(
11506 			&gcm_test_case_5);
11507 }
11508 
11509 static int
11510 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
11511 {
11512 	return test_authenticated_encryption(&ccm_test_case_128_1);
11513 }
11514 
11515 static int
11516 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
11517 {
11518 	return test_authenticated_encryption(&ccm_test_case_128_2);
11519 }
11520 
11521 static int
11522 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
11523 {
11524 	return test_authenticated_encryption(&ccm_test_case_128_3);
11525 }
11526 
11527 static int
11528 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
11529 {
11530 	return test_authenticated_decryption(&ccm_test_case_128_1);
11531 }
11532 
11533 static int
11534 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
11535 {
11536 	return test_authenticated_decryption(&ccm_test_case_128_2);
11537 }
11538 
11539 static int
11540 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
11541 {
11542 	return test_authenticated_decryption(&ccm_test_case_128_3);
11543 }
11544 
11545 static int
11546 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
11547 {
11548 	return test_authenticated_encryption(&ccm_test_case_192_1);
11549 }
11550 
11551 static int
11552 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
11553 {
11554 	return test_authenticated_encryption(&ccm_test_case_192_2);
11555 }
11556 
11557 static int
11558 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
11559 {
11560 	return test_authenticated_encryption(&ccm_test_case_192_3);
11561 }
11562 
11563 static int
11564 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
11565 {
11566 	return test_authenticated_decryption(&ccm_test_case_192_1);
11567 }
11568 
11569 static int
11570 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
11571 {
11572 	return test_authenticated_decryption(&ccm_test_case_192_2);
11573 }
11574 
11575 static int
11576 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
11577 {
11578 	return test_authenticated_decryption(&ccm_test_case_192_3);
11579 }
11580 
11581 static int
11582 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11583 {
11584 	return test_authenticated_encryption(&ccm_test_case_256_1);
11585 }
11586 
11587 static int
11588 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11589 {
11590 	return test_authenticated_encryption(&ccm_test_case_256_2);
11591 }
11592 
11593 static int
11594 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11595 {
11596 	return test_authenticated_encryption(&ccm_test_case_256_3);
11597 }
11598 
11599 static int
11600 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11601 {
11602 	return test_authenticated_decryption(&ccm_test_case_256_1);
11603 }
11604 
11605 static int
11606 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11607 {
11608 	return test_authenticated_decryption(&ccm_test_case_256_2);
11609 }
11610 
11611 static int
11612 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11613 {
11614 	return test_authenticated_decryption(&ccm_test_case_256_3);
11615 }
11616 
11617 static int
11618 test_stats(void)
11619 {
11620 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11621 	struct rte_cryptodev_stats stats;
11622 
11623 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11624 		return TEST_SKIPPED;
11625 
11626 	/* Verify the capabilities */
11627 	struct rte_cryptodev_sym_capability_idx cap_idx;
11628 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11629 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11630 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11631 			&cap_idx) == NULL)
11632 		return TEST_SKIPPED;
11633 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11634 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11635 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11636 			&cap_idx) == NULL)
11637 		return TEST_SKIPPED;
11638 
11639 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11640 			== -ENOTSUP)
11641 		return TEST_SKIPPED;
11642 
11643 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11644 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11645 			&stats) == -ENODEV),
11646 		"rte_cryptodev_stats_get invalid dev failed");
11647 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11648 		"rte_cryptodev_stats_get invalid Param failed");
11649 
11650 	/* Test expected values */
11651 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
11652 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11653 			&stats),
11654 		"rte_cryptodev_stats_get failed");
11655 	TEST_ASSERT((stats.enqueued_count == 1),
11656 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11657 	TEST_ASSERT((stats.dequeued_count == 1),
11658 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11659 	TEST_ASSERT((stats.enqueue_err_count == 0),
11660 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11661 	TEST_ASSERT((stats.dequeue_err_count == 0),
11662 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11663 
11664 	/* invalid device but should ignore and not reset device stats*/
11665 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11666 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11667 			&stats),
11668 		"rte_cryptodev_stats_get failed");
11669 	TEST_ASSERT((stats.enqueued_count == 1),
11670 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11671 
11672 	/* check that a valid reset clears stats */
11673 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11674 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11675 			&stats),
11676 					  "rte_cryptodev_stats_get failed");
11677 	TEST_ASSERT((stats.enqueued_count == 0),
11678 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11679 	TEST_ASSERT((stats.dequeued_count == 0),
11680 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11681 
11682 	return TEST_SUCCESS;
11683 }
11684 
11685 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11686 				   struct crypto_unittest_params *ut_params,
11687 				   enum rte_crypto_auth_operation op,
11688 				   const struct HMAC_MD5_vector *test_case)
11689 {
11690 	uint8_t key[64];
11691 	int status;
11692 
11693 	memcpy(key, test_case->key.data, test_case->key.len);
11694 
11695 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11696 	ut_params->auth_xform.next = NULL;
11697 	ut_params->auth_xform.auth.op = op;
11698 
11699 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11700 
11701 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11702 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11703 	ut_params->auth_xform.auth.key.data = key;
11704 
11705 	ut_params->sess = rte_cryptodev_sym_session_create(
11706 			ts_params->session_mpool);
11707 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11708 	if (ut_params->sess == NULL)
11709 		return TEST_FAILED;
11710 
11711 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11712 			ut_params->sess, &ut_params->auth_xform,
11713 			ts_params->session_priv_mpool);
11714 	if (status == -ENOTSUP)
11715 		return TEST_SKIPPED;
11716 
11717 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11718 
11719 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11720 			rte_pktmbuf_tailroom(ut_params->ibuf));
11721 
11722 	return 0;
11723 }
11724 
11725 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11726 			      const struct HMAC_MD5_vector *test_case,
11727 			      uint8_t **plaintext)
11728 {
11729 	uint16_t plaintext_pad_len;
11730 
11731 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11732 
11733 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11734 				16);
11735 
11736 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11737 			plaintext_pad_len);
11738 	memcpy(*plaintext, test_case->plaintext.data,
11739 			test_case->plaintext.len);
11740 
11741 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11742 			ut_params->ibuf, MD5_DIGEST_LEN);
11743 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11744 			"no room to append digest");
11745 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11746 			ut_params->ibuf, plaintext_pad_len);
11747 
11748 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11749 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11750 			   test_case->auth_tag.len);
11751 	}
11752 
11753 	sym_op->auth.data.offset = 0;
11754 	sym_op->auth.data.length = test_case->plaintext.len;
11755 
11756 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11757 	ut_params->op->sym->m_src = ut_params->ibuf;
11758 
11759 	return 0;
11760 }
11761 
11762 static int
11763 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11764 {
11765 	uint16_t plaintext_pad_len;
11766 	uint8_t *plaintext, *auth_tag;
11767 
11768 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11769 	struct crypto_unittest_params *ut_params = &unittest_params;
11770 	struct rte_cryptodev_info dev_info;
11771 
11772 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11773 	uint64_t feat_flags = dev_info.feature_flags;
11774 
11775 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11776 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11777 		printf("Device doesn't support RAW data-path APIs.\n");
11778 		return TEST_SKIPPED;
11779 	}
11780 
11781 	/* Verify the capabilities */
11782 	struct rte_cryptodev_sym_capability_idx cap_idx;
11783 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11784 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11785 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11786 			&cap_idx) == NULL)
11787 		return TEST_SKIPPED;
11788 
11789 	if (MD5_HMAC_create_session(ts_params, ut_params,
11790 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11791 		return TEST_FAILED;
11792 
11793 	/* Generate Crypto op data structure */
11794 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11795 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11796 	TEST_ASSERT_NOT_NULL(ut_params->op,
11797 			"Failed to allocate symmetric crypto operation struct");
11798 
11799 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11800 				16);
11801 
11802 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11803 		return TEST_FAILED;
11804 
11805 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11806 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11807 			ut_params->op);
11808 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11809 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11810 				ut_params->op, 0, 1, 0, 0);
11811 	else
11812 		TEST_ASSERT_NOT_NULL(
11813 			process_crypto_request(ts_params->valid_devs[0],
11814 				ut_params->op),
11815 				"failed to process sym crypto op");
11816 
11817 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11818 			"crypto op processing failed");
11819 
11820 	if (ut_params->op->sym->m_dst) {
11821 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11822 				uint8_t *, plaintext_pad_len);
11823 	} else {
11824 		auth_tag = plaintext + plaintext_pad_len;
11825 	}
11826 
11827 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11828 			auth_tag,
11829 			test_case->auth_tag.data,
11830 			test_case->auth_tag.len,
11831 			"HMAC_MD5 generated tag not as expected");
11832 
11833 	return TEST_SUCCESS;
11834 }
11835 
11836 static int
11837 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11838 {
11839 	uint8_t *plaintext;
11840 
11841 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11842 	struct crypto_unittest_params *ut_params = &unittest_params;
11843 	struct rte_cryptodev_info dev_info;
11844 
11845 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11846 	uint64_t feat_flags = dev_info.feature_flags;
11847 
11848 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11849 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11850 		printf("Device doesn't support RAW data-path APIs.\n");
11851 		return TEST_SKIPPED;
11852 	}
11853 
11854 	/* Verify the capabilities */
11855 	struct rte_cryptodev_sym_capability_idx cap_idx;
11856 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11857 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11858 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11859 			&cap_idx) == NULL)
11860 		return TEST_SKIPPED;
11861 
11862 	if (MD5_HMAC_create_session(ts_params, ut_params,
11863 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11864 		return TEST_FAILED;
11865 	}
11866 
11867 	/* Generate Crypto op data structure */
11868 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11869 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11870 	TEST_ASSERT_NOT_NULL(ut_params->op,
11871 			"Failed to allocate symmetric crypto operation struct");
11872 
11873 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11874 		return TEST_FAILED;
11875 
11876 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11877 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11878 			ut_params->op);
11879 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11880 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11881 				ut_params->op, 0, 1, 0, 0);
11882 	else
11883 		TEST_ASSERT_NOT_NULL(
11884 			process_crypto_request(ts_params->valid_devs[0],
11885 				ut_params->op),
11886 				"failed to process sym crypto op");
11887 
11888 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11889 			"HMAC_MD5 crypto op processing failed");
11890 
11891 	return TEST_SUCCESS;
11892 }
11893 
11894 static int
11895 test_MD5_HMAC_generate_case_1(void)
11896 {
11897 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11898 }
11899 
11900 static int
11901 test_MD5_HMAC_verify_case_1(void)
11902 {
11903 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11904 }
11905 
11906 static int
11907 test_MD5_HMAC_generate_case_2(void)
11908 {
11909 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11910 }
11911 
11912 static int
11913 test_MD5_HMAC_verify_case_2(void)
11914 {
11915 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11916 }
11917 
11918 static int
11919 test_multi_session(void)
11920 {
11921 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11922 	struct crypto_unittest_params *ut_params = &unittest_params;
11923 
11924 	struct rte_cryptodev_info dev_info;
11925 	struct rte_cryptodev_sym_session **sessions;
11926 
11927 	uint16_t i;
11928 	int status;
11929 
11930 	/* Verify the capabilities */
11931 	struct rte_cryptodev_sym_capability_idx cap_idx;
11932 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11933 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11934 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11935 			&cap_idx) == NULL)
11936 		return TEST_SKIPPED;
11937 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11938 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11939 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11940 			&cap_idx) == NULL)
11941 		return TEST_SKIPPED;
11942 
11943 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11944 			aes_cbc_key, hmac_sha512_key);
11945 
11946 
11947 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11948 
11949 	sessions = rte_malloc(NULL,
11950 			sizeof(struct rte_cryptodev_sym_session *) *
11951 			(MAX_NB_SESSIONS + 1), 0);
11952 
11953 	/* Create multiple crypto sessions*/
11954 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11955 
11956 		sessions[i] = rte_cryptodev_sym_session_create(
11957 				ts_params->session_mpool);
11958 		TEST_ASSERT_NOT_NULL(sessions[i],
11959 				"Session creation failed at session number %u",
11960 				i);
11961 
11962 		status = rte_cryptodev_sym_session_init(
11963 				ts_params->valid_devs[0],
11964 				sessions[i], &ut_params->auth_xform,
11965 				ts_params->session_priv_mpool);
11966 		if (status == -ENOTSUP)
11967 			return TEST_SKIPPED;
11968 
11969 		/* Attempt to send a request on each session */
11970 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11971 			sessions[i],
11972 			ut_params,
11973 			ts_params,
11974 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11975 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11976 			aes_cbc_iv),
11977 			"Failed to perform decrypt on request number %u.", i);
11978 		/* free crypto operation structure */
11979 		if (ut_params->op)
11980 			rte_crypto_op_free(ut_params->op);
11981 
11982 		/*
11983 		 * free mbuf - both obuf and ibuf are usually the same,
11984 		 * so check if they point at the same address is necessary,
11985 		 * to avoid freeing the mbuf twice.
11986 		 */
11987 		if (ut_params->obuf) {
11988 			rte_pktmbuf_free(ut_params->obuf);
11989 			if (ut_params->ibuf == ut_params->obuf)
11990 				ut_params->ibuf = 0;
11991 			ut_params->obuf = 0;
11992 		}
11993 		if (ut_params->ibuf) {
11994 			rte_pktmbuf_free(ut_params->ibuf);
11995 			ut_params->ibuf = 0;
11996 		}
11997 	}
11998 
11999 	sessions[i] = NULL;
12000 	/* Next session create should fail */
12001 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12002 			sessions[i], &ut_params->auth_xform,
12003 			ts_params->session_priv_mpool);
12004 	TEST_ASSERT_NULL(sessions[i],
12005 			"Session creation succeeded unexpectedly!");
12006 
12007 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
12008 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
12009 				sessions[i]);
12010 		rte_cryptodev_sym_session_free(sessions[i]);
12011 	}
12012 
12013 	rte_free(sessions);
12014 
12015 	return TEST_SUCCESS;
12016 }
12017 
12018 struct multi_session_params {
12019 	struct crypto_unittest_params ut_params;
12020 	uint8_t *cipher_key;
12021 	uint8_t *hmac_key;
12022 	const uint8_t *cipher;
12023 	const uint8_t *digest;
12024 	uint8_t *iv;
12025 };
12026 
12027 #define MB_SESSION_NUMBER 3
12028 
12029 static int
12030 test_multi_session_random_usage(void)
12031 {
12032 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12033 	struct rte_cryptodev_info dev_info;
12034 	struct rte_cryptodev_sym_session **sessions;
12035 	uint32_t i, j;
12036 	struct multi_session_params ut_paramz[] = {
12037 
12038 		{
12039 			.cipher_key = ms_aes_cbc_key0,
12040 			.hmac_key = ms_hmac_key0,
12041 			.cipher = ms_aes_cbc_cipher0,
12042 			.digest = ms_hmac_digest0,
12043 			.iv = ms_aes_cbc_iv0
12044 		},
12045 		{
12046 			.cipher_key = ms_aes_cbc_key1,
12047 			.hmac_key = ms_hmac_key1,
12048 			.cipher = ms_aes_cbc_cipher1,
12049 			.digest = ms_hmac_digest1,
12050 			.iv = ms_aes_cbc_iv1
12051 		},
12052 		{
12053 			.cipher_key = ms_aes_cbc_key2,
12054 			.hmac_key = ms_hmac_key2,
12055 			.cipher = ms_aes_cbc_cipher2,
12056 			.digest = ms_hmac_digest2,
12057 			.iv = ms_aes_cbc_iv2
12058 		},
12059 
12060 	};
12061 	int status;
12062 
12063 	/* Verify the capabilities */
12064 	struct rte_cryptodev_sym_capability_idx cap_idx;
12065 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12066 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
12067 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12068 			&cap_idx) == NULL)
12069 		return TEST_SKIPPED;
12070 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12071 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12072 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12073 			&cap_idx) == NULL)
12074 		return TEST_SKIPPED;
12075 
12076 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12077 
12078 	sessions = rte_malloc(NULL,
12079 			(sizeof(struct rte_cryptodev_sym_session *)
12080 					* MAX_NB_SESSIONS) + 1, 0);
12081 
12082 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
12083 		sessions[i] = rte_cryptodev_sym_session_create(
12084 				ts_params->session_mpool);
12085 		TEST_ASSERT_NOT_NULL(sessions[i],
12086 				"Session creation failed at session number %u",
12087 				i);
12088 
12089 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
12090 				sizeof(struct crypto_unittest_params));
12091 
12092 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
12093 				&ut_paramz[i].ut_params,
12094 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
12095 
12096 		/* Create multiple crypto sessions*/
12097 		status = rte_cryptodev_sym_session_init(
12098 				ts_params->valid_devs[0],
12099 				sessions[i],
12100 				&ut_paramz[i].ut_params.auth_xform,
12101 				ts_params->session_priv_mpool);
12102 
12103 		if (status == -ENOTSUP)
12104 			return TEST_SKIPPED;
12105 
12106 		TEST_ASSERT_EQUAL(status, 0, "Session init failed");
12107 	}
12108 
12109 	srand(time(NULL));
12110 	for (i = 0; i < 40000; i++) {
12111 
12112 		j = rand() % MB_SESSION_NUMBER;
12113 
12114 		TEST_ASSERT_SUCCESS(
12115 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
12116 					sessions[j],
12117 					&ut_paramz[j].ut_params,
12118 					ts_params, ut_paramz[j].cipher,
12119 					ut_paramz[j].digest,
12120 					ut_paramz[j].iv),
12121 			"Failed to perform decrypt on request number %u.", i);
12122 
12123 		if (ut_paramz[j].ut_params.op)
12124 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
12125 
12126 		/*
12127 		 * free mbuf - both obuf and ibuf are usually the same,
12128 		 * so check if they point at the same address is necessary,
12129 		 * to avoid freeing the mbuf twice.
12130 		 */
12131 		if (ut_paramz[j].ut_params.obuf) {
12132 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
12133 			if (ut_paramz[j].ut_params.ibuf
12134 					== ut_paramz[j].ut_params.obuf)
12135 				ut_paramz[j].ut_params.ibuf = 0;
12136 			ut_paramz[j].ut_params.obuf = 0;
12137 		}
12138 		if (ut_paramz[j].ut_params.ibuf) {
12139 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
12140 			ut_paramz[j].ut_params.ibuf = 0;
12141 		}
12142 	}
12143 
12144 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
12145 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
12146 				sessions[i]);
12147 		rte_cryptodev_sym_session_free(sessions[i]);
12148 	}
12149 
12150 	rte_free(sessions);
12151 
12152 	return TEST_SUCCESS;
12153 }
12154 
12155 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
12156 			0xab, 0xab, 0xab, 0xab,
12157 			0xab, 0xab, 0xab, 0xab,
12158 			0xab, 0xab, 0xab, 0xab};
12159 
12160 static int
12161 test_null_invalid_operation(void)
12162 {
12163 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12164 	struct crypto_unittest_params *ut_params = &unittest_params;
12165 	int ret;
12166 
12167 	/* This test is for NULL PMD only */
12168 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
12169 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
12170 		return TEST_SKIPPED;
12171 
12172 	/* Setup Cipher Parameters */
12173 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12174 	ut_params->cipher_xform.next = NULL;
12175 
12176 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
12177 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12178 
12179 	ut_params->sess = rte_cryptodev_sym_session_create(
12180 			ts_params->session_mpool);
12181 
12182 	/* Create Crypto session*/
12183 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12184 			ut_params->sess, &ut_params->cipher_xform,
12185 			ts_params->session_priv_mpool);
12186 	TEST_ASSERT(ret < 0,
12187 			"Session creation succeeded unexpectedly");
12188 
12189 
12190 	/* Setup HMAC Parameters */
12191 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12192 	ut_params->auth_xform.next = NULL;
12193 
12194 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
12195 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12196 
12197 	ut_params->sess = rte_cryptodev_sym_session_create(
12198 			ts_params->session_mpool);
12199 
12200 	/* Create Crypto session*/
12201 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12202 			ut_params->sess, &ut_params->auth_xform,
12203 			ts_params->session_priv_mpool);
12204 	TEST_ASSERT(ret < 0,
12205 			"Session creation succeeded unexpectedly");
12206 
12207 	return TEST_SUCCESS;
12208 }
12209 
12210 
12211 #define NULL_BURST_LENGTH (32)
12212 
12213 static int
12214 test_null_burst_operation(void)
12215 {
12216 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12217 	struct crypto_unittest_params *ut_params = &unittest_params;
12218 	int status;
12219 
12220 	unsigned i, burst_len = NULL_BURST_LENGTH;
12221 
12222 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
12223 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
12224 
12225 	/* This test is for NULL PMD only */
12226 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
12227 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
12228 		return TEST_SKIPPED;
12229 
12230 	/* Setup Cipher Parameters */
12231 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12232 	ut_params->cipher_xform.next = &ut_params->auth_xform;
12233 
12234 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
12235 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12236 
12237 	/* Setup HMAC Parameters */
12238 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12239 	ut_params->auth_xform.next = NULL;
12240 
12241 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
12242 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12243 
12244 	ut_params->sess = rte_cryptodev_sym_session_create(
12245 			ts_params->session_mpool);
12246 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12247 
12248 	/* Create Crypto session*/
12249 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
12250 			ut_params->sess, &ut_params->cipher_xform,
12251 			ts_params->session_priv_mpool);
12252 
12253 	if (status == -ENOTSUP)
12254 		return TEST_SKIPPED;
12255 
12256 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
12257 
12258 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
12259 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
12260 			burst_len, "failed to generate burst of crypto ops");
12261 
12262 	/* Generate an operation for each mbuf in burst */
12263 	for (i = 0; i < burst_len; i++) {
12264 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12265 
12266 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
12267 
12268 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
12269 				sizeof(unsigned));
12270 		*data = i;
12271 
12272 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
12273 
12274 		burst[i]->sym->m_src = m;
12275 	}
12276 
12277 	/* Process crypto operation */
12278 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
12279 			0, burst, burst_len),
12280 			burst_len,
12281 			"Error enqueuing burst");
12282 
12283 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
12284 			0, burst_dequeued, burst_len),
12285 			burst_len,
12286 			"Error dequeuing burst");
12287 
12288 
12289 	for (i = 0; i < burst_len; i++) {
12290 		TEST_ASSERT_EQUAL(
12291 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
12292 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
12293 					uint32_t *),
12294 			"data not as expected");
12295 
12296 		rte_pktmbuf_free(burst[i]->sym->m_src);
12297 		rte_crypto_op_free(burst[i]);
12298 	}
12299 
12300 	return TEST_SUCCESS;
12301 }
12302 
12303 static uint16_t
12304 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
12305 		  uint16_t nb_ops, void *user_param)
12306 {
12307 	RTE_SET_USED(dev_id);
12308 	RTE_SET_USED(qp_id);
12309 	RTE_SET_USED(ops);
12310 	RTE_SET_USED(user_param);
12311 
12312 	printf("crypto enqueue callback called\n");
12313 	return nb_ops;
12314 }
12315 
12316 static uint16_t
12317 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
12318 		  uint16_t nb_ops, void *user_param)
12319 {
12320 	RTE_SET_USED(dev_id);
12321 	RTE_SET_USED(qp_id);
12322 	RTE_SET_USED(ops);
12323 	RTE_SET_USED(user_param);
12324 
12325 	printf("crypto dequeue callback called\n");
12326 	return nb_ops;
12327 }
12328 
12329 /*
12330  * Thread using enqueue/dequeue callback with RCU.
12331  */
12332 static int
12333 test_enqdeq_callback_thread(void *arg)
12334 {
12335 	RTE_SET_USED(arg);
12336 	/* DP thread calls rte_cryptodev_enqueue_burst()/
12337 	 * rte_cryptodev_dequeue_burst() and invokes callback.
12338 	 */
12339 	test_null_burst_operation();
12340 	return 0;
12341 }
12342 
12343 static int
12344 test_enq_callback_setup(void)
12345 {
12346 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12347 	struct rte_cryptodev_info dev_info;
12348 	struct rte_cryptodev_qp_conf qp_conf = {
12349 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
12350 	};
12351 
12352 	struct rte_cryptodev_cb *cb;
12353 	uint16_t qp_id = 0;
12354 
12355 	/* Stop the device in case it's started so it can be configured */
12356 	rte_cryptodev_stop(ts_params->valid_devs[0]);
12357 
12358 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12359 
12360 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12361 			&ts_params->conf),
12362 			"Failed to configure cryptodev %u",
12363 			ts_params->valid_devs[0]);
12364 
12365 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12366 	qp_conf.mp_session = ts_params->session_mpool;
12367 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
12368 
12369 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12370 			ts_params->valid_devs[0], qp_id, &qp_conf,
12371 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12372 			"Failed test for "
12373 			"rte_cryptodev_queue_pair_setup: num_inflights "
12374 			"%u on qp %u on cryptodev %u",
12375 			qp_conf.nb_descriptors, qp_id,
12376 			ts_params->valid_devs[0]);
12377 
12378 	/* Test with invalid crypto device */
12379 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
12380 			qp_id, test_enq_callback, NULL);
12381 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12382 			"cryptodev %u did not fail",
12383 			qp_id, RTE_CRYPTO_MAX_DEVS);
12384 
12385 	/* Test with invalid queue pair */
12386 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12387 			dev_info.max_nb_queue_pairs + 1,
12388 			test_enq_callback, NULL);
12389 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12390 			"cryptodev %u did not fail",
12391 			dev_info.max_nb_queue_pairs + 1,
12392 			ts_params->valid_devs[0]);
12393 
12394 	/* Test with NULL callback */
12395 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12396 			qp_id, NULL, NULL);
12397 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12398 			"cryptodev %u did not fail",
12399 			qp_id, ts_params->valid_devs[0]);
12400 
12401 	/* Test with valid configuration */
12402 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12403 			qp_id, test_enq_callback, NULL);
12404 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12405 			"qp %u on cryptodev %u",
12406 			qp_id, ts_params->valid_devs[0]);
12407 
12408 	rte_cryptodev_start(ts_params->valid_devs[0]);
12409 
12410 	/* Launch a thread */
12411 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12412 				rte_get_next_lcore(-1, 1, 0));
12413 
12414 	/* Wait until reader exited. */
12415 	rte_eal_mp_wait_lcore();
12416 
12417 	/* Test with invalid crypto device */
12418 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12419 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12420 			"Expected call to fail as crypto device is invalid");
12421 
12422 	/* Test with invalid queue pair */
12423 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12424 			ts_params->valid_devs[0],
12425 			dev_info.max_nb_queue_pairs + 1, cb),
12426 			"Expected call to fail as queue pair is invalid");
12427 
12428 	/* Test with NULL callback */
12429 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12430 			ts_params->valid_devs[0], qp_id, NULL),
12431 			"Expected call to fail as callback is NULL");
12432 
12433 	/* Test with valid configuration */
12434 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
12435 			ts_params->valid_devs[0], qp_id, cb),
12436 			"Failed test to remove callback on "
12437 			"qp %u on cryptodev %u",
12438 			qp_id, ts_params->valid_devs[0]);
12439 
12440 	return TEST_SUCCESS;
12441 }
12442 
12443 static int
12444 test_deq_callback_setup(void)
12445 {
12446 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12447 	struct rte_cryptodev_info dev_info;
12448 	struct rte_cryptodev_qp_conf qp_conf = {
12449 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
12450 	};
12451 
12452 	struct rte_cryptodev_cb *cb;
12453 	uint16_t qp_id = 0;
12454 
12455 	/* Stop the device in case it's started so it can be configured */
12456 	rte_cryptodev_stop(ts_params->valid_devs[0]);
12457 
12458 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12459 
12460 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12461 			&ts_params->conf),
12462 			"Failed to configure cryptodev %u",
12463 			ts_params->valid_devs[0]);
12464 
12465 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12466 	qp_conf.mp_session = ts_params->session_mpool;
12467 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
12468 
12469 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12470 			ts_params->valid_devs[0], qp_id, &qp_conf,
12471 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12472 			"Failed test for "
12473 			"rte_cryptodev_queue_pair_setup: num_inflights "
12474 			"%u on qp %u on cryptodev %u",
12475 			qp_conf.nb_descriptors, qp_id,
12476 			ts_params->valid_devs[0]);
12477 
12478 	/* Test with invalid crypto device */
12479 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
12480 			qp_id, test_deq_callback, NULL);
12481 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12482 			"cryptodev %u did not fail",
12483 			qp_id, RTE_CRYPTO_MAX_DEVS);
12484 
12485 	/* Test with invalid queue pair */
12486 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12487 			dev_info.max_nb_queue_pairs + 1,
12488 			test_deq_callback, NULL);
12489 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12490 			"cryptodev %u did not fail",
12491 			dev_info.max_nb_queue_pairs + 1,
12492 			ts_params->valid_devs[0]);
12493 
12494 	/* Test with NULL callback */
12495 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12496 			qp_id, NULL, NULL);
12497 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12498 			"cryptodev %u did not fail",
12499 			qp_id, ts_params->valid_devs[0]);
12500 
12501 	/* Test with valid configuration */
12502 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12503 			qp_id, test_deq_callback, NULL);
12504 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12505 			"qp %u on cryptodev %u",
12506 			qp_id, ts_params->valid_devs[0]);
12507 
12508 	rte_cryptodev_start(ts_params->valid_devs[0]);
12509 
12510 	/* Launch a thread */
12511 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12512 				rte_get_next_lcore(-1, 1, 0));
12513 
12514 	/* Wait until reader exited. */
12515 	rte_eal_mp_wait_lcore();
12516 
12517 	/* Test with invalid crypto device */
12518 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12519 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12520 			"Expected call to fail as crypto device is invalid");
12521 
12522 	/* Test with invalid queue pair */
12523 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12524 			ts_params->valid_devs[0],
12525 			dev_info.max_nb_queue_pairs + 1, cb),
12526 			"Expected call to fail as queue pair is invalid");
12527 
12528 	/* Test with NULL callback */
12529 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12530 			ts_params->valid_devs[0], qp_id, NULL),
12531 			"Expected call to fail as callback is NULL");
12532 
12533 	/* Test with valid configuration */
12534 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
12535 			ts_params->valid_devs[0], qp_id, cb),
12536 			"Failed test to remove callback on "
12537 			"qp %u on cryptodev %u",
12538 			qp_id, ts_params->valid_devs[0]);
12539 
12540 	return TEST_SUCCESS;
12541 }
12542 
12543 static void
12544 generate_gmac_large_plaintext(uint8_t *data)
12545 {
12546 	uint16_t i;
12547 
12548 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
12549 		memcpy(&data[i], &data[0], 32);
12550 }
12551 
12552 static int
12553 create_gmac_operation(enum rte_crypto_auth_operation op,
12554 		const struct gmac_test_data *tdata)
12555 {
12556 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12557 	struct crypto_unittest_params *ut_params = &unittest_params;
12558 	struct rte_crypto_sym_op *sym_op;
12559 
12560 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12561 
12562 	/* Generate Crypto op data structure */
12563 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12564 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12565 	TEST_ASSERT_NOT_NULL(ut_params->op,
12566 			"Failed to allocate symmetric crypto operation struct");
12567 
12568 	sym_op = ut_params->op->sym;
12569 
12570 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12571 			ut_params->ibuf, tdata->gmac_tag.len);
12572 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12573 			"no room to append digest");
12574 
12575 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12576 			ut_params->ibuf, plaintext_pad_len);
12577 
12578 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12579 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12580 				tdata->gmac_tag.len);
12581 		debug_hexdump(stdout, "digest:",
12582 				sym_op->auth.digest.data,
12583 				tdata->gmac_tag.len);
12584 	}
12585 
12586 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12587 			uint8_t *, IV_OFFSET);
12588 
12589 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12590 
12591 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12592 
12593 	sym_op->cipher.data.length = 0;
12594 	sym_op->cipher.data.offset = 0;
12595 
12596 	sym_op->auth.data.offset = 0;
12597 	sym_op->auth.data.length = tdata->plaintext.len;
12598 
12599 	return 0;
12600 }
12601 
12602 static int
12603 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12604 		const struct gmac_test_data *tdata,
12605 		void *digest_mem, uint64_t digest_phys)
12606 {
12607 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12608 	struct crypto_unittest_params *ut_params = &unittest_params;
12609 	struct rte_crypto_sym_op *sym_op;
12610 
12611 	/* Generate Crypto op data structure */
12612 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12613 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12614 	TEST_ASSERT_NOT_NULL(ut_params->op,
12615 			"Failed to allocate symmetric crypto operation struct");
12616 
12617 	sym_op = ut_params->op->sym;
12618 
12619 	sym_op->auth.digest.data = digest_mem;
12620 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12621 			"no room to append digest");
12622 
12623 	sym_op->auth.digest.phys_addr = digest_phys;
12624 
12625 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12626 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12627 				tdata->gmac_tag.len);
12628 		debug_hexdump(stdout, "digest:",
12629 				sym_op->auth.digest.data,
12630 				tdata->gmac_tag.len);
12631 	}
12632 
12633 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12634 			uint8_t *, IV_OFFSET);
12635 
12636 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12637 
12638 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12639 
12640 	sym_op->cipher.data.length = 0;
12641 	sym_op->cipher.data.offset = 0;
12642 
12643 	sym_op->auth.data.offset = 0;
12644 	sym_op->auth.data.length = tdata->plaintext.len;
12645 
12646 	return 0;
12647 }
12648 
12649 static int create_gmac_session(uint8_t dev_id,
12650 		const struct gmac_test_data *tdata,
12651 		enum rte_crypto_auth_operation auth_op)
12652 {
12653 	uint8_t auth_key[tdata->key.len];
12654 	int status;
12655 
12656 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12657 	struct crypto_unittest_params *ut_params = &unittest_params;
12658 
12659 	memcpy(auth_key, tdata->key.data, tdata->key.len);
12660 
12661 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12662 	ut_params->auth_xform.next = NULL;
12663 
12664 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12665 	ut_params->auth_xform.auth.op = auth_op;
12666 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12667 	ut_params->auth_xform.auth.key.length = tdata->key.len;
12668 	ut_params->auth_xform.auth.key.data = auth_key;
12669 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12670 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12671 
12672 
12673 	ut_params->sess = rte_cryptodev_sym_session_create(
12674 			ts_params->session_mpool);
12675 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12676 
12677 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12678 			&ut_params->auth_xform,
12679 			ts_params->session_priv_mpool);
12680 
12681 	return status;
12682 }
12683 
12684 static int
12685 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12686 {
12687 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12688 	struct crypto_unittest_params *ut_params = &unittest_params;
12689 	struct rte_cryptodev_info dev_info;
12690 
12691 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12692 	uint64_t feat_flags = dev_info.feature_flags;
12693 
12694 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12695 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12696 		printf("Device doesn't support RAW data-path APIs.\n");
12697 		return TEST_SKIPPED;
12698 	}
12699 
12700 	int retval;
12701 
12702 	uint8_t *auth_tag, *plaintext;
12703 	uint16_t plaintext_pad_len;
12704 
12705 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12706 			      "No GMAC length in the source data");
12707 
12708 	/* Verify the capabilities */
12709 	struct rte_cryptodev_sym_capability_idx cap_idx;
12710 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12711 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12712 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12713 			&cap_idx) == NULL)
12714 		return TEST_SKIPPED;
12715 
12716 	retval = create_gmac_session(ts_params->valid_devs[0],
12717 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12718 
12719 	if (retval == -ENOTSUP)
12720 		return TEST_SKIPPED;
12721 	if (retval < 0)
12722 		return retval;
12723 
12724 	if (tdata->plaintext.len > MBUF_SIZE)
12725 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12726 	else
12727 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12728 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12729 			"Failed to allocate input buffer in mempool");
12730 
12731 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12732 			rte_pktmbuf_tailroom(ut_params->ibuf));
12733 
12734 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12735 	/*
12736 	 * Runtime generate the large plain text instead of use hard code
12737 	 * plain text vector. It is done to avoid create huge source file
12738 	 * with the test vector.
12739 	 */
12740 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12741 		generate_gmac_large_plaintext(tdata->plaintext.data);
12742 
12743 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12744 				plaintext_pad_len);
12745 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12746 
12747 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12748 	debug_hexdump(stdout, "plaintext:", plaintext,
12749 			tdata->plaintext.len);
12750 
12751 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12752 			tdata);
12753 
12754 	if (retval < 0)
12755 		return retval;
12756 
12757 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12758 
12759 	ut_params->op->sym->m_src = ut_params->ibuf;
12760 
12761 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12762 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12763 			ut_params->op);
12764 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12765 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12766 				ut_params->op, 0, 1, 0, 0);
12767 	else
12768 		TEST_ASSERT_NOT_NULL(
12769 			process_crypto_request(ts_params->valid_devs[0],
12770 			ut_params->op), "failed to process sym crypto op");
12771 
12772 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12773 			"crypto op processing failed");
12774 
12775 	if (ut_params->op->sym->m_dst) {
12776 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12777 				uint8_t *, plaintext_pad_len);
12778 	} else {
12779 		auth_tag = plaintext + plaintext_pad_len;
12780 	}
12781 
12782 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12783 
12784 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12785 			auth_tag,
12786 			tdata->gmac_tag.data,
12787 			tdata->gmac_tag.len,
12788 			"GMAC Generated auth tag not as expected");
12789 
12790 	return 0;
12791 }
12792 
12793 static int
12794 test_AES_GMAC_authentication_test_case_1(void)
12795 {
12796 	return test_AES_GMAC_authentication(&gmac_test_case_1);
12797 }
12798 
12799 static int
12800 test_AES_GMAC_authentication_test_case_2(void)
12801 {
12802 	return test_AES_GMAC_authentication(&gmac_test_case_2);
12803 }
12804 
12805 static int
12806 test_AES_GMAC_authentication_test_case_3(void)
12807 {
12808 	return test_AES_GMAC_authentication(&gmac_test_case_3);
12809 }
12810 
12811 static int
12812 test_AES_GMAC_authentication_test_case_4(void)
12813 {
12814 	return test_AES_GMAC_authentication(&gmac_test_case_4);
12815 }
12816 
12817 static int
12818 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12819 {
12820 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12821 	struct crypto_unittest_params *ut_params = &unittest_params;
12822 	int retval;
12823 	uint32_t plaintext_pad_len;
12824 	uint8_t *plaintext;
12825 	struct rte_cryptodev_info dev_info;
12826 
12827 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12828 	uint64_t feat_flags = dev_info.feature_flags;
12829 
12830 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12831 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12832 		printf("Device doesn't support RAW data-path APIs.\n");
12833 		return TEST_SKIPPED;
12834 	}
12835 
12836 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12837 			      "No GMAC length in the source data");
12838 
12839 	/* Verify the capabilities */
12840 	struct rte_cryptodev_sym_capability_idx cap_idx;
12841 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12842 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12843 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12844 			&cap_idx) == NULL)
12845 		return TEST_SKIPPED;
12846 
12847 	retval = create_gmac_session(ts_params->valid_devs[0],
12848 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12849 
12850 	if (retval == -ENOTSUP)
12851 		return TEST_SKIPPED;
12852 	if (retval < 0)
12853 		return retval;
12854 
12855 	if (tdata->plaintext.len > MBUF_SIZE)
12856 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12857 	else
12858 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12859 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12860 			"Failed to allocate input buffer in mempool");
12861 
12862 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12863 			rte_pktmbuf_tailroom(ut_params->ibuf));
12864 
12865 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12866 
12867 	/*
12868 	 * Runtime generate the large plain text instead of use hard code
12869 	 * plain text vector. It is done to avoid create huge source file
12870 	 * with the test vector.
12871 	 */
12872 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12873 		generate_gmac_large_plaintext(tdata->plaintext.data);
12874 
12875 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12876 				plaintext_pad_len);
12877 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12878 
12879 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12880 	debug_hexdump(stdout, "plaintext:", plaintext,
12881 			tdata->plaintext.len);
12882 
12883 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12884 			tdata);
12885 
12886 	if (retval < 0)
12887 		return retval;
12888 
12889 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12890 
12891 	ut_params->op->sym->m_src = ut_params->ibuf;
12892 
12893 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12894 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12895 			ut_params->op);
12896 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12897 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12898 				ut_params->op, 0, 1, 0, 0);
12899 	else
12900 		TEST_ASSERT_NOT_NULL(
12901 			process_crypto_request(ts_params->valid_devs[0],
12902 			ut_params->op), "failed to process sym crypto op");
12903 
12904 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12905 			"crypto op processing failed");
12906 
12907 	return 0;
12908 
12909 }
12910 
12911 static int
12912 test_AES_GMAC_authentication_verify_test_case_1(void)
12913 {
12914 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12915 }
12916 
12917 static int
12918 test_AES_GMAC_authentication_verify_test_case_2(void)
12919 {
12920 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12921 }
12922 
12923 static int
12924 test_AES_GMAC_authentication_verify_test_case_3(void)
12925 {
12926 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12927 }
12928 
12929 static int
12930 test_AES_GMAC_authentication_verify_test_case_4(void)
12931 {
12932 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12933 }
12934 
12935 static int
12936 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12937 				uint32_t fragsz)
12938 {
12939 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12940 	struct crypto_unittest_params *ut_params = &unittest_params;
12941 	struct rte_cryptodev_info dev_info;
12942 	uint64_t feature_flags;
12943 	unsigned int trn_data = 0;
12944 	void *digest_mem = NULL;
12945 	uint32_t segs = 1;
12946 	unsigned int to_trn = 0;
12947 	struct rte_mbuf *buf = NULL;
12948 	uint8_t *auth_tag, *plaintext;
12949 	int retval;
12950 
12951 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12952 			      "No GMAC length in the source data");
12953 
12954 	/* Verify the capabilities */
12955 	struct rte_cryptodev_sym_capability_idx cap_idx;
12956 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12957 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12958 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12959 			&cap_idx) == NULL)
12960 		return TEST_SKIPPED;
12961 
12962 	/* Check for any input SGL support */
12963 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12964 	feature_flags = dev_info.feature_flags;
12965 
12966 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12967 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12968 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12969 		return TEST_SKIPPED;
12970 
12971 	if (fragsz > tdata->plaintext.len)
12972 		fragsz = tdata->plaintext.len;
12973 
12974 	uint16_t plaintext_len = fragsz;
12975 
12976 	retval = create_gmac_session(ts_params->valid_devs[0],
12977 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12978 
12979 	if (retval == -ENOTSUP)
12980 		return TEST_SKIPPED;
12981 	if (retval < 0)
12982 		return retval;
12983 
12984 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12985 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12986 			"Failed to allocate input buffer in mempool");
12987 
12988 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12989 			rte_pktmbuf_tailroom(ut_params->ibuf));
12990 
12991 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12992 				plaintext_len);
12993 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12994 
12995 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12996 
12997 	trn_data += plaintext_len;
12998 
12999 	buf = ut_params->ibuf;
13000 
13001 	/*
13002 	 * Loop until no more fragments
13003 	 */
13004 
13005 	while (trn_data < tdata->plaintext.len) {
13006 		++segs;
13007 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13008 				(tdata->plaintext.len - trn_data) : fragsz;
13009 
13010 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13011 		buf = buf->next;
13012 
13013 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13014 				rte_pktmbuf_tailroom(buf));
13015 
13016 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13017 				to_trn);
13018 
13019 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13020 				to_trn);
13021 		trn_data += to_trn;
13022 		if (trn_data  == tdata->plaintext.len)
13023 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13024 					tdata->gmac_tag.len);
13025 	}
13026 	ut_params->ibuf->nb_segs = segs;
13027 
13028 	/*
13029 	 * Place digest at the end of the last buffer
13030 	 */
13031 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13032 
13033 	if (!digest_mem) {
13034 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13035 				+ tdata->gmac_tag.len);
13036 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13037 				tdata->plaintext.len);
13038 	}
13039 
13040 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
13041 			tdata, digest_mem, digest_phys);
13042 
13043 	if (retval < 0)
13044 		return retval;
13045 
13046 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13047 
13048 	ut_params->op->sym->m_src = ut_params->ibuf;
13049 
13050 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13051 		return TEST_SKIPPED;
13052 
13053 	TEST_ASSERT_NOT_NULL(
13054 		process_crypto_request(ts_params->valid_devs[0],
13055 		ut_params->op), "failed to process sym crypto op");
13056 
13057 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13058 			"crypto op processing failed");
13059 
13060 	auth_tag = digest_mem;
13061 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
13062 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13063 			auth_tag,
13064 			tdata->gmac_tag.data,
13065 			tdata->gmac_tag.len,
13066 			"GMAC Generated auth tag not as expected");
13067 
13068 	return 0;
13069 }
13070 
13071 /* Segment size not multiple of block size (16B) */
13072 static int
13073 test_AES_GMAC_authentication_SGL_40B(void)
13074 {
13075 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
13076 }
13077 
13078 static int
13079 test_AES_GMAC_authentication_SGL_80B(void)
13080 {
13081 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
13082 }
13083 
13084 static int
13085 test_AES_GMAC_authentication_SGL_2048B(void)
13086 {
13087 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
13088 }
13089 
13090 /* Segment size not multiple of block size (16B) */
13091 static int
13092 test_AES_GMAC_authentication_SGL_2047B(void)
13093 {
13094 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
13095 }
13096 
13097 struct test_crypto_vector {
13098 	enum rte_crypto_cipher_algorithm crypto_algo;
13099 	unsigned int cipher_offset;
13100 	unsigned int cipher_len;
13101 
13102 	struct {
13103 		uint8_t data[64];
13104 		unsigned int len;
13105 	} cipher_key;
13106 
13107 	struct {
13108 		uint8_t data[64];
13109 		unsigned int len;
13110 	} iv;
13111 
13112 	struct {
13113 		const uint8_t *data;
13114 		unsigned int len;
13115 	} plaintext;
13116 
13117 	struct {
13118 		const uint8_t *data;
13119 		unsigned int len;
13120 	} ciphertext;
13121 
13122 	enum rte_crypto_auth_algorithm auth_algo;
13123 	unsigned int auth_offset;
13124 
13125 	struct {
13126 		uint8_t data[128];
13127 		unsigned int len;
13128 	} auth_key;
13129 
13130 	struct {
13131 		const uint8_t *data;
13132 		unsigned int len;
13133 	} aad;
13134 
13135 	struct {
13136 		uint8_t data[128];
13137 		unsigned int len;
13138 	} digest;
13139 };
13140 
13141 static const struct test_crypto_vector
13142 hmac_sha1_test_crypto_vector = {
13143 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13144 	.plaintext = {
13145 		.data = plaintext_hash,
13146 		.len = 512
13147 	},
13148 	.auth_key = {
13149 		.data = {
13150 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13151 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13152 			0xDE, 0xF4, 0xDE, 0xAD
13153 		},
13154 		.len = 20
13155 	},
13156 	.digest = {
13157 		.data = {
13158 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
13159 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
13160 			0x3F, 0x91, 0x64, 0x59
13161 		},
13162 		.len = 20
13163 	}
13164 };
13165 
13166 static const struct test_crypto_vector
13167 aes128_gmac_test_vector = {
13168 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
13169 	.plaintext = {
13170 		.data = plaintext_hash,
13171 		.len = 512
13172 	},
13173 	.iv = {
13174 		.data = {
13175 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13176 			0x08, 0x09, 0x0A, 0x0B
13177 		},
13178 		.len = 12
13179 	},
13180 	.auth_key = {
13181 		.data = {
13182 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
13183 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
13184 		},
13185 		.len = 16
13186 	},
13187 	.digest = {
13188 		.data = {
13189 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
13190 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
13191 		},
13192 		.len = 16
13193 	}
13194 };
13195 
13196 static const struct test_crypto_vector
13197 aes128cbc_hmac_sha1_test_vector = {
13198 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
13199 	.cipher_offset = 0,
13200 	.cipher_len = 512,
13201 	.cipher_key = {
13202 		.data = {
13203 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
13204 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
13205 		},
13206 		.len = 16
13207 	},
13208 	.iv = {
13209 		.data = {
13210 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13211 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
13212 		},
13213 		.len = 16
13214 	},
13215 	.plaintext = {
13216 		.data = plaintext_hash,
13217 		.len = 512
13218 	},
13219 	.ciphertext = {
13220 		.data = ciphertext512_aes128cbc,
13221 		.len = 512
13222 	},
13223 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13224 	.auth_offset = 0,
13225 	.auth_key = {
13226 		.data = {
13227 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13228 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13229 			0xDE, 0xF4, 0xDE, 0xAD
13230 		},
13231 		.len = 20
13232 	},
13233 	.digest = {
13234 		.data = {
13235 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
13236 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
13237 			0x18, 0x8C, 0x1D, 0x32
13238 		},
13239 		.len = 20
13240 	}
13241 };
13242 
13243 static const struct test_crypto_vector
13244 aes128cbc_hmac_sha1_aad_test_vector = {
13245 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
13246 	.cipher_offset = 8,
13247 	.cipher_len = 496,
13248 	.cipher_key = {
13249 		.data = {
13250 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
13251 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
13252 		},
13253 		.len = 16
13254 	},
13255 	.iv = {
13256 		.data = {
13257 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13258 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
13259 		},
13260 		.len = 16
13261 	},
13262 	.plaintext = {
13263 		.data = plaintext_hash,
13264 		.len = 512
13265 	},
13266 	.ciphertext = {
13267 		.data = ciphertext512_aes128cbc_aad,
13268 		.len = 512
13269 	},
13270 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13271 	.auth_offset = 0,
13272 	.auth_key = {
13273 		.data = {
13274 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13275 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13276 			0xDE, 0xF4, 0xDE, 0xAD
13277 		},
13278 		.len = 20
13279 	},
13280 	.digest = {
13281 		.data = {
13282 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
13283 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
13284 			0x62, 0x0F, 0xFB, 0x10
13285 		},
13286 		.len = 20
13287 	}
13288 };
13289 
13290 static void
13291 data_corruption(uint8_t *data)
13292 {
13293 	data[0] += 1;
13294 }
13295 
13296 static void
13297 tag_corruption(uint8_t *data, unsigned int tag_offset)
13298 {
13299 	data[tag_offset] += 1;
13300 }
13301 
13302 static int
13303 create_auth_session(struct crypto_unittest_params *ut_params,
13304 		uint8_t dev_id,
13305 		const struct test_crypto_vector *reference,
13306 		enum rte_crypto_auth_operation auth_op)
13307 {
13308 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13309 	uint8_t auth_key[reference->auth_key.len + 1];
13310 	int status;
13311 
13312 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13313 
13314 	/* Setup Authentication Parameters */
13315 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13316 	ut_params->auth_xform.auth.op = auth_op;
13317 	ut_params->auth_xform.next = NULL;
13318 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13319 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13320 	ut_params->auth_xform.auth.key.data = auth_key;
13321 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13322 
13323 	/* Create Crypto session*/
13324 	ut_params->sess = rte_cryptodev_sym_session_create(
13325 			ts_params->session_mpool);
13326 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13327 
13328 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
13329 				&ut_params->auth_xform,
13330 				ts_params->session_priv_mpool);
13331 
13332 	return status;
13333 }
13334 
13335 static int
13336 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
13337 		uint8_t dev_id,
13338 		const struct test_crypto_vector *reference,
13339 		enum rte_crypto_auth_operation auth_op,
13340 		enum rte_crypto_cipher_operation cipher_op)
13341 {
13342 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13343 	uint8_t cipher_key[reference->cipher_key.len + 1];
13344 	uint8_t auth_key[reference->auth_key.len + 1];
13345 	int status;
13346 
13347 	memcpy(cipher_key, reference->cipher_key.data,
13348 			reference->cipher_key.len);
13349 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13350 
13351 	/* Setup Authentication Parameters */
13352 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13353 	ut_params->auth_xform.auth.op = auth_op;
13354 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13355 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13356 	ut_params->auth_xform.auth.key.data = auth_key;
13357 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13358 
13359 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
13360 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
13361 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
13362 	} else {
13363 		ut_params->auth_xform.next = &ut_params->cipher_xform;
13364 
13365 		/* Setup Cipher Parameters */
13366 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13367 		ut_params->cipher_xform.next = NULL;
13368 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13369 		ut_params->cipher_xform.cipher.op = cipher_op;
13370 		ut_params->cipher_xform.cipher.key.data = cipher_key;
13371 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13372 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13373 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13374 	}
13375 
13376 	/* Create Crypto session*/
13377 	ut_params->sess = rte_cryptodev_sym_session_create(
13378 			ts_params->session_mpool);
13379 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13380 
13381 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
13382 				&ut_params->auth_xform,
13383 				ts_params->session_priv_mpool);
13384 
13385 	return status;
13386 }
13387 
13388 static int
13389 create_auth_operation(struct crypto_testsuite_params *ts_params,
13390 		struct crypto_unittest_params *ut_params,
13391 		const struct test_crypto_vector *reference,
13392 		unsigned int auth_generate)
13393 {
13394 	/* Generate Crypto op data structure */
13395 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13396 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13397 	TEST_ASSERT_NOT_NULL(ut_params->op,
13398 			"Failed to allocate pktmbuf offload");
13399 
13400 	/* Set crypto operation data parameters */
13401 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13402 
13403 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13404 
13405 	/* set crypto operation source mbuf */
13406 	sym_op->m_src = ut_params->ibuf;
13407 
13408 	/* digest */
13409 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13410 			ut_params->ibuf, reference->digest.len);
13411 
13412 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13413 			"no room to append auth tag");
13414 
13415 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13416 			ut_params->ibuf, reference->plaintext.len);
13417 
13418 	if (auth_generate)
13419 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13420 	else
13421 		memcpy(sym_op->auth.digest.data,
13422 				reference->digest.data,
13423 				reference->digest.len);
13424 
13425 	debug_hexdump(stdout, "digest:",
13426 			sym_op->auth.digest.data,
13427 			reference->digest.len);
13428 
13429 	sym_op->auth.data.length = reference->plaintext.len;
13430 	sym_op->auth.data.offset = 0;
13431 
13432 	return 0;
13433 }
13434 
13435 static int
13436 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
13437 		struct crypto_unittest_params *ut_params,
13438 		const struct test_crypto_vector *reference,
13439 		unsigned int auth_generate)
13440 {
13441 	/* Generate Crypto op data structure */
13442 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13443 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13444 	TEST_ASSERT_NOT_NULL(ut_params->op,
13445 			"Failed to allocate pktmbuf offload");
13446 
13447 	/* Set crypto operation data parameters */
13448 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13449 
13450 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13451 
13452 	/* set crypto operation source mbuf */
13453 	sym_op->m_src = ut_params->ibuf;
13454 
13455 	/* digest */
13456 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13457 			ut_params->ibuf, reference->digest.len);
13458 
13459 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13460 			"no room to append auth tag");
13461 
13462 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13463 			ut_params->ibuf, reference->ciphertext.len);
13464 
13465 	if (auth_generate)
13466 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13467 	else
13468 		memcpy(sym_op->auth.digest.data,
13469 				reference->digest.data,
13470 				reference->digest.len);
13471 
13472 	debug_hexdump(stdout, "digest:",
13473 			sym_op->auth.digest.data,
13474 			reference->digest.len);
13475 
13476 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13477 			reference->iv.data, reference->iv.len);
13478 
13479 	sym_op->cipher.data.length = 0;
13480 	sym_op->cipher.data.offset = 0;
13481 
13482 	sym_op->auth.data.length = reference->plaintext.len;
13483 	sym_op->auth.data.offset = 0;
13484 
13485 	return 0;
13486 }
13487 
13488 static int
13489 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
13490 		struct crypto_unittest_params *ut_params,
13491 		const struct test_crypto_vector *reference,
13492 		unsigned int auth_generate)
13493 {
13494 	/* Generate Crypto op data structure */
13495 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13496 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13497 	TEST_ASSERT_NOT_NULL(ut_params->op,
13498 			"Failed to allocate pktmbuf offload");
13499 
13500 	/* Set crypto operation data parameters */
13501 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13502 
13503 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13504 
13505 	/* set crypto operation source mbuf */
13506 	sym_op->m_src = ut_params->ibuf;
13507 
13508 	/* digest */
13509 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13510 			ut_params->ibuf, reference->digest.len);
13511 
13512 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13513 			"no room to append auth tag");
13514 
13515 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13516 			ut_params->ibuf, reference->ciphertext.len);
13517 
13518 	if (auth_generate)
13519 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13520 	else
13521 		memcpy(sym_op->auth.digest.data,
13522 				reference->digest.data,
13523 				reference->digest.len);
13524 
13525 	debug_hexdump(stdout, "digest:",
13526 			sym_op->auth.digest.data,
13527 			reference->digest.len);
13528 
13529 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13530 			reference->iv.data, reference->iv.len);
13531 
13532 	sym_op->cipher.data.length = reference->cipher_len;
13533 	sym_op->cipher.data.offset = reference->cipher_offset;
13534 
13535 	sym_op->auth.data.length = reference->plaintext.len;
13536 	sym_op->auth.data.offset = reference->auth_offset;
13537 
13538 	return 0;
13539 }
13540 
13541 static int
13542 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13543 		struct crypto_unittest_params *ut_params,
13544 		const struct test_crypto_vector *reference)
13545 {
13546 	return create_auth_operation(ts_params, ut_params, reference, 0);
13547 }
13548 
13549 static int
13550 create_auth_verify_GMAC_operation(
13551 		struct crypto_testsuite_params *ts_params,
13552 		struct crypto_unittest_params *ut_params,
13553 		const struct test_crypto_vector *reference)
13554 {
13555 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
13556 }
13557 
13558 static int
13559 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13560 		struct crypto_unittest_params *ut_params,
13561 		const struct test_crypto_vector *reference)
13562 {
13563 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
13564 }
13565 
13566 static int
13567 test_authentication_verify_fail_when_data_corruption(
13568 		struct crypto_testsuite_params *ts_params,
13569 		struct crypto_unittest_params *ut_params,
13570 		const struct test_crypto_vector *reference,
13571 		unsigned int data_corrupted)
13572 {
13573 	int retval;
13574 
13575 	uint8_t *plaintext;
13576 	struct rte_cryptodev_info dev_info;
13577 
13578 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13579 	uint64_t feat_flags = dev_info.feature_flags;
13580 
13581 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13582 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13583 		printf("Device doesn't support RAW data-path APIs.\n");
13584 		return TEST_SKIPPED;
13585 	}
13586 
13587 	/* Verify the capabilities */
13588 	struct rte_cryptodev_sym_capability_idx cap_idx;
13589 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13590 	cap_idx.algo.auth = reference->auth_algo;
13591 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13592 			&cap_idx) == NULL)
13593 		return TEST_SKIPPED;
13594 
13595 
13596 	/* Create session */
13597 	retval = create_auth_session(ut_params,
13598 			ts_params->valid_devs[0],
13599 			reference,
13600 			RTE_CRYPTO_AUTH_OP_VERIFY);
13601 
13602 	if (retval == -ENOTSUP)
13603 		return TEST_SKIPPED;
13604 	if (retval < 0)
13605 		return retval;
13606 
13607 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13608 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13609 			"Failed to allocate input buffer in mempool");
13610 
13611 	/* clear mbuf payload */
13612 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13613 			rte_pktmbuf_tailroom(ut_params->ibuf));
13614 
13615 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13616 			reference->plaintext.len);
13617 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13618 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13619 
13620 	debug_hexdump(stdout, "plaintext:", plaintext,
13621 		reference->plaintext.len);
13622 
13623 	/* Create operation */
13624 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
13625 
13626 	if (retval < 0)
13627 		return retval;
13628 
13629 	if (data_corrupted)
13630 		data_corruption(plaintext);
13631 	else
13632 		tag_corruption(plaintext, reference->plaintext.len);
13633 
13634 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13635 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13636 			ut_params->op);
13637 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13638 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13639 			"authentication not failed");
13640 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13641 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13642 				ut_params->op, 0, 1, 0, 0);
13643 	else {
13644 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13645 			ut_params->op);
13646 	}
13647 	if (ut_params->op == NULL)
13648 		return 0;
13649 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13650 		return 0;
13651 
13652 	return -1;
13653 }
13654 
13655 static int
13656 test_authentication_verify_GMAC_fail_when_corruption(
13657 		struct crypto_testsuite_params *ts_params,
13658 		struct crypto_unittest_params *ut_params,
13659 		const struct test_crypto_vector *reference,
13660 		unsigned int data_corrupted)
13661 {
13662 	int retval;
13663 	uint8_t *plaintext;
13664 	struct rte_cryptodev_info dev_info;
13665 
13666 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13667 	uint64_t feat_flags = dev_info.feature_flags;
13668 
13669 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13670 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13671 		printf("Device doesn't support RAW data-path APIs.\n");
13672 		return TEST_SKIPPED;
13673 	}
13674 
13675 	/* Verify the capabilities */
13676 	struct rte_cryptodev_sym_capability_idx cap_idx;
13677 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13678 	cap_idx.algo.auth = reference->auth_algo;
13679 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13680 			&cap_idx) == NULL)
13681 		return TEST_SKIPPED;
13682 
13683 	/* Create session */
13684 	retval = create_auth_cipher_session(ut_params,
13685 			ts_params->valid_devs[0],
13686 			reference,
13687 			RTE_CRYPTO_AUTH_OP_VERIFY,
13688 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13689 	if (retval < 0)
13690 		return retval;
13691 
13692 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13693 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13694 			"Failed to allocate input buffer in mempool");
13695 
13696 	/* clear mbuf payload */
13697 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13698 			rte_pktmbuf_tailroom(ut_params->ibuf));
13699 
13700 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13701 			reference->plaintext.len);
13702 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13703 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13704 
13705 	debug_hexdump(stdout, "plaintext:", plaintext,
13706 		reference->plaintext.len);
13707 
13708 	/* Create operation */
13709 	retval = create_auth_verify_GMAC_operation(ts_params,
13710 			ut_params,
13711 			reference);
13712 
13713 	if (retval < 0)
13714 		return retval;
13715 
13716 	if (data_corrupted)
13717 		data_corruption(plaintext);
13718 	else
13719 		tag_corruption(plaintext, reference->aad.len);
13720 
13721 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13722 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13723 			ut_params->op);
13724 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13725 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13726 			"authentication not failed");
13727 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13728 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13729 				ut_params->op, 0, 1, 0, 0);
13730 	else {
13731 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13732 			ut_params->op);
13733 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13734 	}
13735 
13736 	return 0;
13737 }
13738 
13739 static int
13740 test_authenticated_decryption_fail_when_corruption(
13741 		struct crypto_testsuite_params *ts_params,
13742 		struct crypto_unittest_params *ut_params,
13743 		const struct test_crypto_vector *reference,
13744 		unsigned int data_corrupted)
13745 {
13746 	int retval;
13747 
13748 	uint8_t *ciphertext;
13749 	struct rte_cryptodev_info dev_info;
13750 
13751 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13752 	uint64_t feat_flags = dev_info.feature_flags;
13753 
13754 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13755 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13756 		printf("Device doesn't support RAW data-path APIs.\n");
13757 		return TEST_SKIPPED;
13758 	}
13759 
13760 	/* Verify the capabilities */
13761 	struct rte_cryptodev_sym_capability_idx cap_idx;
13762 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13763 	cap_idx.algo.auth = reference->auth_algo;
13764 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13765 			&cap_idx) == NULL)
13766 		return TEST_SKIPPED;
13767 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13768 	cap_idx.algo.cipher = reference->crypto_algo;
13769 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13770 			&cap_idx) == NULL)
13771 		return TEST_SKIPPED;
13772 
13773 	/* Create session */
13774 	retval = create_auth_cipher_session(ut_params,
13775 			ts_params->valid_devs[0],
13776 			reference,
13777 			RTE_CRYPTO_AUTH_OP_VERIFY,
13778 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13779 
13780 	if (retval == -ENOTSUP)
13781 		return TEST_SKIPPED;
13782 	if (retval < 0)
13783 		return retval;
13784 
13785 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13786 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13787 			"Failed to allocate input buffer in mempool");
13788 
13789 	/* clear mbuf payload */
13790 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13791 			rte_pktmbuf_tailroom(ut_params->ibuf));
13792 
13793 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13794 			reference->ciphertext.len);
13795 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13796 	memcpy(ciphertext, reference->ciphertext.data,
13797 			reference->ciphertext.len);
13798 
13799 	/* Create operation */
13800 	retval = create_cipher_auth_verify_operation(ts_params,
13801 			ut_params,
13802 			reference);
13803 
13804 	if (retval < 0)
13805 		return retval;
13806 
13807 	if (data_corrupted)
13808 		data_corruption(ciphertext);
13809 	else
13810 		tag_corruption(ciphertext, reference->ciphertext.len);
13811 
13812 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13813 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13814 			ut_params->op);
13815 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13816 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13817 			"authentication not failed");
13818 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13819 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13820 				ut_params->op, 1, 1, 0, 0);
13821 	else {
13822 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13823 			ut_params->op);
13824 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13825 	}
13826 
13827 	return 0;
13828 }
13829 
13830 static int
13831 test_authenticated_encrypt_with_esn(
13832 		struct crypto_testsuite_params *ts_params,
13833 		struct crypto_unittest_params *ut_params,
13834 		const struct test_crypto_vector *reference)
13835 {
13836 	int retval;
13837 
13838 	uint8_t *authciphertext, *plaintext, *auth_tag;
13839 	uint16_t plaintext_pad_len;
13840 	uint8_t cipher_key[reference->cipher_key.len + 1];
13841 	uint8_t auth_key[reference->auth_key.len + 1];
13842 	struct rte_cryptodev_info dev_info;
13843 	int status;
13844 
13845 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13846 	uint64_t feat_flags = dev_info.feature_flags;
13847 
13848 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13849 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13850 		printf("Device doesn't support RAW data-path APIs.\n");
13851 		return TEST_SKIPPED;
13852 	}
13853 
13854 	/* Verify the capabilities */
13855 	struct rte_cryptodev_sym_capability_idx cap_idx;
13856 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13857 	cap_idx.algo.auth = reference->auth_algo;
13858 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13859 			&cap_idx) == NULL)
13860 		return TEST_SKIPPED;
13861 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13862 	cap_idx.algo.cipher = reference->crypto_algo;
13863 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13864 			&cap_idx) == NULL)
13865 		return TEST_SKIPPED;
13866 
13867 	/* Create session */
13868 	memcpy(cipher_key, reference->cipher_key.data,
13869 			reference->cipher_key.len);
13870 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13871 
13872 	/* Setup Cipher Parameters */
13873 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13874 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13875 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13876 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13877 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13878 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13879 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13880 
13881 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13882 
13883 	/* Setup Authentication Parameters */
13884 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13885 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13886 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13887 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13888 	ut_params->auth_xform.auth.key.data = auth_key;
13889 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13890 	ut_params->auth_xform.next = NULL;
13891 
13892 	/* Create Crypto session*/
13893 	ut_params->sess = rte_cryptodev_sym_session_create(
13894 			ts_params->session_mpool);
13895 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13896 
13897 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13898 				ut_params->sess,
13899 				&ut_params->cipher_xform,
13900 				ts_params->session_priv_mpool);
13901 
13902 	if (status == -ENOTSUP)
13903 		return TEST_SKIPPED;
13904 
13905 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
13906 
13907 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13908 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13909 			"Failed to allocate input buffer in mempool");
13910 
13911 	/* clear mbuf payload */
13912 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13913 			rte_pktmbuf_tailroom(ut_params->ibuf));
13914 
13915 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13916 			reference->plaintext.len);
13917 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13918 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13919 
13920 	/* Create operation */
13921 	retval = create_cipher_auth_operation(ts_params,
13922 			ut_params,
13923 			reference, 0);
13924 
13925 	if (retval < 0)
13926 		return retval;
13927 
13928 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13929 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13930 			ut_params->op);
13931 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13932 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13933 				ut_params->op, 1, 1, 0, 0);
13934 	else
13935 		ut_params->op = process_crypto_request(
13936 			ts_params->valid_devs[0], ut_params->op);
13937 
13938 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13939 
13940 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13941 			"crypto op processing failed");
13942 
13943 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13944 
13945 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13946 			ut_params->op->sym->auth.data.offset);
13947 	auth_tag = authciphertext + plaintext_pad_len;
13948 	debug_hexdump(stdout, "ciphertext:", authciphertext,
13949 			reference->ciphertext.len);
13950 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13951 
13952 	/* Validate obuf */
13953 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13954 			authciphertext,
13955 			reference->ciphertext.data,
13956 			reference->ciphertext.len,
13957 			"Ciphertext data not as expected");
13958 
13959 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13960 			auth_tag,
13961 			reference->digest.data,
13962 			reference->digest.len,
13963 			"Generated digest not as expected");
13964 
13965 	return TEST_SUCCESS;
13966 
13967 }
13968 
13969 static int
13970 test_authenticated_decrypt_with_esn(
13971 		struct crypto_testsuite_params *ts_params,
13972 		struct crypto_unittest_params *ut_params,
13973 		const struct test_crypto_vector *reference)
13974 {
13975 	int retval;
13976 
13977 	uint8_t *ciphertext;
13978 	uint8_t cipher_key[reference->cipher_key.len + 1];
13979 	uint8_t auth_key[reference->auth_key.len + 1];
13980 	struct rte_cryptodev_info dev_info;
13981 
13982 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13983 	uint64_t feat_flags = dev_info.feature_flags;
13984 
13985 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13986 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13987 		printf("Device doesn't support RAW data-path APIs.\n");
13988 		return TEST_SKIPPED;
13989 	}
13990 
13991 	/* Verify the capabilities */
13992 	struct rte_cryptodev_sym_capability_idx cap_idx;
13993 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13994 	cap_idx.algo.auth = reference->auth_algo;
13995 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13996 			&cap_idx) == NULL)
13997 		return TEST_SKIPPED;
13998 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13999 	cap_idx.algo.cipher = reference->crypto_algo;
14000 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14001 			&cap_idx) == NULL)
14002 		return TEST_SKIPPED;
14003 
14004 	/* Create session */
14005 	memcpy(cipher_key, reference->cipher_key.data,
14006 			reference->cipher_key.len);
14007 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14008 
14009 	/* Setup Authentication Parameters */
14010 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14011 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
14012 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14013 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14014 	ut_params->auth_xform.auth.key.data = auth_key;
14015 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14016 	ut_params->auth_xform.next = &ut_params->cipher_xform;
14017 
14018 	/* Setup Cipher Parameters */
14019 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14020 	ut_params->cipher_xform.next = NULL;
14021 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
14022 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
14023 	ut_params->cipher_xform.cipher.key.data = cipher_key;
14024 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
14025 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
14026 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
14027 
14028 	/* Create Crypto session*/
14029 	ut_params->sess = rte_cryptodev_sym_session_create(
14030 			ts_params->session_mpool);
14031 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14032 
14033 	retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
14034 				ut_params->sess,
14035 				&ut_params->auth_xform,
14036 				ts_params->session_priv_mpool);
14037 
14038 	if (retval == -ENOTSUP)
14039 		return TEST_SKIPPED;
14040 
14041 	TEST_ASSERT_EQUAL(retval, 0, "Session init failed");
14042 
14043 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14044 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14045 			"Failed to allocate input buffer in mempool");
14046 
14047 	/* clear mbuf payload */
14048 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14049 			rte_pktmbuf_tailroom(ut_params->ibuf));
14050 
14051 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14052 			reference->ciphertext.len);
14053 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
14054 	memcpy(ciphertext, reference->ciphertext.data,
14055 			reference->ciphertext.len);
14056 
14057 	/* Create operation */
14058 	retval = create_cipher_auth_verify_operation(ts_params,
14059 			ut_params,
14060 			reference);
14061 
14062 	if (retval < 0)
14063 		return retval;
14064 
14065 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14066 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14067 			ut_params->op);
14068 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14069 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14070 				ut_params->op, 1, 1, 0, 0);
14071 	else
14072 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14073 			ut_params->op);
14074 
14075 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
14076 	TEST_ASSERT_EQUAL(ut_params->op->status,
14077 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14078 			"crypto op processing passed");
14079 
14080 	ut_params->obuf = ut_params->op->sym->m_src;
14081 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
14082 
14083 	return 0;
14084 }
14085 
14086 static int
14087 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
14088 		const struct aead_test_data *tdata,
14089 		void *digest_mem, uint64_t digest_phys)
14090 {
14091 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14092 	struct crypto_unittest_params *ut_params = &unittest_params;
14093 
14094 	const unsigned int auth_tag_len = tdata->auth_tag.len;
14095 	const unsigned int iv_len = tdata->iv.len;
14096 	unsigned int aad_len = tdata->aad.len;
14097 	unsigned int aad_len_pad = 0;
14098 
14099 	/* Generate Crypto op data structure */
14100 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14101 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14102 	TEST_ASSERT_NOT_NULL(ut_params->op,
14103 		"Failed to allocate symmetric crypto operation struct");
14104 
14105 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14106 
14107 	sym_op->aead.digest.data = digest_mem;
14108 
14109 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
14110 			"no room to append digest");
14111 
14112 	sym_op->aead.digest.phys_addr = digest_phys;
14113 
14114 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
14115 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
14116 				auth_tag_len);
14117 		debug_hexdump(stdout, "digest:",
14118 				sym_op->aead.digest.data,
14119 				auth_tag_len);
14120 	}
14121 
14122 	/* Append aad data */
14123 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
14124 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
14125 				uint8_t *, IV_OFFSET);
14126 
14127 		/* Copy IV 1 byte after the IV pointer, according to the API */
14128 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
14129 
14130 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
14131 
14132 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
14133 				ut_params->ibuf, aad_len);
14134 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
14135 				"no room to prepend aad");
14136 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
14137 				ut_params->ibuf);
14138 
14139 		memset(sym_op->aead.aad.data, 0, aad_len);
14140 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
14141 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
14142 
14143 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
14144 		debug_hexdump(stdout, "aad:",
14145 				sym_op->aead.aad.data, aad_len);
14146 	} else {
14147 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
14148 				uint8_t *, IV_OFFSET);
14149 
14150 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
14151 
14152 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
14153 
14154 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
14155 				ut_params->ibuf, aad_len_pad);
14156 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
14157 				"no room to prepend aad");
14158 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
14159 				ut_params->ibuf);
14160 
14161 		memset(sym_op->aead.aad.data, 0, aad_len);
14162 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
14163 
14164 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
14165 		debug_hexdump(stdout, "aad:",
14166 				sym_op->aead.aad.data, aad_len);
14167 	}
14168 
14169 	sym_op->aead.data.length = tdata->plaintext.len;
14170 	sym_op->aead.data.offset = aad_len_pad;
14171 
14172 	return 0;
14173 }
14174 
14175 #define SGL_MAX_NO	16
14176 
14177 static int
14178 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
14179 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
14180 {
14181 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14182 	struct crypto_unittest_params *ut_params = &unittest_params;
14183 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
14184 	int retval;
14185 	int to_trn = 0;
14186 	int to_trn_tbl[SGL_MAX_NO];
14187 	int segs = 1;
14188 	unsigned int trn_data = 0;
14189 	uint8_t *plaintext, *ciphertext, *auth_tag;
14190 	struct rte_cryptodev_info dev_info;
14191 
14192 	/* Verify the capabilities */
14193 	struct rte_cryptodev_sym_capability_idx cap_idx;
14194 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
14195 	cap_idx.algo.aead = tdata->algo;
14196 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14197 			&cap_idx) == NULL)
14198 		return TEST_SKIPPED;
14199 
14200 	/* OOP not supported with CPU crypto */
14201 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14202 		return TEST_SKIPPED;
14203 
14204 	/* Detailed check for the particular SGL support flag */
14205 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14206 	if (!oop) {
14207 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
14208 		if (sgl_in && (!(dev_info.feature_flags &
14209 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
14210 			return TEST_SKIPPED;
14211 
14212 		uint64_t feat_flags = dev_info.feature_flags;
14213 
14214 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14215 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14216 			printf("Device doesn't support RAW data-path APIs.\n");
14217 			return TEST_SKIPPED;
14218 		}
14219 	} else {
14220 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
14221 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
14222 				tdata->plaintext.len;
14223 		/* Raw data path API does not support OOP */
14224 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14225 			return TEST_SKIPPED;
14226 		if (sgl_in && !sgl_out) {
14227 			if (!(dev_info.feature_flags &
14228 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
14229 				return TEST_SKIPPED;
14230 		} else if (!sgl_in && sgl_out) {
14231 			if (!(dev_info.feature_flags &
14232 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
14233 				return TEST_SKIPPED;
14234 		} else if (sgl_in && sgl_out) {
14235 			if (!(dev_info.feature_flags &
14236 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
14237 				return TEST_SKIPPED;
14238 		}
14239 	}
14240 
14241 	if (fragsz > tdata->plaintext.len)
14242 		fragsz = tdata->plaintext.len;
14243 
14244 	uint16_t plaintext_len = fragsz;
14245 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
14246 
14247 	if (fragsz_oop > tdata->plaintext.len)
14248 		frag_size_oop = tdata->plaintext.len;
14249 
14250 	int ecx = 0;
14251 	void *digest_mem = NULL;
14252 
14253 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
14254 
14255 	if (tdata->plaintext.len % fragsz != 0) {
14256 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
14257 			return 1;
14258 	}	else {
14259 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
14260 			return 1;
14261 	}
14262 
14263 	/*
14264 	 * For out-op-place we need to alloc another mbuf
14265 	 */
14266 	if (oop) {
14267 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14268 		rte_pktmbuf_append(ut_params->obuf,
14269 				frag_size_oop + prepend_len);
14270 		buf_oop = ut_params->obuf;
14271 	}
14272 
14273 	/* Create AEAD session */
14274 	retval = create_aead_session(ts_params->valid_devs[0],
14275 			tdata->algo,
14276 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
14277 			tdata->key.data, tdata->key.len,
14278 			tdata->aad.len, tdata->auth_tag.len,
14279 			tdata->iv.len);
14280 	if (retval < 0)
14281 		return retval;
14282 
14283 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14284 
14285 	/* clear mbuf payload */
14286 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14287 			rte_pktmbuf_tailroom(ut_params->ibuf));
14288 
14289 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14290 			plaintext_len);
14291 
14292 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
14293 
14294 	trn_data += plaintext_len;
14295 
14296 	buf = ut_params->ibuf;
14297 
14298 	/*
14299 	 * Loop until no more fragments
14300 	 */
14301 
14302 	while (trn_data < tdata->plaintext.len) {
14303 		++segs;
14304 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
14305 				(tdata->plaintext.len - trn_data) : fragsz;
14306 
14307 		to_trn_tbl[ecx++] = to_trn;
14308 
14309 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14310 		buf = buf->next;
14311 
14312 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
14313 				rte_pktmbuf_tailroom(buf));
14314 
14315 		/* OOP */
14316 		if (oop && !fragsz_oop) {
14317 			buf_last_oop = buf_oop->next =
14318 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
14319 			buf_oop = buf_oop->next;
14320 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
14321 					0, rte_pktmbuf_tailroom(buf_oop));
14322 			rte_pktmbuf_append(buf_oop, to_trn);
14323 		}
14324 
14325 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
14326 				to_trn);
14327 
14328 		memcpy(plaintext, tdata->plaintext.data + trn_data,
14329 				to_trn);
14330 		trn_data += to_trn;
14331 		if (trn_data  == tdata->plaintext.len) {
14332 			if (oop) {
14333 				if (!fragsz_oop)
14334 					digest_mem = rte_pktmbuf_append(buf_oop,
14335 						tdata->auth_tag.len);
14336 			} else
14337 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
14338 					tdata->auth_tag.len);
14339 		}
14340 	}
14341 
14342 	uint64_t digest_phys = 0;
14343 
14344 	ut_params->ibuf->nb_segs = segs;
14345 
14346 	segs = 1;
14347 	if (fragsz_oop && oop) {
14348 		to_trn = 0;
14349 		ecx = 0;
14350 
14351 		if (frag_size_oop == tdata->plaintext.len) {
14352 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
14353 				tdata->auth_tag.len);
14354 
14355 			digest_phys = rte_pktmbuf_iova_offset(
14356 					ut_params->obuf,
14357 					tdata->plaintext.len + prepend_len);
14358 		}
14359 
14360 		trn_data = frag_size_oop;
14361 		while (trn_data < tdata->plaintext.len) {
14362 			++segs;
14363 			to_trn =
14364 				(tdata->plaintext.len - trn_data <
14365 						frag_size_oop) ?
14366 				(tdata->plaintext.len - trn_data) :
14367 						frag_size_oop;
14368 
14369 			to_trn_tbl[ecx++] = to_trn;
14370 
14371 			buf_last_oop = buf_oop->next =
14372 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
14373 			buf_oop = buf_oop->next;
14374 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
14375 					0, rte_pktmbuf_tailroom(buf_oop));
14376 			rte_pktmbuf_append(buf_oop, to_trn);
14377 
14378 			trn_data += to_trn;
14379 
14380 			if (trn_data  == tdata->plaintext.len) {
14381 				digest_mem = rte_pktmbuf_append(buf_oop,
14382 					tdata->auth_tag.len);
14383 			}
14384 		}
14385 
14386 		ut_params->obuf->nb_segs = segs;
14387 	}
14388 
14389 	/*
14390 	 * Place digest at the end of the last buffer
14391 	 */
14392 	if (!digest_phys)
14393 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
14394 	if (oop && buf_last_oop)
14395 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
14396 
14397 	if (!digest_mem && !oop) {
14398 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14399 				+ tdata->auth_tag.len);
14400 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
14401 				tdata->plaintext.len);
14402 	}
14403 
14404 	/* Create AEAD operation */
14405 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
14406 			tdata, digest_mem, digest_phys);
14407 
14408 	if (retval < 0)
14409 		return retval;
14410 
14411 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14412 
14413 	ut_params->op->sym->m_src = ut_params->ibuf;
14414 	if (oop)
14415 		ut_params->op->sym->m_dst = ut_params->obuf;
14416 
14417 	/* Process crypto operation */
14418 	if (oop == IN_PLACE &&
14419 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14420 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
14421 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14422 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14423 				ut_params->op, 0, 0, 0, 0);
14424 	else
14425 		TEST_ASSERT_NOT_NULL(
14426 			process_crypto_request(ts_params->valid_devs[0],
14427 			ut_params->op), "failed to process sym crypto op");
14428 
14429 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14430 			"crypto op processing failed");
14431 
14432 
14433 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
14434 			uint8_t *, prepend_len);
14435 	if (oop) {
14436 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
14437 				uint8_t *, prepend_len);
14438 	}
14439 
14440 	if (fragsz_oop)
14441 		fragsz = fragsz_oop;
14442 
14443 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14444 			ciphertext,
14445 			tdata->ciphertext.data,
14446 			fragsz,
14447 			"Ciphertext data not as expected");
14448 
14449 	buf = ut_params->op->sym->m_src->next;
14450 	if (oop)
14451 		buf = ut_params->op->sym->m_dst->next;
14452 
14453 	unsigned int off = fragsz;
14454 
14455 	ecx = 0;
14456 	while (buf) {
14457 		ciphertext = rte_pktmbuf_mtod(buf,
14458 				uint8_t *);
14459 
14460 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
14461 				ciphertext,
14462 				tdata->ciphertext.data + off,
14463 				to_trn_tbl[ecx],
14464 				"Ciphertext data not as expected");
14465 
14466 		off += to_trn_tbl[ecx++];
14467 		buf = buf->next;
14468 	}
14469 
14470 	auth_tag = digest_mem;
14471 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14472 			auth_tag,
14473 			tdata->auth_tag.data,
14474 			tdata->auth_tag.len,
14475 			"Generated auth tag not as expected");
14476 
14477 	return 0;
14478 }
14479 
14480 static int
14481 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
14482 {
14483 	return test_authenticated_encryption_SGL(
14484 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
14485 }
14486 
14487 static int
14488 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
14489 {
14490 	return test_authenticated_encryption_SGL(
14491 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
14492 }
14493 
14494 static int
14495 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
14496 {
14497 	return test_authenticated_encryption_SGL(
14498 			&gcm_test_case_8, OUT_OF_PLACE, 400,
14499 			gcm_test_case_8.plaintext.len);
14500 }
14501 
14502 static int
14503 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
14504 {
14505 	/* This test is not for OPENSSL PMD */
14506 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14507 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
14508 		return TEST_SKIPPED;
14509 
14510 	return test_authenticated_encryption_SGL(
14511 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
14512 }
14513 
14514 static int
14515 test_authentication_verify_fail_when_data_corrupted(
14516 		struct crypto_testsuite_params *ts_params,
14517 		struct crypto_unittest_params *ut_params,
14518 		const struct test_crypto_vector *reference)
14519 {
14520 	return test_authentication_verify_fail_when_data_corruption(
14521 			ts_params, ut_params, reference, 1);
14522 }
14523 
14524 static int
14525 test_authentication_verify_fail_when_tag_corrupted(
14526 		struct crypto_testsuite_params *ts_params,
14527 		struct crypto_unittest_params *ut_params,
14528 		const struct test_crypto_vector *reference)
14529 {
14530 	return test_authentication_verify_fail_when_data_corruption(
14531 			ts_params, ut_params, reference, 0);
14532 }
14533 
14534 static int
14535 test_authentication_verify_GMAC_fail_when_data_corrupted(
14536 		struct crypto_testsuite_params *ts_params,
14537 		struct crypto_unittest_params *ut_params,
14538 		const struct test_crypto_vector *reference)
14539 {
14540 	return test_authentication_verify_GMAC_fail_when_corruption(
14541 			ts_params, ut_params, reference, 1);
14542 }
14543 
14544 static int
14545 test_authentication_verify_GMAC_fail_when_tag_corrupted(
14546 		struct crypto_testsuite_params *ts_params,
14547 		struct crypto_unittest_params *ut_params,
14548 		const struct test_crypto_vector *reference)
14549 {
14550 	return test_authentication_verify_GMAC_fail_when_corruption(
14551 			ts_params, ut_params, reference, 0);
14552 }
14553 
14554 static int
14555 test_authenticated_decryption_fail_when_data_corrupted(
14556 		struct crypto_testsuite_params *ts_params,
14557 		struct crypto_unittest_params *ut_params,
14558 		const struct test_crypto_vector *reference)
14559 {
14560 	return test_authenticated_decryption_fail_when_corruption(
14561 			ts_params, ut_params, reference, 1);
14562 }
14563 
14564 static int
14565 test_authenticated_decryption_fail_when_tag_corrupted(
14566 		struct crypto_testsuite_params *ts_params,
14567 		struct crypto_unittest_params *ut_params,
14568 		const struct test_crypto_vector *reference)
14569 {
14570 	return test_authenticated_decryption_fail_when_corruption(
14571 			ts_params, ut_params, reference, 0);
14572 }
14573 
14574 static int
14575 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
14576 {
14577 	return test_authentication_verify_fail_when_data_corrupted(
14578 			&testsuite_params, &unittest_params,
14579 			&hmac_sha1_test_crypto_vector);
14580 }
14581 
14582 static int
14583 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
14584 {
14585 	return test_authentication_verify_fail_when_tag_corrupted(
14586 			&testsuite_params, &unittest_params,
14587 			&hmac_sha1_test_crypto_vector);
14588 }
14589 
14590 static int
14591 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
14592 {
14593 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
14594 			&testsuite_params, &unittest_params,
14595 			&aes128_gmac_test_vector);
14596 }
14597 
14598 static int
14599 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
14600 {
14601 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
14602 			&testsuite_params, &unittest_params,
14603 			&aes128_gmac_test_vector);
14604 }
14605 
14606 static int
14607 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
14608 {
14609 	return test_authenticated_decryption_fail_when_data_corrupted(
14610 			&testsuite_params,
14611 			&unittest_params,
14612 			&aes128cbc_hmac_sha1_test_vector);
14613 }
14614 
14615 static int
14616 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14617 {
14618 	return test_authenticated_decryption_fail_when_tag_corrupted(
14619 			&testsuite_params,
14620 			&unittest_params,
14621 			&aes128cbc_hmac_sha1_test_vector);
14622 }
14623 
14624 static int
14625 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14626 {
14627 	return test_authenticated_encrypt_with_esn(
14628 			&testsuite_params,
14629 			&unittest_params,
14630 			&aes128cbc_hmac_sha1_aad_test_vector);
14631 }
14632 
14633 static int
14634 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14635 {
14636 	return test_authenticated_decrypt_with_esn(
14637 			&testsuite_params,
14638 			&unittest_params,
14639 			&aes128cbc_hmac_sha1_aad_test_vector);
14640 }
14641 
14642 static int
14643 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14644 {
14645 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14646 }
14647 
14648 static int
14649 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14650 {
14651 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14652 }
14653 
14654 static int
14655 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
14656 {
14657 	return test_authenticated_encryption_SGL(
14658 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
14659 		chacha20_poly1305_case_2.plaintext.len);
14660 }
14661 
14662 #ifdef RTE_CRYPTO_SCHEDULER
14663 
14664 /* global AESNI worker IDs for the scheduler test */
14665 uint8_t aesni_ids[2];
14666 
14667 static int
14668 scheduler_testsuite_setup(void)
14669 {
14670 	uint32_t i = 0;
14671 	int32_t nb_devs, ret;
14672 	char vdev_args[VDEV_ARGS_SIZE] = {""};
14673 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14674 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
14675 	uint16_t worker_core_count = 0;
14676 	uint16_t socket_id = 0;
14677 
14678 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14679 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14680 
14681 		/* Identify the Worker Cores
14682 		 * Use 2 worker cores for the device args
14683 		 */
14684 		RTE_LCORE_FOREACH_WORKER(i) {
14685 			if (worker_core_count > 1)
14686 				break;
14687 			snprintf(vdev_args, sizeof(vdev_args),
14688 					"%s%d", temp_str, i);
14689 			strcpy(temp_str, vdev_args);
14690 			strlcat(temp_str, ";", sizeof(temp_str));
14691 			worker_core_count++;
14692 			socket_id = rte_lcore_to_socket_id(i);
14693 		}
14694 		if (worker_core_count != 2) {
14695 			RTE_LOG(ERR, USER1,
14696 				"Cryptodev scheduler test require at least "
14697 				"two worker cores to run. "
14698 				"Please use the correct coremask.\n");
14699 			return TEST_FAILED;
14700 		}
14701 		strcpy(temp_str, vdev_args);
14702 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14703 				temp_str, socket_id);
14704 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14705 		nb_devs = rte_cryptodev_device_count_by_driver(
14706 				rte_cryptodev_driver_id_get(
14707 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14708 		if (nb_devs < 1) {
14709 			ret = rte_vdev_init(
14710 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14711 					vdev_args);
14712 			TEST_ASSERT(ret == 0,
14713 				"Failed to create instance %u of pmd : %s",
14714 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14715 		}
14716 	}
14717 	return testsuite_setup();
14718 }
14719 
14720 static int
14721 test_scheduler_attach_worker_op(void)
14722 {
14723 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14724 	uint8_t sched_id = ts_params->valid_devs[0];
14725 	uint32_t i, nb_devs_attached = 0;
14726 	int ret;
14727 	char vdev_name[32];
14728 	unsigned int count = rte_cryptodev_count();
14729 
14730 	/* create 2 AESNI_MB vdevs on top of existing devices */
14731 	for (i = count; i < count + 2; i++) {
14732 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14733 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14734 				i);
14735 		ret = rte_vdev_init(vdev_name, NULL);
14736 
14737 		TEST_ASSERT(ret == 0,
14738 			"Failed to create instance %u of"
14739 			" pmd : %s",
14740 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14741 
14742 		if (ret < 0) {
14743 			RTE_LOG(ERR, USER1,
14744 				"Failed to create 2 AESNI MB PMDs.\n");
14745 			return TEST_SKIPPED;
14746 		}
14747 	}
14748 
14749 	/* attach 2 AESNI_MB cdevs */
14750 	for (i = count; i < count + 2; i++) {
14751 		struct rte_cryptodev_info info;
14752 		unsigned int session_size;
14753 
14754 		rte_cryptodev_info_get(i, &info);
14755 		if (info.driver_id != rte_cryptodev_driver_id_get(
14756 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14757 			continue;
14758 
14759 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14760 		/*
14761 		 * Create the session mempool again, since now there are new devices
14762 		 * to use the mempool.
14763 		 */
14764 		if (ts_params->session_mpool) {
14765 			rte_mempool_free(ts_params->session_mpool);
14766 			ts_params->session_mpool = NULL;
14767 		}
14768 		if (ts_params->session_priv_mpool) {
14769 			rte_mempool_free(ts_params->session_priv_mpool);
14770 			ts_params->session_priv_mpool = NULL;
14771 		}
14772 
14773 		if (info.sym.max_nb_sessions != 0 &&
14774 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14775 			RTE_LOG(ERR, USER1,
14776 					"Device does not support "
14777 					"at least %u sessions\n",
14778 					MAX_NB_SESSIONS);
14779 			return TEST_FAILED;
14780 		}
14781 		/*
14782 		 * Create mempool with maximum number of sessions,
14783 		 * to include the session headers
14784 		 */
14785 		if (ts_params->session_mpool == NULL) {
14786 			ts_params->session_mpool =
14787 				rte_cryptodev_sym_session_pool_create(
14788 						"test_sess_mp",
14789 						MAX_NB_SESSIONS, 0, 0, 0,
14790 						SOCKET_ID_ANY);
14791 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14792 					"session mempool allocation failed");
14793 		}
14794 
14795 		/*
14796 		 * Create mempool with maximum number of sessions,
14797 		 * to include device specific session private data
14798 		 */
14799 		if (ts_params->session_priv_mpool == NULL) {
14800 			ts_params->session_priv_mpool = rte_mempool_create(
14801 					"test_sess_mp_priv",
14802 					MAX_NB_SESSIONS,
14803 					session_size,
14804 					0, 0, NULL, NULL, NULL,
14805 					NULL, SOCKET_ID_ANY,
14806 					0);
14807 
14808 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14809 					"session mempool allocation failed");
14810 		}
14811 
14812 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
14813 		ts_params->qp_conf.mp_session_private =
14814 				ts_params->session_priv_mpool;
14815 
14816 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14817 				(uint8_t)i);
14818 
14819 		TEST_ASSERT(ret == 0,
14820 			"Failed to attach device %u of pmd : %s", i,
14821 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14822 
14823 		aesni_ids[nb_devs_attached] = (uint8_t)i;
14824 
14825 		nb_devs_attached++;
14826 	}
14827 
14828 	return 0;
14829 }
14830 
14831 static int
14832 test_scheduler_detach_worker_op(void)
14833 {
14834 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14835 	uint8_t sched_id = ts_params->valid_devs[0];
14836 	uint32_t i;
14837 	int ret;
14838 
14839 	for (i = 0; i < 2; i++) {
14840 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14841 				aesni_ids[i]);
14842 		TEST_ASSERT(ret == 0,
14843 			"Failed to detach device %u", aesni_ids[i]);
14844 	}
14845 
14846 	return 0;
14847 }
14848 
14849 static int
14850 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14851 {
14852 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14853 	uint8_t sched_id = ts_params->valid_devs[0];
14854 	/* set mode */
14855 	return rte_cryptodev_scheduler_mode_set(sched_id,
14856 		scheduler_mode);
14857 }
14858 
14859 static int
14860 test_scheduler_mode_roundrobin_op(void)
14861 {
14862 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14863 			0, "Failed to set roundrobin mode");
14864 	return 0;
14865 
14866 }
14867 
14868 static int
14869 test_scheduler_mode_multicore_op(void)
14870 {
14871 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14872 			0, "Failed to set multicore mode");
14873 
14874 	return 0;
14875 }
14876 
14877 static int
14878 test_scheduler_mode_failover_op(void)
14879 {
14880 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14881 			0, "Failed to set failover mode");
14882 
14883 	return 0;
14884 }
14885 
14886 static int
14887 test_scheduler_mode_pkt_size_distr_op(void)
14888 {
14889 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14890 			0, "Failed to set pktsize mode");
14891 
14892 	return 0;
14893 }
14894 
14895 static int
14896 scheduler_multicore_testsuite_setup(void)
14897 {
14898 	if (test_scheduler_attach_worker_op() < 0)
14899 		return TEST_SKIPPED;
14900 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14901 		return TEST_SKIPPED;
14902 	return 0;
14903 }
14904 
14905 static int
14906 scheduler_roundrobin_testsuite_setup(void)
14907 {
14908 	if (test_scheduler_attach_worker_op() < 0)
14909 		return TEST_SKIPPED;
14910 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14911 		return TEST_SKIPPED;
14912 	return 0;
14913 }
14914 
14915 static int
14916 scheduler_failover_testsuite_setup(void)
14917 {
14918 	if (test_scheduler_attach_worker_op() < 0)
14919 		return TEST_SKIPPED;
14920 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14921 		return TEST_SKIPPED;
14922 	return 0;
14923 }
14924 
14925 static int
14926 scheduler_pkt_size_distr_testsuite_setup(void)
14927 {
14928 	if (test_scheduler_attach_worker_op() < 0)
14929 		return TEST_SKIPPED;
14930 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14931 		return TEST_SKIPPED;
14932 	return 0;
14933 }
14934 
14935 static void
14936 scheduler_mode_testsuite_teardown(void)
14937 {
14938 	test_scheduler_detach_worker_op();
14939 }
14940 
14941 #endif /* RTE_CRYPTO_SCHEDULER */
14942 
14943 static struct unit_test_suite end_testsuite = {
14944 	.suite_name = NULL,
14945 	.setup = NULL,
14946 	.teardown = NULL,
14947 	.unit_test_suites = NULL
14948 };
14949 
14950 #ifdef RTE_LIB_SECURITY
14951 static struct unit_test_suite ipsec_proto_testsuite  = {
14952 	.suite_name = "IPsec Proto Unit Test Suite",
14953 	.setup = ipsec_proto_testsuite_setup,
14954 	.unit_test_cases = {
14955 		TEST_CASE_NAMED_WITH_DATA(
14956 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14957 			ut_setup_security, ut_teardown,
14958 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14959 		TEST_CASE_NAMED_WITH_DATA(
14960 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14961 			ut_setup_security, ut_teardown,
14962 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14963 		TEST_CASE_NAMED_WITH_DATA(
14964 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14965 			ut_setup_security, ut_teardown,
14966 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14967 		TEST_CASE_NAMED_WITH_DATA(
14968 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
14969 			ut_setup_security, ut_teardown,
14970 			test_ipsec_proto_known_vec,
14971 			&pkt_aes_128_cbc_hmac_sha256),
14972 		TEST_CASE_NAMED_WITH_DATA(
14973 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
14974 			ut_setup_security, ut_teardown,
14975 			test_ipsec_proto_known_vec,
14976 			&pkt_aes_128_cbc_hmac_sha384),
14977 		TEST_CASE_NAMED_WITH_DATA(
14978 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
14979 			ut_setup_security, ut_teardown,
14980 			test_ipsec_proto_known_vec,
14981 			&pkt_aes_128_cbc_hmac_sha512),
14982 		TEST_CASE_NAMED_WITH_DATA(
14983 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
14984 			ut_setup_security, ut_teardown,
14985 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6),
14986 		TEST_CASE_NAMED_WITH_DATA(
14987 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
14988 			ut_setup_security, ut_teardown,
14989 			test_ipsec_proto_known_vec,
14990 			&pkt_aes_128_cbc_hmac_sha256_v6),
14991 		TEST_CASE_NAMED_WITH_DATA(
14992 			"Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
14993 			ut_setup_security, ut_teardown,
14994 			test_ipsec_proto_known_vec,
14995 			&pkt_null_aes_xcbc),
14996 		TEST_CASE_NAMED_WITH_DATA(
14997 			"Outbound fragmented packet",
14998 			ut_setup_security, ut_teardown,
14999 			test_ipsec_proto_known_vec_fragmented,
15000 			&pkt_aes_128_gcm_frag),
15001 		TEST_CASE_NAMED_WITH_DATA(
15002 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
15003 			ut_setup_security, ut_teardown,
15004 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
15005 		TEST_CASE_NAMED_WITH_DATA(
15006 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
15007 			ut_setup_security, ut_teardown,
15008 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
15009 		TEST_CASE_NAMED_WITH_DATA(
15010 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
15011 			ut_setup_security, ut_teardown,
15012 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
15013 		TEST_CASE_NAMED_WITH_DATA(
15014 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
15015 			ut_setup_security, ut_teardown,
15016 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null),
15017 		TEST_CASE_NAMED_WITH_DATA(
15018 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15019 			ut_setup_security, ut_teardown,
15020 			test_ipsec_proto_known_vec_inb,
15021 			&pkt_aes_128_cbc_hmac_sha256),
15022 		TEST_CASE_NAMED_WITH_DATA(
15023 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
15024 			ut_setup_security, ut_teardown,
15025 			test_ipsec_proto_known_vec_inb,
15026 			&pkt_aes_128_cbc_hmac_sha384),
15027 		TEST_CASE_NAMED_WITH_DATA(
15028 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
15029 			ut_setup_security, ut_teardown,
15030 			test_ipsec_proto_known_vec_inb,
15031 			&pkt_aes_128_cbc_hmac_sha512),
15032 		TEST_CASE_NAMED_WITH_DATA(
15033 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
15034 			ut_setup_security, ut_teardown,
15035 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
15036 		TEST_CASE_NAMED_WITH_DATA(
15037 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15038 			ut_setup_security, ut_teardown,
15039 			test_ipsec_proto_known_vec_inb,
15040 			&pkt_aes_128_cbc_hmac_sha256_v6),
15041 		TEST_CASE_NAMED_WITH_DATA(
15042 			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
15043 			ut_setup_security, ut_teardown,
15044 			test_ipsec_proto_known_vec_inb,
15045 			&pkt_null_aes_xcbc),
15046 		TEST_CASE_NAMED_ST(
15047 			"Combined test alg list",
15048 			ut_setup_security, ut_teardown,
15049 			test_ipsec_proto_display_list),
15050 		TEST_CASE_NAMED_ST(
15051 			"IV generation",
15052 			ut_setup_security, ut_teardown,
15053 			test_ipsec_proto_iv_gen),
15054 		TEST_CASE_NAMED_ST(
15055 			"UDP encapsulation",
15056 			ut_setup_security, ut_teardown,
15057 			test_ipsec_proto_udp_encap),
15058 		TEST_CASE_NAMED_ST(
15059 			"UDP encapsulation ports verification test",
15060 			ut_setup_security, ut_teardown,
15061 			test_ipsec_proto_udp_ports_verify),
15062 		TEST_CASE_NAMED_ST(
15063 			"SA expiry packets soft",
15064 			ut_setup_security, ut_teardown,
15065 			test_ipsec_proto_sa_exp_pkts_soft),
15066 		TEST_CASE_NAMED_ST(
15067 			"SA expiry packets hard",
15068 			ut_setup_security, ut_teardown,
15069 			test_ipsec_proto_sa_exp_pkts_hard),
15070 		TEST_CASE_NAMED_ST(
15071 			"Negative test: ICV corruption",
15072 			ut_setup_security, ut_teardown,
15073 			test_ipsec_proto_err_icv_corrupt),
15074 		TEST_CASE_NAMED_ST(
15075 			"Tunnel dst addr verification",
15076 			ut_setup_security, ut_teardown,
15077 			test_ipsec_proto_tunnel_dst_addr_verify),
15078 		TEST_CASE_NAMED_ST(
15079 			"Tunnel src and dst addr verification",
15080 			ut_setup_security, ut_teardown,
15081 			test_ipsec_proto_tunnel_src_dst_addr_verify),
15082 		TEST_CASE_NAMED_ST(
15083 			"Inner IP checksum",
15084 			ut_setup_security, ut_teardown,
15085 			test_ipsec_proto_inner_ip_csum),
15086 		TEST_CASE_NAMED_ST(
15087 			"Inner L4 checksum",
15088 			ut_setup_security, ut_teardown,
15089 			test_ipsec_proto_inner_l4_csum),
15090 		TEST_CASE_NAMED_ST(
15091 			"Tunnel IPv4 in IPv4",
15092 			ut_setup_security, ut_teardown,
15093 			test_ipsec_proto_tunnel_v4_in_v4),
15094 		TEST_CASE_NAMED_ST(
15095 			"Tunnel IPv6 in IPv6",
15096 			ut_setup_security, ut_teardown,
15097 			test_ipsec_proto_tunnel_v6_in_v6),
15098 		TEST_CASE_NAMED_ST(
15099 			"Tunnel IPv4 in IPv6",
15100 			ut_setup_security, ut_teardown,
15101 			test_ipsec_proto_tunnel_v4_in_v6),
15102 		TEST_CASE_NAMED_ST(
15103 			"Tunnel IPv6 in IPv4",
15104 			ut_setup_security, ut_teardown,
15105 			test_ipsec_proto_tunnel_v6_in_v4),
15106 		TEST_CASE_NAMED_ST(
15107 			"Transport IPv4",
15108 			ut_setup_security, ut_teardown,
15109 			test_ipsec_proto_transport_v4),
15110 		TEST_CASE_NAMED_ST(
15111 			"Transport l4 checksum",
15112 			ut_setup_security, ut_teardown,
15113 			test_ipsec_proto_transport_l4_csum),
15114 		TEST_CASE_NAMED_ST(
15115 			"Statistics: success",
15116 			ut_setup_security, ut_teardown,
15117 			test_ipsec_proto_stats),
15118 		TEST_CASE_NAMED_ST(
15119 			"Fragmented packet",
15120 			ut_setup_security, ut_teardown,
15121 			test_ipsec_proto_pkt_fragment),
15122 		TEST_CASE_NAMED_ST(
15123 			"Tunnel header copy DF (inner 0)",
15124 			ut_setup_security, ut_teardown,
15125 			test_ipsec_proto_copy_df_inner_0),
15126 		TEST_CASE_NAMED_ST(
15127 			"Tunnel header copy DF (inner 1)",
15128 			ut_setup_security, ut_teardown,
15129 			test_ipsec_proto_copy_df_inner_1),
15130 		TEST_CASE_NAMED_ST(
15131 			"Tunnel header set DF 0 (inner 1)",
15132 			ut_setup_security, ut_teardown,
15133 			test_ipsec_proto_set_df_0_inner_1),
15134 		TEST_CASE_NAMED_ST(
15135 			"Tunnel header set DF 1 (inner 0)",
15136 			ut_setup_security, ut_teardown,
15137 			test_ipsec_proto_set_df_1_inner_0),
15138 		TEST_CASE_NAMED_ST(
15139 			"Tunnel header IPv4 copy DSCP (inner 0)",
15140 			ut_setup_security, ut_teardown,
15141 			test_ipsec_proto_ipv4_copy_dscp_inner_0),
15142 		TEST_CASE_NAMED_ST(
15143 			"Tunnel header IPv4 copy DSCP (inner 1)",
15144 			ut_setup_security, ut_teardown,
15145 			test_ipsec_proto_ipv4_copy_dscp_inner_1),
15146 		TEST_CASE_NAMED_ST(
15147 			"Tunnel header IPv4 set DSCP 0 (inner 1)",
15148 			ut_setup_security, ut_teardown,
15149 			test_ipsec_proto_ipv4_set_dscp_0_inner_1),
15150 		TEST_CASE_NAMED_ST(
15151 			"Tunnel header IPv4 set DSCP 1 (inner 0)",
15152 			ut_setup_security, ut_teardown,
15153 			test_ipsec_proto_ipv4_set_dscp_1_inner_0),
15154 		TEST_CASE_NAMED_ST(
15155 			"Tunnel header IPv6 copy DSCP (inner 0)",
15156 			ut_setup_security, ut_teardown,
15157 			test_ipsec_proto_ipv6_copy_dscp_inner_0),
15158 		TEST_CASE_NAMED_ST(
15159 			"Tunnel header IPv6 copy DSCP (inner 1)",
15160 			ut_setup_security, ut_teardown,
15161 			test_ipsec_proto_ipv6_copy_dscp_inner_1),
15162 		TEST_CASE_NAMED_ST(
15163 			"Tunnel header IPv6 set DSCP 0 (inner 1)",
15164 			ut_setup_security, ut_teardown,
15165 			test_ipsec_proto_ipv6_set_dscp_0_inner_1),
15166 		TEST_CASE_NAMED_ST(
15167 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
15168 			ut_setup_security, ut_teardown,
15169 			test_ipsec_proto_ipv6_set_dscp_1_inner_0),
15170 		TEST_CASE_NAMED_WITH_DATA(
15171 			"Antireplay with window size 1024",
15172 			ut_setup_security, ut_teardown,
15173 			test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm),
15174 		TEST_CASE_NAMED_WITH_DATA(
15175 			"Antireplay with window size 2048",
15176 			ut_setup_security, ut_teardown,
15177 			test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm),
15178 		TEST_CASE_NAMED_WITH_DATA(
15179 			"Antireplay with window size 4096",
15180 			ut_setup_security, ut_teardown,
15181 			test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm),
15182 		TEST_CASE_NAMED_WITH_DATA(
15183 			"ESN and Antireplay with window size 1024",
15184 			ut_setup_security, ut_teardown,
15185 			test_ipsec_proto_pkt_esn_antireplay1024,
15186 			&pkt_aes_128_gcm),
15187 		TEST_CASE_NAMED_WITH_DATA(
15188 			"ESN and Antireplay with window size 2048",
15189 			ut_setup_security, ut_teardown,
15190 			test_ipsec_proto_pkt_esn_antireplay2048,
15191 			&pkt_aes_128_gcm),
15192 		TEST_CASE_NAMED_WITH_DATA(
15193 			"ESN and Antireplay with window size 4096",
15194 			ut_setup_security, ut_teardown,
15195 			test_ipsec_proto_pkt_esn_antireplay4096,
15196 			&pkt_aes_128_gcm),
15197 		TEST_CASE_NAMED_ST(
15198 			"Tunnel header IPv4 decrement inner TTL",
15199 			ut_setup_security, ut_teardown,
15200 			test_ipsec_proto_ipv4_ttl_decrement),
15201 		TEST_CASE_NAMED_ST(
15202 			"Tunnel header IPv6 decrement inner hop limit",
15203 			ut_setup_security, ut_teardown,
15204 			test_ipsec_proto_ipv6_hop_limit_decrement),
15205 		TEST_CASES_END() /**< NULL terminate unit test array */
15206 	}
15207 };
15208 
15209 static struct unit_test_suite pdcp_proto_testsuite  = {
15210 	.suite_name = "PDCP Proto Unit Test Suite",
15211 	.setup = pdcp_proto_testsuite_setup,
15212 	.unit_test_cases = {
15213 		TEST_CASE_ST(ut_setup_security, ut_teardown,
15214 			test_PDCP_PROTO_all),
15215 		TEST_CASES_END() /**< NULL terminate unit test array */
15216 	}
15217 };
15218 
15219 #define ADD_UPLINK_TESTCASE(data)						\
15220 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security,	\
15221 	ut_teardown, test_docsis_proto_uplink, (const void *) &data),		\
15222 
15223 #define ADD_DOWNLINK_TESTCASE(data)						\
15224 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security,	\
15225 	ut_teardown, test_docsis_proto_downlink, (const void *) &data),		\
15226 
15227 static struct unit_test_suite docsis_proto_testsuite  = {
15228 	.suite_name = "DOCSIS Proto Unit Test Suite",
15229 	.setup = docsis_proto_testsuite_setup,
15230 	.unit_test_cases = {
15231 		/* Uplink */
15232 		ADD_UPLINK_TESTCASE(docsis_test_case_1)
15233 		ADD_UPLINK_TESTCASE(docsis_test_case_2)
15234 		ADD_UPLINK_TESTCASE(docsis_test_case_3)
15235 		ADD_UPLINK_TESTCASE(docsis_test_case_4)
15236 		ADD_UPLINK_TESTCASE(docsis_test_case_5)
15237 		ADD_UPLINK_TESTCASE(docsis_test_case_6)
15238 		ADD_UPLINK_TESTCASE(docsis_test_case_7)
15239 		ADD_UPLINK_TESTCASE(docsis_test_case_8)
15240 		ADD_UPLINK_TESTCASE(docsis_test_case_9)
15241 		ADD_UPLINK_TESTCASE(docsis_test_case_10)
15242 		ADD_UPLINK_TESTCASE(docsis_test_case_11)
15243 		ADD_UPLINK_TESTCASE(docsis_test_case_12)
15244 		ADD_UPLINK_TESTCASE(docsis_test_case_13)
15245 		ADD_UPLINK_TESTCASE(docsis_test_case_14)
15246 		ADD_UPLINK_TESTCASE(docsis_test_case_15)
15247 		ADD_UPLINK_TESTCASE(docsis_test_case_16)
15248 		ADD_UPLINK_TESTCASE(docsis_test_case_17)
15249 		ADD_UPLINK_TESTCASE(docsis_test_case_18)
15250 		ADD_UPLINK_TESTCASE(docsis_test_case_19)
15251 		ADD_UPLINK_TESTCASE(docsis_test_case_20)
15252 		ADD_UPLINK_TESTCASE(docsis_test_case_21)
15253 		ADD_UPLINK_TESTCASE(docsis_test_case_22)
15254 		ADD_UPLINK_TESTCASE(docsis_test_case_23)
15255 		ADD_UPLINK_TESTCASE(docsis_test_case_24)
15256 		ADD_UPLINK_TESTCASE(docsis_test_case_25)
15257 		ADD_UPLINK_TESTCASE(docsis_test_case_26)
15258 		/* Downlink */
15259 		ADD_DOWNLINK_TESTCASE(docsis_test_case_1)
15260 		ADD_DOWNLINK_TESTCASE(docsis_test_case_2)
15261 		ADD_DOWNLINK_TESTCASE(docsis_test_case_3)
15262 		ADD_DOWNLINK_TESTCASE(docsis_test_case_4)
15263 		ADD_DOWNLINK_TESTCASE(docsis_test_case_5)
15264 		ADD_DOWNLINK_TESTCASE(docsis_test_case_6)
15265 		ADD_DOWNLINK_TESTCASE(docsis_test_case_7)
15266 		ADD_DOWNLINK_TESTCASE(docsis_test_case_8)
15267 		ADD_DOWNLINK_TESTCASE(docsis_test_case_9)
15268 		ADD_DOWNLINK_TESTCASE(docsis_test_case_10)
15269 		ADD_DOWNLINK_TESTCASE(docsis_test_case_11)
15270 		ADD_DOWNLINK_TESTCASE(docsis_test_case_12)
15271 		ADD_DOWNLINK_TESTCASE(docsis_test_case_13)
15272 		ADD_DOWNLINK_TESTCASE(docsis_test_case_14)
15273 		ADD_DOWNLINK_TESTCASE(docsis_test_case_15)
15274 		ADD_DOWNLINK_TESTCASE(docsis_test_case_16)
15275 		ADD_DOWNLINK_TESTCASE(docsis_test_case_17)
15276 		ADD_DOWNLINK_TESTCASE(docsis_test_case_18)
15277 		ADD_DOWNLINK_TESTCASE(docsis_test_case_19)
15278 		ADD_DOWNLINK_TESTCASE(docsis_test_case_20)
15279 		ADD_DOWNLINK_TESTCASE(docsis_test_case_21)
15280 		ADD_DOWNLINK_TESTCASE(docsis_test_case_22)
15281 		ADD_DOWNLINK_TESTCASE(docsis_test_case_23)
15282 		ADD_DOWNLINK_TESTCASE(docsis_test_case_24)
15283 		ADD_DOWNLINK_TESTCASE(docsis_test_case_25)
15284 		ADD_DOWNLINK_TESTCASE(docsis_test_case_26)
15285 		TEST_CASES_END() /**< NULL terminate unit test array */
15286 	}
15287 };
15288 #endif
15289 
15290 static struct unit_test_suite cryptodev_gen_testsuite  = {
15291 	.suite_name = "Crypto General Unit Test Suite",
15292 	.setup = crypto_gen_testsuite_setup,
15293 	.unit_test_cases = {
15294 		TEST_CASE_ST(ut_setup, ut_teardown,
15295 				test_device_configure_invalid_dev_id),
15296 		TEST_CASE_ST(ut_setup, ut_teardown,
15297 				test_queue_pair_descriptor_setup),
15298 		TEST_CASE_ST(ut_setup, ut_teardown,
15299 				test_device_configure_invalid_queue_pair_ids),
15300 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
15301 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
15302 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
15303 		TEST_CASES_END() /**< NULL terminate unit test array */
15304 	}
15305 };
15306 
15307 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
15308 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
15309 	.setup = negative_hmac_sha1_testsuite_setup,
15310 	.unit_test_cases = {
15311 		/** Negative tests */
15312 		TEST_CASE_ST(ut_setup, ut_teardown,
15313 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
15314 		TEST_CASE_ST(ut_setup, ut_teardown,
15315 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
15316 		TEST_CASE_ST(ut_setup, ut_teardown,
15317 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
15318 		TEST_CASE_ST(ut_setup, ut_teardown,
15319 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
15320 
15321 		TEST_CASES_END() /**< NULL terminate unit test array */
15322 	}
15323 };
15324 
15325 static struct unit_test_suite cryptodev_multi_session_testsuite = {
15326 	.suite_name = "Multi Session Unit Test Suite",
15327 	.setup = multi_session_testsuite_setup,
15328 	.unit_test_cases = {
15329 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
15330 		TEST_CASE_ST(ut_setup, ut_teardown,
15331 				test_multi_session_random_usage),
15332 
15333 		TEST_CASES_END() /**< NULL terminate unit test array */
15334 	}
15335 };
15336 
15337 static struct unit_test_suite cryptodev_null_testsuite  = {
15338 	.suite_name = "NULL Test Suite",
15339 	.setup = null_testsuite_setup,
15340 	.unit_test_cases = {
15341 		TEST_CASE_ST(ut_setup, ut_teardown,
15342 			test_null_invalid_operation),
15343 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
15344 		TEST_CASES_END()
15345 	}
15346 };
15347 
15348 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
15349 	.suite_name = "AES CCM Authenticated Test Suite",
15350 	.setup = aes_ccm_auth_testsuite_setup,
15351 	.unit_test_cases = {
15352 		/** AES CCM Authenticated Encryption 128 bits key*/
15353 		TEST_CASE_ST(ut_setup, ut_teardown,
15354 			test_AES_CCM_authenticated_encryption_test_case_128_1),
15355 		TEST_CASE_ST(ut_setup, ut_teardown,
15356 			test_AES_CCM_authenticated_encryption_test_case_128_2),
15357 		TEST_CASE_ST(ut_setup, ut_teardown,
15358 			test_AES_CCM_authenticated_encryption_test_case_128_3),
15359 
15360 		/** AES CCM Authenticated Decryption 128 bits key*/
15361 		TEST_CASE_ST(ut_setup, ut_teardown,
15362 			test_AES_CCM_authenticated_decryption_test_case_128_1),
15363 		TEST_CASE_ST(ut_setup, ut_teardown,
15364 			test_AES_CCM_authenticated_decryption_test_case_128_2),
15365 		TEST_CASE_ST(ut_setup, ut_teardown,
15366 			test_AES_CCM_authenticated_decryption_test_case_128_3),
15367 
15368 		/** AES CCM Authenticated Encryption 192 bits key */
15369 		TEST_CASE_ST(ut_setup, ut_teardown,
15370 			test_AES_CCM_authenticated_encryption_test_case_192_1),
15371 		TEST_CASE_ST(ut_setup, ut_teardown,
15372 			test_AES_CCM_authenticated_encryption_test_case_192_2),
15373 		TEST_CASE_ST(ut_setup, ut_teardown,
15374 			test_AES_CCM_authenticated_encryption_test_case_192_3),
15375 
15376 		/** AES CCM Authenticated Decryption 192 bits key*/
15377 		TEST_CASE_ST(ut_setup, ut_teardown,
15378 			test_AES_CCM_authenticated_decryption_test_case_192_1),
15379 		TEST_CASE_ST(ut_setup, ut_teardown,
15380 			test_AES_CCM_authenticated_decryption_test_case_192_2),
15381 		TEST_CASE_ST(ut_setup, ut_teardown,
15382 			test_AES_CCM_authenticated_decryption_test_case_192_3),
15383 
15384 		/** AES CCM Authenticated Encryption 256 bits key */
15385 		TEST_CASE_ST(ut_setup, ut_teardown,
15386 			test_AES_CCM_authenticated_encryption_test_case_256_1),
15387 		TEST_CASE_ST(ut_setup, ut_teardown,
15388 			test_AES_CCM_authenticated_encryption_test_case_256_2),
15389 		TEST_CASE_ST(ut_setup, ut_teardown,
15390 			test_AES_CCM_authenticated_encryption_test_case_256_3),
15391 
15392 		/** AES CCM Authenticated Decryption 256 bits key*/
15393 		TEST_CASE_ST(ut_setup, ut_teardown,
15394 			test_AES_CCM_authenticated_decryption_test_case_256_1),
15395 		TEST_CASE_ST(ut_setup, ut_teardown,
15396 			test_AES_CCM_authenticated_decryption_test_case_256_2),
15397 		TEST_CASE_ST(ut_setup, ut_teardown,
15398 			test_AES_CCM_authenticated_decryption_test_case_256_3),
15399 		TEST_CASES_END()
15400 	}
15401 };
15402 
15403 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
15404 	.suite_name = "AES GCM Authenticated Test Suite",
15405 	.setup = aes_gcm_auth_testsuite_setup,
15406 	.unit_test_cases = {
15407 		/** AES GCM Authenticated Encryption */
15408 		TEST_CASE_ST(ut_setup, ut_teardown,
15409 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
15410 		TEST_CASE_ST(ut_setup, ut_teardown,
15411 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
15412 		TEST_CASE_ST(ut_setup, ut_teardown,
15413 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
15414 		TEST_CASE_ST(ut_setup, ut_teardown,
15415 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
15416 		TEST_CASE_ST(ut_setup, ut_teardown,
15417 			test_AES_GCM_authenticated_encryption_test_case_1),
15418 		TEST_CASE_ST(ut_setup, ut_teardown,
15419 			test_AES_GCM_authenticated_encryption_test_case_2),
15420 		TEST_CASE_ST(ut_setup, ut_teardown,
15421 			test_AES_GCM_authenticated_encryption_test_case_3),
15422 		TEST_CASE_ST(ut_setup, ut_teardown,
15423 			test_AES_GCM_authenticated_encryption_test_case_4),
15424 		TEST_CASE_ST(ut_setup, ut_teardown,
15425 			test_AES_GCM_authenticated_encryption_test_case_5),
15426 		TEST_CASE_ST(ut_setup, ut_teardown,
15427 			test_AES_GCM_authenticated_encryption_test_case_6),
15428 		TEST_CASE_ST(ut_setup, ut_teardown,
15429 			test_AES_GCM_authenticated_encryption_test_case_7),
15430 		TEST_CASE_ST(ut_setup, ut_teardown,
15431 			test_AES_GCM_authenticated_encryption_test_case_8),
15432 		TEST_CASE_ST(ut_setup, ut_teardown,
15433 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
15434 
15435 		/** AES GCM Authenticated Decryption */
15436 		TEST_CASE_ST(ut_setup, ut_teardown,
15437 			test_AES_GCM_authenticated_decryption_test_case_1),
15438 		TEST_CASE_ST(ut_setup, ut_teardown,
15439 			test_AES_GCM_authenticated_decryption_test_case_2),
15440 		TEST_CASE_ST(ut_setup, ut_teardown,
15441 			test_AES_GCM_authenticated_decryption_test_case_3),
15442 		TEST_CASE_ST(ut_setup, ut_teardown,
15443 			test_AES_GCM_authenticated_decryption_test_case_4),
15444 		TEST_CASE_ST(ut_setup, ut_teardown,
15445 			test_AES_GCM_authenticated_decryption_test_case_5),
15446 		TEST_CASE_ST(ut_setup, ut_teardown,
15447 			test_AES_GCM_authenticated_decryption_test_case_6),
15448 		TEST_CASE_ST(ut_setup, ut_teardown,
15449 			test_AES_GCM_authenticated_decryption_test_case_7),
15450 		TEST_CASE_ST(ut_setup, ut_teardown,
15451 			test_AES_GCM_authenticated_decryption_test_case_8),
15452 		TEST_CASE_ST(ut_setup, ut_teardown,
15453 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
15454 
15455 		/** AES GCM Authenticated Encryption 192 bits key */
15456 		TEST_CASE_ST(ut_setup, ut_teardown,
15457 			test_AES_GCM_auth_encryption_test_case_192_1),
15458 		TEST_CASE_ST(ut_setup, ut_teardown,
15459 			test_AES_GCM_auth_encryption_test_case_192_2),
15460 		TEST_CASE_ST(ut_setup, ut_teardown,
15461 			test_AES_GCM_auth_encryption_test_case_192_3),
15462 		TEST_CASE_ST(ut_setup, ut_teardown,
15463 			test_AES_GCM_auth_encryption_test_case_192_4),
15464 		TEST_CASE_ST(ut_setup, ut_teardown,
15465 			test_AES_GCM_auth_encryption_test_case_192_5),
15466 		TEST_CASE_ST(ut_setup, ut_teardown,
15467 			test_AES_GCM_auth_encryption_test_case_192_6),
15468 		TEST_CASE_ST(ut_setup, ut_teardown,
15469 			test_AES_GCM_auth_encryption_test_case_192_7),
15470 
15471 		/** AES GCM Authenticated Decryption 192 bits key */
15472 		TEST_CASE_ST(ut_setup, ut_teardown,
15473 			test_AES_GCM_auth_decryption_test_case_192_1),
15474 		TEST_CASE_ST(ut_setup, ut_teardown,
15475 			test_AES_GCM_auth_decryption_test_case_192_2),
15476 		TEST_CASE_ST(ut_setup, ut_teardown,
15477 			test_AES_GCM_auth_decryption_test_case_192_3),
15478 		TEST_CASE_ST(ut_setup, ut_teardown,
15479 			test_AES_GCM_auth_decryption_test_case_192_4),
15480 		TEST_CASE_ST(ut_setup, ut_teardown,
15481 			test_AES_GCM_auth_decryption_test_case_192_5),
15482 		TEST_CASE_ST(ut_setup, ut_teardown,
15483 			test_AES_GCM_auth_decryption_test_case_192_6),
15484 		TEST_CASE_ST(ut_setup, ut_teardown,
15485 			test_AES_GCM_auth_decryption_test_case_192_7),
15486 
15487 		/** AES GCM Authenticated Encryption 256 bits key */
15488 		TEST_CASE_ST(ut_setup, ut_teardown,
15489 			test_AES_GCM_auth_encryption_test_case_256_1),
15490 		TEST_CASE_ST(ut_setup, ut_teardown,
15491 			test_AES_GCM_auth_encryption_test_case_256_2),
15492 		TEST_CASE_ST(ut_setup, ut_teardown,
15493 			test_AES_GCM_auth_encryption_test_case_256_3),
15494 		TEST_CASE_ST(ut_setup, ut_teardown,
15495 			test_AES_GCM_auth_encryption_test_case_256_4),
15496 		TEST_CASE_ST(ut_setup, ut_teardown,
15497 			test_AES_GCM_auth_encryption_test_case_256_5),
15498 		TEST_CASE_ST(ut_setup, ut_teardown,
15499 			test_AES_GCM_auth_encryption_test_case_256_6),
15500 		TEST_CASE_ST(ut_setup, ut_teardown,
15501 			test_AES_GCM_auth_encryption_test_case_256_7),
15502 
15503 		/** AES GCM Authenticated Decryption 256 bits key */
15504 		TEST_CASE_ST(ut_setup, ut_teardown,
15505 			test_AES_GCM_auth_decryption_test_case_256_1),
15506 		TEST_CASE_ST(ut_setup, ut_teardown,
15507 			test_AES_GCM_auth_decryption_test_case_256_2),
15508 		TEST_CASE_ST(ut_setup, ut_teardown,
15509 			test_AES_GCM_auth_decryption_test_case_256_3),
15510 		TEST_CASE_ST(ut_setup, ut_teardown,
15511 			test_AES_GCM_auth_decryption_test_case_256_4),
15512 		TEST_CASE_ST(ut_setup, ut_teardown,
15513 			test_AES_GCM_auth_decryption_test_case_256_5),
15514 		TEST_CASE_ST(ut_setup, ut_teardown,
15515 			test_AES_GCM_auth_decryption_test_case_256_6),
15516 		TEST_CASE_ST(ut_setup, ut_teardown,
15517 			test_AES_GCM_auth_decryption_test_case_256_7),
15518 
15519 		/** AES GCM Authenticated Encryption big aad size */
15520 		TEST_CASE_ST(ut_setup, ut_teardown,
15521 			test_AES_GCM_auth_encryption_test_case_aad_1),
15522 		TEST_CASE_ST(ut_setup, ut_teardown,
15523 			test_AES_GCM_auth_encryption_test_case_aad_2),
15524 
15525 		/** AES GCM Authenticated Decryption big aad size */
15526 		TEST_CASE_ST(ut_setup, ut_teardown,
15527 			test_AES_GCM_auth_decryption_test_case_aad_1),
15528 		TEST_CASE_ST(ut_setup, ut_teardown,
15529 			test_AES_GCM_auth_decryption_test_case_aad_2),
15530 
15531 		/** Out of place tests */
15532 		TEST_CASE_ST(ut_setup, ut_teardown,
15533 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
15534 		TEST_CASE_ST(ut_setup, ut_teardown,
15535 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
15536 
15537 		/** Session-less tests */
15538 		TEST_CASE_ST(ut_setup, ut_teardown,
15539 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
15540 		TEST_CASE_ST(ut_setup, ut_teardown,
15541 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
15542 
15543 		TEST_CASES_END()
15544 	}
15545 };
15546 
15547 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
15548 	.suite_name = "AES GMAC Authentication Test Suite",
15549 	.setup = aes_gmac_auth_testsuite_setup,
15550 	.unit_test_cases = {
15551 		TEST_CASE_ST(ut_setup, ut_teardown,
15552 			test_AES_GMAC_authentication_test_case_1),
15553 		TEST_CASE_ST(ut_setup, ut_teardown,
15554 			test_AES_GMAC_authentication_verify_test_case_1),
15555 		TEST_CASE_ST(ut_setup, ut_teardown,
15556 			test_AES_GMAC_authentication_test_case_2),
15557 		TEST_CASE_ST(ut_setup, ut_teardown,
15558 			test_AES_GMAC_authentication_verify_test_case_2),
15559 		TEST_CASE_ST(ut_setup, ut_teardown,
15560 			test_AES_GMAC_authentication_test_case_3),
15561 		TEST_CASE_ST(ut_setup, ut_teardown,
15562 			test_AES_GMAC_authentication_verify_test_case_3),
15563 		TEST_CASE_ST(ut_setup, ut_teardown,
15564 			test_AES_GMAC_authentication_test_case_4),
15565 		TEST_CASE_ST(ut_setup, ut_teardown,
15566 			test_AES_GMAC_authentication_verify_test_case_4),
15567 		TEST_CASE_ST(ut_setup, ut_teardown,
15568 			test_AES_GMAC_authentication_SGL_40B),
15569 		TEST_CASE_ST(ut_setup, ut_teardown,
15570 			test_AES_GMAC_authentication_SGL_80B),
15571 		TEST_CASE_ST(ut_setup, ut_teardown,
15572 			test_AES_GMAC_authentication_SGL_2048B),
15573 		TEST_CASE_ST(ut_setup, ut_teardown,
15574 			test_AES_GMAC_authentication_SGL_2047B),
15575 
15576 		TEST_CASES_END()
15577 	}
15578 };
15579 
15580 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
15581 	.suite_name = "Chacha20-Poly1305 Test Suite",
15582 	.setup = chacha20_poly1305_testsuite_setup,
15583 	.unit_test_cases = {
15584 		TEST_CASE_ST(ut_setup, ut_teardown,
15585 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
15586 		TEST_CASE_ST(ut_setup, ut_teardown,
15587 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
15588 		TEST_CASE_ST(ut_setup, ut_teardown,
15589 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
15590 		TEST_CASES_END()
15591 	}
15592 };
15593 
15594 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
15595 	.suite_name = "SNOW 3G Test Suite",
15596 	.setup = snow3g_testsuite_setup,
15597 	.unit_test_cases = {
15598 		/** SNOW 3G encrypt only (UEA2) */
15599 		TEST_CASE_ST(ut_setup, ut_teardown,
15600 			test_snow3g_encryption_test_case_1),
15601 		TEST_CASE_ST(ut_setup, ut_teardown,
15602 			test_snow3g_encryption_test_case_2),
15603 		TEST_CASE_ST(ut_setup, ut_teardown,
15604 			test_snow3g_encryption_test_case_3),
15605 		TEST_CASE_ST(ut_setup, ut_teardown,
15606 			test_snow3g_encryption_test_case_4),
15607 		TEST_CASE_ST(ut_setup, ut_teardown,
15608 			test_snow3g_encryption_test_case_5),
15609 
15610 		TEST_CASE_ST(ut_setup, ut_teardown,
15611 			test_snow3g_encryption_test_case_1_oop),
15612 		TEST_CASE_ST(ut_setup, ut_teardown,
15613 			test_snow3g_encryption_test_case_1_oop_sgl),
15614 		TEST_CASE_ST(ut_setup, ut_teardown,
15615 			test_snow3g_encryption_test_case_1_offset_oop),
15616 		TEST_CASE_ST(ut_setup, ut_teardown,
15617 			test_snow3g_decryption_test_case_1_oop),
15618 
15619 		/** SNOW 3G generate auth, then encrypt (UEA2) */
15620 		TEST_CASE_ST(ut_setup, ut_teardown,
15621 			test_snow3g_auth_cipher_test_case_1),
15622 		TEST_CASE_ST(ut_setup, ut_teardown,
15623 			test_snow3g_auth_cipher_test_case_2),
15624 		TEST_CASE_ST(ut_setup, ut_teardown,
15625 			test_snow3g_auth_cipher_test_case_2_oop),
15626 		TEST_CASE_ST(ut_setup, ut_teardown,
15627 			test_snow3g_auth_cipher_part_digest_enc),
15628 		TEST_CASE_ST(ut_setup, ut_teardown,
15629 			test_snow3g_auth_cipher_part_digest_enc_oop),
15630 		TEST_CASE_ST(ut_setup, ut_teardown,
15631 			test_snow3g_auth_cipher_test_case_3_sgl),
15632 		TEST_CASE_ST(ut_setup, ut_teardown,
15633 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
15634 		TEST_CASE_ST(ut_setup, ut_teardown,
15635 			test_snow3g_auth_cipher_part_digest_enc_sgl),
15636 		TEST_CASE_ST(ut_setup, ut_teardown,
15637 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
15638 
15639 		/** SNOW 3G decrypt (UEA2), then verify auth */
15640 		TEST_CASE_ST(ut_setup, ut_teardown,
15641 			test_snow3g_auth_cipher_verify_test_case_1),
15642 		TEST_CASE_ST(ut_setup, ut_teardown,
15643 			test_snow3g_auth_cipher_verify_test_case_2),
15644 		TEST_CASE_ST(ut_setup, ut_teardown,
15645 			test_snow3g_auth_cipher_verify_test_case_2_oop),
15646 		TEST_CASE_ST(ut_setup, ut_teardown,
15647 			test_snow3g_auth_cipher_verify_part_digest_enc),
15648 		TEST_CASE_ST(ut_setup, ut_teardown,
15649 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
15650 		TEST_CASE_ST(ut_setup, ut_teardown,
15651 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
15652 		TEST_CASE_ST(ut_setup, ut_teardown,
15653 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
15654 		TEST_CASE_ST(ut_setup, ut_teardown,
15655 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
15656 		TEST_CASE_ST(ut_setup, ut_teardown,
15657 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
15658 
15659 		/** SNOW 3G decrypt only (UEA2) */
15660 		TEST_CASE_ST(ut_setup, ut_teardown,
15661 			test_snow3g_decryption_test_case_1),
15662 		TEST_CASE_ST(ut_setup, ut_teardown,
15663 			test_snow3g_decryption_test_case_2),
15664 		TEST_CASE_ST(ut_setup, ut_teardown,
15665 			test_snow3g_decryption_test_case_3),
15666 		TEST_CASE_ST(ut_setup, ut_teardown,
15667 			test_snow3g_decryption_test_case_4),
15668 		TEST_CASE_ST(ut_setup, ut_teardown,
15669 			test_snow3g_decryption_test_case_5),
15670 		TEST_CASE_ST(ut_setup, ut_teardown,
15671 			test_snow3g_decryption_with_digest_test_case_1),
15672 		TEST_CASE_ST(ut_setup, ut_teardown,
15673 			test_snow3g_hash_generate_test_case_1),
15674 		TEST_CASE_ST(ut_setup, ut_teardown,
15675 			test_snow3g_hash_generate_test_case_2),
15676 		TEST_CASE_ST(ut_setup, ut_teardown,
15677 			test_snow3g_hash_generate_test_case_3),
15678 
15679 		/* Tests with buffers which length is not byte-aligned */
15680 		TEST_CASE_ST(ut_setup, ut_teardown,
15681 			test_snow3g_hash_generate_test_case_4),
15682 		TEST_CASE_ST(ut_setup, ut_teardown,
15683 			test_snow3g_hash_generate_test_case_5),
15684 		TEST_CASE_ST(ut_setup, ut_teardown,
15685 			test_snow3g_hash_generate_test_case_6),
15686 		TEST_CASE_ST(ut_setup, ut_teardown,
15687 			test_snow3g_hash_verify_test_case_1),
15688 		TEST_CASE_ST(ut_setup, ut_teardown,
15689 			test_snow3g_hash_verify_test_case_2),
15690 		TEST_CASE_ST(ut_setup, ut_teardown,
15691 			test_snow3g_hash_verify_test_case_3),
15692 
15693 		/* Tests with buffers which length is not byte-aligned */
15694 		TEST_CASE_ST(ut_setup, ut_teardown,
15695 			test_snow3g_hash_verify_test_case_4),
15696 		TEST_CASE_ST(ut_setup, ut_teardown,
15697 			test_snow3g_hash_verify_test_case_5),
15698 		TEST_CASE_ST(ut_setup, ut_teardown,
15699 			test_snow3g_hash_verify_test_case_6),
15700 		TEST_CASE_ST(ut_setup, ut_teardown,
15701 			test_snow3g_cipher_auth_test_case_1),
15702 		TEST_CASE_ST(ut_setup, ut_teardown,
15703 			test_snow3g_auth_cipher_with_digest_test_case_1),
15704 		TEST_CASES_END()
15705 	}
15706 };
15707 
15708 static struct unit_test_suite cryptodev_zuc_testsuite  = {
15709 	.suite_name = "ZUC Test Suite",
15710 	.setup = zuc_testsuite_setup,
15711 	.unit_test_cases = {
15712 		/** ZUC encrypt only (EEA3) */
15713 		TEST_CASE_ST(ut_setup, ut_teardown,
15714 			test_zuc_encryption_test_case_1),
15715 		TEST_CASE_ST(ut_setup, ut_teardown,
15716 			test_zuc_encryption_test_case_2),
15717 		TEST_CASE_ST(ut_setup, ut_teardown,
15718 			test_zuc_encryption_test_case_3),
15719 		TEST_CASE_ST(ut_setup, ut_teardown,
15720 			test_zuc_encryption_test_case_4),
15721 		TEST_CASE_ST(ut_setup, ut_teardown,
15722 			test_zuc_encryption_test_case_5),
15723 		TEST_CASE_ST(ut_setup, ut_teardown,
15724 			test_zuc_encryption_test_case_6_sgl),
15725 
15726 		/** ZUC authenticate (EIA3) */
15727 		TEST_CASE_ST(ut_setup, ut_teardown,
15728 			test_zuc_hash_generate_test_case_1),
15729 		TEST_CASE_ST(ut_setup, ut_teardown,
15730 			test_zuc_hash_generate_test_case_2),
15731 		TEST_CASE_ST(ut_setup, ut_teardown,
15732 			test_zuc_hash_generate_test_case_3),
15733 		TEST_CASE_ST(ut_setup, ut_teardown,
15734 			test_zuc_hash_generate_test_case_4),
15735 		TEST_CASE_ST(ut_setup, ut_teardown,
15736 			test_zuc_hash_generate_test_case_5),
15737 		TEST_CASE_ST(ut_setup, ut_teardown,
15738 			test_zuc_hash_generate_test_case_6),
15739 		TEST_CASE_ST(ut_setup, ut_teardown,
15740 			test_zuc_hash_generate_test_case_7),
15741 		TEST_CASE_ST(ut_setup, ut_teardown,
15742 			test_zuc_hash_generate_test_case_8),
15743 		TEST_CASE_ST(ut_setup, ut_teardown,
15744 			test_zuc_hash_generate_test_case_9),
15745 		TEST_CASE_ST(ut_setup, ut_teardown,
15746 			test_zuc_hash_generate_test_case_10),
15747 		TEST_CASE_ST(ut_setup, ut_teardown,
15748 			test_zuc_hash_generate_test_case_11),
15749 
15750 
15751 		/** ZUC alg-chain (EEA3/EIA3) */
15752 		TEST_CASE_ST(ut_setup, ut_teardown,
15753 			test_zuc_cipher_auth_test_case_1),
15754 		TEST_CASE_ST(ut_setup, ut_teardown,
15755 			test_zuc_cipher_auth_test_case_2),
15756 
15757 		/** ZUC generate auth, then encrypt (EEA3) */
15758 		TEST_CASE_ST(ut_setup, ut_teardown,
15759 			test_zuc_auth_cipher_test_case_1),
15760 		TEST_CASE_ST(ut_setup, ut_teardown,
15761 			test_zuc_auth_cipher_test_case_1_oop),
15762 		TEST_CASE_ST(ut_setup, ut_teardown,
15763 			test_zuc_auth_cipher_test_case_1_sgl),
15764 		TEST_CASE_ST(ut_setup, ut_teardown,
15765 			test_zuc_auth_cipher_test_case_1_oop_sgl),
15766 
15767 		/** ZUC decrypt (EEA3), then verify auth */
15768 		TEST_CASE_ST(ut_setup, ut_teardown,
15769 			test_zuc_auth_cipher_verify_test_case_1),
15770 		TEST_CASE_ST(ut_setup, ut_teardown,
15771 			test_zuc_auth_cipher_verify_test_case_1_oop),
15772 		TEST_CASE_ST(ut_setup, ut_teardown,
15773 			test_zuc_auth_cipher_verify_test_case_1_sgl),
15774 		TEST_CASE_ST(ut_setup, ut_teardown,
15775 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
15776 
15777 		/** ZUC-256 encrypt only **/
15778 		TEST_CASE_ST(ut_setup, ut_teardown,
15779 			test_zuc256_encryption_test_case_1),
15780 		TEST_CASE_ST(ut_setup, ut_teardown,
15781 			test_zuc256_encryption_test_case_2),
15782 
15783 		/** ZUC-256 authentication only **/
15784 		TEST_CASE_ST(ut_setup, ut_teardown,
15785 			test_zuc256_authentication_test_case_1),
15786 		TEST_CASE_ST(ut_setup, ut_teardown,
15787 			test_zuc256_authentication_test_case_2),
15788 
15789 		TEST_CASES_END()
15790 	}
15791 };
15792 
15793 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
15794 	.suite_name = "HMAC_MD5 Authentication Test Suite",
15795 	.setup = hmac_md5_auth_testsuite_setup,
15796 	.unit_test_cases = {
15797 		TEST_CASE_ST(ut_setup, ut_teardown,
15798 			test_MD5_HMAC_generate_case_1),
15799 		TEST_CASE_ST(ut_setup, ut_teardown,
15800 			test_MD5_HMAC_verify_case_1),
15801 		TEST_CASE_ST(ut_setup, ut_teardown,
15802 			test_MD5_HMAC_generate_case_2),
15803 		TEST_CASE_ST(ut_setup, ut_teardown,
15804 			test_MD5_HMAC_verify_case_2),
15805 		TEST_CASES_END()
15806 	}
15807 };
15808 
15809 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
15810 	.suite_name = "Kasumi Test Suite",
15811 	.setup = kasumi_testsuite_setup,
15812 	.unit_test_cases = {
15813 		/** KASUMI hash only (UIA1) */
15814 		TEST_CASE_ST(ut_setup, ut_teardown,
15815 			test_kasumi_hash_generate_test_case_1),
15816 		TEST_CASE_ST(ut_setup, ut_teardown,
15817 			test_kasumi_hash_generate_test_case_2),
15818 		TEST_CASE_ST(ut_setup, ut_teardown,
15819 			test_kasumi_hash_generate_test_case_3),
15820 		TEST_CASE_ST(ut_setup, ut_teardown,
15821 			test_kasumi_hash_generate_test_case_4),
15822 		TEST_CASE_ST(ut_setup, ut_teardown,
15823 			test_kasumi_hash_generate_test_case_5),
15824 		TEST_CASE_ST(ut_setup, ut_teardown,
15825 			test_kasumi_hash_generate_test_case_6),
15826 
15827 		TEST_CASE_ST(ut_setup, ut_teardown,
15828 			test_kasumi_hash_verify_test_case_1),
15829 		TEST_CASE_ST(ut_setup, ut_teardown,
15830 			test_kasumi_hash_verify_test_case_2),
15831 		TEST_CASE_ST(ut_setup, ut_teardown,
15832 			test_kasumi_hash_verify_test_case_3),
15833 		TEST_CASE_ST(ut_setup, ut_teardown,
15834 			test_kasumi_hash_verify_test_case_4),
15835 		TEST_CASE_ST(ut_setup, ut_teardown,
15836 			test_kasumi_hash_verify_test_case_5),
15837 
15838 		/** KASUMI encrypt only (UEA1) */
15839 		TEST_CASE_ST(ut_setup, ut_teardown,
15840 			test_kasumi_encryption_test_case_1),
15841 		TEST_CASE_ST(ut_setup, ut_teardown,
15842 			test_kasumi_encryption_test_case_1_sgl),
15843 		TEST_CASE_ST(ut_setup, ut_teardown,
15844 			test_kasumi_encryption_test_case_1_oop),
15845 		TEST_CASE_ST(ut_setup, ut_teardown,
15846 			test_kasumi_encryption_test_case_1_oop_sgl),
15847 		TEST_CASE_ST(ut_setup, ut_teardown,
15848 			test_kasumi_encryption_test_case_2),
15849 		TEST_CASE_ST(ut_setup, ut_teardown,
15850 			test_kasumi_encryption_test_case_3),
15851 		TEST_CASE_ST(ut_setup, ut_teardown,
15852 			test_kasumi_encryption_test_case_4),
15853 		TEST_CASE_ST(ut_setup, ut_teardown,
15854 			test_kasumi_encryption_test_case_5),
15855 
15856 		/** KASUMI decrypt only (UEA1) */
15857 		TEST_CASE_ST(ut_setup, ut_teardown,
15858 			test_kasumi_decryption_test_case_1),
15859 		TEST_CASE_ST(ut_setup, ut_teardown,
15860 			test_kasumi_decryption_test_case_2),
15861 		TEST_CASE_ST(ut_setup, ut_teardown,
15862 			test_kasumi_decryption_test_case_3),
15863 		TEST_CASE_ST(ut_setup, ut_teardown,
15864 			test_kasumi_decryption_test_case_4),
15865 		TEST_CASE_ST(ut_setup, ut_teardown,
15866 			test_kasumi_decryption_test_case_5),
15867 		TEST_CASE_ST(ut_setup, ut_teardown,
15868 			test_kasumi_decryption_test_case_1_oop),
15869 		TEST_CASE_ST(ut_setup, ut_teardown,
15870 			test_kasumi_cipher_auth_test_case_1),
15871 
15872 		/** KASUMI generate auth, then encrypt (F8) */
15873 		TEST_CASE_ST(ut_setup, ut_teardown,
15874 			test_kasumi_auth_cipher_test_case_1),
15875 		TEST_CASE_ST(ut_setup, ut_teardown,
15876 			test_kasumi_auth_cipher_test_case_2),
15877 		TEST_CASE_ST(ut_setup, ut_teardown,
15878 			test_kasumi_auth_cipher_test_case_2_oop),
15879 		TEST_CASE_ST(ut_setup, ut_teardown,
15880 			test_kasumi_auth_cipher_test_case_2_sgl),
15881 		TEST_CASE_ST(ut_setup, ut_teardown,
15882 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
15883 
15884 		/** KASUMI decrypt (F8), then verify auth */
15885 		TEST_CASE_ST(ut_setup, ut_teardown,
15886 			test_kasumi_auth_cipher_verify_test_case_1),
15887 		TEST_CASE_ST(ut_setup, ut_teardown,
15888 			test_kasumi_auth_cipher_verify_test_case_2),
15889 		TEST_CASE_ST(ut_setup, ut_teardown,
15890 			test_kasumi_auth_cipher_verify_test_case_2_oop),
15891 		TEST_CASE_ST(ut_setup, ut_teardown,
15892 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
15893 		TEST_CASE_ST(ut_setup, ut_teardown,
15894 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
15895 
15896 		TEST_CASES_END()
15897 	}
15898 };
15899 
15900 static struct unit_test_suite cryptodev_esn_testsuite  = {
15901 	.suite_name = "ESN Test Suite",
15902 	.setup = esn_testsuite_setup,
15903 	.unit_test_cases = {
15904 		TEST_CASE_ST(ut_setup, ut_teardown,
15905 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
15906 		TEST_CASE_ST(ut_setup, ut_teardown,
15907 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
15908 		TEST_CASES_END()
15909 	}
15910 };
15911 
15912 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
15913 	.suite_name = "Negative AES GCM Test Suite",
15914 	.setup = negative_aes_gcm_testsuite_setup,
15915 	.unit_test_cases = {
15916 		TEST_CASE_ST(ut_setup, ut_teardown,
15917 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
15918 		TEST_CASE_ST(ut_setup, ut_teardown,
15919 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
15920 		TEST_CASE_ST(ut_setup, ut_teardown,
15921 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
15922 		TEST_CASE_ST(ut_setup, ut_teardown,
15923 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
15924 		TEST_CASE_ST(ut_setup, ut_teardown,
15925 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
15926 		TEST_CASE_ST(ut_setup, ut_teardown,
15927 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
15928 		TEST_CASE_ST(ut_setup, ut_teardown,
15929 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
15930 		TEST_CASE_ST(ut_setup, ut_teardown,
15931 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
15932 		TEST_CASE_ST(ut_setup, ut_teardown,
15933 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
15934 		TEST_CASE_ST(ut_setup, ut_teardown,
15935 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
15936 		TEST_CASE_ST(ut_setup, ut_teardown,
15937 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
15938 		TEST_CASE_ST(ut_setup, ut_teardown,
15939 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
15940 
15941 		TEST_CASES_END()
15942 	}
15943 };
15944 
15945 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
15946 	.suite_name = "Negative AES GMAC Test Suite",
15947 	.setup = negative_aes_gmac_testsuite_setup,
15948 	.unit_test_cases = {
15949 		TEST_CASE_ST(ut_setup, ut_teardown,
15950 			authentication_verify_AES128_GMAC_fail_data_corrupt),
15951 		TEST_CASE_ST(ut_setup, ut_teardown,
15952 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
15953 
15954 		TEST_CASES_END()
15955 	}
15956 };
15957 
15958 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
15959 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
15960 	.setup = mixed_cipher_hash_testsuite_setup,
15961 	.unit_test_cases = {
15962 		/** AUTH AES CMAC + CIPHER AES CTR */
15963 		TEST_CASE_ST(ut_setup, ut_teardown,
15964 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
15965 		TEST_CASE_ST(ut_setup, ut_teardown,
15966 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15967 		TEST_CASE_ST(ut_setup, ut_teardown,
15968 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15969 		TEST_CASE_ST(ut_setup, ut_teardown,
15970 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15971 		TEST_CASE_ST(ut_setup, ut_teardown,
15972 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
15973 		TEST_CASE_ST(ut_setup, ut_teardown,
15974 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15975 		TEST_CASE_ST(ut_setup, ut_teardown,
15976 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15977 		TEST_CASE_ST(ut_setup, ut_teardown,
15978 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15979 
15980 		/** AUTH ZUC + CIPHER SNOW3G */
15981 		TEST_CASE_ST(ut_setup, ut_teardown,
15982 			test_auth_zuc_cipher_snow_test_case_1),
15983 		TEST_CASE_ST(ut_setup, ut_teardown,
15984 			test_verify_auth_zuc_cipher_snow_test_case_1),
15985 		/** AUTH AES CMAC + CIPHER SNOW3G */
15986 		TEST_CASE_ST(ut_setup, ut_teardown,
15987 			test_auth_aes_cmac_cipher_snow_test_case_1),
15988 		TEST_CASE_ST(ut_setup, ut_teardown,
15989 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15990 		/** AUTH ZUC + CIPHER AES CTR */
15991 		TEST_CASE_ST(ut_setup, ut_teardown,
15992 			test_auth_zuc_cipher_aes_ctr_test_case_1),
15993 		TEST_CASE_ST(ut_setup, ut_teardown,
15994 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15995 		/** AUTH SNOW3G + CIPHER AES CTR */
15996 		TEST_CASE_ST(ut_setup, ut_teardown,
15997 			test_auth_snow_cipher_aes_ctr_test_case_1),
15998 		TEST_CASE_ST(ut_setup, ut_teardown,
15999 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
16000 		/** AUTH SNOW3G + CIPHER ZUC */
16001 		TEST_CASE_ST(ut_setup, ut_teardown,
16002 			test_auth_snow_cipher_zuc_test_case_1),
16003 		TEST_CASE_ST(ut_setup, ut_teardown,
16004 			test_verify_auth_snow_cipher_zuc_test_case_1),
16005 		/** AUTH AES CMAC + CIPHER ZUC */
16006 		TEST_CASE_ST(ut_setup, ut_teardown,
16007 			test_auth_aes_cmac_cipher_zuc_test_case_1),
16008 		TEST_CASE_ST(ut_setup, ut_teardown,
16009 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
16010 
16011 		/** AUTH NULL + CIPHER SNOW3G */
16012 		TEST_CASE_ST(ut_setup, ut_teardown,
16013 			test_auth_null_cipher_snow_test_case_1),
16014 		TEST_CASE_ST(ut_setup, ut_teardown,
16015 			test_verify_auth_null_cipher_snow_test_case_1),
16016 		/** AUTH NULL + CIPHER ZUC */
16017 		TEST_CASE_ST(ut_setup, ut_teardown,
16018 			test_auth_null_cipher_zuc_test_case_1),
16019 		TEST_CASE_ST(ut_setup, ut_teardown,
16020 			test_verify_auth_null_cipher_zuc_test_case_1),
16021 		/** AUTH SNOW3G + CIPHER NULL */
16022 		TEST_CASE_ST(ut_setup, ut_teardown,
16023 			test_auth_snow_cipher_null_test_case_1),
16024 		TEST_CASE_ST(ut_setup, ut_teardown,
16025 			test_verify_auth_snow_cipher_null_test_case_1),
16026 		/** AUTH ZUC + CIPHER NULL */
16027 		TEST_CASE_ST(ut_setup, ut_teardown,
16028 			test_auth_zuc_cipher_null_test_case_1),
16029 		TEST_CASE_ST(ut_setup, ut_teardown,
16030 			test_verify_auth_zuc_cipher_null_test_case_1),
16031 		/** AUTH NULL + CIPHER AES CTR */
16032 		TEST_CASE_ST(ut_setup, ut_teardown,
16033 			test_auth_null_cipher_aes_ctr_test_case_1),
16034 		TEST_CASE_ST(ut_setup, ut_teardown,
16035 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
16036 		/** AUTH AES CMAC + CIPHER NULL */
16037 		TEST_CASE_ST(ut_setup, ut_teardown,
16038 			test_auth_aes_cmac_cipher_null_test_case_1),
16039 		TEST_CASE_ST(ut_setup, ut_teardown,
16040 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
16041 		TEST_CASES_END()
16042 	}
16043 };
16044 
16045 static int
16046 run_cryptodev_testsuite(const char *pmd_name)
16047 {
16048 	uint8_t ret, j, i = 0, blk_start_idx = 0;
16049 	const enum blockcipher_test_type blk_suites[] = {
16050 		BLKCIPHER_AES_CHAIN_TYPE,
16051 		BLKCIPHER_AES_CIPHERONLY_TYPE,
16052 		BLKCIPHER_AES_DOCSIS_TYPE,
16053 		BLKCIPHER_3DES_CHAIN_TYPE,
16054 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
16055 		BLKCIPHER_DES_CIPHERONLY_TYPE,
16056 		BLKCIPHER_DES_DOCSIS_TYPE,
16057 		BLKCIPHER_AUTHONLY_TYPE};
16058 	struct unit_test_suite *static_suites[] = {
16059 		&cryptodev_multi_session_testsuite,
16060 		&cryptodev_null_testsuite,
16061 		&cryptodev_aes_ccm_auth_testsuite,
16062 		&cryptodev_aes_gcm_auth_testsuite,
16063 		&cryptodev_aes_gmac_auth_testsuite,
16064 		&cryptodev_snow3g_testsuite,
16065 		&cryptodev_chacha20_poly1305_testsuite,
16066 		&cryptodev_zuc_testsuite,
16067 		&cryptodev_hmac_md5_auth_testsuite,
16068 		&cryptodev_kasumi_testsuite,
16069 		&cryptodev_esn_testsuite,
16070 		&cryptodev_negative_aes_gcm_testsuite,
16071 		&cryptodev_negative_aes_gmac_testsuite,
16072 		&cryptodev_mixed_cipher_hash_testsuite,
16073 		&cryptodev_negative_hmac_sha1_testsuite,
16074 		&cryptodev_gen_testsuite,
16075 #ifdef RTE_LIB_SECURITY
16076 		&ipsec_proto_testsuite,
16077 		&pdcp_proto_testsuite,
16078 		&docsis_proto_testsuite,
16079 #endif
16080 		&end_testsuite
16081 	};
16082 	static struct unit_test_suite ts = {
16083 		.suite_name = "Cryptodev Unit Test Suite",
16084 		.setup = testsuite_setup,
16085 		.teardown = testsuite_teardown,
16086 		.unit_test_cases = {TEST_CASES_END()}
16087 	};
16088 
16089 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
16090 
16091 	if (gbl_driver_id == -1) {
16092 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
16093 		return TEST_SKIPPED;
16094 	}
16095 
16096 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
16097 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
16098 
16099 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
16100 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
16101 	ret = unit_test_suite_runner(&ts);
16102 
16103 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
16104 	free(ts.unit_test_suites);
16105 	return ret;
16106 }
16107 
16108 static int
16109 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
16110 {
16111 	struct rte_cryptodev_info dev_info;
16112 	uint8_t i, nb_devs;
16113 	int driver_id;
16114 
16115 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
16116 	if (driver_id == -1) {
16117 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
16118 		return TEST_SKIPPED;
16119 	}
16120 
16121 	nb_devs = rte_cryptodev_count();
16122 	if (nb_devs < 1) {
16123 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
16124 		return TEST_SKIPPED;
16125 	}
16126 
16127 	for (i = 0; i < nb_devs; i++) {
16128 		rte_cryptodev_info_get(i, &dev_info);
16129 		if (dev_info.driver_id == driver_id) {
16130 			if (!(dev_info.feature_flags & flag)) {
16131 				RTE_LOG(INFO, USER1, "%s not supported\n",
16132 						flag_name);
16133 				return TEST_SKIPPED;
16134 			}
16135 			return 0; /* found */
16136 		}
16137 	}
16138 
16139 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
16140 	return TEST_SKIPPED;
16141 }
16142 
16143 static int
16144 test_cryptodev_qat(void)
16145 {
16146 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
16147 }
16148 
16149 static int
16150 test_cryptodev_virtio(void)
16151 {
16152 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
16153 }
16154 
16155 static int
16156 test_cryptodev_aesni_mb(void)
16157 {
16158 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
16159 }
16160 
16161 static int
16162 test_cryptodev_cpu_aesni_mb(void)
16163 {
16164 	int32_t rc;
16165 	enum rte_security_session_action_type at = gbl_action_type;
16166 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
16167 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
16168 	gbl_action_type = at;
16169 	return rc;
16170 }
16171 
16172 static int
16173 test_cryptodev_chacha_poly_mb(void)
16174 {
16175 	int32_t rc;
16176 	enum rte_security_session_action_type at = gbl_action_type;
16177 	rc = run_cryptodev_testsuite(
16178 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
16179 	gbl_action_type = at;
16180 	return rc;
16181 }
16182 
16183 static int
16184 test_cryptodev_openssl(void)
16185 {
16186 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
16187 }
16188 
16189 static int
16190 test_cryptodev_aesni_gcm(void)
16191 {
16192 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
16193 }
16194 
16195 static int
16196 test_cryptodev_cpu_aesni_gcm(void)
16197 {
16198 	int32_t rc;
16199 	enum rte_security_session_action_type at = gbl_action_type;
16200 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
16201 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
16202 	gbl_action_type = at;
16203 	return rc;
16204 }
16205 
16206 static int
16207 test_cryptodev_mlx5(void)
16208 {
16209 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
16210 }
16211 
16212 static int
16213 test_cryptodev_null(void)
16214 {
16215 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
16216 }
16217 
16218 static int
16219 test_cryptodev_sw_snow3g(void)
16220 {
16221 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
16222 }
16223 
16224 static int
16225 test_cryptodev_sw_kasumi(void)
16226 {
16227 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
16228 }
16229 
16230 static int
16231 test_cryptodev_sw_zuc(void)
16232 {
16233 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
16234 }
16235 
16236 static int
16237 test_cryptodev_armv8(void)
16238 {
16239 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
16240 }
16241 
16242 static int
16243 test_cryptodev_mrvl(void)
16244 {
16245 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
16246 }
16247 
16248 #ifdef RTE_CRYPTO_SCHEDULER
16249 
16250 static int
16251 test_cryptodev_scheduler(void)
16252 {
16253 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
16254 	const enum blockcipher_test_type blk_suites[] = {
16255 		BLKCIPHER_AES_CHAIN_TYPE,
16256 		BLKCIPHER_AES_CIPHERONLY_TYPE,
16257 		BLKCIPHER_AUTHONLY_TYPE
16258 	};
16259 	static struct unit_test_suite scheduler_multicore = {
16260 		.suite_name = "Scheduler Multicore Unit Test Suite",
16261 		.setup = scheduler_multicore_testsuite_setup,
16262 		.teardown = scheduler_mode_testsuite_teardown,
16263 		.unit_test_cases = {TEST_CASES_END()}
16264 	};
16265 	static struct unit_test_suite scheduler_round_robin = {
16266 		.suite_name = "Scheduler Round Robin Unit Test Suite",
16267 		.setup = scheduler_roundrobin_testsuite_setup,
16268 		.teardown = scheduler_mode_testsuite_teardown,
16269 		.unit_test_cases = {TEST_CASES_END()}
16270 	};
16271 	static struct unit_test_suite scheduler_failover = {
16272 		.suite_name = "Scheduler Failover Unit Test Suite",
16273 		.setup = scheduler_failover_testsuite_setup,
16274 		.teardown = scheduler_mode_testsuite_teardown,
16275 		.unit_test_cases = {TEST_CASES_END()}
16276 	};
16277 	static struct unit_test_suite scheduler_pkt_size_distr = {
16278 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
16279 		.setup = scheduler_pkt_size_distr_testsuite_setup,
16280 		.teardown = scheduler_mode_testsuite_teardown,
16281 		.unit_test_cases = {TEST_CASES_END()}
16282 	};
16283 	struct unit_test_suite *sched_mode_suites[] = {
16284 		&scheduler_multicore,
16285 		&scheduler_round_robin,
16286 		&scheduler_failover,
16287 		&scheduler_pkt_size_distr
16288 	};
16289 	static struct unit_test_suite scheduler_config = {
16290 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
16291 		.unit_test_cases = {
16292 			TEST_CASE(test_scheduler_attach_worker_op),
16293 			TEST_CASE(test_scheduler_mode_multicore_op),
16294 			TEST_CASE(test_scheduler_mode_roundrobin_op),
16295 			TEST_CASE(test_scheduler_mode_failover_op),
16296 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
16297 			TEST_CASE(test_scheduler_detach_worker_op),
16298 
16299 			TEST_CASES_END() /**< NULL terminate array */
16300 		}
16301 	};
16302 	struct unit_test_suite *static_suites[] = {
16303 		&scheduler_config,
16304 		&end_testsuite
16305 	};
16306 	static struct unit_test_suite ts = {
16307 		.suite_name = "Scheduler Unit Test Suite",
16308 		.setup = scheduler_testsuite_setup,
16309 		.teardown = testsuite_teardown,
16310 		.unit_test_cases = {TEST_CASES_END()}
16311 	};
16312 
16313 	gbl_driver_id =	rte_cryptodev_driver_id_get(
16314 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
16315 
16316 	if (gbl_driver_id == -1) {
16317 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
16318 		return TEST_SKIPPED;
16319 	}
16320 
16321 	if (rte_cryptodev_driver_id_get(
16322 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
16323 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
16324 		return TEST_SKIPPED;
16325 	}
16326 
16327 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
16328 		uint8_t blk_i = 0;
16329 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
16330 				(struct unit_test_suite *) *
16331 				(RTE_DIM(blk_suites) + 1));
16332 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
16333 				blk_suites, RTE_DIM(blk_suites));
16334 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
16335 	}
16336 
16337 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
16338 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
16339 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
16340 			RTE_DIM(sched_mode_suites));
16341 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
16342 	ret = unit_test_suite_runner(&ts);
16343 
16344 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
16345 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
16346 				(*sched_mode_suites[sched_i]),
16347 				RTE_DIM(blk_suites));
16348 		free(sched_mode_suites[sched_i]->unit_test_suites);
16349 	}
16350 	free(ts.unit_test_suites);
16351 	return ret;
16352 }
16353 
16354 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
16355 
16356 #endif
16357 
16358 static int
16359 test_cryptodev_dpaa2_sec(void)
16360 {
16361 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
16362 }
16363 
16364 static int
16365 test_cryptodev_dpaa_sec(void)
16366 {
16367 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
16368 }
16369 
16370 static int
16371 test_cryptodev_ccp(void)
16372 {
16373 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
16374 }
16375 
16376 static int
16377 test_cryptodev_octeontx(void)
16378 {
16379 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
16380 }
16381 
16382 static int
16383 test_cryptodev_caam_jr(void)
16384 {
16385 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
16386 }
16387 
16388 static int
16389 test_cryptodev_nitrox(void)
16390 {
16391 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
16392 }
16393 
16394 static int
16395 test_cryptodev_bcmfs(void)
16396 {
16397 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
16398 }
16399 
16400 static int
16401 test_cryptodev_qat_raw_api(void)
16402 {
16403 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
16404 	int ret;
16405 
16406 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16407 			"RAW API");
16408 	if (ret)
16409 		return ret;
16410 
16411 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16412 	ret = run_cryptodev_testsuite(pmd_name);
16413 	global_api_test_type = CRYPTODEV_API_TEST;
16414 
16415 	return ret;
16416 }
16417 
16418 static int
16419 test_cryptodev_cn9k(void)
16420 {
16421 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
16422 }
16423 
16424 static int
16425 test_cryptodev_cn10k(void)
16426 {
16427 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
16428 }
16429 
16430 static int
16431 test_cryptodev_dpaa2_sec_raw_api(void)
16432 {
16433 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
16434 	int ret;
16435 
16436 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16437 			"RAW API");
16438 	if (ret)
16439 		return ret;
16440 
16441 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16442 	ret = run_cryptodev_testsuite(pmd_name);
16443 	global_api_test_type = CRYPTODEV_API_TEST;
16444 
16445 	return ret;
16446 }
16447 
16448 static int
16449 test_cryptodev_dpaa_sec_raw_api(void)
16450 {
16451 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
16452 	int ret;
16453 
16454 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16455 			"RAW API");
16456 	if (ret)
16457 		return ret;
16458 
16459 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16460 	ret = run_cryptodev_testsuite(pmd_name);
16461 	global_api_test_type = CRYPTODEV_API_TEST;
16462 
16463 	return ret;
16464 }
16465 
16466 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
16467 		test_cryptodev_dpaa2_sec_raw_api);
16468 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
16469 		test_cryptodev_dpaa_sec_raw_api);
16470 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
16471 		test_cryptodev_qat_raw_api);
16472 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
16473 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
16474 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
16475 	test_cryptodev_cpu_aesni_mb);
16476 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest,
16477 	test_cryptodev_chacha_poly_mb);
16478 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
16479 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
16480 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
16481 	test_cryptodev_cpu_aesni_gcm);
16482 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
16483 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
16484 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
16485 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
16486 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
16487 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
16488 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
16489 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
16490 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
16491 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
16492 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
16493 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
16494 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
16495 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
16496 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
16497 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
16498 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
16499 
16500 #endif /* !RTE_EXEC_ENV_WINDOWS */
16501