xref: /dpdk/app/test/test_cryptodev.c (revision a16cbb9838ff67ad92cf74c23e2e95fa2fb242e1)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #include <time.h>
7 
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16 
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_ip.h>
20 #include <rte_string_fns.h>
21 #include <rte_tcp.h>
22 #include <rte_udp.h>
23 
24 #ifdef RTE_CRYPTO_SCHEDULER
25 #include <rte_cryptodev_scheduler.h>
26 #include <rte_cryptodev_scheduler_operations.h>
27 #endif
28 
29 #include <rte_lcore.h>
30 
31 #include "test.h"
32 #include "test_cryptodev.h"
33 
34 #include "test_cryptodev_blockcipher.h"
35 #include "test_cryptodev_aes_test_vectors.h"
36 #include "test_cryptodev_des_test_vectors.h"
37 #include "test_cryptodev_hash_test_vectors.h"
38 #include "test_cryptodev_kasumi_test_vectors.h"
39 #include "test_cryptodev_kasumi_hash_test_vectors.h"
40 #include "test_cryptodev_snow3g_test_vectors.h"
41 #include "test_cryptodev_snow3g_hash_test_vectors.h"
42 #include "test_cryptodev_zuc_test_vectors.h"
43 #include "test_cryptodev_aead_test_vectors.h"
44 #include "test_cryptodev_hmac_test_vectors.h"
45 #include "test_cryptodev_mixed_test_vectors.h"
46 #ifdef RTE_LIB_SECURITY
47 #include "test_cryptodev_security_ipsec.h"
48 #include "test_cryptodev_security_ipsec_test_vectors.h"
49 #include "test_cryptodev_security_pdcp_test_vectors.h"
50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_func.h"
52 #include "test_cryptodev_security_docsis_test_vectors.h"
53 
54 #define SDAP_DISABLED	0
55 #define SDAP_ENABLED	1
56 #endif
57 
58 #define VDEV_ARGS_SIZE 100
59 #define MAX_NB_SESSIONS 4
60 
61 #define MAX_DRV_SERVICE_CTX_SIZE 256
62 
63 #define MAX_RAW_DEQUEUE_COUNT	65535
64 
65 #define IN_PLACE 0
66 #define OUT_OF_PLACE 1
67 
68 static int gbl_driver_id;
69 
70 static enum rte_security_session_action_type gbl_action_type =
71 	RTE_SECURITY_ACTION_TYPE_NONE;
72 
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74 
75 struct crypto_unittest_params {
76 	struct rte_crypto_sym_xform cipher_xform;
77 	struct rte_crypto_sym_xform auth_xform;
78 	struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80 	struct rte_security_docsis_xform docsis_xform;
81 #endif
82 
83 	union {
84 		struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86 		struct rte_security_session *sec_session;
87 #endif
88 	};
89 #ifdef RTE_LIB_SECURITY
90 	enum rte_security_session_action_type type;
91 #endif
92 	struct rte_crypto_op *op;
93 
94 	struct rte_mbuf *obuf, *ibuf;
95 
96 	uint8_t *digest;
97 };
98 
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100 	(((num) + (align) - 1) & ~((align) - 1))
101 
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
103 	for (j = 0; j < num_child_ts; index++, j++)			\
104 		parent_ts.unit_test_suites[index] = child_ts[j]
105 
106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
107 	for (j = 0; j < num_blk_types; index++, j++)				\
108 		parent_ts.unit_test_suites[index] =				\
109 				build_blockcipher_test_suite(blk_types[j])
110 
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
112 	for (j = index; j < index + num_blk_types; j++)				\
113 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114 
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121 		uint8_t *hmac_key);
122 
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125 		struct crypto_unittest_params *ut_params,
126 		struct crypto_testsuite_params *ts_param,
127 		const uint8_t *cipher,
128 		const uint8_t *digest,
129 		const uint8_t *iv);
130 
131 static int
132 security_proto_supported(enum rte_security_session_action_type action,
133 	enum rte_security_session_protocol proto);
134 
135 static int
136 dev_configure_and_start(uint64_t ff_disable);
137 
138 static struct rte_mbuf *
139 setup_test_string(struct rte_mempool *mpool,
140 		const char *string, size_t len, uint8_t blocksize)
141 {
142 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
143 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
144 
145 	if (m) {
146 		char *dst;
147 
148 		memset(m->buf_addr, 0, m->buf_len);
149 		dst = rte_pktmbuf_append(m, t_len);
150 		if (!dst) {
151 			rte_pktmbuf_free(m);
152 			return NULL;
153 		}
154 		if (string != NULL)
155 			rte_memcpy(dst, string, t_len);
156 		else
157 			memset(dst, 0, t_len);
158 	}
159 
160 	return m;
161 }
162 
163 /* Get number of bytes in X bits (rounding up) */
164 static uint32_t
165 ceil_byte_length(uint32_t num_bits)
166 {
167 	if (num_bits % 8)
168 		return ((num_bits >> 3) + 1);
169 	else
170 		return (num_bits >> 3);
171 }
172 
173 static void
174 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
175 		uint8_t is_op_success)
176 {
177 	struct rte_crypto_op *op = user_data;
178 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
179 			RTE_CRYPTO_OP_STATUS_ERROR;
180 }
181 
182 void
183 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
184 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
185 		uint8_t len_in_bits, uint8_t cipher_iv_len)
186 {
187 	struct rte_crypto_sym_op *sop = op->sym;
188 	struct rte_crypto_op *ret_op = NULL;
189 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
190 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
191 	union rte_crypto_sym_ofs ofs;
192 	struct rte_crypto_sym_vec vec;
193 	struct rte_crypto_sgl sgl, dest_sgl;
194 	uint32_t max_len;
195 	union rte_cryptodev_session_ctx sess;
196 	uint32_t count = 0;
197 	struct rte_crypto_raw_dp_ctx *ctx;
198 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
199 			auth_len = 0;
200 	int32_t n;
201 	uint32_t n_success;
202 	int ctx_service_size;
203 	int32_t status = 0;
204 	int enqueue_status, dequeue_status;
205 
206 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
207 	if (ctx_service_size < 0) {
208 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
209 		return;
210 	}
211 
212 	ctx = malloc(ctx_service_size);
213 	if (!ctx) {
214 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
215 		return;
216 	}
217 
218 	/* Both are enums, setting crypto_sess will suit any session type */
219 	sess.crypto_sess = op->sym->session;
220 
221 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
222 			op->sess_type, sess, 0) < 0) {
223 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
224 		goto exit;
225 	}
226 
227 	cipher_iv.iova = 0;
228 	cipher_iv.va = NULL;
229 	aad_auth_iv.iova = 0;
230 	aad_auth_iv.va = NULL;
231 	digest.iova = 0;
232 	digest.va = NULL;
233 	sgl.vec = data_vec;
234 	vec.num = 1;
235 	vec.src_sgl = &sgl;
236 	vec.iv = &cipher_iv;
237 	vec.digest = &digest;
238 	vec.aad = &aad_auth_iv;
239 	vec.status = &status;
240 
241 	ofs.raw = 0;
242 
243 	if (is_cipher && is_auth) {
244 		cipher_offset = sop->cipher.data.offset;
245 		cipher_len = sop->cipher.data.length;
246 		auth_offset = sop->auth.data.offset;
247 		auth_len = sop->auth.data.length;
248 		max_len = RTE_MAX(cipher_offset + cipher_len,
249 				auth_offset + auth_len);
250 		if (len_in_bits) {
251 			max_len = max_len >> 3;
252 			cipher_offset = cipher_offset >> 3;
253 			auth_offset = auth_offset >> 3;
254 			cipher_len = cipher_len >> 3;
255 			auth_len = auth_len >> 3;
256 		}
257 		ofs.ofs.cipher.head = cipher_offset;
258 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
259 		ofs.ofs.auth.head = auth_offset;
260 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
261 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
262 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
263 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
264 				op, void *, IV_OFFSET + cipher_iv_len);
265 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
266 				cipher_iv_len);
267 		digest.va = (void *)sop->auth.digest.data;
268 		digest.iova = sop->auth.digest.phys_addr;
269 
270 	} else if (is_cipher) {
271 		cipher_offset = sop->cipher.data.offset;
272 		cipher_len = sop->cipher.data.length;
273 		max_len = cipher_len + cipher_offset;
274 		if (len_in_bits) {
275 			max_len = max_len >> 3;
276 			cipher_offset = cipher_offset >> 3;
277 			cipher_len = cipher_len >> 3;
278 		}
279 		ofs.ofs.cipher.head = cipher_offset;
280 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
281 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
282 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
283 
284 	} else if (is_auth) {
285 		auth_offset = sop->auth.data.offset;
286 		auth_len = sop->auth.data.length;
287 		max_len = auth_len + auth_offset;
288 		if (len_in_bits) {
289 			max_len = max_len >> 3;
290 			auth_offset = auth_offset >> 3;
291 			auth_len = auth_len >> 3;
292 		}
293 		ofs.ofs.auth.head = auth_offset;
294 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
295 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
296 				op, void *, IV_OFFSET + cipher_iv_len);
297 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
298 				cipher_iv_len);
299 		digest.va = (void *)sop->auth.digest.data;
300 		digest.iova = sop->auth.digest.phys_addr;
301 
302 	} else { /* aead */
303 		cipher_offset = sop->aead.data.offset;
304 		cipher_len = sop->aead.data.length;
305 		max_len = cipher_len + cipher_offset;
306 		if (len_in_bits) {
307 			max_len = max_len >> 3;
308 			cipher_offset = cipher_offset >> 3;
309 			cipher_len = cipher_len >> 3;
310 		}
311 		ofs.ofs.cipher.head = cipher_offset;
312 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
313 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
314 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
315 		aad_auth_iv.va = (void *)sop->aead.aad.data;
316 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
317 		digest.va = (void *)sop->aead.digest.data;
318 		digest.iova = sop->aead.digest.phys_addr;
319 	}
320 
321 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
322 			data_vec, RTE_DIM(data_vec));
323 	if (n < 0 || n > sop->m_src->nb_segs) {
324 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
325 		goto exit;
326 	}
327 
328 	sgl.num = n;
329 	/* Out of place */
330 	if (sop->m_dst != NULL) {
331 		dest_sgl.vec = dest_data_vec;
332 		vec.dest_sgl = &dest_sgl;
333 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
334 				dest_data_vec, RTE_DIM(dest_data_vec));
335 		if (n < 0 || n > sop->m_dst->nb_segs) {
336 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
337 			goto exit;
338 		}
339 		dest_sgl.num = n;
340 	} else
341 		vec.dest_sgl = NULL;
342 
343 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
344 			&enqueue_status) < 1) {
345 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
346 		goto exit;
347 	}
348 
349 	if (enqueue_status == 0) {
350 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
351 		if (status < 0) {
352 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
353 			goto exit;
354 		}
355 	} else if (enqueue_status < 0) {
356 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
357 		goto exit;
358 	}
359 
360 	n = n_success = 0;
361 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
362 		n = rte_cryptodev_raw_dequeue_burst(ctx,
363 			NULL, 1, post_process_raw_dp_op,
364 				(void **)&ret_op, 0, &n_success,
365 				&dequeue_status);
366 		if (dequeue_status < 0) {
367 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
368 			goto exit;
369 		}
370 		if (n == 0)
371 			rte_pause();
372 	}
373 
374 	if (n == 1 && dequeue_status == 0) {
375 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
376 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
377 			goto exit;
378 		}
379 	}
380 
381 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
382 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
383 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
384 					RTE_CRYPTO_OP_STATUS_SUCCESS;
385 
386 exit:
387 	free(ctx);
388 }
389 
390 static void
391 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
392 {
393 	int32_t n, st;
394 	struct rte_crypto_sym_op *sop;
395 	union rte_crypto_sym_ofs ofs;
396 	struct rte_crypto_sgl sgl;
397 	struct rte_crypto_sym_vec symvec;
398 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
399 	struct rte_crypto_vec vec[UINT8_MAX];
400 
401 	sop = op->sym;
402 
403 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
404 		sop->aead.data.length, vec, RTE_DIM(vec));
405 
406 	if (n < 0 || n != sop->m_src->nb_segs) {
407 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
408 		return;
409 	}
410 
411 	sgl.vec = vec;
412 	sgl.num = n;
413 	symvec.src_sgl = &sgl;
414 	symvec.iv = &iv_ptr;
415 	symvec.digest = &digest_ptr;
416 	symvec.aad = &aad_ptr;
417 	symvec.status = &st;
418 	symvec.num = 1;
419 
420 	/* for CPU crypto the IOVA address is not required */
421 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
422 	digest_ptr.va = (void *)sop->aead.digest.data;
423 	aad_ptr.va = (void *)sop->aead.aad.data;
424 
425 	ofs.raw = 0;
426 
427 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
428 		&symvec);
429 
430 	if (n != 1)
431 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
432 	else
433 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
434 }
435 
436 static void
437 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
438 {
439 	int32_t n, st;
440 	struct rte_crypto_sym_op *sop;
441 	union rte_crypto_sym_ofs ofs;
442 	struct rte_crypto_sgl sgl;
443 	struct rte_crypto_sym_vec symvec;
444 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
445 	struct rte_crypto_vec vec[UINT8_MAX];
446 
447 	sop = op->sym;
448 
449 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
450 		sop->auth.data.length, vec, RTE_DIM(vec));
451 
452 	if (n < 0 || n != sop->m_src->nb_segs) {
453 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
454 		return;
455 	}
456 
457 	sgl.vec = vec;
458 	sgl.num = n;
459 	symvec.src_sgl = &sgl;
460 	symvec.iv = &iv_ptr;
461 	symvec.digest = &digest_ptr;
462 	symvec.status = &st;
463 	symvec.num = 1;
464 
465 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
466 	digest_ptr.va = (void *)sop->auth.digest.data;
467 
468 	ofs.raw = 0;
469 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
470 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
471 		(sop->cipher.data.offset + sop->cipher.data.length);
472 
473 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
474 		&symvec);
475 
476 	if (n != 1)
477 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
478 	else
479 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
480 }
481 
482 static struct rte_crypto_op *
483 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
484 {
485 
486 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
487 
488 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
489 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
490 		return NULL;
491 	}
492 
493 	op = NULL;
494 
495 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
496 		rte_pause();
497 
498 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
499 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
500 		return NULL;
501 	}
502 
503 	return op;
504 }
505 
506 static struct crypto_testsuite_params testsuite_params = { NULL };
507 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
508 static struct crypto_unittest_params unittest_params;
509 
510 static int
511 testsuite_setup(void)
512 {
513 	struct crypto_testsuite_params *ts_params = &testsuite_params;
514 	struct rte_cryptodev_info info;
515 	uint32_t i = 0, nb_devs, dev_id;
516 	uint16_t qp_id;
517 
518 	memset(ts_params, 0, sizeof(*ts_params));
519 
520 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
521 	if (ts_params->mbuf_pool == NULL) {
522 		/* Not already created so create */
523 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
524 				"CRYPTO_MBUFPOOL",
525 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
526 				rte_socket_id());
527 		if (ts_params->mbuf_pool == NULL) {
528 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
529 			return TEST_FAILED;
530 		}
531 	}
532 
533 	ts_params->large_mbuf_pool = rte_mempool_lookup(
534 			"CRYPTO_LARGE_MBUFPOOL");
535 	if (ts_params->large_mbuf_pool == NULL) {
536 		/* Not already created so create */
537 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
538 				"CRYPTO_LARGE_MBUFPOOL",
539 				1, 0, 0, UINT16_MAX,
540 				rte_socket_id());
541 		if (ts_params->large_mbuf_pool == NULL) {
542 			RTE_LOG(ERR, USER1,
543 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
544 			return TEST_FAILED;
545 		}
546 	}
547 
548 	ts_params->op_mpool = rte_crypto_op_pool_create(
549 			"MBUF_CRYPTO_SYM_OP_POOL",
550 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
551 			NUM_MBUFS, MBUF_CACHE_SIZE,
552 			DEFAULT_NUM_XFORMS *
553 			sizeof(struct rte_crypto_sym_xform) +
554 			MAXIMUM_IV_LENGTH,
555 			rte_socket_id());
556 	if (ts_params->op_mpool == NULL) {
557 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
558 		return TEST_FAILED;
559 	}
560 
561 	nb_devs = rte_cryptodev_count();
562 	if (nb_devs < 1) {
563 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
564 		return TEST_SKIPPED;
565 	}
566 
567 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
568 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
569 				rte_cryptodev_driver_name_get(gbl_driver_id));
570 		return TEST_SKIPPED;
571 	}
572 
573 	/* Create list of valid crypto devs */
574 	for (i = 0; i < nb_devs; i++) {
575 		rte_cryptodev_info_get(i, &info);
576 		if (info.driver_id == gbl_driver_id)
577 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
578 	}
579 
580 	if (ts_params->valid_dev_count < 1)
581 		return TEST_FAILED;
582 
583 	/* Set up all the qps on the first of the valid devices found */
584 
585 	dev_id = ts_params->valid_devs[0];
586 
587 	rte_cryptodev_info_get(dev_id, &info);
588 
589 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
590 	ts_params->conf.socket_id = SOCKET_ID_ANY;
591 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
592 
593 	unsigned int session_size =
594 		rte_cryptodev_sym_get_private_session_size(dev_id);
595 
596 #ifdef RTE_LIB_SECURITY
597 	unsigned int security_session_size = rte_security_session_get_size(
598 			rte_cryptodev_get_sec_ctx(dev_id));
599 
600 	if (session_size < security_session_size)
601 		session_size = security_session_size;
602 #endif
603 	/*
604 	 * Create mempool with maximum number of sessions.
605 	 */
606 	if (info.sym.max_nb_sessions != 0 &&
607 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
608 		RTE_LOG(ERR, USER1, "Device does not support "
609 				"at least %u sessions\n",
610 				MAX_NB_SESSIONS);
611 		return TEST_FAILED;
612 	}
613 
614 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
615 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
616 			SOCKET_ID_ANY);
617 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
618 			"session mempool allocation failed");
619 
620 	ts_params->session_priv_mpool = rte_mempool_create(
621 			"test_sess_mp_priv",
622 			MAX_NB_SESSIONS,
623 			session_size,
624 			0, 0, NULL, NULL, NULL,
625 			NULL, SOCKET_ID_ANY,
626 			0);
627 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
628 			"session mempool allocation failed");
629 
630 
631 
632 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
633 			&ts_params->conf),
634 			"Failed to configure cryptodev %u with %u qps",
635 			dev_id, ts_params->conf.nb_queue_pairs);
636 
637 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
638 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
639 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
640 
641 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
642 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
643 			dev_id, qp_id, &ts_params->qp_conf,
644 			rte_cryptodev_socket_id(dev_id)),
645 			"Failed to setup queue pair %u on cryptodev %u",
646 			qp_id, dev_id);
647 	}
648 
649 	return TEST_SUCCESS;
650 }
651 
652 static void
653 testsuite_teardown(void)
654 {
655 	struct crypto_testsuite_params *ts_params = &testsuite_params;
656 	int res;
657 
658 	if (ts_params->mbuf_pool != NULL) {
659 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
660 		rte_mempool_avail_count(ts_params->mbuf_pool));
661 	}
662 
663 	if (ts_params->op_mpool != NULL) {
664 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
665 		rte_mempool_avail_count(ts_params->op_mpool));
666 	}
667 
668 	/* Free session mempools */
669 	if (ts_params->session_priv_mpool != NULL) {
670 		rte_mempool_free(ts_params->session_priv_mpool);
671 		ts_params->session_priv_mpool = NULL;
672 	}
673 
674 	if (ts_params->session_mpool != NULL) {
675 		rte_mempool_free(ts_params->session_mpool);
676 		ts_params->session_mpool = NULL;
677 	}
678 
679 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
680 	if (res)
681 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
682 }
683 
684 static int
685 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
686 		const int *algs, uint16_t num_algs)
687 {
688 	uint8_t dev_id = testsuite_params.valid_devs[0];
689 	bool some_alg_supported = FALSE;
690 	uint16_t i;
691 
692 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
693 		struct rte_cryptodev_sym_capability_idx alg = {
694 			type, {algs[i]}
695 		};
696 		if (rte_cryptodev_sym_capability_get(dev_id,
697 				&alg) != NULL)
698 			some_alg_supported = TRUE;
699 	}
700 	if (!some_alg_supported)
701 		return TEST_SKIPPED;
702 
703 	return 0;
704 }
705 
706 int
707 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
708 		uint16_t num_ciphers)
709 {
710 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
711 			(const int *) ciphers, num_ciphers);
712 }
713 
714 int
715 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
716 		uint16_t num_auths)
717 {
718 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
719 			(const int *) auths, num_auths);
720 }
721 
722 int
723 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
724 		uint16_t num_aeads)
725 {
726 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
727 			(const int *) aeads, num_aeads);
728 }
729 
730 static int
731 null_testsuite_setup(void)
732 {
733 	struct crypto_testsuite_params *ts_params = &testsuite_params;
734 	uint8_t dev_id = ts_params->valid_devs[0];
735 	struct rte_cryptodev_info dev_info;
736 	const enum rte_crypto_cipher_algorithm ciphers[] = {
737 		RTE_CRYPTO_CIPHER_NULL
738 	};
739 	const enum rte_crypto_auth_algorithm auths[] = {
740 		RTE_CRYPTO_AUTH_NULL
741 	};
742 
743 	rte_cryptodev_info_get(dev_id, &dev_info);
744 
745 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
746 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
747 				"testsuite not met\n");
748 		return TEST_SKIPPED;
749 	}
750 
751 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
752 			&& check_auth_capabilities_supported(auths,
753 			RTE_DIM(auths)) != 0) {
754 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
755 				"testsuite not met\n");
756 		return TEST_SKIPPED;
757 	}
758 
759 	return 0;
760 }
761 
762 static int
763 crypto_gen_testsuite_setup(void)
764 {
765 	struct crypto_testsuite_params *ts_params = &testsuite_params;
766 	uint8_t dev_id = ts_params->valid_devs[0];
767 	struct rte_cryptodev_info dev_info;
768 
769 	rte_cryptodev_info_get(dev_id, &dev_info);
770 
771 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
772 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
773 				"testsuite not met\n");
774 		return TEST_SKIPPED;
775 	}
776 
777 	return 0;
778 }
779 
780 #ifdef RTE_LIB_SECURITY
781 static int
782 ipsec_proto_testsuite_setup(void)
783 {
784 	struct crypto_testsuite_params *ts_params = &testsuite_params;
785 	struct crypto_unittest_params *ut_params = &unittest_params;
786 	struct rte_cryptodev_info dev_info;
787 	int ret = 0;
788 
789 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
790 
791 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
792 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
793 				"testsuite not met\n");
794 		return TEST_SKIPPED;
795 	}
796 
797 	/* Reconfigure to enable security */
798 	ret = dev_configure_and_start(0);
799 	if (ret != TEST_SUCCESS)
800 		return ret;
801 
802 	/* Set action type */
803 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
804 
805 	if (security_proto_supported(
806 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
807 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
808 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
809 				"test not met\n");
810 		ret = TEST_SKIPPED;
811 	}
812 
813 	/*
814 	 * Stop the device. Device would be started again by individual test
815 	 * case setup routine.
816 	 */
817 	rte_cryptodev_stop(ts_params->valid_devs[0]);
818 
819 	return ret;
820 }
821 
822 static int
823 pdcp_proto_testsuite_setup(void)
824 {
825 	struct crypto_testsuite_params *ts_params = &testsuite_params;
826 	uint8_t dev_id = ts_params->valid_devs[0];
827 	struct rte_cryptodev_info dev_info;
828 	const enum rte_crypto_cipher_algorithm ciphers[] = {
829 		RTE_CRYPTO_CIPHER_NULL,
830 		RTE_CRYPTO_CIPHER_AES_CTR,
831 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
832 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
833 	};
834 	const enum rte_crypto_auth_algorithm auths[] = {
835 		RTE_CRYPTO_AUTH_NULL,
836 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
837 		RTE_CRYPTO_AUTH_AES_CMAC,
838 		RTE_CRYPTO_AUTH_ZUC_EIA3
839 	};
840 
841 	rte_cryptodev_info_get(dev_id, &dev_info);
842 
843 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
844 			!(dev_info.feature_flags &
845 			RTE_CRYPTODEV_FF_SECURITY)) {
846 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
847 				"testsuite not met\n");
848 		return TEST_SKIPPED;
849 	}
850 
851 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
852 			&& check_auth_capabilities_supported(auths,
853 			RTE_DIM(auths)) != 0) {
854 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
855 				"testsuite not met\n");
856 		return TEST_SKIPPED;
857 	}
858 
859 	return 0;
860 }
861 
862 static int
863 docsis_proto_testsuite_setup(void)
864 {
865 	struct crypto_testsuite_params *ts_params = &testsuite_params;
866 	uint8_t dev_id = ts_params->valid_devs[0];
867 	struct rte_cryptodev_info dev_info;
868 	const enum rte_crypto_cipher_algorithm ciphers[] = {
869 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
870 	};
871 
872 	rte_cryptodev_info_get(dev_id, &dev_info);
873 
874 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
875 			!(dev_info.feature_flags &
876 			RTE_CRYPTODEV_FF_SECURITY)) {
877 		RTE_LOG(INFO, USER1, "Feature flag requirements for Docsis "
878 				"Proto testsuite not met\n");
879 		return TEST_SKIPPED;
880 	}
881 
882 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
883 		RTE_LOG(INFO, USER1, "Capability requirements for Docsis Proto "
884 				"testsuite not met\n");
885 		return TEST_SKIPPED;
886 	}
887 
888 	return 0;
889 }
890 #endif
891 
892 static int
893 aes_ccm_auth_testsuite_setup(void)
894 {
895 	struct crypto_testsuite_params *ts_params = &testsuite_params;
896 	uint8_t dev_id = ts_params->valid_devs[0];
897 	struct rte_cryptodev_info dev_info;
898 	const enum rte_crypto_aead_algorithm aeads[] = {
899 		RTE_CRYPTO_AEAD_AES_CCM
900 	};
901 
902 	rte_cryptodev_info_get(dev_id, &dev_info);
903 
904 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
905 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
906 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
907 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
908 				"testsuite not met\n");
909 		return TEST_SKIPPED;
910 	}
911 
912 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
913 		RTE_LOG(INFO, USER1, "Capability requirements for AES CCM "
914 				"testsuite not met\n");
915 		return TEST_SKIPPED;
916 	}
917 
918 	return 0;
919 }
920 
921 static int
922 aes_gcm_auth_testsuite_setup(void)
923 {
924 	struct crypto_testsuite_params *ts_params = &testsuite_params;
925 	uint8_t dev_id = ts_params->valid_devs[0];
926 	struct rte_cryptodev_info dev_info;
927 	const enum rte_crypto_aead_algorithm aeads[] = {
928 		RTE_CRYPTO_AEAD_AES_GCM
929 	};
930 
931 	rte_cryptodev_info_get(dev_id, &dev_info);
932 
933 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
934 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
935 				"testsuite not met\n");
936 		return TEST_SKIPPED;
937 	}
938 
939 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
940 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
941 				"testsuite not met\n");
942 		return TEST_SKIPPED;
943 	}
944 
945 	return 0;
946 }
947 
948 static int
949 aes_gmac_auth_testsuite_setup(void)
950 {
951 	struct crypto_testsuite_params *ts_params = &testsuite_params;
952 	uint8_t dev_id = ts_params->valid_devs[0];
953 	struct rte_cryptodev_info dev_info;
954 	const enum rte_crypto_auth_algorithm auths[] = {
955 		RTE_CRYPTO_AUTH_AES_GMAC
956 	};
957 
958 	rte_cryptodev_info_get(dev_id, &dev_info);
959 
960 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
961 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
962 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
963 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
964 				"testsuite not met\n");
965 		return TEST_SKIPPED;
966 	}
967 
968 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
969 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
970 				"testsuite not met\n");
971 		return TEST_SKIPPED;
972 	}
973 
974 	return 0;
975 }
976 
977 static int
978 chacha20_poly1305_testsuite_setup(void)
979 {
980 	struct crypto_testsuite_params *ts_params = &testsuite_params;
981 	uint8_t dev_id = ts_params->valid_devs[0];
982 	struct rte_cryptodev_info dev_info;
983 	const enum rte_crypto_aead_algorithm aeads[] = {
984 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
985 	};
986 
987 	rte_cryptodev_info_get(dev_id, &dev_info);
988 
989 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
990 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
991 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
992 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
993 				"Chacha20-Poly1305 testsuite not met\n");
994 		return TEST_SKIPPED;
995 	}
996 
997 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
998 		RTE_LOG(INFO, USER1, "Capability requirements for "
999 				"Chacha20-Poly1305 testsuite not met\n");
1000 		return TEST_SKIPPED;
1001 	}
1002 
1003 	return 0;
1004 }
1005 
1006 static int
1007 snow3g_testsuite_setup(void)
1008 {
1009 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1010 	uint8_t dev_id = ts_params->valid_devs[0];
1011 	struct rte_cryptodev_info dev_info;
1012 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1013 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1014 
1015 	};
1016 	const enum rte_crypto_auth_algorithm auths[] = {
1017 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1018 	};
1019 
1020 	rte_cryptodev_info_get(dev_id, &dev_info);
1021 
1022 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1023 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1024 				"testsuite not met\n");
1025 		return TEST_SKIPPED;
1026 	}
1027 
1028 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1029 			&& check_auth_capabilities_supported(auths,
1030 			RTE_DIM(auths)) != 0) {
1031 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1032 				"testsuite not met\n");
1033 		return TEST_SKIPPED;
1034 	}
1035 
1036 	return 0;
1037 }
1038 
1039 static int
1040 zuc_testsuite_setup(void)
1041 {
1042 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1043 	uint8_t dev_id = ts_params->valid_devs[0];
1044 	struct rte_cryptodev_info dev_info;
1045 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1046 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1047 	};
1048 	const enum rte_crypto_auth_algorithm auths[] = {
1049 		RTE_CRYPTO_AUTH_ZUC_EIA3
1050 	};
1051 
1052 	rte_cryptodev_info_get(dev_id, &dev_info);
1053 
1054 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1055 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1056 				"testsuite not met\n");
1057 		return TEST_SKIPPED;
1058 	}
1059 
1060 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1061 			&& check_auth_capabilities_supported(auths,
1062 			RTE_DIM(auths)) != 0) {
1063 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1064 				"testsuite not met\n");
1065 		return TEST_SKIPPED;
1066 	}
1067 
1068 	return 0;
1069 }
1070 
1071 static int
1072 hmac_md5_auth_testsuite_setup(void)
1073 {
1074 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1075 	uint8_t dev_id = ts_params->valid_devs[0];
1076 	struct rte_cryptodev_info dev_info;
1077 	const enum rte_crypto_auth_algorithm auths[] = {
1078 		RTE_CRYPTO_AUTH_MD5_HMAC
1079 	};
1080 
1081 	rte_cryptodev_info_get(dev_id, &dev_info);
1082 
1083 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1084 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1085 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1086 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1087 				"Auth testsuite not met\n");
1088 		return TEST_SKIPPED;
1089 	}
1090 
1091 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1092 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1093 				"testsuite not met\n");
1094 		return TEST_SKIPPED;
1095 	}
1096 
1097 	return 0;
1098 }
1099 
1100 static int
1101 kasumi_testsuite_setup(void)
1102 {
1103 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1104 	uint8_t dev_id = ts_params->valid_devs[0];
1105 	struct rte_cryptodev_info dev_info;
1106 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1107 		RTE_CRYPTO_CIPHER_KASUMI_F8
1108 	};
1109 	const enum rte_crypto_auth_algorithm auths[] = {
1110 		RTE_CRYPTO_AUTH_KASUMI_F9
1111 	};
1112 
1113 	rte_cryptodev_info_get(dev_id, &dev_info);
1114 
1115 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1116 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1117 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1118 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1119 				"testsuite not met\n");
1120 		return TEST_SKIPPED;
1121 	}
1122 
1123 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1124 			&& check_auth_capabilities_supported(auths,
1125 			RTE_DIM(auths)) != 0) {
1126 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1127 				"testsuite not met\n");
1128 		return TEST_SKIPPED;
1129 	}
1130 
1131 	return 0;
1132 }
1133 
1134 static int
1135 negative_aes_gcm_testsuite_setup(void)
1136 {
1137 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1138 	uint8_t dev_id = ts_params->valid_devs[0];
1139 	struct rte_cryptodev_info dev_info;
1140 	const enum rte_crypto_aead_algorithm aeads[] = {
1141 		RTE_CRYPTO_AEAD_AES_GCM
1142 	};
1143 
1144 	rte_cryptodev_info_get(dev_id, &dev_info);
1145 
1146 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1147 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1148 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1149 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1150 				"AES GCM testsuite not met\n");
1151 		return TEST_SKIPPED;
1152 	}
1153 
1154 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1155 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1156 				"AES GCM testsuite not met\n");
1157 		return TEST_SKIPPED;
1158 	}
1159 
1160 	return 0;
1161 }
1162 
1163 static int
1164 negative_aes_gmac_testsuite_setup(void)
1165 {
1166 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1167 	uint8_t dev_id = ts_params->valid_devs[0];
1168 	struct rte_cryptodev_info dev_info;
1169 	const enum rte_crypto_auth_algorithm auths[] = {
1170 		RTE_CRYPTO_AUTH_AES_GMAC
1171 	};
1172 
1173 	rte_cryptodev_info_get(dev_id, &dev_info);
1174 
1175 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1176 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1177 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1178 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1179 				"AES GMAC testsuite not met\n");
1180 		return TEST_SKIPPED;
1181 	}
1182 
1183 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1184 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1185 				"AES GMAC testsuite not met\n");
1186 		return TEST_SKIPPED;
1187 	}
1188 
1189 	return 0;
1190 }
1191 
1192 static int
1193 mixed_cipher_hash_testsuite_setup(void)
1194 {
1195 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1196 	uint8_t dev_id = ts_params->valid_devs[0];
1197 	struct rte_cryptodev_info dev_info;
1198 	uint64_t feat_flags;
1199 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1200 		RTE_CRYPTO_CIPHER_NULL,
1201 		RTE_CRYPTO_CIPHER_AES_CTR,
1202 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1203 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1204 	};
1205 	const enum rte_crypto_auth_algorithm auths[] = {
1206 		RTE_CRYPTO_AUTH_NULL,
1207 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1208 		RTE_CRYPTO_AUTH_AES_CMAC,
1209 		RTE_CRYPTO_AUTH_ZUC_EIA3
1210 	};
1211 
1212 	rte_cryptodev_info_get(dev_id, &dev_info);
1213 	feat_flags = dev_info.feature_flags;
1214 
1215 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1216 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1217 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1218 				"Cipher Hash testsuite not met\n");
1219 		return TEST_SKIPPED;
1220 	}
1221 
1222 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1223 			&& check_auth_capabilities_supported(auths,
1224 			RTE_DIM(auths)) != 0) {
1225 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1226 				"Cipher Hash testsuite not met\n");
1227 		return TEST_SKIPPED;
1228 	}
1229 
1230 	return 0;
1231 }
1232 
1233 static int
1234 esn_testsuite_setup(void)
1235 {
1236 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1237 	uint8_t dev_id = ts_params->valid_devs[0];
1238 	struct rte_cryptodev_info dev_info;
1239 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1240 		RTE_CRYPTO_CIPHER_AES_CBC
1241 	};
1242 	const enum rte_crypto_auth_algorithm auths[] = {
1243 		RTE_CRYPTO_AUTH_SHA1_HMAC
1244 	};
1245 
1246 	rte_cryptodev_info_get(dev_id, &dev_info);
1247 
1248 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1249 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1250 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1251 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1252 				"testsuite not met\n");
1253 		return TEST_SKIPPED;
1254 	}
1255 
1256 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1257 			&& check_auth_capabilities_supported(auths,
1258 			RTE_DIM(auths)) != 0) {
1259 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1260 				"testsuite not met\n");
1261 		return TEST_SKIPPED;
1262 	}
1263 
1264 	return 0;
1265 }
1266 
1267 static int
1268 multi_session_testsuite_setup(void)
1269 {
1270 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1271 	uint8_t dev_id = ts_params->valid_devs[0];
1272 	struct rte_cryptodev_info dev_info;
1273 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1274 		RTE_CRYPTO_CIPHER_AES_CBC
1275 	};
1276 	const enum rte_crypto_auth_algorithm auths[] = {
1277 		RTE_CRYPTO_AUTH_SHA512_HMAC
1278 	};
1279 
1280 	rte_cryptodev_info_get(dev_id, &dev_info);
1281 
1282 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1283 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1284 				"Session testsuite not met\n");
1285 		return TEST_SKIPPED;
1286 	}
1287 
1288 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1289 			&& check_auth_capabilities_supported(auths,
1290 			RTE_DIM(auths)) != 0) {
1291 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1292 				"Session testsuite not met\n");
1293 		return TEST_SKIPPED;
1294 	}
1295 
1296 	return 0;
1297 }
1298 
1299 static int
1300 negative_hmac_sha1_testsuite_setup(void)
1301 {
1302 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1303 	uint8_t dev_id = ts_params->valid_devs[0];
1304 	struct rte_cryptodev_info dev_info;
1305 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1306 		RTE_CRYPTO_CIPHER_AES_CBC
1307 	};
1308 	const enum rte_crypto_auth_algorithm auths[] = {
1309 		RTE_CRYPTO_AUTH_SHA1_HMAC
1310 	};
1311 
1312 	rte_cryptodev_info_get(dev_id, &dev_info);
1313 
1314 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1315 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1316 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1317 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1318 				"HMAC SHA1 testsuite not met\n");
1319 		return TEST_SKIPPED;
1320 	}
1321 
1322 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1323 			&& check_auth_capabilities_supported(auths,
1324 			RTE_DIM(auths)) != 0) {
1325 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1326 				"HMAC SHA1 testsuite not met\n");
1327 		return TEST_SKIPPED;
1328 	}
1329 
1330 	return 0;
1331 }
1332 
1333 static int
1334 dev_configure_and_start(uint64_t ff_disable)
1335 {
1336 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1337 	struct crypto_unittest_params *ut_params = &unittest_params;
1338 
1339 	uint16_t qp_id;
1340 
1341 	/* Clear unit test parameters before running test */
1342 	memset(ut_params, 0, sizeof(*ut_params));
1343 
1344 	/* Reconfigure device to default parameters */
1345 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1346 	ts_params->conf.ff_disable = ff_disable;
1347 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1348 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1349 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1350 
1351 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1352 			&ts_params->conf),
1353 			"Failed to configure cryptodev %u",
1354 			ts_params->valid_devs[0]);
1355 
1356 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1357 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1358 			ts_params->valid_devs[0], qp_id,
1359 			&ts_params->qp_conf,
1360 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1361 			"Failed to setup queue pair %u on cryptodev %u",
1362 			qp_id, ts_params->valid_devs[0]);
1363 	}
1364 
1365 
1366 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1367 
1368 	/* Start the device */
1369 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1370 			"Failed to start cryptodev %u",
1371 			ts_params->valid_devs[0]);
1372 
1373 	return TEST_SUCCESS;
1374 }
1375 
1376 int
1377 ut_setup(void)
1378 {
1379 	/* Configure and start the device with security feature disabled */
1380 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1381 }
1382 
1383 static int
1384 ut_setup_security(void)
1385 {
1386 	/* Configure and start the device with no features disabled */
1387 	return dev_configure_and_start(0);
1388 }
1389 
1390 void
1391 ut_teardown(void)
1392 {
1393 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1394 	struct crypto_unittest_params *ut_params = &unittest_params;
1395 	struct rte_cryptodev_stats stats;
1396 
1397 	/* free crypto session structure */
1398 #ifdef RTE_LIB_SECURITY
1399 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1400 		if (ut_params->sec_session) {
1401 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1402 						(ts_params->valid_devs[0]),
1403 						ut_params->sec_session);
1404 			ut_params->sec_session = NULL;
1405 		}
1406 	} else
1407 #endif
1408 	{
1409 		if (ut_params->sess) {
1410 			rte_cryptodev_sym_session_clear(
1411 					ts_params->valid_devs[0],
1412 					ut_params->sess);
1413 			rte_cryptodev_sym_session_free(ut_params->sess);
1414 			ut_params->sess = NULL;
1415 		}
1416 	}
1417 
1418 	/* free crypto operation structure */
1419 	if (ut_params->op)
1420 		rte_crypto_op_free(ut_params->op);
1421 
1422 	/*
1423 	 * free mbuf - both obuf and ibuf are usually the same,
1424 	 * so check if they point at the same address is necessary,
1425 	 * to avoid freeing the mbuf twice.
1426 	 */
1427 	if (ut_params->obuf) {
1428 		rte_pktmbuf_free(ut_params->obuf);
1429 		if (ut_params->ibuf == ut_params->obuf)
1430 			ut_params->ibuf = 0;
1431 		ut_params->obuf = 0;
1432 	}
1433 	if (ut_params->ibuf) {
1434 		rte_pktmbuf_free(ut_params->ibuf);
1435 		ut_params->ibuf = 0;
1436 	}
1437 
1438 	if (ts_params->mbuf_pool != NULL)
1439 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1440 			rte_mempool_avail_count(ts_params->mbuf_pool));
1441 
1442 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1443 
1444 	/* Stop the device */
1445 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1446 }
1447 
1448 static int
1449 test_device_configure_invalid_dev_id(void)
1450 {
1451 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1452 	uint16_t dev_id, num_devs = 0;
1453 
1454 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1455 			"Need at least %d devices for test", 1);
1456 
1457 	/* valid dev_id values */
1458 	dev_id = ts_params->valid_devs[0];
1459 
1460 	/* Stop the device in case it's started so it can be configured */
1461 	rte_cryptodev_stop(dev_id);
1462 
1463 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1464 			"Failed test for rte_cryptodev_configure: "
1465 			"invalid dev_num %u", dev_id);
1466 
1467 	/* invalid dev_id values */
1468 	dev_id = num_devs;
1469 
1470 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1471 			"Failed test for rte_cryptodev_configure: "
1472 			"invalid dev_num %u", dev_id);
1473 
1474 	dev_id = 0xff;
1475 
1476 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1477 			"Failed test for rte_cryptodev_configure:"
1478 			"invalid dev_num %u", dev_id);
1479 
1480 	return TEST_SUCCESS;
1481 }
1482 
1483 static int
1484 test_device_configure_invalid_queue_pair_ids(void)
1485 {
1486 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1487 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1488 
1489 	/* Stop the device in case it's started so it can be configured */
1490 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1491 
1492 	/* valid - max value queue pairs */
1493 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1494 
1495 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1496 			&ts_params->conf),
1497 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1498 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1499 
1500 	/* valid - one queue pairs */
1501 	ts_params->conf.nb_queue_pairs = 1;
1502 
1503 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1504 			&ts_params->conf),
1505 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1506 			ts_params->valid_devs[0],
1507 			ts_params->conf.nb_queue_pairs);
1508 
1509 
1510 	/* invalid - zero queue pairs */
1511 	ts_params->conf.nb_queue_pairs = 0;
1512 
1513 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1514 			&ts_params->conf),
1515 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1516 			" invalid qps: %u",
1517 			ts_params->valid_devs[0],
1518 			ts_params->conf.nb_queue_pairs);
1519 
1520 
1521 	/* invalid - max value supported by field queue pairs */
1522 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1523 
1524 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1525 			&ts_params->conf),
1526 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1527 			" invalid qps: %u",
1528 			ts_params->valid_devs[0],
1529 			ts_params->conf.nb_queue_pairs);
1530 
1531 
1532 	/* invalid - max value + 1 queue pairs */
1533 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1534 
1535 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1536 			&ts_params->conf),
1537 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1538 			" invalid qps: %u",
1539 			ts_params->valid_devs[0],
1540 			ts_params->conf.nb_queue_pairs);
1541 
1542 	/* revert to original testsuite value */
1543 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1544 
1545 	return TEST_SUCCESS;
1546 }
1547 
1548 static int
1549 test_queue_pair_descriptor_setup(void)
1550 {
1551 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1552 	struct rte_cryptodev_qp_conf qp_conf = {
1553 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1554 	};
1555 	uint16_t qp_id;
1556 
1557 	/* Stop the device in case it's started so it can be configured */
1558 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1559 
1560 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1561 			&ts_params->conf),
1562 			"Failed to configure cryptodev %u",
1563 			ts_params->valid_devs[0]);
1564 
1565 	/*
1566 	 * Test various ring sizes on this device. memzones can't be
1567 	 * freed so are re-used if ring is released and re-created.
1568 	 */
1569 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1570 	qp_conf.mp_session = ts_params->session_mpool;
1571 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1572 
1573 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1574 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1575 				ts_params->valid_devs[0], qp_id, &qp_conf,
1576 				rte_cryptodev_socket_id(
1577 						ts_params->valid_devs[0])),
1578 				"Failed test for "
1579 				"rte_cryptodev_queue_pair_setup: num_inflights "
1580 				"%u on qp %u on cryptodev %u",
1581 				qp_conf.nb_descriptors, qp_id,
1582 				ts_params->valid_devs[0]);
1583 	}
1584 
1585 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1586 
1587 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1588 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1589 				ts_params->valid_devs[0], qp_id, &qp_conf,
1590 				rte_cryptodev_socket_id(
1591 						ts_params->valid_devs[0])),
1592 				"Failed test for"
1593 				" rte_cryptodev_queue_pair_setup: num_inflights"
1594 				" %u on qp %u on cryptodev %u",
1595 				qp_conf.nb_descriptors, qp_id,
1596 				ts_params->valid_devs[0]);
1597 	}
1598 
1599 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
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 = DEFAULT_NUM_OPS_INFLIGHT;
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:"
1622 				"num_inflights %u on qp %u on cryptodev %u",
1623 				qp_conf.nb_descriptors, qp_id,
1624 				ts_params->valid_devs[0]);
1625 	}
1626 
1627 	/* test invalid queue pair id */
1628 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1629 
1630 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1631 
1632 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1633 			ts_params->valid_devs[0],
1634 			qp_id, &qp_conf,
1635 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1636 			"Failed test for rte_cryptodev_queue_pair_setup:"
1637 			"invalid qp %u on cryptodev %u",
1638 			qp_id, ts_params->valid_devs[0]);
1639 
1640 	qp_id = 0xffff; /*invalid*/
1641 
1642 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1643 			ts_params->valid_devs[0],
1644 			qp_id, &qp_conf,
1645 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1646 			"Failed test for rte_cryptodev_queue_pair_setup:"
1647 			"invalid qp %u on cryptodev %u",
1648 			qp_id, ts_params->valid_devs[0]);
1649 
1650 	return TEST_SUCCESS;
1651 }
1652 
1653 /* ***** Plaintext data for tests ***** */
1654 
1655 const char catch_22_quote_1[] =
1656 		"There was only one catch and that was Catch-22, which "
1657 		"specified that a concern for one's safety in the face of "
1658 		"dangers that were real and immediate was the process of a "
1659 		"rational mind. Orr was crazy and could be grounded. All he "
1660 		"had to do was ask; and as soon as he did, he would no longer "
1661 		"be crazy and would have to fly more missions. Orr would be "
1662 		"crazy to fly more missions and sane if he didn't, but if he "
1663 		"was sane he had to fly them. If he flew them he was crazy "
1664 		"and didn't have to; but if he didn't want to he was sane and "
1665 		"had to. Yossarian was moved very deeply by the absolute "
1666 		"simplicity of this clause of Catch-22 and let out a "
1667 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1668 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1669 
1670 const char catch_22_quote[] =
1671 		"What a lousy earth! He wondered how many people were "
1672 		"destitute that same night even in his own prosperous country, "
1673 		"how many homes were shanties, how many husbands were drunk "
1674 		"and wives socked, and how many children were bullied, abused, "
1675 		"or abandoned. How many families hungered for food they could "
1676 		"not afford to buy? How many hearts were broken? How many "
1677 		"suicides would take place that same night, how many people "
1678 		"would go insane? How many cockroaches and landlords would "
1679 		"triumph? How many winners were losers, successes failures, "
1680 		"and rich men poor men? How many wise guys were stupid? How "
1681 		"many happy endings were unhappy endings? How many honest men "
1682 		"were liars, brave men cowards, loyal men traitors, how many "
1683 		"sainted men were corrupt, how many people in positions of "
1684 		"trust had sold their souls to bodyguards, how many had never "
1685 		"had souls? How many straight-and-narrow paths were crooked "
1686 		"paths? How many best families were worst families and how "
1687 		"many good people were bad people? When you added them all up "
1688 		"and then subtracted, you might be left with only the children, "
1689 		"and perhaps with Albert Einstein and an old violinist or "
1690 		"sculptor somewhere.";
1691 
1692 #define QUOTE_480_BYTES		(480)
1693 #define QUOTE_512_BYTES		(512)
1694 #define QUOTE_768_BYTES		(768)
1695 #define QUOTE_1024_BYTES	(1024)
1696 
1697 
1698 
1699 /* ***** SHA1 Hash Tests ***** */
1700 
1701 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1702 
1703 static uint8_t hmac_sha1_key[] = {
1704 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1705 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1706 	0xDE, 0xF4, 0xDE, 0xAD };
1707 
1708 /* ***** SHA224 Hash Tests ***** */
1709 
1710 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1711 
1712 
1713 /* ***** AES-CBC Cipher Tests ***** */
1714 
1715 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1716 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1717 
1718 static uint8_t aes_cbc_key[] = {
1719 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1720 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1721 
1722 static uint8_t aes_cbc_iv[] = {
1723 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1724 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1725 
1726 
1727 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1728 
1729 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1730 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1731 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1732 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1733 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1734 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1735 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1736 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1737 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1738 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1739 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1740 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1741 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1742 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1743 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1744 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1745 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1746 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1747 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1748 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1749 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1750 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1751 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1752 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1753 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1754 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1755 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1756 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1757 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1758 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1759 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1760 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1761 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1762 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1763 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1764 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1765 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1766 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1767 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1768 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1769 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1770 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1771 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1772 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1773 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1774 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1775 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1776 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1777 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1778 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1779 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1780 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1781 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1782 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1783 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1784 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1785 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1786 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1787 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1788 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1789 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1790 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1791 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1792 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1793 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1794 };
1795 
1796 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1797 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1798 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1799 	0x18, 0x8c, 0x1d, 0x32
1800 };
1801 
1802 
1803 /* Multisession Vector context Test */
1804 /*Begin Session 0 */
1805 static uint8_t ms_aes_cbc_key0[] = {
1806 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1807 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1808 };
1809 
1810 static uint8_t ms_aes_cbc_iv0[] = {
1811 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1812 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1813 };
1814 
1815 static const uint8_t ms_aes_cbc_cipher0[] = {
1816 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1817 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1818 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1819 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1820 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1821 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1822 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1823 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1824 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1825 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1826 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1827 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1828 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1829 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1830 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1831 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1832 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1833 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1834 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1835 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1836 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1837 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1838 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1839 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1840 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1841 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1842 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1843 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1844 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1845 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1846 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1847 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1848 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1849 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1850 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1851 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1852 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1853 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1854 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1855 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1856 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1857 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1858 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1859 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1860 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1861 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1862 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1863 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1864 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1865 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1866 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1867 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1868 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1869 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1870 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1871 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1872 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1873 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1874 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1875 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1876 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1877 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1878 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1879 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1880 };
1881 
1882 
1883 static  uint8_t ms_hmac_key0[] = {
1884 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1885 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1886 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1887 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1888 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1889 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1890 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1891 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1892 };
1893 
1894 static const uint8_t ms_hmac_digest0[] = {
1895 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1896 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1897 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1898 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1899 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1900 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1901 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1902 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1903 		};
1904 
1905 /* End Session 0 */
1906 /* Begin session 1 */
1907 
1908 static  uint8_t ms_aes_cbc_key1[] = {
1909 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1910 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1911 };
1912 
1913 static  uint8_t ms_aes_cbc_iv1[] = {
1914 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1915 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1916 };
1917 
1918 static const uint8_t ms_aes_cbc_cipher1[] = {
1919 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1920 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1921 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1922 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1923 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1924 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1925 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1926 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1927 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1928 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1929 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1930 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1931 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1932 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1933 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1934 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1935 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1936 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1937 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1938 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1939 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1940 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1941 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1942 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1943 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1944 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1945 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1946 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1947 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1948 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1949 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1950 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1951 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1952 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1953 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1954 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1955 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1956 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1957 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1958 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1959 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1960 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1961 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1962 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1963 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1964 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1965 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1966 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1967 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1968 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1969 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1970 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1971 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1972 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1973 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1974 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1975 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1976 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1977 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1978 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1979 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1980 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1981 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1982 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1983 
1984 };
1985 
1986 static uint8_t ms_hmac_key1[] = {
1987 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1988 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1989 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1990 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1991 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1992 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1993 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1994 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1995 };
1996 
1997 static const uint8_t ms_hmac_digest1[] = {
1998 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1999 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2000 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2001 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2002 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2003 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2004 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2005 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2006 };
2007 /* End Session 1  */
2008 /* Begin Session 2 */
2009 static  uint8_t ms_aes_cbc_key2[] = {
2010 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2011 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2012 };
2013 
2014 static  uint8_t ms_aes_cbc_iv2[] = {
2015 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2016 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2017 };
2018 
2019 static const uint8_t ms_aes_cbc_cipher2[] = {
2020 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2021 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2022 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2023 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2024 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2025 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2026 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2027 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2028 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2029 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2030 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2031 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2032 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2033 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2034 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2035 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2036 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2037 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2038 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2039 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2040 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2041 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2042 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2043 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2044 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2045 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2046 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2047 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2048 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2049 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2050 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2051 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2052 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2053 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2054 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2055 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2056 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2057 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2058 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2059 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2060 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2061 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2062 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2063 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2064 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2065 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2066 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2067 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2068 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2069 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2070 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2071 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2072 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2073 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2074 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2075 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2076 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2077 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2078 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2079 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2080 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2081 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2082 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2083 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2084 };
2085 
2086 static  uint8_t ms_hmac_key2[] = {
2087 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2088 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2089 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2090 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2091 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2092 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2093 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2094 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2095 };
2096 
2097 static const uint8_t ms_hmac_digest2[] = {
2098 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2099 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2100 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2101 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2102 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2103 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2104 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2105 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2106 };
2107 
2108 /* End Session 2 */
2109 
2110 
2111 static int
2112 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2113 {
2114 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2115 	struct crypto_unittest_params *ut_params = &unittest_params;
2116 
2117 	/* Verify the capabilities */
2118 	struct rte_cryptodev_sym_capability_idx cap_idx;
2119 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2120 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2121 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2122 			&cap_idx) == NULL)
2123 		return TEST_SKIPPED;
2124 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2125 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2126 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2127 			&cap_idx) == NULL)
2128 		return TEST_SKIPPED;
2129 
2130 	/* Generate test mbuf data and space for digest */
2131 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2132 			catch_22_quote,	QUOTE_512_BYTES, 0);
2133 
2134 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2135 			DIGEST_BYTE_LENGTH_SHA1);
2136 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2137 
2138 	/* Setup Cipher Parameters */
2139 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2140 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2141 
2142 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2143 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2144 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2145 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2146 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2147 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2148 
2149 	/* Setup HMAC Parameters */
2150 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2151 
2152 	ut_params->auth_xform.next = NULL;
2153 
2154 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2155 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2156 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2157 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2158 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2159 
2160 	ut_params->sess = rte_cryptodev_sym_session_create(
2161 			ts_params->session_mpool);
2162 
2163 	/* Create crypto session*/
2164 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2165 			ut_params->sess, &ut_params->cipher_xform,
2166 			ts_params->session_priv_mpool);
2167 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2168 
2169 	/* Generate crypto op data structure */
2170 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2171 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2172 	TEST_ASSERT_NOT_NULL(ut_params->op,
2173 			"Failed to allocate symmetric crypto operation struct");
2174 
2175 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2176 
2177 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2178 
2179 	/* set crypto operation source mbuf */
2180 	sym_op->m_src = ut_params->ibuf;
2181 
2182 	/* Set crypto operation authentication parameters */
2183 	sym_op->auth.digest.data = ut_params->digest;
2184 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2185 			ut_params->ibuf, QUOTE_512_BYTES);
2186 
2187 	sym_op->auth.data.offset = 0;
2188 	sym_op->auth.data.length = QUOTE_512_BYTES;
2189 
2190 	/* Copy IV at the end of the crypto operation */
2191 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2192 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2193 
2194 	/* Set crypto operation cipher parameters */
2195 	sym_op->cipher.data.offset = 0;
2196 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2197 
2198 	/* Process crypto operation */
2199 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2200 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2201 			ut_params->op);
2202 	else
2203 		TEST_ASSERT_NOT_NULL(
2204 			process_crypto_request(ts_params->valid_devs[0],
2205 				ut_params->op),
2206 				"failed to process sym crypto op");
2207 
2208 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2209 			"crypto op processing failed");
2210 
2211 	/* Validate obuf */
2212 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2213 			uint8_t *);
2214 
2215 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2216 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2217 			QUOTE_512_BYTES,
2218 			"ciphertext data not as expected");
2219 
2220 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2221 
2222 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2223 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2224 			gbl_driver_id == rte_cryptodev_driver_id_get(
2225 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2226 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2227 					DIGEST_BYTE_LENGTH_SHA1,
2228 			"Generated digest data not as expected");
2229 
2230 	return TEST_SUCCESS;
2231 }
2232 
2233 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2234 
2235 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2236 
2237 static uint8_t hmac_sha512_key[] = {
2238 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2239 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2240 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2241 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2242 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2243 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2244 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2245 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2246 
2247 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2248 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2249 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2250 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2251 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2252 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2253 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2254 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2255 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2256 
2257 
2258 
2259 static int
2260 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2261 		struct crypto_unittest_params *ut_params,
2262 		uint8_t *cipher_key,
2263 		uint8_t *hmac_key);
2264 
2265 static int
2266 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2267 		struct crypto_unittest_params *ut_params,
2268 		struct crypto_testsuite_params *ts_params,
2269 		const uint8_t *cipher,
2270 		const uint8_t *digest,
2271 		const uint8_t *iv);
2272 
2273 
2274 static int
2275 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2276 		struct crypto_unittest_params *ut_params,
2277 		uint8_t *cipher_key,
2278 		uint8_t *hmac_key)
2279 {
2280 
2281 	/* Setup Cipher Parameters */
2282 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2283 	ut_params->cipher_xform.next = NULL;
2284 
2285 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2286 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2287 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2288 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2289 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2290 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2291 
2292 	/* Setup HMAC Parameters */
2293 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2294 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2295 
2296 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2297 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2298 	ut_params->auth_xform.auth.key.data = hmac_key;
2299 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2300 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2301 
2302 	return TEST_SUCCESS;
2303 }
2304 
2305 
2306 static int
2307 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2308 		struct crypto_unittest_params *ut_params,
2309 		struct crypto_testsuite_params *ts_params,
2310 		const uint8_t *cipher,
2311 		const uint8_t *digest,
2312 		const uint8_t *iv)
2313 {
2314 	/* Generate test mbuf data and digest */
2315 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2316 			(const char *)
2317 			cipher,
2318 			QUOTE_512_BYTES, 0);
2319 
2320 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2321 			DIGEST_BYTE_LENGTH_SHA512);
2322 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2323 
2324 	rte_memcpy(ut_params->digest,
2325 			digest,
2326 			DIGEST_BYTE_LENGTH_SHA512);
2327 
2328 	/* Generate Crypto op data structure */
2329 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2330 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2331 	TEST_ASSERT_NOT_NULL(ut_params->op,
2332 			"Failed to allocate symmetric crypto operation struct");
2333 
2334 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2335 
2336 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2337 
2338 	/* set crypto operation source mbuf */
2339 	sym_op->m_src = ut_params->ibuf;
2340 
2341 	sym_op->auth.digest.data = ut_params->digest;
2342 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2343 			ut_params->ibuf, QUOTE_512_BYTES);
2344 
2345 	sym_op->auth.data.offset = 0;
2346 	sym_op->auth.data.length = QUOTE_512_BYTES;
2347 
2348 	/* Copy IV at the end of the crypto operation */
2349 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2350 			iv, CIPHER_IV_LENGTH_AES_CBC);
2351 
2352 	sym_op->cipher.data.offset = 0;
2353 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2354 
2355 	/* Process crypto operation */
2356 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2357 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2358 			ut_params->op);
2359 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2360 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2361 				ut_params->op, 1, 1, 0, 0);
2362 	else
2363 		TEST_ASSERT_NOT_NULL(
2364 				process_crypto_request(ts_params->valid_devs[0],
2365 					ut_params->op),
2366 					"failed to process sym crypto op");
2367 
2368 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2369 			"crypto op processing failed");
2370 
2371 	ut_params->obuf = ut_params->op->sym->m_src;
2372 
2373 	/* Validate obuf */
2374 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2375 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2376 			catch_22_quote,
2377 			QUOTE_512_BYTES,
2378 			"Plaintext data not as expected");
2379 
2380 	/* Validate obuf */
2381 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2382 			"Digest verification failed");
2383 
2384 	return TEST_SUCCESS;
2385 }
2386 
2387 /* ***** SNOW 3G Tests ***** */
2388 static int
2389 create_wireless_algo_hash_session(uint8_t dev_id,
2390 	const uint8_t *key, const uint8_t key_len,
2391 	const uint8_t iv_len, const uint8_t auth_len,
2392 	enum rte_crypto_auth_operation op,
2393 	enum rte_crypto_auth_algorithm algo)
2394 {
2395 	uint8_t hash_key[key_len];
2396 	int status;
2397 
2398 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2399 	struct crypto_unittest_params *ut_params = &unittest_params;
2400 
2401 	memcpy(hash_key, key, key_len);
2402 
2403 	debug_hexdump(stdout, "key:", key, key_len);
2404 
2405 	/* Setup Authentication Parameters */
2406 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2407 	ut_params->auth_xform.next = NULL;
2408 
2409 	ut_params->auth_xform.auth.op = op;
2410 	ut_params->auth_xform.auth.algo = algo;
2411 	ut_params->auth_xform.auth.key.length = key_len;
2412 	ut_params->auth_xform.auth.key.data = hash_key;
2413 	ut_params->auth_xform.auth.digest_length = auth_len;
2414 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2415 	ut_params->auth_xform.auth.iv.length = iv_len;
2416 	ut_params->sess = rte_cryptodev_sym_session_create(
2417 			ts_params->session_mpool);
2418 
2419 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2420 			&ut_params->auth_xform,
2421 			ts_params->session_priv_mpool);
2422 	if (status == -ENOTSUP)
2423 		return TEST_SKIPPED;
2424 
2425 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2426 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2427 	return 0;
2428 }
2429 
2430 static int
2431 create_wireless_algo_cipher_session(uint8_t dev_id,
2432 			enum rte_crypto_cipher_operation op,
2433 			enum rte_crypto_cipher_algorithm algo,
2434 			const uint8_t *key, const uint8_t key_len,
2435 			uint8_t iv_len)
2436 {
2437 	uint8_t cipher_key[key_len];
2438 	int status;
2439 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2440 	struct crypto_unittest_params *ut_params = &unittest_params;
2441 
2442 	memcpy(cipher_key, key, key_len);
2443 
2444 	/* Setup Cipher Parameters */
2445 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2446 	ut_params->cipher_xform.next = NULL;
2447 
2448 	ut_params->cipher_xform.cipher.algo = algo;
2449 	ut_params->cipher_xform.cipher.op = op;
2450 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2451 	ut_params->cipher_xform.cipher.key.length = key_len;
2452 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2453 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2454 
2455 	debug_hexdump(stdout, "key:", key, key_len);
2456 
2457 	/* Create Crypto session */
2458 	ut_params->sess = rte_cryptodev_sym_session_create(
2459 			ts_params->session_mpool);
2460 
2461 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2462 			&ut_params->cipher_xform,
2463 			ts_params->session_priv_mpool);
2464 	if (status == -ENOTSUP)
2465 		return TEST_SKIPPED;
2466 
2467 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2468 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2469 	return 0;
2470 }
2471 
2472 static int
2473 create_wireless_algo_cipher_operation(const uint8_t *iv, uint8_t iv_len,
2474 			unsigned int cipher_len,
2475 			unsigned int cipher_offset)
2476 {
2477 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2478 	struct crypto_unittest_params *ut_params = &unittest_params;
2479 
2480 	/* Generate Crypto op data structure */
2481 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2482 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2483 	TEST_ASSERT_NOT_NULL(ut_params->op,
2484 				"Failed to allocate pktmbuf offload");
2485 
2486 	/* Set crypto operation data parameters */
2487 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2488 
2489 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2490 
2491 	/* set crypto operation source mbuf */
2492 	sym_op->m_src = ut_params->ibuf;
2493 
2494 	/* iv */
2495 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2496 			iv, iv_len);
2497 	sym_op->cipher.data.length = cipher_len;
2498 	sym_op->cipher.data.offset = cipher_offset;
2499 	return 0;
2500 }
2501 
2502 static int
2503 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2504 			unsigned int cipher_len,
2505 			unsigned int cipher_offset)
2506 {
2507 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2508 	struct crypto_unittest_params *ut_params = &unittest_params;
2509 
2510 	/* Generate Crypto op data structure */
2511 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2512 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2513 	TEST_ASSERT_NOT_NULL(ut_params->op,
2514 				"Failed to allocate pktmbuf offload");
2515 
2516 	/* Set crypto operation data parameters */
2517 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2518 
2519 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2520 
2521 	/* set crypto operation source mbuf */
2522 	sym_op->m_src = ut_params->ibuf;
2523 	sym_op->m_dst = ut_params->obuf;
2524 
2525 	/* iv */
2526 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2527 			iv, iv_len);
2528 	sym_op->cipher.data.length = cipher_len;
2529 	sym_op->cipher.data.offset = cipher_offset;
2530 	return 0;
2531 }
2532 
2533 static int
2534 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2535 		enum rte_crypto_cipher_operation cipher_op,
2536 		enum rte_crypto_auth_operation auth_op,
2537 		enum rte_crypto_auth_algorithm auth_algo,
2538 		enum rte_crypto_cipher_algorithm cipher_algo,
2539 		const uint8_t *key, uint8_t key_len,
2540 		uint8_t auth_iv_len, uint8_t auth_len,
2541 		uint8_t cipher_iv_len)
2542 
2543 {
2544 	uint8_t cipher_auth_key[key_len];
2545 	int status;
2546 
2547 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2548 	struct crypto_unittest_params *ut_params = &unittest_params;
2549 
2550 	memcpy(cipher_auth_key, key, key_len);
2551 
2552 	/* Setup Authentication Parameters */
2553 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2554 	ut_params->auth_xform.next = NULL;
2555 
2556 	ut_params->auth_xform.auth.op = auth_op;
2557 	ut_params->auth_xform.auth.algo = auth_algo;
2558 	ut_params->auth_xform.auth.key.length = key_len;
2559 	/* Hash key = cipher key */
2560 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2561 	ut_params->auth_xform.auth.digest_length = auth_len;
2562 	/* Auth IV will be after cipher IV */
2563 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2564 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2565 
2566 	/* Setup Cipher Parameters */
2567 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2568 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2569 
2570 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2571 	ut_params->cipher_xform.cipher.op = cipher_op;
2572 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2573 	ut_params->cipher_xform.cipher.key.length = key_len;
2574 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2575 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2576 
2577 	debug_hexdump(stdout, "key:", key, key_len);
2578 
2579 	/* Create Crypto session*/
2580 	ut_params->sess = rte_cryptodev_sym_session_create(
2581 			ts_params->session_mpool);
2582 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2583 
2584 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2585 			&ut_params->cipher_xform,
2586 			ts_params->session_priv_mpool);
2587 	if (status == -ENOTSUP)
2588 		return TEST_SKIPPED;
2589 
2590 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2591 	return 0;
2592 }
2593 
2594 static int
2595 create_wireless_cipher_auth_session(uint8_t dev_id,
2596 		enum rte_crypto_cipher_operation cipher_op,
2597 		enum rte_crypto_auth_operation auth_op,
2598 		enum rte_crypto_auth_algorithm auth_algo,
2599 		enum rte_crypto_cipher_algorithm cipher_algo,
2600 		const struct wireless_test_data *tdata)
2601 {
2602 	const uint8_t key_len = tdata->key.len;
2603 	uint8_t cipher_auth_key[key_len];
2604 	int status;
2605 
2606 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2607 	struct crypto_unittest_params *ut_params = &unittest_params;
2608 	const uint8_t *key = tdata->key.data;
2609 	const uint8_t auth_len = tdata->digest.len;
2610 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2611 	uint8_t auth_iv_len = tdata->auth_iv.len;
2612 
2613 	memcpy(cipher_auth_key, key, key_len);
2614 
2615 	/* Setup Authentication Parameters */
2616 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2617 	ut_params->auth_xform.next = NULL;
2618 
2619 	ut_params->auth_xform.auth.op = auth_op;
2620 	ut_params->auth_xform.auth.algo = auth_algo;
2621 	ut_params->auth_xform.auth.key.length = key_len;
2622 	/* Hash key = cipher key */
2623 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2624 	ut_params->auth_xform.auth.digest_length = auth_len;
2625 	/* Auth IV will be after cipher IV */
2626 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2627 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2628 
2629 	/* Setup Cipher Parameters */
2630 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2631 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2632 
2633 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2634 	ut_params->cipher_xform.cipher.op = cipher_op;
2635 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2636 	ut_params->cipher_xform.cipher.key.length = key_len;
2637 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2638 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2639 
2640 
2641 	debug_hexdump(stdout, "key:", key, key_len);
2642 
2643 	/* Create Crypto session*/
2644 	ut_params->sess = rte_cryptodev_sym_session_create(
2645 			ts_params->session_mpool);
2646 
2647 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2648 			&ut_params->cipher_xform,
2649 			ts_params->session_priv_mpool);
2650 	if (status == -ENOTSUP)
2651 		return TEST_SKIPPED;
2652 
2653 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2654 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2655 	return 0;
2656 }
2657 
2658 static int
2659 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2660 		const struct wireless_test_data *tdata)
2661 {
2662 	return create_wireless_cipher_auth_session(dev_id,
2663 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2664 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2665 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2666 }
2667 
2668 static int
2669 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2670 		enum rte_crypto_cipher_operation cipher_op,
2671 		enum rte_crypto_auth_operation auth_op,
2672 		enum rte_crypto_auth_algorithm auth_algo,
2673 		enum rte_crypto_cipher_algorithm cipher_algo,
2674 		const uint8_t *key, const uint8_t key_len,
2675 		uint8_t auth_iv_len, uint8_t auth_len,
2676 		uint8_t cipher_iv_len)
2677 {
2678 	uint8_t auth_cipher_key[key_len];
2679 	int status;
2680 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2681 	struct crypto_unittest_params *ut_params = &unittest_params;
2682 
2683 	memcpy(auth_cipher_key, key, key_len);
2684 
2685 	/* Setup Authentication Parameters */
2686 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2687 	ut_params->auth_xform.auth.op = auth_op;
2688 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2689 	ut_params->auth_xform.auth.algo = auth_algo;
2690 	ut_params->auth_xform.auth.key.length = key_len;
2691 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2692 	ut_params->auth_xform.auth.digest_length = auth_len;
2693 	/* Auth IV will be after cipher IV */
2694 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2695 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2696 
2697 	/* Setup Cipher Parameters */
2698 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2699 	ut_params->cipher_xform.next = NULL;
2700 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2701 	ut_params->cipher_xform.cipher.op = cipher_op;
2702 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2703 	ut_params->cipher_xform.cipher.key.length = key_len;
2704 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2705 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2706 
2707 	debug_hexdump(stdout, "key:", key, key_len);
2708 
2709 	/* Create Crypto session*/
2710 	ut_params->sess = rte_cryptodev_sym_session_create(
2711 			ts_params->session_mpool);
2712 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2713 
2714 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2715 		ut_params->auth_xform.next = NULL;
2716 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2717 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2718 				&ut_params->cipher_xform,
2719 				ts_params->session_priv_mpool);
2720 
2721 	} else
2722 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2723 				&ut_params->auth_xform,
2724 				ts_params->session_priv_mpool);
2725 
2726 	if (status == -ENOTSUP)
2727 		return TEST_SKIPPED;
2728 
2729 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2730 
2731 	return 0;
2732 }
2733 
2734 static int
2735 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2736 		unsigned int auth_tag_len,
2737 		const uint8_t *iv, unsigned int iv_len,
2738 		unsigned int data_pad_len,
2739 		enum rte_crypto_auth_operation op,
2740 		unsigned int auth_len, unsigned int auth_offset)
2741 {
2742 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2743 
2744 	struct crypto_unittest_params *ut_params = &unittest_params;
2745 
2746 	/* Generate Crypto op data structure */
2747 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2748 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2749 	TEST_ASSERT_NOT_NULL(ut_params->op,
2750 		"Failed to allocate pktmbuf offload");
2751 
2752 	/* Set crypto operation data parameters */
2753 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2754 
2755 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2756 
2757 	/* set crypto operation source mbuf */
2758 	sym_op->m_src = ut_params->ibuf;
2759 
2760 	/* iv */
2761 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2762 			iv, iv_len);
2763 	/* digest */
2764 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2765 					ut_params->ibuf, auth_tag_len);
2766 
2767 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2768 				"no room to append auth tag");
2769 	ut_params->digest = sym_op->auth.digest.data;
2770 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2771 			ut_params->ibuf, data_pad_len);
2772 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2773 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2774 	else
2775 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2776 
2777 	debug_hexdump(stdout, "digest:",
2778 		sym_op->auth.digest.data,
2779 		auth_tag_len);
2780 
2781 	sym_op->auth.data.length = auth_len;
2782 	sym_op->auth.data.offset = auth_offset;
2783 
2784 	return 0;
2785 }
2786 
2787 static int
2788 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2789 	enum rte_crypto_auth_operation op)
2790 {
2791 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2792 	struct crypto_unittest_params *ut_params = &unittest_params;
2793 
2794 	const uint8_t *auth_tag = tdata->digest.data;
2795 	const unsigned int auth_tag_len = tdata->digest.len;
2796 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2797 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2798 
2799 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2800 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2801 	const uint8_t *auth_iv = tdata->auth_iv.data;
2802 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2803 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2804 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2805 
2806 	/* Generate Crypto op data structure */
2807 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2808 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2809 	TEST_ASSERT_NOT_NULL(ut_params->op,
2810 			"Failed to allocate pktmbuf offload");
2811 	/* Set crypto operation data parameters */
2812 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2813 
2814 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2815 
2816 	/* set crypto operation source mbuf */
2817 	sym_op->m_src = ut_params->ibuf;
2818 
2819 	/* digest */
2820 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2821 			ut_params->ibuf, auth_tag_len);
2822 
2823 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2824 			"no room to append auth tag");
2825 	ut_params->digest = sym_op->auth.digest.data;
2826 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2827 			ut_params->ibuf, data_pad_len);
2828 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2829 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2830 	else
2831 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2832 
2833 	debug_hexdump(stdout, "digest:",
2834 		sym_op->auth.digest.data,
2835 		auth_tag_len);
2836 
2837 	/* Copy cipher and auth IVs at the end of the crypto operation */
2838 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2839 						IV_OFFSET);
2840 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2841 	iv_ptr += cipher_iv_len;
2842 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2843 
2844 	sym_op->cipher.data.length = cipher_len;
2845 	sym_op->cipher.data.offset = 0;
2846 	sym_op->auth.data.length = auth_len;
2847 	sym_op->auth.data.offset = 0;
2848 
2849 	return 0;
2850 }
2851 
2852 static int
2853 create_zuc_cipher_hash_generate_operation(
2854 		const struct wireless_test_data *tdata)
2855 {
2856 	return create_wireless_cipher_hash_operation(tdata,
2857 		RTE_CRYPTO_AUTH_OP_GENERATE);
2858 }
2859 
2860 static int
2861 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2862 		const unsigned auth_tag_len,
2863 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2864 		unsigned data_pad_len,
2865 		enum rte_crypto_auth_operation op,
2866 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2867 		const unsigned cipher_len, const unsigned cipher_offset,
2868 		const unsigned auth_len, const unsigned auth_offset)
2869 {
2870 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2871 	struct crypto_unittest_params *ut_params = &unittest_params;
2872 
2873 	enum rte_crypto_cipher_algorithm cipher_algo =
2874 			ut_params->cipher_xform.cipher.algo;
2875 	enum rte_crypto_auth_algorithm auth_algo =
2876 			ut_params->auth_xform.auth.algo;
2877 
2878 	/* Generate Crypto op data structure */
2879 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2880 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2881 	TEST_ASSERT_NOT_NULL(ut_params->op,
2882 			"Failed to allocate pktmbuf offload");
2883 	/* Set crypto operation data parameters */
2884 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2885 
2886 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2887 
2888 	/* set crypto operation source mbuf */
2889 	sym_op->m_src = ut_params->ibuf;
2890 
2891 	/* digest */
2892 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2893 			ut_params->ibuf, auth_tag_len);
2894 
2895 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2896 			"no room to append auth tag");
2897 	ut_params->digest = sym_op->auth.digest.data;
2898 
2899 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2900 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2901 				ut_params->ibuf, data_pad_len);
2902 	} else {
2903 		struct rte_mbuf *m = ut_params->ibuf;
2904 		unsigned int offset = data_pad_len;
2905 
2906 		while (offset > m->data_len && m->next != NULL) {
2907 			offset -= m->data_len;
2908 			m = m->next;
2909 		}
2910 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2911 			m, offset);
2912 	}
2913 
2914 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2915 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2916 	else
2917 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2918 
2919 	debug_hexdump(stdout, "digest:",
2920 		sym_op->auth.digest.data,
2921 		auth_tag_len);
2922 
2923 	/* Copy cipher and auth IVs at the end of the crypto operation */
2924 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2925 						IV_OFFSET);
2926 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2927 	iv_ptr += cipher_iv_len;
2928 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2929 
2930 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2931 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2932 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2933 		sym_op->cipher.data.length = cipher_len;
2934 		sym_op->cipher.data.offset = cipher_offset;
2935 	} else {
2936 		sym_op->cipher.data.length = cipher_len >> 3;
2937 		sym_op->cipher.data.offset = cipher_offset >> 3;
2938 	}
2939 
2940 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2941 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2942 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2943 		sym_op->auth.data.length = auth_len;
2944 		sym_op->auth.data.offset = auth_offset;
2945 	} else {
2946 		sym_op->auth.data.length = auth_len >> 3;
2947 		sym_op->auth.data.offset = auth_offset >> 3;
2948 	}
2949 
2950 	return 0;
2951 }
2952 
2953 static int
2954 create_wireless_algo_auth_cipher_operation(
2955 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2956 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2957 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2958 		unsigned int data_pad_len,
2959 		unsigned int cipher_len, unsigned int cipher_offset,
2960 		unsigned int auth_len, unsigned int auth_offset,
2961 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2962 {
2963 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2964 	struct crypto_unittest_params *ut_params = &unittest_params;
2965 
2966 	enum rte_crypto_cipher_algorithm cipher_algo =
2967 			ut_params->cipher_xform.cipher.algo;
2968 	enum rte_crypto_auth_algorithm auth_algo =
2969 			ut_params->auth_xform.auth.algo;
2970 
2971 	/* Generate Crypto op data structure */
2972 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2973 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2974 	TEST_ASSERT_NOT_NULL(ut_params->op,
2975 			"Failed to allocate pktmbuf offload");
2976 
2977 	/* Set crypto operation data parameters */
2978 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2979 
2980 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2981 
2982 	/* set crypto operation mbufs */
2983 	sym_op->m_src = ut_params->ibuf;
2984 	if (op_mode == OUT_OF_PLACE)
2985 		sym_op->m_dst = ut_params->obuf;
2986 
2987 	/* digest */
2988 	if (!do_sgl) {
2989 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
2990 			(op_mode == IN_PLACE ?
2991 				ut_params->ibuf : ut_params->obuf),
2992 			uint8_t *, data_pad_len);
2993 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2994 			(op_mode == IN_PLACE ?
2995 				ut_params->ibuf : ut_params->obuf),
2996 			data_pad_len);
2997 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2998 	} else {
2999 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3000 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3001 				sym_op->m_src : sym_op->m_dst);
3002 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3003 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3004 			sgl_buf = sgl_buf->next;
3005 		}
3006 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3007 				uint8_t *, remaining_off);
3008 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3009 				remaining_off);
3010 		memset(sym_op->auth.digest.data, 0, remaining_off);
3011 		while (sgl_buf->next != NULL) {
3012 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3013 				0, rte_pktmbuf_data_len(sgl_buf));
3014 			sgl_buf = sgl_buf->next;
3015 		}
3016 	}
3017 
3018 	/* Copy digest for the verification */
3019 	if (verify)
3020 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3021 
3022 	/* Copy cipher and auth IVs at the end of the crypto operation */
3023 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3024 			ut_params->op, uint8_t *, IV_OFFSET);
3025 
3026 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3027 	iv_ptr += cipher_iv_len;
3028 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3029 
3030 	/* Only copy over the offset data needed from src to dst in OOP,
3031 	 * if the auth and cipher offsets are not aligned
3032 	 */
3033 	if (op_mode == OUT_OF_PLACE) {
3034 		if (cipher_offset > auth_offset)
3035 			rte_memcpy(
3036 				rte_pktmbuf_mtod_offset(
3037 					sym_op->m_dst,
3038 					uint8_t *, auth_offset >> 3),
3039 				rte_pktmbuf_mtod_offset(
3040 					sym_op->m_src,
3041 					uint8_t *, auth_offset >> 3),
3042 				((cipher_offset >> 3) - (auth_offset >> 3)));
3043 	}
3044 
3045 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3046 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3047 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3048 		sym_op->cipher.data.length = cipher_len;
3049 		sym_op->cipher.data.offset = cipher_offset;
3050 	} else {
3051 		sym_op->cipher.data.length = cipher_len >> 3;
3052 		sym_op->cipher.data.offset = cipher_offset >> 3;
3053 	}
3054 
3055 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3056 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3057 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3058 		sym_op->auth.data.length = auth_len;
3059 		sym_op->auth.data.offset = auth_offset;
3060 	} else {
3061 		sym_op->auth.data.length = auth_len >> 3;
3062 		sym_op->auth.data.offset = auth_offset >> 3;
3063 	}
3064 
3065 	return 0;
3066 }
3067 
3068 static int
3069 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3070 {
3071 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3072 	struct crypto_unittest_params *ut_params = &unittest_params;
3073 
3074 	int retval;
3075 	unsigned plaintext_pad_len;
3076 	unsigned plaintext_len;
3077 	uint8_t *plaintext;
3078 	struct rte_cryptodev_info dev_info;
3079 
3080 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3081 	uint64_t feat_flags = dev_info.feature_flags;
3082 
3083 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3084 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3085 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3086 		return TEST_SKIPPED;
3087 	}
3088 
3089 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3090 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3091 		printf("Device doesn't support RAW data-path APIs.\n");
3092 		return TEST_SKIPPED;
3093 	}
3094 
3095 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3096 		return TEST_SKIPPED;
3097 
3098 	/* Verify the capabilities */
3099 	struct rte_cryptodev_sym_capability_idx cap_idx;
3100 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3101 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3102 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3103 			&cap_idx) == NULL)
3104 		return TEST_SKIPPED;
3105 
3106 	/* Create SNOW 3G session */
3107 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3108 			tdata->key.data, tdata->key.len,
3109 			tdata->auth_iv.len, tdata->digest.len,
3110 			RTE_CRYPTO_AUTH_OP_GENERATE,
3111 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3112 	if (retval < 0)
3113 		return retval;
3114 
3115 	/* alloc mbuf and set payload */
3116 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3117 
3118 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3119 	rte_pktmbuf_tailroom(ut_params->ibuf));
3120 
3121 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3122 	/* Append data which is padded to a multiple of */
3123 	/* the algorithms block size */
3124 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3125 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3126 				plaintext_pad_len);
3127 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3128 
3129 	/* Create SNOW 3G operation */
3130 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3131 			tdata->auth_iv.data, tdata->auth_iv.len,
3132 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3133 			tdata->validAuthLenInBits.len,
3134 			0);
3135 	if (retval < 0)
3136 		return retval;
3137 
3138 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3139 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3140 				ut_params->op, 0, 1, 1, 0);
3141 	else
3142 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3143 				ut_params->op);
3144 	ut_params->obuf = ut_params->op->sym->m_src;
3145 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3146 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3147 			+ plaintext_pad_len;
3148 
3149 	/* Validate obuf */
3150 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3151 	ut_params->digest,
3152 	tdata->digest.data,
3153 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3154 	"SNOW 3G Generated auth tag not as expected");
3155 
3156 	return 0;
3157 }
3158 
3159 static int
3160 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3161 {
3162 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3163 	struct crypto_unittest_params *ut_params = &unittest_params;
3164 
3165 	int retval;
3166 	unsigned plaintext_pad_len;
3167 	unsigned plaintext_len;
3168 	uint8_t *plaintext;
3169 	struct rte_cryptodev_info dev_info;
3170 
3171 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3172 	uint64_t feat_flags = dev_info.feature_flags;
3173 
3174 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3175 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3176 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3177 		return TEST_SKIPPED;
3178 	}
3179 
3180 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3181 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3182 		printf("Device doesn't support RAW data-path APIs.\n");
3183 		return TEST_SKIPPED;
3184 	}
3185 
3186 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3187 		return TEST_SKIPPED;
3188 
3189 	/* Verify the capabilities */
3190 	struct rte_cryptodev_sym_capability_idx cap_idx;
3191 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3192 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3193 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3194 			&cap_idx) == NULL)
3195 		return TEST_SKIPPED;
3196 
3197 	/* Create SNOW 3G session */
3198 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3199 				tdata->key.data, tdata->key.len,
3200 				tdata->auth_iv.len, tdata->digest.len,
3201 				RTE_CRYPTO_AUTH_OP_VERIFY,
3202 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3203 	if (retval < 0)
3204 		return retval;
3205 	/* alloc mbuf and set payload */
3206 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3207 
3208 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3209 	rte_pktmbuf_tailroom(ut_params->ibuf));
3210 
3211 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3212 	/* Append data which is padded to a multiple of */
3213 	/* the algorithms block size */
3214 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3215 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3216 				plaintext_pad_len);
3217 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3218 
3219 	/* Create SNOW 3G operation */
3220 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3221 			tdata->digest.len,
3222 			tdata->auth_iv.data, tdata->auth_iv.len,
3223 			plaintext_pad_len,
3224 			RTE_CRYPTO_AUTH_OP_VERIFY,
3225 			tdata->validAuthLenInBits.len,
3226 			0);
3227 	if (retval < 0)
3228 		return retval;
3229 
3230 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3231 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3232 				ut_params->op, 0, 1, 1, 0);
3233 	else
3234 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3235 				ut_params->op);
3236 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3237 	ut_params->obuf = ut_params->op->sym->m_src;
3238 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3239 				+ plaintext_pad_len;
3240 
3241 	/* Validate obuf */
3242 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3243 		return 0;
3244 	else
3245 		return -1;
3246 
3247 	return 0;
3248 }
3249 
3250 static int
3251 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3252 {
3253 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3254 	struct crypto_unittest_params *ut_params = &unittest_params;
3255 
3256 	int retval;
3257 	unsigned plaintext_pad_len;
3258 	unsigned plaintext_len;
3259 	uint8_t *plaintext;
3260 	struct rte_cryptodev_info dev_info;
3261 
3262 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3263 	uint64_t feat_flags = dev_info.feature_flags;
3264 
3265 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3266 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3267 		printf("Device doesn't support RAW data-path APIs.\n");
3268 		return TEST_SKIPPED;
3269 	}
3270 
3271 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3272 		return TEST_SKIPPED;
3273 
3274 	/* Verify the capabilities */
3275 	struct rte_cryptodev_sym_capability_idx cap_idx;
3276 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3277 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3278 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3279 			&cap_idx) == NULL)
3280 		return TEST_SKIPPED;
3281 
3282 	/* Create KASUMI session */
3283 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3284 			tdata->key.data, tdata->key.len,
3285 			0, tdata->digest.len,
3286 			RTE_CRYPTO_AUTH_OP_GENERATE,
3287 			RTE_CRYPTO_AUTH_KASUMI_F9);
3288 	if (retval < 0)
3289 		return retval;
3290 
3291 	/* alloc mbuf and set payload */
3292 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3293 
3294 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3295 	rte_pktmbuf_tailroom(ut_params->ibuf));
3296 
3297 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3298 	/* Append data which is padded to a multiple of */
3299 	/* the algorithms block size */
3300 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3301 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3302 				plaintext_pad_len);
3303 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3304 
3305 	/* Create KASUMI operation */
3306 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3307 			NULL, 0,
3308 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3309 			tdata->plaintext.len,
3310 			0);
3311 	if (retval < 0)
3312 		return retval;
3313 
3314 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3315 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3316 			ut_params->op);
3317 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3318 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3319 				ut_params->op, 0, 1, 1, 0);
3320 	else
3321 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3322 			ut_params->op);
3323 
3324 	ut_params->obuf = ut_params->op->sym->m_src;
3325 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3326 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3327 			+ plaintext_pad_len;
3328 
3329 	/* Validate obuf */
3330 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3331 	ut_params->digest,
3332 	tdata->digest.data,
3333 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3334 	"KASUMI Generated auth tag not as expected");
3335 
3336 	return 0;
3337 }
3338 
3339 static int
3340 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3341 {
3342 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3343 	struct crypto_unittest_params *ut_params = &unittest_params;
3344 
3345 	int retval;
3346 	unsigned plaintext_pad_len;
3347 	unsigned plaintext_len;
3348 	uint8_t *plaintext;
3349 	struct rte_cryptodev_info dev_info;
3350 
3351 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3352 	uint64_t feat_flags = dev_info.feature_flags;
3353 
3354 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3355 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3356 		printf("Device doesn't support RAW data-path APIs.\n");
3357 		return TEST_SKIPPED;
3358 	}
3359 
3360 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3361 		return TEST_SKIPPED;
3362 
3363 	/* Verify the capabilities */
3364 	struct rte_cryptodev_sym_capability_idx cap_idx;
3365 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3366 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3367 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3368 			&cap_idx) == NULL)
3369 		return TEST_SKIPPED;
3370 
3371 	/* Create KASUMI session */
3372 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3373 				tdata->key.data, tdata->key.len,
3374 				0, tdata->digest.len,
3375 				RTE_CRYPTO_AUTH_OP_VERIFY,
3376 				RTE_CRYPTO_AUTH_KASUMI_F9);
3377 	if (retval < 0)
3378 		return retval;
3379 	/* alloc mbuf and set payload */
3380 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3381 
3382 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3383 	rte_pktmbuf_tailroom(ut_params->ibuf));
3384 
3385 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3386 	/* Append data which is padded to a multiple */
3387 	/* of the algorithms block size */
3388 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3389 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3390 				plaintext_pad_len);
3391 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3392 
3393 	/* Create KASUMI operation */
3394 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3395 			tdata->digest.len,
3396 			NULL, 0,
3397 			plaintext_pad_len,
3398 			RTE_CRYPTO_AUTH_OP_VERIFY,
3399 			tdata->plaintext.len,
3400 			0);
3401 	if (retval < 0)
3402 		return retval;
3403 
3404 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3405 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3406 				ut_params->op, 0, 1, 1, 0);
3407 	else
3408 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3409 				ut_params->op);
3410 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3411 	ut_params->obuf = ut_params->op->sym->m_src;
3412 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3413 				+ plaintext_pad_len;
3414 
3415 	/* Validate obuf */
3416 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3417 		return 0;
3418 	else
3419 		return -1;
3420 
3421 	return 0;
3422 }
3423 
3424 static int
3425 test_snow3g_hash_generate_test_case_1(void)
3426 {
3427 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3428 }
3429 
3430 static int
3431 test_snow3g_hash_generate_test_case_2(void)
3432 {
3433 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3434 }
3435 
3436 static int
3437 test_snow3g_hash_generate_test_case_3(void)
3438 {
3439 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3440 }
3441 
3442 static int
3443 test_snow3g_hash_generate_test_case_4(void)
3444 {
3445 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3446 }
3447 
3448 static int
3449 test_snow3g_hash_generate_test_case_5(void)
3450 {
3451 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3452 }
3453 
3454 static int
3455 test_snow3g_hash_generate_test_case_6(void)
3456 {
3457 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3458 }
3459 
3460 static int
3461 test_snow3g_hash_verify_test_case_1(void)
3462 {
3463 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3464 
3465 }
3466 
3467 static int
3468 test_snow3g_hash_verify_test_case_2(void)
3469 {
3470 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3471 }
3472 
3473 static int
3474 test_snow3g_hash_verify_test_case_3(void)
3475 {
3476 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3477 }
3478 
3479 static int
3480 test_snow3g_hash_verify_test_case_4(void)
3481 {
3482 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3483 }
3484 
3485 static int
3486 test_snow3g_hash_verify_test_case_5(void)
3487 {
3488 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3489 }
3490 
3491 static int
3492 test_snow3g_hash_verify_test_case_6(void)
3493 {
3494 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3495 }
3496 
3497 static int
3498 test_kasumi_hash_generate_test_case_1(void)
3499 {
3500 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3501 }
3502 
3503 static int
3504 test_kasumi_hash_generate_test_case_2(void)
3505 {
3506 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3507 }
3508 
3509 static int
3510 test_kasumi_hash_generate_test_case_3(void)
3511 {
3512 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3513 }
3514 
3515 static int
3516 test_kasumi_hash_generate_test_case_4(void)
3517 {
3518 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3519 }
3520 
3521 static int
3522 test_kasumi_hash_generate_test_case_5(void)
3523 {
3524 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3525 }
3526 
3527 static int
3528 test_kasumi_hash_generate_test_case_6(void)
3529 {
3530 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3531 }
3532 
3533 static int
3534 test_kasumi_hash_verify_test_case_1(void)
3535 {
3536 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3537 }
3538 
3539 static int
3540 test_kasumi_hash_verify_test_case_2(void)
3541 {
3542 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3543 }
3544 
3545 static int
3546 test_kasumi_hash_verify_test_case_3(void)
3547 {
3548 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3549 }
3550 
3551 static int
3552 test_kasumi_hash_verify_test_case_4(void)
3553 {
3554 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3555 }
3556 
3557 static int
3558 test_kasumi_hash_verify_test_case_5(void)
3559 {
3560 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3561 }
3562 
3563 static int
3564 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3565 {
3566 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3567 	struct crypto_unittest_params *ut_params = &unittest_params;
3568 
3569 	int retval;
3570 	uint8_t *plaintext, *ciphertext;
3571 	unsigned plaintext_pad_len;
3572 	unsigned plaintext_len;
3573 	struct rte_cryptodev_info dev_info;
3574 
3575 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3576 	uint64_t feat_flags = dev_info.feature_flags;
3577 
3578 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3579 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3580 		printf("Device doesn't support RAW data-path APIs.\n");
3581 		return TEST_SKIPPED;
3582 	}
3583 
3584 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3585 		return TEST_SKIPPED;
3586 
3587 	/* Verify the capabilities */
3588 	struct rte_cryptodev_sym_capability_idx cap_idx;
3589 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3590 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3591 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3592 			&cap_idx) == NULL)
3593 		return TEST_SKIPPED;
3594 
3595 	/* Create KASUMI session */
3596 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3597 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3598 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3599 					tdata->key.data, tdata->key.len,
3600 					tdata->cipher_iv.len);
3601 	if (retval < 0)
3602 		return retval;
3603 
3604 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3605 
3606 	/* Clear mbuf payload */
3607 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3608 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3609 
3610 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3611 	/* Append data which is padded to a multiple */
3612 	/* of the algorithms block size */
3613 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3614 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3615 				plaintext_pad_len);
3616 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3617 
3618 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3619 
3620 	/* Create KASUMI operation */
3621 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3622 				tdata->cipher_iv.len,
3623 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3624 				tdata->validCipherOffsetInBits.len);
3625 	if (retval < 0)
3626 		return retval;
3627 
3628 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3629 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3630 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3631 	else
3632 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3633 				ut_params->op);
3634 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3635 
3636 	ut_params->obuf = ut_params->op->sym->m_dst;
3637 	if (ut_params->obuf)
3638 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3639 	else
3640 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3641 
3642 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3643 
3644 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3645 				(tdata->validCipherOffsetInBits.len >> 3);
3646 	/* Validate obuf */
3647 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3648 		ciphertext,
3649 		reference_ciphertext,
3650 		tdata->validCipherLenInBits.len,
3651 		"KASUMI Ciphertext data not as expected");
3652 	return 0;
3653 }
3654 
3655 static int
3656 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3657 {
3658 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3659 	struct crypto_unittest_params *ut_params = &unittest_params;
3660 
3661 	int retval;
3662 
3663 	unsigned int plaintext_pad_len;
3664 	unsigned int plaintext_len;
3665 
3666 	uint8_t buffer[10000];
3667 	const uint8_t *ciphertext;
3668 
3669 	struct rte_cryptodev_info dev_info;
3670 
3671 	/* Verify the capabilities */
3672 	struct rte_cryptodev_sym_capability_idx cap_idx;
3673 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3674 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3675 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3676 			&cap_idx) == NULL)
3677 		return TEST_SKIPPED;
3678 
3679 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3680 
3681 	uint64_t feat_flags = dev_info.feature_flags;
3682 
3683 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3684 		printf("Device doesn't support in-place scatter-gather. "
3685 				"Test Skipped.\n");
3686 		return TEST_SKIPPED;
3687 	}
3688 
3689 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3690 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3691 		printf("Device doesn't support RAW data-path APIs.\n");
3692 		return TEST_SKIPPED;
3693 	}
3694 
3695 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3696 		return TEST_SKIPPED;
3697 
3698 	/* Create KASUMI session */
3699 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3700 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3701 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3702 					tdata->key.data, tdata->key.len,
3703 					tdata->cipher_iv.len);
3704 	if (retval < 0)
3705 		return retval;
3706 
3707 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3708 
3709 
3710 	/* Append data which is padded to a multiple */
3711 	/* of the algorithms block size */
3712 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3713 
3714 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3715 			plaintext_pad_len, 10, 0);
3716 
3717 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3718 
3719 	/* Create KASUMI operation */
3720 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3721 				tdata->cipher_iv.len,
3722 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3723 				tdata->validCipherOffsetInBits.len);
3724 	if (retval < 0)
3725 		return retval;
3726 
3727 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3728 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3729 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3730 	else
3731 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3732 						ut_params->op);
3733 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3734 
3735 	ut_params->obuf = ut_params->op->sym->m_dst;
3736 
3737 	if (ut_params->obuf)
3738 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3739 				plaintext_len, buffer);
3740 	else
3741 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3742 				tdata->validCipherOffsetInBits.len >> 3,
3743 				plaintext_len, buffer);
3744 
3745 	/* Validate obuf */
3746 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3747 
3748 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3749 				(tdata->validCipherOffsetInBits.len >> 3);
3750 	/* Validate obuf */
3751 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3752 		ciphertext,
3753 		reference_ciphertext,
3754 		tdata->validCipherLenInBits.len,
3755 		"KASUMI Ciphertext data not as expected");
3756 	return 0;
3757 }
3758 
3759 static int
3760 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3761 {
3762 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3763 	struct crypto_unittest_params *ut_params = &unittest_params;
3764 
3765 	int retval;
3766 	uint8_t *plaintext, *ciphertext;
3767 	unsigned plaintext_pad_len;
3768 	unsigned plaintext_len;
3769 
3770 	/* Verify the capabilities */
3771 	struct rte_cryptodev_sym_capability_idx cap_idx;
3772 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3773 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3774 	/* Data-path service does not support OOP */
3775 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3776 			&cap_idx) == NULL)
3777 		return TEST_SKIPPED;
3778 
3779 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3780 		return TEST_SKIPPED;
3781 
3782 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3783 		return TEST_SKIPPED;
3784 
3785 	/* Create KASUMI session */
3786 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3787 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3788 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3789 					tdata->key.data, tdata->key.len,
3790 					tdata->cipher_iv.len);
3791 	if (retval < 0)
3792 		return retval;
3793 
3794 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3795 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3796 
3797 	/* Clear mbuf payload */
3798 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3799 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3800 
3801 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3802 	/* Append data which is padded to a multiple */
3803 	/* of the algorithms block size */
3804 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3805 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3806 				plaintext_pad_len);
3807 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3808 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3809 
3810 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3811 
3812 	/* Create KASUMI operation */
3813 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3814 				tdata->cipher_iv.len,
3815 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3816 				tdata->validCipherOffsetInBits.len);
3817 	if (retval < 0)
3818 		return retval;
3819 
3820 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3821 						ut_params->op);
3822 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3823 
3824 	ut_params->obuf = ut_params->op->sym->m_dst;
3825 	if (ut_params->obuf)
3826 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3827 	else
3828 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3829 
3830 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3831 
3832 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3833 				(tdata->validCipherOffsetInBits.len >> 3);
3834 	/* Validate obuf */
3835 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3836 		ciphertext,
3837 		reference_ciphertext,
3838 		tdata->validCipherLenInBits.len,
3839 		"KASUMI Ciphertext data not as expected");
3840 	return 0;
3841 }
3842 
3843 static int
3844 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3845 {
3846 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3847 	struct crypto_unittest_params *ut_params = &unittest_params;
3848 
3849 	int retval;
3850 	unsigned int plaintext_pad_len;
3851 	unsigned int plaintext_len;
3852 
3853 	const uint8_t *ciphertext;
3854 	uint8_t buffer[2048];
3855 
3856 	struct rte_cryptodev_info dev_info;
3857 
3858 	/* Verify the capabilities */
3859 	struct rte_cryptodev_sym_capability_idx cap_idx;
3860 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3861 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3862 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3863 			&cap_idx) == NULL)
3864 		return TEST_SKIPPED;
3865 
3866 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3867 		return TEST_SKIPPED;
3868 
3869 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3870 		return TEST_SKIPPED;
3871 
3872 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3873 
3874 	uint64_t feat_flags = dev_info.feature_flags;
3875 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3876 		printf("Device doesn't support out-of-place scatter-gather "
3877 				"in both input and output mbufs. "
3878 				"Test Skipped.\n");
3879 		return TEST_SKIPPED;
3880 	}
3881 
3882 	/* Create KASUMI session */
3883 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3884 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3885 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3886 					tdata->key.data, tdata->key.len,
3887 					tdata->cipher_iv.len);
3888 	if (retval < 0)
3889 		return retval;
3890 
3891 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3892 	/* Append data which is padded to a multiple */
3893 	/* of the algorithms block size */
3894 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3895 
3896 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3897 			plaintext_pad_len, 10, 0);
3898 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3899 			plaintext_pad_len, 3, 0);
3900 
3901 	/* Append data which is padded to a multiple */
3902 	/* of the algorithms block size */
3903 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3904 
3905 	/* Create KASUMI operation */
3906 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3907 				tdata->cipher_iv.len,
3908 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3909 				tdata->validCipherOffsetInBits.len);
3910 	if (retval < 0)
3911 		return retval;
3912 
3913 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3914 						ut_params->op);
3915 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3916 
3917 	ut_params->obuf = ut_params->op->sym->m_dst;
3918 	if (ut_params->obuf)
3919 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3920 				plaintext_pad_len, buffer);
3921 	else
3922 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3923 				tdata->validCipherOffsetInBits.len >> 3,
3924 				plaintext_pad_len, buffer);
3925 
3926 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3927 				(tdata->validCipherOffsetInBits.len >> 3);
3928 	/* Validate obuf */
3929 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3930 		ciphertext,
3931 		reference_ciphertext,
3932 		tdata->validCipherLenInBits.len,
3933 		"KASUMI Ciphertext data not as expected");
3934 	return 0;
3935 }
3936 
3937 
3938 static int
3939 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3940 {
3941 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3942 	struct crypto_unittest_params *ut_params = &unittest_params;
3943 
3944 	int retval;
3945 	uint8_t *ciphertext, *plaintext;
3946 	unsigned ciphertext_pad_len;
3947 	unsigned ciphertext_len;
3948 
3949 	/* Verify the capabilities */
3950 	struct rte_cryptodev_sym_capability_idx cap_idx;
3951 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3952 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3953 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3954 			&cap_idx) == NULL)
3955 		return TEST_SKIPPED;
3956 
3957 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3958 		return TEST_SKIPPED;
3959 
3960 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3961 		return TEST_SKIPPED;
3962 
3963 	/* Create KASUMI session */
3964 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3965 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3966 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3967 					tdata->key.data, tdata->key.len,
3968 					tdata->cipher_iv.len);
3969 	if (retval < 0)
3970 		return retval;
3971 
3972 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3973 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3974 
3975 	/* Clear mbuf payload */
3976 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3977 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3978 
3979 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3980 	/* Append data which is padded to a multiple */
3981 	/* of the algorithms block size */
3982 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3983 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3984 				ciphertext_pad_len);
3985 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3986 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3987 
3988 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
3989 
3990 	/* Create KASUMI operation */
3991 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3992 				tdata->cipher_iv.len,
3993 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3994 				tdata->validCipherOffsetInBits.len);
3995 	if (retval < 0)
3996 		return retval;
3997 
3998 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3999 						ut_params->op);
4000 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4001 
4002 	ut_params->obuf = ut_params->op->sym->m_dst;
4003 	if (ut_params->obuf)
4004 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4005 	else
4006 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4007 
4008 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4009 
4010 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4011 				(tdata->validCipherOffsetInBits.len >> 3);
4012 	/* Validate obuf */
4013 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4014 		plaintext,
4015 		reference_plaintext,
4016 		tdata->validCipherLenInBits.len,
4017 		"KASUMI Plaintext data not as expected");
4018 	return 0;
4019 }
4020 
4021 static int
4022 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4023 {
4024 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4025 	struct crypto_unittest_params *ut_params = &unittest_params;
4026 
4027 	int retval;
4028 	uint8_t *ciphertext, *plaintext;
4029 	unsigned ciphertext_pad_len;
4030 	unsigned ciphertext_len;
4031 	struct rte_cryptodev_info dev_info;
4032 
4033 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4034 	uint64_t feat_flags = dev_info.feature_flags;
4035 
4036 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4037 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4038 		printf("Device doesn't support RAW data-path APIs.\n");
4039 		return TEST_SKIPPED;
4040 	}
4041 
4042 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4043 		return TEST_SKIPPED;
4044 
4045 	/* Verify the capabilities */
4046 	struct rte_cryptodev_sym_capability_idx cap_idx;
4047 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4048 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4049 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4050 			&cap_idx) == NULL)
4051 		return TEST_SKIPPED;
4052 
4053 	/* Create KASUMI session */
4054 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4055 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4056 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4057 					tdata->key.data, tdata->key.len,
4058 					tdata->cipher_iv.len);
4059 	if (retval < 0)
4060 		return retval;
4061 
4062 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4063 
4064 	/* Clear mbuf payload */
4065 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4066 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4067 
4068 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4069 	/* Append data which is padded to a multiple */
4070 	/* of the algorithms block size */
4071 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4072 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4073 				ciphertext_pad_len);
4074 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4075 
4076 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4077 
4078 	/* Create KASUMI operation */
4079 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4080 					tdata->cipher_iv.len,
4081 					tdata->ciphertext.len,
4082 					tdata->validCipherOffsetInBits.len);
4083 	if (retval < 0)
4084 		return retval;
4085 
4086 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4087 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4088 				ut_params->op, 1, 0, 1, 0);
4089 	else
4090 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4091 						ut_params->op);
4092 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4093 
4094 	ut_params->obuf = ut_params->op->sym->m_dst;
4095 	if (ut_params->obuf)
4096 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4097 	else
4098 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4099 
4100 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4101 
4102 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4103 				(tdata->validCipherOffsetInBits.len >> 3);
4104 	/* Validate obuf */
4105 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4106 		plaintext,
4107 		reference_plaintext,
4108 		tdata->validCipherLenInBits.len,
4109 		"KASUMI Plaintext data not as expected");
4110 	return 0;
4111 }
4112 
4113 static int
4114 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4115 {
4116 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4117 	struct crypto_unittest_params *ut_params = &unittest_params;
4118 
4119 	int retval;
4120 	uint8_t *plaintext, *ciphertext;
4121 	unsigned plaintext_pad_len;
4122 	unsigned plaintext_len;
4123 	struct rte_cryptodev_info dev_info;
4124 
4125 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4126 	uint64_t feat_flags = dev_info.feature_flags;
4127 
4128 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4129 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4130 		printf("Device doesn't support RAW data-path APIs.\n");
4131 		return TEST_SKIPPED;
4132 	}
4133 
4134 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4135 		return TEST_SKIPPED;
4136 
4137 	/* Verify the capabilities */
4138 	struct rte_cryptodev_sym_capability_idx cap_idx;
4139 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4140 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4141 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4142 			&cap_idx) == NULL)
4143 		return TEST_SKIPPED;
4144 
4145 	/* Create SNOW 3G session */
4146 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4147 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4148 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4149 					tdata->key.data, tdata->key.len,
4150 					tdata->cipher_iv.len);
4151 	if (retval < 0)
4152 		return retval;
4153 
4154 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4155 
4156 	/* Clear mbuf payload */
4157 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4158 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4159 
4160 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4161 	/* Append data which is padded to a multiple of */
4162 	/* the algorithms block size */
4163 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4164 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4165 				plaintext_pad_len);
4166 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4167 
4168 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4169 
4170 	/* Create SNOW 3G operation */
4171 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4172 					tdata->cipher_iv.len,
4173 					tdata->validCipherLenInBits.len,
4174 					0);
4175 	if (retval < 0)
4176 		return retval;
4177 
4178 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4179 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4180 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4181 	else
4182 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4183 						ut_params->op);
4184 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4185 
4186 	ut_params->obuf = ut_params->op->sym->m_dst;
4187 	if (ut_params->obuf)
4188 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4189 	else
4190 		ciphertext = plaintext;
4191 
4192 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4193 
4194 	/* Validate obuf */
4195 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4196 		ciphertext,
4197 		tdata->ciphertext.data,
4198 		tdata->validDataLenInBits.len,
4199 		"SNOW 3G Ciphertext data not as expected");
4200 	return 0;
4201 }
4202 
4203 
4204 static int
4205 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4206 {
4207 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4208 	struct crypto_unittest_params *ut_params = &unittest_params;
4209 	uint8_t *plaintext, *ciphertext;
4210 
4211 	int retval;
4212 	unsigned plaintext_pad_len;
4213 	unsigned plaintext_len;
4214 	struct rte_cryptodev_info dev_info;
4215 
4216 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4217 	uint64_t feat_flags = dev_info.feature_flags;
4218 
4219 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4220 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4221 		printf("Device does not support RAW data-path APIs.\n");
4222 		return -ENOTSUP;
4223 	}
4224 
4225 	/* Verify the capabilities */
4226 	struct rte_cryptodev_sym_capability_idx cap_idx;
4227 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4228 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4229 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4230 			&cap_idx) == NULL)
4231 		return TEST_SKIPPED;
4232 
4233 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4234 		return TEST_SKIPPED;
4235 
4236 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4237 		return TEST_SKIPPED;
4238 
4239 	/* Create SNOW 3G session */
4240 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4241 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4242 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4243 					tdata->key.data, tdata->key.len,
4244 					tdata->cipher_iv.len);
4245 	if (retval < 0)
4246 		return retval;
4247 
4248 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4249 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4250 
4251 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4252 			"Failed to allocate input buffer in mempool");
4253 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4254 			"Failed to allocate output buffer in mempool");
4255 
4256 	/* Clear mbuf payload */
4257 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4258 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4259 
4260 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4261 	/* Append data which is padded to a multiple of */
4262 	/* the algorithms block size */
4263 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4264 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4265 				plaintext_pad_len);
4266 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4267 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4268 
4269 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4270 
4271 	/* Create SNOW 3G operation */
4272 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4273 					tdata->cipher_iv.len,
4274 					tdata->validCipherLenInBits.len,
4275 					0);
4276 	if (retval < 0)
4277 		return retval;
4278 
4279 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4280 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4281 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4282 	else
4283 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4284 						ut_params->op);
4285 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4286 
4287 	ut_params->obuf = ut_params->op->sym->m_dst;
4288 	if (ut_params->obuf)
4289 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4290 	else
4291 		ciphertext = plaintext;
4292 
4293 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4294 
4295 	/* Validate obuf */
4296 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4297 		ciphertext,
4298 		tdata->ciphertext.data,
4299 		tdata->validDataLenInBits.len,
4300 		"SNOW 3G Ciphertext data not as expected");
4301 	return 0;
4302 }
4303 
4304 static int
4305 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4306 {
4307 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4308 	struct crypto_unittest_params *ut_params = &unittest_params;
4309 
4310 	int retval;
4311 	unsigned int plaintext_pad_len;
4312 	unsigned int plaintext_len;
4313 	uint8_t buffer[10000];
4314 	const uint8_t *ciphertext;
4315 
4316 	struct rte_cryptodev_info dev_info;
4317 
4318 	/* Verify the capabilities */
4319 	struct rte_cryptodev_sym_capability_idx cap_idx;
4320 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4321 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4322 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4323 			&cap_idx) == NULL)
4324 		return TEST_SKIPPED;
4325 
4326 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4327 		return TEST_SKIPPED;
4328 
4329 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4330 		return TEST_SKIPPED;
4331 
4332 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4333 
4334 	uint64_t feat_flags = dev_info.feature_flags;
4335 
4336 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4337 		printf("Device doesn't support out-of-place scatter-gather "
4338 				"in both input and output mbufs. "
4339 				"Test Skipped.\n");
4340 		return TEST_SKIPPED;
4341 	}
4342 
4343 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4344 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4345 		printf("Device does not support RAW data-path APIs.\n");
4346 		return -ENOTSUP;
4347 	}
4348 
4349 	/* Create SNOW 3G session */
4350 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4351 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4352 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4353 					tdata->key.data, tdata->key.len,
4354 					tdata->cipher_iv.len);
4355 	if (retval < 0)
4356 		return retval;
4357 
4358 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4359 	/* Append data which is padded to a multiple of */
4360 	/* the algorithms block size */
4361 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4362 
4363 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4364 			plaintext_pad_len, 10, 0);
4365 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4366 			plaintext_pad_len, 3, 0);
4367 
4368 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4369 			"Failed to allocate input buffer in mempool");
4370 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4371 			"Failed to allocate output buffer in mempool");
4372 
4373 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4374 
4375 	/* Create SNOW 3G operation */
4376 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4377 					tdata->cipher_iv.len,
4378 					tdata->validCipherLenInBits.len,
4379 					0);
4380 	if (retval < 0)
4381 		return retval;
4382 
4383 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4384 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4385 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4386 	else
4387 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4388 						ut_params->op);
4389 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4390 
4391 	ut_params->obuf = ut_params->op->sym->m_dst;
4392 	if (ut_params->obuf)
4393 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4394 				plaintext_len, buffer);
4395 	else
4396 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4397 				plaintext_len, buffer);
4398 
4399 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4400 
4401 	/* Validate obuf */
4402 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4403 		ciphertext,
4404 		tdata->ciphertext.data,
4405 		tdata->validDataLenInBits.len,
4406 		"SNOW 3G Ciphertext data not as expected");
4407 
4408 	return 0;
4409 }
4410 
4411 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4412 static void
4413 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4414 {
4415 	uint8_t curr_byte, prev_byte;
4416 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4417 	uint8_t lower_byte_mask = (1 << offset) - 1;
4418 	unsigned i;
4419 
4420 	prev_byte = buffer[0];
4421 	buffer[0] >>= offset;
4422 
4423 	for (i = 1; i < length_in_bytes; i++) {
4424 		curr_byte = buffer[i];
4425 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4426 				(curr_byte >> offset);
4427 		prev_byte = curr_byte;
4428 	}
4429 }
4430 
4431 static int
4432 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4433 {
4434 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4435 	struct crypto_unittest_params *ut_params = &unittest_params;
4436 	uint8_t *plaintext, *ciphertext;
4437 	int retval;
4438 	uint32_t plaintext_len;
4439 	uint32_t plaintext_pad_len;
4440 	uint8_t extra_offset = 4;
4441 	uint8_t *expected_ciphertext_shifted;
4442 	struct rte_cryptodev_info dev_info;
4443 
4444 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4445 	uint64_t feat_flags = dev_info.feature_flags;
4446 
4447 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4448 			((tdata->validDataLenInBits.len % 8) != 0)) {
4449 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4450 		return TEST_SKIPPED;
4451 	}
4452 
4453 	/* Verify the capabilities */
4454 	struct rte_cryptodev_sym_capability_idx cap_idx;
4455 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4456 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4457 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4458 			&cap_idx) == NULL)
4459 		return TEST_SKIPPED;
4460 
4461 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4462 		return TEST_SKIPPED;
4463 
4464 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4465 		return TEST_SKIPPED;
4466 
4467 	/* Create SNOW 3G session */
4468 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4469 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4470 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4471 					tdata->key.data, tdata->key.len,
4472 					tdata->cipher_iv.len);
4473 	if (retval < 0)
4474 		return retval;
4475 
4476 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4477 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4478 
4479 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4480 			"Failed to allocate input buffer in mempool");
4481 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4482 			"Failed to allocate output buffer in mempool");
4483 
4484 	/* Clear mbuf payload */
4485 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4486 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4487 
4488 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4489 	/*
4490 	 * Append data which is padded to a
4491 	 * multiple of the algorithms block size
4492 	 */
4493 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4494 
4495 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4496 						plaintext_pad_len);
4497 
4498 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4499 
4500 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4501 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4502 
4503 #ifdef RTE_APP_TEST_DEBUG
4504 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4505 #endif
4506 	/* Create SNOW 3G operation */
4507 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4508 					tdata->cipher_iv.len,
4509 					tdata->validCipherLenInBits.len,
4510 					extra_offset);
4511 	if (retval < 0)
4512 		return retval;
4513 
4514 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4515 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4516 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4517 	else
4518 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4519 						ut_params->op);
4520 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4521 
4522 	ut_params->obuf = ut_params->op->sym->m_dst;
4523 	if (ut_params->obuf)
4524 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4525 	else
4526 		ciphertext = plaintext;
4527 
4528 #ifdef RTE_APP_TEST_DEBUG
4529 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4530 #endif
4531 
4532 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4533 
4534 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4535 			"failed to reserve memory for ciphertext shifted\n");
4536 
4537 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4538 			ceil_byte_length(tdata->ciphertext.len));
4539 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4540 			extra_offset);
4541 	/* Validate obuf */
4542 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4543 		ciphertext,
4544 		expected_ciphertext_shifted,
4545 		tdata->validDataLenInBits.len,
4546 		extra_offset,
4547 		"SNOW 3G Ciphertext data not as expected");
4548 	return 0;
4549 }
4550 
4551 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4552 {
4553 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4554 	struct crypto_unittest_params *ut_params = &unittest_params;
4555 
4556 	int retval;
4557 
4558 	uint8_t *plaintext, *ciphertext;
4559 	unsigned ciphertext_pad_len;
4560 	unsigned ciphertext_len;
4561 	struct rte_cryptodev_info dev_info;
4562 
4563 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4564 	uint64_t feat_flags = dev_info.feature_flags;
4565 
4566 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4567 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4568 		printf("Device doesn't support RAW data-path APIs.\n");
4569 		return TEST_SKIPPED;
4570 	}
4571 
4572 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4573 		return TEST_SKIPPED;
4574 
4575 	/* Verify the capabilities */
4576 	struct rte_cryptodev_sym_capability_idx cap_idx;
4577 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4578 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4579 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4580 			&cap_idx) == NULL)
4581 		return TEST_SKIPPED;
4582 
4583 	/* Create SNOW 3G session */
4584 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4585 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4586 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4587 					tdata->key.data, tdata->key.len,
4588 					tdata->cipher_iv.len);
4589 	if (retval < 0)
4590 		return retval;
4591 
4592 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4593 
4594 	/* Clear mbuf payload */
4595 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4596 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4597 
4598 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4599 	/* Append data which is padded to a multiple of */
4600 	/* the algorithms block size */
4601 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4602 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4603 				ciphertext_pad_len);
4604 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4605 
4606 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4607 
4608 	/* Create SNOW 3G operation */
4609 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4610 					tdata->cipher_iv.len,
4611 					tdata->validCipherLenInBits.len,
4612 					tdata->cipher.offset_bits);
4613 	if (retval < 0)
4614 		return retval;
4615 
4616 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4617 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4618 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4619 	else
4620 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4621 						ut_params->op);
4622 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4623 	ut_params->obuf = ut_params->op->sym->m_dst;
4624 	if (ut_params->obuf)
4625 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4626 	else
4627 		plaintext = ciphertext;
4628 
4629 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4630 
4631 	/* Validate obuf */
4632 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4633 				tdata->plaintext.data,
4634 				tdata->validDataLenInBits.len,
4635 				"SNOW 3G Plaintext data not as expected");
4636 	return 0;
4637 }
4638 
4639 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4640 {
4641 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4642 	struct crypto_unittest_params *ut_params = &unittest_params;
4643 
4644 	int retval;
4645 
4646 	uint8_t *plaintext, *ciphertext;
4647 	unsigned ciphertext_pad_len;
4648 	unsigned ciphertext_len;
4649 	struct rte_cryptodev_info dev_info;
4650 
4651 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4652 	uint64_t feat_flags = dev_info.feature_flags;
4653 
4654 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4655 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4656 		printf("Device does not support RAW data-path APIs.\n");
4657 		return -ENOTSUP;
4658 	}
4659 	/* Verify the capabilities */
4660 	struct rte_cryptodev_sym_capability_idx cap_idx;
4661 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4662 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4663 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4664 			&cap_idx) == NULL)
4665 		return TEST_SKIPPED;
4666 
4667 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4668 		return TEST_SKIPPED;
4669 
4670 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4671 		return TEST_SKIPPED;
4672 
4673 	/* Create SNOW 3G session */
4674 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4675 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4676 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4677 					tdata->key.data, tdata->key.len,
4678 					tdata->cipher_iv.len);
4679 	if (retval < 0)
4680 		return retval;
4681 
4682 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4683 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4684 
4685 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4686 			"Failed to allocate input buffer");
4687 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4688 			"Failed to allocate output buffer");
4689 
4690 	/* Clear mbuf payload */
4691 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4692 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4693 
4694 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4695 		       rte_pktmbuf_tailroom(ut_params->obuf));
4696 
4697 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4698 	/* Append data which is padded to a multiple of */
4699 	/* the algorithms block size */
4700 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4701 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4702 				ciphertext_pad_len);
4703 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4704 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4705 
4706 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4707 
4708 	/* Create SNOW 3G operation */
4709 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4710 					tdata->cipher_iv.len,
4711 					tdata->validCipherLenInBits.len,
4712 					0);
4713 	if (retval < 0)
4714 		return retval;
4715 
4716 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4717 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4718 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4719 	else
4720 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4721 						ut_params->op);
4722 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4723 	ut_params->obuf = ut_params->op->sym->m_dst;
4724 	if (ut_params->obuf)
4725 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4726 	else
4727 		plaintext = ciphertext;
4728 
4729 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4730 
4731 	/* Validate obuf */
4732 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4733 				tdata->plaintext.data,
4734 				tdata->validDataLenInBits.len,
4735 				"SNOW 3G Plaintext data not as expected");
4736 	return 0;
4737 }
4738 
4739 static int
4740 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4741 {
4742 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4743 	struct crypto_unittest_params *ut_params = &unittest_params;
4744 
4745 	int retval;
4746 
4747 	uint8_t *plaintext, *ciphertext;
4748 	unsigned int plaintext_pad_len;
4749 	unsigned int plaintext_len;
4750 
4751 	struct rte_cryptodev_info dev_info;
4752 	struct rte_cryptodev_sym_capability_idx cap_idx;
4753 
4754 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4755 	uint64_t feat_flags = dev_info.feature_flags;
4756 
4757 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4758 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4759 			(tdata->validDataLenInBits.len % 8 != 0))) {
4760 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4761 		return TEST_SKIPPED;
4762 	}
4763 
4764 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4765 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4766 		printf("Device doesn't support RAW data-path APIs.\n");
4767 		return TEST_SKIPPED;
4768 	}
4769 
4770 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4771 		return TEST_SKIPPED;
4772 
4773 	/* Check if device supports ZUC EEA3 */
4774 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4775 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4776 
4777 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4778 			&cap_idx) == NULL)
4779 		return TEST_SKIPPED;
4780 
4781 	/* Check if device supports ZUC EIA3 */
4782 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4783 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4784 
4785 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4786 			&cap_idx) == NULL)
4787 		return TEST_SKIPPED;
4788 
4789 	/* Create ZUC session */
4790 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4791 			ts_params->valid_devs[0],
4792 			tdata);
4793 	if (retval != 0)
4794 		return retval;
4795 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4796 
4797 	/* clear mbuf payload */
4798 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4799 			rte_pktmbuf_tailroom(ut_params->ibuf));
4800 
4801 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4802 	/* Append data which is padded to a multiple of */
4803 	/* the algorithms block size */
4804 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4805 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4806 				plaintext_pad_len);
4807 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4808 
4809 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4810 
4811 	/* Create ZUC operation */
4812 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4813 	if (retval < 0)
4814 		return retval;
4815 
4816 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4817 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4818 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4819 	else
4820 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4821 			ut_params->op);
4822 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4823 	ut_params->obuf = ut_params->op->sym->m_src;
4824 	if (ut_params->obuf)
4825 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4826 	else
4827 		ciphertext = plaintext;
4828 
4829 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4830 	/* Validate obuf */
4831 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4832 			ciphertext,
4833 			tdata->ciphertext.data,
4834 			tdata->validDataLenInBits.len,
4835 			"ZUC Ciphertext data not as expected");
4836 
4837 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4838 	    + plaintext_pad_len;
4839 
4840 	/* Validate obuf */
4841 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4842 			ut_params->digest,
4843 			tdata->digest.data,
4844 			4,
4845 			"ZUC Generated auth tag not as expected");
4846 	return 0;
4847 }
4848 
4849 static int
4850 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4851 {
4852 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4853 	struct crypto_unittest_params *ut_params = &unittest_params;
4854 
4855 	int retval;
4856 
4857 	uint8_t *plaintext, *ciphertext;
4858 	unsigned plaintext_pad_len;
4859 	unsigned plaintext_len;
4860 	struct rte_cryptodev_info dev_info;
4861 
4862 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4863 	uint64_t feat_flags = dev_info.feature_flags;
4864 
4865 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4866 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4867 		printf("Device doesn't support RAW data-path APIs.\n");
4868 		return TEST_SKIPPED;
4869 	}
4870 
4871 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4872 		return TEST_SKIPPED;
4873 
4874 	/* Verify the capabilities */
4875 	struct rte_cryptodev_sym_capability_idx cap_idx;
4876 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4877 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4878 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4879 			&cap_idx) == NULL)
4880 		return TEST_SKIPPED;
4881 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4882 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4883 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4884 			&cap_idx) == NULL)
4885 		return TEST_SKIPPED;
4886 
4887 	/* Create SNOW 3G session */
4888 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4889 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4890 			RTE_CRYPTO_AUTH_OP_GENERATE,
4891 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4892 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4893 			tdata->key.data, tdata->key.len,
4894 			tdata->auth_iv.len, tdata->digest.len,
4895 			tdata->cipher_iv.len);
4896 	if (retval != 0)
4897 		return retval;
4898 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4899 
4900 	/* clear mbuf payload */
4901 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4902 			rte_pktmbuf_tailroom(ut_params->ibuf));
4903 
4904 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4905 	/* Append data which is padded to a multiple of */
4906 	/* the algorithms block size */
4907 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4908 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4909 				plaintext_pad_len);
4910 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4911 
4912 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4913 
4914 	/* Create SNOW 3G operation */
4915 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4916 			tdata->digest.len, tdata->auth_iv.data,
4917 			tdata->auth_iv.len,
4918 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4919 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4920 			tdata->validCipherLenInBits.len,
4921 			0,
4922 			tdata->validAuthLenInBits.len,
4923 			0
4924 			);
4925 	if (retval < 0)
4926 		return retval;
4927 
4928 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4929 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4930 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4931 	else
4932 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4933 			ut_params->op);
4934 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4935 	ut_params->obuf = ut_params->op->sym->m_src;
4936 	if (ut_params->obuf)
4937 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4938 	else
4939 		ciphertext = plaintext;
4940 
4941 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4942 	/* Validate obuf */
4943 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4944 			ciphertext,
4945 			tdata->ciphertext.data,
4946 			tdata->validDataLenInBits.len,
4947 			"SNOW 3G Ciphertext data not as expected");
4948 
4949 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4950 	    + plaintext_pad_len;
4951 
4952 	/* Validate obuf */
4953 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4954 			ut_params->digest,
4955 			tdata->digest.data,
4956 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4957 			"SNOW 3G Generated auth tag not as expected");
4958 	return 0;
4959 }
4960 
4961 static int
4962 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4963 	uint8_t op_mode, uint8_t verify)
4964 {
4965 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4966 	struct crypto_unittest_params *ut_params = &unittest_params;
4967 
4968 	int retval;
4969 
4970 	uint8_t *plaintext = NULL, *ciphertext = NULL;
4971 	unsigned int plaintext_pad_len;
4972 	unsigned int plaintext_len;
4973 	unsigned int ciphertext_pad_len;
4974 	unsigned int ciphertext_len;
4975 
4976 	struct rte_cryptodev_info dev_info;
4977 
4978 	/* Verify the capabilities */
4979 	struct rte_cryptodev_sym_capability_idx cap_idx;
4980 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4981 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4982 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4983 			&cap_idx) == NULL)
4984 		return TEST_SKIPPED;
4985 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4986 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4987 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4988 			&cap_idx) == NULL)
4989 		return TEST_SKIPPED;
4990 
4991 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4992 		return TEST_SKIPPED;
4993 
4994 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4995 
4996 	uint64_t feat_flags = dev_info.feature_flags;
4997 
4998 	if (op_mode == OUT_OF_PLACE) {
4999 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5000 			printf("Device doesn't support digest encrypted.\n");
5001 			return TEST_SKIPPED;
5002 		}
5003 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5004 			return TEST_SKIPPED;
5005 	}
5006 
5007 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5008 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5009 		printf("Device doesn't support RAW data-path APIs.\n");
5010 		return TEST_SKIPPED;
5011 	}
5012 
5013 	/* Create SNOW 3G session */
5014 	retval = create_wireless_algo_auth_cipher_session(
5015 			ts_params->valid_devs[0],
5016 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5017 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5018 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5019 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5020 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5021 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5022 			tdata->key.data, tdata->key.len,
5023 			tdata->auth_iv.len, tdata->digest.len,
5024 			tdata->cipher_iv.len);
5025 	if (retval != 0)
5026 		return retval;
5027 
5028 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5029 	if (op_mode == OUT_OF_PLACE)
5030 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5031 
5032 	/* clear mbuf payload */
5033 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5034 		rte_pktmbuf_tailroom(ut_params->ibuf));
5035 	if (op_mode == OUT_OF_PLACE)
5036 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5037 			rte_pktmbuf_tailroom(ut_params->obuf));
5038 
5039 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5040 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5041 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5042 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5043 
5044 	if (verify) {
5045 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5046 					ciphertext_pad_len);
5047 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5048 		if (op_mode == OUT_OF_PLACE)
5049 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5050 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5051 			ciphertext_len);
5052 	} else {
5053 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5054 					plaintext_pad_len);
5055 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5056 		if (op_mode == OUT_OF_PLACE)
5057 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5058 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5059 	}
5060 
5061 	/* Create SNOW 3G operation */
5062 	retval = create_wireless_algo_auth_cipher_operation(
5063 		tdata->digest.data, tdata->digest.len,
5064 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5065 		tdata->auth_iv.data, tdata->auth_iv.len,
5066 		(tdata->digest.offset_bytes == 0 ?
5067 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5068 			: tdata->digest.offset_bytes),
5069 		tdata->validCipherLenInBits.len,
5070 		tdata->cipher.offset_bits,
5071 		tdata->validAuthLenInBits.len,
5072 		tdata->auth.offset_bits,
5073 		op_mode, 0, verify);
5074 
5075 	if (retval < 0)
5076 		return retval;
5077 
5078 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5079 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5080 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5081 	else
5082 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5083 			ut_params->op);
5084 
5085 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5086 
5087 	ut_params->obuf = (op_mode == IN_PLACE ?
5088 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5089 
5090 	if (verify) {
5091 		if (ut_params->obuf)
5092 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5093 							uint8_t *);
5094 		else
5095 			plaintext = ciphertext +
5096 				(tdata->cipher.offset_bits >> 3);
5097 
5098 		debug_hexdump(stdout, "plaintext:", plaintext,
5099 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5100 		debug_hexdump(stdout, "plaintext expected:",
5101 			tdata->plaintext.data,
5102 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5103 	} else {
5104 		if (ut_params->obuf)
5105 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5106 							uint8_t *);
5107 		else
5108 			ciphertext = plaintext;
5109 
5110 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5111 			ciphertext_len);
5112 		debug_hexdump(stdout, "ciphertext expected:",
5113 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5114 
5115 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5116 			+ (tdata->digest.offset_bytes == 0 ?
5117 		plaintext_pad_len : tdata->digest.offset_bytes);
5118 
5119 		debug_hexdump(stdout, "digest:", ut_params->digest,
5120 			tdata->digest.len);
5121 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5122 				tdata->digest.len);
5123 	}
5124 
5125 	/* Validate obuf */
5126 	if (verify) {
5127 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5128 			plaintext,
5129 			tdata->plaintext.data,
5130 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5131 			 (tdata->digest.len << 3)),
5132 			tdata->cipher.offset_bits,
5133 			"SNOW 3G Plaintext data not as expected");
5134 	} else {
5135 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5136 			ciphertext,
5137 			tdata->ciphertext.data,
5138 			(tdata->validDataLenInBits.len -
5139 			 tdata->cipher.offset_bits),
5140 			tdata->cipher.offset_bits,
5141 			"SNOW 3G Ciphertext data not as expected");
5142 
5143 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5144 			ut_params->digest,
5145 			tdata->digest.data,
5146 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5147 			"SNOW 3G Generated auth tag not as expected");
5148 	}
5149 	return 0;
5150 }
5151 
5152 static int
5153 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5154 	uint8_t op_mode, uint8_t verify)
5155 {
5156 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5157 	struct crypto_unittest_params *ut_params = &unittest_params;
5158 
5159 	int retval;
5160 
5161 	const uint8_t *plaintext = NULL;
5162 	const uint8_t *ciphertext = NULL;
5163 	const uint8_t *digest = NULL;
5164 	unsigned int plaintext_pad_len;
5165 	unsigned int plaintext_len;
5166 	unsigned int ciphertext_pad_len;
5167 	unsigned int ciphertext_len;
5168 	uint8_t buffer[10000];
5169 	uint8_t digest_buffer[10000];
5170 
5171 	struct rte_cryptodev_info dev_info;
5172 
5173 	/* Verify the capabilities */
5174 	struct rte_cryptodev_sym_capability_idx cap_idx;
5175 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5176 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5177 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5178 			&cap_idx) == NULL)
5179 		return TEST_SKIPPED;
5180 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5181 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5182 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5183 			&cap_idx) == NULL)
5184 		return TEST_SKIPPED;
5185 
5186 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5187 		return TEST_SKIPPED;
5188 
5189 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5190 
5191 	uint64_t feat_flags = dev_info.feature_flags;
5192 
5193 	if (op_mode == IN_PLACE) {
5194 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5195 			printf("Device doesn't support in-place scatter-gather "
5196 					"in both input and output mbufs.\n");
5197 			return TEST_SKIPPED;
5198 		}
5199 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5200 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5201 			printf("Device doesn't support RAW data-path APIs.\n");
5202 			return TEST_SKIPPED;
5203 		}
5204 	} else {
5205 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5206 			return TEST_SKIPPED;
5207 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5208 			printf("Device doesn't support out-of-place scatter-gather "
5209 					"in both input and output mbufs.\n");
5210 			return TEST_SKIPPED;
5211 		}
5212 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5213 			printf("Device doesn't support digest encrypted.\n");
5214 			return TEST_SKIPPED;
5215 		}
5216 	}
5217 
5218 	/* Create SNOW 3G session */
5219 	retval = create_wireless_algo_auth_cipher_session(
5220 			ts_params->valid_devs[0],
5221 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5222 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5223 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5224 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5225 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5226 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5227 			tdata->key.data, tdata->key.len,
5228 			tdata->auth_iv.len, tdata->digest.len,
5229 			tdata->cipher_iv.len);
5230 
5231 	if (retval != 0)
5232 		return retval;
5233 
5234 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5235 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5236 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5237 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5238 
5239 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5240 			plaintext_pad_len, 15, 0);
5241 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5242 			"Failed to allocate input buffer in mempool");
5243 
5244 	if (op_mode == OUT_OF_PLACE) {
5245 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5246 				plaintext_pad_len, 15, 0);
5247 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5248 				"Failed to allocate output buffer in mempool");
5249 	}
5250 
5251 	if (verify) {
5252 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5253 			tdata->ciphertext.data);
5254 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5255 					ciphertext_len, buffer);
5256 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5257 			ciphertext_len);
5258 	} else {
5259 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5260 			tdata->plaintext.data);
5261 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5262 					plaintext_len, buffer);
5263 		debug_hexdump(stdout, "plaintext:", plaintext,
5264 			plaintext_len);
5265 	}
5266 	memset(buffer, 0, sizeof(buffer));
5267 
5268 	/* Create SNOW 3G operation */
5269 	retval = create_wireless_algo_auth_cipher_operation(
5270 		tdata->digest.data, tdata->digest.len,
5271 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5272 		tdata->auth_iv.data, tdata->auth_iv.len,
5273 		(tdata->digest.offset_bytes == 0 ?
5274 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5275 			: tdata->digest.offset_bytes),
5276 		tdata->validCipherLenInBits.len,
5277 		tdata->cipher.offset_bits,
5278 		tdata->validAuthLenInBits.len,
5279 		tdata->auth.offset_bits,
5280 		op_mode, 1, verify);
5281 
5282 	if (retval < 0)
5283 		return retval;
5284 
5285 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5286 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5287 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5288 	else
5289 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5290 			ut_params->op);
5291 
5292 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5293 
5294 	ut_params->obuf = (op_mode == IN_PLACE ?
5295 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5296 
5297 	if (verify) {
5298 		if (ut_params->obuf)
5299 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5300 					plaintext_len, buffer);
5301 		else
5302 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5303 					plaintext_len, buffer);
5304 
5305 		debug_hexdump(stdout, "plaintext:", plaintext,
5306 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5307 		debug_hexdump(stdout, "plaintext expected:",
5308 			tdata->plaintext.data,
5309 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5310 	} else {
5311 		if (ut_params->obuf)
5312 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5313 					ciphertext_len, buffer);
5314 		else
5315 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5316 					ciphertext_len, buffer);
5317 
5318 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5319 			ciphertext_len);
5320 		debug_hexdump(stdout, "ciphertext expected:",
5321 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5322 
5323 		if (ut_params->obuf)
5324 			digest = rte_pktmbuf_read(ut_params->obuf,
5325 				(tdata->digest.offset_bytes == 0 ?
5326 				plaintext_pad_len : tdata->digest.offset_bytes),
5327 				tdata->digest.len, digest_buffer);
5328 		else
5329 			digest = rte_pktmbuf_read(ut_params->ibuf,
5330 				(tdata->digest.offset_bytes == 0 ?
5331 				plaintext_pad_len : tdata->digest.offset_bytes),
5332 				tdata->digest.len, digest_buffer);
5333 
5334 		debug_hexdump(stdout, "digest:", digest,
5335 			tdata->digest.len);
5336 		debug_hexdump(stdout, "digest expected:",
5337 			tdata->digest.data, tdata->digest.len);
5338 	}
5339 
5340 	/* Validate obuf */
5341 	if (verify) {
5342 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5343 			plaintext,
5344 			tdata->plaintext.data,
5345 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5346 			 (tdata->digest.len << 3)),
5347 			tdata->cipher.offset_bits,
5348 			"SNOW 3G Plaintext data not as expected");
5349 	} else {
5350 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5351 			ciphertext,
5352 			tdata->ciphertext.data,
5353 			(tdata->validDataLenInBits.len -
5354 			 tdata->cipher.offset_bits),
5355 			tdata->cipher.offset_bits,
5356 			"SNOW 3G Ciphertext data not as expected");
5357 
5358 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5359 			digest,
5360 			tdata->digest.data,
5361 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5362 			"SNOW 3G Generated auth tag not as expected");
5363 	}
5364 	return 0;
5365 }
5366 
5367 static int
5368 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5369 	uint8_t op_mode, uint8_t verify)
5370 {
5371 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5372 	struct crypto_unittest_params *ut_params = &unittest_params;
5373 
5374 	int retval;
5375 
5376 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5377 	unsigned int plaintext_pad_len;
5378 	unsigned int plaintext_len;
5379 	unsigned int ciphertext_pad_len;
5380 	unsigned int ciphertext_len;
5381 
5382 	struct rte_cryptodev_info dev_info;
5383 
5384 	/* Verify the capabilities */
5385 	struct rte_cryptodev_sym_capability_idx cap_idx;
5386 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5387 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5388 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5389 			&cap_idx) == NULL)
5390 		return TEST_SKIPPED;
5391 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5392 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5393 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5394 			&cap_idx) == NULL)
5395 		return TEST_SKIPPED;
5396 
5397 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5398 
5399 	uint64_t feat_flags = dev_info.feature_flags;
5400 
5401 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5402 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5403 		printf("Device doesn't support RAW data-path APIs.\n");
5404 		return TEST_SKIPPED;
5405 	}
5406 
5407 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5408 		return TEST_SKIPPED;
5409 
5410 	if (op_mode == OUT_OF_PLACE) {
5411 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5412 			return TEST_SKIPPED;
5413 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5414 			printf("Device doesn't support digest encrypted.\n");
5415 			return TEST_SKIPPED;
5416 		}
5417 	}
5418 
5419 	/* Create KASUMI session */
5420 	retval = create_wireless_algo_auth_cipher_session(
5421 			ts_params->valid_devs[0],
5422 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5423 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5424 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5425 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5426 			RTE_CRYPTO_AUTH_KASUMI_F9,
5427 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5428 			tdata->key.data, tdata->key.len,
5429 			0, tdata->digest.len,
5430 			tdata->cipher_iv.len);
5431 
5432 	if (retval != 0)
5433 		return retval;
5434 
5435 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5436 	if (op_mode == OUT_OF_PLACE)
5437 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5438 
5439 	/* clear mbuf payload */
5440 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5441 		rte_pktmbuf_tailroom(ut_params->ibuf));
5442 	if (op_mode == OUT_OF_PLACE)
5443 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5444 			rte_pktmbuf_tailroom(ut_params->obuf));
5445 
5446 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5447 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5448 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5449 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5450 
5451 	if (verify) {
5452 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5453 					ciphertext_pad_len);
5454 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5455 		if (op_mode == OUT_OF_PLACE)
5456 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5457 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5458 			ciphertext_len);
5459 	} else {
5460 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5461 					plaintext_pad_len);
5462 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5463 		if (op_mode == OUT_OF_PLACE)
5464 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5465 		debug_hexdump(stdout, "plaintext:", plaintext,
5466 			plaintext_len);
5467 	}
5468 
5469 	/* Create KASUMI operation */
5470 	retval = create_wireless_algo_auth_cipher_operation(
5471 		tdata->digest.data, tdata->digest.len,
5472 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5473 		NULL, 0,
5474 		(tdata->digest.offset_bytes == 0 ?
5475 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5476 			: tdata->digest.offset_bytes),
5477 		tdata->validCipherLenInBits.len,
5478 		tdata->validCipherOffsetInBits.len,
5479 		tdata->validAuthLenInBits.len,
5480 		0,
5481 		op_mode, 0, verify);
5482 
5483 	if (retval < 0)
5484 		return retval;
5485 
5486 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5487 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5488 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5489 	else
5490 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5491 			ut_params->op);
5492 
5493 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5494 
5495 	ut_params->obuf = (op_mode == IN_PLACE ?
5496 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5497 
5498 
5499 	if (verify) {
5500 		if (ut_params->obuf)
5501 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5502 							uint8_t *);
5503 		else
5504 			plaintext = ciphertext;
5505 
5506 		debug_hexdump(stdout, "plaintext:", plaintext,
5507 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5508 		debug_hexdump(stdout, "plaintext expected:",
5509 			tdata->plaintext.data,
5510 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5511 	} else {
5512 		if (ut_params->obuf)
5513 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5514 							uint8_t *);
5515 		else
5516 			ciphertext = plaintext;
5517 
5518 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5519 			ciphertext_len);
5520 		debug_hexdump(stdout, "ciphertext expected:",
5521 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5522 
5523 		ut_params->digest = rte_pktmbuf_mtod(
5524 			ut_params->obuf, uint8_t *) +
5525 			(tdata->digest.offset_bytes == 0 ?
5526 			plaintext_pad_len : tdata->digest.offset_bytes);
5527 
5528 		debug_hexdump(stdout, "digest:", ut_params->digest,
5529 			tdata->digest.len);
5530 		debug_hexdump(stdout, "digest expected:",
5531 			tdata->digest.data, tdata->digest.len);
5532 	}
5533 
5534 	/* Validate obuf */
5535 	if (verify) {
5536 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5537 			plaintext,
5538 			tdata->plaintext.data,
5539 			tdata->plaintext.len >> 3,
5540 			"KASUMI Plaintext data not as expected");
5541 	} else {
5542 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5543 			ciphertext,
5544 			tdata->ciphertext.data,
5545 			tdata->ciphertext.len >> 3,
5546 			"KASUMI Ciphertext data not as expected");
5547 
5548 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5549 			ut_params->digest,
5550 			tdata->digest.data,
5551 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5552 			"KASUMI Generated auth tag not as expected");
5553 	}
5554 	return 0;
5555 }
5556 
5557 static int
5558 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5559 	uint8_t op_mode, uint8_t verify)
5560 {
5561 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5562 	struct crypto_unittest_params *ut_params = &unittest_params;
5563 
5564 	int retval;
5565 
5566 	const uint8_t *plaintext = NULL;
5567 	const uint8_t *ciphertext = NULL;
5568 	const uint8_t *digest = NULL;
5569 	unsigned int plaintext_pad_len;
5570 	unsigned int plaintext_len;
5571 	unsigned int ciphertext_pad_len;
5572 	unsigned int ciphertext_len;
5573 	uint8_t buffer[10000];
5574 	uint8_t digest_buffer[10000];
5575 
5576 	struct rte_cryptodev_info dev_info;
5577 
5578 	/* Verify the capabilities */
5579 	struct rte_cryptodev_sym_capability_idx cap_idx;
5580 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5581 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5582 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5583 			&cap_idx) == NULL)
5584 		return TEST_SKIPPED;
5585 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5586 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5587 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5588 			&cap_idx) == NULL)
5589 		return TEST_SKIPPED;
5590 
5591 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5592 		return TEST_SKIPPED;
5593 
5594 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5595 
5596 	uint64_t feat_flags = dev_info.feature_flags;
5597 
5598 	if (op_mode == IN_PLACE) {
5599 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5600 			printf("Device doesn't support in-place scatter-gather "
5601 					"in both input and output mbufs.\n");
5602 			return TEST_SKIPPED;
5603 		}
5604 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5605 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5606 			printf("Device doesn't support RAW data-path APIs.\n");
5607 			return TEST_SKIPPED;
5608 		}
5609 	} else {
5610 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5611 			return TEST_SKIPPED;
5612 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5613 			printf("Device doesn't support out-of-place scatter-gather "
5614 					"in both input and output mbufs.\n");
5615 			return TEST_SKIPPED;
5616 		}
5617 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5618 			printf("Device doesn't support digest encrypted.\n");
5619 			return TEST_SKIPPED;
5620 		}
5621 	}
5622 
5623 	/* Create KASUMI session */
5624 	retval = create_wireless_algo_auth_cipher_session(
5625 			ts_params->valid_devs[0],
5626 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5627 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5628 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5629 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5630 			RTE_CRYPTO_AUTH_KASUMI_F9,
5631 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5632 			tdata->key.data, tdata->key.len,
5633 			0, tdata->digest.len,
5634 			tdata->cipher_iv.len);
5635 
5636 	if (retval != 0)
5637 		return retval;
5638 
5639 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5640 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5641 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5642 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5643 
5644 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5645 			plaintext_pad_len, 15, 0);
5646 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5647 			"Failed to allocate input buffer in mempool");
5648 
5649 	if (op_mode == OUT_OF_PLACE) {
5650 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5651 				plaintext_pad_len, 15, 0);
5652 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5653 				"Failed to allocate output buffer in mempool");
5654 	}
5655 
5656 	if (verify) {
5657 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5658 			tdata->ciphertext.data);
5659 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5660 					ciphertext_len, buffer);
5661 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5662 			ciphertext_len);
5663 	} else {
5664 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5665 			tdata->plaintext.data);
5666 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5667 					plaintext_len, buffer);
5668 		debug_hexdump(stdout, "plaintext:", plaintext,
5669 			plaintext_len);
5670 	}
5671 	memset(buffer, 0, sizeof(buffer));
5672 
5673 	/* Create KASUMI operation */
5674 	retval = create_wireless_algo_auth_cipher_operation(
5675 		tdata->digest.data, tdata->digest.len,
5676 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5677 		NULL, 0,
5678 		(tdata->digest.offset_bytes == 0 ?
5679 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5680 			: tdata->digest.offset_bytes),
5681 		tdata->validCipherLenInBits.len,
5682 		tdata->validCipherOffsetInBits.len,
5683 		tdata->validAuthLenInBits.len,
5684 		0,
5685 		op_mode, 1, verify);
5686 
5687 	if (retval < 0)
5688 		return retval;
5689 
5690 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5691 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5692 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5693 	else
5694 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5695 			ut_params->op);
5696 
5697 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5698 
5699 	ut_params->obuf = (op_mode == IN_PLACE ?
5700 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5701 
5702 	if (verify) {
5703 		if (ut_params->obuf)
5704 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5705 					plaintext_len, buffer);
5706 		else
5707 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5708 					plaintext_len, buffer);
5709 
5710 		debug_hexdump(stdout, "plaintext:", plaintext,
5711 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5712 		debug_hexdump(stdout, "plaintext expected:",
5713 			tdata->plaintext.data,
5714 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5715 	} else {
5716 		if (ut_params->obuf)
5717 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5718 					ciphertext_len, buffer);
5719 		else
5720 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5721 					ciphertext_len, buffer);
5722 
5723 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5724 			ciphertext_len);
5725 		debug_hexdump(stdout, "ciphertext expected:",
5726 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5727 
5728 		if (ut_params->obuf)
5729 			digest = rte_pktmbuf_read(ut_params->obuf,
5730 				(tdata->digest.offset_bytes == 0 ?
5731 				plaintext_pad_len : tdata->digest.offset_bytes),
5732 				tdata->digest.len, digest_buffer);
5733 		else
5734 			digest = rte_pktmbuf_read(ut_params->ibuf,
5735 				(tdata->digest.offset_bytes == 0 ?
5736 				plaintext_pad_len : tdata->digest.offset_bytes),
5737 				tdata->digest.len, digest_buffer);
5738 
5739 		debug_hexdump(stdout, "digest:", digest,
5740 			tdata->digest.len);
5741 		debug_hexdump(stdout, "digest expected:",
5742 			tdata->digest.data, tdata->digest.len);
5743 	}
5744 
5745 	/* Validate obuf */
5746 	if (verify) {
5747 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5748 			plaintext,
5749 			tdata->plaintext.data,
5750 			tdata->plaintext.len >> 3,
5751 			"KASUMI Plaintext data not as expected");
5752 	} else {
5753 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5754 			ciphertext,
5755 			tdata->ciphertext.data,
5756 			tdata->validDataLenInBits.len,
5757 			"KASUMI Ciphertext data not as expected");
5758 
5759 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5760 			digest,
5761 			tdata->digest.data,
5762 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5763 			"KASUMI Generated auth tag not as expected");
5764 	}
5765 	return 0;
5766 }
5767 
5768 static int
5769 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5770 {
5771 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5772 	struct crypto_unittest_params *ut_params = &unittest_params;
5773 
5774 	int retval;
5775 
5776 	uint8_t *plaintext, *ciphertext;
5777 	unsigned plaintext_pad_len;
5778 	unsigned plaintext_len;
5779 	struct rte_cryptodev_info dev_info;
5780 
5781 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5782 	uint64_t feat_flags = dev_info.feature_flags;
5783 
5784 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5785 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5786 		printf("Device doesn't support RAW data-path APIs.\n");
5787 		return TEST_SKIPPED;
5788 	}
5789 
5790 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5791 		return TEST_SKIPPED;
5792 
5793 	/* Verify the capabilities */
5794 	struct rte_cryptodev_sym_capability_idx cap_idx;
5795 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5796 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5797 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5798 			&cap_idx) == NULL)
5799 		return TEST_SKIPPED;
5800 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5801 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5802 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5803 			&cap_idx) == NULL)
5804 		return TEST_SKIPPED;
5805 
5806 	/* Create KASUMI session */
5807 	retval = create_wireless_algo_cipher_auth_session(
5808 			ts_params->valid_devs[0],
5809 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5810 			RTE_CRYPTO_AUTH_OP_GENERATE,
5811 			RTE_CRYPTO_AUTH_KASUMI_F9,
5812 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5813 			tdata->key.data, tdata->key.len,
5814 			0, tdata->digest.len,
5815 			tdata->cipher_iv.len);
5816 	if (retval != 0)
5817 		return retval;
5818 
5819 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5820 
5821 	/* clear mbuf payload */
5822 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5823 			rte_pktmbuf_tailroom(ut_params->ibuf));
5824 
5825 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5826 	/* Append data which is padded to a multiple of */
5827 	/* the algorithms block size */
5828 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5829 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5830 				plaintext_pad_len);
5831 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5832 
5833 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5834 
5835 	/* Create KASUMI operation */
5836 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5837 				tdata->digest.len, NULL, 0,
5838 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5839 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5840 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5841 				tdata->validCipherOffsetInBits.len,
5842 				tdata->validAuthLenInBits.len,
5843 				0
5844 				);
5845 	if (retval < 0)
5846 		return retval;
5847 
5848 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5849 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5850 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5851 	else
5852 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5853 			ut_params->op);
5854 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5855 
5856 	if (ut_params->op->sym->m_dst)
5857 		ut_params->obuf = ut_params->op->sym->m_dst;
5858 	else
5859 		ut_params->obuf = ut_params->op->sym->m_src;
5860 
5861 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5862 				tdata->validCipherOffsetInBits.len >> 3);
5863 
5864 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5865 			+ plaintext_pad_len;
5866 
5867 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5868 				(tdata->validCipherOffsetInBits.len >> 3);
5869 	/* Validate obuf */
5870 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5871 		ciphertext,
5872 		reference_ciphertext,
5873 		tdata->validCipherLenInBits.len,
5874 		"KASUMI Ciphertext data not as expected");
5875 
5876 	/* Validate obuf */
5877 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5878 		ut_params->digest,
5879 		tdata->digest.data,
5880 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5881 		"KASUMI Generated auth tag not as expected");
5882 	return 0;
5883 }
5884 
5885 static int
5886 test_zuc_encryption(const struct wireless_test_data *tdata)
5887 {
5888 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5889 	struct crypto_unittest_params *ut_params = &unittest_params;
5890 
5891 	int retval;
5892 	uint8_t *plaintext, *ciphertext;
5893 	unsigned plaintext_pad_len;
5894 	unsigned plaintext_len;
5895 	struct rte_cryptodev_info dev_info;
5896 
5897 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5898 	uint64_t feat_flags = dev_info.feature_flags;
5899 
5900 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5901 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5902 		printf("Device doesn't support RAW data-path APIs.\n");
5903 		return TEST_SKIPPED;
5904 	}
5905 
5906 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5907 		return TEST_SKIPPED;
5908 
5909 	struct rte_cryptodev_sym_capability_idx cap_idx;
5910 
5911 	/* Check if device supports ZUC EEA3 */
5912 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5913 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5914 
5915 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5916 			&cap_idx) == NULL)
5917 		return TEST_SKIPPED;
5918 
5919 	/* Create ZUC session */
5920 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
5921 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5922 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
5923 					tdata->key.data, tdata->key.len,
5924 					tdata->cipher_iv.len);
5925 	if (retval != 0)
5926 		return retval;
5927 
5928 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5929 
5930 	/* Clear mbuf payload */
5931 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5932 	       rte_pktmbuf_tailroom(ut_params->ibuf));
5933 
5934 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5935 	/* Append data which is padded to a multiple */
5936 	/* of the algorithms block size */
5937 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
5938 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5939 				plaintext_pad_len);
5940 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5941 
5942 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5943 
5944 	/* Create ZUC operation */
5945 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
5946 					tdata->cipher_iv.len,
5947 					tdata->plaintext.len,
5948 					0);
5949 	if (retval < 0)
5950 		return retval;
5951 
5952 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5953 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5954 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
5955 	else
5956 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5957 						ut_params->op);
5958 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5959 
5960 	ut_params->obuf = ut_params->op->sym->m_dst;
5961 	if (ut_params->obuf)
5962 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
5963 	else
5964 		ciphertext = plaintext;
5965 
5966 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
5967 
5968 	/* Validate obuf */
5969 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5970 		ciphertext,
5971 		tdata->ciphertext.data,
5972 		tdata->validCipherLenInBits.len,
5973 		"ZUC Ciphertext data not as expected");
5974 	return 0;
5975 }
5976 
5977 static int
5978 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
5979 {
5980 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5981 	struct crypto_unittest_params *ut_params = &unittest_params;
5982 
5983 	int retval;
5984 
5985 	unsigned int plaintext_pad_len;
5986 	unsigned int plaintext_len;
5987 	const uint8_t *ciphertext;
5988 	uint8_t ciphertext_buffer[2048];
5989 	struct rte_cryptodev_info dev_info;
5990 
5991 	struct rte_cryptodev_sym_capability_idx cap_idx;
5992 
5993 	/* Check if device supports ZUC EEA3 */
5994 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5995 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
5996 
5997 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5998 			&cap_idx) == NULL)
5999 		return TEST_SKIPPED;
6000 
6001 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6002 		return TEST_SKIPPED;
6003 
6004 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6005 
6006 	uint64_t feat_flags = dev_info.feature_flags;
6007 
6008 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6009 		printf("Device doesn't support in-place scatter-gather. "
6010 				"Test Skipped.\n");
6011 		return TEST_SKIPPED;
6012 	}
6013 
6014 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6015 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6016 		printf("Device doesn't support RAW data-path APIs.\n");
6017 		return TEST_SKIPPED;
6018 	}
6019 
6020 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6021 
6022 	/* Append data which is padded to a multiple */
6023 	/* of the algorithms block size */
6024 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6025 
6026 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6027 			plaintext_pad_len, 10, 0);
6028 
6029 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6030 			tdata->plaintext.data);
6031 
6032 	/* Create ZUC session */
6033 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6034 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6035 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6036 			tdata->key.data, tdata->key.len,
6037 			tdata->cipher_iv.len);
6038 	if (retval < 0)
6039 		return retval;
6040 
6041 	/* Clear mbuf payload */
6042 
6043 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6044 
6045 	/* Create ZUC operation */
6046 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6047 			tdata->cipher_iv.len, tdata->plaintext.len,
6048 			0);
6049 	if (retval < 0)
6050 		return retval;
6051 
6052 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6053 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6054 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6055 	else
6056 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6057 						ut_params->op);
6058 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6059 
6060 	ut_params->obuf = ut_params->op->sym->m_dst;
6061 	if (ut_params->obuf)
6062 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6063 			0, plaintext_len, ciphertext_buffer);
6064 	else
6065 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6066 			0, plaintext_len, ciphertext_buffer);
6067 
6068 	/* Validate obuf */
6069 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6070 
6071 	/* Validate obuf */
6072 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6073 		ciphertext,
6074 		tdata->ciphertext.data,
6075 		tdata->validCipherLenInBits.len,
6076 		"ZUC Ciphertext data not as expected");
6077 
6078 	return 0;
6079 }
6080 
6081 static int
6082 test_zuc_authentication(const struct wireless_test_data *tdata)
6083 {
6084 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6085 	struct crypto_unittest_params *ut_params = &unittest_params;
6086 
6087 	int retval;
6088 	unsigned plaintext_pad_len;
6089 	unsigned plaintext_len;
6090 	uint8_t *plaintext;
6091 
6092 	struct rte_cryptodev_sym_capability_idx cap_idx;
6093 	struct rte_cryptodev_info dev_info;
6094 
6095 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6096 	uint64_t feat_flags = dev_info.feature_flags;
6097 
6098 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6099 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6100 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6101 		return TEST_SKIPPED;
6102 	}
6103 
6104 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6105 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6106 		printf("Device doesn't support RAW data-path APIs.\n");
6107 		return TEST_SKIPPED;
6108 	}
6109 
6110 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6111 		return TEST_SKIPPED;
6112 
6113 	/* Check if device supports ZUC EIA3 */
6114 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6115 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6116 
6117 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6118 			&cap_idx) == NULL)
6119 		return TEST_SKIPPED;
6120 
6121 	/* Create ZUC session */
6122 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6123 			tdata->key.data, tdata->key.len,
6124 			tdata->auth_iv.len, tdata->digest.len,
6125 			RTE_CRYPTO_AUTH_OP_GENERATE,
6126 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6127 	if (retval != 0)
6128 		return retval;
6129 
6130 	/* alloc mbuf and set payload */
6131 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6132 
6133 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6134 	rte_pktmbuf_tailroom(ut_params->ibuf));
6135 
6136 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6137 	/* Append data which is padded to a multiple of */
6138 	/* the algorithms block size */
6139 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6140 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6141 				plaintext_pad_len);
6142 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6143 
6144 	/* Create ZUC operation */
6145 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6146 			tdata->auth_iv.data, tdata->auth_iv.len,
6147 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6148 			tdata->validAuthLenInBits.len,
6149 			0);
6150 	if (retval < 0)
6151 		return retval;
6152 
6153 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6154 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6155 				ut_params->op, 0, 1, 1, 0);
6156 	else
6157 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6158 				ut_params->op);
6159 	ut_params->obuf = ut_params->op->sym->m_src;
6160 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6161 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6162 			+ plaintext_pad_len;
6163 
6164 	/* Validate obuf */
6165 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6166 	ut_params->digest,
6167 	tdata->digest.data,
6168 	tdata->digest.len,
6169 	"ZUC Generated auth tag not as expected");
6170 
6171 	return 0;
6172 }
6173 
6174 static int
6175 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6176 	uint8_t op_mode, uint8_t verify)
6177 {
6178 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6179 	struct crypto_unittest_params *ut_params = &unittest_params;
6180 
6181 	int retval;
6182 
6183 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6184 	unsigned int plaintext_pad_len;
6185 	unsigned int plaintext_len;
6186 	unsigned int ciphertext_pad_len;
6187 	unsigned int ciphertext_len;
6188 
6189 	struct rte_cryptodev_info dev_info;
6190 	struct rte_cryptodev_sym_capability_idx cap_idx;
6191 
6192 	/* Check if device supports ZUC EIA3 */
6193 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6194 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6195 
6196 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6197 			&cap_idx) == NULL)
6198 		return TEST_SKIPPED;
6199 
6200 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6201 
6202 	uint64_t feat_flags = dev_info.feature_flags;
6203 
6204 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6205 		printf("Device doesn't support digest encrypted.\n");
6206 		return TEST_SKIPPED;
6207 	}
6208 	if (op_mode == IN_PLACE) {
6209 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6210 			printf("Device doesn't support in-place scatter-gather "
6211 					"in both input and output mbufs.\n");
6212 			return TEST_SKIPPED;
6213 		}
6214 
6215 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6216 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6217 			printf("Device doesn't support RAW data-path APIs.\n");
6218 			return TEST_SKIPPED;
6219 		}
6220 	} else {
6221 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6222 			return TEST_SKIPPED;
6223 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6224 			printf("Device doesn't support out-of-place scatter-gather "
6225 					"in both input and output mbufs.\n");
6226 			return TEST_SKIPPED;
6227 		}
6228 	}
6229 
6230 	/* Create ZUC session */
6231 	retval = create_wireless_algo_auth_cipher_session(
6232 			ts_params->valid_devs[0],
6233 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6234 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6235 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6236 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6237 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6238 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6239 			tdata->key.data, tdata->key.len,
6240 			tdata->auth_iv.len, tdata->digest.len,
6241 			tdata->cipher_iv.len);
6242 
6243 	if (retval != 0)
6244 		return retval;
6245 
6246 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6247 	if (op_mode == OUT_OF_PLACE)
6248 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6249 
6250 	/* clear mbuf payload */
6251 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6252 		rte_pktmbuf_tailroom(ut_params->ibuf));
6253 	if (op_mode == OUT_OF_PLACE)
6254 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6255 			rte_pktmbuf_tailroom(ut_params->obuf));
6256 
6257 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6258 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6259 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6260 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6261 
6262 	if (verify) {
6263 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6264 					ciphertext_pad_len);
6265 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6266 		if (op_mode == OUT_OF_PLACE)
6267 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6268 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6269 			ciphertext_len);
6270 	} else {
6271 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6272 					plaintext_pad_len);
6273 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6274 		if (op_mode == OUT_OF_PLACE)
6275 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
6276 		debug_hexdump(stdout, "plaintext:", plaintext,
6277 			plaintext_len);
6278 	}
6279 
6280 	/* Create ZUC operation */
6281 	retval = create_wireless_algo_auth_cipher_operation(
6282 		tdata->digest.data, tdata->digest.len,
6283 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6284 		tdata->auth_iv.data, tdata->auth_iv.len,
6285 		(tdata->digest.offset_bytes == 0 ?
6286 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6287 			: tdata->digest.offset_bytes),
6288 		tdata->validCipherLenInBits.len,
6289 		tdata->validCipherOffsetInBits.len,
6290 		tdata->validAuthLenInBits.len,
6291 		0,
6292 		op_mode, 0, verify);
6293 
6294 	if (retval < 0)
6295 		return retval;
6296 
6297 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6298 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6299 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6300 	else
6301 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6302 			ut_params->op);
6303 
6304 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6305 
6306 	ut_params->obuf = (op_mode == IN_PLACE ?
6307 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6308 
6309 
6310 	if (verify) {
6311 		if (ut_params->obuf)
6312 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6313 							uint8_t *);
6314 		else
6315 			plaintext = ciphertext;
6316 
6317 		debug_hexdump(stdout, "plaintext:", plaintext,
6318 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6319 		debug_hexdump(stdout, "plaintext expected:",
6320 			tdata->plaintext.data,
6321 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6322 	} else {
6323 		if (ut_params->obuf)
6324 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6325 							uint8_t *);
6326 		else
6327 			ciphertext = plaintext;
6328 
6329 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6330 			ciphertext_len);
6331 		debug_hexdump(stdout, "ciphertext expected:",
6332 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6333 
6334 		ut_params->digest = rte_pktmbuf_mtod(
6335 			ut_params->obuf, uint8_t *) +
6336 			(tdata->digest.offset_bytes == 0 ?
6337 			plaintext_pad_len : tdata->digest.offset_bytes);
6338 
6339 		debug_hexdump(stdout, "digest:", ut_params->digest,
6340 			tdata->digest.len);
6341 		debug_hexdump(stdout, "digest expected:",
6342 			tdata->digest.data, tdata->digest.len);
6343 	}
6344 
6345 	/* Validate obuf */
6346 	if (verify) {
6347 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6348 			plaintext,
6349 			tdata->plaintext.data,
6350 			tdata->plaintext.len >> 3,
6351 			"ZUC Plaintext data not as expected");
6352 	} else {
6353 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6354 			ciphertext,
6355 			tdata->ciphertext.data,
6356 			tdata->ciphertext.len >> 3,
6357 			"ZUC Ciphertext data not as expected");
6358 
6359 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6360 			ut_params->digest,
6361 			tdata->digest.data,
6362 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6363 			"ZUC Generated auth tag not as expected");
6364 	}
6365 	return 0;
6366 }
6367 
6368 static int
6369 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6370 	uint8_t op_mode, uint8_t verify)
6371 {
6372 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6373 	struct crypto_unittest_params *ut_params = &unittest_params;
6374 
6375 	int retval;
6376 
6377 	const uint8_t *plaintext = NULL;
6378 	const uint8_t *ciphertext = NULL;
6379 	const uint8_t *digest = NULL;
6380 	unsigned int plaintext_pad_len;
6381 	unsigned int plaintext_len;
6382 	unsigned int ciphertext_pad_len;
6383 	unsigned int ciphertext_len;
6384 	uint8_t buffer[10000];
6385 	uint8_t digest_buffer[10000];
6386 
6387 	struct rte_cryptodev_info dev_info;
6388 	struct rte_cryptodev_sym_capability_idx cap_idx;
6389 
6390 	/* Check if device supports ZUC EIA3 */
6391 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6392 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
6393 
6394 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
6395 			&cap_idx) == NULL)
6396 		return TEST_SKIPPED;
6397 
6398 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6399 
6400 	uint64_t feat_flags = dev_info.feature_flags;
6401 
6402 	if (op_mode == IN_PLACE) {
6403 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6404 			printf("Device doesn't support in-place scatter-gather "
6405 					"in both input and output mbufs.\n");
6406 			return TEST_SKIPPED;
6407 		}
6408 
6409 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6410 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6411 			printf("Device doesn't support RAW data-path APIs.\n");
6412 			return TEST_SKIPPED;
6413 		}
6414 	} else {
6415 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6416 			return TEST_SKIPPED;
6417 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6418 			printf("Device doesn't support out-of-place scatter-gather "
6419 					"in both input and output mbufs.\n");
6420 			return TEST_SKIPPED;
6421 		}
6422 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6423 			printf("Device doesn't support digest encrypted.\n");
6424 			return TEST_SKIPPED;
6425 		}
6426 	}
6427 
6428 	/* Create ZUC session */
6429 	retval = create_wireless_algo_auth_cipher_session(
6430 			ts_params->valid_devs[0],
6431 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6432 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6433 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6434 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6435 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6436 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6437 			tdata->key.data, tdata->key.len,
6438 			tdata->auth_iv.len, tdata->digest.len,
6439 			tdata->cipher_iv.len);
6440 
6441 	if (retval != 0)
6442 		return retval;
6443 
6444 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6445 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6446 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6447 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6448 
6449 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6450 			plaintext_pad_len, 15, 0);
6451 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6452 			"Failed to allocate input buffer in mempool");
6453 
6454 	if (op_mode == OUT_OF_PLACE) {
6455 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6456 				plaintext_pad_len, 15, 0);
6457 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6458 				"Failed to allocate output buffer in mempool");
6459 	}
6460 
6461 	if (verify) {
6462 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6463 			tdata->ciphertext.data);
6464 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6465 					ciphertext_len, buffer);
6466 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6467 			ciphertext_len);
6468 	} else {
6469 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6470 			tdata->plaintext.data);
6471 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6472 					plaintext_len, buffer);
6473 		debug_hexdump(stdout, "plaintext:", plaintext,
6474 			plaintext_len);
6475 	}
6476 	memset(buffer, 0, sizeof(buffer));
6477 
6478 	/* Create ZUC operation */
6479 	retval = create_wireless_algo_auth_cipher_operation(
6480 		tdata->digest.data, tdata->digest.len,
6481 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6482 		NULL, 0,
6483 		(tdata->digest.offset_bytes == 0 ?
6484 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6485 			: tdata->digest.offset_bytes),
6486 		tdata->validCipherLenInBits.len,
6487 		tdata->validCipherOffsetInBits.len,
6488 		tdata->validAuthLenInBits.len,
6489 		0,
6490 		op_mode, 1, verify);
6491 
6492 	if (retval < 0)
6493 		return retval;
6494 
6495 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6496 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6497 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6498 	else
6499 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6500 			ut_params->op);
6501 
6502 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6503 
6504 	ut_params->obuf = (op_mode == IN_PLACE ?
6505 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6506 
6507 	if (verify) {
6508 		if (ut_params->obuf)
6509 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6510 					plaintext_len, buffer);
6511 		else
6512 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6513 					plaintext_len, buffer);
6514 
6515 		debug_hexdump(stdout, "plaintext:", plaintext,
6516 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6517 		debug_hexdump(stdout, "plaintext expected:",
6518 			tdata->plaintext.data,
6519 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6520 	} else {
6521 		if (ut_params->obuf)
6522 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6523 					ciphertext_len, buffer);
6524 		else
6525 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6526 					ciphertext_len, buffer);
6527 
6528 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6529 			ciphertext_len);
6530 		debug_hexdump(stdout, "ciphertext expected:",
6531 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6532 
6533 		if (ut_params->obuf)
6534 			digest = rte_pktmbuf_read(ut_params->obuf,
6535 				(tdata->digest.offset_bytes == 0 ?
6536 				plaintext_pad_len : tdata->digest.offset_bytes),
6537 				tdata->digest.len, digest_buffer);
6538 		else
6539 			digest = rte_pktmbuf_read(ut_params->ibuf,
6540 				(tdata->digest.offset_bytes == 0 ?
6541 				plaintext_pad_len : tdata->digest.offset_bytes),
6542 				tdata->digest.len, digest_buffer);
6543 
6544 		debug_hexdump(stdout, "digest:", digest,
6545 			tdata->digest.len);
6546 		debug_hexdump(stdout, "digest expected:",
6547 			tdata->digest.data, tdata->digest.len);
6548 	}
6549 
6550 	/* Validate obuf */
6551 	if (verify) {
6552 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6553 			plaintext,
6554 			tdata->plaintext.data,
6555 			tdata->plaintext.len >> 3,
6556 			"ZUC Plaintext data not as expected");
6557 	} else {
6558 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6559 			ciphertext,
6560 			tdata->ciphertext.data,
6561 			tdata->validDataLenInBits.len,
6562 			"ZUC Ciphertext data not as expected");
6563 
6564 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6565 			digest,
6566 			tdata->digest.data,
6567 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6568 			"ZUC Generated auth tag not as expected");
6569 	}
6570 	return 0;
6571 }
6572 
6573 static int
6574 test_kasumi_encryption_test_case_1(void)
6575 {
6576 	return test_kasumi_encryption(&kasumi_test_case_1);
6577 }
6578 
6579 static int
6580 test_kasumi_encryption_test_case_1_sgl(void)
6581 {
6582 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6583 }
6584 
6585 static int
6586 test_kasumi_encryption_test_case_1_oop(void)
6587 {
6588 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6589 }
6590 
6591 static int
6592 test_kasumi_encryption_test_case_1_oop_sgl(void)
6593 {
6594 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6595 }
6596 
6597 static int
6598 test_kasumi_encryption_test_case_2(void)
6599 {
6600 	return test_kasumi_encryption(&kasumi_test_case_2);
6601 }
6602 
6603 static int
6604 test_kasumi_encryption_test_case_3(void)
6605 {
6606 	return test_kasumi_encryption(&kasumi_test_case_3);
6607 }
6608 
6609 static int
6610 test_kasumi_encryption_test_case_4(void)
6611 {
6612 	return test_kasumi_encryption(&kasumi_test_case_4);
6613 }
6614 
6615 static int
6616 test_kasumi_encryption_test_case_5(void)
6617 {
6618 	return test_kasumi_encryption(&kasumi_test_case_5);
6619 }
6620 
6621 static int
6622 test_kasumi_decryption_test_case_1(void)
6623 {
6624 	return test_kasumi_decryption(&kasumi_test_case_1);
6625 }
6626 
6627 static int
6628 test_kasumi_decryption_test_case_1_oop(void)
6629 {
6630 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6631 }
6632 
6633 static int
6634 test_kasumi_decryption_test_case_2(void)
6635 {
6636 	return test_kasumi_decryption(&kasumi_test_case_2);
6637 }
6638 
6639 static int
6640 test_kasumi_decryption_test_case_3(void)
6641 {
6642 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6643 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6644 		return TEST_SKIPPED;
6645 	return test_kasumi_decryption(&kasumi_test_case_3);
6646 }
6647 
6648 static int
6649 test_kasumi_decryption_test_case_4(void)
6650 {
6651 	return test_kasumi_decryption(&kasumi_test_case_4);
6652 }
6653 
6654 static int
6655 test_kasumi_decryption_test_case_5(void)
6656 {
6657 	return test_kasumi_decryption(&kasumi_test_case_5);
6658 }
6659 static int
6660 test_snow3g_encryption_test_case_1(void)
6661 {
6662 	return test_snow3g_encryption(&snow3g_test_case_1);
6663 }
6664 
6665 static int
6666 test_snow3g_encryption_test_case_1_oop(void)
6667 {
6668 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6669 }
6670 
6671 static int
6672 test_snow3g_encryption_test_case_1_oop_sgl(void)
6673 {
6674 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6675 }
6676 
6677 
6678 static int
6679 test_snow3g_encryption_test_case_1_offset_oop(void)
6680 {
6681 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6682 }
6683 
6684 static int
6685 test_snow3g_encryption_test_case_2(void)
6686 {
6687 	return test_snow3g_encryption(&snow3g_test_case_2);
6688 }
6689 
6690 static int
6691 test_snow3g_encryption_test_case_3(void)
6692 {
6693 	return test_snow3g_encryption(&snow3g_test_case_3);
6694 }
6695 
6696 static int
6697 test_snow3g_encryption_test_case_4(void)
6698 {
6699 	return test_snow3g_encryption(&snow3g_test_case_4);
6700 }
6701 
6702 static int
6703 test_snow3g_encryption_test_case_5(void)
6704 {
6705 	return test_snow3g_encryption(&snow3g_test_case_5);
6706 }
6707 
6708 static int
6709 test_snow3g_decryption_test_case_1(void)
6710 {
6711 	return test_snow3g_decryption(&snow3g_test_case_1);
6712 }
6713 
6714 static int
6715 test_snow3g_decryption_test_case_1_oop(void)
6716 {
6717 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6718 }
6719 
6720 static int
6721 test_snow3g_decryption_test_case_2(void)
6722 {
6723 	return test_snow3g_decryption(&snow3g_test_case_2);
6724 }
6725 
6726 static int
6727 test_snow3g_decryption_test_case_3(void)
6728 {
6729 	return test_snow3g_decryption(&snow3g_test_case_3);
6730 }
6731 
6732 static int
6733 test_snow3g_decryption_test_case_4(void)
6734 {
6735 	return test_snow3g_decryption(&snow3g_test_case_4);
6736 }
6737 
6738 static int
6739 test_snow3g_decryption_test_case_5(void)
6740 {
6741 	return test_snow3g_decryption(&snow3g_test_case_5);
6742 }
6743 
6744 /*
6745  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6746  * Pattern digest from snow3g_test_data must be allocated as
6747  * 4 last bytes in plaintext.
6748  */
6749 static void
6750 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6751 		struct snow3g_hash_test_data *output)
6752 {
6753 	if ((pattern != NULL) && (output != NULL)) {
6754 		output->key.len = pattern->key.len;
6755 
6756 		memcpy(output->key.data,
6757 		pattern->key.data, pattern->key.len);
6758 
6759 		output->auth_iv.len = pattern->auth_iv.len;
6760 
6761 		memcpy(output->auth_iv.data,
6762 		pattern->auth_iv.data, pattern->auth_iv.len);
6763 
6764 		output->plaintext.len = pattern->plaintext.len;
6765 
6766 		memcpy(output->plaintext.data,
6767 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6768 
6769 		output->digest.len = pattern->digest.len;
6770 
6771 		memcpy(output->digest.data,
6772 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6773 		pattern->digest.len);
6774 
6775 		output->validAuthLenInBits.len =
6776 		pattern->validAuthLenInBits.len;
6777 	}
6778 }
6779 
6780 /*
6781  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6782  */
6783 static int
6784 test_snow3g_decryption_with_digest_test_case_1(void)
6785 {
6786 	struct snow3g_hash_test_data snow3g_hash_data;
6787 	struct rte_cryptodev_info dev_info;
6788 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6789 
6790 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6791 	uint64_t feat_flags = dev_info.feature_flags;
6792 
6793 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6794 		printf("Device doesn't support encrypted digest operations.\n");
6795 		return TEST_SKIPPED;
6796 	}
6797 
6798 	/*
6799 	 * Function prepare data for hash veryfication test case.
6800 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6801 	 */
6802 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6803 
6804 	return test_snow3g_decryption(&snow3g_test_case_7) &
6805 			test_snow3g_authentication_verify(&snow3g_hash_data);
6806 }
6807 
6808 static int
6809 test_snow3g_cipher_auth_test_case_1(void)
6810 {
6811 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6812 }
6813 
6814 static int
6815 test_snow3g_auth_cipher_test_case_1(void)
6816 {
6817 	return test_snow3g_auth_cipher(
6818 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6819 }
6820 
6821 static int
6822 test_snow3g_auth_cipher_test_case_2(void)
6823 {
6824 	return test_snow3g_auth_cipher(
6825 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6826 }
6827 
6828 static int
6829 test_snow3g_auth_cipher_test_case_2_oop(void)
6830 {
6831 	return test_snow3g_auth_cipher(
6832 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6833 }
6834 
6835 static int
6836 test_snow3g_auth_cipher_part_digest_enc(void)
6837 {
6838 	return test_snow3g_auth_cipher(
6839 		&snow3g_auth_cipher_partial_digest_encryption,
6840 			IN_PLACE, 0);
6841 }
6842 
6843 static int
6844 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6845 {
6846 	return test_snow3g_auth_cipher(
6847 		&snow3g_auth_cipher_partial_digest_encryption,
6848 			OUT_OF_PLACE, 0);
6849 }
6850 
6851 static int
6852 test_snow3g_auth_cipher_test_case_3_sgl(void)
6853 {
6854 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6855 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6856 		return TEST_SKIPPED;
6857 	return test_snow3g_auth_cipher_sgl(
6858 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6859 }
6860 
6861 static int
6862 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6863 {
6864 	return test_snow3g_auth_cipher_sgl(
6865 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6866 }
6867 
6868 static int
6869 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6870 {
6871 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6872 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6873 		return TEST_SKIPPED;
6874 	return test_snow3g_auth_cipher_sgl(
6875 		&snow3g_auth_cipher_partial_digest_encryption,
6876 			IN_PLACE, 0);
6877 }
6878 
6879 static int
6880 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6881 {
6882 	return test_snow3g_auth_cipher_sgl(
6883 		&snow3g_auth_cipher_partial_digest_encryption,
6884 			OUT_OF_PLACE, 0);
6885 }
6886 
6887 static int
6888 test_snow3g_auth_cipher_verify_test_case_1(void)
6889 {
6890 	return test_snow3g_auth_cipher(
6891 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6892 }
6893 
6894 static int
6895 test_snow3g_auth_cipher_verify_test_case_2(void)
6896 {
6897 	return test_snow3g_auth_cipher(
6898 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6899 }
6900 
6901 static int
6902 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6903 {
6904 	return test_snow3g_auth_cipher(
6905 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6906 }
6907 
6908 static int
6909 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6910 {
6911 	return test_snow3g_auth_cipher(
6912 		&snow3g_auth_cipher_partial_digest_encryption,
6913 			IN_PLACE, 1);
6914 }
6915 
6916 static int
6917 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6918 {
6919 	return test_snow3g_auth_cipher(
6920 		&snow3g_auth_cipher_partial_digest_encryption,
6921 			OUT_OF_PLACE, 1);
6922 }
6923 
6924 static int
6925 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
6926 {
6927 	return test_snow3g_auth_cipher_sgl(
6928 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
6929 }
6930 
6931 static int
6932 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
6933 {
6934 	return test_snow3g_auth_cipher_sgl(
6935 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
6936 }
6937 
6938 static int
6939 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
6940 {
6941 	return test_snow3g_auth_cipher_sgl(
6942 		&snow3g_auth_cipher_partial_digest_encryption,
6943 			IN_PLACE, 1);
6944 }
6945 
6946 static int
6947 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
6948 {
6949 	return test_snow3g_auth_cipher_sgl(
6950 		&snow3g_auth_cipher_partial_digest_encryption,
6951 			OUT_OF_PLACE, 1);
6952 }
6953 
6954 static int
6955 test_snow3g_auth_cipher_with_digest_test_case_1(void)
6956 {
6957 	return test_snow3g_auth_cipher(
6958 		&snow3g_test_case_7, IN_PLACE, 0);
6959 }
6960 
6961 static int
6962 test_kasumi_auth_cipher_test_case_1(void)
6963 {
6964 	return test_kasumi_auth_cipher(
6965 		&kasumi_test_case_3, IN_PLACE, 0);
6966 }
6967 
6968 static int
6969 test_kasumi_auth_cipher_test_case_2(void)
6970 {
6971 	return test_kasumi_auth_cipher(
6972 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6973 }
6974 
6975 static int
6976 test_kasumi_auth_cipher_test_case_2_oop(void)
6977 {
6978 	return test_kasumi_auth_cipher(
6979 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6980 }
6981 
6982 static int
6983 test_kasumi_auth_cipher_test_case_2_sgl(void)
6984 {
6985 	return test_kasumi_auth_cipher_sgl(
6986 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
6987 }
6988 
6989 static int
6990 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
6991 {
6992 	return test_kasumi_auth_cipher_sgl(
6993 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6994 }
6995 
6996 static int
6997 test_kasumi_auth_cipher_verify_test_case_1(void)
6998 {
6999 	return test_kasumi_auth_cipher(
7000 		&kasumi_test_case_3, IN_PLACE, 1);
7001 }
7002 
7003 static int
7004 test_kasumi_auth_cipher_verify_test_case_2(void)
7005 {
7006 	return test_kasumi_auth_cipher(
7007 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7008 }
7009 
7010 static int
7011 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7012 {
7013 	return test_kasumi_auth_cipher(
7014 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7015 }
7016 
7017 static int
7018 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7019 {
7020 	return test_kasumi_auth_cipher_sgl(
7021 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7022 }
7023 
7024 static int
7025 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7026 {
7027 	return test_kasumi_auth_cipher_sgl(
7028 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7029 }
7030 
7031 static int
7032 test_kasumi_cipher_auth_test_case_1(void)
7033 {
7034 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7035 }
7036 
7037 static int
7038 test_zuc_encryption_test_case_1(void)
7039 {
7040 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
7041 }
7042 
7043 static int
7044 test_zuc_encryption_test_case_2(void)
7045 {
7046 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
7047 }
7048 
7049 static int
7050 test_zuc_encryption_test_case_3(void)
7051 {
7052 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7053 }
7054 
7055 static int
7056 test_zuc_encryption_test_case_4(void)
7057 {
7058 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7059 }
7060 
7061 static int
7062 test_zuc_encryption_test_case_5(void)
7063 {
7064 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7065 }
7066 
7067 static int
7068 test_zuc_encryption_test_case_6_sgl(void)
7069 {
7070 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7071 }
7072 
7073 static int
7074 test_zuc_encryption_test_case_7(void)
7075 {
7076 	return test_zuc_encryption(&zuc_test_case_cipher_800b_key_256b);
7077 }
7078 
7079 static int
7080 test_zuc_hash_generate_test_case_1(void)
7081 {
7082 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7083 }
7084 
7085 static int
7086 test_zuc_hash_generate_test_case_2(void)
7087 {
7088 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7089 }
7090 
7091 static int
7092 test_zuc_hash_generate_test_case_3(void)
7093 {
7094 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7095 }
7096 
7097 static int
7098 test_zuc_hash_generate_test_case_4(void)
7099 {
7100 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7101 }
7102 
7103 static int
7104 test_zuc_hash_generate_test_case_5(void)
7105 {
7106 	return test_zuc_authentication(&zuc_test_auth_5670b);
7107 }
7108 
7109 static int
7110 test_zuc_hash_generate_test_case_6(void)
7111 {
7112 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7113 }
7114 
7115 static int
7116 test_zuc_hash_generate_test_case_7(void)
7117 {
7118 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7119 }
7120 
7121 static int
7122 test_zuc_hash_generate_test_case_8(void)
7123 {
7124 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7125 }
7126 
7127 static int
7128 test_zuc_hash_generate_test_case_9(void)
7129 {
7130 	return test_zuc_authentication(&zuc_test_case_auth_584b_mac_64b);
7131 }
7132 
7133 static int
7134 test_zuc_hash_generate_test_case_10(void)
7135 {
7136 	return test_zuc_authentication(&zuc_test_case_auth_2080b_mac_128b);
7137 }
7138 
7139 static int
7140 test_zuc_cipher_auth_test_case_1(void)
7141 {
7142 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7143 }
7144 
7145 static int
7146 test_zuc_cipher_auth_test_case_2(void)
7147 {
7148 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7149 }
7150 
7151 static int
7152 test_zuc_auth_cipher_test_case_1(void)
7153 {
7154 	return test_zuc_auth_cipher(
7155 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7156 }
7157 
7158 static int
7159 test_zuc_auth_cipher_test_case_1_oop(void)
7160 {
7161 	return test_zuc_auth_cipher(
7162 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7163 }
7164 
7165 static int
7166 test_zuc_auth_cipher_test_case_1_sgl(void)
7167 {
7168 	return test_zuc_auth_cipher_sgl(
7169 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7170 }
7171 
7172 static int
7173 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7174 {
7175 	return test_zuc_auth_cipher_sgl(
7176 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7177 }
7178 
7179 static int
7180 test_zuc_auth_cipher_verify_test_case_1(void)
7181 {
7182 	return test_zuc_auth_cipher(
7183 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7184 }
7185 
7186 static int
7187 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7188 {
7189 	return test_zuc_auth_cipher(
7190 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7191 }
7192 
7193 static int
7194 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7195 {
7196 	return test_zuc_auth_cipher_sgl(
7197 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7198 }
7199 
7200 static int
7201 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7202 {
7203 	return test_zuc_auth_cipher_sgl(
7204 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7205 }
7206 
7207 static int
7208 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7209 {
7210 	uint8_t dev_id = testsuite_params.valid_devs[0];
7211 
7212 	struct rte_cryptodev_sym_capability_idx cap_idx;
7213 
7214 	/* Check if device supports particular cipher algorithm */
7215 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7216 	cap_idx.algo.cipher = tdata->cipher_algo;
7217 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7218 		return TEST_SKIPPED;
7219 
7220 	/* Check if device supports particular hash algorithm */
7221 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7222 	cap_idx.algo.auth = tdata->auth_algo;
7223 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7224 		return TEST_SKIPPED;
7225 
7226 	return 0;
7227 }
7228 
7229 static int
7230 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7231 	uint8_t op_mode, uint8_t verify)
7232 {
7233 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7234 	struct crypto_unittest_params *ut_params = &unittest_params;
7235 
7236 	int retval;
7237 
7238 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7239 	unsigned int plaintext_pad_len;
7240 	unsigned int plaintext_len;
7241 	unsigned int ciphertext_pad_len;
7242 	unsigned int ciphertext_len;
7243 
7244 	struct rte_cryptodev_info dev_info;
7245 	struct rte_crypto_op *op;
7246 
7247 	/* Check if device supports particular algorithms separately */
7248 	if (test_mixed_check_if_unsupported(tdata))
7249 		return TEST_SKIPPED;
7250 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7251 		return TEST_SKIPPED;
7252 
7253 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7254 
7255 	uint64_t feat_flags = dev_info.feature_flags;
7256 
7257 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7258 		printf("Device doesn't support digest encrypted.\n");
7259 		return TEST_SKIPPED;
7260 	}
7261 
7262 	/* Create the session */
7263 	if (verify)
7264 		retval = create_wireless_algo_cipher_auth_session(
7265 				ts_params->valid_devs[0],
7266 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7267 				RTE_CRYPTO_AUTH_OP_VERIFY,
7268 				tdata->auth_algo,
7269 				tdata->cipher_algo,
7270 				tdata->auth_key.data, tdata->auth_key.len,
7271 				tdata->auth_iv.len, tdata->digest_enc.len,
7272 				tdata->cipher_iv.len);
7273 	else
7274 		retval = create_wireless_algo_auth_cipher_session(
7275 				ts_params->valid_devs[0],
7276 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7277 				RTE_CRYPTO_AUTH_OP_GENERATE,
7278 				tdata->auth_algo,
7279 				tdata->cipher_algo,
7280 				tdata->auth_key.data, tdata->auth_key.len,
7281 				tdata->auth_iv.len, tdata->digest_enc.len,
7282 				tdata->cipher_iv.len);
7283 	if (retval != 0)
7284 		return retval;
7285 
7286 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7287 	if (op_mode == OUT_OF_PLACE)
7288 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7289 
7290 	/* clear mbuf payload */
7291 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7292 		rte_pktmbuf_tailroom(ut_params->ibuf));
7293 	if (op_mode == OUT_OF_PLACE) {
7294 
7295 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7296 				rte_pktmbuf_tailroom(ut_params->obuf));
7297 	}
7298 
7299 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7300 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7301 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7302 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7303 
7304 	if (verify) {
7305 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7306 				ciphertext_pad_len);
7307 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7308 		if (op_mode == OUT_OF_PLACE)
7309 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7310 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7311 				ciphertext_len);
7312 	} else {
7313 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7314 				plaintext_pad_len);
7315 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7316 		if (op_mode == OUT_OF_PLACE)
7317 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
7318 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7319 	}
7320 
7321 	/* Create the operation */
7322 	retval = create_wireless_algo_auth_cipher_operation(
7323 			tdata->digest_enc.data, tdata->digest_enc.len,
7324 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7325 			tdata->auth_iv.data, tdata->auth_iv.len,
7326 			(tdata->digest_enc.offset == 0 ?
7327 				plaintext_pad_len
7328 				: tdata->digest_enc.offset),
7329 			tdata->validCipherLen.len_bits,
7330 			tdata->cipher.offset_bits,
7331 			tdata->validAuthLen.len_bits,
7332 			tdata->auth.offset_bits,
7333 			op_mode, 0, verify);
7334 
7335 	if (retval < 0)
7336 		return retval;
7337 
7338 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7339 
7340 	/* Check if the op failed because the device doesn't */
7341 	/* support this particular combination of algorithms */
7342 	if (op == NULL && ut_params->op->status ==
7343 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7344 		printf("Device doesn't support this mixed combination. "
7345 				"Test Skipped.\n");
7346 		return TEST_SKIPPED;
7347 	}
7348 	ut_params->op = op;
7349 
7350 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7351 
7352 	ut_params->obuf = (op_mode == IN_PLACE ?
7353 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7354 
7355 	if (verify) {
7356 		if (ut_params->obuf)
7357 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7358 							uint8_t *);
7359 		else
7360 			plaintext = ciphertext +
7361 					(tdata->cipher.offset_bits >> 3);
7362 
7363 		debug_hexdump(stdout, "plaintext:", plaintext,
7364 				tdata->plaintext.len_bits >> 3);
7365 		debug_hexdump(stdout, "plaintext expected:",
7366 				tdata->plaintext.data,
7367 				tdata->plaintext.len_bits >> 3);
7368 	} else {
7369 		if (ut_params->obuf)
7370 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7371 					uint8_t *);
7372 		else
7373 			ciphertext = plaintext;
7374 
7375 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7376 				ciphertext_len);
7377 		debug_hexdump(stdout, "ciphertext expected:",
7378 				tdata->ciphertext.data,
7379 				tdata->ciphertext.len_bits >> 3);
7380 
7381 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7382 				+ (tdata->digest_enc.offset == 0 ?
7383 		plaintext_pad_len : tdata->digest_enc.offset);
7384 
7385 		debug_hexdump(stdout, "digest:", ut_params->digest,
7386 				tdata->digest_enc.len);
7387 		debug_hexdump(stdout, "digest expected:",
7388 				tdata->digest_enc.data,
7389 				tdata->digest_enc.len);
7390 	}
7391 
7392 	/* Validate obuf */
7393 	if (verify) {
7394 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7395 				plaintext,
7396 				tdata->plaintext.data,
7397 				tdata->plaintext.len_bits >> 3,
7398 				"Plaintext data not as expected");
7399 	} else {
7400 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7401 				ciphertext,
7402 				tdata->ciphertext.data,
7403 				tdata->validDataLen.len_bits,
7404 				"Ciphertext data not as expected");
7405 
7406 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7407 				ut_params->digest,
7408 				tdata->digest_enc.data,
7409 				DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
7410 				"Generated auth tag not as expected");
7411 	}
7412 
7413 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7414 			"crypto op processing failed");
7415 
7416 	return 0;
7417 }
7418 
7419 static int
7420 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7421 	uint8_t op_mode, uint8_t verify)
7422 {
7423 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7424 	struct crypto_unittest_params *ut_params = &unittest_params;
7425 
7426 	int retval;
7427 
7428 	const uint8_t *plaintext = NULL;
7429 	const uint8_t *ciphertext = NULL;
7430 	const uint8_t *digest = NULL;
7431 	unsigned int plaintext_pad_len;
7432 	unsigned int plaintext_len;
7433 	unsigned int ciphertext_pad_len;
7434 	unsigned int ciphertext_len;
7435 	uint8_t buffer[10000];
7436 	uint8_t digest_buffer[10000];
7437 
7438 	struct rte_cryptodev_info dev_info;
7439 	struct rte_crypto_op *op;
7440 
7441 	/* Check if device supports particular algorithms */
7442 	if (test_mixed_check_if_unsupported(tdata))
7443 		return TEST_SKIPPED;
7444 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7445 		return TEST_SKIPPED;
7446 
7447 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7448 
7449 	uint64_t feat_flags = dev_info.feature_flags;
7450 
7451 	if (op_mode == IN_PLACE) {
7452 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7453 			printf("Device doesn't support in-place scatter-gather "
7454 					"in both input and output mbufs.\n");
7455 			return TEST_SKIPPED;
7456 		}
7457 	} else {
7458 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7459 			printf("Device doesn't support out-of-place scatter-gather "
7460 					"in both input and output mbufs.\n");
7461 			return TEST_SKIPPED;
7462 		}
7463 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7464 			printf("Device doesn't support digest encrypted.\n");
7465 			return TEST_SKIPPED;
7466 		}
7467 	}
7468 
7469 	/* Create the session */
7470 	if (verify)
7471 		retval = create_wireless_algo_cipher_auth_session(
7472 				ts_params->valid_devs[0],
7473 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7474 				RTE_CRYPTO_AUTH_OP_VERIFY,
7475 				tdata->auth_algo,
7476 				tdata->cipher_algo,
7477 				tdata->auth_key.data, tdata->auth_key.len,
7478 				tdata->auth_iv.len, tdata->digest_enc.len,
7479 				tdata->cipher_iv.len);
7480 	else
7481 		retval = create_wireless_algo_auth_cipher_session(
7482 				ts_params->valid_devs[0],
7483 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7484 				RTE_CRYPTO_AUTH_OP_GENERATE,
7485 				tdata->auth_algo,
7486 				tdata->cipher_algo,
7487 				tdata->auth_key.data, tdata->auth_key.len,
7488 				tdata->auth_iv.len, tdata->digest_enc.len,
7489 				tdata->cipher_iv.len);
7490 	if (retval != 0)
7491 		return retval;
7492 
7493 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7494 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7495 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7496 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7497 
7498 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7499 			ciphertext_pad_len, 15, 0);
7500 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7501 			"Failed to allocate input buffer in mempool");
7502 
7503 	if (op_mode == OUT_OF_PLACE) {
7504 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7505 				plaintext_pad_len, 15, 0);
7506 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7507 				"Failed to allocate output buffer in mempool");
7508 	}
7509 
7510 	if (verify) {
7511 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7512 			tdata->ciphertext.data);
7513 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7514 					ciphertext_len, buffer);
7515 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7516 			ciphertext_len);
7517 	} else {
7518 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7519 			tdata->plaintext.data);
7520 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7521 					plaintext_len, buffer);
7522 		debug_hexdump(stdout, "plaintext:", plaintext,
7523 			plaintext_len);
7524 	}
7525 	memset(buffer, 0, sizeof(buffer));
7526 
7527 	/* Create the operation */
7528 	retval = create_wireless_algo_auth_cipher_operation(
7529 			tdata->digest_enc.data, tdata->digest_enc.len,
7530 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7531 			tdata->auth_iv.data, tdata->auth_iv.len,
7532 			(tdata->digest_enc.offset == 0 ?
7533 				plaintext_pad_len
7534 				: tdata->digest_enc.offset),
7535 			tdata->validCipherLen.len_bits,
7536 			tdata->cipher.offset_bits,
7537 			tdata->validAuthLen.len_bits,
7538 			tdata->auth.offset_bits,
7539 			op_mode, 1, verify);
7540 
7541 	if (retval < 0)
7542 		return retval;
7543 
7544 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7545 
7546 	/* Check if the op failed because the device doesn't */
7547 	/* support this particular combination of algorithms */
7548 	if (op == NULL && ut_params->op->status ==
7549 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7550 		printf("Device doesn't support this mixed combination. "
7551 				"Test Skipped.\n");
7552 		return TEST_SKIPPED;
7553 	}
7554 	ut_params->op = op;
7555 
7556 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7557 
7558 	ut_params->obuf = (op_mode == IN_PLACE ?
7559 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7560 
7561 	if (verify) {
7562 		if (ut_params->obuf)
7563 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7564 					plaintext_len, buffer);
7565 		else
7566 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7567 					plaintext_len, buffer);
7568 
7569 		debug_hexdump(stdout, "plaintext:", plaintext,
7570 				(tdata->plaintext.len_bits >> 3) -
7571 				tdata->digest_enc.len);
7572 		debug_hexdump(stdout, "plaintext expected:",
7573 				tdata->plaintext.data,
7574 				(tdata->plaintext.len_bits >> 3) -
7575 				tdata->digest_enc.len);
7576 	} else {
7577 		if (ut_params->obuf)
7578 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7579 					ciphertext_len, buffer);
7580 		else
7581 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7582 					ciphertext_len, buffer);
7583 
7584 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7585 			ciphertext_len);
7586 		debug_hexdump(stdout, "ciphertext expected:",
7587 			tdata->ciphertext.data,
7588 			tdata->ciphertext.len_bits >> 3);
7589 
7590 		if (ut_params->obuf)
7591 			digest = rte_pktmbuf_read(ut_params->obuf,
7592 					(tdata->digest_enc.offset == 0 ?
7593 						plaintext_pad_len :
7594 						tdata->digest_enc.offset),
7595 					tdata->digest_enc.len, digest_buffer);
7596 		else
7597 			digest = rte_pktmbuf_read(ut_params->ibuf,
7598 					(tdata->digest_enc.offset == 0 ?
7599 						plaintext_pad_len :
7600 						tdata->digest_enc.offset),
7601 					tdata->digest_enc.len, digest_buffer);
7602 
7603 		debug_hexdump(stdout, "digest:", digest,
7604 				tdata->digest_enc.len);
7605 		debug_hexdump(stdout, "digest expected:",
7606 				tdata->digest_enc.data, tdata->digest_enc.len);
7607 	}
7608 
7609 	/* Validate obuf */
7610 	if (verify) {
7611 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7612 				plaintext,
7613 				tdata->plaintext.data,
7614 				tdata->plaintext.len_bits >> 3,
7615 				"Plaintext data not as expected");
7616 	} else {
7617 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7618 				ciphertext,
7619 				tdata->ciphertext.data,
7620 				tdata->validDataLen.len_bits,
7621 				"Ciphertext data not as expected");
7622 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7623 				digest,
7624 				tdata->digest_enc.data,
7625 				tdata->digest_enc.len,
7626 				"Generated auth tag not as expected");
7627 	}
7628 
7629 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7630 			"crypto op processing failed");
7631 
7632 	return 0;
7633 }
7634 
7635 /** AUTH AES CMAC + CIPHER AES CTR */
7636 
7637 static int
7638 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7639 {
7640 	return test_mixed_auth_cipher(
7641 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7642 }
7643 
7644 static int
7645 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7646 {
7647 	return test_mixed_auth_cipher(
7648 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7649 }
7650 
7651 static int
7652 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7653 {
7654 	return test_mixed_auth_cipher_sgl(
7655 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7656 }
7657 
7658 static int
7659 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7660 {
7661 	return test_mixed_auth_cipher_sgl(
7662 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7663 }
7664 
7665 static int
7666 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7667 {
7668 	return test_mixed_auth_cipher(
7669 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7670 }
7671 
7672 static int
7673 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7674 {
7675 	return test_mixed_auth_cipher(
7676 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7677 }
7678 
7679 static int
7680 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7681 {
7682 	return test_mixed_auth_cipher_sgl(
7683 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7684 }
7685 
7686 static int
7687 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7688 {
7689 	return test_mixed_auth_cipher_sgl(
7690 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7691 }
7692 
7693 /** MIXED AUTH + CIPHER */
7694 
7695 static int
7696 test_auth_zuc_cipher_snow_test_case_1(void)
7697 {
7698 	return test_mixed_auth_cipher(
7699 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7700 }
7701 
7702 static int
7703 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7704 {
7705 	return test_mixed_auth_cipher(
7706 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7707 }
7708 
7709 static int
7710 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7711 {
7712 	return test_mixed_auth_cipher(
7713 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7714 }
7715 
7716 static int
7717 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7718 {
7719 	return test_mixed_auth_cipher(
7720 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7721 }
7722 
7723 static int
7724 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7725 {
7726 	return test_mixed_auth_cipher(
7727 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7728 }
7729 
7730 static int
7731 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7732 {
7733 	return test_mixed_auth_cipher(
7734 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7735 }
7736 
7737 static int
7738 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7739 {
7740 	return test_mixed_auth_cipher(
7741 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7742 }
7743 
7744 static int
7745 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7746 {
7747 	return test_mixed_auth_cipher(
7748 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7749 }
7750 
7751 static int
7752 test_auth_snow_cipher_zuc_test_case_1(void)
7753 {
7754 	return test_mixed_auth_cipher(
7755 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7756 }
7757 
7758 static int
7759 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7760 {
7761 	return test_mixed_auth_cipher(
7762 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7763 }
7764 
7765 static int
7766 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7767 {
7768 	return test_mixed_auth_cipher(
7769 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7770 }
7771 
7772 static int
7773 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7774 {
7775 	return test_mixed_auth_cipher(
7776 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7777 }
7778 
7779 static int
7780 test_auth_null_cipher_snow_test_case_1(void)
7781 {
7782 	return test_mixed_auth_cipher(
7783 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7784 }
7785 
7786 static int
7787 test_verify_auth_null_cipher_snow_test_case_1(void)
7788 {
7789 	return test_mixed_auth_cipher(
7790 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7791 }
7792 
7793 static int
7794 test_auth_null_cipher_zuc_test_case_1(void)
7795 {
7796 	return test_mixed_auth_cipher(
7797 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7798 }
7799 
7800 static int
7801 test_verify_auth_null_cipher_zuc_test_case_1(void)
7802 {
7803 	return test_mixed_auth_cipher(
7804 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7805 }
7806 
7807 static int
7808 test_auth_snow_cipher_null_test_case_1(void)
7809 {
7810 	return test_mixed_auth_cipher(
7811 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7812 }
7813 
7814 static int
7815 test_verify_auth_snow_cipher_null_test_case_1(void)
7816 {
7817 	return test_mixed_auth_cipher(
7818 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7819 }
7820 
7821 static int
7822 test_auth_zuc_cipher_null_test_case_1(void)
7823 {
7824 	return test_mixed_auth_cipher(
7825 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7826 }
7827 
7828 static int
7829 test_verify_auth_zuc_cipher_null_test_case_1(void)
7830 {
7831 	return test_mixed_auth_cipher(
7832 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7833 }
7834 
7835 static int
7836 test_auth_null_cipher_aes_ctr_test_case_1(void)
7837 {
7838 	return test_mixed_auth_cipher(
7839 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7840 }
7841 
7842 static int
7843 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7844 {
7845 	return test_mixed_auth_cipher(
7846 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7847 }
7848 
7849 static int
7850 test_auth_aes_cmac_cipher_null_test_case_1(void)
7851 {
7852 	return test_mixed_auth_cipher(
7853 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7854 }
7855 
7856 static int
7857 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7858 {
7859 	return test_mixed_auth_cipher(
7860 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7861 }
7862 
7863 /* ***** AEAD algorithm Tests ***** */
7864 
7865 static int
7866 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7867 		enum rte_crypto_aead_operation op,
7868 		const uint8_t *key, const uint8_t key_len,
7869 		const uint16_t aad_len, const uint8_t auth_len,
7870 		uint8_t iv_len)
7871 {
7872 	uint8_t aead_key[key_len];
7873 
7874 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7875 	struct crypto_unittest_params *ut_params = &unittest_params;
7876 
7877 	memcpy(aead_key, key, key_len);
7878 
7879 	/* Setup AEAD Parameters */
7880 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7881 	ut_params->aead_xform.next = NULL;
7882 	ut_params->aead_xform.aead.algo = algo;
7883 	ut_params->aead_xform.aead.op = op;
7884 	ut_params->aead_xform.aead.key.data = aead_key;
7885 	ut_params->aead_xform.aead.key.length = key_len;
7886 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7887 	ut_params->aead_xform.aead.iv.length = iv_len;
7888 	ut_params->aead_xform.aead.digest_length = auth_len;
7889 	ut_params->aead_xform.aead.aad_length = aad_len;
7890 
7891 	debug_hexdump(stdout, "key:", key, key_len);
7892 
7893 	/* Create Crypto session*/
7894 	ut_params->sess = rte_cryptodev_sym_session_create(
7895 			ts_params->session_mpool);
7896 
7897 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
7898 			&ut_params->aead_xform,
7899 			ts_params->session_priv_mpool);
7900 
7901 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
7902 
7903 	return 0;
7904 }
7905 
7906 static int
7907 create_aead_xform(struct rte_crypto_op *op,
7908 		enum rte_crypto_aead_algorithm algo,
7909 		enum rte_crypto_aead_operation aead_op,
7910 		uint8_t *key, const uint8_t key_len,
7911 		const uint8_t aad_len, const uint8_t auth_len,
7912 		uint8_t iv_len)
7913 {
7914 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
7915 			"failed to allocate space for crypto transform");
7916 
7917 	struct rte_crypto_sym_op *sym_op = op->sym;
7918 
7919 	/* Setup AEAD Parameters */
7920 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
7921 	sym_op->xform->next = NULL;
7922 	sym_op->xform->aead.algo = algo;
7923 	sym_op->xform->aead.op = aead_op;
7924 	sym_op->xform->aead.key.data = key;
7925 	sym_op->xform->aead.key.length = key_len;
7926 	sym_op->xform->aead.iv.offset = IV_OFFSET;
7927 	sym_op->xform->aead.iv.length = iv_len;
7928 	sym_op->xform->aead.digest_length = auth_len;
7929 	sym_op->xform->aead.aad_length = aad_len;
7930 
7931 	debug_hexdump(stdout, "key:", key, key_len);
7932 
7933 	return 0;
7934 }
7935 
7936 static int
7937 create_aead_operation(enum rte_crypto_aead_operation op,
7938 		const struct aead_test_data *tdata)
7939 {
7940 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7941 	struct crypto_unittest_params *ut_params = &unittest_params;
7942 
7943 	uint8_t *plaintext, *ciphertext;
7944 	unsigned int aad_pad_len, plaintext_pad_len;
7945 
7946 	/* Generate Crypto op data structure */
7947 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7948 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7949 	TEST_ASSERT_NOT_NULL(ut_params->op,
7950 			"Failed to allocate symmetric crypto operation struct");
7951 
7952 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7953 
7954 	/* Append aad data */
7955 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
7956 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
7957 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7958 				aad_pad_len);
7959 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7960 				"no room to append aad");
7961 
7962 		sym_op->aead.aad.phys_addr =
7963 				rte_pktmbuf_iova(ut_params->ibuf);
7964 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
7965 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
7966 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7967 			tdata->aad.len);
7968 
7969 		/* Append IV at the end of the crypto operation*/
7970 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7971 				uint8_t *, IV_OFFSET);
7972 
7973 		/* Copy IV 1 byte after the IV pointer, according to the API */
7974 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
7975 		debug_hexdump(stdout, "iv:", iv_ptr,
7976 			tdata->iv.len);
7977 	} else {
7978 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
7979 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7980 				aad_pad_len);
7981 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
7982 				"no room to append aad");
7983 
7984 		sym_op->aead.aad.phys_addr =
7985 				rte_pktmbuf_iova(ut_params->ibuf);
7986 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
7987 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
7988 			tdata->aad.len);
7989 
7990 		/* Append IV at the end of the crypto operation*/
7991 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
7992 				uint8_t *, IV_OFFSET);
7993 
7994 		if (tdata->iv.len == 0) {
7995 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
7996 			debug_hexdump(stdout, "iv:", iv_ptr,
7997 				AES_GCM_J0_LENGTH);
7998 		} else {
7999 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8000 			debug_hexdump(stdout, "iv:", iv_ptr,
8001 				tdata->iv.len);
8002 		}
8003 	}
8004 
8005 	/* Append plaintext/ciphertext */
8006 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8007 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8008 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8009 				plaintext_pad_len);
8010 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8011 
8012 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8013 		debug_hexdump(stdout, "plaintext:", plaintext,
8014 				tdata->plaintext.len);
8015 
8016 		if (ut_params->obuf) {
8017 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8018 					ut_params->obuf,
8019 					plaintext_pad_len + aad_pad_len);
8020 			TEST_ASSERT_NOT_NULL(ciphertext,
8021 					"no room to append ciphertext");
8022 
8023 			memset(ciphertext + aad_pad_len, 0,
8024 					tdata->ciphertext.len);
8025 		}
8026 	} else {
8027 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8028 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8029 				plaintext_pad_len);
8030 		TEST_ASSERT_NOT_NULL(ciphertext,
8031 				"no room to append ciphertext");
8032 
8033 		memcpy(ciphertext, tdata->ciphertext.data,
8034 				tdata->ciphertext.len);
8035 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8036 				tdata->ciphertext.len);
8037 
8038 		if (ut_params->obuf) {
8039 			plaintext = (uint8_t *)rte_pktmbuf_append(
8040 					ut_params->obuf,
8041 					plaintext_pad_len + aad_pad_len);
8042 			TEST_ASSERT_NOT_NULL(plaintext,
8043 					"no room to append plaintext");
8044 
8045 			memset(plaintext + aad_pad_len, 0,
8046 					tdata->plaintext.len);
8047 		}
8048 	}
8049 
8050 	/* Append digest data */
8051 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8052 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8053 				ut_params->obuf ? ut_params->obuf :
8054 						ut_params->ibuf,
8055 						tdata->auth_tag.len);
8056 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8057 				"no room to append digest");
8058 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8059 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8060 				ut_params->obuf ? ut_params->obuf :
8061 						ut_params->ibuf,
8062 						plaintext_pad_len +
8063 						aad_pad_len);
8064 	} else {
8065 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8066 				ut_params->ibuf, tdata->auth_tag.len);
8067 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8068 				"no room to append digest");
8069 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8070 				ut_params->ibuf,
8071 				plaintext_pad_len + aad_pad_len);
8072 
8073 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8074 			tdata->auth_tag.len);
8075 		debug_hexdump(stdout, "digest:",
8076 			sym_op->aead.digest.data,
8077 			tdata->auth_tag.len);
8078 	}
8079 
8080 	sym_op->aead.data.length = tdata->plaintext.len;
8081 	sym_op->aead.data.offset = aad_pad_len;
8082 
8083 	return 0;
8084 }
8085 
8086 static int
8087 test_authenticated_encryption(const struct aead_test_data *tdata)
8088 {
8089 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8090 	struct crypto_unittest_params *ut_params = &unittest_params;
8091 
8092 	int retval;
8093 	uint8_t *ciphertext, *auth_tag;
8094 	uint16_t plaintext_pad_len;
8095 	uint32_t i;
8096 	struct rte_cryptodev_info dev_info;
8097 
8098 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8099 	uint64_t feat_flags = dev_info.feature_flags;
8100 
8101 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8102 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8103 		printf("Device doesn't support RAW data-path APIs.\n");
8104 		return TEST_SKIPPED;
8105 	}
8106 
8107 	/* Verify the capabilities */
8108 	struct rte_cryptodev_sym_capability_idx cap_idx;
8109 	const struct rte_cryptodev_symmetric_capability *capability;
8110 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8111 	cap_idx.algo.aead = tdata->algo;
8112 	capability = rte_cryptodev_sym_capability_get(
8113 			ts_params->valid_devs[0], &cap_idx);
8114 	if (capability == NULL)
8115 		return TEST_SKIPPED;
8116 	if (rte_cryptodev_sym_capability_check_aead(
8117 			capability, tdata->key.len, tdata->auth_tag.len,
8118 			tdata->aad.len, tdata->iv.len))
8119 		return TEST_SKIPPED;
8120 
8121 	/* Create AEAD session */
8122 	retval = create_aead_session(ts_params->valid_devs[0],
8123 			tdata->algo,
8124 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8125 			tdata->key.data, tdata->key.len,
8126 			tdata->aad.len, tdata->auth_tag.len,
8127 			tdata->iv.len);
8128 	if (retval < 0)
8129 		return retval;
8130 
8131 	if (tdata->aad.len > MBUF_SIZE) {
8132 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8133 		/* Populate full size of add data */
8134 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8135 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8136 	} else
8137 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8138 
8139 	/* clear mbuf payload */
8140 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8141 			rte_pktmbuf_tailroom(ut_params->ibuf));
8142 
8143 	/* Create AEAD operation */
8144 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8145 	if (retval < 0)
8146 		return retval;
8147 
8148 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8149 
8150 	ut_params->op->sym->m_src = ut_params->ibuf;
8151 
8152 	/* Process crypto operation */
8153 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8154 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8155 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8156 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8157 				ut_params->op, 0, 0, 0, 0);
8158 	else
8159 		TEST_ASSERT_NOT_NULL(
8160 			process_crypto_request(ts_params->valid_devs[0],
8161 			ut_params->op), "failed to process sym crypto op");
8162 
8163 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8164 			"crypto op processing failed");
8165 
8166 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8167 
8168 	if (ut_params->op->sym->m_dst) {
8169 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8170 				uint8_t *);
8171 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8172 				uint8_t *, plaintext_pad_len);
8173 	} else {
8174 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8175 				uint8_t *,
8176 				ut_params->op->sym->cipher.data.offset);
8177 		auth_tag = ciphertext + plaintext_pad_len;
8178 	}
8179 
8180 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8181 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8182 
8183 	/* Validate obuf */
8184 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8185 			ciphertext,
8186 			tdata->ciphertext.data,
8187 			tdata->ciphertext.len,
8188 			"Ciphertext data not as expected");
8189 
8190 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8191 			auth_tag,
8192 			tdata->auth_tag.data,
8193 			tdata->auth_tag.len,
8194 			"Generated auth tag not as expected");
8195 
8196 	return 0;
8197 
8198 }
8199 
8200 #ifdef RTE_LIB_SECURITY
8201 static int
8202 security_proto_supported(enum rte_security_session_action_type action,
8203 	enum rte_security_session_protocol proto)
8204 {
8205 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8206 
8207 	const struct rte_security_capability *capabilities;
8208 	const struct rte_security_capability *capability;
8209 	uint16_t i = 0;
8210 
8211 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8212 				rte_cryptodev_get_sec_ctx(
8213 				ts_params->valid_devs[0]);
8214 
8215 
8216 	capabilities = rte_security_capabilities_get(ctx);
8217 
8218 	if (capabilities == NULL)
8219 		return -ENOTSUP;
8220 
8221 	while ((capability = &capabilities[i++])->action !=
8222 			RTE_SECURITY_ACTION_TYPE_NONE) {
8223 		if (capability->action == action &&
8224 				capability->protocol == proto)
8225 			return 0;
8226 	}
8227 
8228 	return -ENOTSUP;
8229 }
8230 
8231 /* Basic algorithm run function for async inplace mode.
8232  * Creates a session from input parameters and runs one operation
8233  * on input_vec. Checks the output of the crypto operation against
8234  * output_vec.
8235  */
8236 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8237 			   enum rte_crypto_auth_operation opa,
8238 			   const uint8_t *input_vec, unsigned int input_vec_len,
8239 			   const uint8_t *output_vec,
8240 			   unsigned int output_vec_len,
8241 			   enum rte_crypto_cipher_algorithm cipher_alg,
8242 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8243 			   enum rte_crypto_auth_algorithm auth_alg,
8244 			   const uint8_t *auth_key, uint32_t auth_key_len,
8245 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8246 			   uint8_t packet_direction, uint8_t sn_size,
8247 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8248 {
8249 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8250 	struct crypto_unittest_params *ut_params = &unittest_params;
8251 	uint8_t *plaintext;
8252 	int ret = TEST_SUCCESS;
8253 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8254 				rte_cryptodev_get_sec_ctx(
8255 				ts_params->valid_devs[0]);
8256 
8257 	/* Verify the capabilities */
8258 	struct rte_security_capability_idx sec_cap_idx;
8259 
8260 	sec_cap_idx.action = ut_params->type;
8261 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8262 	sec_cap_idx.pdcp.domain = domain;
8263 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8264 		return TEST_SKIPPED;
8265 
8266 	/* Generate test mbuf data */
8267 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8268 
8269 	/* clear mbuf payload */
8270 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8271 			rte_pktmbuf_tailroom(ut_params->ibuf));
8272 
8273 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8274 						  input_vec_len);
8275 	memcpy(plaintext, input_vec, input_vec_len);
8276 
8277 	/* Out of place support */
8278 	if (oop) {
8279 		/*
8280 		 * For out-op-place we need to alloc another mbuf
8281 		 */
8282 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8283 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8284 	}
8285 
8286 	/* Setup Cipher Parameters */
8287 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8288 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8289 	ut_params->cipher_xform.cipher.op = opc;
8290 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8291 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8292 	ut_params->cipher_xform.cipher.iv.length =
8293 				packet_direction ? 4 : 0;
8294 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8295 
8296 	/* Setup HMAC Parameters if ICV header is required */
8297 	if (auth_alg != 0) {
8298 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8299 		ut_params->auth_xform.next = NULL;
8300 		ut_params->auth_xform.auth.algo = auth_alg;
8301 		ut_params->auth_xform.auth.op = opa;
8302 		ut_params->auth_xform.auth.key.data = auth_key;
8303 		ut_params->auth_xform.auth.key.length = auth_key_len;
8304 
8305 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8306 	} else {
8307 		ut_params->cipher_xform.next = NULL;
8308 	}
8309 
8310 	struct rte_security_session_conf sess_conf = {
8311 		.action_type = ut_params->type,
8312 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8313 		{.pdcp = {
8314 			.bearer = bearer,
8315 			.domain = domain,
8316 			.pkt_dir = packet_direction,
8317 			.sn_size = sn_size,
8318 			.hfn = packet_direction ? 0 : hfn,
8319 			/**
8320 			 * hfn can be set as pdcp_test_hfn[i]
8321 			 * if hfn_ovrd is not set. Here, PDCP
8322 			 * packet direction is just used to
8323 			 * run half of the cases with session
8324 			 * HFN and other half with per packet
8325 			 * HFN.
8326 			 */
8327 			.hfn_threshold = hfn_threshold,
8328 			.hfn_ovrd = packet_direction ? 1 : 0,
8329 			.sdap_enabled = sdap,
8330 		} },
8331 		.crypto_xform = &ut_params->cipher_xform
8332 	};
8333 
8334 	/* Create security session */
8335 	ut_params->sec_session = rte_security_session_create(ctx,
8336 				&sess_conf, ts_params->session_mpool,
8337 				ts_params->session_priv_mpool);
8338 
8339 	if (!ut_params->sec_session) {
8340 		printf("TestCase %s()-%d line %d failed %s: ",
8341 			__func__, i, __LINE__, "Failed to allocate session");
8342 		ret = TEST_FAILED;
8343 		goto on_err;
8344 	}
8345 
8346 	/* Generate crypto op data structure */
8347 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8348 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8349 	if (!ut_params->op) {
8350 		printf("TestCase %s()-%d line %d failed %s: ",
8351 			__func__, i, __LINE__,
8352 			"Failed to allocate symmetric crypto operation struct");
8353 		ret = TEST_FAILED;
8354 		goto on_err;
8355 	}
8356 
8357 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8358 					uint32_t *, IV_OFFSET);
8359 	*per_pkt_hfn = packet_direction ? hfn : 0;
8360 
8361 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8362 
8363 	/* set crypto operation source mbuf */
8364 	ut_params->op->sym->m_src = ut_params->ibuf;
8365 	if (oop)
8366 		ut_params->op->sym->m_dst = ut_params->obuf;
8367 
8368 	/* Process crypto operation */
8369 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8370 		== NULL) {
8371 		printf("TestCase %s()-%d line %d failed %s: ",
8372 			__func__, i, __LINE__,
8373 			"failed to process sym crypto op");
8374 		ret = TEST_FAILED;
8375 		goto on_err;
8376 	}
8377 
8378 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8379 		printf("TestCase %s()-%d line %d failed %s: ",
8380 			__func__, i, __LINE__, "crypto op processing failed");
8381 		ret = TEST_FAILED;
8382 		goto on_err;
8383 	}
8384 
8385 	/* Validate obuf */
8386 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8387 			uint8_t *);
8388 	if (oop) {
8389 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8390 				uint8_t *);
8391 	}
8392 
8393 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8394 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8395 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8396 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8397 		ret = TEST_FAILED;
8398 		goto on_err;
8399 	}
8400 
8401 on_err:
8402 	rte_crypto_op_free(ut_params->op);
8403 	ut_params->op = NULL;
8404 
8405 	if (ut_params->sec_session)
8406 		rte_security_session_destroy(ctx, ut_params->sec_session);
8407 	ut_params->sec_session = NULL;
8408 
8409 	rte_pktmbuf_free(ut_params->ibuf);
8410 	ut_params->ibuf = NULL;
8411 	if (oop) {
8412 		rte_pktmbuf_free(ut_params->obuf);
8413 		ut_params->obuf = NULL;
8414 	}
8415 
8416 	return ret;
8417 }
8418 
8419 static int
8420 test_pdcp_proto_SGL(int i, int oop,
8421 	enum rte_crypto_cipher_operation opc,
8422 	enum rte_crypto_auth_operation opa,
8423 	uint8_t *input_vec,
8424 	unsigned int input_vec_len,
8425 	uint8_t *output_vec,
8426 	unsigned int output_vec_len,
8427 	uint32_t fragsz,
8428 	uint32_t fragsz_oop)
8429 {
8430 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8431 	struct crypto_unittest_params *ut_params = &unittest_params;
8432 	uint8_t *plaintext;
8433 	struct rte_mbuf *buf, *buf_oop = NULL;
8434 	int ret = TEST_SUCCESS;
8435 	int to_trn = 0;
8436 	int to_trn_tbl[16];
8437 	int segs = 1;
8438 	unsigned int trn_data = 0;
8439 	struct rte_cryptodev_info dev_info;
8440 	uint64_t feat_flags;
8441 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8442 				rte_cryptodev_get_sec_ctx(
8443 				ts_params->valid_devs[0]);
8444 	struct rte_mbuf *temp_mbuf;
8445 
8446 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8447 	feat_flags = dev_info.feature_flags;
8448 
8449 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8450 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8451 		printf("Device does not support RAW data-path APIs.\n");
8452 		return -ENOTSUP;
8453 	}
8454 	/* Verify the capabilities */
8455 	struct rte_security_capability_idx sec_cap_idx;
8456 
8457 	sec_cap_idx.action = ut_params->type;
8458 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8459 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8460 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8461 		return TEST_SKIPPED;
8462 
8463 	if (fragsz > input_vec_len)
8464 		fragsz = input_vec_len;
8465 
8466 	uint16_t plaintext_len = fragsz;
8467 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8468 
8469 	if (fragsz_oop > output_vec_len)
8470 		frag_size_oop = output_vec_len;
8471 
8472 	int ecx = 0;
8473 	if (input_vec_len % fragsz != 0) {
8474 		if (input_vec_len / fragsz + 1 > 16)
8475 			return 1;
8476 	} else if (input_vec_len / fragsz > 16)
8477 		return 1;
8478 
8479 	/* Out of place support */
8480 	if (oop) {
8481 		/*
8482 		 * For out-op-place we need to alloc another mbuf
8483 		 */
8484 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8485 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8486 		buf_oop = ut_params->obuf;
8487 	}
8488 
8489 	/* Generate test mbuf data */
8490 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8491 
8492 	/* clear mbuf payload */
8493 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8494 			rte_pktmbuf_tailroom(ut_params->ibuf));
8495 
8496 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8497 						  plaintext_len);
8498 	memcpy(plaintext, input_vec, plaintext_len);
8499 	trn_data += plaintext_len;
8500 
8501 	buf = ut_params->ibuf;
8502 
8503 	/*
8504 	 * Loop until no more fragments
8505 	 */
8506 
8507 	while (trn_data < input_vec_len) {
8508 		++segs;
8509 		to_trn = (input_vec_len - trn_data < fragsz) ?
8510 				(input_vec_len - trn_data) : fragsz;
8511 
8512 		to_trn_tbl[ecx++] = to_trn;
8513 
8514 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8515 		buf = buf->next;
8516 
8517 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8518 				rte_pktmbuf_tailroom(buf));
8519 
8520 		/* OOP */
8521 		if (oop && !fragsz_oop) {
8522 			buf_oop->next =
8523 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8524 			buf_oop = buf_oop->next;
8525 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8526 					0, rte_pktmbuf_tailroom(buf_oop));
8527 			rte_pktmbuf_append(buf_oop, to_trn);
8528 		}
8529 
8530 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8531 				to_trn);
8532 
8533 		memcpy(plaintext, input_vec + trn_data, to_trn);
8534 		trn_data += to_trn;
8535 	}
8536 
8537 	ut_params->ibuf->nb_segs = segs;
8538 
8539 	segs = 1;
8540 	if (fragsz_oop && oop) {
8541 		to_trn = 0;
8542 		ecx = 0;
8543 
8544 		trn_data = frag_size_oop;
8545 		while (trn_data < output_vec_len) {
8546 			++segs;
8547 			to_trn =
8548 				(output_vec_len - trn_data <
8549 						frag_size_oop) ?
8550 				(output_vec_len - trn_data) :
8551 						frag_size_oop;
8552 
8553 			to_trn_tbl[ecx++] = to_trn;
8554 
8555 			buf_oop->next =
8556 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8557 			buf_oop = buf_oop->next;
8558 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8559 					0, rte_pktmbuf_tailroom(buf_oop));
8560 			rte_pktmbuf_append(buf_oop, to_trn);
8561 
8562 			trn_data += to_trn;
8563 		}
8564 		ut_params->obuf->nb_segs = segs;
8565 	}
8566 
8567 	/* Setup Cipher Parameters */
8568 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8569 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8570 	ut_params->cipher_xform.cipher.op = opc;
8571 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8572 	ut_params->cipher_xform.cipher.key.length =
8573 					pdcp_test_params[i].cipher_key_len;
8574 	ut_params->cipher_xform.cipher.iv.length = 0;
8575 
8576 	/* Setup HMAC Parameters if ICV header is required */
8577 	if (pdcp_test_params[i].auth_alg != 0) {
8578 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8579 		ut_params->auth_xform.next = NULL;
8580 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8581 		ut_params->auth_xform.auth.op = opa;
8582 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8583 		ut_params->auth_xform.auth.key.length =
8584 					pdcp_test_params[i].auth_key_len;
8585 
8586 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8587 	} else {
8588 		ut_params->cipher_xform.next = NULL;
8589 	}
8590 
8591 	struct rte_security_session_conf sess_conf = {
8592 		.action_type = ut_params->type,
8593 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8594 		{.pdcp = {
8595 			.bearer = pdcp_test_bearer[i],
8596 			.domain = pdcp_test_params[i].domain,
8597 			.pkt_dir = pdcp_test_packet_direction[i],
8598 			.sn_size = pdcp_test_data_sn_size[i],
8599 			.hfn = pdcp_test_hfn[i],
8600 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8601 			.hfn_ovrd = 0,
8602 		} },
8603 		.crypto_xform = &ut_params->cipher_xform
8604 	};
8605 
8606 	/* Create security session */
8607 	ut_params->sec_session = rte_security_session_create(ctx,
8608 				&sess_conf, ts_params->session_mpool,
8609 				ts_params->session_priv_mpool);
8610 
8611 	if (!ut_params->sec_session) {
8612 		printf("TestCase %s()-%d line %d failed %s: ",
8613 			__func__, i, __LINE__, "Failed to allocate session");
8614 		ret = TEST_FAILED;
8615 		goto on_err;
8616 	}
8617 
8618 	/* Generate crypto op data structure */
8619 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8620 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8621 	if (!ut_params->op) {
8622 		printf("TestCase %s()-%d line %d failed %s: ",
8623 			__func__, i, __LINE__,
8624 			"Failed to allocate symmetric crypto operation struct");
8625 		ret = TEST_FAILED;
8626 		goto on_err;
8627 	}
8628 
8629 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8630 
8631 	/* set crypto operation source mbuf */
8632 	ut_params->op->sym->m_src = ut_params->ibuf;
8633 	if (oop)
8634 		ut_params->op->sym->m_dst = ut_params->obuf;
8635 
8636 	/* Process crypto operation */
8637 	temp_mbuf = ut_params->op->sym->m_src;
8638 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8639 		/* filling lengths */
8640 		while (temp_mbuf) {
8641 			ut_params->op->sym->cipher.data.length
8642 				+= temp_mbuf->pkt_len;
8643 			ut_params->op->sym->auth.data.length
8644 				+= temp_mbuf->pkt_len;
8645 			temp_mbuf = temp_mbuf->next;
8646 		}
8647 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8648 			ut_params->op, 1, 1, 0, 0);
8649 	} else {
8650 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8651 							ut_params->op);
8652 	}
8653 	if (ut_params->op == NULL) {
8654 		printf("TestCase %s()-%d line %d failed %s: ",
8655 			__func__, i, __LINE__,
8656 			"failed to process sym crypto op");
8657 		ret = TEST_FAILED;
8658 		goto on_err;
8659 	}
8660 
8661 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8662 		printf("TestCase %s()-%d line %d failed %s: ",
8663 			__func__, i, __LINE__, "crypto op processing failed");
8664 		ret = TEST_FAILED;
8665 		goto on_err;
8666 	}
8667 
8668 	/* Validate obuf */
8669 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8670 			uint8_t *);
8671 	if (oop) {
8672 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8673 				uint8_t *);
8674 	}
8675 	if (fragsz_oop)
8676 		fragsz = frag_size_oop;
8677 	if (memcmp(ciphertext, output_vec, fragsz)) {
8678 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8679 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8680 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8681 		ret = TEST_FAILED;
8682 		goto on_err;
8683 	}
8684 
8685 	buf = ut_params->op->sym->m_src->next;
8686 	if (oop)
8687 		buf = ut_params->op->sym->m_dst->next;
8688 
8689 	unsigned int off = fragsz;
8690 
8691 	ecx = 0;
8692 	while (buf) {
8693 		ciphertext = rte_pktmbuf_mtod(buf,
8694 				uint8_t *);
8695 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8696 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8697 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8698 			rte_hexdump(stdout, "reference", output_vec + off,
8699 					to_trn_tbl[ecx]);
8700 			ret = TEST_FAILED;
8701 			goto on_err;
8702 		}
8703 		off += to_trn_tbl[ecx++];
8704 		buf = buf->next;
8705 	}
8706 on_err:
8707 	rte_crypto_op_free(ut_params->op);
8708 	ut_params->op = NULL;
8709 
8710 	if (ut_params->sec_session)
8711 		rte_security_session_destroy(ctx, ut_params->sec_session);
8712 	ut_params->sec_session = NULL;
8713 
8714 	rte_pktmbuf_free(ut_params->ibuf);
8715 	ut_params->ibuf = NULL;
8716 	if (oop) {
8717 		rte_pktmbuf_free(ut_params->obuf);
8718 		ut_params->obuf = NULL;
8719 	}
8720 
8721 	return ret;
8722 }
8723 
8724 int
8725 test_pdcp_proto_cplane_encap(int i)
8726 {
8727 	return test_pdcp_proto(
8728 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8729 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8730 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8731 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8732 		pdcp_test_params[i].cipher_key_len,
8733 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8734 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8735 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8736 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8737 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8738 }
8739 
8740 int
8741 test_pdcp_proto_uplane_encap(int i)
8742 {
8743 	return test_pdcp_proto(
8744 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8745 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8746 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8747 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8748 		pdcp_test_params[i].cipher_key_len,
8749 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8750 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8751 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8752 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8753 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8754 }
8755 
8756 int
8757 test_pdcp_proto_uplane_encap_with_int(int i)
8758 {
8759 	return test_pdcp_proto(
8760 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8761 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8762 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8763 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8764 		pdcp_test_params[i].cipher_key_len,
8765 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8766 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8767 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8768 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8769 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8770 }
8771 
8772 int
8773 test_pdcp_proto_cplane_decap(int i)
8774 {
8775 	return test_pdcp_proto(
8776 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8777 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8778 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8779 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8780 		pdcp_test_params[i].cipher_key_len,
8781 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8782 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8783 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8784 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8785 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8786 }
8787 
8788 int
8789 test_pdcp_proto_uplane_decap(int i)
8790 {
8791 	return test_pdcp_proto(
8792 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8793 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8794 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8795 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8796 		pdcp_test_params[i].cipher_key_len,
8797 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8798 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8799 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8800 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8801 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8802 }
8803 
8804 int
8805 test_pdcp_proto_uplane_decap_with_int(int i)
8806 {
8807 	return test_pdcp_proto(
8808 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8809 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8810 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8811 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8812 		pdcp_test_params[i].cipher_key_len,
8813 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8814 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8815 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8816 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8817 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8818 }
8819 
8820 static int
8821 test_PDCP_PROTO_SGL_in_place_32B(void)
8822 {
8823 	/* i can be used for running any PDCP case
8824 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8825 	 */
8826 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8827 	return test_pdcp_proto_SGL(i, IN_PLACE,
8828 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8829 			RTE_CRYPTO_AUTH_OP_GENERATE,
8830 			pdcp_test_data_in[i],
8831 			pdcp_test_data_in_len[i],
8832 			pdcp_test_data_out[i],
8833 			pdcp_test_data_in_len[i]+4,
8834 			32, 0);
8835 }
8836 static int
8837 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8838 {
8839 	/* i can be used for running any PDCP case
8840 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8841 	 */
8842 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8843 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8844 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8845 			RTE_CRYPTO_AUTH_OP_GENERATE,
8846 			pdcp_test_data_in[i],
8847 			pdcp_test_data_in_len[i],
8848 			pdcp_test_data_out[i],
8849 			pdcp_test_data_in_len[i]+4,
8850 			32, 128);
8851 }
8852 static int
8853 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8854 {
8855 	/* i can be used for running any PDCP case
8856 	 * In this case it is uplane 18-bit AES DL encap
8857 	 */
8858 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8859 			+ DOWNLINK;
8860 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8861 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8862 			RTE_CRYPTO_AUTH_OP_GENERATE,
8863 			pdcp_test_data_in[i],
8864 			pdcp_test_data_in_len[i],
8865 			pdcp_test_data_out[i],
8866 			pdcp_test_data_in_len[i],
8867 			32, 40);
8868 }
8869 static int
8870 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8871 {
8872 	/* i can be used for running any PDCP case
8873 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8874 	 */
8875 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8876 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8877 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8878 			RTE_CRYPTO_AUTH_OP_GENERATE,
8879 			pdcp_test_data_in[i],
8880 			pdcp_test_data_in_len[i],
8881 			pdcp_test_data_out[i],
8882 			pdcp_test_data_in_len[i]+4,
8883 			128, 32);
8884 }
8885 
8886 static int
8887 test_PDCP_SDAP_PROTO_encap_all(void)
8888 {
8889 	int i = 0, size = 0;
8890 	int err, all_err = TEST_SUCCESS;
8891 	const struct pdcp_sdap_test *cur_test;
8892 
8893 	size = RTE_DIM(list_pdcp_sdap_tests);
8894 
8895 	for (i = 0; i < size; i++) {
8896 		cur_test = &list_pdcp_sdap_tests[i];
8897 		err = test_pdcp_proto(
8898 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8899 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8900 			cur_test->in_len, cur_test->data_out,
8901 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8902 			cur_test->param.cipher_alg, cur_test->cipher_key,
8903 			cur_test->param.cipher_key_len,
8904 			cur_test->param.auth_alg,
8905 			cur_test->auth_key, cur_test->param.auth_key_len,
8906 			cur_test->bearer, cur_test->param.domain,
8907 			cur_test->packet_direction, cur_test->sn_size,
8908 			cur_test->hfn,
8909 			cur_test->hfn_threshold, SDAP_ENABLED);
8910 		if (err) {
8911 			printf("\t%d) %s: Encapsulation failed\n",
8912 					cur_test->test_idx,
8913 					cur_test->param.name);
8914 			err = TEST_FAILED;
8915 		} else {
8916 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
8917 					cur_test->param.name);
8918 			err = TEST_SUCCESS;
8919 		}
8920 		all_err += err;
8921 	}
8922 
8923 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8924 
8925 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8926 }
8927 
8928 static int
8929 test_PDCP_PROTO_short_mac(void)
8930 {
8931 	int i = 0, size = 0;
8932 	int err, all_err = TEST_SUCCESS;
8933 	const struct pdcp_short_mac_test *cur_test;
8934 
8935 	size = RTE_DIM(list_pdcp_smac_tests);
8936 
8937 	for (i = 0; i < size; i++) {
8938 		cur_test = &list_pdcp_smac_tests[i];
8939 		err = test_pdcp_proto(
8940 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8941 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
8942 			cur_test->in_len, cur_test->data_out,
8943 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8944 			RTE_CRYPTO_CIPHER_NULL, NULL,
8945 			0, cur_test->param.auth_alg,
8946 			cur_test->auth_key, cur_test->param.auth_key_len,
8947 			0, cur_test->param.domain, 0, 0,
8948 			0, 0, 0);
8949 		if (err) {
8950 			printf("\t%d) %s: Short MAC test failed\n",
8951 					cur_test->test_idx,
8952 					cur_test->param.name);
8953 			err = TEST_FAILED;
8954 		} else {
8955 			printf("\t%d) %s: Short MAC test PASS\n",
8956 					cur_test->test_idx,
8957 					cur_test->param.name);
8958 			rte_hexdump(stdout, "MAC I",
8959 				    cur_test->data_out + cur_test->in_len + 2,
8960 				    2);
8961 			err = TEST_SUCCESS;
8962 		}
8963 		all_err += err;
8964 	}
8965 
8966 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
8967 
8968 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
8969 
8970 }
8971 
8972 static int
8973 test_PDCP_SDAP_PROTO_decap_all(void)
8974 {
8975 	int i = 0, size = 0;
8976 	int err, all_err = TEST_SUCCESS;
8977 	const struct pdcp_sdap_test *cur_test;
8978 
8979 	size = RTE_DIM(list_pdcp_sdap_tests);
8980 
8981 	for (i = 0; i < size; i++) {
8982 		cur_test = &list_pdcp_sdap_tests[i];
8983 		err = test_pdcp_proto(
8984 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
8985 			RTE_CRYPTO_AUTH_OP_VERIFY,
8986 			cur_test->data_out,
8987 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
8988 			cur_test->data_in, cur_test->in_len,
8989 			cur_test->param.cipher_alg,
8990 			cur_test->cipher_key, cur_test->param.cipher_key_len,
8991 			cur_test->param.auth_alg, cur_test->auth_key,
8992 			cur_test->param.auth_key_len, cur_test->bearer,
8993 			cur_test->param.domain, cur_test->packet_direction,
8994 			cur_test->sn_size, cur_test->hfn,
8995 			cur_test->hfn_threshold, SDAP_ENABLED);
8996 		if (err) {
8997 			printf("\t%d) %s: Decapsulation failed\n",
8998 					cur_test->test_idx,
8999 					cur_test->param.name);
9000 			err = TEST_FAILED;
9001 		} else {
9002 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9003 					cur_test->param.name);
9004 			err = TEST_SUCCESS;
9005 		}
9006 		all_err += err;
9007 	}
9008 
9009 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9010 
9011 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9012 }
9013 
9014 static int
9015 test_ipsec_proto_process(const struct ipsec_test_data td[],
9016 			 struct ipsec_test_data res_d[],
9017 			 int nb_td,
9018 			 bool silent,
9019 			 const struct ipsec_test_flags *flags)
9020 {
9021 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9022 	struct crypto_unittest_params *ut_params = &unittest_params;
9023 	struct rte_security_capability_idx sec_cap_idx;
9024 	const struct rte_security_capability *sec_cap;
9025 	struct rte_security_ipsec_xform ipsec_xform;
9026 	uint8_t dev_id = ts_params->valid_devs[0];
9027 	enum rte_security_ipsec_sa_direction dir;
9028 	struct ipsec_test_data *res_d_tmp = NULL;
9029 	uint32_t src = RTE_IPV4(192, 168, 1, 0);
9030 	uint32_t dst = RTE_IPV4(192, 168, 1, 1);
9031 	int salt_len, i, ret = TEST_SUCCESS;
9032 	struct rte_security_ctx *ctx;
9033 	uint8_t *input_text;
9034 	uint32_t verify;
9035 
9036 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9037 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9038 
9039 	/* Use first test data to create session */
9040 
9041 	/* Copy IPsec xform */
9042 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9043 
9044 	dir = ipsec_xform.direction;
9045 	verify = flags->tunnel_hdr_verify;
9046 
9047 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9048 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9049 			src += 1;
9050 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9051 			dst += 1;
9052 	}
9053 
9054 	memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
9055 	memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
9056 
9057 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9058 
9059 	sec_cap_idx.action = ut_params->type;
9060 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9061 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9062 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9063 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9064 
9065 	if (flags->udp_encap)
9066 		ipsec_xform.options.udp_encap = 1;
9067 
9068 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9069 	if (sec_cap == NULL)
9070 		return TEST_SKIPPED;
9071 
9072 	/* Copy cipher session parameters */
9073 	if (td[0].aead) {
9074 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9075 		       sizeof(ut_params->aead_xform));
9076 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9077 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9078 
9079 		/* Verify crypto capabilities */
9080 		if (test_ipsec_crypto_caps_aead_verify(
9081 				sec_cap,
9082 				&ut_params->aead_xform) != 0) {
9083 			if (!silent)
9084 				RTE_LOG(INFO, USER1,
9085 					"Crypto capabilities not supported\n");
9086 			return TEST_SKIPPED;
9087 		}
9088 	} else {
9089 		/* Only AEAD supported now */
9090 		return TEST_SKIPPED;
9091 	}
9092 
9093 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9094 		return TEST_SKIPPED;
9095 
9096 	salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9097 	memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9098 
9099 	struct rte_security_session_conf sess_conf = {
9100 		.action_type = ut_params->type,
9101 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9102 		.ipsec = ipsec_xform,
9103 		.crypto_xform = &ut_params->aead_xform,
9104 	};
9105 
9106 	/* Create security session */
9107 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9108 					ts_params->session_mpool,
9109 					ts_params->session_priv_mpool);
9110 
9111 	if (ut_params->sec_session == NULL)
9112 		return TEST_SKIPPED;
9113 
9114 	for (i = 0; i < nb_td; i++) {
9115 		/* Setup source mbuf payload */
9116 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9117 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9118 				rte_pktmbuf_tailroom(ut_params->ibuf));
9119 
9120 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9121 				td[i].input_text.len);
9122 
9123 		memcpy(input_text, td[i].input_text.data,
9124 		       td[i].input_text.len);
9125 
9126 		/* Generate crypto op data structure */
9127 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9128 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9129 		if (!ut_params->op) {
9130 			printf("TestCase %s line %d: %s\n",
9131 				__func__, __LINE__,
9132 				"failed to allocate crypto op");
9133 			ret = TEST_FAILED;
9134 			goto crypto_op_free;
9135 		}
9136 
9137 		/* Attach session to operation */
9138 		rte_security_attach_session(ut_params->op,
9139 					    ut_params->sec_session);
9140 
9141 		/* Set crypto operation mbufs */
9142 		ut_params->op->sym->m_src = ut_params->ibuf;
9143 		ut_params->op->sym->m_dst = NULL;
9144 
9145 		/* Copy IV in crypto operation when IV generation is disabled */
9146 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9147 		    ipsec_xform.options.iv_gen_disable == 1) {
9148 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9149 								uint8_t *,
9150 								IV_OFFSET);
9151 			int len;
9152 
9153 			if (td[i].aead)
9154 				len = td[i].xform.aead.aead.iv.length;
9155 			else
9156 				len = td[i].xform.chain.cipher.cipher.iv.length;
9157 
9158 			memcpy(iv, td[i].iv.data, len);
9159 		}
9160 
9161 		/* Process crypto operation */
9162 		process_crypto_request(dev_id, ut_params->op);
9163 
9164 		ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9165 		if (ret != TEST_SUCCESS)
9166 			goto crypto_op_free;
9167 
9168 		if (res_d != NULL)
9169 			res_d_tmp = &res_d[i];
9170 
9171 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9172 					      res_d_tmp, silent, flags);
9173 		if (ret != TEST_SUCCESS)
9174 			goto crypto_op_free;
9175 
9176 		rte_crypto_op_free(ut_params->op);
9177 		ut_params->op = NULL;
9178 
9179 		rte_pktmbuf_free(ut_params->ibuf);
9180 		ut_params->ibuf = NULL;
9181 	}
9182 
9183 crypto_op_free:
9184 	rte_crypto_op_free(ut_params->op);
9185 	ut_params->op = NULL;
9186 
9187 	rte_pktmbuf_free(ut_params->ibuf);
9188 	ut_params->ibuf = NULL;
9189 
9190 	if (ut_params->sec_session)
9191 		rte_security_session_destroy(ctx, ut_params->sec_session);
9192 	ut_params->sec_session = NULL;
9193 
9194 	return ret;
9195 }
9196 
9197 static int
9198 test_ipsec_proto_known_vec(const void *test_data)
9199 {
9200 	struct ipsec_test_data td_outb;
9201 	struct ipsec_test_flags flags;
9202 
9203 	memset(&flags, 0, sizeof(flags));
9204 
9205 	memcpy(&td_outb, test_data, sizeof(td_outb));
9206 
9207 	/* Disable IV gen to be able to test with known vectors */
9208 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9209 
9210 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9211 }
9212 
9213 static int
9214 test_ipsec_proto_known_vec_inb(const void *td_outb)
9215 {
9216 	struct ipsec_test_flags flags;
9217 	struct ipsec_test_data td_inb;
9218 
9219 	memset(&flags, 0, sizeof(flags));
9220 
9221 	test_ipsec_td_in_from_out(td_outb, &td_inb);
9222 
9223 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9224 }
9225 
9226 static int
9227 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9228 {
9229 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9230 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9231 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9232 	int ret;
9233 
9234 	if (flags->iv_gen ||
9235 	    flags->sa_expiry_pkts_soft ||
9236 	    flags->sa_expiry_pkts_hard)
9237 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9238 
9239 	for (i = 0; i < RTE_DIM(aead_list); i++) {
9240 		test_ipsec_td_prepare(&aead_list[i],
9241 				      NULL,
9242 				      flags,
9243 				      td_outb,
9244 				      nb_pkts);
9245 
9246 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9247 					       flags);
9248 		if (ret == TEST_SKIPPED)
9249 			continue;
9250 
9251 		if (ret == TEST_FAILED)
9252 			return TEST_FAILED;
9253 
9254 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9255 
9256 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9257 					       flags);
9258 		if (ret == TEST_SKIPPED)
9259 			continue;
9260 
9261 		if (ret == TEST_FAILED)
9262 			return TEST_FAILED;
9263 
9264 		if (flags->display_alg)
9265 			test_ipsec_display_alg(&aead_list[i], NULL);
9266 
9267 		pass_cnt++;
9268 	}
9269 
9270 	if (pass_cnt > 0)
9271 		return TEST_SUCCESS;
9272 	else
9273 		return TEST_SKIPPED;
9274 }
9275 
9276 static int
9277 test_ipsec_proto_display_list(const void *data __rte_unused)
9278 {
9279 	struct ipsec_test_flags flags;
9280 
9281 	memset(&flags, 0, sizeof(flags));
9282 
9283 	flags.display_alg = true;
9284 
9285 	return test_ipsec_proto_all(&flags);
9286 }
9287 
9288 static int
9289 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9290 {
9291 	struct ipsec_test_flags flags;
9292 
9293 	memset(&flags, 0, sizeof(flags));
9294 
9295 	flags.iv_gen = true;
9296 
9297 	return test_ipsec_proto_all(&flags);
9298 }
9299 
9300 static int
9301 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9302 {
9303 	struct ipsec_test_flags flags;
9304 
9305 	memset(&flags, 0, sizeof(flags));
9306 
9307 	flags.sa_expiry_pkts_soft = true;
9308 
9309 	return test_ipsec_proto_all(&flags);
9310 }
9311 
9312 static int
9313 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9314 {
9315 	struct ipsec_test_flags flags;
9316 
9317 	memset(&flags, 0, sizeof(flags));
9318 
9319 	flags.sa_expiry_pkts_hard = true;
9320 
9321 	return test_ipsec_proto_all(&flags);
9322 }
9323 
9324 static int
9325 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9326 {
9327 	struct ipsec_test_flags flags;
9328 
9329 	memset(&flags, 0, sizeof(flags));
9330 
9331 	flags.icv_corrupt = true;
9332 
9333 	return test_ipsec_proto_all(&flags);
9334 }
9335 
9336 static int
9337 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9338 {
9339 	struct ipsec_test_flags flags;
9340 
9341 	memset(&flags, 0, sizeof(flags));
9342 
9343 	flags.udp_encap = true;
9344 
9345 	return test_ipsec_proto_all(&flags);
9346 }
9347 
9348 static int
9349 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9350 {
9351 	struct ipsec_test_flags flags;
9352 
9353 	memset(&flags, 0, sizeof(flags));
9354 
9355 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9356 
9357 	return test_ipsec_proto_all(&flags);
9358 }
9359 
9360 static int
9361 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9362 {
9363 	struct ipsec_test_flags flags;
9364 
9365 	memset(&flags, 0, sizeof(flags));
9366 
9367 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9368 
9369 	return test_ipsec_proto_all(&flags);
9370 }
9371 
9372 static int
9373 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9374 {
9375 	struct ipsec_test_flags flags;
9376 
9377 	memset(&flags, 0, sizeof(flags));
9378 
9379 	flags.udp_encap = true;
9380 	flags.udp_ports_verify = true;
9381 
9382 	return test_ipsec_proto_all(&flags);
9383 }
9384 
9385 static int
9386 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9387 {
9388 	struct ipsec_test_flags flags;
9389 
9390 	memset(&flags, 0, sizeof(flags));
9391 
9392 	flags.ip_csum = true;
9393 
9394 	return test_ipsec_proto_all(&flags);
9395 }
9396 
9397 static int
9398 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9399 {
9400 	struct ipsec_test_flags flags;
9401 
9402 	memset(&flags, 0, sizeof(flags));
9403 
9404 	flags.l4_csum = true;
9405 
9406 	return test_ipsec_proto_all(&flags);
9407 }
9408 
9409 static int
9410 test_PDCP_PROTO_all(void)
9411 {
9412 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9413 	struct crypto_unittest_params *ut_params = &unittest_params;
9414 	struct rte_cryptodev_info dev_info;
9415 	int status;
9416 
9417 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9418 	uint64_t feat_flags = dev_info.feature_flags;
9419 
9420 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9421 		return TEST_SKIPPED;
9422 
9423 	/* Set action type */
9424 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9425 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9426 		gbl_action_type;
9427 
9428 	if (security_proto_supported(ut_params->type,
9429 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
9430 		return TEST_SKIPPED;
9431 
9432 	status = test_PDCP_PROTO_cplane_encap_all();
9433 	status += test_PDCP_PROTO_cplane_decap_all();
9434 	status += test_PDCP_PROTO_uplane_encap_all();
9435 	status += test_PDCP_PROTO_uplane_decap_all();
9436 	status += test_PDCP_PROTO_SGL_in_place_32B();
9437 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
9438 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
9439 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
9440 	status += test_PDCP_SDAP_PROTO_encap_all();
9441 	status += test_PDCP_SDAP_PROTO_decap_all();
9442 	status += test_PDCP_PROTO_short_mac();
9443 
9444 	if (status)
9445 		return TEST_FAILED;
9446 	else
9447 		return TEST_SUCCESS;
9448 }
9449 
9450 static int
9451 test_docsis_proto_uplink(int i, struct docsis_test_data *d_td)
9452 {
9453 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9454 	struct crypto_unittest_params *ut_params = &unittest_params;
9455 	uint8_t *plaintext, *ciphertext;
9456 	uint8_t *iv_ptr;
9457 	int32_t cipher_len, crc_len;
9458 	uint32_t crc_data_len;
9459 	int ret = TEST_SUCCESS;
9460 
9461 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9462 					rte_cryptodev_get_sec_ctx(
9463 						ts_params->valid_devs[0]);
9464 
9465 	/* Verify the capabilities */
9466 	struct rte_security_capability_idx sec_cap_idx;
9467 	const struct rte_security_capability *sec_cap;
9468 	const struct rte_cryptodev_capabilities *crypto_cap;
9469 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9470 	int j = 0;
9471 
9472 	sec_cap_idx.action = ut_params->type;
9473 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9474 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9475 
9476 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9477 	if (sec_cap == NULL)
9478 		return TEST_SKIPPED;
9479 
9480 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9481 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9482 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9483 				crypto_cap->sym.xform_type ==
9484 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9485 				crypto_cap->sym.cipher.algo ==
9486 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9487 			sym_cap = &crypto_cap->sym;
9488 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9489 						d_td->key.len,
9490 						d_td->iv.len) == 0)
9491 				break;
9492 		}
9493 	}
9494 
9495 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9496 		return TEST_SKIPPED;
9497 
9498 	/* Setup source mbuf payload */
9499 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9500 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9501 			rte_pktmbuf_tailroom(ut_params->ibuf));
9502 
9503 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9504 			d_td->ciphertext.len);
9505 
9506 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9507 
9508 	/* Setup cipher session parameters */
9509 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9510 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9511 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9512 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9513 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9514 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9515 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9516 	ut_params->cipher_xform.next = NULL;
9517 
9518 	/* Setup DOCSIS session parameters */
9519 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9520 
9521 	struct rte_security_session_conf sess_conf = {
9522 		.action_type = ut_params->type,
9523 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9524 		.docsis = ut_params->docsis_xform,
9525 		.crypto_xform = &ut_params->cipher_xform,
9526 	};
9527 
9528 	/* Create security session */
9529 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9530 					ts_params->session_mpool,
9531 					ts_params->session_priv_mpool);
9532 
9533 	if (!ut_params->sec_session) {
9534 		printf("TestCase %s(%d) line %d: %s\n",
9535 			__func__, i, __LINE__, "failed to allocate session");
9536 		ret = TEST_FAILED;
9537 		goto on_err;
9538 	}
9539 
9540 	/* Generate crypto op data structure */
9541 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9542 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9543 	if (!ut_params->op) {
9544 		printf("TestCase %s(%d) line %d: %s\n",
9545 			__func__, i, __LINE__,
9546 			"failed to allocate symmetric crypto operation");
9547 		ret = TEST_FAILED;
9548 		goto on_err;
9549 	}
9550 
9551 	/* Setup CRC operation parameters */
9552 	crc_len = d_td->ciphertext.no_crc == false ?
9553 			(d_td->ciphertext.len -
9554 				d_td->ciphertext.crc_offset -
9555 				RTE_ETHER_CRC_LEN) :
9556 			0;
9557 	crc_len = crc_len > 0 ? crc_len : 0;
9558 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9559 	ut_params->op->sym->auth.data.length = crc_len;
9560 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9561 
9562 	/* Setup cipher operation parameters */
9563 	cipher_len = d_td->ciphertext.no_cipher == false ?
9564 			(d_td->ciphertext.len -
9565 				d_td->ciphertext.cipher_offset) :
9566 			0;
9567 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9568 	ut_params->op->sym->cipher.data.length = cipher_len;
9569 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9570 
9571 	/* Setup cipher IV */
9572 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9573 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9574 
9575 	/* Attach session to operation */
9576 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9577 
9578 	/* Set crypto operation mbufs */
9579 	ut_params->op->sym->m_src = ut_params->ibuf;
9580 	ut_params->op->sym->m_dst = NULL;
9581 
9582 	/* Process crypto operation */
9583 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9584 			NULL) {
9585 		printf("TestCase %s(%d) line %d: %s\n",
9586 			__func__, i, __LINE__,
9587 			"failed to process security crypto op");
9588 		ret = TEST_FAILED;
9589 		goto on_err;
9590 	}
9591 
9592 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9593 		printf("TestCase %s(%d) line %d: %s\n",
9594 			__func__, i, __LINE__, "crypto op processing failed");
9595 		ret = TEST_FAILED;
9596 		goto on_err;
9597 	}
9598 
9599 	/* Validate plaintext */
9600 	plaintext = ciphertext;
9601 
9602 	if (memcmp(plaintext, d_td->plaintext.data,
9603 			d_td->plaintext.len - crc_data_len)) {
9604 		printf("TestCase %s(%d) line %d: %s\n",
9605 			__func__, i, __LINE__, "plaintext not as expected\n");
9606 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
9607 				d_td->plaintext.len);
9608 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9609 		ret = TEST_FAILED;
9610 		goto on_err;
9611 	}
9612 
9613 on_err:
9614 	rte_crypto_op_free(ut_params->op);
9615 	ut_params->op = NULL;
9616 
9617 	if (ut_params->sec_session)
9618 		rte_security_session_destroy(ctx, ut_params->sec_session);
9619 	ut_params->sec_session = NULL;
9620 
9621 	rte_pktmbuf_free(ut_params->ibuf);
9622 	ut_params->ibuf = NULL;
9623 
9624 	return ret;
9625 }
9626 
9627 static int
9628 test_docsis_proto_downlink(int i, struct docsis_test_data *d_td)
9629 {
9630 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9631 	struct crypto_unittest_params *ut_params = &unittest_params;
9632 	uint8_t *plaintext, *ciphertext;
9633 	uint8_t *iv_ptr;
9634 	int32_t cipher_len, crc_len;
9635 	int ret = TEST_SUCCESS;
9636 
9637 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9638 					rte_cryptodev_get_sec_ctx(
9639 						ts_params->valid_devs[0]);
9640 
9641 	/* Verify the capabilities */
9642 	struct rte_security_capability_idx sec_cap_idx;
9643 	const struct rte_security_capability *sec_cap;
9644 	const struct rte_cryptodev_capabilities *crypto_cap;
9645 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9646 	int j = 0;
9647 
9648 	sec_cap_idx.action = ut_params->type;
9649 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9650 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9651 
9652 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9653 	if (sec_cap == NULL)
9654 		return TEST_SKIPPED;
9655 
9656 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9657 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9658 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9659 				crypto_cap->sym.xform_type ==
9660 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9661 				crypto_cap->sym.cipher.algo ==
9662 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9663 			sym_cap = &crypto_cap->sym;
9664 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9665 						d_td->key.len,
9666 						d_td->iv.len) == 0)
9667 				break;
9668 		}
9669 	}
9670 
9671 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9672 		return TEST_SKIPPED;
9673 
9674 	/* Setup source mbuf payload */
9675 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9676 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9677 			rte_pktmbuf_tailroom(ut_params->ibuf));
9678 
9679 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9680 			d_td->plaintext.len);
9681 
9682 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9683 
9684 	/* Setup cipher session parameters */
9685 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9686 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9687 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9688 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9689 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9690 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9691 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9692 	ut_params->cipher_xform.next = NULL;
9693 
9694 	/* Setup DOCSIS session parameters */
9695 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9696 
9697 	struct rte_security_session_conf sess_conf = {
9698 		.action_type = ut_params->type,
9699 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9700 		.docsis = ut_params->docsis_xform,
9701 		.crypto_xform = &ut_params->cipher_xform,
9702 	};
9703 
9704 	/* Create security session */
9705 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9706 					ts_params->session_mpool,
9707 					ts_params->session_priv_mpool);
9708 
9709 	if (!ut_params->sec_session) {
9710 		printf("TestCase %s(%d) line %d: %s\n",
9711 			__func__, i, __LINE__, "failed to allocate session");
9712 		ret = TEST_FAILED;
9713 		goto on_err;
9714 	}
9715 
9716 	/* Generate crypto op data structure */
9717 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9718 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9719 	if (!ut_params->op) {
9720 		printf("TestCase %s(%d) line %d: %s\n",
9721 			__func__, i, __LINE__,
9722 			"failed to allocate security crypto operation");
9723 		ret = TEST_FAILED;
9724 		goto on_err;
9725 	}
9726 
9727 	/* Setup CRC operation parameters */
9728 	crc_len = d_td->plaintext.no_crc == false ?
9729 			(d_td->plaintext.len -
9730 				d_td->plaintext.crc_offset -
9731 				RTE_ETHER_CRC_LEN) :
9732 			0;
9733 	crc_len = crc_len > 0 ? crc_len : 0;
9734 	ut_params->op->sym->auth.data.length = crc_len;
9735 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9736 
9737 	/* Setup cipher operation parameters */
9738 	cipher_len = d_td->plaintext.no_cipher == false ?
9739 			(d_td->plaintext.len -
9740 				d_td->plaintext.cipher_offset) :
9741 			0;
9742 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9743 	ut_params->op->sym->cipher.data.length = cipher_len;
9744 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9745 
9746 	/* Setup cipher IV */
9747 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9748 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9749 
9750 	/* Attach session to operation */
9751 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9752 
9753 	/* Set crypto operation mbufs */
9754 	ut_params->op->sym->m_src = ut_params->ibuf;
9755 	ut_params->op->sym->m_dst = NULL;
9756 
9757 	/* Process crypto operation */
9758 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9759 			NULL) {
9760 		printf("TestCase %s(%d) line %d: %s\n",
9761 			__func__, i, __LINE__,
9762 			"failed to process security crypto op");
9763 		ret = TEST_FAILED;
9764 		goto on_err;
9765 	}
9766 
9767 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9768 		printf("TestCase %s(%d) line %d: %s\n",
9769 			__func__, i, __LINE__, "crypto op processing failed");
9770 		ret = TEST_FAILED;
9771 		goto on_err;
9772 	}
9773 
9774 	/* Validate ciphertext */
9775 	ciphertext = plaintext;
9776 
9777 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
9778 		printf("TestCase %s(%d) line %d: %s\n",
9779 			__func__, i, __LINE__, "ciphertext not as expected\n");
9780 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
9781 				d_td->ciphertext.len);
9782 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
9783 		ret = TEST_FAILED;
9784 		goto on_err;
9785 	}
9786 
9787 on_err:
9788 	rte_crypto_op_free(ut_params->op);
9789 	ut_params->op = NULL;
9790 
9791 	if (ut_params->sec_session)
9792 		rte_security_session_destroy(ctx, ut_params->sec_session);
9793 	ut_params->sec_session = NULL;
9794 
9795 	rte_pktmbuf_free(ut_params->ibuf);
9796 	ut_params->ibuf = NULL;
9797 
9798 	return ret;
9799 }
9800 
9801 #define TEST_DOCSIS_COUNT(func) do {			\
9802 	int ret = func;					\
9803 	if (ret == TEST_SUCCESS)  {			\
9804 		printf("\t%2d)", n++);			\
9805 		printf("+++++ PASSED:" #func"\n");	\
9806 		p++;					\
9807 	} else if (ret == TEST_SKIPPED) {		\
9808 		printf("\t%2d)", n++);			\
9809 		printf("~~~~~ SKIPPED:" #func"\n");	\
9810 		s++;					\
9811 	} else {					\
9812 		printf("\t%2d)", n++);			\
9813 		printf("----- FAILED:" #func"\n");	\
9814 		f++;					\
9815 	}						\
9816 } while (0)
9817 
9818 static int
9819 test_DOCSIS_PROTO_uplink_all(void)
9820 {
9821 	int p = 0, s = 0, f = 0, n = 0;
9822 
9823 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(1, &docsis_test_case_1));
9824 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(2, &docsis_test_case_2));
9825 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(3, &docsis_test_case_3));
9826 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(4, &docsis_test_case_4));
9827 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(5, &docsis_test_case_5));
9828 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(6, &docsis_test_case_6));
9829 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(7, &docsis_test_case_7));
9830 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(8, &docsis_test_case_8));
9831 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(9, &docsis_test_case_9));
9832 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(10, &docsis_test_case_10));
9833 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(11, &docsis_test_case_11));
9834 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(12, &docsis_test_case_12));
9835 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(13, &docsis_test_case_13));
9836 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(14, &docsis_test_case_14));
9837 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(15, &docsis_test_case_15));
9838 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(16, &docsis_test_case_16));
9839 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(17, &docsis_test_case_17));
9840 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(18, &docsis_test_case_18));
9841 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(19, &docsis_test_case_19));
9842 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(20, &docsis_test_case_20));
9843 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(21, &docsis_test_case_21));
9844 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(22, &docsis_test_case_22));
9845 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(23, &docsis_test_case_23));
9846 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(24, &docsis_test_case_24));
9847 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(25, &docsis_test_case_25));
9848 	TEST_DOCSIS_COUNT(test_docsis_proto_uplink(26, &docsis_test_case_26));
9849 
9850 	if (f)
9851 		printf("## %s: %d passed out of %d (%d skipped)\n",
9852 			__func__, p, n, s);
9853 
9854 	return f;
9855 };
9856 
9857 static int
9858 test_DOCSIS_PROTO_downlink_all(void)
9859 {
9860 	int p = 0, s = 0, f = 0, n = 0;
9861 
9862 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(1, &docsis_test_case_1));
9863 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(2, &docsis_test_case_2));
9864 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(3, &docsis_test_case_3));
9865 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(4, &docsis_test_case_4));
9866 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(5, &docsis_test_case_5));
9867 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(6, &docsis_test_case_6));
9868 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(7, &docsis_test_case_7));
9869 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(8, &docsis_test_case_8));
9870 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(9, &docsis_test_case_9));
9871 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(10, &docsis_test_case_10));
9872 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(11, &docsis_test_case_11));
9873 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(12, &docsis_test_case_12));
9874 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(13, &docsis_test_case_13));
9875 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(14, &docsis_test_case_14));
9876 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(15, &docsis_test_case_15));
9877 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(16, &docsis_test_case_16));
9878 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(17, &docsis_test_case_17));
9879 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(18, &docsis_test_case_18));
9880 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(19, &docsis_test_case_19));
9881 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(20, &docsis_test_case_20));
9882 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(21, &docsis_test_case_21));
9883 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(22, &docsis_test_case_22));
9884 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(23, &docsis_test_case_23));
9885 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(24, &docsis_test_case_24));
9886 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(25, &docsis_test_case_25));
9887 	TEST_DOCSIS_COUNT(test_docsis_proto_downlink(26, &docsis_test_case_26));
9888 
9889 	if (f)
9890 		printf("## %s: %d passed out of %d (%d skipped)\n",
9891 			__func__, p, n, s);
9892 
9893 	return f;
9894 };
9895 
9896 static int
9897 test_DOCSIS_PROTO_all(void)
9898 {
9899 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9900 	struct crypto_unittest_params *ut_params = &unittest_params;
9901 	struct rte_cryptodev_info dev_info;
9902 	int status;
9903 
9904 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9905 	uint64_t feat_flags = dev_info.feature_flags;
9906 
9907 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9908 		return TEST_SKIPPED;
9909 
9910 	/* Set action type */
9911 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9912 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9913 		gbl_action_type;
9914 
9915 	if (security_proto_supported(ut_params->type,
9916 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9917 		return TEST_SKIPPED;
9918 
9919 	status = test_DOCSIS_PROTO_uplink_all();
9920 	status += test_DOCSIS_PROTO_downlink_all();
9921 
9922 	if (status)
9923 		return TEST_FAILED;
9924 	else
9925 		return TEST_SUCCESS;
9926 }
9927 #endif
9928 
9929 static int
9930 test_AES_GCM_authenticated_encryption_test_case_1(void)
9931 {
9932 	return test_authenticated_encryption(&gcm_test_case_1);
9933 }
9934 
9935 static int
9936 test_AES_GCM_authenticated_encryption_test_case_2(void)
9937 {
9938 	return test_authenticated_encryption(&gcm_test_case_2);
9939 }
9940 
9941 static int
9942 test_AES_GCM_authenticated_encryption_test_case_3(void)
9943 {
9944 	return test_authenticated_encryption(&gcm_test_case_3);
9945 }
9946 
9947 static int
9948 test_AES_GCM_authenticated_encryption_test_case_4(void)
9949 {
9950 	return test_authenticated_encryption(&gcm_test_case_4);
9951 }
9952 
9953 static int
9954 test_AES_GCM_authenticated_encryption_test_case_5(void)
9955 {
9956 	return test_authenticated_encryption(&gcm_test_case_5);
9957 }
9958 
9959 static int
9960 test_AES_GCM_authenticated_encryption_test_case_6(void)
9961 {
9962 	return test_authenticated_encryption(&gcm_test_case_6);
9963 }
9964 
9965 static int
9966 test_AES_GCM_authenticated_encryption_test_case_7(void)
9967 {
9968 	return test_authenticated_encryption(&gcm_test_case_7);
9969 }
9970 
9971 static int
9972 test_AES_GCM_authenticated_encryption_test_case_8(void)
9973 {
9974 	return test_authenticated_encryption(&gcm_test_case_8);
9975 }
9976 
9977 static int
9978 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
9979 {
9980 	return test_authenticated_encryption(&gcm_J0_test_case_1);
9981 }
9982 
9983 static int
9984 test_AES_GCM_auth_encryption_test_case_192_1(void)
9985 {
9986 	return test_authenticated_encryption(&gcm_test_case_192_1);
9987 }
9988 
9989 static int
9990 test_AES_GCM_auth_encryption_test_case_192_2(void)
9991 {
9992 	return test_authenticated_encryption(&gcm_test_case_192_2);
9993 }
9994 
9995 static int
9996 test_AES_GCM_auth_encryption_test_case_192_3(void)
9997 {
9998 	return test_authenticated_encryption(&gcm_test_case_192_3);
9999 }
10000 
10001 static int
10002 test_AES_GCM_auth_encryption_test_case_192_4(void)
10003 {
10004 	return test_authenticated_encryption(&gcm_test_case_192_4);
10005 }
10006 
10007 static int
10008 test_AES_GCM_auth_encryption_test_case_192_5(void)
10009 {
10010 	return test_authenticated_encryption(&gcm_test_case_192_5);
10011 }
10012 
10013 static int
10014 test_AES_GCM_auth_encryption_test_case_192_6(void)
10015 {
10016 	return test_authenticated_encryption(&gcm_test_case_192_6);
10017 }
10018 
10019 static int
10020 test_AES_GCM_auth_encryption_test_case_192_7(void)
10021 {
10022 	return test_authenticated_encryption(&gcm_test_case_192_7);
10023 }
10024 
10025 static int
10026 test_AES_GCM_auth_encryption_test_case_256_1(void)
10027 {
10028 	return test_authenticated_encryption(&gcm_test_case_256_1);
10029 }
10030 
10031 static int
10032 test_AES_GCM_auth_encryption_test_case_256_2(void)
10033 {
10034 	return test_authenticated_encryption(&gcm_test_case_256_2);
10035 }
10036 
10037 static int
10038 test_AES_GCM_auth_encryption_test_case_256_3(void)
10039 {
10040 	return test_authenticated_encryption(&gcm_test_case_256_3);
10041 }
10042 
10043 static int
10044 test_AES_GCM_auth_encryption_test_case_256_4(void)
10045 {
10046 	return test_authenticated_encryption(&gcm_test_case_256_4);
10047 }
10048 
10049 static int
10050 test_AES_GCM_auth_encryption_test_case_256_5(void)
10051 {
10052 	return test_authenticated_encryption(&gcm_test_case_256_5);
10053 }
10054 
10055 static int
10056 test_AES_GCM_auth_encryption_test_case_256_6(void)
10057 {
10058 	return test_authenticated_encryption(&gcm_test_case_256_6);
10059 }
10060 
10061 static int
10062 test_AES_GCM_auth_encryption_test_case_256_7(void)
10063 {
10064 	return test_authenticated_encryption(&gcm_test_case_256_7);
10065 }
10066 
10067 static int
10068 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10069 {
10070 	return test_authenticated_encryption(&gcm_test_case_aad_1);
10071 }
10072 
10073 static int
10074 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10075 {
10076 	return test_authenticated_encryption(&gcm_test_case_aad_2);
10077 }
10078 
10079 static int
10080 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10081 {
10082 	struct aead_test_data tdata;
10083 	int res;
10084 
10085 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10086 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10087 	tdata.iv.data[0] += 1;
10088 	res = test_authenticated_encryption(&tdata);
10089 	if (res == TEST_SKIPPED)
10090 		return res;
10091 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10092 	return TEST_SUCCESS;
10093 }
10094 
10095 static int
10096 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10097 {
10098 	struct aead_test_data tdata;
10099 	int res;
10100 
10101 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10102 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10103 	tdata.plaintext.data[0] += 1;
10104 	res = test_authenticated_encryption(&tdata);
10105 	if (res == TEST_SKIPPED)
10106 		return res;
10107 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10108 	return TEST_SUCCESS;
10109 }
10110 
10111 static int
10112 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10113 {
10114 	struct aead_test_data tdata;
10115 	int res;
10116 
10117 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10118 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10119 	tdata.ciphertext.data[0] += 1;
10120 	res = test_authenticated_encryption(&tdata);
10121 	if (res == TEST_SKIPPED)
10122 		return res;
10123 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10124 	return TEST_SUCCESS;
10125 }
10126 
10127 static int
10128 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10129 {
10130 	struct aead_test_data tdata;
10131 	int res;
10132 
10133 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10134 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10135 	tdata.aad.len += 1;
10136 	res = test_authenticated_encryption(&tdata);
10137 	if (res == TEST_SKIPPED)
10138 		return res;
10139 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10140 	return TEST_SUCCESS;
10141 }
10142 
10143 static int
10144 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10145 {
10146 	struct aead_test_data tdata;
10147 	uint8_t aad[gcm_test_case_7.aad.len];
10148 	int res;
10149 
10150 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10151 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10152 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10153 	aad[0] += 1;
10154 	tdata.aad.data = aad;
10155 	res = test_authenticated_encryption(&tdata);
10156 	if (res == TEST_SKIPPED)
10157 		return res;
10158 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10159 	return TEST_SUCCESS;
10160 }
10161 
10162 static int
10163 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10164 {
10165 	struct aead_test_data tdata;
10166 	int res;
10167 
10168 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10169 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10170 	tdata.auth_tag.data[0] += 1;
10171 	res = test_authenticated_encryption(&tdata);
10172 	if (res == TEST_SKIPPED)
10173 		return res;
10174 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10175 	return TEST_SUCCESS;
10176 }
10177 
10178 static int
10179 test_authenticated_decryption(const struct aead_test_data *tdata)
10180 {
10181 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10182 	struct crypto_unittest_params *ut_params = &unittest_params;
10183 
10184 	int retval;
10185 	uint8_t *plaintext;
10186 	uint32_t i;
10187 	struct rte_cryptodev_info dev_info;
10188 
10189 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10190 	uint64_t feat_flags = dev_info.feature_flags;
10191 
10192 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10193 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10194 		printf("Device doesn't support RAW data-path APIs.\n");
10195 		return TEST_SKIPPED;
10196 	}
10197 
10198 	/* Verify the capabilities */
10199 	struct rte_cryptodev_sym_capability_idx cap_idx;
10200 	const struct rte_cryptodev_symmetric_capability *capability;
10201 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10202 	cap_idx.algo.aead = tdata->algo;
10203 	capability = rte_cryptodev_sym_capability_get(
10204 			ts_params->valid_devs[0], &cap_idx);
10205 	if (capability == NULL)
10206 		return TEST_SKIPPED;
10207 	if (rte_cryptodev_sym_capability_check_aead(
10208 			capability, tdata->key.len, tdata->auth_tag.len,
10209 			tdata->aad.len, tdata->iv.len))
10210 		return TEST_SKIPPED;
10211 
10212 	/* Create AEAD session */
10213 	retval = create_aead_session(ts_params->valid_devs[0],
10214 			tdata->algo,
10215 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10216 			tdata->key.data, tdata->key.len,
10217 			tdata->aad.len, tdata->auth_tag.len,
10218 			tdata->iv.len);
10219 	if (retval < 0)
10220 		return retval;
10221 
10222 	/* alloc mbuf and set payload */
10223 	if (tdata->aad.len > MBUF_SIZE) {
10224 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10225 		/* Populate full size of add data */
10226 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10227 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10228 	} else
10229 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10230 
10231 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10232 			rte_pktmbuf_tailroom(ut_params->ibuf));
10233 
10234 	/* Create AEAD operation */
10235 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10236 	if (retval < 0)
10237 		return retval;
10238 
10239 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10240 
10241 	ut_params->op->sym->m_src = ut_params->ibuf;
10242 
10243 	/* Process crypto operation */
10244 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10245 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10246 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10247 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10248 				ut_params->op, 0, 0, 0, 0);
10249 	else
10250 		TEST_ASSERT_NOT_NULL(
10251 			process_crypto_request(ts_params->valid_devs[0],
10252 			ut_params->op), "failed to process sym crypto op");
10253 
10254 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10255 			"crypto op processing failed");
10256 
10257 	if (ut_params->op->sym->m_dst)
10258 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10259 				uint8_t *);
10260 	else
10261 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10262 				uint8_t *,
10263 				ut_params->op->sym->cipher.data.offset);
10264 
10265 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10266 
10267 	/* Validate obuf */
10268 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10269 			plaintext,
10270 			tdata->plaintext.data,
10271 			tdata->plaintext.len,
10272 			"Plaintext data not as expected");
10273 
10274 	TEST_ASSERT_EQUAL(ut_params->op->status,
10275 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10276 			"Authentication failed");
10277 
10278 	return 0;
10279 }
10280 
10281 static int
10282 test_AES_GCM_authenticated_decryption_test_case_1(void)
10283 {
10284 	return test_authenticated_decryption(&gcm_test_case_1);
10285 }
10286 
10287 static int
10288 test_AES_GCM_authenticated_decryption_test_case_2(void)
10289 {
10290 	return test_authenticated_decryption(&gcm_test_case_2);
10291 }
10292 
10293 static int
10294 test_AES_GCM_authenticated_decryption_test_case_3(void)
10295 {
10296 	return test_authenticated_decryption(&gcm_test_case_3);
10297 }
10298 
10299 static int
10300 test_AES_GCM_authenticated_decryption_test_case_4(void)
10301 {
10302 	return test_authenticated_decryption(&gcm_test_case_4);
10303 }
10304 
10305 static int
10306 test_AES_GCM_authenticated_decryption_test_case_5(void)
10307 {
10308 	return test_authenticated_decryption(&gcm_test_case_5);
10309 }
10310 
10311 static int
10312 test_AES_GCM_authenticated_decryption_test_case_6(void)
10313 {
10314 	return test_authenticated_decryption(&gcm_test_case_6);
10315 }
10316 
10317 static int
10318 test_AES_GCM_authenticated_decryption_test_case_7(void)
10319 {
10320 	return test_authenticated_decryption(&gcm_test_case_7);
10321 }
10322 
10323 static int
10324 test_AES_GCM_authenticated_decryption_test_case_8(void)
10325 {
10326 	return test_authenticated_decryption(&gcm_test_case_8);
10327 }
10328 
10329 static int
10330 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10331 {
10332 	return test_authenticated_decryption(&gcm_J0_test_case_1);
10333 }
10334 
10335 static int
10336 test_AES_GCM_auth_decryption_test_case_192_1(void)
10337 {
10338 	return test_authenticated_decryption(&gcm_test_case_192_1);
10339 }
10340 
10341 static int
10342 test_AES_GCM_auth_decryption_test_case_192_2(void)
10343 {
10344 	return test_authenticated_decryption(&gcm_test_case_192_2);
10345 }
10346 
10347 static int
10348 test_AES_GCM_auth_decryption_test_case_192_3(void)
10349 {
10350 	return test_authenticated_decryption(&gcm_test_case_192_3);
10351 }
10352 
10353 static int
10354 test_AES_GCM_auth_decryption_test_case_192_4(void)
10355 {
10356 	return test_authenticated_decryption(&gcm_test_case_192_4);
10357 }
10358 
10359 static int
10360 test_AES_GCM_auth_decryption_test_case_192_5(void)
10361 {
10362 	return test_authenticated_decryption(&gcm_test_case_192_5);
10363 }
10364 
10365 static int
10366 test_AES_GCM_auth_decryption_test_case_192_6(void)
10367 {
10368 	return test_authenticated_decryption(&gcm_test_case_192_6);
10369 }
10370 
10371 static int
10372 test_AES_GCM_auth_decryption_test_case_192_7(void)
10373 {
10374 	return test_authenticated_decryption(&gcm_test_case_192_7);
10375 }
10376 
10377 static int
10378 test_AES_GCM_auth_decryption_test_case_256_1(void)
10379 {
10380 	return test_authenticated_decryption(&gcm_test_case_256_1);
10381 }
10382 
10383 static int
10384 test_AES_GCM_auth_decryption_test_case_256_2(void)
10385 {
10386 	return test_authenticated_decryption(&gcm_test_case_256_2);
10387 }
10388 
10389 static int
10390 test_AES_GCM_auth_decryption_test_case_256_3(void)
10391 {
10392 	return test_authenticated_decryption(&gcm_test_case_256_3);
10393 }
10394 
10395 static int
10396 test_AES_GCM_auth_decryption_test_case_256_4(void)
10397 {
10398 	return test_authenticated_decryption(&gcm_test_case_256_4);
10399 }
10400 
10401 static int
10402 test_AES_GCM_auth_decryption_test_case_256_5(void)
10403 {
10404 	return test_authenticated_decryption(&gcm_test_case_256_5);
10405 }
10406 
10407 static int
10408 test_AES_GCM_auth_decryption_test_case_256_6(void)
10409 {
10410 	return test_authenticated_decryption(&gcm_test_case_256_6);
10411 }
10412 
10413 static int
10414 test_AES_GCM_auth_decryption_test_case_256_7(void)
10415 {
10416 	return test_authenticated_decryption(&gcm_test_case_256_7);
10417 }
10418 
10419 static int
10420 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10421 {
10422 	return test_authenticated_decryption(&gcm_test_case_aad_1);
10423 }
10424 
10425 static int
10426 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10427 {
10428 	return test_authenticated_decryption(&gcm_test_case_aad_2);
10429 }
10430 
10431 static int
10432 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10433 {
10434 	struct aead_test_data tdata;
10435 	int res;
10436 
10437 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10438 	tdata.iv.data[0] += 1;
10439 	res = test_authenticated_decryption(&tdata);
10440 	if (res == TEST_SKIPPED)
10441 		return res;
10442 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10443 	return TEST_SUCCESS;
10444 }
10445 
10446 static int
10447 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10448 {
10449 	struct aead_test_data tdata;
10450 	int res;
10451 
10452 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10453 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10454 	tdata.plaintext.data[0] += 1;
10455 	res = test_authenticated_decryption(&tdata);
10456 	if (res == TEST_SKIPPED)
10457 		return res;
10458 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10459 	return TEST_SUCCESS;
10460 }
10461 
10462 static int
10463 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10464 {
10465 	struct aead_test_data tdata;
10466 	int res;
10467 
10468 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10469 	tdata.ciphertext.data[0] += 1;
10470 	res = test_authenticated_decryption(&tdata);
10471 	if (res == TEST_SKIPPED)
10472 		return res;
10473 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10474 	return TEST_SUCCESS;
10475 }
10476 
10477 static int
10478 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10479 {
10480 	struct aead_test_data tdata;
10481 	int res;
10482 
10483 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10484 	tdata.aad.len += 1;
10485 	res = test_authenticated_decryption(&tdata);
10486 	if (res == TEST_SKIPPED)
10487 		return res;
10488 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10489 	return TEST_SUCCESS;
10490 }
10491 
10492 static int
10493 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10494 {
10495 	struct aead_test_data tdata;
10496 	uint8_t aad[gcm_test_case_7.aad.len];
10497 	int res;
10498 
10499 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10500 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10501 	aad[0] += 1;
10502 	tdata.aad.data = aad;
10503 	res = test_authenticated_decryption(&tdata);
10504 	if (res == TEST_SKIPPED)
10505 		return res;
10506 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10507 	return TEST_SUCCESS;
10508 }
10509 
10510 static int
10511 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10512 {
10513 	struct aead_test_data tdata;
10514 	int res;
10515 
10516 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10517 	tdata.auth_tag.data[0] += 1;
10518 	res = test_authenticated_decryption(&tdata);
10519 	if (res == TEST_SKIPPED)
10520 		return res;
10521 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10522 	return TEST_SUCCESS;
10523 }
10524 
10525 static int
10526 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10527 {
10528 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10529 	struct crypto_unittest_params *ut_params = &unittest_params;
10530 
10531 	int retval;
10532 	uint8_t *ciphertext, *auth_tag;
10533 	uint16_t plaintext_pad_len;
10534 	struct rte_cryptodev_info dev_info;
10535 
10536 	/* Verify the capabilities */
10537 	struct rte_cryptodev_sym_capability_idx cap_idx;
10538 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10539 	cap_idx.algo.aead = tdata->algo;
10540 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10541 			&cap_idx) == NULL)
10542 		return TEST_SKIPPED;
10543 
10544 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10545 	uint64_t feat_flags = dev_info.feature_flags;
10546 
10547 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10548 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
10549 		return TEST_SKIPPED;
10550 
10551 	/* not supported with CPU crypto */
10552 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10553 		return TEST_SKIPPED;
10554 
10555 	/* Create AEAD session */
10556 	retval = create_aead_session(ts_params->valid_devs[0],
10557 			tdata->algo,
10558 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10559 			tdata->key.data, tdata->key.len,
10560 			tdata->aad.len, tdata->auth_tag.len,
10561 			tdata->iv.len);
10562 	if (retval < 0)
10563 		return retval;
10564 
10565 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10566 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10567 
10568 	/* clear mbuf payload */
10569 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10570 			rte_pktmbuf_tailroom(ut_params->ibuf));
10571 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10572 			rte_pktmbuf_tailroom(ut_params->obuf));
10573 
10574 	/* Create AEAD operation */
10575 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10576 	if (retval < 0)
10577 		return retval;
10578 
10579 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10580 
10581 	ut_params->op->sym->m_src = ut_params->ibuf;
10582 	ut_params->op->sym->m_dst = ut_params->obuf;
10583 
10584 	/* Process crypto operation */
10585 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10586 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10587 			ut_params->op, 0, 0, 0, 0);
10588 	else
10589 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10590 			ut_params->op), "failed to process sym crypto op");
10591 
10592 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10593 			"crypto op processing failed");
10594 
10595 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10596 
10597 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10598 			ut_params->op->sym->cipher.data.offset);
10599 	auth_tag = ciphertext + plaintext_pad_len;
10600 
10601 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10602 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10603 
10604 	/* Validate obuf */
10605 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10606 			ciphertext,
10607 			tdata->ciphertext.data,
10608 			tdata->ciphertext.len,
10609 			"Ciphertext data not as expected");
10610 
10611 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10612 			auth_tag,
10613 			tdata->auth_tag.data,
10614 			tdata->auth_tag.len,
10615 			"Generated auth tag not as expected");
10616 
10617 	return 0;
10618 
10619 }
10620 
10621 static int
10622 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10623 {
10624 	return test_authenticated_encryption_oop(&gcm_test_case_5);
10625 }
10626 
10627 static int
10628 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10629 {
10630 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10631 	struct crypto_unittest_params *ut_params = &unittest_params;
10632 
10633 	int retval;
10634 	uint8_t *plaintext;
10635 	struct rte_cryptodev_info dev_info;
10636 
10637 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10638 	uint64_t feat_flags = dev_info.feature_flags;
10639 
10640 	/* Verify the capabilities */
10641 	struct rte_cryptodev_sym_capability_idx cap_idx;
10642 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10643 	cap_idx.algo.aead = tdata->algo;
10644 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10645 			&cap_idx) == NULL)
10646 		return TEST_SKIPPED;
10647 
10648 	/* not supported with CPU crypto and raw data-path APIs*/
10649 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10650 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
10651 		return TEST_SKIPPED;
10652 
10653 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10654 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10655 		printf("Device does not support RAW data-path APIs.\n");
10656 		return TEST_SKIPPED;
10657 	}
10658 
10659 	/* Create AEAD session */
10660 	retval = create_aead_session(ts_params->valid_devs[0],
10661 			tdata->algo,
10662 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10663 			tdata->key.data, tdata->key.len,
10664 			tdata->aad.len, tdata->auth_tag.len,
10665 			tdata->iv.len);
10666 	if (retval < 0)
10667 		return retval;
10668 
10669 	/* alloc mbuf and set payload */
10670 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10671 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10672 
10673 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10674 			rte_pktmbuf_tailroom(ut_params->ibuf));
10675 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10676 			rte_pktmbuf_tailroom(ut_params->obuf));
10677 
10678 	/* Create AEAD operation */
10679 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10680 	if (retval < 0)
10681 		return retval;
10682 
10683 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10684 
10685 	ut_params->op->sym->m_src = ut_params->ibuf;
10686 	ut_params->op->sym->m_dst = ut_params->obuf;
10687 
10688 	/* Process crypto operation */
10689 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10690 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10691 				ut_params->op, 0, 0, 0, 0);
10692 	else
10693 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10694 			ut_params->op), "failed to process sym crypto op");
10695 
10696 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10697 			"crypto op processing failed");
10698 
10699 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10700 			ut_params->op->sym->cipher.data.offset);
10701 
10702 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10703 
10704 	/* Validate obuf */
10705 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10706 			plaintext,
10707 			tdata->plaintext.data,
10708 			tdata->plaintext.len,
10709 			"Plaintext data not as expected");
10710 
10711 	TEST_ASSERT_EQUAL(ut_params->op->status,
10712 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10713 			"Authentication failed");
10714 	return 0;
10715 }
10716 
10717 static int
10718 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10719 {
10720 	return test_authenticated_decryption_oop(&gcm_test_case_5);
10721 }
10722 
10723 static int
10724 test_authenticated_encryption_sessionless(
10725 		const struct aead_test_data *tdata)
10726 {
10727 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10728 	struct crypto_unittest_params *ut_params = &unittest_params;
10729 
10730 	int retval;
10731 	uint8_t *ciphertext, *auth_tag;
10732 	uint16_t plaintext_pad_len;
10733 	uint8_t key[tdata->key.len + 1];
10734 	struct rte_cryptodev_info dev_info;
10735 
10736 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10737 	uint64_t feat_flags = dev_info.feature_flags;
10738 
10739 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10740 		printf("Device doesn't support Sessionless ops.\n");
10741 		return TEST_SKIPPED;
10742 	}
10743 
10744 	/* not supported with CPU crypto */
10745 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10746 		return TEST_SKIPPED;
10747 
10748 	/* Verify the capabilities */
10749 	struct rte_cryptodev_sym_capability_idx cap_idx;
10750 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10751 	cap_idx.algo.aead = tdata->algo;
10752 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10753 			&cap_idx) == NULL)
10754 		return TEST_SKIPPED;
10755 
10756 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10757 
10758 	/* clear mbuf payload */
10759 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10760 			rte_pktmbuf_tailroom(ut_params->ibuf));
10761 
10762 	/* Create AEAD operation */
10763 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10764 	if (retval < 0)
10765 		return retval;
10766 
10767 	/* Create GCM xform */
10768 	memcpy(key, tdata->key.data, tdata->key.len);
10769 	retval = create_aead_xform(ut_params->op,
10770 			tdata->algo,
10771 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10772 			key, tdata->key.len,
10773 			tdata->aad.len, tdata->auth_tag.len,
10774 			tdata->iv.len);
10775 	if (retval < 0)
10776 		return retval;
10777 
10778 	ut_params->op->sym->m_src = ut_params->ibuf;
10779 
10780 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10781 			RTE_CRYPTO_OP_SESSIONLESS,
10782 			"crypto op session type not sessionless");
10783 
10784 	/* Process crypto operation */
10785 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10786 			ut_params->op), "failed to process sym crypto op");
10787 
10788 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10789 
10790 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10791 			"crypto op status not success");
10792 
10793 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10794 
10795 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10796 			ut_params->op->sym->cipher.data.offset);
10797 	auth_tag = ciphertext + plaintext_pad_len;
10798 
10799 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10800 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10801 
10802 	/* Validate obuf */
10803 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10804 			ciphertext,
10805 			tdata->ciphertext.data,
10806 			tdata->ciphertext.len,
10807 			"Ciphertext data not as expected");
10808 
10809 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10810 			auth_tag,
10811 			tdata->auth_tag.data,
10812 			tdata->auth_tag.len,
10813 			"Generated auth tag not as expected");
10814 
10815 	return 0;
10816 
10817 }
10818 
10819 static int
10820 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10821 {
10822 	return test_authenticated_encryption_sessionless(
10823 			&gcm_test_case_5);
10824 }
10825 
10826 static int
10827 test_authenticated_decryption_sessionless(
10828 		const struct aead_test_data *tdata)
10829 {
10830 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10831 	struct crypto_unittest_params *ut_params = &unittest_params;
10832 
10833 	int retval;
10834 	uint8_t *plaintext;
10835 	uint8_t key[tdata->key.len + 1];
10836 	struct rte_cryptodev_info dev_info;
10837 
10838 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10839 	uint64_t feat_flags = dev_info.feature_flags;
10840 
10841 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10842 		printf("Device doesn't support Sessionless ops.\n");
10843 		return TEST_SKIPPED;
10844 	}
10845 
10846 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10847 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10848 		printf("Device doesn't support RAW data-path APIs.\n");
10849 		return TEST_SKIPPED;
10850 	}
10851 
10852 	/* not supported with CPU crypto */
10853 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10854 		return TEST_SKIPPED;
10855 
10856 	/* Verify the capabilities */
10857 	struct rte_cryptodev_sym_capability_idx cap_idx;
10858 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10859 	cap_idx.algo.aead = tdata->algo;
10860 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10861 			&cap_idx) == NULL)
10862 		return TEST_SKIPPED;
10863 
10864 	/* alloc mbuf and set payload */
10865 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10866 
10867 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10868 			rte_pktmbuf_tailroom(ut_params->ibuf));
10869 
10870 	/* Create AEAD operation */
10871 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10872 	if (retval < 0)
10873 		return retval;
10874 
10875 	/* Create AEAD xform */
10876 	memcpy(key, tdata->key.data, tdata->key.len);
10877 	retval = create_aead_xform(ut_params->op,
10878 			tdata->algo,
10879 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10880 			key, tdata->key.len,
10881 			tdata->aad.len, tdata->auth_tag.len,
10882 			tdata->iv.len);
10883 	if (retval < 0)
10884 		return retval;
10885 
10886 	ut_params->op->sym->m_src = ut_params->ibuf;
10887 
10888 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10889 			RTE_CRYPTO_OP_SESSIONLESS,
10890 			"crypto op session type not sessionless");
10891 
10892 	/* Process crypto operation */
10893 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10894 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10895 				ut_params->op, 0, 0, 0, 0);
10896 	else
10897 		TEST_ASSERT_NOT_NULL(process_crypto_request(
10898 			ts_params->valid_devs[0], ut_params->op),
10899 				"failed to process sym crypto op");
10900 
10901 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10902 
10903 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10904 			"crypto op status not success");
10905 
10906 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10907 			ut_params->op->sym->cipher.data.offset);
10908 
10909 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10910 
10911 	/* Validate obuf */
10912 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10913 			plaintext,
10914 			tdata->plaintext.data,
10915 			tdata->plaintext.len,
10916 			"Plaintext data not as expected");
10917 
10918 	TEST_ASSERT_EQUAL(ut_params->op->status,
10919 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10920 			"Authentication failed");
10921 	return 0;
10922 }
10923 
10924 static int
10925 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
10926 {
10927 	return test_authenticated_decryption_sessionless(
10928 			&gcm_test_case_5);
10929 }
10930 
10931 static int
10932 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
10933 {
10934 	return test_authenticated_encryption(&ccm_test_case_128_1);
10935 }
10936 
10937 static int
10938 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
10939 {
10940 	return test_authenticated_encryption(&ccm_test_case_128_2);
10941 }
10942 
10943 static int
10944 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
10945 {
10946 	return test_authenticated_encryption(&ccm_test_case_128_3);
10947 }
10948 
10949 static int
10950 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
10951 {
10952 	return test_authenticated_decryption(&ccm_test_case_128_1);
10953 }
10954 
10955 static int
10956 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
10957 {
10958 	return test_authenticated_decryption(&ccm_test_case_128_2);
10959 }
10960 
10961 static int
10962 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
10963 {
10964 	return test_authenticated_decryption(&ccm_test_case_128_3);
10965 }
10966 
10967 static int
10968 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
10969 {
10970 	return test_authenticated_encryption(&ccm_test_case_192_1);
10971 }
10972 
10973 static int
10974 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
10975 {
10976 	return test_authenticated_encryption(&ccm_test_case_192_2);
10977 }
10978 
10979 static int
10980 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
10981 {
10982 	return test_authenticated_encryption(&ccm_test_case_192_3);
10983 }
10984 
10985 static int
10986 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
10987 {
10988 	return test_authenticated_decryption(&ccm_test_case_192_1);
10989 }
10990 
10991 static int
10992 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
10993 {
10994 	return test_authenticated_decryption(&ccm_test_case_192_2);
10995 }
10996 
10997 static int
10998 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
10999 {
11000 	return test_authenticated_decryption(&ccm_test_case_192_3);
11001 }
11002 
11003 static int
11004 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11005 {
11006 	return test_authenticated_encryption(&ccm_test_case_256_1);
11007 }
11008 
11009 static int
11010 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11011 {
11012 	return test_authenticated_encryption(&ccm_test_case_256_2);
11013 }
11014 
11015 static int
11016 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11017 {
11018 	return test_authenticated_encryption(&ccm_test_case_256_3);
11019 }
11020 
11021 static int
11022 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11023 {
11024 	return test_authenticated_decryption(&ccm_test_case_256_1);
11025 }
11026 
11027 static int
11028 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11029 {
11030 	return test_authenticated_decryption(&ccm_test_case_256_2);
11031 }
11032 
11033 static int
11034 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11035 {
11036 	return test_authenticated_decryption(&ccm_test_case_256_3);
11037 }
11038 
11039 static int
11040 test_stats(void)
11041 {
11042 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11043 	struct rte_cryptodev_stats stats;
11044 
11045 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11046 		return TEST_SKIPPED;
11047 
11048 	/* Verify the capabilities */
11049 	struct rte_cryptodev_sym_capability_idx cap_idx;
11050 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11051 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11052 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11053 			&cap_idx) == NULL)
11054 		return TEST_SKIPPED;
11055 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11056 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11057 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11058 			&cap_idx) == NULL)
11059 		return TEST_SKIPPED;
11060 
11061 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11062 			== -ENOTSUP)
11063 		return TEST_SKIPPED;
11064 
11065 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11066 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11067 			&stats) == -ENODEV),
11068 		"rte_cryptodev_stats_get invalid dev failed");
11069 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11070 		"rte_cryptodev_stats_get invalid Param failed");
11071 
11072 	/* Test expected values */
11073 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
11074 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11075 			&stats),
11076 		"rte_cryptodev_stats_get failed");
11077 	TEST_ASSERT((stats.enqueued_count == 1),
11078 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11079 	TEST_ASSERT((stats.dequeued_count == 1),
11080 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11081 	TEST_ASSERT((stats.enqueue_err_count == 0),
11082 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11083 	TEST_ASSERT((stats.dequeue_err_count == 0),
11084 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11085 
11086 	/* invalid device but should ignore and not reset device stats*/
11087 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11088 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11089 			&stats),
11090 		"rte_cryptodev_stats_get failed");
11091 	TEST_ASSERT((stats.enqueued_count == 1),
11092 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11093 
11094 	/* check that a valid reset clears stats */
11095 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11096 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11097 			&stats),
11098 					  "rte_cryptodev_stats_get failed");
11099 	TEST_ASSERT((stats.enqueued_count == 0),
11100 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11101 	TEST_ASSERT((stats.dequeued_count == 0),
11102 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11103 
11104 	return TEST_SUCCESS;
11105 }
11106 
11107 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11108 				   struct crypto_unittest_params *ut_params,
11109 				   enum rte_crypto_auth_operation op,
11110 				   const struct HMAC_MD5_vector *test_case)
11111 {
11112 	uint8_t key[64];
11113 
11114 	memcpy(key, test_case->key.data, test_case->key.len);
11115 
11116 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11117 	ut_params->auth_xform.next = NULL;
11118 	ut_params->auth_xform.auth.op = op;
11119 
11120 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11121 
11122 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11123 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11124 	ut_params->auth_xform.auth.key.data = key;
11125 
11126 	ut_params->sess = rte_cryptodev_sym_session_create(
11127 			ts_params->session_mpool);
11128 
11129 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11130 			ut_params->sess, &ut_params->auth_xform,
11131 			ts_params->session_priv_mpool);
11132 
11133 	if (ut_params->sess == NULL)
11134 		return TEST_FAILED;
11135 
11136 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11137 
11138 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11139 			rte_pktmbuf_tailroom(ut_params->ibuf));
11140 
11141 	return 0;
11142 }
11143 
11144 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11145 			      const struct HMAC_MD5_vector *test_case,
11146 			      uint8_t **plaintext)
11147 {
11148 	uint16_t plaintext_pad_len;
11149 
11150 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11151 
11152 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11153 				16);
11154 
11155 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11156 			plaintext_pad_len);
11157 	memcpy(*plaintext, test_case->plaintext.data,
11158 			test_case->plaintext.len);
11159 
11160 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11161 			ut_params->ibuf, MD5_DIGEST_LEN);
11162 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11163 			"no room to append digest");
11164 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11165 			ut_params->ibuf, plaintext_pad_len);
11166 
11167 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11168 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11169 			   test_case->auth_tag.len);
11170 	}
11171 
11172 	sym_op->auth.data.offset = 0;
11173 	sym_op->auth.data.length = test_case->plaintext.len;
11174 
11175 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11176 	ut_params->op->sym->m_src = ut_params->ibuf;
11177 
11178 	return 0;
11179 }
11180 
11181 static int
11182 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11183 {
11184 	uint16_t plaintext_pad_len;
11185 	uint8_t *plaintext, *auth_tag;
11186 
11187 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11188 	struct crypto_unittest_params *ut_params = &unittest_params;
11189 	struct rte_cryptodev_info dev_info;
11190 
11191 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11192 	uint64_t feat_flags = dev_info.feature_flags;
11193 
11194 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11195 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11196 		printf("Device doesn't support RAW data-path APIs.\n");
11197 		return TEST_SKIPPED;
11198 	}
11199 
11200 	/* Verify the capabilities */
11201 	struct rte_cryptodev_sym_capability_idx cap_idx;
11202 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11203 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11204 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11205 			&cap_idx) == NULL)
11206 		return TEST_SKIPPED;
11207 
11208 	if (MD5_HMAC_create_session(ts_params, ut_params,
11209 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11210 		return TEST_FAILED;
11211 
11212 	/* Generate Crypto op data structure */
11213 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11214 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11215 	TEST_ASSERT_NOT_NULL(ut_params->op,
11216 			"Failed to allocate symmetric crypto operation struct");
11217 
11218 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11219 				16);
11220 
11221 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11222 		return TEST_FAILED;
11223 
11224 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11225 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11226 			ut_params->op);
11227 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11228 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11229 				ut_params->op, 0, 1, 0, 0);
11230 	else
11231 		TEST_ASSERT_NOT_NULL(
11232 			process_crypto_request(ts_params->valid_devs[0],
11233 				ut_params->op),
11234 				"failed to process sym crypto op");
11235 
11236 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11237 			"crypto op processing failed");
11238 
11239 	if (ut_params->op->sym->m_dst) {
11240 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11241 				uint8_t *, plaintext_pad_len);
11242 	} else {
11243 		auth_tag = plaintext + plaintext_pad_len;
11244 	}
11245 
11246 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11247 			auth_tag,
11248 			test_case->auth_tag.data,
11249 			test_case->auth_tag.len,
11250 			"HMAC_MD5 generated tag not as expected");
11251 
11252 	return TEST_SUCCESS;
11253 }
11254 
11255 static int
11256 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11257 {
11258 	uint8_t *plaintext;
11259 
11260 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11261 	struct crypto_unittest_params *ut_params = &unittest_params;
11262 	struct rte_cryptodev_info dev_info;
11263 
11264 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11265 	uint64_t feat_flags = dev_info.feature_flags;
11266 
11267 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11268 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11269 		printf("Device doesn't support RAW data-path APIs.\n");
11270 		return TEST_SKIPPED;
11271 	}
11272 
11273 	/* Verify the capabilities */
11274 	struct rte_cryptodev_sym_capability_idx cap_idx;
11275 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11276 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11277 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11278 			&cap_idx) == NULL)
11279 		return TEST_SKIPPED;
11280 
11281 	if (MD5_HMAC_create_session(ts_params, ut_params,
11282 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11283 		return TEST_FAILED;
11284 	}
11285 
11286 	/* Generate Crypto op data structure */
11287 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11288 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11289 	TEST_ASSERT_NOT_NULL(ut_params->op,
11290 			"Failed to allocate symmetric crypto operation struct");
11291 
11292 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11293 		return TEST_FAILED;
11294 
11295 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11296 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11297 			ut_params->op);
11298 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11299 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11300 				ut_params->op, 0, 1, 0, 0);
11301 	else
11302 		TEST_ASSERT_NOT_NULL(
11303 			process_crypto_request(ts_params->valid_devs[0],
11304 				ut_params->op),
11305 				"failed to process sym crypto op");
11306 
11307 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11308 			"HMAC_MD5 crypto op processing failed");
11309 
11310 	return TEST_SUCCESS;
11311 }
11312 
11313 static int
11314 test_MD5_HMAC_generate_case_1(void)
11315 {
11316 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11317 }
11318 
11319 static int
11320 test_MD5_HMAC_verify_case_1(void)
11321 {
11322 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11323 }
11324 
11325 static int
11326 test_MD5_HMAC_generate_case_2(void)
11327 {
11328 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11329 }
11330 
11331 static int
11332 test_MD5_HMAC_verify_case_2(void)
11333 {
11334 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11335 }
11336 
11337 static int
11338 test_multi_session(void)
11339 {
11340 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11341 	struct crypto_unittest_params *ut_params = &unittest_params;
11342 
11343 	struct rte_cryptodev_info dev_info;
11344 	struct rte_cryptodev_sym_session **sessions;
11345 
11346 	uint16_t i;
11347 
11348 	/* Verify the capabilities */
11349 	struct rte_cryptodev_sym_capability_idx cap_idx;
11350 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11351 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11352 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11353 			&cap_idx) == NULL)
11354 		return TEST_SKIPPED;
11355 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11356 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11357 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11358 			&cap_idx) == NULL)
11359 		return TEST_SKIPPED;
11360 
11361 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11362 			aes_cbc_key, hmac_sha512_key);
11363 
11364 
11365 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11366 
11367 	sessions = rte_malloc(NULL,
11368 			sizeof(struct rte_cryptodev_sym_session *) *
11369 			(MAX_NB_SESSIONS + 1), 0);
11370 
11371 	/* Create multiple crypto sessions*/
11372 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11373 
11374 		sessions[i] = rte_cryptodev_sym_session_create(
11375 				ts_params->session_mpool);
11376 
11377 		rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11378 				sessions[i], &ut_params->auth_xform,
11379 				ts_params->session_priv_mpool);
11380 		TEST_ASSERT_NOT_NULL(sessions[i],
11381 				"Session creation failed at session number %u",
11382 				i);
11383 
11384 		/* Attempt to send a request on each session */
11385 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11386 			sessions[i],
11387 			ut_params,
11388 			ts_params,
11389 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11390 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11391 			aes_cbc_iv),
11392 			"Failed to perform decrypt on request number %u.", i);
11393 		/* free crypto operation structure */
11394 		if (ut_params->op)
11395 			rte_crypto_op_free(ut_params->op);
11396 
11397 		/*
11398 		 * free mbuf - both obuf and ibuf are usually the same,
11399 		 * so check if they point at the same address is necessary,
11400 		 * to avoid freeing the mbuf twice.
11401 		 */
11402 		if (ut_params->obuf) {
11403 			rte_pktmbuf_free(ut_params->obuf);
11404 			if (ut_params->ibuf == ut_params->obuf)
11405 				ut_params->ibuf = 0;
11406 			ut_params->obuf = 0;
11407 		}
11408 		if (ut_params->ibuf) {
11409 			rte_pktmbuf_free(ut_params->ibuf);
11410 			ut_params->ibuf = 0;
11411 		}
11412 	}
11413 
11414 	sessions[i] = NULL;
11415 	/* Next session create should fail */
11416 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11417 			sessions[i], &ut_params->auth_xform,
11418 			ts_params->session_priv_mpool);
11419 	TEST_ASSERT_NULL(sessions[i],
11420 			"Session creation succeeded unexpectedly!");
11421 
11422 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11423 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11424 				sessions[i]);
11425 		rte_cryptodev_sym_session_free(sessions[i]);
11426 	}
11427 
11428 	rte_free(sessions);
11429 
11430 	return TEST_SUCCESS;
11431 }
11432 
11433 struct multi_session_params {
11434 	struct crypto_unittest_params ut_params;
11435 	uint8_t *cipher_key;
11436 	uint8_t *hmac_key;
11437 	const uint8_t *cipher;
11438 	const uint8_t *digest;
11439 	uint8_t *iv;
11440 };
11441 
11442 #define MB_SESSION_NUMBER 3
11443 
11444 static int
11445 test_multi_session_random_usage(void)
11446 {
11447 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11448 	struct rte_cryptodev_info dev_info;
11449 	struct rte_cryptodev_sym_session **sessions;
11450 	uint32_t i, j;
11451 	struct multi_session_params ut_paramz[] = {
11452 
11453 		{
11454 			.cipher_key = ms_aes_cbc_key0,
11455 			.hmac_key = ms_hmac_key0,
11456 			.cipher = ms_aes_cbc_cipher0,
11457 			.digest = ms_hmac_digest0,
11458 			.iv = ms_aes_cbc_iv0
11459 		},
11460 		{
11461 			.cipher_key = ms_aes_cbc_key1,
11462 			.hmac_key = ms_hmac_key1,
11463 			.cipher = ms_aes_cbc_cipher1,
11464 			.digest = ms_hmac_digest1,
11465 			.iv = ms_aes_cbc_iv1
11466 		},
11467 		{
11468 			.cipher_key = ms_aes_cbc_key2,
11469 			.hmac_key = ms_hmac_key2,
11470 			.cipher = ms_aes_cbc_cipher2,
11471 			.digest = ms_hmac_digest2,
11472 			.iv = ms_aes_cbc_iv2
11473 		},
11474 
11475 	};
11476 
11477 	/* Verify the capabilities */
11478 	struct rte_cryptodev_sym_capability_idx cap_idx;
11479 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11480 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11481 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11482 			&cap_idx) == NULL)
11483 		return TEST_SKIPPED;
11484 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11485 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11486 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11487 			&cap_idx) == NULL)
11488 		return TEST_SKIPPED;
11489 
11490 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11491 
11492 	sessions = rte_malloc(NULL,
11493 			(sizeof(struct rte_cryptodev_sym_session *)
11494 					* MAX_NB_SESSIONS) + 1, 0);
11495 
11496 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11497 		sessions[i] = rte_cryptodev_sym_session_create(
11498 				ts_params->session_mpool);
11499 
11500 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11501 				sizeof(struct crypto_unittest_params));
11502 
11503 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11504 				&ut_paramz[i].ut_params,
11505 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11506 
11507 		/* Create multiple crypto sessions*/
11508 		rte_cryptodev_sym_session_init(
11509 				ts_params->valid_devs[0],
11510 				sessions[i],
11511 				&ut_paramz[i].ut_params.auth_xform,
11512 				ts_params->session_priv_mpool);
11513 
11514 		TEST_ASSERT_NOT_NULL(sessions[i],
11515 				"Session creation failed at session number %u",
11516 				i);
11517 
11518 	}
11519 
11520 	srand(time(NULL));
11521 	for (i = 0; i < 40000; i++) {
11522 
11523 		j = rand() % MB_SESSION_NUMBER;
11524 
11525 		TEST_ASSERT_SUCCESS(
11526 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
11527 					sessions[j],
11528 					&ut_paramz[j].ut_params,
11529 					ts_params, ut_paramz[j].cipher,
11530 					ut_paramz[j].digest,
11531 					ut_paramz[j].iv),
11532 			"Failed to perform decrypt on request number %u.", i);
11533 
11534 		if (ut_paramz[j].ut_params.op)
11535 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
11536 
11537 		/*
11538 		 * free mbuf - both obuf and ibuf are usually the same,
11539 		 * so check if they point at the same address is necessary,
11540 		 * to avoid freeing the mbuf twice.
11541 		 */
11542 		if (ut_paramz[j].ut_params.obuf) {
11543 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11544 			if (ut_paramz[j].ut_params.ibuf
11545 					== ut_paramz[j].ut_params.obuf)
11546 				ut_paramz[j].ut_params.ibuf = 0;
11547 			ut_paramz[j].ut_params.obuf = 0;
11548 		}
11549 		if (ut_paramz[j].ut_params.ibuf) {
11550 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11551 			ut_paramz[j].ut_params.ibuf = 0;
11552 		}
11553 	}
11554 
11555 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11556 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11557 				sessions[i]);
11558 		rte_cryptodev_sym_session_free(sessions[i]);
11559 	}
11560 
11561 	rte_free(sessions);
11562 
11563 	return TEST_SUCCESS;
11564 }
11565 
11566 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11567 			0xab, 0xab, 0xab, 0xab,
11568 			0xab, 0xab, 0xab, 0xab,
11569 			0xab, 0xab, 0xab, 0xab};
11570 
11571 static int
11572 test_null_invalid_operation(void)
11573 {
11574 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11575 	struct crypto_unittest_params *ut_params = &unittest_params;
11576 	int ret;
11577 
11578 	/* This test is for NULL PMD only */
11579 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11580 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11581 		return TEST_SKIPPED;
11582 
11583 	/* Setup Cipher Parameters */
11584 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11585 	ut_params->cipher_xform.next = NULL;
11586 
11587 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11588 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11589 
11590 	ut_params->sess = rte_cryptodev_sym_session_create(
11591 			ts_params->session_mpool);
11592 
11593 	/* Create Crypto session*/
11594 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11595 			ut_params->sess, &ut_params->cipher_xform,
11596 			ts_params->session_priv_mpool);
11597 	TEST_ASSERT(ret < 0,
11598 			"Session creation succeeded unexpectedly");
11599 
11600 
11601 	/* Setup HMAC Parameters */
11602 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11603 	ut_params->auth_xform.next = NULL;
11604 
11605 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11606 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11607 
11608 	ut_params->sess = rte_cryptodev_sym_session_create(
11609 			ts_params->session_mpool);
11610 
11611 	/* Create Crypto session*/
11612 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11613 			ut_params->sess, &ut_params->auth_xform,
11614 			ts_params->session_priv_mpool);
11615 	TEST_ASSERT(ret < 0,
11616 			"Session creation succeeded unexpectedly");
11617 
11618 	return TEST_SUCCESS;
11619 }
11620 
11621 
11622 #define NULL_BURST_LENGTH (32)
11623 
11624 static int
11625 test_null_burst_operation(void)
11626 {
11627 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11628 	struct crypto_unittest_params *ut_params = &unittest_params;
11629 
11630 	unsigned i, burst_len = NULL_BURST_LENGTH;
11631 
11632 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11633 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11634 
11635 	/* This test is for NULL PMD only */
11636 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11637 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11638 		return TEST_SKIPPED;
11639 
11640 	/* Setup Cipher Parameters */
11641 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11642 	ut_params->cipher_xform.next = &ut_params->auth_xform;
11643 
11644 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11645 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11646 
11647 	/* Setup HMAC Parameters */
11648 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11649 	ut_params->auth_xform.next = NULL;
11650 
11651 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11652 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11653 
11654 	ut_params->sess = rte_cryptodev_sym_session_create(
11655 			ts_params->session_mpool);
11656 
11657 	/* Create Crypto session*/
11658 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11659 			ut_params->sess, &ut_params->cipher_xform,
11660 			ts_params->session_priv_mpool);
11661 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11662 
11663 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11664 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11665 			burst_len, "failed to generate burst of crypto ops");
11666 
11667 	/* Generate an operation for each mbuf in burst */
11668 	for (i = 0; i < burst_len; i++) {
11669 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11670 
11671 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11672 
11673 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11674 				sizeof(unsigned));
11675 		*data = i;
11676 
11677 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11678 
11679 		burst[i]->sym->m_src = m;
11680 	}
11681 
11682 	/* Process crypto operation */
11683 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11684 			0, burst, burst_len),
11685 			burst_len,
11686 			"Error enqueuing burst");
11687 
11688 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11689 			0, burst_dequeued, burst_len),
11690 			burst_len,
11691 			"Error dequeuing burst");
11692 
11693 
11694 	for (i = 0; i < burst_len; i++) {
11695 		TEST_ASSERT_EQUAL(
11696 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11697 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11698 					uint32_t *),
11699 			"data not as expected");
11700 
11701 		rte_pktmbuf_free(burst[i]->sym->m_src);
11702 		rte_crypto_op_free(burst[i]);
11703 	}
11704 
11705 	return TEST_SUCCESS;
11706 }
11707 
11708 static uint16_t
11709 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11710 		  uint16_t nb_ops, void *user_param)
11711 {
11712 	RTE_SET_USED(dev_id);
11713 	RTE_SET_USED(qp_id);
11714 	RTE_SET_USED(ops);
11715 	RTE_SET_USED(user_param);
11716 
11717 	printf("crypto enqueue callback called\n");
11718 	return nb_ops;
11719 }
11720 
11721 static uint16_t
11722 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11723 		  uint16_t nb_ops, void *user_param)
11724 {
11725 	RTE_SET_USED(dev_id);
11726 	RTE_SET_USED(qp_id);
11727 	RTE_SET_USED(ops);
11728 	RTE_SET_USED(user_param);
11729 
11730 	printf("crypto dequeue callback called\n");
11731 	return nb_ops;
11732 }
11733 
11734 /*
11735  * Thread using enqueue/dequeue callback with RCU.
11736  */
11737 static int
11738 test_enqdeq_callback_thread(void *arg)
11739 {
11740 	RTE_SET_USED(arg);
11741 	/* DP thread calls rte_cryptodev_enqueue_burst()/
11742 	 * rte_cryptodev_dequeue_burst() and invokes callback.
11743 	 */
11744 	test_null_burst_operation();
11745 	return 0;
11746 }
11747 
11748 static int
11749 test_enq_callback_setup(void)
11750 {
11751 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11752 	struct rte_cryptodev_info dev_info;
11753 	struct rte_cryptodev_qp_conf qp_conf = {
11754 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11755 	};
11756 
11757 	struct rte_cryptodev_cb *cb;
11758 	uint16_t qp_id = 0;
11759 
11760 	/* Stop the device in case it's started so it can be configured */
11761 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11762 
11763 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11764 
11765 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11766 			&ts_params->conf),
11767 			"Failed to configure cryptodev %u",
11768 			ts_params->valid_devs[0]);
11769 
11770 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11771 	qp_conf.mp_session = ts_params->session_mpool;
11772 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11773 
11774 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11775 			ts_params->valid_devs[0], qp_id, &qp_conf,
11776 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11777 			"Failed test for "
11778 			"rte_cryptodev_queue_pair_setup: num_inflights "
11779 			"%u on qp %u on cryptodev %u",
11780 			qp_conf.nb_descriptors, qp_id,
11781 			ts_params->valid_devs[0]);
11782 
11783 	/* Test with invalid crypto device */
11784 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11785 			qp_id, test_enq_callback, NULL);
11786 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11787 			"cryptodev %u did not fail",
11788 			qp_id, RTE_CRYPTO_MAX_DEVS);
11789 
11790 	/* Test with invalid queue pair */
11791 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11792 			dev_info.max_nb_queue_pairs + 1,
11793 			test_enq_callback, NULL);
11794 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11795 			"cryptodev %u did not fail",
11796 			dev_info.max_nb_queue_pairs + 1,
11797 			ts_params->valid_devs[0]);
11798 
11799 	/* Test with NULL callback */
11800 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11801 			qp_id, NULL, NULL);
11802 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11803 			"cryptodev %u did not fail",
11804 			qp_id, ts_params->valid_devs[0]);
11805 
11806 	/* Test with valid configuration */
11807 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11808 			qp_id, test_enq_callback, NULL);
11809 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11810 			"qp %u on cryptodev %u",
11811 			qp_id, ts_params->valid_devs[0]);
11812 
11813 	rte_cryptodev_start(ts_params->valid_devs[0]);
11814 
11815 	/* Launch a thread */
11816 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11817 				rte_get_next_lcore(-1, 1, 0));
11818 
11819 	/* Wait until reader exited. */
11820 	rte_eal_mp_wait_lcore();
11821 
11822 	/* Test with invalid crypto device */
11823 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11824 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11825 			"Expected call to fail as crypto device is invalid");
11826 
11827 	/* Test with invalid queue pair */
11828 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11829 			ts_params->valid_devs[0],
11830 			dev_info.max_nb_queue_pairs + 1, cb),
11831 			"Expected call to fail as queue pair is invalid");
11832 
11833 	/* Test with NULL callback */
11834 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11835 			ts_params->valid_devs[0], qp_id, NULL),
11836 			"Expected call to fail as callback is NULL");
11837 
11838 	/* Test with valid configuration */
11839 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11840 			ts_params->valid_devs[0], qp_id, cb),
11841 			"Failed test to remove callback on "
11842 			"qp %u on cryptodev %u",
11843 			qp_id, ts_params->valid_devs[0]);
11844 
11845 	return TEST_SUCCESS;
11846 }
11847 
11848 static int
11849 test_deq_callback_setup(void)
11850 {
11851 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11852 	struct rte_cryptodev_info dev_info;
11853 	struct rte_cryptodev_qp_conf qp_conf = {
11854 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11855 	};
11856 
11857 	struct rte_cryptodev_cb *cb;
11858 	uint16_t qp_id = 0;
11859 
11860 	/* Stop the device in case it's started so it can be configured */
11861 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11862 
11863 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11864 
11865 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11866 			&ts_params->conf),
11867 			"Failed to configure cryptodev %u",
11868 			ts_params->valid_devs[0]);
11869 
11870 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11871 	qp_conf.mp_session = ts_params->session_mpool;
11872 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11873 
11874 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11875 			ts_params->valid_devs[0], qp_id, &qp_conf,
11876 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11877 			"Failed test for "
11878 			"rte_cryptodev_queue_pair_setup: num_inflights "
11879 			"%u on qp %u on cryptodev %u",
11880 			qp_conf.nb_descriptors, qp_id,
11881 			ts_params->valid_devs[0]);
11882 
11883 	/* Test with invalid crypto device */
11884 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
11885 			qp_id, test_deq_callback, NULL);
11886 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11887 			"cryptodev %u did not fail",
11888 			qp_id, RTE_CRYPTO_MAX_DEVS);
11889 
11890 	/* Test with invalid queue pair */
11891 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11892 			dev_info.max_nb_queue_pairs + 1,
11893 			test_deq_callback, NULL);
11894 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11895 			"cryptodev %u did not fail",
11896 			dev_info.max_nb_queue_pairs + 1,
11897 			ts_params->valid_devs[0]);
11898 
11899 	/* Test with NULL callback */
11900 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11901 			qp_id, NULL, NULL);
11902 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11903 			"cryptodev %u did not fail",
11904 			qp_id, ts_params->valid_devs[0]);
11905 
11906 	/* Test with valid configuration */
11907 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
11908 			qp_id, test_deq_callback, NULL);
11909 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11910 			"qp %u on cryptodev %u",
11911 			qp_id, ts_params->valid_devs[0]);
11912 
11913 	rte_cryptodev_start(ts_params->valid_devs[0]);
11914 
11915 	/* Launch a thread */
11916 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11917 				rte_get_next_lcore(-1, 1, 0));
11918 
11919 	/* Wait until reader exited. */
11920 	rte_eal_mp_wait_lcore();
11921 
11922 	/* Test with invalid crypto device */
11923 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11924 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11925 			"Expected call to fail as crypto device is invalid");
11926 
11927 	/* Test with invalid queue pair */
11928 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11929 			ts_params->valid_devs[0],
11930 			dev_info.max_nb_queue_pairs + 1, cb),
11931 			"Expected call to fail as queue pair is invalid");
11932 
11933 	/* Test with NULL callback */
11934 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
11935 			ts_params->valid_devs[0], qp_id, NULL),
11936 			"Expected call to fail as callback is NULL");
11937 
11938 	/* Test with valid configuration */
11939 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
11940 			ts_params->valid_devs[0], qp_id, cb),
11941 			"Failed test to remove callback on "
11942 			"qp %u on cryptodev %u",
11943 			qp_id, ts_params->valid_devs[0]);
11944 
11945 	return TEST_SUCCESS;
11946 }
11947 
11948 static void
11949 generate_gmac_large_plaintext(uint8_t *data)
11950 {
11951 	uint16_t i;
11952 
11953 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
11954 		memcpy(&data[i], &data[0], 32);
11955 }
11956 
11957 static int
11958 create_gmac_operation(enum rte_crypto_auth_operation op,
11959 		const struct gmac_test_data *tdata)
11960 {
11961 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11962 	struct crypto_unittest_params *ut_params = &unittest_params;
11963 	struct rte_crypto_sym_op *sym_op;
11964 
11965 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
11966 
11967 	/* Generate Crypto op data structure */
11968 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11969 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11970 	TEST_ASSERT_NOT_NULL(ut_params->op,
11971 			"Failed to allocate symmetric crypto operation struct");
11972 
11973 	sym_op = ut_params->op->sym;
11974 
11975 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11976 			ut_params->ibuf, tdata->gmac_tag.len);
11977 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11978 			"no room to append digest");
11979 
11980 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11981 			ut_params->ibuf, plaintext_pad_len);
11982 
11983 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11984 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
11985 				tdata->gmac_tag.len);
11986 		debug_hexdump(stdout, "digest:",
11987 				sym_op->auth.digest.data,
11988 				tdata->gmac_tag.len);
11989 	}
11990 
11991 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
11992 			uint8_t *, IV_OFFSET);
11993 
11994 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
11995 
11996 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
11997 
11998 	sym_op->cipher.data.length = 0;
11999 	sym_op->cipher.data.offset = 0;
12000 
12001 	sym_op->auth.data.offset = 0;
12002 	sym_op->auth.data.length = tdata->plaintext.len;
12003 
12004 	return 0;
12005 }
12006 
12007 static int
12008 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12009 		const struct gmac_test_data *tdata,
12010 		void *digest_mem, uint64_t digest_phys)
12011 {
12012 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12013 	struct crypto_unittest_params *ut_params = &unittest_params;
12014 	struct rte_crypto_sym_op *sym_op;
12015 
12016 	/* Generate Crypto op data structure */
12017 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12018 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12019 	TEST_ASSERT_NOT_NULL(ut_params->op,
12020 			"Failed to allocate symmetric crypto operation struct");
12021 
12022 	sym_op = ut_params->op->sym;
12023 
12024 	sym_op->auth.digest.data = digest_mem;
12025 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12026 			"no room to append digest");
12027 
12028 	sym_op->auth.digest.phys_addr = digest_phys;
12029 
12030 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12031 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12032 				tdata->gmac_tag.len);
12033 		debug_hexdump(stdout, "digest:",
12034 				sym_op->auth.digest.data,
12035 				tdata->gmac_tag.len);
12036 	}
12037 
12038 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12039 			uint8_t *, IV_OFFSET);
12040 
12041 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12042 
12043 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12044 
12045 	sym_op->cipher.data.length = 0;
12046 	sym_op->cipher.data.offset = 0;
12047 
12048 	sym_op->auth.data.offset = 0;
12049 	sym_op->auth.data.length = tdata->plaintext.len;
12050 
12051 	return 0;
12052 }
12053 
12054 static int create_gmac_session(uint8_t dev_id,
12055 		const struct gmac_test_data *tdata,
12056 		enum rte_crypto_auth_operation auth_op)
12057 {
12058 	uint8_t auth_key[tdata->key.len];
12059 
12060 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12061 	struct crypto_unittest_params *ut_params = &unittest_params;
12062 
12063 	memcpy(auth_key, tdata->key.data, tdata->key.len);
12064 
12065 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12066 	ut_params->auth_xform.next = NULL;
12067 
12068 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12069 	ut_params->auth_xform.auth.op = auth_op;
12070 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12071 	ut_params->auth_xform.auth.key.length = tdata->key.len;
12072 	ut_params->auth_xform.auth.key.data = auth_key;
12073 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12074 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12075 
12076 
12077 	ut_params->sess = rte_cryptodev_sym_session_create(
12078 			ts_params->session_mpool);
12079 
12080 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12081 			&ut_params->auth_xform,
12082 			ts_params->session_priv_mpool);
12083 
12084 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12085 
12086 	return 0;
12087 }
12088 
12089 static int
12090 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12091 {
12092 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12093 	struct crypto_unittest_params *ut_params = &unittest_params;
12094 	struct rte_cryptodev_info dev_info;
12095 
12096 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12097 	uint64_t feat_flags = dev_info.feature_flags;
12098 
12099 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12100 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12101 		printf("Device doesn't support RAW data-path APIs.\n");
12102 		return TEST_SKIPPED;
12103 	}
12104 
12105 	int retval;
12106 
12107 	uint8_t *auth_tag, *plaintext;
12108 	uint16_t plaintext_pad_len;
12109 
12110 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12111 			      "No GMAC length in the source data");
12112 
12113 	/* Verify the capabilities */
12114 	struct rte_cryptodev_sym_capability_idx cap_idx;
12115 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12116 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12117 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12118 			&cap_idx) == NULL)
12119 		return TEST_SKIPPED;
12120 
12121 	retval = create_gmac_session(ts_params->valid_devs[0],
12122 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12123 
12124 	if (retval < 0)
12125 		return retval;
12126 
12127 	if (tdata->plaintext.len > MBUF_SIZE)
12128 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12129 	else
12130 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12131 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12132 			"Failed to allocate input buffer in mempool");
12133 
12134 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12135 			rte_pktmbuf_tailroom(ut_params->ibuf));
12136 
12137 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12138 	/*
12139 	 * Runtime generate the large plain text instead of use hard code
12140 	 * plain text vector. It is done to avoid create huge source file
12141 	 * with the test vector.
12142 	 */
12143 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12144 		generate_gmac_large_plaintext(tdata->plaintext.data);
12145 
12146 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12147 				plaintext_pad_len);
12148 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12149 
12150 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12151 	debug_hexdump(stdout, "plaintext:", plaintext,
12152 			tdata->plaintext.len);
12153 
12154 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12155 			tdata);
12156 
12157 	if (retval < 0)
12158 		return retval;
12159 
12160 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12161 
12162 	ut_params->op->sym->m_src = ut_params->ibuf;
12163 
12164 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12165 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12166 			ut_params->op);
12167 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12168 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12169 				ut_params->op, 0, 1, 0, 0);
12170 	else
12171 		TEST_ASSERT_NOT_NULL(
12172 			process_crypto_request(ts_params->valid_devs[0],
12173 			ut_params->op), "failed to process sym crypto op");
12174 
12175 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12176 			"crypto op processing failed");
12177 
12178 	if (ut_params->op->sym->m_dst) {
12179 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12180 				uint8_t *, plaintext_pad_len);
12181 	} else {
12182 		auth_tag = plaintext + plaintext_pad_len;
12183 	}
12184 
12185 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12186 
12187 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12188 			auth_tag,
12189 			tdata->gmac_tag.data,
12190 			tdata->gmac_tag.len,
12191 			"GMAC Generated auth tag not as expected");
12192 
12193 	return 0;
12194 }
12195 
12196 static int
12197 test_AES_GMAC_authentication_test_case_1(void)
12198 {
12199 	return test_AES_GMAC_authentication(&gmac_test_case_1);
12200 }
12201 
12202 static int
12203 test_AES_GMAC_authentication_test_case_2(void)
12204 {
12205 	return test_AES_GMAC_authentication(&gmac_test_case_2);
12206 }
12207 
12208 static int
12209 test_AES_GMAC_authentication_test_case_3(void)
12210 {
12211 	return test_AES_GMAC_authentication(&gmac_test_case_3);
12212 }
12213 
12214 static int
12215 test_AES_GMAC_authentication_test_case_4(void)
12216 {
12217 	return test_AES_GMAC_authentication(&gmac_test_case_4);
12218 }
12219 
12220 static int
12221 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12222 {
12223 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12224 	struct crypto_unittest_params *ut_params = &unittest_params;
12225 	int retval;
12226 	uint32_t plaintext_pad_len;
12227 	uint8_t *plaintext;
12228 	struct rte_cryptodev_info dev_info;
12229 
12230 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12231 	uint64_t feat_flags = dev_info.feature_flags;
12232 
12233 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12234 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12235 		printf("Device doesn't support RAW data-path APIs.\n");
12236 		return TEST_SKIPPED;
12237 	}
12238 
12239 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12240 			      "No GMAC length in the source data");
12241 
12242 	/* Verify the capabilities */
12243 	struct rte_cryptodev_sym_capability_idx cap_idx;
12244 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12245 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12246 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12247 			&cap_idx) == NULL)
12248 		return TEST_SKIPPED;
12249 
12250 	retval = create_gmac_session(ts_params->valid_devs[0],
12251 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12252 
12253 	if (retval < 0)
12254 		return retval;
12255 
12256 	if (tdata->plaintext.len > MBUF_SIZE)
12257 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12258 	else
12259 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12260 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12261 			"Failed to allocate input buffer in mempool");
12262 
12263 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12264 			rte_pktmbuf_tailroom(ut_params->ibuf));
12265 
12266 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12267 
12268 	/*
12269 	 * Runtime generate the large plain text instead of use hard code
12270 	 * plain text vector. It is done to avoid create huge source file
12271 	 * with the test vector.
12272 	 */
12273 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12274 		generate_gmac_large_plaintext(tdata->plaintext.data);
12275 
12276 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12277 				plaintext_pad_len);
12278 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12279 
12280 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12281 	debug_hexdump(stdout, "plaintext:", plaintext,
12282 			tdata->plaintext.len);
12283 
12284 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12285 			tdata);
12286 
12287 	if (retval < 0)
12288 		return retval;
12289 
12290 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12291 
12292 	ut_params->op->sym->m_src = ut_params->ibuf;
12293 
12294 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12295 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12296 			ut_params->op);
12297 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12298 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12299 				ut_params->op, 0, 1, 0, 0);
12300 	else
12301 		TEST_ASSERT_NOT_NULL(
12302 			process_crypto_request(ts_params->valid_devs[0],
12303 			ut_params->op), "failed to process sym crypto op");
12304 
12305 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12306 			"crypto op processing failed");
12307 
12308 	return 0;
12309 
12310 }
12311 
12312 static int
12313 test_AES_GMAC_authentication_verify_test_case_1(void)
12314 {
12315 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12316 }
12317 
12318 static int
12319 test_AES_GMAC_authentication_verify_test_case_2(void)
12320 {
12321 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12322 }
12323 
12324 static int
12325 test_AES_GMAC_authentication_verify_test_case_3(void)
12326 {
12327 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12328 }
12329 
12330 static int
12331 test_AES_GMAC_authentication_verify_test_case_4(void)
12332 {
12333 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12334 }
12335 
12336 static int
12337 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12338 				uint32_t fragsz)
12339 {
12340 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12341 	struct crypto_unittest_params *ut_params = &unittest_params;
12342 	struct rte_cryptodev_info dev_info;
12343 	uint64_t feature_flags;
12344 	unsigned int trn_data = 0;
12345 	void *digest_mem = NULL;
12346 	uint32_t segs = 1;
12347 	unsigned int to_trn = 0;
12348 	struct rte_mbuf *buf = NULL;
12349 	uint8_t *auth_tag, *plaintext;
12350 	int retval;
12351 
12352 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12353 			      "No GMAC length in the source data");
12354 
12355 	/* Verify the capabilities */
12356 	struct rte_cryptodev_sym_capability_idx cap_idx;
12357 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12358 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12359 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12360 			&cap_idx) == NULL)
12361 		return TEST_SKIPPED;
12362 
12363 	/* Check for any input SGL support */
12364 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12365 	feature_flags = dev_info.feature_flags;
12366 
12367 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12368 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12369 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12370 		return TEST_SKIPPED;
12371 
12372 	if (fragsz > tdata->plaintext.len)
12373 		fragsz = tdata->plaintext.len;
12374 
12375 	uint16_t plaintext_len = fragsz;
12376 
12377 	retval = create_gmac_session(ts_params->valid_devs[0],
12378 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12379 
12380 	if (retval < 0)
12381 		return retval;
12382 
12383 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12384 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12385 			"Failed to allocate input buffer in mempool");
12386 
12387 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12388 			rte_pktmbuf_tailroom(ut_params->ibuf));
12389 
12390 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12391 				plaintext_len);
12392 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12393 
12394 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12395 
12396 	trn_data += plaintext_len;
12397 
12398 	buf = ut_params->ibuf;
12399 
12400 	/*
12401 	 * Loop until no more fragments
12402 	 */
12403 
12404 	while (trn_data < tdata->plaintext.len) {
12405 		++segs;
12406 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12407 				(tdata->plaintext.len - trn_data) : fragsz;
12408 
12409 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12410 		buf = buf->next;
12411 
12412 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12413 				rte_pktmbuf_tailroom(buf));
12414 
12415 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12416 				to_trn);
12417 
12418 		memcpy(plaintext, tdata->plaintext.data + trn_data,
12419 				to_trn);
12420 		trn_data += to_trn;
12421 		if (trn_data  == tdata->plaintext.len)
12422 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12423 					tdata->gmac_tag.len);
12424 	}
12425 	ut_params->ibuf->nb_segs = segs;
12426 
12427 	/*
12428 	 * Place digest at the end of the last buffer
12429 	 */
12430 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12431 
12432 	if (!digest_mem) {
12433 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12434 				+ tdata->gmac_tag.len);
12435 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12436 				tdata->plaintext.len);
12437 	}
12438 
12439 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12440 			tdata, digest_mem, digest_phys);
12441 
12442 	if (retval < 0)
12443 		return retval;
12444 
12445 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12446 
12447 	ut_params->op->sym->m_src = ut_params->ibuf;
12448 
12449 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12450 		return TEST_SKIPPED;
12451 
12452 	TEST_ASSERT_NOT_NULL(
12453 		process_crypto_request(ts_params->valid_devs[0],
12454 		ut_params->op), "failed to process sym crypto op");
12455 
12456 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12457 			"crypto op processing failed");
12458 
12459 	auth_tag = digest_mem;
12460 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12461 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12462 			auth_tag,
12463 			tdata->gmac_tag.data,
12464 			tdata->gmac_tag.len,
12465 			"GMAC Generated auth tag not as expected");
12466 
12467 	return 0;
12468 }
12469 
12470 /* Segment size not multiple of block size (16B) */
12471 static int
12472 test_AES_GMAC_authentication_SGL_40B(void)
12473 {
12474 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12475 }
12476 
12477 static int
12478 test_AES_GMAC_authentication_SGL_80B(void)
12479 {
12480 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12481 }
12482 
12483 static int
12484 test_AES_GMAC_authentication_SGL_2048B(void)
12485 {
12486 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12487 }
12488 
12489 /* Segment size not multiple of block size (16B) */
12490 static int
12491 test_AES_GMAC_authentication_SGL_2047B(void)
12492 {
12493 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12494 }
12495 
12496 struct test_crypto_vector {
12497 	enum rte_crypto_cipher_algorithm crypto_algo;
12498 	unsigned int cipher_offset;
12499 	unsigned int cipher_len;
12500 
12501 	struct {
12502 		uint8_t data[64];
12503 		unsigned int len;
12504 	} cipher_key;
12505 
12506 	struct {
12507 		uint8_t data[64];
12508 		unsigned int len;
12509 	} iv;
12510 
12511 	struct {
12512 		const uint8_t *data;
12513 		unsigned int len;
12514 	} plaintext;
12515 
12516 	struct {
12517 		const uint8_t *data;
12518 		unsigned int len;
12519 	} ciphertext;
12520 
12521 	enum rte_crypto_auth_algorithm auth_algo;
12522 	unsigned int auth_offset;
12523 
12524 	struct {
12525 		uint8_t data[128];
12526 		unsigned int len;
12527 	} auth_key;
12528 
12529 	struct {
12530 		const uint8_t *data;
12531 		unsigned int len;
12532 	} aad;
12533 
12534 	struct {
12535 		uint8_t data[128];
12536 		unsigned int len;
12537 	} digest;
12538 };
12539 
12540 static const struct test_crypto_vector
12541 hmac_sha1_test_crypto_vector = {
12542 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12543 	.plaintext = {
12544 		.data = plaintext_hash,
12545 		.len = 512
12546 	},
12547 	.auth_key = {
12548 		.data = {
12549 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12550 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12551 			0xDE, 0xF4, 0xDE, 0xAD
12552 		},
12553 		.len = 20
12554 	},
12555 	.digest = {
12556 		.data = {
12557 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12558 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12559 			0x3F, 0x91, 0x64, 0x59
12560 		},
12561 		.len = 20
12562 	}
12563 };
12564 
12565 static const struct test_crypto_vector
12566 aes128_gmac_test_vector = {
12567 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12568 	.plaintext = {
12569 		.data = plaintext_hash,
12570 		.len = 512
12571 	},
12572 	.iv = {
12573 		.data = {
12574 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12575 			0x08, 0x09, 0x0A, 0x0B
12576 		},
12577 		.len = 12
12578 	},
12579 	.auth_key = {
12580 		.data = {
12581 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12582 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12583 		},
12584 		.len = 16
12585 	},
12586 	.digest = {
12587 		.data = {
12588 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12589 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12590 		},
12591 		.len = 16
12592 	}
12593 };
12594 
12595 static const struct test_crypto_vector
12596 aes128cbc_hmac_sha1_test_vector = {
12597 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12598 	.cipher_offset = 0,
12599 	.cipher_len = 512,
12600 	.cipher_key = {
12601 		.data = {
12602 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12603 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12604 		},
12605 		.len = 16
12606 	},
12607 	.iv = {
12608 		.data = {
12609 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12610 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12611 		},
12612 		.len = 16
12613 	},
12614 	.plaintext = {
12615 		.data = plaintext_hash,
12616 		.len = 512
12617 	},
12618 	.ciphertext = {
12619 		.data = ciphertext512_aes128cbc,
12620 		.len = 512
12621 	},
12622 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12623 	.auth_offset = 0,
12624 	.auth_key = {
12625 		.data = {
12626 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12627 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12628 			0xDE, 0xF4, 0xDE, 0xAD
12629 		},
12630 		.len = 20
12631 	},
12632 	.digest = {
12633 		.data = {
12634 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12635 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12636 			0x18, 0x8C, 0x1D, 0x32
12637 		},
12638 		.len = 20
12639 	}
12640 };
12641 
12642 static const struct test_crypto_vector
12643 aes128cbc_hmac_sha1_aad_test_vector = {
12644 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12645 	.cipher_offset = 8,
12646 	.cipher_len = 496,
12647 	.cipher_key = {
12648 		.data = {
12649 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12650 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12651 		},
12652 		.len = 16
12653 	},
12654 	.iv = {
12655 		.data = {
12656 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12657 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12658 		},
12659 		.len = 16
12660 	},
12661 	.plaintext = {
12662 		.data = plaintext_hash,
12663 		.len = 512
12664 	},
12665 	.ciphertext = {
12666 		.data = ciphertext512_aes128cbc_aad,
12667 		.len = 512
12668 	},
12669 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12670 	.auth_offset = 0,
12671 	.auth_key = {
12672 		.data = {
12673 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12674 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12675 			0xDE, 0xF4, 0xDE, 0xAD
12676 		},
12677 		.len = 20
12678 	},
12679 	.digest = {
12680 		.data = {
12681 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12682 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12683 			0x62, 0x0F, 0xFB, 0x10
12684 		},
12685 		.len = 20
12686 	}
12687 };
12688 
12689 static void
12690 data_corruption(uint8_t *data)
12691 {
12692 	data[0] += 1;
12693 }
12694 
12695 static void
12696 tag_corruption(uint8_t *data, unsigned int tag_offset)
12697 {
12698 	data[tag_offset] += 1;
12699 }
12700 
12701 static int
12702 create_auth_session(struct crypto_unittest_params *ut_params,
12703 		uint8_t dev_id,
12704 		const struct test_crypto_vector *reference,
12705 		enum rte_crypto_auth_operation auth_op)
12706 {
12707 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12708 	uint8_t auth_key[reference->auth_key.len + 1];
12709 
12710 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12711 
12712 	/* Setup Authentication Parameters */
12713 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12714 	ut_params->auth_xform.auth.op = auth_op;
12715 	ut_params->auth_xform.next = NULL;
12716 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12717 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12718 	ut_params->auth_xform.auth.key.data = auth_key;
12719 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12720 
12721 	/* Create Crypto session*/
12722 	ut_params->sess = rte_cryptodev_sym_session_create(
12723 			ts_params->session_mpool);
12724 
12725 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12726 				&ut_params->auth_xform,
12727 				ts_params->session_priv_mpool);
12728 
12729 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12730 
12731 	return 0;
12732 }
12733 
12734 static int
12735 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12736 		uint8_t dev_id,
12737 		const struct test_crypto_vector *reference,
12738 		enum rte_crypto_auth_operation auth_op,
12739 		enum rte_crypto_cipher_operation cipher_op)
12740 {
12741 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12742 	uint8_t cipher_key[reference->cipher_key.len + 1];
12743 	uint8_t auth_key[reference->auth_key.len + 1];
12744 
12745 	memcpy(cipher_key, reference->cipher_key.data,
12746 			reference->cipher_key.len);
12747 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12748 
12749 	/* Setup Authentication Parameters */
12750 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12751 	ut_params->auth_xform.auth.op = auth_op;
12752 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12753 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12754 	ut_params->auth_xform.auth.key.data = auth_key;
12755 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12756 
12757 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12758 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12759 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
12760 	} else {
12761 		ut_params->auth_xform.next = &ut_params->cipher_xform;
12762 
12763 		/* Setup Cipher Parameters */
12764 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12765 		ut_params->cipher_xform.next = NULL;
12766 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12767 		ut_params->cipher_xform.cipher.op = cipher_op;
12768 		ut_params->cipher_xform.cipher.key.data = cipher_key;
12769 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12770 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12771 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12772 	}
12773 
12774 	/* Create Crypto session*/
12775 	ut_params->sess = rte_cryptodev_sym_session_create(
12776 			ts_params->session_mpool);
12777 
12778 	rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12779 				&ut_params->auth_xform,
12780 				ts_params->session_priv_mpool);
12781 
12782 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12783 
12784 	return 0;
12785 }
12786 
12787 static int
12788 create_auth_operation(struct crypto_testsuite_params *ts_params,
12789 		struct crypto_unittest_params *ut_params,
12790 		const struct test_crypto_vector *reference,
12791 		unsigned int auth_generate)
12792 {
12793 	/* Generate Crypto op data structure */
12794 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12795 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12796 	TEST_ASSERT_NOT_NULL(ut_params->op,
12797 			"Failed to allocate pktmbuf offload");
12798 
12799 	/* Set crypto operation data parameters */
12800 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12801 
12802 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12803 
12804 	/* set crypto operation source mbuf */
12805 	sym_op->m_src = ut_params->ibuf;
12806 
12807 	/* digest */
12808 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12809 			ut_params->ibuf, reference->digest.len);
12810 
12811 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12812 			"no room to append auth tag");
12813 
12814 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12815 			ut_params->ibuf, reference->plaintext.len);
12816 
12817 	if (auth_generate)
12818 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12819 	else
12820 		memcpy(sym_op->auth.digest.data,
12821 				reference->digest.data,
12822 				reference->digest.len);
12823 
12824 	debug_hexdump(stdout, "digest:",
12825 			sym_op->auth.digest.data,
12826 			reference->digest.len);
12827 
12828 	sym_op->auth.data.length = reference->plaintext.len;
12829 	sym_op->auth.data.offset = 0;
12830 
12831 	return 0;
12832 }
12833 
12834 static int
12835 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12836 		struct crypto_unittest_params *ut_params,
12837 		const struct test_crypto_vector *reference,
12838 		unsigned int auth_generate)
12839 {
12840 	/* Generate Crypto op data structure */
12841 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12842 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12843 	TEST_ASSERT_NOT_NULL(ut_params->op,
12844 			"Failed to allocate pktmbuf offload");
12845 
12846 	/* Set crypto operation data parameters */
12847 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12848 
12849 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12850 
12851 	/* set crypto operation source mbuf */
12852 	sym_op->m_src = ut_params->ibuf;
12853 
12854 	/* digest */
12855 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12856 			ut_params->ibuf, reference->digest.len);
12857 
12858 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12859 			"no room to append auth tag");
12860 
12861 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12862 			ut_params->ibuf, reference->ciphertext.len);
12863 
12864 	if (auth_generate)
12865 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12866 	else
12867 		memcpy(sym_op->auth.digest.data,
12868 				reference->digest.data,
12869 				reference->digest.len);
12870 
12871 	debug_hexdump(stdout, "digest:",
12872 			sym_op->auth.digest.data,
12873 			reference->digest.len);
12874 
12875 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12876 			reference->iv.data, reference->iv.len);
12877 
12878 	sym_op->cipher.data.length = 0;
12879 	sym_op->cipher.data.offset = 0;
12880 
12881 	sym_op->auth.data.length = reference->plaintext.len;
12882 	sym_op->auth.data.offset = 0;
12883 
12884 	return 0;
12885 }
12886 
12887 static int
12888 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
12889 		struct crypto_unittest_params *ut_params,
12890 		const struct test_crypto_vector *reference,
12891 		unsigned int auth_generate)
12892 {
12893 	/* Generate Crypto op data structure */
12894 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12895 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12896 	TEST_ASSERT_NOT_NULL(ut_params->op,
12897 			"Failed to allocate pktmbuf offload");
12898 
12899 	/* Set crypto operation data parameters */
12900 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12901 
12902 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12903 
12904 	/* set crypto operation source mbuf */
12905 	sym_op->m_src = ut_params->ibuf;
12906 
12907 	/* digest */
12908 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12909 			ut_params->ibuf, reference->digest.len);
12910 
12911 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12912 			"no room to append auth tag");
12913 
12914 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12915 			ut_params->ibuf, reference->ciphertext.len);
12916 
12917 	if (auth_generate)
12918 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12919 	else
12920 		memcpy(sym_op->auth.digest.data,
12921 				reference->digest.data,
12922 				reference->digest.len);
12923 
12924 	debug_hexdump(stdout, "digest:",
12925 			sym_op->auth.digest.data,
12926 			reference->digest.len);
12927 
12928 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
12929 			reference->iv.data, reference->iv.len);
12930 
12931 	sym_op->cipher.data.length = reference->cipher_len;
12932 	sym_op->cipher.data.offset = reference->cipher_offset;
12933 
12934 	sym_op->auth.data.length = reference->plaintext.len;
12935 	sym_op->auth.data.offset = reference->auth_offset;
12936 
12937 	return 0;
12938 }
12939 
12940 static int
12941 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12942 		struct crypto_unittest_params *ut_params,
12943 		const struct test_crypto_vector *reference)
12944 {
12945 	return create_auth_operation(ts_params, ut_params, reference, 0);
12946 }
12947 
12948 static int
12949 create_auth_verify_GMAC_operation(
12950 		struct crypto_testsuite_params *ts_params,
12951 		struct crypto_unittest_params *ut_params,
12952 		const struct test_crypto_vector *reference)
12953 {
12954 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
12955 }
12956 
12957 static int
12958 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
12959 		struct crypto_unittest_params *ut_params,
12960 		const struct test_crypto_vector *reference)
12961 {
12962 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
12963 }
12964 
12965 static int
12966 test_authentication_verify_fail_when_data_corruption(
12967 		struct crypto_testsuite_params *ts_params,
12968 		struct crypto_unittest_params *ut_params,
12969 		const struct test_crypto_vector *reference,
12970 		unsigned int data_corrupted)
12971 {
12972 	int retval;
12973 
12974 	uint8_t *plaintext;
12975 	struct rte_cryptodev_info dev_info;
12976 
12977 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12978 	uint64_t feat_flags = dev_info.feature_flags;
12979 
12980 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12981 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12982 		printf("Device doesn't support RAW data-path APIs.\n");
12983 		return TEST_SKIPPED;
12984 	}
12985 
12986 	/* Verify the capabilities */
12987 	struct rte_cryptodev_sym_capability_idx cap_idx;
12988 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12989 	cap_idx.algo.auth = reference->auth_algo;
12990 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12991 			&cap_idx) == NULL)
12992 		return TEST_SKIPPED;
12993 
12994 
12995 	/* Create session */
12996 	retval = create_auth_session(ut_params,
12997 			ts_params->valid_devs[0],
12998 			reference,
12999 			RTE_CRYPTO_AUTH_OP_VERIFY);
13000 	if (retval < 0)
13001 		return retval;
13002 
13003 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13004 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13005 			"Failed to allocate input buffer in mempool");
13006 
13007 	/* clear mbuf payload */
13008 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13009 			rte_pktmbuf_tailroom(ut_params->ibuf));
13010 
13011 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13012 			reference->plaintext.len);
13013 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13014 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13015 
13016 	debug_hexdump(stdout, "plaintext:", plaintext,
13017 		reference->plaintext.len);
13018 
13019 	/* Create operation */
13020 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
13021 
13022 	if (retval < 0)
13023 		return retval;
13024 
13025 	if (data_corrupted)
13026 		data_corruption(plaintext);
13027 	else
13028 		tag_corruption(plaintext, reference->plaintext.len);
13029 
13030 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13031 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13032 			ut_params->op);
13033 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13034 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13035 			"authentication not failed");
13036 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13037 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13038 				ut_params->op, 0, 1, 0, 0);
13039 	else {
13040 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13041 			ut_params->op);
13042 	}
13043 	if (ut_params->op == NULL)
13044 		return 0;
13045 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13046 		return 0;
13047 
13048 	return -1;
13049 }
13050 
13051 static int
13052 test_authentication_verify_GMAC_fail_when_corruption(
13053 		struct crypto_testsuite_params *ts_params,
13054 		struct crypto_unittest_params *ut_params,
13055 		const struct test_crypto_vector *reference,
13056 		unsigned int data_corrupted)
13057 {
13058 	int retval;
13059 	uint8_t *plaintext;
13060 	struct rte_cryptodev_info dev_info;
13061 
13062 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13063 	uint64_t feat_flags = dev_info.feature_flags;
13064 
13065 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13066 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13067 		printf("Device doesn't support RAW data-path APIs.\n");
13068 		return TEST_SKIPPED;
13069 	}
13070 
13071 	/* Verify the capabilities */
13072 	struct rte_cryptodev_sym_capability_idx cap_idx;
13073 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13074 	cap_idx.algo.auth = reference->auth_algo;
13075 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13076 			&cap_idx) == NULL)
13077 		return TEST_SKIPPED;
13078 
13079 	/* Create session */
13080 	retval = create_auth_cipher_session(ut_params,
13081 			ts_params->valid_devs[0],
13082 			reference,
13083 			RTE_CRYPTO_AUTH_OP_VERIFY,
13084 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13085 	if (retval < 0)
13086 		return retval;
13087 
13088 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13089 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13090 			"Failed to allocate input buffer in mempool");
13091 
13092 	/* clear mbuf payload */
13093 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13094 			rte_pktmbuf_tailroom(ut_params->ibuf));
13095 
13096 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13097 			reference->plaintext.len);
13098 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13099 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13100 
13101 	debug_hexdump(stdout, "plaintext:", plaintext,
13102 		reference->plaintext.len);
13103 
13104 	/* Create operation */
13105 	retval = create_auth_verify_GMAC_operation(ts_params,
13106 			ut_params,
13107 			reference);
13108 
13109 	if (retval < 0)
13110 		return retval;
13111 
13112 	if (data_corrupted)
13113 		data_corruption(plaintext);
13114 	else
13115 		tag_corruption(plaintext, reference->aad.len);
13116 
13117 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13118 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13119 			ut_params->op);
13120 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13121 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13122 			"authentication not failed");
13123 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13124 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13125 				ut_params->op, 0, 1, 0, 0);
13126 	else {
13127 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13128 			ut_params->op);
13129 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13130 	}
13131 
13132 	return 0;
13133 }
13134 
13135 static int
13136 test_authenticated_decryption_fail_when_corruption(
13137 		struct crypto_testsuite_params *ts_params,
13138 		struct crypto_unittest_params *ut_params,
13139 		const struct test_crypto_vector *reference,
13140 		unsigned int data_corrupted)
13141 {
13142 	int retval;
13143 
13144 	uint8_t *ciphertext;
13145 	struct rte_cryptodev_info dev_info;
13146 
13147 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13148 	uint64_t feat_flags = dev_info.feature_flags;
13149 
13150 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13151 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13152 		printf("Device doesn't support RAW data-path APIs.\n");
13153 		return TEST_SKIPPED;
13154 	}
13155 
13156 	/* Verify the capabilities */
13157 	struct rte_cryptodev_sym_capability_idx cap_idx;
13158 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13159 	cap_idx.algo.auth = reference->auth_algo;
13160 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13161 			&cap_idx) == NULL)
13162 		return TEST_SKIPPED;
13163 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13164 	cap_idx.algo.cipher = reference->crypto_algo;
13165 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13166 			&cap_idx) == NULL)
13167 		return TEST_SKIPPED;
13168 
13169 	/* Create session */
13170 	retval = create_auth_cipher_session(ut_params,
13171 			ts_params->valid_devs[0],
13172 			reference,
13173 			RTE_CRYPTO_AUTH_OP_VERIFY,
13174 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13175 	if (retval < 0)
13176 		return retval;
13177 
13178 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13179 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13180 			"Failed to allocate input buffer in mempool");
13181 
13182 	/* clear mbuf payload */
13183 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13184 			rte_pktmbuf_tailroom(ut_params->ibuf));
13185 
13186 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13187 			reference->ciphertext.len);
13188 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13189 	memcpy(ciphertext, reference->ciphertext.data,
13190 			reference->ciphertext.len);
13191 
13192 	/* Create operation */
13193 	retval = create_cipher_auth_verify_operation(ts_params,
13194 			ut_params,
13195 			reference);
13196 
13197 	if (retval < 0)
13198 		return retval;
13199 
13200 	if (data_corrupted)
13201 		data_corruption(ciphertext);
13202 	else
13203 		tag_corruption(ciphertext, reference->ciphertext.len);
13204 
13205 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13206 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13207 			ut_params->op);
13208 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13209 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13210 			"authentication not failed");
13211 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13212 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13213 				ut_params->op, 1, 1, 0, 0);
13214 	else {
13215 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13216 			ut_params->op);
13217 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13218 	}
13219 
13220 	return 0;
13221 }
13222 
13223 static int
13224 test_authenticated_encrypt_with_esn(
13225 		struct crypto_testsuite_params *ts_params,
13226 		struct crypto_unittest_params *ut_params,
13227 		const struct test_crypto_vector *reference)
13228 {
13229 	int retval;
13230 
13231 	uint8_t *authciphertext, *plaintext, *auth_tag;
13232 	uint16_t plaintext_pad_len;
13233 	uint8_t cipher_key[reference->cipher_key.len + 1];
13234 	uint8_t auth_key[reference->auth_key.len + 1];
13235 	struct rte_cryptodev_info dev_info;
13236 
13237 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13238 	uint64_t feat_flags = dev_info.feature_flags;
13239 
13240 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13241 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13242 		printf("Device doesn't support RAW data-path APIs.\n");
13243 		return TEST_SKIPPED;
13244 	}
13245 
13246 	/* Verify the capabilities */
13247 	struct rte_cryptodev_sym_capability_idx cap_idx;
13248 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13249 	cap_idx.algo.auth = reference->auth_algo;
13250 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13251 			&cap_idx) == NULL)
13252 		return TEST_SKIPPED;
13253 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13254 	cap_idx.algo.cipher = reference->crypto_algo;
13255 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13256 			&cap_idx) == NULL)
13257 		return TEST_SKIPPED;
13258 
13259 	/* Create session */
13260 	memcpy(cipher_key, reference->cipher_key.data,
13261 			reference->cipher_key.len);
13262 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13263 
13264 	/* Setup Cipher Parameters */
13265 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13266 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13267 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13268 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13269 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13270 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13271 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13272 
13273 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13274 
13275 	/* Setup Authentication Parameters */
13276 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13277 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13278 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13279 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13280 	ut_params->auth_xform.auth.key.data = auth_key;
13281 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13282 	ut_params->auth_xform.next = NULL;
13283 
13284 	/* Create Crypto session*/
13285 	ut_params->sess = rte_cryptodev_sym_session_create(
13286 			ts_params->session_mpool);
13287 
13288 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13289 				ut_params->sess,
13290 				&ut_params->cipher_xform,
13291 				ts_params->session_priv_mpool);
13292 
13293 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13294 
13295 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13296 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13297 			"Failed to allocate input buffer in mempool");
13298 
13299 	/* clear mbuf payload */
13300 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13301 			rte_pktmbuf_tailroom(ut_params->ibuf));
13302 
13303 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13304 			reference->plaintext.len);
13305 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13306 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13307 
13308 	/* Create operation */
13309 	retval = create_cipher_auth_operation(ts_params,
13310 			ut_params,
13311 			reference, 0);
13312 
13313 	if (retval < 0)
13314 		return retval;
13315 
13316 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13317 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13318 			ut_params->op);
13319 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13320 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13321 				ut_params->op, 1, 1, 0, 0);
13322 	else
13323 		ut_params->op = process_crypto_request(
13324 			ts_params->valid_devs[0], ut_params->op);
13325 
13326 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13327 
13328 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13329 			"crypto op processing failed");
13330 
13331 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13332 
13333 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13334 			ut_params->op->sym->auth.data.offset);
13335 	auth_tag = authciphertext + plaintext_pad_len;
13336 	debug_hexdump(stdout, "ciphertext:", authciphertext,
13337 			reference->ciphertext.len);
13338 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13339 
13340 	/* Validate obuf */
13341 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13342 			authciphertext,
13343 			reference->ciphertext.data,
13344 			reference->ciphertext.len,
13345 			"Ciphertext data not as expected");
13346 
13347 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13348 			auth_tag,
13349 			reference->digest.data,
13350 			reference->digest.len,
13351 			"Generated digest not as expected");
13352 
13353 	return TEST_SUCCESS;
13354 
13355 }
13356 
13357 static int
13358 test_authenticated_decrypt_with_esn(
13359 		struct crypto_testsuite_params *ts_params,
13360 		struct crypto_unittest_params *ut_params,
13361 		const struct test_crypto_vector *reference)
13362 {
13363 	int retval;
13364 
13365 	uint8_t *ciphertext;
13366 	uint8_t cipher_key[reference->cipher_key.len + 1];
13367 	uint8_t auth_key[reference->auth_key.len + 1];
13368 	struct rte_cryptodev_info dev_info;
13369 
13370 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13371 	uint64_t feat_flags = dev_info.feature_flags;
13372 
13373 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13374 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13375 		printf("Device doesn't support RAW data-path APIs.\n");
13376 		return TEST_SKIPPED;
13377 	}
13378 
13379 	/* Verify the capabilities */
13380 	struct rte_cryptodev_sym_capability_idx cap_idx;
13381 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13382 	cap_idx.algo.auth = reference->auth_algo;
13383 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13384 			&cap_idx) == NULL)
13385 		return TEST_SKIPPED;
13386 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13387 	cap_idx.algo.cipher = reference->crypto_algo;
13388 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13389 			&cap_idx) == NULL)
13390 		return TEST_SKIPPED;
13391 
13392 	/* Create session */
13393 	memcpy(cipher_key, reference->cipher_key.data,
13394 			reference->cipher_key.len);
13395 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13396 
13397 	/* Setup Authentication Parameters */
13398 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13399 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13400 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13401 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13402 	ut_params->auth_xform.auth.key.data = auth_key;
13403 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13404 	ut_params->auth_xform.next = &ut_params->cipher_xform;
13405 
13406 	/* Setup Cipher Parameters */
13407 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13408 	ut_params->cipher_xform.next = NULL;
13409 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13410 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13411 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13412 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13413 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13414 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13415 
13416 	/* Create Crypto session*/
13417 	ut_params->sess = rte_cryptodev_sym_session_create(
13418 			ts_params->session_mpool);
13419 
13420 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13421 				ut_params->sess,
13422 				&ut_params->auth_xform,
13423 				ts_params->session_priv_mpool);
13424 
13425 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13426 
13427 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13428 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13429 			"Failed to allocate input buffer in mempool");
13430 
13431 	/* clear mbuf payload */
13432 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13433 			rte_pktmbuf_tailroom(ut_params->ibuf));
13434 
13435 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13436 			reference->ciphertext.len);
13437 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13438 	memcpy(ciphertext, reference->ciphertext.data,
13439 			reference->ciphertext.len);
13440 
13441 	/* Create operation */
13442 	retval = create_cipher_auth_verify_operation(ts_params,
13443 			ut_params,
13444 			reference);
13445 
13446 	if (retval < 0)
13447 		return retval;
13448 
13449 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13450 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13451 			ut_params->op);
13452 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13453 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13454 				ut_params->op, 1, 1, 0, 0);
13455 	else
13456 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13457 			ut_params->op);
13458 
13459 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13460 	TEST_ASSERT_EQUAL(ut_params->op->status,
13461 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13462 			"crypto op processing passed");
13463 
13464 	ut_params->obuf = ut_params->op->sym->m_src;
13465 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13466 
13467 	return 0;
13468 }
13469 
13470 static int
13471 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13472 		const struct aead_test_data *tdata,
13473 		void *digest_mem, uint64_t digest_phys)
13474 {
13475 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13476 	struct crypto_unittest_params *ut_params = &unittest_params;
13477 
13478 	const unsigned int auth_tag_len = tdata->auth_tag.len;
13479 	const unsigned int iv_len = tdata->iv.len;
13480 	unsigned int aad_len = tdata->aad.len;
13481 	unsigned int aad_len_pad = 0;
13482 
13483 	/* Generate Crypto op data structure */
13484 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13485 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13486 	TEST_ASSERT_NOT_NULL(ut_params->op,
13487 		"Failed to allocate symmetric crypto operation struct");
13488 
13489 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13490 
13491 	sym_op->aead.digest.data = digest_mem;
13492 
13493 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13494 			"no room to append digest");
13495 
13496 	sym_op->aead.digest.phys_addr = digest_phys;
13497 
13498 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13499 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13500 				auth_tag_len);
13501 		debug_hexdump(stdout, "digest:",
13502 				sym_op->aead.digest.data,
13503 				auth_tag_len);
13504 	}
13505 
13506 	/* Append aad data */
13507 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13508 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13509 				uint8_t *, IV_OFFSET);
13510 
13511 		/* Copy IV 1 byte after the IV pointer, according to the API */
13512 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13513 
13514 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13515 
13516 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13517 				ut_params->ibuf, aad_len);
13518 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13519 				"no room to prepend aad");
13520 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13521 				ut_params->ibuf);
13522 
13523 		memset(sym_op->aead.aad.data, 0, aad_len);
13524 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
13525 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13526 
13527 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13528 		debug_hexdump(stdout, "aad:",
13529 				sym_op->aead.aad.data, aad_len);
13530 	} else {
13531 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13532 				uint8_t *, IV_OFFSET);
13533 
13534 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13535 
13536 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13537 
13538 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13539 				ut_params->ibuf, aad_len_pad);
13540 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13541 				"no room to prepend aad");
13542 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13543 				ut_params->ibuf);
13544 
13545 		memset(sym_op->aead.aad.data, 0, aad_len);
13546 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13547 
13548 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13549 		debug_hexdump(stdout, "aad:",
13550 				sym_op->aead.aad.data, aad_len);
13551 	}
13552 
13553 	sym_op->aead.data.length = tdata->plaintext.len;
13554 	sym_op->aead.data.offset = aad_len_pad;
13555 
13556 	return 0;
13557 }
13558 
13559 #define SGL_MAX_NO	16
13560 
13561 static int
13562 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13563 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13564 {
13565 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13566 	struct crypto_unittest_params *ut_params = &unittest_params;
13567 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13568 	int retval;
13569 	int to_trn = 0;
13570 	int to_trn_tbl[SGL_MAX_NO];
13571 	int segs = 1;
13572 	unsigned int trn_data = 0;
13573 	uint8_t *plaintext, *ciphertext, *auth_tag;
13574 	struct rte_cryptodev_info dev_info;
13575 
13576 	/* Verify the capabilities */
13577 	struct rte_cryptodev_sym_capability_idx cap_idx;
13578 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13579 	cap_idx.algo.aead = tdata->algo;
13580 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13581 			&cap_idx) == NULL)
13582 		return TEST_SKIPPED;
13583 
13584 	/* OOP not supported with CPU crypto */
13585 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13586 		return TEST_SKIPPED;
13587 
13588 	/* Detailed check for the particular SGL support flag */
13589 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13590 	if (!oop) {
13591 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13592 		if (sgl_in && (!(dev_info.feature_flags &
13593 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13594 			return TEST_SKIPPED;
13595 
13596 		uint64_t feat_flags = dev_info.feature_flags;
13597 
13598 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13599 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13600 			printf("Device doesn't support RAW data-path APIs.\n");
13601 			return TEST_SKIPPED;
13602 		}
13603 	} else {
13604 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13605 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13606 				tdata->plaintext.len;
13607 		/* Raw data path API does not support OOP */
13608 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13609 			return TEST_SKIPPED;
13610 		if (sgl_in && !sgl_out) {
13611 			if (!(dev_info.feature_flags &
13612 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13613 				return TEST_SKIPPED;
13614 		} else if (!sgl_in && sgl_out) {
13615 			if (!(dev_info.feature_flags &
13616 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13617 				return TEST_SKIPPED;
13618 		} else if (sgl_in && sgl_out) {
13619 			if (!(dev_info.feature_flags &
13620 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13621 				return TEST_SKIPPED;
13622 		}
13623 	}
13624 
13625 	if (fragsz > tdata->plaintext.len)
13626 		fragsz = tdata->plaintext.len;
13627 
13628 	uint16_t plaintext_len = fragsz;
13629 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13630 
13631 	if (fragsz_oop > tdata->plaintext.len)
13632 		frag_size_oop = tdata->plaintext.len;
13633 
13634 	int ecx = 0;
13635 	void *digest_mem = NULL;
13636 
13637 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13638 
13639 	if (tdata->plaintext.len % fragsz != 0) {
13640 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13641 			return 1;
13642 	}	else {
13643 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13644 			return 1;
13645 	}
13646 
13647 	/*
13648 	 * For out-op-place we need to alloc another mbuf
13649 	 */
13650 	if (oop) {
13651 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13652 		rte_pktmbuf_append(ut_params->obuf,
13653 				frag_size_oop + prepend_len);
13654 		buf_oop = ut_params->obuf;
13655 	}
13656 
13657 	/* Create AEAD session */
13658 	retval = create_aead_session(ts_params->valid_devs[0],
13659 			tdata->algo,
13660 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13661 			tdata->key.data, tdata->key.len,
13662 			tdata->aad.len, tdata->auth_tag.len,
13663 			tdata->iv.len);
13664 	if (retval < 0)
13665 		return retval;
13666 
13667 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13668 
13669 	/* clear mbuf payload */
13670 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13671 			rte_pktmbuf_tailroom(ut_params->ibuf));
13672 
13673 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13674 			plaintext_len);
13675 
13676 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13677 
13678 	trn_data += plaintext_len;
13679 
13680 	buf = ut_params->ibuf;
13681 
13682 	/*
13683 	 * Loop until no more fragments
13684 	 */
13685 
13686 	while (trn_data < tdata->plaintext.len) {
13687 		++segs;
13688 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13689 				(tdata->plaintext.len - trn_data) : fragsz;
13690 
13691 		to_trn_tbl[ecx++] = to_trn;
13692 
13693 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13694 		buf = buf->next;
13695 
13696 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13697 				rte_pktmbuf_tailroom(buf));
13698 
13699 		/* OOP */
13700 		if (oop && !fragsz_oop) {
13701 			buf_last_oop = buf_oop->next =
13702 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13703 			buf_oop = buf_oop->next;
13704 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13705 					0, rte_pktmbuf_tailroom(buf_oop));
13706 			rte_pktmbuf_append(buf_oop, to_trn);
13707 		}
13708 
13709 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13710 				to_trn);
13711 
13712 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13713 				to_trn);
13714 		trn_data += to_trn;
13715 		if (trn_data  == tdata->plaintext.len) {
13716 			if (oop) {
13717 				if (!fragsz_oop)
13718 					digest_mem = rte_pktmbuf_append(buf_oop,
13719 						tdata->auth_tag.len);
13720 			} else
13721 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13722 					tdata->auth_tag.len);
13723 		}
13724 	}
13725 
13726 	uint64_t digest_phys = 0;
13727 
13728 	ut_params->ibuf->nb_segs = segs;
13729 
13730 	segs = 1;
13731 	if (fragsz_oop && oop) {
13732 		to_trn = 0;
13733 		ecx = 0;
13734 
13735 		if (frag_size_oop == tdata->plaintext.len) {
13736 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
13737 				tdata->auth_tag.len);
13738 
13739 			digest_phys = rte_pktmbuf_iova_offset(
13740 					ut_params->obuf,
13741 					tdata->plaintext.len + prepend_len);
13742 		}
13743 
13744 		trn_data = frag_size_oop;
13745 		while (trn_data < tdata->plaintext.len) {
13746 			++segs;
13747 			to_trn =
13748 				(tdata->plaintext.len - trn_data <
13749 						frag_size_oop) ?
13750 				(tdata->plaintext.len - trn_data) :
13751 						frag_size_oop;
13752 
13753 			to_trn_tbl[ecx++] = to_trn;
13754 
13755 			buf_last_oop = buf_oop->next =
13756 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13757 			buf_oop = buf_oop->next;
13758 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13759 					0, rte_pktmbuf_tailroom(buf_oop));
13760 			rte_pktmbuf_append(buf_oop, to_trn);
13761 
13762 			trn_data += to_trn;
13763 
13764 			if (trn_data  == tdata->plaintext.len) {
13765 				digest_mem = rte_pktmbuf_append(buf_oop,
13766 					tdata->auth_tag.len);
13767 			}
13768 		}
13769 
13770 		ut_params->obuf->nb_segs = segs;
13771 	}
13772 
13773 	/*
13774 	 * Place digest at the end of the last buffer
13775 	 */
13776 	if (!digest_phys)
13777 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13778 	if (oop && buf_last_oop)
13779 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13780 
13781 	if (!digest_mem && !oop) {
13782 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13783 				+ tdata->auth_tag.len);
13784 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13785 				tdata->plaintext.len);
13786 	}
13787 
13788 	/* Create AEAD operation */
13789 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13790 			tdata, digest_mem, digest_phys);
13791 
13792 	if (retval < 0)
13793 		return retval;
13794 
13795 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13796 
13797 	ut_params->op->sym->m_src = ut_params->ibuf;
13798 	if (oop)
13799 		ut_params->op->sym->m_dst = ut_params->obuf;
13800 
13801 	/* Process crypto operation */
13802 	if (oop == IN_PLACE &&
13803 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13804 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13805 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13806 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13807 				ut_params->op, 0, 0, 0, 0);
13808 	else
13809 		TEST_ASSERT_NOT_NULL(
13810 			process_crypto_request(ts_params->valid_devs[0],
13811 			ut_params->op), "failed to process sym crypto op");
13812 
13813 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13814 			"crypto op processing failed");
13815 
13816 
13817 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13818 			uint8_t *, prepend_len);
13819 	if (oop) {
13820 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13821 				uint8_t *, prepend_len);
13822 	}
13823 
13824 	if (fragsz_oop)
13825 		fragsz = fragsz_oop;
13826 
13827 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13828 			ciphertext,
13829 			tdata->ciphertext.data,
13830 			fragsz,
13831 			"Ciphertext data not as expected");
13832 
13833 	buf = ut_params->op->sym->m_src->next;
13834 	if (oop)
13835 		buf = ut_params->op->sym->m_dst->next;
13836 
13837 	unsigned int off = fragsz;
13838 
13839 	ecx = 0;
13840 	while (buf) {
13841 		ciphertext = rte_pktmbuf_mtod(buf,
13842 				uint8_t *);
13843 
13844 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
13845 				ciphertext,
13846 				tdata->ciphertext.data + off,
13847 				to_trn_tbl[ecx],
13848 				"Ciphertext data not as expected");
13849 
13850 		off += to_trn_tbl[ecx++];
13851 		buf = buf->next;
13852 	}
13853 
13854 	auth_tag = digest_mem;
13855 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13856 			auth_tag,
13857 			tdata->auth_tag.data,
13858 			tdata->auth_tag.len,
13859 			"Generated auth tag not as expected");
13860 
13861 	return 0;
13862 }
13863 
13864 static int
13865 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
13866 {
13867 	return test_authenticated_encryption_SGL(
13868 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
13869 }
13870 
13871 static int
13872 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
13873 {
13874 	return test_authenticated_encryption_SGL(
13875 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
13876 }
13877 
13878 static int
13879 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
13880 {
13881 	return test_authenticated_encryption_SGL(
13882 			&gcm_test_case_8, OUT_OF_PLACE, 400,
13883 			gcm_test_case_8.plaintext.len);
13884 }
13885 
13886 static int
13887 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
13888 {
13889 	/* This test is not for OPENSSL PMD */
13890 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
13891 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
13892 		return TEST_SKIPPED;
13893 
13894 	return test_authenticated_encryption_SGL(
13895 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
13896 }
13897 
13898 static int
13899 test_authentication_verify_fail_when_data_corrupted(
13900 		struct crypto_testsuite_params *ts_params,
13901 		struct crypto_unittest_params *ut_params,
13902 		const struct test_crypto_vector *reference)
13903 {
13904 	return test_authentication_verify_fail_when_data_corruption(
13905 			ts_params, ut_params, reference, 1);
13906 }
13907 
13908 static int
13909 test_authentication_verify_fail_when_tag_corrupted(
13910 		struct crypto_testsuite_params *ts_params,
13911 		struct crypto_unittest_params *ut_params,
13912 		const struct test_crypto_vector *reference)
13913 {
13914 	return test_authentication_verify_fail_when_data_corruption(
13915 			ts_params, ut_params, reference, 0);
13916 }
13917 
13918 static int
13919 test_authentication_verify_GMAC_fail_when_data_corrupted(
13920 		struct crypto_testsuite_params *ts_params,
13921 		struct crypto_unittest_params *ut_params,
13922 		const struct test_crypto_vector *reference)
13923 {
13924 	return test_authentication_verify_GMAC_fail_when_corruption(
13925 			ts_params, ut_params, reference, 1);
13926 }
13927 
13928 static int
13929 test_authentication_verify_GMAC_fail_when_tag_corrupted(
13930 		struct crypto_testsuite_params *ts_params,
13931 		struct crypto_unittest_params *ut_params,
13932 		const struct test_crypto_vector *reference)
13933 {
13934 	return test_authentication_verify_GMAC_fail_when_corruption(
13935 			ts_params, ut_params, reference, 0);
13936 }
13937 
13938 static int
13939 test_authenticated_decryption_fail_when_data_corrupted(
13940 		struct crypto_testsuite_params *ts_params,
13941 		struct crypto_unittest_params *ut_params,
13942 		const struct test_crypto_vector *reference)
13943 {
13944 	return test_authenticated_decryption_fail_when_corruption(
13945 			ts_params, ut_params, reference, 1);
13946 }
13947 
13948 static int
13949 test_authenticated_decryption_fail_when_tag_corrupted(
13950 		struct crypto_testsuite_params *ts_params,
13951 		struct crypto_unittest_params *ut_params,
13952 		const struct test_crypto_vector *reference)
13953 {
13954 	return test_authenticated_decryption_fail_when_corruption(
13955 			ts_params, ut_params, reference, 0);
13956 }
13957 
13958 static int
13959 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
13960 {
13961 	return test_authentication_verify_fail_when_data_corrupted(
13962 			&testsuite_params, &unittest_params,
13963 			&hmac_sha1_test_crypto_vector);
13964 }
13965 
13966 static int
13967 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
13968 {
13969 	return test_authentication_verify_fail_when_tag_corrupted(
13970 			&testsuite_params, &unittest_params,
13971 			&hmac_sha1_test_crypto_vector);
13972 }
13973 
13974 static int
13975 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
13976 {
13977 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
13978 			&testsuite_params, &unittest_params,
13979 			&aes128_gmac_test_vector);
13980 }
13981 
13982 static int
13983 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
13984 {
13985 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
13986 			&testsuite_params, &unittest_params,
13987 			&aes128_gmac_test_vector);
13988 }
13989 
13990 static int
13991 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
13992 {
13993 	return test_authenticated_decryption_fail_when_data_corrupted(
13994 			&testsuite_params,
13995 			&unittest_params,
13996 			&aes128cbc_hmac_sha1_test_vector);
13997 }
13998 
13999 static int
14000 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14001 {
14002 	return test_authenticated_decryption_fail_when_tag_corrupted(
14003 			&testsuite_params,
14004 			&unittest_params,
14005 			&aes128cbc_hmac_sha1_test_vector);
14006 }
14007 
14008 static int
14009 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14010 {
14011 	return test_authenticated_encrypt_with_esn(
14012 			&testsuite_params,
14013 			&unittest_params,
14014 			&aes128cbc_hmac_sha1_aad_test_vector);
14015 }
14016 
14017 static int
14018 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14019 {
14020 	return test_authenticated_decrypt_with_esn(
14021 			&testsuite_params,
14022 			&unittest_params,
14023 			&aes128cbc_hmac_sha1_aad_test_vector);
14024 }
14025 
14026 static int
14027 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14028 {
14029 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14030 }
14031 
14032 static int
14033 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14034 {
14035 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14036 }
14037 
14038 #ifdef RTE_CRYPTO_SCHEDULER
14039 
14040 /* global AESNI worker IDs for the scheduler test */
14041 uint8_t aesni_ids[2];
14042 
14043 static int
14044 scheduler_testsuite_setup(void)
14045 {
14046 	uint32_t i = 0;
14047 	int32_t nb_devs, ret;
14048 	char vdev_args[VDEV_ARGS_SIZE] = {""};
14049 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14050 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
14051 	uint16_t worker_core_count = 0;
14052 	uint16_t socket_id = 0;
14053 
14054 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14055 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14056 
14057 		/* Identify the Worker Cores
14058 		 * Use 2 worker cores for the device args
14059 		 */
14060 		RTE_LCORE_FOREACH_WORKER(i) {
14061 			if (worker_core_count > 1)
14062 				break;
14063 			snprintf(vdev_args, sizeof(vdev_args),
14064 					"%s%d", temp_str, i);
14065 			strcpy(temp_str, vdev_args);
14066 			strlcat(temp_str, ";", sizeof(temp_str));
14067 			worker_core_count++;
14068 			socket_id = rte_lcore_to_socket_id(i);
14069 		}
14070 		if (worker_core_count != 2) {
14071 			RTE_LOG(ERR, USER1,
14072 				"Cryptodev scheduler test require at least "
14073 				"two worker cores to run. "
14074 				"Please use the correct coremask.\n");
14075 			return TEST_FAILED;
14076 		}
14077 		strcpy(temp_str, vdev_args);
14078 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14079 				temp_str, socket_id);
14080 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14081 		nb_devs = rte_cryptodev_device_count_by_driver(
14082 				rte_cryptodev_driver_id_get(
14083 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14084 		if (nb_devs < 1) {
14085 			ret = rte_vdev_init(
14086 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14087 					vdev_args);
14088 			TEST_ASSERT(ret == 0,
14089 				"Failed to create instance %u of pmd : %s",
14090 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14091 		}
14092 	}
14093 	return testsuite_setup();
14094 }
14095 
14096 static int
14097 test_scheduler_attach_worker_op(void)
14098 {
14099 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14100 	uint8_t sched_id = ts_params->valid_devs[0];
14101 	uint32_t i, nb_devs_attached = 0;
14102 	int ret;
14103 	char vdev_name[32];
14104 	unsigned int count = rte_cryptodev_count();
14105 
14106 	/* create 2 AESNI_MB vdevs on top of existing devices */
14107 	for (i = count; i < count + 2; i++) {
14108 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14109 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14110 				i);
14111 		ret = rte_vdev_init(vdev_name, NULL);
14112 
14113 		TEST_ASSERT(ret == 0,
14114 			"Failed to create instance %u of"
14115 			" pmd : %s",
14116 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14117 
14118 		if (ret < 0) {
14119 			RTE_LOG(ERR, USER1,
14120 				"Failed to create 2 AESNI MB PMDs.\n");
14121 			return TEST_SKIPPED;
14122 		}
14123 	}
14124 
14125 	/* attach 2 AESNI_MB cdevs */
14126 	for (i = count; i < count + 2; i++) {
14127 		struct rte_cryptodev_info info;
14128 		unsigned int session_size;
14129 
14130 		rte_cryptodev_info_get(i, &info);
14131 		if (info.driver_id != rte_cryptodev_driver_id_get(
14132 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14133 			continue;
14134 
14135 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14136 		/*
14137 		 * Create the session mempool again, since now there are new devices
14138 		 * to use the mempool.
14139 		 */
14140 		if (ts_params->session_mpool) {
14141 			rte_mempool_free(ts_params->session_mpool);
14142 			ts_params->session_mpool = NULL;
14143 		}
14144 		if (ts_params->session_priv_mpool) {
14145 			rte_mempool_free(ts_params->session_priv_mpool);
14146 			ts_params->session_priv_mpool = NULL;
14147 		}
14148 
14149 		if (info.sym.max_nb_sessions != 0 &&
14150 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14151 			RTE_LOG(ERR, USER1,
14152 					"Device does not support "
14153 					"at least %u sessions\n",
14154 					MAX_NB_SESSIONS);
14155 			return TEST_FAILED;
14156 		}
14157 		/*
14158 		 * Create mempool with maximum number of sessions,
14159 		 * to include the session headers
14160 		 */
14161 		if (ts_params->session_mpool == NULL) {
14162 			ts_params->session_mpool =
14163 				rte_cryptodev_sym_session_pool_create(
14164 						"test_sess_mp",
14165 						MAX_NB_SESSIONS, 0, 0, 0,
14166 						SOCKET_ID_ANY);
14167 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14168 					"session mempool allocation failed");
14169 		}
14170 
14171 		/*
14172 		 * Create mempool with maximum number of sessions,
14173 		 * to include device specific session private data
14174 		 */
14175 		if (ts_params->session_priv_mpool == NULL) {
14176 			ts_params->session_priv_mpool = rte_mempool_create(
14177 					"test_sess_mp_priv",
14178 					MAX_NB_SESSIONS,
14179 					session_size,
14180 					0, 0, NULL, NULL, NULL,
14181 					NULL, SOCKET_ID_ANY,
14182 					0);
14183 
14184 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14185 					"session mempool allocation failed");
14186 		}
14187 
14188 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
14189 		ts_params->qp_conf.mp_session_private =
14190 				ts_params->session_priv_mpool;
14191 
14192 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14193 				(uint8_t)i);
14194 
14195 		TEST_ASSERT(ret == 0,
14196 			"Failed to attach device %u of pmd : %s", i,
14197 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14198 
14199 		aesni_ids[nb_devs_attached] = (uint8_t)i;
14200 
14201 		nb_devs_attached++;
14202 	}
14203 
14204 	return 0;
14205 }
14206 
14207 static int
14208 test_scheduler_detach_worker_op(void)
14209 {
14210 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14211 	uint8_t sched_id = ts_params->valid_devs[0];
14212 	uint32_t i;
14213 	int ret;
14214 
14215 	for (i = 0; i < 2; i++) {
14216 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14217 				aesni_ids[i]);
14218 		TEST_ASSERT(ret == 0,
14219 			"Failed to detach device %u", aesni_ids[i]);
14220 	}
14221 
14222 	return 0;
14223 }
14224 
14225 static int
14226 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14227 {
14228 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14229 	uint8_t sched_id = ts_params->valid_devs[0];
14230 	/* set mode */
14231 	return rte_cryptodev_scheduler_mode_set(sched_id,
14232 		scheduler_mode);
14233 }
14234 
14235 static int
14236 test_scheduler_mode_roundrobin_op(void)
14237 {
14238 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14239 			0, "Failed to set roundrobin mode");
14240 	return 0;
14241 
14242 }
14243 
14244 static int
14245 test_scheduler_mode_multicore_op(void)
14246 {
14247 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14248 			0, "Failed to set multicore mode");
14249 
14250 	return 0;
14251 }
14252 
14253 static int
14254 test_scheduler_mode_failover_op(void)
14255 {
14256 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14257 			0, "Failed to set failover mode");
14258 
14259 	return 0;
14260 }
14261 
14262 static int
14263 test_scheduler_mode_pkt_size_distr_op(void)
14264 {
14265 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14266 			0, "Failed to set pktsize mode");
14267 
14268 	return 0;
14269 }
14270 
14271 static int
14272 scheduler_multicore_testsuite_setup(void)
14273 {
14274 	if (test_scheduler_attach_worker_op() < 0)
14275 		return TEST_SKIPPED;
14276 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14277 		return TEST_SKIPPED;
14278 	return 0;
14279 }
14280 
14281 static int
14282 scheduler_roundrobin_testsuite_setup(void)
14283 {
14284 	if (test_scheduler_attach_worker_op() < 0)
14285 		return TEST_SKIPPED;
14286 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14287 		return TEST_SKIPPED;
14288 	return 0;
14289 }
14290 
14291 static int
14292 scheduler_failover_testsuite_setup(void)
14293 {
14294 	if (test_scheduler_attach_worker_op() < 0)
14295 		return TEST_SKIPPED;
14296 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14297 		return TEST_SKIPPED;
14298 	return 0;
14299 }
14300 
14301 static int
14302 scheduler_pkt_size_distr_testsuite_setup(void)
14303 {
14304 	if (test_scheduler_attach_worker_op() < 0)
14305 		return TEST_SKIPPED;
14306 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14307 		return TEST_SKIPPED;
14308 	return 0;
14309 }
14310 
14311 static void
14312 scheduler_mode_testsuite_teardown(void)
14313 {
14314 	test_scheduler_detach_worker_op();
14315 }
14316 
14317 #endif /* RTE_CRYPTO_SCHEDULER */
14318 
14319 static struct unit_test_suite end_testsuite = {
14320 	.suite_name = NULL,
14321 	.setup = NULL,
14322 	.teardown = NULL,
14323 	.unit_test_suites = NULL
14324 };
14325 
14326 #ifdef RTE_LIB_SECURITY
14327 static struct unit_test_suite ipsec_proto_testsuite  = {
14328 	.suite_name = "IPsec Proto Unit Test Suite",
14329 	.setup = ipsec_proto_testsuite_setup,
14330 	.unit_test_cases = {
14331 		TEST_CASE_NAMED_WITH_DATA(
14332 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14333 			ut_setup_security, ut_teardown,
14334 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14335 		TEST_CASE_NAMED_WITH_DATA(
14336 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14337 			ut_setup_security, ut_teardown,
14338 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14339 		TEST_CASE_NAMED_WITH_DATA(
14340 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14341 			ut_setup_security, ut_teardown,
14342 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14343 		TEST_CASE_NAMED_WITH_DATA(
14344 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14345 			ut_setup_security, ut_teardown,
14346 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14347 		TEST_CASE_NAMED_WITH_DATA(
14348 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14349 			ut_setup_security, ut_teardown,
14350 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14351 		TEST_CASE_NAMED_WITH_DATA(
14352 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14353 			ut_setup_security, ut_teardown,
14354 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14355 		TEST_CASE_NAMED_ST(
14356 			"Combined test alg list",
14357 			ut_setup_security, ut_teardown,
14358 			test_ipsec_proto_display_list),
14359 		TEST_CASE_NAMED_ST(
14360 			"IV generation",
14361 			ut_setup_security, ut_teardown,
14362 			test_ipsec_proto_iv_gen),
14363 		TEST_CASE_NAMED_ST(
14364 			"UDP encapsulation",
14365 			ut_setup_security, ut_teardown,
14366 			test_ipsec_proto_udp_encap),
14367 		TEST_CASE_NAMED_ST(
14368 			"UDP encapsulation ports verification test",
14369 			ut_setup_security, ut_teardown,
14370 			test_ipsec_proto_udp_ports_verify),
14371 		TEST_CASE_NAMED_ST(
14372 			"SA expiry packets soft",
14373 			ut_setup_security, ut_teardown,
14374 			test_ipsec_proto_sa_exp_pkts_soft),
14375 		TEST_CASE_NAMED_ST(
14376 			"SA expiry packets hard",
14377 			ut_setup_security, ut_teardown,
14378 			test_ipsec_proto_sa_exp_pkts_hard),
14379 		TEST_CASE_NAMED_ST(
14380 			"Negative test: ICV corruption",
14381 			ut_setup_security, ut_teardown,
14382 			test_ipsec_proto_err_icv_corrupt),
14383 		TEST_CASE_NAMED_ST(
14384 			"Tunnel dst addr verification",
14385 			ut_setup_security, ut_teardown,
14386 			test_ipsec_proto_tunnel_dst_addr_verify),
14387 		TEST_CASE_NAMED_ST(
14388 			"Tunnel src and dst addr verification",
14389 			ut_setup_security, ut_teardown,
14390 			test_ipsec_proto_tunnel_src_dst_addr_verify),
14391 		TEST_CASE_NAMED_ST(
14392 			"Inner IP checksum",
14393 			ut_setup_security, ut_teardown,
14394 			test_ipsec_proto_inner_ip_csum),
14395 		TEST_CASE_NAMED_ST(
14396 			"Inner L4 checksum",
14397 			ut_setup_security, ut_teardown,
14398 			test_ipsec_proto_inner_l4_csum),
14399 		TEST_CASES_END() /**< NULL terminate unit test array */
14400 	}
14401 };
14402 
14403 static struct unit_test_suite pdcp_proto_testsuite  = {
14404 	.suite_name = "PDCP Proto Unit Test Suite",
14405 	.setup = pdcp_proto_testsuite_setup,
14406 	.unit_test_cases = {
14407 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14408 			test_PDCP_PROTO_all),
14409 		TEST_CASES_END() /**< NULL terminate unit test array */
14410 	}
14411 };
14412 
14413 static struct unit_test_suite docsis_proto_testsuite  = {
14414 	.suite_name = "Docsis Proto Unit Test Suite",
14415 	.setup = docsis_proto_testsuite_setup,
14416 	.unit_test_cases = {
14417 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14418 			test_DOCSIS_PROTO_all),
14419 		TEST_CASES_END() /**< NULL terminate unit test array */
14420 	}
14421 };
14422 #endif
14423 
14424 static struct unit_test_suite cryptodev_gen_testsuite  = {
14425 	.suite_name = "Crypto General Unit Test Suite",
14426 	.setup = crypto_gen_testsuite_setup,
14427 	.unit_test_cases = {
14428 		TEST_CASE_ST(ut_setup, ut_teardown,
14429 				test_device_configure_invalid_dev_id),
14430 		TEST_CASE_ST(ut_setup, ut_teardown,
14431 				test_queue_pair_descriptor_setup),
14432 		TEST_CASE_ST(ut_setup, ut_teardown,
14433 				test_device_configure_invalid_queue_pair_ids),
14434 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14435 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14436 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14437 		TEST_CASES_END() /**< NULL terminate unit test array */
14438 	}
14439 };
14440 
14441 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14442 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
14443 	.setup = negative_hmac_sha1_testsuite_setup,
14444 	.unit_test_cases = {
14445 		/** Negative tests */
14446 		TEST_CASE_ST(ut_setup, ut_teardown,
14447 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
14448 		TEST_CASE_ST(ut_setup, ut_teardown,
14449 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14450 		TEST_CASE_ST(ut_setup, ut_teardown,
14451 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14452 		TEST_CASE_ST(ut_setup, ut_teardown,
14453 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14454 
14455 		TEST_CASES_END() /**< NULL terminate unit test array */
14456 	}
14457 };
14458 
14459 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14460 	.suite_name = "Multi Session Unit Test Suite",
14461 	.setup = multi_session_testsuite_setup,
14462 	.unit_test_cases = {
14463 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14464 		TEST_CASE_ST(ut_setup, ut_teardown,
14465 				test_multi_session_random_usage),
14466 
14467 		TEST_CASES_END() /**< NULL terminate unit test array */
14468 	}
14469 };
14470 
14471 static struct unit_test_suite cryptodev_null_testsuite  = {
14472 	.suite_name = "NULL Test Suite",
14473 	.setup = null_testsuite_setup,
14474 	.unit_test_cases = {
14475 		TEST_CASE_ST(ut_setup, ut_teardown,
14476 			test_null_invalid_operation),
14477 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14478 		TEST_CASES_END()
14479 	}
14480 };
14481 
14482 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14483 	.suite_name = "AES CCM Authenticated Test Suite",
14484 	.setup = aes_ccm_auth_testsuite_setup,
14485 	.unit_test_cases = {
14486 		/** AES CCM Authenticated Encryption 128 bits key*/
14487 		TEST_CASE_ST(ut_setup, ut_teardown,
14488 			test_AES_CCM_authenticated_encryption_test_case_128_1),
14489 		TEST_CASE_ST(ut_setup, ut_teardown,
14490 			test_AES_CCM_authenticated_encryption_test_case_128_2),
14491 		TEST_CASE_ST(ut_setup, ut_teardown,
14492 			test_AES_CCM_authenticated_encryption_test_case_128_3),
14493 
14494 		/** AES CCM Authenticated Decryption 128 bits key*/
14495 		TEST_CASE_ST(ut_setup, ut_teardown,
14496 			test_AES_CCM_authenticated_decryption_test_case_128_1),
14497 		TEST_CASE_ST(ut_setup, ut_teardown,
14498 			test_AES_CCM_authenticated_decryption_test_case_128_2),
14499 		TEST_CASE_ST(ut_setup, ut_teardown,
14500 			test_AES_CCM_authenticated_decryption_test_case_128_3),
14501 
14502 		/** AES CCM Authenticated Encryption 192 bits key */
14503 		TEST_CASE_ST(ut_setup, ut_teardown,
14504 			test_AES_CCM_authenticated_encryption_test_case_192_1),
14505 		TEST_CASE_ST(ut_setup, ut_teardown,
14506 			test_AES_CCM_authenticated_encryption_test_case_192_2),
14507 		TEST_CASE_ST(ut_setup, ut_teardown,
14508 			test_AES_CCM_authenticated_encryption_test_case_192_3),
14509 
14510 		/** AES CCM Authenticated Decryption 192 bits key*/
14511 		TEST_CASE_ST(ut_setup, ut_teardown,
14512 			test_AES_CCM_authenticated_decryption_test_case_192_1),
14513 		TEST_CASE_ST(ut_setup, ut_teardown,
14514 			test_AES_CCM_authenticated_decryption_test_case_192_2),
14515 		TEST_CASE_ST(ut_setup, ut_teardown,
14516 			test_AES_CCM_authenticated_decryption_test_case_192_3),
14517 
14518 		/** AES CCM Authenticated Encryption 256 bits key */
14519 		TEST_CASE_ST(ut_setup, ut_teardown,
14520 			test_AES_CCM_authenticated_encryption_test_case_256_1),
14521 		TEST_CASE_ST(ut_setup, ut_teardown,
14522 			test_AES_CCM_authenticated_encryption_test_case_256_2),
14523 		TEST_CASE_ST(ut_setup, ut_teardown,
14524 			test_AES_CCM_authenticated_encryption_test_case_256_3),
14525 
14526 		/** AES CCM Authenticated Decryption 256 bits key*/
14527 		TEST_CASE_ST(ut_setup, ut_teardown,
14528 			test_AES_CCM_authenticated_decryption_test_case_256_1),
14529 		TEST_CASE_ST(ut_setup, ut_teardown,
14530 			test_AES_CCM_authenticated_decryption_test_case_256_2),
14531 		TEST_CASE_ST(ut_setup, ut_teardown,
14532 			test_AES_CCM_authenticated_decryption_test_case_256_3),
14533 		TEST_CASES_END()
14534 	}
14535 };
14536 
14537 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14538 	.suite_name = "AES GCM Authenticated Test Suite",
14539 	.setup = aes_gcm_auth_testsuite_setup,
14540 	.unit_test_cases = {
14541 		/** AES GCM Authenticated Encryption */
14542 		TEST_CASE_ST(ut_setup, ut_teardown,
14543 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14544 		TEST_CASE_ST(ut_setup, ut_teardown,
14545 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14546 		TEST_CASE_ST(ut_setup, ut_teardown,
14547 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14548 		TEST_CASE_ST(ut_setup, ut_teardown,
14549 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14550 		TEST_CASE_ST(ut_setup, ut_teardown,
14551 			test_AES_GCM_authenticated_encryption_test_case_1),
14552 		TEST_CASE_ST(ut_setup, ut_teardown,
14553 			test_AES_GCM_authenticated_encryption_test_case_2),
14554 		TEST_CASE_ST(ut_setup, ut_teardown,
14555 			test_AES_GCM_authenticated_encryption_test_case_3),
14556 		TEST_CASE_ST(ut_setup, ut_teardown,
14557 			test_AES_GCM_authenticated_encryption_test_case_4),
14558 		TEST_CASE_ST(ut_setup, ut_teardown,
14559 			test_AES_GCM_authenticated_encryption_test_case_5),
14560 		TEST_CASE_ST(ut_setup, ut_teardown,
14561 			test_AES_GCM_authenticated_encryption_test_case_6),
14562 		TEST_CASE_ST(ut_setup, ut_teardown,
14563 			test_AES_GCM_authenticated_encryption_test_case_7),
14564 		TEST_CASE_ST(ut_setup, ut_teardown,
14565 			test_AES_GCM_authenticated_encryption_test_case_8),
14566 		TEST_CASE_ST(ut_setup, ut_teardown,
14567 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
14568 
14569 		/** AES GCM Authenticated Decryption */
14570 		TEST_CASE_ST(ut_setup, ut_teardown,
14571 			test_AES_GCM_authenticated_decryption_test_case_1),
14572 		TEST_CASE_ST(ut_setup, ut_teardown,
14573 			test_AES_GCM_authenticated_decryption_test_case_2),
14574 		TEST_CASE_ST(ut_setup, ut_teardown,
14575 			test_AES_GCM_authenticated_decryption_test_case_3),
14576 		TEST_CASE_ST(ut_setup, ut_teardown,
14577 			test_AES_GCM_authenticated_decryption_test_case_4),
14578 		TEST_CASE_ST(ut_setup, ut_teardown,
14579 			test_AES_GCM_authenticated_decryption_test_case_5),
14580 		TEST_CASE_ST(ut_setup, ut_teardown,
14581 			test_AES_GCM_authenticated_decryption_test_case_6),
14582 		TEST_CASE_ST(ut_setup, ut_teardown,
14583 			test_AES_GCM_authenticated_decryption_test_case_7),
14584 		TEST_CASE_ST(ut_setup, ut_teardown,
14585 			test_AES_GCM_authenticated_decryption_test_case_8),
14586 		TEST_CASE_ST(ut_setup, ut_teardown,
14587 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
14588 
14589 		/** AES GCM Authenticated Encryption 192 bits key */
14590 		TEST_CASE_ST(ut_setup, ut_teardown,
14591 			test_AES_GCM_auth_encryption_test_case_192_1),
14592 		TEST_CASE_ST(ut_setup, ut_teardown,
14593 			test_AES_GCM_auth_encryption_test_case_192_2),
14594 		TEST_CASE_ST(ut_setup, ut_teardown,
14595 			test_AES_GCM_auth_encryption_test_case_192_3),
14596 		TEST_CASE_ST(ut_setup, ut_teardown,
14597 			test_AES_GCM_auth_encryption_test_case_192_4),
14598 		TEST_CASE_ST(ut_setup, ut_teardown,
14599 			test_AES_GCM_auth_encryption_test_case_192_5),
14600 		TEST_CASE_ST(ut_setup, ut_teardown,
14601 			test_AES_GCM_auth_encryption_test_case_192_6),
14602 		TEST_CASE_ST(ut_setup, ut_teardown,
14603 			test_AES_GCM_auth_encryption_test_case_192_7),
14604 
14605 		/** AES GCM Authenticated Decryption 192 bits key */
14606 		TEST_CASE_ST(ut_setup, ut_teardown,
14607 			test_AES_GCM_auth_decryption_test_case_192_1),
14608 		TEST_CASE_ST(ut_setup, ut_teardown,
14609 			test_AES_GCM_auth_decryption_test_case_192_2),
14610 		TEST_CASE_ST(ut_setup, ut_teardown,
14611 			test_AES_GCM_auth_decryption_test_case_192_3),
14612 		TEST_CASE_ST(ut_setup, ut_teardown,
14613 			test_AES_GCM_auth_decryption_test_case_192_4),
14614 		TEST_CASE_ST(ut_setup, ut_teardown,
14615 			test_AES_GCM_auth_decryption_test_case_192_5),
14616 		TEST_CASE_ST(ut_setup, ut_teardown,
14617 			test_AES_GCM_auth_decryption_test_case_192_6),
14618 		TEST_CASE_ST(ut_setup, ut_teardown,
14619 			test_AES_GCM_auth_decryption_test_case_192_7),
14620 
14621 		/** AES GCM Authenticated Encryption 256 bits key */
14622 		TEST_CASE_ST(ut_setup, ut_teardown,
14623 			test_AES_GCM_auth_encryption_test_case_256_1),
14624 		TEST_CASE_ST(ut_setup, ut_teardown,
14625 			test_AES_GCM_auth_encryption_test_case_256_2),
14626 		TEST_CASE_ST(ut_setup, ut_teardown,
14627 			test_AES_GCM_auth_encryption_test_case_256_3),
14628 		TEST_CASE_ST(ut_setup, ut_teardown,
14629 			test_AES_GCM_auth_encryption_test_case_256_4),
14630 		TEST_CASE_ST(ut_setup, ut_teardown,
14631 			test_AES_GCM_auth_encryption_test_case_256_5),
14632 		TEST_CASE_ST(ut_setup, ut_teardown,
14633 			test_AES_GCM_auth_encryption_test_case_256_6),
14634 		TEST_CASE_ST(ut_setup, ut_teardown,
14635 			test_AES_GCM_auth_encryption_test_case_256_7),
14636 
14637 		/** AES GCM Authenticated Decryption 256 bits key */
14638 		TEST_CASE_ST(ut_setup, ut_teardown,
14639 			test_AES_GCM_auth_decryption_test_case_256_1),
14640 		TEST_CASE_ST(ut_setup, ut_teardown,
14641 			test_AES_GCM_auth_decryption_test_case_256_2),
14642 		TEST_CASE_ST(ut_setup, ut_teardown,
14643 			test_AES_GCM_auth_decryption_test_case_256_3),
14644 		TEST_CASE_ST(ut_setup, ut_teardown,
14645 			test_AES_GCM_auth_decryption_test_case_256_4),
14646 		TEST_CASE_ST(ut_setup, ut_teardown,
14647 			test_AES_GCM_auth_decryption_test_case_256_5),
14648 		TEST_CASE_ST(ut_setup, ut_teardown,
14649 			test_AES_GCM_auth_decryption_test_case_256_6),
14650 		TEST_CASE_ST(ut_setup, ut_teardown,
14651 			test_AES_GCM_auth_decryption_test_case_256_7),
14652 
14653 		/** AES GCM Authenticated Encryption big aad size */
14654 		TEST_CASE_ST(ut_setup, ut_teardown,
14655 			test_AES_GCM_auth_encryption_test_case_aad_1),
14656 		TEST_CASE_ST(ut_setup, ut_teardown,
14657 			test_AES_GCM_auth_encryption_test_case_aad_2),
14658 
14659 		/** AES GCM Authenticated Decryption big aad size */
14660 		TEST_CASE_ST(ut_setup, ut_teardown,
14661 			test_AES_GCM_auth_decryption_test_case_aad_1),
14662 		TEST_CASE_ST(ut_setup, ut_teardown,
14663 			test_AES_GCM_auth_decryption_test_case_aad_2),
14664 
14665 		/** Out of place tests */
14666 		TEST_CASE_ST(ut_setup, ut_teardown,
14667 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
14668 		TEST_CASE_ST(ut_setup, ut_teardown,
14669 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
14670 
14671 		/** Session-less tests */
14672 		TEST_CASE_ST(ut_setup, ut_teardown,
14673 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14674 		TEST_CASE_ST(ut_setup, ut_teardown,
14675 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14676 
14677 		TEST_CASES_END()
14678 	}
14679 };
14680 
14681 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14682 	.suite_name = "AES GMAC Authentication Test Suite",
14683 	.setup = aes_gmac_auth_testsuite_setup,
14684 	.unit_test_cases = {
14685 		TEST_CASE_ST(ut_setup, ut_teardown,
14686 			test_AES_GMAC_authentication_test_case_1),
14687 		TEST_CASE_ST(ut_setup, ut_teardown,
14688 			test_AES_GMAC_authentication_verify_test_case_1),
14689 		TEST_CASE_ST(ut_setup, ut_teardown,
14690 			test_AES_GMAC_authentication_test_case_2),
14691 		TEST_CASE_ST(ut_setup, ut_teardown,
14692 			test_AES_GMAC_authentication_verify_test_case_2),
14693 		TEST_CASE_ST(ut_setup, ut_teardown,
14694 			test_AES_GMAC_authentication_test_case_3),
14695 		TEST_CASE_ST(ut_setup, ut_teardown,
14696 			test_AES_GMAC_authentication_verify_test_case_3),
14697 		TEST_CASE_ST(ut_setup, ut_teardown,
14698 			test_AES_GMAC_authentication_test_case_4),
14699 		TEST_CASE_ST(ut_setup, ut_teardown,
14700 			test_AES_GMAC_authentication_verify_test_case_4),
14701 		TEST_CASE_ST(ut_setup, ut_teardown,
14702 			test_AES_GMAC_authentication_SGL_40B),
14703 		TEST_CASE_ST(ut_setup, ut_teardown,
14704 			test_AES_GMAC_authentication_SGL_80B),
14705 		TEST_CASE_ST(ut_setup, ut_teardown,
14706 			test_AES_GMAC_authentication_SGL_2048B),
14707 		TEST_CASE_ST(ut_setup, ut_teardown,
14708 			test_AES_GMAC_authentication_SGL_2047B),
14709 
14710 		TEST_CASES_END()
14711 	}
14712 };
14713 
14714 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
14715 	.suite_name = "Chacha20-Poly1305 Test Suite",
14716 	.setup = chacha20_poly1305_testsuite_setup,
14717 	.unit_test_cases = {
14718 		TEST_CASE_ST(ut_setup, ut_teardown,
14719 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
14720 		TEST_CASE_ST(ut_setup, ut_teardown,
14721 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
14722 		TEST_CASES_END()
14723 	}
14724 };
14725 
14726 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
14727 	.suite_name = "SNOW 3G Test Suite",
14728 	.setup = snow3g_testsuite_setup,
14729 	.unit_test_cases = {
14730 		/** SNOW 3G encrypt only (UEA2) */
14731 		TEST_CASE_ST(ut_setup, ut_teardown,
14732 			test_snow3g_encryption_test_case_1),
14733 		TEST_CASE_ST(ut_setup, ut_teardown,
14734 			test_snow3g_encryption_test_case_2),
14735 		TEST_CASE_ST(ut_setup, ut_teardown,
14736 			test_snow3g_encryption_test_case_3),
14737 		TEST_CASE_ST(ut_setup, ut_teardown,
14738 			test_snow3g_encryption_test_case_4),
14739 		TEST_CASE_ST(ut_setup, ut_teardown,
14740 			test_snow3g_encryption_test_case_5),
14741 
14742 		TEST_CASE_ST(ut_setup, ut_teardown,
14743 			test_snow3g_encryption_test_case_1_oop),
14744 		TEST_CASE_ST(ut_setup, ut_teardown,
14745 			test_snow3g_encryption_test_case_1_oop_sgl),
14746 		TEST_CASE_ST(ut_setup, ut_teardown,
14747 			test_snow3g_encryption_test_case_1_offset_oop),
14748 		TEST_CASE_ST(ut_setup, ut_teardown,
14749 			test_snow3g_decryption_test_case_1_oop),
14750 
14751 		/** SNOW 3G generate auth, then encrypt (UEA2) */
14752 		TEST_CASE_ST(ut_setup, ut_teardown,
14753 			test_snow3g_auth_cipher_test_case_1),
14754 		TEST_CASE_ST(ut_setup, ut_teardown,
14755 			test_snow3g_auth_cipher_test_case_2),
14756 		TEST_CASE_ST(ut_setup, ut_teardown,
14757 			test_snow3g_auth_cipher_test_case_2_oop),
14758 		TEST_CASE_ST(ut_setup, ut_teardown,
14759 			test_snow3g_auth_cipher_part_digest_enc),
14760 		TEST_CASE_ST(ut_setup, ut_teardown,
14761 			test_snow3g_auth_cipher_part_digest_enc_oop),
14762 		TEST_CASE_ST(ut_setup, ut_teardown,
14763 			test_snow3g_auth_cipher_test_case_3_sgl),
14764 		TEST_CASE_ST(ut_setup, ut_teardown,
14765 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
14766 		TEST_CASE_ST(ut_setup, ut_teardown,
14767 			test_snow3g_auth_cipher_part_digest_enc_sgl),
14768 		TEST_CASE_ST(ut_setup, ut_teardown,
14769 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
14770 
14771 		/** SNOW 3G decrypt (UEA2), then verify auth */
14772 		TEST_CASE_ST(ut_setup, ut_teardown,
14773 			test_snow3g_auth_cipher_verify_test_case_1),
14774 		TEST_CASE_ST(ut_setup, ut_teardown,
14775 			test_snow3g_auth_cipher_verify_test_case_2),
14776 		TEST_CASE_ST(ut_setup, ut_teardown,
14777 			test_snow3g_auth_cipher_verify_test_case_2_oop),
14778 		TEST_CASE_ST(ut_setup, ut_teardown,
14779 			test_snow3g_auth_cipher_verify_part_digest_enc),
14780 		TEST_CASE_ST(ut_setup, ut_teardown,
14781 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
14782 		TEST_CASE_ST(ut_setup, ut_teardown,
14783 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
14784 		TEST_CASE_ST(ut_setup, ut_teardown,
14785 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
14786 		TEST_CASE_ST(ut_setup, ut_teardown,
14787 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
14788 		TEST_CASE_ST(ut_setup, ut_teardown,
14789 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
14790 
14791 		/** SNOW 3G decrypt only (UEA2) */
14792 		TEST_CASE_ST(ut_setup, ut_teardown,
14793 			test_snow3g_decryption_test_case_1),
14794 		TEST_CASE_ST(ut_setup, ut_teardown,
14795 			test_snow3g_decryption_test_case_2),
14796 		TEST_CASE_ST(ut_setup, ut_teardown,
14797 			test_snow3g_decryption_test_case_3),
14798 		TEST_CASE_ST(ut_setup, ut_teardown,
14799 			test_snow3g_decryption_test_case_4),
14800 		TEST_CASE_ST(ut_setup, ut_teardown,
14801 			test_snow3g_decryption_test_case_5),
14802 		TEST_CASE_ST(ut_setup, ut_teardown,
14803 			test_snow3g_decryption_with_digest_test_case_1),
14804 		TEST_CASE_ST(ut_setup, ut_teardown,
14805 			test_snow3g_hash_generate_test_case_1),
14806 		TEST_CASE_ST(ut_setup, ut_teardown,
14807 			test_snow3g_hash_generate_test_case_2),
14808 		TEST_CASE_ST(ut_setup, ut_teardown,
14809 			test_snow3g_hash_generate_test_case_3),
14810 
14811 		/* Tests with buffers which length is not byte-aligned */
14812 		TEST_CASE_ST(ut_setup, ut_teardown,
14813 			test_snow3g_hash_generate_test_case_4),
14814 		TEST_CASE_ST(ut_setup, ut_teardown,
14815 			test_snow3g_hash_generate_test_case_5),
14816 		TEST_CASE_ST(ut_setup, ut_teardown,
14817 			test_snow3g_hash_generate_test_case_6),
14818 		TEST_CASE_ST(ut_setup, ut_teardown,
14819 			test_snow3g_hash_verify_test_case_1),
14820 		TEST_CASE_ST(ut_setup, ut_teardown,
14821 			test_snow3g_hash_verify_test_case_2),
14822 		TEST_CASE_ST(ut_setup, ut_teardown,
14823 			test_snow3g_hash_verify_test_case_3),
14824 
14825 		/* Tests with buffers which length is not byte-aligned */
14826 		TEST_CASE_ST(ut_setup, ut_teardown,
14827 			test_snow3g_hash_verify_test_case_4),
14828 		TEST_CASE_ST(ut_setup, ut_teardown,
14829 			test_snow3g_hash_verify_test_case_5),
14830 		TEST_CASE_ST(ut_setup, ut_teardown,
14831 			test_snow3g_hash_verify_test_case_6),
14832 		TEST_CASE_ST(ut_setup, ut_teardown,
14833 			test_snow3g_cipher_auth_test_case_1),
14834 		TEST_CASE_ST(ut_setup, ut_teardown,
14835 			test_snow3g_auth_cipher_with_digest_test_case_1),
14836 		TEST_CASES_END()
14837 	}
14838 };
14839 
14840 static struct unit_test_suite cryptodev_zuc_testsuite  = {
14841 	.suite_name = "ZUC Test Suite",
14842 	.setup = zuc_testsuite_setup,
14843 	.unit_test_cases = {
14844 		/** ZUC encrypt only (EEA3) */
14845 		TEST_CASE_ST(ut_setup, ut_teardown,
14846 			test_zuc_encryption_test_case_1),
14847 		TEST_CASE_ST(ut_setup, ut_teardown,
14848 			test_zuc_encryption_test_case_2),
14849 		TEST_CASE_ST(ut_setup, ut_teardown,
14850 			test_zuc_encryption_test_case_3),
14851 		TEST_CASE_ST(ut_setup, ut_teardown,
14852 			test_zuc_encryption_test_case_4),
14853 		TEST_CASE_ST(ut_setup, ut_teardown,
14854 			test_zuc_encryption_test_case_5),
14855 		TEST_CASE_ST(ut_setup, ut_teardown,
14856 			test_zuc_encryption_test_case_6_sgl),
14857 		TEST_CASE_ST(ut_setup, ut_teardown,
14858 			test_zuc_encryption_test_case_7),
14859 
14860 		/** ZUC authenticate (EIA3) */
14861 		TEST_CASE_ST(ut_setup, ut_teardown,
14862 			test_zuc_hash_generate_test_case_1),
14863 		TEST_CASE_ST(ut_setup, ut_teardown,
14864 			test_zuc_hash_generate_test_case_2),
14865 		TEST_CASE_ST(ut_setup, ut_teardown,
14866 			test_zuc_hash_generate_test_case_3),
14867 		TEST_CASE_ST(ut_setup, ut_teardown,
14868 			test_zuc_hash_generate_test_case_4),
14869 		TEST_CASE_ST(ut_setup, ut_teardown,
14870 			test_zuc_hash_generate_test_case_5),
14871 		TEST_CASE_ST(ut_setup, ut_teardown,
14872 			test_zuc_hash_generate_test_case_6),
14873 		TEST_CASE_ST(ut_setup, ut_teardown,
14874 			test_zuc_hash_generate_test_case_7),
14875 		TEST_CASE_ST(ut_setup, ut_teardown,
14876 			test_zuc_hash_generate_test_case_8),
14877 		TEST_CASE_ST(ut_setup, ut_teardown,
14878 			test_zuc_hash_generate_test_case_9),
14879 		TEST_CASE_ST(ut_setup, ut_teardown,
14880 			test_zuc_hash_generate_test_case_10),
14881 
14882 
14883 		/** ZUC alg-chain (EEA3/EIA3) */
14884 		TEST_CASE_ST(ut_setup, ut_teardown,
14885 			test_zuc_cipher_auth_test_case_1),
14886 		TEST_CASE_ST(ut_setup, ut_teardown,
14887 			test_zuc_cipher_auth_test_case_2),
14888 
14889 		/** ZUC generate auth, then encrypt (EEA3) */
14890 		TEST_CASE_ST(ut_setup, ut_teardown,
14891 			test_zuc_auth_cipher_test_case_1),
14892 		TEST_CASE_ST(ut_setup, ut_teardown,
14893 			test_zuc_auth_cipher_test_case_1_oop),
14894 		TEST_CASE_ST(ut_setup, ut_teardown,
14895 			test_zuc_auth_cipher_test_case_1_sgl),
14896 		TEST_CASE_ST(ut_setup, ut_teardown,
14897 			test_zuc_auth_cipher_test_case_1_oop_sgl),
14898 
14899 		/** ZUC decrypt (EEA3), then verify auth */
14900 		TEST_CASE_ST(ut_setup, ut_teardown,
14901 			test_zuc_auth_cipher_verify_test_case_1),
14902 		TEST_CASE_ST(ut_setup, ut_teardown,
14903 			test_zuc_auth_cipher_verify_test_case_1_oop),
14904 		TEST_CASE_ST(ut_setup, ut_teardown,
14905 			test_zuc_auth_cipher_verify_test_case_1_sgl),
14906 		TEST_CASE_ST(ut_setup, ut_teardown,
14907 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
14908 		TEST_CASES_END()
14909 	}
14910 };
14911 
14912 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
14913 	.suite_name = "HMAC_MD5 Authentication Test Suite",
14914 	.setup = hmac_md5_auth_testsuite_setup,
14915 	.unit_test_cases = {
14916 		TEST_CASE_ST(ut_setup, ut_teardown,
14917 			test_MD5_HMAC_generate_case_1),
14918 		TEST_CASE_ST(ut_setup, ut_teardown,
14919 			test_MD5_HMAC_verify_case_1),
14920 		TEST_CASE_ST(ut_setup, ut_teardown,
14921 			test_MD5_HMAC_generate_case_2),
14922 		TEST_CASE_ST(ut_setup, ut_teardown,
14923 			test_MD5_HMAC_verify_case_2),
14924 		TEST_CASES_END()
14925 	}
14926 };
14927 
14928 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
14929 	.suite_name = "Kasumi Test Suite",
14930 	.setup = kasumi_testsuite_setup,
14931 	.unit_test_cases = {
14932 		/** KASUMI hash only (UIA1) */
14933 		TEST_CASE_ST(ut_setup, ut_teardown,
14934 			test_kasumi_hash_generate_test_case_1),
14935 		TEST_CASE_ST(ut_setup, ut_teardown,
14936 			test_kasumi_hash_generate_test_case_2),
14937 		TEST_CASE_ST(ut_setup, ut_teardown,
14938 			test_kasumi_hash_generate_test_case_3),
14939 		TEST_CASE_ST(ut_setup, ut_teardown,
14940 			test_kasumi_hash_generate_test_case_4),
14941 		TEST_CASE_ST(ut_setup, ut_teardown,
14942 			test_kasumi_hash_generate_test_case_5),
14943 		TEST_CASE_ST(ut_setup, ut_teardown,
14944 			test_kasumi_hash_generate_test_case_6),
14945 
14946 		TEST_CASE_ST(ut_setup, ut_teardown,
14947 			test_kasumi_hash_verify_test_case_1),
14948 		TEST_CASE_ST(ut_setup, ut_teardown,
14949 			test_kasumi_hash_verify_test_case_2),
14950 		TEST_CASE_ST(ut_setup, ut_teardown,
14951 			test_kasumi_hash_verify_test_case_3),
14952 		TEST_CASE_ST(ut_setup, ut_teardown,
14953 			test_kasumi_hash_verify_test_case_4),
14954 		TEST_CASE_ST(ut_setup, ut_teardown,
14955 			test_kasumi_hash_verify_test_case_5),
14956 
14957 		/** KASUMI encrypt only (UEA1) */
14958 		TEST_CASE_ST(ut_setup, ut_teardown,
14959 			test_kasumi_encryption_test_case_1),
14960 		TEST_CASE_ST(ut_setup, ut_teardown,
14961 			test_kasumi_encryption_test_case_1_sgl),
14962 		TEST_CASE_ST(ut_setup, ut_teardown,
14963 			test_kasumi_encryption_test_case_1_oop),
14964 		TEST_CASE_ST(ut_setup, ut_teardown,
14965 			test_kasumi_encryption_test_case_1_oop_sgl),
14966 		TEST_CASE_ST(ut_setup, ut_teardown,
14967 			test_kasumi_encryption_test_case_2),
14968 		TEST_CASE_ST(ut_setup, ut_teardown,
14969 			test_kasumi_encryption_test_case_3),
14970 		TEST_CASE_ST(ut_setup, ut_teardown,
14971 			test_kasumi_encryption_test_case_4),
14972 		TEST_CASE_ST(ut_setup, ut_teardown,
14973 			test_kasumi_encryption_test_case_5),
14974 
14975 		/** KASUMI decrypt only (UEA1) */
14976 		TEST_CASE_ST(ut_setup, ut_teardown,
14977 			test_kasumi_decryption_test_case_1),
14978 		TEST_CASE_ST(ut_setup, ut_teardown,
14979 			test_kasumi_decryption_test_case_2),
14980 		TEST_CASE_ST(ut_setup, ut_teardown,
14981 			test_kasumi_decryption_test_case_3),
14982 		TEST_CASE_ST(ut_setup, ut_teardown,
14983 			test_kasumi_decryption_test_case_4),
14984 		TEST_CASE_ST(ut_setup, ut_teardown,
14985 			test_kasumi_decryption_test_case_5),
14986 		TEST_CASE_ST(ut_setup, ut_teardown,
14987 			test_kasumi_decryption_test_case_1_oop),
14988 		TEST_CASE_ST(ut_setup, ut_teardown,
14989 			test_kasumi_cipher_auth_test_case_1),
14990 
14991 		/** KASUMI generate auth, then encrypt (F8) */
14992 		TEST_CASE_ST(ut_setup, ut_teardown,
14993 			test_kasumi_auth_cipher_test_case_1),
14994 		TEST_CASE_ST(ut_setup, ut_teardown,
14995 			test_kasumi_auth_cipher_test_case_2),
14996 		TEST_CASE_ST(ut_setup, ut_teardown,
14997 			test_kasumi_auth_cipher_test_case_2_oop),
14998 		TEST_CASE_ST(ut_setup, ut_teardown,
14999 			test_kasumi_auth_cipher_test_case_2_sgl),
15000 		TEST_CASE_ST(ut_setup, ut_teardown,
15001 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
15002 
15003 		/** KASUMI decrypt (F8), then verify auth */
15004 		TEST_CASE_ST(ut_setup, ut_teardown,
15005 			test_kasumi_auth_cipher_verify_test_case_1),
15006 		TEST_CASE_ST(ut_setup, ut_teardown,
15007 			test_kasumi_auth_cipher_verify_test_case_2),
15008 		TEST_CASE_ST(ut_setup, ut_teardown,
15009 			test_kasumi_auth_cipher_verify_test_case_2_oop),
15010 		TEST_CASE_ST(ut_setup, ut_teardown,
15011 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
15012 		TEST_CASE_ST(ut_setup, ut_teardown,
15013 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
15014 
15015 		TEST_CASES_END()
15016 	}
15017 };
15018 
15019 static struct unit_test_suite cryptodev_esn_testsuite  = {
15020 	.suite_name = "ESN Test Suite",
15021 	.setup = esn_testsuite_setup,
15022 	.unit_test_cases = {
15023 		TEST_CASE_ST(ut_setup, ut_teardown,
15024 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
15025 		TEST_CASE_ST(ut_setup, ut_teardown,
15026 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
15027 		TEST_CASES_END()
15028 	}
15029 };
15030 
15031 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
15032 	.suite_name = "Negative AES GCM Test Suite",
15033 	.setup = negative_aes_gcm_testsuite_setup,
15034 	.unit_test_cases = {
15035 		TEST_CASE_ST(ut_setup, ut_teardown,
15036 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
15037 		TEST_CASE_ST(ut_setup, ut_teardown,
15038 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
15039 		TEST_CASE_ST(ut_setup, ut_teardown,
15040 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
15041 		TEST_CASE_ST(ut_setup, ut_teardown,
15042 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
15043 		TEST_CASE_ST(ut_setup, ut_teardown,
15044 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
15045 		TEST_CASE_ST(ut_setup, ut_teardown,
15046 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
15047 		TEST_CASE_ST(ut_setup, ut_teardown,
15048 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
15049 		TEST_CASE_ST(ut_setup, ut_teardown,
15050 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
15051 		TEST_CASE_ST(ut_setup, ut_teardown,
15052 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
15053 		TEST_CASE_ST(ut_setup, ut_teardown,
15054 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
15055 		TEST_CASE_ST(ut_setup, ut_teardown,
15056 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
15057 		TEST_CASE_ST(ut_setup, ut_teardown,
15058 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
15059 
15060 		TEST_CASES_END()
15061 	}
15062 };
15063 
15064 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
15065 	.suite_name = "Negative AES GMAC Test Suite",
15066 	.setup = negative_aes_gmac_testsuite_setup,
15067 	.unit_test_cases = {
15068 		TEST_CASE_ST(ut_setup, ut_teardown,
15069 			authentication_verify_AES128_GMAC_fail_data_corrupt),
15070 		TEST_CASE_ST(ut_setup, ut_teardown,
15071 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
15072 
15073 		TEST_CASES_END()
15074 	}
15075 };
15076 
15077 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
15078 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
15079 	.setup = mixed_cipher_hash_testsuite_setup,
15080 	.unit_test_cases = {
15081 		/** AUTH AES CMAC + CIPHER AES CTR */
15082 		TEST_CASE_ST(ut_setup, ut_teardown,
15083 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
15084 		TEST_CASE_ST(ut_setup, ut_teardown,
15085 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15086 		TEST_CASE_ST(ut_setup, ut_teardown,
15087 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15088 		TEST_CASE_ST(ut_setup, ut_teardown,
15089 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15090 		TEST_CASE_ST(ut_setup, ut_teardown,
15091 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
15092 		TEST_CASE_ST(ut_setup, ut_teardown,
15093 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15094 		TEST_CASE_ST(ut_setup, ut_teardown,
15095 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15096 		TEST_CASE_ST(ut_setup, ut_teardown,
15097 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15098 
15099 		/** AUTH ZUC + CIPHER SNOW3G */
15100 		TEST_CASE_ST(ut_setup, ut_teardown,
15101 			test_auth_zuc_cipher_snow_test_case_1),
15102 		TEST_CASE_ST(ut_setup, ut_teardown,
15103 			test_verify_auth_zuc_cipher_snow_test_case_1),
15104 		/** AUTH AES CMAC + CIPHER SNOW3G */
15105 		TEST_CASE_ST(ut_setup, ut_teardown,
15106 			test_auth_aes_cmac_cipher_snow_test_case_1),
15107 		TEST_CASE_ST(ut_setup, ut_teardown,
15108 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15109 		/** AUTH ZUC + CIPHER AES CTR */
15110 		TEST_CASE_ST(ut_setup, ut_teardown,
15111 			test_auth_zuc_cipher_aes_ctr_test_case_1),
15112 		TEST_CASE_ST(ut_setup, ut_teardown,
15113 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15114 		/** AUTH SNOW3G + CIPHER AES CTR */
15115 		TEST_CASE_ST(ut_setup, ut_teardown,
15116 			test_auth_snow_cipher_aes_ctr_test_case_1),
15117 		TEST_CASE_ST(ut_setup, ut_teardown,
15118 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
15119 		/** AUTH SNOW3G + CIPHER ZUC */
15120 		TEST_CASE_ST(ut_setup, ut_teardown,
15121 			test_auth_snow_cipher_zuc_test_case_1),
15122 		TEST_CASE_ST(ut_setup, ut_teardown,
15123 			test_verify_auth_snow_cipher_zuc_test_case_1),
15124 		/** AUTH AES CMAC + CIPHER ZUC */
15125 		TEST_CASE_ST(ut_setup, ut_teardown,
15126 			test_auth_aes_cmac_cipher_zuc_test_case_1),
15127 		TEST_CASE_ST(ut_setup, ut_teardown,
15128 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
15129 
15130 		/** AUTH NULL + CIPHER SNOW3G */
15131 		TEST_CASE_ST(ut_setup, ut_teardown,
15132 			test_auth_null_cipher_snow_test_case_1),
15133 		TEST_CASE_ST(ut_setup, ut_teardown,
15134 			test_verify_auth_null_cipher_snow_test_case_1),
15135 		/** AUTH NULL + CIPHER ZUC */
15136 		TEST_CASE_ST(ut_setup, ut_teardown,
15137 			test_auth_null_cipher_zuc_test_case_1),
15138 		TEST_CASE_ST(ut_setup, ut_teardown,
15139 			test_verify_auth_null_cipher_zuc_test_case_1),
15140 		/** AUTH SNOW3G + CIPHER NULL */
15141 		TEST_CASE_ST(ut_setup, ut_teardown,
15142 			test_auth_snow_cipher_null_test_case_1),
15143 		TEST_CASE_ST(ut_setup, ut_teardown,
15144 			test_verify_auth_snow_cipher_null_test_case_1),
15145 		/** AUTH ZUC + CIPHER NULL */
15146 		TEST_CASE_ST(ut_setup, ut_teardown,
15147 			test_auth_zuc_cipher_null_test_case_1),
15148 		TEST_CASE_ST(ut_setup, ut_teardown,
15149 			test_verify_auth_zuc_cipher_null_test_case_1),
15150 		/** AUTH NULL + CIPHER AES CTR */
15151 		TEST_CASE_ST(ut_setup, ut_teardown,
15152 			test_auth_null_cipher_aes_ctr_test_case_1),
15153 		TEST_CASE_ST(ut_setup, ut_teardown,
15154 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
15155 		/** AUTH AES CMAC + CIPHER NULL */
15156 		TEST_CASE_ST(ut_setup, ut_teardown,
15157 			test_auth_aes_cmac_cipher_null_test_case_1),
15158 		TEST_CASE_ST(ut_setup, ut_teardown,
15159 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
15160 		TEST_CASES_END()
15161 	}
15162 };
15163 
15164 static int
15165 run_cryptodev_testsuite(const char *pmd_name)
15166 {
15167 	uint8_t ret, j, i = 0, blk_start_idx = 0;
15168 	const enum blockcipher_test_type blk_suites[] = {
15169 		BLKCIPHER_AES_CHAIN_TYPE,
15170 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15171 		BLKCIPHER_AES_DOCSIS_TYPE,
15172 		BLKCIPHER_3DES_CHAIN_TYPE,
15173 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
15174 		BLKCIPHER_DES_CIPHERONLY_TYPE,
15175 		BLKCIPHER_DES_DOCSIS_TYPE,
15176 		BLKCIPHER_AUTHONLY_TYPE};
15177 	struct unit_test_suite *static_suites[] = {
15178 		&cryptodev_multi_session_testsuite,
15179 		&cryptodev_null_testsuite,
15180 		&cryptodev_aes_ccm_auth_testsuite,
15181 		&cryptodev_aes_gcm_auth_testsuite,
15182 		&cryptodev_aes_gmac_auth_testsuite,
15183 		&cryptodev_snow3g_testsuite,
15184 		&cryptodev_chacha20_poly1305_testsuite,
15185 		&cryptodev_zuc_testsuite,
15186 		&cryptodev_hmac_md5_auth_testsuite,
15187 		&cryptodev_kasumi_testsuite,
15188 		&cryptodev_esn_testsuite,
15189 		&cryptodev_negative_aes_gcm_testsuite,
15190 		&cryptodev_negative_aes_gmac_testsuite,
15191 		&cryptodev_mixed_cipher_hash_testsuite,
15192 		&cryptodev_negative_hmac_sha1_testsuite,
15193 		&cryptodev_gen_testsuite,
15194 #ifdef RTE_LIB_SECURITY
15195 		&ipsec_proto_testsuite,
15196 		&pdcp_proto_testsuite,
15197 		&docsis_proto_testsuite,
15198 #endif
15199 		&end_testsuite
15200 	};
15201 	static struct unit_test_suite ts = {
15202 		.suite_name = "Cryptodev Unit Test Suite",
15203 		.setup = testsuite_setup,
15204 		.teardown = testsuite_teardown,
15205 		.unit_test_cases = {TEST_CASES_END()}
15206 	};
15207 
15208 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15209 
15210 	if (gbl_driver_id == -1) {
15211 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15212 		return TEST_SKIPPED;
15213 	}
15214 
15215 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15216 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15217 
15218 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15219 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15220 	ret = unit_test_suite_runner(&ts);
15221 
15222 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15223 	free(ts.unit_test_suites);
15224 	return ret;
15225 }
15226 
15227 static int
15228 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15229 {
15230 	struct rte_cryptodev_info dev_info;
15231 	uint8_t i, nb_devs;
15232 	int driver_id;
15233 
15234 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
15235 	if (driver_id == -1) {
15236 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15237 		return TEST_SKIPPED;
15238 	}
15239 
15240 	nb_devs = rte_cryptodev_count();
15241 	if (nb_devs < 1) {
15242 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15243 		return TEST_SKIPPED;
15244 	}
15245 
15246 	for (i = 0; i < nb_devs; i++) {
15247 		rte_cryptodev_info_get(i, &dev_info);
15248 		if (dev_info.driver_id == driver_id) {
15249 			if (!(dev_info.feature_flags & flag)) {
15250 				RTE_LOG(INFO, USER1, "%s not supported\n",
15251 						flag_name);
15252 				return TEST_SKIPPED;
15253 			}
15254 			return 0; /* found */
15255 		}
15256 	}
15257 
15258 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15259 	return TEST_SKIPPED;
15260 }
15261 
15262 static int
15263 test_cryptodev_qat(void)
15264 {
15265 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15266 }
15267 
15268 static int
15269 test_cryptodev_virtio(void)
15270 {
15271 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15272 }
15273 
15274 static int
15275 test_cryptodev_aesni_mb(void)
15276 {
15277 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15278 }
15279 
15280 static int
15281 test_cryptodev_cpu_aesni_mb(void)
15282 {
15283 	int32_t rc;
15284 	enum rte_security_session_action_type at = gbl_action_type;
15285 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15286 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15287 	gbl_action_type = at;
15288 	return rc;
15289 }
15290 
15291 static int
15292 test_cryptodev_openssl(void)
15293 {
15294 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15295 }
15296 
15297 static int
15298 test_cryptodev_aesni_gcm(void)
15299 {
15300 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15301 }
15302 
15303 static int
15304 test_cryptodev_cpu_aesni_gcm(void)
15305 {
15306 	int32_t rc;
15307 	enum rte_security_session_action_type at = gbl_action_type;
15308 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15309 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15310 	gbl_action_type = at;
15311 	return rc;
15312 }
15313 
15314 static int
15315 test_cryptodev_mlx5(void)
15316 {
15317 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15318 }
15319 
15320 static int
15321 test_cryptodev_null(void)
15322 {
15323 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15324 }
15325 
15326 static int
15327 test_cryptodev_sw_snow3g(void)
15328 {
15329 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15330 }
15331 
15332 static int
15333 test_cryptodev_sw_kasumi(void)
15334 {
15335 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15336 }
15337 
15338 static int
15339 test_cryptodev_sw_zuc(void)
15340 {
15341 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15342 }
15343 
15344 static int
15345 test_cryptodev_armv8(void)
15346 {
15347 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15348 }
15349 
15350 static int
15351 test_cryptodev_mrvl(void)
15352 {
15353 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15354 }
15355 
15356 #ifdef RTE_CRYPTO_SCHEDULER
15357 
15358 static int
15359 test_cryptodev_scheduler(void)
15360 {
15361 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15362 	const enum blockcipher_test_type blk_suites[] = {
15363 		BLKCIPHER_AES_CHAIN_TYPE,
15364 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15365 		BLKCIPHER_AUTHONLY_TYPE
15366 	};
15367 	static struct unit_test_suite scheduler_multicore = {
15368 		.suite_name = "Scheduler Multicore Unit Test Suite",
15369 		.setup = scheduler_multicore_testsuite_setup,
15370 		.teardown = scheduler_mode_testsuite_teardown,
15371 		.unit_test_cases = {TEST_CASES_END()}
15372 	};
15373 	static struct unit_test_suite scheduler_round_robin = {
15374 		.suite_name = "Scheduler Round Robin Unit Test Suite",
15375 		.setup = scheduler_roundrobin_testsuite_setup,
15376 		.teardown = scheduler_mode_testsuite_teardown,
15377 		.unit_test_cases = {TEST_CASES_END()}
15378 	};
15379 	static struct unit_test_suite scheduler_failover = {
15380 		.suite_name = "Scheduler Failover Unit Test Suite",
15381 		.setup = scheduler_failover_testsuite_setup,
15382 		.teardown = scheduler_mode_testsuite_teardown,
15383 		.unit_test_cases = {TEST_CASES_END()}
15384 	};
15385 	static struct unit_test_suite scheduler_pkt_size_distr = {
15386 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15387 		.setup = scheduler_pkt_size_distr_testsuite_setup,
15388 		.teardown = scheduler_mode_testsuite_teardown,
15389 		.unit_test_cases = {TEST_CASES_END()}
15390 	};
15391 	struct unit_test_suite *sched_mode_suites[] = {
15392 		&scheduler_multicore,
15393 		&scheduler_round_robin,
15394 		&scheduler_failover,
15395 		&scheduler_pkt_size_distr
15396 	};
15397 	static struct unit_test_suite scheduler_config = {
15398 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15399 		.unit_test_cases = {
15400 			TEST_CASE(test_scheduler_attach_worker_op),
15401 			TEST_CASE(test_scheduler_mode_multicore_op),
15402 			TEST_CASE(test_scheduler_mode_roundrobin_op),
15403 			TEST_CASE(test_scheduler_mode_failover_op),
15404 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15405 			TEST_CASE(test_scheduler_detach_worker_op),
15406 
15407 			TEST_CASES_END() /**< NULL terminate array */
15408 		}
15409 	};
15410 	struct unit_test_suite *static_suites[] = {
15411 		&scheduler_config,
15412 		&end_testsuite
15413 	};
15414 	static struct unit_test_suite ts = {
15415 		.suite_name = "Scheduler Unit Test Suite",
15416 		.setup = scheduler_testsuite_setup,
15417 		.teardown = testsuite_teardown,
15418 		.unit_test_cases = {TEST_CASES_END()}
15419 	};
15420 
15421 	gbl_driver_id =	rte_cryptodev_driver_id_get(
15422 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15423 
15424 	if (gbl_driver_id == -1) {
15425 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15426 		return TEST_SKIPPED;
15427 	}
15428 
15429 	if (rte_cryptodev_driver_id_get(
15430 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15431 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15432 		return TEST_SKIPPED;
15433 	}
15434 
15435 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15436 		uint8_t blk_i = 0;
15437 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15438 				(struct unit_test_suite *) *
15439 				(RTE_DIM(blk_suites) + 1));
15440 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15441 				blk_suites, RTE_DIM(blk_suites));
15442 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15443 	}
15444 
15445 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15446 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15447 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15448 			RTE_DIM(sched_mode_suites));
15449 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15450 	ret = unit_test_suite_runner(&ts);
15451 
15452 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15453 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15454 				(*sched_mode_suites[sched_i]),
15455 				RTE_DIM(blk_suites));
15456 		free(sched_mode_suites[sched_i]->unit_test_suites);
15457 	}
15458 	free(ts.unit_test_suites);
15459 	return ret;
15460 }
15461 
15462 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15463 
15464 #endif
15465 
15466 static int
15467 test_cryptodev_dpaa2_sec(void)
15468 {
15469 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15470 }
15471 
15472 static int
15473 test_cryptodev_dpaa_sec(void)
15474 {
15475 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15476 }
15477 
15478 static int
15479 test_cryptodev_ccp(void)
15480 {
15481 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15482 }
15483 
15484 static int
15485 test_cryptodev_octeontx(void)
15486 {
15487 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15488 }
15489 
15490 static int
15491 test_cryptodev_octeontx2(void)
15492 {
15493 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
15494 }
15495 
15496 static int
15497 test_cryptodev_caam_jr(void)
15498 {
15499 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15500 }
15501 
15502 static int
15503 test_cryptodev_nitrox(void)
15504 {
15505 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15506 }
15507 
15508 static int
15509 test_cryptodev_bcmfs(void)
15510 {
15511 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15512 }
15513 
15514 static int
15515 test_cryptodev_qat_raw_api(void)
15516 {
15517 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15518 	int ret;
15519 
15520 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15521 			"RAW API");
15522 	if (ret)
15523 		return ret;
15524 
15525 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15526 	ret = run_cryptodev_testsuite(pmd_name);
15527 	global_api_test_type = CRYPTODEV_API_TEST;
15528 
15529 	return ret;
15530 }
15531 
15532 static int
15533 test_cryptodev_cn9k(void)
15534 {
15535 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15536 }
15537 
15538 static int
15539 test_cryptodev_cn10k(void)
15540 {
15541 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15542 }
15543 
15544 static int
15545 test_cryptodev_dpaa2_sec_raw_api(void)
15546 {
15547 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15548 	int ret;
15549 
15550 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15551 			"RAW API");
15552 	if (ret)
15553 		return ret;
15554 
15555 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15556 	ret = run_cryptodev_testsuite(pmd_name);
15557 	global_api_test_type = CRYPTODEV_API_TEST;
15558 
15559 	return ret;
15560 }
15561 
15562 static int
15563 test_cryptodev_dpaa_sec_raw_api(void)
15564 {
15565 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15566 	int ret;
15567 
15568 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15569 			"RAW API");
15570 	if (ret)
15571 		return ret;
15572 
15573 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15574 	ret = run_cryptodev_testsuite(pmd_name);
15575 	global_api_test_type = CRYPTODEV_API_TEST;
15576 
15577 	return ret;
15578 }
15579 
15580 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
15581 		test_cryptodev_dpaa2_sec_raw_api);
15582 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
15583 		test_cryptodev_dpaa_sec_raw_api);
15584 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15585 		test_cryptodev_qat_raw_api);
15586 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15587 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15588 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15589 	test_cryptodev_cpu_aesni_mb);
15590 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15591 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15592 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15593 	test_cryptodev_cpu_aesni_gcm);
15594 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15595 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15596 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15597 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15598 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15599 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15600 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15601 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15602 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15603 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15604 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15605 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15606 REGISTER_TEST_COMMAND(cryptodev_octeontx2_autotest, test_cryptodev_octeontx2);
15607 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15608 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15609 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15610 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15611 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
15612