xref: /dpdk/app/test/test_cryptodev.c (revision bdce2564dbf78e1fecc0db438b562ae19f0c057c)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #include <time.h>
7 
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16 #include <rte_errno.h>
17 
18 #include <rte_crypto.h>
19 #include <rte_cryptodev.h>
20 #include <rte_ip.h>
21 #include <rte_string_fns.h>
22 #include <rte_tcp.h>
23 #include <rte_udp.h>
24 
25 #ifdef RTE_CRYPTO_SCHEDULER
26 #include <rte_cryptodev_scheduler.h>
27 #include <rte_cryptodev_scheduler_operations.h>
28 #endif
29 
30 #include <rte_lcore.h>
31 
32 #include "test.h"
33 #include "test_cryptodev.h"
34 
35 #include "test_cryptodev_blockcipher.h"
36 #include "test_cryptodev_aes_test_vectors.h"
37 #include "test_cryptodev_des_test_vectors.h"
38 #include "test_cryptodev_hash_test_vectors.h"
39 #include "test_cryptodev_kasumi_test_vectors.h"
40 #include "test_cryptodev_kasumi_hash_test_vectors.h"
41 #include "test_cryptodev_snow3g_test_vectors.h"
42 #include "test_cryptodev_snow3g_hash_test_vectors.h"
43 #include "test_cryptodev_zuc_test_vectors.h"
44 #include "test_cryptodev_aead_test_vectors.h"
45 #include "test_cryptodev_hmac_test_vectors.h"
46 #include "test_cryptodev_mixed_test_vectors.h"
47 #ifdef RTE_LIB_SECURITY
48 #include "test_cryptodev_security_ipsec.h"
49 #include "test_cryptodev_security_ipsec_test_vectors.h"
50 #include "test_cryptodev_security_pdcp_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
52 #include "test_cryptodev_security_pdcp_test_func.h"
53 #include "test_cryptodev_security_docsis_test_vectors.h"
54 
55 #define SDAP_DISABLED	0
56 #define SDAP_ENABLED	1
57 #endif
58 
59 #define VDEV_ARGS_SIZE 100
60 #define MAX_NB_SESSIONS 4
61 
62 #define MAX_DRV_SERVICE_CTX_SIZE 256
63 
64 #define MAX_RAW_DEQUEUE_COUNT	65535
65 
66 #define IN_PLACE 0
67 #define OUT_OF_PLACE 1
68 
69 static int gbl_driver_id;
70 
71 static enum rte_security_session_action_type gbl_action_type =
72 	RTE_SECURITY_ACTION_TYPE_NONE;
73 
74 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
75 
76 struct crypto_unittest_params {
77 	struct rte_crypto_sym_xform cipher_xform;
78 	struct rte_crypto_sym_xform auth_xform;
79 	struct rte_crypto_sym_xform aead_xform;
80 #ifdef RTE_LIB_SECURITY
81 	struct rte_security_docsis_xform docsis_xform;
82 #endif
83 
84 	union {
85 		struct rte_cryptodev_sym_session *sess;
86 #ifdef RTE_LIB_SECURITY
87 		struct rte_security_session *sec_session;
88 #endif
89 	};
90 #ifdef RTE_LIB_SECURITY
91 	enum rte_security_session_action_type type;
92 #endif
93 	struct rte_crypto_op *op;
94 
95 	struct rte_mbuf *obuf, *ibuf;
96 
97 	uint8_t *digest;
98 };
99 
100 #define ALIGN_POW2_ROUNDUP(num, align) \
101 	(((num) + (align) - 1) & ~((align) - 1))
102 
103 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
104 	for (j = 0; j < num_child_ts; index++, j++)			\
105 		parent_ts.unit_test_suites[index] = child_ts[j]
106 
107 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
108 	for (j = 0; j < num_blk_types; index++, j++)				\
109 		parent_ts.unit_test_suites[index] =				\
110 				build_blockcipher_test_suite(blk_types[j])
111 
112 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
113 	for (j = index; j < index + num_blk_types; j++)				\
114 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
115 
116 /*
117  * Forward declarations.
118  */
119 static int
120 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
121 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
122 		uint8_t *hmac_key);
123 
124 static int
125 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
126 		struct crypto_unittest_params *ut_params,
127 		struct crypto_testsuite_params *ts_param,
128 		const uint8_t *cipher,
129 		const uint8_t *digest,
130 		const uint8_t *iv);
131 
132 static int
133 security_proto_supported(enum rte_security_session_action_type action,
134 	enum rte_security_session_protocol proto);
135 
136 static int
137 dev_configure_and_start(uint64_t ff_disable);
138 
139 static struct rte_mbuf *
140 setup_test_string(struct rte_mempool *mpool,
141 		const char *string, size_t len, uint8_t blocksize)
142 {
143 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
144 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
145 
146 	if (m) {
147 		char *dst;
148 
149 		memset(m->buf_addr, 0, m->buf_len);
150 		dst = rte_pktmbuf_append(m, t_len);
151 		if (!dst) {
152 			rte_pktmbuf_free(m);
153 			return NULL;
154 		}
155 		if (string != NULL)
156 			rte_memcpy(dst, string, t_len);
157 		else
158 			memset(dst, 0, t_len);
159 	}
160 
161 	return m;
162 }
163 
164 /* Get number of bytes in X bits (rounding up) */
165 static uint32_t
166 ceil_byte_length(uint32_t num_bits)
167 {
168 	if (num_bits % 8)
169 		return ((num_bits >> 3) + 1);
170 	else
171 		return (num_bits >> 3);
172 }
173 
174 static void
175 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
176 		uint8_t is_op_success)
177 {
178 	struct rte_crypto_op *op = user_data;
179 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
180 			RTE_CRYPTO_OP_STATUS_ERROR;
181 }
182 
183 static struct crypto_testsuite_params testsuite_params = { NULL };
184 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
185 static struct crypto_unittest_params unittest_params;
186 
187 void
188 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
189 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
190 		uint8_t len_in_bits, uint8_t cipher_iv_len)
191 {
192 	struct rte_crypto_sym_op *sop = op->sym;
193 	struct rte_crypto_op *ret_op = NULL;
194 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
195 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
196 	union rte_crypto_sym_ofs ofs;
197 	struct rte_crypto_sym_vec vec;
198 	struct rte_crypto_sgl sgl, dest_sgl;
199 	uint32_t max_len;
200 	union rte_cryptodev_session_ctx sess;
201 	uint64_t auth_end_iova;
202 	uint32_t count = 0;
203 	struct rte_crypto_raw_dp_ctx *ctx;
204 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
205 			auth_len = 0;
206 	int32_t n;
207 	uint32_t n_success;
208 	int ctx_service_size;
209 	int32_t status = 0;
210 	int enqueue_status, dequeue_status;
211 	struct crypto_unittest_params *ut_params = &unittest_params;
212 	int is_sgl = sop->m_src->nb_segs > 1;
213 	int is_oop = 0;
214 
215 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
216 	if (ctx_service_size < 0) {
217 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
218 		return;
219 	}
220 
221 	ctx = malloc(ctx_service_size);
222 	if (!ctx) {
223 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
224 		return;
225 	}
226 
227 	/* Both are enums, setting crypto_sess will suit any session type */
228 	sess.crypto_sess = op->sym->session;
229 
230 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
231 			op->sess_type, sess, 0) < 0) {
232 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
233 		goto exit;
234 	}
235 
236 	cipher_iv.iova = 0;
237 	cipher_iv.va = NULL;
238 	aad_auth_iv.iova = 0;
239 	aad_auth_iv.va = NULL;
240 	digest.iova = 0;
241 	digest.va = NULL;
242 	sgl.vec = data_vec;
243 	vec.num = 1;
244 	vec.src_sgl = &sgl;
245 	vec.iv = &cipher_iv;
246 	vec.digest = &digest;
247 	vec.aad = &aad_auth_iv;
248 	vec.status = &status;
249 
250 	ofs.raw = 0;
251 
252 	if ((sop->m_dst != NULL) && (sop->m_dst != sop->m_src))
253 		is_oop = 1;
254 
255 	if (is_cipher && is_auth) {
256 		cipher_offset = sop->cipher.data.offset;
257 		cipher_len = sop->cipher.data.length;
258 		auth_offset = sop->auth.data.offset;
259 		auth_len = sop->auth.data.length;
260 		max_len = RTE_MAX(cipher_offset + cipher_len,
261 				auth_offset + auth_len);
262 		if (len_in_bits) {
263 			max_len = max_len >> 3;
264 			cipher_offset = cipher_offset >> 3;
265 			auth_offset = auth_offset >> 3;
266 			cipher_len = cipher_len >> 3;
267 			auth_len = auth_len >> 3;
268 		}
269 		ofs.ofs.cipher.head = cipher_offset;
270 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
271 		ofs.ofs.auth.head = auth_offset;
272 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
273 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
274 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
275 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
276 				op, void *, IV_OFFSET + cipher_iv_len);
277 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
278 				cipher_iv_len);
279 		digest.va = (void *)sop->auth.digest.data;
280 		digest.iova = sop->auth.digest.phys_addr;
281 
282 		if (is_sgl) {
283 			uint32_t remaining_off = auth_offset + auth_len;
284 			struct rte_mbuf *sgl_buf = sop->m_src;
285 			if (is_oop)
286 				sgl_buf = sop->m_dst;
287 
288 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
289 					&& sgl_buf->next != NULL) {
290 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
291 				sgl_buf = sgl_buf->next;
292 			}
293 
294 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
295 				sgl_buf, remaining_off);
296 		} else {
297 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
298 							 auth_offset + auth_len;
299 		}
300 		/* Then check if digest-encrypted conditions are met */
301 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
302 				(digest.iova == auth_end_iova) && is_sgl)
303 			max_len = RTE_MAX(max_len,
304 				auth_offset + auth_len +
305 				ut_params->auth_xform.auth.digest_length);
306 
307 	} else if (is_cipher) {
308 		cipher_offset = sop->cipher.data.offset;
309 		cipher_len = sop->cipher.data.length;
310 		max_len = cipher_len + cipher_offset;
311 		if (len_in_bits) {
312 			max_len = max_len >> 3;
313 			cipher_offset = cipher_offset >> 3;
314 			cipher_len = cipher_len >> 3;
315 		}
316 		ofs.ofs.cipher.head = cipher_offset;
317 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
318 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
319 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
320 
321 	} else if (is_auth) {
322 		auth_offset = sop->auth.data.offset;
323 		auth_len = sop->auth.data.length;
324 		max_len = auth_len + auth_offset;
325 		if (len_in_bits) {
326 			max_len = max_len >> 3;
327 			auth_offset = auth_offset >> 3;
328 			auth_len = auth_len >> 3;
329 		}
330 		ofs.ofs.auth.head = auth_offset;
331 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
332 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
333 				op, void *, IV_OFFSET + cipher_iv_len);
334 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
335 				cipher_iv_len);
336 		digest.va = (void *)sop->auth.digest.data;
337 		digest.iova = sop->auth.digest.phys_addr;
338 
339 	} else { /* aead */
340 		cipher_offset = sop->aead.data.offset;
341 		cipher_len = sop->aead.data.length;
342 		max_len = cipher_len + cipher_offset;
343 		if (len_in_bits) {
344 			max_len = max_len >> 3;
345 			cipher_offset = cipher_offset >> 3;
346 			cipher_len = cipher_len >> 3;
347 		}
348 		ofs.ofs.cipher.head = cipher_offset;
349 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
350 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
351 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
352 		aad_auth_iv.va = (void *)sop->aead.aad.data;
353 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
354 		digest.va = (void *)sop->aead.digest.data;
355 		digest.iova = sop->aead.digest.phys_addr;
356 	}
357 
358 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
359 			data_vec, RTE_DIM(data_vec));
360 	if (n < 0 || n > sop->m_src->nb_segs) {
361 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
362 		goto exit;
363 	}
364 
365 	sgl.num = n;
366 	/* Out of place */
367 	if (is_oop) {
368 		dest_sgl.vec = dest_data_vec;
369 		vec.dest_sgl = &dest_sgl;
370 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
371 				dest_data_vec, RTE_DIM(dest_data_vec));
372 		if (n < 0 || n > sop->m_dst->nb_segs) {
373 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
374 			goto exit;
375 		}
376 		dest_sgl.num = n;
377 	} else
378 		vec.dest_sgl = NULL;
379 
380 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
381 			&enqueue_status) < 1) {
382 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
383 		goto exit;
384 	}
385 
386 	if (enqueue_status == 0) {
387 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
388 		if (status < 0) {
389 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
390 			goto exit;
391 		}
392 	} else if (enqueue_status < 0) {
393 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
394 		goto exit;
395 	}
396 
397 	n = n_success = 0;
398 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
399 		n = rte_cryptodev_raw_dequeue_burst(ctx,
400 			NULL, 1, post_process_raw_dp_op,
401 				(void **)&ret_op, 0, &n_success,
402 				&dequeue_status);
403 		if (dequeue_status < 0) {
404 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
405 			goto exit;
406 		}
407 		if (n == 0)
408 			rte_pause();
409 	}
410 
411 	if (n == 1 && dequeue_status == 0) {
412 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
413 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
414 			goto exit;
415 		}
416 	}
417 
418 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
419 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
420 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
421 					RTE_CRYPTO_OP_STATUS_SUCCESS;
422 
423 exit:
424 	free(ctx);
425 }
426 
427 static void
428 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
429 {
430 	int32_t n, st;
431 	struct rte_crypto_sym_op *sop;
432 	union rte_crypto_sym_ofs ofs;
433 	struct rte_crypto_sgl sgl;
434 	struct rte_crypto_sym_vec symvec;
435 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
436 	struct rte_crypto_vec vec[UINT8_MAX];
437 
438 	sop = op->sym;
439 
440 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
441 		sop->aead.data.length, vec, RTE_DIM(vec));
442 
443 	if (n < 0 || n != sop->m_src->nb_segs) {
444 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
445 		return;
446 	}
447 
448 	sgl.vec = vec;
449 	sgl.num = n;
450 	symvec.src_sgl = &sgl;
451 	symvec.iv = &iv_ptr;
452 	symvec.digest = &digest_ptr;
453 	symvec.aad = &aad_ptr;
454 	symvec.status = &st;
455 	symvec.num = 1;
456 
457 	/* for CPU crypto the IOVA address is not required */
458 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
459 	digest_ptr.va = (void *)sop->aead.digest.data;
460 	aad_ptr.va = (void *)sop->aead.aad.data;
461 
462 	ofs.raw = 0;
463 
464 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
465 		&symvec);
466 
467 	if (n != 1)
468 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
469 	else
470 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
471 }
472 
473 static void
474 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
475 {
476 	int32_t n, st;
477 	struct rte_crypto_sym_op *sop;
478 	union rte_crypto_sym_ofs ofs;
479 	struct rte_crypto_sgl sgl;
480 	struct rte_crypto_sym_vec symvec;
481 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
482 	struct rte_crypto_vec vec[UINT8_MAX];
483 
484 	sop = op->sym;
485 
486 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
487 		sop->auth.data.length, vec, RTE_DIM(vec));
488 
489 	if (n < 0 || n != sop->m_src->nb_segs) {
490 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
491 		return;
492 	}
493 
494 	sgl.vec = vec;
495 	sgl.num = n;
496 	symvec.src_sgl = &sgl;
497 	symvec.iv = &iv_ptr;
498 	symvec.digest = &digest_ptr;
499 	symvec.status = &st;
500 	symvec.num = 1;
501 
502 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
503 	digest_ptr.va = (void *)sop->auth.digest.data;
504 
505 	ofs.raw = 0;
506 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
507 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
508 		(sop->cipher.data.offset + sop->cipher.data.length);
509 
510 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
511 		&symvec);
512 
513 	if (n != 1)
514 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
515 	else
516 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
517 }
518 
519 static struct rte_crypto_op *
520 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
521 {
522 
523 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
524 
525 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
526 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
527 		return NULL;
528 	}
529 
530 	op = NULL;
531 
532 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
533 		rte_pause();
534 
535 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
536 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
537 		return NULL;
538 	}
539 
540 	return op;
541 }
542 
543 static int
544 testsuite_setup(void)
545 {
546 	struct crypto_testsuite_params *ts_params = &testsuite_params;
547 	struct rte_cryptodev_info info;
548 	uint32_t i = 0, nb_devs, dev_id;
549 	uint16_t qp_id;
550 
551 	memset(ts_params, 0, sizeof(*ts_params));
552 
553 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
554 	if (ts_params->mbuf_pool == NULL) {
555 		/* Not already created so create */
556 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
557 				"CRYPTO_MBUFPOOL",
558 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
559 				rte_socket_id());
560 		if (ts_params->mbuf_pool == NULL) {
561 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
562 			return TEST_FAILED;
563 		}
564 	}
565 
566 	ts_params->large_mbuf_pool = rte_mempool_lookup(
567 			"CRYPTO_LARGE_MBUFPOOL");
568 	if (ts_params->large_mbuf_pool == NULL) {
569 		/* Not already created so create */
570 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
571 				"CRYPTO_LARGE_MBUFPOOL",
572 				1, 0, 0, UINT16_MAX,
573 				rte_socket_id());
574 		if (ts_params->large_mbuf_pool == NULL) {
575 			RTE_LOG(ERR, USER1,
576 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
577 			return TEST_FAILED;
578 		}
579 	}
580 
581 	ts_params->op_mpool = rte_crypto_op_pool_create(
582 			"MBUF_CRYPTO_SYM_OP_POOL",
583 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
584 			NUM_MBUFS, MBUF_CACHE_SIZE,
585 			DEFAULT_NUM_XFORMS *
586 			sizeof(struct rte_crypto_sym_xform) +
587 			MAXIMUM_IV_LENGTH,
588 			rte_socket_id());
589 	if (ts_params->op_mpool == NULL) {
590 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
591 		return TEST_FAILED;
592 	}
593 
594 	nb_devs = rte_cryptodev_count();
595 	if (nb_devs < 1) {
596 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
597 		return TEST_SKIPPED;
598 	}
599 
600 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
601 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
602 				rte_cryptodev_driver_name_get(gbl_driver_id));
603 		return TEST_SKIPPED;
604 	}
605 
606 	/* Create list of valid crypto devs */
607 	for (i = 0; i < nb_devs; i++) {
608 		rte_cryptodev_info_get(i, &info);
609 		if (info.driver_id == gbl_driver_id)
610 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
611 	}
612 
613 	if (ts_params->valid_dev_count < 1)
614 		return TEST_FAILED;
615 
616 	/* Set up all the qps on the first of the valid devices found */
617 
618 	dev_id = ts_params->valid_devs[0];
619 
620 	rte_cryptodev_info_get(dev_id, &info);
621 
622 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
623 	ts_params->conf.socket_id = SOCKET_ID_ANY;
624 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
625 
626 	unsigned int session_size =
627 		rte_cryptodev_sym_get_private_session_size(dev_id);
628 
629 #ifdef RTE_LIB_SECURITY
630 	unsigned int security_session_size = rte_security_session_get_size(
631 			rte_cryptodev_get_sec_ctx(dev_id));
632 
633 	if (session_size < security_session_size)
634 		session_size = security_session_size;
635 #endif
636 	/*
637 	 * Create mempool with maximum number of sessions.
638 	 */
639 	if (info.sym.max_nb_sessions != 0 &&
640 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
641 		RTE_LOG(ERR, USER1, "Device does not support "
642 				"at least %u sessions\n",
643 				MAX_NB_SESSIONS);
644 		return TEST_FAILED;
645 	}
646 
647 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
648 			"test_sess_mp", MAX_NB_SESSIONS, session_size, 0, 0,
649 			SOCKET_ID_ANY);
650 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
651 			"session mempool allocation failed");
652 	ts_params->session_priv_mpool = rte_mempool_create(
653 			"test_sess_mp_priv", MAX_NB_SESSIONS, session_size,
654 			0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0);
655 
656 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
657 			"session mempool allocation failed");
658 
659 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
660 			&ts_params->conf),
661 			"Failed to configure cryptodev %u with %u qps",
662 			dev_id, ts_params->conf.nb_queue_pairs);
663 
664 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
665 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
666 
667 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
668 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
669 			dev_id, qp_id, &ts_params->qp_conf,
670 			rte_cryptodev_socket_id(dev_id)),
671 			"Failed to setup queue pair %u on cryptodev %u",
672 			qp_id, dev_id);
673 	}
674 
675 	return TEST_SUCCESS;
676 }
677 
678 static void
679 testsuite_teardown(void)
680 {
681 	struct crypto_testsuite_params *ts_params = &testsuite_params;
682 	int res;
683 
684 	if (ts_params->mbuf_pool != NULL) {
685 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
686 		rte_mempool_avail_count(ts_params->mbuf_pool));
687 	}
688 
689 	if (ts_params->op_mpool != NULL) {
690 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
691 		rte_mempool_avail_count(ts_params->op_mpool));
692 	}
693 
694 	if (ts_params->session_mpool != NULL) {
695 		rte_mempool_free(ts_params->session_mpool);
696 		ts_params->session_mpool = NULL;
697 		rte_mempool_free(ts_params->session_priv_mpool);
698 		ts_params->session_priv_mpool = NULL;
699 	}
700 
701 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
702 	if (res)
703 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
704 }
705 
706 static int
707 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
708 		const int *algs, uint16_t num_algs)
709 {
710 	uint8_t dev_id = testsuite_params.valid_devs[0];
711 	bool some_alg_supported = FALSE;
712 	uint16_t i;
713 
714 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
715 		struct rte_cryptodev_sym_capability_idx alg = {
716 			type, {algs[i]}
717 		};
718 		if (rte_cryptodev_sym_capability_get(dev_id,
719 				&alg) != NULL)
720 			some_alg_supported = TRUE;
721 	}
722 	if (!some_alg_supported)
723 		return TEST_SKIPPED;
724 
725 	return 0;
726 }
727 
728 int
729 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
730 		uint16_t num_ciphers)
731 {
732 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
733 			(const int *) ciphers, num_ciphers);
734 }
735 
736 int
737 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
738 		uint16_t num_auths)
739 {
740 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
741 			(const int *) auths, num_auths);
742 }
743 
744 int
745 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
746 		uint16_t num_aeads)
747 {
748 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
749 			(const int *) aeads, num_aeads);
750 }
751 
752 static int
753 null_testsuite_setup(void)
754 {
755 	struct crypto_testsuite_params *ts_params = &testsuite_params;
756 	uint8_t dev_id = ts_params->valid_devs[0];
757 	struct rte_cryptodev_info dev_info;
758 	const enum rte_crypto_cipher_algorithm ciphers[] = {
759 		RTE_CRYPTO_CIPHER_NULL
760 	};
761 	const enum rte_crypto_auth_algorithm auths[] = {
762 		RTE_CRYPTO_AUTH_NULL
763 	};
764 
765 	rte_cryptodev_info_get(dev_id, &dev_info);
766 
767 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
768 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
769 				"testsuite not met\n");
770 		return TEST_SKIPPED;
771 	}
772 
773 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
774 			&& check_auth_capabilities_supported(auths,
775 			RTE_DIM(auths)) != 0) {
776 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
777 				"testsuite not met\n");
778 		return TEST_SKIPPED;
779 	}
780 
781 	return 0;
782 }
783 
784 static int
785 crypto_gen_testsuite_setup(void)
786 {
787 	struct crypto_testsuite_params *ts_params = &testsuite_params;
788 	uint8_t dev_id = ts_params->valid_devs[0];
789 	struct rte_cryptodev_info dev_info;
790 
791 	rte_cryptodev_info_get(dev_id, &dev_info);
792 
793 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
794 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
795 				"testsuite not met\n");
796 		return TEST_SKIPPED;
797 	}
798 
799 	return 0;
800 }
801 
802 #ifdef RTE_LIB_SECURITY
803 static int
804 ipsec_proto_testsuite_setup(void)
805 {
806 	struct crypto_testsuite_params *ts_params = &testsuite_params;
807 	struct crypto_unittest_params *ut_params = &unittest_params;
808 	struct rte_cryptodev_info dev_info;
809 	int ret = 0;
810 
811 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
812 
813 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
814 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
815 				"testsuite not met\n");
816 		return TEST_SKIPPED;
817 	}
818 
819 	/* Reconfigure to enable security */
820 	ret = dev_configure_and_start(0);
821 	if (ret != TEST_SUCCESS)
822 		return ret;
823 
824 	/* Set action type */
825 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
826 
827 	if (security_proto_supported(
828 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
829 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
830 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
831 				"test not met\n");
832 		ret = TEST_SKIPPED;
833 	}
834 
835 	test_ipsec_alg_list_populate();
836 	test_ipsec_ah_alg_list_populate();
837 
838 	/*
839 	 * Stop the device. Device would be started again by individual test
840 	 * case setup routine.
841 	 */
842 	rte_cryptodev_stop(ts_params->valid_devs[0]);
843 
844 	return ret;
845 }
846 
847 static int
848 pdcp_proto_testsuite_setup(void)
849 {
850 	struct crypto_testsuite_params *ts_params = &testsuite_params;
851 	uint8_t dev_id = ts_params->valid_devs[0];
852 	struct rte_cryptodev_info dev_info;
853 	const enum rte_crypto_cipher_algorithm ciphers[] = {
854 		RTE_CRYPTO_CIPHER_NULL,
855 		RTE_CRYPTO_CIPHER_AES_CTR,
856 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
857 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
858 	};
859 	const enum rte_crypto_auth_algorithm auths[] = {
860 		RTE_CRYPTO_AUTH_NULL,
861 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
862 		RTE_CRYPTO_AUTH_AES_CMAC,
863 		RTE_CRYPTO_AUTH_ZUC_EIA3
864 	};
865 
866 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_auth_key));
867 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_bearer));
868 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_crypto_key));
869 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in));
870 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_in_len));
871 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_out));
872 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_data_sn_size));
873 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn));
874 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_hfn_threshold));
875 	RTE_BUILD_BUG_ON(RTE_DIM(pdcp_test_params) != RTE_DIM(pdcp_test_packet_direction));
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 
1386 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1387 			&ts_params->conf),
1388 			"Failed to configure cryptodev %u",
1389 			ts_params->valid_devs[0]);
1390 
1391 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1392 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1393 			ts_params->valid_devs[0], qp_id,
1394 			&ts_params->qp_conf,
1395 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1396 			"Failed to setup queue pair %u on cryptodev %u",
1397 			qp_id, ts_params->valid_devs[0]);
1398 	}
1399 
1400 
1401 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1402 
1403 	/* Start the device */
1404 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1405 			"Failed to start cryptodev %u",
1406 			ts_params->valid_devs[0]);
1407 
1408 	return TEST_SUCCESS;
1409 }
1410 
1411 int
1412 ut_setup(void)
1413 {
1414 	/* Configure and start the device with security feature disabled */
1415 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1416 }
1417 
1418 static int
1419 ut_setup_security(void)
1420 {
1421 	/* Configure and start the device with no features disabled */
1422 	return dev_configure_and_start(0);
1423 }
1424 
1425 void
1426 ut_teardown(void)
1427 {
1428 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1429 	struct crypto_unittest_params *ut_params = &unittest_params;
1430 
1431 	/* free crypto session structure */
1432 #ifdef RTE_LIB_SECURITY
1433 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1434 		if (ut_params->sec_session) {
1435 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1436 						(ts_params->valid_devs[0]),
1437 						ut_params->sec_session);
1438 			ut_params->sec_session = NULL;
1439 		}
1440 	} else
1441 #endif
1442 	{
1443 		if (ut_params->sess) {
1444 			rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
1445 					ut_params->sess);
1446 			ut_params->sess = NULL;
1447 		}
1448 	}
1449 
1450 	/* free crypto operation structure */
1451 	rte_crypto_op_free(ut_params->op);
1452 
1453 	/*
1454 	 * free mbuf - both obuf and ibuf are usually the same,
1455 	 * so check if they point at the same address is necessary,
1456 	 * to avoid freeing the mbuf twice.
1457 	 */
1458 	if (ut_params->obuf) {
1459 		rte_pktmbuf_free(ut_params->obuf);
1460 		if (ut_params->ibuf == ut_params->obuf)
1461 			ut_params->ibuf = 0;
1462 		ut_params->obuf = 0;
1463 	}
1464 	if (ut_params->ibuf) {
1465 		rte_pktmbuf_free(ut_params->ibuf);
1466 		ut_params->ibuf = 0;
1467 	}
1468 
1469 	if (ts_params->mbuf_pool != NULL)
1470 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1471 			rte_mempool_avail_count(ts_params->mbuf_pool));
1472 
1473 	/* Stop the device */
1474 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1475 }
1476 
1477 static int
1478 test_device_configure_invalid_dev_id(void)
1479 {
1480 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1481 	uint16_t dev_id, num_devs = 0;
1482 
1483 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1484 			"Need at least %d devices for test", 1);
1485 
1486 	/* valid dev_id values */
1487 	dev_id = ts_params->valid_devs[0];
1488 
1489 	/* Stop the device in case it's started so it can be configured */
1490 	rte_cryptodev_stop(dev_id);
1491 
1492 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1493 			"Failed test for rte_cryptodev_configure: "
1494 			"invalid dev_num %u", dev_id);
1495 
1496 	/* invalid dev_id values */
1497 	dev_id = num_devs;
1498 
1499 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1500 			"Failed test for rte_cryptodev_configure: "
1501 			"invalid dev_num %u", dev_id);
1502 
1503 	dev_id = 0xff;
1504 
1505 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1506 			"Failed test for rte_cryptodev_configure:"
1507 			"invalid dev_num %u", dev_id);
1508 
1509 	return TEST_SUCCESS;
1510 }
1511 
1512 static int
1513 test_device_configure_invalid_queue_pair_ids(void)
1514 {
1515 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1516 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1517 
1518 	/* Stop the device in case it's started so it can be configured */
1519 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1520 
1521 	/* valid - max value queue pairs */
1522 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1523 
1524 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1525 			&ts_params->conf),
1526 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1527 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1528 
1529 	/* valid - one queue pairs */
1530 	ts_params->conf.nb_queue_pairs = 1;
1531 
1532 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1533 			&ts_params->conf),
1534 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1535 			ts_params->valid_devs[0],
1536 			ts_params->conf.nb_queue_pairs);
1537 
1538 
1539 	/* invalid - zero queue pairs */
1540 	ts_params->conf.nb_queue_pairs = 0;
1541 
1542 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1543 			&ts_params->conf),
1544 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1545 			" invalid qps: %u",
1546 			ts_params->valid_devs[0],
1547 			ts_params->conf.nb_queue_pairs);
1548 
1549 
1550 	/* invalid - max value supported by field queue pairs */
1551 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1552 
1553 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1554 			&ts_params->conf),
1555 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1556 			" invalid qps: %u",
1557 			ts_params->valid_devs[0],
1558 			ts_params->conf.nb_queue_pairs);
1559 
1560 
1561 	/* invalid - max value + 1 queue pairs */
1562 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1563 
1564 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1565 			&ts_params->conf),
1566 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1567 			" invalid qps: %u",
1568 			ts_params->valid_devs[0],
1569 			ts_params->conf.nb_queue_pairs);
1570 
1571 	/* revert to original testsuite value */
1572 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1573 
1574 	return TEST_SUCCESS;
1575 }
1576 
1577 static int
1578 test_queue_pair_descriptor_setup(void)
1579 {
1580 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1581 	struct rte_cryptodev_qp_conf qp_conf = {
1582 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1583 	};
1584 	uint16_t qp_id;
1585 
1586 	/* Stop the device in case it's started so it can be configured */
1587 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1588 
1589 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1590 			&ts_params->conf),
1591 			"Failed to configure cryptodev %u",
1592 			ts_params->valid_devs[0]);
1593 
1594 	/*
1595 	 * Test various ring sizes on this device. memzones can't be
1596 	 * freed so are re-used if ring is released and re-created.
1597 	 */
1598 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1599 	qp_conf.mp_session = ts_params->session_mpool;
1600 
1601 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1602 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1603 				ts_params->valid_devs[0], qp_id, &qp_conf,
1604 				rte_cryptodev_socket_id(
1605 						ts_params->valid_devs[0])),
1606 				"Failed test for "
1607 				"rte_cryptodev_queue_pair_setup: num_inflights "
1608 				"%u on qp %u on cryptodev %u",
1609 				qp_conf.nb_descriptors, qp_id,
1610 				ts_params->valid_devs[0]);
1611 	}
1612 
1613 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1614 
1615 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1616 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1617 				ts_params->valid_devs[0], qp_id, &qp_conf,
1618 				rte_cryptodev_socket_id(
1619 						ts_params->valid_devs[0])),
1620 				"Failed test for"
1621 				" rte_cryptodev_queue_pair_setup: num_inflights"
1622 				" %u on qp %u on cryptodev %u",
1623 				qp_conf.nb_descriptors, qp_id,
1624 				ts_params->valid_devs[0]);
1625 	}
1626 
1627 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1628 
1629 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1630 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1631 				ts_params->valid_devs[0], qp_id, &qp_conf,
1632 				rte_cryptodev_socket_id(
1633 						ts_params->valid_devs[0])),
1634 				"Failed test for "
1635 				"rte_cryptodev_queue_pair_setup: num_inflights"
1636 				" %u on qp %u on cryptodev %u",
1637 				qp_conf.nb_descriptors, qp_id,
1638 				ts_params->valid_devs[0]);
1639 	}
1640 
1641 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1642 
1643 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1644 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1645 				ts_params->valid_devs[0], qp_id, &qp_conf,
1646 				rte_cryptodev_socket_id(
1647 						ts_params->valid_devs[0])),
1648 				"Failed test for"
1649 				" rte_cryptodev_queue_pair_setup:"
1650 				"num_inflights %u on qp %u on cryptodev %u",
1651 				qp_conf.nb_descriptors, qp_id,
1652 				ts_params->valid_devs[0]);
1653 	}
1654 
1655 	/* test invalid queue pair id */
1656 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1657 
1658 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1659 
1660 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1661 			ts_params->valid_devs[0],
1662 			qp_id, &qp_conf,
1663 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1664 			"Failed test for rte_cryptodev_queue_pair_setup:"
1665 			"invalid qp %u on cryptodev %u",
1666 			qp_id, ts_params->valid_devs[0]);
1667 
1668 	qp_id = 0xffff; /*invalid*/
1669 
1670 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1671 			ts_params->valid_devs[0],
1672 			qp_id, &qp_conf,
1673 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1674 			"Failed test for rte_cryptodev_queue_pair_setup:"
1675 			"invalid qp %u on cryptodev %u",
1676 			qp_id, ts_params->valid_devs[0]);
1677 
1678 	return TEST_SUCCESS;
1679 }
1680 
1681 /* ***** Plaintext data for tests ***** */
1682 
1683 const char catch_22_quote_1[] =
1684 		"There was only one catch and that was Catch-22, which "
1685 		"specified that a concern for one's safety in the face of "
1686 		"dangers that were real and immediate was the process of a "
1687 		"rational mind. Orr was crazy and could be grounded. All he "
1688 		"had to do was ask; and as soon as he did, he would no longer "
1689 		"be crazy and would have to fly more missions. Orr would be "
1690 		"crazy to fly more missions and sane if he didn't, but if he "
1691 		"was sane he had to fly them. If he flew them he was crazy "
1692 		"and didn't have to; but if he didn't want to he was sane and "
1693 		"had to. Yossarian was moved very deeply by the absolute "
1694 		"simplicity of this clause of Catch-22 and let out a "
1695 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1696 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1697 
1698 const char catch_22_quote[] =
1699 		"What a lousy earth! He wondered how many people were "
1700 		"destitute that same night even in his own prosperous country, "
1701 		"how many homes were shanties, how many husbands were drunk "
1702 		"and wives socked, and how many children were bullied, abused, "
1703 		"or abandoned. How many families hungered for food they could "
1704 		"not afford to buy? How many hearts were broken? How many "
1705 		"suicides would take place that same night, how many people "
1706 		"would go insane? How many cockroaches and landlords would "
1707 		"triumph? How many winners were losers, successes failures, "
1708 		"and rich men poor men? How many wise guys were stupid? How "
1709 		"many happy endings were unhappy endings? How many honest men "
1710 		"were liars, brave men cowards, loyal men traitors, how many "
1711 		"sainted men were corrupt, how many people in positions of "
1712 		"trust had sold their souls to bodyguards, how many had never "
1713 		"had souls? How many straight-and-narrow paths were crooked "
1714 		"paths? How many best families were worst families and how "
1715 		"many good people were bad people? When you added them all up "
1716 		"and then subtracted, you might be left with only the children, "
1717 		"and perhaps with Albert Einstein and an old violinist or "
1718 		"sculptor somewhere.";
1719 
1720 #define QUOTE_480_BYTES		(480)
1721 #define QUOTE_512_BYTES		(512)
1722 #define QUOTE_768_BYTES		(768)
1723 #define QUOTE_1024_BYTES	(1024)
1724 
1725 
1726 
1727 /* ***** SHA1 Hash Tests ***** */
1728 
1729 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1730 
1731 static uint8_t hmac_sha1_key[] = {
1732 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1733 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1734 	0xDE, 0xF4, 0xDE, 0xAD };
1735 
1736 /* ***** SHA224 Hash Tests ***** */
1737 
1738 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1739 
1740 
1741 /* ***** AES-CBC Cipher Tests ***** */
1742 
1743 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1744 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1745 
1746 static uint8_t aes_cbc_key[] = {
1747 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1748 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1749 
1750 static uint8_t aes_cbc_iv[] = {
1751 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1752 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1753 
1754 
1755 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1756 
1757 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1758 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1759 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1760 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1761 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1762 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1763 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1764 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1765 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1766 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1767 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1768 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1769 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1770 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1771 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1772 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1773 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1774 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1775 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1776 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1777 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1778 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1779 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1780 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1781 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1782 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1783 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1784 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1785 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1786 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1787 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1788 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1789 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1790 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1791 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1792 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1793 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1794 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1795 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1796 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1797 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1798 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1799 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1800 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1801 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1802 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1803 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1804 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1805 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1806 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1807 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1808 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1809 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1810 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1811 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1812 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1813 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1814 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1815 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1816 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1817 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1818 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1819 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1820 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1821 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1822 };
1823 
1824 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1825 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1826 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1827 	0x18, 0x8c, 0x1d, 0x32
1828 };
1829 
1830 
1831 /* Multisession Vector context Test */
1832 /*Begin Session 0 */
1833 static uint8_t ms_aes_cbc_key0[] = {
1834 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1835 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1836 };
1837 
1838 static uint8_t ms_aes_cbc_iv0[] = {
1839 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1840 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1841 };
1842 
1843 static const uint8_t ms_aes_cbc_cipher0[] = {
1844 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1845 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1846 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1847 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1848 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1849 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1850 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1851 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1852 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1853 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1854 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1855 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1856 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1857 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1858 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1859 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1860 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1861 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1862 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1863 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1864 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1865 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1866 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1867 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1868 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1869 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1870 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1871 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1872 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1873 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1874 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1875 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1876 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1877 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1878 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1879 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1880 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1881 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1882 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1883 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1884 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1885 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1886 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1887 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1888 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1889 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1890 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1891 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1892 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1893 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1894 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1895 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1896 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1897 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1898 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1899 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1900 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1901 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1902 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1903 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1904 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1905 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1906 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1907 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1908 };
1909 
1910 
1911 static  uint8_t ms_hmac_key0[] = {
1912 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1913 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1914 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1915 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1916 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1917 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1918 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1919 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1920 };
1921 
1922 static const uint8_t ms_hmac_digest0[] = {
1923 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1924 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1925 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1926 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1927 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1928 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1929 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1930 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1931 		};
1932 
1933 /* End Session 0 */
1934 /* Begin session 1 */
1935 
1936 static  uint8_t ms_aes_cbc_key1[] = {
1937 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1938 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1939 };
1940 
1941 static  uint8_t ms_aes_cbc_iv1[] = {
1942 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1943 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1944 };
1945 
1946 static const uint8_t ms_aes_cbc_cipher1[] = {
1947 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1948 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1949 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1950 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1951 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1952 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1953 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1954 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1955 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1956 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1957 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1958 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1959 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1960 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1961 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1962 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1963 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1964 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1965 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1966 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1967 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1968 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1969 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1970 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1971 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1972 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1973 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1974 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1975 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1976 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1977 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1978 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1979 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1980 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1981 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1982 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1983 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1984 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1985 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1986 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1987 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1988 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1989 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1990 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1991 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1992 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1993 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1994 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1995 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1996 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1997 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1998 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1999 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
2000 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
2001 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
2002 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
2003 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2004 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2005 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2006 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2007 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2008 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2009 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2010 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2011 
2012 };
2013 
2014 static uint8_t ms_hmac_key1[] = {
2015 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2016 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2017 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2018 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2019 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2020 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2021 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2022 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2023 };
2024 
2025 static const uint8_t ms_hmac_digest1[] = {
2026 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2027 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2028 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2029 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2030 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2031 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2032 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2033 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2034 };
2035 /* End Session 1  */
2036 /* Begin Session 2 */
2037 static  uint8_t ms_aes_cbc_key2[] = {
2038 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2039 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2040 };
2041 
2042 static  uint8_t ms_aes_cbc_iv2[] = {
2043 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2044 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2045 };
2046 
2047 static const uint8_t ms_aes_cbc_cipher2[] = {
2048 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2049 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2050 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2051 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2052 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2053 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2054 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2055 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2056 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2057 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2058 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2059 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2060 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2061 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2062 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2063 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2064 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2065 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2066 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2067 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2068 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2069 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2070 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2071 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2072 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2073 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2074 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2075 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2076 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2077 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2078 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2079 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2080 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2081 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2082 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2083 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2084 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2085 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2086 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2087 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2088 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2089 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2090 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2091 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2092 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2093 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2094 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2095 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2096 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2097 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2098 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2099 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2100 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2101 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2102 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2103 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2104 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2105 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2106 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2107 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2108 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2109 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2110 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2111 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2112 };
2113 
2114 static  uint8_t ms_hmac_key2[] = {
2115 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2116 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2117 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2118 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2119 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2120 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2121 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2122 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2123 };
2124 
2125 static const uint8_t ms_hmac_digest2[] = {
2126 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2127 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2128 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2129 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2130 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2131 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2132 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2133 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2134 };
2135 
2136 /* End Session 2 */
2137 
2138 
2139 static int
2140 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2141 {
2142 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2143 	struct crypto_unittest_params *ut_params = &unittest_params;
2144 	/* Verify the capabilities */
2145 	struct rte_cryptodev_sym_capability_idx cap_idx;
2146 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2147 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2148 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2149 			&cap_idx) == NULL)
2150 		return TEST_SKIPPED;
2151 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2152 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2153 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2154 			&cap_idx) == NULL)
2155 		return TEST_SKIPPED;
2156 
2157 	/* Generate test mbuf data and space for digest */
2158 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2159 			catch_22_quote,	QUOTE_512_BYTES, 0);
2160 
2161 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2162 			DIGEST_BYTE_LENGTH_SHA1);
2163 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2164 
2165 	/* Setup Cipher Parameters */
2166 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2167 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2168 
2169 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2170 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2171 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2172 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2173 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2174 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2175 
2176 	/* Setup HMAC Parameters */
2177 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2178 
2179 	ut_params->auth_xform.next = NULL;
2180 
2181 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2182 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2183 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2184 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2185 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2186 
2187 	rte_errno = 0;
2188 	ut_params->sess = rte_cryptodev_sym_session_create(
2189 			ts_params->valid_devs[0], &ut_params->cipher_xform,
2190 			ts_params->session_mpool);
2191 	if (rte_errno == ENOTSUP)
2192 		return TEST_SKIPPED;
2193 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2194 
2195 	/* Generate crypto op data structure */
2196 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2197 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2198 	TEST_ASSERT_NOT_NULL(ut_params->op,
2199 			"Failed to allocate symmetric crypto operation struct");
2200 
2201 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2202 
2203 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2204 
2205 	/* set crypto operation source mbuf */
2206 	sym_op->m_src = ut_params->ibuf;
2207 
2208 	/* Set crypto operation authentication parameters */
2209 	sym_op->auth.digest.data = ut_params->digest;
2210 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2211 			ut_params->ibuf, QUOTE_512_BYTES);
2212 
2213 	sym_op->auth.data.offset = 0;
2214 	sym_op->auth.data.length = QUOTE_512_BYTES;
2215 
2216 	/* Copy IV at the end of the crypto operation */
2217 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2218 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2219 
2220 	/* Set crypto operation cipher parameters */
2221 	sym_op->cipher.data.offset = 0;
2222 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2223 
2224 	/* Process crypto operation */
2225 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2226 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2227 			ut_params->op);
2228 	else
2229 		TEST_ASSERT_NOT_NULL(
2230 			process_crypto_request(ts_params->valid_devs[0],
2231 				ut_params->op),
2232 				"failed to process sym crypto op");
2233 
2234 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2235 			"crypto op processing failed");
2236 
2237 	/* Validate obuf */
2238 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2239 			uint8_t *);
2240 
2241 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2242 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2243 			QUOTE_512_BYTES,
2244 			"ciphertext data not as expected");
2245 
2246 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2247 
2248 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2249 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2250 			gbl_driver_id == rte_cryptodev_driver_id_get(
2251 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2252 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2253 					DIGEST_BYTE_LENGTH_SHA1,
2254 			"Generated digest data not as expected");
2255 
2256 	return TEST_SUCCESS;
2257 }
2258 
2259 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2260 
2261 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2262 
2263 static uint8_t hmac_sha512_key[] = {
2264 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2265 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2266 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2267 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2268 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2269 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2270 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2271 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2272 
2273 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2274 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2275 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2276 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2277 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2278 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2279 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2280 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2281 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2282 
2283 
2284 
2285 static int
2286 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2287 		struct crypto_unittest_params *ut_params,
2288 		uint8_t *cipher_key,
2289 		uint8_t *hmac_key);
2290 
2291 static int
2292 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2293 		struct crypto_unittest_params *ut_params,
2294 		struct crypto_testsuite_params *ts_params,
2295 		const uint8_t *cipher,
2296 		const uint8_t *digest,
2297 		const uint8_t *iv);
2298 
2299 
2300 static int
2301 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2302 		struct crypto_unittest_params *ut_params,
2303 		uint8_t *cipher_key,
2304 		uint8_t *hmac_key)
2305 {
2306 
2307 	/* Setup Cipher Parameters */
2308 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2309 	ut_params->cipher_xform.next = NULL;
2310 
2311 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2312 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2313 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2314 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2315 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2316 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2317 
2318 	/* Setup HMAC Parameters */
2319 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2320 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2321 
2322 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2323 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2324 	ut_params->auth_xform.auth.key.data = hmac_key;
2325 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2326 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2327 
2328 	return TEST_SUCCESS;
2329 }
2330 
2331 
2332 static int
2333 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2334 		struct crypto_unittest_params *ut_params,
2335 		struct crypto_testsuite_params *ts_params,
2336 		const uint8_t *cipher,
2337 		const uint8_t *digest,
2338 		const uint8_t *iv)
2339 {
2340 	/* Generate test mbuf data and digest */
2341 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2342 			(const char *)
2343 			cipher,
2344 			QUOTE_512_BYTES, 0);
2345 
2346 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2347 			DIGEST_BYTE_LENGTH_SHA512);
2348 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2349 
2350 	rte_memcpy(ut_params->digest,
2351 			digest,
2352 			DIGEST_BYTE_LENGTH_SHA512);
2353 
2354 	/* Generate Crypto op data structure */
2355 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2356 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2357 	TEST_ASSERT_NOT_NULL(ut_params->op,
2358 			"Failed to allocate symmetric crypto operation struct");
2359 
2360 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2361 
2362 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2363 
2364 	/* set crypto operation source mbuf */
2365 	sym_op->m_src = ut_params->ibuf;
2366 
2367 	sym_op->auth.digest.data = ut_params->digest;
2368 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2369 			ut_params->ibuf, QUOTE_512_BYTES);
2370 
2371 	sym_op->auth.data.offset = 0;
2372 	sym_op->auth.data.length = QUOTE_512_BYTES;
2373 
2374 	/* Copy IV at the end of the crypto operation */
2375 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2376 			iv, CIPHER_IV_LENGTH_AES_CBC);
2377 
2378 	sym_op->cipher.data.offset = 0;
2379 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2380 
2381 	/* Process crypto operation */
2382 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2383 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2384 			ut_params->op);
2385 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2386 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2387 				ut_params->op, 1, 1, 0, 0);
2388 	else
2389 		TEST_ASSERT_NOT_NULL(
2390 				process_crypto_request(ts_params->valid_devs[0],
2391 					ut_params->op),
2392 					"failed to process sym crypto op");
2393 
2394 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2395 			"crypto op processing failed");
2396 
2397 	ut_params->obuf = ut_params->op->sym->m_src;
2398 
2399 	/* Validate obuf */
2400 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2401 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2402 			catch_22_quote,
2403 			QUOTE_512_BYTES,
2404 			"Plaintext data not as expected");
2405 
2406 	/* Validate obuf */
2407 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2408 			"Digest verification failed");
2409 
2410 	return TEST_SUCCESS;
2411 }
2412 
2413 /* ***** SNOW 3G Tests ***** */
2414 static int
2415 create_wireless_algo_hash_session(uint8_t dev_id,
2416 	const uint8_t *key, const uint8_t key_len,
2417 	const uint8_t iv_len, const uint8_t auth_len,
2418 	enum rte_crypto_auth_operation op,
2419 	enum rte_crypto_auth_algorithm algo)
2420 {
2421 	uint8_t hash_key[key_len];
2422 
2423 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2424 	struct crypto_unittest_params *ut_params = &unittest_params;
2425 
2426 	memcpy(hash_key, key, key_len);
2427 
2428 	debug_hexdump(stdout, "key:", key, key_len);
2429 
2430 	/* Setup Authentication Parameters */
2431 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2432 	ut_params->auth_xform.next = NULL;
2433 
2434 	ut_params->auth_xform.auth.op = op;
2435 	ut_params->auth_xform.auth.algo = algo;
2436 	ut_params->auth_xform.auth.key.length = key_len;
2437 	ut_params->auth_xform.auth.key.data = hash_key;
2438 	ut_params->auth_xform.auth.digest_length = auth_len;
2439 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2440 	ut_params->auth_xform.auth.iv.length = iv_len;
2441 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2442 			&ut_params->auth_xform, ts_params->session_mpool);
2443 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2444 		return TEST_SKIPPED;
2445 
2446 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2447 	return 0;
2448 }
2449 
2450 static int
2451 create_wireless_algo_cipher_session(uint8_t dev_id,
2452 			enum rte_crypto_cipher_operation op,
2453 			enum rte_crypto_cipher_algorithm algo,
2454 			const uint8_t *key, const uint8_t key_len,
2455 			uint8_t iv_len)
2456 {
2457 	uint8_t cipher_key[key_len];
2458 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2459 	struct crypto_unittest_params *ut_params = &unittest_params;
2460 
2461 	memcpy(cipher_key, key, key_len);
2462 
2463 	/* Setup Cipher Parameters */
2464 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2465 	ut_params->cipher_xform.next = NULL;
2466 
2467 	ut_params->cipher_xform.cipher.algo = algo;
2468 	ut_params->cipher_xform.cipher.op = op;
2469 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2470 	ut_params->cipher_xform.cipher.key.length = key_len;
2471 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2472 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2473 
2474 	debug_hexdump(stdout, "key:", key, key_len);
2475 
2476 	/* Create Crypto session */
2477 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2478 			&ut_params->cipher_xform, ts_params->session_mpool);
2479 
2480 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2481 		return TEST_SKIPPED;
2482 
2483 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2484 	return 0;
2485 }
2486 
2487 static int
2488 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2489 			unsigned int cipher_len,
2490 			unsigned int cipher_offset)
2491 {
2492 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2493 	struct crypto_unittest_params *ut_params = &unittest_params;
2494 
2495 	/* Generate Crypto op data structure */
2496 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2497 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2498 	TEST_ASSERT_NOT_NULL(ut_params->op,
2499 				"Failed to allocate pktmbuf offload");
2500 
2501 	/* Set crypto operation data parameters */
2502 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2503 
2504 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2505 
2506 	/* set crypto operation source mbuf */
2507 	sym_op->m_src = ut_params->ibuf;
2508 
2509 	/* iv */
2510 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2511 			iv, iv_len);
2512 	sym_op->cipher.data.length = cipher_len;
2513 	sym_op->cipher.data.offset = cipher_offset;
2514 	return 0;
2515 }
2516 
2517 static int
2518 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2519 			unsigned int cipher_len,
2520 			unsigned int cipher_offset)
2521 {
2522 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2523 	struct crypto_unittest_params *ut_params = &unittest_params;
2524 
2525 	/* Generate Crypto op data structure */
2526 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2527 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2528 	TEST_ASSERT_NOT_NULL(ut_params->op,
2529 				"Failed to allocate pktmbuf offload");
2530 
2531 	/* Set crypto operation data parameters */
2532 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2533 
2534 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2535 
2536 	/* set crypto operation source mbuf */
2537 	sym_op->m_src = ut_params->ibuf;
2538 	sym_op->m_dst = ut_params->obuf;
2539 
2540 	/* iv */
2541 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2542 			iv, iv_len);
2543 	sym_op->cipher.data.length = cipher_len;
2544 	sym_op->cipher.data.offset = cipher_offset;
2545 	return 0;
2546 }
2547 
2548 static int
2549 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2550 		enum rte_crypto_cipher_operation cipher_op,
2551 		enum rte_crypto_auth_operation auth_op,
2552 		enum rte_crypto_auth_algorithm auth_algo,
2553 		enum rte_crypto_cipher_algorithm cipher_algo,
2554 		const uint8_t *key, uint8_t key_len,
2555 		uint8_t auth_iv_len, uint8_t auth_len,
2556 		uint8_t cipher_iv_len)
2557 
2558 {
2559 	uint8_t cipher_auth_key[key_len];
2560 
2561 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2562 	struct crypto_unittest_params *ut_params = &unittest_params;
2563 
2564 	memcpy(cipher_auth_key, key, key_len);
2565 
2566 	/* Setup Authentication Parameters */
2567 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2568 	ut_params->auth_xform.next = NULL;
2569 
2570 	ut_params->auth_xform.auth.op = auth_op;
2571 	ut_params->auth_xform.auth.algo = auth_algo;
2572 	ut_params->auth_xform.auth.key.length = key_len;
2573 	/* Hash key = cipher key */
2574 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2575 	ut_params->auth_xform.auth.digest_length = auth_len;
2576 	/* Auth IV will be after cipher IV */
2577 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2578 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2579 
2580 	/* Setup Cipher Parameters */
2581 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2582 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2583 
2584 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2585 	ut_params->cipher_xform.cipher.op = cipher_op;
2586 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2587 	ut_params->cipher_xform.cipher.key.length = key_len;
2588 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2589 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2590 
2591 	debug_hexdump(stdout, "key:", key, key_len);
2592 
2593 	/* Create Crypto session*/
2594 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2595 			&ut_params->cipher_xform, ts_params->session_mpool);
2596 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2597 		return TEST_SKIPPED;
2598 
2599 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2600 	return 0;
2601 }
2602 
2603 static int
2604 create_wireless_cipher_auth_session(uint8_t dev_id,
2605 		enum rte_crypto_cipher_operation cipher_op,
2606 		enum rte_crypto_auth_operation auth_op,
2607 		enum rte_crypto_auth_algorithm auth_algo,
2608 		enum rte_crypto_cipher_algorithm cipher_algo,
2609 		const struct wireless_test_data *tdata)
2610 {
2611 	const uint8_t key_len = tdata->key.len;
2612 	uint8_t cipher_auth_key[key_len];
2613 
2614 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2615 	struct crypto_unittest_params *ut_params = &unittest_params;
2616 	const uint8_t *key = tdata->key.data;
2617 	const uint8_t auth_len = tdata->digest.len;
2618 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2619 	uint8_t auth_iv_len = tdata->auth_iv.len;
2620 
2621 	memcpy(cipher_auth_key, key, key_len);
2622 
2623 	/* Setup Authentication Parameters */
2624 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2625 	ut_params->auth_xform.next = NULL;
2626 
2627 	ut_params->auth_xform.auth.op = auth_op;
2628 	ut_params->auth_xform.auth.algo = auth_algo;
2629 	ut_params->auth_xform.auth.key.length = key_len;
2630 	/* Hash key = cipher key */
2631 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2632 	ut_params->auth_xform.auth.digest_length = auth_len;
2633 	/* Auth IV will be after cipher IV */
2634 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2635 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2636 
2637 	/* Setup Cipher Parameters */
2638 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2639 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2640 
2641 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2642 	ut_params->cipher_xform.cipher.op = cipher_op;
2643 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2644 	ut_params->cipher_xform.cipher.key.length = key_len;
2645 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2646 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2647 
2648 
2649 	debug_hexdump(stdout, "key:", key, key_len);
2650 
2651 	/* Create Crypto session*/
2652 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2653 			&ut_params->cipher_xform, ts_params->session_mpool);
2654 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2655 		return TEST_SKIPPED;
2656 
2657 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2658 	return 0;
2659 }
2660 
2661 static int
2662 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2663 		const struct wireless_test_data *tdata)
2664 {
2665 	return create_wireless_cipher_auth_session(dev_id,
2666 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2667 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2668 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2669 }
2670 
2671 static int
2672 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2673 		enum rte_crypto_cipher_operation cipher_op,
2674 		enum rte_crypto_auth_operation auth_op,
2675 		enum rte_crypto_auth_algorithm auth_algo,
2676 		enum rte_crypto_cipher_algorithm cipher_algo,
2677 		const uint8_t *key, const uint8_t key_len,
2678 		uint8_t auth_iv_len, uint8_t auth_len,
2679 		uint8_t cipher_iv_len)
2680 {
2681 	uint8_t auth_cipher_key[key_len];
2682 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2683 	struct crypto_unittest_params *ut_params = &unittest_params;
2684 
2685 	memcpy(auth_cipher_key, key, key_len);
2686 
2687 	/* Setup Authentication Parameters */
2688 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2689 	ut_params->auth_xform.auth.op = auth_op;
2690 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2691 	ut_params->auth_xform.auth.algo = auth_algo;
2692 	ut_params->auth_xform.auth.key.length = key_len;
2693 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2694 	ut_params->auth_xform.auth.digest_length = auth_len;
2695 	/* Auth IV will be after cipher IV */
2696 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2697 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2698 
2699 	/* Setup Cipher Parameters */
2700 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2701 	ut_params->cipher_xform.next = NULL;
2702 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2703 	ut_params->cipher_xform.cipher.op = cipher_op;
2704 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2705 	ut_params->cipher_xform.cipher.key.length = key_len;
2706 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2707 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2708 
2709 	debug_hexdump(stdout, "key:", key, key_len);
2710 
2711 	/* Create Crypto session*/
2712 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2713 		ut_params->auth_xform.next = NULL;
2714 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2715 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2716 			&ut_params->cipher_xform, ts_params->session_mpool);
2717 	} else
2718 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2719 			&ut_params->auth_xform, ts_params->session_mpool);
2720 
2721 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
2722 		return TEST_SKIPPED;
2723 
2724 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2725 
2726 	return 0;
2727 }
2728 
2729 static int
2730 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2731 		unsigned int auth_tag_len,
2732 		const uint8_t *iv, unsigned int iv_len,
2733 		unsigned int data_pad_len,
2734 		enum rte_crypto_auth_operation op,
2735 		unsigned int auth_len, unsigned int auth_offset)
2736 {
2737 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2738 
2739 	struct crypto_unittest_params *ut_params = &unittest_params;
2740 
2741 	/* Generate Crypto op data structure */
2742 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2743 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2744 	TEST_ASSERT_NOT_NULL(ut_params->op,
2745 		"Failed to allocate pktmbuf offload");
2746 
2747 	/* Set crypto operation data parameters */
2748 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2749 
2750 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2751 
2752 	/* set crypto operation source mbuf */
2753 	sym_op->m_src = ut_params->ibuf;
2754 
2755 	/* iv */
2756 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2757 			iv, iv_len);
2758 	/* digest */
2759 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2760 					ut_params->ibuf, auth_tag_len);
2761 
2762 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2763 				"no room to append auth tag");
2764 	ut_params->digest = sym_op->auth.digest.data;
2765 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2766 			ut_params->ibuf, data_pad_len);
2767 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2768 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2769 	else
2770 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2771 
2772 	debug_hexdump(stdout, "digest:",
2773 		sym_op->auth.digest.data,
2774 		auth_tag_len);
2775 
2776 	sym_op->auth.data.length = auth_len;
2777 	sym_op->auth.data.offset = auth_offset;
2778 
2779 	return 0;
2780 }
2781 
2782 static int
2783 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2784 	enum rte_crypto_auth_operation op)
2785 {
2786 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2787 	struct crypto_unittest_params *ut_params = &unittest_params;
2788 
2789 	const uint8_t *auth_tag = tdata->digest.data;
2790 	const unsigned int auth_tag_len = tdata->digest.len;
2791 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2792 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2793 
2794 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2795 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2796 	const uint8_t *auth_iv = tdata->auth_iv.data;
2797 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2798 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2799 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2800 
2801 	/* Generate Crypto op data structure */
2802 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2803 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2804 	TEST_ASSERT_NOT_NULL(ut_params->op,
2805 			"Failed to allocate pktmbuf offload");
2806 	/* Set crypto operation data parameters */
2807 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2808 
2809 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2810 
2811 	/* set crypto operation source mbuf */
2812 	sym_op->m_src = ut_params->ibuf;
2813 
2814 	/* digest */
2815 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2816 			ut_params->ibuf, auth_tag_len);
2817 
2818 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2819 			"no room to append auth tag");
2820 	ut_params->digest = sym_op->auth.digest.data;
2821 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2822 			ut_params->ibuf, data_pad_len);
2823 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2824 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2825 	else
2826 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2827 
2828 	debug_hexdump(stdout, "digest:",
2829 		sym_op->auth.digest.data,
2830 		auth_tag_len);
2831 
2832 	/* Copy cipher and auth IVs at the end of the crypto operation */
2833 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2834 						IV_OFFSET);
2835 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2836 	iv_ptr += cipher_iv_len;
2837 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2838 
2839 	sym_op->cipher.data.length = cipher_len;
2840 	sym_op->cipher.data.offset = 0;
2841 	sym_op->auth.data.length = auth_len;
2842 	sym_op->auth.data.offset = 0;
2843 
2844 	return 0;
2845 }
2846 
2847 static int
2848 create_zuc_cipher_hash_generate_operation(
2849 		const struct wireless_test_data *tdata)
2850 {
2851 	return create_wireless_cipher_hash_operation(tdata,
2852 		RTE_CRYPTO_AUTH_OP_GENERATE);
2853 }
2854 
2855 static int
2856 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2857 		const unsigned auth_tag_len,
2858 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2859 		unsigned data_pad_len,
2860 		enum rte_crypto_auth_operation op,
2861 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2862 		const unsigned cipher_len, const unsigned cipher_offset,
2863 		const unsigned auth_len, const unsigned auth_offset)
2864 {
2865 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2866 	struct crypto_unittest_params *ut_params = &unittest_params;
2867 
2868 	enum rte_crypto_cipher_algorithm cipher_algo =
2869 			ut_params->cipher_xform.cipher.algo;
2870 	enum rte_crypto_auth_algorithm auth_algo =
2871 			ut_params->auth_xform.auth.algo;
2872 
2873 	/* Generate Crypto op data structure */
2874 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2875 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2876 	TEST_ASSERT_NOT_NULL(ut_params->op,
2877 			"Failed to allocate pktmbuf offload");
2878 	/* Set crypto operation data parameters */
2879 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2880 
2881 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2882 
2883 	/* set crypto operation source mbuf */
2884 	sym_op->m_src = ut_params->ibuf;
2885 
2886 	/* digest */
2887 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2888 			ut_params->ibuf, auth_tag_len);
2889 
2890 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2891 			"no room to append auth tag");
2892 	ut_params->digest = sym_op->auth.digest.data;
2893 
2894 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2895 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2896 				ut_params->ibuf, data_pad_len);
2897 	} else {
2898 		struct rte_mbuf *m = ut_params->ibuf;
2899 		unsigned int offset = data_pad_len;
2900 
2901 		while (offset > m->data_len && m->next != NULL) {
2902 			offset -= m->data_len;
2903 			m = m->next;
2904 		}
2905 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2906 			m, offset);
2907 	}
2908 
2909 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2910 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2911 	else
2912 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2913 
2914 	debug_hexdump(stdout, "digest:",
2915 		sym_op->auth.digest.data,
2916 		auth_tag_len);
2917 
2918 	/* Copy cipher and auth IVs at the end of the crypto operation */
2919 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2920 						IV_OFFSET);
2921 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2922 	iv_ptr += cipher_iv_len;
2923 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2924 
2925 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2926 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2927 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2928 		sym_op->cipher.data.length = cipher_len;
2929 		sym_op->cipher.data.offset = cipher_offset;
2930 	} else {
2931 		sym_op->cipher.data.length = cipher_len >> 3;
2932 		sym_op->cipher.data.offset = cipher_offset >> 3;
2933 	}
2934 
2935 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2936 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2937 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2938 		sym_op->auth.data.length = auth_len;
2939 		sym_op->auth.data.offset = auth_offset;
2940 	} else {
2941 		sym_op->auth.data.length = auth_len >> 3;
2942 		sym_op->auth.data.offset = auth_offset >> 3;
2943 	}
2944 
2945 	return 0;
2946 }
2947 
2948 static int
2949 create_wireless_algo_auth_cipher_operation(
2950 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2951 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2952 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2953 		unsigned int data_pad_len,
2954 		unsigned int cipher_len, unsigned int cipher_offset,
2955 		unsigned int auth_len, unsigned int auth_offset,
2956 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2957 {
2958 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2959 	struct crypto_unittest_params *ut_params = &unittest_params;
2960 
2961 	enum rte_crypto_cipher_algorithm cipher_algo =
2962 			ut_params->cipher_xform.cipher.algo;
2963 	enum rte_crypto_auth_algorithm auth_algo =
2964 			ut_params->auth_xform.auth.algo;
2965 
2966 	/* Generate Crypto op data structure */
2967 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2968 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2969 	TEST_ASSERT_NOT_NULL(ut_params->op,
2970 			"Failed to allocate pktmbuf offload");
2971 
2972 	/* Set crypto operation data parameters */
2973 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2974 
2975 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2976 
2977 	/* set crypto operation mbufs */
2978 	sym_op->m_src = ut_params->ibuf;
2979 	if (op_mode == OUT_OF_PLACE)
2980 		sym_op->m_dst = ut_params->obuf;
2981 
2982 	/* digest */
2983 	if (!do_sgl) {
2984 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2985 			(op_mode == IN_PLACE ?
2986 				ut_params->ibuf : ut_params->obuf),
2987 			uint8_t *, data_pad_len);
2988 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2989 			(op_mode == IN_PLACE ?
2990 				ut_params->ibuf : ut_params->obuf),
2991 			data_pad_len);
2992 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2993 	} else {
2994 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
2995 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
2996 				sym_op->m_src : sym_op->m_dst);
2997 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
2998 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
2999 			sgl_buf = sgl_buf->next;
3000 		}
3001 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3002 				uint8_t *, remaining_off);
3003 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3004 				remaining_off);
3005 		memset(sym_op->auth.digest.data, 0, remaining_off);
3006 		while (sgl_buf->next != NULL) {
3007 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3008 				0, rte_pktmbuf_data_len(sgl_buf));
3009 			sgl_buf = sgl_buf->next;
3010 		}
3011 	}
3012 
3013 	/* Copy digest for the verification */
3014 	if (verify)
3015 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3016 
3017 	/* Copy cipher and auth IVs at the end of the crypto operation */
3018 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3019 			ut_params->op, uint8_t *, IV_OFFSET);
3020 
3021 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3022 	iv_ptr += cipher_iv_len;
3023 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3024 
3025 	/* Only copy over the offset data needed from src to dst in OOP,
3026 	 * if the auth and cipher offsets are not aligned
3027 	 */
3028 	if (op_mode == OUT_OF_PLACE) {
3029 		if (cipher_offset > auth_offset)
3030 			rte_memcpy(
3031 				rte_pktmbuf_mtod_offset(
3032 					sym_op->m_dst,
3033 					uint8_t *, auth_offset >> 3),
3034 				rte_pktmbuf_mtod_offset(
3035 					sym_op->m_src,
3036 					uint8_t *, auth_offset >> 3),
3037 				((cipher_offset >> 3) - (auth_offset >> 3)));
3038 	}
3039 
3040 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3041 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3042 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3043 		sym_op->cipher.data.length = cipher_len;
3044 		sym_op->cipher.data.offset = cipher_offset;
3045 	} else {
3046 		sym_op->cipher.data.length = cipher_len >> 3;
3047 		sym_op->cipher.data.offset = cipher_offset >> 3;
3048 	}
3049 
3050 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3051 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3052 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3053 		sym_op->auth.data.length = auth_len;
3054 		sym_op->auth.data.offset = auth_offset;
3055 	} else {
3056 		sym_op->auth.data.length = auth_len >> 3;
3057 		sym_op->auth.data.offset = auth_offset >> 3;
3058 	}
3059 
3060 	return 0;
3061 }
3062 
3063 static int
3064 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3065 {
3066 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3067 	struct crypto_unittest_params *ut_params = &unittest_params;
3068 
3069 	int retval;
3070 	unsigned plaintext_pad_len;
3071 	unsigned plaintext_len;
3072 	uint8_t *plaintext;
3073 	struct rte_cryptodev_info dev_info;
3074 
3075 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3076 	uint64_t feat_flags = dev_info.feature_flags;
3077 
3078 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3079 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3080 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3081 		return TEST_SKIPPED;
3082 	}
3083 
3084 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3085 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3086 		printf("Device doesn't support RAW data-path APIs.\n");
3087 		return TEST_SKIPPED;
3088 	}
3089 
3090 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3091 		return TEST_SKIPPED;
3092 
3093 	/* Verify the capabilities */
3094 	struct rte_cryptodev_sym_capability_idx cap_idx;
3095 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3096 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3097 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3098 			&cap_idx) == NULL)
3099 		return TEST_SKIPPED;
3100 
3101 	/* Create SNOW 3G session */
3102 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3103 			tdata->key.data, tdata->key.len,
3104 			tdata->auth_iv.len, tdata->digest.len,
3105 			RTE_CRYPTO_AUTH_OP_GENERATE,
3106 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3107 	if (retval < 0)
3108 		return retval;
3109 
3110 	/* alloc mbuf and set payload */
3111 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3112 
3113 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3114 	rte_pktmbuf_tailroom(ut_params->ibuf));
3115 
3116 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3117 	/* Append data which is padded to a multiple of */
3118 	/* the algorithms block size */
3119 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3120 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3121 				plaintext_pad_len);
3122 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3123 
3124 	/* Create SNOW 3G operation */
3125 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3126 			tdata->auth_iv.data, tdata->auth_iv.len,
3127 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3128 			tdata->validAuthLenInBits.len,
3129 			0);
3130 	if (retval < 0)
3131 		return retval;
3132 
3133 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3134 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3135 				ut_params->op, 0, 1, 1, 0);
3136 	else
3137 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3138 				ut_params->op);
3139 	ut_params->obuf = ut_params->op->sym->m_src;
3140 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3141 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3142 			+ plaintext_pad_len;
3143 
3144 	/* Validate obuf */
3145 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3146 	ut_params->digest,
3147 	tdata->digest.data,
3148 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3149 	"SNOW 3G Generated auth tag not as expected");
3150 
3151 	return 0;
3152 }
3153 
3154 static int
3155 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3156 {
3157 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3158 	struct crypto_unittest_params *ut_params = &unittest_params;
3159 
3160 	int retval;
3161 	unsigned plaintext_pad_len;
3162 	unsigned plaintext_len;
3163 	uint8_t *plaintext;
3164 	struct rte_cryptodev_info dev_info;
3165 
3166 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3167 	uint64_t feat_flags = dev_info.feature_flags;
3168 
3169 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3170 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3171 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3172 		return TEST_SKIPPED;
3173 	}
3174 
3175 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3176 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3177 		printf("Device doesn't support RAW data-path APIs.\n");
3178 		return TEST_SKIPPED;
3179 	}
3180 
3181 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3182 		return TEST_SKIPPED;
3183 
3184 	/* Verify the capabilities */
3185 	struct rte_cryptodev_sym_capability_idx cap_idx;
3186 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3187 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3188 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3189 			&cap_idx) == NULL)
3190 		return TEST_SKIPPED;
3191 
3192 	/* Create SNOW 3G session */
3193 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3194 				tdata->key.data, tdata->key.len,
3195 				tdata->auth_iv.len, tdata->digest.len,
3196 				RTE_CRYPTO_AUTH_OP_VERIFY,
3197 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3198 	if (retval < 0)
3199 		return retval;
3200 	/* alloc mbuf and set payload */
3201 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3202 
3203 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3204 	rte_pktmbuf_tailroom(ut_params->ibuf));
3205 
3206 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3207 	/* Append data which is padded to a multiple of */
3208 	/* the algorithms block size */
3209 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3210 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3211 				plaintext_pad_len);
3212 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3213 
3214 	/* Create SNOW 3G operation */
3215 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3216 			tdata->digest.len,
3217 			tdata->auth_iv.data, tdata->auth_iv.len,
3218 			plaintext_pad_len,
3219 			RTE_CRYPTO_AUTH_OP_VERIFY,
3220 			tdata->validAuthLenInBits.len,
3221 			0);
3222 	if (retval < 0)
3223 		return retval;
3224 
3225 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3226 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3227 				ut_params->op, 0, 1, 1, 0);
3228 	else
3229 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3230 				ut_params->op);
3231 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3232 	ut_params->obuf = ut_params->op->sym->m_src;
3233 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3234 				+ plaintext_pad_len;
3235 
3236 	/* Validate obuf */
3237 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3238 		return 0;
3239 	else
3240 		return -1;
3241 
3242 	return 0;
3243 }
3244 
3245 static int
3246 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3247 {
3248 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3249 	struct crypto_unittest_params *ut_params = &unittest_params;
3250 
3251 	int retval;
3252 	unsigned plaintext_pad_len;
3253 	unsigned plaintext_len;
3254 	uint8_t *plaintext;
3255 	struct rte_cryptodev_info dev_info;
3256 
3257 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3258 	uint64_t feat_flags = dev_info.feature_flags;
3259 
3260 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3261 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3262 		printf("Device doesn't support RAW data-path APIs.\n");
3263 		return TEST_SKIPPED;
3264 	}
3265 
3266 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3267 		return TEST_SKIPPED;
3268 
3269 	/* Verify the capabilities */
3270 	struct rte_cryptodev_sym_capability_idx cap_idx;
3271 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3272 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3273 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3274 			&cap_idx) == NULL)
3275 		return TEST_SKIPPED;
3276 
3277 	/* Create KASUMI session */
3278 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3279 			tdata->key.data, tdata->key.len,
3280 			0, tdata->digest.len,
3281 			RTE_CRYPTO_AUTH_OP_GENERATE,
3282 			RTE_CRYPTO_AUTH_KASUMI_F9);
3283 	if (retval < 0)
3284 		return retval;
3285 
3286 	/* alloc mbuf and set payload */
3287 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3288 
3289 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3290 	rte_pktmbuf_tailroom(ut_params->ibuf));
3291 
3292 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3293 	/* Append data which is padded to a multiple of */
3294 	/* the algorithms block size */
3295 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3296 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3297 				plaintext_pad_len);
3298 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3299 
3300 	/* Create KASUMI operation */
3301 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3302 			NULL, 0,
3303 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3304 			tdata->plaintext.len,
3305 			0);
3306 	if (retval < 0)
3307 		return retval;
3308 
3309 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3310 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3311 			ut_params->op);
3312 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3313 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3314 				ut_params->op, 0, 1, 1, 0);
3315 	else
3316 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3317 			ut_params->op);
3318 
3319 	ut_params->obuf = ut_params->op->sym->m_src;
3320 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3321 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3322 			+ plaintext_pad_len;
3323 
3324 	/* Validate obuf */
3325 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3326 	ut_params->digest,
3327 	tdata->digest.data,
3328 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3329 	"KASUMI Generated auth tag not as expected");
3330 
3331 	return 0;
3332 }
3333 
3334 static int
3335 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3336 {
3337 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3338 	struct crypto_unittest_params *ut_params = &unittest_params;
3339 
3340 	int retval;
3341 	unsigned plaintext_pad_len;
3342 	unsigned plaintext_len;
3343 	uint8_t *plaintext;
3344 	struct rte_cryptodev_info dev_info;
3345 
3346 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3347 	uint64_t feat_flags = dev_info.feature_flags;
3348 
3349 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3350 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3351 		printf("Device doesn't support RAW data-path APIs.\n");
3352 		return TEST_SKIPPED;
3353 	}
3354 
3355 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3356 		return TEST_SKIPPED;
3357 
3358 	/* Verify the capabilities */
3359 	struct rte_cryptodev_sym_capability_idx cap_idx;
3360 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3361 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3362 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3363 			&cap_idx) == NULL)
3364 		return TEST_SKIPPED;
3365 
3366 	/* Create KASUMI session */
3367 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3368 				tdata->key.data, tdata->key.len,
3369 				0, tdata->digest.len,
3370 				RTE_CRYPTO_AUTH_OP_VERIFY,
3371 				RTE_CRYPTO_AUTH_KASUMI_F9);
3372 	if (retval < 0)
3373 		return retval;
3374 	/* alloc mbuf and set payload */
3375 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3376 
3377 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3378 	rte_pktmbuf_tailroom(ut_params->ibuf));
3379 
3380 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3381 	/* Append data which is padded to a multiple */
3382 	/* of the algorithms block size */
3383 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3384 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3385 				plaintext_pad_len);
3386 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3387 
3388 	/* Create KASUMI operation */
3389 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3390 			tdata->digest.len,
3391 			NULL, 0,
3392 			plaintext_pad_len,
3393 			RTE_CRYPTO_AUTH_OP_VERIFY,
3394 			tdata->plaintext.len,
3395 			0);
3396 	if (retval < 0)
3397 		return retval;
3398 
3399 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3400 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3401 				ut_params->op, 0, 1, 1, 0);
3402 	else
3403 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3404 				ut_params->op);
3405 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3406 	ut_params->obuf = ut_params->op->sym->m_src;
3407 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3408 				+ plaintext_pad_len;
3409 
3410 	/* Validate obuf */
3411 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3412 		return 0;
3413 	else
3414 		return -1;
3415 
3416 	return 0;
3417 }
3418 
3419 static int
3420 test_snow3g_hash_generate_test_case_1(void)
3421 {
3422 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3423 }
3424 
3425 static int
3426 test_snow3g_hash_generate_test_case_2(void)
3427 {
3428 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3429 }
3430 
3431 static int
3432 test_snow3g_hash_generate_test_case_3(void)
3433 {
3434 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3435 }
3436 
3437 static int
3438 test_snow3g_hash_generate_test_case_4(void)
3439 {
3440 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3441 }
3442 
3443 static int
3444 test_snow3g_hash_generate_test_case_5(void)
3445 {
3446 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3447 }
3448 
3449 static int
3450 test_snow3g_hash_generate_test_case_6(void)
3451 {
3452 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3453 }
3454 
3455 static int
3456 test_snow3g_hash_verify_test_case_1(void)
3457 {
3458 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3459 
3460 }
3461 
3462 static int
3463 test_snow3g_hash_verify_test_case_2(void)
3464 {
3465 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3466 }
3467 
3468 static int
3469 test_snow3g_hash_verify_test_case_3(void)
3470 {
3471 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3472 }
3473 
3474 static int
3475 test_snow3g_hash_verify_test_case_4(void)
3476 {
3477 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3478 }
3479 
3480 static int
3481 test_snow3g_hash_verify_test_case_5(void)
3482 {
3483 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3484 }
3485 
3486 static int
3487 test_snow3g_hash_verify_test_case_6(void)
3488 {
3489 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3490 }
3491 
3492 static int
3493 test_kasumi_hash_generate_test_case_1(void)
3494 {
3495 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3496 }
3497 
3498 static int
3499 test_kasumi_hash_generate_test_case_2(void)
3500 {
3501 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3502 }
3503 
3504 static int
3505 test_kasumi_hash_generate_test_case_3(void)
3506 {
3507 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3508 }
3509 
3510 static int
3511 test_kasumi_hash_generate_test_case_4(void)
3512 {
3513 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3514 }
3515 
3516 static int
3517 test_kasumi_hash_generate_test_case_5(void)
3518 {
3519 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3520 }
3521 
3522 static int
3523 test_kasumi_hash_generate_test_case_6(void)
3524 {
3525 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3526 }
3527 
3528 static int
3529 test_kasumi_hash_verify_test_case_1(void)
3530 {
3531 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3532 }
3533 
3534 static int
3535 test_kasumi_hash_verify_test_case_2(void)
3536 {
3537 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3538 }
3539 
3540 static int
3541 test_kasumi_hash_verify_test_case_3(void)
3542 {
3543 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3544 }
3545 
3546 static int
3547 test_kasumi_hash_verify_test_case_4(void)
3548 {
3549 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3550 }
3551 
3552 static int
3553 test_kasumi_hash_verify_test_case_5(void)
3554 {
3555 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3556 }
3557 
3558 static int
3559 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3560 {
3561 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3562 	struct crypto_unittest_params *ut_params = &unittest_params;
3563 
3564 	int retval;
3565 	uint8_t *plaintext, *ciphertext;
3566 	unsigned plaintext_pad_len;
3567 	unsigned plaintext_len;
3568 	struct rte_cryptodev_info dev_info;
3569 
3570 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3571 	uint64_t feat_flags = dev_info.feature_flags;
3572 
3573 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3574 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3575 		printf("Device doesn't support RAW data-path APIs.\n");
3576 		return TEST_SKIPPED;
3577 	}
3578 
3579 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3580 		return TEST_SKIPPED;
3581 
3582 	/* Verify the capabilities */
3583 	struct rte_cryptodev_sym_capability_idx cap_idx;
3584 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3585 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3586 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3587 			&cap_idx) == NULL)
3588 		return TEST_SKIPPED;
3589 
3590 	/* Create KASUMI session */
3591 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3592 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3593 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3594 					tdata->key.data, tdata->key.len,
3595 					tdata->cipher_iv.len);
3596 	if (retval < 0)
3597 		return retval;
3598 
3599 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3600 
3601 	/* Clear mbuf payload */
3602 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3603 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3604 
3605 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3606 	/* Append data which is padded to a multiple */
3607 	/* of the algorithms block size */
3608 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3609 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3610 				plaintext_pad_len);
3611 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3612 
3613 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3614 
3615 	/* Create KASUMI operation */
3616 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3617 				tdata->cipher_iv.len,
3618 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3619 				tdata->validCipherOffsetInBits.len);
3620 	if (retval < 0)
3621 		return retval;
3622 
3623 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3624 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3625 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3626 	else
3627 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3628 				ut_params->op);
3629 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3630 
3631 	ut_params->obuf = ut_params->op->sym->m_dst;
3632 	if (ut_params->obuf)
3633 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3634 	else
3635 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3636 
3637 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3638 
3639 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3640 				(tdata->validCipherOffsetInBits.len >> 3);
3641 	/* Validate obuf */
3642 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3643 		ciphertext,
3644 		reference_ciphertext,
3645 		tdata->validCipherLenInBits.len,
3646 		"KASUMI Ciphertext data not as expected");
3647 	return 0;
3648 }
3649 
3650 static int
3651 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3652 {
3653 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3654 	struct crypto_unittest_params *ut_params = &unittest_params;
3655 
3656 	int retval;
3657 
3658 	unsigned int plaintext_pad_len;
3659 	unsigned int plaintext_len;
3660 
3661 	uint8_t buffer[10000];
3662 	const uint8_t *ciphertext;
3663 
3664 	struct rte_cryptodev_info dev_info;
3665 
3666 	/* Verify the capabilities */
3667 	struct rte_cryptodev_sym_capability_idx cap_idx;
3668 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3669 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3670 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3671 			&cap_idx) == NULL)
3672 		return TEST_SKIPPED;
3673 
3674 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3675 
3676 	uint64_t feat_flags = dev_info.feature_flags;
3677 
3678 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3679 		printf("Device doesn't support in-place scatter-gather. "
3680 				"Test Skipped.\n");
3681 		return TEST_SKIPPED;
3682 	}
3683 
3684 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3685 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3686 		printf("Device doesn't support RAW data-path APIs.\n");
3687 		return TEST_SKIPPED;
3688 	}
3689 
3690 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3691 		return TEST_SKIPPED;
3692 
3693 	/* Create KASUMI session */
3694 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3695 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3696 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3697 					tdata->key.data, tdata->key.len,
3698 					tdata->cipher_iv.len);
3699 	if (retval < 0)
3700 		return retval;
3701 
3702 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3703 
3704 
3705 	/* Append data which is padded to a multiple */
3706 	/* of the algorithms block size */
3707 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3708 
3709 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3710 			plaintext_pad_len, 10, 0);
3711 
3712 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3713 
3714 	/* Create KASUMI operation */
3715 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3716 				tdata->cipher_iv.len,
3717 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3718 				tdata->validCipherOffsetInBits.len);
3719 	if (retval < 0)
3720 		return retval;
3721 
3722 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3723 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3724 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3725 	else
3726 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3727 						ut_params->op);
3728 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3729 
3730 	ut_params->obuf = ut_params->op->sym->m_dst;
3731 
3732 	if (ut_params->obuf)
3733 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3734 				plaintext_len, buffer);
3735 	else
3736 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3737 				tdata->validCipherOffsetInBits.len >> 3,
3738 				plaintext_len, buffer);
3739 
3740 	/* Validate obuf */
3741 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3742 
3743 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3744 				(tdata->validCipherOffsetInBits.len >> 3);
3745 	/* Validate obuf */
3746 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3747 		ciphertext,
3748 		reference_ciphertext,
3749 		tdata->validCipherLenInBits.len,
3750 		"KASUMI Ciphertext data not as expected");
3751 	return 0;
3752 }
3753 
3754 static int
3755 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3756 {
3757 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3758 	struct crypto_unittest_params *ut_params = &unittest_params;
3759 
3760 	int retval;
3761 	uint8_t *plaintext, *ciphertext;
3762 	unsigned plaintext_pad_len;
3763 	unsigned plaintext_len;
3764 
3765 	/* Verify the capabilities */
3766 	struct rte_cryptodev_sym_capability_idx cap_idx;
3767 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3768 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3769 	/* Data-path service does not support OOP */
3770 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3771 			&cap_idx) == NULL)
3772 		return TEST_SKIPPED;
3773 
3774 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3775 		return TEST_SKIPPED;
3776 
3777 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3778 		return TEST_SKIPPED;
3779 
3780 	/* Create KASUMI session */
3781 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3782 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3783 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3784 					tdata->key.data, tdata->key.len,
3785 					tdata->cipher_iv.len);
3786 	if (retval < 0)
3787 		return retval;
3788 
3789 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3790 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3791 
3792 	/* Clear mbuf payload */
3793 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3794 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3795 
3796 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3797 	/* Append data which is padded to a multiple */
3798 	/* of the algorithms block size */
3799 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3800 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3801 				plaintext_pad_len);
3802 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3803 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3804 
3805 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3806 
3807 	/* Create KASUMI operation */
3808 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3809 				tdata->cipher_iv.len,
3810 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3811 				tdata->validCipherOffsetInBits.len);
3812 	if (retval < 0)
3813 		return retval;
3814 
3815 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3816 						ut_params->op);
3817 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3818 
3819 	ut_params->obuf = ut_params->op->sym->m_dst;
3820 	if (ut_params->obuf)
3821 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3822 	else
3823 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3824 
3825 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3826 
3827 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3828 				(tdata->validCipherOffsetInBits.len >> 3);
3829 	/* Validate obuf */
3830 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3831 		ciphertext,
3832 		reference_ciphertext,
3833 		tdata->validCipherLenInBits.len,
3834 		"KASUMI Ciphertext data not as expected");
3835 	return 0;
3836 }
3837 
3838 static int
3839 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3840 {
3841 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3842 	struct crypto_unittest_params *ut_params = &unittest_params;
3843 
3844 	int retval;
3845 	unsigned int plaintext_pad_len;
3846 	unsigned int plaintext_len;
3847 
3848 	const uint8_t *ciphertext;
3849 	uint8_t buffer[2048];
3850 
3851 	struct rte_cryptodev_info dev_info;
3852 
3853 	/* Verify the capabilities */
3854 	struct rte_cryptodev_sym_capability_idx cap_idx;
3855 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3856 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3857 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3858 			&cap_idx) == NULL)
3859 		return TEST_SKIPPED;
3860 
3861 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3862 		return TEST_SKIPPED;
3863 
3864 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3865 		return TEST_SKIPPED;
3866 
3867 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3868 
3869 	uint64_t feat_flags = dev_info.feature_flags;
3870 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3871 		printf("Device doesn't support out-of-place scatter-gather "
3872 				"in both input and output mbufs. "
3873 				"Test Skipped.\n");
3874 		return TEST_SKIPPED;
3875 	}
3876 
3877 	/* Create KASUMI session */
3878 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3879 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3880 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3881 					tdata->key.data, tdata->key.len,
3882 					tdata->cipher_iv.len);
3883 	if (retval < 0)
3884 		return retval;
3885 
3886 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3887 	/* Append data which is padded to a multiple */
3888 	/* of the algorithms block size */
3889 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3890 
3891 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3892 			plaintext_pad_len, 10, 0);
3893 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3894 			plaintext_pad_len, 3, 0);
3895 
3896 	/* Append data which is padded to a multiple */
3897 	/* of the algorithms block size */
3898 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3899 
3900 	/* Create KASUMI operation */
3901 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3902 				tdata->cipher_iv.len,
3903 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3904 				tdata->validCipherOffsetInBits.len);
3905 	if (retval < 0)
3906 		return retval;
3907 
3908 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3909 						ut_params->op);
3910 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3911 
3912 	ut_params->obuf = ut_params->op->sym->m_dst;
3913 	if (ut_params->obuf)
3914 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3915 				plaintext_pad_len, buffer);
3916 	else
3917 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3918 				tdata->validCipherOffsetInBits.len >> 3,
3919 				plaintext_pad_len, buffer);
3920 
3921 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3922 				(tdata->validCipherOffsetInBits.len >> 3);
3923 	/* Validate obuf */
3924 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3925 		ciphertext,
3926 		reference_ciphertext,
3927 		tdata->validCipherLenInBits.len,
3928 		"KASUMI Ciphertext data not as expected");
3929 	return 0;
3930 }
3931 
3932 
3933 static int
3934 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3935 {
3936 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3937 	struct crypto_unittest_params *ut_params = &unittest_params;
3938 
3939 	int retval;
3940 	uint8_t *ciphertext, *plaintext;
3941 	unsigned ciphertext_pad_len;
3942 	unsigned ciphertext_len;
3943 
3944 	/* Verify the capabilities */
3945 	struct rte_cryptodev_sym_capability_idx cap_idx;
3946 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3947 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3948 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3949 			&cap_idx) == NULL)
3950 		return TEST_SKIPPED;
3951 
3952 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3953 		return TEST_SKIPPED;
3954 
3955 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3956 		return TEST_SKIPPED;
3957 
3958 	/* Create KASUMI session */
3959 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3960 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3961 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3962 					tdata->key.data, tdata->key.len,
3963 					tdata->cipher_iv.len);
3964 	if (retval < 0)
3965 		return retval;
3966 
3967 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3968 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3969 
3970 	/* Clear mbuf payload */
3971 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3972 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3973 
3974 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3975 	/* Append data which is padded to a multiple */
3976 	/* of the algorithms block size */
3977 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3978 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3979 				ciphertext_pad_len);
3980 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3981 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3982 
3983 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3984 
3985 	/* Create KASUMI operation */
3986 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3987 				tdata->cipher_iv.len,
3988 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3989 				tdata->validCipherOffsetInBits.len);
3990 	if (retval < 0)
3991 		return retval;
3992 
3993 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3994 						ut_params->op);
3995 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3996 
3997 	ut_params->obuf = ut_params->op->sym->m_dst;
3998 	if (ut_params->obuf)
3999 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4000 	else
4001 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4002 
4003 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4004 
4005 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4006 				(tdata->validCipherOffsetInBits.len >> 3);
4007 	/* Validate obuf */
4008 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4009 		plaintext,
4010 		reference_plaintext,
4011 		tdata->validCipherLenInBits.len,
4012 		"KASUMI Plaintext data not as expected");
4013 	return 0;
4014 }
4015 
4016 static int
4017 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4018 {
4019 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4020 	struct crypto_unittest_params *ut_params = &unittest_params;
4021 
4022 	int retval;
4023 	uint8_t *ciphertext, *plaintext;
4024 	unsigned ciphertext_pad_len;
4025 	unsigned ciphertext_len;
4026 	struct rte_cryptodev_info dev_info;
4027 
4028 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4029 	uint64_t feat_flags = dev_info.feature_flags;
4030 
4031 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4032 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4033 		printf("Device doesn't support RAW data-path APIs.\n");
4034 		return TEST_SKIPPED;
4035 	}
4036 
4037 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4038 		return TEST_SKIPPED;
4039 
4040 	/* Verify the capabilities */
4041 	struct rte_cryptodev_sym_capability_idx cap_idx;
4042 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4043 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4044 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4045 			&cap_idx) == NULL)
4046 		return TEST_SKIPPED;
4047 
4048 	/* Create KASUMI session */
4049 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4050 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4051 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4052 					tdata->key.data, tdata->key.len,
4053 					tdata->cipher_iv.len);
4054 	if (retval < 0)
4055 		return retval;
4056 
4057 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4058 
4059 	/* Clear mbuf payload */
4060 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4061 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4062 
4063 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4064 	/* Append data which is padded to a multiple */
4065 	/* of the algorithms block size */
4066 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4067 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4068 				ciphertext_pad_len);
4069 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4070 
4071 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4072 
4073 	/* Create KASUMI operation */
4074 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4075 			tdata->cipher_iv.len,
4076 			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4077 			tdata->validCipherOffsetInBits.len);
4078 	if (retval < 0)
4079 		return retval;
4080 
4081 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4082 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4083 				ut_params->op, 1, 0, 1, 0);
4084 	else
4085 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4086 						ut_params->op);
4087 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4088 
4089 	ut_params->obuf = ut_params->op->sym->m_dst;
4090 	if (ut_params->obuf)
4091 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4092 	else
4093 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4094 
4095 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4096 
4097 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4098 				(tdata->validCipherOffsetInBits.len >> 3);
4099 	/* Validate obuf */
4100 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4101 		plaintext,
4102 		reference_plaintext,
4103 		tdata->validCipherLenInBits.len,
4104 		"KASUMI Plaintext data not as expected");
4105 	return 0;
4106 }
4107 
4108 static int
4109 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4110 {
4111 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4112 	struct crypto_unittest_params *ut_params = &unittest_params;
4113 
4114 	int retval;
4115 	uint8_t *plaintext, *ciphertext;
4116 	unsigned plaintext_pad_len;
4117 	unsigned plaintext_len;
4118 	struct rte_cryptodev_info dev_info;
4119 
4120 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4121 	uint64_t feat_flags = dev_info.feature_flags;
4122 
4123 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4124 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4125 		printf("Device doesn't support RAW data-path APIs.\n");
4126 		return TEST_SKIPPED;
4127 	}
4128 
4129 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4130 		return TEST_SKIPPED;
4131 
4132 	/* Verify the capabilities */
4133 	struct rte_cryptodev_sym_capability_idx cap_idx;
4134 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4135 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4136 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4137 			&cap_idx) == NULL)
4138 		return TEST_SKIPPED;
4139 
4140 	/* Create SNOW 3G session */
4141 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4142 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4143 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4144 					tdata->key.data, tdata->key.len,
4145 					tdata->cipher_iv.len);
4146 	if (retval < 0)
4147 		return retval;
4148 
4149 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4150 
4151 	/* Clear mbuf payload */
4152 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4153 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4154 
4155 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4156 	/* Append data which is padded to a multiple of */
4157 	/* the algorithms block size */
4158 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4159 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4160 				plaintext_pad_len);
4161 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4162 
4163 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4164 
4165 	/* Create SNOW 3G operation */
4166 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4167 					tdata->cipher_iv.len,
4168 					tdata->validCipherLenInBits.len,
4169 					0);
4170 	if (retval < 0)
4171 		return retval;
4172 
4173 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4174 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4175 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4176 	else
4177 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4178 						ut_params->op);
4179 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4180 
4181 	ut_params->obuf = ut_params->op->sym->m_dst;
4182 	if (ut_params->obuf)
4183 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4184 	else
4185 		ciphertext = plaintext;
4186 
4187 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4188 
4189 	/* Validate obuf */
4190 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4191 		ciphertext,
4192 		tdata->ciphertext.data,
4193 		tdata->validDataLenInBits.len,
4194 		"SNOW 3G Ciphertext data not as expected");
4195 	return 0;
4196 }
4197 
4198 
4199 static int
4200 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4201 {
4202 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4203 	struct crypto_unittest_params *ut_params = &unittest_params;
4204 	uint8_t *plaintext, *ciphertext;
4205 
4206 	int retval;
4207 	unsigned plaintext_pad_len;
4208 	unsigned plaintext_len;
4209 	struct rte_cryptodev_info dev_info;
4210 
4211 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4212 	uint64_t feat_flags = dev_info.feature_flags;
4213 
4214 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4215 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4216 		printf("Device does not support RAW data-path APIs.\n");
4217 		return -ENOTSUP;
4218 	}
4219 
4220 	/* Verify the capabilities */
4221 	struct rte_cryptodev_sym_capability_idx cap_idx;
4222 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4223 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4224 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4225 			&cap_idx) == NULL)
4226 		return TEST_SKIPPED;
4227 
4228 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4229 		return TEST_SKIPPED;
4230 
4231 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4232 		return TEST_SKIPPED;
4233 
4234 	/* Create SNOW 3G session */
4235 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4236 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4237 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4238 					tdata->key.data, tdata->key.len,
4239 					tdata->cipher_iv.len);
4240 	if (retval < 0)
4241 		return retval;
4242 
4243 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4244 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4245 
4246 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4247 			"Failed to allocate input buffer in mempool");
4248 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4249 			"Failed to allocate output buffer in mempool");
4250 
4251 	/* Clear mbuf payload */
4252 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4253 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4254 
4255 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4256 	/* Append data which is padded to a multiple of */
4257 	/* the algorithms block size */
4258 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4259 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4260 				plaintext_pad_len);
4261 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4262 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4263 
4264 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4265 
4266 	/* Create SNOW 3G operation */
4267 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4268 					tdata->cipher_iv.len,
4269 					tdata->validCipherLenInBits.len,
4270 					0);
4271 	if (retval < 0)
4272 		return retval;
4273 
4274 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4275 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4276 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4277 	else
4278 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4279 						ut_params->op);
4280 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4281 
4282 	ut_params->obuf = ut_params->op->sym->m_dst;
4283 	if (ut_params->obuf)
4284 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4285 	else
4286 		ciphertext = plaintext;
4287 
4288 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4289 
4290 	/* Validate obuf */
4291 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4292 		ciphertext,
4293 		tdata->ciphertext.data,
4294 		tdata->validDataLenInBits.len,
4295 		"SNOW 3G Ciphertext data not as expected");
4296 	return 0;
4297 }
4298 
4299 static int
4300 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4301 {
4302 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4303 	struct crypto_unittest_params *ut_params = &unittest_params;
4304 
4305 	int retval;
4306 	unsigned int plaintext_pad_len;
4307 	unsigned int plaintext_len;
4308 	uint8_t buffer[10000];
4309 	const uint8_t *ciphertext;
4310 
4311 	struct rte_cryptodev_info dev_info;
4312 
4313 	/* Verify the capabilities */
4314 	struct rte_cryptodev_sym_capability_idx cap_idx;
4315 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4316 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4317 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4318 			&cap_idx) == NULL)
4319 		return TEST_SKIPPED;
4320 
4321 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4322 		return TEST_SKIPPED;
4323 
4324 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4325 		return TEST_SKIPPED;
4326 
4327 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4328 
4329 	uint64_t feat_flags = dev_info.feature_flags;
4330 
4331 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4332 		printf("Device doesn't support out-of-place scatter-gather "
4333 				"in both input and output mbufs. "
4334 				"Test Skipped.\n");
4335 		return TEST_SKIPPED;
4336 	}
4337 
4338 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4339 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4340 		printf("Device does not support RAW data-path APIs.\n");
4341 		return -ENOTSUP;
4342 	}
4343 
4344 	/* Create SNOW 3G session */
4345 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4346 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4347 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4348 					tdata->key.data, tdata->key.len,
4349 					tdata->cipher_iv.len);
4350 	if (retval < 0)
4351 		return retval;
4352 
4353 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4354 	/* Append data which is padded to a multiple of */
4355 	/* the algorithms block size */
4356 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4357 
4358 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4359 			plaintext_pad_len, 10, 0);
4360 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4361 			plaintext_pad_len, 3, 0);
4362 
4363 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4364 			"Failed to allocate input buffer in mempool");
4365 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4366 			"Failed to allocate output buffer in mempool");
4367 
4368 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4369 
4370 	/* Create SNOW 3G operation */
4371 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4372 					tdata->cipher_iv.len,
4373 					tdata->validCipherLenInBits.len,
4374 					0);
4375 	if (retval < 0)
4376 		return retval;
4377 
4378 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4379 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4380 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4381 	else
4382 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4383 						ut_params->op);
4384 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4385 
4386 	ut_params->obuf = ut_params->op->sym->m_dst;
4387 	if (ut_params->obuf)
4388 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4389 				plaintext_len, buffer);
4390 	else
4391 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4392 				plaintext_len, buffer);
4393 
4394 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4395 
4396 	/* Validate obuf */
4397 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4398 		ciphertext,
4399 		tdata->ciphertext.data,
4400 		tdata->validDataLenInBits.len,
4401 		"SNOW 3G Ciphertext data not as expected");
4402 
4403 	return 0;
4404 }
4405 
4406 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4407 static void
4408 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4409 {
4410 	uint8_t curr_byte, prev_byte;
4411 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4412 	uint8_t lower_byte_mask = (1 << offset) - 1;
4413 	unsigned i;
4414 
4415 	prev_byte = buffer[0];
4416 	buffer[0] >>= offset;
4417 
4418 	for (i = 1; i < length_in_bytes; i++) {
4419 		curr_byte = buffer[i];
4420 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4421 				(curr_byte >> offset);
4422 		prev_byte = curr_byte;
4423 	}
4424 }
4425 
4426 static int
4427 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4428 {
4429 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4430 	struct crypto_unittest_params *ut_params = &unittest_params;
4431 	uint8_t *plaintext, *ciphertext;
4432 	int retval;
4433 	uint32_t plaintext_len;
4434 	uint32_t plaintext_pad_len;
4435 	uint8_t extra_offset = 4;
4436 	uint8_t *expected_ciphertext_shifted;
4437 	struct rte_cryptodev_info dev_info;
4438 
4439 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4440 	uint64_t feat_flags = dev_info.feature_flags;
4441 
4442 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4443 			((tdata->validDataLenInBits.len % 8) != 0)) {
4444 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4445 		return TEST_SKIPPED;
4446 	}
4447 
4448 	/* Verify the capabilities */
4449 	struct rte_cryptodev_sym_capability_idx cap_idx;
4450 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4451 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4452 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4453 			&cap_idx) == NULL)
4454 		return TEST_SKIPPED;
4455 
4456 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4457 		return TEST_SKIPPED;
4458 
4459 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4460 		return TEST_SKIPPED;
4461 
4462 	/* Create SNOW 3G session */
4463 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4464 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4465 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4466 					tdata->key.data, tdata->key.len,
4467 					tdata->cipher_iv.len);
4468 	if (retval < 0)
4469 		return retval;
4470 
4471 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4472 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4473 
4474 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4475 			"Failed to allocate input buffer in mempool");
4476 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4477 			"Failed to allocate output buffer in mempool");
4478 
4479 	/* Clear mbuf payload */
4480 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4481 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4482 
4483 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4484 	/*
4485 	 * Append data which is padded to a
4486 	 * multiple of the algorithms block size
4487 	 */
4488 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4489 
4490 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4491 						plaintext_pad_len);
4492 
4493 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4494 
4495 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4496 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4497 
4498 #ifdef RTE_APP_TEST_DEBUG
4499 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4500 #endif
4501 	/* Create SNOW 3G operation */
4502 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4503 					tdata->cipher_iv.len,
4504 					tdata->validCipherLenInBits.len,
4505 					extra_offset);
4506 	if (retval < 0)
4507 		return retval;
4508 
4509 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4510 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4511 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4512 	else
4513 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4514 						ut_params->op);
4515 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4516 
4517 	ut_params->obuf = ut_params->op->sym->m_dst;
4518 	if (ut_params->obuf)
4519 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4520 	else
4521 		ciphertext = plaintext;
4522 
4523 #ifdef RTE_APP_TEST_DEBUG
4524 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4525 #endif
4526 
4527 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4528 
4529 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4530 			"failed to reserve memory for ciphertext shifted\n");
4531 
4532 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4533 			ceil_byte_length(tdata->ciphertext.len));
4534 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4535 			extra_offset);
4536 	/* Validate obuf */
4537 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4538 		ciphertext,
4539 		expected_ciphertext_shifted,
4540 		tdata->validDataLenInBits.len,
4541 		extra_offset,
4542 		"SNOW 3G Ciphertext data not as expected");
4543 	return 0;
4544 }
4545 
4546 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4547 {
4548 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4549 	struct crypto_unittest_params *ut_params = &unittest_params;
4550 
4551 	int retval;
4552 
4553 	uint8_t *plaintext, *ciphertext;
4554 	unsigned ciphertext_pad_len;
4555 	unsigned ciphertext_len;
4556 	struct rte_cryptodev_info dev_info;
4557 
4558 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4559 	uint64_t feat_flags = dev_info.feature_flags;
4560 
4561 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4562 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4563 		printf("Device doesn't support RAW data-path APIs.\n");
4564 		return TEST_SKIPPED;
4565 	}
4566 
4567 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4568 		return TEST_SKIPPED;
4569 
4570 	/* Verify the capabilities */
4571 	struct rte_cryptodev_sym_capability_idx cap_idx;
4572 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4573 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4574 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4575 			&cap_idx) == NULL)
4576 		return TEST_SKIPPED;
4577 
4578 	/* Create SNOW 3G session */
4579 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4580 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4581 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4582 					tdata->key.data, tdata->key.len,
4583 					tdata->cipher_iv.len);
4584 	if (retval < 0)
4585 		return retval;
4586 
4587 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4588 
4589 	/* Clear mbuf payload */
4590 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4591 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4592 
4593 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4594 	/* Append data which is padded to a multiple of */
4595 	/* the algorithms block size */
4596 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4597 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4598 				ciphertext_pad_len);
4599 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4600 
4601 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4602 
4603 	/* Create SNOW 3G operation */
4604 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4605 					tdata->cipher_iv.len,
4606 					tdata->validCipherLenInBits.len,
4607 					tdata->cipher.offset_bits);
4608 	if (retval < 0)
4609 		return retval;
4610 
4611 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4612 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4613 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4614 	else
4615 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4616 						ut_params->op);
4617 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4618 	ut_params->obuf = ut_params->op->sym->m_dst;
4619 	if (ut_params->obuf)
4620 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4621 	else
4622 		plaintext = ciphertext;
4623 
4624 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4625 
4626 	/* Validate obuf */
4627 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4628 				tdata->plaintext.data,
4629 				tdata->validDataLenInBits.len,
4630 				"SNOW 3G Plaintext data not as expected");
4631 	return 0;
4632 }
4633 
4634 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4635 {
4636 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4637 	struct crypto_unittest_params *ut_params = &unittest_params;
4638 
4639 	int retval;
4640 
4641 	uint8_t *plaintext, *ciphertext;
4642 	unsigned ciphertext_pad_len;
4643 	unsigned ciphertext_len;
4644 	struct rte_cryptodev_info dev_info;
4645 
4646 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4647 	uint64_t feat_flags = dev_info.feature_flags;
4648 
4649 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4650 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4651 		printf("Device does not support RAW data-path APIs.\n");
4652 		return -ENOTSUP;
4653 	}
4654 	/* Verify the capabilities */
4655 	struct rte_cryptodev_sym_capability_idx cap_idx;
4656 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4657 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4658 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4659 			&cap_idx) == NULL)
4660 		return TEST_SKIPPED;
4661 
4662 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4663 		return TEST_SKIPPED;
4664 
4665 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4666 		return TEST_SKIPPED;
4667 
4668 	/* Create SNOW 3G session */
4669 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4670 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4671 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4672 					tdata->key.data, tdata->key.len,
4673 					tdata->cipher_iv.len);
4674 	if (retval < 0)
4675 		return retval;
4676 
4677 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4678 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4679 
4680 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4681 			"Failed to allocate input buffer");
4682 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4683 			"Failed to allocate output buffer");
4684 
4685 	/* Clear mbuf payload */
4686 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4687 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4688 
4689 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4690 		       rte_pktmbuf_tailroom(ut_params->obuf));
4691 
4692 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4693 	/* Append data which is padded to a multiple of */
4694 	/* the algorithms block size */
4695 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4696 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4697 				ciphertext_pad_len);
4698 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4699 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4700 
4701 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4702 
4703 	/* Create SNOW 3G operation */
4704 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4705 					tdata->cipher_iv.len,
4706 					tdata->validCipherLenInBits.len,
4707 					0);
4708 	if (retval < 0)
4709 		return retval;
4710 
4711 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4712 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4713 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4714 	else
4715 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4716 						ut_params->op);
4717 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4718 	ut_params->obuf = ut_params->op->sym->m_dst;
4719 	if (ut_params->obuf)
4720 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4721 	else
4722 		plaintext = ciphertext;
4723 
4724 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4725 
4726 	/* Validate obuf */
4727 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4728 				tdata->plaintext.data,
4729 				tdata->validDataLenInBits.len,
4730 				"SNOW 3G Plaintext data not as expected");
4731 	return 0;
4732 }
4733 
4734 static int
4735 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4736 {
4737 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4738 	struct crypto_unittest_params *ut_params = &unittest_params;
4739 
4740 	int retval;
4741 
4742 	uint8_t *plaintext, *ciphertext;
4743 	unsigned int plaintext_pad_len;
4744 	unsigned int plaintext_len;
4745 
4746 	struct rte_cryptodev_info dev_info;
4747 	struct rte_cryptodev_sym_capability_idx cap_idx;
4748 
4749 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4750 	uint64_t feat_flags = dev_info.feature_flags;
4751 
4752 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4753 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4754 			(tdata->validDataLenInBits.len % 8 != 0))) {
4755 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4756 		return TEST_SKIPPED;
4757 	}
4758 
4759 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4760 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4761 		printf("Device doesn't support RAW data-path APIs.\n");
4762 		return TEST_SKIPPED;
4763 	}
4764 
4765 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4766 		return TEST_SKIPPED;
4767 
4768 	/* Check if device supports ZUC EEA3 */
4769 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4770 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4771 
4772 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4773 			&cap_idx) == NULL)
4774 		return TEST_SKIPPED;
4775 
4776 	/* Check if device supports ZUC EIA3 */
4777 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4778 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4779 
4780 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4781 			&cap_idx) == NULL)
4782 		return TEST_SKIPPED;
4783 
4784 	/* Create ZUC session */
4785 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4786 			ts_params->valid_devs[0],
4787 			tdata);
4788 	if (retval != 0)
4789 		return retval;
4790 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4791 
4792 	/* clear mbuf payload */
4793 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4794 			rte_pktmbuf_tailroom(ut_params->ibuf));
4795 
4796 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4797 	/* Append data which is padded to a multiple of */
4798 	/* the algorithms block size */
4799 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4800 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4801 				plaintext_pad_len);
4802 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4803 
4804 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4805 
4806 	/* Create ZUC operation */
4807 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4808 	if (retval < 0)
4809 		return retval;
4810 
4811 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4812 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4813 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4814 	else
4815 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4816 			ut_params->op);
4817 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4818 	ut_params->obuf = ut_params->op->sym->m_src;
4819 	if (ut_params->obuf)
4820 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4821 	else
4822 		ciphertext = plaintext;
4823 
4824 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4825 	/* Validate obuf */
4826 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4827 			ciphertext,
4828 			tdata->ciphertext.data,
4829 			tdata->validDataLenInBits.len,
4830 			"ZUC Ciphertext data not as expected");
4831 
4832 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4833 	    + plaintext_pad_len;
4834 
4835 	/* Validate obuf */
4836 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4837 			ut_params->digest,
4838 			tdata->digest.data,
4839 			4,
4840 			"ZUC Generated auth tag not as expected");
4841 	return 0;
4842 }
4843 
4844 static int
4845 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4846 {
4847 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4848 	struct crypto_unittest_params *ut_params = &unittest_params;
4849 
4850 	int retval;
4851 
4852 	uint8_t *plaintext, *ciphertext;
4853 	unsigned plaintext_pad_len;
4854 	unsigned plaintext_len;
4855 	struct rte_cryptodev_info dev_info;
4856 
4857 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4858 	uint64_t feat_flags = dev_info.feature_flags;
4859 
4860 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4861 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4862 		printf("Device doesn't support RAW data-path APIs.\n");
4863 		return TEST_SKIPPED;
4864 	}
4865 
4866 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4867 		return TEST_SKIPPED;
4868 
4869 	/* Verify the capabilities */
4870 	struct rte_cryptodev_sym_capability_idx cap_idx;
4871 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4872 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4873 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4874 			&cap_idx) == NULL)
4875 		return TEST_SKIPPED;
4876 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4877 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4878 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4879 			&cap_idx) == NULL)
4880 		return TEST_SKIPPED;
4881 
4882 	/* Create SNOW 3G session */
4883 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4884 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4885 			RTE_CRYPTO_AUTH_OP_GENERATE,
4886 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4887 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4888 			tdata->key.data, tdata->key.len,
4889 			tdata->auth_iv.len, tdata->digest.len,
4890 			tdata->cipher_iv.len);
4891 	if (retval != 0)
4892 		return retval;
4893 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4894 
4895 	/* clear mbuf payload */
4896 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4897 			rte_pktmbuf_tailroom(ut_params->ibuf));
4898 
4899 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4900 	/* Append data which is padded to a multiple of */
4901 	/* the algorithms block size */
4902 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4903 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4904 				plaintext_pad_len);
4905 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4906 
4907 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4908 
4909 	/* Create SNOW 3G operation */
4910 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4911 			tdata->digest.len, tdata->auth_iv.data,
4912 			tdata->auth_iv.len,
4913 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4914 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4915 			tdata->validCipherLenInBits.len,
4916 			0,
4917 			tdata->validAuthLenInBits.len,
4918 			0
4919 			);
4920 	if (retval < 0)
4921 		return retval;
4922 
4923 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4924 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4925 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4926 	else
4927 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4928 			ut_params->op);
4929 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4930 	ut_params->obuf = ut_params->op->sym->m_src;
4931 	if (ut_params->obuf)
4932 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4933 	else
4934 		ciphertext = plaintext;
4935 
4936 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4937 	/* Validate obuf */
4938 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4939 			ciphertext,
4940 			tdata->ciphertext.data,
4941 			tdata->validDataLenInBits.len,
4942 			"SNOW 3G Ciphertext data not as expected");
4943 
4944 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4945 	    + plaintext_pad_len;
4946 
4947 	/* Validate obuf */
4948 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4949 			ut_params->digest,
4950 			tdata->digest.data,
4951 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4952 			"SNOW 3G Generated auth tag not as expected");
4953 	return 0;
4954 }
4955 
4956 static int
4957 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4958 	uint8_t op_mode, uint8_t verify)
4959 {
4960 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4961 	struct crypto_unittest_params *ut_params = &unittest_params;
4962 
4963 	int retval;
4964 
4965 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4966 	unsigned int plaintext_pad_len;
4967 	unsigned int plaintext_len;
4968 	unsigned int ciphertext_pad_len;
4969 	unsigned int ciphertext_len;
4970 
4971 	struct rte_cryptodev_info dev_info;
4972 
4973 	/* Verify the capabilities */
4974 	struct rte_cryptodev_sym_capability_idx cap_idx;
4975 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4976 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4977 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4978 			&cap_idx) == NULL)
4979 		return TEST_SKIPPED;
4980 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4981 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4982 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4983 			&cap_idx) == NULL)
4984 		return TEST_SKIPPED;
4985 
4986 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4987 		return TEST_SKIPPED;
4988 
4989 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4990 
4991 	uint64_t feat_flags = dev_info.feature_flags;
4992 
4993 	if (op_mode == OUT_OF_PLACE) {
4994 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
4995 			printf("Device doesn't support digest encrypted.\n");
4996 			return TEST_SKIPPED;
4997 		}
4998 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4999 			return TEST_SKIPPED;
5000 	}
5001 
5002 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5003 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5004 		printf("Device doesn't support RAW data-path APIs.\n");
5005 		return TEST_SKIPPED;
5006 	}
5007 
5008 	/* Create SNOW 3G session */
5009 	retval = create_wireless_algo_auth_cipher_session(
5010 			ts_params->valid_devs[0],
5011 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5012 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5013 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5014 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5015 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5016 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5017 			tdata->key.data, tdata->key.len,
5018 			tdata->auth_iv.len, tdata->digest.len,
5019 			tdata->cipher_iv.len);
5020 	if (retval != 0)
5021 		return retval;
5022 
5023 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5024 	if (op_mode == OUT_OF_PLACE)
5025 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5026 
5027 	/* clear mbuf payload */
5028 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5029 		rte_pktmbuf_tailroom(ut_params->ibuf));
5030 	if (op_mode == OUT_OF_PLACE)
5031 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5032 			rte_pktmbuf_tailroom(ut_params->obuf));
5033 
5034 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5035 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5036 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5037 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5038 
5039 	if (verify) {
5040 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5041 					ciphertext_pad_len);
5042 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5043 		if (op_mode == OUT_OF_PLACE)
5044 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5045 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5046 			ciphertext_len);
5047 	} else {
5048 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5049 					plaintext_pad_len);
5050 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5051 		if (op_mode == OUT_OF_PLACE)
5052 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5053 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5054 	}
5055 
5056 	/* Create SNOW 3G operation */
5057 	retval = create_wireless_algo_auth_cipher_operation(
5058 		tdata->digest.data, tdata->digest.len,
5059 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5060 		tdata->auth_iv.data, tdata->auth_iv.len,
5061 		(tdata->digest.offset_bytes == 0 ?
5062 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5063 			: tdata->digest.offset_bytes),
5064 		tdata->validCipherLenInBits.len,
5065 		tdata->cipher.offset_bits,
5066 		tdata->validAuthLenInBits.len,
5067 		tdata->auth.offset_bits,
5068 		op_mode, 0, verify);
5069 
5070 	if (retval < 0)
5071 		return retval;
5072 
5073 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5074 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5075 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5076 	else
5077 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5078 			ut_params->op);
5079 
5080 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5081 
5082 	ut_params->obuf = (op_mode == IN_PLACE ?
5083 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5084 
5085 	if (verify) {
5086 		if (ut_params->obuf)
5087 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5088 							uint8_t *);
5089 		else
5090 			plaintext = ciphertext +
5091 				(tdata->cipher.offset_bits >> 3);
5092 
5093 		debug_hexdump(stdout, "plaintext:", plaintext,
5094 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5095 		debug_hexdump(stdout, "plaintext expected:",
5096 			tdata->plaintext.data,
5097 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5098 	} else {
5099 		if (ut_params->obuf)
5100 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5101 							uint8_t *);
5102 		else
5103 			ciphertext = plaintext;
5104 
5105 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5106 			ciphertext_len);
5107 		debug_hexdump(stdout, "ciphertext expected:",
5108 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5109 
5110 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5111 			+ (tdata->digest.offset_bytes == 0 ?
5112 		plaintext_pad_len : tdata->digest.offset_bytes);
5113 
5114 		debug_hexdump(stdout, "digest:", ut_params->digest,
5115 			tdata->digest.len);
5116 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5117 				tdata->digest.len);
5118 	}
5119 
5120 	/* Validate obuf */
5121 	if (verify) {
5122 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5123 			plaintext,
5124 			tdata->plaintext.data,
5125 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5126 			 (tdata->digest.len << 3)),
5127 			tdata->cipher.offset_bits,
5128 			"SNOW 3G Plaintext data not as expected");
5129 	} else {
5130 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5131 			ciphertext,
5132 			tdata->ciphertext.data,
5133 			(tdata->validDataLenInBits.len -
5134 			 tdata->cipher.offset_bits),
5135 			tdata->cipher.offset_bits,
5136 			"SNOW 3G Ciphertext data not as expected");
5137 
5138 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5139 			ut_params->digest,
5140 			tdata->digest.data,
5141 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5142 			"SNOW 3G Generated auth tag not as expected");
5143 	}
5144 	return 0;
5145 }
5146 
5147 static int
5148 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5149 	uint8_t op_mode, uint8_t verify)
5150 {
5151 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5152 	struct crypto_unittest_params *ut_params = &unittest_params;
5153 
5154 	int retval;
5155 
5156 	const uint8_t *plaintext = NULL;
5157 	const uint8_t *ciphertext = NULL;
5158 	const uint8_t *digest = NULL;
5159 	unsigned int plaintext_pad_len;
5160 	unsigned int plaintext_len;
5161 	unsigned int ciphertext_pad_len;
5162 	unsigned int ciphertext_len;
5163 	uint8_t buffer[10000];
5164 	uint8_t digest_buffer[10000];
5165 
5166 	struct rte_cryptodev_info dev_info;
5167 
5168 	/* Verify the capabilities */
5169 	struct rte_cryptodev_sym_capability_idx cap_idx;
5170 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5171 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5172 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5173 			&cap_idx) == NULL)
5174 		return TEST_SKIPPED;
5175 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5176 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5177 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5178 			&cap_idx) == NULL)
5179 		return TEST_SKIPPED;
5180 
5181 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5182 		return TEST_SKIPPED;
5183 
5184 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5185 
5186 	uint64_t feat_flags = dev_info.feature_flags;
5187 
5188 	if (op_mode == IN_PLACE) {
5189 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5190 			printf("Device doesn't support in-place scatter-gather "
5191 					"in both input and output mbufs.\n");
5192 			return TEST_SKIPPED;
5193 		}
5194 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5195 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5196 			printf("Device doesn't support RAW data-path APIs.\n");
5197 			return TEST_SKIPPED;
5198 		}
5199 	} else {
5200 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5201 			return TEST_SKIPPED;
5202 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5203 			printf("Device doesn't support out-of-place scatter-gather "
5204 					"in both input and output mbufs.\n");
5205 			return TEST_SKIPPED;
5206 		}
5207 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5208 			printf("Device doesn't support digest encrypted.\n");
5209 			return TEST_SKIPPED;
5210 		}
5211 	}
5212 
5213 	/* Create SNOW 3G session */
5214 	retval = create_wireless_algo_auth_cipher_session(
5215 			ts_params->valid_devs[0],
5216 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5217 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5218 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5219 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5220 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5221 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5222 			tdata->key.data, tdata->key.len,
5223 			tdata->auth_iv.len, tdata->digest.len,
5224 			tdata->cipher_iv.len);
5225 
5226 	if (retval != 0)
5227 		return retval;
5228 
5229 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5230 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5231 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5232 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5233 
5234 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5235 			plaintext_pad_len, 15, 0);
5236 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5237 			"Failed to allocate input buffer in mempool");
5238 
5239 	if (op_mode == OUT_OF_PLACE) {
5240 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5241 				plaintext_pad_len, 15, 0);
5242 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5243 				"Failed to allocate output buffer in mempool");
5244 	}
5245 
5246 	if (verify) {
5247 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5248 			tdata->ciphertext.data);
5249 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5250 					ciphertext_len, buffer);
5251 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5252 			ciphertext_len);
5253 	} else {
5254 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5255 			tdata->plaintext.data);
5256 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5257 					plaintext_len, buffer);
5258 		debug_hexdump(stdout, "plaintext:", plaintext,
5259 			plaintext_len);
5260 	}
5261 	memset(buffer, 0, sizeof(buffer));
5262 
5263 	/* Create SNOW 3G operation */
5264 	retval = create_wireless_algo_auth_cipher_operation(
5265 		tdata->digest.data, tdata->digest.len,
5266 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5267 		tdata->auth_iv.data, tdata->auth_iv.len,
5268 		(tdata->digest.offset_bytes == 0 ?
5269 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5270 			: tdata->digest.offset_bytes),
5271 		tdata->validCipherLenInBits.len,
5272 		tdata->cipher.offset_bits,
5273 		tdata->validAuthLenInBits.len,
5274 		tdata->auth.offset_bits,
5275 		op_mode, 1, verify);
5276 
5277 	if (retval < 0)
5278 		return retval;
5279 
5280 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5281 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5282 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5283 	else
5284 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5285 			ut_params->op);
5286 
5287 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5288 
5289 	ut_params->obuf = (op_mode == IN_PLACE ?
5290 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5291 
5292 	if (verify) {
5293 		if (ut_params->obuf)
5294 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5295 					plaintext_len, buffer);
5296 		else
5297 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5298 					plaintext_len, buffer);
5299 
5300 		debug_hexdump(stdout, "plaintext:", plaintext,
5301 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5302 		debug_hexdump(stdout, "plaintext expected:",
5303 			tdata->plaintext.data,
5304 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5305 	} else {
5306 		if (ut_params->obuf)
5307 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5308 					ciphertext_len, buffer);
5309 		else
5310 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5311 					ciphertext_len, buffer);
5312 
5313 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5314 			ciphertext_len);
5315 		debug_hexdump(stdout, "ciphertext expected:",
5316 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5317 
5318 		if (ut_params->obuf)
5319 			digest = rte_pktmbuf_read(ut_params->obuf,
5320 				(tdata->digest.offset_bytes == 0 ?
5321 				plaintext_pad_len : tdata->digest.offset_bytes),
5322 				tdata->digest.len, digest_buffer);
5323 		else
5324 			digest = rte_pktmbuf_read(ut_params->ibuf,
5325 				(tdata->digest.offset_bytes == 0 ?
5326 				plaintext_pad_len : tdata->digest.offset_bytes),
5327 				tdata->digest.len, digest_buffer);
5328 
5329 		debug_hexdump(stdout, "digest:", digest,
5330 			tdata->digest.len);
5331 		debug_hexdump(stdout, "digest expected:",
5332 			tdata->digest.data, tdata->digest.len);
5333 	}
5334 
5335 	/* Validate obuf */
5336 	if (verify) {
5337 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5338 			plaintext,
5339 			tdata->plaintext.data,
5340 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5341 			 (tdata->digest.len << 3)),
5342 			tdata->cipher.offset_bits,
5343 			"SNOW 3G Plaintext data not as expected");
5344 	} else {
5345 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5346 			ciphertext,
5347 			tdata->ciphertext.data,
5348 			(tdata->validDataLenInBits.len -
5349 			 tdata->cipher.offset_bits),
5350 			tdata->cipher.offset_bits,
5351 			"SNOW 3G Ciphertext data not as expected");
5352 
5353 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5354 			digest,
5355 			tdata->digest.data,
5356 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5357 			"SNOW 3G Generated auth tag not as expected");
5358 	}
5359 	return 0;
5360 }
5361 
5362 static int
5363 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5364 	uint8_t op_mode, uint8_t verify)
5365 {
5366 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5367 	struct crypto_unittest_params *ut_params = &unittest_params;
5368 
5369 	int retval;
5370 
5371 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5372 	unsigned int plaintext_pad_len;
5373 	unsigned int plaintext_len;
5374 	unsigned int ciphertext_pad_len;
5375 	unsigned int ciphertext_len;
5376 
5377 	struct rte_cryptodev_info dev_info;
5378 
5379 	/* Verify the capabilities */
5380 	struct rte_cryptodev_sym_capability_idx cap_idx;
5381 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5382 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5383 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5384 			&cap_idx) == NULL)
5385 		return TEST_SKIPPED;
5386 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5387 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5388 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5389 			&cap_idx) == NULL)
5390 		return TEST_SKIPPED;
5391 
5392 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5393 
5394 	uint64_t feat_flags = dev_info.feature_flags;
5395 
5396 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5397 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5398 		printf("Device doesn't support RAW data-path APIs.\n");
5399 		return TEST_SKIPPED;
5400 	}
5401 
5402 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5403 		return TEST_SKIPPED;
5404 
5405 	if (op_mode == OUT_OF_PLACE) {
5406 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5407 			return TEST_SKIPPED;
5408 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5409 			printf("Device doesn't support digest encrypted.\n");
5410 			return TEST_SKIPPED;
5411 		}
5412 	}
5413 
5414 	/* Create KASUMI session */
5415 	retval = create_wireless_algo_auth_cipher_session(
5416 			ts_params->valid_devs[0],
5417 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5418 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5419 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5420 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5421 			RTE_CRYPTO_AUTH_KASUMI_F9,
5422 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5423 			tdata->key.data, tdata->key.len,
5424 			0, tdata->digest.len,
5425 			tdata->cipher_iv.len);
5426 
5427 	if (retval != 0)
5428 		return retval;
5429 
5430 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5431 	if (op_mode == OUT_OF_PLACE)
5432 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5433 
5434 	/* clear mbuf payload */
5435 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5436 		rte_pktmbuf_tailroom(ut_params->ibuf));
5437 	if (op_mode == OUT_OF_PLACE)
5438 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5439 			rte_pktmbuf_tailroom(ut_params->obuf));
5440 
5441 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5442 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5443 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5444 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5445 
5446 	if (verify) {
5447 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5448 					ciphertext_pad_len);
5449 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5450 		if (op_mode == OUT_OF_PLACE)
5451 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5452 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5453 			ciphertext_len);
5454 	} else {
5455 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5456 					plaintext_pad_len);
5457 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5458 		if (op_mode == OUT_OF_PLACE)
5459 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5460 		debug_hexdump(stdout, "plaintext:", plaintext,
5461 			plaintext_len);
5462 	}
5463 
5464 	/* Create KASUMI operation */
5465 	retval = create_wireless_algo_auth_cipher_operation(
5466 		tdata->digest.data, tdata->digest.len,
5467 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5468 		NULL, 0,
5469 		(tdata->digest.offset_bytes == 0 ?
5470 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5471 			: tdata->digest.offset_bytes),
5472 		tdata->validCipherLenInBits.len,
5473 		tdata->validCipherOffsetInBits.len,
5474 		tdata->validAuthLenInBits.len,
5475 		0,
5476 		op_mode, 0, verify);
5477 
5478 	if (retval < 0)
5479 		return retval;
5480 
5481 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5482 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5483 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5484 	else
5485 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5486 			ut_params->op);
5487 
5488 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5489 
5490 	ut_params->obuf = (op_mode == IN_PLACE ?
5491 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5492 
5493 
5494 	if (verify) {
5495 		if (ut_params->obuf)
5496 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5497 							uint8_t *);
5498 		else
5499 			plaintext = ciphertext;
5500 
5501 		debug_hexdump(stdout, "plaintext:", plaintext,
5502 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5503 		debug_hexdump(stdout, "plaintext expected:",
5504 			tdata->plaintext.data,
5505 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5506 	} else {
5507 		if (ut_params->obuf)
5508 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5509 							uint8_t *);
5510 		else
5511 			ciphertext = plaintext;
5512 
5513 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5514 			ciphertext_len);
5515 		debug_hexdump(stdout, "ciphertext expected:",
5516 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5517 
5518 		ut_params->digest = rte_pktmbuf_mtod(
5519 			ut_params->obuf, uint8_t *) +
5520 			(tdata->digest.offset_bytes == 0 ?
5521 			plaintext_pad_len : tdata->digest.offset_bytes);
5522 
5523 		debug_hexdump(stdout, "digest:", ut_params->digest,
5524 			tdata->digest.len);
5525 		debug_hexdump(stdout, "digest expected:",
5526 			tdata->digest.data, tdata->digest.len);
5527 	}
5528 
5529 	/* Validate obuf */
5530 	if (verify) {
5531 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5532 			plaintext,
5533 			tdata->plaintext.data,
5534 			tdata->plaintext.len >> 3,
5535 			"KASUMI Plaintext data not as expected");
5536 	} else {
5537 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5538 			ciphertext,
5539 			tdata->ciphertext.data,
5540 			tdata->ciphertext.len >> 3,
5541 			"KASUMI Ciphertext data not as expected");
5542 
5543 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5544 			ut_params->digest,
5545 			tdata->digest.data,
5546 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5547 			"KASUMI Generated auth tag not as expected");
5548 	}
5549 	return 0;
5550 }
5551 
5552 static int
5553 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5554 	uint8_t op_mode, uint8_t verify)
5555 {
5556 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5557 	struct crypto_unittest_params *ut_params = &unittest_params;
5558 
5559 	int retval;
5560 
5561 	const uint8_t *plaintext = NULL;
5562 	const uint8_t *ciphertext = NULL;
5563 	const uint8_t *digest = NULL;
5564 	unsigned int plaintext_pad_len;
5565 	unsigned int plaintext_len;
5566 	unsigned int ciphertext_pad_len;
5567 	unsigned int ciphertext_len;
5568 	uint8_t buffer[10000];
5569 	uint8_t digest_buffer[10000];
5570 
5571 	struct rte_cryptodev_info dev_info;
5572 
5573 	/* Verify the capabilities */
5574 	struct rte_cryptodev_sym_capability_idx cap_idx;
5575 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5576 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5577 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5578 			&cap_idx) == NULL)
5579 		return TEST_SKIPPED;
5580 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5581 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5582 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5583 			&cap_idx) == NULL)
5584 		return TEST_SKIPPED;
5585 
5586 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5587 		return TEST_SKIPPED;
5588 
5589 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5590 
5591 	uint64_t feat_flags = dev_info.feature_flags;
5592 
5593 	if (op_mode == IN_PLACE) {
5594 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5595 			printf("Device doesn't support in-place scatter-gather "
5596 					"in both input and output mbufs.\n");
5597 			return TEST_SKIPPED;
5598 		}
5599 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5600 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5601 			printf("Device doesn't support RAW data-path APIs.\n");
5602 			return TEST_SKIPPED;
5603 		}
5604 	} else {
5605 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5606 			return TEST_SKIPPED;
5607 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5608 			printf("Device doesn't support out-of-place scatter-gather "
5609 					"in both input and output mbufs.\n");
5610 			return TEST_SKIPPED;
5611 		}
5612 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5613 			printf("Device doesn't support digest encrypted.\n");
5614 			return TEST_SKIPPED;
5615 		}
5616 	}
5617 
5618 	/* Create KASUMI session */
5619 	retval = create_wireless_algo_auth_cipher_session(
5620 			ts_params->valid_devs[0],
5621 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5622 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5623 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5624 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5625 			RTE_CRYPTO_AUTH_KASUMI_F9,
5626 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5627 			tdata->key.data, tdata->key.len,
5628 			0, tdata->digest.len,
5629 			tdata->cipher_iv.len);
5630 
5631 	if (retval != 0)
5632 		return retval;
5633 
5634 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5635 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5636 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5637 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5638 
5639 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5640 			plaintext_pad_len, 15, 0);
5641 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5642 			"Failed to allocate input buffer in mempool");
5643 
5644 	if (op_mode == OUT_OF_PLACE) {
5645 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5646 				plaintext_pad_len, 15, 0);
5647 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5648 				"Failed to allocate output buffer in mempool");
5649 	}
5650 
5651 	if (verify) {
5652 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5653 			tdata->ciphertext.data);
5654 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5655 					ciphertext_len, buffer);
5656 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5657 			ciphertext_len);
5658 	} else {
5659 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5660 			tdata->plaintext.data);
5661 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5662 					plaintext_len, buffer);
5663 		debug_hexdump(stdout, "plaintext:", plaintext,
5664 			plaintext_len);
5665 	}
5666 	memset(buffer, 0, sizeof(buffer));
5667 
5668 	/* Create KASUMI operation */
5669 	retval = create_wireless_algo_auth_cipher_operation(
5670 		tdata->digest.data, tdata->digest.len,
5671 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5672 		NULL, 0,
5673 		(tdata->digest.offset_bytes == 0 ?
5674 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5675 			: tdata->digest.offset_bytes),
5676 		tdata->validCipherLenInBits.len,
5677 		tdata->validCipherOffsetInBits.len,
5678 		tdata->validAuthLenInBits.len,
5679 		0,
5680 		op_mode, 1, verify);
5681 
5682 	if (retval < 0)
5683 		return retval;
5684 
5685 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5686 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5687 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5688 	else
5689 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5690 			ut_params->op);
5691 
5692 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5693 
5694 	ut_params->obuf = (op_mode == IN_PLACE ?
5695 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5696 
5697 	if (verify) {
5698 		if (ut_params->obuf)
5699 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5700 					plaintext_len, buffer);
5701 		else
5702 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5703 					plaintext_len, buffer);
5704 
5705 		debug_hexdump(stdout, "plaintext:", plaintext,
5706 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5707 		debug_hexdump(stdout, "plaintext expected:",
5708 			tdata->plaintext.data,
5709 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5710 	} else {
5711 		if (ut_params->obuf)
5712 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5713 					ciphertext_len, buffer);
5714 		else
5715 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5716 					ciphertext_len, buffer);
5717 
5718 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5719 			ciphertext_len);
5720 		debug_hexdump(stdout, "ciphertext expected:",
5721 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5722 
5723 		if (ut_params->obuf)
5724 			digest = rte_pktmbuf_read(ut_params->obuf,
5725 				(tdata->digest.offset_bytes == 0 ?
5726 				plaintext_pad_len : tdata->digest.offset_bytes),
5727 				tdata->digest.len, digest_buffer);
5728 		else
5729 			digest = rte_pktmbuf_read(ut_params->ibuf,
5730 				(tdata->digest.offset_bytes == 0 ?
5731 				plaintext_pad_len : tdata->digest.offset_bytes),
5732 				tdata->digest.len, digest_buffer);
5733 
5734 		debug_hexdump(stdout, "digest:", digest,
5735 			tdata->digest.len);
5736 		debug_hexdump(stdout, "digest expected:",
5737 			tdata->digest.data, tdata->digest.len);
5738 	}
5739 
5740 	/* Validate obuf */
5741 	if (verify) {
5742 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5743 			plaintext,
5744 			tdata->plaintext.data,
5745 			tdata->plaintext.len >> 3,
5746 			"KASUMI Plaintext data not as expected");
5747 	} else {
5748 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5749 			ciphertext,
5750 			tdata->ciphertext.data,
5751 			tdata->validDataLenInBits.len,
5752 			"KASUMI Ciphertext data not as expected");
5753 
5754 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5755 			digest,
5756 			tdata->digest.data,
5757 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5758 			"KASUMI Generated auth tag not as expected");
5759 	}
5760 	return 0;
5761 }
5762 
5763 static int
5764 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5765 {
5766 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5767 	struct crypto_unittest_params *ut_params = &unittest_params;
5768 
5769 	int retval;
5770 
5771 	uint8_t *plaintext, *ciphertext;
5772 	unsigned plaintext_pad_len;
5773 	unsigned plaintext_len;
5774 	struct rte_cryptodev_info dev_info;
5775 
5776 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5777 	uint64_t feat_flags = dev_info.feature_flags;
5778 
5779 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5780 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5781 		printf("Device doesn't support RAW data-path APIs.\n");
5782 		return TEST_SKIPPED;
5783 	}
5784 
5785 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5786 		return TEST_SKIPPED;
5787 
5788 	/* Verify the capabilities */
5789 	struct rte_cryptodev_sym_capability_idx cap_idx;
5790 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5791 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5792 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5793 			&cap_idx) == NULL)
5794 		return TEST_SKIPPED;
5795 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5796 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5797 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5798 			&cap_idx) == NULL)
5799 		return TEST_SKIPPED;
5800 
5801 	/* Create KASUMI session */
5802 	retval = create_wireless_algo_cipher_auth_session(
5803 			ts_params->valid_devs[0],
5804 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5805 			RTE_CRYPTO_AUTH_OP_GENERATE,
5806 			RTE_CRYPTO_AUTH_KASUMI_F9,
5807 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5808 			tdata->key.data, tdata->key.len,
5809 			0, tdata->digest.len,
5810 			tdata->cipher_iv.len);
5811 	if (retval != 0)
5812 		return retval;
5813 
5814 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5815 
5816 	/* clear mbuf payload */
5817 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5818 			rte_pktmbuf_tailroom(ut_params->ibuf));
5819 
5820 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5821 	/* Append data which is padded to a multiple of */
5822 	/* the algorithms block size */
5823 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5824 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5825 				plaintext_pad_len);
5826 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5827 
5828 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5829 
5830 	/* Create KASUMI operation */
5831 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5832 				tdata->digest.len, NULL, 0,
5833 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5834 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5835 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5836 				tdata->validCipherOffsetInBits.len,
5837 				tdata->validAuthLenInBits.len,
5838 				0
5839 				);
5840 	if (retval < 0)
5841 		return retval;
5842 
5843 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5844 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5845 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5846 	else
5847 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5848 			ut_params->op);
5849 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5850 
5851 	if (ut_params->op->sym->m_dst)
5852 		ut_params->obuf = ut_params->op->sym->m_dst;
5853 	else
5854 		ut_params->obuf = ut_params->op->sym->m_src;
5855 
5856 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5857 				tdata->validCipherOffsetInBits.len >> 3);
5858 
5859 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5860 			+ plaintext_pad_len;
5861 
5862 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5863 				(tdata->validCipherOffsetInBits.len >> 3);
5864 	/* Validate obuf */
5865 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5866 		ciphertext,
5867 		reference_ciphertext,
5868 		tdata->validCipherLenInBits.len,
5869 		"KASUMI Ciphertext data not as expected");
5870 
5871 	/* Validate obuf */
5872 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5873 		ut_params->digest,
5874 		tdata->digest.data,
5875 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5876 		"KASUMI Generated auth tag not as expected");
5877 	return 0;
5878 }
5879 
5880 static int
5881 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5882 			const enum rte_crypto_cipher_algorithm cipher_algo,
5883 			const uint16_t key_size, const uint16_t iv_size)
5884 {
5885 	struct rte_cryptodev_sym_capability_idx cap_idx;
5886 	const struct rte_cryptodev_symmetric_capability *cap;
5887 
5888 	/* Check if device supports the algorithm */
5889 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5890 	cap_idx.algo.cipher = cipher_algo;
5891 
5892 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5893 			&cap_idx);
5894 
5895 	if (cap == NULL)
5896 		return -1;
5897 
5898 	/* Check if device supports key size and IV size */
5899 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5900 			iv_size) < 0) {
5901 		return -1;
5902 	}
5903 
5904 	return 0;
5905 }
5906 
5907 static int
5908 check_auth_capability(const struct crypto_testsuite_params *ts_params,
5909 			const enum rte_crypto_auth_algorithm auth_algo,
5910 			const uint16_t key_size, const uint16_t iv_size,
5911 			const uint16_t tag_size)
5912 {
5913 	struct rte_cryptodev_sym_capability_idx cap_idx;
5914 	const struct rte_cryptodev_symmetric_capability *cap;
5915 
5916 	/* Check if device supports the algorithm */
5917 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5918 	cap_idx.algo.auth = auth_algo;
5919 
5920 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5921 			&cap_idx);
5922 
5923 	if (cap == NULL)
5924 		return -1;
5925 
5926 	/* Check if device supports key size and IV size */
5927 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
5928 			tag_size, iv_size) < 0) {
5929 		return -1;
5930 	}
5931 
5932 	return 0;
5933 }
5934 
5935 static int
5936 test_zuc_encryption(const struct wireless_test_data *tdata)
5937 {
5938 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5939 	struct crypto_unittest_params *ut_params = &unittest_params;
5940 
5941 	int retval;
5942 	uint8_t *plaintext, *ciphertext;
5943 	unsigned plaintext_pad_len;
5944 	unsigned plaintext_len;
5945 	struct rte_cryptodev_info dev_info;
5946 
5947 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5948 	uint64_t feat_flags = dev_info.feature_flags;
5949 
5950 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5951 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5952 		printf("Device doesn't support RAW data-path APIs.\n");
5953 		return TEST_SKIPPED;
5954 	}
5955 
5956 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5957 		return TEST_SKIPPED;
5958 
5959 	/* Check if device supports ZUC EEA3 */
5960 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
5961 			tdata->key.len, tdata->cipher_iv.len) < 0)
5962 		return TEST_SKIPPED;
5963 
5964 	/* Create ZUC session */
5965 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5966 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5967 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5968 					tdata->key.data, tdata->key.len,
5969 					tdata->cipher_iv.len);
5970 	if (retval != 0)
5971 		return retval;
5972 
5973 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5974 
5975 	/* Clear mbuf payload */
5976 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5977 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5978 
5979 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5980 	/* Append data which is padded to a multiple */
5981 	/* of the algorithms block size */
5982 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5983 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5984 				plaintext_pad_len);
5985 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5986 
5987 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5988 
5989 	/* Create ZUC operation */
5990 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5991 					tdata->cipher_iv.len,
5992 					tdata->plaintext.len,
5993 					tdata->validCipherOffsetInBits.len);
5994 	if (retval < 0)
5995 		return retval;
5996 
5997 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5998 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5999 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6000 	else
6001 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6002 						ut_params->op);
6003 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6004 
6005 	ut_params->obuf = ut_params->op->sym->m_dst;
6006 	if (ut_params->obuf)
6007 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6008 	else
6009 		ciphertext = plaintext;
6010 
6011 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6012 
6013 	/* Validate obuf */
6014 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6015 		ciphertext,
6016 		tdata->ciphertext.data,
6017 		tdata->validCipherLenInBits.len,
6018 		"ZUC Ciphertext data not as expected");
6019 	return 0;
6020 }
6021 
6022 static int
6023 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
6024 {
6025 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6026 	struct crypto_unittest_params *ut_params = &unittest_params;
6027 
6028 	int retval;
6029 
6030 	unsigned int plaintext_pad_len;
6031 	unsigned int plaintext_len;
6032 	const uint8_t *ciphertext;
6033 	uint8_t ciphertext_buffer[2048];
6034 	struct rte_cryptodev_info dev_info;
6035 
6036 	/* Check if device supports ZUC EEA3 */
6037 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6038 			tdata->key.len, tdata->cipher_iv.len) < 0)
6039 		return TEST_SKIPPED;
6040 
6041 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6042 		return TEST_SKIPPED;
6043 
6044 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6045 
6046 	uint64_t feat_flags = dev_info.feature_flags;
6047 
6048 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6049 		printf("Device doesn't support in-place scatter-gather. "
6050 				"Test Skipped.\n");
6051 		return TEST_SKIPPED;
6052 	}
6053 
6054 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6055 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6056 		printf("Device doesn't support RAW data-path APIs.\n");
6057 		return TEST_SKIPPED;
6058 	}
6059 
6060 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6061 
6062 	/* Append data which is padded to a multiple */
6063 	/* of the algorithms block size */
6064 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6065 
6066 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6067 			plaintext_pad_len, 10, 0);
6068 
6069 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6070 			tdata->plaintext.data);
6071 
6072 	/* Create ZUC session */
6073 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6074 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6075 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6076 			tdata->key.data, tdata->key.len,
6077 			tdata->cipher_iv.len);
6078 	if (retval < 0)
6079 		return retval;
6080 
6081 	/* Clear mbuf payload */
6082 
6083 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6084 
6085 	/* Create ZUC operation */
6086 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6087 			tdata->cipher_iv.len, tdata->plaintext.len,
6088 			tdata->validCipherOffsetInBits.len);
6089 	if (retval < 0)
6090 		return retval;
6091 
6092 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6093 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6094 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6095 	else
6096 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6097 						ut_params->op);
6098 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6099 
6100 	ut_params->obuf = ut_params->op->sym->m_dst;
6101 	if (ut_params->obuf)
6102 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6103 			0, plaintext_len, ciphertext_buffer);
6104 	else
6105 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6106 			0, plaintext_len, ciphertext_buffer);
6107 
6108 	/* Validate obuf */
6109 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6110 
6111 	/* Validate obuf */
6112 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6113 		ciphertext,
6114 		tdata->ciphertext.data,
6115 		tdata->validCipherLenInBits.len,
6116 		"ZUC Ciphertext data not as expected");
6117 
6118 	return 0;
6119 }
6120 
6121 static int
6122 test_zuc_authentication(const struct wireless_test_data *tdata)
6123 {
6124 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6125 	struct crypto_unittest_params *ut_params = &unittest_params;
6126 
6127 	int retval;
6128 	unsigned plaintext_pad_len;
6129 	unsigned plaintext_len;
6130 	uint8_t *plaintext;
6131 
6132 	struct rte_cryptodev_info dev_info;
6133 
6134 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6135 	uint64_t feat_flags = dev_info.feature_flags;
6136 
6137 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6138 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6139 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6140 		return TEST_SKIPPED;
6141 	}
6142 
6143 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6144 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6145 		printf("Device doesn't support RAW data-path APIs.\n");
6146 		return TEST_SKIPPED;
6147 	}
6148 
6149 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6150 		return TEST_SKIPPED;
6151 
6152 	/* Check if device supports ZUC EIA3 */
6153 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6154 			tdata->key.len, tdata->auth_iv.len,
6155 			tdata->digest.len) < 0)
6156 		return TEST_SKIPPED;
6157 
6158 	/* Create ZUC session */
6159 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6160 			tdata->key.data, tdata->key.len,
6161 			tdata->auth_iv.len, tdata->digest.len,
6162 			RTE_CRYPTO_AUTH_OP_GENERATE,
6163 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6164 	if (retval != 0)
6165 		return retval;
6166 
6167 	/* alloc mbuf and set payload */
6168 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6169 
6170 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6171 	rte_pktmbuf_tailroom(ut_params->ibuf));
6172 
6173 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6174 	/* Append data which is padded to a multiple of */
6175 	/* the algorithms block size */
6176 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6177 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6178 				plaintext_pad_len);
6179 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6180 
6181 	/* Create ZUC operation */
6182 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6183 			tdata->auth_iv.data, tdata->auth_iv.len,
6184 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6185 			tdata->validAuthLenInBits.len,
6186 			0);
6187 	if (retval < 0)
6188 		return retval;
6189 
6190 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6191 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6192 				ut_params->op, 0, 1, 1, 0);
6193 	else
6194 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6195 				ut_params->op);
6196 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6197 	ut_params->obuf = ut_params->op->sym->m_src;
6198 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6199 			+ plaintext_pad_len;
6200 
6201 	/* Validate obuf */
6202 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6203 	ut_params->digest,
6204 	tdata->digest.data,
6205 	tdata->digest.len,
6206 	"ZUC Generated auth tag not as expected");
6207 
6208 	return 0;
6209 }
6210 
6211 static int
6212 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6213 	uint8_t op_mode, uint8_t verify)
6214 {
6215 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6216 	struct crypto_unittest_params *ut_params = &unittest_params;
6217 
6218 	int retval;
6219 
6220 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6221 	unsigned int plaintext_pad_len;
6222 	unsigned int plaintext_len;
6223 	unsigned int ciphertext_pad_len;
6224 	unsigned int ciphertext_len;
6225 
6226 	struct rte_cryptodev_info dev_info;
6227 
6228 	/* Check if device supports ZUC EEA3 */
6229 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6230 			tdata->key.len, tdata->cipher_iv.len) < 0)
6231 		return TEST_SKIPPED;
6232 
6233 	/* Check if device supports ZUC EIA3 */
6234 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6235 			tdata->key.len, tdata->auth_iv.len,
6236 			tdata->digest.len) < 0)
6237 		return TEST_SKIPPED;
6238 
6239 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6240 
6241 	uint64_t feat_flags = dev_info.feature_flags;
6242 
6243 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6244 		printf("Device doesn't support digest encrypted.\n");
6245 		return TEST_SKIPPED;
6246 	}
6247 	if (op_mode == IN_PLACE) {
6248 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6249 			printf("Device doesn't support in-place scatter-gather "
6250 					"in both input and output mbufs.\n");
6251 			return TEST_SKIPPED;
6252 		}
6253 
6254 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6255 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6256 			printf("Device doesn't support RAW data-path APIs.\n");
6257 			return TEST_SKIPPED;
6258 		}
6259 	} else {
6260 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6261 			return TEST_SKIPPED;
6262 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6263 			printf("Device doesn't support out-of-place scatter-gather "
6264 					"in both input and output mbufs.\n");
6265 			return TEST_SKIPPED;
6266 		}
6267 	}
6268 
6269 	/* Create ZUC session */
6270 	retval = create_wireless_algo_auth_cipher_session(
6271 			ts_params->valid_devs[0],
6272 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6273 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6274 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6275 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6276 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6277 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6278 			tdata->key.data, tdata->key.len,
6279 			tdata->auth_iv.len, tdata->digest.len,
6280 			tdata->cipher_iv.len);
6281 
6282 	if (retval != 0)
6283 		return retval;
6284 
6285 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6286 	if (op_mode == OUT_OF_PLACE)
6287 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6288 
6289 	/* clear mbuf payload */
6290 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6291 		rte_pktmbuf_tailroom(ut_params->ibuf));
6292 	if (op_mode == OUT_OF_PLACE)
6293 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6294 			rte_pktmbuf_tailroom(ut_params->obuf));
6295 
6296 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6297 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6298 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6299 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6300 
6301 	if (verify) {
6302 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6303 					ciphertext_pad_len);
6304 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6305 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6306 			ciphertext_len);
6307 	} else {
6308 		/* make sure enough space to cover partial digest verify case */
6309 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6310 					ciphertext_pad_len);
6311 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6312 		debug_hexdump(stdout, "plaintext:", plaintext,
6313 			plaintext_len);
6314 	}
6315 
6316 	if (op_mode == OUT_OF_PLACE)
6317 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6318 
6319 	/* Create ZUC operation */
6320 	retval = create_wireless_algo_auth_cipher_operation(
6321 		tdata->digest.data, tdata->digest.len,
6322 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6323 		tdata->auth_iv.data, tdata->auth_iv.len,
6324 		(tdata->digest.offset_bytes == 0 ?
6325 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6326 			: tdata->digest.offset_bytes),
6327 		tdata->validCipherLenInBits.len,
6328 		tdata->validCipherOffsetInBits.len,
6329 		tdata->validAuthLenInBits.len,
6330 		0,
6331 		op_mode, 0, verify);
6332 
6333 	if (retval < 0)
6334 		return retval;
6335 
6336 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6337 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6338 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6339 	else
6340 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6341 			ut_params->op);
6342 
6343 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6344 
6345 	ut_params->obuf = (op_mode == IN_PLACE ?
6346 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6347 
6348 
6349 	if (verify) {
6350 		if (ut_params->obuf)
6351 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6352 							uint8_t *);
6353 		else
6354 			plaintext = ciphertext;
6355 
6356 		debug_hexdump(stdout, "plaintext:", plaintext,
6357 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6358 		debug_hexdump(stdout, "plaintext expected:",
6359 			tdata->plaintext.data,
6360 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6361 	} else {
6362 		if (ut_params->obuf)
6363 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6364 							uint8_t *);
6365 		else
6366 			ciphertext = plaintext;
6367 
6368 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6369 			ciphertext_len);
6370 		debug_hexdump(stdout, "ciphertext expected:",
6371 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6372 
6373 		ut_params->digest = rte_pktmbuf_mtod(
6374 			ut_params->obuf, uint8_t *) +
6375 			(tdata->digest.offset_bytes == 0 ?
6376 			plaintext_pad_len : tdata->digest.offset_bytes);
6377 
6378 		debug_hexdump(stdout, "digest:", ut_params->digest,
6379 			tdata->digest.len);
6380 		debug_hexdump(stdout, "digest expected:",
6381 			tdata->digest.data, tdata->digest.len);
6382 	}
6383 
6384 	/* Validate obuf */
6385 	if (verify) {
6386 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6387 			plaintext,
6388 			tdata->plaintext.data,
6389 			tdata->plaintext.len >> 3,
6390 			"ZUC Plaintext data not as expected");
6391 	} else {
6392 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6393 			ciphertext,
6394 			tdata->ciphertext.data,
6395 			tdata->ciphertext.len >> 3,
6396 			"ZUC Ciphertext data not as expected");
6397 
6398 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6399 			ut_params->digest,
6400 			tdata->digest.data,
6401 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6402 			"ZUC Generated auth tag not as expected");
6403 	}
6404 	return 0;
6405 }
6406 
6407 static int
6408 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6409 	uint8_t op_mode, uint8_t verify)
6410 {
6411 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6412 	struct crypto_unittest_params *ut_params = &unittest_params;
6413 
6414 	int retval;
6415 
6416 	const uint8_t *plaintext = NULL;
6417 	const uint8_t *ciphertext = NULL;
6418 	const uint8_t *digest = NULL;
6419 	unsigned int plaintext_pad_len;
6420 	unsigned int plaintext_len;
6421 	unsigned int ciphertext_pad_len;
6422 	unsigned int ciphertext_len;
6423 	uint8_t buffer[10000];
6424 	uint8_t digest_buffer[10000];
6425 
6426 	struct rte_cryptodev_info dev_info;
6427 
6428 	/* Check if device supports ZUC EEA3 */
6429 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6430 			tdata->key.len, tdata->cipher_iv.len) < 0)
6431 		return TEST_SKIPPED;
6432 
6433 	/* Check if device supports ZUC EIA3 */
6434 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6435 			tdata->key.len, tdata->auth_iv.len,
6436 			tdata->digest.len) < 0)
6437 		return TEST_SKIPPED;
6438 
6439 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6440 
6441 	uint64_t feat_flags = dev_info.feature_flags;
6442 
6443 	if (op_mode == IN_PLACE) {
6444 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6445 			printf("Device doesn't support in-place scatter-gather "
6446 					"in both input and output mbufs.\n");
6447 			return TEST_SKIPPED;
6448 		}
6449 
6450 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6451 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6452 			printf("Device doesn't support RAW data-path APIs.\n");
6453 			return TEST_SKIPPED;
6454 		}
6455 	} else {
6456 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6457 			return TEST_SKIPPED;
6458 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6459 			printf("Device doesn't support out-of-place scatter-gather "
6460 					"in both input and output mbufs.\n");
6461 			return TEST_SKIPPED;
6462 		}
6463 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6464 			printf("Device doesn't support digest encrypted.\n");
6465 			return TEST_SKIPPED;
6466 		}
6467 	}
6468 
6469 	/* Create ZUC session */
6470 	retval = create_wireless_algo_auth_cipher_session(
6471 			ts_params->valid_devs[0],
6472 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6473 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6474 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6475 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6476 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6477 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6478 			tdata->key.data, tdata->key.len,
6479 			tdata->auth_iv.len, tdata->digest.len,
6480 			tdata->cipher_iv.len);
6481 
6482 	if (retval != 0)
6483 		return retval;
6484 
6485 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6486 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6487 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6488 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6489 
6490 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6491 			plaintext_pad_len, 15, 0);
6492 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6493 			"Failed to allocate input buffer in mempool");
6494 
6495 	if (op_mode == OUT_OF_PLACE) {
6496 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6497 				plaintext_pad_len, 15, 0);
6498 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6499 				"Failed to allocate output buffer in mempool");
6500 	}
6501 
6502 	if (verify) {
6503 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6504 			tdata->ciphertext.data);
6505 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6506 					ciphertext_len, buffer);
6507 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6508 			ciphertext_len);
6509 	} else {
6510 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6511 			tdata->plaintext.data);
6512 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6513 					plaintext_len, buffer);
6514 		debug_hexdump(stdout, "plaintext:", plaintext,
6515 			plaintext_len);
6516 	}
6517 	memset(buffer, 0, sizeof(buffer));
6518 
6519 	/* Create ZUC operation */
6520 	retval = create_wireless_algo_auth_cipher_operation(
6521 		tdata->digest.data, tdata->digest.len,
6522 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6523 		tdata->auth_iv.data, tdata->auth_iv.len,
6524 		(tdata->digest.offset_bytes == 0 ?
6525 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6526 			: tdata->digest.offset_bytes),
6527 		tdata->validCipherLenInBits.len,
6528 		tdata->validCipherOffsetInBits.len,
6529 		tdata->validAuthLenInBits.len,
6530 		0,
6531 		op_mode, 1, verify);
6532 
6533 	if (retval < 0)
6534 		return retval;
6535 
6536 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6537 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6538 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6539 	else
6540 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6541 			ut_params->op);
6542 
6543 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6544 
6545 	ut_params->obuf = (op_mode == IN_PLACE ?
6546 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6547 
6548 	if (verify) {
6549 		if (ut_params->obuf)
6550 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6551 					plaintext_len, buffer);
6552 		else
6553 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6554 					plaintext_len, buffer);
6555 
6556 		debug_hexdump(stdout, "plaintext:", plaintext,
6557 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6558 		debug_hexdump(stdout, "plaintext expected:",
6559 			tdata->plaintext.data,
6560 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6561 	} else {
6562 		if (ut_params->obuf)
6563 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6564 					ciphertext_len, buffer);
6565 		else
6566 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6567 					ciphertext_len, buffer);
6568 
6569 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6570 			ciphertext_len);
6571 		debug_hexdump(stdout, "ciphertext expected:",
6572 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6573 
6574 		if (ut_params->obuf)
6575 			digest = rte_pktmbuf_read(ut_params->obuf,
6576 				(tdata->digest.offset_bytes == 0 ?
6577 				plaintext_pad_len : tdata->digest.offset_bytes),
6578 				tdata->digest.len, digest_buffer);
6579 		else
6580 			digest = rte_pktmbuf_read(ut_params->ibuf,
6581 				(tdata->digest.offset_bytes == 0 ?
6582 				plaintext_pad_len : tdata->digest.offset_bytes),
6583 				tdata->digest.len, digest_buffer);
6584 
6585 		debug_hexdump(stdout, "digest:", digest,
6586 			tdata->digest.len);
6587 		debug_hexdump(stdout, "digest expected:",
6588 			tdata->digest.data, tdata->digest.len);
6589 	}
6590 
6591 	/* Validate obuf */
6592 	if (verify) {
6593 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6594 			plaintext,
6595 			tdata->plaintext.data,
6596 			tdata->plaintext.len >> 3,
6597 			"ZUC Plaintext data not as expected");
6598 	} else {
6599 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6600 			ciphertext,
6601 			tdata->ciphertext.data,
6602 			tdata->validDataLenInBits.len,
6603 			"ZUC Ciphertext data not as expected");
6604 
6605 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6606 			digest,
6607 			tdata->digest.data,
6608 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6609 			"ZUC Generated auth tag not as expected");
6610 	}
6611 	return 0;
6612 }
6613 
6614 static int
6615 test_kasumi_encryption_test_case_1(void)
6616 {
6617 	return test_kasumi_encryption(&kasumi_test_case_1);
6618 }
6619 
6620 static int
6621 test_kasumi_encryption_test_case_1_sgl(void)
6622 {
6623 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6624 }
6625 
6626 static int
6627 test_kasumi_encryption_test_case_1_oop(void)
6628 {
6629 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6630 }
6631 
6632 static int
6633 test_kasumi_encryption_test_case_1_oop_sgl(void)
6634 {
6635 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6636 }
6637 
6638 static int
6639 test_kasumi_encryption_test_case_2(void)
6640 {
6641 	return test_kasumi_encryption(&kasumi_test_case_2);
6642 }
6643 
6644 static int
6645 test_kasumi_encryption_test_case_3(void)
6646 {
6647 	return test_kasumi_encryption(&kasumi_test_case_3);
6648 }
6649 
6650 static int
6651 test_kasumi_encryption_test_case_4(void)
6652 {
6653 	return test_kasumi_encryption(&kasumi_test_case_4);
6654 }
6655 
6656 static int
6657 test_kasumi_encryption_test_case_5(void)
6658 {
6659 	return test_kasumi_encryption(&kasumi_test_case_5);
6660 }
6661 
6662 static int
6663 test_kasumi_decryption_test_case_1(void)
6664 {
6665 	return test_kasumi_decryption(&kasumi_test_case_1);
6666 }
6667 
6668 static int
6669 test_kasumi_decryption_test_case_1_oop(void)
6670 {
6671 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6672 }
6673 
6674 static int
6675 test_kasumi_decryption_test_case_2(void)
6676 {
6677 	return test_kasumi_decryption(&kasumi_test_case_2);
6678 }
6679 
6680 static int
6681 test_kasumi_decryption_test_case_3(void)
6682 {
6683 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6684 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6685 		return TEST_SKIPPED;
6686 	return test_kasumi_decryption(&kasumi_test_case_3);
6687 }
6688 
6689 static int
6690 test_kasumi_decryption_test_case_4(void)
6691 {
6692 	return test_kasumi_decryption(&kasumi_test_case_4);
6693 }
6694 
6695 static int
6696 test_kasumi_decryption_test_case_5(void)
6697 {
6698 	return test_kasumi_decryption(&kasumi_test_case_5);
6699 }
6700 static int
6701 test_snow3g_encryption_test_case_1(void)
6702 {
6703 	return test_snow3g_encryption(&snow3g_test_case_1);
6704 }
6705 
6706 static int
6707 test_snow3g_encryption_test_case_1_oop(void)
6708 {
6709 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6710 }
6711 
6712 static int
6713 test_snow3g_encryption_test_case_1_oop_sgl(void)
6714 {
6715 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6716 }
6717 
6718 
6719 static int
6720 test_snow3g_encryption_test_case_1_offset_oop(void)
6721 {
6722 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6723 }
6724 
6725 static int
6726 test_snow3g_encryption_test_case_2(void)
6727 {
6728 	return test_snow3g_encryption(&snow3g_test_case_2);
6729 }
6730 
6731 static int
6732 test_snow3g_encryption_test_case_3(void)
6733 {
6734 	return test_snow3g_encryption(&snow3g_test_case_3);
6735 }
6736 
6737 static int
6738 test_snow3g_encryption_test_case_4(void)
6739 {
6740 	return test_snow3g_encryption(&snow3g_test_case_4);
6741 }
6742 
6743 static int
6744 test_snow3g_encryption_test_case_5(void)
6745 {
6746 	return test_snow3g_encryption(&snow3g_test_case_5);
6747 }
6748 
6749 static int
6750 test_snow3g_decryption_test_case_1(void)
6751 {
6752 	return test_snow3g_decryption(&snow3g_test_case_1);
6753 }
6754 
6755 static int
6756 test_snow3g_decryption_test_case_1_oop(void)
6757 {
6758 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6759 }
6760 
6761 static int
6762 test_snow3g_decryption_test_case_2(void)
6763 {
6764 	return test_snow3g_decryption(&snow3g_test_case_2);
6765 }
6766 
6767 static int
6768 test_snow3g_decryption_test_case_3(void)
6769 {
6770 	return test_snow3g_decryption(&snow3g_test_case_3);
6771 }
6772 
6773 static int
6774 test_snow3g_decryption_test_case_4(void)
6775 {
6776 	return test_snow3g_decryption(&snow3g_test_case_4);
6777 }
6778 
6779 static int
6780 test_snow3g_decryption_test_case_5(void)
6781 {
6782 	return test_snow3g_decryption(&snow3g_test_case_5);
6783 }
6784 
6785 /*
6786  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6787  * Pattern digest from snow3g_test_data must be allocated as
6788  * 4 last bytes in plaintext.
6789  */
6790 static void
6791 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6792 		struct snow3g_hash_test_data *output)
6793 {
6794 	if ((pattern != NULL) && (output != NULL)) {
6795 		output->key.len = pattern->key.len;
6796 
6797 		memcpy(output->key.data,
6798 		pattern->key.data, pattern->key.len);
6799 
6800 		output->auth_iv.len = pattern->auth_iv.len;
6801 
6802 		memcpy(output->auth_iv.data,
6803 		pattern->auth_iv.data, pattern->auth_iv.len);
6804 
6805 		output->plaintext.len = pattern->plaintext.len;
6806 
6807 		memcpy(output->plaintext.data,
6808 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6809 
6810 		output->digest.len = pattern->digest.len;
6811 
6812 		memcpy(output->digest.data,
6813 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6814 		pattern->digest.len);
6815 
6816 		output->validAuthLenInBits.len =
6817 		pattern->validAuthLenInBits.len;
6818 	}
6819 }
6820 
6821 /*
6822  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6823  */
6824 static int
6825 test_snow3g_decryption_with_digest_test_case_1(void)
6826 {
6827 	struct snow3g_hash_test_data snow3g_hash_data;
6828 	struct rte_cryptodev_info dev_info;
6829 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6830 
6831 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6832 	uint64_t feat_flags = dev_info.feature_flags;
6833 
6834 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6835 		printf("Device doesn't support encrypted digest operations.\n");
6836 		return TEST_SKIPPED;
6837 	}
6838 
6839 	/*
6840 	 * Function prepare data for hash verification test case.
6841 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6842 	 */
6843 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6844 
6845 	return test_snow3g_decryption(&snow3g_test_case_7) &
6846 			test_snow3g_authentication_verify(&snow3g_hash_data);
6847 }
6848 
6849 static int
6850 test_snow3g_cipher_auth_test_case_1(void)
6851 {
6852 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6853 }
6854 
6855 static int
6856 test_snow3g_auth_cipher_test_case_1(void)
6857 {
6858 	return test_snow3g_auth_cipher(
6859 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6860 }
6861 
6862 static int
6863 test_snow3g_auth_cipher_test_case_2(void)
6864 {
6865 	return test_snow3g_auth_cipher(
6866 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6867 }
6868 
6869 static int
6870 test_snow3g_auth_cipher_test_case_2_oop(void)
6871 {
6872 	return test_snow3g_auth_cipher(
6873 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6874 }
6875 
6876 static int
6877 test_snow3g_auth_cipher_part_digest_enc(void)
6878 {
6879 	return test_snow3g_auth_cipher(
6880 		&snow3g_auth_cipher_partial_digest_encryption,
6881 			IN_PLACE, 0);
6882 }
6883 
6884 static int
6885 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6886 {
6887 	return test_snow3g_auth_cipher(
6888 		&snow3g_auth_cipher_partial_digest_encryption,
6889 			OUT_OF_PLACE, 0);
6890 }
6891 
6892 static int
6893 test_snow3g_auth_cipher_test_case_3_sgl(void)
6894 {
6895 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6896 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6897 		return TEST_SKIPPED;
6898 	return test_snow3g_auth_cipher_sgl(
6899 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6900 }
6901 
6902 static int
6903 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6904 {
6905 	return test_snow3g_auth_cipher_sgl(
6906 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6907 }
6908 
6909 static int
6910 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6911 {
6912 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6913 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6914 		return TEST_SKIPPED;
6915 	return test_snow3g_auth_cipher_sgl(
6916 		&snow3g_auth_cipher_partial_digest_encryption,
6917 			IN_PLACE, 0);
6918 }
6919 
6920 static int
6921 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6922 {
6923 	return test_snow3g_auth_cipher_sgl(
6924 		&snow3g_auth_cipher_partial_digest_encryption,
6925 			OUT_OF_PLACE, 0);
6926 }
6927 
6928 static int
6929 test_snow3g_auth_cipher_total_digest_enc_1(void)
6930 {
6931 	return test_snow3g_auth_cipher(
6932 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0);
6933 }
6934 
6935 static int
6936 test_snow3g_auth_cipher_total_digest_enc_1_oop(void)
6937 {
6938 	return test_snow3g_auth_cipher(
6939 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0);
6940 }
6941 
6942 static int
6943 test_snow3g_auth_cipher_total_digest_enc_1_sgl(void)
6944 {
6945 	return test_snow3g_auth_cipher_sgl(
6946 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 0);
6947 }
6948 
6949 static int
6950 test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl(void)
6951 {
6952 	return test_snow3g_auth_cipher_sgl(
6953 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 0);
6954 }
6955 
6956 static int
6957 test_snow3g_auth_cipher_verify_test_case_1(void)
6958 {
6959 	return test_snow3g_auth_cipher(
6960 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6961 }
6962 
6963 static int
6964 test_snow3g_auth_cipher_verify_test_case_2(void)
6965 {
6966 	return test_snow3g_auth_cipher(
6967 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6968 }
6969 
6970 static int
6971 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6972 {
6973 	return test_snow3g_auth_cipher(
6974 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6975 }
6976 
6977 static int
6978 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6979 {
6980 	return test_snow3g_auth_cipher(
6981 		&snow3g_auth_cipher_partial_digest_encryption,
6982 			IN_PLACE, 1);
6983 }
6984 
6985 static int
6986 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6987 {
6988 	return test_snow3g_auth_cipher(
6989 		&snow3g_auth_cipher_partial_digest_encryption,
6990 			OUT_OF_PLACE, 1);
6991 }
6992 
6993 static int
6994 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6995 {
6996 	return test_snow3g_auth_cipher_sgl(
6997 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6998 }
6999 
7000 static int
7001 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7002 {
7003 	return test_snow3g_auth_cipher_sgl(
7004 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7005 }
7006 
7007 static int
7008 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7009 {
7010 	return test_snow3g_auth_cipher_sgl(
7011 		&snow3g_auth_cipher_partial_digest_encryption,
7012 			IN_PLACE, 1);
7013 }
7014 
7015 static int
7016 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7017 {
7018 	return test_snow3g_auth_cipher_sgl(
7019 		&snow3g_auth_cipher_partial_digest_encryption,
7020 			OUT_OF_PLACE, 1);
7021 }
7022 
7023 static int
7024 test_snow3g_auth_cipher_verify_total_digest_enc_1(void)
7025 {
7026 	return test_snow3g_auth_cipher(
7027 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1);
7028 }
7029 
7030 static int
7031 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop(void)
7032 {
7033 	return test_snow3g_auth_cipher(
7034 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1);
7035 }
7036 
7037 static int
7038 test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl(void)
7039 {
7040 	return test_snow3g_auth_cipher_sgl(
7041 		&snow3g_auth_cipher_total_digest_encryption_1, IN_PLACE, 1);
7042 }
7043 
7044 static int
7045 test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl(void)
7046 {
7047 	return test_snow3g_auth_cipher_sgl(
7048 		&snow3g_auth_cipher_total_digest_encryption_1, OUT_OF_PLACE, 1);
7049 }
7050 
7051 static int
7052 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7053 {
7054 	return test_snow3g_auth_cipher(
7055 		&snow3g_test_case_7, IN_PLACE, 0);
7056 }
7057 
7058 static int
7059 test_kasumi_auth_cipher_test_case_1(void)
7060 {
7061 	return test_kasumi_auth_cipher(
7062 		&kasumi_test_case_3, IN_PLACE, 0);
7063 }
7064 
7065 static int
7066 test_kasumi_auth_cipher_test_case_2(void)
7067 {
7068 	return test_kasumi_auth_cipher(
7069 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7070 }
7071 
7072 static int
7073 test_kasumi_auth_cipher_test_case_2_oop(void)
7074 {
7075 	return test_kasumi_auth_cipher(
7076 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7077 }
7078 
7079 static int
7080 test_kasumi_auth_cipher_test_case_2_sgl(void)
7081 {
7082 	return test_kasumi_auth_cipher_sgl(
7083 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7084 }
7085 
7086 static int
7087 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7088 {
7089 	return test_kasumi_auth_cipher_sgl(
7090 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7091 }
7092 
7093 static int
7094 test_kasumi_auth_cipher_verify_test_case_1(void)
7095 {
7096 	return test_kasumi_auth_cipher(
7097 		&kasumi_test_case_3, IN_PLACE, 1);
7098 }
7099 
7100 static int
7101 test_kasumi_auth_cipher_verify_test_case_2(void)
7102 {
7103 	return test_kasumi_auth_cipher(
7104 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7105 }
7106 
7107 static int
7108 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7109 {
7110 	return test_kasumi_auth_cipher(
7111 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7112 }
7113 
7114 static int
7115 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7116 {
7117 	return test_kasumi_auth_cipher_sgl(
7118 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7119 }
7120 
7121 static int
7122 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7123 {
7124 	return test_kasumi_auth_cipher_sgl(
7125 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7126 }
7127 
7128 static int
7129 test_kasumi_cipher_auth_test_case_1(void)
7130 {
7131 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7132 }
7133 
7134 static int
7135 test_zuc_encryption_test_case_1(void)
7136 {
7137 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
7138 }
7139 
7140 static int
7141 test_zuc_encryption_test_case_2(void)
7142 {
7143 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
7144 }
7145 
7146 static int
7147 test_zuc_encryption_test_case_3(void)
7148 {
7149 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7150 }
7151 
7152 static int
7153 test_zuc_encryption_test_case_4(void)
7154 {
7155 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7156 }
7157 
7158 static int
7159 test_zuc_encryption_test_case_5(void)
7160 {
7161 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7162 }
7163 
7164 static int
7165 test_zuc_encryption_test_case_6_sgl(void)
7166 {
7167 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7168 }
7169 
7170 static int
7171 test_zuc_hash_generate_test_case_1(void)
7172 {
7173 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7174 }
7175 
7176 static int
7177 test_zuc_hash_generate_test_case_2(void)
7178 {
7179 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7180 }
7181 
7182 static int
7183 test_zuc_hash_generate_test_case_3(void)
7184 {
7185 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7186 }
7187 
7188 static int
7189 test_zuc_hash_generate_test_case_4(void)
7190 {
7191 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7192 }
7193 
7194 static int
7195 test_zuc_hash_generate_test_case_5(void)
7196 {
7197 	return test_zuc_authentication(&zuc_test_auth_5670b);
7198 }
7199 
7200 static int
7201 test_zuc_hash_generate_test_case_6(void)
7202 {
7203 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7204 }
7205 
7206 static int
7207 test_zuc_hash_generate_test_case_7(void)
7208 {
7209 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7210 }
7211 
7212 static int
7213 test_zuc_hash_generate_test_case_8(void)
7214 {
7215 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7216 }
7217 
7218 static int
7219 test_zuc_hash_generate_test_case_9(void)
7220 {
7221 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b);
7222 }
7223 
7224 static int
7225 test_zuc_hash_generate_test_case_10(void)
7226 {
7227 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b);
7228 }
7229 
7230 static int
7231 test_zuc_hash_generate_test_case_11(void)
7232 {
7233 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b);
7234 }
7235 
7236 static int
7237 test_zuc_cipher_auth_test_case_1(void)
7238 {
7239 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7240 }
7241 
7242 static int
7243 test_zuc_cipher_auth_test_case_2(void)
7244 {
7245 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7246 }
7247 
7248 static int
7249 test_zuc_auth_cipher_test_case_1(void)
7250 {
7251 	return test_zuc_auth_cipher(
7252 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7253 }
7254 
7255 static int
7256 test_zuc_auth_cipher_test_case_1_oop(void)
7257 {
7258 	return test_zuc_auth_cipher(
7259 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7260 }
7261 
7262 static int
7263 test_zuc_auth_cipher_test_case_1_sgl(void)
7264 {
7265 	return test_zuc_auth_cipher_sgl(
7266 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7267 }
7268 
7269 static int
7270 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7271 {
7272 	return test_zuc_auth_cipher_sgl(
7273 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7274 }
7275 
7276 static int
7277 test_zuc_auth_cipher_test_case_2(void)
7278 {
7279 	return test_zuc_auth_cipher(
7280 		&zuc_auth_cipher_test_case_2, IN_PLACE, 0);
7281 }
7282 
7283 static int
7284 test_zuc_auth_cipher_test_case_2_oop(void)
7285 {
7286 	return test_zuc_auth_cipher(
7287 		&zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7288 }
7289 
7290 static int
7291 test_zuc_auth_cipher_verify_test_case_1(void)
7292 {
7293 	return test_zuc_auth_cipher(
7294 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7295 }
7296 
7297 static int
7298 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7299 {
7300 	return test_zuc_auth_cipher(
7301 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7302 }
7303 
7304 static int
7305 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7306 {
7307 	return test_zuc_auth_cipher_sgl(
7308 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7309 }
7310 
7311 static int
7312 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7313 {
7314 	return test_zuc_auth_cipher_sgl(
7315 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7316 }
7317 
7318 static int
7319 test_zuc_auth_cipher_verify_test_case_2(void)
7320 {
7321 	return test_zuc_auth_cipher(
7322 		&zuc_auth_cipher_test_case_2, IN_PLACE, 1);
7323 }
7324 
7325 static int
7326 test_zuc_auth_cipher_verify_test_case_2_oop(void)
7327 {
7328 	return test_zuc_auth_cipher(
7329 		&zuc_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7330 }
7331 
7332 static int
7333 test_zuc256_encryption_test_case_1(void)
7334 {
7335 	return test_zuc_encryption(&zuc256_test_case_cipher_1);
7336 }
7337 
7338 static int
7339 test_zuc256_encryption_test_case_2(void)
7340 {
7341 	return test_zuc_encryption(&zuc256_test_case_cipher_2);
7342 }
7343 
7344 static int
7345 test_zuc256_authentication_test_case_1(void)
7346 {
7347 	return test_zuc_authentication(&zuc256_test_case_auth_1);
7348 }
7349 
7350 static int
7351 test_zuc256_authentication_test_case_2(void)
7352 {
7353 	return test_zuc_authentication(&zuc256_test_case_auth_2);
7354 }
7355 
7356 static int
7357 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7358 {
7359 	uint8_t dev_id = testsuite_params.valid_devs[0];
7360 
7361 	struct rte_cryptodev_sym_capability_idx cap_idx;
7362 
7363 	/* Check if device supports particular cipher algorithm */
7364 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7365 	cap_idx.algo.cipher = tdata->cipher_algo;
7366 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7367 		return TEST_SKIPPED;
7368 
7369 	/* Check if device supports particular hash algorithm */
7370 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7371 	cap_idx.algo.auth = tdata->auth_algo;
7372 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7373 		return TEST_SKIPPED;
7374 
7375 	return 0;
7376 }
7377 
7378 static int
7379 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7380 	uint8_t op_mode, uint8_t verify)
7381 {
7382 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7383 	struct crypto_unittest_params *ut_params = &unittest_params;
7384 
7385 	int retval;
7386 
7387 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7388 	unsigned int plaintext_pad_len;
7389 	unsigned int plaintext_len;
7390 	unsigned int ciphertext_pad_len;
7391 	unsigned int ciphertext_len;
7392 
7393 	struct rte_cryptodev_info dev_info;
7394 	struct rte_crypto_op *op;
7395 
7396 	/* Check if device supports particular algorithms separately */
7397 	if (test_mixed_check_if_unsupported(tdata))
7398 		return TEST_SKIPPED;
7399 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7400 		return TEST_SKIPPED;
7401 
7402 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7403 
7404 	uint64_t feat_flags = dev_info.feature_flags;
7405 
7406 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7407 		printf("Device doesn't support digest encrypted.\n");
7408 		return TEST_SKIPPED;
7409 	}
7410 
7411 	/* Create the session */
7412 	if (verify)
7413 		retval = create_wireless_algo_cipher_auth_session(
7414 				ts_params->valid_devs[0],
7415 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7416 				RTE_CRYPTO_AUTH_OP_VERIFY,
7417 				tdata->auth_algo,
7418 				tdata->cipher_algo,
7419 				tdata->auth_key.data, tdata->auth_key.len,
7420 				tdata->auth_iv.len, tdata->digest_enc.len,
7421 				tdata->cipher_iv.len);
7422 	else
7423 		retval = create_wireless_algo_auth_cipher_session(
7424 				ts_params->valid_devs[0],
7425 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7426 				RTE_CRYPTO_AUTH_OP_GENERATE,
7427 				tdata->auth_algo,
7428 				tdata->cipher_algo,
7429 				tdata->auth_key.data, tdata->auth_key.len,
7430 				tdata->auth_iv.len, tdata->digest_enc.len,
7431 				tdata->cipher_iv.len);
7432 	if (retval != 0)
7433 		return retval;
7434 
7435 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7436 	if (op_mode == OUT_OF_PLACE)
7437 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7438 
7439 	/* clear mbuf payload */
7440 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7441 		rte_pktmbuf_tailroom(ut_params->ibuf));
7442 	if (op_mode == OUT_OF_PLACE) {
7443 
7444 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7445 				rte_pktmbuf_tailroom(ut_params->obuf));
7446 	}
7447 
7448 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7449 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7450 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7451 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7452 
7453 	if (verify) {
7454 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7455 				ciphertext_pad_len);
7456 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7457 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7458 				ciphertext_len);
7459 	} else {
7460 		/* make sure enough space to cover partial digest verify case */
7461 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7462 				ciphertext_pad_len);
7463 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7464 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7465 	}
7466 
7467 	if (op_mode == OUT_OF_PLACE)
7468 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7469 
7470 	/* Create the operation */
7471 	retval = create_wireless_algo_auth_cipher_operation(
7472 			tdata->digest_enc.data, tdata->digest_enc.len,
7473 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7474 			tdata->auth_iv.data, tdata->auth_iv.len,
7475 			(tdata->digest_enc.offset == 0 ?
7476 				plaintext_pad_len
7477 				: tdata->digest_enc.offset),
7478 			tdata->validCipherLen.len_bits,
7479 			tdata->cipher.offset_bits,
7480 			tdata->validAuthLen.len_bits,
7481 			tdata->auth.offset_bits,
7482 			op_mode, 0, verify);
7483 
7484 	if (retval < 0)
7485 		return retval;
7486 
7487 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7488 
7489 	/* Check if the op failed because the device doesn't */
7490 	/* support this particular combination of algorithms */
7491 	if (op == NULL && ut_params->op->status ==
7492 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7493 		printf("Device doesn't support this mixed combination. "
7494 				"Test Skipped.\n");
7495 		return TEST_SKIPPED;
7496 	}
7497 	ut_params->op = op;
7498 
7499 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7500 
7501 	ut_params->obuf = (op_mode == IN_PLACE ?
7502 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7503 
7504 	if (verify) {
7505 		if (ut_params->obuf)
7506 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7507 							uint8_t *);
7508 		else
7509 			plaintext = ciphertext +
7510 					(tdata->cipher.offset_bits >> 3);
7511 
7512 		debug_hexdump(stdout, "plaintext:", plaintext,
7513 				tdata->plaintext.len_bits >> 3);
7514 		debug_hexdump(stdout, "plaintext expected:",
7515 				tdata->plaintext.data,
7516 				tdata->plaintext.len_bits >> 3);
7517 	} else {
7518 		if (ut_params->obuf)
7519 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7520 					uint8_t *);
7521 		else
7522 			ciphertext = plaintext;
7523 
7524 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7525 				ciphertext_len);
7526 		debug_hexdump(stdout, "ciphertext expected:",
7527 				tdata->ciphertext.data,
7528 				tdata->ciphertext.len_bits >> 3);
7529 
7530 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7531 				+ (tdata->digest_enc.offset == 0 ?
7532 		plaintext_pad_len : tdata->digest_enc.offset);
7533 
7534 		debug_hexdump(stdout, "digest:", ut_params->digest,
7535 				tdata->digest_enc.len);
7536 		debug_hexdump(stdout, "digest expected:",
7537 				tdata->digest_enc.data,
7538 				tdata->digest_enc.len);
7539 	}
7540 
7541 	if (!verify) {
7542 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7543 				ut_params->digest,
7544 				tdata->digest_enc.data,
7545 				tdata->digest_enc.len,
7546 				"Generated auth tag not as expected");
7547 	}
7548 
7549 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7550 		if (verify) {
7551 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7552 					plaintext,
7553 					tdata->plaintext.data,
7554 					tdata->plaintext.len_bits >> 3,
7555 					"Plaintext data not as expected");
7556 		} else {
7557 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7558 					ciphertext,
7559 					tdata->ciphertext.data,
7560 					tdata->validDataLen.len_bits,
7561 					"Ciphertext data not as expected");
7562 		}
7563 	}
7564 
7565 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7566 			"crypto op processing failed");
7567 
7568 	return 0;
7569 }
7570 
7571 static int
7572 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7573 	uint8_t op_mode, uint8_t verify)
7574 {
7575 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7576 	struct crypto_unittest_params *ut_params = &unittest_params;
7577 
7578 	int retval;
7579 
7580 	const uint8_t *plaintext = NULL;
7581 	const uint8_t *ciphertext = NULL;
7582 	const uint8_t *digest = NULL;
7583 	unsigned int plaintext_pad_len;
7584 	unsigned int plaintext_len;
7585 	unsigned int ciphertext_pad_len;
7586 	unsigned int ciphertext_len;
7587 	uint8_t buffer[10000];
7588 	uint8_t digest_buffer[10000];
7589 
7590 	struct rte_cryptodev_info dev_info;
7591 	struct rte_crypto_op *op;
7592 
7593 	/* Check if device supports particular algorithms */
7594 	if (test_mixed_check_if_unsupported(tdata))
7595 		return TEST_SKIPPED;
7596 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7597 		return TEST_SKIPPED;
7598 
7599 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7600 
7601 	uint64_t feat_flags = dev_info.feature_flags;
7602 
7603 	if (op_mode == IN_PLACE) {
7604 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7605 			printf("Device doesn't support in-place scatter-gather "
7606 					"in both input and output mbufs.\n");
7607 			return TEST_SKIPPED;
7608 		}
7609 	} else {
7610 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7611 			printf("Device doesn't support out-of-place scatter-gather "
7612 					"in both input and output mbufs.\n");
7613 			return TEST_SKIPPED;
7614 		}
7615 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7616 			printf("Device doesn't support digest encrypted.\n");
7617 			return TEST_SKIPPED;
7618 		}
7619 	}
7620 
7621 	/* Create the session */
7622 	if (verify)
7623 		retval = create_wireless_algo_cipher_auth_session(
7624 				ts_params->valid_devs[0],
7625 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7626 				RTE_CRYPTO_AUTH_OP_VERIFY,
7627 				tdata->auth_algo,
7628 				tdata->cipher_algo,
7629 				tdata->auth_key.data, tdata->auth_key.len,
7630 				tdata->auth_iv.len, tdata->digest_enc.len,
7631 				tdata->cipher_iv.len);
7632 	else
7633 		retval = create_wireless_algo_auth_cipher_session(
7634 				ts_params->valid_devs[0],
7635 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7636 				RTE_CRYPTO_AUTH_OP_GENERATE,
7637 				tdata->auth_algo,
7638 				tdata->cipher_algo,
7639 				tdata->auth_key.data, tdata->auth_key.len,
7640 				tdata->auth_iv.len, tdata->digest_enc.len,
7641 				tdata->cipher_iv.len);
7642 	if (retval != 0)
7643 		return retval;
7644 
7645 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7646 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7647 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7648 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7649 
7650 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7651 			ciphertext_pad_len, 15, 0);
7652 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7653 			"Failed to allocate input buffer in mempool");
7654 
7655 	if (op_mode == OUT_OF_PLACE) {
7656 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7657 				plaintext_pad_len, 15, 0);
7658 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7659 				"Failed to allocate output buffer in mempool");
7660 	}
7661 
7662 	if (verify) {
7663 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7664 			tdata->ciphertext.data);
7665 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7666 					ciphertext_len, buffer);
7667 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7668 			ciphertext_len);
7669 	} else {
7670 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7671 			tdata->plaintext.data);
7672 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7673 					plaintext_len, buffer);
7674 		debug_hexdump(stdout, "plaintext:", plaintext,
7675 			plaintext_len);
7676 	}
7677 	memset(buffer, 0, sizeof(buffer));
7678 
7679 	/* Create the operation */
7680 	retval = create_wireless_algo_auth_cipher_operation(
7681 			tdata->digest_enc.data, tdata->digest_enc.len,
7682 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7683 			tdata->auth_iv.data, tdata->auth_iv.len,
7684 			(tdata->digest_enc.offset == 0 ?
7685 				plaintext_pad_len
7686 				: tdata->digest_enc.offset),
7687 			tdata->validCipherLen.len_bits,
7688 			tdata->cipher.offset_bits,
7689 			tdata->validAuthLen.len_bits,
7690 			tdata->auth.offset_bits,
7691 			op_mode, 1, verify);
7692 
7693 	if (retval < 0)
7694 		return retval;
7695 
7696 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7697 
7698 	/* Check if the op failed because the device doesn't */
7699 	/* support this particular combination of algorithms */
7700 	if (op == NULL && ut_params->op->status ==
7701 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7702 		printf("Device doesn't support this mixed combination. "
7703 				"Test Skipped.\n");
7704 		return TEST_SKIPPED;
7705 	}
7706 	ut_params->op = op;
7707 
7708 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7709 
7710 	ut_params->obuf = (op_mode == IN_PLACE ?
7711 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7712 
7713 	if (verify) {
7714 		if (ut_params->obuf)
7715 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7716 					plaintext_len, buffer);
7717 		else
7718 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7719 					plaintext_len, buffer);
7720 
7721 		debug_hexdump(stdout, "plaintext:", plaintext,
7722 				(tdata->plaintext.len_bits >> 3) -
7723 				tdata->digest_enc.len);
7724 		debug_hexdump(stdout, "plaintext expected:",
7725 				tdata->plaintext.data,
7726 				(tdata->plaintext.len_bits >> 3) -
7727 				tdata->digest_enc.len);
7728 	} else {
7729 		if (ut_params->obuf)
7730 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7731 					ciphertext_len, buffer);
7732 		else
7733 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7734 					ciphertext_len, buffer);
7735 
7736 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7737 			ciphertext_len);
7738 		debug_hexdump(stdout, "ciphertext expected:",
7739 			tdata->ciphertext.data,
7740 			tdata->ciphertext.len_bits >> 3);
7741 
7742 		if (ut_params->obuf)
7743 			digest = rte_pktmbuf_read(ut_params->obuf,
7744 					(tdata->digest_enc.offset == 0 ?
7745 						plaintext_pad_len :
7746 						tdata->digest_enc.offset),
7747 					tdata->digest_enc.len, digest_buffer);
7748 		else
7749 			digest = rte_pktmbuf_read(ut_params->ibuf,
7750 					(tdata->digest_enc.offset == 0 ?
7751 						plaintext_pad_len :
7752 						tdata->digest_enc.offset),
7753 					tdata->digest_enc.len, digest_buffer);
7754 
7755 		debug_hexdump(stdout, "digest:", digest,
7756 				tdata->digest_enc.len);
7757 		debug_hexdump(stdout, "digest expected:",
7758 				tdata->digest_enc.data, tdata->digest_enc.len);
7759 	}
7760 
7761 	if (!verify) {
7762 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7763 				digest,
7764 				tdata->digest_enc.data,
7765 				tdata->digest_enc.len,
7766 				"Generated auth tag not as expected");
7767 	}
7768 
7769 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7770 		if (verify) {
7771 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7772 					plaintext,
7773 					tdata->plaintext.data,
7774 					tdata->plaintext.len_bits >> 3,
7775 					"Plaintext data not as expected");
7776 		} else {
7777 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7778 					ciphertext,
7779 					tdata->ciphertext.data,
7780 					tdata->validDataLen.len_bits,
7781 					"Ciphertext data not as expected");
7782 		}
7783 	}
7784 
7785 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7786 			"crypto op processing failed");
7787 
7788 	return 0;
7789 }
7790 
7791 /** AUTH AES CMAC + CIPHER AES CTR */
7792 
7793 static int
7794 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7795 {
7796 	return test_mixed_auth_cipher(
7797 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7798 }
7799 
7800 static int
7801 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7802 {
7803 	return test_mixed_auth_cipher(
7804 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7805 }
7806 
7807 static int
7808 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7809 {
7810 	return test_mixed_auth_cipher_sgl(
7811 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7812 }
7813 
7814 static int
7815 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7816 {
7817 	return test_mixed_auth_cipher_sgl(
7818 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7819 }
7820 
7821 static int
7822 test_aes_cmac_aes_ctr_digest_enc_test_case_2(void)
7823 {
7824 	return test_mixed_auth_cipher(
7825 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 0);
7826 }
7827 
7828 static int
7829 test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void)
7830 {
7831 	return test_mixed_auth_cipher(
7832 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 0);
7833 }
7834 
7835 static int
7836 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7837 {
7838 	return test_mixed_auth_cipher(
7839 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7840 }
7841 
7842 static int
7843 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2(void)
7844 {
7845 	return test_mixed_auth_cipher(
7846 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, IN_PLACE, 1);
7847 }
7848 
7849 static int
7850 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7851 {
7852 	return test_mixed_auth_cipher(
7853 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7854 }
7855 
7856 static int
7857 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7858 {
7859 	return test_mixed_auth_cipher_sgl(
7860 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7861 }
7862 
7863 static int
7864 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7865 {
7866 	return test_mixed_auth_cipher_sgl(
7867 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7868 }
7869 
7870 static int
7871 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop(void)
7872 {
7873 	return test_mixed_auth_cipher(
7874 		&auth_aes_cmac_cipher_aes_ctr_test_case_2, OUT_OF_PLACE, 1);
7875 }
7876 
7877 /** MIXED AUTH + CIPHER */
7878 
7879 static int
7880 test_auth_zuc_cipher_snow_test_case_1(void)
7881 {
7882 	return test_mixed_auth_cipher(
7883 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7884 }
7885 
7886 static int
7887 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7888 {
7889 	return test_mixed_auth_cipher(
7890 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7891 }
7892 
7893 static int
7894 test_auth_zuc_cipher_snow_test_case_1_inplace(void)
7895 {
7896 	return test_mixed_auth_cipher(
7897 		&auth_zuc_cipher_snow_test_case_1, IN_PLACE, 0);
7898 }
7899 
7900 static int
7901 test_verify_auth_zuc_cipher_snow_test_case_1_inplace(void)
7902 {
7903 	return test_mixed_auth_cipher(
7904 		&auth_zuc_cipher_snow_test_case_1, IN_PLACE, 1);
7905 }
7906 
7907 
7908 static int
7909 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7910 {
7911 	return test_mixed_auth_cipher(
7912 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7913 }
7914 
7915 static int
7916 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7917 {
7918 	return test_mixed_auth_cipher(
7919 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7920 }
7921 
7922 static int
7923 test_auth_aes_cmac_cipher_snow_test_case_1_inplace(void)
7924 {
7925 	return test_mixed_auth_cipher(
7926 		&auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 0);
7927 }
7928 
7929 static int
7930 test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace(void)
7931 {
7932 	return test_mixed_auth_cipher(
7933 		&auth_aes_cmac_cipher_snow_test_case_1, IN_PLACE, 1);
7934 }
7935 
7936 static int
7937 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7938 {
7939 	return test_mixed_auth_cipher(
7940 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7941 }
7942 
7943 static int
7944 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7945 {
7946 	return test_mixed_auth_cipher(
7947 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7948 }
7949 
7950 static int
7951 test_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void)
7952 {
7953 	return test_mixed_auth_cipher(
7954 		&auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7955 }
7956 
7957 static int
7958 test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace(void)
7959 {
7960 	return test_mixed_auth_cipher(
7961 		&auth_zuc_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7962 }
7963 
7964 static int
7965 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7966 {
7967 	return test_mixed_auth_cipher(
7968 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7969 }
7970 
7971 static int
7972 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7973 {
7974 	return test_mixed_auth_cipher(
7975 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7976 }
7977 
7978 static int
7979 test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void)
7980 {
7981 	return test_mixed_auth_cipher_sgl(
7982 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7983 }
7984 
7985 static int
7986 test_auth_snow_cipher_aes_ctr_test_case_1_inplace(void)
7987 {
7988 	return test_mixed_auth_cipher(
7989 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7990 }
7991 
7992 static int
7993 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl(void)
7994 {
7995 	return test_mixed_auth_cipher_sgl(
7996 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7997 }
7998 
7999 static int
8000 test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace(void)
8001 {
8002 	return test_mixed_auth_cipher(
8003 		&auth_snow_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
8004 }
8005 
8006 static int
8007 test_auth_snow_cipher_zuc_test_case_1(void)
8008 {
8009 	return test_mixed_auth_cipher(
8010 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8011 }
8012 
8013 static int
8014 test_verify_auth_snow_cipher_zuc_test_case_1(void)
8015 {
8016 	return test_mixed_auth_cipher(
8017 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8018 }
8019 
8020 static int
8021 test_auth_snow_cipher_zuc_test_case_1_inplace(void)
8022 {
8023 	return test_mixed_auth_cipher(
8024 		&auth_snow_cipher_zuc_test_case_1, IN_PLACE, 0);
8025 }
8026 
8027 static int
8028 test_verify_auth_snow_cipher_zuc_test_case_1_inplace(void)
8029 {
8030 	return test_mixed_auth_cipher(
8031 		&auth_snow_cipher_zuc_test_case_1, IN_PLACE, 1);
8032 }
8033 
8034 static int
8035 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
8036 {
8037 	return test_mixed_auth_cipher(
8038 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8039 }
8040 
8041 static int
8042 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
8043 {
8044 	return test_mixed_auth_cipher(
8045 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8046 }
8047 static int
8048 test_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void)
8049 {
8050 	return test_mixed_auth_cipher(
8051 		&auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 0);
8052 }
8053 
8054 static int
8055 test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace(void)
8056 {
8057 	return test_mixed_auth_cipher(
8058 		&auth_aes_cmac_cipher_zuc_test_case_1, IN_PLACE, 1);
8059 }
8060 
8061 static int
8062 test_auth_null_cipher_snow_test_case_1(void)
8063 {
8064 	return test_mixed_auth_cipher(
8065 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
8066 }
8067 
8068 static int
8069 test_verify_auth_null_cipher_snow_test_case_1(void)
8070 {
8071 	return test_mixed_auth_cipher(
8072 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
8073 }
8074 
8075 static int
8076 test_auth_null_cipher_zuc_test_case_1(void)
8077 {
8078 	return test_mixed_auth_cipher(
8079 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
8080 }
8081 
8082 static int
8083 test_verify_auth_null_cipher_zuc_test_case_1(void)
8084 {
8085 	return test_mixed_auth_cipher(
8086 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
8087 }
8088 
8089 static int
8090 test_auth_snow_cipher_null_test_case_1(void)
8091 {
8092 	return test_mixed_auth_cipher(
8093 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8094 }
8095 
8096 static int
8097 test_verify_auth_snow_cipher_null_test_case_1(void)
8098 {
8099 	return test_mixed_auth_cipher(
8100 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8101 }
8102 
8103 static int
8104 test_auth_zuc_cipher_null_test_case_1(void)
8105 {
8106 	return test_mixed_auth_cipher(
8107 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8108 }
8109 
8110 static int
8111 test_verify_auth_zuc_cipher_null_test_case_1(void)
8112 {
8113 	return test_mixed_auth_cipher(
8114 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8115 }
8116 
8117 static int
8118 test_auth_null_cipher_aes_ctr_test_case_1(void)
8119 {
8120 	return test_mixed_auth_cipher(
8121 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
8122 }
8123 
8124 static int
8125 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
8126 {
8127 	return test_mixed_auth_cipher(
8128 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
8129 }
8130 
8131 static int
8132 test_auth_aes_cmac_cipher_null_test_case_1(void)
8133 {
8134 	return test_mixed_auth_cipher(
8135 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
8136 }
8137 
8138 static int
8139 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
8140 {
8141 	return test_mixed_auth_cipher(
8142 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
8143 }
8144 
8145 /* ***** AEAD algorithm Tests ***** */
8146 
8147 static int
8148 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
8149 		enum rte_crypto_aead_operation op,
8150 		const uint8_t *key, const uint8_t key_len,
8151 		const uint16_t aad_len, const uint8_t auth_len,
8152 		uint8_t iv_len)
8153 {
8154 	uint8_t aead_key[key_len];
8155 
8156 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8157 	struct crypto_unittest_params *ut_params = &unittest_params;
8158 
8159 	memcpy(aead_key, key, key_len);
8160 
8161 	/* Setup AEAD Parameters */
8162 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8163 	ut_params->aead_xform.next = NULL;
8164 	ut_params->aead_xform.aead.algo = algo;
8165 	ut_params->aead_xform.aead.op = op;
8166 	ut_params->aead_xform.aead.key.data = aead_key;
8167 	ut_params->aead_xform.aead.key.length = key_len;
8168 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
8169 	ut_params->aead_xform.aead.iv.length = iv_len;
8170 	ut_params->aead_xform.aead.digest_length = auth_len;
8171 	ut_params->aead_xform.aead.aad_length = aad_len;
8172 
8173 	debug_hexdump(stdout, "key:", key, key_len);
8174 
8175 	/* Create Crypto session*/
8176 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
8177 			&ut_params->aead_xform, ts_params->session_mpool);
8178 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
8179 		return TEST_SKIPPED;
8180 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8181 	return 0;
8182 }
8183 
8184 static int
8185 create_aead_xform(struct rte_crypto_op *op,
8186 		enum rte_crypto_aead_algorithm algo,
8187 		enum rte_crypto_aead_operation aead_op,
8188 		uint8_t *key, const uint8_t key_len,
8189 		const uint8_t aad_len, const uint8_t auth_len,
8190 		uint8_t iv_len)
8191 {
8192 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
8193 			"failed to allocate space for crypto transform");
8194 
8195 	struct rte_crypto_sym_op *sym_op = op->sym;
8196 
8197 	/* Setup AEAD Parameters */
8198 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
8199 	sym_op->xform->next = NULL;
8200 	sym_op->xform->aead.algo = algo;
8201 	sym_op->xform->aead.op = aead_op;
8202 	sym_op->xform->aead.key.data = key;
8203 	sym_op->xform->aead.key.length = key_len;
8204 	sym_op->xform->aead.iv.offset = IV_OFFSET;
8205 	sym_op->xform->aead.iv.length = iv_len;
8206 	sym_op->xform->aead.digest_length = auth_len;
8207 	sym_op->xform->aead.aad_length = aad_len;
8208 
8209 	debug_hexdump(stdout, "key:", key, key_len);
8210 
8211 	return 0;
8212 }
8213 
8214 static int
8215 create_aead_operation(enum rte_crypto_aead_operation op,
8216 		const struct aead_test_data *tdata)
8217 {
8218 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8219 	struct crypto_unittest_params *ut_params = &unittest_params;
8220 
8221 	uint8_t *plaintext, *ciphertext;
8222 	unsigned int aad_pad_len, plaintext_pad_len;
8223 
8224 	/* Generate Crypto op data structure */
8225 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8226 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8227 	TEST_ASSERT_NOT_NULL(ut_params->op,
8228 			"Failed to allocate symmetric crypto operation struct");
8229 
8230 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8231 
8232 	/* Append aad data */
8233 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8234 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
8235 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8236 				aad_pad_len);
8237 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8238 				"no room to append aad");
8239 
8240 		sym_op->aead.aad.phys_addr =
8241 				rte_pktmbuf_iova(ut_params->ibuf);
8242 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
8243 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
8244 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data + 18,
8245 			tdata->aad.len);
8246 
8247 		/* Append IV at the end of the crypto operation*/
8248 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8249 				uint8_t *, IV_OFFSET);
8250 
8251 		/* Copy IV 1 byte after the IV pointer, according to the API */
8252 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8253 		debug_hexdump(stdout, "iv:", iv_ptr + 1,
8254 			tdata->iv.len);
8255 	} else {
8256 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
8257 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8258 				aad_pad_len);
8259 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8260 				"no room to append aad");
8261 
8262 		sym_op->aead.aad.phys_addr =
8263 				rte_pktmbuf_iova(ut_params->ibuf);
8264 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8265 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8266 			tdata->aad.len);
8267 
8268 		/* Append IV at the end of the crypto operation*/
8269 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8270 				uint8_t *, IV_OFFSET);
8271 
8272 		if (tdata->iv.len == 0) {
8273 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8274 			debug_hexdump(stdout, "iv:", iv_ptr,
8275 				AES_GCM_J0_LENGTH);
8276 		} else {
8277 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8278 			debug_hexdump(stdout, "iv:", iv_ptr,
8279 				tdata->iv.len);
8280 		}
8281 	}
8282 
8283 	/* Append plaintext/ciphertext */
8284 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8285 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8286 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8287 				plaintext_pad_len);
8288 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8289 
8290 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8291 		debug_hexdump(stdout, "plaintext:", plaintext,
8292 				tdata->plaintext.len);
8293 
8294 		if (ut_params->obuf) {
8295 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8296 					ut_params->obuf,
8297 					plaintext_pad_len + aad_pad_len);
8298 			TEST_ASSERT_NOT_NULL(ciphertext,
8299 					"no room to append ciphertext");
8300 
8301 			memset(ciphertext + aad_pad_len, 0,
8302 					tdata->ciphertext.len);
8303 		}
8304 	} else {
8305 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8306 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8307 				plaintext_pad_len);
8308 		TEST_ASSERT_NOT_NULL(ciphertext,
8309 				"no room to append ciphertext");
8310 
8311 		memcpy(ciphertext, tdata->ciphertext.data,
8312 				tdata->ciphertext.len);
8313 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8314 				tdata->ciphertext.len);
8315 
8316 		if (ut_params->obuf) {
8317 			plaintext = (uint8_t *)rte_pktmbuf_append(
8318 					ut_params->obuf,
8319 					plaintext_pad_len + aad_pad_len);
8320 			TEST_ASSERT_NOT_NULL(plaintext,
8321 					"no room to append plaintext");
8322 
8323 			memset(plaintext + aad_pad_len, 0,
8324 					tdata->plaintext.len);
8325 		}
8326 	}
8327 
8328 	/* Append digest data */
8329 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8330 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8331 				ut_params->obuf ? ut_params->obuf :
8332 						ut_params->ibuf,
8333 						tdata->auth_tag.len);
8334 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8335 				"no room to append digest");
8336 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8337 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8338 				ut_params->obuf ? ut_params->obuf :
8339 						ut_params->ibuf,
8340 						plaintext_pad_len +
8341 						aad_pad_len);
8342 	} else {
8343 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8344 				ut_params->ibuf, tdata->auth_tag.len);
8345 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8346 				"no room to append digest");
8347 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8348 				ut_params->ibuf,
8349 				plaintext_pad_len + aad_pad_len);
8350 
8351 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8352 			tdata->auth_tag.len);
8353 		debug_hexdump(stdout, "digest:",
8354 			sym_op->aead.digest.data,
8355 			tdata->auth_tag.len);
8356 	}
8357 
8358 	sym_op->aead.data.length = tdata->plaintext.len;
8359 	sym_op->aead.data.offset = aad_pad_len;
8360 
8361 	return 0;
8362 }
8363 
8364 static int
8365 test_authenticated_encryption(const struct aead_test_data *tdata)
8366 {
8367 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8368 	struct crypto_unittest_params *ut_params = &unittest_params;
8369 
8370 	int retval;
8371 	uint8_t *ciphertext, *auth_tag;
8372 	uint16_t plaintext_pad_len;
8373 	uint32_t i;
8374 	struct rte_cryptodev_info dev_info;
8375 
8376 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8377 	uint64_t feat_flags = dev_info.feature_flags;
8378 
8379 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8380 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8381 		printf("Device doesn't support RAW data-path APIs.\n");
8382 		return TEST_SKIPPED;
8383 	}
8384 
8385 	/* Verify the capabilities */
8386 	struct rte_cryptodev_sym_capability_idx cap_idx;
8387 	const struct rte_cryptodev_symmetric_capability *capability;
8388 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8389 	cap_idx.algo.aead = tdata->algo;
8390 	capability = rte_cryptodev_sym_capability_get(
8391 			ts_params->valid_devs[0], &cap_idx);
8392 	if (capability == NULL)
8393 		return TEST_SKIPPED;
8394 	if (rte_cryptodev_sym_capability_check_aead(
8395 			capability, tdata->key.len, tdata->auth_tag.len,
8396 			tdata->aad.len, tdata->iv.len))
8397 		return TEST_SKIPPED;
8398 
8399 	/* Create AEAD session */
8400 	retval = create_aead_session(ts_params->valid_devs[0],
8401 			tdata->algo,
8402 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8403 			tdata->key.data, tdata->key.len,
8404 			tdata->aad.len, tdata->auth_tag.len,
8405 			tdata->iv.len);
8406 	if (retval < 0)
8407 		return retval;
8408 
8409 	if (tdata->aad.len > MBUF_SIZE) {
8410 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8411 		/* Populate full size of add data */
8412 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8413 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8414 	} else
8415 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8416 
8417 	/* clear mbuf payload */
8418 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8419 			rte_pktmbuf_tailroom(ut_params->ibuf));
8420 
8421 	/* Create AEAD operation */
8422 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8423 	if (retval < 0)
8424 		return retval;
8425 
8426 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8427 
8428 	ut_params->op->sym->m_src = ut_params->ibuf;
8429 
8430 	/* Process crypto operation */
8431 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8432 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8433 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8434 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8435 				ut_params->op, 0, 0, 0, 0);
8436 	else
8437 		TEST_ASSERT_NOT_NULL(
8438 			process_crypto_request(ts_params->valid_devs[0],
8439 			ut_params->op), "failed to process sym crypto op");
8440 
8441 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8442 			"crypto op processing failed");
8443 
8444 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8445 
8446 	if (ut_params->op->sym->m_dst) {
8447 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8448 				uint8_t *);
8449 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8450 				uint8_t *, plaintext_pad_len);
8451 	} else {
8452 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8453 				uint8_t *,
8454 				ut_params->op->sym->cipher.data.offset);
8455 		auth_tag = ciphertext + plaintext_pad_len;
8456 	}
8457 
8458 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8459 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8460 
8461 	/* Validate obuf */
8462 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8463 			ciphertext,
8464 			tdata->ciphertext.data,
8465 			tdata->ciphertext.len,
8466 			"Ciphertext data not as expected");
8467 
8468 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8469 			auth_tag,
8470 			tdata->auth_tag.data,
8471 			tdata->auth_tag.len,
8472 			"Generated auth tag not as expected");
8473 
8474 	return 0;
8475 
8476 }
8477 
8478 #ifdef RTE_LIB_SECURITY
8479 static int
8480 security_proto_supported(enum rte_security_session_action_type action,
8481 	enum rte_security_session_protocol proto)
8482 {
8483 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8484 
8485 	const struct rte_security_capability *capabilities;
8486 	const struct rte_security_capability *capability;
8487 	uint16_t i = 0;
8488 
8489 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8490 				rte_cryptodev_get_sec_ctx(
8491 				ts_params->valid_devs[0]);
8492 
8493 
8494 	capabilities = rte_security_capabilities_get(ctx);
8495 
8496 	if (capabilities == NULL)
8497 		return -ENOTSUP;
8498 
8499 	while ((capability = &capabilities[i++])->action !=
8500 			RTE_SECURITY_ACTION_TYPE_NONE) {
8501 		if (capability->action == action &&
8502 				capability->protocol == proto)
8503 			return 0;
8504 	}
8505 
8506 	return -ENOTSUP;
8507 }
8508 
8509 /* Basic algorithm run function for async inplace mode.
8510  * Creates a session from input parameters and runs one operation
8511  * on input_vec. Checks the output of the crypto operation against
8512  * output_vec.
8513  */
8514 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8515 			   enum rte_crypto_auth_operation opa,
8516 			   const uint8_t *input_vec, unsigned int input_vec_len,
8517 			   const uint8_t *output_vec,
8518 			   unsigned int output_vec_len,
8519 			   enum rte_crypto_cipher_algorithm cipher_alg,
8520 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8521 			   enum rte_crypto_auth_algorithm auth_alg,
8522 			   const uint8_t *auth_key, uint32_t auth_key_len,
8523 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8524 			   uint8_t packet_direction, uint8_t sn_size,
8525 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8526 {
8527 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8528 	struct crypto_unittest_params *ut_params = &unittest_params;
8529 	uint8_t *plaintext;
8530 	int ret = TEST_SUCCESS;
8531 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8532 				rte_cryptodev_get_sec_ctx(
8533 				ts_params->valid_devs[0]);
8534 	struct rte_cryptodev_info dev_info;
8535 	uint64_t feat_flags;
8536 
8537 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8538 	feat_flags = dev_info.feature_flags;
8539 
8540 	/* Verify the capabilities */
8541 	struct rte_security_capability_idx sec_cap_idx;
8542 
8543 	sec_cap_idx.action = ut_params->type;
8544 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8545 	sec_cap_idx.pdcp.domain = domain;
8546 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8547 		return TEST_SKIPPED;
8548 
8549 	/* Generate test mbuf data */
8550 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8551 
8552 	/* clear mbuf payload */
8553 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8554 			rte_pktmbuf_tailroom(ut_params->ibuf));
8555 
8556 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8557 						  input_vec_len);
8558 	memcpy(plaintext, input_vec, input_vec_len);
8559 
8560 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8561 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8562 		printf("Device does not support RAW data-path APIs.\n");
8563 		return TEST_SKIPPED;
8564 	}
8565 	/* Out of place support */
8566 	if (oop) {
8567 		/*
8568 		 * For out-op-place we need to alloc another mbuf
8569 		 */
8570 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8571 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8572 	}
8573 
8574 	/* Setup Cipher Parameters */
8575 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8576 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8577 	ut_params->cipher_xform.cipher.op = opc;
8578 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8579 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8580 	ut_params->cipher_xform.cipher.iv.length =
8581 				packet_direction ? 4 : 0;
8582 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8583 
8584 	/* Setup HMAC Parameters if ICV header is required */
8585 	if (auth_alg != 0) {
8586 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8587 		ut_params->auth_xform.next = NULL;
8588 		ut_params->auth_xform.auth.algo = auth_alg;
8589 		ut_params->auth_xform.auth.op = opa;
8590 		ut_params->auth_xform.auth.key.data = auth_key;
8591 		ut_params->auth_xform.auth.key.length = auth_key_len;
8592 
8593 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8594 	} else {
8595 		ut_params->cipher_xform.next = NULL;
8596 	}
8597 
8598 	struct rte_security_session_conf sess_conf = {
8599 		.action_type = ut_params->type,
8600 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8601 		{.pdcp = {
8602 			.bearer = bearer,
8603 			.domain = domain,
8604 			.pkt_dir = packet_direction,
8605 			.sn_size = sn_size,
8606 			.hfn = packet_direction ? 0 : hfn,
8607 			/**
8608 			 * hfn can be set as pdcp_test_hfn[i]
8609 			 * if hfn_ovrd is not set. Here, PDCP
8610 			 * packet direction is just used to
8611 			 * run half of the cases with session
8612 			 * HFN and other half with per packet
8613 			 * HFN.
8614 			 */
8615 			.hfn_threshold = hfn_threshold,
8616 			.hfn_ovrd = packet_direction ? 1 : 0,
8617 			.sdap_enabled = sdap,
8618 		} },
8619 		.crypto_xform = &ut_params->cipher_xform
8620 	};
8621 
8622 	/* Create security session */
8623 	ut_params->sec_session = rte_security_session_create(ctx,
8624 				&sess_conf, ts_params->session_mpool,
8625 				NULL);
8626 
8627 	if (!ut_params->sec_session) {
8628 		printf("TestCase %s()-%d line %d failed %s: ",
8629 			__func__, i, __LINE__, "Failed to allocate session");
8630 		ret = TEST_FAILED;
8631 		goto on_err;
8632 	}
8633 
8634 	/* Generate crypto op data structure */
8635 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8636 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8637 	if (!ut_params->op) {
8638 		printf("TestCase %s()-%d line %d failed %s: ",
8639 			__func__, i, __LINE__,
8640 			"Failed to allocate symmetric crypto operation struct");
8641 		ret = TEST_FAILED;
8642 		goto on_err;
8643 	}
8644 
8645 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8646 					uint32_t *, IV_OFFSET);
8647 	*per_pkt_hfn = packet_direction ? hfn : 0;
8648 
8649 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8650 
8651 	/* set crypto operation source mbuf */
8652 	ut_params->op->sym->m_src = ut_params->ibuf;
8653 	if (oop)
8654 		ut_params->op->sym->m_dst = ut_params->obuf;
8655 
8656 	/* Process crypto operation */
8657 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8658 		/* filling lengths */
8659 		ut_params->op->sym->cipher.data.length = ut_params->op->sym->m_src->pkt_len;
8660 		ut_params->op->sym->auth.data.length = ut_params->op->sym->m_src->pkt_len;
8661 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8662 			ut_params->op, 1, 1, 0, 0);
8663 	} else {
8664 		ut_params->op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
8665 	}
8666 	if (ut_params->op == NULL) {
8667 		printf("TestCase %s()-%d line %d failed %s: ",
8668 			__func__, i, __LINE__,
8669 			"failed to process sym crypto op");
8670 		ret = TEST_FAILED;
8671 		goto on_err;
8672 	}
8673 
8674 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8675 		printf("TestCase %s()-%d line %d failed %s: ",
8676 			__func__, i, __LINE__, "crypto op processing failed");
8677 		ret = TEST_FAILED;
8678 		goto on_err;
8679 	}
8680 
8681 	/* Validate obuf */
8682 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8683 			uint8_t *);
8684 	if (oop) {
8685 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8686 				uint8_t *);
8687 	}
8688 
8689 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8690 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8691 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8692 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8693 		ret = TEST_FAILED;
8694 		goto on_err;
8695 	}
8696 
8697 on_err:
8698 	rte_crypto_op_free(ut_params->op);
8699 	ut_params->op = NULL;
8700 
8701 	if (ut_params->sec_session)
8702 		rte_security_session_destroy(ctx, ut_params->sec_session);
8703 	ut_params->sec_session = NULL;
8704 
8705 	rte_pktmbuf_free(ut_params->ibuf);
8706 	ut_params->ibuf = NULL;
8707 	if (oop) {
8708 		rte_pktmbuf_free(ut_params->obuf);
8709 		ut_params->obuf = NULL;
8710 	}
8711 
8712 	return ret;
8713 }
8714 
8715 static int
8716 test_pdcp_proto_SGL(int i, int oop,
8717 	enum rte_crypto_cipher_operation opc,
8718 	enum rte_crypto_auth_operation opa,
8719 	uint8_t *input_vec,
8720 	unsigned int input_vec_len,
8721 	uint8_t *output_vec,
8722 	unsigned int output_vec_len,
8723 	uint32_t fragsz,
8724 	uint32_t fragsz_oop)
8725 {
8726 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8727 	struct crypto_unittest_params *ut_params = &unittest_params;
8728 	uint8_t *plaintext;
8729 	struct rte_mbuf *buf, *buf_oop = NULL;
8730 	int ret = TEST_SUCCESS;
8731 	int to_trn = 0;
8732 	int to_trn_tbl[16];
8733 	int segs = 1;
8734 	unsigned int trn_data = 0;
8735 	struct rte_cryptodev_info dev_info;
8736 	uint64_t feat_flags;
8737 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8738 				rte_cryptodev_get_sec_ctx(
8739 				ts_params->valid_devs[0]);
8740 	struct rte_mbuf *temp_mbuf;
8741 
8742 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8743 	feat_flags = dev_info.feature_flags;
8744 
8745 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8746 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8747 		printf("Device does not support RAW data-path APIs.\n");
8748 		return -ENOTSUP;
8749 	}
8750 	/* Verify the capabilities */
8751 	struct rte_security_capability_idx sec_cap_idx;
8752 
8753 	sec_cap_idx.action = ut_params->type;
8754 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8755 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8756 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8757 		return TEST_SKIPPED;
8758 
8759 	if (fragsz > input_vec_len)
8760 		fragsz = input_vec_len;
8761 
8762 	uint16_t plaintext_len = fragsz;
8763 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8764 
8765 	if (fragsz_oop > output_vec_len)
8766 		frag_size_oop = output_vec_len;
8767 
8768 	int ecx = 0;
8769 	if (input_vec_len % fragsz != 0) {
8770 		if (input_vec_len / fragsz + 1 > 16)
8771 			return 1;
8772 	} else if (input_vec_len / fragsz > 16)
8773 		return 1;
8774 
8775 	/* Out of place support */
8776 	if (oop) {
8777 		/*
8778 		 * For out-op-place we need to alloc another mbuf
8779 		 */
8780 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8781 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8782 		buf_oop = ut_params->obuf;
8783 	}
8784 
8785 	/* Generate test mbuf data */
8786 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8787 
8788 	/* clear mbuf payload */
8789 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8790 			rte_pktmbuf_tailroom(ut_params->ibuf));
8791 
8792 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8793 						  plaintext_len);
8794 	memcpy(plaintext, input_vec, plaintext_len);
8795 	trn_data += plaintext_len;
8796 
8797 	buf = ut_params->ibuf;
8798 
8799 	/*
8800 	 * Loop until no more fragments
8801 	 */
8802 
8803 	while (trn_data < input_vec_len) {
8804 		++segs;
8805 		to_trn = (input_vec_len - trn_data < fragsz) ?
8806 				(input_vec_len - trn_data) : fragsz;
8807 
8808 		to_trn_tbl[ecx++] = to_trn;
8809 
8810 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8811 		buf = buf->next;
8812 
8813 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8814 				rte_pktmbuf_tailroom(buf));
8815 
8816 		/* OOP */
8817 		if (oop && !fragsz_oop) {
8818 			buf_oop->next =
8819 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8820 			buf_oop = buf_oop->next;
8821 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8822 					0, rte_pktmbuf_tailroom(buf_oop));
8823 			rte_pktmbuf_append(buf_oop, to_trn);
8824 		}
8825 
8826 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8827 				to_trn);
8828 
8829 		memcpy(plaintext, input_vec + trn_data, to_trn);
8830 		trn_data += to_trn;
8831 	}
8832 
8833 	ut_params->ibuf->nb_segs = segs;
8834 
8835 	segs = 1;
8836 	if (fragsz_oop && oop) {
8837 		to_trn = 0;
8838 		ecx = 0;
8839 
8840 		trn_data = frag_size_oop;
8841 		while (trn_data < output_vec_len) {
8842 			++segs;
8843 			to_trn =
8844 				(output_vec_len - trn_data <
8845 						frag_size_oop) ?
8846 				(output_vec_len - trn_data) :
8847 						frag_size_oop;
8848 
8849 			to_trn_tbl[ecx++] = to_trn;
8850 
8851 			buf_oop->next =
8852 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8853 			buf_oop = buf_oop->next;
8854 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8855 					0, rte_pktmbuf_tailroom(buf_oop));
8856 			rte_pktmbuf_append(buf_oop, to_trn);
8857 
8858 			trn_data += to_trn;
8859 		}
8860 		ut_params->obuf->nb_segs = segs;
8861 	}
8862 
8863 	/* Setup Cipher Parameters */
8864 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8865 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8866 	ut_params->cipher_xform.cipher.op = opc;
8867 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8868 	ut_params->cipher_xform.cipher.key.length =
8869 					pdcp_test_params[i].cipher_key_len;
8870 	ut_params->cipher_xform.cipher.iv.length = 0;
8871 
8872 	/* Setup HMAC Parameters if ICV header is required */
8873 	if (pdcp_test_params[i].auth_alg != 0) {
8874 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8875 		ut_params->auth_xform.next = NULL;
8876 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8877 		ut_params->auth_xform.auth.op = opa;
8878 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8879 		ut_params->auth_xform.auth.key.length =
8880 					pdcp_test_params[i].auth_key_len;
8881 
8882 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8883 	} else {
8884 		ut_params->cipher_xform.next = NULL;
8885 	}
8886 
8887 	struct rte_security_session_conf sess_conf = {
8888 		.action_type = ut_params->type,
8889 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8890 		{.pdcp = {
8891 			.bearer = pdcp_test_bearer[i],
8892 			.domain = pdcp_test_params[i].domain,
8893 			.pkt_dir = pdcp_test_packet_direction[i],
8894 			.sn_size = pdcp_test_data_sn_size[i],
8895 			.hfn = pdcp_test_hfn[i],
8896 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8897 			.hfn_ovrd = 0,
8898 		} },
8899 		.crypto_xform = &ut_params->cipher_xform
8900 	};
8901 
8902 	/* Create security session */
8903 	ut_params->sec_session = rte_security_session_create(ctx,
8904 				&sess_conf, ts_params->session_mpool,
8905 				ts_params->session_priv_mpool);
8906 
8907 	if (!ut_params->sec_session) {
8908 		printf("TestCase %s()-%d line %d failed %s: ",
8909 			__func__, i, __LINE__, "Failed to allocate session");
8910 		ret = TEST_FAILED;
8911 		goto on_err;
8912 	}
8913 
8914 	/* Generate crypto op data structure */
8915 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8916 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8917 	if (!ut_params->op) {
8918 		printf("TestCase %s()-%d line %d failed %s: ",
8919 			__func__, i, __LINE__,
8920 			"Failed to allocate symmetric crypto operation struct");
8921 		ret = TEST_FAILED;
8922 		goto on_err;
8923 	}
8924 
8925 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8926 
8927 	/* set crypto operation source mbuf */
8928 	ut_params->op->sym->m_src = ut_params->ibuf;
8929 	if (oop)
8930 		ut_params->op->sym->m_dst = ut_params->obuf;
8931 
8932 	/* Process crypto operation */
8933 	temp_mbuf = ut_params->op->sym->m_src;
8934 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8935 		/* filling lengths */
8936 		while (temp_mbuf) {
8937 			ut_params->op->sym->cipher.data.length
8938 				+= temp_mbuf->pkt_len;
8939 			ut_params->op->sym->auth.data.length
8940 				+= temp_mbuf->pkt_len;
8941 			temp_mbuf = temp_mbuf->next;
8942 		}
8943 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8944 			ut_params->op, 1, 1, 0, 0);
8945 	} else {
8946 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8947 							ut_params->op);
8948 	}
8949 	if (ut_params->op == NULL) {
8950 		printf("TestCase %s()-%d line %d failed %s: ",
8951 			__func__, i, __LINE__,
8952 			"failed to process sym crypto op");
8953 		ret = TEST_FAILED;
8954 		goto on_err;
8955 	}
8956 
8957 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8958 		printf("TestCase %s()-%d line %d failed %s: ",
8959 			__func__, i, __LINE__, "crypto op processing failed");
8960 		ret = TEST_FAILED;
8961 		goto on_err;
8962 	}
8963 
8964 	/* Validate obuf */
8965 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8966 			uint8_t *);
8967 	if (oop) {
8968 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8969 				uint8_t *);
8970 	}
8971 	if (fragsz_oop)
8972 		fragsz = frag_size_oop;
8973 	if (memcmp(ciphertext, output_vec, fragsz)) {
8974 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8975 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8976 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8977 		ret = TEST_FAILED;
8978 		goto on_err;
8979 	}
8980 
8981 	buf = ut_params->op->sym->m_src->next;
8982 	if (oop)
8983 		buf = ut_params->op->sym->m_dst->next;
8984 
8985 	unsigned int off = fragsz;
8986 
8987 	ecx = 0;
8988 	while (buf) {
8989 		ciphertext = rte_pktmbuf_mtod(buf,
8990 				uint8_t *);
8991 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8992 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8993 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8994 			rte_hexdump(stdout, "reference", output_vec + off,
8995 					to_trn_tbl[ecx]);
8996 			ret = TEST_FAILED;
8997 			goto on_err;
8998 		}
8999 		off += to_trn_tbl[ecx++];
9000 		buf = buf->next;
9001 	}
9002 on_err:
9003 	rte_crypto_op_free(ut_params->op);
9004 	ut_params->op = NULL;
9005 
9006 	if (ut_params->sec_session)
9007 		rte_security_session_destroy(ctx, ut_params->sec_session);
9008 	ut_params->sec_session = NULL;
9009 
9010 	rte_pktmbuf_free(ut_params->ibuf);
9011 	ut_params->ibuf = NULL;
9012 	if (oop) {
9013 		rte_pktmbuf_free(ut_params->obuf);
9014 		ut_params->obuf = NULL;
9015 	}
9016 
9017 	return ret;
9018 }
9019 
9020 int
9021 test_pdcp_proto_cplane_encap(int i)
9022 {
9023 	return test_pdcp_proto(
9024 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9025 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9026 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9027 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9028 		pdcp_test_params[i].cipher_key_len,
9029 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9030 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9031 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9032 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9033 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9034 }
9035 
9036 int
9037 test_pdcp_proto_uplane_encap(int i)
9038 {
9039 	return test_pdcp_proto(
9040 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9041 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9042 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
9043 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9044 		pdcp_test_params[i].cipher_key_len,
9045 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9046 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9047 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9048 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9049 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9050 }
9051 
9052 int
9053 test_pdcp_proto_uplane_encap_with_int(int i)
9054 {
9055 	return test_pdcp_proto(
9056 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
9057 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9058 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9059 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9060 		pdcp_test_params[i].cipher_key_len,
9061 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9062 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9063 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9064 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9065 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9066 }
9067 
9068 int
9069 test_pdcp_proto_cplane_decap(int i)
9070 {
9071 	return test_pdcp_proto(
9072 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9073 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9074 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9075 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9076 		pdcp_test_params[i].cipher_key_len,
9077 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9078 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9079 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9080 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9081 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9082 }
9083 
9084 int
9085 test_pdcp_proto_uplane_decap(int i)
9086 {
9087 	return test_pdcp_proto(
9088 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9089 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
9090 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9091 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9092 		pdcp_test_params[i].cipher_key_len,
9093 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9094 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9095 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9096 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9097 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9098 }
9099 
9100 int
9101 test_pdcp_proto_uplane_decap_with_int(int i)
9102 {
9103 	return test_pdcp_proto(
9104 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
9105 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
9106 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
9107 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
9108 		pdcp_test_params[i].cipher_key_len,
9109 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
9110 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
9111 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
9112 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
9113 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
9114 }
9115 
9116 static int
9117 test_PDCP_PROTO_SGL_in_place_32B(void)
9118 {
9119 	/* i can be used for running any PDCP case
9120 	 * In this case it is uplane 12-bit AES-SNOW DL encap
9121 	 */
9122 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
9123 	return test_pdcp_proto_SGL(i, IN_PLACE,
9124 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9125 			RTE_CRYPTO_AUTH_OP_GENERATE,
9126 			pdcp_test_data_in[i],
9127 			pdcp_test_data_in_len[i],
9128 			pdcp_test_data_out[i],
9129 			pdcp_test_data_in_len[i]+4,
9130 			32, 0);
9131 }
9132 static int
9133 test_PDCP_PROTO_SGL_oop_32B_128B(void)
9134 {
9135 	/* i can be used for running any PDCP case
9136 	 * In this case it is uplane 18-bit NULL-NULL DL encap
9137 	 */
9138 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
9139 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
9140 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9141 			RTE_CRYPTO_AUTH_OP_GENERATE,
9142 			pdcp_test_data_in[i],
9143 			pdcp_test_data_in_len[i],
9144 			pdcp_test_data_out[i],
9145 			pdcp_test_data_in_len[i]+4,
9146 			32, 128);
9147 }
9148 static int
9149 test_PDCP_PROTO_SGL_oop_32B_40B(void)
9150 {
9151 	/* i can be used for running any PDCP case
9152 	 * In this case it is uplane 18-bit AES DL encap
9153 	 */
9154 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
9155 			+ DOWNLINK;
9156 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
9157 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9158 			RTE_CRYPTO_AUTH_OP_GENERATE,
9159 			pdcp_test_data_in[i],
9160 			pdcp_test_data_in_len[i],
9161 			pdcp_test_data_out[i],
9162 			pdcp_test_data_in_len[i],
9163 			32, 40);
9164 }
9165 static int
9166 test_PDCP_PROTO_SGL_oop_128B_32B(void)
9167 {
9168 	/* i can be used for running any PDCP case
9169 	 * In this case it is cplane 12-bit AES-ZUC DL encap
9170 	 */
9171 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
9172 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
9173 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9174 			RTE_CRYPTO_AUTH_OP_GENERATE,
9175 			pdcp_test_data_in[i],
9176 			pdcp_test_data_in_len[i],
9177 			pdcp_test_data_out[i],
9178 			pdcp_test_data_in_len[i]+4,
9179 			128, 32);
9180 }
9181 
9182 static int
9183 test_PDCP_SDAP_PROTO_encap_all(void)
9184 {
9185 	int i = 0, size = 0;
9186 	int err, all_err = TEST_SUCCESS;
9187 	const struct pdcp_sdap_test *cur_test;
9188 
9189 	size = RTE_DIM(list_pdcp_sdap_tests);
9190 
9191 	for (i = 0; i < size; i++) {
9192 		cur_test = &list_pdcp_sdap_tests[i];
9193 		err = test_pdcp_proto(
9194 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9195 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9196 			cur_test->in_len, cur_test->data_out,
9197 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9198 			cur_test->param.cipher_alg, cur_test->cipher_key,
9199 			cur_test->param.cipher_key_len,
9200 			cur_test->param.auth_alg,
9201 			cur_test->auth_key, cur_test->param.auth_key_len,
9202 			cur_test->bearer, cur_test->param.domain,
9203 			cur_test->packet_direction, cur_test->sn_size,
9204 			cur_test->hfn,
9205 			cur_test->hfn_threshold, SDAP_ENABLED);
9206 		if (err) {
9207 			printf("\t%d) %s: Encapsulation failed\n",
9208 					cur_test->test_idx,
9209 					cur_test->param.name);
9210 			err = TEST_FAILED;
9211 		} else {
9212 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
9213 					cur_test->param.name);
9214 			err = TEST_SUCCESS;
9215 		}
9216 		all_err += err;
9217 	}
9218 
9219 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9220 
9221 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9222 }
9223 
9224 static int
9225 test_PDCP_PROTO_short_mac(void)
9226 {
9227 	int i = 0, size = 0;
9228 	int err, all_err = TEST_SUCCESS;
9229 	const struct pdcp_short_mac_test *cur_test;
9230 
9231 	size = RTE_DIM(list_pdcp_smac_tests);
9232 
9233 	for (i = 0; i < size; i++) {
9234 		cur_test = &list_pdcp_smac_tests[i];
9235 		err = test_pdcp_proto(
9236 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9237 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9238 			cur_test->in_len, cur_test->data_out,
9239 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9240 			RTE_CRYPTO_CIPHER_NULL, NULL,
9241 			0, cur_test->param.auth_alg,
9242 			cur_test->auth_key, cur_test->param.auth_key_len,
9243 			0, cur_test->param.domain, 0, 0,
9244 			0, 0, 0);
9245 		if (err) {
9246 			printf("\t%d) %s: Short MAC test failed\n",
9247 					cur_test->test_idx,
9248 					cur_test->param.name);
9249 			err = TEST_FAILED;
9250 		} else {
9251 			printf("\t%d) %s: Short MAC test PASS\n",
9252 					cur_test->test_idx,
9253 					cur_test->param.name);
9254 			rte_hexdump(stdout, "MAC I",
9255 				    cur_test->data_out + cur_test->in_len + 2,
9256 				    2);
9257 			err = TEST_SUCCESS;
9258 		}
9259 		all_err += err;
9260 	}
9261 
9262 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9263 
9264 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9265 
9266 }
9267 
9268 static int
9269 test_PDCP_SDAP_PROTO_decap_all(void)
9270 {
9271 	int i = 0, size = 0;
9272 	int err, all_err = TEST_SUCCESS;
9273 	const struct pdcp_sdap_test *cur_test;
9274 
9275 	size = RTE_DIM(list_pdcp_sdap_tests);
9276 
9277 	for (i = 0; i < size; i++) {
9278 		cur_test = &list_pdcp_sdap_tests[i];
9279 		err = test_pdcp_proto(
9280 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9281 			RTE_CRYPTO_AUTH_OP_VERIFY,
9282 			cur_test->data_out,
9283 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9284 			cur_test->data_in, cur_test->in_len,
9285 			cur_test->param.cipher_alg,
9286 			cur_test->cipher_key, cur_test->param.cipher_key_len,
9287 			cur_test->param.auth_alg, cur_test->auth_key,
9288 			cur_test->param.auth_key_len, cur_test->bearer,
9289 			cur_test->param.domain, cur_test->packet_direction,
9290 			cur_test->sn_size, cur_test->hfn,
9291 			cur_test->hfn_threshold, SDAP_ENABLED);
9292 		if (err) {
9293 			printf("\t%d) %s: Decapsulation failed\n",
9294 					cur_test->test_idx,
9295 					cur_test->param.name);
9296 			err = TEST_FAILED;
9297 		} else {
9298 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9299 					cur_test->param.name);
9300 			err = TEST_SUCCESS;
9301 		}
9302 		all_err += err;
9303 	}
9304 
9305 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9306 
9307 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9308 }
9309 
9310 static int
9311 test_ipsec_proto_process(const struct ipsec_test_data td[],
9312 			 struct ipsec_test_data res_d[],
9313 			 int nb_td,
9314 			 bool silent,
9315 			 const struct ipsec_test_flags *flags)
9316 {
9317 	uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
9318 				0x0000, 0x001a};
9319 	uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
9320 				0xe82c, 0x4887};
9321 	const struct rte_ipv4_hdr *ipv4 =
9322 			(const struct rte_ipv4_hdr *)td[0].output_text.data;
9323 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9324 	struct crypto_unittest_params *ut_params = &unittest_params;
9325 	struct rte_security_capability_idx sec_cap_idx;
9326 	const struct rte_security_capability *sec_cap;
9327 	struct rte_security_ipsec_xform ipsec_xform;
9328 	uint8_t dev_id = ts_params->valid_devs[0];
9329 	enum rte_security_ipsec_sa_direction dir;
9330 	struct ipsec_test_data *res_d_tmp = NULL;
9331 	int salt_len, i, ret = TEST_SUCCESS;
9332 	struct rte_security_ctx *ctx;
9333 	uint8_t *input_text;
9334 	uint32_t src, dst;
9335 	uint32_t verify;
9336 
9337 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9338 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9339 
9340 	/* Use first test data to create session */
9341 
9342 	/* Copy IPsec xform */
9343 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9344 
9345 	dir = ipsec_xform.direction;
9346 	verify = flags->tunnel_hdr_verify;
9347 
9348 	memcpy(&src, &ipv4->src_addr, sizeof(ipv4->src_addr));
9349 	memcpy(&dst, &ipv4->dst_addr, sizeof(ipv4->dst_addr));
9350 
9351 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9352 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9353 			src += 1;
9354 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9355 			dst += 1;
9356 	}
9357 
9358 	if (td->ipsec_xform.mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
9359 		if (td->ipsec_xform.tunnel.type ==
9360 				RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
9361 			memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src,
9362 			       sizeof(src));
9363 			memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst,
9364 			       sizeof(dst));
9365 
9366 			if (flags->df == TEST_IPSEC_SET_DF_0_INNER_1)
9367 				ipsec_xform.tunnel.ipv4.df = 0;
9368 
9369 			if (flags->df == TEST_IPSEC_SET_DF_1_INNER_0)
9370 				ipsec_xform.tunnel.ipv4.df = 1;
9371 
9372 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9373 				ipsec_xform.tunnel.ipv4.dscp = 0;
9374 
9375 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9376 				ipsec_xform.tunnel.ipv4.dscp =
9377 						TEST_IPSEC_DSCP_VAL;
9378 
9379 		} else {
9380 			if (flags->dscp == TEST_IPSEC_SET_DSCP_0_INNER_1)
9381 				ipsec_xform.tunnel.ipv6.dscp = 0;
9382 
9383 			if (flags->dscp == TEST_IPSEC_SET_DSCP_1_INNER_0)
9384 				ipsec_xform.tunnel.ipv6.dscp =
9385 						TEST_IPSEC_DSCP_VAL;
9386 
9387 			memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
9388 			       sizeof(v6_src));
9389 			memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
9390 			       sizeof(v6_dst));
9391 		}
9392 	}
9393 
9394 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9395 
9396 	sec_cap_idx.action = ut_params->type;
9397 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9398 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9399 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9400 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9401 
9402 	if (flags->udp_encap)
9403 		ipsec_xform.options.udp_encap = 1;
9404 
9405 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9406 	if (sec_cap == NULL)
9407 		return TEST_SKIPPED;
9408 
9409 	/* Copy cipher session parameters */
9410 	if (td[0].aead) {
9411 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9412 		       sizeof(ut_params->aead_xform));
9413 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9414 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9415 
9416 		/* Verify crypto capabilities */
9417 		if (test_ipsec_crypto_caps_aead_verify(
9418 				sec_cap,
9419 				&ut_params->aead_xform) != 0) {
9420 			if (!silent)
9421 				RTE_LOG(INFO, USER1,
9422 					"Crypto capabilities not supported\n");
9423 			return TEST_SKIPPED;
9424 		}
9425 	} else if (td[0].auth_only) {
9426 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9427 		       sizeof(ut_params->auth_xform));
9428 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9429 
9430 		if (test_ipsec_crypto_caps_auth_verify(
9431 				sec_cap,
9432 				&ut_params->auth_xform) != 0) {
9433 			if (!silent)
9434 				RTE_LOG(INFO, USER1,
9435 					"Auth crypto capabilities not supported\n");
9436 			return TEST_SKIPPED;
9437 		}
9438 	} else {
9439 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
9440 		       sizeof(ut_params->cipher_xform));
9441 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9442 		       sizeof(ut_params->auth_xform));
9443 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
9444 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9445 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9446 
9447 		/* Verify crypto capabilities */
9448 
9449 		if (test_ipsec_crypto_caps_cipher_verify(
9450 				sec_cap,
9451 				&ut_params->cipher_xform) != 0) {
9452 			if (!silent)
9453 				RTE_LOG(INFO, USER1,
9454 					"Cipher crypto capabilities not supported\n");
9455 			return TEST_SKIPPED;
9456 		}
9457 
9458 		if (test_ipsec_crypto_caps_auth_verify(
9459 				sec_cap,
9460 				&ut_params->auth_xform) != 0) {
9461 			if (!silent)
9462 				RTE_LOG(INFO, USER1,
9463 					"Auth crypto capabilities not supported\n");
9464 			return TEST_SKIPPED;
9465 		}
9466 	}
9467 
9468 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9469 		return TEST_SKIPPED;
9470 
9471 	struct rte_security_session_conf sess_conf = {
9472 		.action_type = ut_params->type,
9473 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9474 	};
9475 
9476 	if (td[0].aead || td[0].aes_gmac) {
9477 		salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9478 		memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9479 	}
9480 
9481 	if (td[0].aead) {
9482 		sess_conf.ipsec = ipsec_xform;
9483 		sess_conf.crypto_xform = &ut_params->aead_xform;
9484 	} else if (td[0].auth_only) {
9485 		sess_conf.ipsec = ipsec_xform;
9486 		sess_conf.crypto_xform = &ut_params->auth_xform;
9487 	} else {
9488 		sess_conf.ipsec = ipsec_xform;
9489 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
9490 			sess_conf.crypto_xform = &ut_params->cipher_xform;
9491 			ut_params->cipher_xform.next = &ut_params->auth_xform;
9492 		} else {
9493 			sess_conf.crypto_xform = &ut_params->auth_xform;
9494 			ut_params->auth_xform.next = &ut_params->cipher_xform;
9495 		}
9496 	}
9497 
9498 	/* Create security session */
9499 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9500 					ts_params->session_mpool,
9501 					ts_params->session_priv_mpool);
9502 
9503 	if (ut_params->sec_session == NULL)
9504 		return TEST_SKIPPED;
9505 
9506 	for (i = 0; i < nb_td; i++) {
9507 		if (flags->antireplay &&
9508 		    (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)) {
9509 			sess_conf.ipsec.esn.value = td[i].ipsec_xform.esn.value;
9510 			ret = rte_security_session_update(ctx,
9511 				ut_params->sec_session, &sess_conf);
9512 			if (ret) {
9513 				printf("Could not update sequence number in "
9514 				       "session\n");
9515 				return TEST_SKIPPED;
9516 			}
9517 		}
9518 
9519 		/* Setup source mbuf payload */
9520 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9521 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9522 				rte_pktmbuf_tailroom(ut_params->ibuf));
9523 
9524 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9525 				td[i].input_text.len);
9526 
9527 		memcpy(input_text, td[i].input_text.data,
9528 		       td[i].input_text.len);
9529 
9530 		if (test_ipsec_pkt_update(input_text, flags))
9531 			return TEST_FAILED;
9532 
9533 		/* Generate crypto op data structure */
9534 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9535 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9536 		if (!ut_params->op) {
9537 			printf("TestCase %s line %d: %s\n",
9538 				__func__, __LINE__,
9539 				"failed to allocate crypto op");
9540 			ret = TEST_FAILED;
9541 			goto crypto_op_free;
9542 		}
9543 
9544 		/* Attach session to operation */
9545 		rte_security_attach_session(ut_params->op,
9546 					    ut_params->sec_session);
9547 
9548 		/* Set crypto operation mbufs */
9549 		ut_params->op->sym->m_src = ut_params->ibuf;
9550 		ut_params->op->sym->m_dst = NULL;
9551 
9552 		/* Copy IV in crypto operation when IV generation is disabled */
9553 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9554 		    ipsec_xform.options.iv_gen_disable == 1) {
9555 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9556 								uint8_t *,
9557 								IV_OFFSET);
9558 			int len;
9559 
9560 			if (td[i].aead)
9561 				len = td[i].xform.aead.aead.iv.length;
9562 			else if (td[i].aes_gmac)
9563 				len = td[i].xform.chain.auth.auth.iv.length;
9564 			else
9565 				len = td[i].xform.chain.cipher.cipher.iv.length;
9566 
9567 			memcpy(iv, td[i].iv.data, len);
9568 		}
9569 
9570 		/* Process crypto operation */
9571 		process_crypto_request(dev_id, ut_params->op);
9572 
9573 		ret = test_ipsec_status_check(&td[i], ut_params->op, flags, dir,
9574 					      i + 1);
9575 		if (ret != TEST_SUCCESS)
9576 			goto crypto_op_free;
9577 
9578 		if (res_d != NULL)
9579 			res_d_tmp = &res_d[i];
9580 
9581 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9582 					      res_d_tmp, silent, flags);
9583 		if (ret != TEST_SUCCESS)
9584 			goto crypto_op_free;
9585 
9586 		ret = test_ipsec_stats_verify(ctx, ut_params->sec_session,
9587 					      flags, dir);
9588 		if (ret != TEST_SUCCESS)
9589 			goto crypto_op_free;
9590 
9591 		rte_crypto_op_free(ut_params->op);
9592 		ut_params->op = NULL;
9593 
9594 		rte_pktmbuf_free(ut_params->ibuf);
9595 		ut_params->ibuf = NULL;
9596 	}
9597 
9598 crypto_op_free:
9599 	rte_crypto_op_free(ut_params->op);
9600 	ut_params->op = NULL;
9601 
9602 	rte_pktmbuf_free(ut_params->ibuf);
9603 	ut_params->ibuf = NULL;
9604 
9605 	if (ut_params->sec_session)
9606 		rte_security_session_destroy(ctx, ut_params->sec_session);
9607 	ut_params->sec_session = NULL;
9608 
9609 	return ret;
9610 }
9611 
9612 static int
9613 test_ipsec_proto_known_vec(const void *test_data)
9614 {
9615 	struct ipsec_test_data td_outb;
9616 	struct ipsec_test_flags flags;
9617 
9618 	memset(&flags, 0, sizeof(flags));
9619 
9620 	memcpy(&td_outb, test_data, sizeof(td_outb));
9621 
9622 	if (td_outb.aes_gmac || td_outb.aead ||
9623 	    ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) &&
9624 	     (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) {
9625 		/* Disable IV gen to be able to test with known vectors */
9626 		td_outb.ipsec_xform.options.iv_gen_disable = 1;
9627 	}
9628 
9629 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9630 }
9631 
9632 static int
9633 test_ipsec_proto_known_vec_inb(const void *test_data)
9634 {
9635 	const struct ipsec_test_data *td = test_data;
9636 	struct ipsec_test_flags flags;
9637 	struct ipsec_test_data td_inb;
9638 
9639 	memset(&flags, 0, sizeof(flags));
9640 
9641 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
9642 		test_ipsec_td_in_from_out(td, &td_inb);
9643 	else
9644 		memcpy(&td_inb, td, sizeof(td_inb));
9645 
9646 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9647 }
9648 
9649 static int
9650 test_ipsec_proto_known_vec_fragmented(const void *test_data)
9651 {
9652 	struct ipsec_test_data td_outb;
9653 	struct ipsec_test_flags flags;
9654 
9655 	memset(&flags, 0, sizeof(flags));
9656 	flags.fragment = true;
9657 
9658 	memcpy(&td_outb, test_data, sizeof(td_outb));
9659 
9660 	/* Disable IV gen to be able to test with known vectors */
9661 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9662 
9663 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9664 }
9665 
9666 static int
9667 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9668 {
9669 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9670 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9671 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9672 	int ret;
9673 
9674 	if (flags->iv_gen ||
9675 	    flags->sa_expiry_pkts_soft ||
9676 	    flags->sa_expiry_pkts_hard)
9677 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9678 
9679 	for (i = 0; i < RTE_DIM(alg_list); i++) {
9680 		test_ipsec_td_prepare(alg_list[i].param1,
9681 				      alg_list[i].param2,
9682 				      flags,
9683 				      td_outb,
9684 				      nb_pkts);
9685 
9686 		if (!td_outb->aead) {
9687 			enum rte_crypto_cipher_algorithm cipher_alg;
9688 			enum rte_crypto_auth_algorithm auth_alg;
9689 
9690 			cipher_alg = td_outb->xform.chain.cipher.cipher.algo;
9691 			auth_alg = td_outb->xform.chain.auth.auth.algo;
9692 
9693 			if (td_outb->aes_gmac && cipher_alg != RTE_CRYPTO_CIPHER_NULL)
9694 				continue;
9695 
9696 			/* ICV is not applicable for NULL auth */
9697 			if (flags->icv_corrupt &&
9698 			    auth_alg == RTE_CRYPTO_AUTH_NULL)
9699 				continue;
9700 
9701 			/* IV is not applicable for NULL cipher */
9702 			if (flags->iv_gen &&
9703 			    cipher_alg == RTE_CRYPTO_CIPHER_NULL)
9704 				continue;
9705 		}
9706 
9707 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9708 					       flags);
9709 		if (ret == TEST_SKIPPED)
9710 			continue;
9711 
9712 		if (ret == TEST_FAILED)
9713 			return TEST_FAILED;
9714 
9715 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9716 
9717 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9718 					       flags);
9719 		if (ret == TEST_SKIPPED)
9720 			continue;
9721 
9722 		if (ret == TEST_FAILED)
9723 			return TEST_FAILED;
9724 
9725 		if (flags->display_alg)
9726 			test_ipsec_display_alg(alg_list[i].param1,
9727 					       alg_list[i].param2);
9728 
9729 		pass_cnt++;
9730 	}
9731 
9732 	if (pass_cnt > 0)
9733 		return TEST_SUCCESS;
9734 	else
9735 		return TEST_SKIPPED;
9736 }
9737 
9738 static int
9739 test_ipsec_ah_proto_all(const struct ipsec_test_flags *flags)
9740 {
9741 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9742 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9743 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9744 	int ret;
9745 
9746 	for (i = 0; i < RTE_DIM(ah_alg_list); i++) {
9747 		test_ipsec_td_prepare(ah_alg_list[i].param1,
9748 				      ah_alg_list[i].param2,
9749 				      flags,
9750 				      td_outb,
9751 				      nb_pkts);
9752 
9753 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9754 					       flags);
9755 		if (ret == TEST_SKIPPED)
9756 			continue;
9757 
9758 		if (ret == TEST_FAILED)
9759 			return TEST_FAILED;
9760 
9761 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9762 
9763 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9764 					       flags);
9765 		if (ret == TEST_SKIPPED)
9766 			continue;
9767 
9768 		if (ret == TEST_FAILED)
9769 			return TEST_FAILED;
9770 
9771 		if (flags->display_alg)
9772 			test_ipsec_display_alg(ah_alg_list[i].param1,
9773 					       ah_alg_list[i].param2);
9774 
9775 		pass_cnt++;
9776 	}
9777 
9778 	if (pass_cnt > 0)
9779 		return TEST_SUCCESS;
9780 	else
9781 		return TEST_SKIPPED;
9782 }
9783 
9784 static int
9785 test_ipsec_proto_display_list(const void *data __rte_unused)
9786 {
9787 	struct ipsec_test_flags flags;
9788 
9789 	memset(&flags, 0, sizeof(flags));
9790 
9791 	flags.display_alg = true;
9792 
9793 	return test_ipsec_proto_all(&flags);
9794 }
9795 
9796 static int
9797 test_ipsec_proto_ah_tunnel_ipv4(const void *data __rte_unused)
9798 {
9799 	struct ipsec_test_flags flags;
9800 
9801 	memset(&flags, 0, sizeof(flags));
9802 
9803 	flags.ah = true;
9804 	flags.display_alg = true;
9805 
9806 	return test_ipsec_ah_proto_all(&flags);
9807 }
9808 
9809 static int
9810 test_ipsec_proto_ah_transport_ipv4(const void *data __rte_unused)
9811 {
9812 	struct ipsec_test_flags flags;
9813 
9814 	memset(&flags, 0, sizeof(flags));
9815 
9816 	flags.ah = true;
9817 	flags.transport = true;
9818 
9819 	return test_ipsec_ah_proto_all(&flags);
9820 }
9821 
9822 static int
9823 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9824 {
9825 	struct ipsec_test_flags flags;
9826 
9827 	memset(&flags, 0, sizeof(flags));
9828 
9829 	flags.iv_gen = true;
9830 
9831 	return test_ipsec_proto_all(&flags);
9832 }
9833 
9834 static int
9835 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9836 {
9837 	struct ipsec_test_flags flags;
9838 
9839 	memset(&flags, 0, sizeof(flags));
9840 
9841 	flags.sa_expiry_pkts_soft = true;
9842 
9843 	return test_ipsec_proto_all(&flags);
9844 }
9845 
9846 static int
9847 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9848 {
9849 	struct ipsec_test_flags flags;
9850 
9851 	memset(&flags, 0, sizeof(flags));
9852 
9853 	flags.sa_expiry_pkts_hard = true;
9854 
9855 	return test_ipsec_proto_all(&flags);
9856 }
9857 
9858 static int
9859 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9860 {
9861 	struct ipsec_test_flags flags;
9862 
9863 	memset(&flags, 0, sizeof(flags));
9864 
9865 	flags.icv_corrupt = true;
9866 
9867 	return test_ipsec_proto_all(&flags);
9868 }
9869 
9870 static int
9871 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9872 {
9873 	struct ipsec_test_flags flags;
9874 
9875 	memset(&flags, 0, sizeof(flags));
9876 
9877 	flags.udp_encap = true;
9878 
9879 	return test_ipsec_proto_all(&flags);
9880 }
9881 
9882 static int
9883 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9884 {
9885 	struct ipsec_test_flags flags;
9886 
9887 	memset(&flags, 0, sizeof(flags));
9888 
9889 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9890 
9891 	return test_ipsec_proto_all(&flags);
9892 }
9893 
9894 static int
9895 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9896 {
9897 	struct ipsec_test_flags flags;
9898 
9899 	memset(&flags, 0, sizeof(flags));
9900 
9901 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9902 
9903 	return test_ipsec_proto_all(&flags);
9904 }
9905 
9906 static int
9907 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9908 {
9909 	struct ipsec_test_flags flags;
9910 
9911 	memset(&flags, 0, sizeof(flags));
9912 
9913 	flags.udp_encap = true;
9914 	flags.udp_ports_verify = true;
9915 
9916 	return test_ipsec_proto_all(&flags);
9917 }
9918 
9919 static int
9920 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9921 {
9922 	struct ipsec_test_flags flags;
9923 
9924 	memset(&flags, 0, sizeof(flags));
9925 
9926 	flags.ip_csum = true;
9927 
9928 	return test_ipsec_proto_all(&flags);
9929 }
9930 
9931 static int
9932 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9933 {
9934 	struct ipsec_test_flags flags;
9935 
9936 	memset(&flags, 0, sizeof(flags));
9937 
9938 	flags.l4_csum = true;
9939 
9940 	return test_ipsec_proto_all(&flags);
9941 }
9942 
9943 static int
9944 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused)
9945 {
9946 	struct ipsec_test_flags flags;
9947 
9948 	memset(&flags, 0, sizeof(flags));
9949 
9950 	flags.ipv6 = false;
9951 	flags.tunnel_ipv6 = false;
9952 
9953 	return test_ipsec_proto_all(&flags);
9954 }
9955 
9956 static int
9957 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused)
9958 {
9959 	struct ipsec_test_flags flags;
9960 
9961 	memset(&flags, 0, sizeof(flags));
9962 
9963 	flags.ipv6 = true;
9964 	flags.tunnel_ipv6 = true;
9965 
9966 	return test_ipsec_proto_all(&flags);
9967 }
9968 
9969 static int
9970 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused)
9971 {
9972 	struct ipsec_test_flags flags;
9973 
9974 	memset(&flags, 0, sizeof(flags));
9975 
9976 	flags.ipv6 = false;
9977 	flags.tunnel_ipv6 = true;
9978 
9979 	return test_ipsec_proto_all(&flags);
9980 }
9981 
9982 static int
9983 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused)
9984 {
9985 	struct ipsec_test_flags flags;
9986 
9987 	memset(&flags, 0, sizeof(flags));
9988 
9989 	flags.ipv6 = true;
9990 	flags.tunnel_ipv6 = false;
9991 
9992 	return test_ipsec_proto_all(&flags);
9993 }
9994 
9995 static int
9996 test_ipsec_proto_transport_v4(const void *data __rte_unused)
9997 {
9998 	struct ipsec_test_flags flags;
9999 
10000 	memset(&flags, 0, sizeof(flags));
10001 
10002 	flags.ipv6 = false;
10003 	flags.transport = true;
10004 
10005 	return test_ipsec_proto_all(&flags);
10006 }
10007 
10008 static int
10009 test_ipsec_proto_transport_l4_csum(const void *data __rte_unused)
10010 {
10011 	struct ipsec_test_flags flags = {
10012 		.l4_csum = true,
10013 		.transport = true,
10014 	};
10015 
10016 	return test_ipsec_proto_all(&flags);
10017 }
10018 
10019 static int
10020 test_ipsec_proto_stats(const void *data __rte_unused)
10021 {
10022 	struct ipsec_test_flags flags;
10023 
10024 	memset(&flags, 0, sizeof(flags));
10025 
10026 	flags.stats_success = true;
10027 
10028 	return test_ipsec_proto_all(&flags);
10029 }
10030 
10031 static int
10032 test_ipsec_proto_pkt_fragment(const void *data __rte_unused)
10033 {
10034 	struct ipsec_test_flags flags;
10035 
10036 	memset(&flags, 0, sizeof(flags));
10037 
10038 	flags.fragment = true;
10039 
10040 	return test_ipsec_proto_all(&flags);
10041 
10042 }
10043 
10044 static int
10045 test_ipsec_proto_copy_df_inner_0(const void *data __rte_unused)
10046 {
10047 	struct ipsec_test_flags flags;
10048 
10049 	memset(&flags, 0, sizeof(flags));
10050 
10051 	flags.df = TEST_IPSEC_COPY_DF_INNER_0;
10052 
10053 	return test_ipsec_proto_all(&flags);
10054 }
10055 
10056 static int
10057 test_ipsec_proto_copy_df_inner_1(const void *data __rte_unused)
10058 {
10059 	struct ipsec_test_flags flags;
10060 
10061 	memset(&flags, 0, sizeof(flags));
10062 
10063 	flags.df = TEST_IPSEC_COPY_DF_INNER_1;
10064 
10065 	return test_ipsec_proto_all(&flags);
10066 }
10067 
10068 static int
10069 test_ipsec_proto_set_df_0_inner_1(const void *data __rte_unused)
10070 {
10071 	struct ipsec_test_flags flags;
10072 
10073 	memset(&flags, 0, sizeof(flags));
10074 
10075 	flags.df = TEST_IPSEC_SET_DF_0_INNER_1;
10076 
10077 	return test_ipsec_proto_all(&flags);
10078 }
10079 
10080 static int
10081 test_ipsec_proto_set_df_1_inner_0(const void *data __rte_unused)
10082 {
10083 	struct ipsec_test_flags flags;
10084 
10085 	memset(&flags, 0, sizeof(flags));
10086 
10087 	flags.df = TEST_IPSEC_SET_DF_1_INNER_0;
10088 
10089 	return test_ipsec_proto_all(&flags);
10090 }
10091 
10092 static int
10093 test_ipsec_proto_ipv4_copy_dscp_inner_0(const void *data __rte_unused)
10094 {
10095 	struct ipsec_test_flags flags;
10096 
10097 	memset(&flags, 0, sizeof(flags));
10098 
10099 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
10100 
10101 	return test_ipsec_proto_all(&flags);
10102 }
10103 
10104 static int
10105 test_ipsec_proto_ipv4_copy_dscp_inner_1(const void *data __rte_unused)
10106 {
10107 	struct ipsec_test_flags flags;
10108 
10109 	memset(&flags, 0, sizeof(flags));
10110 
10111 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
10112 
10113 	return test_ipsec_proto_all(&flags);
10114 }
10115 
10116 static int
10117 test_ipsec_proto_ipv4_set_dscp_0_inner_1(const void *data __rte_unused)
10118 {
10119 	struct ipsec_test_flags flags;
10120 
10121 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10122 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10123 		return TEST_SKIPPED;
10124 
10125 	memset(&flags, 0, sizeof(flags));
10126 
10127 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
10128 
10129 	return test_ipsec_proto_all(&flags);
10130 }
10131 
10132 static int
10133 test_ipsec_proto_ipv4_set_dscp_1_inner_0(const void *data __rte_unused)
10134 {
10135 	struct ipsec_test_flags flags;
10136 
10137 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10138 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10139 		return TEST_SKIPPED;
10140 
10141 	memset(&flags, 0, sizeof(flags));
10142 
10143 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
10144 
10145 	return test_ipsec_proto_all(&flags);
10146 }
10147 
10148 static int
10149 test_ipsec_proto_ipv6_copy_dscp_inner_0(const void *data __rte_unused)
10150 {
10151 	struct ipsec_test_flags flags;
10152 
10153 	memset(&flags, 0, sizeof(flags));
10154 
10155 	flags.ipv6 = true;
10156 	flags.tunnel_ipv6 = true;
10157 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_0;
10158 
10159 	return test_ipsec_proto_all(&flags);
10160 }
10161 
10162 static int
10163 test_ipsec_proto_ipv6_copy_dscp_inner_1(const void *data __rte_unused)
10164 {
10165 	struct ipsec_test_flags flags;
10166 
10167 	memset(&flags, 0, sizeof(flags));
10168 
10169 	flags.ipv6 = true;
10170 	flags.tunnel_ipv6 = true;
10171 	flags.dscp = TEST_IPSEC_COPY_DSCP_INNER_1;
10172 
10173 	return test_ipsec_proto_all(&flags);
10174 }
10175 
10176 static int
10177 test_ipsec_proto_ipv6_set_dscp_0_inner_1(const void *data __rte_unused)
10178 {
10179 	struct ipsec_test_flags flags;
10180 
10181 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10182 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10183 		return TEST_SKIPPED;
10184 
10185 	memset(&flags, 0, sizeof(flags));
10186 
10187 	flags.ipv6 = true;
10188 	flags.tunnel_ipv6 = true;
10189 	flags.dscp = TEST_IPSEC_SET_DSCP_0_INNER_1;
10190 
10191 	return test_ipsec_proto_all(&flags);
10192 }
10193 
10194 static int
10195 test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused)
10196 {
10197 	struct ipsec_test_flags flags;
10198 
10199 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
10200 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD)))
10201 		return TEST_SKIPPED;
10202 
10203 	memset(&flags, 0, sizeof(flags));
10204 
10205 	flags.ipv6 = true;
10206 	flags.tunnel_ipv6 = true;
10207 	flags.dscp = TEST_IPSEC_SET_DSCP_1_INNER_0;
10208 
10209 	return test_ipsec_proto_all(&flags);
10210 }
10211 
10212 static int
10213 test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[],
10214 		      bool replayed_pkt[], uint32_t nb_pkts, bool esn_en,
10215 		      uint64_t winsz)
10216 {
10217 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
10218 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
10219 	struct ipsec_test_flags flags;
10220 	uint32_t i = 0, ret = 0;
10221 
10222 	if (nb_pkts == 0)
10223 		return TEST_FAILED;
10224 
10225 	memset(&flags, 0, sizeof(flags));
10226 	flags.antireplay = true;
10227 
10228 	for (i = 0; i < nb_pkts; i++) {
10229 		memcpy(&td_outb[i], test_data, sizeof(td_outb[i]));
10230 		td_outb[i].ipsec_xform.options.iv_gen_disable = 1;
10231 		td_outb[i].ipsec_xform.replay_win_sz = winsz;
10232 		td_outb[i].ipsec_xform.options.esn = esn_en;
10233 	}
10234 
10235 	for (i = 0; i < nb_pkts; i++)
10236 		td_outb[i].ipsec_xform.esn.value = esn[i];
10237 
10238 	ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
10239 				       &flags);
10240 	if (ret != TEST_SUCCESS)
10241 		return ret;
10242 
10243 	test_ipsec_td_update(td_inb, td_outb, nb_pkts, &flags);
10244 
10245 	for (i = 0; i < nb_pkts; i++) {
10246 		td_inb[i].ipsec_xform.options.esn = esn_en;
10247 		/* Set antireplay flag for packets to be dropped */
10248 		td_inb[i].ar_packet = replayed_pkt[i];
10249 	}
10250 
10251 	ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
10252 				       &flags);
10253 
10254 	return ret;
10255 }
10256 
10257 static int
10258 test_ipsec_proto_pkt_antireplay(const void *test_data, uint64_t winsz)
10259 {
10260 
10261 	uint32_t nb_pkts = 5;
10262 	bool replayed_pkt[5];
10263 	uint64_t esn[5];
10264 
10265 	/* 1. Advance the TOP of the window to WS * 2 */
10266 	esn[0] = winsz * 2;
10267 	/* 2. Test sequence number within the new window(WS + 1) */
10268 	esn[1] = winsz + 1;
10269 	/* 3. Test sequence number less than the window BOTTOM */
10270 	esn[2] = winsz;
10271 	/* 4. Test sequence number in the middle of the window */
10272 	esn[3] = winsz + (winsz / 2);
10273 	/* 5. Test replay of the packet in the middle of the window */
10274 	esn[4] = winsz + (winsz / 2);
10275 
10276 	replayed_pkt[0] = false;
10277 	replayed_pkt[1] = false;
10278 	replayed_pkt[2] = true;
10279 	replayed_pkt[3] = false;
10280 	replayed_pkt[4] = true;
10281 
10282 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10283 				     false, winsz);
10284 }
10285 
10286 static int
10287 test_ipsec_proto_pkt_antireplay1024(const void *test_data)
10288 {
10289 	return test_ipsec_proto_pkt_antireplay(test_data, 1024);
10290 }
10291 
10292 static int
10293 test_ipsec_proto_pkt_antireplay2048(const void *test_data)
10294 {
10295 	return test_ipsec_proto_pkt_antireplay(test_data, 2048);
10296 }
10297 
10298 static int
10299 test_ipsec_proto_pkt_antireplay4096(const void *test_data)
10300 {
10301 	return test_ipsec_proto_pkt_antireplay(test_data, 4096);
10302 }
10303 
10304 static int
10305 test_ipsec_proto_pkt_esn_antireplay(const void *test_data, uint64_t winsz)
10306 {
10307 
10308 	uint32_t nb_pkts = 7;
10309 	bool replayed_pkt[7];
10310 	uint64_t esn[7];
10311 
10312 	/* Set the initial sequence number */
10313 	esn[0] = (uint64_t)(0xFFFFFFFF - winsz);
10314 	/* 1. Advance the TOP of the window to (1<<32 + WS/2) */
10315 	esn[1] = (uint64_t)((1ULL << 32) + (winsz / 2));
10316 	/* 2. Test sequence number within new window (1<<32 + WS/2 + 1) */
10317 	esn[2] = (uint64_t)((1ULL << 32) - (winsz / 2) + 1);
10318 	/* 3. Test with sequence number within window (1<<32 - 1) */
10319 	esn[3] = (uint64_t)((1ULL << 32) - 1);
10320 	/* 4. Test with sequence number within window (1<<32 - 1) */
10321 	esn[4] = (uint64_t)(1ULL << 32);
10322 	/* 5. Test with duplicate sequence number within
10323 	 * new window (1<<32 - 1)
10324 	 */
10325 	esn[5] = (uint64_t)((1ULL << 32) - 1);
10326 	/* 6. Test with duplicate sequence number within new window (1<<32) */
10327 	esn[6] = (uint64_t)(1ULL << 32);
10328 
10329 	replayed_pkt[0] = false;
10330 	replayed_pkt[1] = false;
10331 	replayed_pkt[2] = false;
10332 	replayed_pkt[3] = false;
10333 	replayed_pkt[4] = false;
10334 	replayed_pkt[5] = true;
10335 	replayed_pkt[6] = true;
10336 
10337 	return test_ipsec_pkt_replay(test_data, esn, replayed_pkt, nb_pkts,
10338 				     true, winsz);
10339 }
10340 
10341 static int
10342 test_ipsec_proto_pkt_esn_antireplay1024(const void *test_data)
10343 {
10344 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 1024);
10345 }
10346 
10347 static int
10348 test_ipsec_proto_pkt_esn_antireplay2048(const void *test_data)
10349 {
10350 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 2048);
10351 }
10352 
10353 static int
10354 test_ipsec_proto_pkt_esn_antireplay4096(const void *test_data)
10355 {
10356 	return test_ipsec_proto_pkt_esn_antireplay(test_data, 4096);
10357 }
10358 
10359 static int
10360 test_PDCP_PROTO_all(void)
10361 {
10362 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10363 	struct crypto_unittest_params *ut_params = &unittest_params;
10364 	struct rte_cryptodev_info dev_info;
10365 	int status;
10366 
10367 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10368 	uint64_t feat_flags = dev_info.feature_flags;
10369 
10370 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
10371 		return TEST_SKIPPED;
10372 
10373 	/* Set action type */
10374 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10375 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10376 		gbl_action_type;
10377 
10378 	if (security_proto_supported(ut_params->type,
10379 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
10380 		return TEST_SKIPPED;
10381 
10382 	status = test_PDCP_PROTO_cplane_encap_all();
10383 	status += test_PDCP_PROTO_cplane_decap_all();
10384 	status += test_PDCP_PROTO_uplane_encap_all();
10385 	status += test_PDCP_PROTO_uplane_decap_all();
10386 	status += test_PDCP_PROTO_SGL_in_place_32B();
10387 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
10388 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
10389 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
10390 	status += test_PDCP_SDAP_PROTO_encap_all();
10391 	status += test_PDCP_SDAP_PROTO_decap_all();
10392 	status += test_PDCP_PROTO_short_mac();
10393 
10394 	if (status)
10395 		return TEST_FAILED;
10396 	else
10397 		return TEST_SUCCESS;
10398 }
10399 
10400 static int
10401 test_ipsec_proto_ipv4_ttl_decrement(const void *data __rte_unused)
10402 {
10403 	struct ipsec_test_flags flags = {
10404 		.dec_ttl_or_hop_limit = true
10405 	};
10406 
10407 	return test_ipsec_proto_all(&flags);
10408 }
10409 
10410 static int
10411 test_ipsec_proto_ipv6_hop_limit_decrement(const void *data __rte_unused)
10412 {
10413 	struct ipsec_test_flags flags = {
10414 		.ipv6 = true,
10415 		.dec_ttl_or_hop_limit = true
10416 	};
10417 
10418 	return test_ipsec_proto_all(&flags);
10419 }
10420 
10421 static int
10422 test_docsis_proto_uplink(const void *data)
10423 {
10424 	const struct docsis_test_data *d_td = data;
10425 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10426 	struct crypto_unittest_params *ut_params = &unittest_params;
10427 	uint8_t *plaintext = NULL;
10428 	uint8_t *ciphertext = NULL;
10429 	uint8_t *iv_ptr;
10430 	int32_t cipher_len, crc_len;
10431 	uint32_t crc_data_len;
10432 	int ret = TEST_SUCCESS;
10433 
10434 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
10435 					rte_cryptodev_get_sec_ctx(
10436 						ts_params->valid_devs[0]);
10437 
10438 	/* Verify the capabilities */
10439 	struct rte_security_capability_idx sec_cap_idx;
10440 	const struct rte_security_capability *sec_cap;
10441 	const struct rte_cryptodev_capabilities *crypto_cap;
10442 	const struct rte_cryptodev_symmetric_capability *sym_cap;
10443 	int j = 0;
10444 
10445 	/* Set action type */
10446 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10447 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10448 		gbl_action_type;
10449 
10450 	if (security_proto_supported(ut_params->type,
10451 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10452 		return TEST_SKIPPED;
10453 
10454 	sec_cap_idx.action = ut_params->type;
10455 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
10456 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
10457 
10458 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10459 	if (sec_cap == NULL)
10460 		return TEST_SKIPPED;
10461 
10462 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
10463 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
10464 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
10465 				crypto_cap->sym.xform_type ==
10466 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
10467 				crypto_cap->sym.cipher.algo ==
10468 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
10469 			sym_cap = &crypto_cap->sym;
10470 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
10471 						d_td->key.len,
10472 						d_td->iv.len) == 0)
10473 				break;
10474 		}
10475 	}
10476 
10477 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
10478 		return TEST_SKIPPED;
10479 
10480 	/* Setup source mbuf payload */
10481 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10482 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10483 			rte_pktmbuf_tailroom(ut_params->ibuf));
10484 
10485 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10486 			d_td->ciphertext.len);
10487 
10488 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
10489 
10490 	/* Setup cipher session parameters */
10491 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10492 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
10493 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
10494 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
10495 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
10496 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
10497 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10498 	ut_params->cipher_xform.next = NULL;
10499 
10500 	/* Setup DOCSIS session parameters */
10501 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
10502 
10503 	struct rte_security_session_conf sess_conf = {
10504 		.action_type = ut_params->type,
10505 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
10506 		.docsis = ut_params->docsis_xform,
10507 		.crypto_xform = &ut_params->cipher_xform,
10508 	};
10509 
10510 	/* Create security session */
10511 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10512 					ts_params->session_mpool,
10513 					ts_params->session_priv_mpool);
10514 
10515 	if (!ut_params->sec_session) {
10516 		printf("Test function %s line %u: failed to allocate session\n",
10517 			__func__, __LINE__);
10518 		ret = TEST_FAILED;
10519 		goto on_err;
10520 	}
10521 
10522 	/* Generate crypto op data structure */
10523 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10524 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10525 	if (!ut_params->op) {
10526 		printf("Test function %s line %u: failed to allocate symmetric "
10527 			"crypto operation\n", __func__, __LINE__);
10528 		ret = TEST_FAILED;
10529 		goto on_err;
10530 	}
10531 
10532 	/* Setup CRC operation parameters */
10533 	crc_len = d_td->ciphertext.no_crc == false ?
10534 			(d_td->ciphertext.len -
10535 				d_td->ciphertext.crc_offset -
10536 				RTE_ETHER_CRC_LEN) :
10537 			0;
10538 	crc_len = crc_len > 0 ? crc_len : 0;
10539 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
10540 	ut_params->op->sym->auth.data.length = crc_len;
10541 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
10542 
10543 	/* Setup cipher operation parameters */
10544 	cipher_len = d_td->ciphertext.no_cipher == false ?
10545 			(d_td->ciphertext.len -
10546 				d_td->ciphertext.cipher_offset) :
10547 			0;
10548 	cipher_len = cipher_len > 0 ? cipher_len : 0;
10549 	ut_params->op->sym->cipher.data.length = cipher_len;
10550 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
10551 
10552 	/* Setup cipher IV */
10553 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
10554 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
10555 
10556 	/* Attach session to operation */
10557 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10558 
10559 	/* Set crypto operation mbufs */
10560 	ut_params->op->sym->m_src = ut_params->ibuf;
10561 	ut_params->op->sym->m_dst = NULL;
10562 
10563 	/* Process crypto operation */
10564 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10565 			NULL) {
10566 		printf("Test function %s line %u: failed to process security "
10567 			"crypto op\n", __func__, __LINE__);
10568 		ret = TEST_FAILED;
10569 		goto on_err;
10570 	}
10571 
10572 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10573 		printf("Test function %s line %u: failed to process crypto op\n",
10574 			__func__, __LINE__);
10575 		ret = TEST_FAILED;
10576 		goto on_err;
10577 	}
10578 
10579 	/* Validate plaintext */
10580 	plaintext = ciphertext;
10581 
10582 	if (memcmp(plaintext, d_td->plaintext.data,
10583 			d_td->plaintext.len - crc_data_len)) {
10584 		printf("Test function %s line %u: plaintext not as expected\n",
10585 			__func__, __LINE__);
10586 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
10587 				d_td->plaintext.len);
10588 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
10589 		ret = TEST_FAILED;
10590 		goto on_err;
10591 	}
10592 
10593 on_err:
10594 	rte_crypto_op_free(ut_params->op);
10595 	ut_params->op = NULL;
10596 
10597 	if (ut_params->sec_session)
10598 		rte_security_session_destroy(ctx, ut_params->sec_session);
10599 	ut_params->sec_session = NULL;
10600 
10601 	rte_pktmbuf_free(ut_params->ibuf);
10602 	ut_params->ibuf = NULL;
10603 
10604 	return ret;
10605 }
10606 
10607 static int
10608 test_docsis_proto_downlink(const void *data)
10609 {
10610 	const struct docsis_test_data *d_td = data;
10611 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10612 	struct crypto_unittest_params *ut_params = &unittest_params;
10613 	uint8_t *plaintext = NULL;
10614 	uint8_t *ciphertext = NULL;
10615 	uint8_t *iv_ptr;
10616 	int32_t cipher_len, crc_len;
10617 	int ret = TEST_SUCCESS;
10618 
10619 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
10620 					rte_cryptodev_get_sec_ctx(
10621 						ts_params->valid_devs[0]);
10622 
10623 	/* Verify the capabilities */
10624 	struct rte_security_capability_idx sec_cap_idx;
10625 	const struct rte_security_capability *sec_cap;
10626 	const struct rte_cryptodev_capabilities *crypto_cap;
10627 	const struct rte_cryptodev_symmetric_capability *sym_cap;
10628 	int j = 0;
10629 
10630 	/* Set action type */
10631 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
10632 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
10633 		gbl_action_type;
10634 
10635 	if (security_proto_supported(ut_params->type,
10636 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
10637 		return TEST_SKIPPED;
10638 
10639 	sec_cap_idx.action = ut_params->type;
10640 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
10641 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
10642 
10643 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
10644 	if (sec_cap == NULL)
10645 		return TEST_SKIPPED;
10646 
10647 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
10648 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
10649 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
10650 				crypto_cap->sym.xform_type ==
10651 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
10652 				crypto_cap->sym.cipher.algo ==
10653 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
10654 			sym_cap = &crypto_cap->sym;
10655 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
10656 						d_td->key.len,
10657 						d_td->iv.len) == 0)
10658 				break;
10659 		}
10660 	}
10661 
10662 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
10663 		return TEST_SKIPPED;
10664 
10665 	/* Setup source mbuf payload */
10666 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10667 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10668 			rte_pktmbuf_tailroom(ut_params->ibuf));
10669 
10670 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
10671 			d_td->plaintext.len);
10672 
10673 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
10674 
10675 	/* Setup cipher session parameters */
10676 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
10677 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
10678 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
10679 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
10680 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
10681 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
10682 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
10683 	ut_params->cipher_xform.next = NULL;
10684 
10685 	/* Setup DOCSIS session parameters */
10686 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
10687 
10688 	struct rte_security_session_conf sess_conf = {
10689 		.action_type = ut_params->type,
10690 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
10691 		.docsis = ut_params->docsis_xform,
10692 		.crypto_xform = &ut_params->cipher_xform,
10693 	};
10694 
10695 	/* Create security session */
10696 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
10697 					ts_params->session_mpool,
10698 					ts_params->session_priv_mpool);
10699 
10700 	if (!ut_params->sec_session) {
10701 		printf("Test function %s line %u: failed to allocate session\n",
10702 			__func__, __LINE__);
10703 		ret = TEST_FAILED;
10704 		goto on_err;
10705 	}
10706 
10707 	/* Generate crypto op data structure */
10708 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
10709 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
10710 	if (!ut_params->op) {
10711 		printf("Test function %s line %u: failed to allocate symmetric "
10712 			"crypto operation\n", __func__, __LINE__);
10713 		ret = TEST_FAILED;
10714 		goto on_err;
10715 	}
10716 
10717 	/* Setup CRC operation parameters */
10718 	crc_len = d_td->plaintext.no_crc == false ?
10719 			(d_td->plaintext.len -
10720 				d_td->plaintext.crc_offset -
10721 				RTE_ETHER_CRC_LEN) :
10722 			0;
10723 	crc_len = crc_len > 0 ? crc_len : 0;
10724 	ut_params->op->sym->auth.data.length = crc_len;
10725 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
10726 
10727 	/* Setup cipher operation parameters */
10728 	cipher_len = d_td->plaintext.no_cipher == false ?
10729 			(d_td->plaintext.len -
10730 				d_td->plaintext.cipher_offset) :
10731 			0;
10732 	cipher_len = cipher_len > 0 ? cipher_len : 0;
10733 	ut_params->op->sym->cipher.data.length = cipher_len;
10734 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
10735 
10736 	/* Setup cipher IV */
10737 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
10738 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
10739 
10740 	/* Attach session to operation */
10741 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10742 
10743 	/* Set crypto operation mbufs */
10744 	ut_params->op->sym->m_src = ut_params->ibuf;
10745 	ut_params->op->sym->m_dst = NULL;
10746 
10747 	/* Process crypto operation */
10748 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10749 			NULL) {
10750 		printf("Test function %s line %u: failed to process crypto op\n",
10751 			__func__, __LINE__);
10752 		ret = TEST_FAILED;
10753 		goto on_err;
10754 	}
10755 
10756 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10757 		printf("Test function %s line %u: crypto op processing failed\n",
10758 			__func__, __LINE__);
10759 		ret = TEST_FAILED;
10760 		goto on_err;
10761 	}
10762 
10763 	/* Validate ciphertext */
10764 	ciphertext = plaintext;
10765 
10766 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
10767 		printf("Test function %s line %u: plaintext not as expected\n",
10768 			__func__, __LINE__);
10769 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
10770 				d_td->ciphertext.len);
10771 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
10772 		ret = TEST_FAILED;
10773 		goto on_err;
10774 	}
10775 
10776 on_err:
10777 	rte_crypto_op_free(ut_params->op);
10778 	ut_params->op = NULL;
10779 
10780 	if (ut_params->sec_session)
10781 		rte_security_session_destroy(ctx, ut_params->sec_session);
10782 	ut_params->sec_session = NULL;
10783 
10784 	rte_pktmbuf_free(ut_params->ibuf);
10785 	ut_params->ibuf = NULL;
10786 
10787 	return ret;
10788 }
10789 #endif
10790 
10791 static int
10792 test_AES_GCM_authenticated_encryption_test_case_1(void)
10793 {
10794 	return test_authenticated_encryption(&gcm_test_case_1);
10795 }
10796 
10797 static int
10798 test_AES_GCM_authenticated_encryption_test_case_2(void)
10799 {
10800 	return test_authenticated_encryption(&gcm_test_case_2);
10801 }
10802 
10803 static int
10804 test_AES_GCM_authenticated_encryption_test_case_3(void)
10805 {
10806 	return test_authenticated_encryption(&gcm_test_case_3);
10807 }
10808 
10809 static int
10810 test_AES_GCM_authenticated_encryption_test_case_4(void)
10811 {
10812 	return test_authenticated_encryption(&gcm_test_case_4);
10813 }
10814 
10815 static int
10816 test_AES_GCM_authenticated_encryption_test_case_5(void)
10817 {
10818 	return test_authenticated_encryption(&gcm_test_case_5);
10819 }
10820 
10821 static int
10822 test_AES_GCM_authenticated_encryption_test_case_6(void)
10823 {
10824 	return test_authenticated_encryption(&gcm_test_case_6);
10825 }
10826 
10827 static int
10828 test_AES_GCM_authenticated_encryption_test_case_7(void)
10829 {
10830 	return test_authenticated_encryption(&gcm_test_case_7);
10831 }
10832 
10833 static int
10834 test_AES_GCM_authenticated_encryption_test_case_8(void)
10835 {
10836 	return test_authenticated_encryption(&gcm_test_case_8);
10837 }
10838 
10839 static int
10840 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
10841 {
10842 	return test_authenticated_encryption(&gcm_J0_test_case_1);
10843 }
10844 
10845 static int
10846 test_AES_GCM_auth_encryption_test_case_192_1(void)
10847 {
10848 	return test_authenticated_encryption(&gcm_test_case_192_1);
10849 }
10850 
10851 static int
10852 test_AES_GCM_auth_encryption_test_case_192_2(void)
10853 {
10854 	return test_authenticated_encryption(&gcm_test_case_192_2);
10855 }
10856 
10857 static int
10858 test_AES_GCM_auth_encryption_test_case_192_3(void)
10859 {
10860 	return test_authenticated_encryption(&gcm_test_case_192_3);
10861 }
10862 
10863 static int
10864 test_AES_GCM_auth_encryption_test_case_192_4(void)
10865 {
10866 	return test_authenticated_encryption(&gcm_test_case_192_4);
10867 }
10868 
10869 static int
10870 test_AES_GCM_auth_encryption_test_case_192_5(void)
10871 {
10872 	return test_authenticated_encryption(&gcm_test_case_192_5);
10873 }
10874 
10875 static int
10876 test_AES_GCM_auth_encryption_test_case_192_6(void)
10877 {
10878 	return test_authenticated_encryption(&gcm_test_case_192_6);
10879 }
10880 
10881 static int
10882 test_AES_GCM_auth_encryption_test_case_192_7(void)
10883 {
10884 	return test_authenticated_encryption(&gcm_test_case_192_7);
10885 }
10886 
10887 static int
10888 test_AES_GCM_auth_encryption_test_case_256_1(void)
10889 {
10890 	return test_authenticated_encryption(&gcm_test_case_256_1);
10891 }
10892 
10893 static int
10894 test_AES_GCM_auth_encryption_test_case_256_2(void)
10895 {
10896 	return test_authenticated_encryption(&gcm_test_case_256_2);
10897 }
10898 
10899 static int
10900 test_AES_GCM_auth_encryption_test_case_256_3(void)
10901 {
10902 	return test_authenticated_encryption(&gcm_test_case_256_3);
10903 }
10904 
10905 static int
10906 test_AES_GCM_auth_encryption_test_case_256_4(void)
10907 {
10908 	return test_authenticated_encryption(&gcm_test_case_256_4);
10909 }
10910 
10911 static int
10912 test_AES_GCM_auth_encryption_test_case_256_5(void)
10913 {
10914 	return test_authenticated_encryption(&gcm_test_case_256_5);
10915 }
10916 
10917 static int
10918 test_AES_GCM_auth_encryption_test_case_256_6(void)
10919 {
10920 	return test_authenticated_encryption(&gcm_test_case_256_6);
10921 }
10922 
10923 static int
10924 test_AES_GCM_auth_encryption_test_case_256_7(void)
10925 {
10926 	return test_authenticated_encryption(&gcm_test_case_256_7);
10927 }
10928 
10929 static int
10930 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10931 {
10932 	return test_authenticated_encryption(&gcm_test_case_aad_1);
10933 }
10934 
10935 static int
10936 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10937 {
10938 	return test_authenticated_encryption(&gcm_test_case_aad_2);
10939 }
10940 
10941 static int
10942 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10943 {
10944 	struct aead_test_data tdata;
10945 	int res;
10946 
10947 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10948 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10949 	tdata.iv.data[0] += 1;
10950 	res = test_authenticated_encryption(&tdata);
10951 	if (res == TEST_SKIPPED)
10952 		return res;
10953 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10954 	return TEST_SUCCESS;
10955 }
10956 
10957 static int
10958 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10959 {
10960 	struct aead_test_data tdata;
10961 	int res;
10962 
10963 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10964 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10965 	tdata.plaintext.data[0] += 1;
10966 	res = test_authenticated_encryption(&tdata);
10967 	if (res == TEST_SKIPPED)
10968 		return res;
10969 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10970 	return TEST_SUCCESS;
10971 }
10972 
10973 static int
10974 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10975 {
10976 	struct aead_test_data tdata;
10977 	int res;
10978 
10979 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10980 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10981 	tdata.ciphertext.data[0] += 1;
10982 	res = test_authenticated_encryption(&tdata);
10983 	if (res == TEST_SKIPPED)
10984 		return res;
10985 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10986 	return TEST_SUCCESS;
10987 }
10988 
10989 static int
10990 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10991 {
10992 	struct aead_test_data tdata;
10993 	int res;
10994 
10995 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10996 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10997 	tdata.aad.len += 1;
10998 	res = test_authenticated_encryption(&tdata);
10999 	if (res == TEST_SKIPPED)
11000 		return res;
11001 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11002 	return TEST_SUCCESS;
11003 }
11004 
11005 static int
11006 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
11007 {
11008 	struct aead_test_data tdata;
11009 	uint8_t aad[gcm_test_case_7.aad.len];
11010 	int res;
11011 
11012 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11013 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11014 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
11015 	aad[0] += 1;
11016 	tdata.aad.data = aad;
11017 	res = test_authenticated_encryption(&tdata);
11018 	if (res == TEST_SKIPPED)
11019 		return res;
11020 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11021 	return TEST_SUCCESS;
11022 }
11023 
11024 static int
11025 test_AES_GCM_auth_encryption_fail_tag_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.auth_tag.data[0] += 1;
11033 	res = test_authenticated_encryption(&tdata);
11034 	if (res == TEST_SKIPPED)
11035 		return res;
11036 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
11037 	return TEST_SUCCESS;
11038 }
11039 
11040 static int
11041 test_authenticated_decryption(const struct aead_test_data *tdata)
11042 {
11043 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11044 	struct crypto_unittest_params *ut_params = &unittest_params;
11045 
11046 	int retval;
11047 	uint8_t *plaintext;
11048 	uint32_t i;
11049 	struct rte_cryptodev_info dev_info;
11050 
11051 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11052 	uint64_t feat_flags = dev_info.feature_flags;
11053 
11054 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11055 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11056 		printf("Device doesn't support RAW data-path APIs.\n");
11057 		return TEST_SKIPPED;
11058 	}
11059 
11060 	/* Verify the capabilities */
11061 	struct rte_cryptodev_sym_capability_idx cap_idx;
11062 	const struct rte_cryptodev_symmetric_capability *capability;
11063 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11064 	cap_idx.algo.aead = tdata->algo;
11065 	capability = rte_cryptodev_sym_capability_get(
11066 			ts_params->valid_devs[0], &cap_idx);
11067 	if (capability == NULL)
11068 		return TEST_SKIPPED;
11069 	if (rte_cryptodev_sym_capability_check_aead(
11070 			capability, tdata->key.len, tdata->auth_tag.len,
11071 			tdata->aad.len, tdata->iv.len))
11072 		return TEST_SKIPPED;
11073 
11074 	/* Create AEAD session */
11075 	retval = create_aead_session(ts_params->valid_devs[0],
11076 			tdata->algo,
11077 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11078 			tdata->key.data, tdata->key.len,
11079 			tdata->aad.len, tdata->auth_tag.len,
11080 			tdata->iv.len);
11081 	if (retval < 0)
11082 		return retval;
11083 
11084 	/* alloc mbuf and set payload */
11085 	if (tdata->aad.len > MBUF_SIZE) {
11086 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
11087 		/* Populate full size of add data */
11088 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
11089 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
11090 	} else
11091 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11092 
11093 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11094 			rte_pktmbuf_tailroom(ut_params->ibuf));
11095 
11096 	/* Create AEAD operation */
11097 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11098 	if (retval < 0)
11099 		return retval;
11100 
11101 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11102 
11103 	ut_params->op->sym->m_src = ut_params->ibuf;
11104 
11105 	/* Process crypto operation */
11106 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11107 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
11108 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11109 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11110 				ut_params->op, 0, 0, 0, 0);
11111 	else
11112 		TEST_ASSERT_NOT_NULL(
11113 			process_crypto_request(ts_params->valid_devs[0],
11114 			ut_params->op), "failed to process sym crypto op");
11115 
11116 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11117 			"crypto op processing failed");
11118 
11119 	if (ut_params->op->sym->m_dst)
11120 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
11121 				uint8_t *);
11122 	else
11123 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
11124 				uint8_t *,
11125 				ut_params->op->sym->cipher.data.offset);
11126 
11127 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11128 
11129 	/* Validate obuf */
11130 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11131 			plaintext,
11132 			tdata->plaintext.data,
11133 			tdata->plaintext.len,
11134 			"Plaintext data not as expected");
11135 
11136 	TEST_ASSERT_EQUAL(ut_params->op->status,
11137 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11138 			"Authentication failed");
11139 
11140 	return 0;
11141 }
11142 
11143 static int
11144 test_AES_GCM_authenticated_decryption_test_case_1(void)
11145 {
11146 	return test_authenticated_decryption(&gcm_test_case_1);
11147 }
11148 
11149 static int
11150 test_AES_GCM_authenticated_decryption_test_case_2(void)
11151 {
11152 	return test_authenticated_decryption(&gcm_test_case_2);
11153 }
11154 
11155 static int
11156 test_AES_GCM_authenticated_decryption_test_case_3(void)
11157 {
11158 	return test_authenticated_decryption(&gcm_test_case_3);
11159 }
11160 
11161 static int
11162 test_AES_GCM_authenticated_decryption_test_case_4(void)
11163 {
11164 	return test_authenticated_decryption(&gcm_test_case_4);
11165 }
11166 
11167 static int
11168 test_AES_GCM_authenticated_decryption_test_case_5(void)
11169 {
11170 	return test_authenticated_decryption(&gcm_test_case_5);
11171 }
11172 
11173 static int
11174 test_AES_GCM_authenticated_decryption_test_case_6(void)
11175 {
11176 	return test_authenticated_decryption(&gcm_test_case_6);
11177 }
11178 
11179 static int
11180 test_AES_GCM_authenticated_decryption_test_case_7(void)
11181 {
11182 	return test_authenticated_decryption(&gcm_test_case_7);
11183 }
11184 
11185 static int
11186 test_AES_GCM_authenticated_decryption_test_case_8(void)
11187 {
11188 	return test_authenticated_decryption(&gcm_test_case_8);
11189 }
11190 
11191 static int
11192 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
11193 {
11194 	return test_authenticated_decryption(&gcm_J0_test_case_1);
11195 }
11196 
11197 static int
11198 test_AES_GCM_auth_decryption_test_case_192_1(void)
11199 {
11200 	return test_authenticated_decryption(&gcm_test_case_192_1);
11201 }
11202 
11203 static int
11204 test_AES_GCM_auth_decryption_test_case_192_2(void)
11205 {
11206 	return test_authenticated_decryption(&gcm_test_case_192_2);
11207 }
11208 
11209 static int
11210 test_AES_GCM_auth_decryption_test_case_192_3(void)
11211 {
11212 	return test_authenticated_decryption(&gcm_test_case_192_3);
11213 }
11214 
11215 static int
11216 test_AES_GCM_auth_decryption_test_case_192_4(void)
11217 {
11218 	return test_authenticated_decryption(&gcm_test_case_192_4);
11219 }
11220 
11221 static int
11222 test_AES_GCM_auth_decryption_test_case_192_5(void)
11223 {
11224 	return test_authenticated_decryption(&gcm_test_case_192_5);
11225 }
11226 
11227 static int
11228 test_AES_GCM_auth_decryption_test_case_192_6(void)
11229 {
11230 	return test_authenticated_decryption(&gcm_test_case_192_6);
11231 }
11232 
11233 static int
11234 test_AES_GCM_auth_decryption_test_case_192_7(void)
11235 {
11236 	return test_authenticated_decryption(&gcm_test_case_192_7);
11237 }
11238 
11239 static int
11240 test_AES_GCM_auth_decryption_test_case_256_1(void)
11241 {
11242 	return test_authenticated_decryption(&gcm_test_case_256_1);
11243 }
11244 
11245 static int
11246 test_AES_GCM_auth_decryption_test_case_256_2(void)
11247 {
11248 	return test_authenticated_decryption(&gcm_test_case_256_2);
11249 }
11250 
11251 static int
11252 test_AES_GCM_auth_decryption_test_case_256_3(void)
11253 {
11254 	return test_authenticated_decryption(&gcm_test_case_256_3);
11255 }
11256 
11257 static int
11258 test_AES_GCM_auth_decryption_test_case_256_4(void)
11259 {
11260 	return test_authenticated_decryption(&gcm_test_case_256_4);
11261 }
11262 
11263 static int
11264 test_AES_GCM_auth_decryption_test_case_256_5(void)
11265 {
11266 	return test_authenticated_decryption(&gcm_test_case_256_5);
11267 }
11268 
11269 static int
11270 test_AES_GCM_auth_decryption_test_case_256_6(void)
11271 {
11272 	return test_authenticated_decryption(&gcm_test_case_256_6);
11273 }
11274 
11275 static int
11276 test_AES_GCM_auth_decryption_test_case_256_7(void)
11277 {
11278 	return test_authenticated_decryption(&gcm_test_case_256_7);
11279 }
11280 
11281 static int
11282 test_AES_GCM_auth_decryption_test_case_aad_1(void)
11283 {
11284 	return test_authenticated_decryption(&gcm_test_case_aad_1);
11285 }
11286 
11287 static int
11288 test_AES_GCM_auth_decryption_test_case_aad_2(void)
11289 {
11290 	return test_authenticated_decryption(&gcm_test_case_aad_2);
11291 }
11292 
11293 static int
11294 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
11295 {
11296 	struct aead_test_data tdata;
11297 	int res;
11298 
11299 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11300 	tdata.iv.data[0] += 1;
11301 	res = test_authenticated_decryption(&tdata);
11302 	if (res == TEST_SKIPPED)
11303 		return res;
11304 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11305 	return TEST_SUCCESS;
11306 }
11307 
11308 static int
11309 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
11310 {
11311 	struct aead_test_data tdata;
11312 	int res;
11313 
11314 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
11315 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11316 	tdata.plaintext.data[0] += 1;
11317 	res = test_authenticated_decryption(&tdata);
11318 	if (res == TEST_SKIPPED)
11319 		return res;
11320 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11321 	return TEST_SUCCESS;
11322 }
11323 
11324 static int
11325 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
11326 {
11327 	struct aead_test_data tdata;
11328 	int res;
11329 
11330 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11331 	tdata.ciphertext.data[0] += 1;
11332 	res = test_authenticated_decryption(&tdata);
11333 	if (res == TEST_SKIPPED)
11334 		return res;
11335 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11336 	return TEST_SUCCESS;
11337 }
11338 
11339 static int
11340 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
11341 {
11342 	struct aead_test_data tdata;
11343 	int res;
11344 
11345 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11346 	tdata.aad.len += 1;
11347 	res = test_authenticated_decryption(&tdata);
11348 	if (res == TEST_SKIPPED)
11349 		return res;
11350 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11351 	return TEST_SUCCESS;
11352 }
11353 
11354 static int
11355 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
11356 {
11357 	struct aead_test_data tdata;
11358 	uint8_t aad[gcm_test_case_7.aad.len];
11359 	int res;
11360 
11361 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11362 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
11363 	aad[0] += 1;
11364 	tdata.aad.data = aad;
11365 	res = test_authenticated_decryption(&tdata);
11366 	if (res == TEST_SKIPPED)
11367 		return res;
11368 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
11369 	return TEST_SUCCESS;
11370 }
11371 
11372 static int
11373 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
11374 {
11375 	struct aead_test_data tdata;
11376 	int res;
11377 
11378 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
11379 	tdata.auth_tag.data[0] += 1;
11380 	res = test_authenticated_decryption(&tdata);
11381 	if (res == TEST_SKIPPED)
11382 		return res;
11383 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
11384 	return TEST_SUCCESS;
11385 }
11386 
11387 static int
11388 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
11389 {
11390 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11391 	struct crypto_unittest_params *ut_params = &unittest_params;
11392 
11393 	int retval;
11394 	uint8_t *ciphertext, *auth_tag;
11395 	uint16_t plaintext_pad_len;
11396 	struct rte_cryptodev_info dev_info;
11397 
11398 	/* Verify the capabilities */
11399 	struct rte_cryptodev_sym_capability_idx cap_idx;
11400 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11401 	cap_idx.algo.aead = tdata->algo;
11402 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11403 			&cap_idx) == NULL)
11404 		return TEST_SKIPPED;
11405 
11406 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11407 	uint64_t feat_flags = dev_info.feature_flags;
11408 
11409 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11410 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
11411 		return TEST_SKIPPED;
11412 
11413 	/* not supported with CPU crypto */
11414 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11415 		return TEST_SKIPPED;
11416 
11417 	/* Create AEAD session */
11418 	retval = create_aead_session(ts_params->valid_devs[0],
11419 			tdata->algo,
11420 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
11421 			tdata->key.data, tdata->key.len,
11422 			tdata->aad.len, tdata->auth_tag.len,
11423 			tdata->iv.len);
11424 	if (retval < 0)
11425 		return retval;
11426 
11427 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11428 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11429 
11430 	/* clear mbuf payload */
11431 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11432 			rte_pktmbuf_tailroom(ut_params->ibuf));
11433 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
11434 			rte_pktmbuf_tailroom(ut_params->obuf));
11435 
11436 	/* Create AEAD operation */
11437 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
11438 	if (retval < 0)
11439 		return retval;
11440 
11441 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11442 
11443 	ut_params->op->sym->m_src = ut_params->ibuf;
11444 	ut_params->op->sym->m_dst = ut_params->obuf;
11445 
11446 	/* Process crypto operation */
11447 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11448 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11449 			ut_params->op, 0, 0, 0, 0);
11450 	else
11451 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11452 			ut_params->op), "failed to process sym crypto op");
11453 
11454 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11455 			"crypto op processing failed");
11456 
11457 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11458 
11459 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
11460 			ut_params->op->sym->cipher.data.offset);
11461 	auth_tag = ciphertext + plaintext_pad_len;
11462 
11463 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
11464 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
11465 
11466 	/* Validate obuf */
11467 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11468 			ciphertext,
11469 			tdata->ciphertext.data,
11470 			tdata->ciphertext.len,
11471 			"Ciphertext data not as expected");
11472 
11473 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11474 			auth_tag,
11475 			tdata->auth_tag.data,
11476 			tdata->auth_tag.len,
11477 			"Generated auth tag not as expected");
11478 
11479 	return 0;
11480 
11481 }
11482 
11483 static int
11484 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
11485 {
11486 	return test_authenticated_encryption_oop(&gcm_test_case_5);
11487 }
11488 
11489 static int
11490 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
11491 {
11492 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11493 	struct crypto_unittest_params *ut_params = &unittest_params;
11494 
11495 	int retval;
11496 	uint8_t *plaintext;
11497 	struct rte_cryptodev_info dev_info;
11498 
11499 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11500 	uint64_t feat_flags = dev_info.feature_flags;
11501 
11502 	/* Verify the capabilities */
11503 	struct rte_cryptodev_sym_capability_idx cap_idx;
11504 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11505 	cap_idx.algo.aead = tdata->algo;
11506 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11507 			&cap_idx) == NULL)
11508 		return TEST_SKIPPED;
11509 
11510 	/* not supported with CPU crypto and raw data-path APIs*/
11511 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
11512 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
11513 		return TEST_SKIPPED;
11514 
11515 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11516 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11517 		printf("Device does not support RAW data-path APIs.\n");
11518 		return TEST_SKIPPED;
11519 	}
11520 
11521 	/* Create AEAD session */
11522 	retval = create_aead_session(ts_params->valid_devs[0],
11523 			tdata->algo,
11524 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11525 			tdata->key.data, tdata->key.len,
11526 			tdata->aad.len, tdata->auth_tag.len,
11527 			tdata->iv.len);
11528 	if (retval < 0)
11529 		return retval;
11530 
11531 	/* alloc mbuf and set payload */
11532 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11533 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11534 
11535 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11536 			rte_pktmbuf_tailroom(ut_params->ibuf));
11537 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
11538 			rte_pktmbuf_tailroom(ut_params->obuf));
11539 
11540 	/* Create AEAD operation */
11541 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11542 	if (retval < 0)
11543 		return retval;
11544 
11545 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11546 
11547 	ut_params->op->sym->m_src = ut_params->ibuf;
11548 	ut_params->op->sym->m_dst = ut_params->obuf;
11549 
11550 	/* Process crypto operation */
11551 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11552 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11553 				ut_params->op, 0, 0, 0, 0);
11554 	else
11555 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11556 			ut_params->op), "failed to process sym crypto op");
11557 
11558 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11559 			"crypto op processing failed");
11560 
11561 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
11562 			ut_params->op->sym->cipher.data.offset);
11563 
11564 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11565 
11566 	/* Validate obuf */
11567 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11568 			plaintext,
11569 			tdata->plaintext.data,
11570 			tdata->plaintext.len,
11571 			"Plaintext data not as expected");
11572 
11573 	TEST_ASSERT_EQUAL(ut_params->op->status,
11574 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11575 			"Authentication failed");
11576 	return 0;
11577 }
11578 
11579 static int
11580 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
11581 {
11582 	return test_authenticated_decryption_oop(&gcm_test_case_5);
11583 }
11584 
11585 static int
11586 test_authenticated_encryption_sessionless(
11587 		const struct aead_test_data *tdata)
11588 {
11589 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11590 	struct crypto_unittest_params *ut_params = &unittest_params;
11591 
11592 	int retval;
11593 	uint8_t *ciphertext, *auth_tag;
11594 	uint16_t plaintext_pad_len;
11595 	uint8_t key[tdata->key.len + 1];
11596 	struct rte_cryptodev_info dev_info;
11597 
11598 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11599 	uint64_t feat_flags = dev_info.feature_flags;
11600 
11601 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
11602 		printf("Device doesn't support Sessionless ops.\n");
11603 		return TEST_SKIPPED;
11604 	}
11605 
11606 	/* not supported with CPU crypto */
11607 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11608 		return TEST_SKIPPED;
11609 
11610 	/* Verify the capabilities */
11611 	struct rte_cryptodev_sym_capability_idx cap_idx;
11612 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11613 	cap_idx.algo.aead = tdata->algo;
11614 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11615 			&cap_idx) == NULL)
11616 		return TEST_SKIPPED;
11617 
11618 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11619 
11620 	/* clear mbuf payload */
11621 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11622 			rte_pktmbuf_tailroom(ut_params->ibuf));
11623 
11624 	/* Create AEAD operation */
11625 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
11626 	if (retval < 0)
11627 		return retval;
11628 
11629 	/* Create GCM xform */
11630 	memcpy(key, tdata->key.data, tdata->key.len);
11631 	retval = create_aead_xform(ut_params->op,
11632 			tdata->algo,
11633 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
11634 			key, tdata->key.len,
11635 			tdata->aad.len, tdata->auth_tag.len,
11636 			tdata->iv.len);
11637 	if (retval < 0)
11638 		return retval;
11639 
11640 	ut_params->op->sym->m_src = ut_params->ibuf;
11641 
11642 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11643 			RTE_CRYPTO_OP_SESSIONLESS,
11644 			"crypto op session type not sessionless");
11645 
11646 	/* Process crypto operation */
11647 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
11648 			ut_params->op), "failed to process sym crypto op");
11649 
11650 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11651 
11652 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11653 			"crypto op status not success");
11654 
11655 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11656 
11657 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11658 			ut_params->op->sym->cipher.data.offset);
11659 	auth_tag = ciphertext + plaintext_pad_len;
11660 
11661 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
11662 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
11663 
11664 	/* Validate obuf */
11665 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11666 			ciphertext,
11667 			tdata->ciphertext.data,
11668 			tdata->ciphertext.len,
11669 			"Ciphertext data not as expected");
11670 
11671 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11672 			auth_tag,
11673 			tdata->auth_tag.data,
11674 			tdata->auth_tag.len,
11675 			"Generated auth tag not as expected");
11676 
11677 	return 0;
11678 
11679 }
11680 
11681 static int
11682 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
11683 {
11684 	return test_authenticated_encryption_sessionless(
11685 			&gcm_test_case_5);
11686 }
11687 
11688 static int
11689 test_authenticated_decryption_sessionless(
11690 		const struct aead_test_data *tdata)
11691 {
11692 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11693 	struct crypto_unittest_params *ut_params = &unittest_params;
11694 
11695 	int retval;
11696 	uint8_t *plaintext;
11697 	uint8_t key[tdata->key.len + 1];
11698 	struct rte_cryptodev_info dev_info;
11699 
11700 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11701 	uint64_t feat_flags = dev_info.feature_flags;
11702 
11703 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
11704 		printf("Device doesn't support Sessionless ops.\n");
11705 		return TEST_SKIPPED;
11706 	}
11707 
11708 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11709 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11710 		printf("Device doesn't support RAW data-path APIs.\n");
11711 		return TEST_SKIPPED;
11712 	}
11713 
11714 	/* not supported with CPU crypto */
11715 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11716 		return TEST_SKIPPED;
11717 
11718 	/* Verify the capabilities */
11719 	struct rte_cryptodev_sym_capability_idx cap_idx;
11720 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
11721 	cap_idx.algo.aead = tdata->algo;
11722 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11723 			&cap_idx) == NULL)
11724 		return TEST_SKIPPED;
11725 
11726 	/* alloc mbuf and set payload */
11727 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11728 
11729 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11730 			rte_pktmbuf_tailroom(ut_params->ibuf));
11731 
11732 	/* Create AEAD operation */
11733 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
11734 	if (retval < 0)
11735 		return retval;
11736 
11737 	/* Create AEAD xform */
11738 	memcpy(key, tdata->key.data, tdata->key.len);
11739 	retval = create_aead_xform(ut_params->op,
11740 			tdata->algo,
11741 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11742 			key, tdata->key.len,
11743 			tdata->aad.len, tdata->auth_tag.len,
11744 			tdata->iv.len);
11745 	if (retval < 0)
11746 		return retval;
11747 
11748 	ut_params->op->sym->m_src = ut_params->ibuf;
11749 
11750 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11751 			RTE_CRYPTO_OP_SESSIONLESS,
11752 			"crypto op session type not sessionless");
11753 
11754 	/* Process crypto operation */
11755 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11756 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11757 				ut_params->op, 0, 0, 0, 0);
11758 	else
11759 		TEST_ASSERT_NOT_NULL(process_crypto_request(
11760 			ts_params->valid_devs[0], ut_params->op),
11761 				"failed to process sym crypto op");
11762 
11763 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11764 
11765 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11766 			"crypto op status not success");
11767 
11768 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11769 			ut_params->op->sym->cipher.data.offset);
11770 
11771 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11772 
11773 	/* Validate obuf */
11774 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11775 			plaintext,
11776 			tdata->plaintext.data,
11777 			tdata->plaintext.len,
11778 			"Plaintext data not as expected");
11779 
11780 	TEST_ASSERT_EQUAL(ut_params->op->status,
11781 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11782 			"Authentication failed");
11783 	return 0;
11784 }
11785 
11786 static int
11787 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
11788 {
11789 	return test_authenticated_decryption_sessionless(
11790 			&gcm_test_case_5);
11791 }
11792 
11793 static int
11794 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
11795 {
11796 	return test_authenticated_encryption(&ccm_test_case_128_1);
11797 }
11798 
11799 static int
11800 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
11801 {
11802 	return test_authenticated_encryption(&ccm_test_case_128_2);
11803 }
11804 
11805 static int
11806 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
11807 {
11808 	return test_authenticated_encryption(&ccm_test_case_128_3);
11809 }
11810 
11811 static int
11812 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
11813 {
11814 	return test_authenticated_decryption(&ccm_test_case_128_1);
11815 }
11816 
11817 static int
11818 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
11819 {
11820 	return test_authenticated_decryption(&ccm_test_case_128_2);
11821 }
11822 
11823 static int
11824 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
11825 {
11826 	return test_authenticated_decryption(&ccm_test_case_128_3);
11827 }
11828 
11829 static int
11830 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
11831 {
11832 	return test_authenticated_encryption(&ccm_test_case_192_1);
11833 }
11834 
11835 static int
11836 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
11837 {
11838 	return test_authenticated_encryption(&ccm_test_case_192_2);
11839 }
11840 
11841 static int
11842 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
11843 {
11844 	return test_authenticated_encryption(&ccm_test_case_192_3);
11845 }
11846 
11847 static int
11848 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
11849 {
11850 	return test_authenticated_decryption(&ccm_test_case_192_1);
11851 }
11852 
11853 static int
11854 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
11855 {
11856 	return test_authenticated_decryption(&ccm_test_case_192_2);
11857 }
11858 
11859 static int
11860 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
11861 {
11862 	return test_authenticated_decryption(&ccm_test_case_192_3);
11863 }
11864 
11865 static int
11866 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11867 {
11868 	return test_authenticated_encryption(&ccm_test_case_256_1);
11869 }
11870 
11871 static int
11872 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11873 {
11874 	return test_authenticated_encryption(&ccm_test_case_256_2);
11875 }
11876 
11877 static int
11878 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11879 {
11880 	return test_authenticated_encryption(&ccm_test_case_256_3);
11881 }
11882 
11883 static int
11884 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11885 {
11886 	return test_authenticated_decryption(&ccm_test_case_256_1);
11887 }
11888 
11889 static int
11890 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11891 {
11892 	return test_authenticated_decryption(&ccm_test_case_256_2);
11893 }
11894 
11895 static int
11896 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11897 {
11898 	return test_authenticated_decryption(&ccm_test_case_256_3);
11899 }
11900 
11901 static int
11902 test_stats(void)
11903 {
11904 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11905 	struct rte_cryptodev_stats stats;
11906 
11907 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11908 		return TEST_SKIPPED;
11909 
11910 	/* Verify the capabilities */
11911 	struct rte_cryptodev_sym_capability_idx cap_idx;
11912 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11913 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11914 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11915 			&cap_idx) == NULL)
11916 		return TEST_SKIPPED;
11917 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11918 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11919 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11920 			&cap_idx) == NULL)
11921 		return TEST_SKIPPED;
11922 
11923 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11924 			== -ENOTSUP)
11925 		return TEST_SKIPPED;
11926 
11927 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11928 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11929 			&stats) == -ENODEV),
11930 		"rte_cryptodev_stats_get invalid dev failed");
11931 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11932 		"rte_cryptodev_stats_get invalid Param failed");
11933 
11934 	/* Test expected values */
11935 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
11936 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11937 			&stats),
11938 		"rte_cryptodev_stats_get failed");
11939 	TEST_ASSERT((stats.enqueued_count == 1),
11940 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11941 	TEST_ASSERT((stats.dequeued_count == 1),
11942 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11943 	TEST_ASSERT((stats.enqueue_err_count == 0),
11944 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11945 	TEST_ASSERT((stats.dequeue_err_count == 0),
11946 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11947 
11948 	/* invalid device but should ignore and not reset device stats*/
11949 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11950 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11951 			&stats),
11952 		"rte_cryptodev_stats_get failed");
11953 	TEST_ASSERT((stats.enqueued_count == 1),
11954 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11955 
11956 	/* check that a valid reset clears stats */
11957 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11958 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11959 			&stats),
11960 					  "rte_cryptodev_stats_get failed");
11961 	TEST_ASSERT((stats.enqueued_count == 0),
11962 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11963 	TEST_ASSERT((stats.dequeued_count == 0),
11964 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11965 
11966 	return TEST_SUCCESS;
11967 }
11968 
11969 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11970 				   struct crypto_unittest_params *ut_params,
11971 				   enum rte_crypto_auth_operation op,
11972 				   const struct HMAC_MD5_vector *test_case)
11973 {
11974 	uint8_t key[64];
11975 
11976 	memcpy(key, test_case->key.data, test_case->key.len);
11977 
11978 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11979 	ut_params->auth_xform.next = NULL;
11980 	ut_params->auth_xform.auth.op = op;
11981 
11982 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11983 
11984 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11985 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11986 	ut_params->auth_xform.auth.key.data = key;
11987 
11988 	ut_params->sess = rte_cryptodev_sym_session_create(
11989 		ts_params->valid_devs[0], &ut_params->auth_xform,
11990 			ts_params->session_mpool);
11991 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
11992 		return TEST_SKIPPED;
11993 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11994 
11995 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11996 
11997 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11998 			rte_pktmbuf_tailroom(ut_params->ibuf));
11999 
12000 	return 0;
12001 }
12002 
12003 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
12004 			      const struct HMAC_MD5_vector *test_case,
12005 			      uint8_t **plaintext)
12006 {
12007 	uint16_t plaintext_pad_len;
12008 
12009 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12010 
12011 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
12012 				16);
12013 
12014 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12015 			plaintext_pad_len);
12016 	memcpy(*plaintext, test_case->plaintext.data,
12017 			test_case->plaintext.len);
12018 
12019 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12020 			ut_params->ibuf, MD5_DIGEST_LEN);
12021 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12022 			"no room to append digest");
12023 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12024 			ut_params->ibuf, plaintext_pad_len);
12025 
12026 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12027 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
12028 			   test_case->auth_tag.len);
12029 	}
12030 
12031 	sym_op->auth.data.offset = 0;
12032 	sym_op->auth.data.length = test_case->plaintext.len;
12033 
12034 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12035 	ut_params->op->sym->m_src = ut_params->ibuf;
12036 
12037 	return 0;
12038 }
12039 
12040 static int
12041 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
12042 {
12043 	uint16_t plaintext_pad_len;
12044 	uint8_t *plaintext, *auth_tag;
12045 
12046 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12047 	struct crypto_unittest_params *ut_params = &unittest_params;
12048 	struct rte_cryptodev_info dev_info;
12049 
12050 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12051 	uint64_t feat_flags = dev_info.feature_flags;
12052 
12053 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12054 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12055 		printf("Device doesn't support RAW data-path APIs.\n");
12056 		return TEST_SKIPPED;
12057 	}
12058 
12059 	/* Verify the capabilities */
12060 	struct rte_cryptodev_sym_capability_idx cap_idx;
12061 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12062 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
12063 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12064 			&cap_idx) == NULL)
12065 		return TEST_SKIPPED;
12066 
12067 	if (MD5_HMAC_create_session(ts_params, ut_params,
12068 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
12069 		return TEST_FAILED;
12070 
12071 	/* Generate Crypto op data structure */
12072 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12073 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12074 	TEST_ASSERT_NOT_NULL(ut_params->op,
12075 			"Failed to allocate symmetric crypto operation struct");
12076 
12077 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
12078 				16);
12079 
12080 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
12081 		return TEST_FAILED;
12082 
12083 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12084 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12085 			ut_params->op);
12086 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12087 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12088 				ut_params->op, 0, 1, 0, 0);
12089 	else
12090 		TEST_ASSERT_NOT_NULL(
12091 			process_crypto_request(ts_params->valid_devs[0],
12092 				ut_params->op),
12093 				"failed to process sym crypto op");
12094 
12095 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12096 			"crypto op processing failed");
12097 
12098 	if (ut_params->op->sym->m_dst) {
12099 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12100 				uint8_t *, plaintext_pad_len);
12101 	} else {
12102 		auth_tag = plaintext + plaintext_pad_len;
12103 	}
12104 
12105 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12106 			auth_tag,
12107 			test_case->auth_tag.data,
12108 			test_case->auth_tag.len,
12109 			"HMAC_MD5 generated tag not as expected");
12110 
12111 	return TEST_SUCCESS;
12112 }
12113 
12114 static int
12115 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
12116 {
12117 	uint8_t *plaintext;
12118 
12119 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12120 	struct crypto_unittest_params *ut_params = &unittest_params;
12121 	struct rte_cryptodev_info dev_info;
12122 
12123 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12124 	uint64_t feat_flags = dev_info.feature_flags;
12125 
12126 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12127 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12128 		printf("Device doesn't support RAW data-path APIs.\n");
12129 		return TEST_SKIPPED;
12130 	}
12131 
12132 	/* Verify the capabilities */
12133 	struct rte_cryptodev_sym_capability_idx cap_idx;
12134 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12135 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
12136 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12137 			&cap_idx) == NULL)
12138 		return TEST_SKIPPED;
12139 
12140 	if (MD5_HMAC_create_session(ts_params, ut_params,
12141 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
12142 		return TEST_FAILED;
12143 	}
12144 
12145 	/* Generate Crypto op data structure */
12146 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12147 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12148 	TEST_ASSERT_NOT_NULL(ut_params->op,
12149 			"Failed to allocate symmetric crypto operation struct");
12150 
12151 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
12152 		return TEST_FAILED;
12153 
12154 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12155 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12156 			ut_params->op);
12157 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12158 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12159 				ut_params->op, 0, 1, 0, 0);
12160 	else
12161 		TEST_ASSERT_NOT_NULL(
12162 			process_crypto_request(ts_params->valid_devs[0],
12163 				ut_params->op),
12164 				"failed to process sym crypto op");
12165 
12166 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12167 			"HMAC_MD5 crypto op processing failed");
12168 
12169 	return TEST_SUCCESS;
12170 }
12171 
12172 static int
12173 test_MD5_HMAC_generate_case_1(void)
12174 {
12175 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
12176 }
12177 
12178 static int
12179 test_MD5_HMAC_verify_case_1(void)
12180 {
12181 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
12182 }
12183 
12184 static int
12185 test_MD5_HMAC_generate_case_2(void)
12186 {
12187 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
12188 }
12189 
12190 static int
12191 test_MD5_HMAC_verify_case_2(void)
12192 {
12193 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
12194 }
12195 
12196 static int
12197 test_multi_session(void)
12198 {
12199 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12200 	struct crypto_unittest_params *ut_params = &unittest_params;
12201 	struct rte_cryptodev_info dev_info;
12202 	struct rte_cryptodev_sym_session **sessions;
12203 	uint16_t i;
12204 
12205 	/* Verify the capabilities */
12206 	struct rte_cryptodev_sym_capability_idx cap_idx;
12207 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12208 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
12209 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12210 			&cap_idx) == NULL)
12211 		return TEST_SKIPPED;
12212 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12213 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12214 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12215 			&cap_idx) == NULL)
12216 		return TEST_SKIPPED;
12217 
12218 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
12219 			aes_cbc_key, hmac_sha512_key);
12220 
12221 
12222 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12223 
12224 	sessions = rte_malloc(NULL,
12225 			sizeof(struct rte_cryptodev_sym_session *) *
12226 			(MAX_NB_SESSIONS + 1), 0);
12227 
12228 	/* Create multiple crypto sessions*/
12229 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
12230 		sessions[i] = rte_cryptodev_sym_session_create(
12231 			ts_params->valid_devs[0], &ut_params->auth_xform,
12232 				ts_params->session_mpool);
12233 		if (sessions[i] == NULL && rte_errno == ENOTSUP)
12234 			return TEST_SKIPPED;
12235 
12236 		TEST_ASSERT_NOT_NULL(sessions[i],
12237 				"Session creation failed at session number %u",
12238 				i);
12239 		/* Attempt to send a request on each session */
12240 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
12241 			sessions[i],
12242 			ut_params,
12243 			ts_params,
12244 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
12245 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
12246 			aes_cbc_iv),
12247 			"Failed to perform decrypt on request number %u.", i);
12248 		/* free crypto operation structure */
12249 		rte_crypto_op_free(ut_params->op);
12250 
12251 		/*
12252 		 * free mbuf - both obuf and ibuf are usually the same,
12253 		 * so check if they point at the same address is necessary,
12254 		 * to avoid freeing the mbuf twice.
12255 		 */
12256 		if (ut_params->obuf) {
12257 			rte_pktmbuf_free(ut_params->obuf);
12258 			if (ut_params->ibuf == ut_params->obuf)
12259 				ut_params->ibuf = 0;
12260 			ut_params->obuf = 0;
12261 		}
12262 		if (ut_params->ibuf) {
12263 			rte_pktmbuf_free(ut_params->ibuf);
12264 			ut_params->ibuf = 0;
12265 		}
12266 	}
12267 
12268 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
12269 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
12270 				sessions[i]);
12271 	}
12272 
12273 	rte_free(sessions);
12274 
12275 	return TEST_SUCCESS;
12276 }
12277 
12278 struct multi_session_params {
12279 	struct crypto_unittest_params ut_params;
12280 	uint8_t *cipher_key;
12281 	uint8_t *hmac_key;
12282 	const uint8_t *cipher;
12283 	const uint8_t *digest;
12284 	uint8_t *iv;
12285 };
12286 
12287 #define MB_SESSION_NUMBER 3
12288 
12289 static int
12290 test_multi_session_random_usage(void)
12291 {
12292 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12293 	struct rte_cryptodev_info dev_info;
12294 	struct rte_cryptodev_sym_session **sessions;
12295 	uint32_t i, j;
12296 	struct multi_session_params ut_paramz[] = {
12297 
12298 		{
12299 			.cipher_key = ms_aes_cbc_key0,
12300 			.hmac_key = ms_hmac_key0,
12301 			.cipher = ms_aes_cbc_cipher0,
12302 			.digest = ms_hmac_digest0,
12303 			.iv = ms_aes_cbc_iv0
12304 		},
12305 		{
12306 			.cipher_key = ms_aes_cbc_key1,
12307 			.hmac_key = ms_hmac_key1,
12308 			.cipher = ms_aes_cbc_cipher1,
12309 			.digest = ms_hmac_digest1,
12310 			.iv = ms_aes_cbc_iv1
12311 		},
12312 		{
12313 			.cipher_key = ms_aes_cbc_key2,
12314 			.hmac_key = ms_hmac_key2,
12315 			.cipher = ms_aes_cbc_cipher2,
12316 			.digest = ms_hmac_digest2,
12317 			.iv = ms_aes_cbc_iv2
12318 		},
12319 
12320 	};
12321 
12322 	/* Verify the capabilities */
12323 	struct rte_cryptodev_sym_capability_idx cap_idx;
12324 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12325 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
12326 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12327 			&cap_idx) == NULL)
12328 		return TEST_SKIPPED;
12329 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12330 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
12331 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12332 			&cap_idx) == NULL)
12333 		return TEST_SKIPPED;
12334 
12335 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12336 
12337 	sessions = rte_malloc(NULL,
12338 			(sizeof(struct rte_cryptodev_sym_session *)
12339 					* MAX_NB_SESSIONS) + 1, 0);
12340 
12341 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
12342 
12343 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
12344 				sizeof(struct crypto_unittest_params));
12345 
12346 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
12347 				&ut_paramz[i].ut_params,
12348 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
12349 
12350 		/* Create multiple crypto sessions*/
12351 		sessions[i] = rte_cryptodev_sym_session_create(
12352 				ts_params->valid_devs[0],
12353 				&ut_paramz[i].ut_params.auth_xform,
12354 				ts_params->session_mpool);
12355 		if (sessions[i] == NULL && rte_errno == ENOTSUP)
12356 			return TEST_SKIPPED;
12357 
12358 		TEST_ASSERT_NOT_NULL(sessions[i],
12359 				"Session creation failed at session number %u",
12360 				i);
12361 	}
12362 
12363 	srand(time(NULL));
12364 	for (i = 0; i < 40000; i++) {
12365 
12366 		j = rand() % MB_SESSION_NUMBER;
12367 
12368 		TEST_ASSERT_SUCCESS(
12369 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
12370 					sessions[j],
12371 					&ut_paramz[j].ut_params,
12372 					ts_params, ut_paramz[j].cipher,
12373 					ut_paramz[j].digest,
12374 					ut_paramz[j].iv),
12375 			"Failed to perform decrypt on request number %u.", i);
12376 
12377 		rte_crypto_op_free(ut_paramz[j].ut_params.op);
12378 
12379 		/*
12380 		 * free mbuf - both obuf and ibuf are usually the same,
12381 		 * so check if they point at the same address is necessary,
12382 		 * to avoid freeing the mbuf twice.
12383 		 */
12384 		if (ut_paramz[j].ut_params.obuf) {
12385 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
12386 			if (ut_paramz[j].ut_params.ibuf
12387 					== ut_paramz[j].ut_params.obuf)
12388 				ut_paramz[j].ut_params.ibuf = 0;
12389 			ut_paramz[j].ut_params.obuf = 0;
12390 		}
12391 		if (ut_paramz[j].ut_params.ibuf) {
12392 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
12393 			ut_paramz[j].ut_params.ibuf = 0;
12394 		}
12395 	}
12396 
12397 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
12398 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
12399 				sessions[i]);
12400 	}
12401 
12402 	rte_free(sessions);
12403 
12404 	return TEST_SUCCESS;
12405 }
12406 
12407 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
12408 			0xab, 0xab, 0xab, 0xab,
12409 			0xab, 0xab, 0xab, 0xab,
12410 			0xab, 0xab, 0xab, 0xab};
12411 
12412 static int
12413 test_null_invalid_operation(void)
12414 {
12415 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12416 	struct crypto_unittest_params *ut_params = &unittest_params;
12417 
12418 	/* This test is for NULL PMD only */
12419 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
12420 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
12421 		return TEST_SKIPPED;
12422 
12423 	/* Setup Cipher Parameters */
12424 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12425 	ut_params->cipher_xform.next = NULL;
12426 
12427 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
12428 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12429 
12430 	/* Create Crypto session*/
12431 	ut_params->sess = rte_cryptodev_sym_session_create(
12432 			ts_params->valid_devs[0], &ut_params->cipher_xform,
12433 			ts_params->session_mpool);
12434 	TEST_ASSERT(ut_params->sess == NULL,
12435 			"Session creation succeeded unexpectedly");
12436 
12437 	/* Setup HMAC Parameters */
12438 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12439 	ut_params->auth_xform.next = NULL;
12440 
12441 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
12442 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12443 
12444 	/* Create Crypto session*/
12445 	ut_params->sess = rte_cryptodev_sym_session_create(
12446 			ts_params->valid_devs[0], &ut_params->auth_xform,
12447 			ts_params->session_mpool);
12448 	TEST_ASSERT(ut_params->sess == NULL,
12449 			"Session creation succeeded unexpectedly");
12450 
12451 	return TEST_SUCCESS;
12452 }
12453 
12454 
12455 #define NULL_BURST_LENGTH (32)
12456 
12457 static int
12458 test_null_burst_operation(void)
12459 {
12460 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12461 	struct crypto_unittest_params *ut_params = &unittest_params;
12462 
12463 	unsigned i, burst_len = NULL_BURST_LENGTH;
12464 
12465 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
12466 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
12467 
12468 	/* This test is for NULL PMD only */
12469 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
12470 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
12471 		return TEST_SKIPPED;
12472 
12473 	/* Setup Cipher Parameters */
12474 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12475 	ut_params->cipher_xform.next = &ut_params->auth_xform;
12476 
12477 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
12478 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
12479 
12480 	/* Setup HMAC Parameters */
12481 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12482 	ut_params->auth_xform.next = NULL;
12483 
12484 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
12485 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
12486 
12487 	/* Create Crypto session*/
12488 	ut_params->sess = rte_cryptodev_sym_session_create(
12489 				ts_params->valid_devs[0],
12490 				&ut_params->auth_xform,
12491 				ts_params->session_mpool);
12492 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
12493 		return TEST_SKIPPED;
12494 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12495 
12496 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
12497 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
12498 			burst_len, "failed to generate burst of crypto ops");
12499 
12500 	/* Generate an operation for each mbuf in burst */
12501 	for (i = 0; i < burst_len; i++) {
12502 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12503 
12504 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
12505 
12506 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
12507 				sizeof(unsigned));
12508 		*data = i;
12509 
12510 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
12511 
12512 		burst[i]->sym->m_src = m;
12513 	}
12514 
12515 	/* Process crypto operation */
12516 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
12517 			0, burst, burst_len),
12518 			burst_len,
12519 			"Error enqueuing burst");
12520 
12521 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
12522 			0, burst_dequeued, burst_len),
12523 			burst_len,
12524 			"Error dequeuing burst");
12525 
12526 
12527 	for (i = 0; i < burst_len; i++) {
12528 		TEST_ASSERT_EQUAL(
12529 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
12530 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
12531 					uint32_t *),
12532 			"data not as expected");
12533 
12534 		rte_pktmbuf_free(burst[i]->sym->m_src);
12535 		rte_crypto_op_free(burst[i]);
12536 	}
12537 
12538 	return TEST_SUCCESS;
12539 }
12540 
12541 static uint16_t
12542 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
12543 		  uint16_t nb_ops, void *user_param)
12544 {
12545 	RTE_SET_USED(dev_id);
12546 	RTE_SET_USED(qp_id);
12547 	RTE_SET_USED(ops);
12548 	RTE_SET_USED(user_param);
12549 
12550 	printf("crypto enqueue callback called\n");
12551 	return nb_ops;
12552 }
12553 
12554 static uint16_t
12555 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
12556 		  uint16_t nb_ops, void *user_param)
12557 {
12558 	RTE_SET_USED(dev_id);
12559 	RTE_SET_USED(qp_id);
12560 	RTE_SET_USED(ops);
12561 	RTE_SET_USED(user_param);
12562 
12563 	printf("crypto dequeue callback called\n");
12564 	return nb_ops;
12565 }
12566 
12567 /*
12568  * Thread using enqueue/dequeue callback with RCU.
12569  */
12570 static int
12571 test_enqdeq_callback_thread(void *arg)
12572 {
12573 	RTE_SET_USED(arg);
12574 	/* DP thread calls rte_cryptodev_enqueue_burst()/
12575 	 * rte_cryptodev_dequeue_burst() and invokes callback.
12576 	 */
12577 	test_null_burst_operation();
12578 	return 0;
12579 }
12580 
12581 static int
12582 test_enq_callback_setup(void)
12583 {
12584 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12585 	struct rte_cryptodev_info dev_info;
12586 	struct rte_cryptodev_qp_conf qp_conf = {
12587 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
12588 	};
12589 
12590 	struct rte_cryptodev_cb *cb;
12591 	uint16_t qp_id = 0;
12592 
12593 	/* Stop the device in case it's started so it can be configured */
12594 	rte_cryptodev_stop(ts_params->valid_devs[0]);
12595 
12596 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12597 
12598 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12599 			&ts_params->conf),
12600 			"Failed to configure cryptodev %u",
12601 			ts_params->valid_devs[0]);
12602 
12603 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12604 	qp_conf.mp_session = ts_params->session_mpool;
12605 
12606 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12607 			ts_params->valid_devs[0], qp_id, &qp_conf,
12608 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12609 			"Failed test for "
12610 			"rte_cryptodev_queue_pair_setup: num_inflights "
12611 			"%u on qp %u on cryptodev %u",
12612 			qp_conf.nb_descriptors, qp_id,
12613 			ts_params->valid_devs[0]);
12614 
12615 	/* Test with invalid crypto device */
12616 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
12617 			qp_id, test_enq_callback, NULL);
12618 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12619 			"cryptodev %u did not fail",
12620 			qp_id, RTE_CRYPTO_MAX_DEVS);
12621 
12622 	/* Test with invalid queue pair */
12623 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12624 			dev_info.max_nb_queue_pairs + 1,
12625 			test_enq_callback, NULL);
12626 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12627 			"cryptodev %u did not fail",
12628 			dev_info.max_nb_queue_pairs + 1,
12629 			ts_params->valid_devs[0]);
12630 
12631 	/* Test with NULL callback */
12632 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12633 			qp_id, NULL, NULL);
12634 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12635 			"cryptodev %u did not fail",
12636 			qp_id, ts_params->valid_devs[0]);
12637 
12638 	/* Test with valid configuration */
12639 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
12640 			qp_id, test_enq_callback, NULL);
12641 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12642 			"qp %u on cryptodev %u",
12643 			qp_id, ts_params->valid_devs[0]);
12644 
12645 	rte_cryptodev_start(ts_params->valid_devs[0]);
12646 
12647 	/* Launch a thread */
12648 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12649 				rte_get_next_lcore(-1, 1, 0));
12650 
12651 	/* Wait until reader exited. */
12652 	rte_eal_mp_wait_lcore();
12653 
12654 	/* Test with invalid crypto device */
12655 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12656 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12657 			"Expected call to fail as crypto device is invalid");
12658 
12659 	/* Test with invalid queue pair */
12660 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12661 			ts_params->valid_devs[0],
12662 			dev_info.max_nb_queue_pairs + 1, cb),
12663 			"Expected call to fail as queue pair is invalid");
12664 
12665 	/* Test with NULL callback */
12666 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
12667 			ts_params->valid_devs[0], qp_id, NULL),
12668 			"Expected call to fail as callback is NULL");
12669 
12670 	/* Test with valid configuration */
12671 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
12672 			ts_params->valid_devs[0], qp_id, cb),
12673 			"Failed test to remove callback on "
12674 			"qp %u on cryptodev %u",
12675 			qp_id, ts_params->valid_devs[0]);
12676 
12677 	return TEST_SUCCESS;
12678 }
12679 
12680 static int
12681 test_deq_callback_setup(void)
12682 {
12683 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12684 	struct rte_cryptodev_info dev_info;
12685 	struct rte_cryptodev_qp_conf qp_conf = {
12686 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
12687 	};
12688 
12689 	struct rte_cryptodev_cb *cb;
12690 	uint16_t qp_id = 0;
12691 
12692 	/* Stop the device in case it's started so it can be configured */
12693 	rte_cryptodev_stop(ts_params->valid_devs[0]);
12694 
12695 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12696 
12697 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12698 			&ts_params->conf),
12699 			"Failed to configure cryptodev %u",
12700 			ts_params->valid_devs[0]);
12701 
12702 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12703 	qp_conf.mp_session = ts_params->session_mpool;
12704 
12705 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12706 			ts_params->valid_devs[0], qp_id, &qp_conf,
12707 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12708 			"Failed test for "
12709 			"rte_cryptodev_queue_pair_setup: num_inflights "
12710 			"%u on qp %u on cryptodev %u",
12711 			qp_conf.nb_descriptors, qp_id,
12712 			ts_params->valid_devs[0]);
12713 
12714 	/* Test with invalid crypto device */
12715 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
12716 			qp_id, test_deq_callback, NULL);
12717 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12718 			"cryptodev %u did not fail",
12719 			qp_id, RTE_CRYPTO_MAX_DEVS);
12720 
12721 	/* Test with invalid queue pair */
12722 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12723 			dev_info.max_nb_queue_pairs + 1,
12724 			test_deq_callback, NULL);
12725 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12726 			"cryptodev %u did not fail",
12727 			dev_info.max_nb_queue_pairs + 1,
12728 			ts_params->valid_devs[0]);
12729 
12730 	/* Test with NULL callback */
12731 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12732 			qp_id, NULL, NULL);
12733 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12734 			"cryptodev %u did not fail",
12735 			qp_id, ts_params->valid_devs[0]);
12736 
12737 	/* Test with valid configuration */
12738 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12739 			qp_id, test_deq_callback, NULL);
12740 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12741 			"qp %u on cryptodev %u",
12742 			qp_id, ts_params->valid_devs[0]);
12743 
12744 	rte_cryptodev_start(ts_params->valid_devs[0]);
12745 
12746 	/* Launch a thread */
12747 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12748 				rte_get_next_lcore(-1, 1, 0));
12749 
12750 	/* Wait until reader exited. */
12751 	rte_eal_mp_wait_lcore();
12752 
12753 	/* Test with invalid crypto device */
12754 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12755 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12756 			"Expected call to fail as crypto device is invalid");
12757 
12758 	/* Test with invalid queue pair */
12759 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12760 			ts_params->valid_devs[0],
12761 			dev_info.max_nb_queue_pairs + 1, cb),
12762 			"Expected call to fail as queue pair is invalid");
12763 
12764 	/* Test with NULL callback */
12765 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12766 			ts_params->valid_devs[0], qp_id, NULL),
12767 			"Expected call to fail as callback is NULL");
12768 
12769 	/* Test with valid configuration */
12770 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
12771 			ts_params->valid_devs[0], qp_id, cb),
12772 			"Failed test to remove callback on "
12773 			"qp %u on cryptodev %u",
12774 			qp_id, ts_params->valid_devs[0]);
12775 
12776 	return TEST_SUCCESS;
12777 }
12778 
12779 static void
12780 generate_gmac_large_plaintext(uint8_t *data)
12781 {
12782 	uint16_t i;
12783 
12784 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
12785 		memcpy(&data[i], &data[0], 32);
12786 }
12787 
12788 static int
12789 create_gmac_operation(enum rte_crypto_auth_operation op,
12790 		const struct gmac_test_data *tdata)
12791 {
12792 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12793 	struct crypto_unittest_params *ut_params = &unittest_params;
12794 	struct rte_crypto_sym_op *sym_op;
12795 
12796 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12797 
12798 	/* Generate Crypto op data structure */
12799 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12800 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12801 	TEST_ASSERT_NOT_NULL(ut_params->op,
12802 			"Failed to allocate symmetric crypto operation struct");
12803 
12804 	sym_op = ut_params->op->sym;
12805 
12806 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12807 			ut_params->ibuf, tdata->gmac_tag.len);
12808 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12809 			"no room to append digest");
12810 
12811 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12812 			ut_params->ibuf, plaintext_pad_len);
12813 
12814 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12815 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12816 				tdata->gmac_tag.len);
12817 		debug_hexdump(stdout, "digest:",
12818 				sym_op->auth.digest.data,
12819 				tdata->gmac_tag.len);
12820 	}
12821 
12822 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12823 			uint8_t *, IV_OFFSET);
12824 
12825 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12826 
12827 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12828 
12829 	sym_op->cipher.data.length = 0;
12830 	sym_op->cipher.data.offset = 0;
12831 
12832 	sym_op->auth.data.offset = 0;
12833 	sym_op->auth.data.length = tdata->plaintext.len;
12834 
12835 	return 0;
12836 }
12837 
12838 static int
12839 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12840 		const struct gmac_test_data *tdata,
12841 		void *digest_mem, uint64_t digest_phys)
12842 {
12843 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12844 	struct crypto_unittest_params *ut_params = &unittest_params;
12845 	struct rte_crypto_sym_op *sym_op;
12846 
12847 	/* Generate Crypto op data structure */
12848 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12849 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12850 	TEST_ASSERT_NOT_NULL(ut_params->op,
12851 			"Failed to allocate symmetric crypto operation struct");
12852 
12853 	sym_op = ut_params->op->sym;
12854 
12855 	sym_op->auth.digest.data = digest_mem;
12856 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12857 			"no room to append digest");
12858 
12859 	sym_op->auth.digest.phys_addr = digest_phys;
12860 
12861 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12862 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12863 				tdata->gmac_tag.len);
12864 		debug_hexdump(stdout, "digest:",
12865 				sym_op->auth.digest.data,
12866 				tdata->gmac_tag.len);
12867 	}
12868 
12869 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12870 			uint8_t *, IV_OFFSET);
12871 
12872 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12873 
12874 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12875 
12876 	sym_op->cipher.data.length = 0;
12877 	sym_op->cipher.data.offset = 0;
12878 
12879 	sym_op->auth.data.offset = 0;
12880 	sym_op->auth.data.length = tdata->plaintext.len;
12881 
12882 	return 0;
12883 }
12884 
12885 static int create_gmac_session(uint8_t dev_id,
12886 		const struct gmac_test_data *tdata,
12887 		enum rte_crypto_auth_operation auth_op)
12888 {
12889 	uint8_t auth_key[tdata->key.len];
12890 
12891 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12892 	struct crypto_unittest_params *ut_params = &unittest_params;
12893 
12894 	memcpy(auth_key, tdata->key.data, tdata->key.len);
12895 
12896 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12897 	ut_params->auth_xform.next = NULL;
12898 
12899 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12900 	ut_params->auth_xform.auth.op = auth_op;
12901 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12902 	ut_params->auth_xform.auth.key.length = tdata->key.len;
12903 	ut_params->auth_xform.auth.key.data = auth_key;
12904 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12905 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12906 
12907 
12908 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
12909 			&ut_params->auth_xform, ts_params->session_mpool);
12910 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
12911 		return TEST_SKIPPED;
12912 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12913 
12914 	return 0;
12915 }
12916 
12917 static int
12918 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12919 {
12920 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12921 	struct crypto_unittest_params *ut_params = &unittest_params;
12922 	struct rte_cryptodev_info dev_info;
12923 
12924 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12925 	uint64_t feat_flags = dev_info.feature_flags;
12926 
12927 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12928 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12929 		printf("Device doesn't support RAW data-path APIs.\n");
12930 		return TEST_SKIPPED;
12931 	}
12932 
12933 	int retval;
12934 
12935 	uint8_t *auth_tag, *plaintext;
12936 	uint16_t plaintext_pad_len;
12937 
12938 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12939 			      "No GMAC length in the source data");
12940 
12941 	/* Verify the capabilities */
12942 	struct rte_cryptodev_sym_capability_idx cap_idx;
12943 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12944 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12945 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12946 			&cap_idx) == NULL)
12947 		return TEST_SKIPPED;
12948 
12949 	retval = create_gmac_session(ts_params->valid_devs[0],
12950 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12951 
12952 	if (retval == -ENOTSUP)
12953 		return TEST_SKIPPED;
12954 	if (retval < 0)
12955 		return retval;
12956 
12957 	if (tdata->plaintext.len > MBUF_SIZE)
12958 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12959 	else
12960 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12961 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12962 			"Failed to allocate input buffer in mempool");
12963 
12964 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12965 			rte_pktmbuf_tailroom(ut_params->ibuf));
12966 
12967 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12968 	/*
12969 	 * Runtime generate the large plain text instead of use hard code
12970 	 * plain text vector. It is done to avoid create huge source file
12971 	 * with the test vector.
12972 	 */
12973 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12974 		generate_gmac_large_plaintext(tdata->plaintext.data);
12975 
12976 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12977 				plaintext_pad_len);
12978 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12979 
12980 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12981 	debug_hexdump(stdout, "plaintext:", plaintext,
12982 			tdata->plaintext.len);
12983 
12984 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12985 			tdata);
12986 
12987 	if (retval < 0)
12988 		return retval;
12989 
12990 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12991 
12992 	ut_params->op->sym->m_src = ut_params->ibuf;
12993 
12994 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12995 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12996 			ut_params->op);
12997 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12998 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12999 				ut_params->op, 0, 1, 0, 0);
13000 	else
13001 		TEST_ASSERT_NOT_NULL(
13002 			process_crypto_request(ts_params->valid_devs[0],
13003 			ut_params->op), "failed to process sym crypto op");
13004 
13005 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13006 			"crypto op processing failed");
13007 
13008 	if (ut_params->op->sym->m_dst) {
13009 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13010 				uint8_t *, plaintext_pad_len);
13011 	} else {
13012 		auth_tag = plaintext + plaintext_pad_len;
13013 	}
13014 
13015 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
13016 
13017 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13018 			auth_tag,
13019 			tdata->gmac_tag.data,
13020 			tdata->gmac_tag.len,
13021 			"GMAC Generated auth tag not as expected");
13022 
13023 	return 0;
13024 }
13025 
13026 static int
13027 test_AES_GMAC_authentication_test_case_1(void)
13028 {
13029 	return test_AES_GMAC_authentication(&gmac_test_case_1);
13030 }
13031 
13032 static int
13033 test_AES_GMAC_authentication_test_case_2(void)
13034 {
13035 	return test_AES_GMAC_authentication(&gmac_test_case_2);
13036 }
13037 
13038 static int
13039 test_AES_GMAC_authentication_test_case_3(void)
13040 {
13041 	return test_AES_GMAC_authentication(&gmac_test_case_3);
13042 }
13043 
13044 static int
13045 test_AES_GMAC_authentication_test_case_4(void)
13046 {
13047 	return test_AES_GMAC_authentication(&gmac_test_case_4);
13048 }
13049 
13050 static int
13051 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
13052 {
13053 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13054 	struct crypto_unittest_params *ut_params = &unittest_params;
13055 	int retval;
13056 	uint32_t plaintext_pad_len;
13057 	uint8_t *plaintext;
13058 	struct rte_cryptodev_info dev_info;
13059 
13060 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13061 	uint64_t feat_flags = dev_info.feature_flags;
13062 
13063 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13064 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13065 		printf("Device doesn't support RAW data-path APIs.\n");
13066 		return TEST_SKIPPED;
13067 	}
13068 
13069 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
13070 			      "No GMAC length in the source data");
13071 
13072 	/* Verify the capabilities */
13073 	struct rte_cryptodev_sym_capability_idx cap_idx;
13074 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13075 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
13076 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13077 			&cap_idx) == NULL)
13078 		return TEST_SKIPPED;
13079 
13080 	retval = create_gmac_session(ts_params->valid_devs[0],
13081 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
13082 
13083 	if (retval == -ENOTSUP)
13084 		return TEST_SKIPPED;
13085 	if (retval < 0)
13086 		return retval;
13087 
13088 	if (tdata->plaintext.len > MBUF_SIZE)
13089 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
13090 	else
13091 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13092 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13093 			"Failed to allocate input buffer in mempool");
13094 
13095 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13096 			rte_pktmbuf_tailroom(ut_params->ibuf));
13097 
13098 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
13099 
13100 	/*
13101 	 * Runtime generate the large plain text instead of use hard code
13102 	 * plain text vector. It is done to avoid create huge source file
13103 	 * with the test vector.
13104 	 */
13105 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
13106 		generate_gmac_large_plaintext(tdata->plaintext.data);
13107 
13108 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13109 				plaintext_pad_len);
13110 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13111 
13112 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
13113 	debug_hexdump(stdout, "plaintext:", plaintext,
13114 			tdata->plaintext.len);
13115 
13116 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
13117 			tdata);
13118 
13119 	if (retval < 0)
13120 		return retval;
13121 
13122 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13123 
13124 	ut_params->op->sym->m_src = ut_params->ibuf;
13125 
13126 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13127 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13128 			ut_params->op);
13129 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13130 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13131 				ut_params->op, 0, 1, 0, 0);
13132 	else
13133 		TEST_ASSERT_NOT_NULL(
13134 			process_crypto_request(ts_params->valid_devs[0],
13135 			ut_params->op), "failed to process sym crypto op");
13136 
13137 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13138 			"crypto op processing failed");
13139 
13140 	return 0;
13141 
13142 }
13143 
13144 static int
13145 test_AES_GMAC_authentication_verify_test_case_1(void)
13146 {
13147 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
13148 }
13149 
13150 static int
13151 test_AES_GMAC_authentication_verify_test_case_2(void)
13152 {
13153 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
13154 }
13155 
13156 static int
13157 test_AES_GMAC_authentication_verify_test_case_3(void)
13158 {
13159 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
13160 }
13161 
13162 static int
13163 test_AES_GMAC_authentication_verify_test_case_4(void)
13164 {
13165 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
13166 }
13167 
13168 static int
13169 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
13170 				uint32_t fragsz)
13171 {
13172 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13173 	struct crypto_unittest_params *ut_params = &unittest_params;
13174 	struct rte_cryptodev_info dev_info;
13175 	uint64_t feature_flags;
13176 	unsigned int trn_data = 0;
13177 	void *digest_mem = NULL;
13178 	uint32_t segs = 1;
13179 	unsigned int to_trn = 0;
13180 	struct rte_mbuf *buf = NULL;
13181 	uint8_t *auth_tag, *plaintext;
13182 	int retval;
13183 
13184 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
13185 			      "No GMAC length in the source data");
13186 
13187 	/* Verify the capabilities */
13188 	struct rte_cryptodev_sym_capability_idx cap_idx;
13189 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13190 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
13191 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13192 			&cap_idx) == NULL)
13193 		return TEST_SKIPPED;
13194 
13195 	/* Check for any input SGL support */
13196 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13197 	feature_flags = dev_info.feature_flags;
13198 
13199 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
13200 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
13201 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
13202 		return TEST_SKIPPED;
13203 
13204 	if (fragsz > tdata->plaintext.len)
13205 		fragsz = tdata->plaintext.len;
13206 
13207 	uint16_t plaintext_len = fragsz;
13208 
13209 	retval = create_gmac_session(ts_params->valid_devs[0],
13210 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
13211 
13212 	if (retval == -ENOTSUP)
13213 		return TEST_SKIPPED;
13214 	if (retval < 0)
13215 		return retval;
13216 
13217 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13218 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13219 			"Failed to allocate input buffer in mempool");
13220 
13221 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13222 			rte_pktmbuf_tailroom(ut_params->ibuf));
13223 
13224 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13225 				plaintext_len);
13226 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13227 
13228 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13229 
13230 	trn_data += plaintext_len;
13231 
13232 	buf = ut_params->ibuf;
13233 
13234 	/*
13235 	 * Loop until no more fragments
13236 	 */
13237 
13238 	while (trn_data < tdata->plaintext.len) {
13239 		++segs;
13240 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13241 				(tdata->plaintext.len - trn_data) : fragsz;
13242 
13243 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13244 		buf = buf->next;
13245 
13246 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13247 				rte_pktmbuf_tailroom(buf));
13248 
13249 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13250 				to_trn);
13251 
13252 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13253 				to_trn);
13254 		trn_data += to_trn;
13255 		if (trn_data  == tdata->plaintext.len)
13256 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13257 					tdata->gmac_tag.len);
13258 	}
13259 	ut_params->ibuf->nb_segs = segs;
13260 
13261 	/*
13262 	 * Place digest at the end of the last buffer
13263 	 */
13264 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13265 
13266 	if (!digest_mem) {
13267 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13268 				+ tdata->gmac_tag.len);
13269 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13270 				tdata->plaintext.len);
13271 	}
13272 
13273 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
13274 			tdata, digest_mem, digest_phys);
13275 
13276 	if (retval < 0)
13277 		return retval;
13278 
13279 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13280 
13281 	ut_params->op->sym->m_src = ut_params->ibuf;
13282 
13283 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13284 		return TEST_SKIPPED;
13285 
13286 	TEST_ASSERT_NOT_NULL(
13287 		process_crypto_request(ts_params->valid_devs[0],
13288 		ut_params->op), "failed to process sym crypto op");
13289 
13290 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13291 			"crypto op processing failed");
13292 
13293 	auth_tag = digest_mem;
13294 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
13295 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13296 			auth_tag,
13297 			tdata->gmac_tag.data,
13298 			tdata->gmac_tag.len,
13299 			"GMAC Generated auth tag not as expected");
13300 
13301 	return 0;
13302 }
13303 
13304 /* Segment size not multiple of block size (16B) */
13305 static int
13306 test_AES_GMAC_authentication_SGL_40B(void)
13307 {
13308 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
13309 }
13310 
13311 static int
13312 test_AES_GMAC_authentication_SGL_80B(void)
13313 {
13314 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
13315 }
13316 
13317 static int
13318 test_AES_GMAC_authentication_SGL_2048B(void)
13319 {
13320 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
13321 }
13322 
13323 /* Segment size not multiple of block size (16B) */
13324 static int
13325 test_AES_GMAC_authentication_SGL_2047B(void)
13326 {
13327 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
13328 }
13329 
13330 struct test_crypto_vector {
13331 	enum rte_crypto_cipher_algorithm crypto_algo;
13332 	unsigned int cipher_offset;
13333 	unsigned int cipher_len;
13334 
13335 	struct {
13336 		uint8_t data[64];
13337 		unsigned int len;
13338 	} cipher_key;
13339 
13340 	struct {
13341 		uint8_t data[64];
13342 		unsigned int len;
13343 	} iv;
13344 
13345 	struct {
13346 		const uint8_t *data;
13347 		unsigned int len;
13348 	} plaintext;
13349 
13350 	struct {
13351 		const uint8_t *data;
13352 		unsigned int len;
13353 	} ciphertext;
13354 
13355 	enum rte_crypto_auth_algorithm auth_algo;
13356 	unsigned int auth_offset;
13357 
13358 	struct {
13359 		uint8_t data[128];
13360 		unsigned int len;
13361 	} auth_key;
13362 
13363 	struct {
13364 		const uint8_t *data;
13365 		unsigned int len;
13366 	} aad;
13367 
13368 	struct {
13369 		uint8_t data[128];
13370 		unsigned int len;
13371 	} digest;
13372 };
13373 
13374 static const struct test_crypto_vector
13375 hmac_sha1_test_crypto_vector = {
13376 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13377 	.plaintext = {
13378 		.data = plaintext_hash,
13379 		.len = 512
13380 	},
13381 	.auth_key = {
13382 		.data = {
13383 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13384 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13385 			0xDE, 0xF4, 0xDE, 0xAD
13386 		},
13387 		.len = 20
13388 	},
13389 	.digest = {
13390 		.data = {
13391 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
13392 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
13393 			0x3F, 0x91, 0x64, 0x59
13394 		},
13395 		.len = 20
13396 	}
13397 };
13398 
13399 static const struct test_crypto_vector
13400 aes128_gmac_test_vector = {
13401 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
13402 	.plaintext = {
13403 		.data = plaintext_hash,
13404 		.len = 512
13405 	},
13406 	.iv = {
13407 		.data = {
13408 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13409 			0x08, 0x09, 0x0A, 0x0B
13410 		},
13411 		.len = 12
13412 	},
13413 	.auth_key = {
13414 		.data = {
13415 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
13416 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
13417 		},
13418 		.len = 16
13419 	},
13420 	.digest = {
13421 		.data = {
13422 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
13423 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
13424 		},
13425 		.len = 16
13426 	}
13427 };
13428 
13429 static const struct test_crypto_vector
13430 aes128cbc_hmac_sha1_test_vector = {
13431 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
13432 	.cipher_offset = 0,
13433 	.cipher_len = 512,
13434 	.cipher_key = {
13435 		.data = {
13436 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
13437 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
13438 		},
13439 		.len = 16
13440 	},
13441 	.iv = {
13442 		.data = {
13443 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13444 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
13445 		},
13446 		.len = 16
13447 	},
13448 	.plaintext = {
13449 		.data = plaintext_hash,
13450 		.len = 512
13451 	},
13452 	.ciphertext = {
13453 		.data = ciphertext512_aes128cbc,
13454 		.len = 512
13455 	},
13456 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13457 	.auth_offset = 0,
13458 	.auth_key = {
13459 		.data = {
13460 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13461 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13462 			0xDE, 0xF4, 0xDE, 0xAD
13463 		},
13464 		.len = 20
13465 	},
13466 	.digest = {
13467 		.data = {
13468 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
13469 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
13470 			0x18, 0x8C, 0x1D, 0x32
13471 		},
13472 		.len = 20
13473 	}
13474 };
13475 
13476 static const struct test_crypto_vector
13477 aes128cbc_hmac_sha1_aad_test_vector = {
13478 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
13479 	.cipher_offset = 8,
13480 	.cipher_len = 496,
13481 	.cipher_key = {
13482 		.data = {
13483 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
13484 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
13485 		},
13486 		.len = 16
13487 	},
13488 	.iv = {
13489 		.data = {
13490 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
13491 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
13492 		},
13493 		.len = 16
13494 	},
13495 	.plaintext = {
13496 		.data = plaintext_hash,
13497 		.len = 512
13498 	},
13499 	.ciphertext = {
13500 		.data = ciphertext512_aes128cbc_aad,
13501 		.len = 512
13502 	},
13503 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
13504 	.auth_offset = 0,
13505 	.auth_key = {
13506 		.data = {
13507 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
13508 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
13509 			0xDE, 0xF4, 0xDE, 0xAD
13510 		},
13511 		.len = 20
13512 	},
13513 	.digest = {
13514 		.data = {
13515 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
13516 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
13517 			0x62, 0x0F, 0xFB, 0x10
13518 		},
13519 		.len = 20
13520 	}
13521 };
13522 
13523 static void
13524 data_corruption(uint8_t *data)
13525 {
13526 	data[0] += 1;
13527 }
13528 
13529 static void
13530 tag_corruption(uint8_t *data, unsigned int tag_offset)
13531 {
13532 	data[tag_offset] += 1;
13533 }
13534 
13535 static int
13536 create_auth_session(struct crypto_unittest_params *ut_params,
13537 		uint8_t dev_id,
13538 		const struct test_crypto_vector *reference,
13539 		enum rte_crypto_auth_operation auth_op)
13540 {
13541 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13542 	uint8_t auth_key[reference->auth_key.len + 1];
13543 
13544 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13545 
13546 	/* Setup Authentication Parameters */
13547 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13548 	ut_params->auth_xform.auth.op = auth_op;
13549 	ut_params->auth_xform.next = NULL;
13550 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13551 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13552 	ut_params->auth_xform.auth.key.data = auth_key;
13553 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13554 
13555 	/* Create Crypto session*/
13556 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
13557 				&ut_params->auth_xform,
13558 				ts_params->session_mpool);
13559 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
13560 		return TEST_SKIPPED;
13561 
13562 	return 0;
13563 }
13564 
13565 static int
13566 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
13567 		uint8_t dev_id,
13568 		const struct test_crypto_vector *reference,
13569 		enum rte_crypto_auth_operation auth_op,
13570 		enum rte_crypto_cipher_operation cipher_op)
13571 {
13572 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13573 	uint8_t cipher_key[reference->cipher_key.len + 1];
13574 	uint8_t auth_key[reference->auth_key.len + 1];
13575 
13576 	memcpy(cipher_key, reference->cipher_key.data,
13577 			reference->cipher_key.len);
13578 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13579 
13580 	/* Setup Authentication Parameters */
13581 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13582 	ut_params->auth_xform.auth.op = auth_op;
13583 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13584 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13585 	ut_params->auth_xform.auth.key.data = auth_key;
13586 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13587 
13588 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
13589 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
13590 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
13591 	} else {
13592 		ut_params->auth_xform.next = &ut_params->cipher_xform;
13593 
13594 		/* Setup Cipher Parameters */
13595 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13596 		ut_params->cipher_xform.next = NULL;
13597 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13598 		ut_params->cipher_xform.cipher.op = cipher_op;
13599 		ut_params->cipher_xform.cipher.key.data = cipher_key;
13600 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13601 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13602 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13603 	}
13604 
13605 	/* Create Crypto session*/
13606 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
13607 				&ut_params->auth_xform,
13608 				ts_params->session_mpool);
13609 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
13610 		return TEST_SKIPPED;
13611 
13612 	return 0;
13613 }
13614 
13615 static int
13616 create_auth_operation(struct crypto_testsuite_params *ts_params,
13617 		struct crypto_unittest_params *ut_params,
13618 		const struct test_crypto_vector *reference,
13619 		unsigned int auth_generate)
13620 {
13621 	/* Generate Crypto op data structure */
13622 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13623 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13624 	TEST_ASSERT_NOT_NULL(ut_params->op,
13625 			"Failed to allocate pktmbuf offload");
13626 
13627 	/* Set crypto operation data parameters */
13628 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13629 
13630 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13631 
13632 	/* set crypto operation source mbuf */
13633 	sym_op->m_src = ut_params->ibuf;
13634 
13635 	/* digest */
13636 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13637 			ut_params->ibuf, reference->digest.len);
13638 
13639 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13640 			"no room to append auth tag");
13641 
13642 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13643 			ut_params->ibuf, reference->plaintext.len);
13644 
13645 	if (auth_generate)
13646 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13647 	else
13648 		memcpy(sym_op->auth.digest.data,
13649 				reference->digest.data,
13650 				reference->digest.len);
13651 
13652 	debug_hexdump(stdout, "digest:",
13653 			sym_op->auth.digest.data,
13654 			reference->digest.len);
13655 
13656 	sym_op->auth.data.length = reference->plaintext.len;
13657 	sym_op->auth.data.offset = 0;
13658 
13659 	return 0;
13660 }
13661 
13662 static int
13663 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
13664 		struct crypto_unittest_params *ut_params,
13665 		const struct test_crypto_vector *reference,
13666 		unsigned int auth_generate)
13667 {
13668 	/* Generate Crypto op data structure */
13669 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13670 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13671 	TEST_ASSERT_NOT_NULL(ut_params->op,
13672 			"Failed to allocate pktmbuf offload");
13673 
13674 	/* Set crypto operation data parameters */
13675 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13676 
13677 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13678 
13679 	/* set crypto operation source mbuf */
13680 	sym_op->m_src = ut_params->ibuf;
13681 
13682 	/* digest */
13683 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13684 			ut_params->ibuf, reference->digest.len);
13685 
13686 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13687 			"no room to append auth tag");
13688 
13689 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13690 			ut_params->ibuf, reference->ciphertext.len);
13691 
13692 	if (auth_generate)
13693 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13694 	else
13695 		memcpy(sym_op->auth.digest.data,
13696 				reference->digest.data,
13697 				reference->digest.len);
13698 
13699 	debug_hexdump(stdout, "digest:",
13700 			sym_op->auth.digest.data,
13701 			reference->digest.len);
13702 
13703 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13704 			reference->iv.data, reference->iv.len);
13705 
13706 	sym_op->cipher.data.length = 0;
13707 	sym_op->cipher.data.offset = 0;
13708 
13709 	sym_op->auth.data.length = reference->plaintext.len;
13710 	sym_op->auth.data.offset = 0;
13711 
13712 	return 0;
13713 }
13714 
13715 static int
13716 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
13717 		struct crypto_unittest_params *ut_params,
13718 		const struct test_crypto_vector *reference,
13719 		unsigned int auth_generate)
13720 {
13721 	/* Generate Crypto op data structure */
13722 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13723 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13724 	TEST_ASSERT_NOT_NULL(ut_params->op,
13725 			"Failed to allocate pktmbuf offload");
13726 
13727 	/* Set crypto operation data parameters */
13728 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13729 
13730 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13731 
13732 	/* set crypto operation source mbuf */
13733 	sym_op->m_src = ut_params->ibuf;
13734 
13735 	/* digest */
13736 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13737 			ut_params->ibuf, reference->digest.len);
13738 
13739 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13740 			"no room to append auth tag");
13741 
13742 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13743 			ut_params->ibuf, reference->ciphertext.len);
13744 
13745 	if (auth_generate)
13746 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13747 	else
13748 		memcpy(sym_op->auth.digest.data,
13749 				reference->digest.data,
13750 				reference->digest.len);
13751 
13752 	debug_hexdump(stdout, "digest:",
13753 			sym_op->auth.digest.data,
13754 			reference->digest.len);
13755 
13756 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13757 			reference->iv.data, reference->iv.len);
13758 
13759 	sym_op->cipher.data.length = reference->cipher_len;
13760 	sym_op->cipher.data.offset = reference->cipher_offset;
13761 
13762 	sym_op->auth.data.length = reference->plaintext.len;
13763 	sym_op->auth.data.offset = reference->auth_offset;
13764 
13765 	return 0;
13766 }
13767 
13768 static int
13769 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13770 		struct crypto_unittest_params *ut_params,
13771 		const struct test_crypto_vector *reference)
13772 {
13773 	return create_auth_operation(ts_params, ut_params, reference, 0);
13774 }
13775 
13776 static int
13777 create_auth_verify_GMAC_operation(
13778 		struct crypto_testsuite_params *ts_params,
13779 		struct crypto_unittest_params *ut_params,
13780 		const struct test_crypto_vector *reference)
13781 {
13782 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
13783 }
13784 
13785 static int
13786 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13787 		struct crypto_unittest_params *ut_params,
13788 		const struct test_crypto_vector *reference)
13789 {
13790 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
13791 }
13792 
13793 static int
13794 test_authentication_verify_fail_when_data_corruption(
13795 		struct crypto_testsuite_params *ts_params,
13796 		struct crypto_unittest_params *ut_params,
13797 		const struct test_crypto_vector *reference,
13798 		unsigned int data_corrupted)
13799 {
13800 	int retval;
13801 
13802 	uint8_t *plaintext;
13803 	struct rte_cryptodev_info dev_info;
13804 
13805 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13806 	uint64_t feat_flags = dev_info.feature_flags;
13807 
13808 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13809 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13810 		printf("Device doesn't support RAW data-path APIs.\n");
13811 		return TEST_SKIPPED;
13812 	}
13813 
13814 	/* Verify the capabilities */
13815 	struct rte_cryptodev_sym_capability_idx cap_idx;
13816 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13817 	cap_idx.algo.auth = reference->auth_algo;
13818 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13819 			&cap_idx) == NULL)
13820 		return TEST_SKIPPED;
13821 
13822 
13823 	/* Create session */
13824 	retval = create_auth_session(ut_params,
13825 			ts_params->valid_devs[0],
13826 			reference,
13827 			RTE_CRYPTO_AUTH_OP_VERIFY);
13828 
13829 	if (retval == -ENOTSUP)
13830 		return TEST_SKIPPED;
13831 	if (retval < 0)
13832 		return retval;
13833 
13834 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13835 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13836 			"Failed to allocate input buffer in mempool");
13837 
13838 	/* clear mbuf payload */
13839 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13840 			rte_pktmbuf_tailroom(ut_params->ibuf));
13841 
13842 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13843 			reference->plaintext.len);
13844 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13845 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13846 
13847 	debug_hexdump(stdout, "plaintext:", plaintext,
13848 		reference->plaintext.len);
13849 
13850 	/* Create operation */
13851 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
13852 
13853 	if (retval < 0)
13854 		return retval;
13855 
13856 	if (data_corrupted)
13857 		data_corruption(plaintext);
13858 	else
13859 		tag_corruption(plaintext, reference->plaintext.len);
13860 
13861 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13862 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13863 			ut_params->op);
13864 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13865 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13866 			"authentication not failed");
13867 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13868 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13869 				ut_params->op, 0, 1, 0, 0);
13870 	else {
13871 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13872 			ut_params->op);
13873 	}
13874 	if (ut_params->op == NULL)
13875 		return 0;
13876 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13877 		return 0;
13878 
13879 	return -1;
13880 }
13881 
13882 static int
13883 test_authentication_verify_GMAC_fail_when_corruption(
13884 		struct crypto_testsuite_params *ts_params,
13885 		struct crypto_unittest_params *ut_params,
13886 		const struct test_crypto_vector *reference,
13887 		unsigned int data_corrupted)
13888 {
13889 	int retval;
13890 	uint8_t *plaintext;
13891 	struct rte_cryptodev_info dev_info;
13892 
13893 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13894 	uint64_t feat_flags = dev_info.feature_flags;
13895 
13896 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13897 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13898 		printf("Device doesn't support RAW data-path APIs.\n");
13899 		return TEST_SKIPPED;
13900 	}
13901 
13902 	/* Verify the capabilities */
13903 	struct rte_cryptodev_sym_capability_idx cap_idx;
13904 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13905 	cap_idx.algo.auth = reference->auth_algo;
13906 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13907 			&cap_idx) == NULL)
13908 		return TEST_SKIPPED;
13909 
13910 	/* Create session */
13911 	retval = create_auth_cipher_session(ut_params,
13912 			ts_params->valid_devs[0],
13913 			reference,
13914 			RTE_CRYPTO_AUTH_OP_VERIFY,
13915 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13916 	if (retval < 0)
13917 		return retval;
13918 
13919 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13920 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13921 			"Failed to allocate input buffer in mempool");
13922 
13923 	/* clear mbuf payload */
13924 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13925 			rte_pktmbuf_tailroom(ut_params->ibuf));
13926 
13927 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13928 			reference->plaintext.len);
13929 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13930 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13931 
13932 	debug_hexdump(stdout, "plaintext:", plaintext,
13933 		reference->plaintext.len);
13934 
13935 	/* Create operation */
13936 	retval = create_auth_verify_GMAC_operation(ts_params,
13937 			ut_params,
13938 			reference);
13939 
13940 	if (retval < 0)
13941 		return retval;
13942 
13943 	if (data_corrupted)
13944 		data_corruption(plaintext);
13945 	else
13946 		tag_corruption(plaintext, reference->aad.len);
13947 
13948 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13949 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13950 			ut_params->op);
13951 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13952 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13953 			"authentication not failed");
13954 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13955 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13956 				ut_params->op, 0, 1, 0, 0);
13957 	else {
13958 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13959 			ut_params->op);
13960 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13961 	}
13962 
13963 	return 0;
13964 }
13965 
13966 static int
13967 test_authenticated_decryption_fail_when_corruption(
13968 		struct crypto_testsuite_params *ts_params,
13969 		struct crypto_unittest_params *ut_params,
13970 		const struct test_crypto_vector *reference,
13971 		unsigned int data_corrupted)
13972 {
13973 	int retval;
13974 
13975 	uint8_t *ciphertext;
13976 	struct rte_cryptodev_info dev_info;
13977 
13978 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13979 	uint64_t feat_flags = dev_info.feature_flags;
13980 
13981 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13982 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13983 		printf("Device doesn't support RAW data-path APIs.\n");
13984 		return TEST_SKIPPED;
13985 	}
13986 
13987 	/* Verify the capabilities */
13988 	struct rte_cryptodev_sym_capability_idx cap_idx;
13989 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13990 	cap_idx.algo.auth = reference->auth_algo;
13991 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13992 			&cap_idx) == NULL)
13993 		return TEST_SKIPPED;
13994 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13995 	cap_idx.algo.cipher = reference->crypto_algo;
13996 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13997 			&cap_idx) == NULL)
13998 		return TEST_SKIPPED;
13999 
14000 	/* Create session */
14001 	retval = create_auth_cipher_session(ut_params,
14002 			ts_params->valid_devs[0],
14003 			reference,
14004 			RTE_CRYPTO_AUTH_OP_VERIFY,
14005 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
14006 
14007 	if (retval == -ENOTSUP)
14008 		return TEST_SKIPPED;
14009 	if (retval < 0)
14010 		return retval;
14011 
14012 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14013 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14014 			"Failed to allocate input buffer in mempool");
14015 
14016 	/* clear mbuf payload */
14017 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14018 			rte_pktmbuf_tailroom(ut_params->ibuf));
14019 
14020 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14021 			reference->ciphertext.len);
14022 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
14023 	memcpy(ciphertext, reference->ciphertext.data,
14024 			reference->ciphertext.len);
14025 
14026 	/* Create operation */
14027 	retval = create_cipher_auth_verify_operation(ts_params,
14028 			ut_params,
14029 			reference);
14030 
14031 	if (retval < 0)
14032 		return retval;
14033 
14034 	if (data_corrupted)
14035 		data_corruption(ciphertext);
14036 	else
14037 		tag_corruption(ciphertext, reference->ciphertext.len);
14038 
14039 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
14040 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14041 			ut_params->op);
14042 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
14043 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14044 			"authentication not failed");
14045 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14046 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14047 				ut_params->op, 1, 1, 0, 0);
14048 	else {
14049 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14050 			ut_params->op);
14051 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
14052 	}
14053 
14054 	return 0;
14055 }
14056 
14057 static int
14058 test_authenticated_encrypt_with_esn(
14059 		struct crypto_testsuite_params *ts_params,
14060 		struct crypto_unittest_params *ut_params,
14061 		const struct test_crypto_vector *reference)
14062 {
14063 	int retval;
14064 
14065 	uint8_t *authciphertext, *plaintext, *auth_tag;
14066 	uint16_t plaintext_pad_len;
14067 	uint8_t cipher_key[reference->cipher_key.len + 1];
14068 	uint8_t auth_key[reference->auth_key.len + 1];
14069 	struct rte_cryptodev_info dev_info;
14070 
14071 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14072 	uint64_t feat_flags = dev_info.feature_flags;
14073 
14074 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14075 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14076 		printf("Device doesn't support RAW data-path APIs.\n");
14077 		return TEST_SKIPPED;
14078 	}
14079 
14080 	/* Verify the capabilities */
14081 	struct rte_cryptodev_sym_capability_idx cap_idx;
14082 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14083 	cap_idx.algo.auth = reference->auth_algo;
14084 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14085 			&cap_idx) == NULL)
14086 		return TEST_SKIPPED;
14087 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14088 	cap_idx.algo.cipher = reference->crypto_algo;
14089 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14090 			&cap_idx) == NULL)
14091 		return TEST_SKIPPED;
14092 
14093 	/* Create session */
14094 	memcpy(cipher_key, reference->cipher_key.data,
14095 			reference->cipher_key.len);
14096 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14097 
14098 	/* Setup Cipher Parameters */
14099 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14100 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
14101 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
14102 	ut_params->cipher_xform.cipher.key.data = cipher_key;
14103 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
14104 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
14105 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
14106 
14107 	ut_params->cipher_xform.next = &ut_params->auth_xform;
14108 
14109 	/* Setup Authentication Parameters */
14110 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14111 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
14112 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14113 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14114 	ut_params->auth_xform.auth.key.data = auth_key;
14115 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14116 	ut_params->auth_xform.next = NULL;
14117 
14118 	/* Create Crypto session*/
14119 	ut_params->sess = rte_cryptodev_sym_session_create(
14120 			ts_params->valid_devs[0], &ut_params->cipher_xform,
14121 			ts_params->session_mpool);
14122 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14123 		return TEST_SKIPPED;
14124 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14125 
14126 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14127 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14128 			"Failed to allocate input buffer in mempool");
14129 
14130 	/* clear mbuf payload */
14131 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14132 			rte_pktmbuf_tailroom(ut_params->ibuf));
14133 
14134 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14135 			reference->plaintext.len);
14136 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
14137 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
14138 
14139 	/* Create operation */
14140 	retval = create_cipher_auth_operation(ts_params,
14141 			ut_params,
14142 			reference, 0);
14143 
14144 	if (retval < 0)
14145 		return retval;
14146 
14147 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14148 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14149 			ut_params->op);
14150 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14151 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14152 				ut_params->op, 1, 1, 0, 0);
14153 	else
14154 		ut_params->op = process_crypto_request(
14155 			ts_params->valid_devs[0], ut_params->op);
14156 
14157 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
14158 
14159 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14160 			"crypto op processing failed");
14161 
14162 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
14163 
14164 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
14165 			ut_params->op->sym->auth.data.offset);
14166 	auth_tag = authciphertext + plaintext_pad_len;
14167 	debug_hexdump(stdout, "ciphertext:", authciphertext,
14168 			reference->ciphertext.len);
14169 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
14170 
14171 	/* Validate obuf */
14172 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14173 			authciphertext,
14174 			reference->ciphertext.data,
14175 			reference->ciphertext.len,
14176 			"Ciphertext data not as expected");
14177 
14178 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14179 			auth_tag,
14180 			reference->digest.data,
14181 			reference->digest.len,
14182 			"Generated digest not as expected");
14183 
14184 	return TEST_SUCCESS;
14185 
14186 }
14187 
14188 static int
14189 test_authenticated_decrypt_with_esn(
14190 		struct crypto_testsuite_params *ts_params,
14191 		struct crypto_unittest_params *ut_params,
14192 		const struct test_crypto_vector *reference)
14193 {
14194 	int retval;
14195 
14196 	uint8_t *ciphertext;
14197 	uint8_t cipher_key[reference->cipher_key.len + 1];
14198 	uint8_t auth_key[reference->auth_key.len + 1];
14199 	struct rte_cryptodev_info dev_info;
14200 
14201 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14202 	uint64_t feat_flags = dev_info.feature_flags;
14203 
14204 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14205 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14206 		printf("Device doesn't support RAW data-path APIs.\n");
14207 		return TEST_SKIPPED;
14208 	}
14209 
14210 	/* Verify the capabilities */
14211 	struct rte_cryptodev_sym_capability_idx cap_idx;
14212 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14213 	cap_idx.algo.auth = reference->auth_algo;
14214 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14215 			&cap_idx) == NULL)
14216 		return TEST_SKIPPED;
14217 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14218 	cap_idx.algo.cipher = reference->crypto_algo;
14219 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14220 			&cap_idx) == NULL)
14221 		return TEST_SKIPPED;
14222 
14223 	/* Create session */
14224 	memcpy(cipher_key, reference->cipher_key.data,
14225 			reference->cipher_key.len);
14226 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
14227 
14228 	/* Setup Authentication Parameters */
14229 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
14230 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
14231 	ut_params->auth_xform.auth.algo = reference->auth_algo;
14232 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
14233 	ut_params->auth_xform.auth.key.data = auth_key;
14234 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
14235 	ut_params->auth_xform.next = &ut_params->cipher_xform;
14236 
14237 	/* Setup Cipher Parameters */
14238 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
14239 	ut_params->cipher_xform.next = NULL;
14240 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
14241 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
14242 	ut_params->cipher_xform.cipher.key.data = cipher_key;
14243 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
14244 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
14245 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
14246 
14247 	/* Create Crypto session*/
14248 	ut_params->sess = rte_cryptodev_sym_session_create(
14249 			ts_params->valid_devs[0], &ut_params->auth_xform,
14250 			ts_params->session_mpool);
14251 	if (ut_params->sess == NULL && rte_errno == ENOTSUP)
14252 		return TEST_SKIPPED;
14253 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
14254 
14255 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14256 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
14257 			"Failed to allocate input buffer in mempool");
14258 
14259 	/* clear mbuf payload */
14260 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14261 			rte_pktmbuf_tailroom(ut_params->ibuf));
14262 
14263 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14264 			reference->ciphertext.len);
14265 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
14266 	memcpy(ciphertext, reference->ciphertext.data,
14267 			reference->ciphertext.len);
14268 
14269 	/* Create operation */
14270 	retval = create_cipher_auth_verify_operation(ts_params,
14271 			ut_params,
14272 			reference);
14273 
14274 	if (retval < 0)
14275 		return retval;
14276 
14277 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14278 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
14279 			ut_params->op);
14280 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14281 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14282 				ut_params->op, 1, 1, 0, 0);
14283 	else
14284 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
14285 			ut_params->op);
14286 
14287 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
14288 	TEST_ASSERT_EQUAL(ut_params->op->status,
14289 			RTE_CRYPTO_OP_STATUS_SUCCESS,
14290 			"crypto op processing passed");
14291 
14292 	ut_params->obuf = ut_params->op->sym->m_src;
14293 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
14294 
14295 	return 0;
14296 }
14297 
14298 static int
14299 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
14300 		const struct aead_test_data *tdata,
14301 		void *digest_mem, uint64_t digest_phys)
14302 {
14303 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14304 	struct crypto_unittest_params *ut_params = &unittest_params;
14305 
14306 	const unsigned int auth_tag_len = tdata->auth_tag.len;
14307 	const unsigned int iv_len = tdata->iv.len;
14308 	unsigned int aad_len = tdata->aad.len;
14309 	unsigned int aad_len_pad = 0;
14310 
14311 	/* Generate Crypto op data structure */
14312 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
14313 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
14314 	TEST_ASSERT_NOT_NULL(ut_params->op,
14315 		"Failed to allocate symmetric crypto operation struct");
14316 
14317 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
14318 
14319 	sym_op->aead.digest.data = digest_mem;
14320 
14321 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
14322 			"no room to append digest");
14323 
14324 	sym_op->aead.digest.phys_addr = digest_phys;
14325 
14326 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
14327 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
14328 				auth_tag_len);
14329 		debug_hexdump(stdout, "digest:",
14330 				sym_op->aead.digest.data,
14331 				auth_tag_len);
14332 	}
14333 
14334 	/* Append aad data */
14335 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
14336 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
14337 				uint8_t *, IV_OFFSET);
14338 
14339 		/* Copy IV 1 byte after the IV pointer, according to the API */
14340 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
14341 
14342 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
14343 
14344 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
14345 				ut_params->ibuf, aad_len);
14346 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
14347 				"no room to prepend aad");
14348 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
14349 				ut_params->ibuf);
14350 
14351 		memset(sym_op->aead.aad.data, 0, aad_len);
14352 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
14353 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
14354 
14355 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
14356 		debug_hexdump(stdout, "aad:",
14357 				sym_op->aead.aad.data, aad_len);
14358 	} else {
14359 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
14360 				uint8_t *, IV_OFFSET);
14361 
14362 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
14363 
14364 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
14365 
14366 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
14367 				ut_params->ibuf, aad_len_pad);
14368 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
14369 				"no room to prepend aad");
14370 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
14371 				ut_params->ibuf);
14372 
14373 		memset(sym_op->aead.aad.data, 0, aad_len);
14374 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
14375 
14376 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
14377 		debug_hexdump(stdout, "aad:",
14378 				sym_op->aead.aad.data, aad_len);
14379 	}
14380 
14381 	sym_op->aead.data.length = tdata->plaintext.len;
14382 	sym_op->aead.data.offset = aad_len_pad;
14383 
14384 	return 0;
14385 }
14386 
14387 #define SGL_MAX_NO	16
14388 
14389 static int
14390 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
14391 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
14392 {
14393 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14394 	struct crypto_unittest_params *ut_params = &unittest_params;
14395 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
14396 	int retval;
14397 	int to_trn = 0;
14398 	int to_trn_tbl[SGL_MAX_NO];
14399 	int segs = 1;
14400 	unsigned int trn_data = 0;
14401 	uint8_t *plaintext, *ciphertext, *auth_tag;
14402 	struct rte_cryptodev_info dev_info;
14403 
14404 	/* Verify the capabilities */
14405 	struct rte_cryptodev_sym_capability_idx cap_idx;
14406 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
14407 	cap_idx.algo.aead = tdata->algo;
14408 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
14409 			&cap_idx) == NULL)
14410 		return TEST_SKIPPED;
14411 
14412 	/* OOP not supported with CPU crypto */
14413 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14414 		return TEST_SKIPPED;
14415 
14416 	/* Detailed check for the particular SGL support flag */
14417 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
14418 	if (!oop) {
14419 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
14420 		if (sgl_in && (!(dev_info.feature_flags &
14421 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
14422 			return TEST_SKIPPED;
14423 
14424 		uint64_t feat_flags = dev_info.feature_flags;
14425 
14426 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
14427 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
14428 			printf("Device doesn't support RAW data-path APIs.\n");
14429 			return TEST_SKIPPED;
14430 		}
14431 	} else {
14432 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
14433 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
14434 				tdata->plaintext.len;
14435 		/* Raw data path API does not support OOP */
14436 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14437 			return TEST_SKIPPED;
14438 		if (sgl_in && !sgl_out) {
14439 			if (!(dev_info.feature_flags &
14440 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
14441 				return TEST_SKIPPED;
14442 		} else if (!sgl_in && sgl_out) {
14443 			if (!(dev_info.feature_flags &
14444 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
14445 				return TEST_SKIPPED;
14446 		} else if (sgl_in && sgl_out) {
14447 			if (!(dev_info.feature_flags &
14448 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
14449 				return TEST_SKIPPED;
14450 		}
14451 	}
14452 
14453 	if (fragsz > tdata->plaintext.len)
14454 		fragsz = tdata->plaintext.len;
14455 
14456 	uint16_t plaintext_len = fragsz;
14457 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
14458 
14459 	if (fragsz_oop > tdata->plaintext.len)
14460 		frag_size_oop = tdata->plaintext.len;
14461 
14462 	int ecx = 0;
14463 	void *digest_mem = NULL;
14464 
14465 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
14466 
14467 	if (tdata->plaintext.len % fragsz != 0) {
14468 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
14469 			return 1;
14470 	}	else {
14471 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
14472 			return 1;
14473 	}
14474 
14475 	/*
14476 	 * For out-op-place we need to alloc another mbuf
14477 	 */
14478 	if (oop) {
14479 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14480 		rte_pktmbuf_append(ut_params->obuf,
14481 				frag_size_oop + prepend_len);
14482 		buf_oop = ut_params->obuf;
14483 	}
14484 
14485 	/* Create AEAD session */
14486 	retval = create_aead_session(ts_params->valid_devs[0],
14487 			tdata->algo,
14488 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
14489 			tdata->key.data, tdata->key.len,
14490 			tdata->aad.len, tdata->auth_tag.len,
14491 			tdata->iv.len);
14492 	if (retval < 0)
14493 		return retval;
14494 
14495 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14496 
14497 	/* clear mbuf payload */
14498 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
14499 			rte_pktmbuf_tailroom(ut_params->ibuf));
14500 
14501 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14502 			plaintext_len);
14503 
14504 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
14505 
14506 	trn_data += plaintext_len;
14507 
14508 	buf = ut_params->ibuf;
14509 
14510 	/*
14511 	 * Loop until no more fragments
14512 	 */
14513 
14514 	while (trn_data < tdata->plaintext.len) {
14515 		++segs;
14516 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
14517 				(tdata->plaintext.len - trn_data) : fragsz;
14518 
14519 		to_trn_tbl[ecx++] = to_trn;
14520 
14521 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
14522 		buf = buf->next;
14523 
14524 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
14525 				rte_pktmbuf_tailroom(buf));
14526 
14527 		/* OOP */
14528 		if (oop && !fragsz_oop) {
14529 			buf_last_oop = buf_oop->next =
14530 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
14531 			buf_oop = buf_oop->next;
14532 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
14533 					0, rte_pktmbuf_tailroom(buf_oop));
14534 			rte_pktmbuf_append(buf_oop, to_trn);
14535 		}
14536 
14537 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
14538 				to_trn);
14539 
14540 		memcpy(plaintext, tdata->plaintext.data + trn_data,
14541 				to_trn);
14542 		trn_data += to_trn;
14543 		if (trn_data  == tdata->plaintext.len) {
14544 			if (oop) {
14545 				if (!fragsz_oop)
14546 					digest_mem = rte_pktmbuf_append(buf_oop,
14547 						tdata->auth_tag.len);
14548 			} else
14549 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
14550 					tdata->auth_tag.len);
14551 		}
14552 	}
14553 
14554 	uint64_t digest_phys = 0;
14555 
14556 	ut_params->ibuf->nb_segs = segs;
14557 
14558 	segs = 1;
14559 	if (fragsz_oop && oop) {
14560 		to_trn = 0;
14561 		ecx = 0;
14562 
14563 		if (frag_size_oop == tdata->plaintext.len) {
14564 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
14565 				tdata->auth_tag.len);
14566 
14567 			digest_phys = rte_pktmbuf_iova_offset(
14568 					ut_params->obuf,
14569 					tdata->plaintext.len + prepend_len);
14570 		}
14571 
14572 		trn_data = frag_size_oop;
14573 		while (trn_data < tdata->plaintext.len) {
14574 			++segs;
14575 			to_trn =
14576 				(tdata->plaintext.len - trn_data <
14577 						frag_size_oop) ?
14578 				(tdata->plaintext.len - trn_data) :
14579 						frag_size_oop;
14580 
14581 			to_trn_tbl[ecx++] = to_trn;
14582 
14583 			buf_last_oop = buf_oop->next =
14584 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
14585 			buf_oop = buf_oop->next;
14586 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
14587 					0, rte_pktmbuf_tailroom(buf_oop));
14588 			rte_pktmbuf_append(buf_oop, to_trn);
14589 
14590 			trn_data += to_trn;
14591 
14592 			if (trn_data  == tdata->plaintext.len) {
14593 				digest_mem = rte_pktmbuf_append(buf_oop,
14594 					tdata->auth_tag.len);
14595 			}
14596 		}
14597 
14598 		ut_params->obuf->nb_segs = segs;
14599 	}
14600 
14601 	/*
14602 	 * Place digest at the end of the last buffer
14603 	 */
14604 	if (!digest_phys)
14605 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
14606 	if (oop && buf_last_oop)
14607 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
14608 
14609 	if (!digest_mem && !oop) {
14610 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
14611 				+ tdata->auth_tag.len);
14612 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
14613 				tdata->plaintext.len);
14614 	}
14615 
14616 	/* Create AEAD operation */
14617 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
14618 			tdata, digest_mem, digest_phys);
14619 
14620 	if (retval < 0)
14621 		return retval;
14622 
14623 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
14624 
14625 	ut_params->op->sym->m_src = ut_params->ibuf;
14626 	if (oop)
14627 		ut_params->op->sym->m_dst = ut_params->obuf;
14628 
14629 	/* Process crypto operation */
14630 	if (oop == IN_PLACE &&
14631 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
14632 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
14633 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
14634 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
14635 				ut_params->op, 0, 0, 0, 0);
14636 	else
14637 		TEST_ASSERT_NOT_NULL(
14638 			process_crypto_request(ts_params->valid_devs[0],
14639 			ut_params->op), "failed to process sym crypto op");
14640 
14641 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
14642 			"crypto op processing failed");
14643 
14644 
14645 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
14646 			uint8_t *, prepend_len);
14647 	if (oop) {
14648 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
14649 				uint8_t *, prepend_len);
14650 	}
14651 
14652 	if (fragsz_oop)
14653 		fragsz = fragsz_oop;
14654 
14655 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14656 			ciphertext,
14657 			tdata->ciphertext.data,
14658 			fragsz,
14659 			"Ciphertext data not as expected");
14660 
14661 	buf = ut_params->op->sym->m_src->next;
14662 	if (oop)
14663 		buf = ut_params->op->sym->m_dst->next;
14664 
14665 	unsigned int off = fragsz;
14666 
14667 	ecx = 0;
14668 	while (buf) {
14669 		ciphertext = rte_pktmbuf_mtod(buf,
14670 				uint8_t *);
14671 
14672 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
14673 				ciphertext,
14674 				tdata->ciphertext.data + off,
14675 				to_trn_tbl[ecx],
14676 				"Ciphertext data not as expected");
14677 
14678 		off += to_trn_tbl[ecx++];
14679 		buf = buf->next;
14680 	}
14681 
14682 	auth_tag = digest_mem;
14683 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14684 			auth_tag,
14685 			tdata->auth_tag.data,
14686 			tdata->auth_tag.len,
14687 			"Generated auth tag not as expected");
14688 
14689 	return 0;
14690 }
14691 
14692 static int
14693 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
14694 {
14695 	return test_authenticated_encryption_SGL(
14696 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
14697 }
14698 
14699 static int
14700 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
14701 {
14702 	return test_authenticated_encryption_SGL(
14703 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
14704 }
14705 
14706 static int
14707 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
14708 {
14709 	return test_authenticated_encryption_SGL(
14710 			&gcm_test_case_8, OUT_OF_PLACE, 400,
14711 			gcm_test_case_8.plaintext.len);
14712 }
14713 
14714 static int
14715 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
14716 {
14717 	/* This test is not for OPENSSL PMD */
14718 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14719 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
14720 		return TEST_SKIPPED;
14721 
14722 	return test_authenticated_encryption_SGL(
14723 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
14724 }
14725 
14726 static int
14727 test_authentication_verify_fail_when_data_corrupted(
14728 		struct crypto_testsuite_params *ts_params,
14729 		struct crypto_unittest_params *ut_params,
14730 		const struct test_crypto_vector *reference)
14731 {
14732 	return test_authentication_verify_fail_when_data_corruption(
14733 			ts_params, ut_params, reference, 1);
14734 }
14735 
14736 static int
14737 test_authentication_verify_fail_when_tag_corrupted(
14738 		struct crypto_testsuite_params *ts_params,
14739 		struct crypto_unittest_params *ut_params,
14740 		const struct test_crypto_vector *reference)
14741 {
14742 	return test_authentication_verify_fail_when_data_corruption(
14743 			ts_params, ut_params, reference, 0);
14744 }
14745 
14746 static int
14747 test_authentication_verify_GMAC_fail_when_data_corrupted(
14748 		struct crypto_testsuite_params *ts_params,
14749 		struct crypto_unittest_params *ut_params,
14750 		const struct test_crypto_vector *reference)
14751 {
14752 	return test_authentication_verify_GMAC_fail_when_corruption(
14753 			ts_params, ut_params, reference, 1);
14754 }
14755 
14756 static int
14757 test_authentication_verify_GMAC_fail_when_tag_corrupted(
14758 		struct crypto_testsuite_params *ts_params,
14759 		struct crypto_unittest_params *ut_params,
14760 		const struct test_crypto_vector *reference)
14761 {
14762 	return test_authentication_verify_GMAC_fail_when_corruption(
14763 			ts_params, ut_params, reference, 0);
14764 }
14765 
14766 static int
14767 test_authenticated_decryption_fail_when_data_corrupted(
14768 		struct crypto_testsuite_params *ts_params,
14769 		struct crypto_unittest_params *ut_params,
14770 		const struct test_crypto_vector *reference)
14771 {
14772 	return test_authenticated_decryption_fail_when_corruption(
14773 			ts_params, ut_params, reference, 1);
14774 }
14775 
14776 static int
14777 test_authenticated_decryption_fail_when_tag_corrupted(
14778 		struct crypto_testsuite_params *ts_params,
14779 		struct crypto_unittest_params *ut_params,
14780 		const struct test_crypto_vector *reference)
14781 {
14782 	return test_authenticated_decryption_fail_when_corruption(
14783 			ts_params, ut_params, reference, 0);
14784 }
14785 
14786 static int
14787 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
14788 {
14789 	return test_authentication_verify_fail_when_data_corrupted(
14790 			&testsuite_params, &unittest_params,
14791 			&hmac_sha1_test_crypto_vector);
14792 }
14793 
14794 static int
14795 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
14796 {
14797 	return test_authentication_verify_fail_when_tag_corrupted(
14798 			&testsuite_params, &unittest_params,
14799 			&hmac_sha1_test_crypto_vector);
14800 }
14801 
14802 static int
14803 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
14804 {
14805 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
14806 			&testsuite_params, &unittest_params,
14807 			&aes128_gmac_test_vector);
14808 }
14809 
14810 static int
14811 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
14812 {
14813 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
14814 			&testsuite_params, &unittest_params,
14815 			&aes128_gmac_test_vector);
14816 }
14817 
14818 static int
14819 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
14820 {
14821 	return test_authenticated_decryption_fail_when_data_corrupted(
14822 			&testsuite_params,
14823 			&unittest_params,
14824 			&aes128cbc_hmac_sha1_test_vector);
14825 }
14826 
14827 static int
14828 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14829 {
14830 	return test_authenticated_decryption_fail_when_tag_corrupted(
14831 			&testsuite_params,
14832 			&unittest_params,
14833 			&aes128cbc_hmac_sha1_test_vector);
14834 }
14835 
14836 static int
14837 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14838 {
14839 	return test_authenticated_encrypt_with_esn(
14840 			&testsuite_params,
14841 			&unittest_params,
14842 			&aes128cbc_hmac_sha1_aad_test_vector);
14843 }
14844 
14845 static int
14846 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14847 {
14848 	return test_authenticated_decrypt_with_esn(
14849 			&testsuite_params,
14850 			&unittest_params,
14851 			&aes128cbc_hmac_sha1_aad_test_vector);
14852 }
14853 
14854 static int
14855 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14856 {
14857 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14858 }
14859 
14860 static int
14861 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14862 {
14863 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14864 }
14865 
14866 static int
14867 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
14868 {
14869 	return test_authenticated_encryption_SGL(
14870 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
14871 		chacha20_poly1305_case_2.plaintext.len);
14872 }
14873 
14874 #ifdef RTE_CRYPTO_SCHEDULER
14875 
14876 /* global AESNI worker IDs for the scheduler test */
14877 uint8_t aesni_ids[2];
14878 
14879 static int
14880 scheduler_testsuite_setup(void)
14881 {
14882 	uint32_t i = 0;
14883 	int32_t nb_devs, ret;
14884 	char vdev_args[VDEV_ARGS_SIZE] = {""};
14885 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14886 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
14887 	uint16_t worker_core_count = 0;
14888 	uint16_t socket_id = 0;
14889 
14890 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14891 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14892 
14893 		/* Identify the Worker Cores
14894 		 * Use 2 worker cores for the device args
14895 		 */
14896 		RTE_LCORE_FOREACH_WORKER(i) {
14897 			if (worker_core_count > 1)
14898 				break;
14899 			snprintf(vdev_args, sizeof(vdev_args),
14900 					"%s%d", temp_str, i);
14901 			strcpy(temp_str, vdev_args);
14902 			strlcat(temp_str, ";", sizeof(temp_str));
14903 			worker_core_count++;
14904 			socket_id = rte_lcore_to_socket_id(i);
14905 		}
14906 		if (worker_core_count != 2) {
14907 			RTE_LOG(ERR, USER1,
14908 				"Cryptodev scheduler test require at least "
14909 				"two worker cores to run. "
14910 				"Please use the correct coremask.\n");
14911 			return TEST_FAILED;
14912 		}
14913 		strcpy(temp_str, vdev_args);
14914 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14915 				temp_str, socket_id);
14916 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14917 		nb_devs = rte_cryptodev_device_count_by_driver(
14918 				rte_cryptodev_driver_id_get(
14919 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14920 		if (nb_devs < 1) {
14921 			ret = rte_vdev_init(
14922 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14923 					vdev_args);
14924 			TEST_ASSERT(ret == 0,
14925 				"Failed to create instance %u of pmd : %s",
14926 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14927 		}
14928 	}
14929 	return testsuite_setup();
14930 }
14931 
14932 static int
14933 test_scheduler_attach_worker_op(void)
14934 {
14935 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14936 	uint8_t sched_id = ts_params->valid_devs[0];
14937 	uint32_t i, nb_devs_attached = 0;
14938 	int ret;
14939 	char vdev_name[32];
14940 	unsigned int count = rte_cryptodev_count();
14941 
14942 	/* create 2 AESNI_MB vdevs on top of existing devices */
14943 	for (i = count; i < count + 2; i++) {
14944 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14945 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14946 				i);
14947 		ret = rte_vdev_init(vdev_name, NULL);
14948 
14949 		TEST_ASSERT(ret == 0,
14950 			"Failed to create instance %u of"
14951 			" pmd : %s",
14952 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14953 
14954 		if (ret < 0) {
14955 			RTE_LOG(ERR, USER1,
14956 				"Failed to create 2 AESNI MB PMDs.\n");
14957 			return TEST_SKIPPED;
14958 		}
14959 	}
14960 
14961 	/* attach 2 AESNI_MB cdevs */
14962 	for (i = count; i < count + 2; i++) {
14963 		struct rte_cryptodev_info info;
14964 		unsigned int session_size;
14965 
14966 		rte_cryptodev_info_get(i, &info);
14967 		if (info.driver_id != rte_cryptodev_driver_id_get(
14968 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14969 			continue;
14970 
14971 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14972 		/*
14973 		 * Create the session mempool again, since now there are new devices
14974 		 * to use the mempool.
14975 		 */
14976 		if (ts_params->session_mpool) {
14977 			rte_mempool_free(ts_params->session_mpool);
14978 			ts_params->session_mpool = NULL;
14979 		}
14980 		if (ts_params->session_priv_mpool) {
14981 			rte_mempool_free(ts_params->session_priv_mpool);
14982 			ts_params->session_priv_mpool = NULL;
14983 		}
14984 
14985 		if (info.sym.max_nb_sessions != 0 &&
14986 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14987 			RTE_LOG(ERR, USER1,
14988 					"Device does not support "
14989 					"at least %u sessions\n",
14990 					MAX_NB_SESSIONS);
14991 			return TEST_FAILED;
14992 		}
14993 		/*
14994 		 * Create mempool with maximum number of sessions,
14995 		 * to include the session headers
14996 		 */
14997 		if (ts_params->session_mpool == NULL) {
14998 			ts_params->session_mpool =
14999 				rte_cryptodev_sym_session_pool_create(
15000 						"test_sess_mp",
15001 						MAX_NB_SESSIONS, session_size,
15002 						0, 0, SOCKET_ID_ANY);
15003 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
15004 					"session mempool allocation failed");
15005 		}
15006 
15007 		/*
15008 		 * Create mempool with maximum number of sessions,
15009 		 * to include device specific session private data
15010 		 */
15011 		if (ts_params->session_priv_mpool == NULL) {
15012 			ts_params->session_priv_mpool = rte_mempool_create(
15013 					"test_sess_mp_priv",
15014 					MAX_NB_SESSIONS,
15015 					session_size,
15016 					0, 0, NULL, NULL, NULL,
15017 					NULL, SOCKET_ID_ANY,
15018 					0);
15019 
15020 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
15021 					"session mempool allocation failed");
15022 		}
15023 
15024 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
15025 
15026 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
15027 				(uint8_t)i);
15028 
15029 		TEST_ASSERT(ret == 0,
15030 			"Failed to attach device %u of pmd : %s", i,
15031 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15032 
15033 		aesni_ids[nb_devs_attached] = (uint8_t)i;
15034 
15035 		nb_devs_attached++;
15036 	}
15037 
15038 	return 0;
15039 }
15040 
15041 static int
15042 test_scheduler_detach_worker_op(void)
15043 {
15044 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15045 	uint8_t sched_id = ts_params->valid_devs[0];
15046 	uint32_t i;
15047 	int ret;
15048 
15049 	for (i = 0; i < 2; i++) {
15050 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
15051 				aesni_ids[i]);
15052 		TEST_ASSERT(ret == 0,
15053 			"Failed to detach device %u", aesni_ids[i]);
15054 	}
15055 
15056 	return 0;
15057 }
15058 
15059 static int
15060 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
15061 {
15062 	struct crypto_testsuite_params *ts_params = &testsuite_params;
15063 	uint8_t sched_id = ts_params->valid_devs[0];
15064 	/* set mode */
15065 	return rte_cryptodev_scheduler_mode_set(sched_id,
15066 		scheduler_mode);
15067 }
15068 
15069 static int
15070 test_scheduler_mode_roundrobin_op(void)
15071 {
15072 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
15073 			0, "Failed to set roundrobin mode");
15074 	return 0;
15075 
15076 }
15077 
15078 static int
15079 test_scheduler_mode_multicore_op(void)
15080 {
15081 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
15082 			0, "Failed to set multicore mode");
15083 
15084 	return 0;
15085 }
15086 
15087 static int
15088 test_scheduler_mode_failover_op(void)
15089 {
15090 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
15091 			0, "Failed to set failover mode");
15092 
15093 	return 0;
15094 }
15095 
15096 static int
15097 test_scheduler_mode_pkt_size_distr_op(void)
15098 {
15099 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
15100 			0, "Failed to set pktsize mode");
15101 
15102 	return 0;
15103 }
15104 
15105 static int
15106 scheduler_multicore_testsuite_setup(void)
15107 {
15108 	if (test_scheduler_attach_worker_op() < 0)
15109 		return TEST_SKIPPED;
15110 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
15111 		return TEST_SKIPPED;
15112 	return 0;
15113 }
15114 
15115 static int
15116 scheduler_roundrobin_testsuite_setup(void)
15117 {
15118 	if (test_scheduler_attach_worker_op() < 0)
15119 		return TEST_SKIPPED;
15120 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
15121 		return TEST_SKIPPED;
15122 	return 0;
15123 }
15124 
15125 static int
15126 scheduler_failover_testsuite_setup(void)
15127 {
15128 	if (test_scheduler_attach_worker_op() < 0)
15129 		return TEST_SKIPPED;
15130 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
15131 		return TEST_SKIPPED;
15132 	return 0;
15133 }
15134 
15135 static int
15136 scheduler_pkt_size_distr_testsuite_setup(void)
15137 {
15138 	if (test_scheduler_attach_worker_op() < 0)
15139 		return TEST_SKIPPED;
15140 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
15141 		return TEST_SKIPPED;
15142 	return 0;
15143 }
15144 
15145 static void
15146 scheduler_mode_testsuite_teardown(void)
15147 {
15148 	test_scheduler_detach_worker_op();
15149 }
15150 
15151 #endif /* RTE_CRYPTO_SCHEDULER */
15152 
15153 static struct unit_test_suite end_testsuite = {
15154 	.suite_name = NULL,
15155 	.setup = NULL,
15156 	.teardown = NULL,
15157 	.unit_test_suites = NULL
15158 };
15159 
15160 #ifdef RTE_LIB_SECURITY
15161 static struct unit_test_suite ipsec_proto_testsuite  = {
15162 	.suite_name = "IPsec Proto Unit Test Suite",
15163 	.setup = ipsec_proto_testsuite_setup,
15164 	.unit_test_cases = {
15165 		TEST_CASE_NAMED_WITH_DATA(
15166 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
15167 			ut_setup_security, ut_teardown,
15168 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
15169 		TEST_CASE_NAMED_WITH_DATA(
15170 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
15171 			ut_setup_security, ut_teardown,
15172 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
15173 		TEST_CASE_NAMED_WITH_DATA(
15174 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
15175 			ut_setup_security, ut_teardown,
15176 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
15177 		TEST_CASE_NAMED_WITH_DATA(
15178 			"Outbound known vector (ESP tunnel mode IPv4 AES-CCM 256)",
15179 			ut_setup_security, ut_teardown,
15180 			test_ipsec_proto_known_vec, &pkt_aes_256_ccm),
15181 		TEST_CASE_NAMED_WITH_DATA(
15182 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15183 			ut_setup_security, ut_teardown,
15184 			test_ipsec_proto_known_vec,
15185 			&pkt_aes_128_cbc_hmac_sha256),
15186 		TEST_CASE_NAMED_WITH_DATA(
15187 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
15188 			ut_setup_security, ut_teardown,
15189 			test_ipsec_proto_known_vec,
15190 			&pkt_aes_128_cbc_hmac_sha384),
15191 		TEST_CASE_NAMED_WITH_DATA(
15192 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
15193 			ut_setup_security, ut_teardown,
15194 			test_ipsec_proto_known_vec,
15195 			&pkt_aes_128_cbc_hmac_sha512),
15196 		TEST_CASE_NAMED_WITH_DATA(
15197 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
15198 			ut_setup_security, ut_teardown,
15199 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6),
15200 		TEST_CASE_NAMED_WITH_DATA(
15201 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15202 			ut_setup_security, ut_teardown,
15203 			test_ipsec_proto_known_vec,
15204 			&pkt_aes_128_cbc_hmac_sha256_v6),
15205 		TEST_CASE_NAMED_WITH_DATA(
15206 			"Outbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
15207 			ut_setup_security, ut_teardown,
15208 			test_ipsec_proto_known_vec,
15209 			&pkt_null_aes_xcbc),
15210 		TEST_CASE_NAMED_WITH_DATA(
15211 			"Outbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
15212 			ut_setup_security, ut_teardown,
15213 			test_ipsec_proto_known_vec,
15214 			&pkt_ah_tunnel_sha256),
15215 		TEST_CASE_NAMED_WITH_DATA(
15216 			"Outbound known vector (AH transport mode IPv4 HMAC-SHA256)",
15217 			ut_setup_security, ut_teardown,
15218 			test_ipsec_proto_known_vec,
15219 			&pkt_ah_transport_sha256),
15220 		TEST_CASE_NAMED_WITH_DATA(
15221 			"Outbound known vector (AH transport mode IPv4 AES-GMAC 128)",
15222 			ut_setup_security, ut_teardown,
15223 			test_ipsec_proto_known_vec,
15224 			&pkt_ah_ipv4_aes_gmac_128),
15225 		TEST_CASE_NAMED_WITH_DATA(
15226 			"Outbound fragmented packet",
15227 			ut_setup_security, ut_teardown,
15228 			test_ipsec_proto_known_vec_fragmented,
15229 			&pkt_aes_128_gcm_frag),
15230 		TEST_CASE_NAMED_WITH_DATA(
15231 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
15232 			ut_setup_security, ut_teardown,
15233 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
15234 		TEST_CASE_NAMED_WITH_DATA(
15235 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
15236 			ut_setup_security, ut_teardown,
15237 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
15238 		TEST_CASE_NAMED_WITH_DATA(
15239 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
15240 			ut_setup_security, ut_teardown,
15241 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
15242 		TEST_CASE_NAMED_WITH_DATA(
15243 			"Inbound known vector (ESP tunnel mode IPv4 AES-CCM 256)",
15244 			ut_setup_security, ut_teardown,
15245 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_ccm),
15246 		TEST_CASE_NAMED_WITH_DATA(
15247 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
15248 			ut_setup_security, ut_teardown,
15249 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null),
15250 		TEST_CASE_NAMED_WITH_DATA(
15251 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15252 			ut_setup_security, ut_teardown,
15253 			test_ipsec_proto_known_vec_inb,
15254 			&pkt_aes_128_cbc_hmac_sha256),
15255 		TEST_CASE_NAMED_WITH_DATA(
15256 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
15257 			ut_setup_security, ut_teardown,
15258 			test_ipsec_proto_known_vec_inb,
15259 			&pkt_aes_128_cbc_hmac_sha384),
15260 		TEST_CASE_NAMED_WITH_DATA(
15261 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
15262 			ut_setup_security, ut_teardown,
15263 			test_ipsec_proto_known_vec_inb,
15264 			&pkt_aes_128_cbc_hmac_sha512),
15265 		TEST_CASE_NAMED_WITH_DATA(
15266 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
15267 			ut_setup_security, ut_teardown,
15268 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
15269 		TEST_CASE_NAMED_WITH_DATA(
15270 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
15271 			ut_setup_security, ut_teardown,
15272 			test_ipsec_proto_known_vec_inb,
15273 			&pkt_aes_128_cbc_hmac_sha256_v6),
15274 		TEST_CASE_NAMED_WITH_DATA(
15275 			"Inbound known vector (ESP tunnel mode IPv4 NULL AES-XCBC-MAC [12B ICV])",
15276 			ut_setup_security, ut_teardown,
15277 			test_ipsec_proto_known_vec_inb,
15278 			&pkt_null_aes_xcbc),
15279 		TEST_CASE_NAMED_WITH_DATA(
15280 			"Inbound known vector (AH tunnel mode IPv4 HMAC-SHA256)",
15281 			ut_setup_security, ut_teardown,
15282 			test_ipsec_proto_known_vec_inb,
15283 			&pkt_ah_tunnel_sha256),
15284 		TEST_CASE_NAMED_WITH_DATA(
15285 			"Inbound known vector (AH transport mode IPv4 HMAC-SHA256)",
15286 			ut_setup_security, ut_teardown,
15287 			test_ipsec_proto_known_vec_inb,
15288 			&pkt_ah_transport_sha256),
15289 		TEST_CASE_NAMED_WITH_DATA(
15290 			"Inbound known vector (AH transport mode IPv4 AES-GMAC 128)",
15291 			ut_setup_security, ut_teardown,
15292 			test_ipsec_proto_known_vec_inb,
15293 			&pkt_ah_ipv4_aes_gmac_128),
15294 		TEST_CASE_NAMED_ST(
15295 			"Combined test alg list",
15296 			ut_setup_security, ut_teardown,
15297 			test_ipsec_proto_display_list),
15298 		TEST_CASE_NAMED_ST(
15299 			"Combined test alg list (AH)",
15300 			ut_setup_security, ut_teardown,
15301 			test_ipsec_proto_ah_tunnel_ipv4),
15302 		TEST_CASE_NAMED_ST(
15303 			"IV generation",
15304 			ut_setup_security, ut_teardown,
15305 			test_ipsec_proto_iv_gen),
15306 		TEST_CASE_NAMED_ST(
15307 			"UDP encapsulation",
15308 			ut_setup_security, ut_teardown,
15309 			test_ipsec_proto_udp_encap),
15310 		TEST_CASE_NAMED_ST(
15311 			"UDP encapsulation ports verification test",
15312 			ut_setup_security, ut_teardown,
15313 			test_ipsec_proto_udp_ports_verify),
15314 		TEST_CASE_NAMED_ST(
15315 			"SA expiry packets soft",
15316 			ut_setup_security, ut_teardown,
15317 			test_ipsec_proto_sa_exp_pkts_soft),
15318 		TEST_CASE_NAMED_ST(
15319 			"SA expiry packets hard",
15320 			ut_setup_security, ut_teardown,
15321 			test_ipsec_proto_sa_exp_pkts_hard),
15322 		TEST_CASE_NAMED_ST(
15323 			"Negative test: ICV corruption",
15324 			ut_setup_security, ut_teardown,
15325 			test_ipsec_proto_err_icv_corrupt),
15326 		TEST_CASE_NAMED_ST(
15327 			"Tunnel dst addr verification",
15328 			ut_setup_security, ut_teardown,
15329 			test_ipsec_proto_tunnel_dst_addr_verify),
15330 		TEST_CASE_NAMED_ST(
15331 			"Tunnel src and dst addr verification",
15332 			ut_setup_security, ut_teardown,
15333 			test_ipsec_proto_tunnel_src_dst_addr_verify),
15334 		TEST_CASE_NAMED_ST(
15335 			"Inner IP checksum",
15336 			ut_setup_security, ut_teardown,
15337 			test_ipsec_proto_inner_ip_csum),
15338 		TEST_CASE_NAMED_ST(
15339 			"Inner L4 checksum",
15340 			ut_setup_security, ut_teardown,
15341 			test_ipsec_proto_inner_l4_csum),
15342 		TEST_CASE_NAMED_ST(
15343 			"Tunnel IPv4 in IPv4",
15344 			ut_setup_security, ut_teardown,
15345 			test_ipsec_proto_tunnel_v4_in_v4),
15346 		TEST_CASE_NAMED_ST(
15347 			"Tunnel IPv6 in IPv6",
15348 			ut_setup_security, ut_teardown,
15349 			test_ipsec_proto_tunnel_v6_in_v6),
15350 		TEST_CASE_NAMED_ST(
15351 			"Tunnel IPv4 in IPv6",
15352 			ut_setup_security, ut_teardown,
15353 			test_ipsec_proto_tunnel_v4_in_v6),
15354 		TEST_CASE_NAMED_ST(
15355 			"Tunnel IPv6 in IPv4",
15356 			ut_setup_security, ut_teardown,
15357 			test_ipsec_proto_tunnel_v6_in_v4),
15358 		TEST_CASE_NAMED_ST(
15359 			"Transport IPv4",
15360 			ut_setup_security, ut_teardown,
15361 			test_ipsec_proto_transport_v4),
15362 		TEST_CASE_NAMED_ST(
15363 			"AH transport IPv4",
15364 			ut_setup_security, ut_teardown,
15365 			test_ipsec_proto_ah_transport_ipv4),
15366 		TEST_CASE_NAMED_ST(
15367 			"Transport l4 checksum",
15368 			ut_setup_security, ut_teardown,
15369 			test_ipsec_proto_transport_l4_csum),
15370 		TEST_CASE_NAMED_ST(
15371 			"Statistics: success",
15372 			ut_setup_security, ut_teardown,
15373 			test_ipsec_proto_stats),
15374 		TEST_CASE_NAMED_ST(
15375 			"Fragmented packet",
15376 			ut_setup_security, ut_teardown,
15377 			test_ipsec_proto_pkt_fragment),
15378 		TEST_CASE_NAMED_ST(
15379 			"Tunnel header copy DF (inner 0)",
15380 			ut_setup_security, ut_teardown,
15381 			test_ipsec_proto_copy_df_inner_0),
15382 		TEST_CASE_NAMED_ST(
15383 			"Tunnel header copy DF (inner 1)",
15384 			ut_setup_security, ut_teardown,
15385 			test_ipsec_proto_copy_df_inner_1),
15386 		TEST_CASE_NAMED_ST(
15387 			"Tunnel header set DF 0 (inner 1)",
15388 			ut_setup_security, ut_teardown,
15389 			test_ipsec_proto_set_df_0_inner_1),
15390 		TEST_CASE_NAMED_ST(
15391 			"Tunnel header set DF 1 (inner 0)",
15392 			ut_setup_security, ut_teardown,
15393 			test_ipsec_proto_set_df_1_inner_0),
15394 		TEST_CASE_NAMED_ST(
15395 			"Tunnel header IPv4 copy DSCP (inner 0)",
15396 			ut_setup_security, ut_teardown,
15397 			test_ipsec_proto_ipv4_copy_dscp_inner_0),
15398 		TEST_CASE_NAMED_ST(
15399 			"Tunnel header IPv4 copy DSCP (inner 1)",
15400 			ut_setup_security, ut_teardown,
15401 			test_ipsec_proto_ipv4_copy_dscp_inner_1),
15402 		TEST_CASE_NAMED_ST(
15403 			"Tunnel header IPv4 set DSCP 0 (inner 1)",
15404 			ut_setup_security, ut_teardown,
15405 			test_ipsec_proto_ipv4_set_dscp_0_inner_1),
15406 		TEST_CASE_NAMED_ST(
15407 			"Tunnel header IPv4 set DSCP 1 (inner 0)",
15408 			ut_setup_security, ut_teardown,
15409 			test_ipsec_proto_ipv4_set_dscp_1_inner_0),
15410 		TEST_CASE_NAMED_ST(
15411 			"Tunnel header IPv6 copy DSCP (inner 0)",
15412 			ut_setup_security, ut_teardown,
15413 			test_ipsec_proto_ipv6_copy_dscp_inner_0),
15414 		TEST_CASE_NAMED_ST(
15415 			"Tunnel header IPv6 copy DSCP (inner 1)",
15416 			ut_setup_security, ut_teardown,
15417 			test_ipsec_proto_ipv6_copy_dscp_inner_1),
15418 		TEST_CASE_NAMED_ST(
15419 			"Tunnel header IPv6 set DSCP 0 (inner 1)",
15420 			ut_setup_security, ut_teardown,
15421 			test_ipsec_proto_ipv6_set_dscp_0_inner_1),
15422 		TEST_CASE_NAMED_ST(
15423 			"Tunnel header IPv6 set DSCP 1 (inner 0)",
15424 			ut_setup_security, ut_teardown,
15425 			test_ipsec_proto_ipv6_set_dscp_1_inner_0),
15426 		TEST_CASE_NAMED_WITH_DATA(
15427 			"Antireplay with window size 1024",
15428 			ut_setup_security, ut_teardown,
15429 			test_ipsec_proto_pkt_antireplay1024, &pkt_aes_128_gcm),
15430 		TEST_CASE_NAMED_WITH_DATA(
15431 			"Antireplay with window size 2048",
15432 			ut_setup_security, ut_teardown,
15433 			test_ipsec_proto_pkt_antireplay2048, &pkt_aes_128_gcm),
15434 		TEST_CASE_NAMED_WITH_DATA(
15435 			"Antireplay with window size 4096",
15436 			ut_setup_security, ut_teardown,
15437 			test_ipsec_proto_pkt_antireplay4096, &pkt_aes_128_gcm),
15438 		TEST_CASE_NAMED_WITH_DATA(
15439 			"ESN and Antireplay with window size 1024",
15440 			ut_setup_security, ut_teardown,
15441 			test_ipsec_proto_pkt_esn_antireplay1024,
15442 			&pkt_aes_128_gcm),
15443 		TEST_CASE_NAMED_WITH_DATA(
15444 			"ESN and Antireplay with window size 2048",
15445 			ut_setup_security, ut_teardown,
15446 			test_ipsec_proto_pkt_esn_antireplay2048,
15447 			&pkt_aes_128_gcm),
15448 		TEST_CASE_NAMED_WITH_DATA(
15449 			"ESN and Antireplay with window size 4096",
15450 			ut_setup_security, ut_teardown,
15451 			test_ipsec_proto_pkt_esn_antireplay4096,
15452 			&pkt_aes_128_gcm),
15453 		TEST_CASE_NAMED_ST(
15454 			"Tunnel header IPv4 decrement inner TTL",
15455 			ut_setup_security, ut_teardown,
15456 			test_ipsec_proto_ipv4_ttl_decrement),
15457 		TEST_CASE_NAMED_ST(
15458 			"Tunnel header IPv6 decrement inner hop limit",
15459 			ut_setup_security, ut_teardown,
15460 			test_ipsec_proto_ipv6_hop_limit_decrement),
15461 		TEST_CASES_END() /**< NULL terminate unit test array */
15462 	}
15463 };
15464 
15465 static struct unit_test_suite pdcp_proto_testsuite  = {
15466 	.suite_name = "PDCP Proto Unit Test Suite",
15467 	.setup = pdcp_proto_testsuite_setup,
15468 	.unit_test_cases = {
15469 		TEST_CASE_ST(ut_setup_security, ut_teardown,
15470 			test_PDCP_PROTO_all),
15471 		TEST_CASES_END() /**< NULL terminate unit test array */
15472 	}
15473 };
15474 
15475 #define ADD_UPLINK_TESTCASE(data)						\
15476 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security,	\
15477 	ut_teardown, test_docsis_proto_uplink, (const void *) &data),		\
15478 
15479 #define ADD_DOWNLINK_TESTCASE(data)						\
15480 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security,	\
15481 	ut_teardown, test_docsis_proto_downlink, (const void *) &data),		\
15482 
15483 static struct unit_test_suite docsis_proto_testsuite  = {
15484 	.suite_name = "DOCSIS Proto Unit Test Suite",
15485 	.setup = docsis_proto_testsuite_setup,
15486 	.unit_test_cases = {
15487 		/* Uplink */
15488 		ADD_UPLINK_TESTCASE(docsis_test_case_1)
15489 		ADD_UPLINK_TESTCASE(docsis_test_case_2)
15490 		ADD_UPLINK_TESTCASE(docsis_test_case_3)
15491 		ADD_UPLINK_TESTCASE(docsis_test_case_4)
15492 		ADD_UPLINK_TESTCASE(docsis_test_case_5)
15493 		ADD_UPLINK_TESTCASE(docsis_test_case_6)
15494 		ADD_UPLINK_TESTCASE(docsis_test_case_7)
15495 		ADD_UPLINK_TESTCASE(docsis_test_case_8)
15496 		ADD_UPLINK_TESTCASE(docsis_test_case_9)
15497 		ADD_UPLINK_TESTCASE(docsis_test_case_10)
15498 		ADD_UPLINK_TESTCASE(docsis_test_case_11)
15499 		ADD_UPLINK_TESTCASE(docsis_test_case_12)
15500 		ADD_UPLINK_TESTCASE(docsis_test_case_13)
15501 		ADD_UPLINK_TESTCASE(docsis_test_case_14)
15502 		ADD_UPLINK_TESTCASE(docsis_test_case_15)
15503 		ADD_UPLINK_TESTCASE(docsis_test_case_16)
15504 		ADD_UPLINK_TESTCASE(docsis_test_case_17)
15505 		ADD_UPLINK_TESTCASE(docsis_test_case_18)
15506 		ADD_UPLINK_TESTCASE(docsis_test_case_19)
15507 		ADD_UPLINK_TESTCASE(docsis_test_case_20)
15508 		ADD_UPLINK_TESTCASE(docsis_test_case_21)
15509 		ADD_UPLINK_TESTCASE(docsis_test_case_22)
15510 		ADD_UPLINK_TESTCASE(docsis_test_case_23)
15511 		ADD_UPLINK_TESTCASE(docsis_test_case_24)
15512 		ADD_UPLINK_TESTCASE(docsis_test_case_25)
15513 		ADD_UPLINK_TESTCASE(docsis_test_case_26)
15514 		/* Downlink */
15515 		ADD_DOWNLINK_TESTCASE(docsis_test_case_1)
15516 		ADD_DOWNLINK_TESTCASE(docsis_test_case_2)
15517 		ADD_DOWNLINK_TESTCASE(docsis_test_case_3)
15518 		ADD_DOWNLINK_TESTCASE(docsis_test_case_4)
15519 		ADD_DOWNLINK_TESTCASE(docsis_test_case_5)
15520 		ADD_DOWNLINK_TESTCASE(docsis_test_case_6)
15521 		ADD_DOWNLINK_TESTCASE(docsis_test_case_7)
15522 		ADD_DOWNLINK_TESTCASE(docsis_test_case_8)
15523 		ADD_DOWNLINK_TESTCASE(docsis_test_case_9)
15524 		ADD_DOWNLINK_TESTCASE(docsis_test_case_10)
15525 		ADD_DOWNLINK_TESTCASE(docsis_test_case_11)
15526 		ADD_DOWNLINK_TESTCASE(docsis_test_case_12)
15527 		ADD_DOWNLINK_TESTCASE(docsis_test_case_13)
15528 		ADD_DOWNLINK_TESTCASE(docsis_test_case_14)
15529 		ADD_DOWNLINK_TESTCASE(docsis_test_case_15)
15530 		ADD_DOWNLINK_TESTCASE(docsis_test_case_16)
15531 		ADD_DOWNLINK_TESTCASE(docsis_test_case_17)
15532 		ADD_DOWNLINK_TESTCASE(docsis_test_case_18)
15533 		ADD_DOWNLINK_TESTCASE(docsis_test_case_19)
15534 		ADD_DOWNLINK_TESTCASE(docsis_test_case_20)
15535 		ADD_DOWNLINK_TESTCASE(docsis_test_case_21)
15536 		ADD_DOWNLINK_TESTCASE(docsis_test_case_22)
15537 		ADD_DOWNLINK_TESTCASE(docsis_test_case_23)
15538 		ADD_DOWNLINK_TESTCASE(docsis_test_case_24)
15539 		ADD_DOWNLINK_TESTCASE(docsis_test_case_25)
15540 		ADD_DOWNLINK_TESTCASE(docsis_test_case_26)
15541 		TEST_CASES_END() /**< NULL terminate unit test array */
15542 	}
15543 };
15544 #endif
15545 
15546 static struct unit_test_suite cryptodev_gen_testsuite  = {
15547 	.suite_name = "Crypto General Unit Test Suite",
15548 	.setup = crypto_gen_testsuite_setup,
15549 	.unit_test_cases = {
15550 		TEST_CASE_ST(ut_setup, ut_teardown,
15551 				test_device_configure_invalid_dev_id),
15552 		TEST_CASE_ST(ut_setup, ut_teardown,
15553 				test_queue_pair_descriptor_setup),
15554 		TEST_CASE_ST(ut_setup, ut_teardown,
15555 				test_device_configure_invalid_queue_pair_ids),
15556 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
15557 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
15558 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
15559 		TEST_CASES_END() /**< NULL terminate unit test array */
15560 	}
15561 };
15562 
15563 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
15564 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
15565 	.setup = negative_hmac_sha1_testsuite_setup,
15566 	.unit_test_cases = {
15567 		/** Negative tests */
15568 		TEST_CASE_ST(ut_setup, ut_teardown,
15569 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
15570 		TEST_CASE_ST(ut_setup, ut_teardown,
15571 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
15572 		TEST_CASE_ST(ut_setup, ut_teardown,
15573 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
15574 		TEST_CASE_ST(ut_setup, ut_teardown,
15575 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
15576 
15577 		TEST_CASES_END() /**< NULL terminate unit test array */
15578 	}
15579 };
15580 
15581 static struct unit_test_suite cryptodev_multi_session_testsuite = {
15582 	.suite_name = "Multi Session Unit Test Suite",
15583 	.setup = multi_session_testsuite_setup,
15584 	.unit_test_cases = {
15585 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
15586 		TEST_CASE_ST(ut_setup, ut_teardown,
15587 				test_multi_session_random_usage),
15588 
15589 		TEST_CASES_END() /**< NULL terminate unit test array */
15590 	}
15591 };
15592 
15593 static struct unit_test_suite cryptodev_null_testsuite  = {
15594 	.suite_name = "NULL Test Suite",
15595 	.setup = null_testsuite_setup,
15596 	.unit_test_cases = {
15597 		TEST_CASE_ST(ut_setup, ut_teardown,
15598 			test_null_invalid_operation),
15599 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
15600 		TEST_CASES_END()
15601 	}
15602 };
15603 
15604 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
15605 	.suite_name = "AES CCM Authenticated Test Suite",
15606 	.setup = aes_ccm_auth_testsuite_setup,
15607 	.unit_test_cases = {
15608 		/** AES CCM Authenticated Encryption 128 bits key*/
15609 		TEST_CASE_ST(ut_setup, ut_teardown,
15610 			test_AES_CCM_authenticated_encryption_test_case_128_1),
15611 		TEST_CASE_ST(ut_setup, ut_teardown,
15612 			test_AES_CCM_authenticated_encryption_test_case_128_2),
15613 		TEST_CASE_ST(ut_setup, ut_teardown,
15614 			test_AES_CCM_authenticated_encryption_test_case_128_3),
15615 
15616 		/** AES CCM Authenticated Decryption 128 bits key*/
15617 		TEST_CASE_ST(ut_setup, ut_teardown,
15618 			test_AES_CCM_authenticated_decryption_test_case_128_1),
15619 		TEST_CASE_ST(ut_setup, ut_teardown,
15620 			test_AES_CCM_authenticated_decryption_test_case_128_2),
15621 		TEST_CASE_ST(ut_setup, ut_teardown,
15622 			test_AES_CCM_authenticated_decryption_test_case_128_3),
15623 
15624 		/** AES CCM Authenticated Encryption 192 bits key */
15625 		TEST_CASE_ST(ut_setup, ut_teardown,
15626 			test_AES_CCM_authenticated_encryption_test_case_192_1),
15627 		TEST_CASE_ST(ut_setup, ut_teardown,
15628 			test_AES_CCM_authenticated_encryption_test_case_192_2),
15629 		TEST_CASE_ST(ut_setup, ut_teardown,
15630 			test_AES_CCM_authenticated_encryption_test_case_192_3),
15631 
15632 		/** AES CCM Authenticated Decryption 192 bits key*/
15633 		TEST_CASE_ST(ut_setup, ut_teardown,
15634 			test_AES_CCM_authenticated_decryption_test_case_192_1),
15635 		TEST_CASE_ST(ut_setup, ut_teardown,
15636 			test_AES_CCM_authenticated_decryption_test_case_192_2),
15637 		TEST_CASE_ST(ut_setup, ut_teardown,
15638 			test_AES_CCM_authenticated_decryption_test_case_192_3),
15639 
15640 		/** AES CCM Authenticated Encryption 256 bits key */
15641 		TEST_CASE_ST(ut_setup, ut_teardown,
15642 			test_AES_CCM_authenticated_encryption_test_case_256_1),
15643 		TEST_CASE_ST(ut_setup, ut_teardown,
15644 			test_AES_CCM_authenticated_encryption_test_case_256_2),
15645 		TEST_CASE_ST(ut_setup, ut_teardown,
15646 			test_AES_CCM_authenticated_encryption_test_case_256_3),
15647 
15648 		/** AES CCM Authenticated Decryption 256 bits key*/
15649 		TEST_CASE_ST(ut_setup, ut_teardown,
15650 			test_AES_CCM_authenticated_decryption_test_case_256_1),
15651 		TEST_CASE_ST(ut_setup, ut_teardown,
15652 			test_AES_CCM_authenticated_decryption_test_case_256_2),
15653 		TEST_CASE_ST(ut_setup, ut_teardown,
15654 			test_AES_CCM_authenticated_decryption_test_case_256_3),
15655 		TEST_CASES_END()
15656 	}
15657 };
15658 
15659 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
15660 	.suite_name = "AES GCM Authenticated Test Suite",
15661 	.setup = aes_gcm_auth_testsuite_setup,
15662 	.unit_test_cases = {
15663 		/** AES GCM Authenticated Encryption */
15664 		TEST_CASE_ST(ut_setup, ut_teardown,
15665 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
15666 		TEST_CASE_ST(ut_setup, ut_teardown,
15667 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
15668 		TEST_CASE_ST(ut_setup, ut_teardown,
15669 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
15670 		TEST_CASE_ST(ut_setup, ut_teardown,
15671 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
15672 		TEST_CASE_ST(ut_setup, ut_teardown,
15673 			test_AES_GCM_authenticated_encryption_test_case_1),
15674 		TEST_CASE_ST(ut_setup, ut_teardown,
15675 			test_AES_GCM_authenticated_encryption_test_case_2),
15676 		TEST_CASE_ST(ut_setup, ut_teardown,
15677 			test_AES_GCM_authenticated_encryption_test_case_3),
15678 		TEST_CASE_ST(ut_setup, ut_teardown,
15679 			test_AES_GCM_authenticated_encryption_test_case_4),
15680 		TEST_CASE_ST(ut_setup, ut_teardown,
15681 			test_AES_GCM_authenticated_encryption_test_case_5),
15682 		TEST_CASE_ST(ut_setup, ut_teardown,
15683 			test_AES_GCM_authenticated_encryption_test_case_6),
15684 		TEST_CASE_ST(ut_setup, ut_teardown,
15685 			test_AES_GCM_authenticated_encryption_test_case_7),
15686 		TEST_CASE_ST(ut_setup, ut_teardown,
15687 			test_AES_GCM_authenticated_encryption_test_case_8),
15688 		TEST_CASE_ST(ut_setup, ut_teardown,
15689 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
15690 
15691 		/** AES GCM Authenticated Decryption */
15692 		TEST_CASE_ST(ut_setup, ut_teardown,
15693 			test_AES_GCM_authenticated_decryption_test_case_1),
15694 		TEST_CASE_ST(ut_setup, ut_teardown,
15695 			test_AES_GCM_authenticated_decryption_test_case_2),
15696 		TEST_CASE_ST(ut_setup, ut_teardown,
15697 			test_AES_GCM_authenticated_decryption_test_case_3),
15698 		TEST_CASE_ST(ut_setup, ut_teardown,
15699 			test_AES_GCM_authenticated_decryption_test_case_4),
15700 		TEST_CASE_ST(ut_setup, ut_teardown,
15701 			test_AES_GCM_authenticated_decryption_test_case_5),
15702 		TEST_CASE_ST(ut_setup, ut_teardown,
15703 			test_AES_GCM_authenticated_decryption_test_case_6),
15704 		TEST_CASE_ST(ut_setup, ut_teardown,
15705 			test_AES_GCM_authenticated_decryption_test_case_7),
15706 		TEST_CASE_ST(ut_setup, ut_teardown,
15707 			test_AES_GCM_authenticated_decryption_test_case_8),
15708 		TEST_CASE_ST(ut_setup, ut_teardown,
15709 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
15710 
15711 		/** AES GCM Authenticated Encryption 192 bits key */
15712 		TEST_CASE_ST(ut_setup, ut_teardown,
15713 			test_AES_GCM_auth_encryption_test_case_192_1),
15714 		TEST_CASE_ST(ut_setup, ut_teardown,
15715 			test_AES_GCM_auth_encryption_test_case_192_2),
15716 		TEST_CASE_ST(ut_setup, ut_teardown,
15717 			test_AES_GCM_auth_encryption_test_case_192_3),
15718 		TEST_CASE_ST(ut_setup, ut_teardown,
15719 			test_AES_GCM_auth_encryption_test_case_192_4),
15720 		TEST_CASE_ST(ut_setup, ut_teardown,
15721 			test_AES_GCM_auth_encryption_test_case_192_5),
15722 		TEST_CASE_ST(ut_setup, ut_teardown,
15723 			test_AES_GCM_auth_encryption_test_case_192_6),
15724 		TEST_CASE_ST(ut_setup, ut_teardown,
15725 			test_AES_GCM_auth_encryption_test_case_192_7),
15726 
15727 		/** AES GCM Authenticated Decryption 192 bits key */
15728 		TEST_CASE_ST(ut_setup, ut_teardown,
15729 			test_AES_GCM_auth_decryption_test_case_192_1),
15730 		TEST_CASE_ST(ut_setup, ut_teardown,
15731 			test_AES_GCM_auth_decryption_test_case_192_2),
15732 		TEST_CASE_ST(ut_setup, ut_teardown,
15733 			test_AES_GCM_auth_decryption_test_case_192_3),
15734 		TEST_CASE_ST(ut_setup, ut_teardown,
15735 			test_AES_GCM_auth_decryption_test_case_192_4),
15736 		TEST_CASE_ST(ut_setup, ut_teardown,
15737 			test_AES_GCM_auth_decryption_test_case_192_5),
15738 		TEST_CASE_ST(ut_setup, ut_teardown,
15739 			test_AES_GCM_auth_decryption_test_case_192_6),
15740 		TEST_CASE_ST(ut_setup, ut_teardown,
15741 			test_AES_GCM_auth_decryption_test_case_192_7),
15742 
15743 		/** AES GCM Authenticated Encryption 256 bits key */
15744 		TEST_CASE_ST(ut_setup, ut_teardown,
15745 			test_AES_GCM_auth_encryption_test_case_256_1),
15746 		TEST_CASE_ST(ut_setup, ut_teardown,
15747 			test_AES_GCM_auth_encryption_test_case_256_2),
15748 		TEST_CASE_ST(ut_setup, ut_teardown,
15749 			test_AES_GCM_auth_encryption_test_case_256_3),
15750 		TEST_CASE_ST(ut_setup, ut_teardown,
15751 			test_AES_GCM_auth_encryption_test_case_256_4),
15752 		TEST_CASE_ST(ut_setup, ut_teardown,
15753 			test_AES_GCM_auth_encryption_test_case_256_5),
15754 		TEST_CASE_ST(ut_setup, ut_teardown,
15755 			test_AES_GCM_auth_encryption_test_case_256_6),
15756 		TEST_CASE_ST(ut_setup, ut_teardown,
15757 			test_AES_GCM_auth_encryption_test_case_256_7),
15758 
15759 		/** AES GCM Authenticated Decryption 256 bits key */
15760 		TEST_CASE_ST(ut_setup, ut_teardown,
15761 			test_AES_GCM_auth_decryption_test_case_256_1),
15762 		TEST_CASE_ST(ut_setup, ut_teardown,
15763 			test_AES_GCM_auth_decryption_test_case_256_2),
15764 		TEST_CASE_ST(ut_setup, ut_teardown,
15765 			test_AES_GCM_auth_decryption_test_case_256_3),
15766 		TEST_CASE_ST(ut_setup, ut_teardown,
15767 			test_AES_GCM_auth_decryption_test_case_256_4),
15768 		TEST_CASE_ST(ut_setup, ut_teardown,
15769 			test_AES_GCM_auth_decryption_test_case_256_5),
15770 		TEST_CASE_ST(ut_setup, ut_teardown,
15771 			test_AES_GCM_auth_decryption_test_case_256_6),
15772 		TEST_CASE_ST(ut_setup, ut_teardown,
15773 			test_AES_GCM_auth_decryption_test_case_256_7),
15774 
15775 		/** AES GCM Authenticated Encryption big aad size */
15776 		TEST_CASE_ST(ut_setup, ut_teardown,
15777 			test_AES_GCM_auth_encryption_test_case_aad_1),
15778 		TEST_CASE_ST(ut_setup, ut_teardown,
15779 			test_AES_GCM_auth_encryption_test_case_aad_2),
15780 
15781 		/** AES GCM Authenticated Decryption big aad size */
15782 		TEST_CASE_ST(ut_setup, ut_teardown,
15783 			test_AES_GCM_auth_decryption_test_case_aad_1),
15784 		TEST_CASE_ST(ut_setup, ut_teardown,
15785 			test_AES_GCM_auth_decryption_test_case_aad_2),
15786 
15787 		/** Out of place tests */
15788 		TEST_CASE_ST(ut_setup, ut_teardown,
15789 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
15790 		TEST_CASE_ST(ut_setup, ut_teardown,
15791 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
15792 
15793 		/** Session-less tests */
15794 		TEST_CASE_ST(ut_setup, ut_teardown,
15795 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
15796 		TEST_CASE_ST(ut_setup, ut_teardown,
15797 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
15798 
15799 		TEST_CASES_END()
15800 	}
15801 };
15802 
15803 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
15804 	.suite_name = "AES GMAC Authentication Test Suite",
15805 	.setup = aes_gmac_auth_testsuite_setup,
15806 	.unit_test_cases = {
15807 		TEST_CASE_ST(ut_setup, ut_teardown,
15808 			test_AES_GMAC_authentication_test_case_1),
15809 		TEST_CASE_ST(ut_setup, ut_teardown,
15810 			test_AES_GMAC_authentication_verify_test_case_1),
15811 		TEST_CASE_ST(ut_setup, ut_teardown,
15812 			test_AES_GMAC_authentication_test_case_2),
15813 		TEST_CASE_ST(ut_setup, ut_teardown,
15814 			test_AES_GMAC_authentication_verify_test_case_2),
15815 		TEST_CASE_ST(ut_setup, ut_teardown,
15816 			test_AES_GMAC_authentication_test_case_3),
15817 		TEST_CASE_ST(ut_setup, ut_teardown,
15818 			test_AES_GMAC_authentication_verify_test_case_3),
15819 		TEST_CASE_ST(ut_setup, ut_teardown,
15820 			test_AES_GMAC_authentication_test_case_4),
15821 		TEST_CASE_ST(ut_setup, ut_teardown,
15822 			test_AES_GMAC_authentication_verify_test_case_4),
15823 		TEST_CASE_ST(ut_setup, ut_teardown,
15824 			test_AES_GMAC_authentication_SGL_40B),
15825 		TEST_CASE_ST(ut_setup, ut_teardown,
15826 			test_AES_GMAC_authentication_SGL_80B),
15827 		TEST_CASE_ST(ut_setup, ut_teardown,
15828 			test_AES_GMAC_authentication_SGL_2048B),
15829 		TEST_CASE_ST(ut_setup, ut_teardown,
15830 			test_AES_GMAC_authentication_SGL_2047B),
15831 
15832 		TEST_CASES_END()
15833 	}
15834 };
15835 
15836 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
15837 	.suite_name = "Chacha20-Poly1305 Test Suite",
15838 	.setup = chacha20_poly1305_testsuite_setup,
15839 	.unit_test_cases = {
15840 		TEST_CASE_ST(ut_setup, ut_teardown,
15841 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
15842 		TEST_CASE_ST(ut_setup, ut_teardown,
15843 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
15844 		TEST_CASE_ST(ut_setup, ut_teardown,
15845 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
15846 		TEST_CASES_END()
15847 	}
15848 };
15849 
15850 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
15851 	.suite_name = "SNOW 3G Test Suite",
15852 	.setup = snow3g_testsuite_setup,
15853 	.unit_test_cases = {
15854 		/** SNOW 3G encrypt only (UEA2) */
15855 		TEST_CASE_ST(ut_setup, ut_teardown,
15856 			test_snow3g_encryption_test_case_1),
15857 		TEST_CASE_ST(ut_setup, ut_teardown,
15858 			test_snow3g_encryption_test_case_2),
15859 		TEST_CASE_ST(ut_setup, ut_teardown,
15860 			test_snow3g_encryption_test_case_3),
15861 		TEST_CASE_ST(ut_setup, ut_teardown,
15862 			test_snow3g_encryption_test_case_4),
15863 		TEST_CASE_ST(ut_setup, ut_teardown,
15864 			test_snow3g_encryption_test_case_5),
15865 
15866 		TEST_CASE_ST(ut_setup, ut_teardown,
15867 			test_snow3g_encryption_test_case_1_oop),
15868 		TEST_CASE_ST(ut_setup, ut_teardown,
15869 			test_snow3g_encryption_test_case_1_oop_sgl),
15870 		TEST_CASE_ST(ut_setup, ut_teardown,
15871 			test_snow3g_encryption_test_case_1_offset_oop),
15872 		TEST_CASE_ST(ut_setup, ut_teardown,
15873 			test_snow3g_decryption_test_case_1_oop),
15874 
15875 		/** SNOW 3G generate auth, then encrypt (UEA2) */
15876 		TEST_CASE_ST(ut_setup, ut_teardown,
15877 			test_snow3g_auth_cipher_test_case_1),
15878 		TEST_CASE_ST(ut_setup, ut_teardown,
15879 			test_snow3g_auth_cipher_test_case_2),
15880 		TEST_CASE_ST(ut_setup, ut_teardown,
15881 			test_snow3g_auth_cipher_test_case_2_oop),
15882 		TEST_CASE_ST(ut_setup, ut_teardown,
15883 			test_snow3g_auth_cipher_part_digest_enc),
15884 		TEST_CASE_ST(ut_setup, ut_teardown,
15885 			test_snow3g_auth_cipher_part_digest_enc_oop),
15886 		TEST_CASE_ST(ut_setup, ut_teardown,
15887 			test_snow3g_auth_cipher_test_case_3_sgl),
15888 		TEST_CASE_ST(ut_setup, ut_teardown,
15889 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
15890 		TEST_CASE_ST(ut_setup, ut_teardown,
15891 			test_snow3g_auth_cipher_part_digest_enc_sgl),
15892 		TEST_CASE_ST(ut_setup, ut_teardown,
15893 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
15894 		TEST_CASE_ST(ut_setup, ut_teardown,
15895 			test_snow3g_auth_cipher_total_digest_enc_1),
15896 		TEST_CASE_ST(ut_setup, ut_teardown,
15897 			test_snow3g_auth_cipher_total_digest_enc_1_oop),
15898 		TEST_CASE_ST(ut_setup, ut_teardown,
15899 			test_snow3g_auth_cipher_total_digest_enc_1_sgl),
15900 		TEST_CASE_ST(ut_setup, ut_teardown,
15901 			test_snow3g_auth_cipher_total_digest_enc_1_oop_sgl),
15902 
15903 		/** SNOW 3G decrypt (UEA2), then verify auth */
15904 		TEST_CASE_ST(ut_setup, ut_teardown,
15905 			test_snow3g_auth_cipher_verify_test_case_1),
15906 		TEST_CASE_ST(ut_setup, ut_teardown,
15907 			test_snow3g_auth_cipher_verify_test_case_2),
15908 		TEST_CASE_ST(ut_setup, ut_teardown,
15909 			test_snow3g_auth_cipher_verify_test_case_2_oop),
15910 		TEST_CASE_ST(ut_setup, ut_teardown,
15911 			test_snow3g_auth_cipher_verify_part_digest_enc),
15912 		TEST_CASE_ST(ut_setup, ut_teardown,
15913 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
15914 		TEST_CASE_ST(ut_setup, ut_teardown,
15915 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
15916 		TEST_CASE_ST(ut_setup, ut_teardown,
15917 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
15918 		TEST_CASE_ST(ut_setup, ut_teardown,
15919 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
15920 		TEST_CASE_ST(ut_setup, ut_teardown,
15921 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
15922 		TEST_CASE_ST(ut_setup, ut_teardown,
15923 			test_snow3g_auth_cipher_verify_total_digest_enc_1),
15924 		TEST_CASE_ST(ut_setup, ut_teardown,
15925 			test_snow3g_auth_cipher_verify_total_digest_enc_1_oop),
15926 		TEST_CASE_ST(ut_setup, ut_teardown,
15927 			test_snow3g_auth_cipher_verify_total_digest_enc_1_sgl),
15928 		TEST_CASE_ST(ut_setup, ut_teardown,
15929 			test_snow3g_auth_cipher_verify_total_digest_enc_1_oop_sgl),
15930 
15931 		/** SNOW 3G decrypt only (UEA2) */
15932 		TEST_CASE_ST(ut_setup, ut_teardown,
15933 			test_snow3g_decryption_test_case_1),
15934 		TEST_CASE_ST(ut_setup, ut_teardown,
15935 			test_snow3g_decryption_test_case_2),
15936 		TEST_CASE_ST(ut_setup, ut_teardown,
15937 			test_snow3g_decryption_test_case_3),
15938 		TEST_CASE_ST(ut_setup, ut_teardown,
15939 			test_snow3g_decryption_test_case_4),
15940 		TEST_CASE_ST(ut_setup, ut_teardown,
15941 			test_snow3g_decryption_test_case_5),
15942 		TEST_CASE_ST(ut_setup, ut_teardown,
15943 			test_snow3g_decryption_with_digest_test_case_1),
15944 		TEST_CASE_ST(ut_setup, ut_teardown,
15945 			test_snow3g_hash_generate_test_case_1),
15946 		TEST_CASE_ST(ut_setup, ut_teardown,
15947 			test_snow3g_hash_generate_test_case_2),
15948 		TEST_CASE_ST(ut_setup, ut_teardown,
15949 			test_snow3g_hash_generate_test_case_3),
15950 
15951 		/* Tests with buffers which length is not byte-aligned */
15952 		TEST_CASE_ST(ut_setup, ut_teardown,
15953 			test_snow3g_hash_generate_test_case_4),
15954 		TEST_CASE_ST(ut_setup, ut_teardown,
15955 			test_snow3g_hash_generate_test_case_5),
15956 		TEST_CASE_ST(ut_setup, ut_teardown,
15957 			test_snow3g_hash_generate_test_case_6),
15958 		TEST_CASE_ST(ut_setup, ut_teardown,
15959 			test_snow3g_hash_verify_test_case_1),
15960 		TEST_CASE_ST(ut_setup, ut_teardown,
15961 			test_snow3g_hash_verify_test_case_2),
15962 		TEST_CASE_ST(ut_setup, ut_teardown,
15963 			test_snow3g_hash_verify_test_case_3),
15964 
15965 		/* Tests with buffers which length is not byte-aligned */
15966 		TEST_CASE_ST(ut_setup, ut_teardown,
15967 			test_snow3g_hash_verify_test_case_4),
15968 		TEST_CASE_ST(ut_setup, ut_teardown,
15969 			test_snow3g_hash_verify_test_case_5),
15970 		TEST_CASE_ST(ut_setup, ut_teardown,
15971 			test_snow3g_hash_verify_test_case_6),
15972 		TEST_CASE_ST(ut_setup, ut_teardown,
15973 			test_snow3g_cipher_auth_test_case_1),
15974 		TEST_CASE_ST(ut_setup, ut_teardown,
15975 			test_snow3g_auth_cipher_with_digest_test_case_1),
15976 		TEST_CASES_END()
15977 	}
15978 };
15979 
15980 static struct unit_test_suite cryptodev_zuc_testsuite  = {
15981 	.suite_name = "ZUC Test Suite",
15982 	.setup = zuc_testsuite_setup,
15983 	.unit_test_cases = {
15984 		/** ZUC encrypt only (EEA3) */
15985 		TEST_CASE_ST(ut_setup, ut_teardown,
15986 			test_zuc_encryption_test_case_1),
15987 		TEST_CASE_ST(ut_setup, ut_teardown,
15988 			test_zuc_encryption_test_case_2),
15989 		TEST_CASE_ST(ut_setup, ut_teardown,
15990 			test_zuc_encryption_test_case_3),
15991 		TEST_CASE_ST(ut_setup, ut_teardown,
15992 			test_zuc_encryption_test_case_4),
15993 		TEST_CASE_ST(ut_setup, ut_teardown,
15994 			test_zuc_encryption_test_case_5),
15995 		TEST_CASE_ST(ut_setup, ut_teardown,
15996 			test_zuc_encryption_test_case_6_sgl),
15997 
15998 		/** ZUC authenticate (EIA3) */
15999 		TEST_CASE_ST(ut_setup, ut_teardown,
16000 			test_zuc_hash_generate_test_case_1),
16001 		TEST_CASE_ST(ut_setup, ut_teardown,
16002 			test_zuc_hash_generate_test_case_2),
16003 		TEST_CASE_ST(ut_setup, ut_teardown,
16004 			test_zuc_hash_generate_test_case_3),
16005 		TEST_CASE_ST(ut_setup, ut_teardown,
16006 			test_zuc_hash_generate_test_case_4),
16007 		TEST_CASE_ST(ut_setup, ut_teardown,
16008 			test_zuc_hash_generate_test_case_5),
16009 		TEST_CASE_ST(ut_setup, ut_teardown,
16010 			test_zuc_hash_generate_test_case_6),
16011 		TEST_CASE_ST(ut_setup, ut_teardown,
16012 			test_zuc_hash_generate_test_case_7),
16013 		TEST_CASE_ST(ut_setup, ut_teardown,
16014 			test_zuc_hash_generate_test_case_8),
16015 		TEST_CASE_ST(ut_setup, ut_teardown,
16016 			test_zuc_hash_generate_test_case_9),
16017 		TEST_CASE_ST(ut_setup, ut_teardown,
16018 			test_zuc_hash_generate_test_case_10),
16019 		TEST_CASE_ST(ut_setup, ut_teardown,
16020 			test_zuc_hash_generate_test_case_11),
16021 
16022 
16023 		/** ZUC alg-chain (EEA3/EIA3) */
16024 		TEST_CASE_ST(ut_setup, ut_teardown,
16025 			test_zuc_cipher_auth_test_case_1),
16026 		TEST_CASE_ST(ut_setup, ut_teardown,
16027 			test_zuc_cipher_auth_test_case_2),
16028 
16029 		/** ZUC generate auth, then encrypt (EEA3) */
16030 		TEST_CASE_ST(ut_setup, ut_teardown,
16031 			test_zuc_auth_cipher_test_case_1),
16032 		TEST_CASE_ST(ut_setup, ut_teardown,
16033 			test_zuc_auth_cipher_test_case_1_oop),
16034 		TEST_CASE_ST(ut_setup, ut_teardown,
16035 			test_zuc_auth_cipher_test_case_1_sgl),
16036 		TEST_CASE_ST(ut_setup, ut_teardown,
16037 			test_zuc_auth_cipher_test_case_1_oop_sgl),
16038 		TEST_CASE_ST(ut_setup, ut_teardown,
16039 			test_zuc_auth_cipher_test_case_2),
16040 		TEST_CASE_ST(ut_setup, ut_teardown,
16041 			test_zuc_auth_cipher_test_case_2_oop),
16042 
16043 		/** ZUC decrypt (EEA3), then verify auth */
16044 		TEST_CASE_ST(ut_setup, ut_teardown,
16045 			test_zuc_auth_cipher_verify_test_case_1),
16046 		TEST_CASE_ST(ut_setup, ut_teardown,
16047 			test_zuc_auth_cipher_verify_test_case_1_oop),
16048 		TEST_CASE_ST(ut_setup, ut_teardown,
16049 			test_zuc_auth_cipher_verify_test_case_1_sgl),
16050 		TEST_CASE_ST(ut_setup, ut_teardown,
16051 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
16052 		TEST_CASE_ST(ut_setup, ut_teardown,
16053 			test_zuc_auth_cipher_verify_test_case_2),
16054 		TEST_CASE_ST(ut_setup, ut_teardown,
16055 			test_zuc_auth_cipher_verify_test_case_2_oop),
16056 
16057 		/** ZUC-256 encrypt only **/
16058 		TEST_CASE_ST(ut_setup, ut_teardown,
16059 			test_zuc256_encryption_test_case_1),
16060 		TEST_CASE_ST(ut_setup, ut_teardown,
16061 			test_zuc256_encryption_test_case_2),
16062 
16063 		/** ZUC-256 authentication only **/
16064 		TEST_CASE_ST(ut_setup, ut_teardown,
16065 			test_zuc256_authentication_test_case_1),
16066 		TEST_CASE_ST(ut_setup, ut_teardown,
16067 			test_zuc256_authentication_test_case_2),
16068 
16069 		TEST_CASES_END()
16070 	}
16071 };
16072 
16073 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
16074 	.suite_name = "HMAC_MD5 Authentication Test Suite",
16075 	.setup = hmac_md5_auth_testsuite_setup,
16076 	.unit_test_cases = {
16077 		TEST_CASE_ST(ut_setup, ut_teardown,
16078 			test_MD5_HMAC_generate_case_1),
16079 		TEST_CASE_ST(ut_setup, ut_teardown,
16080 			test_MD5_HMAC_verify_case_1),
16081 		TEST_CASE_ST(ut_setup, ut_teardown,
16082 			test_MD5_HMAC_generate_case_2),
16083 		TEST_CASE_ST(ut_setup, ut_teardown,
16084 			test_MD5_HMAC_verify_case_2),
16085 		TEST_CASES_END()
16086 	}
16087 };
16088 
16089 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
16090 	.suite_name = "Kasumi Test Suite",
16091 	.setup = kasumi_testsuite_setup,
16092 	.unit_test_cases = {
16093 		/** KASUMI hash only (UIA1) */
16094 		TEST_CASE_ST(ut_setup, ut_teardown,
16095 			test_kasumi_hash_generate_test_case_1),
16096 		TEST_CASE_ST(ut_setup, ut_teardown,
16097 			test_kasumi_hash_generate_test_case_2),
16098 		TEST_CASE_ST(ut_setup, ut_teardown,
16099 			test_kasumi_hash_generate_test_case_3),
16100 		TEST_CASE_ST(ut_setup, ut_teardown,
16101 			test_kasumi_hash_generate_test_case_4),
16102 		TEST_CASE_ST(ut_setup, ut_teardown,
16103 			test_kasumi_hash_generate_test_case_5),
16104 		TEST_CASE_ST(ut_setup, ut_teardown,
16105 			test_kasumi_hash_generate_test_case_6),
16106 
16107 		TEST_CASE_ST(ut_setup, ut_teardown,
16108 			test_kasumi_hash_verify_test_case_1),
16109 		TEST_CASE_ST(ut_setup, ut_teardown,
16110 			test_kasumi_hash_verify_test_case_2),
16111 		TEST_CASE_ST(ut_setup, ut_teardown,
16112 			test_kasumi_hash_verify_test_case_3),
16113 		TEST_CASE_ST(ut_setup, ut_teardown,
16114 			test_kasumi_hash_verify_test_case_4),
16115 		TEST_CASE_ST(ut_setup, ut_teardown,
16116 			test_kasumi_hash_verify_test_case_5),
16117 
16118 		/** KASUMI encrypt only (UEA1) */
16119 		TEST_CASE_ST(ut_setup, ut_teardown,
16120 			test_kasumi_encryption_test_case_1),
16121 		TEST_CASE_ST(ut_setup, ut_teardown,
16122 			test_kasumi_encryption_test_case_1_sgl),
16123 		TEST_CASE_ST(ut_setup, ut_teardown,
16124 			test_kasumi_encryption_test_case_1_oop),
16125 		TEST_CASE_ST(ut_setup, ut_teardown,
16126 			test_kasumi_encryption_test_case_1_oop_sgl),
16127 		TEST_CASE_ST(ut_setup, ut_teardown,
16128 			test_kasumi_encryption_test_case_2),
16129 		TEST_CASE_ST(ut_setup, ut_teardown,
16130 			test_kasumi_encryption_test_case_3),
16131 		TEST_CASE_ST(ut_setup, ut_teardown,
16132 			test_kasumi_encryption_test_case_4),
16133 		TEST_CASE_ST(ut_setup, ut_teardown,
16134 			test_kasumi_encryption_test_case_5),
16135 
16136 		/** KASUMI decrypt only (UEA1) */
16137 		TEST_CASE_ST(ut_setup, ut_teardown,
16138 			test_kasumi_decryption_test_case_1),
16139 		TEST_CASE_ST(ut_setup, ut_teardown,
16140 			test_kasumi_decryption_test_case_2),
16141 		TEST_CASE_ST(ut_setup, ut_teardown,
16142 			test_kasumi_decryption_test_case_3),
16143 		TEST_CASE_ST(ut_setup, ut_teardown,
16144 			test_kasumi_decryption_test_case_4),
16145 		TEST_CASE_ST(ut_setup, ut_teardown,
16146 			test_kasumi_decryption_test_case_5),
16147 		TEST_CASE_ST(ut_setup, ut_teardown,
16148 			test_kasumi_decryption_test_case_1_oop),
16149 		TEST_CASE_ST(ut_setup, ut_teardown,
16150 			test_kasumi_cipher_auth_test_case_1),
16151 
16152 		/** KASUMI generate auth, then encrypt (F8) */
16153 		TEST_CASE_ST(ut_setup, ut_teardown,
16154 			test_kasumi_auth_cipher_test_case_1),
16155 		TEST_CASE_ST(ut_setup, ut_teardown,
16156 			test_kasumi_auth_cipher_test_case_2),
16157 		TEST_CASE_ST(ut_setup, ut_teardown,
16158 			test_kasumi_auth_cipher_test_case_2_oop),
16159 		TEST_CASE_ST(ut_setup, ut_teardown,
16160 			test_kasumi_auth_cipher_test_case_2_sgl),
16161 		TEST_CASE_ST(ut_setup, ut_teardown,
16162 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
16163 
16164 		/** KASUMI decrypt (F8), then verify auth */
16165 		TEST_CASE_ST(ut_setup, ut_teardown,
16166 			test_kasumi_auth_cipher_verify_test_case_1),
16167 		TEST_CASE_ST(ut_setup, ut_teardown,
16168 			test_kasumi_auth_cipher_verify_test_case_2),
16169 		TEST_CASE_ST(ut_setup, ut_teardown,
16170 			test_kasumi_auth_cipher_verify_test_case_2_oop),
16171 		TEST_CASE_ST(ut_setup, ut_teardown,
16172 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
16173 		TEST_CASE_ST(ut_setup, ut_teardown,
16174 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
16175 
16176 		TEST_CASES_END()
16177 	}
16178 };
16179 
16180 static struct unit_test_suite cryptodev_esn_testsuite  = {
16181 	.suite_name = "ESN Test Suite",
16182 	.setup = esn_testsuite_setup,
16183 	.unit_test_cases = {
16184 		TEST_CASE_ST(ut_setup, ut_teardown,
16185 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
16186 		TEST_CASE_ST(ut_setup, ut_teardown,
16187 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
16188 		TEST_CASES_END()
16189 	}
16190 };
16191 
16192 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
16193 	.suite_name = "Negative AES GCM Test Suite",
16194 	.setup = negative_aes_gcm_testsuite_setup,
16195 	.unit_test_cases = {
16196 		TEST_CASE_ST(ut_setup, ut_teardown,
16197 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
16198 		TEST_CASE_ST(ut_setup, ut_teardown,
16199 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
16200 		TEST_CASE_ST(ut_setup, ut_teardown,
16201 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
16202 		TEST_CASE_ST(ut_setup, ut_teardown,
16203 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
16204 		TEST_CASE_ST(ut_setup, ut_teardown,
16205 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
16206 		TEST_CASE_ST(ut_setup, ut_teardown,
16207 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
16208 		TEST_CASE_ST(ut_setup, ut_teardown,
16209 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
16210 		TEST_CASE_ST(ut_setup, ut_teardown,
16211 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
16212 		TEST_CASE_ST(ut_setup, ut_teardown,
16213 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
16214 		TEST_CASE_ST(ut_setup, ut_teardown,
16215 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
16216 		TEST_CASE_ST(ut_setup, ut_teardown,
16217 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
16218 		TEST_CASE_ST(ut_setup, ut_teardown,
16219 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
16220 
16221 		TEST_CASES_END()
16222 	}
16223 };
16224 
16225 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
16226 	.suite_name = "Negative AES GMAC Test Suite",
16227 	.setup = negative_aes_gmac_testsuite_setup,
16228 	.unit_test_cases = {
16229 		TEST_CASE_ST(ut_setup, ut_teardown,
16230 			authentication_verify_AES128_GMAC_fail_data_corrupt),
16231 		TEST_CASE_ST(ut_setup, ut_teardown,
16232 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
16233 
16234 		TEST_CASES_END()
16235 	}
16236 };
16237 
16238 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
16239 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
16240 	.setup = mixed_cipher_hash_testsuite_setup,
16241 	.unit_test_cases = {
16242 		/** AUTH AES CMAC + CIPHER AES CTR */
16243 		TEST_CASE_ST(ut_setup, ut_teardown,
16244 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
16245 		TEST_CASE_ST(ut_setup, ut_teardown,
16246 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
16247 		TEST_CASE_ST(ut_setup, ut_teardown,
16248 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
16249 		TEST_CASE_ST(ut_setup, ut_teardown,
16250 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
16251 		TEST_CASE_ST(ut_setup, ut_teardown,
16252 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
16253 		TEST_CASE_ST(ut_setup, ut_teardown,
16254 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
16255 		TEST_CASE_ST(ut_setup, ut_teardown,
16256 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
16257 		TEST_CASE_ST(ut_setup, ut_teardown,
16258 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
16259 		TEST_CASE_ST(ut_setup, ut_teardown,
16260 			test_aes_cmac_aes_ctr_digest_enc_test_case_2),
16261 		TEST_CASE_ST(ut_setup, ut_teardown,
16262 			test_aes_cmac_aes_ctr_digest_enc_test_case_2_oop),
16263 		TEST_CASE_ST(ut_setup, ut_teardown,
16264 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2),
16265 		TEST_CASE_ST(ut_setup, ut_teardown,
16266 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_2_oop),
16267 
16268 		/** AUTH ZUC + CIPHER SNOW3G */
16269 		TEST_CASE_ST(ut_setup, ut_teardown,
16270 			test_auth_zuc_cipher_snow_test_case_1),
16271 		TEST_CASE_ST(ut_setup, ut_teardown,
16272 			test_verify_auth_zuc_cipher_snow_test_case_1),
16273 		TEST_CASE_ST(ut_setup, ut_teardown,
16274 			test_auth_zuc_cipher_snow_test_case_1_inplace),
16275 		TEST_CASE_ST(ut_setup, ut_teardown,
16276 			test_verify_auth_zuc_cipher_snow_test_case_1_inplace),
16277 		/** AUTH AES CMAC + CIPHER SNOW3G */
16278 		TEST_CASE_ST(ut_setup, ut_teardown,
16279 			test_auth_aes_cmac_cipher_snow_test_case_1),
16280 		TEST_CASE_ST(ut_setup, ut_teardown,
16281 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
16282 		TEST_CASE_ST(ut_setup, ut_teardown,
16283 			test_auth_aes_cmac_cipher_snow_test_case_1_inplace),
16284 		TEST_CASE_ST(ut_setup, ut_teardown,
16285 			test_verify_auth_aes_cmac_cipher_snow_test_case_1_inplace),
16286 		/** AUTH ZUC + CIPHER AES CTR */
16287 		TEST_CASE_ST(ut_setup, ut_teardown,
16288 			test_auth_zuc_cipher_aes_ctr_test_case_1),
16289 		TEST_CASE_ST(ut_setup, ut_teardown,
16290 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
16291 		TEST_CASE_ST(ut_setup, ut_teardown,
16292 			test_auth_zuc_cipher_aes_ctr_test_case_1_inplace),
16293 		TEST_CASE_ST(ut_setup, ut_teardown,
16294 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1_inplace),
16295 		/** AUTH SNOW3G + CIPHER AES CTR */
16296 		TEST_CASE_ST(ut_setup, ut_teardown,
16297 			test_auth_snow_cipher_aes_ctr_test_case_1),
16298 		TEST_CASE_ST(ut_setup, ut_teardown,
16299 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
16300 		TEST_CASE_ST(ut_setup, ut_teardown,
16301 			test_auth_snow_cipher_aes_ctr_test_case_1_inplace),
16302 		TEST_CASE_ST(ut_setup, ut_teardown,
16303 			test_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl),
16304 		TEST_CASE_ST(ut_setup, ut_teardown,
16305 			test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace),
16306 		TEST_CASE_ST(ut_setup, ut_teardown,
16307 			test_verify_auth_snow_cipher_aes_ctr_test_case_1_inplace_sgl),
16308 		/** AUTH SNOW3G + CIPHER ZUC */
16309 		TEST_CASE_ST(ut_setup, ut_teardown,
16310 			test_auth_snow_cipher_zuc_test_case_1),
16311 		TEST_CASE_ST(ut_setup, ut_teardown,
16312 			test_verify_auth_snow_cipher_zuc_test_case_1),
16313 		TEST_CASE_ST(ut_setup, ut_teardown,
16314 			test_auth_snow_cipher_zuc_test_case_1_inplace),
16315 		TEST_CASE_ST(ut_setup, ut_teardown,
16316 			test_verify_auth_snow_cipher_zuc_test_case_1_inplace),
16317 		/** AUTH AES CMAC + CIPHER ZUC */
16318 		TEST_CASE_ST(ut_setup, ut_teardown,
16319 			test_auth_aes_cmac_cipher_zuc_test_case_1),
16320 		TEST_CASE_ST(ut_setup, ut_teardown,
16321 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
16322 		TEST_CASE_ST(ut_setup, ut_teardown,
16323 			test_auth_aes_cmac_cipher_zuc_test_case_1_inplace),
16324 		TEST_CASE_ST(ut_setup, ut_teardown,
16325 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1_inplace),
16326 
16327 		/** AUTH NULL + CIPHER SNOW3G */
16328 		TEST_CASE_ST(ut_setup, ut_teardown,
16329 			test_auth_null_cipher_snow_test_case_1),
16330 		TEST_CASE_ST(ut_setup, ut_teardown,
16331 			test_verify_auth_null_cipher_snow_test_case_1),
16332 		/** AUTH NULL + CIPHER ZUC */
16333 		TEST_CASE_ST(ut_setup, ut_teardown,
16334 			test_auth_null_cipher_zuc_test_case_1),
16335 		TEST_CASE_ST(ut_setup, ut_teardown,
16336 			test_verify_auth_null_cipher_zuc_test_case_1),
16337 		/** AUTH SNOW3G + CIPHER NULL */
16338 		TEST_CASE_ST(ut_setup, ut_teardown,
16339 			test_auth_snow_cipher_null_test_case_1),
16340 		TEST_CASE_ST(ut_setup, ut_teardown,
16341 			test_verify_auth_snow_cipher_null_test_case_1),
16342 		/** AUTH ZUC + CIPHER NULL */
16343 		TEST_CASE_ST(ut_setup, ut_teardown,
16344 			test_auth_zuc_cipher_null_test_case_1),
16345 		TEST_CASE_ST(ut_setup, ut_teardown,
16346 			test_verify_auth_zuc_cipher_null_test_case_1),
16347 		/** AUTH NULL + CIPHER AES CTR */
16348 		TEST_CASE_ST(ut_setup, ut_teardown,
16349 			test_auth_null_cipher_aes_ctr_test_case_1),
16350 		TEST_CASE_ST(ut_setup, ut_teardown,
16351 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
16352 		/** AUTH AES CMAC + CIPHER NULL */
16353 		TEST_CASE_ST(ut_setup, ut_teardown,
16354 			test_auth_aes_cmac_cipher_null_test_case_1),
16355 		TEST_CASE_ST(ut_setup, ut_teardown,
16356 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
16357 		TEST_CASES_END()
16358 	}
16359 };
16360 
16361 static int
16362 run_cryptodev_testsuite(const char *pmd_name)
16363 {
16364 	uint8_t ret, j, i = 0, blk_start_idx = 0;
16365 	const enum blockcipher_test_type blk_suites[] = {
16366 		BLKCIPHER_AES_CHAIN_TYPE,
16367 		BLKCIPHER_AES_CIPHERONLY_TYPE,
16368 		BLKCIPHER_AES_DOCSIS_TYPE,
16369 		BLKCIPHER_3DES_CHAIN_TYPE,
16370 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
16371 		BLKCIPHER_DES_CIPHERONLY_TYPE,
16372 		BLKCIPHER_DES_DOCSIS_TYPE,
16373 		BLKCIPHER_AUTHONLY_TYPE};
16374 	struct unit_test_suite *static_suites[] = {
16375 		&cryptodev_multi_session_testsuite,
16376 		&cryptodev_null_testsuite,
16377 		&cryptodev_aes_ccm_auth_testsuite,
16378 		&cryptodev_aes_gcm_auth_testsuite,
16379 		&cryptodev_aes_gmac_auth_testsuite,
16380 		&cryptodev_snow3g_testsuite,
16381 		&cryptodev_chacha20_poly1305_testsuite,
16382 		&cryptodev_zuc_testsuite,
16383 		&cryptodev_hmac_md5_auth_testsuite,
16384 		&cryptodev_kasumi_testsuite,
16385 		&cryptodev_esn_testsuite,
16386 		&cryptodev_negative_aes_gcm_testsuite,
16387 		&cryptodev_negative_aes_gmac_testsuite,
16388 		&cryptodev_mixed_cipher_hash_testsuite,
16389 		&cryptodev_negative_hmac_sha1_testsuite,
16390 		&cryptodev_gen_testsuite,
16391 #ifdef RTE_LIB_SECURITY
16392 		&ipsec_proto_testsuite,
16393 		&pdcp_proto_testsuite,
16394 		&docsis_proto_testsuite,
16395 #endif
16396 		&end_testsuite
16397 	};
16398 	static struct unit_test_suite ts = {
16399 		.suite_name = "Cryptodev Unit Test Suite",
16400 		.setup = testsuite_setup,
16401 		.teardown = testsuite_teardown,
16402 		.unit_test_cases = {TEST_CASES_END()}
16403 	};
16404 
16405 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
16406 
16407 	if (gbl_driver_id == -1) {
16408 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
16409 		return TEST_SKIPPED;
16410 	}
16411 
16412 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
16413 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
16414 
16415 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
16416 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
16417 	ret = unit_test_suite_runner(&ts);
16418 
16419 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
16420 	free(ts.unit_test_suites);
16421 	return ret;
16422 }
16423 
16424 static int
16425 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
16426 {
16427 	struct rte_cryptodev_info dev_info;
16428 	uint8_t i, nb_devs;
16429 	int driver_id;
16430 
16431 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
16432 	if (driver_id == -1) {
16433 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
16434 		return TEST_SKIPPED;
16435 	}
16436 
16437 	nb_devs = rte_cryptodev_count();
16438 	if (nb_devs < 1) {
16439 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
16440 		return TEST_SKIPPED;
16441 	}
16442 
16443 	for (i = 0; i < nb_devs; i++) {
16444 		rte_cryptodev_info_get(i, &dev_info);
16445 		if (dev_info.driver_id == driver_id) {
16446 			if (!(dev_info.feature_flags & flag)) {
16447 				RTE_LOG(INFO, USER1, "%s not supported\n",
16448 						flag_name);
16449 				return TEST_SKIPPED;
16450 			}
16451 			return 0; /* found */
16452 		}
16453 	}
16454 
16455 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
16456 	return TEST_SKIPPED;
16457 }
16458 
16459 static int
16460 test_cryptodev_qat(void)
16461 {
16462 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
16463 }
16464 
16465 static int
16466 test_cryptodev_virtio(void)
16467 {
16468 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
16469 }
16470 
16471 static int
16472 test_cryptodev_aesni_mb(void)
16473 {
16474 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
16475 }
16476 
16477 static int
16478 test_cryptodev_cpu_aesni_mb(void)
16479 {
16480 	int32_t rc;
16481 	enum rte_security_session_action_type at = gbl_action_type;
16482 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
16483 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
16484 	gbl_action_type = at;
16485 	return rc;
16486 }
16487 
16488 static int
16489 test_cryptodev_chacha_poly_mb(void)
16490 {
16491 	int32_t rc;
16492 	enum rte_security_session_action_type at = gbl_action_type;
16493 	rc = run_cryptodev_testsuite(
16494 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
16495 	gbl_action_type = at;
16496 	return rc;
16497 }
16498 
16499 static int
16500 test_cryptodev_openssl(void)
16501 {
16502 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
16503 }
16504 
16505 static int
16506 test_cryptodev_aesni_gcm(void)
16507 {
16508 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
16509 }
16510 
16511 static int
16512 test_cryptodev_cpu_aesni_gcm(void)
16513 {
16514 	int32_t rc;
16515 	enum rte_security_session_action_type at = gbl_action_type;
16516 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
16517 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
16518 	gbl_action_type = at;
16519 	return rc;
16520 }
16521 
16522 static int
16523 test_cryptodev_mlx5(void)
16524 {
16525 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
16526 }
16527 
16528 static int
16529 test_cryptodev_null(void)
16530 {
16531 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
16532 }
16533 
16534 static int
16535 test_cryptodev_sw_snow3g(void)
16536 {
16537 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
16538 }
16539 
16540 static int
16541 test_cryptodev_sw_kasumi(void)
16542 {
16543 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
16544 }
16545 
16546 static int
16547 test_cryptodev_sw_zuc(void)
16548 {
16549 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
16550 }
16551 
16552 static int
16553 test_cryptodev_armv8(void)
16554 {
16555 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
16556 }
16557 
16558 static int
16559 test_cryptodev_mrvl(void)
16560 {
16561 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
16562 }
16563 
16564 #ifdef RTE_CRYPTO_SCHEDULER
16565 
16566 static int
16567 test_cryptodev_scheduler(void)
16568 {
16569 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
16570 	const enum blockcipher_test_type blk_suites[] = {
16571 		BLKCIPHER_AES_CHAIN_TYPE,
16572 		BLKCIPHER_AES_CIPHERONLY_TYPE,
16573 		BLKCIPHER_AUTHONLY_TYPE
16574 	};
16575 	static struct unit_test_suite scheduler_multicore = {
16576 		.suite_name = "Scheduler Multicore Unit Test Suite",
16577 		.setup = scheduler_multicore_testsuite_setup,
16578 		.teardown = scheduler_mode_testsuite_teardown,
16579 		.unit_test_cases = {TEST_CASES_END()}
16580 	};
16581 	static struct unit_test_suite scheduler_round_robin = {
16582 		.suite_name = "Scheduler Round Robin Unit Test Suite",
16583 		.setup = scheduler_roundrobin_testsuite_setup,
16584 		.teardown = scheduler_mode_testsuite_teardown,
16585 		.unit_test_cases = {TEST_CASES_END()}
16586 	};
16587 	static struct unit_test_suite scheduler_failover = {
16588 		.suite_name = "Scheduler Failover Unit Test Suite",
16589 		.setup = scheduler_failover_testsuite_setup,
16590 		.teardown = scheduler_mode_testsuite_teardown,
16591 		.unit_test_cases = {TEST_CASES_END()}
16592 	};
16593 	static struct unit_test_suite scheduler_pkt_size_distr = {
16594 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
16595 		.setup = scheduler_pkt_size_distr_testsuite_setup,
16596 		.teardown = scheduler_mode_testsuite_teardown,
16597 		.unit_test_cases = {TEST_CASES_END()}
16598 	};
16599 	struct unit_test_suite *sched_mode_suites[] = {
16600 		&scheduler_multicore,
16601 		&scheduler_round_robin,
16602 		&scheduler_failover,
16603 		&scheduler_pkt_size_distr
16604 	};
16605 	static struct unit_test_suite scheduler_config = {
16606 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
16607 		.unit_test_cases = {
16608 			TEST_CASE(test_scheduler_attach_worker_op),
16609 			TEST_CASE(test_scheduler_mode_multicore_op),
16610 			TEST_CASE(test_scheduler_mode_roundrobin_op),
16611 			TEST_CASE(test_scheduler_mode_failover_op),
16612 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
16613 			TEST_CASE(test_scheduler_detach_worker_op),
16614 
16615 			TEST_CASES_END() /**< NULL terminate array */
16616 		}
16617 	};
16618 	struct unit_test_suite *static_suites[] = {
16619 		&scheduler_config,
16620 		&end_testsuite
16621 	};
16622 	static struct unit_test_suite ts = {
16623 		.suite_name = "Scheduler Unit Test Suite",
16624 		.setup = scheduler_testsuite_setup,
16625 		.teardown = testsuite_teardown,
16626 		.unit_test_cases = {TEST_CASES_END()}
16627 	};
16628 
16629 	gbl_driver_id =	rte_cryptodev_driver_id_get(
16630 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
16631 
16632 	if (gbl_driver_id == -1) {
16633 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
16634 		return TEST_SKIPPED;
16635 	}
16636 
16637 	if (rte_cryptodev_driver_id_get(
16638 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
16639 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
16640 		return TEST_SKIPPED;
16641 	}
16642 
16643 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
16644 		uint8_t blk_i = 0;
16645 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
16646 				(struct unit_test_suite *) *
16647 				(RTE_DIM(blk_suites) + 1));
16648 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
16649 				blk_suites, RTE_DIM(blk_suites));
16650 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
16651 	}
16652 
16653 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
16654 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
16655 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
16656 			RTE_DIM(sched_mode_suites));
16657 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
16658 	ret = unit_test_suite_runner(&ts);
16659 
16660 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
16661 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
16662 				(*sched_mode_suites[sched_i]),
16663 				RTE_DIM(blk_suites));
16664 		free(sched_mode_suites[sched_i]->unit_test_suites);
16665 	}
16666 	free(ts.unit_test_suites);
16667 	return ret;
16668 }
16669 
16670 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
16671 
16672 #endif
16673 
16674 static int
16675 test_cryptodev_dpaa2_sec(void)
16676 {
16677 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
16678 }
16679 
16680 static int
16681 test_cryptodev_dpaa_sec(void)
16682 {
16683 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
16684 }
16685 
16686 static int
16687 test_cryptodev_ccp(void)
16688 {
16689 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
16690 }
16691 
16692 static int
16693 test_cryptodev_octeontx(void)
16694 {
16695 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
16696 }
16697 
16698 static int
16699 test_cryptodev_caam_jr(void)
16700 {
16701 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
16702 }
16703 
16704 static int
16705 test_cryptodev_nitrox(void)
16706 {
16707 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
16708 }
16709 
16710 static int
16711 test_cryptodev_bcmfs(void)
16712 {
16713 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
16714 }
16715 
16716 static int
16717 test_cryptodev_qat_raw_api(void)
16718 {
16719 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
16720 	int ret;
16721 
16722 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16723 			"RAW API");
16724 	if (ret)
16725 		return ret;
16726 
16727 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16728 	ret = run_cryptodev_testsuite(pmd_name);
16729 	global_api_test_type = CRYPTODEV_API_TEST;
16730 
16731 	return ret;
16732 }
16733 
16734 static int
16735 test_cryptodev_cn9k(void)
16736 {
16737 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
16738 }
16739 
16740 static int
16741 test_cryptodev_cn10k(void)
16742 {
16743 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
16744 }
16745 
16746 static int
16747 test_cryptodev_dpaa2_sec_raw_api(void)
16748 {
16749 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
16750 	int ret;
16751 
16752 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16753 			"RAW API");
16754 	if (ret)
16755 		return ret;
16756 
16757 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16758 	ret = run_cryptodev_testsuite(pmd_name);
16759 	global_api_test_type = CRYPTODEV_API_TEST;
16760 
16761 	return ret;
16762 }
16763 
16764 static int
16765 test_cryptodev_dpaa_sec_raw_api(void)
16766 {
16767 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD);
16768 	int ret;
16769 
16770 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
16771 			"RAW API");
16772 	if (ret)
16773 		return ret;
16774 
16775 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
16776 	ret = run_cryptodev_testsuite(pmd_name);
16777 	global_api_test_type = CRYPTODEV_API_TEST;
16778 
16779 	return ret;
16780 }
16781 
16782 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
16783 		test_cryptodev_dpaa2_sec_raw_api);
16784 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
16785 		test_cryptodev_dpaa_sec_raw_api);
16786 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
16787 		test_cryptodev_qat_raw_api);
16788 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
16789 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
16790 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
16791 	test_cryptodev_cpu_aesni_mb);
16792 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest,
16793 	test_cryptodev_chacha_poly_mb);
16794 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
16795 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
16796 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
16797 	test_cryptodev_cpu_aesni_gcm);
16798 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
16799 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
16800 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
16801 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
16802 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
16803 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
16804 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
16805 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
16806 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
16807 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
16808 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
16809 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
16810 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
16811 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
16812 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
16813 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
16814 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
16815