xref: /dpdk/app/test/test_cryptodev.c (revision b7986bde)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2015-2020 Intel Corporation
3  * Copyright 2020 NXP
4  */
5 
6 #include <time.h>
7 
8 #include <rte_common.h>
9 #include <rte_hexdump.h>
10 #include <rte_mbuf.h>
11 #include <rte_malloc.h>
12 #include <rte_memcpy.h>
13 #include <rte_pause.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_ether.h>
16 
17 #include <rte_crypto.h>
18 #include <rte_cryptodev.h>
19 #include <rte_ip.h>
20 #include <rte_string_fns.h>
21 #include <rte_tcp.h>
22 #include <rte_udp.h>
23 
24 #ifdef RTE_CRYPTO_SCHEDULER
25 #include <rte_cryptodev_scheduler.h>
26 #include <rte_cryptodev_scheduler_operations.h>
27 #endif
28 
29 #include <rte_lcore.h>
30 
31 #include "test.h"
32 #include "test_cryptodev.h"
33 
34 #include "test_cryptodev_blockcipher.h"
35 #include "test_cryptodev_aes_test_vectors.h"
36 #include "test_cryptodev_des_test_vectors.h"
37 #include "test_cryptodev_hash_test_vectors.h"
38 #include "test_cryptodev_kasumi_test_vectors.h"
39 #include "test_cryptodev_kasumi_hash_test_vectors.h"
40 #include "test_cryptodev_snow3g_test_vectors.h"
41 #include "test_cryptodev_snow3g_hash_test_vectors.h"
42 #include "test_cryptodev_zuc_test_vectors.h"
43 #include "test_cryptodev_aead_test_vectors.h"
44 #include "test_cryptodev_hmac_test_vectors.h"
45 #include "test_cryptodev_mixed_test_vectors.h"
46 #ifdef RTE_LIB_SECURITY
47 #include "test_cryptodev_security_ipsec.h"
48 #include "test_cryptodev_security_ipsec_test_vectors.h"
49 #include "test_cryptodev_security_pdcp_test_vectors.h"
50 #include "test_cryptodev_security_pdcp_sdap_test_vectors.h"
51 #include "test_cryptodev_security_pdcp_test_func.h"
52 #include "test_cryptodev_security_docsis_test_vectors.h"
53 
54 #define SDAP_DISABLED	0
55 #define SDAP_ENABLED	1
56 #endif
57 
58 #define VDEV_ARGS_SIZE 100
59 #define MAX_NB_SESSIONS 4
60 
61 #define MAX_DRV_SERVICE_CTX_SIZE 256
62 
63 #define MAX_RAW_DEQUEUE_COUNT	65535
64 
65 #define IN_PLACE 0
66 #define OUT_OF_PLACE 1
67 
68 static int gbl_driver_id;
69 
70 static enum rte_security_session_action_type gbl_action_type =
71 	RTE_SECURITY_ACTION_TYPE_NONE;
72 
73 enum cryptodev_api_test_type global_api_test_type = CRYPTODEV_API_TEST;
74 
75 struct crypto_unittest_params {
76 	struct rte_crypto_sym_xform cipher_xform;
77 	struct rte_crypto_sym_xform auth_xform;
78 	struct rte_crypto_sym_xform aead_xform;
79 #ifdef RTE_LIB_SECURITY
80 	struct rte_security_docsis_xform docsis_xform;
81 #endif
82 
83 	union {
84 		struct rte_cryptodev_sym_session *sess;
85 #ifdef RTE_LIB_SECURITY
86 		struct rte_security_session *sec_session;
87 #endif
88 	};
89 #ifdef RTE_LIB_SECURITY
90 	enum rte_security_session_action_type type;
91 #endif
92 	struct rte_crypto_op *op;
93 
94 	struct rte_mbuf *obuf, *ibuf;
95 
96 	uint8_t *digest;
97 };
98 
99 #define ALIGN_POW2_ROUNDUP(num, align) \
100 	(((num) + (align) - 1) & ~((align) - 1))
101 
102 #define ADD_STATIC_TESTSUITE(index, parent_ts, child_ts, num_child_ts)	\
103 	for (j = 0; j < num_child_ts; index++, j++)			\
104 		parent_ts.unit_test_suites[index] = child_ts[j]
105 
106 #define ADD_BLOCKCIPHER_TESTSUITE(index, parent_ts, blk_types, num_blk_types)	\
107 	for (j = 0; j < num_blk_types; index++, j++)				\
108 		parent_ts.unit_test_suites[index] =				\
109 				build_blockcipher_test_suite(blk_types[j])
110 
111 #define FREE_BLOCKCIPHER_TESTSUITE(index, parent_ts, num_blk_types)		\
112 	for (j = index; j < index + num_blk_types; j++)				\
113 		free_blockcipher_test_suite(parent_ts.unit_test_suites[j])
114 
115 /*
116  * Forward declarations.
117  */
118 static int
119 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
120 		struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
121 		uint8_t *hmac_key);
122 
123 static int
124 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
125 		struct crypto_unittest_params *ut_params,
126 		struct crypto_testsuite_params *ts_param,
127 		const uint8_t *cipher,
128 		const uint8_t *digest,
129 		const uint8_t *iv);
130 
131 static int
132 security_proto_supported(enum rte_security_session_action_type action,
133 	enum rte_security_session_protocol proto);
134 
135 static int
136 dev_configure_and_start(uint64_t ff_disable);
137 
138 static struct rte_mbuf *
139 setup_test_string(struct rte_mempool *mpool,
140 		const char *string, size_t len, uint8_t blocksize)
141 {
142 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
143 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
144 
145 	if (m) {
146 		char *dst;
147 
148 		memset(m->buf_addr, 0, m->buf_len);
149 		dst = rte_pktmbuf_append(m, t_len);
150 		if (!dst) {
151 			rte_pktmbuf_free(m);
152 			return NULL;
153 		}
154 		if (string != NULL)
155 			rte_memcpy(dst, string, t_len);
156 		else
157 			memset(dst, 0, t_len);
158 	}
159 
160 	return m;
161 }
162 
163 /* Get number of bytes in X bits (rounding up) */
164 static uint32_t
165 ceil_byte_length(uint32_t num_bits)
166 {
167 	if (num_bits % 8)
168 		return ((num_bits >> 3) + 1);
169 	else
170 		return (num_bits >> 3);
171 }
172 
173 static void
174 post_process_raw_dp_op(void *user_data,	uint32_t index __rte_unused,
175 		uint8_t is_op_success)
176 {
177 	struct rte_crypto_op *op = user_data;
178 	op->status = is_op_success ? RTE_CRYPTO_OP_STATUS_SUCCESS :
179 			RTE_CRYPTO_OP_STATUS_ERROR;
180 }
181 
182 static struct crypto_testsuite_params testsuite_params = { NULL };
183 struct crypto_testsuite_params *p_testsuite_params = &testsuite_params;
184 static struct crypto_unittest_params unittest_params;
185 
186 void
187 process_sym_raw_dp_op(uint8_t dev_id, uint16_t qp_id,
188 		struct rte_crypto_op *op, uint8_t is_cipher, uint8_t is_auth,
189 		uint8_t len_in_bits, uint8_t cipher_iv_len)
190 {
191 	struct rte_crypto_sym_op *sop = op->sym;
192 	struct rte_crypto_op *ret_op = NULL;
193 	struct rte_crypto_vec data_vec[UINT8_MAX], dest_data_vec[UINT8_MAX];
194 	struct rte_crypto_va_iova_ptr cipher_iv, digest, aad_auth_iv;
195 	union rte_crypto_sym_ofs ofs;
196 	struct rte_crypto_sym_vec vec;
197 	struct rte_crypto_sgl sgl, dest_sgl;
198 	uint32_t max_len;
199 	union rte_cryptodev_session_ctx sess;
200 	uint64_t auth_end_iova;
201 	uint32_t count = 0;
202 	struct rte_crypto_raw_dp_ctx *ctx;
203 	uint32_t cipher_offset = 0, cipher_len = 0, auth_offset = 0,
204 			auth_len = 0;
205 	int32_t n;
206 	uint32_t n_success;
207 	int ctx_service_size;
208 	int32_t status = 0;
209 	int enqueue_status, dequeue_status;
210 	struct crypto_unittest_params *ut_params = &unittest_params;
211 	int is_sgl = sop->m_src->nb_segs > 1;
212 
213 	ctx_service_size = rte_cryptodev_get_raw_dp_ctx_size(dev_id);
214 	if (ctx_service_size < 0) {
215 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
216 		return;
217 	}
218 
219 	ctx = malloc(ctx_service_size);
220 	if (!ctx) {
221 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
222 		return;
223 	}
224 
225 	/* Both are enums, setting crypto_sess will suit any session type */
226 	sess.crypto_sess = op->sym->session;
227 
228 	if (rte_cryptodev_configure_raw_dp_ctx(dev_id, qp_id, ctx,
229 			op->sess_type, sess, 0) < 0) {
230 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
231 		goto exit;
232 	}
233 
234 	cipher_iv.iova = 0;
235 	cipher_iv.va = NULL;
236 	aad_auth_iv.iova = 0;
237 	aad_auth_iv.va = NULL;
238 	digest.iova = 0;
239 	digest.va = NULL;
240 	sgl.vec = data_vec;
241 	vec.num = 1;
242 	vec.src_sgl = &sgl;
243 	vec.iv = &cipher_iv;
244 	vec.digest = &digest;
245 	vec.aad = &aad_auth_iv;
246 	vec.status = &status;
247 
248 	ofs.raw = 0;
249 
250 	if (is_cipher && is_auth) {
251 		cipher_offset = sop->cipher.data.offset;
252 		cipher_len = sop->cipher.data.length;
253 		auth_offset = sop->auth.data.offset;
254 		auth_len = sop->auth.data.length;
255 		max_len = RTE_MAX(cipher_offset + cipher_len,
256 				auth_offset + auth_len);
257 		if (len_in_bits) {
258 			max_len = max_len >> 3;
259 			cipher_offset = cipher_offset >> 3;
260 			auth_offset = auth_offset >> 3;
261 			cipher_len = cipher_len >> 3;
262 			auth_len = auth_len >> 3;
263 		}
264 		ofs.ofs.cipher.head = cipher_offset;
265 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
266 		ofs.ofs.auth.head = auth_offset;
267 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
268 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
269 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
270 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
271 				op, void *, IV_OFFSET + cipher_iv_len);
272 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
273 				cipher_iv_len);
274 		digest.va = (void *)sop->auth.digest.data;
275 		digest.iova = sop->auth.digest.phys_addr;
276 
277 		if (is_sgl) {
278 			uint32_t remaining_off = auth_offset + auth_len;
279 			struct rte_mbuf *sgl_buf = sop->m_src;
280 
281 			while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)
282 					&& sgl_buf->next != NULL) {
283 				remaining_off -= rte_pktmbuf_data_len(sgl_buf);
284 				sgl_buf = sgl_buf->next;
285 			}
286 
287 			auth_end_iova = (uint64_t)rte_pktmbuf_iova_offset(
288 				sgl_buf, remaining_off);
289 		} else {
290 			auth_end_iova = rte_pktmbuf_iova(op->sym->m_src) +
291 							 auth_offset + auth_len;
292 		}
293 		/* Then check if digest-encrypted conditions are met */
294 		if ((auth_offset + auth_len < cipher_offset + cipher_len) &&
295 				(digest.iova == auth_end_iova) && is_sgl)
296 			max_len = RTE_MAX(max_len, auth_offset + auth_len +
297 				ut_params->auth_xform.auth.digest_length);
298 
299 	} else if (is_cipher) {
300 		cipher_offset = sop->cipher.data.offset;
301 		cipher_len = sop->cipher.data.length;
302 		max_len = cipher_len + cipher_offset;
303 		if (len_in_bits) {
304 			max_len = max_len >> 3;
305 			cipher_offset = cipher_offset >> 3;
306 			cipher_len = cipher_len >> 3;
307 		}
308 		ofs.ofs.cipher.head = cipher_offset;
309 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
310 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
311 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
312 
313 	} else if (is_auth) {
314 		auth_offset = sop->auth.data.offset;
315 		auth_len = sop->auth.data.length;
316 		max_len = auth_len + auth_offset;
317 		if (len_in_bits) {
318 			max_len = max_len >> 3;
319 			auth_offset = auth_offset >> 3;
320 			auth_len = auth_len >> 3;
321 		}
322 		ofs.ofs.auth.head = auth_offset;
323 		ofs.ofs.auth.tail = max_len - auth_offset - auth_len;
324 		aad_auth_iv.va = rte_crypto_op_ctod_offset(
325 				op, void *, IV_OFFSET + cipher_iv_len);
326 		aad_auth_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET +
327 				cipher_iv_len);
328 		digest.va = (void *)sop->auth.digest.data;
329 		digest.iova = sop->auth.digest.phys_addr;
330 
331 	} else { /* aead */
332 		cipher_offset = sop->aead.data.offset;
333 		cipher_len = sop->aead.data.length;
334 		max_len = cipher_len + cipher_offset;
335 		if (len_in_bits) {
336 			max_len = max_len >> 3;
337 			cipher_offset = cipher_offset >> 3;
338 			cipher_len = cipher_len >> 3;
339 		}
340 		ofs.ofs.cipher.head = cipher_offset;
341 		ofs.ofs.cipher.tail = max_len - cipher_offset - cipher_len;
342 		cipher_iv.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
343 		cipher_iv.iova = rte_crypto_op_ctophys_offset(op, IV_OFFSET);
344 		aad_auth_iv.va = (void *)sop->aead.aad.data;
345 		aad_auth_iv.iova = sop->aead.aad.phys_addr;
346 		digest.va = (void *)sop->aead.digest.data;
347 		digest.iova = sop->aead.digest.phys_addr;
348 	}
349 
350 	n = rte_crypto_mbuf_to_vec(sop->m_src, 0, max_len,
351 			data_vec, RTE_DIM(data_vec));
352 	if (n < 0 || n > sop->m_src->nb_segs) {
353 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
354 		goto exit;
355 	}
356 
357 	sgl.num = n;
358 	/* Out of place */
359 	if (sop->m_dst != NULL) {
360 		dest_sgl.vec = dest_data_vec;
361 		vec.dest_sgl = &dest_sgl;
362 		n = rte_crypto_mbuf_to_vec(sop->m_dst, 0, max_len,
363 				dest_data_vec, RTE_DIM(dest_data_vec));
364 		if (n < 0 || n > sop->m_dst->nb_segs) {
365 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
366 			goto exit;
367 		}
368 		dest_sgl.num = n;
369 	} else
370 		vec.dest_sgl = NULL;
371 
372 	if (rte_cryptodev_raw_enqueue_burst(ctx, &vec, ofs, (void **)&op,
373 			&enqueue_status) < 1) {
374 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
375 		goto exit;
376 	}
377 
378 	if (enqueue_status == 0) {
379 		status = rte_cryptodev_raw_enqueue_done(ctx, 1);
380 		if (status < 0) {
381 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
382 			goto exit;
383 		}
384 	} else if (enqueue_status < 0) {
385 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
386 		goto exit;
387 	}
388 
389 	n = n_success = 0;
390 	while (count++ < MAX_RAW_DEQUEUE_COUNT && n == 0) {
391 		n = rte_cryptodev_raw_dequeue_burst(ctx,
392 			NULL, 1, post_process_raw_dp_op,
393 				(void **)&ret_op, 0, &n_success,
394 				&dequeue_status);
395 		if (dequeue_status < 0) {
396 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
397 			goto exit;
398 		}
399 		if (n == 0)
400 			rte_pause();
401 	}
402 
403 	if (n == 1 && dequeue_status == 0) {
404 		if (rte_cryptodev_raw_dequeue_done(ctx, 1) < 0) {
405 			op->status = RTE_CRYPTO_OP_STATUS_ERROR;
406 			goto exit;
407 		}
408 	}
409 
410 	op->status = (count == MAX_RAW_DEQUEUE_COUNT + 1 || ret_op != op ||
411 			ret_op->status == RTE_CRYPTO_OP_STATUS_ERROR ||
412 			n_success < 1) ? RTE_CRYPTO_OP_STATUS_ERROR :
413 					RTE_CRYPTO_OP_STATUS_SUCCESS;
414 
415 exit:
416 	free(ctx);
417 }
418 
419 static void
420 process_cpu_aead_op(uint8_t dev_id, struct rte_crypto_op *op)
421 {
422 	int32_t n, st;
423 	struct rte_crypto_sym_op *sop;
424 	union rte_crypto_sym_ofs ofs;
425 	struct rte_crypto_sgl sgl;
426 	struct rte_crypto_sym_vec symvec;
427 	struct rte_crypto_va_iova_ptr iv_ptr, aad_ptr, digest_ptr;
428 	struct rte_crypto_vec vec[UINT8_MAX];
429 
430 	sop = op->sym;
431 
432 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->aead.data.offset,
433 		sop->aead.data.length, vec, RTE_DIM(vec));
434 
435 	if (n < 0 || n != sop->m_src->nb_segs) {
436 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
437 		return;
438 	}
439 
440 	sgl.vec = vec;
441 	sgl.num = n;
442 	symvec.src_sgl = &sgl;
443 	symvec.iv = &iv_ptr;
444 	symvec.digest = &digest_ptr;
445 	symvec.aad = &aad_ptr;
446 	symvec.status = &st;
447 	symvec.num = 1;
448 
449 	/* for CPU crypto the IOVA address is not required */
450 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
451 	digest_ptr.va = (void *)sop->aead.digest.data;
452 	aad_ptr.va = (void *)sop->aead.aad.data;
453 
454 	ofs.raw = 0;
455 
456 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
457 		&symvec);
458 
459 	if (n != 1)
460 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
461 	else
462 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
463 }
464 
465 static void
466 process_cpu_crypt_auth_op(uint8_t dev_id, struct rte_crypto_op *op)
467 {
468 	int32_t n, st;
469 	struct rte_crypto_sym_op *sop;
470 	union rte_crypto_sym_ofs ofs;
471 	struct rte_crypto_sgl sgl;
472 	struct rte_crypto_sym_vec symvec;
473 	struct rte_crypto_va_iova_ptr iv_ptr, digest_ptr;
474 	struct rte_crypto_vec vec[UINT8_MAX];
475 
476 	sop = op->sym;
477 
478 	n = rte_crypto_mbuf_to_vec(sop->m_src, sop->auth.data.offset,
479 		sop->auth.data.length, vec, RTE_DIM(vec));
480 
481 	if (n < 0 || n != sop->m_src->nb_segs) {
482 		op->status = RTE_CRYPTO_OP_STATUS_ERROR;
483 		return;
484 	}
485 
486 	sgl.vec = vec;
487 	sgl.num = n;
488 	symvec.src_sgl = &sgl;
489 	symvec.iv = &iv_ptr;
490 	symvec.digest = &digest_ptr;
491 	symvec.status = &st;
492 	symvec.num = 1;
493 
494 	iv_ptr.va = rte_crypto_op_ctod_offset(op, void *, IV_OFFSET);
495 	digest_ptr.va = (void *)sop->auth.digest.data;
496 
497 	ofs.raw = 0;
498 	ofs.ofs.cipher.head = sop->cipher.data.offset - sop->auth.data.offset;
499 	ofs.ofs.cipher.tail = (sop->auth.data.offset + sop->auth.data.length) -
500 		(sop->cipher.data.offset + sop->cipher.data.length);
501 
502 	n = rte_cryptodev_sym_cpu_crypto_process(dev_id, sop->session, ofs,
503 		&symvec);
504 
505 	if (n != 1)
506 		op->status = RTE_CRYPTO_OP_STATUS_AUTH_FAILED;
507 	else
508 		op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
509 }
510 
511 static struct rte_crypto_op *
512 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
513 {
514 
515 	RTE_VERIFY(gbl_action_type != RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO);
516 
517 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
518 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
519 		return NULL;
520 	}
521 
522 	op = NULL;
523 
524 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
525 		rte_pause();
526 
527 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
528 		RTE_LOG(DEBUG, USER1, "Operation status %d\n", op->status);
529 		return NULL;
530 	}
531 
532 	return op;
533 }
534 
535 static int
536 testsuite_setup(void)
537 {
538 	struct crypto_testsuite_params *ts_params = &testsuite_params;
539 	struct rte_cryptodev_info info;
540 	uint32_t i = 0, nb_devs, dev_id;
541 	uint16_t qp_id;
542 
543 	memset(ts_params, 0, sizeof(*ts_params));
544 
545 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
546 	if (ts_params->mbuf_pool == NULL) {
547 		/* Not already created so create */
548 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
549 				"CRYPTO_MBUFPOOL",
550 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
551 				rte_socket_id());
552 		if (ts_params->mbuf_pool == NULL) {
553 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
554 			return TEST_FAILED;
555 		}
556 	}
557 
558 	ts_params->large_mbuf_pool = rte_mempool_lookup(
559 			"CRYPTO_LARGE_MBUFPOOL");
560 	if (ts_params->large_mbuf_pool == NULL) {
561 		/* Not already created so create */
562 		ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
563 				"CRYPTO_LARGE_MBUFPOOL",
564 				1, 0, 0, UINT16_MAX,
565 				rte_socket_id());
566 		if (ts_params->large_mbuf_pool == NULL) {
567 			RTE_LOG(ERR, USER1,
568 				"Can't create CRYPTO_LARGE_MBUFPOOL\n");
569 			return TEST_FAILED;
570 		}
571 	}
572 
573 	ts_params->op_mpool = rte_crypto_op_pool_create(
574 			"MBUF_CRYPTO_SYM_OP_POOL",
575 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
576 			NUM_MBUFS, MBUF_CACHE_SIZE,
577 			DEFAULT_NUM_XFORMS *
578 			sizeof(struct rte_crypto_sym_xform) +
579 			MAXIMUM_IV_LENGTH,
580 			rte_socket_id());
581 	if (ts_params->op_mpool == NULL) {
582 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
583 		return TEST_FAILED;
584 	}
585 
586 	nb_devs = rte_cryptodev_count();
587 	if (nb_devs < 1) {
588 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
589 		return TEST_SKIPPED;
590 	}
591 
592 	if (rte_cryptodev_device_count_by_driver(gbl_driver_id) < 1) {
593 		RTE_LOG(WARNING, USER1, "No %s devices found?\n",
594 				rte_cryptodev_driver_name_get(gbl_driver_id));
595 		return TEST_SKIPPED;
596 	}
597 
598 	/* Create list of valid crypto devs */
599 	for (i = 0; i < nb_devs; i++) {
600 		rte_cryptodev_info_get(i, &info);
601 		if (info.driver_id == gbl_driver_id)
602 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
603 	}
604 
605 	if (ts_params->valid_dev_count < 1)
606 		return TEST_FAILED;
607 
608 	/* Set up all the qps on the first of the valid devices found */
609 
610 	dev_id = ts_params->valid_devs[0];
611 
612 	rte_cryptodev_info_get(dev_id, &info);
613 
614 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
615 	ts_params->conf.socket_id = SOCKET_ID_ANY;
616 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY;
617 
618 	unsigned int session_size =
619 		rte_cryptodev_sym_get_private_session_size(dev_id);
620 
621 #ifdef RTE_LIB_SECURITY
622 	unsigned int security_session_size = rte_security_session_get_size(
623 			rte_cryptodev_get_sec_ctx(dev_id));
624 
625 	if (session_size < security_session_size)
626 		session_size = security_session_size;
627 #endif
628 	/*
629 	 * Create mempool with maximum number of sessions.
630 	 */
631 	if (info.sym.max_nb_sessions != 0 &&
632 			info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
633 		RTE_LOG(ERR, USER1, "Device does not support "
634 				"at least %u sessions\n",
635 				MAX_NB_SESSIONS);
636 		return TEST_FAILED;
637 	}
638 
639 	ts_params->session_mpool = rte_cryptodev_sym_session_pool_create(
640 			"test_sess_mp", MAX_NB_SESSIONS, 0, 0, 0,
641 			SOCKET_ID_ANY);
642 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
643 			"session mempool allocation failed");
644 
645 	ts_params->session_priv_mpool = rte_mempool_create(
646 			"test_sess_mp_priv",
647 			MAX_NB_SESSIONS,
648 			session_size,
649 			0, 0, NULL, NULL, NULL,
650 			NULL, SOCKET_ID_ANY,
651 			0);
652 	TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
653 			"session mempool allocation failed");
654 
655 
656 
657 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
658 			&ts_params->conf),
659 			"Failed to configure cryptodev %u with %u qps",
660 			dev_id, ts_params->conf.nb_queue_pairs);
661 
662 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
663 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
664 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
665 
666 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
667 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
668 			dev_id, qp_id, &ts_params->qp_conf,
669 			rte_cryptodev_socket_id(dev_id)),
670 			"Failed to setup queue pair %u on cryptodev %u",
671 			qp_id, dev_id);
672 	}
673 
674 	return TEST_SUCCESS;
675 }
676 
677 static void
678 testsuite_teardown(void)
679 {
680 	struct crypto_testsuite_params *ts_params = &testsuite_params;
681 	int res;
682 
683 	if (ts_params->mbuf_pool != NULL) {
684 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
685 		rte_mempool_avail_count(ts_params->mbuf_pool));
686 	}
687 
688 	if (ts_params->op_mpool != NULL) {
689 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
690 		rte_mempool_avail_count(ts_params->op_mpool));
691 	}
692 
693 	/* Free session mempools */
694 	if (ts_params->session_priv_mpool != NULL) {
695 		rte_mempool_free(ts_params->session_priv_mpool);
696 		ts_params->session_priv_mpool = NULL;
697 	}
698 
699 	if (ts_params->session_mpool != NULL) {
700 		rte_mempool_free(ts_params->session_mpool);
701 		ts_params->session_mpool = NULL;
702 	}
703 
704 	res = rte_cryptodev_close(ts_params->valid_devs[0]);
705 	if (res)
706 		RTE_LOG(ERR, USER1, "Crypto device close error %d\n", res);
707 }
708 
709 static int
710 check_capabilities_supported(enum rte_crypto_sym_xform_type type,
711 		const int *algs, uint16_t num_algs)
712 {
713 	uint8_t dev_id = testsuite_params.valid_devs[0];
714 	bool some_alg_supported = FALSE;
715 	uint16_t i;
716 
717 	for (i = 0; i < num_algs && !some_alg_supported; i++) {
718 		struct rte_cryptodev_sym_capability_idx alg = {
719 			type, {algs[i]}
720 		};
721 		if (rte_cryptodev_sym_capability_get(dev_id,
722 				&alg) != NULL)
723 			some_alg_supported = TRUE;
724 	}
725 	if (!some_alg_supported)
726 		return TEST_SKIPPED;
727 
728 	return 0;
729 }
730 
731 int
732 check_cipher_capabilities_supported(const enum rte_crypto_cipher_algorithm *ciphers,
733 		uint16_t num_ciphers)
734 {
735 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_CIPHER,
736 			(const int *) ciphers, num_ciphers);
737 }
738 
739 int
740 check_auth_capabilities_supported(const enum rte_crypto_auth_algorithm *auths,
741 		uint16_t num_auths)
742 {
743 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AUTH,
744 			(const int *) auths, num_auths);
745 }
746 
747 int
748 check_aead_capabilities_supported(const enum rte_crypto_aead_algorithm *aeads,
749 		uint16_t num_aeads)
750 {
751 	return check_capabilities_supported(RTE_CRYPTO_SYM_XFORM_AEAD,
752 			(const int *) aeads, num_aeads);
753 }
754 
755 static int
756 null_testsuite_setup(void)
757 {
758 	struct crypto_testsuite_params *ts_params = &testsuite_params;
759 	uint8_t dev_id = ts_params->valid_devs[0];
760 	struct rte_cryptodev_info dev_info;
761 	const enum rte_crypto_cipher_algorithm ciphers[] = {
762 		RTE_CRYPTO_CIPHER_NULL
763 	};
764 	const enum rte_crypto_auth_algorithm auths[] = {
765 		RTE_CRYPTO_AUTH_NULL
766 	};
767 
768 	rte_cryptodev_info_get(dev_id, &dev_info);
769 
770 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
771 		RTE_LOG(INFO, USER1, "Feature flag requirements for NULL "
772 				"testsuite not met\n");
773 		return TEST_SKIPPED;
774 	}
775 
776 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
777 			&& check_auth_capabilities_supported(auths,
778 			RTE_DIM(auths)) != 0) {
779 		RTE_LOG(INFO, USER1, "Capability requirements for NULL "
780 				"testsuite not met\n");
781 		return TEST_SKIPPED;
782 	}
783 
784 	return 0;
785 }
786 
787 static int
788 crypto_gen_testsuite_setup(void)
789 {
790 	struct crypto_testsuite_params *ts_params = &testsuite_params;
791 	uint8_t dev_id = ts_params->valid_devs[0];
792 	struct rte_cryptodev_info dev_info;
793 
794 	rte_cryptodev_info_get(dev_id, &dev_info);
795 
796 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
797 		RTE_LOG(INFO, USER1, "Feature flag requirements for Crypto Gen "
798 				"testsuite not met\n");
799 		return TEST_SKIPPED;
800 	}
801 
802 	return 0;
803 }
804 
805 #ifdef RTE_LIB_SECURITY
806 static int
807 ipsec_proto_testsuite_setup(void)
808 {
809 	struct crypto_testsuite_params *ts_params = &testsuite_params;
810 	struct crypto_unittest_params *ut_params = &unittest_params;
811 	struct rte_cryptodev_info dev_info;
812 	int ret = 0;
813 
814 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
815 
816 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SECURITY)) {
817 		RTE_LOG(INFO, USER1, "Feature flag requirements for IPsec Proto "
818 				"testsuite not met\n");
819 		return TEST_SKIPPED;
820 	}
821 
822 	/* Reconfigure to enable security */
823 	ret = dev_configure_and_start(0);
824 	if (ret != TEST_SUCCESS)
825 		return ret;
826 
827 	/* Set action type */
828 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
829 
830 	if (security_proto_supported(
831 			RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
832 			RTE_SECURITY_PROTOCOL_IPSEC) < 0) {
833 		RTE_LOG(INFO, USER1, "Capability requirements for IPsec Proto "
834 				"test not met\n");
835 		ret = TEST_SKIPPED;
836 	}
837 
838 	test_ipsec_alg_list_populate();
839 
840 	/*
841 	 * Stop the device. Device would be started again by individual test
842 	 * case setup routine.
843 	 */
844 	rte_cryptodev_stop(ts_params->valid_devs[0]);
845 
846 	return ret;
847 }
848 
849 static int
850 pdcp_proto_testsuite_setup(void)
851 {
852 	struct crypto_testsuite_params *ts_params = &testsuite_params;
853 	uint8_t dev_id = ts_params->valid_devs[0];
854 	struct rte_cryptodev_info dev_info;
855 	const enum rte_crypto_cipher_algorithm ciphers[] = {
856 		RTE_CRYPTO_CIPHER_NULL,
857 		RTE_CRYPTO_CIPHER_AES_CTR,
858 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
859 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
860 	};
861 	const enum rte_crypto_auth_algorithm auths[] = {
862 		RTE_CRYPTO_AUTH_NULL,
863 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
864 		RTE_CRYPTO_AUTH_AES_CMAC,
865 		RTE_CRYPTO_AUTH_ZUC_EIA3
866 	};
867 
868 	rte_cryptodev_info_get(dev_id, &dev_info);
869 
870 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
871 			!(dev_info.feature_flags &
872 			RTE_CRYPTODEV_FF_SECURITY)) {
873 		RTE_LOG(INFO, USER1, "Feature flag requirements for PDCP Proto "
874 				"testsuite not met\n");
875 		return TEST_SKIPPED;
876 	}
877 
878 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
879 			&& check_auth_capabilities_supported(auths,
880 			RTE_DIM(auths)) != 0) {
881 		RTE_LOG(INFO, USER1, "Capability requirements for PDCP Proto "
882 				"testsuite not met\n");
883 		return TEST_SKIPPED;
884 	}
885 
886 	return 0;
887 }
888 
889 static int
890 docsis_proto_testsuite_setup(void)
891 {
892 	struct crypto_testsuite_params *ts_params = &testsuite_params;
893 	uint8_t dev_id = ts_params->valid_devs[0];
894 	struct rte_cryptodev_info dev_info;
895 	const enum rte_crypto_cipher_algorithm ciphers[] = {
896 		RTE_CRYPTO_CIPHER_AES_DOCSISBPI
897 	};
898 
899 	rte_cryptodev_info_get(dev_id, &dev_info);
900 
901 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
902 			!(dev_info.feature_flags &
903 			RTE_CRYPTODEV_FF_SECURITY)) {
904 		RTE_LOG(INFO, USER1, "Feature flag requirements for DOCSIS "
905 				"Proto testsuite not met\n");
906 		return TEST_SKIPPED;
907 	}
908 
909 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0) {
910 		RTE_LOG(INFO, USER1, "Capability requirements for DOCSIS Proto "
911 				"testsuite not met\n");
912 		return TEST_SKIPPED;
913 	}
914 
915 	return 0;
916 }
917 #endif
918 
919 static int
920 aes_ccm_auth_testsuite_setup(void)
921 {
922 	struct crypto_testsuite_params *ts_params = &testsuite_params;
923 	uint8_t dev_id = ts_params->valid_devs[0];
924 	struct rte_cryptodev_info dev_info;
925 	const enum rte_crypto_aead_algorithm aeads[] = {
926 		RTE_CRYPTO_AEAD_AES_CCM
927 	};
928 
929 	rte_cryptodev_info_get(dev_id, &dev_info);
930 
931 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
932 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
933 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
934 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES CCM "
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 CCM "
941 				"testsuite not met\n");
942 		return TEST_SKIPPED;
943 	}
944 
945 	return 0;
946 }
947 
948 static int
949 aes_gcm_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_aead_algorithm aeads[] = {
955 		RTE_CRYPTO_AEAD_AES_GCM
956 	};
957 
958 	rte_cryptodev_info_get(dev_id, &dev_info);
959 
960 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
961 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GCM "
962 				"testsuite not met\n");
963 		return TEST_SKIPPED;
964 	}
965 
966 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
967 		RTE_LOG(INFO, USER1, "Capability requirements for AES GCM "
968 				"testsuite not met\n");
969 		return TEST_SKIPPED;
970 	}
971 
972 	return 0;
973 }
974 
975 static int
976 aes_gmac_auth_testsuite_setup(void)
977 {
978 	struct crypto_testsuite_params *ts_params = &testsuite_params;
979 	uint8_t dev_id = ts_params->valid_devs[0];
980 	struct rte_cryptodev_info dev_info;
981 	const enum rte_crypto_auth_algorithm auths[] = {
982 		RTE_CRYPTO_AUTH_AES_GMAC
983 	};
984 
985 	rte_cryptodev_info_get(dev_id, &dev_info);
986 
987 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
988 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
989 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
990 		RTE_LOG(INFO, USER1, "Feature flag requirements for AES GMAC "
991 				"testsuite not met\n");
992 		return TEST_SKIPPED;
993 	}
994 
995 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
996 		RTE_LOG(INFO, USER1, "Capability requirements for AES GMAC "
997 				"testsuite not met\n");
998 		return TEST_SKIPPED;
999 	}
1000 
1001 	return 0;
1002 }
1003 
1004 static int
1005 chacha20_poly1305_testsuite_setup(void)
1006 {
1007 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1008 	uint8_t dev_id = ts_params->valid_devs[0];
1009 	struct rte_cryptodev_info dev_info;
1010 	const enum rte_crypto_aead_algorithm aeads[] = {
1011 		RTE_CRYPTO_AEAD_CHACHA20_POLY1305
1012 	};
1013 
1014 	rte_cryptodev_info_get(dev_id, &dev_info);
1015 
1016 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1017 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1018 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1019 		RTE_LOG(INFO, USER1, "Feature flag requirements for "
1020 				"Chacha20-Poly1305 testsuite not met\n");
1021 		return TEST_SKIPPED;
1022 	}
1023 
1024 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1025 		RTE_LOG(INFO, USER1, "Capability requirements for "
1026 				"Chacha20-Poly1305 testsuite not met\n");
1027 		return TEST_SKIPPED;
1028 	}
1029 
1030 	return 0;
1031 }
1032 
1033 static int
1034 snow3g_testsuite_setup(void)
1035 {
1036 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1037 	uint8_t dev_id = ts_params->valid_devs[0];
1038 	struct rte_cryptodev_info dev_info;
1039 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1040 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1041 
1042 	};
1043 	const enum rte_crypto_auth_algorithm auths[] = {
1044 		RTE_CRYPTO_AUTH_SNOW3G_UIA2
1045 	};
1046 
1047 	rte_cryptodev_info_get(dev_id, &dev_info);
1048 
1049 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1050 		RTE_LOG(INFO, USER1, "Feature flag requirements for Snow3G "
1051 				"testsuite not met\n");
1052 		return TEST_SKIPPED;
1053 	}
1054 
1055 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1056 			&& check_auth_capabilities_supported(auths,
1057 			RTE_DIM(auths)) != 0) {
1058 		RTE_LOG(INFO, USER1, "Capability requirements for Snow3G "
1059 				"testsuite not met\n");
1060 		return TEST_SKIPPED;
1061 	}
1062 
1063 	return 0;
1064 }
1065 
1066 static int
1067 zuc_testsuite_setup(void)
1068 {
1069 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1070 	uint8_t dev_id = ts_params->valid_devs[0];
1071 	struct rte_cryptodev_info dev_info;
1072 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1073 		RTE_CRYPTO_CIPHER_ZUC_EEA3
1074 	};
1075 	const enum rte_crypto_auth_algorithm auths[] = {
1076 		RTE_CRYPTO_AUTH_ZUC_EIA3
1077 	};
1078 
1079 	rte_cryptodev_info_get(dev_id, &dev_info);
1080 
1081 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1082 		RTE_LOG(INFO, USER1, "Feature flag requirements for ZUC "
1083 				"testsuite not met\n");
1084 		return TEST_SKIPPED;
1085 	}
1086 
1087 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1088 			&& check_auth_capabilities_supported(auths,
1089 			RTE_DIM(auths)) != 0) {
1090 		RTE_LOG(INFO, USER1, "Capability requirements for ZUC "
1091 				"testsuite not met\n");
1092 		return TEST_SKIPPED;
1093 	}
1094 
1095 	return 0;
1096 }
1097 
1098 static int
1099 hmac_md5_auth_testsuite_setup(void)
1100 {
1101 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1102 	uint8_t dev_id = ts_params->valid_devs[0];
1103 	struct rte_cryptodev_info dev_info;
1104 	const enum rte_crypto_auth_algorithm auths[] = {
1105 		RTE_CRYPTO_AUTH_MD5_HMAC
1106 	};
1107 
1108 	rte_cryptodev_info_get(dev_id, &dev_info);
1109 
1110 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1111 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1112 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1113 		RTE_LOG(INFO, USER1, "Feature flag requirements for HMAC MD5 "
1114 				"Auth testsuite not met\n");
1115 		return TEST_SKIPPED;
1116 	}
1117 
1118 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1119 		RTE_LOG(INFO, USER1, "Capability requirements for HMAC MD5 "
1120 				"testsuite not met\n");
1121 		return TEST_SKIPPED;
1122 	}
1123 
1124 	return 0;
1125 }
1126 
1127 static int
1128 kasumi_testsuite_setup(void)
1129 {
1130 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1131 	uint8_t dev_id = ts_params->valid_devs[0];
1132 	struct rte_cryptodev_info dev_info;
1133 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1134 		RTE_CRYPTO_CIPHER_KASUMI_F8
1135 	};
1136 	const enum rte_crypto_auth_algorithm auths[] = {
1137 		RTE_CRYPTO_AUTH_KASUMI_F9
1138 	};
1139 
1140 	rte_cryptodev_info_get(dev_id, &dev_info);
1141 
1142 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1143 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1144 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1145 		RTE_LOG(INFO, USER1, "Feature flag requirements for Kasumi "
1146 				"testsuite not met\n");
1147 		return TEST_SKIPPED;
1148 	}
1149 
1150 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1151 			&& check_auth_capabilities_supported(auths,
1152 			RTE_DIM(auths)) != 0) {
1153 		RTE_LOG(INFO, USER1, "Capability requirements for Kasumi "
1154 				"testsuite not met\n");
1155 		return TEST_SKIPPED;
1156 	}
1157 
1158 	return 0;
1159 }
1160 
1161 static int
1162 negative_aes_gcm_testsuite_setup(void)
1163 {
1164 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1165 	uint8_t dev_id = ts_params->valid_devs[0];
1166 	struct rte_cryptodev_info dev_info;
1167 	const enum rte_crypto_aead_algorithm aeads[] = {
1168 		RTE_CRYPTO_AEAD_AES_GCM
1169 	};
1170 
1171 	rte_cryptodev_info_get(dev_id, &dev_info);
1172 
1173 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1174 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1175 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1176 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1177 				"AES GCM testsuite not met\n");
1178 		return TEST_SKIPPED;
1179 	}
1180 
1181 	if (check_aead_capabilities_supported(aeads, RTE_DIM(aeads)) != 0) {
1182 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1183 				"AES GCM testsuite not met\n");
1184 		return TEST_SKIPPED;
1185 	}
1186 
1187 	return 0;
1188 }
1189 
1190 static int
1191 negative_aes_gmac_testsuite_setup(void)
1192 {
1193 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1194 	uint8_t dev_id = ts_params->valid_devs[0];
1195 	struct rte_cryptodev_info dev_info;
1196 	const enum rte_crypto_auth_algorithm auths[] = {
1197 		RTE_CRYPTO_AUTH_AES_GMAC
1198 	};
1199 
1200 	rte_cryptodev_info_get(dev_id, &dev_info);
1201 
1202 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1203 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1204 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1205 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1206 				"AES GMAC testsuite not met\n");
1207 		return TEST_SKIPPED;
1208 	}
1209 
1210 	if (check_auth_capabilities_supported(auths, RTE_DIM(auths)) != 0) {
1211 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1212 				"AES GMAC testsuite not met\n");
1213 		return TEST_SKIPPED;
1214 	}
1215 
1216 	return 0;
1217 }
1218 
1219 static int
1220 mixed_cipher_hash_testsuite_setup(void)
1221 {
1222 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1223 	uint8_t dev_id = ts_params->valid_devs[0];
1224 	struct rte_cryptodev_info dev_info;
1225 	uint64_t feat_flags;
1226 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1227 		RTE_CRYPTO_CIPHER_NULL,
1228 		RTE_CRYPTO_CIPHER_AES_CTR,
1229 		RTE_CRYPTO_CIPHER_ZUC_EEA3,
1230 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
1231 	};
1232 	const enum rte_crypto_auth_algorithm auths[] = {
1233 		RTE_CRYPTO_AUTH_NULL,
1234 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1235 		RTE_CRYPTO_AUTH_AES_CMAC,
1236 		RTE_CRYPTO_AUTH_ZUC_EIA3
1237 	};
1238 
1239 	rte_cryptodev_info_get(dev_id, &dev_info);
1240 	feat_flags = dev_info.feature_flags;
1241 
1242 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1243 			(global_api_test_type == CRYPTODEV_RAW_API_TEST)) {
1244 		RTE_LOG(INFO, USER1, "Feature flag requirements for Mixed "
1245 				"Cipher Hash testsuite not met\n");
1246 		return TEST_SKIPPED;
1247 	}
1248 
1249 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1250 			&& check_auth_capabilities_supported(auths,
1251 			RTE_DIM(auths)) != 0) {
1252 		RTE_LOG(INFO, USER1, "Capability requirements for Mixed "
1253 				"Cipher Hash testsuite not met\n");
1254 		return TEST_SKIPPED;
1255 	}
1256 
1257 	return 0;
1258 }
1259 
1260 static int
1261 esn_testsuite_setup(void)
1262 {
1263 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1264 	uint8_t dev_id = ts_params->valid_devs[0];
1265 	struct rte_cryptodev_info dev_info;
1266 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1267 		RTE_CRYPTO_CIPHER_AES_CBC
1268 	};
1269 	const enum rte_crypto_auth_algorithm auths[] = {
1270 		RTE_CRYPTO_AUTH_SHA1_HMAC
1271 	};
1272 
1273 	rte_cryptodev_info_get(dev_id, &dev_info);
1274 
1275 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1276 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1277 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1278 		RTE_LOG(INFO, USER1, "Feature flag requirements for ESN "
1279 				"testsuite not met\n");
1280 		return TEST_SKIPPED;
1281 	}
1282 
1283 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1284 			&& check_auth_capabilities_supported(auths,
1285 			RTE_DIM(auths)) != 0) {
1286 		RTE_LOG(INFO, USER1, "Capability requirements for ESN "
1287 				"testsuite not met\n");
1288 		return TEST_SKIPPED;
1289 	}
1290 
1291 	return 0;
1292 }
1293 
1294 static int
1295 multi_session_testsuite_setup(void)
1296 {
1297 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1298 	uint8_t dev_id = ts_params->valid_devs[0];
1299 	struct rte_cryptodev_info dev_info;
1300 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1301 		RTE_CRYPTO_CIPHER_AES_CBC
1302 	};
1303 	const enum rte_crypto_auth_algorithm auths[] = {
1304 		RTE_CRYPTO_AUTH_SHA512_HMAC
1305 	};
1306 
1307 	rte_cryptodev_info_get(dev_id, &dev_info);
1308 
1309 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO)) {
1310 		RTE_LOG(INFO, USER1, "Feature flag requirements for Multi "
1311 				"Session testsuite not met\n");
1312 		return TEST_SKIPPED;
1313 	}
1314 
1315 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1316 			&& check_auth_capabilities_supported(auths,
1317 			RTE_DIM(auths)) != 0) {
1318 		RTE_LOG(INFO, USER1, "Capability requirements for Multi "
1319 				"Session testsuite not met\n");
1320 		return TEST_SKIPPED;
1321 	}
1322 
1323 	return 0;
1324 }
1325 
1326 static int
1327 negative_hmac_sha1_testsuite_setup(void)
1328 {
1329 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1330 	uint8_t dev_id = ts_params->valid_devs[0];
1331 	struct rte_cryptodev_info dev_info;
1332 	const enum rte_crypto_cipher_algorithm ciphers[] = {
1333 		RTE_CRYPTO_CIPHER_AES_CBC
1334 	};
1335 	const enum rte_crypto_auth_algorithm auths[] = {
1336 		RTE_CRYPTO_AUTH_SHA1_HMAC
1337 	};
1338 
1339 	rte_cryptodev_info_get(dev_id, &dev_info);
1340 
1341 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO) ||
1342 			((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
1343 			!(dev_info.feature_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
1344 		RTE_LOG(INFO, USER1, "Feature flag requirements for Negative "
1345 				"HMAC SHA1 testsuite not met\n");
1346 		return TEST_SKIPPED;
1347 	}
1348 
1349 	if (check_cipher_capabilities_supported(ciphers, RTE_DIM(ciphers)) != 0
1350 			&& check_auth_capabilities_supported(auths,
1351 			RTE_DIM(auths)) != 0) {
1352 		RTE_LOG(INFO, USER1, "Capability requirements for Negative "
1353 				"HMAC SHA1 testsuite not met\n");
1354 		return TEST_SKIPPED;
1355 	}
1356 
1357 	return 0;
1358 }
1359 
1360 static int
1361 dev_configure_and_start(uint64_t ff_disable)
1362 {
1363 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1364 	struct crypto_unittest_params *ut_params = &unittest_params;
1365 
1366 	uint16_t qp_id;
1367 
1368 	/* Clear unit test parameters before running test */
1369 	memset(ut_params, 0, sizeof(*ut_params));
1370 
1371 	/* Reconfigure device to default parameters */
1372 	ts_params->conf.socket_id = SOCKET_ID_ANY;
1373 	ts_params->conf.ff_disable = ff_disable;
1374 	ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
1375 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
1376 	ts_params->qp_conf.mp_session_private = ts_params->session_priv_mpool;
1377 
1378 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1379 			&ts_params->conf),
1380 			"Failed to configure cryptodev %u",
1381 			ts_params->valid_devs[0]);
1382 
1383 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
1384 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1385 			ts_params->valid_devs[0], qp_id,
1386 			&ts_params->qp_conf,
1387 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1388 			"Failed to setup queue pair %u on cryptodev %u",
1389 			qp_id, ts_params->valid_devs[0]);
1390 	}
1391 
1392 
1393 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1394 
1395 	/* Start the device */
1396 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1397 			"Failed to start cryptodev %u",
1398 			ts_params->valid_devs[0]);
1399 
1400 	return TEST_SUCCESS;
1401 }
1402 
1403 int
1404 ut_setup(void)
1405 {
1406 	/* Configure and start the device with security feature disabled */
1407 	return dev_configure_and_start(RTE_CRYPTODEV_FF_SECURITY);
1408 }
1409 
1410 static int
1411 ut_setup_security(void)
1412 {
1413 	/* Configure and start the device with no features disabled */
1414 	return dev_configure_and_start(0);
1415 }
1416 
1417 void
1418 ut_teardown(void)
1419 {
1420 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1421 	struct crypto_unittest_params *ut_params = &unittest_params;
1422 
1423 	/* free crypto session structure */
1424 #ifdef RTE_LIB_SECURITY
1425 	if (ut_params->type == RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL) {
1426 		if (ut_params->sec_session) {
1427 			rte_security_session_destroy(rte_cryptodev_get_sec_ctx
1428 						(ts_params->valid_devs[0]),
1429 						ut_params->sec_session);
1430 			ut_params->sec_session = NULL;
1431 		}
1432 	} else
1433 #endif
1434 	{
1435 		if (ut_params->sess) {
1436 			rte_cryptodev_sym_session_clear(
1437 					ts_params->valid_devs[0],
1438 					ut_params->sess);
1439 			rte_cryptodev_sym_session_free(ut_params->sess);
1440 			ut_params->sess = NULL;
1441 		}
1442 	}
1443 
1444 	/* free crypto operation structure */
1445 	if (ut_params->op)
1446 		rte_crypto_op_free(ut_params->op);
1447 
1448 	/*
1449 	 * free mbuf - both obuf and ibuf are usually the same,
1450 	 * so check if they point at the same address is necessary,
1451 	 * to avoid freeing the mbuf twice.
1452 	 */
1453 	if (ut_params->obuf) {
1454 		rte_pktmbuf_free(ut_params->obuf);
1455 		if (ut_params->ibuf == ut_params->obuf)
1456 			ut_params->ibuf = 0;
1457 		ut_params->obuf = 0;
1458 	}
1459 	if (ut_params->ibuf) {
1460 		rte_pktmbuf_free(ut_params->ibuf);
1461 		ut_params->ibuf = 0;
1462 	}
1463 
1464 	if (ts_params->mbuf_pool != NULL)
1465 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
1466 			rte_mempool_avail_count(ts_params->mbuf_pool));
1467 
1468 	/* Stop the device */
1469 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1470 }
1471 
1472 static int
1473 test_device_configure_invalid_dev_id(void)
1474 {
1475 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1476 	uint16_t dev_id, num_devs = 0;
1477 
1478 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
1479 			"Need at least %d devices for test", 1);
1480 
1481 	/* valid dev_id values */
1482 	dev_id = ts_params->valid_devs[0];
1483 
1484 	/* Stop the device in case it's started so it can be configured */
1485 	rte_cryptodev_stop(dev_id);
1486 
1487 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
1488 			"Failed test for rte_cryptodev_configure: "
1489 			"invalid dev_num %u", dev_id);
1490 
1491 	/* invalid dev_id values */
1492 	dev_id = num_devs;
1493 
1494 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1495 			"Failed test for rte_cryptodev_configure: "
1496 			"invalid dev_num %u", dev_id);
1497 
1498 	dev_id = 0xff;
1499 
1500 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
1501 			"Failed test for rte_cryptodev_configure:"
1502 			"invalid dev_num %u", dev_id);
1503 
1504 	return TEST_SUCCESS;
1505 }
1506 
1507 static int
1508 test_device_configure_invalid_queue_pair_ids(void)
1509 {
1510 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1511 	uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
1512 
1513 	/* Stop the device in case it's started so it can be configured */
1514 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1515 
1516 	/* valid - max value queue pairs */
1517 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1518 
1519 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1520 			&ts_params->conf),
1521 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1522 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
1523 
1524 	/* valid - one queue pairs */
1525 	ts_params->conf.nb_queue_pairs = 1;
1526 
1527 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1528 			&ts_params->conf),
1529 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
1530 			ts_params->valid_devs[0],
1531 			ts_params->conf.nb_queue_pairs);
1532 
1533 
1534 	/* invalid - zero queue pairs */
1535 	ts_params->conf.nb_queue_pairs = 0;
1536 
1537 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1538 			&ts_params->conf),
1539 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1540 			" invalid qps: %u",
1541 			ts_params->valid_devs[0],
1542 			ts_params->conf.nb_queue_pairs);
1543 
1544 
1545 	/* invalid - max value supported by field queue pairs */
1546 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
1547 
1548 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1549 			&ts_params->conf),
1550 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1551 			" invalid qps: %u",
1552 			ts_params->valid_devs[0],
1553 			ts_params->conf.nb_queue_pairs);
1554 
1555 
1556 	/* invalid - max value + 1 queue pairs */
1557 	ts_params->conf.nb_queue_pairs = orig_nb_qps + 1;
1558 
1559 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
1560 			&ts_params->conf),
1561 			"Failed test for rte_cryptodev_configure, dev_id %u,"
1562 			" invalid qps: %u",
1563 			ts_params->valid_devs[0],
1564 			ts_params->conf.nb_queue_pairs);
1565 
1566 	/* revert to original testsuite value */
1567 	ts_params->conf.nb_queue_pairs = orig_nb_qps;
1568 
1569 	return TEST_SUCCESS;
1570 }
1571 
1572 static int
1573 test_queue_pair_descriptor_setup(void)
1574 {
1575 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1576 	struct rte_cryptodev_qp_conf qp_conf = {
1577 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
1578 	};
1579 	uint16_t qp_id;
1580 
1581 	/* Stop the device in case it's started so it can be configured */
1582 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1583 
1584 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
1585 			&ts_params->conf),
1586 			"Failed to configure cryptodev %u",
1587 			ts_params->valid_devs[0]);
1588 
1589 	/*
1590 	 * Test various ring sizes on this device. memzones can't be
1591 	 * freed so are re-used if ring is released and re-created.
1592 	 */
1593 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
1594 	qp_conf.mp_session = ts_params->session_mpool;
1595 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
1596 
1597 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1598 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1599 				ts_params->valid_devs[0], qp_id, &qp_conf,
1600 				rte_cryptodev_socket_id(
1601 						ts_params->valid_devs[0])),
1602 				"Failed test for "
1603 				"rte_cryptodev_queue_pair_setup: num_inflights "
1604 				"%u on qp %u on cryptodev %u",
1605 				qp_conf.nb_descriptors, qp_id,
1606 				ts_params->valid_devs[0]);
1607 	}
1608 
1609 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
1610 
1611 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1612 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1613 				ts_params->valid_devs[0], qp_id, &qp_conf,
1614 				rte_cryptodev_socket_id(
1615 						ts_params->valid_devs[0])),
1616 				"Failed test for"
1617 				" rte_cryptodev_queue_pair_setup: num_inflights"
1618 				" %u on qp %u on cryptodev %u",
1619 				qp_conf.nb_descriptors, qp_id,
1620 				ts_params->valid_devs[0]);
1621 	}
1622 
1623 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
1624 
1625 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1626 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1627 				ts_params->valid_devs[0], qp_id, &qp_conf,
1628 				rte_cryptodev_socket_id(
1629 						ts_params->valid_devs[0])),
1630 				"Failed test for "
1631 				"rte_cryptodev_queue_pair_setup: num_inflights"
1632 				" %u on qp %u on cryptodev %u",
1633 				qp_conf.nb_descriptors, qp_id,
1634 				ts_params->valid_devs[0]);
1635 	}
1636 
1637 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
1638 
1639 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
1640 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
1641 				ts_params->valid_devs[0], qp_id, &qp_conf,
1642 				rte_cryptodev_socket_id(
1643 						ts_params->valid_devs[0])),
1644 				"Failed test for"
1645 				" rte_cryptodev_queue_pair_setup:"
1646 				"num_inflights %u on qp %u on cryptodev %u",
1647 				qp_conf.nb_descriptors, qp_id,
1648 				ts_params->valid_devs[0]);
1649 	}
1650 
1651 	/* test invalid queue pair id */
1652 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
1653 
1654 	qp_id = ts_params->conf.nb_queue_pairs;		/*invalid */
1655 
1656 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1657 			ts_params->valid_devs[0],
1658 			qp_id, &qp_conf,
1659 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1660 			"Failed test for rte_cryptodev_queue_pair_setup:"
1661 			"invalid qp %u on cryptodev %u",
1662 			qp_id, ts_params->valid_devs[0]);
1663 
1664 	qp_id = 0xffff; /*invalid*/
1665 
1666 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
1667 			ts_params->valid_devs[0],
1668 			qp_id, &qp_conf,
1669 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
1670 			"Failed test for rte_cryptodev_queue_pair_setup:"
1671 			"invalid qp %u on cryptodev %u",
1672 			qp_id, ts_params->valid_devs[0]);
1673 
1674 	return TEST_SUCCESS;
1675 }
1676 
1677 /* ***** Plaintext data for tests ***** */
1678 
1679 const char catch_22_quote_1[] =
1680 		"There was only one catch and that was Catch-22, which "
1681 		"specified that a concern for one's safety in the face of "
1682 		"dangers that were real and immediate was the process of a "
1683 		"rational mind. Orr was crazy and could be grounded. All he "
1684 		"had to do was ask; and as soon as he did, he would no longer "
1685 		"be crazy and would have to fly more missions. Orr would be "
1686 		"crazy to fly more missions and sane if he didn't, but if he "
1687 		"was sane he had to fly them. If he flew them he was crazy "
1688 		"and didn't have to; but if he didn't want to he was sane and "
1689 		"had to. Yossarian was moved very deeply by the absolute "
1690 		"simplicity of this clause of Catch-22 and let out a "
1691 		"respectful whistle. \"That's some catch, that Catch-22\", he "
1692 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
1693 
1694 const char catch_22_quote[] =
1695 		"What a lousy earth! He wondered how many people were "
1696 		"destitute that same night even in his own prosperous country, "
1697 		"how many homes were shanties, how many husbands were drunk "
1698 		"and wives socked, and how many children were bullied, abused, "
1699 		"or abandoned. How many families hungered for food they could "
1700 		"not afford to buy? How many hearts were broken? How many "
1701 		"suicides would take place that same night, how many people "
1702 		"would go insane? How many cockroaches and landlords would "
1703 		"triumph? How many winners were losers, successes failures, "
1704 		"and rich men poor men? How many wise guys were stupid? How "
1705 		"many happy endings were unhappy endings? How many honest men "
1706 		"were liars, brave men cowards, loyal men traitors, how many "
1707 		"sainted men were corrupt, how many people in positions of "
1708 		"trust had sold their souls to bodyguards, how many had never "
1709 		"had souls? How many straight-and-narrow paths were crooked "
1710 		"paths? How many best families were worst families and how "
1711 		"many good people were bad people? When you added them all up "
1712 		"and then subtracted, you might be left with only the children, "
1713 		"and perhaps with Albert Einstein and an old violinist or "
1714 		"sculptor somewhere.";
1715 
1716 #define QUOTE_480_BYTES		(480)
1717 #define QUOTE_512_BYTES		(512)
1718 #define QUOTE_768_BYTES		(768)
1719 #define QUOTE_1024_BYTES	(1024)
1720 
1721 
1722 
1723 /* ***** SHA1 Hash Tests ***** */
1724 
1725 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
1726 
1727 static uint8_t hmac_sha1_key[] = {
1728 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
1729 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
1730 	0xDE, 0xF4, 0xDE, 0xAD };
1731 
1732 /* ***** SHA224 Hash Tests ***** */
1733 
1734 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
1735 
1736 
1737 /* ***** AES-CBC Cipher Tests ***** */
1738 
1739 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
1740 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
1741 
1742 static uint8_t aes_cbc_key[] = {
1743 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
1744 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
1745 
1746 static uint8_t aes_cbc_iv[] = {
1747 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1748 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
1749 
1750 
1751 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
1752 
1753 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
1754 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
1755 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
1756 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
1757 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
1758 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
1759 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
1760 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
1761 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
1762 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
1763 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
1764 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
1765 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
1766 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
1767 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
1768 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
1769 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
1770 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
1771 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
1772 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
1773 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
1774 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
1775 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
1776 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1777 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1778 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
1779 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
1780 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
1781 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
1782 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
1783 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
1784 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
1785 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
1786 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
1787 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
1788 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
1789 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
1790 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
1791 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
1792 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
1793 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
1794 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
1795 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
1796 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
1797 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
1798 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
1799 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
1800 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
1801 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
1802 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
1803 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
1804 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
1805 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
1806 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
1807 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
1808 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
1809 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
1810 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
1811 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
1812 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
1813 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
1814 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
1815 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
1816 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
1817 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
1818 };
1819 
1820 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
1821 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
1822 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1823 	0x18, 0x8c, 0x1d, 0x32
1824 };
1825 
1826 
1827 /* Multisession Vector context Test */
1828 /*Begin Session 0 */
1829 static uint8_t ms_aes_cbc_key0[] = {
1830 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1831 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1832 };
1833 
1834 static uint8_t ms_aes_cbc_iv0[] = {
1835 	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1836 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1837 };
1838 
1839 static const uint8_t ms_aes_cbc_cipher0[] = {
1840 		0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
1841 		0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
1842 		0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
1843 		0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
1844 		0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
1845 		0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
1846 		0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
1847 		0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
1848 		0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
1849 		0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
1850 		0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
1851 		0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
1852 		0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
1853 		0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
1854 		0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
1855 		0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
1856 		0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
1857 		0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
1858 		0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
1859 		0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
1860 		0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
1861 		0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
1862 		0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
1863 		0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
1864 		0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
1865 		0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
1866 		0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
1867 		0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
1868 		0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
1869 		0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
1870 		0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
1871 		0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
1872 		0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
1873 		0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
1874 		0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
1875 		0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
1876 		0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
1877 		0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
1878 		0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
1879 		0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
1880 		0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
1881 		0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
1882 		0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
1883 		0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1884 		0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1885 		0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1886 		0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1887 		0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1888 		0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1889 		0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1890 		0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1891 		0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1892 		0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1893 		0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1894 		0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1895 		0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1896 		0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1897 		0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1898 		0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1899 		0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1900 		0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1901 		0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1902 		0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1903 		0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1904 };
1905 
1906 
1907 static  uint8_t ms_hmac_key0[] = {
1908 		0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1909 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1910 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1911 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1912 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1913 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1914 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1915 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1916 };
1917 
1918 static const uint8_t ms_hmac_digest0[] = {
1919 		0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1920 		0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1921 		0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1922 		0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1923 		0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1924 		0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1925 		0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1926 		0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1927 		};
1928 
1929 /* End Session 0 */
1930 /* Begin session 1 */
1931 
1932 static  uint8_t ms_aes_cbc_key1[] = {
1933 		0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1934 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1935 };
1936 
1937 static  uint8_t ms_aes_cbc_iv1[] = {
1938 	0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1939 	0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1940 };
1941 
1942 static const uint8_t ms_aes_cbc_cipher1[] = {
1943 		0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1944 		0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1945 		0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1946 		0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1947 		0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1948 		0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1949 		0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1950 		0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1951 		0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1952 		0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1953 		0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1954 		0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1955 		0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1956 		0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1957 		0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1958 		0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1959 		0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1960 		0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1961 		0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1962 		0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1963 		0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1964 		0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1965 		0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1966 		0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1967 		0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1968 		0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1969 		0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1970 		0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1971 		0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1972 		0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1973 		0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1974 		0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1975 		0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1976 		0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1977 		0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1978 		0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1979 		0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1980 		0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1981 		0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1982 		0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1983 		0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1984 		0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1985 		0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1986 		0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1987 		0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1988 		0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1989 		0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1990 		0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1991 		0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1992 		0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1993 		0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1994 		0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1995 		0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1996 		0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1997 		0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1998 		0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1999 		0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
2000 		0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
2001 		0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
2002 		0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
2003 		0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
2004 		0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
2005 		0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
2006 		0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
2007 
2008 };
2009 
2010 static uint8_t ms_hmac_key1[] = {
2011 		0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2012 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2013 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2014 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2015 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2016 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2017 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2018 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2019 };
2020 
2021 static const uint8_t ms_hmac_digest1[] = {
2022 		0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
2023 		0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
2024 		0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
2025 		0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
2026 		0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
2027 		0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
2028 		0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
2029 		0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
2030 };
2031 /* End Session 1  */
2032 /* Begin Session 2 */
2033 static  uint8_t ms_aes_cbc_key2[] = {
2034 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2035 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2036 };
2037 
2038 static  uint8_t ms_aes_cbc_iv2[] = {
2039 		0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
2040 		0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
2041 };
2042 
2043 static const uint8_t ms_aes_cbc_cipher2[] = {
2044 		0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
2045 		0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
2046 		0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
2047 		0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
2048 		0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
2049 		0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
2050 		0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
2051 		0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
2052 		0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
2053 		0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
2054 		0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
2055 		0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
2056 		0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
2057 		0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
2058 		0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
2059 		0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
2060 		0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
2061 		0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
2062 		0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
2063 		0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
2064 		0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
2065 		0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
2066 		0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
2067 		0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
2068 		0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
2069 		0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
2070 		0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
2071 		0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
2072 		0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
2073 		0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
2074 		0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
2075 		0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
2076 		0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
2077 		0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
2078 		0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
2079 		0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
2080 		0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
2081 		0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
2082 		0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
2083 		0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
2084 		0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
2085 		0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
2086 		0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
2087 		0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
2088 		0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
2089 		0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
2090 		0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
2091 		0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
2092 		0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
2093 		0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
2094 		0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
2095 		0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
2096 		0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
2097 		0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
2098 		0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
2099 		0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
2100 		0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
2101 		0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
2102 		0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
2103 		0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
2104 		0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
2105 		0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
2106 		0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
2107 		0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
2108 };
2109 
2110 static  uint8_t ms_hmac_key2[] = {
2111 		0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
2112 		0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2113 		0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2114 		0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
2115 		0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
2116 		0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2117 		0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
2118 		0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
2119 };
2120 
2121 static const uint8_t ms_hmac_digest2[] = {
2122 		0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
2123 		0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
2124 		0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
2125 		0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
2126 		0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
2127 		0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
2128 		0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
2129 		0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
2130 };
2131 
2132 /* End Session 2 */
2133 
2134 
2135 static int
2136 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
2137 {
2138 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2139 	struct crypto_unittest_params *ut_params = &unittest_params;
2140 	int status;
2141 
2142 	/* Verify the capabilities */
2143 	struct rte_cryptodev_sym_capability_idx cap_idx;
2144 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2145 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
2146 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2147 			&cap_idx) == NULL)
2148 		return TEST_SKIPPED;
2149 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2150 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
2151 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
2152 			&cap_idx) == NULL)
2153 		return TEST_SKIPPED;
2154 
2155 	/* Generate test mbuf data and space for digest */
2156 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2157 			catch_22_quote,	QUOTE_512_BYTES, 0);
2158 
2159 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2160 			DIGEST_BYTE_LENGTH_SHA1);
2161 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2162 
2163 	/* Setup Cipher Parameters */
2164 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2165 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2166 
2167 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2168 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2169 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2170 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2171 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2172 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2173 
2174 	/* Setup HMAC Parameters */
2175 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2176 
2177 	ut_params->auth_xform.next = NULL;
2178 
2179 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2180 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
2181 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
2182 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
2183 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
2184 
2185 	ut_params->sess = rte_cryptodev_sym_session_create(
2186 			ts_params->session_mpool);
2187 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2188 
2189 	/* Create crypto session*/
2190 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
2191 			ut_params->sess, &ut_params->cipher_xform,
2192 			ts_params->session_priv_mpool);
2193 
2194 	if (status == -ENOTSUP)
2195 		return TEST_SKIPPED;
2196 
2197 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
2198 
2199 	/* Generate crypto op data structure */
2200 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2201 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2202 	TEST_ASSERT_NOT_NULL(ut_params->op,
2203 			"Failed to allocate symmetric crypto operation struct");
2204 
2205 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2206 
2207 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2208 
2209 	/* set crypto operation source mbuf */
2210 	sym_op->m_src = ut_params->ibuf;
2211 
2212 	/* Set crypto operation authentication parameters */
2213 	sym_op->auth.digest.data = ut_params->digest;
2214 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2215 			ut_params->ibuf, QUOTE_512_BYTES);
2216 
2217 	sym_op->auth.data.offset = 0;
2218 	sym_op->auth.data.length = QUOTE_512_BYTES;
2219 
2220 	/* Copy IV at the end of the crypto operation */
2221 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2222 			aes_cbc_iv, CIPHER_IV_LENGTH_AES_CBC);
2223 
2224 	/* Set crypto operation cipher parameters */
2225 	sym_op->cipher.data.offset = 0;
2226 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2227 
2228 	/* Process crypto operation */
2229 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2230 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2231 			ut_params->op);
2232 	else
2233 		TEST_ASSERT_NOT_NULL(
2234 			process_crypto_request(ts_params->valid_devs[0],
2235 				ut_params->op),
2236 				"failed to process sym crypto op");
2237 
2238 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2239 			"crypto op processing failed");
2240 
2241 	/* Validate obuf */
2242 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
2243 			uint8_t *);
2244 
2245 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
2246 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2247 			QUOTE_512_BYTES,
2248 			"ciphertext data not as expected");
2249 
2250 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
2251 
2252 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
2253 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
2254 			gbl_driver_id == rte_cryptodev_driver_id_get(
2255 					RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) ?
2256 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
2257 					DIGEST_BYTE_LENGTH_SHA1,
2258 			"Generated digest data not as expected");
2259 
2260 	return TEST_SUCCESS;
2261 }
2262 
2263 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
2264 
2265 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
2266 
2267 static uint8_t hmac_sha512_key[] = {
2268 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
2269 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
2270 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
2271 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
2272 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
2273 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
2274 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
2275 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
2276 
2277 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
2278 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
2279 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
2280 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
2281 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
2282 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
2283 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
2284 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
2285 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
2286 
2287 
2288 
2289 static int
2290 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2291 		struct crypto_unittest_params *ut_params,
2292 		uint8_t *cipher_key,
2293 		uint8_t *hmac_key);
2294 
2295 static int
2296 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2297 		struct crypto_unittest_params *ut_params,
2298 		struct crypto_testsuite_params *ts_params,
2299 		const uint8_t *cipher,
2300 		const uint8_t *digest,
2301 		const uint8_t *iv);
2302 
2303 
2304 static int
2305 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
2306 		struct crypto_unittest_params *ut_params,
2307 		uint8_t *cipher_key,
2308 		uint8_t *hmac_key)
2309 {
2310 
2311 	/* Setup Cipher Parameters */
2312 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2313 	ut_params->cipher_xform.next = NULL;
2314 
2315 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2316 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2317 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2318 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2319 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2320 	ut_params->cipher_xform.cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2321 
2322 	/* Setup HMAC Parameters */
2323 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2324 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2325 
2326 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2327 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
2328 	ut_params->auth_xform.auth.key.data = hmac_key;
2329 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
2330 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2331 
2332 	return TEST_SUCCESS;
2333 }
2334 
2335 
2336 static int
2337 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2338 		struct crypto_unittest_params *ut_params,
2339 		struct crypto_testsuite_params *ts_params,
2340 		const uint8_t *cipher,
2341 		const uint8_t *digest,
2342 		const uint8_t *iv)
2343 {
2344 	/* Generate test mbuf data and digest */
2345 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2346 			(const char *)
2347 			cipher,
2348 			QUOTE_512_BYTES, 0);
2349 
2350 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2351 			DIGEST_BYTE_LENGTH_SHA512);
2352 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2353 
2354 	rte_memcpy(ut_params->digest,
2355 			digest,
2356 			DIGEST_BYTE_LENGTH_SHA512);
2357 
2358 	/* Generate Crypto op data structure */
2359 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2360 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2361 	TEST_ASSERT_NOT_NULL(ut_params->op,
2362 			"Failed to allocate symmetric crypto operation struct");
2363 
2364 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
2365 
2366 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2367 
2368 	/* set crypto operation source mbuf */
2369 	sym_op->m_src = ut_params->ibuf;
2370 
2371 	sym_op->auth.digest.data = ut_params->digest;
2372 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2373 			ut_params->ibuf, QUOTE_512_BYTES);
2374 
2375 	sym_op->auth.data.offset = 0;
2376 	sym_op->auth.data.length = QUOTE_512_BYTES;
2377 
2378 	/* Copy IV at the end of the crypto operation */
2379 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2380 			iv, CIPHER_IV_LENGTH_AES_CBC);
2381 
2382 	sym_op->cipher.data.offset = 0;
2383 	sym_op->cipher.data.length = QUOTE_512_BYTES;
2384 
2385 	/* Process crypto operation */
2386 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
2387 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
2388 			ut_params->op);
2389 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
2390 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
2391 				ut_params->op, 1, 1, 0, 0);
2392 	else
2393 		TEST_ASSERT_NOT_NULL(
2394 				process_crypto_request(ts_params->valid_devs[0],
2395 					ut_params->op),
2396 					"failed to process sym crypto op");
2397 
2398 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2399 			"crypto op processing failed");
2400 
2401 	ut_params->obuf = ut_params->op->sym->m_src;
2402 
2403 	/* Validate obuf */
2404 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2405 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *),
2406 			catch_22_quote,
2407 			QUOTE_512_BYTES,
2408 			"Plaintext data not as expected");
2409 
2410 	/* Validate obuf */
2411 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2412 			"Digest verification failed");
2413 
2414 	return TEST_SUCCESS;
2415 }
2416 
2417 /* ***** SNOW 3G Tests ***** */
2418 static int
2419 create_wireless_algo_hash_session(uint8_t dev_id,
2420 	const uint8_t *key, const uint8_t key_len,
2421 	const uint8_t iv_len, const uint8_t auth_len,
2422 	enum rte_crypto_auth_operation op,
2423 	enum rte_crypto_auth_algorithm algo)
2424 {
2425 	uint8_t hash_key[key_len];
2426 	int status;
2427 
2428 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2429 	struct crypto_unittest_params *ut_params = &unittest_params;
2430 
2431 	memcpy(hash_key, key, key_len);
2432 
2433 	debug_hexdump(stdout, "key:", key, key_len);
2434 
2435 	/* Setup Authentication Parameters */
2436 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2437 	ut_params->auth_xform.next = NULL;
2438 
2439 	ut_params->auth_xform.auth.op = op;
2440 	ut_params->auth_xform.auth.algo = algo;
2441 	ut_params->auth_xform.auth.key.length = key_len;
2442 	ut_params->auth_xform.auth.key.data = hash_key;
2443 	ut_params->auth_xform.auth.digest_length = auth_len;
2444 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
2445 	ut_params->auth_xform.auth.iv.length = iv_len;
2446 	ut_params->sess = rte_cryptodev_sym_session_create(
2447 			ts_params->session_mpool);
2448 
2449 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2450 			&ut_params->auth_xform,
2451 			ts_params->session_priv_mpool);
2452 	if (status == -ENOTSUP)
2453 		return TEST_SKIPPED;
2454 
2455 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2456 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2457 	return 0;
2458 }
2459 
2460 static int
2461 create_wireless_algo_cipher_session(uint8_t dev_id,
2462 			enum rte_crypto_cipher_operation op,
2463 			enum rte_crypto_cipher_algorithm algo,
2464 			const uint8_t *key, const uint8_t key_len,
2465 			uint8_t iv_len)
2466 {
2467 	uint8_t cipher_key[key_len];
2468 	int status;
2469 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2470 	struct crypto_unittest_params *ut_params = &unittest_params;
2471 
2472 	memcpy(cipher_key, key, key_len);
2473 
2474 	/* Setup Cipher Parameters */
2475 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2476 	ut_params->cipher_xform.next = NULL;
2477 
2478 	ut_params->cipher_xform.cipher.algo = algo;
2479 	ut_params->cipher_xform.cipher.op = op;
2480 	ut_params->cipher_xform.cipher.key.data = cipher_key;
2481 	ut_params->cipher_xform.cipher.key.length = key_len;
2482 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2483 	ut_params->cipher_xform.cipher.iv.length = iv_len;
2484 
2485 	debug_hexdump(stdout, "key:", key, key_len);
2486 
2487 	/* Create Crypto session */
2488 	ut_params->sess = rte_cryptodev_sym_session_create(
2489 			ts_params->session_mpool);
2490 
2491 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2492 			&ut_params->cipher_xform,
2493 			ts_params->session_priv_mpool);
2494 	if (status == -ENOTSUP)
2495 		return TEST_SKIPPED;
2496 
2497 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2498 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2499 	return 0;
2500 }
2501 
2502 static int
2503 create_wireless_algo_cipher_operation(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 
2524 	/* iv */
2525 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2526 			iv, iv_len);
2527 	sym_op->cipher.data.length = cipher_len;
2528 	sym_op->cipher.data.offset = cipher_offset;
2529 	return 0;
2530 }
2531 
2532 static int
2533 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, uint8_t iv_len,
2534 			unsigned int cipher_len,
2535 			unsigned int cipher_offset)
2536 {
2537 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2538 	struct crypto_unittest_params *ut_params = &unittest_params;
2539 
2540 	/* Generate Crypto op data structure */
2541 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2542 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2543 	TEST_ASSERT_NOT_NULL(ut_params->op,
2544 				"Failed to allocate pktmbuf offload");
2545 
2546 	/* Set crypto operation data parameters */
2547 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2548 
2549 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2550 
2551 	/* set crypto operation source mbuf */
2552 	sym_op->m_src = ut_params->ibuf;
2553 	sym_op->m_dst = ut_params->obuf;
2554 
2555 	/* iv */
2556 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2557 			iv, iv_len);
2558 	sym_op->cipher.data.length = cipher_len;
2559 	sym_op->cipher.data.offset = cipher_offset;
2560 	return 0;
2561 }
2562 
2563 static int
2564 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
2565 		enum rte_crypto_cipher_operation cipher_op,
2566 		enum rte_crypto_auth_operation auth_op,
2567 		enum rte_crypto_auth_algorithm auth_algo,
2568 		enum rte_crypto_cipher_algorithm cipher_algo,
2569 		const uint8_t *key, uint8_t key_len,
2570 		uint8_t auth_iv_len, uint8_t auth_len,
2571 		uint8_t cipher_iv_len)
2572 
2573 {
2574 	uint8_t cipher_auth_key[key_len];
2575 	int status;
2576 
2577 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2578 	struct crypto_unittest_params *ut_params = &unittest_params;
2579 
2580 	memcpy(cipher_auth_key, key, key_len);
2581 
2582 	/* Setup Authentication Parameters */
2583 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2584 	ut_params->auth_xform.next = NULL;
2585 
2586 	ut_params->auth_xform.auth.op = auth_op;
2587 	ut_params->auth_xform.auth.algo = auth_algo;
2588 	ut_params->auth_xform.auth.key.length = key_len;
2589 	/* Hash key = cipher key */
2590 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2591 	ut_params->auth_xform.auth.digest_length = auth_len;
2592 	/* Auth IV will be after cipher IV */
2593 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2594 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2595 
2596 	/* Setup Cipher Parameters */
2597 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2598 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2599 
2600 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2601 	ut_params->cipher_xform.cipher.op = cipher_op;
2602 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2603 	ut_params->cipher_xform.cipher.key.length = key_len;
2604 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2605 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2606 
2607 	debug_hexdump(stdout, "key:", key, key_len);
2608 
2609 	/* Create Crypto session*/
2610 	ut_params->sess = rte_cryptodev_sym_session_create(
2611 			ts_params->session_mpool);
2612 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2613 
2614 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2615 			&ut_params->cipher_xform,
2616 			ts_params->session_priv_mpool);
2617 	if (status == -ENOTSUP)
2618 		return TEST_SKIPPED;
2619 
2620 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2621 	return 0;
2622 }
2623 
2624 static int
2625 create_wireless_cipher_auth_session(uint8_t dev_id,
2626 		enum rte_crypto_cipher_operation cipher_op,
2627 		enum rte_crypto_auth_operation auth_op,
2628 		enum rte_crypto_auth_algorithm auth_algo,
2629 		enum rte_crypto_cipher_algorithm cipher_algo,
2630 		const struct wireless_test_data *tdata)
2631 {
2632 	const uint8_t key_len = tdata->key.len;
2633 	uint8_t cipher_auth_key[key_len];
2634 	int status;
2635 
2636 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2637 	struct crypto_unittest_params *ut_params = &unittest_params;
2638 	const uint8_t *key = tdata->key.data;
2639 	const uint8_t auth_len = tdata->digest.len;
2640 	uint8_t cipher_iv_len = tdata->cipher_iv.len;
2641 	uint8_t auth_iv_len = tdata->auth_iv.len;
2642 
2643 	memcpy(cipher_auth_key, key, key_len);
2644 
2645 	/* Setup Authentication Parameters */
2646 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2647 	ut_params->auth_xform.next = NULL;
2648 
2649 	ut_params->auth_xform.auth.op = auth_op;
2650 	ut_params->auth_xform.auth.algo = auth_algo;
2651 	ut_params->auth_xform.auth.key.length = key_len;
2652 	/* Hash key = cipher key */
2653 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
2654 	ut_params->auth_xform.auth.digest_length = auth_len;
2655 	/* Auth IV will be after cipher IV */
2656 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2657 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2658 
2659 	/* Setup Cipher Parameters */
2660 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2661 	ut_params->cipher_xform.next = &ut_params->auth_xform;
2662 
2663 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2664 	ut_params->cipher_xform.cipher.op = cipher_op;
2665 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2666 	ut_params->cipher_xform.cipher.key.length = key_len;
2667 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2668 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2669 
2670 
2671 	debug_hexdump(stdout, "key:", key, key_len);
2672 
2673 	/* Create Crypto session*/
2674 	ut_params->sess = rte_cryptodev_sym_session_create(
2675 			ts_params->session_mpool);
2676 
2677 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2678 			&ut_params->cipher_xform,
2679 			ts_params->session_priv_mpool);
2680 	if (status == -ENOTSUP)
2681 		return TEST_SKIPPED;
2682 
2683 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2684 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2685 	return 0;
2686 }
2687 
2688 static int
2689 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2690 		const struct wireless_test_data *tdata)
2691 {
2692 	return create_wireless_cipher_auth_session(dev_id,
2693 		RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2694 		RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2695 		RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2696 }
2697 
2698 static int
2699 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2700 		enum rte_crypto_cipher_operation cipher_op,
2701 		enum rte_crypto_auth_operation auth_op,
2702 		enum rte_crypto_auth_algorithm auth_algo,
2703 		enum rte_crypto_cipher_algorithm cipher_algo,
2704 		const uint8_t *key, const uint8_t key_len,
2705 		uint8_t auth_iv_len, uint8_t auth_len,
2706 		uint8_t cipher_iv_len)
2707 {
2708 	uint8_t auth_cipher_key[key_len];
2709 	int status;
2710 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2711 	struct crypto_unittest_params *ut_params = &unittest_params;
2712 
2713 	memcpy(auth_cipher_key, key, key_len);
2714 
2715 	/* Setup Authentication Parameters */
2716 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2717 	ut_params->auth_xform.auth.op = auth_op;
2718 	ut_params->auth_xform.next = &ut_params->cipher_xform;
2719 	ut_params->auth_xform.auth.algo = auth_algo;
2720 	ut_params->auth_xform.auth.key.length = key_len;
2721 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
2722 	ut_params->auth_xform.auth.digest_length = auth_len;
2723 	/* Auth IV will be after cipher IV */
2724 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET + cipher_iv_len;
2725 	ut_params->auth_xform.auth.iv.length = auth_iv_len;
2726 
2727 	/* Setup Cipher Parameters */
2728 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2729 	ut_params->cipher_xform.next = NULL;
2730 	ut_params->cipher_xform.cipher.algo = cipher_algo;
2731 	ut_params->cipher_xform.cipher.op = cipher_op;
2732 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2733 	ut_params->cipher_xform.cipher.key.length = key_len;
2734 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
2735 	ut_params->cipher_xform.cipher.iv.length = cipher_iv_len;
2736 
2737 	debug_hexdump(stdout, "key:", key, key_len);
2738 
2739 	/* Create Crypto session*/
2740 	ut_params->sess = rte_cryptodev_sym_session_create(
2741 			ts_params->session_mpool);
2742 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2743 
2744 	if (cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2745 		ut_params->auth_xform.next = NULL;
2746 		ut_params->cipher_xform.next = &ut_params->auth_xform;
2747 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2748 				&ut_params->cipher_xform,
2749 				ts_params->session_priv_mpool);
2750 
2751 	} else
2752 		status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
2753 				&ut_params->auth_xform,
2754 				ts_params->session_priv_mpool);
2755 
2756 	if (status == -ENOTSUP)
2757 		return TEST_SKIPPED;
2758 
2759 	TEST_ASSERT_EQUAL(status, 0, "session init failed");
2760 
2761 	return 0;
2762 }
2763 
2764 static int
2765 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2766 		unsigned int auth_tag_len,
2767 		const uint8_t *iv, unsigned int iv_len,
2768 		unsigned int data_pad_len,
2769 		enum rte_crypto_auth_operation op,
2770 		unsigned int auth_len, unsigned int auth_offset)
2771 {
2772 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2773 
2774 	struct crypto_unittest_params *ut_params = &unittest_params;
2775 
2776 	/* Generate Crypto op data structure */
2777 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2778 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2779 	TEST_ASSERT_NOT_NULL(ut_params->op,
2780 		"Failed to allocate pktmbuf offload");
2781 
2782 	/* Set crypto operation data parameters */
2783 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2784 
2785 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2786 
2787 	/* set crypto operation source mbuf */
2788 	sym_op->m_src = ut_params->ibuf;
2789 
2790 	/* iv */
2791 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
2792 			iv, iv_len);
2793 	/* digest */
2794 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2795 					ut_params->ibuf, auth_tag_len);
2796 
2797 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2798 				"no room to append auth tag");
2799 	ut_params->digest = sym_op->auth.digest.data;
2800 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2801 			ut_params->ibuf, data_pad_len);
2802 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2803 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2804 	else
2805 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2806 
2807 	debug_hexdump(stdout, "digest:",
2808 		sym_op->auth.digest.data,
2809 		auth_tag_len);
2810 
2811 	sym_op->auth.data.length = auth_len;
2812 	sym_op->auth.data.offset = auth_offset;
2813 
2814 	return 0;
2815 }
2816 
2817 static int
2818 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2819 	enum rte_crypto_auth_operation op)
2820 {
2821 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2822 	struct crypto_unittest_params *ut_params = &unittest_params;
2823 
2824 	const uint8_t *auth_tag = tdata->digest.data;
2825 	const unsigned int auth_tag_len = tdata->digest.len;
2826 	unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2827 	unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2828 
2829 	const uint8_t *cipher_iv = tdata->cipher_iv.data;
2830 	const uint8_t cipher_iv_len = tdata->cipher_iv.len;
2831 	const uint8_t *auth_iv = tdata->auth_iv.data;
2832 	const uint8_t auth_iv_len = tdata->auth_iv.len;
2833 	const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2834 	const unsigned int auth_len = tdata->validAuthLenInBits.len;
2835 
2836 	/* Generate Crypto op data structure */
2837 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2838 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2839 	TEST_ASSERT_NOT_NULL(ut_params->op,
2840 			"Failed to allocate pktmbuf offload");
2841 	/* Set crypto operation data parameters */
2842 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2843 
2844 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2845 
2846 	/* set crypto operation source mbuf */
2847 	sym_op->m_src = ut_params->ibuf;
2848 
2849 	/* digest */
2850 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2851 			ut_params->ibuf, auth_tag_len);
2852 
2853 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2854 			"no room to append auth tag");
2855 	ut_params->digest = sym_op->auth.digest.data;
2856 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2857 			ut_params->ibuf, data_pad_len);
2858 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2859 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2860 	else
2861 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2862 
2863 	debug_hexdump(stdout, "digest:",
2864 		sym_op->auth.digest.data,
2865 		auth_tag_len);
2866 
2867 	/* Copy cipher and auth IVs at the end of the crypto operation */
2868 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2869 						IV_OFFSET);
2870 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2871 	iv_ptr += cipher_iv_len;
2872 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2873 
2874 	sym_op->cipher.data.length = cipher_len;
2875 	sym_op->cipher.data.offset = 0;
2876 	sym_op->auth.data.length = auth_len;
2877 	sym_op->auth.data.offset = 0;
2878 
2879 	return 0;
2880 }
2881 
2882 static int
2883 create_zuc_cipher_hash_generate_operation(
2884 		const struct wireless_test_data *tdata)
2885 {
2886 	return create_wireless_cipher_hash_operation(tdata,
2887 		RTE_CRYPTO_AUTH_OP_GENERATE);
2888 }
2889 
2890 static int
2891 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2892 		const unsigned auth_tag_len,
2893 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2894 		unsigned data_pad_len,
2895 		enum rte_crypto_auth_operation op,
2896 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2897 		const unsigned cipher_len, const unsigned cipher_offset,
2898 		const unsigned auth_len, const unsigned auth_offset)
2899 {
2900 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2901 	struct crypto_unittest_params *ut_params = &unittest_params;
2902 
2903 	enum rte_crypto_cipher_algorithm cipher_algo =
2904 			ut_params->cipher_xform.cipher.algo;
2905 	enum rte_crypto_auth_algorithm auth_algo =
2906 			ut_params->auth_xform.auth.algo;
2907 
2908 	/* Generate Crypto op data structure */
2909 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2910 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2911 	TEST_ASSERT_NOT_NULL(ut_params->op,
2912 			"Failed to allocate pktmbuf offload");
2913 	/* Set crypto operation data parameters */
2914 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2915 
2916 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2917 
2918 	/* set crypto operation source mbuf */
2919 	sym_op->m_src = ut_params->ibuf;
2920 
2921 	/* digest */
2922 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2923 			ut_params->ibuf, auth_tag_len);
2924 
2925 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2926 			"no room to append auth tag");
2927 	ut_params->digest = sym_op->auth.digest.data;
2928 
2929 	if (rte_pktmbuf_is_contiguous(ut_params->ibuf)) {
2930 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2931 				ut_params->ibuf, data_pad_len);
2932 	} else {
2933 		struct rte_mbuf *m = ut_params->ibuf;
2934 		unsigned int offset = data_pad_len;
2935 
2936 		while (offset > m->data_len && m->next != NULL) {
2937 			offset -= m->data_len;
2938 			m = m->next;
2939 		}
2940 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
2941 			m, offset);
2942 	}
2943 
2944 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2945 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
2946 	else
2947 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2948 
2949 	debug_hexdump(stdout, "digest:",
2950 		sym_op->auth.digest.data,
2951 		auth_tag_len);
2952 
2953 	/* Copy cipher and auth IVs at the end of the crypto operation */
2954 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op, uint8_t *,
2955 						IV_OFFSET);
2956 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
2957 	iv_ptr += cipher_iv_len;
2958 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
2959 
2960 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
2961 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
2962 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
2963 		sym_op->cipher.data.length = cipher_len;
2964 		sym_op->cipher.data.offset = cipher_offset;
2965 	} else {
2966 		sym_op->cipher.data.length = cipher_len >> 3;
2967 		sym_op->cipher.data.offset = cipher_offset >> 3;
2968 	}
2969 
2970 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
2971 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
2972 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
2973 		sym_op->auth.data.length = auth_len;
2974 		sym_op->auth.data.offset = auth_offset;
2975 	} else {
2976 		sym_op->auth.data.length = auth_len >> 3;
2977 		sym_op->auth.data.offset = auth_offset >> 3;
2978 	}
2979 
2980 	return 0;
2981 }
2982 
2983 static int
2984 create_wireless_algo_auth_cipher_operation(
2985 		const uint8_t *auth_tag, unsigned int auth_tag_len,
2986 		const uint8_t *cipher_iv, uint8_t cipher_iv_len,
2987 		const uint8_t *auth_iv, uint8_t auth_iv_len,
2988 		unsigned int data_pad_len,
2989 		unsigned int cipher_len, unsigned int cipher_offset,
2990 		unsigned int auth_len, unsigned int auth_offset,
2991 		uint8_t op_mode, uint8_t do_sgl, uint8_t verify)
2992 {
2993 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2994 	struct crypto_unittest_params *ut_params = &unittest_params;
2995 
2996 	enum rte_crypto_cipher_algorithm cipher_algo =
2997 			ut_params->cipher_xform.cipher.algo;
2998 	enum rte_crypto_auth_algorithm auth_algo =
2999 			ut_params->auth_xform.auth.algo;
3000 
3001 	/* Generate Crypto op data structure */
3002 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3003 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3004 	TEST_ASSERT_NOT_NULL(ut_params->op,
3005 			"Failed to allocate pktmbuf offload");
3006 
3007 	/* Set crypto operation data parameters */
3008 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3009 
3010 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3011 
3012 	/* set crypto operation mbufs */
3013 	sym_op->m_src = ut_params->ibuf;
3014 	if (op_mode == OUT_OF_PLACE)
3015 		sym_op->m_dst = ut_params->obuf;
3016 
3017 	/* digest */
3018 	if (!do_sgl) {
3019 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(
3020 			(op_mode == IN_PLACE ?
3021 				ut_params->ibuf : ut_params->obuf),
3022 			uint8_t *, data_pad_len);
3023 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
3024 			(op_mode == IN_PLACE ?
3025 				ut_params->ibuf : ut_params->obuf),
3026 			data_pad_len);
3027 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
3028 	} else {
3029 		uint16_t remaining_off = (auth_offset >> 3) + (auth_len >> 3);
3030 		struct rte_mbuf *sgl_buf = (op_mode == IN_PLACE ?
3031 				sym_op->m_src : sym_op->m_dst);
3032 		while (remaining_off >= rte_pktmbuf_data_len(sgl_buf)) {
3033 			remaining_off -= rte_pktmbuf_data_len(sgl_buf);
3034 			sgl_buf = sgl_buf->next;
3035 		}
3036 		sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(sgl_buf,
3037 				uint8_t *, remaining_off);
3038 		sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(sgl_buf,
3039 				remaining_off);
3040 		memset(sym_op->auth.digest.data, 0, remaining_off);
3041 		while (sgl_buf->next != NULL) {
3042 			memset(rte_pktmbuf_mtod(sgl_buf, uint8_t *),
3043 				0, rte_pktmbuf_data_len(sgl_buf));
3044 			sgl_buf = sgl_buf->next;
3045 		}
3046 	}
3047 
3048 	/* Copy digest for the verification */
3049 	if (verify)
3050 		memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3051 
3052 	/* Copy cipher and auth IVs at the end of the crypto operation */
3053 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(
3054 			ut_params->op, uint8_t *, IV_OFFSET);
3055 
3056 	rte_memcpy(iv_ptr, cipher_iv, cipher_iv_len);
3057 	iv_ptr += cipher_iv_len;
3058 	rte_memcpy(iv_ptr, auth_iv, auth_iv_len);
3059 
3060 	/* Only copy over the offset data needed from src to dst in OOP,
3061 	 * if the auth and cipher offsets are not aligned
3062 	 */
3063 	if (op_mode == OUT_OF_PLACE) {
3064 		if (cipher_offset > auth_offset)
3065 			rte_memcpy(
3066 				rte_pktmbuf_mtod_offset(
3067 					sym_op->m_dst,
3068 					uint8_t *, auth_offset >> 3),
3069 				rte_pktmbuf_mtod_offset(
3070 					sym_op->m_src,
3071 					uint8_t *, auth_offset >> 3),
3072 				((cipher_offset >> 3) - (auth_offset >> 3)));
3073 	}
3074 
3075 	if (cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
3076 		cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
3077 		cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) {
3078 		sym_op->cipher.data.length = cipher_len;
3079 		sym_op->cipher.data.offset = cipher_offset;
3080 	} else {
3081 		sym_op->cipher.data.length = cipher_len >> 3;
3082 		sym_op->cipher.data.offset = cipher_offset >> 3;
3083 	}
3084 
3085 	if (auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
3086 		auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
3087 		auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) {
3088 		sym_op->auth.data.length = auth_len;
3089 		sym_op->auth.data.offset = auth_offset;
3090 	} else {
3091 		sym_op->auth.data.length = auth_len >> 3;
3092 		sym_op->auth.data.offset = auth_offset >> 3;
3093 	}
3094 
3095 	return 0;
3096 }
3097 
3098 static int
3099 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
3100 {
3101 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3102 	struct crypto_unittest_params *ut_params = &unittest_params;
3103 
3104 	int retval;
3105 	unsigned plaintext_pad_len;
3106 	unsigned plaintext_len;
3107 	uint8_t *plaintext;
3108 	struct rte_cryptodev_info dev_info;
3109 
3110 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3111 	uint64_t feat_flags = dev_info.feature_flags;
3112 
3113 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3114 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3115 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3116 		return TEST_SKIPPED;
3117 	}
3118 
3119 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3120 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3121 		printf("Device doesn't support RAW data-path APIs.\n");
3122 		return TEST_SKIPPED;
3123 	}
3124 
3125 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3126 		return TEST_SKIPPED;
3127 
3128 	/* Verify the capabilities */
3129 	struct rte_cryptodev_sym_capability_idx cap_idx;
3130 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3131 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3132 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3133 			&cap_idx) == NULL)
3134 		return TEST_SKIPPED;
3135 
3136 	/* Create SNOW 3G session */
3137 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3138 			tdata->key.data, tdata->key.len,
3139 			tdata->auth_iv.len, tdata->digest.len,
3140 			RTE_CRYPTO_AUTH_OP_GENERATE,
3141 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3142 	if (retval < 0)
3143 		return retval;
3144 
3145 	/* alloc mbuf and set payload */
3146 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3147 
3148 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3149 	rte_pktmbuf_tailroom(ut_params->ibuf));
3150 
3151 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3152 	/* Append data which is padded to a multiple of */
3153 	/* the algorithms block size */
3154 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3155 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3156 				plaintext_pad_len);
3157 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3158 
3159 	/* Create SNOW 3G operation */
3160 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3161 			tdata->auth_iv.data, tdata->auth_iv.len,
3162 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3163 			tdata->validAuthLenInBits.len,
3164 			0);
3165 	if (retval < 0)
3166 		return retval;
3167 
3168 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3169 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3170 				ut_params->op, 0, 1, 1, 0);
3171 	else
3172 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3173 				ut_params->op);
3174 	ut_params->obuf = ut_params->op->sym->m_src;
3175 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3176 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3177 			+ plaintext_pad_len;
3178 
3179 	/* Validate obuf */
3180 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3181 	ut_params->digest,
3182 	tdata->digest.data,
3183 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3184 	"SNOW 3G Generated auth tag not as expected");
3185 
3186 	return 0;
3187 }
3188 
3189 static int
3190 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
3191 {
3192 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3193 	struct crypto_unittest_params *ut_params = &unittest_params;
3194 
3195 	int retval;
3196 	unsigned plaintext_pad_len;
3197 	unsigned plaintext_len;
3198 	uint8_t *plaintext;
3199 	struct rte_cryptodev_info dev_info;
3200 
3201 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3202 	uint64_t feat_flags = dev_info.feature_flags;
3203 
3204 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
3205 			((tdata->validAuthLenInBits.len % 8) != 0)) {
3206 		printf("Device doesn't support NON-Byte Aligned Data.\n");
3207 		return TEST_SKIPPED;
3208 	}
3209 
3210 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3211 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3212 		printf("Device doesn't support RAW data-path APIs.\n");
3213 		return TEST_SKIPPED;
3214 	}
3215 
3216 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3217 		return TEST_SKIPPED;
3218 
3219 	/* Verify the capabilities */
3220 	struct rte_cryptodev_sym_capability_idx cap_idx;
3221 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3222 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
3223 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3224 			&cap_idx) == NULL)
3225 		return TEST_SKIPPED;
3226 
3227 	/* Create SNOW 3G session */
3228 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3229 				tdata->key.data, tdata->key.len,
3230 				tdata->auth_iv.len, tdata->digest.len,
3231 				RTE_CRYPTO_AUTH_OP_VERIFY,
3232 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
3233 	if (retval < 0)
3234 		return retval;
3235 	/* alloc mbuf and set payload */
3236 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3237 
3238 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3239 	rte_pktmbuf_tailroom(ut_params->ibuf));
3240 
3241 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3242 	/* Append data which is padded to a multiple of */
3243 	/* the algorithms block size */
3244 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3245 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3246 				plaintext_pad_len);
3247 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3248 
3249 	/* Create SNOW 3G operation */
3250 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3251 			tdata->digest.len,
3252 			tdata->auth_iv.data, tdata->auth_iv.len,
3253 			plaintext_pad_len,
3254 			RTE_CRYPTO_AUTH_OP_VERIFY,
3255 			tdata->validAuthLenInBits.len,
3256 			0);
3257 	if (retval < 0)
3258 		return retval;
3259 
3260 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3261 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3262 				ut_params->op, 0, 1, 1, 0);
3263 	else
3264 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3265 				ut_params->op);
3266 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3267 	ut_params->obuf = ut_params->op->sym->m_src;
3268 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3269 				+ plaintext_pad_len;
3270 
3271 	/* Validate obuf */
3272 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3273 		return 0;
3274 	else
3275 		return -1;
3276 
3277 	return 0;
3278 }
3279 
3280 static int
3281 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
3282 {
3283 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3284 	struct crypto_unittest_params *ut_params = &unittest_params;
3285 
3286 	int retval;
3287 	unsigned plaintext_pad_len;
3288 	unsigned plaintext_len;
3289 	uint8_t *plaintext;
3290 	struct rte_cryptodev_info dev_info;
3291 
3292 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3293 	uint64_t feat_flags = dev_info.feature_flags;
3294 
3295 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3296 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3297 		printf("Device doesn't support RAW data-path APIs.\n");
3298 		return TEST_SKIPPED;
3299 	}
3300 
3301 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3302 		return TEST_SKIPPED;
3303 
3304 	/* Verify the capabilities */
3305 	struct rte_cryptodev_sym_capability_idx cap_idx;
3306 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3307 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3308 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3309 			&cap_idx) == NULL)
3310 		return TEST_SKIPPED;
3311 
3312 	/* Create KASUMI session */
3313 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3314 			tdata->key.data, tdata->key.len,
3315 			0, tdata->digest.len,
3316 			RTE_CRYPTO_AUTH_OP_GENERATE,
3317 			RTE_CRYPTO_AUTH_KASUMI_F9);
3318 	if (retval < 0)
3319 		return retval;
3320 
3321 	/* alloc mbuf and set payload */
3322 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3323 
3324 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3325 	rte_pktmbuf_tailroom(ut_params->ibuf));
3326 
3327 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3328 	/* Append data which is padded to a multiple of */
3329 	/* the algorithms block size */
3330 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3331 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3332 				plaintext_pad_len);
3333 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3334 
3335 	/* Create KASUMI operation */
3336 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3337 			NULL, 0,
3338 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3339 			tdata->plaintext.len,
3340 			0);
3341 	if (retval < 0)
3342 		return retval;
3343 
3344 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3345 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
3346 			ut_params->op);
3347 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3348 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3349 				ut_params->op, 0, 1, 1, 0);
3350 	else
3351 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3352 			ut_params->op);
3353 
3354 	ut_params->obuf = ut_params->op->sym->m_src;
3355 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3356 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3357 			+ plaintext_pad_len;
3358 
3359 	/* Validate obuf */
3360 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3361 	ut_params->digest,
3362 	tdata->digest.data,
3363 	DIGEST_BYTE_LENGTH_KASUMI_F9,
3364 	"KASUMI Generated auth tag not as expected");
3365 
3366 	return 0;
3367 }
3368 
3369 static int
3370 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
3371 {
3372 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3373 	struct crypto_unittest_params *ut_params = &unittest_params;
3374 
3375 	int retval;
3376 	unsigned plaintext_pad_len;
3377 	unsigned plaintext_len;
3378 	uint8_t *plaintext;
3379 	struct rte_cryptodev_info dev_info;
3380 
3381 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3382 	uint64_t feat_flags = dev_info.feature_flags;
3383 
3384 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3385 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3386 		printf("Device doesn't support RAW data-path APIs.\n");
3387 		return TEST_SKIPPED;
3388 	}
3389 
3390 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3391 		return TEST_SKIPPED;
3392 
3393 	/* Verify the capabilities */
3394 	struct rte_cryptodev_sym_capability_idx cap_idx;
3395 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3396 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
3397 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3398 			&cap_idx) == NULL)
3399 		return TEST_SKIPPED;
3400 
3401 	/* Create KASUMI session */
3402 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3403 				tdata->key.data, tdata->key.len,
3404 				0, tdata->digest.len,
3405 				RTE_CRYPTO_AUTH_OP_VERIFY,
3406 				RTE_CRYPTO_AUTH_KASUMI_F9);
3407 	if (retval < 0)
3408 		return retval;
3409 	/* alloc mbuf and set payload */
3410 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3411 
3412 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3413 	rte_pktmbuf_tailroom(ut_params->ibuf));
3414 
3415 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3416 	/* Append data which is padded to a multiple */
3417 	/* of the algorithms block size */
3418 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3419 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3420 				plaintext_pad_len);
3421 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3422 
3423 	/* Create KASUMI operation */
3424 	retval = create_wireless_algo_hash_operation(tdata->digest.data,
3425 			tdata->digest.len,
3426 			NULL, 0,
3427 			plaintext_pad_len,
3428 			RTE_CRYPTO_AUTH_OP_VERIFY,
3429 			tdata->plaintext.len,
3430 			0);
3431 	if (retval < 0)
3432 		return retval;
3433 
3434 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3435 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3436 				ut_params->op, 0, 1, 1, 0);
3437 	else
3438 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3439 				ut_params->op);
3440 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3441 	ut_params->obuf = ut_params->op->sym->m_src;
3442 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3443 				+ plaintext_pad_len;
3444 
3445 	/* Validate obuf */
3446 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
3447 		return 0;
3448 	else
3449 		return -1;
3450 
3451 	return 0;
3452 }
3453 
3454 static int
3455 test_snow3g_hash_generate_test_case_1(void)
3456 {
3457 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
3458 }
3459 
3460 static int
3461 test_snow3g_hash_generate_test_case_2(void)
3462 {
3463 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
3464 }
3465 
3466 static int
3467 test_snow3g_hash_generate_test_case_3(void)
3468 {
3469 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
3470 }
3471 
3472 static int
3473 test_snow3g_hash_generate_test_case_4(void)
3474 {
3475 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
3476 }
3477 
3478 static int
3479 test_snow3g_hash_generate_test_case_5(void)
3480 {
3481 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
3482 }
3483 
3484 static int
3485 test_snow3g_hash_generate_test_case_6(void)
3486 {
3487 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
3488 }
3489 
3490 static int
3491 test_snow3g_hash_verify_test_case_1(void)
3492 {
3493 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
3494 
3495 }
3496 
3497 static int
3498 test_snow3g_hash_verify_test_case_2(void)
3499 {
3500 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
3501 }
3502 
3503 static int
3504 test_snow3g_hash_verify_test_case_3(void)
3505 {
3506 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
3507 }
3508 
3509 static int
3510 test_snow3g_hash_verify_test_case_4(void)
3511 {
3512 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
3513 }
3514 
3515 static int
3516 test_snow3g_hash_verify_test_case_5(void)
3517 {
3518 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
3519 }
3520 
3521 static int
3522 test_snow3g_hash_verify_test_case_6(void)
3523 {
3524 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
3525 }
3526 
3527 static int
3528 test_kasumi_hash_generate_test_case_1(void)
3529 {
3530 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
3531 }
3532 
3533 static int
3534 test_kasumi_hash_generate_test_case_2(void)
3535 {
3536 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
3537 }
3538 
3539 static int
3540 test_kasumi_hash_generate_test_case_3(void)
3541 {
3542 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
3543 }
3544 
3545 static int
3546 test_kasumi_hash_generate_test_case_4(void)
3547 {
3548 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
3549 }
3550 
3551 static int
3552 test_kasumi_hash_generate_test_case_5(void)
3553 {
3554 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
3555 }
3556 
3557 static int
3558 test_kasumi_hash_generate_test_case_6(void)
3559 {
3560 	return test_kasumi_authentication(&kasumi_hash_test_case_6);
3561 }
3562 
3563 static int
3564 test_kasumi_hash_verify_test_case_1(void)
3565 {
3566 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
3567 }
3568 
3569 static int
3570 test_kasumi_hash_verify_test_case_2(void)
3571 {
3572 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
3573 }
3574 
3575 static int
3576 test_kasumi_hash_verify_test_case_3(void)
3577 {
3578 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
3579 }
3580 
3581 static int
3582 test_kasumi_hash_verify_test_case_4(void)
3583 {
3584 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
3585 }
3586 
3587 static int
3588 test_kasumi_hash_verify_test_case_5(void)
3589 {
3590 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
3591 }
3592 
3593 static int
3594 test_kasumi_encryption(const struct kasumi_test_data *tdata)
3595 {
3596 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3597 	struct crypto_unittest_params *ut_params = &unittest_params;
3598 
3599 	int retval;
3600 	uint8_t *plaintext, *ciphertext;
3601 	unsigned plaintext_pad_len;
3602 	unsigned plaintext_len;
3603 	struct rte_cryptodev_info dev_info;
3604 
3605 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3606 	uint64_t feat_flags = dev_info.feature_flags;
3607 
3608 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3609 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3610 		printf("Device doesn't support RAW data-path APIs.\n");
3611 		return TEST_SKIPPED;
3612 	}
3613 
3614 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3615 		return TEST_SKIPPED;
3616 
3617 	/* Verify the capabilities */
3618 	struct rte_cryptodev_sym_capability_idx cap_idx;
3619 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3620 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3621 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3622 			&cap_idx) == NULL)
3623 		return TEST_SKIPPED;
3624 
3625 	/* Create KASUMI session */
3626 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3627 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3628 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3629 					tdata->key.data, tdata->key.len,
3630 					tdata->cipher_iv.len);
3631 	if (retval < 0)
3632 		return retval;
3633 
3634 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3635 
3636 	/* Clear mbuf payload */
3637 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3638 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3639 
3640 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3641 	/* Append data which is padded to a multiple */
3642 	/* of the algorithms block size */
3643 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3644 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3645 				plaintext_pad_len);
3646 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3647 
3648 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3649 
3650 	/* Create KASUMI operation */
3651 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3652 				tdata->cipher_iv.len,
3653 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3654 				tdata->validCipherOffsetInBits.len);
3655 	if (retval < 0)
3656 		return retval;
3657 
3658 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3659 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3660 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3661 	else
3662 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3663 				ut_params->op);
3664 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3665 
3666 	ut_params->obuf = ut_params->op->sym->m_dst;
3667 	if (ut_params->obuf)
3668 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3669 	else
3670 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3671 
3672 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3673 
3674 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3675 				(tdata->validCipherOffsetInBits.len >> 3);
3676 	/* Validate obuf */
3677 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3678 		ciphertext,
3679 		reference_ciphertext,
3680 		tdata->validCipherLenInBits.len,
3681 		"KASUMI Ciphertext data not as expected");
3682 	return 0;
3683 }
3684 
3685 static int
3686 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
3687 {
3688 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3689 	struct crypto_unittest_params *ut_params = &unittest_params;
3690 
3691 	int retval;
3692 
3693 	unsigned int plaintext_pad_len;
3694 	unsigned int plaintext_len;
3695 
3696 	uint8_t buffer[10000];
3697 	const uint8_t *ciphertext;
3698 
3699 	struct rte_cryptodev_info dev_info;
3700 
3701 	/* Verify the capabilities */
3702 	struct rte_cryptodev_sym_capability_idx cap_idx;
3703 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3704 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3705 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3706 			&cap_idx) == NULL)
3707 		return TEST_SKIPPED;
3708 
3709 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3710 
3711 	uint64_t feat_flags = dev_info.feature_flags;
3712 
3713 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
3714 		printf("Device doesn't support in-place scatter-gather. "
3715 				"Test Skipped.\n");
3716 		return TEST_SKIPPED;
3717 	}
3718 
3719 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
3720 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
3721 		printf("Device doesn't support RAW data-path APIs.\n");
3722 		return TEST_SKIPPED;
3723 	}
3724 
3725 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3726 		return TEST_SKIPPED;
3727 
3728 	/* Create KASUMI session */
3729 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3730 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3731 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3732 					tdata->key.data, tdata->key.len,
3733 					tdata->cipher_iv.len);
3734 	if (retval < 0)
3735 		return retval;
3736 
3737 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3738 
3739 
3740 	/* Append data which is padded to a multiple */
3741 	/* of the algorithms block size */
3742 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3743 
3744 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3745 			plaintext_pad_len, 10, 0);
3746 
3747 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3748 
3749 	/* Create KASUMI operation */
3750 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
3751 				tdata->cipher_iv.len,
3752 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3753 				tdata->validCipherOffsetInBits.len);
3754 	if (retval < 0)
3755 		return retval;
3756 
3757 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3758 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
3759 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
3760 	else
3761 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3762 						ut_params->op);
3763 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3764 
3765 	ut_params->obuf = ut_params->op->sym->m_dst;
3766 
3767 	if (ut_params->obuf)
3768 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3769 				plaintext_len, buffer);
3770 	else
3771 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3772 				tdata->validCipherOffsetInBits.len >> 3,
3773 				plaintext_len, buffer);
3774 
3775 	/* Validate obuf */
3776 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3777 
3778 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3779 				(tdata->validCipherOffsetInBits.len >> 3);
3780 	/* Validate obuf */
3781 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3782 		ciphertext,
3783 		reference_ciphertext,
3784 		tdata->validCipherLenInBits.len,
3785 		"KASUMI Ciphertext data not as expected");
3786 	return 0;
3787 }
3788 
3789 static int
3790 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
3791 {
3792 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3793 	struct crypto_unittest_params *ut_params = &unittest_params;
3794 
3795 	int retval;
3796 	uint8_t *plaintext, *ciphertext;
3797 	unsigned plaintext_pad_len;
3798 	unsigned plaintext_len;
3799 
3800 	/* Verify the capabilities */
3801 	struct rte_cryptodev_sym_capability_idx cap_idx;
3802 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3803 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3804 	/* Data-path service does not support OOP */
3805 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3806 			&cap_idx) == NULL)
3807 		return TEST_SKIPPED;
3808 
3809 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3810 		return TEST_SKIPPED;
3811 
3812 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3813 		return TEST_SKIPPED;
3814 
3815 	/* Create KASUMI session */
3816 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3817 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3818 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3819 					tdata->key.data, tdata->key.len,
3820 					tdata->cipher_iv.len);
3821 	if (retval < 0)
3822 		return retval;
3823 
3824 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3825 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3826 
3827 	/* Clear mbuf payload */
3828 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3829 	       rte_pktmbuf_tailroom(ut_params->ibuf));
3830 
3831 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3832 	/* Append data which is padded to a multiple */
3833 	/* of the algorithms block size */
3834 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3835 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3836 				plaintext_pad_len);
3837 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3838 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3839 
3840 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
3841 
3842 	/* Create KASUMI operation */
3843 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3844 				tdata->cipher_iv.len,
3845 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3846 				tdata->validCipherOffsetInBits.len);
3847 	if (retval < 0)
3848 		return retval;
3849 
3850 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3851 						ut_params->op);
3852 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3853 
3854 	ut_params->obuf = ut_params->op->sym->m_dst;
3855 	if (ut_params->obuf)
3856 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
3857 	else
3858 		ciphertext = plaintext + (tdata->validCipherOffsetInBits.len >> 3);
3859 
3860 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3861 
3862 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3863 				(tdata->validCipherOffsetInBits.len >> 3);
3864 	/* Validate obuf */
3865 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3866 		ciphertext,
3867 		reference_ciphertext,
3868 		tdata->validCipherLenInBits.len,
3869 		"KASUMI Ciphertext data not as expected");
3870 	return 0;
3871 }
3872 
3873 static int
3874 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3875 {
3876 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3877 	struct crypto_unittest_params *ut_params = &unittest_params;
3878 
3879 	int retval;
3880 	unsigned int plaintext_pad_len;
3881 	unsigned int plaintext_len;
3882 
3883 	const uint8_t *ciphertext;
3884 	uint8_t buffer[2048];
3885 
3886 	struct rte_cryptodev_info dev_info;
3887 
3888 	/* Verify the capabilities */
3889 	struct rte_cryptodev_sym_capability_idx cap_idx;
3890 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3891 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3892 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3893 			&cap_idx) == NULL)
3894 		return TEST_SKIPPED;
3895 
3896 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3897 		return TEST_SKIPPED;
3898 
3899 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3900 		return TEST_SKIPPED;
3901 
3902 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3903 
3904 	uint64_t feat_flags = dev_info.feature_flags;
3905 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
3906 		printf("Device doesn't support out-of-place scatter-gather "
3907 				"in both input and output mbufs. "
3908 				"Test Skipped.\n");
3909 		return TEST_SKIPPED;
3910 	}
3911 
3912 	/* Create KASUMI session */
3913 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3914 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3915 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3916 					tdata->key.data, tdata->key.len,
3917 					tdata->cipher_iv.len);
3918 	if (retval < 0)
3919 		return retval;
3920 
3921 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
3922 	/* Append data which is padded to a multiple */
3923 	/* of the algorithms block size */
3924 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3925 
3926 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3927 			plaintext_pad_len, 10, 0);
3928 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3929 			plaintext_pad_len, 3, 0);
3930 
3931 	/* Append data which is padded to a multiple */
3932 	/* of the algorithms block size */
3933 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3934 
3935 	/* Create KASUMI operation */
3936 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
3937 				tdata->cipher_iv.len,
3938 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
3939 				tdata->validCipherOffsetInBits.len);
3940 	if (retval < 0)
3941 		return retval;
3942 
3943 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3944 						ut_params->op);
3945 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3946 
3947 	ut_params->obuf = ut_params->op->sym->m_dst;
3948 	if (ut_params->obuf)
3949 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
3950 				plaintext_pad_len, buffer);
3951 	else
3952 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3953 				tdata->validCipherOffsetInBits.len >> 3,
3954 				plaintext_pad_len, buffer);
3955 
3956 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
3957 				(tdata->validCipherOffsetInBits.len >> 3);
3958 	/* Validate obuf */
3959 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3960 		ciphertext,
3961 		reference_ciphertext,
3962 		tdata->validCipherLenInBits.len,
3963 		"KASUMI Ciphertext data not as expected");
3964 	return 0;
3965 }
3966 
3967 
3968 static int
3969 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3970 {
3971 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3972 	struct crypto_unittest_params *ut_params = &unittest_params;
3973 
3974 	int retval;
3975 	uint8_t *ciphertext, *plaintext;
3976 	unsigned ciphertext_pad_len;
3977 	unsigned ciphertext_len;
3978 
3979 	/* Verify the capabilities */
3980 	struct rte_cryptodev_sym_capability_idx cap_idx;
3981 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3982 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
3983 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3984 			&cap_idx) == NULL)
3985 		return TEST_SKIPPED;
3986 
3987 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
3988 		return TEST_SKIPPED;
3989 
3990 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
3991 		return TEST_SKIPPED;
3992 
3993 	/* Create KASUMI session */
3994 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3995 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
3996 					RTE_CRYPTO_CIPHER_KASUMI_F8,
3997 					tdata->key.data, tdata->key.len,
3998 					tdata->cipher_iv.len);
3999 	if (retval < 0)
4000 		return retval;
4001 
4002 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4003 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4004 
4005 	/* Clear mbuf payload */
4006 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4007 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4008 
4009 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4010 	/* Append data which is padded to a multiple */
4011 	/* of the algorithms block size */
4012 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4013 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4014 				ciphertext_pad_len);
4015 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4016 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4017 
4018 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4019 
4020 	/* Create KASUMI operation */
4021 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4022 				tdata->cipher_iv.len,
4023 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4024 				tdata->validCipherOffsetInBits.len);
4025 	if (retval < 0)
4026 		return retval;
4027 
4028 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4029 						ut_params->op);
4030 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4031 
4032 	ut_params->obuf = ut_params->op->sym->m_dst;
4033 	if (ut_params->obuf)
4034 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4035 	else
4036 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4037 
4038 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4039 
4040 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4041 				(tdata->validCipherOffsetInBits.len >> 3);
4042 	/* Validate obuf */
4043 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4044 		plaintext,
4045 		reference_plaintext,
4046 		tdata->validCipherLenInBits.len,
4047 		"KASUMI Plaintext data not as expected");
4048 	return 0;
4049 }
4050 
4051 static int
4052 test_kasumi_decryption(const struct kasumi_test_data *tdata)
4053 {
4054 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4055 	struct crypto_unittest_params *ut_params = &unittest_params;
4056 
4057 	int retval;
4058 	uint8_t *ciphertext, *plaintext;
4059 	unsigned ciphertext_pad_len;
4060 	unsigned ciphertext_len;
4061 	struct rte_cryptodev_info dev_info;
4062 
4063 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4064 	uint64_t feat_flags = dev_info.feature_flags;
4065 
4066 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4067 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4068 		printf("Device doesn't support RAW data-path APIs.\n");
4069 		return TEST_SKIPPED;
4070 	}
4071 
4072 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4073 		return TEST_SKIPPED;
4074 
4075 	/* Verify the capabilities */
4076 	struct rte_cryptodev_sym_capability_idx cap_idx;
4077 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4078 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
4079 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4080 			&cap_idx) == NULL)
4081 		return TEST_SKIPPED;
4082 
4083 	/* Create KASUMI session */
4084 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4085 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4086 					RTE_CRYPTO_CIPHER_KASUMI_F8,
4087 					tdata->key.data, tdata->key.len,
4088 					tdata->cipher_iv.len);
4089 	if (retval < 0)
4090 		return retval;
4091 
4092 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4093 
4094 	/* Clear mbuf payload */
4095 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4096 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4097 
4098 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4099 	/* Append data which is padded to a multiple */
4100 	/* of the algorithms block size */
4101 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
4102 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4103 				ciphertext_pad_len);
4104 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4105 
4106 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4107 
4108 	/* Create KASUMI operation */
4109 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4110 			tdata->cipher_iv.len,
4111 			RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
4112 			tdata->validCipherOffsetInBits.len);
4113 	if (retval < 0)
4114 		return retval;
4115 
4116 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4117 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4118 				ut_params->op, 1, 0, 1, 0);
4119 	else
4120 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4121 						ut_params->op);
4122 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4123 
4124 	ut_params->obuf = ut_params->op->sym->m_dst;
4125 	if (ut_params->obuf)
4126 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4127 	else
4128 		plaintext = ciphertext + (tdata->validCipherOffsetInBits.len >> 3);
4129 
4130 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4131 
4132 	const uint8_t *reference_plaintext = tdata->plaintext.data +
4133 				(tdata->validCipherOffsetInBits.len >> 3);
4134 	/* Validate obuf */
4135 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4136 		plaintext,
4137 		reference_plaintext,
4138 		tdata->validCipherLenInBits.len,
4139 		"KASUMI Plaintext data not as expected");
4140 	return 0;
4141 }
4142 
4143 static int
4144 test_snow3g_encryption(const struct snow3g_test_data *tdata)
4145 {
4146 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4147 	struct crypto_unittest_params *ut_params = &unittest_params;
4148 
4149 	int retval;
4150 	uint8_t *plaintext, *ciphertext;
4151 	unsigned plaintext_pad_len;
4152 	unsigned plaintext_len;
4153 	struct rte_cryptodev_info dev_info;
4154 
4155 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4156 	uint64_t feat_flags = dev_info.feature_flags;
4157 
4158 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4159 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4160 		printf("Device doesn't support RAW data-path APIs.\n");
4161 		return TEST_SKIPPED;
4162 	}
4163 
4164 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4165 		return TEST_SKIPPED;
4166 
4167 	/* Verify the capabilities */
4168 	struct rte_cryptodev_sym_capability_idx cap_idx;
4169 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4170 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4171 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4172 			&cap_idx) == NULL)
4173 		return TEST_SKIPPED;
4174 
4175 	/* Create SNOW 3G session */
4176 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4177 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4178 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4179 					tdata->key.data, tdata->key.len,
4180 					tdata->cipher_iv.len);
4181 	if (retval < 0)
4182 		return retval;
4183 
4184 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4185 
4186 	/* Clear mbuf payload */
4187 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4188 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4189 
4190 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4191 	/* Append data which is padded to a multiple of */
4192 	/* the algorithms block size */
4193 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4194 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4195 				plaintext_pad_len);
4196 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4197 
4198 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4199 
4200 	/* Create SNOW 3G operation */
4201 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4202 					tdata->cipher_iv.len,
4203 					tdata->validCipherLenInBits.len,
4204 					0);
4205 	if (retval < 0)
4206 		return retval;
4207 
4208 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4209 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4210 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4211 	else
4212 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4213 						ut_params->op);
4214 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4215 
4216 	ut_params->obuf = ut_params->op->sym->m_dst;
4217 	if (ut_params->obuf)
4218 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4219 	else
4220 		ciphertext = plaintext;
4221 
4222 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4223 
4224 	/* Validate obuf */
4225 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4226 		ciphertext,
4227 		tdata->ciphertext.data,
4228 		tdata->validDataLenInBits.len,
4229 		"SNOW 3G Ciphertext data not as expected");
4230 	return 0;
4231 }
4232 
4233 
4234 static int
4235 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
4236 {
4237 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4238 	struct crypto_unittest_params *ut_params = &unittest_params;
4239 	uint8_t *plaintext, *ciphertext;
4240 
4241 	int retval;
4242 	unsigned plaintext_pad_len;
4243 	unsigned plaintext_len;
4244 	struct rte_cryptodev_info dev_info;
4245 
4246 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4247 	uint64_t feat_flags = dev_info.feature_flags;
4248 
4249 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4250 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4251 		printf("Device does not support RAW data-path APIs.\n");
4252 		return -ENOTSUP;
4253 	}
4254 
4255 	/* Verify the capabilities */
4256 	struct rte_cryptodev_sym_capability_idx cap_idx;
4257 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4258 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4259 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4260 			&cap_idx) == NULL)
4261 		return TEST_SKIPPED;
4262 
4263 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4264 		return TEST_SKIPPED;
4265 
4266 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4267 		return TEST_SKIPPED;
4268 
4269 	/* Create SNOW 3G session */
4270 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4271 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4272 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4273 					tdata->key.data, tdata->key.len,
4274 					tdata->cipher_iv.len);
4275 	if (retval < 0)
4276 		return retval;
4277 
4278 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4279 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4280 
4281 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4282 			"Failed to allocate input buffer in mempool");
4283 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4284 			"Failed to allocate output buffer in mempool");
4285 
4286 	/* Clear mbuf payload */
4287 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4288 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4289 
4290 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4291 	/* Append data which is padded to a multiple of */
4292 	/* the algorithms block size */
4293 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4294 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4295 				plaintext_pad_len);
4296 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4297 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4298 
4299 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4300 
4301 	/* Create SNOW 3G operation */
4302 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4303 					tdata->cipher_iv.len,
4304 					tdata->validCipherLenInBits.len,
4305 					0);
4306 	if (retval < 0)
4307 		return retval;
4308 
4309 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4310 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4311 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4312 	else
4313 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4314 						ut_params->op);
4315 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4316 
4317 	ut_params->obuf = ut_params->op->sym->m_dst;
4318 	if (ut_params->obuf)
4319 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4320 	else
4321 		ciphertext = plaintext;
4322 
4323 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4324 
4325 	/* Validate obuf */
4326 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4327 		ciphertext,
4328 		tdata->ciphertext.data,
4329 		tdata->validDataLenInBits.len,
4330 		"SNOW 3G Ciphertext data not as expected");
4331 	return 0;
4332 }
4333 
4334 static int
4335 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
4336 {
4337 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4338 	struct crypto_unittest_params *ut_params = &unittest_params;
4339 
4340 	int retval;
4341 	unsigned int plaintext_pad_len;
4342 	unsigned int plaintext_len;
4343 	uint8_t buffer[10000];
4344 	const uint8_t *ciphertext;
4345 
4346 	struct rte_cryptodev_info dev_info;
4347 
4348 	/* Verify the capabilities */
4349 	struct rte_cryptodev_sym_capability_idx cap_idx;
4350 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4351 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4352 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4353 			&cap_idx) == NULL)
4354 		return TEST_SKIPPED;
4355 
4356 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4357 		return TEST_SKIPPED;
4358 
4359 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4360 		return TEST_SKIPPED;
4361 
4362 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4363 
4364 	uint64_t feat_flags = dev_info.feature_flags;
4365 
4366 	if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
4367 		printf("Device doesn't support out-of-place scatter-gather "
4368 				"in both input and output mbufs. "
4369 				"Test Skipped.\n");
4370 		return TEST_SKIPPED;
4371 	}
4372 
4373 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4374 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4375 		printf("Device does not support RAW data-path APIs.\n");
4376 		return -ENOTSUP;
4377 	}
4378 
4379 	/* Create SNOW 3G session */
4380 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4381 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4382 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4383 					tdata->key.data, tdata->key.len,
4384 					tdata->cipher_iv.len);
4385 	if (retval < 0)
4386 		return retval;
4387 
4388 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4389 	/* Append data which is padded to a multiple of */
4390 	/* the algorithms block size */
4391 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4392 
4393 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4394 			plaintext_pad_len, 10, 0);
4395 	ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
4396 			plaintext_pad_len, 3, 0);
4397 
4398 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4399 			"Failed to allocate input buffer in mempool");
4400 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4401 			"Failed to allocate output buffer in mempool");
4402 
4403 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4404 
4405 	/* Create SNOW 3G operation */
4406 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4407 					tdata->cipher_iv.len,
4408 					tdata->validCipherLenInBits.len,
4409 					0);
4410 	if (retval < 0)
4411 		return retval;
4412 
4413 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4414 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4415 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4416 	else
4417 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4418 						ut_params->op);
4419 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4420 
4421 	ut_params->obuf = ut_params->op->sym->m_dst;
4422 	if (ut_params->obuf)
4423 		ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
4424 				plaintext_len, buffer);
4425 	else
4426 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
4427 				plaintext_len, buffer);
4428 
4429 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4430 
4431 	/* Validate obuf */
4432 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4433 		ciphertext,
4434 		tdata->ciphertext.data,
4435 		tdata->validDataLenInBits.len,
4436 		"SNOW 3G Ciphertext data not as expected");
4437 
4438 	return 0;
4439 }
4440 
4441 /* Shift right a buffer by "offset" bits, "offset" < 8 */
4442 static void
4443 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
4444 {
4445 	uint8_t curr_byte, prev_byte;
4446 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
4447 	uint8_t lower_byte_mask = (1 << offset) - 1;
4448 	unsigned i;
4449 
4450 	prev_byte = buffer[0];
4451 	buffer[0] >>= offset;
4452 
4453 	for (i = 1; i < length_in_bytes; i++) {
4454 		curr_byte = buffer[i];
4455 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
4456 				(curr_byte >> offset);
4457 		prev_byte = curr_byte;
4458 	}
4459 }
4460 
4461 static int
4462 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
4463 {
4464 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4465 	struct crypto_unittest_params *ut_params = &unittest_params;
4466 	uint8_t *plaintext, *ciphertext;
4467 	int retval;
4468 	uint32_t plaintext_len;
4469 	uint32_t plaintext_pad_len;
4470 	uint8_t extra_offset = 4;
4471 	uint8_t *expected_ciphertext_shifted;
4472 	struct rte_cryptodev_info dev_info;
4473 
4474 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4475 	uint64_t feat_flags = dev_info.feature_flags;
4476 
4477 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4478 			((tdata->validDataLenInBits.len % 8) != 0)) {
4479 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4480 		return TEST_SKIPPED;
4481 	}
4482 
4483 	/* Verify the capabilities */
4484 	struct rte_cryptodev_sym_capability_idx cap_idx;
4485 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4486 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4487 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4488 			&cap_idx) == NULL)
4489 		return TEST_SKIPPED;
4490 
4491 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4492 		return TEST_SKIPPED;
4493 
4494 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4495 		return TEST_SKIPPED;
4496 
4497 	/* Create SNOW 3G session */
4498 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4499 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4500 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4501 					tdata->key.data, tdata->key.len,
4502 					tdata->cipher_iv.len);
4503 	if (retval < 0)
4504 		return retval;
4505 
4506 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4507 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4508 
4509 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4510 			"Failed to allocate input buffer in mempool");
4511 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4512 			"Failed to allocate output buffer in mempool");
4513 
4514 	/* Clear mbuf payload */
4515 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4516 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4517 
4518 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
4519 	/*
4520 	 * Append data which is padded to a
4521 	 * multiple of the algorithms block size
4522 	 */
4523 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4524 
4525 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
4526 						plaintext_pad_len);
4527 
4528 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
4529 
4530 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
4531 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
4532 
4533 #ifdef RTE_APP_TEST_DEBUG
4534 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4535 #endif
4536 	/* Create SNOW 3G operation */
4537 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4538 					tdata->cipher_iv.len,
4539 					tdata->validCipherLenInBits.len,
4540 					extra_offset);
4541 	if (retval < 0)
4542 		return retval;
4543 
4544 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4545 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4546 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4547 	else
4548 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4549 						ut_params->op);
4550 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4551 
4552 	ut_params->obuf = ut_params->op->sym->m_dst;
4553 	if (ut_params->obuf)
4554 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4555 	else
4556 		ciphertext = plaintext;
4557 
4558 #ifdef RTE_APP_TEST_DEBUG
4559 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4560 #endif
4561 
4562 	expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
4563 
4564 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
4565 			"failed to reserve memory for ciphertext shifted\n");
4566 
4567 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
4568 			ceil_byte_length(tdata->ciphertext.len));
4569 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
4570 			extra_offset);
4571 	/* Validate obuf */
4572 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
4573 		ciphertext,
4574 		expected_ciphertext_shifted,
4575 		tdata->validDataLenInBits.len,
4576 		extra_offset,
4577 		"SNOW 3G Ciphertext data not as expected");
4578 	return 0;
4579 }
4580 
4581 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
4582 {
4583 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4584 	struct crypto_unittest_params *ut_params = &unittest_params;
4585 
4586 	int retval;
4587 
4588 	uint8_t *plaintext, *ciphertext;
4589 	unsigned ciphertext_pad_len;
4590 	unsigned ciphertext_len;
4591 	struct rte_cryptodev_info dev_info;
4592 
4593 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4594 	uint64_t feat_flags = dev_info.feature_flags;
4595 
4596 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4597 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4598 		printf("Device doesn't support RAW data-path APIs.\n");
4599 		return TEST_SKIPPED;
4600 	}
4601 
4602 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4603 		return TEST_SKIPPED;
4604 
4605 	/* Verify the capabilities */
4606 	struct rte_cryptodev_sym_capability_idx cap_idx;
4607 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4608 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4609 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4610 			&cap_idx) == NULL)
4611 		return TEST_SKIPPED;
4612 
4613 	/* Create SNOW 3G session */
4614 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4615 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4616 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4617 					tdata->key.data, tdata->key.len,
4618 					tdata->cipher_iv.len);
4619 	if (retval < 0)
4620 		return retval;
4621 
4622 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4623 
4624 	/* Clear mbuf payload */
4625 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4626 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4627 
4628 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4629 	/* Append data which is padded to a multiple of */
4630 	/* the algorithms block size */
4631 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4632 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4633 				ciphertext_pad_len);
4634 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4635 
4636 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4637 
4638 	/* Create SNOW 3G operation */
4639 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
4640 					tdata->cipher_iv.len,
4641 					tdata->validCipherLenInBits.len,
4642 					tdata->cipher.offset_bits);
4643 	if (retval < 0)
4644 		return retval;
4645 
4646 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4647 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4648 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4649 	else
4650 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4651 						ut_params->op);
4652 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4653 	ut_params->obuf = ut_params->op->sym->m_dst;
4654 	if (ut_params->obuf)
4655 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4656 	else
4657 		plaintext = ciphertext;
4658 
4659 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4660 
4661 	/* Validate obuf */
4662 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4663 				tdata->plaintext.data,
4664 				tdata->validDataLenInBits.len,
4665 				"SNOW 3G Plaintext data not as expected");
4666 	return 0;
4667 }
4668 
4669 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
4670 {
4671 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4672 	struct crypto_unittest_params *ut_params = &unittest_params;
4673 
4674 	int retval;
4675 
4676 	uint8_t *plaintext, *ciphertext;
4677 	unsigned ciphertext_pad_len;
4678 	unsigned ciphertext_len;
4679 	struct rte_cryptodev_info dev_info;
4680 
4681 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4682 	uint64_t feat_flags = dev_info.feature_flags;
4683 
4684 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4685 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4686 		printf("Device does not support RAW data-path APIs.\n");
4687 		return -ENOTSUP;
4688 	}
4689 	/* Verify the capabilities */
4690 	struct rte_cryptodev_sym_capability_idx cap_idx;
4691 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4692 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4693 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4694 			&cap_idx) == NULL)
4695 		return TEST_SKIPPED;
4696 
4697 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4698 		return TEST_SKIPPED;
4699 
4700 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4701 		return TEST_SKIPPED;
4702 
4703 	/* Create SNOW 3G session */
4704 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4705 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
4706 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4707 					tdata->key.data, tdata->key.len,
4708 					tdata->cipher_iv.len);
4709 	if (retval < 0)
4710 		return retval;
4711 
4712 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4713 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4714 
4715 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
4716 			"Failed to allocate input buffer");
4717 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
4718 			"Failed to allocate output buffer");
4719 
4720 	/* Clear mbuf payload */
4721 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4722 	       rte_pktmbuf_tailroom(ut_params->ibuf));
4723 
4724 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
4725 		       rte_pktmbuf_tailroom(ut_params->obuf));
4726 
4727 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
4728 	/* Append data which is padded to a multiple of */
4729 	/* the algorithms block size */
4730 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
4731 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4732 				ciphertext_pad_len);
4733 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
4734 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
4735 
4736 	debug_hexdump(stdout, "ciphertext:", ciphertext, ciphertext_len);
4737 
4738 	/* Create SNOW 3G operation */
4739 	retval = create_wireless_algo_cipher_operation_oop(tdata->cipher_iv.data,
4740 					tdata->cipher_iv.len,
4741 					tdata->validCipherLenInBits.len,
4742 					0);
4743 	if (retval < 0)
4744 		return retval;
4745 
4746 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4747 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4748 			ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
4749 	else
4750 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4751 						ut_params->op);
4752 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4753 	ut_params->obuf = ut_params->op->sym->m_dst;
4754 	if (ut_params->obuf)
4755 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4756 	else
4757 		plaintext = ciphertext;
4758 
4759 	debug_hexdump(stdout, "plaintext:", plaintext, ciphertext_len);
4760 
4761 	/* Validate obuf */
4762 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
4763 				tdata->plaintext.data,
4764 				tdata->validDataLenInBits.len,
4765 				"SNOW 3G Plaintext data not as expected");
4766 	return 0;
4767 }
4768 
4769 static int
4770 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
4771 {
4772 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4773 	struct crypto_unittest_params *ut_params = &unittest_params;
4774 
4775 	int retval;
4776 
4777 	uint8_t *plaintext, *ciphertext;
4778 	unsigned int plaintext_pad_len;
4779 	unsigned int plaintext_len;
4780 
4781 	struct rte_cryptodev_info dev_info;
4782 	struct rte_cryptodev_sym_capability_idx cap_idx;
4783 
4784 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4785 	uint64_t feat_flags = dev_info.feature_flags;
4786 
4787 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
4788 			((tdata->validAuthLenInBits.len % 8 != 0) ||
4789 			(tdata->validDataLenInBits.len % 8 != 0))) {
4790 		printf("Device doesn't support NON-Byte Aligned Data.\n");
4791 		return TEST_SKIPPED;
4792 	}
4793 
4794 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4795 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4796 		printf("Device doesn't support RAW data-path APIs.\n");
4797 		return TEST_SKIPPED;
4798 	}
4799 
4800 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4801 		return TEST_SKIPPED;
4802 
4803 	/* Check if device supports ZUC EEA3 */
4804 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4805 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4806 
4807 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4808 			&cap_idx) == NULL)
4809 		return TEST_SKIPPED;
4810 
4811 	/* Check if device supports ZUC EIA3 */
4812 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4813 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4814 
4815 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4816 			&cap_idx) == NULL)
4817 		return TEST_SKIPPED;
4818 
4819 	/* Create ZUC session */
4820 	retval = create_zuc_cipher_auth_encrypt_generate_session(
4821 			ts_params->valid_devs[0],
4822 			tdata);
4823 	if (retval != 0)
4824 		return retval;
4825 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4826 
4827 	/* clear mbuf payload */
4828 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4829 			rte_pktmbuf_tailroom(ut_params->ibuf));
4830 
4831 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4832 	/* Append data which is padded to a multiple of */
4833 	/* the algorithms block size */
4834 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4835 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4836 				plaintext_pad_len);
4837 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4838 
4839 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4840 
4841 	/* Create ZUC operation */
4842 	retval = create_zuc_cipher_hash_generate_operation(tdata);
4843 	if (retval < 0)
4844 		return retval;
4845 
4846 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4847 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4848 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4849 	else
4850 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4851 			ut_params->op);
4852 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4853 	ut_params->obuf = ut_params->op->sym->m_src;
4854 	if (ut_params->obuf)
4855 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4856 	else
4857 		ciphertext = plaintext;
4858 
4859 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4860 	/* Validate obuf */
4861 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4862 			ciphertext,
4863 			tdata->ciphertext.data,
4864 			tdata->validDataLenInBits.len,
4865 			"ZUC Ciphertext data not as expected");
4866 
4867 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4868 	    + plaintext_pad_len;
4869 
4870 	/* Validate obuf */
4871 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4872 			ut_params->digest,
4873 			tdata->digest.data,
4874 			4,
4875 			"ZUC Generated auth tag not as expected");
4876 	return 0;
4877 }
4878 
4879 static int
4880 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
4881 {
4882 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4883 	struct crypto_unittest_params *ut_params = &unittest_params;
4884 
4885 	int retval;
4886 
4887 	uint8_t *plaintext, *ciphertext;
4888 	unsigned plaintext_pad_len;
4889 	unsigned plaintext_len;
4890 	struct rte_cryptodev_info dev_info;
4891 
4892 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4893 	uint64_t feat_flags = dev_info.feature_flags;
4894 
4895 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
4896 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
4897 		printf("Device doesn't support RAW data-path APIs.\n");
4898 		return TEST_SKIPPED;
4899 	}
4900 
4901 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
4902 		return TEST_SKIPPED;
4903 
4904 	/* Verify the capabilities */
4905 	struct rte_cryptodev_sym_capability_idx cap_idx;
4906 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4907 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
4908 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4909 			&cap_idx) == NULL)
4910 		return TEST_SKIPPED;
4911 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4912 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
4913 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4914 			&cap_idx) == NULL)
4915 		return TEST_SKIPPED;
4916 
4917 	/* Create SNOW 3G session */
4918 	retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
4919 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4920 			RTE_CRYPTO_AUTH_OP_GENERATE,
4921 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
4922 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
4923 			tdata->key.data, tdata->key.len,
4924 			tdata->auth_iv.len, tdata->digest.len,
4925 			tdata->cipher_iv.len);
4926 	if (retval != 0)
4927 		return retval;
4928 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4929 
4930 	/* clear mbuf payload */
4931 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4932 			rte_pktmbuf_tailroom(ut_params->ibuf));
4933 
4934 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
4935 	/* Append data which is padded to a multiple of */
4936 	/* the algorithms block size */
4937 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4938 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4939 				plaintext_pad_len);
4940 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4941 
4942 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
4943 
4944 	/* Create SNOW 3G operation */
4945 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4946 			tdata->digest.len, tdata->auth_iv.data,
4947 			tdata->auth_iv.len,
4948 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4949 			tdata->cipher_iv.data, tdata->cipher_iv.len,
4950 			tdata->validCipherLenInBits.len,
4951 			0,
4952 			tdata->validAuthLenInBits.len,
4953 			0
4954 			);
4955 	if (retval < 0)
4956 		return retval;
4957 
4958 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
4959 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
4960 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
4961 	else
4962 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4963 			ut_params->op);
4964 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4965 	ut_params->obuf = ut_params->op->sym->m_src;
4966 	if (ut_params->obuf)
4967 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
4968 	else
4969 		ciphertext = plaintext;
4970 
4971 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
4972 	/* Validate obuf */
4973 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4974 			ciphertext,
4975 			tdata->ciphertext.data,
4976 			tdata->validDataLenInBits.len,
4977 			"SNOW 3G Ciphertext data not as expected");
4978 
4979 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4980 	    + plaintext_pad_len;
4981 
4982 	/* Validate obuf */
4983 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
4984 			ut_params->digest,
4985 			tdata->digest.data,
4986 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4987 			"SNOW 3G Generated auth tag not as expected");
4988 	return 0;
4989 }
4990 
4991 static int
4992 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata,
4993 	uint8_t op_mode, uint8_t verify)
4994 {
4995 	struct crypto_testsuite_params *ts_params = &testsuite_params;
4996 	struct crypto_unittest_params *ut_params = &unittest_params;
4997 
4998 	int retval;
4999 
5000 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5001 	unsigned int plaintext_pad_len;
5002 	unsigned int plaintext_len;
5003 	unsigned int ciphertext_pad_len;
5004 	unsigned int ciphertext_len;
5005 
5006 	struct rte_cryptodev_info dev_info;
5007 
5008 	/* Verify the capabilities */
5009 	struct rte_cryptodev_sym_capability_idx cap_idx;
5010 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5011 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5012 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5013 			&cap_idx) == NULL)
5014 		return TEST_SKIPPED;
5015 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5016 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5017 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5018 			&cap_idx) == NULL)
5019 		return TEST_SKIPPED;
5020 
5021 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5022 		return TEST_SKIPPED;
5023 
5024 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5025 
5026 	uint64_t feat_flags = dev_info.feature_flags;
5027 
5028 	if (op_mode == OUT_OF_PLACE) {
5029 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5030 			printf("Device doesn't support digest encrypted.\n");
5031 			return TEST_SKIPPED;
5032 		}
5033 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5034 			return TEST_SKIPPED;
5035 	}
5036 
5037 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5038 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5039 		printf("Device doesn't support RAW data-path APIs.\n");
5040 		return TEST_SKIPPED;
5041 	}
5042 
5043 	/* Create SNOW 3G session */
5044 	retval = create_wireless_algo_auth_cipher_session(
5045 			ts_params->valid_devs[0],
5046 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5047 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5048 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5049 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5050 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5051 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5052 			tdata->key.data, tdata->key.len,
5053 			tdata->auth_iv.len, tdata->digest.len,
5054 			tdata->cipher_iv.len);
5055 	if (retval != 0)
5056 		return retval;
5057 
5058 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5059 	if (op_mode == OUT_OF_PLACE)
5060 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5061 
5062 	/* clear mbuf payload */
5063 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5064 		rte_pktmbuf_tailroom(ut_params->ibuf));
5065 	if (op_mode == OUT_OF_PLACE)
5066 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5067 			rte_pktmbuf_tailroom(ut_params->obuf));
5068 
5069 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5070 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5071 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5072 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5073 
5074 	if (verify) {
5075 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5076 					ciphertext_pad_len);
5077 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5078 		if (op_mode == OUT_OF_PLACE)
5079 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5080 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5081 			ciphertext_len);
5082 	} else {
5083 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5084 					plaintext_pad_len);
5085 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5086 		if (op_mode == OUT_OF_PLACE)
5087 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5088 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5089 	}
5090 
5091 	/* Create SNOW 3G operation */
5092 	retval = create_wireless_algo_auth_cipher_operation(
5093 		tdata->digest.data, tdata->digest.len,
5094 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5095 		tdata->auth_iv.data, tdata->auth_iv.len,
5096 		(tdata->digest.offset_bytes == 0 ?
5097 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5098 			: tdata->digest.offset_bytes),
5099 		tdata->validCipherLenInBits.len,
5100 		tdata->cipher.offset_bits,
5101 		tdata->validAuthLenInBits.len,
5102 		tdata->auth.offset_bits,
5103 		op_mode, 0, verify);
5104 
5105 	if (retval < 0)
5106 		return retval;
5107 
5108 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5109 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5110 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5111 	else
5112 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5113 			ut_params->op);
5114 
5115 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5116 
5117 	ut_params->obuf = (op_mode == IN_PLACE ?
5118 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5119 
5120 	if (verify) {
5121 		if (ut_params->obuf)
5122 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5123 							uint8_t *);
5124 		else
5125 			plaintext = ciphertext +
5126 				(tdata->cipher.offset_bits >> 3);
5127 
5128 		debug_hexdump(stdout, "plaintext:", plaintext,
5129 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5130 		debug_hexdump(stdout, "plaintext expected:",
5131 			tdata->plaintext.data,
5132 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5133 	} else {
5134 		if (ut_params->obuf)
5135 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5136 							uint8_t *);
5137 		else
5138 			ciphertext = plaintext;
5139 
5140 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5141 			ciphertext_len);
5142 		debug_hexdump(stdout, "ciphertext expected:",
5143 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5144 
5145 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5146 			+ (tdata->digest.offset_bytes == 0 ?
5147 		plaintext_pad_len : tdata->digest.offset_bytes);
5148 
5149 		debug_hexdump(stdout, "digest:", ut_params->digest,
5150 			tdata->digest.len);
5151 		debug_hexdump(stdout, "digest expected:", tdata->digest.data,
5152 				tdata->digest.len);
5153 	}
5154 
5155 	/* Validate obuf */
5156 	if (verify) {
5157 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5158 			plaintext,
5159 			tdata->plaintext.data,
5160 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5161 			 (tdata->digest.len << 3)),
5162 			tdata->cipher.offset_bits,
5163 			"SNOW 3G Plaintext data not as expected");
5164 	} else {
5165 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5166 			ciphertext,
5167 			tdata->ciphertext.data,
5168 			(tdata->validDataLenInBits.len -
5169 			 tdata->cipher.offset_bits),
5170 			tdata->cipher.offset_bits,
5171 			"SNOW 3G Ciphertext data not as expected");
5172 
5173 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5174 			ut_params->digest,
5175 			tdata->digest.data,
5176 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5177 			"SNOW 3G Generated auth tag not as expected");
5178 	}
5179 	return 0;
5180 }
5181 
5182 static int
5183 test_snow3g_auth_cipher_sgl(const struct snow3g_test_data *tdata,
5184 	uint8_t op_mode, uint8_t verify)
5185 {
5186 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5187 	struct crypto_unittest_params *ut_params = &unittest_params;
5188 
5189 	int retval;
5190 
5191 	const uint8_t *plaintext = NULL;
5192 	const uint8_t *ciphertext = NULL;
5193 	const uint8_t *digest = NULL;
5194 	unsigned int plaintext_pad_len;
5195 	unsigned int plaintext_len;
5196 	unsigned int ciphertext_pad_len;
5197 	unsigned int ciphertext_len;
5198 	uint8_t buffer[10000];
5199 	uint8_t digest_buffer[10000];
5200 
5201 	struct rte_cryptodev_info dev_info;
5202 
5203 	/* Verify the capabilities */
5204 	struct rte_cryptodev_sym_capability_idx cap_idx;
5205 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5206 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
5207 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5208 			&cap_idx) == NULL)
5209 		return TEST_SKIPPED;
5210 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5211 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
5212 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5213 			&cap_idx) == NULL)
5214 		return TEST_SKIPPED;
5215 
5216 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5217 		return TEST_SKIPPED;
5218 
5219 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5220 
5221 	uint64_t feat_flags = dev_info.feature_flags;
5222 
5223 	if (op_mode == IN_PLACE) {
5224 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5225 			printf("Device doesn't support in-place scatter-gather "
5226 					"in both input and output mbufs.\n");
5227 			return TEST_SKIPPED;
5228 		}
5229 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5230 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5231 			printf("Device doesn't support RAW data-path APIs.\n");
5232 			return TEST_SKIPPED;
5233 		}
5234 	} else {
5235 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5236 			return TEST_SKIPPED;
5237 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5238 			printf("Device doesn't support out-of-place scatter-gather "
5239 					"in both input and output mbufs.\n");
5240 			return TEST_SKIPPED;
5241 		}
5242 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5243 			printf("Device doesn't support digest encrypted.\n");
5244 			return TEST_SKIPPED;
5245 		}
5246 	}
5247 
5248 	/* Create SNOW 3G session */
5249 	retval = create_wireless_algo_auth_cipher_session(
5250 			ts_params->valid_devs[0],
5251 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5252 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5253 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5254 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5255 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
5256 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
5257 			tdata->key.data, tdata->key.len,
5258 			tdata->auth_iv.len, tdata->digest.len,
5259 			tdata->cipher_iv.len);
5260 
5261 	if (retval != 0)
5262 		return retval;
5263 
5264 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5265 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5266 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5267 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5268 
5269 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5270 			plaintext_pad_len, 15, 0);
5271 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5272 			"Failed to allocate input buffer in mempool");
5273 
5274 	if (op_mode == OUT_OF_PLACE) {
5275 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5276 				plaintext_pad_len, 15, 0);
5277 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5278 				"Failed to allocate output buffer in mempool");
5279 	}
5280 
5281 	if (verify) {
5282 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5283 			tdata->ciphertext.data);
5284 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5285 					ciphertext_len, buffer);
5286 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5287 			ciphertext_len);
5288 	} else {
5289 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5290 			tdata->plaintext.data);
5291 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5292 					plaintext_len, buffer);
5293 		debug_hexdump(stdout, "plaintext:", plaintext,
5294 			plaintext_len);
5295 	}
5296 	memset(buffer, 0, sizeof(buffer));
5297 
5298 	/* Create SNOW 3G operation */
5299 	retval = create_wireless_algo_auth_cipher_operation(
5300 		tdata->digest.data, tdata->digest.len,
5301 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5302 		tdata->auth_iv.data, tdata->auth_iv.len,
5303 		(tdata->digest.offset_bytes == 0 ?
5304 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5305 			: tdata->digest.offset_bytes),
5306 		tdata->validCipherLenInBits.len,
5307 		tdata->cipher.offset_bits,
5308 		tdata->validAuthLenInBits.len,
5309 		tdata->auth.offset_bits,
5310 		op_mode, 1, verify);
5311 
5312 	if (retval < 0)
5313 		return retval;
5314 
5315 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5316 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5317 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5318 	else
5319 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5320 			ut_params->op);
5321 
5322 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5323 
5324 	ut_params->obuf = (op_mode == IN_PLACE ?
5325 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5326 
5327 	if (verify) {
5328 		if (ut_params->obuf)
5329 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5330 					plaintext_len, buffer);
5331 		else
5332 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5333 					plaintext_len, buffer);
5334 
5335 		debug_hexdump(stdout, "plaintext:", plaintext,
5336 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5337 		debug_hexdump(stdout, "plaintext expected:",
5338 			tdata->plaintext.data,
5339 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5340 	} else {
5341 		if (ut_params->obuf)
5342 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5343 					ciphertext_len, buffer);
5344 		else
5345 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5346 					ciphertext_len, buffer);
5347 
5348 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5349 			ciphertext_len);
5350 		debug_hexdump(stdout, "ciphertext expected:",
5351 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5352 
5353 		if (ut_params->obuf)
5354 			digest = rte_pktmbuf_read(ut_params->obuf,
5355 				(tdata->digest.offset_bytes == 0 ?
5356 				plaintext_pad_len : tdata->digest.offset_bytes),
5357 				tdata->digest.len, digest_buffer);
5358 		else
5359 			digest = rte_pktmbuf_read(ut_params->ibuf,
5360 				(tdata->digest.offset_bytes == 0 ?
5361 				plaintext_pad_len : tdata->digest.offset_bytes),
5362 				tdata->digest.len, digest_buffer);
5363 
5364 		debug_hexdump(stdout, "digest:", digest,
5365 			tdata->digest.len);
5366 		debug_hexdump(stdout, "digest expected:",
5367 			tdata->digest.data, tdata->digest.len);
5368 	}
5369 
5370 	/* Validate obuf */
5371 	if (verify) {
5372 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5373 			plaintext,
5374 			tdata->plaintext.data,
5375 			(tdata->plaintext.len - tdata->cipher.offset_bits -
5376 			 (tdata->digest.len << 3)),
5377 			tdata->cipher.offset_bits,
5378 			"SNOW 3G Plaintext data not as expected");
5379 	} else {
5380 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
5381 			ciphertext,
5382 			tdata->ciphertext.data,
5383 			(tdata->validDataLenInBits.len -
5384 			 tdata->cipher.offset_bits),
5385 			tdata->cipher.offset_bits,
5386 			"SNOW 3G Ciphertext data not as expected");
5387 
5388 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5389 			digest,
5390 			tdata->digest.data,
5391 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5392 			"SNOW 3G Generated auth tag not as expected");
5393 	}
5394 	return 0;
5395 }
5396 
5397 static int
5398 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata,
5399 	uint8_t op_mode, uint8_t verify)
5400 {
5401 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5402 	struct crypto_unittest_params *ut_params = &unittest_params;
5403 
5404 	int retval;
5405 
5406 	uint8_t *plaintext = NULL, *ciphertext = NULL;
5407 	unsigned int plaintext_pad_len;
5408 	unsigned int plaintext_len;
5409 	unsigned int ciphertext_pad_len;
5410 	unsigned int ciphertext_len;
5411 
5412 	struct rte_cryptodev_info dev_info;
5413 
5414 	/* Verify the capabilities */
5415 	struct rte_cryptodev_sym_capability_idx cap_idx;
5416 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5417 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5418 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5419 			&cap_idx) == NULL)
5420 		return TEST_SKIPPED;
5421 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5422 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5423 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5424 			&cap_idx) == NULL)
5425 		return TEST_SKIPPED;
5426 
5427 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5428 
5429 	uint64_t feat_flags = dev_info.feature_flags;
5430 
5431 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5432 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5433 		printf("Device doesn't support RAW data-path APIs.\n");
5434 		return TEST_SKIPPED;
5435 	}
5436 
5437 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5438 		return TEST_SKIPPED;
5439 
5440 	if (op_mode == OUT_OF_PLACE) {
5441 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5442 			return TEST_SKIPPED;
5443 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5444 			printf("Device doesn't support digest encrypted.\n");
5445 			return TEST_SKIPPED;
5446 		}
5447 	}
5448 
5449 	/* Create KASUMI session */
5450 	retval = create_wireless_algo_auth_cipher_session(
5451 			ts_params->valid_devs[0],
5452 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5453 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5454 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5455 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5456 			RTE_CRYPTO_AUTH_KASUMI_F9,
5457 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5458 			tdata->key.data, tdata->key.len,
5459 			0, tdata->digest.len,
5460 			tdata->cipher_iv.len);
5461 
5462 	if (retval != 0)
5463 		return retval;
5464 
5465 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5466 	if (op_mode == OUT_OF_PLACE)
5467 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5468 
5469 	/* clear mbuf payload */
5470 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5471 		rte_pktmbuf_tailroom(ut_params->ibuf));
5472 	if (op_mode == OUT_OF_PLACE)
5473 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5474 			rte_pktmbuf_tailroom(ut_params->obuf));
5475 
5476 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5477 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5478 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5479 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5480 
5481 	if (verify) {
5482 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5483 					ciphertext_pad_len);
5484 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
5485 		if (op_mode == OUT_OF_PLACE)
5486 			rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
5487 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5488 			ciphertext_len);
5489 	} else {
5490 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5491 					plaintext_pad_len);
5492 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5493 		if (op_mode == OUT_OF_PLACE)
5494 			rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
5495 		debug_hexdump(stdout, "plaintext:", plaintext,
5496 			plaintext_len);
5497 	}
5498 
5499 	/* Create KASUMI operation */
5500 	retval = create_wireless_algo_auth_cipher_operation(
5501 		tdata->digest.data, tdata->digest.len,
5502 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5503 		NULL, 0,
5504 		(tdata->digest.offset_bytes == 0 ?
5505 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5506 			: tdata->digest.offset_bytes),
5507 		tdata->validCipherLenInBits.len,
5508 		tdata->validCipherOffsetInBits.len,
5509 		tdata->validAuthLenInBits.len,
5510 		0,
5511 		op_mode, 0, verify);
5512 
5513 	if (retval < 0)
5514 		return retval;
5515 
5516 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5517 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5518 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5519 	else
5520 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5521 			ut_params->op);
5522 
5523 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5524 
5525 	ut_params->obuf = (op_mode == IN_PLACE ?
5526 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5527 
5528 
5529 	if (verify) {
5530 		if (ut_params->obuf)
5531 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
5532 							uint8_t *);
5533 		else
5534 			plaintext = ciphertext;
5535 
5536 		debug_hexdump(stdout, "plaintext:", plaintext,
5537 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5538 		debug_hexdump(stdout, "plaintext expected:",
5539 			tdata->plaintext.data,
5540 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5541 	} else {
5542 		if (ut_params->obuf)
5543 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
5544 							uint8_t *);
5545 		else
5546 			ciphertext = plaintext;
5547 
5548 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5549 			ciphertext_len);
5550 		debug_hexdump(stdout, "ciphertext expected:",
5551 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5552 
5553 		ut_params->digest = rte_pktmbuf_mtod(
5554 			ut_params->obuf, uint8_t *) +
5555 			(tdata->digest.offset_bytes == 0 ?
5556 			plaintext_pad_len : tdata->digest.offset_bytes);
5557 
5558 		debug_hexdump(stdout, "digest:", ut_params->digest,
5559 			tdata->digest.len);
5560 		debug_hexdump(stdout, "digest expected:",
5561 			tdata->digest.data, tdata->digest.len);
5562 	}
5563 
5564 	/* Validate obuf */
5565 	if (verify) {
5566 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5567 			plaintext,
5568 			tdata->plaintext.data,
5569 			tdata->plaintext.len >> 3,
5570 			"KASUMI Plaintext data not as expected");
5571 	} else {
5572 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5573 			ciphertext,
5574 			tdata->ciphertext.data,
5575 			tdata->ciphertext.len >> 3,
5576 			"KASUMI Ciphertext data not as expected");
5577 
5578 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5579 			ut_params->digest,
5580 			tdata->digest.data,
5581 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5582 			"KASUMI Generated auth tag not as expected");
5583 	}
5584 	return 0;
5585 }
5586 
5587 static int
5588 test_kasumi_auth_cipher_sgl(const struct kasumi_test_data *tdata,
5589 	uint8_t op_mode, uint8_t verify)
5590 {
5591 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5592 	struct crypto_unittest_params *ut_params = &unittest_params;
5593 
5594 	int retval;
5595 
5596 	const uint8_t *plaintext = NULL;
5597 	const uint8_t *ciphertext = NULL;
5598 	const uint8_t *digest = NULL;
5599 	unsigned int plaintext_pad_len;
5600 	unsigned int plaintext_len;
5601 	unsigned int ciphertext_pad_len;
5602 	unsigned int ciphertext_len;
5603 	uint8_t buffer[10000];
5604 	uint8_t digest_buffer[10000];
5605 
5606 	struct rte_cryptodev_info dev_info;
5607 
5608 	/* Verify the capabilities */
5609 	struct rte_cryptodev_sym_capability_idx cap_idx;
5610 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5611 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5612 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5613 			&cap_idx) == NULL)
5614 		return TEST_SKIPPED;
5615 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5616 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5617 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5618 			&cap_idx) == NULL)
5619 		return TEST_SKIPPED;
5620 
5621 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5622 		return TEST_SKIPPED;
5623 
5624 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5625 
5626 	uint64_t feat_flags = dev_info.feature_flags;
5627 
5628 	if (op_mode == IN_PLACE) {
5629 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
5630 			printf("Device doesn't support in-place scatter-gather "
5631 					"in both input and output mbufs.\n");
5632 			return TEST_SKIPPED;
5633 		}
5634 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5635 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5636 			printf("Device doesn't support RAW data-path APIs.\n");
5637 			return TEST_SKIPPED;
5638 		}
5639 	} else {
5640 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5641 			return TEST_SKIPPED;
5642 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
5643 			printf("Device doesn't support out-of-place scatter-gather "
5644 					"in both input and output mbufs.\n");
5645 			return TEST_SKIPPED;
5646 		}
5647 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
5648 			printf("Device doesn't support digest encrypted.\n");
5649 			return TEST_SKIPPED;
5650 		}
5651 	}
5652 
5653 	/* Create KASUMI session */
5654 	retval = create_wireless_algo_auth_cipher_session(
5655 			ts_params->valid_devs[0],
5656 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
5657 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
5658 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
5659 					: RTE_CRYPTO_AUTH_OP_GENERATE),
5660 			RTE_CRYPTO_AUTH_KASUMI_F9,
5661 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5662 			tdata->key.data, tdata->key.len,
5663 			0, tdata->digest.len,
5664 			tdata->cipher_iv.len);
5665 
5666 	if (retval != 0)
5667 		return retval;
5668 
5669 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
5670 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5671 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
5672 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5673 
5674 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
5675 			plaintext_pad_len, 15, 0);
5676 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5677 			"Failed to allocate input buffer in mempool");
5678 
5679 	if (op_mode == OUT_OF_PLACE) {
5680 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
5681 				plaintext_pad_len, 15, 0);
5682 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
5683 				"Failed to allocate output buffer in mempool");
5684 	}
5685 
5686 	if (verify) {
5687 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
5688 			tdata->ciphertext.data);
5689 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5690 					ciphertext_len, buffer);
5691 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5692 			ciphertext_len);
5693 	} else {
5694 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
5695 			tdata->plaintext.data);
5696 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5697 					plaintext_len, buffer);
5698 		debug_hexdump(stdout, "plaintext:", plaintext,
5699 			plaintext_len);
5700 	}
5701 	memset(buffer, 0, sizeof(buffer));
5702 
5703 	/* Create KASUMI operation */
5704 	retval = create_wireless_algo_auth_cipher_operation(
5705 		tdata->digest.data, tdata->digest.len,
5706 		tdata->cipher_iv.data, tdata->cipher_iv.len,
5707 		NULL, 0,
5708 		(tdata->digest.offset_bytes == 0 ?
5709 		(verify ? ciphertext_pad_len : plaintext_pad_len)
5710 			: tdata->digest.offset_bytes),
5711 		tdata->validCipherLenInBits.len,
5712 		tdata->validCipherOffsetInBits.len,
5713 		tdata->validAuthLenInBits.len,
5714 		0,
5715 		op_mode, 1, verify);
5716 
5717 	if (retval < 0)
5718 		return retval;
5719 
5720 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5721 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5722 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5723 	else
5724 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5725 			ut_params->op);
5726 
5727 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5728 
5729 	ut_params->obuf = (op_mode == IN_PLACE ?
5730 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
5731 
5732 	if (verify) {
5733 		if (ut_params->obuf)
5734 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
5735 					plaintext_len, buffer);
5736 		else
5737 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
5738 					plaintext_len, buffer);
5739 
5740 		debug_hexdump(stdout, "plaintext:", plaintext,
5741 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5742 		debug_hexdump(stdout, "plaintext expected:",
5743 			tdata->plaintext.data,
5744 			(tdata->plaintext.len >> 3) - tdata->digest.len);
5745 	} else {
5746 		if (ut_params->obuf)
5747 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
5748 					ciphertext_len, buffer);
5749 		else
5750 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
5751 					ciphertext_len, buffer);
5752 
5753 		debug_hexdump(stdout, "ciphertext:", ciphertext,
5754 			ciphertext_len);
5755 		debug_hexdump(stdout, "ciphertext expected:",
5756 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
5757 
5758 		if (ut_params->obuf)
5759 			digest = rte_pktmbuf_read(ut_params->obuf,
5760 				(tdata->digest.offset_bytes == 0 ?
5761 				plaintext_pad_len : tdata->digest.offset_bytes),
5762 				tdata->digest.len, digest_buffer);
5763 		else
5764 			digest = rte_pktmbuf_read(ut_params->ibuf,
5765 				(tdata->digest.offset_bytes == 0 ?
5766 				plaintext_pad_len : tdata->digest.offset_bytes),
5767 				tdata->digest.len, digest_buffer);
5768 
5769 		debug_hexdump(stdout, "digest:", digest,
5770 			tdata->digest.len);
5771 		debug_hexdump(stdout, "digest expected:",
5772 			tdata->digest.data, tdata->digest.len);
5773 	}
5774 
5775 	/* Validate obuf */
5776 	if (verify) {
5777 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5778 			plaintext,
5779 			tdata->plaintext.data,
5780 			tdata->plaintext.len >> 3,
5781 			"KASUMI Plaintext data not as expected");
5782 	} else {
5783 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5784 			ciphertext,
5785 			tdata->ciphertext.data,
5786 			tdata->validDataLenInBits.len,
5787 			"KASUMI Ciphertext data not as expected");
5788 
5789 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
5790 			digest,
5791 			tdata->digest.data,
5792 			DIGEST_BYTE_LENGTH_KASUMI_F9,
5793 			"KASUMI Generated auth tag not as expected");
5794 	}
5795 	return 0;
5796 }
5797 
5798 static int
5799 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
5800 {
5801 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5802 	struct crypto_unittest_params *ut_params = &unittest_params;
5803 
5804 	int retval;
5805 
5806 	uint8_t *plaintext, *ciphertext;
5807 	unsigned plaintext_pad_len;
5808 	unsigned plaintext_len;
5809 	struct rte_cryptodev_info dev_info;
5810 
5811 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5812 	uint64_t feat_flags = dev_info.feature_flags;
5813 
5814 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5815 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5816 		printf("Device doesn't support RAW data-path APIs.\n");
5817 		return TEST_SKIPPED;
5818 	}
5819 
5820 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5821 		return TEST_SKIPPED;
5822 
5823 	/* Verify the capabilities */
5824 	struct rte_cryptodev_sym_capability_idx cap_idx;
5825 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5826 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_KASUMI_F9;
5827 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5828 			&cap_idx) == NULL)
5829 		return TEST_SKIPPED;
5830 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5831 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_KASUMI_F8;
5832 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5833 			&cap_idx) == NULL)
5834 		return TEST_SKIPPED;
5835 
5836 	/* Create KASUMI session */
5837 	retval = create_wireless_algo_cipher_auth_session(
5838 			ts_params->valid_devs[0],
5839 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5840 			RTE_CRYPTO_AUTH_OP_GENERATE,
5841 			RTE_CRYPTO_AUTH_KASUMI_F9,
5842 			RTE_CRYPTO_CIPHER_KASUMI_F8,
5843 			tdata->key.data, tdata->key.len,
5844 			0, tdata->digest.len,
5845 			tdata->cipher_iv.len);
5846 	if (retval != 0)
5847 		return retval;
5848 
5849 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5850 
5851 	/* clear mbuf payload */
5852 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5853 			rte_pktmbuf_tailroom(ut_params->ibuf));
5854 
5855 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
5856 	/* Append data which is padded to a multiple of */
5857 	/* the algorithms block size */
5858 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
5859 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5860 				plaintext_pad_len);
5861 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
5862 
5863 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
5864 
5865 	/* Create KASUMI operation */
5866 	retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
5867 				tdata->digest.len, NULL, 0,
5868 				plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
5869 				tdata->cipher_iv.data, tdata->cipher_iv.len,
5870 				RTE_ALIGN_CEIL(tdata->validCipherLenInBits.len, 8),
5871 				tdata->validCipherOffsetInBits.len,
5872 				tdata->validAuthLenInBits.len,
5873 				0
5874 				);
5875 	if (retval < 0)
5876 		return retval;
5877 
5878 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
5879 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
5880 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
5881 	else
5882 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5883 			ut_params->op);
5884 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
5885 
5886 	if (ut_params->op->sym->m_dst)
5887 		ut_params->obuf = ut_params->op->sym->m_dst;
5888 	else
5889 		ut_params->obuf = ut_params->op->sym->m_src;
5890 
5891 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5892 				tdata->validCipherOffsetInBits.len >> 3);
5893 
5894 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
5895 			+ plaintext_pad_len;
5896 
5897 	const uint8_t *reference_ciphertext = tdata->ciphertext.data +
5898 				(tdata->validCipherOffsetInBits.len >> 3);
5899 	/* Validate obuf */
5900 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
5901 		ciphertext,
5902 		reference_ciphertext,
5903 		tdata->validCipherLenInBits.len,
5904 		"KASUMI Ciphertext data not as expected");
5905 
5906 	/* Validate obuf */
5907 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
5908 		ut_params->digest,
5909 		tdata->digest.data,
5910 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
5911 		"KASUMI Generated auth tag not as expected");
5912 	return 0;
5913 }
5914 
5915 static int
5916 check_cipher_capability(const struct crypto_testsuite_params *ts_params,
5917 			const enum rte_crypto_cipher_algorithm cipher_algo,
5918 			const uint16_t key_size, const uint16_t iv_size)
5919 {
5920 	struct rte_cryptodev_sym_capability_idx cap_idx;
5921 	const struct rte_cryptodev_symmetric_capability *cap;
5922 
5923 	/* Check if device supports the algorithm */
5924 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5925 	cap_idx.algo.cipher = cipher_algo;
5926 
5927 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5928 			&cap_idx);
5929 
5930 	if (cap == NULL)
5931 		return -1;
5932 
5933 	/* Check if device supports key size and IV size */
5934 	if (rte_cryptodev_sym_capability_check_cipher(cap, key_size,
5935 			iv_size) < 0) {
5936 		return -1;
5937 	}
5938 
5939 	return 0;
5940 }
5941 
5942 static int
5943 check_auth_capability(const struct crypto_testsuite_params *ts_params,
5944 			const enum rte_crypto_auth_algorithm auth_algo,
5945 			const uint16_t key_size, const uint16_t iv_size,
5946 			const uint16_t tag_size)
5947 {
5948 	struct rte_cryptodev_sym_capability_idx cap_idx;
5949 	const struct rte_cryptodev_symmetric_capability *cap;
5950 
5951 	/* Check if device supports the algorithm */
5952 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5953 	cap_idx.algo.auth = auth_algo;
5954 
5955 	cap = rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
5956 			&cap_idx);
5957 
5958 	if (cap == NULL)
5959 		return -1;
5960 
5961 	/* Check if device supports key size and IV size */
5962 	if (rte_cryptodev_sym_capability_check_auth(cap, key_size,
5963 			tag_size, iv_size) < 0) {
5964 		return -1;
5965 	}
5966 
5967 	return 0;
5968 }
5969 
5970 static int
5971 test_zuc_encryption(const struct wireless_test_data *tdata)
5972 {
5973 	struct crypto_testsuite_params *ts_params = &testsuite_params;
5974 	struct crypto_unittest_params *ut_params = &unittest_params;
5975 
5976 	int retval;
5977 	uint8_t *plaintext, *ciphertext;
5978 	unsigned plaintext_pad_len;
5979 	unsigned plaintext_len;
5980 	struct rte_cryptodev_info dev_info;
5981 
5982 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5983 	uint64_t feat_flags = dev_info.feature_flags;
5984 
5985 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
5986 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
5987 		printf("Device doesn't support RAW data-path APIs.\n");
5988 		return TEST_SKIPPED;
5989 	}
5990 
5991 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
5992 		return TEST_SKIPPED;
5993 
5994 	/* Check if device supports ZUC EEA3 */
5995 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
5996 			tdata->key.len, tdata->cipher_iv.len) < 0)
5997 		return TEST_SKIPPED;
5998 
5999 	/* Create ZUC session */
6000 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6001 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6002 					RTE_CRYPTO_CIPHER_ZUC_EEA3,
6003 					tdata->key.data, tdata->key.len,
6004 					tdata->cipher_iv.len);
6005 	if (retval != 0)
6006 		return retval;
6007 
6008 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6009 
6010 	/* Clear mbuf payload */
6011 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6012 	       rte_pktmbuf_tailroom(ut_params->ibuf));
6013 
6014 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6015 	/* Append data which is padded to a multiple */
6016 	/* of the algorithms block size */
6017 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6018 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6019 				plaintext_pad_len);
6020 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6021 
6022 	debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
6023 
6024 	/* Create ZUC operation */
6025 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6026 					tdata->cipher_iv.len,
6027 					tdata->plaintext.len,
6028 					0);
6029 	if (retval < 0)
6030 		return retval;
6031 
6032 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6033 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6034 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6035 	else
6036 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6037 						ut_params->op);
6038 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6039 
6040 	ut_params->obuf = ut_params->op->sym->m_dst;
6041 	if (ut_params->obuf)
6042 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *);
6043 	else
6044 		ciphertext = plaintext;
6045 
6046 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6047 
6048 	/* Validate obuf */
6049 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6050 		ciphertext,
6051 		tdata->ciphertext.data,
6052 		tdata->validCipherLenInBits.len,
6053 		"ZUC Ciphertext data not as expected");
6054 	return 0;
6055 }
6056 
6057 static int
6058 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
6059 {
6060 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6061 	struct crypto_unittest_params *ut_params = &unittest_params;
6062 
6063 	int retval;
6064 
6065 	unsigned int plaintext_pad_len;
6066 	unsigned int plaintext_len;
6067 	const uint8_t *ciphertext;
6068 	uint8_t ciphertext_buffer[2048];
6069 	struct rte_cryptodev_info dev_info;
6070 
6071 	/* Check if device supports ZUC EEA3 */
6072 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6073 			tdata->key.len, tdata->cipher_iv.len) < 0)
6074 		return TEST_SKIPPED;
6075 
6076 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6077 		return TEST_SKIPPED;
6078 
6079 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6080 
6081 	uint64_t feat_flags = dev_info.feature_flags;
6082 
6083 	if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6084 		printf("Device doesn't support in-place scatter-gather. "
6085 				"Test Skipped.\n");
6086 		return TEST_SKIPPED;
6087 	}
6088 
6089 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6090 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6091 		printf("Device doesn't support RAW data-path APIs.\n");
6092 		return TEST_SKIPPED;
6093 	}
6094 
6095 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6096 
6097 	/* Append data which is padded to a multiple */
6098 	/* of the algorithms block size */
6099 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6100 
6101 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6102 			plaintext_pad_len, 10, 0);
6103 
6104 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6105 			tdata->plaintext.data);
6106 
6107 	/* Create ZUC session */
6108 	retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
6109 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6110 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6111 			tdata->key.data, tdata->key.len,
6112 			tdata->cipher_iv.len);
6113 	if (retval < 0)
6114 		return retval;
6115 
6116 	/* Clear mbuf payload */
6117 
6118 	pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
6119 
6120 	/* Create ZUC operation */
6121 	retval = create_wireless_algo_cipher_operation(tdata->cipher_iv.data,
6122 			tdata->cipher_iv.len, tdata->plaintext.len,
6123 			0);
6124 	if (retval < 0)
6125 		return retval;
6126 
6127 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6128 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6129 				ut_params->op, 1, 0, 1, tdata->cipher_iv.len);
6130 	else
6131 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6132 						ut_params->op);
6133 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6134 
6135 	ut_params->obuf = ut_params->op->sym->m_dst;
6136 	if (ut_params->obuf)
6137 		ciphertext = rte_pktmbuf_read(ut_params->obuf,
6138 			0, plaintext_len, ciphertext_buffer);
6139 	else
6140 		ciphertext = rte_pktmbuf_read(ut_params->ibuf,
6141 			0, plaintext_len, ciphertext_buffer);
6142 
6143 	/* Validate obuf */
6144 	debug_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
6145 
6146 	/* Validate obuf */
6147 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6148 		ciphertext,
6149 		tdata->ciphertext.data,
6150 		tdata->validCipherLenInBits.len,
6151 		"ZUC Ciphertext data not as expected");
6152 
6153 	return 0;
6154 }
6155 
6156 static int
6157 test_zuc_authentication(const struct wireless_test_data *tdata)
6158 {
6159 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6160 	struct crypto_unittest_params *ut_params = &unittest_params;
6161 
6162 	int retval;
6163 	unsigned plaintext_pad_len;
6164 	unsigned plaintext_len;
6165 	uint8_t *plaintext;
6166 
6167 	struct rte_cryptodev_info dev_info;
6168 
6169 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6170 	uint64_t feat_flags = dev_info.feature_flags;
6171 
6172 	if (!(feat_flags & RTE_CRYPTODEV_FF_NON_BYTE_ALIGNED_DATA) &&
6173 			(tdata->validAuthLenInBits.len % 8 != 0)) {
6174 		printf("Device doesn't support NON-Byte Aligned Data.\n");
6175 		return TEST_SKIPPED;
6176 	}
6177 
6178 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6179 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6180 		printf("Device doesn't support RAW data-path APIs.\n");
6181 		return TEST_SKIPPED;
6182 	}
6183 
6184 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
6185 		return TEST_SKIPPED;
6186 
6187 	/* Check if device supports ZUC EIA3 */
6188 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6189 			tdata->key.len, tdata->auth_iv.len,
6190 			tdata->digest.len) < 0)
6191 		return TEST_SKIPPED;
6192 
6193 	/* Create ZUC session */
6194 	retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
6195 			tdata->key.data, tdata->key.len,
6196 			tdata->auth_iv.len, tdata->digest.len,
6197 			RTE_CRYPTO_AUTH_OP_GENERATE,
6198 			RTE_CRYPTO_AUTH_ZUC_EIA3);
6199 	if (retval != 0)
6200 		return retval;
6201 
6202 	/* alloc mbuf and set payload */
6203 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6204 
6205 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6206 	rte_pktmbuf_tailroom(ut_params->ibuf));
6207 
6208 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6209 	/* Append data which is padded to a multiple of */
6210 	/* the algorithms block size */
6211 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
6212 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6213 				plaintext_pad_len);
6214 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6215 
6216 	/* Create ZUC operation */
6217 	retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
6218 			tdata->auth_iv.data, tdata->auth_iv.len,
6219 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
6220 			tdata->validAuthLenInBits.len,
6221 			0);
6222 	if (retval < 0)
6223 		return retval;
6224 
6225 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6226 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6227 				ut_params->op, 0, 1, 1, 0);
6228 	else
6229 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6230 				ut_params->op);
6231 	ut_params->obuf = ut_params->op->sym->m_src;
6232 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6233 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
6234 			+ plaintext_pad_len;
6235 
6236 	/* Validate obuf */
6237 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
6238 	ut_params->digest,
6239 	tdata->digest.data,
6240 	tdata->digest.len,
6241 	"ZUC Generated auth tag not as expected");
6242 
6243 	return 0;
6244 }
6245 
6246 static int
6247 test_zuc_auth_cipher(const struct wireless_test_data *tdata,
6248 	uint8_t op_mode, uint8_t verify)
6249 {
6250 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6251 	struct crypto_unittest_params *ut_params = &unittest_params;
6252 
6253 	int retval;
6254 
6255 	uint8_t *plaintext = NULL, *ciphertext = NULL;
6256 	unsigned int plaintext_pad_len;
6257 	unsigned int plaintext_len;
6258 	unsigned int ciphertext_pad_len;
6259 	unsigned int ciphertext_len;
6260 
6261 	struct rte_cryptodev_info dev_info;
6262 
6263 	/* Check if device supports ZUC EEA3 */
6264 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6265 			tdata->key.len, tdata->cipher_iv.len) < 0)
6266 		return TEST_SKIPPED;
6267 
6268 	/* Check if device supports ZUC EIA3 */
6269 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6270 			tdata->key.len, tdata->auth_iv.len,
6271 			tdata->digest.len) < 0)
6272 		return TEST_SKIPPED;
6273 
6274 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6275 
6276 	uint64_t feat_flags = dev_info.feature_flags;
6277 
6278 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6279 		printf("Device doesn't support digest encrypted.\n");
6280 		return TEST_SKIPPED;
6281 	}
6282 	if (op_mode == IN_PLACE) {
6283 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6284 			printf("Device doesn't support in-place scatter-gather "
6285 					"in both input and output mbufs.\n");
6286 			return TEST_SKIPPED;
6287 		}
6288 
6289 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6290 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6291 			printf("Device doesn't support RAW data-path APIs.\n");
6292 			return TEST_SKIPPED;
6293 		}
6294 	} else {
6295 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6296 			return TEST_SKIPPED;
6297 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6298 			printf("Device doesn't support out-of-place scatter-gather "
6299 					"in both input and output mbufs.\n");
6300 			return TEST_SKIPPED;
6301 		}
6302 	}
6303 
6304 	/* Create ZUC session */
6305 	retval = create_wireless_algo_auth_cipher_session(
6306 			ts_params->valid_devs[0],
6307 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6308 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6309 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6310 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6311 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6312 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6313 			tdata->key.data, tdata->key.len,
6314 			tdata->auth_iv.len, tdata->digest.len,
6315 			tdata->cipher_iv.len);
6316 
6317 	if (retval != 0)
6318 		return retval;
6319 
6320 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6321 	if (op_mode == OUT_OF_PLACE)
6322 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6323 
6324 	/* clear mbuf payload */
6325 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6326 		rte_pktmbuf_tailroom(ut_params->ibuf));
6327 	if (op_mode == OUT_OF_PLACE)
6328 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
6329 			rte_pktmbuf_tailroom(ut_params->obuf));
6330 
6331 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6332 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6333 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6334 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6335 
6336 	if (verify) {
6337 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6338 					ciphertext_pad_len);
6339 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
6340 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6341 			ciphertext_len);
6342 	} else {
6343 		/* make sure enough space to cover partial digest verify case */
6344 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6345 					ciphertext_pad_len);
6346 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6347 		debug_hexdump(stdout, "plaintext:", plaintext,
6348 			plaintext_len);
6349 	}
6350 
6351 	if (op_mode == OUT_OF_PLACE)
6352 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
6353 
6354 	/* Create ZUC operation */
6355 	retval = create_wireless_algo_auth_cipher_operation(
6356 		tdata->digest.data, tdata->digest.len,
6357 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6358 		tdata->auth_iv.data, tdata->auth_iv.len,
6359 		(tdata->digest.offset_bytes == 0 ?
6360 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6361 			: tdata->digest.offset_bytes),
6362 		tdata->validCipherLenInBits.len,
6363 		tdata->validCipherOffsetInBits.len,
6364 		tdata->validAuthLenInBits.len,
6365 		0,
6366 		op_mode, 0, verify);
6367 
6368 	if (retval < 0)
6369 		return retval;
6370 
6371 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6372 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6373 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6374 	else
6375 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6376 			ut_params->op);
6377 
6378 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6379 
6380 	ut_params->obuf = (op_mode == IN_PLACE ?
6381 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6382 
6383 
6384 	if (verify) {
6385 		if (ut_params->obuf)
6386 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
6387 							uint8_t *);
6388 		else
6389 			plaintext = ciphertext;
6390 
6391 		debug_hexdump(stdout, "plaintext:", plaintext,
6392 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6393 		debug_hexdump(stdout, "plaintext expected:",
6394 			tdata->plaintext.data,
6395 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6396 	} else {
6397 		if (ut_params->obuf)
6398 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
6399 							uint8_t *);
6400 		else
6401 			ciphertext = plaintext;
6402 
6403 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6404 			ciphertext_len);
6405 		debug_hexdump(stdout, "ciphertext expected:",
6406 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6407 
6408 		ut_params->digest = rte_pktmbuf_mtod(
6409 			ut_params->obuf, uint8_t *) +
6410 			(tdata->digest.offset_bytes == 0 ?
6411 			plaintext_pad_len : tdata->digest.offset_bytes);
6412 
6413 		debug_hexdump(stdout, "digest:", ut_params->digest,
6414 			tdata->digest.len);
6415 		debug_hexdump(stdout, "digest expected:",
6416 			tdata->digest.data, tdata->digest.len);
6417 	}
6418 
6419 	/* Validate obuf */
6420 	if (verify) {
6421 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6422 			plaintext,
6423 			tdata->plaintext.data,
6424 			tdata->plaintext.len >> 3,
6425 			"ZUC Plaintext data not as expected");
6426 	} else {
6427 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6428 			ciphertext,
6429 			tdata->ciphertext.data,
6430 			tdata->ciphertext.len >> 3,
6431 			"ZUC Ciphertext data not as expected");
6432 
6433 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6434 			ut_params->digest,
6435 			tdata->digest.data,
6436 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6437 			"ZUC Generated auth tag not as expected");
6438 	}
6439 	return 0;
6440 }
6441 
6442 static int
6443 test_zuc_auth_cipher_sgl(const struct wireless_test_data *tdata,
6444 	uint8_t op_mode, uint8_t verify)
6445 {
6446 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6447 	struct crypto_unittest_params *ut_params = &unittest_params;
6448 
6449 	int retval;
6450 
6451 	const uint8_t *plaintext = NULL;
6452 	const uint8_t *ciphertext = NULL;
6453 	const uint8_t *digest = NULL;
6454 	unsigned int plaintext_pad_len;
6455 	unsigned int plaintext_len;
6456 	unsigned int ciphertext_pad_len;
6457 	unsigned int ciphertext_len;
6458 	uint8_t buffer[10000];
6459 	uint8_t digest_buffer[10000];
6460 
6461 	struct rte_cryptodev_info dev_info;
6462 
6463 	/* Check if device supports ZUC EEA3 */
6464 	if (check_cipher_capability(ts_params, RTE_CRYPTO_CIPHER_ZUC_EEA3,
6465 			tdata->key.len, tdata->cipher_iv.len) < 0)
6466 		return TEST_SKIPPED;
6467 
6468 	/* Check if device supports ZUC EIA3 */
6469 	if (check_auth_capability(ts_params, RTE_CRYPTO_AUTH_ZUC_EIA3,
6470 			tdata->key.len, tdata->auth_iv.len,
6471 			tdata->digest.len) < 0)
6472 		return TEST_SKIPPED;
6473 
6474 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6475 
6476 	uint64_t feat_flags = dev_info.feature_flags;
6477 
6478 	if (op_mode == IN_PLACE) {
6479 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
6480 			printf("Device doesn't support in-place scatter-gather "
6481 					"in both input and output mbufs.\n");
6482 			return TEST_SKIPPED;
6483 		}
6484 
6485 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
6486 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
6487 			printf("Device doesn't support RAW data-path APIs.\n");
6488 			return TEST_SKIPPED;
6489 		}
6490 	} else {
6491 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6492 			return TEST_SKIPPED;
6493 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
6494 			printf("Device doesn't support out-of-place scatter-gather "
6495 					"in both input and output mbufs.\n");
6496 			return TEST_SKIPPED;
6497 		}
6498 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6499 			printf("Device doesn't support digest encrypted.\n");
6500 			return TEST_SKIPPED;
6501 		}
6502 	}
6503 
6504 	/* Create ZUC session */
6505 	retval = create_wireless_algo_auth_cipher_session(
6506 			ts_params->valid_devs[0],
6507 			(verify ? RTE_CRYPTO_CIPHER_OP_DECRYPT
6508 					: RTE_CRYPTO_CIPHER_OP_ENCRYPT),
6509 			(verify ? RTE_CRYPTO_AUTH_OP_VERIFY
6510 					: RTE_CRYPTO_AUTH_OP_GENERATE),
6511 			RTE_CRYPTO_AUTH_ZUC_EIA3,
6512 			RTE_CRYPTO_CIPHER_ZUC_EEA3,
6513 			tdata->key.data, tdata->key.len,
6514 			tdata->auth_iv.len, tdata->digest.len,
6515 			tdata->cipher_iv.len);
6516 
6517 	if (retval != 0)
6518 		return retval;
6519 
6520 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
6521 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
6522 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
6523 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
6524 
6525 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
6526 			plaintext_pad_len, 15, 0);
6527 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6528 			"Failed to allocate input buffer in mempool");
6529 
6530 	if (op_mode == OUT_OF_PLACE) {
6531 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
6532 				plaintext_pad_len, 15, 0);
6533 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
6534 				"Failed to allocate output buffer in mempool");
6535 	}
6536 
6537 	if (verify) {
6538 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
6539 			tdata->ciphertext.data);
6540 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6541 					ciphertext_len, buffer);
6542 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6543 			ciphertext_len);
6544 	} else {
6545 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
6546 			tdata->plaintext.data);
6547 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6548 					plaintext_len, buffer);
6549 		debug_hexdump(stdout, "plaintext:", plaintext,
6550 			plaintext_len);
6551 	}
6552 	memset(buffer, 0, sizeof(buffer));
6553 
6554 	/* Create ZUC operation */
6555 	retval = create_wireless_algo_auth_cipher_operation(
6556 		tdata->digest.data, tdata->digest.len,
6557 		tdata->cipher_iv.data, tdata->cipher_iv.len,
6558 		NULL, 0,
6559 		(tdata->digest.offset_bytes == 0 ?
6560 		(verify ? ciphertext_pad_len : plaintext_pad_len)
6561 			: tdata->digest.offset_bytes),
6562 		tdata->validCipherLenInBits.len,
6563 		tdata->validCipherOffsetInBits.len,
6564 		tdata->validAuthLenInBits.len,
6565 		0,
6566 		op_mode, 1, verify);
6567 
6568 	if (retval < 0)
6569 		return retval;
6570 
6571 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6572 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
6573 				ut_params->op, 1, 1, 1, tdata->cipher_iv.len);
6574 	else
6575 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6576 			ut_params->op);
6577 
6578 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
6579 
6580 	ut_params->obuf = (op_mode == IN_PLACE ?
6581 		ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
6582 
6583 	if (verify) {
6584 		if (ut_params->obuf)
6585 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
6586 					plaintext_len, buffer);
6587 		else
6588 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
6589 					plaintext_len, buffer);
6590 
6591 		debug_hexdump(stdout, "plaintext:", plaintext,
6592 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6593 		debug_hexdump(stdout, "plaintext expected:",
6594 			tdata->plaintext.data,
6595 			(tdata->plaintext.len >> 3) - tdata->digest.len);
6596 	} else {
6597 		if (ut_params->obuf)
6598 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
6599 					ciphertext_len, buffer);
6600 		else
6601 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
6602 					ciphertext_len, buffer);
6603 
6604 		debug_hexdump(stdout, "ciphertext:", ciphertext,
6605 			ciphertext_len);
6606 		debug_hexdump(stdout, "ciphertext expected:",
6607 			tdata->ciphertext.data, tdata->ciphertext.len >> 3);
6608 
6609 		if (ut_params->obuf)
6610 			digest = rte_pktmbuf_read(ut_params->obuf,
6611 				(tdata->digest.offset_bytes == 0 ?
6612 				plaintext_pad_len : tdata->digest.offset_bytes),
6613 				tdata->digest.len, digest_buffer);
6614 		else
6615 			digest = rte_pktmbuf_read(ut_params->ibuf,
6616 				(tdata->digest.offset_bytes == 0 ?
6617 				plaintext_pad_len : tdata->digest.offset_bytes),
6618 				tdata->digest.len, digest_buffer);
6619 
6620 		debug_hexdump(stdout, "digest:", digest,
6621 			tdata->digest.len);
6622 		debug_hexdump(stdout, "digest expected:",
6623 			tdata->digest.data, tdata->digest.len);
6624 	}
6625 
6626 	/* Validate obuf */
6627 	if (verify) {
6628 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6629 			plaintext,
6630 			tdata->plaintext.data,
6631 			tdata->plaintext.len >> 3,
6632 			"ZUC Plaintext data not as expected");
6633 	} else {
6634 		TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
6635 			ciphertext,
6636 			tdata->ciphertext.data,
6637 			tdata->validDataLenInBits.len,
6638 			"ZUC Ciphertext data not as expected");
6639 
6640 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
6641 			digest,
6642 			tdata->digest.data,
6643 			DIGEST_BYTE_LENGTH_KASUMI_F9,
6644 			"ZUC Generated auth tag not as expected");
6645 	}
6646 	return 0;
6647 }
6648 
6649 static int
6650 test_kasumi_encryption_test_case_1(void)
6651 {
6652 	return test_kasumi_encryption(&kasumi_test_case_1);
6653 }
6654 
6655 static int
6656 test_kasumi_encryption_test_case_1_sgl(void)
6657 {
6658 	return test_kasumi_encryption_sgl(&kasumi_test_case_1);
6659 }
6660 
6661 static int
6662 test_kasumi_encryption_test_case_1_oop(void)
6663 {
6664 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
6665 }
6666 
6667 static int
6668 test_kasumi_encryption_test_case_1_oop_sgl(void)
6669 {
6670 	return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
6671 }
6672 
6673 static int
6674 test_kasumi_encryption_test_case_2(void)
6675 {
6676 	return test_kasumi_encryption(&kasumi_test_case_2);
6677 }
6678 
6679 static int
6680 test_kasumi_encryption_test_case_3(void)
6681 {
6682 	return test_kasumi_encryption(&kasumi_test_case_3);
6683 }
6684 
6685 static int
6686 test_kasumi_encryption_test_case_4(void)
6687 {
6688 	return test_kasumi_encryption(&kasumi_test_case_4);
6689 }
6690 
6691 static int
6692 test_kasumi_encryption_test_case_5(void)
6693 {
6694 	return test_kasumi_encryption(&kasumi_test_case_5);
6695 }
6696 
6697 static int
6698 test_kasumi_decryption_test_case_1(void)
6699 {
6700 	return test_kasumi_decryption(&kasumi_test_case_1);
6701 }
6702 
6703 static int
6704 test_kasumi_decryption_test_case_1_oop(void)
6705 {
6706 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
6707 }
6708 
6709 static int
6710 test_kasumi_decryption_test_case_2(void)
6711 {
6712 	return test_kasumi_decryption(&kasumi_test_case_2);
6713 }
6714 
6715 static int
6716 test_kasumi_decryption_test_case_3(void)
6717 {
6718 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6719 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6720 		return TEST_SKIPPED;
6721 	return test_kasumi_decryption(&kasumi_test_case_3);
6722 }
6723 
6724 static int
6725 test_kasumi_decryption_test_case_4(void)
6726 {
6727 	return test_kasumi_decryption(&kasumi_test_case_4);
6728 }
6729 
6730 static int
6731 test_kasumi_decryption_test_case_5(void)
6732 {
6733 	return test_kasumi_decryption(&kasumi_test_case_5);
6734 }
6735 static int
6736 test_snow3g_encryption_test_case_1(void)
6737 {
6738 	return test_snow3g_encryption(&snow3g_test_case_1);
6739 }
6740 
6741 static int
6742 test_snow3g_encryption_test_case_1_oop(void)
6743 {
6744 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
6745 }
6746 
6747 static int
6748 test_snow3g_encryption_test_case_1_oop_sgl(void)
6749 {
6750 	return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
6751 }
6752 
6753 
6754 static int
6755 test_snow3g_encryption_test_case_1_offset_oop(void)
6756 {
6757 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
6758 }
6759 
6760 static int
6761 test_snow3g_encryption_test_case_2(void)
6762 {
6763 	return test_snow3g_encryption(&snow3g_test_case_2);
6764 }
6765 
6766 static int
6767 test_snow3g_encryption_test_case_3(void)
6768 {
6769 	return test_snow3g_encryption(&snow3g_test_case_3);
6770 }
6771 
6772 static int
6773 test_snow3g_encryption_test_case_4(void)
6774 {
6775 	return test_snow3g_encryption(&snow3g_test_case_4);
6776 }
6777 
6778 static int
6779 test_snow3g_encryption_test_case_5(void)
6780 {
6781 	return test_snow3g_encryption(&snow3g_test_case_5);
6782 }
6783 
6784 static int
6785 test_snow3g_decryption_test_case_1(void)
6786 {
6787 	return test_snow3g_decryption(&snow3g_test_case_1);
6788 }
6789 
6790 static int
6791 test_snow3g_decryption_test_case_1_oop(void)
6792 {
6793 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
6794 }
6795 
6796 static int
6797 test_snow3g_decryption_test_case_2(void)
6798 {
6799 	return test_snow3g_decryption(&snow3g_test_case_2);
6800 }
6801 
6802 static int
6803 test_snow3g_decryption_test_case_3(void)
6804 {
6805 	return test_snow3g_decryption(&snow3g_test_case_3);
6806 }
6807 
6808 static int
6809 test_snow3g_decryption_test_case_4(void)
6810 {
6811 	return test_snow3g_decryption(&snow3g_test_case_4);
6812 }
6813 
6814 static int
6815 test_snow3g_decryption_test_case_5(void)
6816 {
6817 	return test_snow3g_decryption(&snow3g_test_case_5);
6818 }
6819 
6820 /*
6821  * Function prepares snow3g_hash_test_data from snow3g_test_data.
6822  * Pattern digest from snow3g_test_data must be allocated as
6823  * 4 last bytes in plaintext.
6824  */
6825 static void
6826 snow3g_hash_test_vector_setup(const struct snow3g_test_data *pattern,
6827 		struct snow3g_hash_test_data *output)
6828 {
6829 	if ((pattern != NULL) && (output != NULL)) {
6830 		output->key.len = pattern->key.len;
6831 
6832 		memcpy(output->key.data,
6833 		pattern->key.data, pattern->key.len);
6834 
6835 		output->auth_iv.len = pattern->auth_iv.len;
6836 
6837 		memcpy(output->auth_iv.data,
6838 		pattern->auth_iv.data, pattern->auth_iv.len);
6839 
6840 		output->plaintext.len = pattern->plaintext.len;
6841 
6842 		memcpy(output->plaintext.data,
6843 		pattern->plaintext.data, pattern->plaintext.len >> 3);
6844 
6845 		output->digest.len = pattern->digest.len;
6846 
6847 		memcpy(output->digest.data,
6848 		&pattern->plaintext.data[pattern->digest.offset_bytes],
6849 		pattern->digest.len);
6850 
6851 		output->validAuthLenInBits.len =
6852 		pattern->validAuthLenInBits.len;
6853 	}
6854 }
6855 
6856 /*
6857  * Test case verify computed cipher and digest from snow3g_test_case_7 data.
6858  */
6859 static int
6860 test_snow3g_decryption_with_digest_test_case_1(void)
6861 {
6862 	struct snow3g_hash_test_data snow3g_hash_data;
6863 	struct rte_cryptodev_info dev_info;
6864 	struct crypto_testsuite_params *ts_params = &testsuite_params;
6865 
6866 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6867 	uint64_t feat_flags = dev_info.feature_flags;
6868 
6869 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
6870 		printf("Device doesn't support encrypted digest operations.\n");
6871 		return TEST_SKIPPED;
6872 	}
6873 
6874 	/*
6875 	 * Function prepare data for hash verification test case.
6876 	 * Digest is allocated in 4 last bytes in plaintext, pattern.
6877 	 */
6878 	snow3g_hash_test_vector_setup(&snow3g_test_case_7, &snow3g_hash_data);
6879 
6880 	return test_snow3g_decryption(&snow3g_test_case_7) &
6881 			test_snow3g_authentication_verify(&snow3g_hash_data);
6882 }
6883 
6884 static int
6885 test_snow3g_cipher_auth_test_case_1(void)
6886 {
6887 	return test_snow3g_cipher_auth(&snow3g_test_case_3);
6888 }
6889 
6890 static int
6891 test_snow3g_auth_cipher_test_case_1(void)
6892 {
6893 	return test_snow3g_auth_cipher(
6894 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 0);
6895 }
6896 
6897 static int
6898 test_snow3g_auth_cipher_test_case_2(void)
6899 {
6900 	return test_snow3g_auth_cipher(
6901 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 0);
6902 }
6903 
6904 static int
6905 test_snow3g_auth_cipher_test_case_2_oop(void)
6906 {
6907 	return test_snow3g_auth_cipher(
6908 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
6909 }
6910 
6911 static int
6912 test_snow3g_auth_cipher_part_digest_enc(void)
6913 {
6914 	return test_snow3g_auth_cipher(
6915 		&snow3g_auth_cipher_partial_digest_encryption,
6916 			IN_PLACE, 0);
6917 }
6918 
6919 static int
6920 test_snow3g_auth_cipher_part_digest_enc_oop(void)
6921 {
6922 	return test_snow3g_auth_cipher(
6923 		&snow3g_auth_cipher_partial_digest_encryption,
6924 			OUT_OF_PLACE, 0);
6925 }
6926 
6927 static int
6928 test_snow3g_auth_cipher_test_case_3_sgl(void)
6929 {
6930 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6931 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6932 		return TEST_SKIPPED;
6933 	return test_snow3g_auth_cipher_sgl(
6934 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 0);
6935 }
6936 
6937 static int
6938 test_snow3g_auth_cipher_test_case_3_oop_sgl(void)
6939 {
6940 	return test_snow3g_auth_cipher_sgl(
6941 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 0);
6942 }
6943 
6944 static int
6945 test_snow3g_auth_cipher_part_digest_enc_sgl(void)
6946 {
6947 	/* rte_crypto_mbuf_to_vec does not support incomplete mbuf build */
6948 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
6949 		return TEST_SKIPPED;
6950 	return test_snow3g_auth_cipher_sgl(
6951 		&snow3g_auth_cipher_partial_digest_encryption,
6952 			IN_PLACE, 0);
6953 }
6954 
6955 static int
6956 test_snow3g_auth_cipher_part_digest_enc_oop_sgl(void)
6957 {
6958 	return test_snow3g_auth_cipher_sgl(
6959 		&snow3g_auth_cipher_partial_digest_encryption,
6960 			OUT_OF_PLACE, 0);
6961 }
6962 
6963 static int
6964 test_snow3g_auth_cipher_verify_test_case_1(void)
6965 {
6966 	return test_snow3g_auth_cipher(
6967 		&snow3g_auth_cipher_test_case_1, IN_PLACE, 1);
6968 }
6969 
6970 static int
6971 test_snow3g_auth_cipher_verify_test_case_2(void)
6972 {
6973 	return test_snow3g_auth_cipher(
6974 		&snow3g_auth_cipher_test_case_2, IN_PLACE, 1);
6975 }
6976 
6977 static int
6978 test_snow3g_auth_cipher_verify_test_case_2_oop(void)
6979 {
6980 	return test_snow3g_auth_cipher(
6981 		&snow3g_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
6982 }
6983 
6984 static int
6985 test_snow3g_auth_cipher_verify_part_digest_enc(void)
6986 {
6987 	return test_snow3g_auth_cipher(
6988 		&snow3g_auth_cipher_partial_digest_encryption,
6989 			IN_PLACE, 1);
6990 }
6991 
6992 static int
6993 test_snow3g_auth_cipher_verify_part_digest_enc_oop(void)
6994 {
6995 	return test_snow3g_auth_cipher(
6996 		&snow3g_auth_cipher_partial_digest_encryption,
6997 			OUT_OF_PLACE, 1);
6998 }
6999 
7000 static int
7001 test_snow3g_auth_cipher_verify_test_case_3_sgl(void)
7002 {
7003 	return test_snow3g_auth_cipher_sgl(
7004 		&snow3g_auth_cipher_test_case_3, IN_PLACE, 1);
7005 }
7006 
7007 static int
7008 test_snow3g_auth_cipher_verify_test_case_3_oop_sgl(void)
7009 {
7010 	return test_snow3g_auth_cipher_sgl(
7011 		&snow3g_auth_cipher_test_case_3, OUT_OF_PLACE, 1);
7012 }
7013 
7014 static int
7015 test_snow3g_auth_cipher_verify_part_digest_enc_sgl(void)
7016 {
7017 	return test_snow3g_auth_cipher_sgl(
7018 		&snow3g_auth_cipher_partial_digest_encryption,
7019 			IN_PLACE, 1);
7020 }
7021 
7022 static int
7023 test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl(void)
7024 {
7025 	return test_snow3g_auth_cipher_sgl(
7026 		&snow3g_auth_cipher_partial_digest_encryption,
7027 			OUT_OF_PLACE, 1);
7028 }
7029 
7030 static int
7031 test_snow3g_auth_cipher_with_digest_test_case_1(void)
7032 {
7033 	return test_snow3g_auth_cipher(
7034 		&snow3g_test_case_7, IN_PLACE, 0);
7035 }
7036 
7037 static int
7038 test_kasumi_auth_cipher_test_case_1(void)
7039 {
7040 	return test_kasumi_auth_cipher(
7041 		&kasumi_test_case_3, IN_PLACE, 0);
7042 }
7043 
7044 static int
7045 test_kasumi_auth_cipher_test_case_2(void)
7046 {
7047 	return test_kasumi_auth_cipher(
7048 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7049 }
7050 
7051 static int
7052 test_kasumi_auth_cipher_test_case_2_oop(void)
7053 {
7054 	return test_kasumi_auth_cipher(
7055 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7056 }
7057 
7058 static int
7059 test_kasumi_auth_cipher_test_case_2_sgl(void)
7060 {
7061 	return test_kasumi_auth_cipher_sgl(
7062 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 0);
7063 }
7064 
7065 static int
7066 test_kasumi_auth_cipher_test_case_2_oop_sgl(void)
7067 {
7068 	return test_kasumi_auth_cipher_sgl(
7069 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 0);
7070 }
7071 
7072 static int
7073 test_kasumi_auth_cipher_verify_test_case_1(void)
7074 {
7075 	return test_kasumi_auth_cipher(
7076 		&kasumi_test_case_3, IN_PLACE, 1);
7077 }
7078 
7079 static int
7080 test_kasumi_auth_cipher_verify_test_case_2(void)
7081 {
7082 	return test_kasumi_auth_cipher(
7083 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7084 }
7085 
7086 static int
7087 test_kasumi_auth_cipher_verify_test_case_2_oop(void)
7088 {
7089 	return test_kasumi_auth_cipher(
7090 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7091 }
7092 
7093 static int
7094 test_kasumi_auth_cipher_verify_test_case_2_sgl(void)
7095 {
7096 	return test_kasumi_auth_cipher_sgl(
7097 		&kasumi_auth_cipher_test_case_2, IN_PLACE, 1);
7098 }
7099 
7100 static int
7101 test_kasumi_auth_cipher_verify_test_case_2_oop_sgl(void)
7102 {
7103 	return test_kasumi_auth_cipher_sgl(
7104 		&kasumi_auth_cipher_test_case_2, OUT_OF_PLACE, 1);
7105 }
7106 
7107 static int
7108 test_kasumi_cipher_auth_test_case_1(void)
7109 {
7110 	return test_kasumi_cipher_auth(&kasumi_test_case_6);
7111 }
7112 
7113 static int
7114 test_zuc_encryption_test_case_1(void)
7115 {
7116 	return test_zuc_encryption(&zuc_test_case_cipher_193b);
7117 }
7118 
7119 static int
7120 test_zuc_encryption_test_case_2(void)
7121 {
7122 	return test_zuc_encryption(&zuc_test_case_cipher_800b);
7123 }
7124 
7125 static int
7126 test_zuc_encryption_test_case_3(void)
7127 {
7128 	return test_zuc_encryption(&zuc_test_case_cipher_1570b);
7129 }
7130 
7131 static int
7132 test_zuc_encryption_test_case_4(void)
7133 {
7134 	return test_zuc_encryption(&zuc_test_case_cipher_2798b);
7135 }
7136 
7137 static int
7138 test_zuc_encryption_test_case_5(void)
7139 {
7140 	return test_zuc_encryption(&zuc_test_case_cipher_4019b);
7141 }
7142 
7143 static int
7144 test_zuc_encryption_test_case_6_sgl(void)
7145 {
7146 	return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
7147 }
7148 
7149 static int
7150 test_zuc_hash_generate_test_case_1(void)
7151 {
7152 	return test_zuc_authentication(&zuc_test_case_auth_1b);
7153 }
7154 
7155 static int
7156 test_zuc_hash_generate_test_case_2(void)
7157 {
7158 	return test_zuc_authentication(&zuc_test_case_auth_90b);
7159 }
7160 
7161 static int
7162 test_zuc_hash_generate_test_case_3(void)
7163 {
7164 	return test_zuc_authentication(&zuc_test_case_auth_577b);
7165 }
7166 
7167 static int
7168 test_zuc_hash_generate_test_case_4(void)
7169 {
7170 	return test_zuc_authentication(&zuc_test_case_auth_2079b);
7171 }
7172 
7173 static int
7174 test_zuc_hash_generate_test_case_5(void)
7175 {
7176 	return test_zuc_authentication(&zuc_test_auth_5670b);
7177 }
7178 
7179 static int
7180 test_zuc_hash_generate_test_case_6(void)
7181 {
7182 	return test_zuc_authentication(&zuc_test_case_auth_128b);
7183 }
7184 
7185 static int
7186 test_zuc_hash_generate_test_case_7(void)
7187 {
7188 	return test_zuc_authentication(&zuc_test_case_auth_2080b);
7189 }
7190 
7191 static int
7192 test_zuc_hash_generate_test_case_8(void)
7193 {
7194 	return test_zuc_authentication(&zuc_test_case_auth_584b);
7195 }
7196 
7197 static int
7198 test_zuc_hash_generate_test_case_9(void)
7199 {
7200 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_32b);
7201 }
7202 
7203 static int
7204 test_zuc_hash_generate_test_case_10(void)
7205 {
7206 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_64b);
7207 }
7208 
7209 static int
7210 test_zuc_hash_generate_test_case_11(void)
7211 {
7212 	return test_zuc_authentication(&zuc_test_case_auth_4000b_mac_128b);
7213 }
7214 
7215 static int
7216 test_zuc_cipher_auth_test_case_1(void)
7217 {
7218 	return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
7219 }
7220 
7221 static int
7222 test_zuc_cipher_auth_test_case_2(void)
7223 {
7224 	return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
7225 }
7226 
7227 static int
7228 test_zuc_auth_cipher_test_case_1(void)
7229 {
7230 	return test_zuc_auth_cipher(
7231 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7232 }
7233 
7234 static int
7235 test_zuc_auth_cipher_test_case_1_oop(void)
7236 {
7237 	return test_zuc_auth_cipher(
7238 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7239 }
7240 
7241 static int
7242 test_zuc_auth_cipher_test_case_1_sgl(void)
7243 {
7244 	return test_zuc_auth_cipher_sgl(
7245 		&zuc_auth_cipher_test_case_1, IN_PLACE, 0);
7246 }
7247 
7248 static int
7249 test_zuc_auth_cipher_test_case_1_oop_sgl(void)
7250 {
7251 	return test_zuc_auth_cipher_sgl(
7252 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 0);
7253 }
7254 
7255 static int
7256 test_zuc_auth_cipher_verify_test_case_1(void)
7257 {
7258 	return test_zuc_auth_cipher(
7259 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7260 }
7261 
7262 static int
7263 test_zuc_auth_cipher_verify_test_case_1_oop(void)
7264 {
7265 	return test_zuc_auth_cipher(
7266 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7267 }
7268 
7269 static int
7270 test_zuc_auth_cipher_verify_test_case_1_sgl(void)
7271 {
7272 	return test_zuc_auth_cipher_sgl(
7273 		&zuc_auth_cipher_test_case_1, IN_PLACE, 1);
7274 }
7275 
7276 static int
7277 test_zuc_auth_cipher_verify_test_case_1_oop_sgl(void)
7278 {
7279 	return test_zuc_auth_cipher_sgl(
7280 		&zuc_auth_cipher_test_case_1, OUT_OF_PLACE, 1);
7281 }
7282 
7283 static int
7284 test_zuc256_encryption_test_case_1(void)
7285 {
7286 	return test_zuc_encryption(&zuc256_test_case_cipher_1);
7287 }
7288 
7289 static int
7290 test_zuc256_encryption_test_case_2(void)
7291 {
7292 	return test_zuc_encryption(&zuc256_test_case_cipher_2);
7293 }
7294 
7295 static int
7296 test_zuc256_authentication_test_case_1(void)
7297 {
7298 	return test_zuc_authentication(&zuc256_test_case_auth_1);
7299 }
7300 
7301 static int
7302 test_zuc256_authentication_test_case_2(void)
7303 {
7304 	return test_zuc_authentication(&zuc256_test_case_auth_2);
7305 }
7306 
7307 static int
7308 test_mixed_check_if_unsupported(const struct mixed_cipher_auth_test_data *tdata)
7309 {
7310 	uint8_t dev_id = testsuite_params.valid_devs[0];
7311 
7312 	struct rte_cryptodev_sym_capability_idx cap_idx;
7313 
7314 	/* Check if device supports particular cipher algorithm */
7315 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
7316 	cap_idx.algo.cipher = tdata->cipher_algo;
7317 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7318 		return TEST_SKIPPED;
7319 
7320 	/* Check if device supports particular hash algorithm */
7321 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
7322 	cap_idx.algo.auth = tdata->auth_algo;
7323 	if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL)
7324 		return TEST_SKIPPED;
7325 
7326 	return 0;
7327 }
7328 
7329 static int
7330 test_mixed_auth_cipher(const struct mixed_cipher_auth_test_data *tdata,
7331 	uint8_t op_mode, uint8_t verify)
7332 {
7333 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7334 	struct crypto_unittest_params *ut_params = &unittest_params;
7335 
7336 	int retval;
7337 
7338 	uint8_t *plaintext = NULL, *ciphertext = NULL;
7339 	unsigned int plaintext_pad_len;
7340 	unsigned int plaintext_len;
7341 	unsigned int ciphertext_pad_len;
7342 	unsigned int ciphertext_len;
7343 
7344 	struct rte_cryptodev_info dev_info;
7345 	struct rte_crypto_op *op;
7346 
7347 	/* Check if device supports particular algorithms separately */
7348 	if (test_mixed_check_if_unsupported(tdata))
7349 		return TEST_SKIPPED;
7350 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7351 		return TEST_SKIPPED;
7352 
7353 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7354 
7355 	uint64_t feat_flags = dev_info.feature_flags;
7356 
7357 	if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7358 		printf("Device doesn't support digest encrypted.\n");
7359 		return TEST_SKIPPED;
7360 	}
7361 
7362 	/* Create the session */
7363 	if (verify)
7364 		retval = create_wireless_algo_cipher_auth_session(
7365 				ts_params->valid_devs[0],
7366 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7367 				RTE_CRYPTO_AUTH_OP_VERIFY,
7368 				tdata->auth_algo,
7369 				tdata->cipher_algo,
7370 				tdata->auth_key.data, tdata->auth_key.len,
7371 				tdata->auth_iv.len, tdata->digest_enc.len,
7372 				tdata->cipher_iv.len);
7373 	else
7374 		retval = create_wireless_algo_auth_cipher_session(
7375 				ts_params->valid_devs[0],
7376 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7377 				RTE_CRYPTO_AUTH_OP_GENERATE,
7378 				tdata->auth_algo,
7379 				tdata->cipher_algo,
7380 				tdata->auth_key.data, tdata->auth_key.len,
7381 				tdata->auth_iv.len, tdata->digest_enc.len,
7382 				tdata->cipher_iv.len);
7383 	if (retval != 0)
7384 		return retval;
7385 
7386 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7387 	if (op_mode == OUT_OF_PLACE)
7388 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7389 
7390 	/* clear mbuf payload */
7391 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7392 		rte_pktmbuf_tailroom(ut_params->ibuf));
7393 	if (op_mode == OUT_OF_PLACE) {
7394 
7395 		memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
7396 				rte_pktmbuf_tailroom(ut_params->obuf));
7397 	}
7398 
7399 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7400 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7401 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7402 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7403 
7404 	if (verify) {
7405 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7406 				ciphertext_pad_len);
7407 		memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
7408 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7409 				ciphertext_len);
7410 	} else {
7411 		/* make sure enough space to cover partial digest verify case */
7412 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7413 				ciphertext_pad_len);
7414 		memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7415 		debug_hexdump(stdout, "plaintext:", plaintext, plaintext_len);
7416 	}
7417 
7418 	if (op_mode == OUT_OF_PLACE)
7419 		rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
7420 
7421 	/* Create the operation */
7422 	retval = create_wireless_algo_auth_cipher_operation(
7423 			tdata->digest_enc.data, tdata->digest_enc.len,
7424 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7425 			tdata->auth_iv.data, tdata->auth_iv.len,
7426 			(tdata->digest_enc.offset == 0 ?
7427 				plaintext_pad_len
7428 				: tdata->digest_enc.offset),
7429 			tdata->validCipherLen.len_bits,
7430 			tdata->cipher.offset_bits,
7431 			tdata->validAuthLen.len_bits,
7432 			tdata->auth.offset_bits,
7433 			op_mode, 0, verify);
7434 
7435 	if (retval < 0)
7436 		return retval;
7437 
7438 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7439 
7440 	/* Check if the op failed because the device doesn't */
7441 	/* support this particular combination of algorithms */
7442 	if (op == NULL && ut_params->op->status ==
7443 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7444 		printf("Device doesn't support this mixed combination. "
7445 				"Test Skipped.\n");
7446 		return TEST_SKIPPED;
7447 	}
7448 	ut_params->op = op;
7449 
7450 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7451 
7452 	ut_params->obuf = (op_mode == IN_PLACE ?
7453 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7454 
7455 	if (verify) {
7456 		if (ut_params->obuf)
7457 			plaintext = rte_pktmbuf_mtod(ut_params->obuf,
7458 							uint8_t *);
7459 		else
7460 			plaintext = ciphertext +
7461 					(tdata->cipher.offset_bits >> 3);
7462 
7463 		debug_hexdump(stdout, "plaintext:", plaintext,
7464 				tdata->plaintext.len_bits >> 3);
7465 		debug_hexdump(stdout, "plaintext expected:",
7466 				tdata->plaintext.data,
7467 				tdata->plaintext.len_bits >> 3);
7468 	} else {
7469 		if (ut_params->obuf)
7470 			ciphertext = rte_pktmbuf_mtod(ut_params->obuf,
7471 					uint8_t *);
7472 		else
7473 			ciphertext = plaintext;
7474 
7475 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7476 				ciphertext_len);
7477 		debug_hexdump(stdout, "ciphertext expected:",
7478 				tdata->ciphertext.data,
7479 				tdata->ciphertext.len_bits >> 3);
7480 
7481 		ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
7482 				+ (tdata->digest_enc.offset == 0 ?
7483 		plaintext_pad_len : tdata->digest_enc.offset);
7484 
7485 		debug_hexdump(stdout, "digest:", ut_params->digest,
7486 				tdata->digest_enc.len);
7487 		debug_hexdump(stdout, "digest expected:",
7488 				tdata->digest_enc.data,
7489 				tdata->digest_enc.len);
7490 	}
7491 
7492 	if (!verify) {
7493 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7494 				ut_params->digest,
7495 				tdata->digest_enc.data,
7496 				tdata->digest_enc.len,
7497 				"Generated auth tag not as expected");
7498 	}
7499 
7500 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7501 		if (verify) {
7502 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7503 					plaintext,
7504 					tdata->plaintext.data,
7505 					tdata->plaintext.len_bits >> 3,
7506 					"Plaintext data not as expected");
7507 		} else {
7508 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7509 					ciphertext,
7510 					tdata->ciphertext.data,
7511 					tdata->validDataLen.len_bits,
7512 					"Ciphertext data not as expected");
7513 		}
7514 	}
7515 
7516 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7517 			"crypto op processing failed");
7518 
7519 	return 0;
7520 }
7521 
7522 static int
7523 test_mixed_auth_cipher_sgl(const struct mixed_cipher_auth_test_data *tdata,
7524 	uint8_t op_mode, uint8_t verify)
7525 {
7526 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7527 	struct crypto_unittest_params *ut_params = &unittest_params;
7528 
7529 	int retval;
7530 
7531 	const uint8_t *plaintext = NULL;
7532 	const uint8_t *ciphertext = NULL;
7533 	const uint8_t *digest = NULL;
7534 	unsigned int plaintext_pad_len;
7535 	unsigned int plaintext_len;
7536 	unsigned int ciphertext_pad_len;
7537 	unsigned int ciphertext_len;
7538 	uint8_t buffer[10000];
7539 	uint8_t digest_buffer[10000];
7540 
7541 	struct rte_cryptodev_info dev_info;
7542 	struct rte_crypto_op *op;
7543 
7544 	/* Check if device supports particular algorithms */
7545 	if (test_mixed_check_if_unsupported(tdata))
7546 		return TEST_SKIPPED;
7547 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
7548 		return TEST_SKIPPED;
7549 
7550 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
7551 
7552 	uint64_t feat_flags = dev_info.feature_flags;
7553 
7554 	if (op_mode == IN_PLACE) {
7555 		if (!(feat_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) {
7556 			printf("Device doesn't support in-place scatter-gather "
7557 					"in both input and output mbufs.\n");
7558 			return TEST_SKIPPED;
7559 		}
7560 	} else {
7561 		if (!(feat_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)) {
7562 			printf("Device doesn't support out-of-place scatter-gather "
7563 					"in both input and output mbufs.\n");
7564 			return TEST_SKIPPED;
7565 		}
7566 		if (!(feat_flags & RTE_CRYPTODEV_FF_DIGEST_ENCRYPTED)) {
7567 			printf("Device doesn't support digest encrypted.\n");
7568 			return TEST_SKIPPED;
7569 		}
7570 	}
7571 
7572 	/* Create the session */
7573 	if (verify)
7574 		retval = create_wireless_algo_cipher_auth_session(
7575 				ts_params->valid_devs[0],
7576 				RTE_CRYPTO_CIPHER_OP_DECRYPT,
7577 				RTE_CRYPTO_AUTH_OP_VERIFY,
7578 				tdata->auth_algo,
7579 				tdata->cipher_algo,
7580 				tdata->auth_key.data, tdata->auth_key.len,
7581 				tdata->auth_iv.len, tdata->digest_enc.len,
7582 				tdata->cipher_iv.len);
7583 	else
7584 		retval = create_wireless_algo_auth_cipher_session(
7585 				ts_params->valid_devs[0],
7586 				RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7587 				RTE_CRYPTO_AUTH_OP_GENERATE,
7588 				tdata->auth_algo,
7589 				tdata->cipher_algo,
7590 				tdata->auth_key.data, tdata->auth_key.len,
7591 				tdata->auth_iv.len, tdata->digest_enc.len,
7592 				tdata->cipher_iv.len);
7593 	if (retval != 0)
7594 		return retval;
7595 
7596 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len_bits);
7597 	plaintext_len = ceil_byte_length(tdata->plaintext.len_bits);
7598 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
7599 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
7600 
7601 	ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
7602 			ciphertext_pad_len, 15, 0);
7603 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7604 			"Failed to allocate input buffer in mempool");
7605 
7606 	if (op_mode == OUT_OF_PLACE) {
7607 		ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
7608 				plaintext_pad_len, 15, 0);
7609 		TEST_ASSERT_NOT_NULL(ut_params->obuf,
7610 				"Failed to allocate output buffer in mempool");
7611 	}
7612 
7613 	if (verify) {
7614 		pktmbuf_write(ut_params->ibuf, 0, ciphertext_len,
7615 			tdata->ciphertext.data);
7616 		ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7617 					ciphertext_len, buffer);
7618 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7619 			ciphertext_len);
7620 	} else {
7621 		pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
7622 			tdata->plaintext.data);
7623 		plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7624 					plaintext_len, buffer);
7625 		debug_hexdump(stdout, "plaintext:", plaintext,
7626 			plaintext_len);
7627 	}
7628 	memset(buffer, 0, sizeof(buffer));
7629 
7630 	/* Create the operation */
7631 	retval = create_wireless_algo_auth_cipher_operation(
7632 			tdata->digest_enc.data, tdata->digest_enc.len,
7633 			tdata->cipher_iv.data, tdata->cipher_iv.len,
7634 			tdata->auth_iv.data, tdata->auth_iv.len,
7635 			(tdata->digest_enc.offset == 0 ?
7636 				plaintext_pad_len
7637 				: tdata->digest_enc.offset),
7638 			tdata->validCipherLen.len_bits,
7639 			tdata->cipher.offset_bits,
7640 			tdata->validAuthLen.len_bits,
7641 			tdata->auth.offset_bits,
7642 			op_mode, 1, verify);
7643 
7644 	if (retval < 0)
7645 		return retval;
7646 
7647 	op = process_crypto_request(ts_params->valid_devs[0], ut_params->op);
7648 
7649 	/* Check if the op failed because the device doesn't */
7650 	/* support this particular combination of algorithms */
7651 	if (op == NULL && ut_params->op->status ==
7652 			RTE_CRYPTO_OP_STATUS_INVALID_SESSION) {
7653 		printf("Device doesn't support this mixed combination. "
7654 				"Test Skipped.\n");
7655 		return TEST_SKIPPED;
7656 	}
7657 	ut_params->op = op;
7658 
7659 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
7660 
7661 	ut_params->obuf = (op_mode == IN_PLACE ?
7662 			ut_params->op->sym->m_src : ut_params->op->sym->m_dst);
7663 
7664 	if (verify) {
7665 		if (ut_params->obuf)
7666 			plaintext = rte_pktmbuf_read(ut_params->obuf, 0,
7667 					plaintext_len, buffer);
7668 		else
7669 			plaintext = rte_pktmbuf_read(ut_params->ibuf, 0,
7670 					plaintext_len, buffer);
7671 
7672 		debug_hexdump(stdout, "plaintext:", plaintext,
7673 				(tdata->plaintext.len_bits >> 3) -
7674 				tdata->digest_enc.len);
7675 		debug_hexdump(stdout, "plaintext expected:",
7676 				tdata->plaintext.data,
7677 				(tdata->plaintext.len_bits >> 3) -
7678 				tdata->digest_enc.len);
7679 	} else {
7680 		if (ut_params->obuf)
7681 			ciphertext = rte_pktmbuf_read(ut_params->obuf, 0,
7682 					ciphertext_len, buffer);
7683 		else
7684 			ciphertext = rte_pktmbuf_read(ut_params->ibuf, 0,
7685 					ciphertext_len, buffer);
7686 
7687 		debug_hexdump(stdout, "ciphertext:", ciphertext,
7688 			ciphertext_len);
7689 		debug_hexdump(stdout, "ciphertext expected:",
7690 			tdata->ciphertext.data,
7691 			tdata->ciphertext.len_bits >> 3);
7692 
7693 		if (ut_params->obuf)
7694 			digest = rte_pktmbuf_read(ut_params->obuf,
7695 					(tdata->digest_enc.offset == 0 ?
7696 						plaintext_pad_len :
7697 						tdata->digest_enc.offset),
7698 					tdata->digest_enc.len, digest_buffer);
7699 		else
7700 			digest = rte_pktmbuf_read(ut_params->ibuf,
7701 					(tdata->digest_enc.offset == 0 ?
7702 						plaintext_pad_len :
7703 						tdata->digest_enc.offset),
7704 					tdata->digest_enc.len, digest_buffer);
7705 
7706 		debug_hexdump(stdout, "digest:", digest,
7707 				tdata->digest_enc.len);
7708 		debug_hexdump(stdout, "digest expected:",
7709 				tdata->digest_enc.data, tdata->digest_enc.len);
7710 	}
7711 
7712 	if (!verify) {
7713 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
7714 				digest,
7715 				tdata->digest_enc.data,
7716 				tdata->digest_enc.len,
7717 				"Generated auth tag not as expected");
7718 	}
7719 
7720 	if (tdata->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
7721 		if (verify) {
7722 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7723 					plaintext,
7724 					tdata->plaintext.data,
7725 					tdata->plaintext.len_bits >> 3,
7726 					"Plaintext data not as expected");
7727 		} else {
7728 			TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
7729 					ciphertext,
7730 					tdata->ciphertext.data,
7731 					tdata->validDataLen.len_bits,
7732 					"Ciphertext data not as expected");
7733 		}
7734 	}
7735 
7736 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7737 			"crypto op processing failed");
7738 
7739 	return 0;
7740 }
7741 
7742 /** AUTH AES CMAC + CIPHER AES CTR */
7743 
7744 static int
7745 test_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7746 {
7747 	return test_mixed_auth_cipher(
7748 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7749 }
7750 
7751 static int
7752 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7753 {
7754 	return test_mixed_auth_cipher(
7755 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7756 }
7757 
7758 static int
7759 test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7760 {
7761 	return test_mixed_auth_cipher_sgl(
7762 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 0);
7763 }
7764 
7765 static int
7766 test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7767 {
7768 	return test_mixed_auth_cipher_sgl(
7769 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7770 }
7771 
7772 static int
7773 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1(void)
7774 {
7775 	return test_mixed_auth_cipher(
7776 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7777 }
7778 
7779 static int
7780 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop(void)
7781 {
7782 	return test_mixed_auth_cipher(
7783 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7784 }
7785 
7786 static int
7787 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl(void)
7788 {
7789 	return test_mixed_auth_cipher_sgl(
7790 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, IN_PLACE, 1);
7791 }
7792 
7793 static int
7794 test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl(void)
7795 {
7796 	return test_mixed_auth_cipher_sgl(
7797 		&auth_aes_cmac_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7798 }
7799 
7800 /** MIXED AUTH + CIPHER */
7801 
7802 static int
7803 test_auth_zuc_cipher_snow_test_case_1(void)
7804 {
7805 	return test_mixed_auth_cipher(
7806 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7807 }
7808 
7809 static int
7810 test_verify_auth_zuc_cipher_snow_test_case_1(void)
7811 {
7812 	return test_mixed_auth_cipher(
7813 		&auth_zuc_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7814 }
7815 
7816 static int
7817 test_auth_aes_cmac_cipher_snow_test_case_1(void)
7818 {
7819 	return test_mixed_auth_cipher(
7820 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7821 }
7822 
7823 static int
7824 test_verify_auth_aes_cmac_cipher_snow_test_case_1(void)
7825 {
7826 	return test_mixed_auth_cipher(
7827 		&auth_aes_cmac_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7828 }
7829 
7830 static int
7831 test_auth_zuc_cipher_aes_ctr_test_case_1(void)
7832 {
7833 	return test_mixed_auth_cipher(
7834 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7835 }
7836 
7837 static int
7838 test_verify_auth_zuc_cipher_aes_ctr_test_case_1(void)
7839 {
7840 	return test_mixed_auth_cipher(
7841 		&auth_zuc_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7842 }
7843 
7844 static int
7845 test_auth_snow_cipher_aes_ctr_test_case_1(void)
7846 {
7847 	return test_mixed_auth_cipher(
7848 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7849 }
7850 
7851 static int
7852 test_verify_auth_snow_cipher_aes_ctr_test_case_1(void)
7853 {
7854 	return test_mixed_auth_cipher(
7855 		&auth_snow_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7856 }
7857 
7858 static int
7859 test_auth_snow_cipher_zuc_test_case_1(void)
7860 {
7861 	return test_mixed_auth_cipher(
7862 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7863 }
7864 
7865 static int
7866 test_verify_auth_snow_cipher_zuc_test_case_1(void)
7867 {
7868 	return test_mixed_auth_cipher(
7869 		&auth_snow_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7870 }
7871 
7872 static int
7873 test_auth_aes_cmac_cipher_zuc_test_case_1(void)
7874 {
7875 	return test_mixed_auth_cipher(
7876 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7877 }
7878 
7879 static int
7880 test_verify_auth_aes_cmac_cipher_zuc_test_case_1(void)
7881 {
7882 	return test_mixed_auth_cipher(
7883 		&auth_aes_cmac_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7884 }
7885 
7886 static int
7887 test_auth_null_cipher_snow_test_case_1(void)
7888 {
7889 	return test_mixed_auth_cipher(
7890 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 0);
7891 }
7892 
7893 static int
7894 test_verify_auth_null_cipher_snow_test_case_1(void)
7895 {
7896 	return test_mixed_auth_cipher(
7897 		&auth_null_cipher_snow_test_case_1, OUT_OF_PLACE, 1);
7898 }
7899 
7900 static int
7901 test_auth_null_cipher_zuc_test_case_1(void)
7902 {
7903 	return test_mixed_auth_cipher(
7904 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 0);
7905 }
7906 
7907 static int
7908 test_verify_auth_null_cipher_zuc_test_case_1(void)
7909 {
7910 	return test_mixed_auth_cipher(
7911 		&auth_null_cipher_zuc_test_case_1, OUT_OF_PLACE, 1);
7912 }
7913 
7914 static int
7915 test_auth_snow_cipher_null_test_case_1(void)
7916 {
7917 	return test_mixed_auth_cipher(
7918 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7919 }
7920 
7921 static int
7922 test_verify_auth_snow_cipher_null_test_case_1(void)
7923 {
7924 	return test_mixed_auth_cipher(
7925 		&auth_snow_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7926 }
7927 
7928 static int
7929 test_auth_zuc_cipher_null_test_case_1(void)
7930 {
7931 	return test_mixed_auth_cipher(
7932 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7933 }
7934 
7935 static int
7936 test_verify_auth_zuc_cipher_null_test_case_1(void)
7937 {
7938 	return test_mixed_auth_cipher(
7939 		&auth_zuc_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7940 }
7941 
7942 static int
7943 test_auth_null_cipher_aes_ctr_test_case_1(void)
7944 {
7945 	return test_mixed_auth_cipher(
7946 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 0);
7947 }
7948 
7949 static int
7950 test_verify_auth_null_cipher_aes_ctr_test_case_1(void)
7951 {
7952 	return test_mixed_auth_cipher(
7953 		&auth_null_cipher_aes_ctr_test_case_1, OUT_OF_PLACE, 1);
7954 }
7955 
7956 static int
7957 test_auth_aes_cmac_cipher_null_test_case_1(void)
7958 {
7959 	return test_mixed_auth_cipher(
7960 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 0);
7961 }
7962 
7963 static int
7964 test_verify_auth_aes_cmac_cipher_null_test_case_1(void)
7965 {
7966 	return test_mixed_auth_cipher(
7967 		&auth_aes_cmac_cipher_null_test_case_1, OUT_OF_PLACE, 1);
7968 }
7969 
7970 /* ***** AEAD algorithm Tests ***** */
7971 
7972 static int
7973 create_aead_session(uint8_t dev_id, enum rte_crypto_aead_algorithm algo,
7974 		enum rte_crypto_aead_operation op,
7975 		const uint8_t *key, const uint8_t key_len,
7976 		const uint16_t aad_len, const uint8_t auth_len,
7977 		uint8_t iv_len)
7978 {
7979 	uint8_t aead_key[key_len];
7980 	int status;
7981 
7982 	struct crypto_testsuite_params *ts_params = &testsuite_params;
7983 	struct crypto_unittest_params *ut_params = &unittest_params;
7984 
7985 	memcpy(aead_key, key, key_len);
7986 
7987 	/* Setup AEAD Parameters */
7988 	ut_params->aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
7989 	ut_params->aead_xform.next = NULL;
7990 	ut_params->aead_xform.aead.algo = algo;
7991 	ut_params->aead_xform.aead.op = op;
7992 	ut_params->aead_xform.aead.key.data = aead_key;
7993 	ut_params->aead_xform.aead.key.length = key_len;
7994 	ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
7995 	ut_params->aead_xform.aead.iv.length = iv_len;
7996 	ut_params->aead_xform.aead.digest_length = auth_len;
7997 	ut_params->aead_xform.aead.aad_length = aad_len;
7998 
7999 	debug_hexdump(stdout, "key:", key, key_len);
8000 
8001 	/* Create Crypto session*/
8002 	ut_params->sess = rte_cryptodev_sym_session_create(
8003 			ts_params->session_mpool);
8004 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
8005 
8006 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
8007 			&ut_params->aead_xform,
8008 			ts_params->session_priv_mpool);
8009 
8010 	return status;
8011 }
8012 
8013 static int
8014 create_aead_xform(struct rte_crypto_op *op,
8015 		enum rte_crypto_aead_algorithm algo,
8016 		enum rte_crypto_aead_operation aead_op,
8017 		uint8_t *key, const uint8_t key_len,
8018 		const uint8_t aad_len, const uint8_t auth_len,
8019 		uint8_t iv_len)
8020 {
8021 	TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 1),
8022 			"failed to allocate space for crypto transform");
8023 
8024 	struct rte_crypto_sym_op *sym_op = op->sym;
8025 
8026 	/* Setup AEAD Parameters */
8027 	sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_AEAD;
8028 	sym_op->xform->next = NULL;
8029 	sym_op->xform->aead.algo = algo;
8030 	sym_op->xform->aead.op = aead_op;
8031 	sym_op->xform->aead.key.data = key;
8032 	sym_op->xform->aead.key.length = key_len;
8033 	sym_op->xform->aead.iv.offset = IV_OFFSET;
8034 	sym_op->xform->aead.iv.length = iv_len;
8035 	sym_op->xform->aead.digest_length = auth_len;
8036 	sym_op->xform->aead.aad_length = aad_len;
8037 
8038 	debug_hexdump(stdout, "key:", key, key_len);
8039 
8040 	return 0;
8041 }
8042 
8043 static int
8044 create_aead_operation(enum rte_crypto_aead_operation op,
8045 		const struct aead_test_data *tdata)
8046 {
8047 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8048 	struct crypto_unittest_params *ut_params = &unittest_params;
8049 
8050 	uint8_t *plaintext, *ciphertext;
8051 	unsigned int aad_pad_len, plaintext_pad_len;
8052 
8053 	/* Generate Crypto op data structure */
8054 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8055 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8056 	TEST_ASSERT_NOT_NULL(ut_params->op,
8057 			"Failed to allocate symmetric crypto operation struct");
8058 
8059 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
8060 
8061 	/* Append aad data */
8062 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
8063 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len + 18, 16);
8064 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8065 				aad_pad_len);
8066 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8067 				"no room to append aad");
8068 
8069 		sym_op->aead.aad.phys_addr =
8070 				rte_pktmbuf_iova(ut_params->ibuf);
8071 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
8072 		memcpy(sym_op->aead.aad.data + 18, tdata->aad.data, tdata->aad.len);
8073 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8074 			tdata->aad.len);
8075 
8076 		/* Append IV at the end of the crypto operation*/
8077 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8078 				uint8_t *, IV_OFFSET);
8079 
8080 		/* Copy IV 1 byte after the IV pointer, according to the API */
8081 		rte_memcpy(iv_ptr + 1, tdata->iv.data, tdata->iv.len);
8082 		debug_hexdump(stdout, "iv:", iv_ptr,
8083 			tdata->iv.len);
8084 	} else {
8085 		aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
8086 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8087 				aad_pad_len);
8088 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
8089 				"no room to append aad");
8090 
8091 		sym_op->aead.aad.phys_addr =
8092 				rte_pktmbuf_iova(ut_params->ibuf);
8093 		memcpy(sym_op->aead.aad.data, tdata->aad.data, tdata->aad.len);
8094 		debug_hexdump(stdout, "aad:", sym_op->aead.aad.data,
8095 			tdata->aad.len);
8096 
8097 		/* Append IV at the end of the crypto operation*/
8098 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
8099 				uint8_t *, IV_OFFSET);
8100 
8101 		if (tdata->iv.len == 0) {
8102 			rte_memcpy(iv_ptr, tdata->iv.data, AES_GCM_J0_LENGTH);
8103 			debug_hexdump(stdout, "iv:", iv_ptr,
8104 				AES_GCM_J0_LENGTH);
8105 		} else {
8106 			rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
8107 			debug_hexdump(stdout, "iv:", iv_ptr,
8108 				tdata->iv.len);
8109 		}
8110 	}
8111 
8112 	/* Append plaintext/ciphertext */
8113 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8114 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8115 		plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8116 				plaintext_pad_len);
8117 		TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
8118 
8119 		memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
8120 		debug_hexdump(stdout, "plaintext:", plaintext,
8121 				tdata->plaintext.len);
8122 
8123 		if (ut_params->obuf) {
8124 			ciphertext = (uint8_t *)rte_pktmbuf_append(
8125 					ut_params->obuf,
8126 					plaintext_pad_len + aad_pad_len);
8127 			TEST_ASSERT_NOT_NULL(ciphertext,
8128 					"no room to append ciphertext");
8129 
8130 			memset(ciphertext + aad_pad_len, 0,
8131 					tdata->ciphertext.len);
8132 		}
8133 	} else {
8134 		plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
8135 		ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8136 				plaintext_pad_len);
8137 		TEST_ASSERT_NOT_NULL(ciphertext,
8138 				"no room to append ciphertext");
8139 
8140 		memcpy(ciphertext, tdata->ciphertext.data,
8141 				tdata->ciphertext.len);
8142 		debug_hexdump(stdout, "ciphertext:", ciphertext,
8143 				tdata->ciphertext.len);
8144 
8145 		if (ut_params->obuf) {
8146 			plaintext = (uint8_t *)rte_pktmbuf_append(
8147 					ut_params->obuf,
8148 					plaintext_pad_len + aad_pad_len);
8149 			TEST_ASSERT_NOT_NULL(plaintext,
8150 					"no room to append plaintext");
8151 
8152 			memset(plaintext + aad_pad_len, 0,
8153 					tdata->plaintext.len);
8154 		}
8155 	}
8156 
8157 	/* Append digest data */
8158 	if (op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
8159 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8160 				ut_params->obuf ? ut_params->obuf :
8161 						ut_params->ibuf,
8162 						tdata->auth_tag.len);
8163 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8164 				"no room to append digest");
8165 		memset(sym_op->aead.digest.data, 0, tdata->auth_tag.len);
8166 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8167 				ut_params->obuf ? ut_params->obuf :
8168 						ut_params->ibuf,
8169 						plaintext_pad_len +
8170 						aad_pad_len);
8171 	} else {
8172 		sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append(
8173 				ut_params->ibuf, tdata->auth_tag.len);
8174 		TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
8175 				"no room to append digest");
8176 		sym_op->aead.digest.phys_addr = rte_pktmbuf_iova_offset(
8177 				ut_params->ibuf,
8178 				plaintext_pad_len + aad_pad_len);
8179 
8180 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
8181 			tdata->auth_tag.len);
8182 		debug_hexdump(stdout, "digest:",
8183 			sym_op->aead.digest.data,
8184 			tdata->auth_tag.len);
8185 	}
8186 
8187 	sym_op->aead.data.length = tdata->plaintext.len;
8188 	sym_op->aead.data.offset = aad_pad_len;
8189 
8190 	return 0;
8191 }
8192 
8193 static int
8194 test_authenticated_encryption(const struct aead_test_data *tdata)
8195 {
8196 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8197 	struct crypto_unittest_params *ut_params = &unittest_params;
8198 
8199 	int retval;
8200 	uint8_t *ciphertext, *auth_tag;
8201 	uint16_t plaintext_pad_len;
8202 	uint32_t i;
8203 	struct rte_cryptodev_info dev_info;
8204 
8205 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8206 	uint64_t feat_flags = dev_info.feature_flags;
8207 
8208 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8209 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8210 		printf("Device doesn't support RAW data-path APIs.\n");
8211 		return TEST_SKIPPED;
8212 	}
8213 
8214 	/* Verify the capabilities */
8215 	struct rte_cryptodev_sym_capability_idx cap_idx;
8216 	const struct rte_cryptodev_symmetric_capability *capability;
8217 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
8218 	cap_idx.algo.aead = tdata->algo;
8219 	capability = rte_cryptodev_sym_capability_get(
8220 			ts_params->valid_devs[0], &cap_idx);
8221 	if (capability == NULL)
8222 		return TEST_SKIPPED;
8223 	if (rte_cryptodev_sym_capability_check_aead(
8224 			capability, tdata->key.len, tdata->auth_tag.len,
8225 			tdata->aad.len, tdata->iv.len))
8226 		return TEST_SKIPPED;
8227 
8228 	/* Create AEAD session */
8229 	retval = create_aead_session(ts_params->valid_devs[0],
8230 			tdata->algo,
8231 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
8232 			tdata->key.data, tdata->key.len,
8233 			tdata->aad.len, tdata->auth_tag.len,
8234 			tdata->iv.len);
8235 	if (retval < 0)
8236 		return retval;
8237 
8238 	if (tdata->aad.len > MBUF_SIZE) {
8239 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
8240 		/* Populate full size of add data */
8241 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
8242 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
8243 	} else
8244 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8245 
8246 	/* clear mbuf payload */
8247 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8248 			rte_pktmbuf_tailroom(ut_params->ibuf));
8249 
8250 	/* Create AEAD operation */
8251 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
8252 	if (retval < 0)
8253 		return retval;
8254 
8255 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
8256 
8257 	ut_params->op->sym->m_src = ut_params->ibuf;
8258 
8259 	/* Process crypto operation */
8260 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
8261 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
8262 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
8263 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8264 				ut_params->op, 0, 0, 0, 0);
8265 	else
8266 		TEST_ASSERT_NOT_NULL(
8267 			process_crypto_request(ts_params->valid_devs[0],
8268 			ut_params->op), "failed to process sym crypto op");
8269 
8270 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
8271 			"crypto op processing failed");
8272 
8273 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
8274 
8275 	if (ut_params->op->sym->m_dst) {
8276 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8277 				uint8_t *);
8278 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
8279 				uint8_t *, plaintext_pad_len);
8280 	} else {
8281 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
8282 				uint8_t *,
8283 				ut_params->op->sym->cipher.data.offset);
8284 		auth_tag = ciphertext + plaintext_pad_len;
8285 	}
8286 
8287 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
8288 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
8289 
8290 	/* Validate obuf */
8291 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8292 			ciphertext,
8293 			tdata->ciphertext.data,
8294 			tdata->ciphertext.len,
8295 			"Ciphertext data not as expected");
8296 
8297 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
8298 			auth_tag,
8299 			tdata->auth_tag.data,
8300 			tdata->auth_tag.len,
8301 			"Generated auth tag not as expected");
8302 
8303 	return 0;
8304 
8305 }
8306 
8307 #ifdef RTE_LIB_SECURITY
8308 static int
8309 security_proto_supported(enum rte_security_session_action_type action,
8310 	enum rte_security_session_protocol proto)
8311 {
8312 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8313 
8314 	const struct rte_security_capability *capabilities;
8315 	const struct rte_security_capability *capability;
8316 	uint16_t i = 0;
8317 
8318 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8319 				rte_cryptodev_get_sec_ctx(
8320 				ts_params->valid_devs[0]);
8321 
8322 
8323 	capabilities = rte_security_capabilities_get(ctx);
8324 
8325 	if (capabilities == NULL)
8326 		return -ENOTSUP;
8327 
8328 	while ((capability = &capabilities[i++])->action !=
8329 			RTE_SECURITY_ACTION_TYPE_NONE) {
8330 		if (capability->action == action &&
8331 				capability->protocol == proto)
8332 			return 0;
8333 	}
8334 
8335 	return -ENOTSUP;
8336 }
8337 
8338 /* Basic algorithm run function for async inplace mode.
8339  * Creates a session from input parameters and runs one operation
8340  * on input_vec. Checks the output of the crypto operation against
8341  * output_vec.
8342  */
8343 static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,
8344 			   enum rte_crypto_auth_operation opa,
8345 			   const uint8_t *input_vec, unsigned int input_vec_len,
8346 			   const uint8_t *output_vec,
8347 			   unsigned int output_vec_len,
8348 			   enum rte_crypto_cipher_algorithm cipher_alg,
8349 			   const uint8_t *cipher_key, uint32_t cipher_key_len,
8350 			   enum rte_crypto_auth_algorithm auth_alg,
8351 			   const uint8_t *auth_key, uint32_t auth_key_len,
8352 			   uint8_t bearer, enum rte_security_pdcp_domain domain,
8353 			   uint8_t packet_direction, uint8_t sn_size,
8354 			   uint32_t hfn, uint32_t hfn_threshold, uint8_t sdap)
8355 {
8356 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8357 	struct crypto_unittest_params *ut_params = &unittest_params;
8358 	uint8_t *plaintext;
8359 	int ret = TEST_SUCCESS;
8360 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8361 				rte_cryptodev_get_sec_ctx(
8362 				ts_params->valid_devs[0]);
8363 
8364 	/* Verify the capabilities */
8365 	struct rte_security_capability_idx sec_cap_idx;
8366 
8367 	sec_cap_idx.action = ut_params->type;
8368 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8369 	sec_cap_idx.pdcp.domain = domain;
8370 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8371 		return TEST_SKIPPED;
8372 
8373 	/* Generate test mbuf data */
8374 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8375 
8376 	/* clear mbuf payload */
8377 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8378 			rte_pktmbuf_tailroom(ut_params->ibuf));
8379 
8380 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8381 						  input_vec_len);
8382 	memcpy(plaintext, input_vec, input_vec_len);
8383 
8384 	/* Out of place support */
8385 	if (oop) {
8386 		/*
8387 		 * For out-op-place we need to alloc another mbuf
8388 		 */
8389 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8390 		rte_pktmbuf_append(ut_params->obuf, output_vec_len);
8391 	}
8392 
8393 	/* Setup Cipher Parameters */
8394 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8395 	ut_params->cipher_xform.cipher.algo = cipher_alg;
8396 	ut_params->cipher_xform.cipher.op = opc;
8397 	ut_params->cipher_xform.cipher.key.data = cipher_key;
8398 	ut_params->cipher_xform.cipher.key.length = cipher_key_len;
8399 	ut_params->cipher_xform.cipher.iv.length =
8400 				packet_direction ? 4 : 0;
8401 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
8402 
8403 	/* Setup HMAC Parameters if ICV header is required */
8404 	if (auth_alg != 0) {
8405 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8406 		ut_params->auth_xform.next = NULL;
8407 		ut_params->auth_xform.auth.algo = auth_alg;
8408 		ut_params->auth_xform.auth.op = opa;
8409 		ut_params->auth_xform.auth.key.data = auth_key;
8410 		ut_params->auth_xform.auth.key.length = auth_key_len;
8411 
8412 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8413 	} else {
8414 		ut_params->cipher_xform.next = NULL;
8415 	}
8416 
8417 	struct rte_security_session_conf sess_conf = {
8418 		.action_type = ut_params->type,
8419 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8420 		{.pdcp = {
8421 			.bearer = bearer,
8422 			.domain = domain,
8423 			.pkt_dir = packet_direction,
8424 			.sn_size = sn_size,
8425 			.hfn = packet_direction ? 0 : hfn,
8426 			/**
8427 			 * hfn can be set as pdcp_test_hfn[i]
8428 			 * if hfn_ovrd is not set. Here, PDCP
8429 			 * packet direction is just used to
8430 			 * run half of the cases with session
8431 			 * HFN and other half with per packet
8432 			 * HFN.
8433 			 */
8434 			.hfn_threshold = hfn_threshold,
8435 			.hfn_ovrd = packet_direction ? 1 : 0,
8436 			.sdap_enabled = sdap,
8437 		} },
8438 		.crypto_xform = &ut_params->cipher_xform
8439 	};
8440 
8441 	/* Create security session */
8442 	ut_params->sec_session = rte_security_session_create(ctx,
8443 				&sess_conf, ts_params->session_mpool,
8444 				ts_params->session_priv_mpool);
8445 
8446 	if (!ut_params->sec_session) {
8447 		printf("TestCase %s()-%d line %d failed %s: ",
8448 			__func__, i, __LINE__, "Failed to allocate session");
8449 		ret = TEST_FAILED;
8450 		goto on_err;
8451 	}
8452 
8453 	/* Generate crypto op data structure */
8454 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8455 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8456 	if (!ut_params->op) {
8457 		printf("TestCase %s()-%d line %d failed %s: ",
8458 			__func__, i, __LINE__,
8459 			"Failed to allocate symmetric crypto operation struct");
8460 		ret = TEST_FAILED;
8461 		goto on_err;
8462 	}
8463 
8464 	uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ut_params->op,
8465 					uint32_t *, IV_OFFSET);
8466 	*per_pkt_hfn = packet_direction ? hfn : 0;
8467 
8468 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8469 
8470 	/* set crypto operation source mbuf */
8471 	ut_params->op->sym->m_src = ut_params->ibuf;
8472 	if (oop)
8473 		ut_params->op->sym->m_dst = ut_params->obuf;
8474 
8475 	/* Process crypto operation */
8476 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op)
8477 		== NULL) {
8478 		printf("TestCase %s()-%d line %d failed %s: ",
8479 			__func__, i, __LINE__,
8480 			"failed to process sym crypto op");
8481 		ret = TEST_FAILED;
8482 		goto on_err;
8483 	}
8484 
8485 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8486 		printf("TestCase %s()-%d line %d failed %s: ",
8487 			__func__, i, __LINE__, "crypto op processing failed");
8488 		ret = TEST_FAILED;
8489 		goto on_err;
8490 	}
8491 
8492 	/* Validate obuf */
8493 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8494 			uint8_t *);
8495 	if (oop) {
8496 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8497 				uint8_t *);
8498 	}
8499 
8500 	if (memcmp(ciphertext, output_vec, output_vec_len)) {
8501 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8502 		rte_hexdump(stdout, "encrypted", ciphertext, output_vec_len);
8503 		rte_hexdump(stdout, "reference", output_vec, output_vec_len);
8504 		ret = TEST_FAILED;
8505 		goto on_err;
8506 	}
8507 
8508 on_err:
8509 	rte_crypto_op_free(ut_params->op);
8510 	ut_params->op = NULL;
8511 
8512 	if (ut_params->sec_session)
8513 		rte_security_session_destroy(ctx, ut_params->sec_session);
8514 	ut_params->sec_session = NULL;
8515 
8516 	rte_pktmbuf_free(ut_params->ibuf);
8517 	ut_params->ibuf = NULL;
8518 	if (oop) {
8519 		rte_pktmbuf_free(ut_params->obuf);
8520 		ut_params->obuf = NULL;
8521 	}
8522 
8523 	return ret;
8524 }
8525 
8526 static int
8527 test_pdcp_proto_SGL(int i, int oop,
8528 	enum rte_crypto_cipher_operation opc,
8529 	enum rte_crypto_auth_operation opa,
8530 	uint8_t *input_vec,
8531 	unsigned int input_vec_len,
8532 	uint8_t *output_vec,
8533 	unsigned int output_vec_len,
8534 	uint32_t fragsz,
8535 	uint32_t fragsz_oop)
8536 {
8537 	struct crypto_testsuite_params *ts_params = &testsuite_params;
8538 	struct crypto_unittest_params *ut_params = &unittest_params;
8539 	uint8_t *plaintext;
8540 	struct rte_mbuf *buf, *buf_oop = NULL;
8541 	int ret = TEST_SUCCESS;
8542 	int to_trn = 0;
8543 	int to_trn_tbl[16];
8544 	int segs = 1;
8545 	unsigned int trn_data = 0;
8546 	struct rte_cryptodev_info dev_info;
8547 	uint64_t feat_flags;
8548 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
8549 				rte_cryptodev_get_sec_ctx(
8550 				ts_params->valid_devs[0]);
8551 	struct rte_mbuf *temp_mbuf;
8552 
8553 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
8554 	feat_flags = dev_info.feature_flags;
8555 
8556 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
8557 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
8558 		printf("Device does not support RAW data-path APIs.\n");
8559 		return -ENOTSUP;
8560 	}
8561 	/* Verify the capabilities */
8562 	struct rte_security_capability_idx sec_cap_idx;
8563 
8564 	sec_cap_idx.action = ut_params->type;
8565 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_PDCP;
8566 	sec_cap_idx.pdcp.domain = pdcp_test_params[i].domain;
8567 	if (rte_security_capability_get(ctx, &sec_cap_idx) == NULL)
8568 		return TEST_SKIPPED;
8569 
8570 	if (fragsz > input_vec_len)
8571 		fragsz = input_vec_len;
8572 
8573 	uint16_t plaintext_len = fragsz;
8574 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
8575 
8576 	if (fragsz_oop > output_vec_len)
8577 		frag_size_oop = output_vec_len;
8578 
8579 	int ecx = 0;
8580 	if (input_vec_len % fragsz != 0) {
8581 		if (input_vec_len / fragsz + 1 > 16)
8582 			return 1;
8583 	} else if (input_vec_len / fragsz > 16)
8584 		return 1;
8585 
8586 	/* Out of place support */
8587 	if (oop) {
8588 		/*
8589 		 * For out-op-place we need to alloc another mbuf
8590 		 */
8591 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8592 		rte_pktmbuf_append(ut_params->obuf, frag_size_oop);
8593 		buf_oop = ut_params->obuf;
8594 	}
8595 
8596 	/* Generate test mbuf data */
8597 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8598 
8599 	/* clear mbuf payload */
8600 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
8601 			rte_pktmbuf_tailroom(ut_params->ibuf));
8602 
8603 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
8604 						  plaintext_len);
8605 	memcpy(plaintext, input_vec, plaintext_len);
8606 	trn_data += plaintext_len;
8607 
8608 	buf = ut_params->ibuf;
8609 
8610 	/*
8611 	 * Loop until no more fragments
8612 	 */
8613 
8614 	while (trn_data < input_vec_len) {
8615 		++segs;
8616 		to_trn = (input_vec_len - trn_data < fragsz) ?
8617 				(input_vec_len - trn_data) : fragsz;
8618 
8619 		to_trn_tbl[ecx++] = to_trn;
8620 
8621 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
8622 		buf = buf->next;
8623 
8624 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
8625 				rte_pktmbuf_tailroom(buf));
8626 
8627 		/* OOP */
8628 		if (oop && !fragsz_oop) {
8629 			buf_oop->next =
8630 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
8631 			buf_oop = buf_oop->next;
8632 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8633 					0, rte_pktmbuf_tailroom(buf_oop));
8634 			rte_pktmbuf_append(buf_oop, to_trn);
8635 		}
8636 
8637 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
8638 				to_trn);
8639 
8640 		memcpy(plaintext, input_vec + trn_data, to_trn);
8641 		trn_data += to_trn;
8642 	}
8643 
8644 	ut_params->ibuf->nb_segs = segs;
8645 
8646 	segs = 1;
8647 	if (fragsz_oop && oop) {
8648 		to_trn = 0;
8649 		ecx = 0;
8650 
8651 		trn_data = frag_size_oop;
8652 		while (trn_data < output_vec_len) {
8653 			++segs;
8654 			to_trn =
8655 				(output_vec_len - trn_data <
8656 						frag_size_oop) ?
8657 				(output_vec_len - trn_data) :
8658 						frag_size_oop;
8659 
8660 			to_trn_tbl[ecx++] = to_trn;
8661 
8662 			buf_oop->next =
8663 				rte_pktmbuf_alloc(ts_params->mbuf_pool);
8664 			buf_oop = buf_oop->next;
8665 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
8666 					0, rte_pktmbuf_tailroom(buf_oop));
8667 			rte_pktmbuf_append(buf_oop, to_trn);
8668 
8669 			trn_data += to_trn;
8670 		}
8671 		ut_params->obuf->nb_segs = segs;
8672 	}
8673 
8674 	/* Setup Cipher Parameters */
8675 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
8676 	ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg;
8677 	ut_params->cipher_xform.cipher.op = opc;
8678 	ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i];
8679 	ut_params->cipher_xform.cipher.key.length =
8680 					pdcp_test_params[i].cipher_key_len;
8681 	ut_params->cipher_xform.cipher.iv.length = 0;
8682 
8683 	/* Setup HMAC Parameters if ICV header is required */
8684 	if (pdcp_test_params[i].auth_alg != 0) {
8685 		ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
8686 		ut_params->auth_xform.next = NULL;
8687 		ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg;
8688 		ut_params->auth_xform.auth.op = opa;
8689 		ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i];
8690 		ut_params->auth_xform.auth.key.length =
8691 					pdcp_test_params[i].auth_key_len;
8692 
8693 		ut_params->cipher_xform.next = &ut_params->auth_xform;
8694 	} else {
8695 		ut_params->cipher_xform.next = NULL;
8696 	}
8697 
8698 	struct rte_security_session_conf sess_conf = {
8699 		.action_type = ut_params->type,
8700 		.protocol = RTE_SECURITY_PROTOCOL_PDCP,
8701 		{.pdcp = {
8702 			.bearer = pdcp_test_bearer[i],
8703 			.domain = pdcp_test_params[i].domain,
8704 			.pkt_dir = pdcp_test_packet_direction[i],
8705 			.sn_size = pdcp_test_data_sn_size[i],
8706 			.hfn = pdcp_test_hfn[i],
8707 			.hfn_threshold = pdcp_test_hfn_threshold[i],
8708 			.hfn_ovrd = 0,
8709 		} },
8710 		.crypto_xform = &ut_params->cipher_xform
8711 	};
8712 
8713 	/* Create security session */
8714 	ut_params->sec_session = rte_security_session_create(ctx,
8715 				&sess_conf, ts_params->session_mpool,
8716 				ts_params->session_priv_mpool);
8717 
8718 	if (!ut_params->sec_session) {
8719 		printf("TestCase %s()-%d line %d failed %s: ",
8720 			__func__, i, __LINE__, "Failed to allocate session");
8721 		ret = TEST_FAILED;
8722 		goto on_err;
8723 	}
8724 
8725 	/* Generate crypto op data structure */
8726 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
8727 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
8728 	if (!ut_params->op) {
8729 		printf("TestCase %s()-%d line %d failed %s: ",
8730 			__func__, i, __LINE__,
8731 			"Failed to allocate symmetric crypto operation struct");
8732 		ret = TEST_FAILED;
8733 		goto on_err;
8734 	}
8735 
8736 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
8737 
8738 	/* set crypto operation source mbuf */
8739 	ut_params->op->sym->m_src = ut_params->ibuf;
8740 	if (oop)
8741 		ut_params->op->sym->m_dst = ut_params->obuf;
8742 
8743 	/* Process crypto operation */
8744 	temp_mbuf = ut_params->op->sym->m_src;
8745 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST) {
8746 		/* filling lengths */
8747 		while (temp_mbuf) {
8748 			ut_params->op->sym->cipher.data.length
8749 				+= temp_mbuf->pkt_len;
8750 			ut_params->op->sym->auth.data.length
8751 				+= temp_mbuf->pkt_len;
8752 			temp_mbuf = temp_mbuf->next;
8753 		}
8754 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
8755 			ut_params->op, 1, 1, 0, 0);
8756 	} else {
8757 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
8758 							ut_params->op);
8759 	}
8760 	if (ut_params->op == NULL) {
8761 		printf("TestCase %s()-%d line %d failed %s: ",
8762 			__func__, i, __LINE__,
8763 			"failed to process sym crypto op");
8764 		ret = TEST_FAILED;
8765 		goto on_err;
8766 	}
8767 
8768 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
8769 		printf("TestCase %s()-%d line %d failed %s: ",
8770 			__func__, i, __LINE__, "crypto op processing failed");
8771 		ret = TEST_FAILED;
8772 		goto on_err;
8773 	}
8774 
8775 	/* Validate obuf */
8776 	uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src,
8777 			uint8_t *);
8778 	if (oop) {
8779 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
8780 				uint8_t *);
8781 	}
8782 	if (fragsz_oop)
8783 		fragsz = frag_size_oop;
8784 	if (memcmp(ciphertext, output_vec, fragsz)) {
8785 		printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8786 		rte_hexdump(stdout, "encrypted", ciphertext, fragsz);
8787 		rte_hexdump(stdout, "reference", output_vec, fragsz);
8788 		ret = TEST_FAILED;
8789 		goto on_err;
8790 	}
8791 
8792 	buf = ut_params->op->sym->m_src->next;
8793 	if (oop)
8794 		buf = ut_params->op->sym->m_dst->next;
8795 
8796 	unsigned int off = fragsz;
8797 
8798 	ecx = 0;
8799 	while (buf) {
8800 		ciphertext = rte_pktmbuf_mtod(buf,
8801 				uint8_t *);
8802 		if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) {
8803 			printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i);
8804 			rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]);
8805 			rte_hexdump(stdout, "reference", output_vec + off,
8806 					to_trn_tbl[ecx]);
8807 			ret = TEST_FAILED;
8808 			goto on_err;
8809 		}
8810 		off += to_trn_tbl[ecx++];
8811 		buf = buf->next;
8812 	}
8813 on_err:
8814 	rte_crypto_op_free(ut_params->op);
8815 	ut_params->op = NULL;
8816 
8817 	if (ut_params->sec_session)
8818 		rte_security_session_destroy(ctx, ut_params->sec_session);
8819 	ut_params->sec_session = NULL;
8820 
8821 	rte_pktmbuf_free(ut_params->ibuf);
8822 	ut_params->ibuf = NULL;
8823 	if (oop) {
8824 		rte_pktmbuf_free(ut_params->obuf);
8825 		ut_params->obuf = NULL;
8826 	}
8827 
8828 	return ret;
8829 }
8830 
8831 int
8832 test_pdcp_proto_cplane_encap(int i)
8833 {
8834 	return test_pdcp_proto(
8835 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8836 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8837 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8838 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8839 		pdcp_test_params[i].cipher_key_len,
8840 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8841 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8842 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8843 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8844 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8845 }
8846 
8847 int
8848 test_pdcp_proto_uplane_encap(int i)
8849 {
8850 	return test_pdcp_proto(
8851 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8852 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8853 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8854 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8855 		pdcp_test_params[i].cipher_key_len,
8856 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8857 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8858 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8859 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8860 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8861 }
8862 
8863 int
8864 test_pdcp_proto_uplane_encap_with_int(int i)
8865 {
8866 	return test_pdcp_proto(
8867 		i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT, RTE_CRYPTO_AUTH_OP_GENERATE,
8868 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8869 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8870 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8871 		pdcp_test_params[i].cipher_key_len,
8872 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8873 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8874 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8875 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8876 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8877 }
8878 
8879 int
8880 test_pdcp_proto_cplane_decap(int i)
8881 {
8882 	return test_pdcp_proto(
8883 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8884 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8885 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8886 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8887 		pdcp_test_params[i].cipher_key_len,
8888 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8889 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8890 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8891 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8892 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8893 }
8894 
8895 int
8896 test_pdcp_proto_uplane_decap(int i)
8897 {
8898 	return test_pdcp_proto(
8899 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8900 		pdcp_test_data_out[i], pdcp_test_data_in_len[i],
8901 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8902 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8903 		pdcp_test_params[i].cipher_key_len,
8904 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8905 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8906 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8907 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8908 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8909 }
8910 
8911 int
8912 test_pdcp_proto_uplane_decap_with_int(int i)
8913 {
8914 	return test_pdcp_proto(
8915 		i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT, RTE_CRYPTO_AUTH_OP_VERIFY,
8916 		pdcp_test_data_out[i], pdcp_test_data_in_len[i] + 4,
8917 		pdcp_test_data_in[i], pdcp_test_data_in_len[i],
8918 		pdcp_test_params[i].cipher_alg, pdcp_test_crypto_key[i],
8919 		pdcp_test_params[i].cipher_key_len,
8920 		pdcp_test_params[i].auth_alg, pdcp_test_auth_key[i],
8921 		pdcp_test_params[i].auth_key_len, pdcp_test_bearer[i],
8922 		pdcp_test_params[i].domain, pdcp_test_packet_direction[i],
8923 		pdcp_test_data_sn_size[i], pdcp_test_hfn[i],
8924 		pdcp_test_hfn_threshold[i], SDAP_DISABLED);
8925 }
8926 
8927 static int
8928 test_PDCP_PROTO_SGL_in_place_32B(void)
8929 {
8930 	/* i can be used for running any PDCP case
8931 	 * In this case it is uplane 12-bit AES-SNOW DL encap
8932 	 */
8933 	int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK;
8934 	return test_pdcp_proto_SGL(i, IN_PLACE,
8935 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8936 			RTE_CRYPTO_AUTH_OP_GENERATE,
8937 			pdcp_test_data_in[i],
8938 			pdcp_test_data_in_len[i],
8939 			pdcp_test_data_out[i],
8940 			pdcp_test_data_in_len[i]+4,
8941 			32, 0);
8942 }
8943 static int
8944 test_PDCP_PROTO_SGL_oop_32B_128B(void)
8945 {
8946 	/* i can be used for running any PDCP case
8947 	 * In this case it is uplane 18-bit NULL-NULL DL encap
8948 	 */
8949 	int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK;
8950 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8951 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8952 			RTE_CRYPTO_AUTH_OP_GENERATE,
8953 			pdcp_test_data_in[i],
8954 			pdcp_test_data_in_len[i],
8955 			pdcp_test_data_out[i],
8956 			pdcp_test_data_in_len[i]+4,
8957 			32, 128);
8958 }
8959 static int
8960 test_PDCP_PROTO_SGL_oop_32B_40B(void)
8961 {
8962 	/* i can be used for running any PDCP case
8963 	 * In this case it is uplane 18-bit AES DL encap
8964 	 */
8965 	int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET
8966 			+ DOWNLINK;
8967 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8968 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8969 			RTE_CRYPTO_AUTH_OP_GENERATE,
8970 			pdcp_test_data_in[i],
8971 			pdcp_test_data_in_len[i],
8972 			pdcp_test_data_out[i],
8973 			pdcp_test_data_in_len[i],
8974 			32, 40);
8975 }
8976 static int
8977 test_PDCP_PROTO_SGL_oop_128B_32B(void)
8978 {
8979 	/* i can be used for running any PDCP case
8980 	 * In this case it is cplane 12-bit AES-ZUC DL encap
8981 	 */
8982 	int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK;
8983 	return test_pdcp_proto_SGL(i, OUT_OF_PLACE,
8984 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
8985 			RTE_CRYPTO_AUTH_OP_GENERATE,
8986 			pdcp_test_data_in[i],
8987 			pdcp_test_data_in_len[i],
8988 			pdcp_test_data_out[i],
8989 			pdcp_test_data_in_len[i]+4,
8990 			128, 32);
8991 }
8992 
8993 static int
8994 test_PDCP_SDAP_PROTO_encap_all(void)
8995 {
8996 	int i = 0, size = 0;
8997 	int err, all_err = TEST_SUCCESS;
8998 	const struct pdcp_sdap_test *cur_test;
8999 
9000 	size = RTE_DIM(list_pdcp_sdap_tests);
9001 
9002 	for (i = 0; i < size; i++) {
9003 		cur_test = &list_pdcp_sdap_tests[i];
9004 		err = test_pdcp_proto(
9005 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9006 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9007 			cur_test->in_len, cur_test->data_out,
9008 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9009 			cur_test->param.cipher_alg, cur_test->cipher_key,
9010 			cur_test->param.cipher_key_len,
9011 			cur_test->param.auth_alg,
9012 			cur_test->auth_key, cur_test->param.auth_key_len,
9013 			cur_test->bearer, cur_test->param.domain,
9014 			cur_test->packet_direction, cur_test->sn_size,
9015 			cur_test->hfn,
9016 			cur_test->hfn_threshold, SDAP_ENABLED);
9017 		if (err) {
9018 			printf("\t%d) %s: Encapsulation failed\n",
9019 					cur_test->test_idx,
9020 					cur_test->param.name);
9021 			err = TEST_FAILED;
9022 		} else {
9023 			printf("\t%d) %s: Encap PASS\n", cur_test->test_idx,
9024 					cur_test->param.name);
9025 			err = TEST_SUCCESS;
9026 		}
9027 		all_err += err;
9028 	}
9029 
9030 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9031 
9032 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9033 }
9034 
9035 static int
9036 test_PDCP_PROTO_short_mac(void)
9037 {
9038 	int i = 0, size = 0;
9039 	int err, all_err = TEST_SUCCESS;
9040 	const struct pdcp_short_mac_test *cur_test;
9041 
9042 	size = RTE_DIM(list_pdcp_smac_tests);
9043 
9044 	for (i = 0; i < size; i++) {
9045 		cur_test = &list_pdcp_smac_tests[i];
9046 		err = test_pdcp_proto(
9047 			i, 0, RTE_CRYPTO_CIPHER_OP_ENCRYPT,
9048 			RTE_CRYPTO_AUTH_OP_GENERATE, cur_test->data_in,
9049 			cur_test->in_len, cur_test->data_out,
9050 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9051 			RTE_CRYPTO_CIPHER_NULL, NULL,
9052 			0, cur_test->param.auth_alg,
9053 			cur_test->auth_key, cur_test->param.auth_key_len,
9054 			0, cur_test->param.domain, 0, 0,
9055 			0, 0, 0);
9056 		if (err) {
9057 			printf("\t%d) %s: Short MAC test failed\n",
9058 					cur_test->test_idx,
9059 					cur_test->param.name);
9060 			err = TEST_FAILED;
9061 		} else {
9062 			printf("\t%d) %s: Short MAC test PASS\n",
9063 					cur_test->test_idx,
9064 					cur_test->param.name);
9065 			rte_hexdump(stdout, "MAC I",
9066 				    cur_test->data_out + cur_test->in_len + 2,
9067 				    2);
9068 			err = TEST_SUCCESS;
9069 		}
9070 		all_err += err;
9071 	}
9072 
9073 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9074 
9075 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9076 
9077 }
9078 
9079 static int
9080 test_PDCP_SDAP_PROTO_decap_all(void)
9081 {
9082 	int i = 0, size = 0;
9083 	int err, all_err = TEST_SUCCESS;
9084 	const struct pdcp_sdap_test *cur_test;
9085 
9086 	size = RTE_DIM(list_pdcp_sdap_tests);
9087 
9088 	for (i = 0; i < size; i++) {
9089 		cur_test = &list_pdcp_sdap_tests[i];
9090 		err = test_pdcp_proto(
9091 			i, 0, RTE_CRYPTO_CIPHER_OP_DECRYPT,
9092 			RTE_CRYPTO_AUTH_OP_VERIFY,
9093 			cur_test->data_out,
9094 			cur_test->in_len + ((cur_test->auth_key) ? 4 : 0),
9095 			cur_test->data_in, cur_test->in_len,
9096 			cur_test->param.cipher_alg,
9097 			cur_test->cipher_key, cur_test->param.cipher_key_len,
9098 			cur_test->param.auth_alg, cur_test->auth_key,
9099 			cur_test->param.auth_key_len, cur_test->bearer,
9100 			cur_test->param.domain, cur_test->packet_direction,
9101 			cur_test->sn_size, cur_test->hfn,
9102 			cur_test->hfn_threshold, SDAP_ENABLED);
9103 		if (err) {
9104 			printf("\t%d) %s: Decapsulation failed\n",
9105 					cur_test->test_idx,
9106 					cur_test->param.name);
9107 			err = TEST_FAILED;
9108 		} else {
9109 			printf("\t%d) %s: Decap PASS\n", cur_test->test_idx,
9110 					cur_test->param.name);
9111 			err = TEST_SUCCESS;
9112 		}
9113 		all_err += err;
9114 	}
9115 
9116 	printf("Success: %d, Failure: %d\n", size + all_err, -all_err);
9117 
9118 	return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED;
9119 }
9120 
9121 static int
9122 test_ipsec_proto_process(const struct ipsec_test_data td[],
9123 			 struct ipsec_test_data res_d[],
9124 			 int nb_td,
9125 			 bool silent,
9126 			 const struct ipsec_test_flags *flags)
9127 {
9128 	uint16_t v6_src[8] = {0x2607, 0xf8b0, 0x400c, 0x0c03, 0x0000, 0x0000,
9129 				0x0000, 0x001a};
9130 	uint16_t v6_dst[8] = {0x2001, 0x0470, 0xe5bf, 0xdead, 0x4957, 0x2174,
9131 				0xe82c, 0x4887};
9132 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9133 	struct crypto_unittest_params *ut_params = &unittest_params;
9134 	struct rte_security_capability_idx sec_cap_idx;
9135 	const struct rte_security_capability *sec_cap;
9136 	struct rte_security_ipsec_xform ipsec_xform;
9137 	uint8_t dev_id = ts_params->valid_devs[0];
9138 	enum rte_security_ipsec_sa_direction dir;
9139 	struct ipsec_test_data *res_d_tmp = NULL;
9140 	uint32_t src = RTE_IPV4(192, 168, 1, 0);
9141 	uint32_t dst = RTE_IPV4(192, 168, 1, 1);
9142 	int salt_len, i, ret = TEST_SUCCESS;
9143 	struct rte_security_ctx *ctx;
9144 	uint8_t *input_text;
9145 	uint32_t verify;
9146 
9147 	ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9148 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL;
9149 
9150 	/* Use first test data to create session */
9151 
9152 	/* Copy IPsec xform */
9153 	memcpy(&ipsec_xform, &td[0].ipsec_xform, sizeof(ipsec_xform));
9154 
9155 	dir = ipsec_xform.direction;
9156 	verify = flags->tunnel_hdr_verify;
9157 
9158 	if ((dir == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && verify) {
9159 		if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR)
9160 			src += 1;
9161 		else if (verify == RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR)
9162 			dst += 1;
9163 	}
9164 
9165 	if (td->ipsec_xform.tunnel.type ==
9166 			RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
9167 		memcpy(&ipsec_xform.tunnel.ipv4.src_ip, &src, sizeof(src));
9168 		memcpy(&ipsec_xform.tunnel.ipv4.dst_ip, &dst, sizeof(dst));
9169 	} else {
9170 		memcpy(&ipsec_xform.tunnel.ipv6.src_addr, &v6_src,
9171 			sizeof(v6_src));
9172 		memcpy(&ipsec_xform.tunnel.ipv6.dst_addr, &v6_dst,
9173 			sizeof(v6_dst));
9174 	}
9175 
9176 	ctx = rte_cryptodev_get_sec_ctx(dev_id);
9177 
9178 	sec_cap_idx.action = ut_params->type;
9179 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_IPSEC;
9180 	sec_cap_idx.ipsec.proto = ipsec_xform.proto;
9181 	sec_cap_idx.ipsec.mode = ipsec_xform.mode;
9182 	sec_cap_idx.ipsec.direction = ipsec_xform.direction;
9183 
9184 	if (flags->udp_encap)
9185 		ipsec_xform.options.udp_encap = 1;
9186 
9187 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9188 	if (sec_cap == NULL)
9189 		return TEST_SKIPPED;
9190 
9191 	/* Copy cipher session parameters */
9192 	if (td[0].aead) {
9193 		memcpy(&ut_params->aead_xform, &td[0].xform.aead,
9194 		       sizeof(ut_params->aead_xform));
9195 		ut_params->aead_xform.aead.key.data = td[0].key.data;
9196 		ut_params->aead_xform.aead.iv.offset = IV_OFFSET;
9197 
9198 		/* Verify crypto capabilities */
9199 		if (test_ipsec_crypto_caps_aead_verify(
9200 				sec_cap,
9201 				&ut_params->aead_xform) != 0) {
9202 			if (!silent)
9203 				RTE_LOG(INFO, USER1,
9204 					"Crypto capabilities not supported\n");
9205 			return TEST_SKIPPED;
9206 		}
9207 	} else {
9208 		memcpy(&ut_params->cipher_xform, &td[0].xform.chain.cipher,
9209 		       sizeof(ut_params->cipher_xform));
9210 		memcpy(&ut_params->auth_xform, &td[0].xform.chain.auth,
9211 		       sizeof(ut_params->auth_xform));
9212 		ut_params->cipher_xform.cipher.key.data = td[0].key.data;
9213 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9214 		ut_params->auth_xform.auth.key.data = td[0].auth_key.data;
9215 
9216 		/* Verify crypto capabilities */
9217 
9218 		if (test_ipsec_crypto_caps_cipher_verify(
9219 				sec_cap,
9220 				&ut_params->cipher_xform) != 0) {
9221 			if (!silent)
9222 				RTE_LOG(INFO, USER1,
9223 					"Cipher crypto capabilities not supported\n");
9224 			return TEST_SKIPPED;
9225 		}
9226 
9227 		if (test_ipsec_crypto_caps_auth_verify(
9228 				sec_cap,
9229 				&ut_params->auth_xform) != 0) {
9230 			if (!silent)
9231 				RTE_LOG(INFO, USER1,
9232 					"Auth crypto capabilities not supported\n");
9233 			return TEST_SKIPPED;
9234 		}
9235 	}
9236 
9237 	if (test_ipsec_sec_caps_verify(&ipsec_xform, sec_cap, silent) != 0)
9238 		return TEST_SKIPPED;
9239 
9240 	struct rte_security_session_conf sess_conf = {
9241 		.action_type = ut_params->type,
9242 		.protocol = RTE_SECURITY_PROTOCOL_IPSEC,
9243 	};
9244 
9245 	if (td[0].aead) {
9246 		salt_len = RTE_MIN(sizeof(ipsec_xform.salt), td[0].salt.len);
9247 		memcpy(&ipsec_xform.salt, td[0].salt.data, salt_len);
9248 		sess_conf.ipsec = ipsec_xform;
9249 		sess_conf.crypto_xform = &ut_params->aead_xform;
9250 	} else {
9251 		sess_conf.ipsec = ipsec_xform;
9252 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) {
9253 			sess_conf.crypto_xform = &ut_params->cipher_xform;
9254 			ut_params->cipher_xform.next = &ut_params->auth_xform;
9255 		} else {
9256 			sess_conf.crypto_xform = &ut_params->auth_xform;
9257 			ut_params->auth_xform.next = &ut_params->cipher_xform;
9258 		}
9259 	}
9260 
9261 	/* Create security session */
9262 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9263 					ts_params->session_mpool,
9264 					ts_params->session_priv_mpool);
9265 
9266 	if (ut_params->sec_session == NULL)
9267 		return TEST_SKIPPED;
9268 
9269 	for (i = 0; i < nb_td; i++) {
9270 		/* Setup source mbuf payload */
9271 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9272 		memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9273 				rte_pktmbuf_tailroom(ut_params->ibuf));
9274 
9275 		input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9276 				td[i].input_text.len);
9277 
9278 		memcpy(input_text, td[i].input_text.data,
9279 		       td[i].input_text.len);
9280 
9281 		/* Generate crypto op data structure */
9282 		ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9283 					RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9284 		if (!ut_params->op) {
9285 			printf("TestCase %s line %d: %s\n",
9286 				__func__, __LINE__,
9287 				"failed to allocate crypto op");
9288 			ret = TEST_FAILED;
9289 			goto crypto_op_free;
9290 		}
9291 
9292 		/* Attach session to operation */
9293 		rte_security_attach_session(ut_params->op,
9294 					    ut_params->sec_session);
9295 
9296 		/* Set crypto operation mbufs */
9297 		ut_params->op->sym->m_src = ut_params->ibuf;
9298 		ut_params->op->sym->m_dst = NULL;
9299 
9300 		/* Copy IV in crypto operation when IV generation is disabled */
9301 		if (dir == RTE_SECURITY_IPSEC_SA_DIR_EGRESS &&
9302 		    ipsec_xform.options.iv_gen_disable == 1) {
9303 			uint8_t *iv = rte_crypto_op_ctod_offset(ut_params->op,
9304 								uint8_t *,
9305 								IV_OFFSET);
9306 			int len;
9307 
9308 			if (td[i].aead)
9309 				len = td[i].xform.aead.aead.iv.length;
9310 			else
9311 				len = td[i].xform.chain.cipher.cipher.iv.length;
9312 
9313 			memcpy(iv, td[i].iv.data, len);
9314 		}
9315 
9316 		/* Process crypto operation */
9317 		process_crypto_request(dev_id, ut_params->op);
9318 
9319 		ret = test_ipsec_status_check(ut_params->op, flags, dir, i + 1);
9320 		if (ret != TEST_SUCCESS)
9321 			goto crypto_op_free;
9322 
9323 		if (res_d != NULL)
9324 			res_d_tmp = &res_d[i];
9325 
9326 		ret = test_ipsec_post_process(ut_params->ibuf, &td[i],
9327 					      res_d_tmp, silent, flags);
9328 		if (ret != TEST_SUCCESS)
9329 			goto crypto_op_free;
9330 
9331 		rte_crypto_op_free(ut_params->op);
9332 		ut_params->op = NULL;
9333 
9334 		rte_pktmbuf_free(ut_params->ibuf);
9335 		ut_params->ibuf = NULL;
9336 	}
9337 
9338 crypto_op_free:
9339 	rte_crypto_op_free(ut_params->op);
9340 	ut_params->op = NULL;
9341 
9342 	rte_pktmbuf_free(ut_params->ibuf);
9343 	ut_params->ibuf = NULL;
9344 
9345 	if (ut_params->sec_session)
9346 		rte_security_session_destroy(ctx, ut_params->sec_session);
9347 	ut_params->sec_session = NULL;
9348 
9349 	return ret;
9350 }
9351 
9352 static int
9353 test_ipsec_proto_known_vec(const void *test_data)
9354 {
9355 	struct ipsec_test_data td_outb;
9356 	struct ipsec_test_flags flags;
9357 
9358 	memset(&flags, 0, sizeof(flags));
9359 
9360 	memcpy(&td_outb, test_data, sizeof(td_outb));
9361 
9362 	/* Disable IV gen to be able to test with known vectors */
9363 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9364 
9365 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9366 }
9367 
9368 static int
9369 test_ipsec_proto_known_vec_inb(const void *test_data)
9370 {
9371 	const struct ipsec_test_data *td = test_data;
9372 	struct ipsec_test_flags flags;
9373 	struct ipsec_test_data td_inb;
9374 
9375 	memset(&flags, 0, sizeof(flags));
9376 
9377 	if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
9378 		test_ipsec_td_in_from_out(td, &td_inb);
9379 	else
9380 		memcpy(&td_inb, td, sizeof(td_inb));
9381 
9382 	return test_ipsec_proto_process(&td_inb, NULL, 1, false, &flags);
9383 }
9384 
9385 static int
9386 test_ipsec_proto_known_vec_fragmented(const void *test_data)
9387 {
9388 	struct ipsec_test_data td_outb;
9389 	struct ipsec_test_flags flags;
9390 
9391 	memset(&flags, 0, sizeof(flags));
9392 	flags.fragment = true;
9393 
9394 	memcpy(&td_outb, test_data, sizeof(td_outb));
9395 
9396 	/* Disable IV gen to be able to test with known vectors */
9397 	td_outb.ipsec_xform.options.iv_gen_disable = 1;
9398 
9399 	return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags);
9400 }
9401 
9402 static int
9403 test_ipsec_proto_all(const struct ipsec_test_flags *flags)
9404 {
9405 	struct ipsec_test_data td_outb[IPSEC_TEST_PACKETS_MAX];
9406 	struct ipsec_test_data td_inb[IPSEC_TEST_PACKETS_MAX];
9407 	unsigned int i, nb_pkts = 1, pass_cnt = 0;
9408 	int ret;
9409 
9410 	if (flags->iv_gen ||
9411 	    flags->sa_expiry_pkts_soft ||
9412 	    flags->sa_expiry_pkts_hard)
9413 		nb_pkts = IPSEC_TEST_PACKETS_MAX;
9414 
9415 	for (i = 0; i < RTE_DIM(alg_list); i++) {
9416 		test_ipsec_td_prepare(alg_list[i].param1,
9417 				      alg_list[i].param2,
9418 				      flags,
9419 				      td_outb,
9420 				      nb_pkts);
9421 
9422 		ret = test_ipsec_proto_process(td_outb, td_inb, nb_pkts, true,
9423 					       flags);
9424 		if (ret == TEST_SKIPPED)
9425 			continue;
9426 
9427 		if (ret == TEST_FAILED)
9428 			return TEST_FAILED;
9429 
9430 		test_ipsec_td_update(td_inb, td_outb, nb_pkts, flags);
9431 
9432 		ret = test_ipsec_proto_process(td_inb, NULL, nb_pkts, true,
9433 					       flags);
9434 		if (ret == TEST_SKIPPED)
9435 			continue;
9436 
9437 		if (ret == TEST_FAILED)
9438 			return TEST_FAILED;
9439 
9440 		if (flags->display_alg)
9441 			test_ipsec_display_alg(alg_list[i].param1,
9442 					       alg_list[i].param2);
9443 
9444 		pass_cnt++;
9445 	}
9446 
9447 	if (pass_cnt > 0)
9448 		return TEST_SUCCESS;
9449 	else
9450 		return TEST_SKIPPED;
9451 }
9452 
9453 static int
9454 test_ipsec_proto_display_list(const void *data __rte_unused)
9455 {
9456 	struct ipsec_test_flags flags;
9457 
9458 	memset(&flags, 0, sizeof(flags));
9459 
9460 	flags.display_alg = true;
9461 
9462 	return test_ipsec_proto_all(&flags);
9463 }
9464 
9465 static int
9466 test_ipsec_proto_iv_gen(const void *data __rte_unused)
9467 {
9468 	struct ipsec_test_flags flags;
9469 
9470 	memset(&flags, 0, sizeof(flags));
9471 
9472 	flags.iv_gen = true;
9473 
9474 	return test_ipsec_proto_all(&flags);
9475 }
9476 
9477 static int
9478 test_ipsec_proto_sa_exp_pkts_soft(const void *data __rte_unused)
9479 {
9480 	struct ipsec_test_flags flags;
9481 
9482 	memset(&flags, 0, sizeof(flags));
9483 
9484 	flags.sa_expiry_pkts_soft = true;
9485 
9486 	return test_ipsec_proto_all(&flags);
9487 }
9488 
9489 static int
9490 test_ipsec_proto_sa_exp_pkts_hard(const void *data __rte_unused)
9491 {
9492 	struct ipsec_test_flags flags;
9493 
9494 	memset(&flags, 0, sizeof(flags));
9495 
9496 	flags.sa_expiry_pkts_hard = true;
9497 
9498 	return test_ipsec_proto_all(&flags);
9499 }
9500 
9501 static int
9502 test_ipsec_proto_err_icv_corrupt(const void *data __rte_unused)
9503 {
9504 	struct ipsec_test_flags flags;
9505 
9506 	memset(&flags, 0, sizeof(flags));
9507 
9508 	flags.icv_corrupt = true;
9509 
9510 	return test_ipsec_proto_all(&flags);
9511 }
9512 
9513 static int
9514 test_ipsec_proto_udp_encap(const void *data __rte_unused)
9515 {
9516 	struct ipsec_test_flags flags;
9517 
9518 	memset(&flags, 0, sizeof(flags));
9519 
9520 	flags.udp_encap = true;
9521 
9522 	return test_ipsec_proto_all(&flags);
9523 }
9524 
9525 static int
9526 test_ipsec_proto_tunnel_src_dst_addr_verify(const void *data __rte_unused)
9527 {
9528 	struct ipsec_test_flags flags;
9529 
9530 	memset(&flags, 0, sizeof(flags));
9531 
9532 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR;
9533 
9534 	return test_ipsec_proto_all(&flags);
9535 }
9536 
9537 static int
9538 test_ipsec_proto_tunnel_dst_addr_verify(const void *data __rte_unused)
9539 {
9540 	struct ipsec_test_flags flags;
9541 
9542 	memset(&flags, 0, sizeof(flags));
9543 
9544 	flags.tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR;
9545 
9546 	return test_ipsec_proto_all(&flags);
9547 }
9548 
9549 static int
9550 test_ipsec_proto_udp_ports_verify(const void *data __rte_unused)
9551 {
9552 	struct ipsec_test_flags flags;
9553 
9554 	memset(&flags, 0, sizeof(flags));
9555 
9556 	flags.udp_encap = true;
9557 	flags.udp_ports_verify = true;
9558 
9559 	return test_ipsec_proto_all(&flags);
9560 }
9561 
9562 static int
9563 test_ipsec_proto_inner_ip_csum(const void *data __rte_unused)
9564 {
9565 	struct ipsec_test_flags flags;
9566 
9567 	memset(&flags, 0, sizeof(flags));
9568 
9569 	flags.ip_csum = true;
9570 
9571 	return test_ipsec_proto_all(&flags);
9572 }
9573 
9574 static int
9575 test_ipsec_proto_inner_l4_csum(const void *data __rte_unused)
9576 {
9577 	struct ipsec_test_flags flags;
9578 
9579 	memset(&flags, 0, sizeof(flags));
9580 
9581 	flags.l4_csum = true;
9582 
9583 	return test_ipsec_proto_all(&flags);
9584 }
9585 
9586 static int
9587 test_ipsec_proto_tunnel_v4_in_v4(const void *data __rte_unused)
9588 {
9589 	struct ipsec_test_flags flags;
9590 
9591 	memset(&flags, 0, sizeof(flags));
9592 
9593 	flags.ipv6 = false;
9594 	flags.tunnel_ipv6 = false;
9595 
9596 	return test_ipsec_proto_all(&flags);
9597 }
9598 
9599 static int
9600 test_ipsec_proto_tunnel_v6_in_v6(const void *data __rte_unused)
9601 {
9602 	struct ipsec_test_flags flags;
9603 
9604 	memset(&flags, 0, sizeof(flags));
9605 
9606 	flags.ipv6 = true;
9607 	flags.tunnel_ipv6 = true;
9608 
9609 	return test_ipsec_proto_all(&flags);
9610 }
9611 
9612 static int
9613 test_ipsec_proto_tunnel_v4_in_v6(const void *data __rte_unused)
9614 {
9615 	struct ipsec_test_flags flags;
9616 
9617 	memset(&flags, 0, sizeof(flags));
9618 
9619 	flags.ipv6 = false;
9620 	flags.tunnel_ipv6 = true;
9621 
9622 	return test_ipsec_proto_all(&flags);
9623 }
9624 
9625 static int
9626 test_ipsec_proto_tunnel_v6_in_v4(const void *data __rte_unused)
9627 {
9628 	struct ipsec_test_flags flags;
9629 
9630 	memset(&flags, 0, sizeof(flags));
9631 
9632 	flags.ipv6 = true;
9633 	flags.tunnel_ipv6 = false;
9634 
9635 	return test_ipsec_proto_all(&flags);
9636 }
9637 
9638 static int
9639 test_PDCP_PROTO_all(void)
9640 {
9641 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9642 	struct crypto_unittest_params *ut_params = &unittest_params;
9643 	struct rte_cryptodev_info dev_info;
9644 	int status;
9645 
9646 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
9647 	uint64_t feat_flags = dev_info.feature_flags;
9648 
9649 	if (!(feat_flags & RTE_CRYPTODEV_FF_SECURITY))
9650 		return TEST_SKIPPED;
9651 
9652 	/* Set action type */
9653 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9654 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9655 		gbl_action_type;
9656 
9657 	if (security_proto_supported(ut_params->type,
9658 			RTE_SECURITY_PROTOCOL_PDCP) < 0)
9659 		return TEST_SKIPPED;
9660 
9661 	status = test_PDCP_PROTO_cplane_encap_all();
9662 	status += test_PDCP_PROTO_cplane_decap_all();
9663 	status += test_PDCP_PROTO_uplane_encap_all();
9664 	status += test_PDCP_PROTO_uplane_decap_all();
9665 	status += test_PDCP_PROTO_SGL_in_place_32B();
9666 	status += test_PDCP_PROTO_SGL_oop_32B_128B();
9667 	status += test_PDCP_PROTO_SGL_oop_32B_40B();
9668 	status += test_PDCP_PROTO_SGL_oop_128B_32B();
9669 	status += test_PDCP_SDAP_PROTO_encap_all();
9670 	status += test_PDCP_SDAP_PROTO_decap_all();
9671 	status += test_PDCP_PROTO_short_mac();
9672 
9673 	if (status)
9674 		return TEST_FAILED;
9675 	else
9676 		return TEST_SUCCESS;
9677 }
9678 
9679 static int
9680 test_docsis_proto_uplink(const void *data)
9681 {
9682 	const struct docsis_test_data *d_td = data;
9683 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9684 	struct crypto_unittest_params *ut_params = &unittest_params;
9685 	uint8_t *plaintext = NULL;
9686 	uint8_t *ciphertext = NULL;
9687 	uint8_t *iv_ptr;
9688 	int32_t cipher_len, crc_len;
9689 	uint32_t crc_data_len;
9690 	int ret = TEST_SUCCESS;
9691 
9692 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9693 					rte_cryptodev_get_sec_ctx(
9694 						ts_params->valid_devs[0]);
9695 
9696 	/* Verify the capabilities */
9697 	struct rte_security_capability_idx sec_cap_idx;
9698 	const struct rte_security_capability *sec_cap;
9699 	const struct rte_cryptodev_capabilities *crypto_cap;
9700 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9701 	int j = 0;
9702 
9703 	/* Set action type */
9704 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9705 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9706 		gbl_action_type;
9707 
9708 	if (security_proto_supported(ut_params->type,
9709 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9710 		return TEST_SKIPPED;
9711 
9712 	sec_cap_idx.action = ut_params->type;
9713 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9714 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_UPLINK;
9715 
9716 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9717 	if (sec_cap == NULL)
9718 		return TEST_SKIPPED;
9719 
9720 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9721 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9722 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9723 				crypto_cap->sym.xform_type ==
9724 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9725 				crypto_cap->sym.cipher.algo ==
9726 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9727 			sym_cap = &crypto_cap->sym;
9728 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9729 						d_td->key.len,
9730 						d_td->iv.len) == 0)
9731 				break;
9732 		}
9733 	}
9734 
9735 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9736 		return TEST_SKIPPED;
9737 
9738 	/* Setup source mbuf payload */
9739 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9740 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9741 			rte_pktmbuf_tailroom(ut_params->ibuf));
9742 
9743 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9744 			d_td->ciphertext.len);
9745 
9746 	memcpy(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len);
9747 
9748 	/* Setup cipher session parameters */
9749 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9750 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9751 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
9752 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9753 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9754 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9755 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9756 	ut_params->cipher_xform.next = NULL;
9757 
9758 	/* Setup DOCSIS session parameters */
9759 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_UPLINK;
9760 
9761 	struct rte_security_session_conf sess_conf = {
9762 		.action_type = ut_params->type,
9763 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9764 		.docsis = ut_params->docsis_xform,
9765 		.crypto_xform = &ut_params->cipher_xform,
9766 	};
9767 
9768 	/* Create security session */
9769 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9770 					ts_params->session_mpool,
9771 					ts_params->session_priv_mpool);
9772 
9773 	if (!ut_params->sec_session) {
9774 		printf("Test function %s line %u: failed to allocate session\n",
9775 			__func__, __LINE__);
9776 		ret = TEST_FAILED;
9777 		goto on_err;
9778 	}
9779 
9780 	/* Generate crypto op data structure */
9781 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9782 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9783 	if (!ut_params->op) {
9784 		printf("Test function %s line %u: failed to allocate symmetric "
9785 			"crypto operation\n", __func__, __LINE__);
9786 		ret = TEST_FAILED;
9787 		goto on_err;
9788 	}
9789 
9790 	/* Setup CRC operation parameters */
9791 	crc_len = d_td->ciphertext.no_crc == false ?
9792 			(d_td->ciphertext.len -
9793 				d_td->ciphertext.crc_offset -
9794 				RTE_ETHER_CRC_LEN) :
9795 			0;
9796 	crc_len = crc_len > 0 ? crc_len : 0;
9797 	crc_data_len = crc_len == 0 ? 0 : RTE_ETHER_CRC_LEN;
9798 	ut_params->op->sym->auth.data.length = crc_len;
9799 	ut_params->op->sym->auth.data.offset = d_td->ciphertext.crc_offset;
9800 
9801 	/* Setup cipher operation parameters */
9802 	cipher_len = d_td->ciphertext.no_cipher == false ?
9803 			(d_td->ciphertext.len -
9804 				d_td->ciphertext.cipher_offset) :
9805 			0;
9806 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9807 	ut_params->op->sym->cipher.data.length = cipher_len;
9808 	ut_params->op->sym->cipher.data.offset = d_td->ciphertext.cipher_offset;
9809 
9810 	/* Setup cipher IV */
9811 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9812 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9813 
9814 	/* Attach session to operation */
9815 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
9816 
9817 	/* Set crypto operation mbufs */
9818 	ut_params->op->sym->m_src = ut_params->ibuf;
9819 	ut_params->op->sym->m_dst = NULL;
9820 
9821 	/* Process crypto operation */
9822 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
9823 			NULL) {
9824 		printf("Test function %s line %u: failed to process security "
9825 			"crypto op\n", __func__, __LINE__);
9826 		ret = TEST_FAILED;
9827 		goto on_err;
9828 	}
9829 
9830 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
9831 		printf("Test function %s line %u: failed to process crypto op\n",
9832 			__func__, __LINE__);
9833 		ret = TEST_FAILED;
9834 		goto on_err;
9835 	}
9836 
9837 	/* Validate plaintext */
9838 	plaintext = ciphertext;
9839 
9840 	if (memcmp(plaintext, d_td->plaintext.data,
9841 			d_td->plaintext.len - crc_data_len)) {
9842 		printf("Test function %s line %u: plaintext not as expected\n",
9843 			__func__, __LINE__);
9844 		rte_hexdump(stdout, "expected", d_td->plaintext.data,
9845 				d_td->plaintext.len);
9846 		rte_hexdump(stdout, "actual", plaintext, d_td->plaintext.len);
9847 		ret = TEST_FAILED;
9848 		goto on_err;
9849 	}
9850 
9851 on_err:
9852 	rte_crypto_op_free(ut_params->op);
9853 	ut_params->op = NULL;
9854 
9855 	if (ut_params->sec_session)
9856 		rte_security_session_destroy(ctx, ut_params->sec_session);
9857 	ut_params->sec_session = NULL;
9858 
9859 	rte_pktmbuf_free(ut_params->ibuf);
9860 	ut_params->ibuf = NULL;
9861 
9862 	return ret;
9863 }
9864 
9865 static int
9866 test_docsis_proto_downlink(const void *data)
9867 {
9868 	const struct docsis_test_data *d_td = data;
9869 	struct crypto_testsuite_params *ts_params = &testsuite_params;
9870 	struct crypto_unittest_params *ut_params = &unittest_params;
9871 	uint8_t *plaintext = NULL;
9872 	uint8_t *ciphertext = NULL;
9873 	uint8_t *iv_ptr;
9874 	int32_t cipher_len, crc_len;
9875 	int ret = TEST_SUCCESS;
9876 
9877 	struct rte_security_ctx *ctx = (struct rte_security_ctx *)
9878 					rte_cryptodev_get_sec_ctx(
9879 						ts_params->valid_devs[0]);
9880 
9881 	/* Verify the capabilities */
9882 	struct rte_security_capability_idx sec_cap_idx;
9883 	const struct rte_security_capability *sec_cap;
9884 	const struct rte_cryptodev_capabilities *crypto_cap;
9885 	const struct rte_cryptodev_symmetric_capability *sym_cap;
9886 	int j = 0;
9887 
9888 	/* Set action type */
9889 	ut_params->type = gbl_action_type == RTE_SECURITY_ACTION_TYPE_NONE ?
9890 		RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL :
9891 		gbl_action_type;
9892 
9893 	if (security_proto_supported(ut_params->type,
9894 			RTE_SECURITY_PROTOCOL_DOCSIS) < 0)
9895 		return TEST_SKIPPED;
9896 
9897 	sec_cap_idx.action = ut_params->type;
9898 	sec_cap_idx.protocol = RTE_SECURITY_PROTOCOL_DOCSIS;
9899 	sec_cap_idx.docsis.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9900 
9901 	sec_cap = rte_security_capability_get(ctx, &sec_cap_idx);
9902 	if (sec_cap == NULL)
9903 		return TEST_SKIPPED;
9904 
9905 	while ((crypto_cap = &sec_cap->crypto_capabilities[j++])->op !=
9906 			RTE_CRYPTO_OP_TYPE_UNDEFINED) {
9907 		if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_SYMMETRIC &&
9908 				crypto_cap->sym.xform_type ==
9909 					RTE_CRYPTO_SYM_XFORM_CIPHER &&
9910 				crypto_cap->sym.cipher.algo ==
9911 					RTE_CRYPTO_CIPHER_AES_DOCSISBPI) {
9912 			sym_cap = &crypto_cap->sym;
9913 			if (rte_cryptodev_sym_capability_check_cipher(sym_cap,
9914 						d_td->key.len,
9915 						d_td->iv.len) == 0)
9916 				break;
9917 		}
9918 	}
9919 
9920 	if (crypto_cap->op == RTE_CRYPTO_OP_TYPE_UNDEFINED)
9921 		return TEST_SKIPPED;
9922 
9923 	/* Setup source mbuf payload */
9924 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
9925 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
9926 			rte_pktmbuf_tailroom(ut_params->ibuf));
9927 
9928 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
9929 			d_td->plaintext.len);
9930 
9931 	memcpy(plaintext, d_td->plaintext.data, d_td->plaintext.len);
9932 
9933 	/* Setup cipher session parameters */
9934 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
9935 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_DOCSISBPI;
9936 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
9937 	ut_params->cipher_xform.cipher.key.data = d_td->key.data;
9938 	ut_params->cipher_xform.cipher.key.length = d_td->key.len;
9939 	ut_params->cipher_xform.cipher.iv.length = d_td->iv.len;
9940 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
9941 	ut_params->cipher_xform.next = NULL;
9942 
9943 	/* Setup DOCSIS session parameters */
9944 	ut_params->docsis_xform.direction = RTE_SECURITY_DOCSIS_DOWNLINK;
9945 
9946 	struct rte_security_session_conf sess_conf = {
9947 		.action_type = ut_params->type,
9948 		.protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
9949 		.docsis = ut_params->docsis_xform,
9950 		.crypto_xform = &ut_params->cipher_xform,
9951 	};
9952 
9953 	/* Create security session */
9954 	ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
9955 					ts_params->session_mpool,
9956 					ts_params->session_priv_mpool);
9957 
9958 	if (!ut_params->sec_session) {
9959 		printf("Test function %s line %u: failed to allocate session\n",
9960 			__func__, __LINE__);
9961 		ret = TEST_FAILED;
9962 		goto on_err;
9963 	}
9964 
9965 	/* Generate crypto op data structure */
9966 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
9967 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
9968 	if (!ut_params->op) {
9969 		printf("Test function %s line %u: failed to allocate symmetric "
9970 			"crypto operation\n", __func__, __LINE__);
9971 		ret = TEST_FAILED;
9972 		goto on_err;
9973 	}
9974 
9975 	/* Setup CRC operation parameters */
9976 	crc_len = d_td->plaintext.no_crc == false ?
9977 			(d_td->plaintext.len -
9978 				d_td->plaintext.crc_offset -
9979 				RTE_ETHER_CRC_LEN) :
9980 			0;
9981 	crc_len = crc_len > 0 ? crc_len : 0;
9982 	ut_params->op->sym->auth.data.length = crc_len;
9983 	ut_params->op->sym->auth.data.offset = d_td->plaintext.crc_offset;
9984 
9985 	/* Setup cipher operation parameters */
9986 	cipher_len = d_td->plaintext.no_cipher == false ?
9987 			(d_td->plaintext.len -
9988 				d_td->plaintext.cipher_offset) :
9989 			0;
9990 	cipher_len = cipher_len > 0 ? cipher_len : 0;
9991 	ut_params->op->sym->cipher.data.length = cipher_len;
9992 	ut_params->op->sym->cipher.data.offset = d_td->plaintext.cipher_offset;
9993 
9994 	/* Setup cipher IV */
9995 	iv_ptr = (uint8_t *)ut_params->op + IV_OFFSET;
9996 	rte_memcpy(iv_ptr, d_td->iv.data, d_td->iv.len);
9997 
9998 	/* Attach session to operation */
9999 	rte_security_attach_session(ut_params->op, ut_params->sec_session);
10000 
10001 	/* Set crypto operation mbufs */
10002 	ut_params->op->sym->m_src = ut_params->ibuf;
10003 	ut_params->op->sym->m_dst = NULL;
10004 
10005 	/* Process crypto operation */
10006 	if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) ==
10007 			NULL) {
10008 		printf("Test function %s line %u: failed to process crypto op\n",
10009 			__func__, __LINE__);
10010 		ret = TEST_FAILED;
10011 		goto on_err;
10012 	}
10013 
10014 	if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
10015 		printf("Test function %s line %u: crypto op processing failed\n",
10016 			__func__, __LINE__);
10017 		ret = TEST_FAILED;
10018 		goto on_err;
10019 	}
10020 
10021 	/* Validate ciphertext */
10022 	ciphertext = plaintext;
10023 
10024 	if (memcmp(ciphertext, d_td->ciphertext.data, d_td->ciphertext.len)) {
10025 		printf("Test function %s line %u: plaintext not as expected\n",
10026 			__func__, __LINE__);
10027 		rte_hexdump(stdout, "expected", d_td->ciphertext.data,
10028 				d_td->ciphertext.len);
10029 		rte_hexdump(stdout, "actual", ciphertext, d_td->ciphertext.len);
10030 		ret = TEST_FAILED;
10031 		goto on_err;
10032 	}
10033 
10034 on_err:
10035 	rte_crypto_op_free(ut_params->op);
10036 	ut_params->op = NULL;
10037 
10038 	if (ut_params->sec_session)
10039 		rte_security_session_destroy(ctx, ut_params->sec_session);
10040 	ut_params->sec_session = NULL;
10041 
10042 	rte_pktmbuf_free(ut_params->ibuf);
10043 	ut_params->ibuf = NULL;
10044 
10045 	return ret;
10046 }
10047 #endif
10048 
10049 static int
10050 test_AES_GCM_authenticated_encryption_test_case_1(void)
10051 {
10052 	return test_authenticated_encryption(&gcm_test_case_1);
10053 }
10054 
10055 static int
10056 test_AES_GCM_authenticated_encryption_test_case_2(void)
10057 {
10058 	return test_authenticated_encryption(&gcm_test_case_2);
10059 }
10060 
10061 static int
10062 test_AES_GCM_authenticated_encryption_test_case_3(void)
10063 {
10064 	return test_authenticated_encryption(&gcm_test_case_3);
10065 }
10066 
10067 static int
10068 test_AES_GCM_authenticated_encryption_test_case_4(void)
10069 {
10070 	return test_authenticated_encryption(&gcm_test_case_4);
10071 }
10072 
10073 static int
10074 test_AES_GCM_authenticated_encryption_test_case_5(void)
10075 {
10076 	return test_authenticated_encryption(&gcm_test_case_5);
10077 }
10078 
10079 static int
10080 test_AES_GCM_authenticated_encryption_test_case_6(void)
10081 {
10082 	return test_authenticated_encryption(&gcm_test_case_6);
10083 }
10084 
10085 static int
10086 test_AES_GCM_authenticated_encryption_test_case_7(void)
10087 {
10088 	return test_authenticated_encryption(&gcm_test_case_7);
10089 }
10090 
10091 static int
10092 test_AES_GCM_authenticated_encryption_test_case_8(void)
10093 {
10094 	return test_authenticated_encryption(&gcm_test_case_8);
10095 }
10096 
10097 static int
10098 test_AES_GCM_J0_authenticated_encryption_test_case_1(void)
10099 {
10100 	return test_authenticated_encryption(&gcm_J0_test_case_1);
10101 }
10102 
10103 static int
10104 test_AES_GCM_auth_encryption_test_case_192_1(void)
10105 {
10106 	return test_authenticated_encryption(&gcm_test_case_192_1);
10107 }
10108 
10109 static int
10110 test_AES_GCM_auth_encryption_test_case_192_2(void)
10111 {
10112 	return test_authenticated_encryption(&gcm_test_case_192_2);
10113 }
10114 
10115 static int
10116 test_AES_GCM_auth_encryption_test_case_192_3(void)
10117 {
10118 	return test_authenticated_encryption(&gcm_test_case_192_3);
10119 }
10120 
10121 static int
10122 test_AES_GCM_auth_encryption_test_case_192_4(void)
10123 {
10124 	return test_authenticated_encryption(&gcm_test_case_192_4);
10125 }
10126 
10127 static int
10128 test_AES_GCM_auth_encryption_test_case_192_5(void)
10129 {
10130 	return test_authenticated_encryption(&gcm_test_case_192_5);
10131 }
10132 
10133 static int
10134 test_AES_GCM_auth_encryption_test_case_192_6(void)
10135 {
10136 	return test_authenticated_encryption(&gcm_test_case_192_6);
10137 }
10138 
10139 static int
10140 test_AES_GCM_auth_encryption_test_case_192_7(void)
10141 {
10142 	return test_authenticated_encryption(&gcm_test_case_192_7);
10143 }
10144 
10145 static int
10146 test_AES_GCM_auth_encryption_test_case_256_1(void)
10147 {
10148 	return test_authenticated_encryption(&gcm_test_case_256_1);
10149 }
10150 
10151 static int
10152 test_AES_GCM_auth_encryption_test_case_256_2(void)
10153 {
10154 	return test_authenticated_encryption(&gcm_test_case_256_2);
10155 }
10156 
10157 static int
10158 test_AES_GCM_auth_encryption_test_case_256_3(void)
10159 {
10160 	return test_authenticated_encryption(&gcm_test_case_256_3);
10161 }
10162 
10163 static int
10164 test_AES_GCM_auth_encryption_test_case_256_4(void)
10165 {
10166 	return test_authenticated_encryption(&gcm_test_case_256_4);
10167 }
10168 
10169 static int
10170 test_AES_GCM_auth_encryption_test_case_256_5(void)
10171 {
10172 	return test_authenticated_encryption(&gcm_test_case_256_5);
10173 }
10174 
10175 static int
10176 test_AES_GCM_auth_encryption_test_case_256_6(void)
10177 {
10178 	return test_authenticated_encryption(&gcm_test_case_256_6);
10179 }
10180 
10181 static int
10182 test_AES_GCM_auth_encryption_test_case_256_7(void)
10183 {
10184 	return test_authenticated_encryption(&gcm_test_case_256_7);
10185 }
10186 
10187 static int
10188 test_AES_GCM_auth_encryption_test_case_aad_1(void)
10189 {
10190 	return test_authenticated_encryption(&gcm_test_case_aad_1);
10191 }
10192 
10193 static int
10194 test_AES_GCM_auth_encryption_test_case_aad_2(void)
10195 {
10196 	return test_authenticated_encryption(&gcm_test_case_aad_2);
10197 }
10198 
10199 static int
10200 test_AES_GCM_auth_encryption_fail_iv_corrupt(void)
10201 {
10202 	struct aead_test_data tdata;
10203 	int res;
10204 
10205 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10206 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10207 	tdata.iv.data[0] += 1;
10208 	res = test_authenticated_encryption(&tdata);
10209 	if (res == TEST_SKIPPED)
10210 		return res;
10211 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10212 	return TEST_SUCCESS;
10213 }
10214 
10215 static int
10216 test_AES_GCM_auth_encryption_fail_in_data_corrupt(void)
10217 {
10218 	struct aead_test_data tdata;
10219 	int res;
10220 
10221 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10222 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10223 	tdata.plaintext.data[0] += 1;
10224 	res = test_authenticated_encryption(&tdata);
10225 	if (res == TEST_SKIPPED)
10226 		return res;
10227 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10228 	return TEST_SUCCESS;
10229 }
10230 
10231 static int
10232 test_AES_GCM_auth_encryption_fail_out_data_corrupt(void)
10233 {
10234 	struct aead_test_data tdata;
10235 	int res;
10236 
10237 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10238 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10239 	tdata.ciphertext.data[0] += 1;
10240 	res = test_authenticated_encryption(&tdata);
10241 	if (res == TEST_SKIPPED)
10242 		return res;
10243 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10244 	return TEST_SUCCESS;
10245 }
10246 
10247 static int
10248 test_AES_GCM_auth_encryption_fail_aad_len_corrupt(void)
10249 {
10250 	struct aead_test_data tdata;
10251 	int res;
10252 
10253 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10254 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10255 	tdata.aad.len += 1;
10256 	res = test_authenticated_encryption(&tdata);
10257 	if (res == TEST_SKIPPED)
10258 		return res;
10259 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10260 	return TEST_SUCCESS;
10261 }
10262 
10263 static int
10264 test_AES_GCM_auth_encryption_fail_aad_corrupt(void)
10265 {
10266 	struct aead_test_data tdata;
10267 	uint8_t aad[gcm_test_case_7.aad.len];
10268 	int res;
10269 
10270 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10271 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10272 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10273 	aad[0] += 1;
10274 	tdata.aad.data = aad;
10275 	res = test_authenticated_encryption(&tdata);
10276 	if (res == TEST_SKIPPED)
10277 		return res;
10278 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10279 	return TEST_SUCCESS;
10280 }
10281 
10282 static int
10283 test_AES_GCM_auth_encryption_fail_tag_corrupt(void)
10284 {
10285 	struct aead_test_data tdata;
10286 	int res;
10287 
10288 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10289 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10290 	tdata.auth_tag.data[0] += 1;
10291 	res = test_authenticated_encryption(&tdata);
10292 	if (res == TEST_SKIPPED)
10293 		return res;
10294 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "encryption not failed");
10295 	return TEST_SUCCESS;
10296 }
10297 
10298 static int
10299 test_authenticated_decryption(const struct aead_test_data *tdata)
10300 {
10301 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10302 	struct crypto_unittest_params *ut_params = &unittest_params;
10303 
10304 	int retval;
10305 	uint8_t *plaintext;
10306 	uint32_t i;
10307 	struct rte_cryptodev_info dev_info;
10308 
10309 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10310 	uint64_t feat_flags = dev_info.feature_flags;
10311 
10312 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10313 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10314 		printf("Device doesn't support RAW data-path APIs.\n");
10315 		return TEST_SKIPPED;
10316 	}
10317 
10318 	/* Verify the capabilities */
10319 	struct rte_cryptodev_sym_capability_idx cap_idx;
10320 	const struct rte_cryptodev_symmetric_capability *capability;
10321 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10322 	cap_idx.algo.aead = tdata->algo;
10323 	capability = rte_cryptodev_sym_capability_get(
10324 			ts_params->valid_devs[0], &cap_idx);
10325 	if (capability == NULL)
10326 		return TEST_SKIPPED;
10327 	if (rte_cryptodev_sym_capability_check_aead(
10328 			capability, tdata->key.len, tdata->auth_tag.len,
10329 			tdata->aad.len, tdata->iv.len))
10330 		return TEST_SKIPPED;
10331 
10332 	/* Create AEAD session */
10333 	retval = create_aead_session(ts_params->valid_devs[0],
10334 			tdata->algo,
10335 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10336 			tdata->key.data, tdata->key.len,
10337 			tdata->aad.len, tdata->auth_tag.len,
10338 			tdata->iv.len);
10339 	if (retval < 0)
10340 		return retval;
10341 
10342 	/* alloc mbuf and set payload */
10343 	if (tdata->aad.len > MBUF_SIZE) {
10344 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
10345 		/* Populate full size of add data */
10346 		for (i = 32; i < MAX_AAD_LENGTH; i += 32)
10347 			memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
10348 	} else
10349 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10350 
10351 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10352 			rte_pktmbuf_tailroom(ut_params->ibuf));
10353 
10354 	/* Create AEAD operation */
10355 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10356 	if (retval < 0)
10357 		return retval;
10358 
10359 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10360 
10361 	ut_params->op->sym->m_src = ut_params->ibuf;
10362 
10363 	/* Process crypto operation */
10364 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10365 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
10366 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10367 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10368 				ut_params->op, 0, 0, 0, 0);
10369 	else
10370 		TEST_ASSERT_NOT_NULL(
10371 			process_crypto_request(ts_params->valid_devs[0],
10372 			ut_params->op), "failed to process sym crypto op");
10373 
10374 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10375 			"crypto op processing failed");
10376 
10377 	if (ut_params->op->sym->m_dst)
10378 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
10379 				uint8_t *);
10380 	else
10381 		plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
10382 				uint8_t *,
10383 				ut_params->op->sym->cipher.data.offset);
10384 
10385 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10386 
10387 	/* Validate obuf */
10388 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10389 			plaintext,
10390 			tdata->plaintext.data,
10391 			tdata->plaintext.len,
10392 			"Plaintext data not as expected");
10393 
10394 	TEST_ASSERT_EQUAL(ut_params->op->status,
10395 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10396 			"Authentication failed");
10397 
10398 	return 0;
10399 }
10400 
10401 static int
10402 test_AES_GCM_authenticated_decryption_test_case_1(void)
10403 {
10404 	return test_authenticated_decryption(&gcm_test_case_1);
10405 }
10406 
10407 static int
10408 test_AES_GCM_authenticated_decryption_test_case_2(void)
10409 {
10410 	return test_authenticated_decryption(&gcm_test_case_2);
10411 }
10412 
10413 static int
10414 test_AES_GCM_authenticated_decryption_test_case_3(void)
10415 {
10416 	return test_authenticated_decryption(&gcm_test_case_3);
10417 }
10418 
10419 static int
10420 test_AES_GCM_authenticated_decryption_test_case_4(void)
10421 {
10422 	return test_authenticated_decryption(&gcm_test_case_4);
10423 }
10424 
10425 static int
10426 test_AES_GCM_authenticated_decryption_test_case_5(void)
10427 {
10428 	return test_authenticated_decryption(&gcm_test_case_5);
10429 }
10430 
10431 static int
10432 test_AES_GCM_authenticated_decryption_test_case_6(void)
10433 {
10434 	return test_authenticated_decryption(&gcm_test_case_6);
10435 }
10436 
10437 static int
10438 test_AES_GCM_authenticated_decryption_test_case_7(void)
10439 {
10440 	return test_authenticated_decryption(&gcm_test_case_7);
10441 }
10442 
10443 static int
10444 test_AES_GCM_authenticated_decryption_test_case_8(void)
10445 {
10446 	return test_authenticated_decryption(&gcm_test_case_8);
10447 }
10448 
10449 static int
10450 test_AES_GCM_J0_authenticated_decryption_test_case_1(void)
10451 {
10452 	return test_authenticated_decryption(&gcm_J0_test_case_1);
10453 }
10454 
10455 static int
10456 test_AES_GCM_auth_decryption_test_case_192_1(void)
10457 {
10458 	return test_authenticated_decryption(&gcm_test_case_192_1);
10459 }
10460 
10461 static int
10462 test_AES_GCM_auth_decryption_test_case_192_2(void)
10463 {
10464 	return test_authenticated_decryption(&gcm_test_case_192_2);
10465 }
10466 
10467 static int
10468 test_AES_GCM_auth_decryption_test_case_192_3(void)
10469 {
10470 	return test_authenticated_decryption(&gcm_test_case_192_3);
10471 }
10472 
10473 static int
10474 test_AES_GCM_auth_decryption_test_case_192_4(void)
10475 {
10476 	return test_authenticated_decryption(&gcm_test_case_192_4);
10477 }
10478 
10479 static int
10480 test_AES_GCM_auth_decryption_test_case_192_5(void)
10481 {
10482 	return test_authenticated_decryption(&gcm_test_case_192_5);
10483 }
10484 
10485 static int
10486 test_AES_GCM_auth_decryption_test_case_192_6(void)
10487 {
10488 	return test_authenticated_decryption(&gcm_test_case_192_6);
10489 }
10490 
10491 static int
10492 test_AES_GCM_auth_decryption_test_case_192_7(void)
10493 {
10494 	return test_authenticated_decryption(&gcm_test_case_192_7);
10495 }
10496 
10497 static int
10498 test_AES_GCM_auth_decryption_test_case_256_1(void)
10499 {
10500 	return test_authenticated_decryption(&gcm_test_case_256_1);
10501 }
10502 
10503 static int
10504 test_AES_GCM_auth_decryption_test_case_256_2(void)
10505 {
10506 	return test_authenticated_decryption(&gcm_test_case_256_2);
10507 }
10508 
10509 static int
10510 test_AES_GCM_auth_decryption_test_case_256_3(void)
10511 {
10512 	return test_authenticated_decryption(&gcm_test_case_256_3);
10513 }
10514 
10515 static int
10516 test_AES_GCM_auth_decryption_test_case_256_4(void)
10517 {
10518 	return test_authenticated_decryption(&gcm_test_case_256_4);
10519 }
10520 
10521 static int
10522 test_AES_GCM_auth_decryption_test_case_256_5(void)
10523 {
10524 	return test_authenticated_decryption(&gcm_test_case_256_5);
10525 }
10526 
10527 static int
10528 test_AES_GCM_auth_decryption_test_case_256_6(void)
10529 {
10530 	return test_authenticated_decryption(&gcm_test_case_256_6);
10531 }
10532 
10533 static int
10534 test_AES_GCM_auth_decryption_test_case_256_7(void)
10535 {
10536 	return test_authenticated_decryption(&gcm_test_case_256_7);
10537 }
10538 
10539 static int
10540 test_AES_GCM_auth_decryption_test_case_aad_1(void)
10541 {
10542 	return test_authenticated_decryption(&gcm_test_case_aad_1);
10543 }
10544 
10545 static int
10546 test_AES_GCM_auth_decryption_test_case_aad_2(void)
10547 {
10548 	return test_authenticated_decryption(&gcm_test_case_aad_2);
10549 }
10550 
10551 static int
10552 test_AES_GCM_auth_decryption_fail_iv_corrupt(void)
10553 {
10554 	struct aead_test_data tdata;
10555 	int res;
10556 
10557 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10558 	tdata.iv.data[0] += 1;
10559 	res = test_authenticated_decryption(&tdata);
10560 	if (res == TEST_SKIPPED)
10561 		return res;
10562 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10563 	return TEST_SUCCESS;
10564 }
10565 
10566 static int
10567 test_AES_GCM_auth_decryption_fail_in_data_corrupt(void)
10568 {
10569 	struct aead_test_data tdata;
10570 	int res;
10571 
10572 	RTE_LOG(INFO, USER1, "This is a negative test, errors are expected\n");
10573 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10574 	tdata.plaintext.data[0] += 1;
10575 	res = test_authenticated_decryption(&tdata);
10576 	if (res == TEST_SKIPPED)
10577 		return res;
10578 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10579 	return TEST_SUCCESS;
10580 }
10581 
10582 static int
10583 test_AES_GCM_auth_decryption_fail_out_data_corrupt(void)
10584 {
10585 	struct aead_test_data tdata;
10586 	int res;
10587 
10588 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10589 	tdata.ciphertext.data[0] += 1;
10590 	res = test_authenticated_decryption(&tdata);
10591 	if (res == TEST_SKIPPED)
10592 		return res;
10593 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10594 	return TEST_SUCCESS;
10595 }
10596 
10597 static int
10598 test_AES_GCM_auth_decryption_fail_aad_len_corrupt(void)
10599 {
10600 	struct aead_test_data tdata;
10601 	int res;
10602 
10603 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10604 	tdata.aad.len += 1;
10605 	res = test_authenticated_decryption(&tdata);
10606 	if (res == TEST_SKIPPED)
10607 		return res;
10608 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10609 	return TEST_SUCCESS;
10610 }
10611 
10612 static int
10613 test_AES_GCM_auth_decryption_fail_aad_corrupt(void)
10614 {
10615 	struct aead_test_data tdata;
10616 	uint8_t aad[gcm_test_case_7.aad.len];
10617 	int res;
10618 
10619 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10620 	memcpy(aad, gcm_test_case_7.aad.data, gcm_test_case_7.aad.len);
10621 	aad[0] += 1;
10622 	tdata.aad.data = aad;
10623 	res = test_authenticated_decryption(&tdata);
10624 	if (res == TEST_SKIPPED)
10625 		return res;
10626 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "decryption not failed");
10627 	return TEST_SUCCESS;
10628 }
10629 
10630 static int
10631 test_AES_GCM_auth_decryption_fail_tag_corrupt(void)
10632 {
10633 	struct aead_test_data tdata;
10634 	int res;
10635 
10636 	memcpy(&tdata, &gcm_test_case_7, sizeof(struct aead_test_data));
10637 	tdata.auth_tag.data[0] += 1;
10638 	res = test_authenticated_decryption(&tdata);
10639 	if (res == TEST_SKIPPED)
10640 		return res;
10641 	TEST_ASSERT_EQUAL(res, TEST_FAILED, "authentication not failed");
10642 	return TEST_SUCCESS;
10643 }
10644 
10645 static int
10646 test_authenticated_encryption_oop(const struct aead_test_data *tdata)
10647 {
10648 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10649 	struct crypto_unittest_params *ut_params = &unittest_params;
10650 
10651 	int retval;
10652 	uint8_t *ciphertext, *auth_tag;
10653 	uint16_t plaintext_pad_len;
10654 	struct rte_cryptodev_info dev_info;
10655 
10656 	/* Verify the capabilities */
10657 	struct rte_cryptodev_sym_capability_idx cap_idx;
10658 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10659 	cap_idx.algo.aead = tdata->algo;
10660 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10661 			&cap_idx) == NULL)
10662 		return TEST_SKIPPED;
10663 
10664 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10665 	uint64_t feat_flags = dev_info.feature_flags;
10666 
10667 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10668 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP)))
10669 		return TEST_SKIPPED;
10670 
10671 	/* not supported with CPU crypto */
10672 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10673 		return TEST_SKIPPED;
10674 
10675 	/* Create AEAD session */
10676 	retval = create_aead_session(ts_params->valid_devs[0],
10677 			tdata->algo,
10678 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10679 			tdata->key.data, tdata->key.len,
10680 			tdata->aad.len, tdata->auth_tag.len,
10681 			tdata->iv.len);
10682 	if (retval < 0)
10683 		return retval;
10684 
10685 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10686 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10687 
10688 	/* clear mbuf payload */
10689 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10690 			rte_pktmbuf_tailroom(ut_params->ibuf));
10691 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10692 			rte_pktmbuf_tailroom(ut_params->obuf));
10693 
10694 	/* Create AEAD operation */
10695 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10696 	if (retval < 0)
10697 		return retval;
10698 
10699 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10700 
10701 	ut_params->op->sym->m_src = ut_params->ibuf;
10702 	ut_params->op->sym->m_dst = ut_params->obuf;
10703 
10704 	/* Process crypto operation */
10705 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10706 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10707 			ut_params->op, 0, 0, 0, 0);
10708 	else
10709 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10710 			ut_params->op), "failed to process sym crypto op");
10711 
10712 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10713 			"crypto op processing failed");
10714 
10715 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10716 
10717 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10718 			ut_params->op->sym->cipher.data.offset);
10719 	auth_tag = ciphertext + plaintext_pad_len;
10720 
10721 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10722 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10723 
10724 	/* Validate obuf */
10725 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10726 			ciphertext,
10727 			tdata->ciphertext.data,
10728 			tdata->ciphertext.len,
10729 			"Ciphertext data not as expected");
10730 
10731 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10732 			auth_tag,
10733 			tdata->auth_tag.data,
10734 			tdata->auth_tag.len,
10735 			"Generated auth tag not as expected");
10736 
10737 	return 0;
10738 
10739 }
10740 
10741 static int
10742 test_AES_GCM_authenticated_encryption_oop_test_case_1(void)
10743 {
10744 	return test_authenticated_encryption_oop(&gcm_test_case_5);
10745 }
10746 
10747 static int
10748 test_authenticated_decryption_oop(const struct aead_test_data *tdata)
10749 {
10750 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10751 	struct crypto_unittest_params *ut_params = &unittest_params;
10752 
10753 	int retval;
10754 	uint8_t *plaintext;
10755 	struct rte_cryptodev_info dev_info;
10756 
10757 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10758 	uint64_t feat_flags = dev_info.feature_flags;
10759 
10760 	/* Verify the capabilities */
10761 	struct rte_cryptodev_sym_capability_idx cap_idx;
10762 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10763 	cap_idx.algo.aead = tdata->algo;
10764 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10765 			&cap_idx) == NULL)
10766 		return TEST_SKIPPED;
10767 
10768 	/* not supported with CPU crypto and raw data-path APIs*/
10769 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO ||
10770 			global_api_test_type == CRYPTODEV_RAW_API_TEST)
10771 		return TEST_SKIPPED;
10772 
10773 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10774 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10775 		printf("Device does not support RAW data-path APIs.\n");
10776 		return TEST_SKIPPED;
10777 	}
10778 
10779 	/* Create AEAD session */
10780 	retval = create_aead_session(ts_params->valid_devs[0],
10781 			tdata->algo,
10782 			RTE_CRYPTO_AEAD_OP_DECRYPT,
10783 			tdata->key.data, tdata->key.len,
10784 			tdata->aad.len, tdata->auth_tag.len,
10785 			tdata->iv.len);
10786 	if (retval < 0)
10787 		return retval;
10788 
10789 	/* alloc mbuf and set payload */
10790 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10791 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10792 
10793 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10794 			rte_pktmbuf_tailroom(ut_params->ibuf));
10795 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
10796 			rte_pktmbuf_tailroom(ut_params->obuf));
10797 
10798 	/* Create AEAD operation */
10799 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10800 	if (retval < 0)
10801 		return retval;
10802 
10803 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
10804 
10805 	ut_params->op->sym->m_src = ut_params->ibuf;
10806 	ut_params->op->sym->m_dst = ut_params->obuf;
10807 
10808 	/* Process crypto operation */
10809 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
10810 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
10811 				ut_params->op, 0, 0, 0, 0);
10812 	else
10813 		TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10814 			ut_params->op), "failed to process sym crypto op");
10815 
10816 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10817 			"crypto op processing failed");
10818 
10819 	plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
10820 			ut_params->op->sym->cipher.data.offset);
10821 
10822 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
10823 
10824 	/* Validate obuf */
10825 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10826 			plaintext,
10827 			tdata->plaintext.data,
10828 			tdata->plaintext.len,
10829 			"Plaintext data not as expected");
10830 
10831 	TEST_ASSERT_EQUAL(ut_params->op->status,
10832 			RTE_CRYPTO_OP_STATUS_SUCCESS,
10833 			"Authentication failed");
10834 	return 0;
10835 }
10836 
10837 static int
10838 test_AES_GCM_authenticated_decryption_oop_test_case_1(void)
10839 {
10840 	return test_authenticated_decryption_oop(&gcm_test_case_5);
10841 }
10842 
10843 static int
10844 test_authenticated_encryption_sessionless(
10845 		const struct aead_test_data *tdata)
10846 {
10847 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10848 	struct crypto_unittest_params *ut_params = &unittest_params;
10849 
10850 	int retval;
10851 	uint8_t *ciphertext, *auth_tag;
10852 	uint16_t plaintext_pad_len;
10853 	uint8_t key[tdata->key.len + 1];
10854 	struct rte_cryptodev_info dev_info;
10855 
10856 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10857 	uint64_t feat_flags = dev_info.feature_flags;
10858 
10859 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10860 		printf("Device doesn't support Sessionless ops.\n");
10861 		return TEST_SKIPPED;
10862 	}
10863 
10864 	/* not supported with CPU crypto */
10865 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10866 		return TEST_SKIPPED;
10867 
10868 	/* Verify the capabilities */
10869 	struct rte_cryptodev_sym_capability_idx cap_idx;
10870 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10871 	cap_idx.algo.aead = tdata->algo;
10872 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10873 			&cap_idx) == NULL)
10874 		return TEST_SKIPPED;
10875 
10876 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10877 
10878 	/* clear mbuf payload */
10879 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10880 			rte_pktmbuf_tailroom(ut_params->ibuf));
10881 
10882 	/* Create AEAD operation */
10883 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_ENCRYPT, tdata);
10884 	if (retval < 0)
10885 		return retval;
10886 
10887 	/* Create GCM xform */
10888 	memcpy(key, tdata->key.data, tdata->key.len);
10889 	retval = create_aead_xform(ut_params->op,
10890 			tdata->algo,
10891 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
10892 			key, tdata->key.len,
10893 			tdata->aad.len, tdata->auth_tag.len,
10894 			tdata->iv.len);
10895 	if (retval < 0)
10896 		return retval;
10897 
10898 	ut_params->op->sym->m_src = ut_params->ibuf;
10899 
10900 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
10901 			RTE_CRYPTO_OP_SESSIONLESS,
10902 			"crypto op session type not sessionless");
10903 
10904 	/* Process crypto operation */
10905 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
10906 			ut_params->op), "failed to process sym crypto op");
10907 
10908 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
10909 
10910 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
10911 			"crypto op status not success");
10912 
10913 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
10914 
10915 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
10916 			ut_params->op->sym->cipher.data.offset);
10917 	auth_tag = ciphertext + plaintext_pad_len;
10918 
10919 	debug_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
10920 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
10921 
10922 	/* Validate obuf */
10923 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10924 			ciphertext,
10925 			tdata->ciphertext.data,
10926 			tdata->ciphertext.len,
10927 			"Ciphertext data not as expected");
10928 
10929 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
10930 			auth_tag,
10931 			tdata->auth_tag.data,
10932 			tdata->auth_tag.len,
10933 			"Generated auth tag not as expected");
10934 
10935 	return 0;
10936 
10937 }
10938 
10939 static int
10940 test_AES_GCM_authenticated_encryption_sessionless_test_case_1(void)
10941 {
10942 	return test_authenticated_encryption_sessionless(
10943 			&gcm_test_case_5);
10944 }
10945 
10946 static int
10947 test_authenticated_decryption_sessionless(
10948 		const struct aead_test_data *tdata)
10949 {
10950 	struct crypto_testsuite_params *ts_params = &testsuite_params;
10951 	struct crypto_unittest_params *ut_params = &unittest_params;
10952 
10953 	int retval;
10954 	uint8_t *plaintext;
10955 	uint8_t key[tdata->key.len + 1];
10956 	struct rte_cryptodev_info dev_info;
10957 
10958 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
10959 	uint64_t feat_flags = dev_info.feature_flags;
10960 
10961 	if (!(feat_flags & RTE_CRYPTODEV_FF_SYM_SESSIONLESS)) {
10962 		printf("Device doesn't support Sessionless ops.\n");
10963 		return TEST_SKIPPED;
10964 	}
10965 
10966 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
10967 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
10968 		printf("Device doesn't support RAW data-path APIs.\n");
10969 		return TEST_SKIPPED;
10970 	}
10971 
10972 	/* not supported with CPU crypto */
10973 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
10974 		return TEST_SKIPPED;
10975 
10976 	/* Verify the capabilities */
10977 	struct rte_cryptodev_sym_capability_idx cap_idx;
10978 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
10979 	cap_idx.algo.aead = tdata->algo;
10980 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
10981 			&cap_idx) == NULL)
10982 		return TEST_SKIPPED;
10983 
10984 	/* alloc mbuf and set payload */
10985 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
10986 
10987 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
10988 			rte_pktmbuf_tailroom(ut_params->ibuf));
10989 
10990 	/* Create AEAD operation */
10991 	retval = create_aead_operation(RTE_CRYPTO_AEAD_OP_DECRYPT, tdata);
10992 	if (retval < 0)
10993 		return retval;
10994 
10995 	/* Create AEAD xform */
10996 	memcpy(key, tdata->key.data, tdata->key.len);
10997 	retval = create_aead_xform(ut_params->op,
10998 			tdata->algo,
10999 			RTE_CRYPTO_AEAD_OP_DECRYPT,
11000 			key, tdata->key.len,
11001 			tdata->aad.len, tdata->auth_tag.len,
11002 			tdata->iv.len);
11003 	if (retval < 0)
11004 		return retval;
11005 
11006 	ut_params->op->sym->m_src = ut_params->ibuf;
11007 
11008 	TEST_ASSERT_EQUAL(ut_params->op->sess_type,
11009 			RTE_CRYPTO_OP_SESSIONLESS,
11010 			"crypto op session type not sessionless");
11011 
11012 	/* Process crypto operation */
11013 	if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11014 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11015 				ut_params->op, 0, 0, 0, 0);
11016 	else
11017 		TEST_ASSERT_NOT_NULL(process_crypto_request(
11018 			ts_params->valid_devs[0], ut_params->op),
11019 				"failed to process sym crypto op");
11020 
11021 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
11022 
11023 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11024 			"crypto op status not success");
11025 
11026 	plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
11027 			ut_params->op->sym->cipher.data.offset);
11028 
11029 	debug_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
11030 
11031 	/* Validate obuf */
11032 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11033 			plaintext,
11034 			tdata->plaintext.data,
11035 			tdata->plaintext.len,
11036 			"Plaintext data not as expected");
11037 
11038 	TEST_ASSERT_EQUAL(ut_params->op->status,
11039 			RTE_CRYPTO_OP_STATUS_SUCCESS,
11040 			"Authentication failed");
11041 	return 0;
11042 }
11043 
11044 static int
11045 test_AES_GCM_authenticated_decryption_sessionless_test_case_1(void)
11046 {
11047 	return test_authenticated_decryption_sessionless(
11048 			&gcm_test_case_5);
11049 }
11050 
11051 static int
11052 test_AES_CCM_authenticated_encryption_test_case_128_1(void)
11053 {
11054 	return test_authenticated_encryption(&ccm_test_case_128_1);
11055 }
11056 
11057 static int
11058 test_AES_CCM_authenticated_encryption_test_case_128_2(void)
11059 {
11060 	return test_authenticated_encryption(&ccm_test_case_128_2);
11061 }
11062 
11063 static int
11064 test_AES_CCM_authenticated_encryption_test_case_128_3(void)
11065 {
11066 	return test_authenticated_encryption(&ccm_test_case_128_3);
11067 }
11068 
11069 static int
11070 test_AES_CCM_authenticated_decryption_test_case_128_1(void)
11071 {
11072 	return test_authenticated_decryption(&ccm_test_case_128_1);
11073 }
11074 
11075 static int
11076 test_AES_CCM_authenticated_decryption_test_case_128_2(void)
11077 {
11078 	return test_authenticated_decryption(&ccm_test_case_128_2);
11079 }
11080 
11081 static int
11082 test_AES_CCM_authenticated_decryption_test_case_128_3(void)
11083 {
11084 	return test_authenticated_decryption(&ccm_test_case_128_3);
11085 }
11086 
11087 static int
11088 test_AES_CCM_authenticated_encryption_test_case_192_1(void)
11089 {
11090 	return test_authenticated_encryption(&ccm_test_case_192_1);
11091 }
11092 
11093 static int
11094 test_AES_CCM_authenticated_encryption_test_case_192_2(void)
11095 {
11096 	return test_authenticated_encryption(&ccm_test_case_192_2);
11097 }
11098 
11099 static int
11100 test_AES_CCM_authenticated_encryption_test_case_192_3(void)
11101 {
11102 	return test_authenticated_encryption(&ccm_test_case_192_3);
11103 }
11104 
11105 static int
11106 test_AES_CCM_authenticated_decryption_test_case_192_1(void)
11107 {
11108 	return test_authenticated_decryption(&ccm_test_case_192_1);
11109 }
11110 
11111 static int
11112 test_AES_CCM_authenticated_decryption_test_case_192_2(void)
11113 {
11114 	return test_authenticated_decryption(&ccm_test_case_192_2);
11115 }
11116 
11117 static int
11118 test_AES_CCM_authenticated_decryption_test_case_192_3(void)
11119 {
11120 	return test_authenticated_decryption(&ccm_test_case_192_3);
11121 }
11122 
11123 static int
11124 test_AES_CCM_authenticated_encryption_test_case_256_1(void)
11125 {
11126 	return test_authenticated_encryption(&ccm_test_case_256_1);
11127 }
11128 
11129 static int
11130 test_AES_CCM_authenticated_encryption_test_case_256_2(void)
11131 {
11132 	return test_authenticated_encryption(&ccm_test_case_256_2);
11133 }
11134 
11135 static int
11136 test_AES_CCM_authenticated_encryption_test_case_256_3(void)
11137 {
11138 	return test_authenticated_encryption(&ccm_test_case_256_3);
11139 }
11140 
11141 static int
11142 test_AES_CCM_authenticated_decryption_test_case_256_1(void)
11143 {
11144 	return test_authenticated_decryption(&ccm_test_case_256_1);
11145 }
11146 
11147 static int
11148 test_AES_CCM_authenticated_decryption_test_case_256_2(void)
11149 {
11150 	return test_authenticated_decryption(&ccm_test_case_256_2);
11151 }
11152 
11153 static int
11154 test_AES_CCM_authenticated_decryption_test_case_256_3(void)
11155 {
11156 	return test_authenticated_decryption(&ccm_test_case_256_3);
11157 }
11158 
11159 static int
11160 test_stats(void)
11161 {
11162 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11163 	struct rte_cryptodev_stats stats;
11164 
11165 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11166 		return TEST_SKIPPED;
11167 
11168 	/* Verify the capabilities */
11169 	struct rte_cryptodev_sym_capability_idx cap_idx;
11170 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11171 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA1_HMAC;
11172 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11173 			&cap_idx) == NULL)
11174 		return TEST_SKIPPED;
11175 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11176 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11177 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11178 			&cap_idx) == NULL)
11179 		return TEST_SKIPPED;
11180 
11181 	if (rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
11182 			== -ENOTSUP)
11183 		return TEST_SKIPPED;
11184 
11185 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11186 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
11187 			&stats) == -ENODEV),
11188 		"rte_cryptodev_stats_get invalid dev failed");
11189 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
11190 		"rte_cryptodev_stats_get invalid Param failed");
11191 
11192 	/* Test expected values */
11193 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
11194 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11195 			&stats),
11196 		"rte_cryptodev_stats_get failed");
11197 	TEST_ASSERT((stats.enqueued_count == 1),
11198 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11199 	TEST_ASSERT((stats.dequeued_count == 1),
11200 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11201 	TEST_ASSERT((stats.enqueue_err_count == 0),
11202 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11203 	TEST_ASSERT((stats.dequeue_err_count == 0),
11204 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11205 
11206 	/* invalid device but should ignore and not reset device stats*/
11207 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
11208 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11209 			&stats),
11210 		"rte_cryptodev_stats_get failed");
11211 	TEST_ASSERT((stats.enqueued_count == 1),
11212 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11213 
11214 	/* check that a valid reset clears stats */
11215 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
11216 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
11217 			&stats),
11218 					  "rte_cryptodev_stats_get failed");
11219 	TEST_ASSERT((stats.enqueued_count == 0),
11220 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11221 	TEST_ASSERT((stats.dequeued_count == 0),
11222 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
11223 
11224 	return TEST_SUCCESS;
11225 }
11226 
11227 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
11228 				   struct crypto_unittest_params *ut_params,
11229 				   enum rte_crypto_auth_operation op,
11230 				   const struct HMAC_MD5_vector *test_case)
11231 {
11232 	uint8_t key[64];
11233 	int status;
11234 
11235 	memcpy(key, test_case->key.data, test_case->key.len);
11236 
11237 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11238 	ut_params->auth_xform.next = NULL;
11239 	ut_params->auth_xform.auth.op = op;
11240 
11241 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
11242 
11243 	ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
11244 	ut_params->auth_xform.auth.key.length = test_case->key.len;
11245 	ut_params->auth_xform.auth.key.data = key;
11246 
11247 	ut_params->sess = rte_cryptodev_sym_session_create(
11248 			ts_params->session_mpool);
11249 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11250 	if (ut_params->sess == NULL)
11251 		return TEST_FAILED;
11252 
11253 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11254 			ut_params->sess, &ut_params->auth_xform,
11255 			ts_params->session_priv_mpool);
11256 	if (status == -ENOTSUP)
11257 		return TEST_SKIPPED;
11258 
11259 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11260 
11261 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
11262 			rte_pktmbuf_tailroom(ut_params->ibuf));
11263 
11264 	return 0;
11265 }
11266 
11267 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
11268 			      const struct HMAC_MD5_vector *test_case,
11269 			      uint8_t **plaintext)
11270 {
11271 	uint16_t plaintext_pad_len;
11272 
11273 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
11274 
11275 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11276 				16);
11277 
11278 	*plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
11279 			plaintext_pad_len);
11280 	memcpy(*plaintext, test_case->plaintext.data,
11281 			test_case->plaintext.len);
11282 
11283 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
11284 			ut_params->ibuf, MD5_DIGEST_LEN);
11285 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
11286 			"no room to append digest");
11287 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
11288 			ut_params->ibuf, plaintext_pad_len);
11289 
11290 	if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
11291 		rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
11292 			   test_case->auth_tag.len);
11293 	}
11294 
11295 	sym_op->auth.data.offset = 0;
11296 	sym_op->auth.data.length = test_case->plaintext.len;
11297 
11298 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
11299 	ut_params->op->sym->m_src = ut_params->ibuf;
11300 
11301 	return 0;
11302 }
11303 
11304 static int
11305 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
11306 {
11307 	uint16_t plaintext_pad_len;
11308 	uint8_t *plaintext, *auth_tag;
11309 
11310 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11311 	struct crypto_unittest_params *ut_params = &unittest_params;
11312 	struct rte_cryptodev_info dev_info;
11313 
11314 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11315 	uint64_t feat_flags = dev_info.feature_flags;
11316 
11317 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11318 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11319 		printf("Device doesn't support RAW data-path APIs.\n");
11320 		return TEST_SKIPPED;
11321 	}
11322 
11323 	/* Verify the capabilities */
11324 	struct rte_cryptodev_sym_capability_idx cap_idx;
11325 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11326 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11327 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11328 			&cap_idx) == NULL)
11329 		return TEST_SKIPPED;
11330 
11331 	if (MD5_HMAC_create_session(ts_params, ut_params,
11332 			RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
11333 		return TEST_FAILED;
11334 
11335 	/* Generate Crypto op data structure */
11336 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11337 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11338 	TEST_ASSERT_NOT_NULL(ut_params->op,
11339 			"Failed to allocate symmetric crypto operation struct");
11340 
11341 	plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
11342 				16);
11343 
11344 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11345 		return TEST_FAILED;
11346 
11347 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11348 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11349 			ut_params->op);
11350 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11351 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11352 				ut_params->op, 0, 1, 0, 0);
11353 	else
11354 		TEST_ASSERT_NOT_NULL(
11355 			process_crypto_request(ts_params->valid_devs[0],
11356 				ut_params->op),
11357 				"failed to process sym crypto op");
11358 
11359 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11360 			"crypto op processing failed");
11361 
11362 	if (ut_params->op->sym->m_dst) {
11363 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
11364 				uint8_t *, plaintext_pad_len);
11365 	} else {
11366 		auth_tag = plaintext + plaintext_pad_len;
11367 	}
11368 
11369 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
11370 			auth_tag,
11371 			test_case->auth_tag.data,
11372 			test_case->auth_tag.len,
11373 			"HMAC_MD5 generated tag not as expected");
11374 
11375 	return TEST_SUCCESS;
11376 }
11377 
11378 static int
11379 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
11380 {
11381 	uint8_t *plaintext;
11382 
11383 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11384 	struct crypto_unittest_params *ut_params = &unittest_params;
11385 	struct rte_cryptodev_info dev_info;
11386 
11387 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11388 	uint64_t feat_flags = dev_info.feature_flags;
11389 
11390 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
11391 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
11392 		printf("Device doesn't support RAW data-path APIs.\n");
11393 		return TEST_SKIPPED;
11394 	}
11395 
11396 	/* Verify the capabilities */
11397 	struct rte_cryptodev_sym_capability_idx cap_idx;
11398 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11399 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_MD5_HMAC;
11400 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11401 			&cap_idx) == NULL)
11402 		return TEST_SKIPPED;
11403 
11404 	if (MD5_HMAC_create_session(ts_params, ut_params,
11405 			RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
11406 		return TEST_FAILED;
11407 	}
11408 
11409 	/* Generate Crypto op data structure */
11410 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
11411 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
11412 	TEST_ASSERT_NOT_NULL(ut_params->op,
11413 			"Failed to allocate symmetric crypto operation struct");
11414 
11415 	if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
11416 		return TEST_FAILED;
11417 
11418 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
11419 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
11420 			ut_params->op);
11421 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
11422 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
11423 				ut_params->op, 0, 1, 0, 0);
11424 	else
11425 		TEST_ASSERT_NOT_NULL(
11426 			process_crypto_request(ts_params->valid_devs[0],
11427 				ut_params->op),
11428 				"failed to process sym crypto op");
11429 
11430 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
11431 			"HMAC_MD5 crypto op processing failed");
11432 
11433 	return TEST_SUCCESS;
11434 }
11435 
11436 static int
11437 test_MD5_HMAC_generate_case_1(void)
11438 {
11439 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
11440 }
11441 
11442 static int
11443 test_MD5_HMAC_verify_case_1(void)
11444 {
11445 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
11446 }
11447 
11448 static int
11449 test_MD5_HMAC_generate_case_2(void)
11450 {
11451 	return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
11452 }
11453 
11454 static int
11455 test_MD5_HMAC_verify_case_2(void)
11456 {
11457 	return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
11458 }
11459 
11460 static int
11461 test_multi_session(void)
11462 {
11463 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11464 	struct crypto_unittest_params *ut_params = &unittest_params;
11465 
11466 	struct rte_cryptodev_info dev_info;
11467 	struct rte_cryptodev_sym_session **sessions;
11468 
11469 	uint16_t i;
11470 	int status;
11471 
11472 	/* Verify the capabilities */
11473 	struct rte_cryptodev_sym_capability_idx cap_idx;
11474 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11475 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11476 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11477 			&cap_idx) == NULL)
11478 		return TEST_SKIPPED;
11479 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11480 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11481 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11482 			&cap_idx) == NULL)
11483 		return TEST_SKIPPED;
11484 
11485 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
11486 			aes_cbc_key, hmac_sha512_key);
11487 
11488 
11489 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11490 
11491 	sessions = rte_malloc(NULL,
11492 			sizeof(struct rte_cryptodev_sym_session *) *
11493 			(MAX_NB_SESSIONS + 1), 0);
11494 
11495 	/* Create multiple crypto sessions*/
11496 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11497 
11498 		sessions[i] = rte_cryptodev_sym_session_create(
11499 				ts_params->session_mpool);
11500 		TEST_ASSERT_NOT_NULL(sessions[i],
11501 				"Session creation failed at session number %u",
11502 				i);
11503 
11504 		status = rte_cryptodev_sym_session_init(
11505 				ts_params->valid_devs[0],
11506 				sessions[i], &ut_params->auth_xform,
11507 				ts_params->session_priv_mpool);
11508 		if (status == -ENOTSUP)
11509 			return TEST_SKIPPED;
11510 
11511 		/* Attempt to send a request on each session */
11512 		TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
11513 			sessions[i],
11514 			ut_params,
11515 			ts_params,
11516 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
11517 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
11518 			aes_cbc_iv),
11519 			"Failed to perform decrypt on request number %u.", i);
11520 		/* free crypto operation structure */
11521 		if (ut_params->op)
11522 			rte_crypto_op_free(ut_params->op);
11523 
11524 		/*
11525 		 * free mbuf - both obuf and ibuf are usually the same,
11526 		 * so check if they point at the same address is necessary,
11527 		 * to avoid freeing the mbuf twice.
11528 		 */
11529 		if (ut_params->obuf) {
11530 			rte_pktmbuf_free(ut_params->obuf);
11531 			if (ut_params->ibuf == ut_params->obuf)
11532 				ut_params->ibuf = 0;
11533 			ut_params->obuf = 0;
11534 		}
11535 		if (ut_params->ibuf) {
11536 			rte_pktmbuf_free(ut_params->ibuf);
11537 			ut_params->ibuf = 0;
11538 		}
11539 	}
11540 
11541 	sessions[i] = NULL;
11542 	/* Next session create should fail */
11543 	rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11544 			sessions[i], &ut_params->auth_xform,
11545 			ts_params->session_priv_mpool);
11546 	TEST_ASSERT_NULL(sessions[i],
11547 			"Session creation succeeded unexpectedly!");
11548 
11549 	for (i = 0; i < MAX_NB_SESSIONS; i++) {
11550 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11551 				sessions[i]);
11552 		rte_cryptodev_sym_session_free(sessions[i]);
11553 	}
11554 
11555 	rte_free(sessions);
11556 
11557 	return TEST_SUCCESS;
11558 }
11559 
11560 struct multi_session_params {
11561 	struct crypto_unittest_params ut_params;
11562 	uint8_t *cipher_key;
11563 	uint8_t *hmac_key;
11564 	const uint8_t *cipher;
11565 	const uint8_t *digest;
11566 	uint8_t *iv;
11567 };
11568 
11569 #define MB_SESSION_NUMBER 3
11570 
11571 static int
11572 test_multi_session_random_usage(void)
11573 {
11574 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11575 	struct rte_cryptodev_info dev_info;
11576 	struct rte_cryptodev_sym_session **sessions;
11577 	uint32_t i, j;
11578 	struct multi_session_params ut_paramz[] = {
11579 
11580 		{
11581 			.cipher_key = ms_aes_cbc_key0,
11582 			.hmac_key = ms_hmac_key0,
11583 			.cipher = ms_aes_cbc_cipher0,
11584 			.digest = ms_hmac_digest0,
11585 			.iv = ms_aes_cbc_iv0
11586 		},
11587 		{
11588 			.cipher_key = ms_aes_cbc_key1,
11589 			.hmac_key = ms_hmac_key1,
11590 			.cipher = ms_aes_cbc_cipher1,
11591 			.digest = ms_hmac_digest1,
11592 			.iv = ms_aes_cbc_iv1
11593 		},
11594 		{
11595 			.cipher_key = ms_aes_cbc_key2,
11596 			.hmac_key = ms_hmac_key2,
11597 			.cipher = ms_aes_cbc_cipher2,
11598 			.digest = ms_hmac_digest2,
11599 			.iv = ms_aes_cbc_iv2
11600 		},
11601 
11602 	};
11603 	int status;
11604 
11605 	/* Verify the capabilities */
11606 	struct rte_cryptodev_sym_capability_idx cap_idx;
11607 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11608 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_SHA512_HMAC;
11609 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11610 			&cap_idx) == NULL)
11611 		return TEST_SKIPPED;
11612 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11613 	cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_AES_CBC;
11614 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
11615 			&cap_idx) == NULL)
11616 		return TEST_SKIPPED;
11617 
11618 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11619 
11620 	sessions = rte_malloc(NULL,
11621 			(sizeof(struct rte_cryptodev_sym_session *)
11622 					* MAX_NB_SESSIONS) + 1, 0);
11623 
11624 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11625 		sessions[i] = rte_cryptodev_sym_session_create(
11626 				ts_params->session_mpool);
11627 		TEST_ASSERT_NOT_NULL(sessions[i],
11628 				"Session creation failed at session number %u",
11629 				i);
11630 
11631 		rte_memcpy(&ut_paramz[i].ut_params, &unittest_params,
11632 				sizeof(struct crypto_unittest_params));
11633 
11634 		test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
11635 				&ut_paramz[i].ut_params,
11636 				ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
11637 
11638 		/* Create multiple crypto sessions*/
11639 		status = rte_cryptodev_sym_session_init(
11640 				ts_params->valid_devs[0],
11641 				sessions[i],
11642 				&ut_paramz[i].ut_params.auth_xform,
11643 				ts_params->session_priv_mpool);
11644 
11645 		if (status == -ENOTSUP)
11646 			return TEST_SKIPPED;
11647 
11648 		TEST_ASSERT_EQUAL(status, 0, "Session init failed");
11649 	}
11650 
11651 	srand(time(NULL));
11652 	for (i = 0; i < 40000; i++) {
11653 
11654 		j = rand() % MB_SESSION_NUMBER;
11655 
11656 		TEST_ASSERT_SUCCESS(
11657 			test_AES_CBC_HMAC_SHA512_decrypt_perform(
11658 					sessions[j],
11659 					&ut_paramz[j].ut_params,
11660 					ts_params, ut_paramz[j].cipher,
11661 					ut_paramz[j].digest,
11662 					ut_paramz[j].iv),
11663 			"Failed to perform decrypt on request number %u.", i);
11664 
11665 		if (ut_paramz[j].ut_params.op)
11666 			rte_crypto_op_free(ut_paramz[j].ut_params.op);
11667 
11668 		/*
11669 		 * free mbuf - both obuf and ibuf are usually the same,
11670 		 * so check if they point at the same address is necessary,
11671 		 * to avoid freeing the mbuf twice.
11672 		 */
11673 		if (ut_paramz[j].ut_params.obuf) {
11674 			rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
11675 			if (ut_paramz[j].ut_params.ibuf
11676 					== ut_paramz[j].ut_params.obuf)
11677 				ut_paramz[j].ut_params.ibuf = 0;
11678 			ut_paramz[j].ut_params.obuf = 0;
11679 		}
11680 		if (ut_paramz[j].ut_params.ibuf) {
11681 			rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
11682 			ut_paramz[j].ut_params.ibuf = 0;
11683 		}
11684 	}
11685 
11686 	for (i = 0; i < MB_SESSION_NUMBER; i++) {
11687 		rte_cryptodev_sym_session_clear(ts_params->valid_devs[0],
11688 				sessions[i]);
11689 		rte_cryptodev_sym_session_free(sessions[i]);
11690 	}
11691 
11692 	rte_free(sessions);
11693 
11694 	return TEST_SUCCESS;
11695 }
11696 
11697 uint8_t orig_data[] = {0xab, 0xab, 0xab, 0xab,
11698 			0xab, 0xab, 0xab, 0xab,
11699 			0xab, 0xab, 0xab, 0xab,
11700 			0xab, 0xab, 0xab, 0xab};
11701 
11702 static int
11703 test_null_invalid_operation(void)
11704 {
11705 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11706 	struct crypto_unittest_params *ut_params = &unittest_params;
11707 	int ret;
11708 
11709 	/* This test is for NULL PMD only */
11710 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11711 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11712 		return TEST_SKIPPED;
11713 
11714 	/* Setup Cipher Parameters */
11715 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11716 	ut_params->cipher_xform.next = NULL;
11717 
11718 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
11719 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11720 
11721 	ut_params->sess = rte_cryptodev_sym_session_create(
11722 			ts_params->session_mpool);
11723 
11724 	/* Create Crypto session*/
11725 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11726 			ut_params->sess, &ut_params->cipher_xform,
11727 			ts_params->session_priv_mpool);
11728 	TEST_ASSERT(ret < 0,
11729 			"Session creation succeeded unexpectedly");
11730 
11731 
11732 	/* Setup HMAC Parameters */
11733 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11734 	ut_params->auth_xform.next = NULL;
11735 
11736 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
11737 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11738 
11739 	ut_params->sess = rte_cryptodev_sym_session_create(
11740 			ts_params->session_mpool);
11741 
11742 	/* Create Crypto session*/
11743 	ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11744 			ut_params->sess, &ut_params->auth_xform,
11745 			ts_params->session_priv_mpool);
11746 	TEST_ASSERT(ret < 0,
11747 			"Session creation succeeded unexpectedly");
11748 
11749 	return TEST_SUCCESS;
11750 }
11751 
11752 
11753 #define NULL_BURST_LENGTH (32)
11754 
11755 static int
11756 test_null_burst_operation(void)
11757 {
11758 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11759 	struct crypto_unittest_params *ut_params = &unittest_params;
11760 	int status;
11761 
11762 	unsigned i, burst_len = NULL_BURST_LENGTH;
11763 
11764 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
11765 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
11766 
11767 	/* This test is for NULL PMD only */
11768 	if (gbl_driver_id != rte_cryptodev_driver_id_get(
11769 			RTE_STR(CRYPTODEV_NAME_NULL_PMD)))
11770 		return TEST_SKIPPED;
11771 
11772 	/* Setup Cipher Parameters */
11773 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
11774 	ut_params->cipher_xform.next = &ut_params->auth_xform;
11775 
11776 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
11777 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
11778 
11779 	/* Setup HMAC Parameters */
11780 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
11781 	ut_params->auth_xform.next = NULL;
11782 
11783 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
11784 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
11785 
11786 	ut_params->sess = rte_cryptodev_sym_session_create(
11787 			ts_params->session_mpool);
11788 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
11789 
11790 	/* Create Crypto session*/
11791 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
11792 			ut_params->sess, &ut_params->cipher_xform,
11793 			ts_params->session_priv_mpool);
11794 
11795 	if (status == -ENOTSUP)
11796 		return TEST_SKIPPED;
11797 
11798 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
11799 
11800 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
11801 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
11802 			burst_len, "failed to generate burst of crypto ops");
11803 
11804 	/* Generate an operation for each mbuf in burst */
11805 	for (i = 0; i < burst_len; i++) {
11806 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
11807 
11808 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
11809 
11810 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
11811 				sizeof(unsigned));
11812 		*data = i;
11813 
11814 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
11815 
11816 		burst[i]->sym->m_src = m;
11817 	}
11818 
11819 	/* Process crypto operation */
11820 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
11821 			0, burst, burst_len),
11822 			burst_len,
11823 			"Error enqueuing burst");
11824 
11825 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
11826 			0, burst_dequeued, burst_len),
11827 			burst_len,
11828 			"Error dequeuing burst");
11829 
11830 
11831 	for (i = 0; i < burst_len; i++) {
11832 		TEST_ASSERT_EQUAL(
11833 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
11834 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
11835 					uint32_t *),
11836 			"data not as expected");
11837 
11838 		rte_pktmbuf_free(burst[i]->sym->m_src);
11839 		rte_crypto_op_free(burst[i]);
11840 	}
11841 
11842 	return TEST_SUCCESS;
11843 }
11844 
11845 static uint16_t
11846 test_enq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11847 		  uint16_t nb_ops, void *user_param)
11848 {
11849 	RTE_SET_USED(dev_id);
11850 	RTE_SET_USED(qp_id);
11851 	RTE_SET_USED(ops);
11852 	RTE_SET_USED(user_param);
11853 
11854 	printf("crypto enqueue callback called\n");
11855 	return nb_ops;
11856 }
11857 
11858 static uint16_t
11859 test_deq_callback(uint16_t dev_id, uint16_t qp_id, struct rte_crypto_op **ops,
11860 		  uint16_t nb_ops, void *user_param)
11861 {
11862 	RTE_SET_USED(dev_id);
11863 	RTE_SET_USED(qp_id);
11864 	RTE_SET_USED(ops);
11865 	RTE_SET_USED(user_param);
11866 
11867 	printf("crypto dequeue callback called\n");
11868 	return nb_ops;
11869 }
11870 
11871 /*
11872  * Thread using enqueue/dequeue callback with RCU.
11873  */
11874 static int
11875 test_enqdeq_callback_thread(void *arg)
11876 {
11877 	RTE_SET_USED(arg);
11878 	/* DP thread calls rte_cryptodev_enqueue_burst()/
11879 	 * rte_cryptodev_dequeue_burst() and invokes callback.
11880 	 */
11881 	test_null_burst_operation();
11882 	return 0;
11883 }
11884 
11885 static int
11886 test_enq_callback_setup(void)
11887 {
11888 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11889 	struct rte_cryptodev_info dev_info;
11890 	struct rte_cryptodev_qp_conf qp_conf = {
11891 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11892 	};
11893 
11894 	struct rte_cryptodev_cb *cb;
11895 	uint16_t qp_id = 0;
11896 
11897 	/* Stop the device in case it's started so it can be configured */
11898 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11899 
11900 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
11901 
11902 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
11903 			&ts_params->conf),
11904 			"Failed to configure cryptodev %u",
11905 			ts_params->valid_devs[0]);
11906 
11907 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
11908 	qp_conf.mp_session = ts_params->session_mpool;
11909 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
11910 
11911 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
11912 			ts_params->valid_devs[0], qp_id, &qp_conf,
11913 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
11914 			"Failed test for "
11915 			"rte_cryptodev_queue_pair_setup: num_inflights "
11916 			"%u on qp %u on cryptodev %u",
11917 			qp_conf.nb_descriptors, qp_id,
11918 			ts_params->valid_devs[0]);
11919 
11920 	/* Test with invalid crypto device */
11921 	cb = rte_cryptodev_add_enq_callback(RTE_CRYPTO_MAX_DEVS,
11922 			qp_id, test_enq_callback, NULL);
11923 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11924 			"cryptodev %u did not fail",
11925 			qp_id, RTE_CRYPTO_MAX_DEVS);
11926 
11927 	/* Test with invalid queue pair */
11928 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11929 			dev_info.max_nb_queue_pairs + 1,
11930 			test_enq_callback, NULL);
11931 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11932 			"cryptodev %u did not fail",
11933 			dev_info.max_nb_queue_pairs + 1,
11934 			ts_params->valid_devs[0]);
11935 
11936 	/* Test with NULL callback */
11937 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11938 			qp_id, NULL, NULL);
11939 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
11940 			"cryptodev %u did not fail",
11941 			qp_id, ts_params->valid_devs[0]);
11942 
11943 	/* Test with valid configuration */
11944 	cb = rte_cryptodev_add_enq_callback(ts_params->valid_devs[0],
11945 			qp_id, test_enq_callback, NULL);
11946 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
11947 			"qp %u on cryptodev %u",
11948 			qp_id, ts_params->valid_devs[0]);
11949 
11950 	rte_cryptodev_start(ts_params->valid_devs[0]);
11951 
11952 	/* Launch a thread */
11953 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
11954 				rte_get_next_lcore(-1, 1, 0));
11955 
11956 	/* Wait until reader exited. */
11957 	rte_eal_mp_wait_lcore();
11958 
11959 	/* Test with invalid crypto device */
11960 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11961 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
11962 			"Expected call to fail as crypto device is invalid");
11963 
11964 	/* Test with invalid queue pair */
11965 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11966 			ts_params->valid_devs[0],
11967 			dev_info.max_nb_queue_pairs + 1, cb),
11968 			"Expected call to fail as queue pair is invalid");
11969 
11970 	/* Test with NULL callback */
11971 	TEST_ASSERT_FAIL(rte_cryptodev_remove_enq_callback(
11972 			ts_params->valid_devs[0], qp_id, NULL),
11973 			"Expected call to fail as callback is NULL");
11974 
11975 	/* Test with valid configuration */
11976 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_enq_callback(
11977 			ts_params->valid_devs[0], qp_id, cb),
11978 			"Failed test to remove callback on "
11979 			"qp %u on cryptodev %u",
11980 			qp_id, ts_params->valid_devs[0]);
11981 
11982 	return TEST_SUCCESS;
11983 }
11984 
11985 static int
11986 test_deq_callback_setup(void)
11987 {
11988 	struct crypto_testsuite_params *ts_params = &testsuite_params;
11989 	struct rte_cryptodev_info dev_info;
11990 	struct rte_cryptodev_qp_conf qp_conf = {
11991 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
11992 	};
11993 
11994 	struct rte_cryptodev_cb *cb;
11995 	uint16_t qp_id = 0;
11996 
11997 	/* Stop the device in case it's started so it can be configured */
11998 	rte_cryptodev_stop(ts_params->valid_devs[0]);
11999 
12000 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12001 
12002 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
12003 			&ts_params->conf),
12004 			"Failed to configure cryptodev %u",
12005 			ts_params->valid_devs[0]);
12006 
12007 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
12008 	qp_conf.mp_session = ts_params->session_mpool;
12009 	qp_conf.mp_session_private = ts_params->session_priv_mpool;
12010 
12011 	TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
12012 			ts_params->valid_devs[0], qp_id, &qp_conf,
12013 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
12014 			"Failed test for "
12015 			"rte_cryptodev_queue_pair_setup: num_inflights "
12016 			"%u on qp %u on cryptodev %u",
12017 			qp_conf.nb_descriptors, qp_id,
12018 			ts_params->valid_devs[0]);
12019 
12020 	/* Test with invalid crypto device */
12021 	cb = rte_cryptodev_add_deq_callback(RTE_CRYPTO_MAX_DEVS,
12022 			qp_id, test_deq_callback, NULL);
12023 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12024 			"cryptodev %u did not fail",
12025 			qp_id, RTE_CRYPTO_MAX_DEVS);
12026 
12027 	/* Test with invalid queue pair */
12028 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12029 			dev_info.max_nb_queue_pairs + 1,
12030 			test_deq_callback, NULL);
12031 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12032 			"cryptodev %u did not fail",
12033 			dev_info.max_nb_queue_pairs + 1,
12034 			ts_params->valid_devs[0]);
12035 
12036 	/* Test with NULL callback */
12037 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12038 			qp_id, NULL, NULL);
12039 	TEST_ASSERT_NULL(cb, "Add callback on qp %u on "
12040 			"cryptodev %u did not fail",
12041 			qp_id, ts_params->valid_devs[0]);
12042 
12043 	/* Test with valid configuration */
12044 	cb = rte_cryptodev_add_deq_callback(ts_params->valid_devs[0],
12045 			qp_id, test_deq_callback, NULL);
12046 	TEST_ASSERT_NOT_NULL(cb, "Failed test to add callback on "
12047 			"qp %u on cryptodev %u",
12048 			qp_id, ts_params->valid_devs[0]);
12049 
12050 	rte_cryptodev_start(ts_params->valid_devs[0]);
12051 
12052 	/* Launch a thread */
12053 	rte_eal_remote_launch(test_enqdeq_callback_thread, NULL,
12054 				rte_get_next_lcore(-1, 1, 0));
12055 
12056 	/* Wait until reader exited. */
12057 	rte_eal_mp_wait_lcore();
12058 
12059 	/* Test with invalid crypto device */
12060 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12061 			RTE_CRYPTO_MAX_DEVS, qp_id, cb),
12062 			"Expected call to fail as crypto device is invalid");
12063 
12064 	/* Test with invalid queue pair */
12065 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12066 			ts_params->valid_devs[0],
12067 			dev_info.max_nb_queue_pairs + 1, cb),
12068 			"Expected call to fail as queue pair is invalid");
12069 
12070 	/* Test with NULL callback */
12071 	TEST_ASSERT_FAIL(rte_cryptodev_remove_deq_callback(
12072 			ts_params->valid_devs[0], qp_id, NULL),
12073 			"Expected call to fail as callback is NULL");
12074 
12075 	/* Test with valid configuration */
12076 	TEST_ASSERT_SUCCESS(rte_cryptodev_remove_deq_callback(
12077 			ts_params->valid_devs[0], qp_id, cb),
12078 			"Failed test to remove callback on "
12079 			"qp %u on cryptodev %u",
12080 			qp_id, ts_params->valid_devs[0]);
12081 
12082 	return TEST_SUCCESS;
12083 }
12084 
12085 static void
12086 generate_gmac_large_plaintext(uint8_t *data)
12087 {
12088 	uint16_t i;
12089 
12090 	for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
12091 		memcpy(&data[i], &data[0], 32);
12092 }
12093 
12094 static int
12095 create_gmac_operation(enum rte_crypto_auth_operation op,
12096 		const struct gmac_test_data *tdata)
12097 {
12098 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12099 	struct crypto_unittest_params *ut_params = &unittest_params;
12100 	struct rte_crypto_sym_op *sym_op;
12101 
12102 	uint32_t plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12103 
12104 	/* Generate Crypto op data structure */
12105 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12106 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12107 	TEST_ASSERT_NOT_NULL(ut_params->op,
12108 			"Failed to allocate symmetric crypto operation struct");
12109 
12110 	sym_op = ut_params->op->sym;
12111 
12112 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12113 			ut_params->ibuf, tdata->gmac_tag.len);
12114 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12115 			"no room to append digest");
12116 
12117 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12118 			ut_params->ibuf, plaintext_pad_len);
12119 
12120 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12121 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12122 				tdata->gmac_tag.len);
12123 		debug_hexdump(stdout, "digest:",
12124 				sym_op->auth.digest.data,
12125 				tdata->gmac_tag.len);
12126 	}
12127 
12128 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12129 			uint8_t *, IV_OFFSET);
12130 
12131 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12132 
12133 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12134 
12135 	sym_op->cipher.data.length = 0;
12136 	sym_op->cipher.data.offset = 0;
12137 
12138 	sym_op->auth.data.offset = 0;
12139 	sym_op->auth.data.length = tdata->plaintext.len;
12140 
12141 	return 0;
12142 }
12143 
12144 static int
12145 create_gmac_operation_sgl(enum rte_crypto_auth_operation op,
12146 		const struct gmac_test_data *tdata,
12147 		void *digest_mem, uint64_t digest_phys)
12148 {
12149 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12150 	struct crypto_unittest_params *ut_params = &unittest_params;
12151 	struct rte_crypto_sym_op *sym_op;
12152 
12153 	/* Generate Crypto op data structure */
12154 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12155 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12156 	TEST_ASSERT_NOT_NULL(ut_params->op,
12157 			"Failed to allocate symmetric crypto operation struct");
12158 
12159 	sym_op = ut_params->op->sym;
12160 
12161 	sym_op->auth.digest.data = digest_mem;
12162 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12163 			"no room to append digest");
12164 
12165 	sym_op->auth.digest.phys_addr = digest_phys;
12166 
12167 	if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
12168 		rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
12169 				tdata->gmac_tag.len);
12170 		debug_hexdump(stdout, "digest:",
12171 				sym_op->auth.digest.data,
12172 				tdata->gmac_tag.len);
12173 	}
12174 
12175 	uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
12176 			uint8_t *, IV_OFFSET);
12177 
12178 	rte_memcpy(iv_ptr, tdata->iv.data, tdata->iv.len);
12179 
12180 	debug_hexdump(stdout, "iv:", iv_ptr, tdata->iv.len);
12181 
12182 	sym_op->cipher.data.length = 0;
12183 	sym_op->cipher.data.offset = 0;
12184 
12185 	sym_op->auth.data.offset = 0;
12186 	sym_op->auth.data.length = tdata->plaintext.len;
12187 
12188 	return 0;
12189 }
12190 
12191 static int create_gmac_session(uint8_t dev_id,
12192 		const struct gmac_test_data *tdata,
12193 		enum rte_crypto_auth_operation auth_op)
12194 {
12195 	uint8_t auth_key[tdata->key.len];
12196 	int status;
12197 
12198 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12199 	struct crypto_unittest_params *ut_params = &unittest_params;
12200 
12201 	memcpy(auth_key, tdata->key.data, tdata->key.len);
12202 
12203 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12204 	ut_params->auth_xform.next = NULL;
12205 
12206 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
12207 	ut_params->auth_xform.auth.op = auth_op;
12208 	ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
12209 	ut_params->auth_xform.auth.key.length = tdata->key.len;
12210 	ut_params->auth_xform.auth.key.data = auth_key;
12211 	ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12212 	ut_params->auth_xform.auth.iv.length = tdata->iv.len;
12213 
12214 
12215 	ut_params->sess = rte_cryptodev_sym_session_create(
12216 			ts_params->session_mpool);
12217 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12218 
12219 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12220 			&ut_params->auth_xform,
12221 			ts_params->session_priv_mpool);
12222 
12223 	return status;
12224 }
12225 
12226 static int
12227 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
12228 {
12229 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12230 	struct crypto_unittest_params *ut_params = &unittest_params;
12231 	struct rte_cryptodev_info dev_info;
12232 
12233 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12234 	uint64_t feat_flags = dev_info.feature_flags;
12235 
12236 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12237 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12238 		printf("Device doesn't support RAW data-path APIs.\n");
12239 		return TEST_SKIPPED;
12240 	}
12241 
12242 	int retval;
12243 
12244 	uint8_t *auth_tag, *plaintext;
12245 	uint16_t plaintext_pad_len;
12246 
12247 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12248 			      "No GMAC length in the source data");
12249 
12250 	/* Verify the capabilities */
12251 	struct rte_cryptodev_sym_capability_idx cap_idx;
12252 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12253 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12254 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12255 			&cap_idx) == NULL)
12256 		return TEST_SKIPPED;
12257 
12258 	retval = create_gmac_session(ts_params->valid_devs[0],
12259 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12260 
12261 	if (retval == -ENOTSUP)
12262 		return TEST_SKIPPED;
12263 	if (retval < 0)
12264 		return retval;
12265 
12266 	if (tdata->plaintext.len > MBUF_SIZE)
12267 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12268 	else
12269 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12270 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12271 			"Failed to allocate input buffer in mempool");
12272 
12273 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12274 			rte_pktmbuf_tailroom(ut_params->ibuf));
12275 
12276 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12277 	/*
12278 	 * Runtime generate the large plain text instead of use hard code
12279 	 * plain text vector. It is done to avoid create huge source file
12280 	 * with the test vector.
12281 	 */
12282 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12283 		generate_gmac_large_plaintext(tdata->plaintext.data);
12284 
12285 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12286 				plaintext_pad_len);
12287 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12288 
12289 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12290 	debug_hexdump(stdout, "plaintext:", plaintext,
12291 			tdata->plaintext.len);
12292 
12293 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
12294 			tdata);
12295 
12296 	if (retval < 0)
12297 		return retval;
12298 
12299 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12300 
12301 	ut_params->op->sym->m_src = ut_params->ibuf;
12302 
12303 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12304 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12305 			ut_params->op);
12306 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12307 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12308 				ut_params->op, 0, 1, 0, 0);
12309 	else
12310 		TEST_ASSERT_NOT_NULL(
12311 			process_crypto_request(ts_params->valid_devs[0],
12312 			ut_params->op), "failed to process sym crypto op");
12313 
12314 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12315 			"crypto op processing failed");
12316 
12317 	if (ut_params->op->sym->m_dst) {
12318 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
12319 				uint8_t *, plaintext_pad_len);
12320 	} else {
12321 		auth_tag = plaintext + plaintext_pad_len;
12322 	}
12323 
12324 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12325 
12326 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12327 			auth_tag,
12328 			tdata->gmac_tag.data,
12329 			tdata->gmac_tag.len,
12330 			"GMAC Generated auth tag not as expected");
12331 
12332 	return 0;
12333 }
12334 
12335 static int
12336 test_AES_GMAC_authentication_test_case_1(void)
12337 {
12338 	return test_AES_GMAC_authentication(&gmac_test_case_1);
12339 }
12340 
12341 static int
12342 test_AES_GMAC_authentication_test_case_2(void)
12343 {
12344 	return test_AES_GMAC_authentication(&gmac_test_case_2);
12345 }
12346 
12347 static int
12348 test_AES_GMAC_authentication_test_case_3(void)
12349 {
12350 	return test_AES_GMAC_authentication(&gmac_test_case_3);
12351 }
12352 
12353 static int
12354 test_AES_GMAC_authentication_test_case_4(void)
12355 {
12356 	return test_AES_GMAC_authentication(&gmac_test_case_4);
12357 }
12358 
12359 static int
12360 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
12361 {
12362 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12363 	struct crypto_unittest_params *ut_params = &unittest_params;
12364 	int retval;
12365 	uint32_t plaintext_pad_len;
12366 	uint8_t *plaintext;
12367 	struct rte_cryptodev_info dev_info;
12368 
12369 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12370 	uint64_t feat_flags = dev_info.feature_flags;
12371 
12372 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
12373 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
12374 		printf("Device doesn't support RAW data-path APIs.\n");
12375 		return TEST_SKIPPED;
12376 	}
12377 
12378 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12379 			      "No GMAC length in the source data");
12380 
12381 	/* Verify the capabilities */
12382 	struct rte_cryptodev_sym_capability_idx cap_idx;
12383 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12384 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12385 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12386 			&cap_idx) == NULL)
12387 		return TEST_SKIPPED;
12388 
12389 	retval = create_gmac_session(ts_params->valid_devs[0],
12390 			tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
12391 
12392 	if (retval == -ENOTSUP)
12393 		return TEST_SKIPPED;
12394 	if (retval < 0)
12395 		return retval;
12396 
12397 	if (tdata->plaintext.len > MBUF_SIZE)
12398 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
12399 	else
12400 		ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12401 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12402 			"Failed to allocate input buffer in mempool");
12403 
12404 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12405 			rte_pktmbuf_tailroom(ut_params->ibuf));
12406 
12407 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
12408 
12409 	/*
12410 	 * Runtime generate the large plain text instead of use hard code
12411 	 * plain text vector. It is done to avoid create huge source file
12412 	 * with the test vector.
12413 	 */
12414 	if (tdata->plaintext.len == GMAC_LARGE_PLAINTEXT_LENGTH)
12415 		generate_gmac_large_plaintext(tdata->plaintext.data);
12416 
12417 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12418 				plaintext_pad_len);
12419 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12420 
12421 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
12422 	debug_hexdump(stdout, "plaintext:", plaintext,
12423 			tdata->plaintext.len);
12424 
12425 	retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
12426 			tdata);
12427 
12428 	if (retval < 0)
12429 		return retval;
12430 
12431 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12432 
12433 	ut_params->op->sym->m_src = ut_params->ibuf;
12434 
12435 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12436 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
12437 			ut_params->op);
12438 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
12439 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
12440 				ut_params->op, 0, 1, 0, 0);
12441 	else
12442 		TEST_ASSERT_NOT_NULL(
12443 			process_crypto_request(ts_params->valid_devs[0],
12444 			ut_params->op), "failed to process sym crypto op");
12445 
12446 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12447 			"crypto op processing failed");
12448 
12449 	return 0;
12450 
12451 }
12452 
12453 static int
12454 test_AES_GMAC_authentication_verify_test_case_1(void)
12455 {
12456 	return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
12457 }
12458 
12459 static int
12460 test_AES_GMAC_authentication_verify_test_case_2(void)
12461 {
12462 	return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
12463 }
12464 
12465 static int
12466 test_AES_GMAC_authentication_verify_test_case_3(void)
12467 {
12468 	return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
12469 }
12470 
12471 static int
12472 test_AES_GMAC_authentication_verify_test_case_4(void)
12473 {
12474 	return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
12475 }
12476 
12477 static int
12478 test_AES_GMAC_authentication_SGL(const struct gmac_test_data *tdata,
12479 				uint32_t fragsz)
12480 {
12481 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12482 	struct crypto_unittest_params *ut_params = &unittest_params;
12483 	struct rte_cryptodev_info dev_info;
12484 	uint64_t feature_flags;
12485 	unsigned int trn_data = 0;
12486 	void *digest_mem = NULL;
12487 	uint32_t segs = 1;
12488 	unsigned int to_trn = 0;
12489 	struct rte_mbuf *buf = NULL;
12490 	uint8_t *auth_tag, *plaintext;
12491 	int retval;
12492 
12493 	TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
12494 			      "No GMAC length in the source data");
12495 
12496 	/* Verify the capabilities */
12497 	struct rte_cryptodev_sym_capability_idx cap_idx;
12498 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12499 	cap_idx.algo.auth = RTE_CRYPTO_AUTH_AES_GMAC;
12500 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
12501 			&cap_idx) == NULL)
12502 		return TEST_SKIPPED;
12503 
12504 	/* Check for any input SGL support */
12505 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
12506 	feature_flags = dev_info.feature_flags;
12507 
12508 	if ((!(feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) ||
12509 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT)) ||
12510 			(!(feature_flags & RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT)))
12511 		return TEST_SKIPPED;
12512 
12513 	if (fragsz > tdata->plaintext.len)
12514 		fragsz = tdata->plaintext.len;
12515 
12516 	uint16_t plaintext_len = fragsz;
12517 
12518 	retval = create_gmac_session(ts_params->valid_devs[0],
12519 			tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
12520 
12521 	if (retval == -ENOTSUP)
12522 		return TEST_SKIPPED;
12523 	if (retval < 0)
12524 		return retval;
12525 
12526 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12527 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
12528 			"Failed to allocate input buffer in mempool");
12529 
12530 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
12531 			rte_pktmbuf_tailroom(ut_params->ibuf));
12532 
12533 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12534 				plaintext_len);
12535 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
12536 
12537 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
12538 
12539 	trn_data += plaintext_len;
12540 
12541 	buf = ut_params->ibuf;
12542 
12543 	/*
12544 	 * Loop until no more fragments
12545 	 */
12546 
12547 	while (trn_data < tdata->plaintext.len) {
12548 		++segs;
12549 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
12550 				(tdata->plaintext.len - trn_data) : fragsz;
12551 
12552 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
12553 		buf = buf->next;
12554 
12555 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
12556 				rte_pktmbuf_tailroom(buf));
12557 
12558 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
12559 				to_trn);
12560 
12561 		memcpy(plaintext, tdata->plaintext.data + trn_data,
12562 				to_trn);
12563 		trn_data += to_trn;
12564 		if (trn_data  == tdata->plaintext.len)
12565 			digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
12566 					tdata->gmac_tag.len);
12567 	}
12568 	ut_params->ibuf->nb_segs = segs;
12569 
12570 	/*
12571 	 * Place digest at the end of the last buffer
12572 	 */
12573 	uint64_t digest_phys = rte_pktmbuf_iova(buf) + to_trn;
12574 
12575 	if (!digest_mem) {
12576 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
12577 				+ tdata->gmac_tag.len);
12578 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
12579 				tdata->plaintext.len);
12580 	}
12581 
12582 	retval = create_gmac_operation_sgl(RTE_CRYPTO_AUTH_OP_GENERATE,
12583 			tdata, digest_mem, digest_phys);
12584 
12585 	if (retval < 0)
12586 		return retval;
12587 
12588 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12589 
12590 	ut_params->op->sym->m_src = ut_params->ibuf;
12591 
12592 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
12593 		return TEST_SKIPPED;
12594 
12595 	TEST_ASSERT_NOT_NULL(
12596 		process_crypto_request(ts_params->valid_devs[0],
12597 		ut_params->op), "failed to process sym crypto op");
12598 
12599 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
12600 			"crypto op processing failed");
12601 
12602 	auth_tag = digest_mem;
12603 	debug_hexdump(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
12604 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
12605 			auth_tag,
12606 			tdata->gmac_tag.data,
12607 			tdata->gmac_tag.len,
12608 			"GMAC Generated auth tag not as expected");
12609 
12610 	return 0;
12611 }
12612 
12613 /* Segment size not multiple of block size (16B) */
12614 static int
12615 test_AES_GMAC_authentication_SGL_40B(void)
12616 {
12617 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 40);
12618 }
12619 
12620 static int
12621 test_AES_GMAC_authentication_SGL_80B(void)
12622 {
12623 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_1, 80);
12624 }
12625 
12626 static int
12627 test_AES_GMAC_authentication_SGL_2048B(void)
12628 {
12629 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2048);
12630 }
12631 
12632 /* Segment size not multiple of block size (16B) */
12633 static int
12634 test_AES_GMAC_authentication_SGL_2047B(void)
12635 {
12636 	return test_AES_GMAC_authentication_SGL(&gmac_test_case_5, 2047);
12637 }
12638 
12639 struct test_crypto_vector {
12640 	enum rte_crypto_cipher_algorithm crypto_algo;
12641 	unsigned int cipher_offset;
12642 	unsigned int cipher_len;
12643 
12644 	struct {
12645 		uint8_t data[64];
12646 		unsigned int len;
12647 	} cipher_key;
12648 
12649 	struct {
12650 		uint8_t data[64];
12651 		unsigned int len;
12652 	} iv;
12653 
12654 	struct {
12655 		const uint8_t *data;
12656 		unsigned int len;
12657 	} plaintext;
12658 
12659 	struct {
12660 		const uint8_t *data;
12661 		unsigned int len;
12662 	} ciphertext;
12663 
12664 	enum rte_crypto_auth_algorithm auth_algo;
12665 	unsigned int auth_offset;
12666 
12667 	struct {
12668 		uint8_t data[128];
12669 		unsigned int len;
12670 	} auth_key;
12671 
12672 	struct {
12673 		const uint8_t *data;
12674 		unsigned int len;
12675 	} aad;
12676 
12677 	struct {
12678 		uint8_t data[128];
12679 		unsigned int len;
12680 	} digest;
12681 };
12682 
12683 static const struct test_crypto_vector
12684 hmac_sha1_test_crypto_vector = {
12685 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12686 	.plaintext = {
12687 		.data = plaintext_hash,
12688 		.len = 512
12689 	},
12690 	.auth_key = {
12691 		.data = {
12692 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12693 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12694 			0xDE, 0xF4, 0xDE, 0xAD
12695 		},
12696 		.len = 20
12697 	},
12698 	.digest = {
12699 		.data = {
12700 			0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
12701 			0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
12702 			0x3F, 0x91, 0x64, 0x59
12703 		},
12704 		.len = 20
12705 	}
12706 };
12707 
12708 static const struct test_crypto_vector
12709 aes128_gmac_test_vector = {
12710 	.auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
12711 	.plaintext = {
12712 		.data = plaintext_hash,
12713 		.len = 512
12714 	},
12715 	.iv = {
12716 		.data = {
12717 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12718 			0x08, 0x09, 0x0A, 0x0B
12719 		},
12720 		.len = 12
12721 	},
12722 	.auth_key = {
12723 		.data = {
12724 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12725 			0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
12726 		},
12727 		.len = 16
12728 	},
12729 	.digest = {
12730 		.data = {
12731 			0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
12732 			0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
12733 		},
12734 		.len = 16
12735 	}
12736 };
12737 
12738 static const struct test_crypto_vector
12739 aes128cbc_hmac_sha1_test_vector = {
12740 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12741 	.cipher_offset = 0,
12742 	.cipher_len = 512,
12743 	.cipher_key = {
12744 		.data = {
12745 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12746 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12747 		},
12748 		.len = 16
12749 	},
12750 	.iv = {
12751 		.data = {
12752 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12753 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12754 		},
12755 		.len = 16
12756 	},
12757 	.plaintext = {
12758 		.data = plaintext_hash,
12759 		.len = 512
12760 	},
12761 	.ciphertext = {
12762 		.data = ciphertext512_aes128cbc,
12763 		.len = 512
12764 	},
12765 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12766 	.auth_offset = 0,
12767 	.auth_key = {
12768 		.data = {
12769 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12770 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12771 			0xDE, 0xF4, 0xDE, 0xAD
12772 		},
12773 		.len = 20
12774 	},
12775 	.digest = {
12776 		.data = {
12777 			0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
12778 			0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
12779 			0x18, 0x8C, 0x1D, 0x32
12780 		},
12781 		.len = 20
12782 	}
12783 };
12784 
12785 static const struct test_crypto_vector
12786 aes128cbc_hmac_sha1_aad_test_vector = {
12787 	.crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
12788 	.cipher_offset = 8,
12789 	.cipher_len = 496,
12790 	.cipher_key = {
12791 		.data = {
12792 			0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
12793 			0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
12794 		},
12795 		.len = 16
12796 	},
12797 	.iv = {
12798 		.data = {
12799 			0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
12800 			0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
12801 		},
12802 		.len = 16
12803 	},
12804 	.plaintext = {
12805 		.data = plaintext_hash,
12806 		.len = 512
12807 	},
12808 	.ciphertext = {
12809 		.data = ciphertext512_aes128cbc_aad,
12810 		.len = 512
12811 	},
12812 	.auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
12813 	.auth_offset = 0,
12814 	.auth_key = {
12815 		.data = {
12816 			0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
12817 			0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
12818 			0xDE, 0xF4, 0xDE, 0xAD
12819 		},
12820 		.len = 20
12821 	},
12822 	.digest = {
12823 		.data = {
12824 			0x6D, 0xF3, 0x50, 0x79, 0x7A, 0x2A, 0xAC, 0x7F,
12825 			0xA6, 0xF0, 0xC6, 0x38, 0x1F, 0xA4, 0xDD, 0x9B,
12826 			0x62, 0x0F, 0xFB, 0x10
12827 		},
12828 		.len = 20
12829 	}
12830 };
12831 
12832 static void
12833 data_corruption(uint8_t *data)
12834 {
12835 	data[0] += 1;
12836 }
12837 
12838 static void
12839 tag_corruption(uint8_t *data, unsigned int tag_offset)
12840 {
12841 	data[tag_offset] += 1;
12842 }
12843 
12844 static int
12845 create_auth_session(struct crypto_unittest_params *ut_params,
12846 		uint8_t dev_id,
12847 		const struct test_crypto_vector *reference,
12848 		enum rte_crypto_auth_operation auth_op)
12849 {
12850 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12851 	uint8_t auth_key[reference->auth_key.len + 1];
12852 	int status;
12853 
12854 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12855 
12856 	/* Setup Authentication Parameters */
12857 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12858 	ut_params->auth_xform.auth.op = auth_op;
12859 	ut_params->auth_xform.next = NULL;
12860 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12861 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12862 	ut_params->auth_xform.auth.key.data = auth_key;
12863 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12864 
12865 	/* Create Crypto session*/
12866 	ut_params->sess = rte_cryptodev_sym_session_create(
12867 			ts_params->session_mpool);
12868 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12869 
12870 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12871 				&ut_params->auth_xform,
12872 				ts_params->session_priv_mpool);
12873 
12874 	return status;
12875 }
12876 
12877 static int
12878 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
12879 		uint8_t dev_id,
12880 		const struct test_crypto_vector *reference,
12881 		enum rte_crypto_auth_operation auth_op,
12882 		enum rte_crypto_cipher_operation cipher_op)
12883 {
12884 	struct crypto_testsuite_params *ts_params = &testsuite_params;
12885 	uint8_t cipher_key[reference->cipher_key.len + 1];
12886 	uint8_t auth_key[reference->auth_key.len + 1];
12887 	int status;
12888 
12889 	memcpy(cipher_key, reference->cipher_key.data,
12890 			reference->cipher_key.len);
12891 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
12892 
12893 	/* Setup Authentication Parameters */
12894 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
12895 	ut_params->auth_xform.auth.op = auth_op;
12896 	ut_params->auth_xform.auth.algo = reference->auth_algo;
12897 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
12898 	ut_params->auth_xform.auth.key.data = auth_key;
12899 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
12900 
12901 	if (reference->auth_algo == RTE_CRYPTO_AUTH_AES_GMAC) {
12902 		ut_params->auth_xform.auth.iv.offset = IV_OFFSET;
12903 		ut_params->auth_xform.auth.iv.length = reference->iv.len;
12904 	} else {
12905 		ut_params->auth_xform.next = &ut_params->cipher_xform;
12906 
12907 		/* Setup Cipher Parameters */
12908 		ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
12909 		ut_params->cipher_xform.next = NULL;
12910 		ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
12911 		ut_params->cipher_xform.cipher.op = cipher_op;
12912 		ut_params->cipher_xform.cipher.key.data = cipher_key;
12913 		ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
12914 		ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
12915 		ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
12916 	}
12917 
12918 	/* Create Crypto session*/
12919 	ut_params->sess = rte_cryptodev_sym_session_create(
12920 			ts_params->session_mpool);
12921 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
12922 
12923 	status = rte_cryptodev_sym_session_init(dev_id, ut_params->sess,
12924 				&ut_params->auth_xform,
12925 				ts_params->session_priv_mpool);
12926 
12927 	return status;
12928 }
12929 
12930 static int
12931 create_auth_operation(struct crypto_testsuite_params *ts_params,
12932 		struct crypto_unittest_params *ut_params,
12933 		const struct test_crypto_vector *reference,
12934 		unsigned int auth_generate)
12935 {
12936 	/* Generate Crypto op data structure */
12937 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12938 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12939 	TEST_ASSERT_NOT_NULL(ut_params->op,
12940 			"Failed to allocate pktmbuf offload");
12941 
12942 	/* Set crypto operation data parameters */
12943 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12944 
12945 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12946 
12947 	/* set crypto operation source mbuf */
12948 	sym_op->m_src = ut_params->ibuf;
12949 
12950 	/* digest */
12951 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12952 			ut_params->ibuf, reference->digest.len);
12953 
12954 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
12955 			"no room to append auth tag");
12956 
12957 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
12958 			ut_params->ibuf, reference->plaintext.len);
12959 
12960 	if (auth_generate)
12961 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
12962 	else
12963 		memcpy(sym_op->auth.digest.data,
12964 				reference->digest.data,
12965 				reference->digest.len);
12966 
12967 	debug_hexdump(stdout, "digest:",
12968 			sym_op->auth.digest.data,
12969 			reference->digest.len);
12970 
12971 	sym_op->auth.data.length = reference->plaintext.len;
12972 	sym_op->auth.data.offset = 0;
12973 
12974 	return 0;
12975 }
12976 
12977 static int
12978 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
12979 		struct crypto_unittest_params *ut_params,
12980 		const struct test_crypto_vector *reference,
12981 		unsigned int auth_generate)
12982 {
12983 	/* Generate Crypto op data structure */
12984 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
12985 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
12986 	TEST_ASSERT_NOT_NULL(ut_params->op,
12987 			"Failed to allocate pktmbuf offload");
12988 
12989 	/* Set crypto operation data parameters */
12990 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
12991 
12992 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
12993 
12994 	/* set crypto operation source mbuf */
12995 	sym_op->m_src = ut_params->ibuf;
12996 
12997 	/* digest */
12998 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
12999 			ut_params->ibuf, reference->digest.len);
13000 
13001 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13002 			"no room to append auth tag");
13003 
13004 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13005 			ut_params->ibuf, reference->ciphertext.len);
13006 
13007 	if (auth_generate)
13008 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13009 	else
13010 		memcpy(sym_op->auth.digest.data,
13011 				reference->digest.data,
13012 				reference->digest.len);
13013 
13014 	debug_hexdump(stdout, "digest:",
13015 			sym_op->auth.digest.data,
13016 			reference->digest.len);
13017 
13018 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13019 			reference->iv.data, reference->iv.len);
13020 
13021 	sym_op->cipher.data.length = 0;
13022 	sym_op->cipher.data.offset = 0;
13023 
13024 	sym_op->auth.data.length = reference->plaintext.len;
13025 	sym_op->auth.data.offset = 0;
13026 
13027 	return 0;
13028 }
13029 
13030 static int
13031 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
13032 		struct crypto_unittest_params *ut_params,
13033 		const struct test_crypto_vector *reference,
13034 		unsigned int auth_generate)
13035 {
13036 	/* Generate Crypto op data structure */
13037 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13038 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13039 	TEST_ASSERT_NOT_NULL(ut_params->op,
13040 			"Failed to allocate pktmbuf offload");
13041 
13042 	/* Set crypto operation data parameters */
13043 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13044 
13045 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13046 
13047 	/* set crypto operation source mbuf */
13048 	sym_op->m_src = ut_params->ibuf;
13049 
13050 	/* digest */
13051 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
13052 			ut_params->ibuf, reference->digest.len);
13053 
13054 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
13055 			"no room to append auth tag");
13056 
13057 	sym_op->auth.digest.phys_addr = rte_pktmbuf_iova_offset(
13058 			ut_params->ibuf, reference->ciphertext.len);
13059 
13060 	if (auth_generate)
13061 		memset(sym_op->auth.digest.data, 0, reference->digest.len);
13062 	else
13063 		memcpy(sym_op->auth.digest.data,
13064 				reference->digest.data,
13065 				reference->digest.len);
13066 
13067 	debug_hexdump(stdout, "digest:",
13068 			sym_op->auth.digest.data,
13069 			reference->digest.len);
13070 
13071 	rte_memcpy(rte_crypto_op_ctod_offset(ut_params->op, uint8_t *, IV_OFFSET),
13072 			reference->iv.data, reference->iv.len);
13073 
13074 	sym_op->cipher.data.length = reference->cipher_len;
13075 	sym_op->cipher.data.offset = reference->cipher_offset;
13076 
13077 	sym_op->auth.data.length = reference->plaintext.len;
13078 	sym_op->auth.data.offset = reference->auth_offset;
13079 
13080 	return 0;
13081 }
13082 
13083 static int
13084 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13085 		struct crypto_unittest_params *ut_params,
13086 		const struct test_crypto_vector *reference)
13087 {
13088 	return create_auth_operation(ts_params, ut_params, reference, 0);
13089 }
13090 
13091 static int
13092 create_auth_verify_GMAC_operation(
13093 		struct crypto_testsuite_params *ts_params,
13094 		struct crypto_unittest_params *ut_params,
13095 		const struct test_crypto_vector *reference)
13096 {
13097 	return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
13098 }
13099 
13100 static int
13101 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
13102 		struct crypto_unittest_params *ut_params,
13103 		const struct test_crypto_vector *reference)
13104 {
13105 	return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
13106 }
13107 
13108 static int
13109 test_authentication_verify_fail_when_data_corruption(
13110 		struct crypto_testsuite_params *ts_params,
13111 		struct crypto_unittest_params *ut_params,
13112 		const struct test_crypto_vector *reference,
13113 		unsigned int data_corrupted)
13114 {
13115 	int retval;
13116 
13117 	uint8_t *plaintext;
13118 	struct rte_cryptodev_info dev_info;
13119 
13120 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13121 	uint64_t feat_flags = dev_info.feature_flags;
13122 
13123 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13124 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13125 		printf("Device doesn't support RAW data-path APIs.\n");
13126 		return TEST_SKIPPED;
13127 	}
13128 
13129 	/* Verify the capabilities */
13130 	struct rte_cryptodev_sym_capability_idx cap_idx;
13131 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13132 	cap_idx.algo.auth = reference->auth_algo;
13133 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13134 			&cap_idx) == NULL)
13135 		return TEST_SKIPPED;
13136 
13137 
13138 	/* Create session */
13139 	retval = create_auth_session(ut_params,
13140 			ts_params->valid_devs[0],
13141 			reference,
13142 			RTE_CRYPTO_AUTH_OP_VERIFY);
13143 
13144 	if (retval == -ENOTSUP)
13145 		return TEST_SKIPPED;
13146 	if (retval < 0)
13147 		return retval;
13148 
13149 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13150 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13151 			"Failed to allocate input buffer in mempool");
13152 
13153 	/* clear mbuf payload */
13154 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13155 			rte_pktmbuf_tailroom(ut_params->ibuf));
13156 
13157 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13158 			reference->plaintext.len);
13159 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13160 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13161 
13162 	debug_hexdump(stdout, "plaintext:", plaintext,
13163 		reference->plaintext.len);
13164 
13165 	/* Create operation */
13166 	retval = create_auth_verify_operation(ts_params, ut_params, reference);
13167 
13168 	if (retval < 0)
13169 		return retval;
13170 
13171 	if (data_corrupted)
13172 		data_corruption(plaintext);
13173 	else
13174 		tag_corruption(plaintext, reference->plaintext.len);
13175 
13176 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13177 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13178 			ut_params->op);
13179 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13180 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13181 			"authentication not failed");
13182 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13183 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13184 				ut_params->op, 0, 1, 0, 0);
13185 	else {
13186 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13187 			ut_params->op);
13188 	}
13189 	if (ut_params->op == NULL)
13190 		return 0;
13191 	else if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
13192 		return 0;
13193 
13194 	return -1;
13195 }
13196 
13197 static int
13198 test_authentication_verify_GMAC_fail_when_corruption(
13199 		struct crypto_testsuite_params *ts_params,
13200 		struct crypto_unittest_params *ut_params,
13201 		const struct test_crypto_vector *reference,
13202 		unsigned int data_corrupted)
13203 {
13204 	int retval;
13205 	uint8_t *plaintext;
13206 	struct rte_cryptodev_info dev_info;
13207 
13208 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13209 	uint64_t feat_flags = dev_info.feature_flags;
13210 
13211 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13212 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13213 		printf("Device doesn't support RAW data-path APIs.\n");
13214 		return TEST_SKIPPED;
13215 	}
13216 
13217 	/* Verify the capabilities */
13218 	struct rte_cryptodev_sym_capability_idx cap_idx;
13219 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13220 	cap_idx.algo.auth = reference->auth_algo;
13221 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13222 			&cap_idx) == NULL)
13223 		return TEST_SKIPPED;
13224 
13225 	/* Create session */
13226 	retval = create_auth_cipher_session(ut_params,
13227 			ts_params->valid_devs[0],
13228 			reference,
13229 			RTE_CRYPTO_AUTH_OP_VERIFY,
13230 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13231 	if (retval < 0)
13232 		return retval;
13233 
13234 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13235 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13236 			"Failed to allocate input buffer in mempool");
13237 
13238 	/* clear mbuf payload */
13239 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13240 			rte_pktmbuf_tailroom(ut_params->ibuf));
13241 
13242 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13243 			reference->plaintext.len);
13244 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13245 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13246 
13247 	debug_hexdump(stdout, "plaintext:", plaintext,
13248 		reference->plaintext.len);
13249 
13250 	/* Create operation */
13251 	retval = create_auth_verify_GMAC_operation(ts_params,
13252 			ut_params,
13253 			reference);
13254 
13255 	if (retval < 0)
13256 		return retval;
13257 
13258 	if (data_corrupted)
13259 		data_corruption(plaintext);
13260 	else
13261 		tag_corruption(plaintext, reference->aad.len);
13262 
13263 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13264 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13265 			ut_params->op);
13266 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13267 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13268 			"authentication not failed");
13269 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13270 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13271 				ut_params->op, 0, 1, 0, 0);
13272 	else {
13273 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13274 			ut_params->op);
13275 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13276 	}
13277 
13278 	return 0;
13279 }
13280 
13281 static int
13282 test_authenticated_decryption_fail_when_corruption(
13283 		struct crypto_testsuite_params *ts_params,
13284 		struct crypto_unittest_params *ut_params,
13285 		const struct test_crypto_vector *reference,
13286 		unsigned int data_corrupted)
13287 {
13288 	int retval;
13289 
13290 	uint8_t *ciphertext;
13291 	struct rte_cryptodev_info dev_info;
13292 
13293 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13294 	uint64_t feat_flags = dev_info.feature_flags;
13295 
13296 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13297 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13298 		printf("Device doesn't support RAW data-path APIs.\n");
13299 		return TEST_SKIPPED;
13300 	}
13301 
13302 	/* Verify the capabilities */
13303 	struct rte_cryptodev_sym_capability_idx cap_idx;
13304 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13305 	cap_idx.algo.auth = reference->auth_algo;
13306 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13307 			&cap_idx) == NULL)
13308 		return TEST_SKIPPED;
13309 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13310 	cap_idx.algo.cipher = reference->crypto_algo;
13311 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13312 			&cap_idx) == NULL)
13313 		return TEST_SKIPPED;
13314 
13315 	/* Create session */
13316 	retval = create_auth_cipher_session(ut_params,
13317 			ts_params->valid_devs[0],
13318 			reference,
13319 			RTE_CRYPTO_AUTH_OP_VERIFY,
13320 			RTE_CRYPTO_CIPHER_OP_DECRYPT);
13321 
13322 	if (retval == -ENOTSUP)
13323 		return TEST_SKIPPED;
13324 	if (retval < 0)
13325 		return retval;
13326 
13327 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13328 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13329 			"Failed to allocate input buffer in mempool");
13330 
13331 	/* clear mbuf payload */
13332 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13333 			rte_pktmbuf_tailroom(ut_params->ibuf));
13334 
13335 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13336 			reference->ciphertext.len);
13337 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13338 	memcpy(ciphertext, reference->ciphertext.data,
13339 			reference->ciphertext.len);
13340 
13341 	/* Create operation */
13342 	retval = create_cipher_auth_verify_operation(ts_params,
13343 			ut_params,
13344 			reference);
13345 
13346 	if (retval < 0)
13347 		return retval;
13348 
13349 	if (data_corrupted)
13350 		data_corruption(ciphertext);
13351 	else
13352 		tag_corruption(ciphertext, reference->ciphertext.len);
13353 
13354 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO) {
13355 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13356 			ut_params->op);
13357 		TEST_ASSERT_NOT_EQUAL(ut_params->op->status,
13358 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13359 			"authentication not failed");
13360 	} else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13361 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13362 				ut_params->op, 1, 1, 0, 0);
13363 	else {
13364 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13365 			ut_params->op);
13366 		TEST_ASSERT_NULL(ut_params->op, "authentication not failed");
13367 	}
13368 
13369 	return 0;
13370 }
13371 
13372 static int
13373 test_authenticated_encrypt_with_esn(
13374 		struct crypto_testsuite_params *ts_params,
13375 		struct crypto_unittest_params *ut_params,
13376 		const struct test_crypto_vector *reference)
13377 {
13378 	int retval;
13379 
13380 	uint8_t *authciphertext, *plaintext, *auth_tag;
13381 	uint16_t plaintext_pad_len;
13382 	uint8_t cipher_key[reference->cipher_key.len + 1];
13383 	uint8_t auth_key[reference->auth_key.len + 1];
13384 	struct rte_cryptodev_info dev_info;
13385 	int status;
13386 
13387 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13388 	uint64_t feat_flags = dev_info.feature_flags;
13389 
13390 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13391 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13392 		printf("Device doesn't support RAW data-path APIs.\n");
13393 		return TEST_SKIPPED;
13394 	}
13395 
13396 	/* Verify the capabilities */
13397 	struct rte_cryptodev_sym_capability_idx cap_idx;
13398 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13399 	cap_idx.algo.auth = reference->auth_algo;
13400 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13401 			&cap_idx) == NULL)
13402 		return TEST_SKIPPED;
13403 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13404 	cap_idx.algo.cipher = reference->crypto_algo;
13405 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13406 			&cap_idx) == NULL)
13407 		return TEST_SKIPPED;
13408 
13409 	/* Create session */
13410 	memcpy(cipher_key, reference->cipher_key.data,
13411 			reference->cipher_key.len);
13412 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13413 
13414 	/* Setup Cipher Parameters */
13415 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13416 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13417 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
13418 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13419 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13420 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13421 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13422 
13423 	ut_params->cipher_xform.next = &ut_params->auth_xform;
13424 
13425 	/* Setup Authentication Parameters */
13426 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13427 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
13428 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13429 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13430 	ut_params->auth_xform.auth.key.data = auth_key;
13431 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13432 	ut_params->auth_xform.next = NULL;
13433 
13434 	/* Create Crypto session*/
13435 	ut_params->sess = rte_cryptodev_sym_session_create(
13436 			ts_params->session_mpool);
13437 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13438 
13439 	status = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13440 				ut_params->sess,
13441 				&ut_params->cipher_xform,
13442 				ts_params->session_priv_mpool);
13443 
13444 	if (status == -ENOTSUP)
13445 		return TEST_SKIPPED;
13446 
13447 	TEST_ASSERT_EQUAL(status, 0, "Session init failed");
13448 
13449 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13450 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13451 			"Failed to allocate input buffer in mempool");
13452 
13453 	/* clear mbuf payload */
13454 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13455 			rte_pktmbuf_tailroom(ut_params->ibuf));
13456 
13457 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13458 			reference->plaintext.len);
13459 	TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
13460 	memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
13461 
13462 	/* Create operation */
13463 	retval = create_cipher_auth_operation(ts_params,
13464 			ut_params,
13465 			reference, 0);
13466 
13467 	if (retval < 0)
13468 		return retval;
13469 
13470 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13471 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13472 			ut_params->op);
13473 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13474 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13475 				ut_params->op, 1, 1, 0, 0);
13476 	else
13477 		ut_params->op = process_crypto_request(
13478 			ts_params->valid_devs[0], ut_params->op);
13479 
13480 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
13481 
13482 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13483 			"crypto op processing failed");
13484 
13485 	plaintext_pad_len = RTE_ALIGN_CEIL(reference->plaintext.len, 16);
13486 
13487 	authciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
13488 			ut_params->op->sym->auth.data.offset);
13489 	auth_tag = authciphertext + plaintext_pad_len;
13490 	debug_hexdump(stdout, "ciphertext:", authciphertext,
13491 			reference->ciphertext.len);
13492 	debug_hexdump(stdout, "auth tag:", auth_tag, reference->digest.len);
13493 
13494 	/* Validate obuf */
13495 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13496 			authciphertext,
13497 			reference->ciphertext.data,
13498 			reference->ciphertext.len,
13499 			"Ciphertext data not as expected");
13500 
13501 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13502 			auth_tag,
13503 			reference->digest.data,
13504 			reference->digest.len,
13505 			"Generated digest not as expected");
13506 
13507 	return TEST_SUCCESS;
13508 
13509 }
13510 
13511 static int
13512 test_authenticated_decrypt_with_esn(
13513 		struct crypto_testsuite_params *ts_params,
13514 		struct crypto_unittest_params *ut_params,
13515 		const struct test_crypto_vector *reference)
13516 {
13517 	int retval;
13518 
13519 	uint8_t *ciphertext;
13520 	uint8_t cipher_key[reference->cipher_key.len + 1];
13521 	uint8_t auth_key[reference->auth_key.len + 1];
13522 	struct rte_cryptodev_info dev_info;
13523 
13524 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13525 	uint64_t feat_flags = dev_info.feature_flags;
13526 
13527 	if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13528 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13529 		printf("Device doesn't support RAW data-path APIs.\n");
13530 		return TEST_SKIPPED;
13531 	}
13532 
13533 	/* Verify the capabilities */
13534 	struct rte_cryptodev_sym_capability_idx cap_idx;
13535 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13536 	cap_idx.algo.auth = reference->auth_algo;
13537 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13538 			&cap_idx) == NULL)
13539 		return TEST_SKIPPED;
13540 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13541 	cap_idx.algo.cipher = reference->crypto_algo;
13542 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13543 			&cap_idx) == NULL)
13544 		return TEST_SKIPPED;
13545 
13546 	/* Create session */
13547 	memcpy(cipher_key, reference->cipher_key.data,
13548 			reference->cipher_key.len);
13549 	memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
13550 
13551 	/* Setup Authentication Parameters */
13552 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
13553 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
13554 	ut_params->auth_xform.auth.algo = reference->auth_algo;
13555 	ut_params->auth_xform.auth.key.length = reference->auth_key.len;
13556 	ut_params->auth_xform.auth.key.data = auth_key;
13557 	ut_params->auth_xform.auth.digest_length = reference->digest.len;
13558 	ut_params->auth_xform.next = &ut_params->cipher_xform;
13559 
13560 	/* Setup Cipher Parameters */
13561 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
13562 	ut_params->cipher_xform.next = NULL;
13563 	ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
13564 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
13565 	ut_params->cipher_xform.cipher.key.data = cipher_key;
13566 	ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
13567 	ut_params->cipher_xform.cipher.iv.offset = IV_OFFSET;
13568 	ut_params->cipher_xform.cipher.iv.length = reference->iv.len;
13569 
13570 	/* Create Crypto session*/
13571 	ut_params->sess = rte_cryptodev_sym_session_create(
13572 			ts_params->session_mpool);
13573 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
13574 
13575 	retval = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
13576 				ut_params->sess,
13577 				&ut_params->auth_xform,
13578 				ts_params->session_priv_mpool);
13579 
13580 	if (retval == -ENOTSUP)
13581 		return TEST_SKIPPED;
13582 
13583 	TEST_ASSERT_EQUAL(retval, 0, "Session init failed");
13584 
13585 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13586 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
13587 			"Failed to allocate input buffer in mempool");
13588 
13589 	/* clear mbuf payload */
13590 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13591 			rte_pktmbuf_tailroom(ut_params->ibuf));
13592 
13593 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13594 			reference->ciphertext.len);
13595 	TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
13596 	memcpy(ciphertext, reference->ciphertext.data,
13597 			reference->ciphertext.len);
13598 
13599 	/* Create operation */
13600 	retval = create_cipher_auth_verify_operation(ts_params,
13601 			ut_params,
13602 			reference);
13603 
13604 	if (retval < 0)
13605 		return retval;
13606 
13607 	if (gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13608 		process_cpu_crypt_auth_op(ts_params->valid_devs[0],
13609 			ut_params->op);
13610 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13611 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13612 				ut_params->op, 1, 1, 0, 0);
13613 	else
13614 		ut_params->op = process_crypto_request(ts_params->valid_devs[0],
13615 			ut_params->op);
13616 
13617 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
13618 	TEST_ASSERT_EQUAL(ut_params->op->status,
13619 			RTE_CRYPTO_OP_STATUS_SUCCESS,
13620 			"crypto op processing passed");
13621 
13622 	ut_params->obuf = ut_params->op->sym->m_src;
13623 	TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
13624 
13625 	return 0;
13626 }
13627 
13628 static int
13629 create_aead_operation_SGL(enum rte_crypto_aead_operation op,
13630 		const struct aead_test_data *tdata,
13631 		void *digest_mem, uint64_t digest_phys)
13632 {
13633 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13634 	struct crypto_unittest_params *ut_params = &unittest_params;
13635 
13636 	const unsigned int auth_tag_len = tdata->auth_tag.len;
13637 	const unsigned int iv_len = tdata->iv.len;
13638 	unsigned int aad_len = tdata->aad.len;
13639 	unsigned int aad_len_pad = 0;
13640 
13641 	/* Generate Crypto op data structure */
13642 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
13643 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
13644 	TEST_ASSERT_NOT_NULL(ut_params->op,
13645 		"Failed to allocate symmetric crypto operation struct");
13646 
13647 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
13648 
13649 	sym_op->aead.digest.data = digest_mem;
13650 
13651 	TEST_ASSERT_NOT_NULL(sym_op->aead.digest.data,
13652 			"no room to append digest");
13653 
13654 	sym_op->aead.digest.phys_addr = digest_phys;
13655 
13656 	if (op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
13657 		rte_memcpy(sym_op->aead.digest.data, tdata->auth_tag.data,
13658 				auth_tag_len);
13659 		debug_hexdump(stdout, "digest:",
13660 				sym_op->aead.digest.data,
13661 				auth_tag_len);
13662 	}
13663 
13664 	/* Append aad data */
13665 	if (tdata->algo == RTE_CRYPTO_AEAD_AES_CCM) {
13666 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13667 				uint8_t *, IV_OFFSET);
13668 
13669 		/* Copy IV 1 byte after the IV pointer, according to the API */
13670 		rte_memcpy(iv_ptr + 1, tdata->iv.data, iv_len);
13671 
13672 		aad_len = RTE_ALIGN_CEIL(aad_len + 18, 16);
13673 
13674 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13675 				ut_params->ibuf, aad_len);
13676 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13677 				"no room to prepend aad");
13678 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13679 				ut_params->ibuf);
13680 
13681 		memset(sym_op->aead.aad.data, 0, aad_len);
13682 		/* Copy AAD 18 bytes after the AAD pointer, according to the API */
13683 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13684 
13685 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13686 		debug_hexdump(stdout, "aad:",
13687 				sym_op->aead.aad.data, aad_len);
13688 	} else {
13689 		uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ut_params->op,
13690 				uint8_t *, IV_OFFSET);
13691 
13692 		rte_memcpy(iv_ptr, tdata->iv.data, iv_len);
13693 
13694 		aad_len_pad = RTE_ALIGN_CEIL(aad_len, 16);
13695 
13696 		sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_prepend(
13697 				ut_params->ibuf, aad_len_pad);
13698 		TEST_ASSERT_NOT_NULL(sym_op->aead.aad.data,
13699 				"no room to prepend aad");
13700 		sym_op->aead.aad.phys_addr = rte_pktmbuf_iova(
13701 				ut_params->ibuf);
13702 
13703 		memset(sym_op->aead.aad.data, 0, aad_len);
13704 		rte_memcpy(sym_op->aead.aad.data, tdata->aad.data, aad_len);
13705 
13706 		debug_hexdump(stdout, "iv:", iv_ptr, iv_len);
13707 		debug_hexdump(stdout, "aad:",
13708 				sym_op->aead.aad.data, aad_len);
13709 	}
13710 
13711 	sym_op->aead.data.length = tdata->plaintext.len;
13712 	sym_op->aead.data.offset = aad_len_pad;
13713 
13714 	return 0;
13715 }
13716 
13717 #define SGL_MAX_NO	16
13718 
13719 static int
13720 test_authenticated_encryption_SGL(const struct aead_test_data *tdata,
13721 		const int oop, uint32_t fragsz, uint32_t fragsz_oop)
13722 {
13723 	struct crypto_testsuite_params *ts_params = &testsuite_params;
13724 	struct crypto_unittest_params *ut_params = &unittest_params;
13725 	struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
13726 	int retval;
13727 	int to_trn = 0;
13728 	int to_trn_tbl[SGL_MAX_NO];
13729 	int segs = 1;
13730 	unsigned int trn_data = 0;
13731 	uint8_t *plaintext, *ciphertext, *auth_tag;
13732 	struct rte_cryptodev_info dev_info;
13733 
13734 	/* Verify the capabilities */
13735 	struct rte_cryptodev_sym_capability_idx cap_idx;
13736 	cap_idx.type = RTE_CRYPTO_SYM_XFORM_AEAD;
13737 	cap_idx.algo.aead = tdata->algo;
13738 	if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
13739 			&cap_idx) == NULL)
13740 		return TEST_SKIPPED;
13741 
13742 	/* OOP not supported with CPU crypto */
13743 	if (oop && gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13744 		return TEST_SKIPPED;
13745 
13746 	/* Detailed check for the particular SGL support flag */
13747 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
13748 	if (!oop) {
13749 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13750 		if (sgl_in && (!(dev_info.feature_flags &
13751 				RTE_CRYPTODEV_FF_IN_PLACE_SGL)))
13752 			return TEST_SKIPPED;
13753 
13754 		uint64_t feat_flags = dev_info.feature_flags;
13755 
13756 		if ((global_api_test_type == CRYPTODEV_RAW_API_TEST) &&
13757 			(!(feat_flags & RTE_CRYPTODEV_FF_SYM_RAW_DP))) {
13758 			printf("Device doesn't support RAW data-path APIs.\n");
13759 			return TEST_SKIPPED;
13760 		}
13761 	} else {
13762 		unsigned int sgl_in = fragsz < tdata->plaintext.len;
13763 		unsigned int sgl_out = (fragsz_oop ? fragsz_oop : fragsz) <
13764 				tdata->plaintext.len;
13765 		/* Raw data path API does not support OOP */
13766 		if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13767 			return TEST_SKIPPED;
13768 		if (sgl_in && !sgl_out) {
13769 			if (!(dev_info.feature_flags &
13770 					RTE_CRYPTODEV_FF_OOP_SGL_IN_LB_OUT))
13771 				return TEST_SKIPPED;
13772 		} else if (!sgl_in && sgl_out) {
13773 			if (!(dev_info.feature_flags &
13774 					RTE_CRYPTODEV_FF_OOP_LB_IN_SGL_OUT))
13775 				return TEST_SKIPPED;
13776 		} else if (sgl_in && sgl_out) {
13777 			if (!(dev_info.feature_flags &
13778 					RTE_CRYPTODEV_FF_OOP_SGL_IN_SGL_OUT))
13779 				return TEST_SKIPPED;
13780 		}
13781 	}
13782 
13783 	if (fragsz > tdata->plaintext.len)
13784 		fragsz = tdata->plaintext.len;
13785 
13786 	uint16_t plaintext_len = fragsz;
13787 	uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
13788 
13789 	if (fragsz_oop > tdata->plaintext.len)
13790 		frag_size_oop = tdata->plaintext.len;
13791 
13792 	int ecx = 0;
13793 	void *digest_mem = NULL;
13794 
13795 	uint32_t prepend_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
13796 
13797 	if (tdata->plaintext.len % fragsz != 0) {
13798 		if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
13799 			return 1;
13800 	}	else {
13801 		if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
13802 			return 1;
13803 	}
13804 
13805 	/*
13806 	 * For out-op-place we need to alloc another mbuf
13807 	 */
13808 	if (oop) {
13809 		ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13810 		rte_pktmbuf_append(ut_params->obuf,
13811 				frag_size_oop + prepend_len);
13812 		buf_oop = ut_params->obuf;
13813 	}
13814 
13815 	/* Create AEAD session */
13816 	retval = create_aead_session(ts_params->valid_devs[0],
13817 			tdata->algo,
13818 			RTE_CRYPTO_AEAD_OP_ENCRYPT,
13819 			tdata->key.data, tdata->key.len,
13820 			tdata->aad.len, tdata->auth_tag.len,
13821 			tdata->iv.len);
13822 	if (retval < 0)
13823 		return retval;
13824 
13825 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13826 
13827 	/* clear mbuf payload */
13828 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
13829 			rte_pktmbuf_tailroom(ut_params->ibuf));
13830 
13831 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13832 			plaintext_len);
13833 
13834 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
13835 
13836 	trn_data += plaintext_len;
13837 
13838 	buf = ut_params->ibuf;
13839 
13840 	/*
13841 	 * Loop until no more fragments
13842 	 */
13843 
13844 	while (trn_data < tdata->plaintext.len) {
13845 		++segs;
13846 		to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
13847 				(tdata->plaintext.len - trn_data) : fragsz;
13848 
13849 		to_trn_tbl[ecx++] = to_trn;
13850 
13851 		buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
13852 		buf = buf->next;
13853 
13854 		memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
13855 				rte_pktmbuf_tailroom(buf));
13856 
13857 		/* OOP */
13858 		if (oop && !fragsz_oop) {
13859 			buf_last_oop = buf_oop->next =
13860 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13861 			buf_oop = buf_oop->next;
13862 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13863 					0, rte_pktmbuf_tailroom(buf_oop));
13864 			rte_pktmbuf_append(buf_oop, to_trn);
13865 		}
13866 
13867 		plaintext = (uint8_t *)rte_pktmbuf_append(buf,
13868 				to_trn);
13869 
13870 		memcpy(plaintext, tdata->plaintext.data + trn_data,
13871 				to_trn);
13872 		trn_data += to_trn;
13873 		if (trn_data  == tdata->plaintext.len) {
13874 			if (oop) {
13875 				if (!fragsz_oop)
13876 					digest_mem = rte_pktmbuf_append(buf_oop,
13877 						tdata->auth_tag.len);
13878 			} else
13879 				digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
13880 					tdata->auth_tag.len);
13881 		}
13882 	}
13883 
13884 	uint64_t digest_phys = 0;
13885 
13886 	ut_params->ibuf->nb_segs = segs;
13887 
13888 	segs = 1;
13889 	if (fragsz_oop && oop) {
13890 		to_trn = 0;
13891 		ecx = 0;
13892 
13893 		if (frag_size_oop == tdata->plaintext.len) {
13894 			digest_mem = rte_pktmbuf_append(ut_params->obuf,
13895 				tdata->auth_tag.len);
13896 
13897 			digest_phys = rte_pktmbuf_iova_offset(
13898 					ut_params->obuf,
13899 					tdata->plaintext.len + prepend_len);
13900 		}
13901 
13902 		trn_data = frag_size_oop;
13903 		while (trn_data < tdata->plaintext.len) {
13904 			++segs;
13905 			to_trn =
13906 				(tdata->plaintext.len - trn_data <
13907 						frag_size_oop) ?
13908 				(tdata->plaintext.len - trn_data) :
13909 						frag_size_oop;
13910 
13911 			to_trn_tbl[ecx++] = to_trn;
13912 
13913 			buf_last_oop = buf_oop->next =
13914 					rte_pktmbuf_alloc(ts_params->mbuf_pool);
13915 			buf_oop = buf_oop->next;
13916 			memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
13917 					0, rte_pktmbuf_tailroom(buf_oop));
13918 			rte_pktmbuf_append(buf_oop, to_trn);
13919 
13920 			trn_data += to_trn;
13921 
13922 			if (trn_data  == tdata->plaintext.len) {
13923 				digest_mem = rte_pktmbuf_append(buf_oop,
13924 					tdata->auth_tag.len);
13925 			}
13926 		}
13927 
13928 		ut_params->obuf->nb_segs = segs;
13929 	}
13930 
13931 	/*
13932 	 * Place digest at the end of the last buffer
13933 	 */
13934 	if (!digest_phys)
13935 		digest_phys = rte_pktmbuf_iova(buf) + to_trn;
13936 	if (oop && buf_last_oop)
13937 		digest_phys = rte_pktmbuf_iova(buf_last_oop) + to_trn;
13938 
13939 	if (!digest_mem && !oop) {
13940 		digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
13941 				+ tdata->auth_tag.len);
13942 		digest_phys = rte_pktmbuf_iova_offset(ut_params->ibuf,
13943 				tdata->plaintext.len);
13944 	}
13945 
13946 	/* Create AEAD operation */
13947 	retval = create_aead_operation_SGL(RTE_CRYPTO_AEAD_OP_ENCRYPT,
13948 			tdata, digest_mem, digest_phys);
13949 
13950 	if (retval < 0)
13951 		return retval;
13952 
13953 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
13954 
13955 	ut_params->op->sym->m_src = ut_params->ibuf;
13956 	if (oop)
13957 		ut_params->op->sym->m_dst = ut_params->obuf;
13958 
13959 	/* Process crypto operation */
13960 	if (oop == IN_PLACE &&
13961 			gbl_action_type == RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO)
13962 		process_cpu_aead_op(ts_params->valid_devs[0], ut_params->op);
13963 	else if (global_api_test_type == CRYPTODEV_RAW_API_TEST)
13964 		process_sym_raw_dp_op(ts_params->valid_devs[0], 0,
13965 				ut_params->op, 0, 0, 0, 0);
13966 	else
13967 		TEST_ASSERT_NOT_NULL(
13968 			process_crypto_request(ts_params->valid_devs[0],
13969 			ut_params->op), "failed to process sym crypto op");
13970 
13971 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
13972 			"crypto op processing failed");
13973 
13974 
13975 	ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
13976 			uint8_t *, prepend_len);
13977 	if (oop) {
13978 		ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
13979 				uint8_t *, prepend_len);
13980 	}
13981 
13982 	if (fragsz_oop)
13983 		fragsz = fragsz_oop;
13984 
13985 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
13986 			ciphertext,
13987 			tdata->ciphertext.data,
13988 			fragsz,
13989 			"Ciphertext data not as expected");
13990 
13991 	buf = ut_params->op->sym->m_src->next;
13992 	if (oop)
13993 		buf = ut_params->op->sym->m_dst->next;
13994 
13995 	unsigned int off = fragsz;
13996 
13997 	ecx = 0;
13998 	while (buf) {
13999 		ciphertext = rte_pktmbuf_mtod(buf,
14000 				uint8_t *);
14001 
14002 		TEST_ASSERT_BUFFERS_ARE_EQUAL(
14003 				ciphertext,
14004 				tdata->ciphertext.data + off,
14005 				to_trn_tbl[ecx],
14006 				"Ciphertext data not as expected");
14007 
14008 		off += to_trn_tbl[ecx++];
14009 		buf = buf->next;
14010 	}
14011 
14012 	auth_tag = digest_mem;
14013 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
14014 			auth_tag,
14015 			tdata->auth_tag.data,
14016 			tdata->auth_tag.len,
14017 			"Generated auth tag not as expected");
14018 
14019 	return 0;
14020 }
14021 
14022 static int
14023 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
14024 {
14025 	return test_authenticated_encryption_SGL(
14026 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
14027 }
14028 
14029 static int
14030 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
14031 {
14032 	return test_authenticated_encryption_SGL(
14033 			&gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
14034 }
14035 
14036 static int
14037 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
14038 {
14039 	return test_authenticated_encryption_SGL(
14040 			&gcm_test_case_8, OUT_OF_PLACE, 400,
14041 			gcm_test_case_8.plaintext.len);
14042 }
14043 
14044 static int
14045 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
14046 {
14047 	/* This test is not for OPENSSL PMD */
14048 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14049 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)))
14050 		return TEST_SKIPPED;
14051 
14052 	return test_authenticated_encryption_SGL(
14053 			&gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
14054 }
14055 
14056 static int
14057 test_authentication_verify_fail_when_data_corrupted(
14058 		struct crypto_testsuite_params *ts_params,
14059 		struct crypto_unittest_params *ut_params,
14060 		const struct test_crypto_vector *reference)
14061 {
14062 	return test_authentication_verify_fail_when_data_corruption(
14063 			ts_params, ut_params, reference, 1);
14064 }
14065 
14066 static int
14067 test_authentication_verify_fail_when_tag_corrupted(
14068 		struct crypto_testsuite_params *ts_params,
14069 		struct crypto_unittest_params *ut_params,
14070 		const struct test_crypto_vector *reference)
14071 {
14072 	return test_authentication_verify_fail_when_data_corruption(
14073 			ts_params, ut_params, reference, 0);
14074 }
14075 
14076 static int
14077 test_authentication_verify_GMAC_fail_when_data_corrupted(
14078 		struct crypto_testsuite_params *ts_params,
14079 		struct crypto_unittest_params *ut_params,
14080 		const struct test_crypto_vector *reference)
14081 {
14082 	return test_authentication_verify_GMAC_fail_when_corruption(
14083 			ts_params, ut_params, reference, 1);
14084 }
14085 
14086 static int
14087 test_authentication_verify_GMAC_fail_when_tag_corrupted(
14088 		struct crypto_testsuite_params *ts_params,
14089 		struct crypto_unittest_params *ut_params,
14090 		const struct test_crypto_vector *reference)
14091 {
14092 	return test_authentication_verify_GMAC_fail_when_corruption(
14093 			ts_params, ut_params, reference, 0);
14094 }
14095 
14096 static int
14097 test_authenticated_decryption_fail_when_data_corrupted(
14098 		struct crypto_testsuite_params *ts_params,
14099 		struct crypto_unittest_params *ut_params,
14100 		const struct test_crypto_vector *reference)
14101 {
14102 	return test_authenticated_decryption_fail_when_corruption(
14103 			ts_params, ut_params, reference, 1);
14104 }
14105 
14106 static int
14107 test_authenticated_decryption_fail_when_tag_corrupted(
14108 		struct crypto_testsuite_params *ts_params,
14109 		struct crypto_unittest_params *ut_params,
14110 		const struct test_crypto_vector *reference)
14111 {
14112 	return test_authenticated_decryption_fail_when_corruption(
14113 			ts_params, ut_params, reference, 0);
14114 }
14115 
14116 static int
14117 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
14118 {
14119 	return test_authentication_verify_fail_when_data_corrupted(
14120 			&testsuite_params, &unittest_params,
14121 			&hmac_sha1_test_crypto_vector);
14122 }
14123 
14124 static int
14125 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
14126 {
14127 	return test_authentication_verify_fail_when_tag_corrupted(
14128 			&testsuite_params, &unittest_params,
14129 			&hmac_sha1_test_crypto_vector);
14130 }
14131 
14132 static int
14133 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
14134 {
14135 	return test_authentication_verify_GMAC_fail_when_data_corrupted(
14136 			&testsuite_params, &unittest_params,
14137 			&aes128_gmac_test_vector);
14138 }
14139 
14140 static int
14141 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
14142 {
14143 	return test_authentication_verify_GMAC_fail_when_tag_corrupted(
14144 			&testsuite_params, &unittest_params,
14145 			&aes128_gmac_test_vector);
14146 }
14147 
14148 static int
14149 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
14150 {
14151 	return test_authenticated_decryption_fail_when_data_corrupted(
14152 			&testsuite_params,
14153 			&unittest_params,
14154 			&aes128cbc_hmac_sha1_test_vector);
14155 }
14156 
14157 static int
14158 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
14159 {
14160 	return test_authenticated_decryption_fail_when_tag_corrupted(
14161 			&testsuite_params,
14162 			&unittest_params,
14163 			&aes128cbc_hmac_sha1_test_vector);
14164 }
14165 
14166 static int
14167 auth_encrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14168 {
14169 	return test_authenticated_encrypt_with_esn(
14170 			&testsuite_params,
14171 			&unittest_params,
14172 			&aes128cbc_hmac_sha1_aad_test_vector);
14173 }
14174 
14175 static int
14176 auth_decrypt_AES128CBC_HMAC_SHA1_esn_check(void)
14177 {
14178 	return test_authenticated_decrypt_with_esn(
14179 			&testsuite_params,
14180 			&unittest_params,
14181 			&aes128cbc_hmac_sha1_aad_test_vector);
14182 }
14183 
14184 static int
14185 test_chacha20_poly1305_encrypt_test_case_rfc8439(void)
14186 {
14187 	return test_authenticated_encryption(&chacha20_poly1305_case_rfc8439);
14188 }
14189 
14190 static int
14191 test_chacha20_poly1305_decrypt_test_case_rfc8439(void)
14192 {
14193 	return test_authenticated_decryption(&chacha20_poly1305_case_rfc8439);
14194 }
14195 
14196 static int
14197 test_chacha20_poly1305_encrypt_SGL_out_of_place(void)
14198 {
14199 	return test_authenticated_encryption_SGL(
14200 		&chacha20_poly1305_case_2, OUT_OF_PLACE, 32,
14201 		chacha20_poly1305_case_2.plaintext.len);
14202 }
14203 
14204 #ifdef RTE_CRYPTO_SCHEDULER
14205 
14206 /* global AESNI worker IDs for the scheduler test */
14207 uint8_t aesni_ids[2];
14208 
14209 static int
14210 scheduler_testsuite_setup(void)
14211 {
14212 	uint32_t i = 0;
14213 	int32_t nb_devs, ret;
14214 	char vdev_args[VDEV_ARGS_SIZE] = {""};
14215 	char temp_str[VDEV_ARGS_SIZE] = {"mode=multi-core,"
14216 		"ordering=enable,name=cryptodev_test_scheduler,corelist="};
14217 	uint16_t worker_core_count = 0;
14218 	uint16_t socket_id = 0;
14219 
14220 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
14221 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD))) {
14222 
14223 		/* Identify the Worker Cores
14224 		 * Use 2 worker cores for the device args
14225 		 */
14226 		RTE_LCORE_FOREACH_WORKER(i) {
14227 			if (worker_core_count > 1)
14228 				break;
14229 			snprintf(vdev_args, sizeof(vdev_args),
14230 					"%s%d", temp_str, i);
14231 			strcpy(temp_str, vdev_args);
14232 			strlcat(temp_str, ";", sizeof(temp_str));
14233 			worker_core_count++;
14234 			socket_id = rte_lcore_to_socket_id(i);
14235 		}
14236 		if (worker_core_count != 2) {
14237 			RTE_LOG(ERR, USER1,
14238 				"Cryptodev scheduler test require at least "
14239 				"two worker cores to run. "
14240 				"Please use the correct coremask.\n");
14241 			return TEST_FAILED;
14242 		}
14243 		strcpy(temp_str, vdev_args);
14244 		snprintf(vdev_args, sizeof(vdev_args), "%s,socket_id=%d",
14245 				temp_str, socket_id);
14246 		RTE_LOG(DEBUG, USER1, "vdev_args: %s\n", vdev_args);
14247 		nb_devs = rte_cryptodev_device_count_by_driver(
14248 				rte_cryptodev_driver_id_get(
14249 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD)));
14250 		if (nb_devs < 1) {
14251 			ret = rte_vdev_init(
14252 				RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
14253 					vdev_args);
14254 			TEST_ASSERT(ret == 0,
14255 				"Failed to create instance %u of pmd : %s",
14256 				i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
14257 		}
14258 	}
14259 	return testsuite_setup();
14260 }
14261 
14262 static int
14263 test_scheduler_attach_worker_op(void)
14264 {
14265 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14266 	uint8_t sched_id = ts_params->valid_devs[0];
14267 	uint32_t i, nb_devs_attached = 0;
14268 	int ret;
14269 	char vdev_name[32];
14270 	unsigned int count = rte_cryptodev_count();
14271 
14272 	/* create 2 AESNI_MB vdevs on top of existing devices */
14273 	for (i = count; i < count + 2; i++) {
14274 		snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
14275 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
14276 				i);
14277 		ret = rte_vdev_init(vdev_name, NULL);
14278 
14279 		TEST_ASSERT(ret == 0,
14280 			"Failed to create instance %u of"
14281 			" pmd : %s",
14282 			i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14283 
14284 		if (ret < 0) {
14285 			RTE_LOG(ERR, USER1,
14286 				"Failed to create 2 AESNI MB PMDs.\n");
14287 			return TEST_SKIPPED;
14288 		}
14289 	}
14290 
14291 	/* attach 2 AESNI_MB cdevs */
14292 	for (i = count; i < count + 2; i++) {
14293 		struct rte_cryptodev_info info;
14294 		unsigned int session_size;
14295 
14296 		rte_cryptodev_info_get(i, &info);
14297 		if (info.driver_id != rte_cryptodev_driver_id_get(
14298 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)))
14299 			continue;
14300 
14301 		session_size = rte_cryptodev_sym_get_private_session_size(i);
14302 		/*
14303 		 * Create the session mempool again, since now there are new devices
14304 		 * to use the mempool.
14305 		 */
14306 		if (ts_params->session_mpool) {
14307 			rte_mempool_free(ts_params->session_mpool);
14308 			ts_params->session_mpool = NULL;
14309 		}
14310 		if (ts_params->session_priv_mpool) {
14311 			rte_mempool_free(ts_params->session_priv_mpool);
14312 			ts_params->session_priv_mpool = NULL;
14313 		}
14314 
14315 		if (info.sym.max_nb_sessions != 0 &&
14316 				info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
14317 			RTE_LOG(ERR, USER1,
14318 					"Device does not support "
14319 					"at least %u sessions\n",
14320 					MAX_NB_SESSIONS);
14321 			return TEST_FAILED;
14322 		}
14323 		/*
14324 		 * Create mempool with maximum number of sessions,
14325 		 * to include the session headers
14326 		 */
14327 		if (ts_params->session_mpool == NULL) {
14328 			ts_params->session_mpool =
14329 				rte_cryptodev_sym_session_pool_create(
14330 						"test_sess_mp",
14331 						MAX_NB_SESSIONS, 0, 0, 0,
14332 						SOCKET_ID_ANY);
14333 			TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
14334 					"session mempool allocation failed");
14335 		}
14336 
14337 		/*
14338 		 * Create mempool with maximum number of sessions,
14339 		 * to include device specific session private data
14340 		 */
14341 		if (ts_params->session_priv_mpool == NULL) {
14342 			ts_params->session_priv_mpool = rte_mempool_create(
14343 					"test_sess_mp_priv",
14344 					MAX_NB_SESSIONS,
14345 					session_size,
14346 					0, 0, NULL, NULL, NULL,
14347 					NULL, SOCKET_ID_ANY,
14348 					0);
14349 
14350 			TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
14351 					"session mempool allocation failed");
14352 		}
14353 
14354 		ts_params->qp_conf.mp_session = ts_params->session_mpool;
14355 		ts_params->qp_conf.mp_session_private =
14356 				ts_params->session_priv_mpool;
14357 
14358 		ret = rte_cryptodev_scheduler_worker_attach(sched_id,
14359 				(uint8_t)i);
14360 
14361 		TEST_ASSERT(ret == 0,
14362 			"Failed to attach device %u of pmd : %s", i,
14363 			RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
14364 
14365 		aesni_ids[nb_devs_attached] = (uint8_t)i;
14366 
14367 		nb_devs_attached++;
14368 	}
14369 
14370 	return 0;
14371 }
14372 
14373 static int
14374 test_scheduler_detach_worker_op(void)
14375 {
14376 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14377 	uint8_t sched_id = ts_params->valid_devs[0];
14378 	uint32_t i;
14379 	int ret;
14380 
14381 	for (i = 0; i < 2; i++) {
14382 		ret = rte_cryptodev_scheduler_worker_detach(sched_id,
14383 				aesni_ids[i]);
14384 		TEST_ASSERT(ret == 0,
14385 			"Failed to detach device %u", aesni_ids[i]);
14386 	}
14387 
14388 	return 0;
14389 }
14390 
14391 static int
14392 test_scheduler_mode_op(enum rte_cryptodev_scheduler_mode scheduler_mode)
14393 {
14394 	struct crypto_testsuite_params *ts_params = &testsuite_params;
14395 	uint8_t sched_id = ts_params->valid_devs[0];
14396 	/* set mode */
14397 	return rte_cryptodev_scheduler_mode_set(sched_id,
14398 		scheduler_mode);
14399 }
14400 
14401 static int
14402 test_scheduler_mode_roundrobin_op(void)
14403 {
14404 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) ==
14405 			0, "Failed to set roundrobin mode");
14406 	return 0;
14407 
14408 }
14409 
14410 static int
14411 test_scheduler_mode_multicore_op(void)
14412 {
14413 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) ==
14414 			0, "Failed to set multicore mode");
14415 
14416 	return 0;
14417 }
14418 
14419 static int
14420 test_scheduler_mode_failover_op(void)
14421 {
14422 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) ==
14423 			0, "Failed to set failover mode");
14424 
14425 	return 0;
14426 }
14427 
14428 static int
14429 test_scheduler_mode_pkt_size_distr_op(void)
14430 {
14431 	TEST_ASSERT(test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) ==
14432 			0, "Failed to set pktsize mode");
14433 
14434 	return 0;
14435 }
14436 
14437 static int
14438 scheduler_multicore_testsuite_setup(void)
14439 {
14440 	if (test_scheduler_attach_worker_op() < 0)
14441 		return TEST_SKIPPED;
14442 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_MULTICORE) < 0)
14443 		return TEST_SKIPPED;
14444 	return 0;
14445 }
14446 
14447 static int
14448 scheduler_roundrobin_testsuite_setup(void)
14449 {
14450 	if (test_scheduler_attach_worker_op() < 0)
14451 		return TEST_SKIPPED;
14452 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_ROUNDROBIN) < 0)
14453 		return TEST_SKIPPED;
14454 	return 0;
14455 }
14456 
14457 static int
14458 scheduler_failover_testsuite_setup(void)
14459 {
14460 	if (test_scheduler_attach_worker_op() < 0)
14461 		return TEST_SKIPPED;
14462 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_FAILOVER) < 0)
14463 		return TEST_SKIPPED;
14464 	return 0;
14465 }
14466 
14467 static int
14468 scheduler_pkt_size_distr_testsuite_setup(void)
14469 {
14470 	if (test_scheduler_attach_worker_op() < 0)
14471 		return TEST_SKIPPED;
14472 	if (test_scheduler_mode_op(CDEV_SCHED_MODE_PKT_SIZE_DISTR) < 0)
14473 		return TEST_SKIPPED;
14474 	return 0;
14475 }
14476 
14477 static void
14478 scheduler_mode_testsuite_teardown(void)
14479 {
14480 	test_scheduler_detach_worker_op();
14481 }
14482 
14483 #endif /* RTE_CRYPTO_SCHEDULER */
14484 
14485 static struct unit_test_suite end_testsuite = {
14486 	.suite_name = NULL,
14487 	.setup = NULL,
14488 	.teardown = NULL,
14489 	.unit_test_suites = NULL
14490 };
14491 
14492 #ifdef RTE_LIB_SECURITY
14493 static struct unit_test_suite ipsec_proto_testsuite  = {
14494 	.suite_name = "IPsec Proto Unit Test Suite",
14495 	.setup = ipsec_proto_testsuite_setup,
14496 	.unit_test_cases = {
14497 		TEST_CASE_NAMED_WITH_DATA(
14498 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14499 			ut_setup_security, ut_teardown,
14500 			test_ipsec_proto_known_vec, &pkt_aes_128_gcm),
14501 		TEST_CASE_NAMED_WITH_DATA(
14502 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14503 			ut_setup_security, ut_teardown,
14504 			test_ipsec_proto_known_vec, &pkt_aes_192_gcm),
14505 		TEST_CASE_NAMED_WITH_DATA(
14506 			"Outbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14507 			ut_setup_security, ut_teardown,
14508 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm),
14509 		TEST_CASE_NAMED_WITH_DATA(
14510 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
14511 			ut_setup_security, ut_teardown,
14512 			test_ipsec_proto_known_vec,
14513 			&pkt_aes_128_cbc_hmac_sha256),
14514 		TEST_CASE_NAMED_WITH_DATA(
14515 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
14516 			ut_setup_security, ut_teardown,
14517 			test_ipsec_proto_known_vec,
14518 			&pkt_aes_128_cbc_hmac_sha384),
14519 		TEST_CASE_NAMED_WITH_DATA(
14520 			"Outbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
14521 			ut_setup_security, ut_teardown,
14522 			test_ipsec_proto_known_vec,
14523 			&pkt_aes_128_cbc_hmac_sha512),
14524 		TEST_CASE_NAMED_WITH_DATA(
14525 			"Outbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
14526 			ut_setup_security, ut_teardown,
14527 			test_ipsec_proto_known_vec, &pkt_aes_256_gcm_v6),
14528 		TEST_CASE_NAMED_WITH_DATA(
14529 			"Outbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
14530 			ut_setup_security, ut_teardown,
14531 			test_ipsec_proto_known_vec,
14532 			&pkt_aes_128_cbc_hmac_sha256_v6),
14533 		TEST_CASE_NAMED_WITH_DATA(
14534 			"Outbound fragmented packet",
14535 			ut_setup_security, ut_teardown,
14536 			test_ipsec_proto_known_vec_fragmented,
14537 			&pkt_aes_128_gcm_frag),
14538 		TEST_CASE_NAMED_WITH_DATA(
14539 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 128)",
14540 			ut_setup_security, ut_teardown,
14541 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_gcm),
14542 		TEST_CASE_NAMED_WITH_DATA(
14543 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 192)",
14544 			ut_setup_security, ut_teardown,
14545 			test_ipsec_proto_known_vec_inb, &pkt_aes_192_gcm),
14546 		TEST_CASE_NAMED_WITH_DATA(
14547 			"Inbound known vector (ESP tunnel mode IPv4 AES-GCM 256)",
14548 			ut_setup_security, ut_teardown,
14549 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm),
14550 		TEST_CASE_NAMED_WITH_DATA(
14551 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128)",
14552 			ut_setup_security, ut_teardown,
14553 			test_ipsec_proto_known_vec_inb, &pkt_aes_128_cbc_null),
14554 		TEST_CASE_NAMED_WITH_DATA(
14555 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA256 [16B ICV])",
14556 			ut_setup_security, ut_teardown,
14557 			test_ipsec_proto_known_vec_inb,
14558 			&pkt_aes_128_cbc_hmac_sha256),
14559 		TEST_CASE_NAMED_WITH_DATA(
14560 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA384 [24B ICV])",
14561 			ut_setup_security, ut_teardown,
14562 			test_ipsec_proto_known_vec_inb,
14563 			&pkt_aes_128_cbc_hmac_sha384),
14564 		TEST_CASE_NAMED_WITH_DATA(
14565 			"Inbound known vector (ESP tunnel mode IPv4 AES-CBC 128 HMAC-SHA512 [32B ICV])",
14566 			ut_setup_security, ut_teardown,
14567 			test_ipsec_proto_known_vec_inb,
14568 			&pkt_aes_128_cbc_hmac_sha512),
14569 		TEST_CASE_NAMED_WITH_DATA(
14570 			"Inbound known vector (ESP tunnel mode IPv6 AES-GCM 128)",
14571 			ut_setup_security, ut_teardown,
14572 			test_ipsec_proto_known_vec_inb, &pkt_aes_256_gcm_v6),
14573 		TEST_CASE_NAMED_WITH_DATA(
14574 			"Inbound known vector (ESP tunnel mode IPv6 AES-CBC 128 HMAC-SHA256 [16B ICV])",
14575 			ut_setup_security, ut_teardown,
14576 			test_ipsec_proto_known_vec_inb,
14577 			&pkt_aes_128_cbc_hmac_sha256_v6),
14578 		TEST_CASE_NAMED_ST(
14579 			"Combined test alg list",
14580 			ut_setup_security, ut_teardown,
14581 			test_ipsec_proto_display_list),
14582 		TEST_CASE_NAMED_ST(
14583 			"IV generation",
14584 			ut_setup_security, ut_teardown,
14585 			test_ipsec_proto_iv_gen),
14586 		TEST_CASE_NAMED_ST(
14587 			"UDP encapsulation",
14588 			ut_setup_security, ut_teardown,
14589 			test_ipsec_proto_udp_encap),
14590 		TEST_CASE_NAMED_ST(
14591 			"UDP encapsulation ports verification test",
14592 			ut_setup_security, ut_teardown,
14593 			test_ipsec_proto_udp_ports_verify),
14594 		TEST_CASE_NAMED_ST(
14595 			"SA expiry packets soft",
14596 			ut_setup_security, ut_teardown,
14597 			test_ipsec_proto_sa_exp_pkts_soft),
14598 		TEST_CASE_NAMED_ST(
14599 			"SA expiry packets hard",
14600 			ut_setup_security, ut_teardown,
14601 			test_ipsec_proto_sa_exp_pkts_hard),
14602 		TEST_CASE_NAMED_ST(
14603 			"Negative test: ICV corruption",
14604 			ut_setup_security, ut_teardown,
14605 			test_ipsec_proto_err_icv_corrupt),
14606 		TEST_CASE_NAMED_ST(
14607 			"Tunnel dst addr verification",
14608 			ut_setup_security, ut_teardown,
14609 			test_ipsec_proto_tunnel_dst_addr_verify),
14610 		TEST_CASE_NAMED_ST(
14611 			"Tunnel src and dst addr verification",
14612 			ut_setup_security, ut_teardown,
14613 			test_ipsec_proto_tunnel_src_dst_addr_verify),
14614 		TEST_CASE_NAMED_ST(
14615 			"Inner IP checksum",
14616 			ut_setup_security, ut_teardown,
14617 			test_ipsec_proto_inner_ip_csum),
14618 		TEST_CASE_NAMED_ST(
14619 			"Inner L4 checksum",
14620 			ut_setup_security, ut_teardown,
14621 			test_ipsec_proto_inner_l4_csum),
14622 		TEST_CASE_NAMED_ST(
14623 			"Tunnel IPv4 in IPv4",
14624 			ut_setup_security, ut_teardown,
14625 			test_ipsec_proto_tunnel_v4_in_v4),
14626 		TEST_CASE_NAMED_ST(
14627 			"Tunnel IPv6 in IPv6",
14628 			ut_setup_security, ut_teardown,
14629 			test_ipsec_proto_tunnel_v6_in_v6),
14630 		TEST_CASE_NAMED_ST(
14631 			"Tunnel IPv4 in IPv6",
14632 			ut_setup_security, ut_teardown,
14633 			test_ipsec_proto_tunnel_v4_in_v6),
14634 		TEST_CASE_NAMED_ST(
14635 			"Tunnel IPv6 in IPv4",
14636 			ut_setup_security, ut_teardown,
14637 			test_ipsec_proto_tunnel_v6_in_v4),
14638 		TEST_CASES_END() /**< NULL terminate unit test array */
14639 	}
14640 };
14641 
14642 static struct unit_test_suite pdcp_proto_testsuite  = {
14643 	.suite_name = "PDCP Proto Unit Test Suite",
14644 	.setup = pdcp_proto_testsuite_setup,
14645 	.unit_test_cases = {
14646 		TEST_CASE_ST(ut_setup_security, ut_teardown,
14647 			test_PDCP_PROTO_all),
14648 		TEST_CASES_END() /**< NULL terminate unit test array */
14649 	}
14650 };
14651 
14652 #define ADD_UPLINK_TESTCASE(data)						\
14653 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_uplink, ut_setup_security,	\
14654 	ut_teardown, test_docsis_proto_uplink, (const void *) &data),		\
14655 
14656 #define ADD_DOWNLINK_TESTCASE(data)						\
14657 	TEST_CASE_NAMED_WITH_DATA(data.test_descr_downlink, ut_setup_security,	\
14658 	ut_teardown, test_docsis_proto_downlink, (const void *) &data),		\
14659 
14660 static struct unit_test_suite docsis_proto_testsuite  = {
14661 	.suite_name = "DOCSIS Proto Unit Test Suite",
14662 	.setup = docsis_proto_testsuite_setup,
14663 	.unit_test_cases = {
14664 		/* Uplink */
14665 		ADD_UPLINK_TESTCASE(docsis_test_case_1)
14666 		ADD_UPLINK_TESTCASE(docsis_test_case_2)
14667 		ADD_UPLINK_TESTCASE(docsis_test_case_3)
14668 		ADD_UPLINK_TESTCASE(docsis_test_case_4)
14669 		ADD_UPLINK_TESTCASE(docsis_test_case_5)
14670 		ADD_UPLINK_TESTCASE(docsis_test_case_6)
14671 		ADD_UPLINK_TESTCASE(docsis_test_case_7)
14672 		ADD_UPLINK_TESTCASE(docsis_test_case_8)
14673 		ADD_UPLINK_TESTCASE(docsis_test_case_9)
14674 		ADD_UPLINK_TESTCASE(docsis_test_case_10)
14675 		ADD_UPLINK_TESTCASE(docsis_test_case_11)
14676 		ADD_UPLINK_TESTCASE(docsis_test_case_12)
14677 		ADD_UPLINK_TESTCASE(docsis_test_case_13)
14678 		ADD_UPLINK_TESTCASE(docsis_test_case_14)
14679 		ADD_UPLINK_TESTCASE(docsis_test_case_15)
14680 		ADD_UPLINK_TESTCASE(docsis_test_case_16)
14681 		ADD_UPLINK_TESTCASE(docsis_test_case_17)
14682 		ADD_UPLINK_TESTCASE(docsis_test_case_18)
14683 		ADD_UPLINK_TESTCASE(docsis_test_case_19)
14684 		ADD_UPLINK_TESTCASE(docsis_test_case_20)
14685 		ADD_UPLINK_TESTCASE(docsis_test_case_21)
14686 		ADD_UPLINK_TESTCASE(docsis_test_case_22)
14687 		ADD_UPLINK_TESTCASE(docsis_test_case_23)
14688 		ADD_UPLINK_TESTCASE(docsis_test_case_24)
14689 		ADD_UPLINK_TESTCASE(docsis_test_case_25)
14690 		ADD_UPLINK_TESTCASE(docsis_test_case_26)
14691 		/* Downlink */
14692 		ADD_DOWNLINK_TESTCASE(docsis_test_case_1)
14693 		ADD_DOWNLINK_TESTCASE(docsis_test_case_2)
14694 		ADD_DOWNLINK_TESTCASE(docsis_test_case_3)
14695 		ADD_DOWNLINK_TESTCASE(docsis_test_case_4)
14696 		ADD_DOWNLINK_TESTCASE(docsis_test_case_5)
14697 		ADD_DOWNLINK_TESTCASE(docsis_test_case_6)
14698 		ADD_DOWNLINK_TESTCASE(docsis_test_case_7)
14699 		ADD_DOWNLINK_TESTCASE(docsis_test_case_8)
14700 		ADD_DOWNLINK_TESTCASE(docsis_test_case_9)
14701 		ADD_DOWNLINK_TESTCASE(docsis_test_case_10)
14702 		ADD_DOWNLINK_TESTCASE(docsis_test_case_11)
14703 		ADD_DOWNLINK_TESTCASE(docsis_test_case_12)
14704 		ADD_DOWNLINK_TESTCASE(docsis_test_case_13)
14705 		ADD_DOWNLINK_TESTCASE(docsis_test_case_14)
14706 		ADD_DOWNLINK_TESTCASE(docsis_test_case_15)
14707 		ADD_DOWNLINK_TESTCASE(docsis_test_case_16)
14708 		ADD_DOWNLINK_TESTCASE(docsis_test_case_17)
14709 		ADD_DOWNLINK_TESTCASE(docsis_test_case_18)
14710 		ADD_DOWNLINK_TESTCASE(docsis_test_case_19)
14711 		ADD_DOWNLINK_TESTCASE(docsis_test_case_20)
14712 		ADD_DOWNLINK_TESTCASE(docsis_test_case_21)
14713 		ADD_DOWNLINK_TESTCASE(docsis_test_case_22)
14714 		ADD_DOWNLINK_TESTCASE(docsis_test_case_23)
14715 		ADD_DOWNLINK_TESTCASE(docsis_test_case_24)
14716 		ADD_DOWNLINK_TESTCASE(docsis_test_case_25)
14717 		ADD_DOWNLINK_TESTCASE(docsis_test_case_26)
14718 		TEST_CASES_END() /**< NULL terminate unit test array */
14719 	}
14720 };
14721 #endif
14722 
14723 static struct unit_test_suite cryptodev_gen_testsuite  = {
14724 	.suite_name = "Crypto General Unit Test Suite",
14725 	.setup = crypto_gen_testsuite_setup,
14726 	.unit_test_cases = {
14727 		TEST_CASE_ST(ut_setup, ut_teardown,
14728 				test_device_configure_invalid_dev_id),
14729 		TEST_CASE_ST(ut_setup, ut_teardown,
14730 				test_queue_pair_descriptor_setup),
14731 		TEST_CASE_ST(ut_setup, ut_teardown,
14732 				test_device_configure_invalid_queue_pair_ids),
14733 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
14734 		TEST_CASE_ST(ut_setup, ut_teardown, test_enq_callback_setup),
14735 		TEST_CASE_ST(ut_setup, ut_teardown, test_deq_callback_setup),
14736 		TEST_CASES_END() /**< NULL terminate unit test array */
14737 	}
14738 };
14739 
14740 static struct unit_test_suite cryptodev_negative_hmac_sha1_testsuite = {
14741 	.suite_name = "Negative HMAC SHA1 Unit Test Suite",
14742 	.setup = negative_hmac_sha1_testsuite_setup,
14743 	.unit_test_cases = {
14744 		/** Negative tests */
14745 		TEST_CASE_ST(ut_setup, ut_teardown,
14746 			authentication_verify_HMAC_SHA1_fail_data_corrupt),
14747 		TEST_CASE_ST(ut_setup, ut_teardown,
14748 			authentication_verify_HMAC_SHA1_fail_tag_corrupt),
14749 		TEST_CASE_ST(ut_setup, ut_teardown,
14750 			auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
14751 		TEST_CASE_ST(ut_setup, ut_teardown,
14752 			auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
14753 
14754 		TEST_CASES_END() /**< NULL terminate unit test array */
14755 	}
14756 };
14757 
14758 static struct unit_test_suite cryptodev_multi_session_testsuite = {
14759 	.suite_name = "Multi Session Unit Test Suite",
14760 	.setup = multi_session_testsuite_setup,
14761 	.unit_test_cases = {
14762 		TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
14763 		TEST_CASE_ST(ut_setup, ut_teardown,
14764 				test_multi_session_random_usage),
14765 
14766 		TEST_CASES_END() /**< NULL terminate unit test array */
14767 	}
14768 };
14769 
14770 static struct unit_test_suite cryptodev_null_testsuite  = {
14771 	.suite_name = "NULL Test Suite",
14772 	.setup = null_testsuite_setup,
14773 	.unit_test_cases = {
14774 		TEST_CASE_ST(ut_setup, ut_teardown,
14775 			test_null_invalid_operation),
14776 		TEST_CASE_ST(ut_setup, ut_teardown, test_null_burst_operation),
14777 		TEST_CASES_END()
14778 	}
14779 };
14780 
14781 static struct unit_test_suite cryptodev_aes_ccm_auth_testsuite  = {
14782 	.suite_name = "AES CCM Authenticated Test Suite",
14783 	.setup = aes_ccm_auth_testsuite_setup,
14784 	.unit_test_cases = {
14785 		/** AES CCM Authenticated Encryption 128 bits key*/
14786 		TEST_CASE_ST(ut_setup, ut_teardown,
14787 			test_AES_CCM_authenticated_encryption_test_case_128_1),
14788 		TEST_CASE_ST(ut_setup, ut_teardown,
14789 			test_AES_CCM_authenticated_encryption_test_case_128_2),
14790 		TEST_CASE_ST(ut_setup, ut_teardown,
14791 			test_AES_CCM_authenticated_encryption_test_case_128_3),
14792 
14793 		/** AES CCM Authenticated Decryption 128 bits key*/
14794 		TEST_CASE_ST(ut_setup, ut_teardown,
14795 			test_AES_CCM_authenticated_decryption_test_case_128_1),
14796 		TEST_CASE_ST(ut_setup, ut_teardown,
14797 			test_AES_CCM_authenticated_decryption_test_case_128_2),
14798 		TEST_CASE_ST(ut_setup, ut_teardown,
14799 			test_AES_CCM_authenticated_decryption_test_case_128_3),
14800 
14801 		/** AES CCM Authenticated Encryption 192 bits key */
14802 		TEST_CASE_ST(ut_setup, ut_teardown,
14803 			test_AES_CCM_authenticated_encryption_test_case_192_1),
14804 		TEST_CASE_ST(ut_setup, ut_teardown,
14805 			test_AES_CCM_authenticated_encryption_test_case_192_2),
14806 		TEST_CASE_ST(ut_setup, ut_teardown,
14807 			test_AES_CCM_authenticated_encryption_test_case_192_3),
14808 
14809 		/** AES CCM Authenticated Decryption 192 bits key*/
14810 		TEST_CASE_ST(ut_setup, ut_teardown,
14811 			test_AES_CCM_authenticated_decryption_test_case_192_1),
14812 		TEST_CASE_ST(ut_setup, ut_teardown,
14813 			test_AES_CCM_authenticated_decryption_test_case_192_2),
14814 		TEST_CASE_ST(ut_setup, ut_teardown,
14815 			test_AES_CCM_authenticated_decryption_test_case_192_3),
14816 
14817 		/** AES CCM Authenticated Encryption 256 bits key */
14818 		TEST_CASE_ST(ut_setup, ut_teardown,
14819 			test_AES_CCM_authenticated_encryption_test_case_256_1),
14820 		TEST_CASE_ST(ut_setup, ut_teardown,
14821 			test_AES_CCM_authenticated_encryption_test_case_256_2),
14822 		TEST_CASE_ST(ut_setup, ut_teardown,
14823 			test_AES_CCM_authenticated_encryption_test_case_256_3),
14824 
14825 		/** AES CCM Authenticated Decryption 256 bits key*/
14826 		TEST_CASE_ST(ut_setup, ut_teardown,
14827 			test_AES_CCM_authenticated_decryption_test_case_256_1),
14828 		TEST_CASE_ST(ut_setup, ut_teardown,
14829 			test_AES_CCM_authenticated_decryption_test_case_256_2),
14830 		TEST_CASE_ST(ut_setup, ut_teardown,
14831 			test_AES_CCM_authenticated_decryption_test_case_256_3),
14832 		TEST_CASES_END()
14833 	}
14834 };
14835 
14836 static struct unit_test_suite cryptodev_aes_gcm_auth_testsuite  = {
14837 	.suite_name = "AES GCM Authenticated Test Suite",
14838 	.setup = aes_gcm_auth_testsuite_setup,
14839 	.unit_test_cases = {
14840 		/** AES GCM Authenticated Encryption */
14841 		TEST_CASE_ST(ut_setup, ut_teardown,
14842 			test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
14843 		TEST_CASE_ST(ut_setup, ut_teardown,
14844 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
14845 		TEST_CASE_ST(ut_setup, ut_teardown,
14846 			test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
14847 		TEST_CASE_ST(ut_setup, ut_teardown,
14848 			test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
14849 		TEST_CASE_ST(ut_setup, ut_teardown,
14850 			test_AES_GCM_authenticated_encryption_test_case_1),
14851 		TEST_CASE_ST(ut_setup, ut_teardown,
14852 			test_AES_GCM_authenticated_encryption_test_case_2),
14853 		TEST_CASE_ST(ut_setup, ut_teardown,
14854 			test_AES_GCM_authenticated_encryption_test_case_3),
14855 		TEST_CASE_ST(ut_setup, ut_teardown,
14856 			test_AES_GCM_authenticated_encryption_test_case_4),
14857 		TEST_CASE_ST(ut_setup, ut_teardown,
14858 			test_AES_GCM_authenticated_encryption_test_case_5),
14859 		TEST_CASE_ST(ut_setup, ut_teardown,
14860 			test_AES_GCM_authenticated_encryption_test_case_6),
14861 		TEST_CASE_ST(ut_setup, ut_teardown,
14862 			test_AES_GCM_authenticated_encryption_test_case_7),
14863 		TEST_CASE_ST(ut_setup, ut_teardown,
14864 			test_AES_GCM_authenticated_encryption_test_case_8),
14865 		TEST_CASE_ST(ut_setup, ut_teardown,
14866 			test_AES_GCM_J0_authenticated_encryption_test_case_1),
14867 
14868 		/** AES GCM Authenticated Decryption */
14869 		TEST_CASE_ST(ut_setup, ut_teardown,
14870 			test_AES_GCM_authenticated_decryption_test_case_1),
14871 		TEST_CASE_ST(ut_setup, ut_teardown,
14872 			test_AES_GCM_authenticated_decryption_test_case_2),
14873 		TEST_CASE_ST(ut_setup, ut_teardown,
14874 			test_AES_GCM_authenticated_decryption_test_case_3),
14875 		TEST_CASE_ST(ut_setup, ut_teardown,
14876 			test_AES_GCM_authenticated_decryption_test_case_4),
14877 		TEST_CASE_ST(ut_setup, ut_teardown,
14878 			test_AES_GCM_authenticated_decryption_test_case_5),
14879 		TEST_CASE_ST(ut_setup, ut_teardown,
14880 			test_AES_GCM_authenticated_decryption_test_case_6),
14881 		TEST_CASE_ST(ut_setup, ut_teardown,
14882 			test_AES_GCM_authenticated_decryption_test_case_7),
14883 		TEST_CASE_ST(ut_setup, ut_teardown,
14884 			test_AES_GCM_authenticated_decryption_test_case_8),
14885 		TEST_CASE_ST(ut_setup, ut_teardown,
14886 			test_AES_GCM_J0_authenticated_decryption_test_case_1),
14887 
14888 		/** AES GCM Authenticated Encryption 192 bits key */
14889 		TEST_CASE_ST(ut_setup, ut_teardown,
14890 			test_AES_GCM_auth_encryption_test_case_192_1),
14891 		TEST_CASE_ST(ut_setup, ut_teardown,
14892 			test_AES_GCM_auth_encryption_test_case_192_2),
14893 		TEST_CASE_ST(ut_setup, ut_teardown,
14894 			test_AES_GCM_auth_encryption_test_case_192_3),
14895 		TEST_CASE_ST(ut_setup, ut_teardown,
14896 			test_AES_GCM_auth_encryption_test_case_192_4),
14897 		TEST_CASE_ST(ut_setup, ut_teardown,
14898 			test_AES_GCM_auth_encryption_test_case_192_5),
14899 		TEST_CASE_ST(ut_setup, ut_teardown,
14900 			test_AES_GCM_auth_encryption_test_case_192_6),
14901 		TEST_CASE_ST(ut_setup, ut_teardown,
14902 			test_AES_GCM_auth_encryption_test_case_192_7),
14903 
14904 		/** AES GCM Authenticated Decryption 192 bits key */
14905 		TEST_CASE_ST(ut_setup, ut_teardown,
14906 			test_AES_GCM_auth_decryption_test_case_192_1),
14907 		TEST_CASE_ST(ut_setup, ut_teardown,
14908 			test_AES_GCM_auth_decryption_test_case_192_2),
14909 		TEST_CASE_ST(ut_setup, ut_teardown,
14910 			test_AES_GCM_auth_decryption_test_case_192_3),
14911 		TEST_CASE_ST(ut_setup, ut_teardown,
14912 			test_AES_GCM_auth_decryption_test_case_192_4),
14913 		TEST_CASE_ST(ut_setup, ut_teardown,
14914 			test_AES_GCM_auth_decryption_test_case_192_5),
14915 		TEST_CASE_ST(ut_setup, ut_teardown,
14916 			test_AES_GCM_auth_decryption_test_case_192_6),
14917 		TEST_CASE_ST(ut_setup, ut_teardown,
14918 			test_AES_GCM_auth_decryption_test_case_192_7),
14919 
14920 		/** AES GCM Authenticated Encryption 256 bits key */
14921 		TEST_CASE_ST(ut_setup, ut_teardown,
14922 			test_AES_GCM_auth_encryption_test_case_256_1),
14923 		TEST_CASE_ST(ut_setup, ut_teardown,
14924 			test_AES_GCM_auth_encryption_test_case_256_2),
14925 		TEST_CASE_ST(ut_setup, ut_teardown,
14926 			test_AES_GCM_auth_encryption_test_case_256_3),
14927 		TEST_CASE_ST(ut_setup, ut_teardown,
14928 			test_AES_GCM_auth_encryption_test_case_256_4),
14929 		TEST_CASE_ST(ut_setup, ut_teardown,
14930 			test_AES_GCM_auth_encryption_test_case_256_5),
14931 		TEST_CASE_ST(ut_setup, ut_teardown,
14932 			test_AES_GCM_auth_encryption_test_case_256_6),
14933 		TEST_CASE_ST(ut_setup, ut_teardown,
14934 			test_AES_GCM_auth_encryption_test_case_256_7),
14935 
14936 		/** AES GCM Authenticated Decryption 256 bits key */
14937 		TEST_CASE_ST(ut_setup, ut_teardown,
14938 			test_AES_GCM_auth_decryption_test_case_256_1),
14939 		TEST_CASE_ST(ut_setup, ut_teardown,
14940 			test_AES_GCM_auth_decryption_test_case_256_2),
14941 		TEST_CASE_ST(ut_setup, ut_teardown,
14942 			test_AES_GCM_auth_decryption_test_case_256_3),
14943 		TEST_CASE_ST(ut_setup, ut_teardown,
14944 			test_AES_GCM_auth_decryption_test_case_256_4),
14945 		TEST_CASE_ST(ut_setup, ut_teardown,
14946 			test_AES_GCM_auth_decryption_test_case_256_5),
14947 		TEST_CASE_ST(ut_setup, ut_teardown,
14948 			test_AES_GCM_auth_decryption_test_case_256_6),
14949 		TEST_CASE_ST(ut_setup, ut_teardown,
14950 			test_AES_GCM_auth_decryption_test_case_256_7),
14951 
14952 		/** AES GCM Authenticated Encryption big aad size */
14953 		TEST_CASE_ST(ut_setup, ut_teardown,
14954 			test_AES_GCM_auth_encryption_test_case_aad_1),
14955 		TEST_CASE_ST(ut_setup, ut_teardown,
14956 			test_AES_GCM_auth_encryption_test_case_aad_2),
14957 
14958 		/** AES GCM Authenticated Decryption big aad size */
14959 		TEST_CASE_ST(ut_setup, ut_teardown,
14960 			test_AES_GCM_auth_decryption_test_case_aad_1),
14961 		TEST_CASE_ST(ut_setup, ut_teardown,
14962 			test_AES_GCM_auth_decryption_test_case_aad_2),
14963 
14964 		/** Out of place tests */
14965 		TEST_CASE_ST(ut_setup, ut_teardown,
14966 			test_AES_GCM_authenticated_encryption_oop_test_case_1),
14967 		TEST_CASE_ST(ut_setup, ut_teardown,
14968 			test_AES_GCM_authenticated_decryption_oop_test_case_1),
14969 
14970 		/** Session-less tests */
14971 		TEST_CASE_ST(ut_setup, ut_teardown,
14972 			test_AES_GCM_authenticated_encryption_sessionless_test_case_1),
14973 		TEST_CASE_ST(ut_setup, ut_teardown,
14974 			test_AES_GCM_authenticated_decryption_sessionless_test_case_1),
14975 
14976 		TEST_CASES_END()
14977 	}
14978 };
14979 
14980 static struct unit_test_suite cryptodev_aes_gmac_auth_testsuite  = {
14981 	.suite_name = "AES GMAC Authentication Test Suite",
14982 	.setup = aes_gmac_auth_testsuite_setup,
14983 	.unit_test_cases = {
14984 		TEST_CASE_ST(ut_setup, ut_teardown,
14985 			test_AES_GMAC_authentication_test_case_1),
14986 		TEST_CASE_ST(ut_setup, ut_teardown,
14987 			test_AES_GMAC_authentication_verify_test_case_1),
14988 		TEST_CASE_ST(ut_setup, ut_teardown,
14989 			test_AES_GMAC_authentication_test_case_2),
14990 		TEST_CASE_ST(ut_setup, ut_teardown,
14991 			test_AES_GMAC_authentication_verify_test_case_2),
14992 		TEST_CASE_ST(ut_setup, ut_teardown,
14993 			test_AES_GMAC_authentication_test_case_3),
14994 		TEST_CASE_ST(ut_setup, ut_teardown,
14995 			test_AES_GMAC_authentication_verify_test_case_3),
14996 		TEST_CASE_ST(ut_setup, ut_teardown,
14997 			test_AES_GMAC_authentication_test_case_4),
14998 		TEST_CASE_ST(ut_setup, ut_teardown,
14999 			test_AES_GMAC_authentication_verify_test_case_4),
15000 		TEST_CASE_ST(ut_setup, ut_teardown,
15001 			test_AES_GMAC_authentication_SGL_40B),
15002 		TEST_CASE_ST(ut_setup, ut_teardown,
15003 			test_AES_GMAC_authentication_SGL_80B),
15004 		TEST_CASE_ST(ut_setup, ut_teardown,
15005 			test_AES_GMAC_authentication_SGL_2048B),
15006 		TEST_CASE_ST(ut_setup, ut_teardown,
15007 			test_AES_GMAC_authentication_SGL_2047B),
15008 
15009 		TEST_CASES_END()
15010 	}
15011 };
15012 
15013 static struct unit_test_suite cryptodev_chacha20_poly1305_testsuite  = {
15014 	.suite_name = "Chacha20-Poly1305 Test Suite",
15015 	.setup = chacha20_poly1305_testsuite_setup,
15016 	.unit_test_cases = {
15017 		TEST_CASE_ST(ut_setup, ut_teardown,
15018 			test_chacha20_poly1305_encrypt_test_case_rfc8439),
15019 		TEST_CASE_ST(ut_setup, ut_teardown,
15020 			test_chacha20_poly1305_decrypt_test_case_rfc8439),
15021 		TEST_CASE_ST(ut_setup, ut_teardown,
15022 			test_chacha20_poly1305_encrypt_SGL_out_of_place),
15023 		TEST_CASES_END()
15024 	}
15025 };
15026 
15027 static struct unit_test_suite cryptodev_snow3g_testsuite  = {
15028 	.suite_name = "SNOW 3G Test Suite",
15029 	.setup = snow3g_testsuite_setup,
15030 	.unit_test_cases = {
15031 		/** SNOW 3G encrypt only (UEA2) */
15032 		TEST_CASE_ST(ut_setup, ut_teardown,
15033 			test_snow3g_encryption_test_case_1),
15034 		TEST_CASE_ST(ut_setup, ut_teardown,
15035 			test_snow3g_encryption_test_case_2),
15036 		TEST_CASE_ST(ut_setup, ut_teardown,
15037 			test_snow3g_encryption_test_case_3),
15038 		TEST_CASE_ST(ut_setup, ut_teardown,
15039 			test_snow3g_encryption_test_case_4),
15040 		TEST_CASE_ST(ut_setup, ut_teardown,
15041 			test_snow3g_encryption_test_case_5),
15042 
15043 		TEST_CASE_ST(ut_setup, ut_teardown,
15044 			test_snow3g_encryption_test_case_1_oop),
15045 		TEST_CASE_ST(ut_setup, ut_teardown,
15046 			test_snow3g_encryption_test_case_1_oop_sgl),
15047 		TEST_CASE_ST(ut_setup, ut_teardown,
15048 			test_snow3g_encryption_test_case_1_offset_oop),
15049 		TEST_CASE_ST(ut_setup, ut_teardown,
15050 			test_snow3g_decryption_test_case_1_oop),
15051 
15052 		/** SNOW 3G generate auth, then encrypt (UEA2) */
15053 		TEST_CASE_ST(ut_setup, ut_teardown,
15054 			test_snow3g_auth_cipher_test_case_1),
15055 		TEST_CASE_ST(ut_setup, ut_teardown,
15056 			test_snow3g_auth_cipher_test_case_2),
15057 		TEST_CASE_ST(ut_setup, ut_teardown,
15058 			test_snow3g_auth_cipher_test_case_2_oop),
15059 		TEST_CASE_ST(ut_setup, ut_teardown,
15060 			test_snow3g_auth_cipher_part_digest_enc),
15061 		TEST_CASE_ST(ut_setup, ut_teardown,
15062 			test_snow3g_auth_cipher_part_digest_enc_oop),
15063 		TEST_CASE_ST(ut_setup, ut_teardown,
15064 			test_snow3g_auth_cipher_test_case_3_sgl),
15065 		TEST_CASE_ST(ut_setup, ut_teardown,
15066 			test_snow3g_auth_cipher_test_case_3_oop_sgl),
15067 		TEST_CASE_ST(ut_setup, ut_teardown,
15068 			test_snow3g_auth_cipher_part_digest_enc_sgl),
15069 		TEST_CASE_ST(ut_setup, ut_teardown,
15070 			test_snow3g_auth_cipher_part_digest_enc_oop_sgl),
15071 
15072 		/** SNOW 3G decrypt (UEA2), then verify auth */
15073 		TEST_CASE_ST(ut_setup, ut_teardown,
15074 			test_snow3g_auth_cipher_verify_test_case_1),
15075 		TEST_CASE_ST(ut_setup, ut_teardown,
15076 			test_snow3g_auth_cipher_verify_test_case_2),
15077 		TEST_CASE_ST(ut_setup, ut_teardown,
15078 			test_snow3g_auth_cipher_verify_test_case_2_oop),
15079 		TEST_CASE_ST(ut_setup, ut_teardown,
15080 			test_snow3g_auth_cipher_verify_part_digest_enc),
15081 		TEST_CASE_ST(ut_setup, ut_teardown,
15082 			test_snow3g_auth_cipher_verify_part_digest_enc_oop),
15083 		TEST_CASE_ST(ut_setup, ut_teardown,
15084 			test_snow3g_auth_cipher_verify_test_case_3_sgl),
15085 		TEST_CASE_ST(ut_setup, ut_teardown,
15086 			test_snow3g_auth_cipher_verify_test_case_3_oop_sgl),
15087 		TEST_CASE_ST(ut_setup, ut_teardown,
15088 			test_snow3g_auth_cipher_verify_part_digest_enc_sgl),
15089 		TEST_CASE_ST(ut_setup, ut_teardown,
15090 			test_snow3g_auth_cipher_verify_part_digest_enc_oop_sgl),
15091 
15092 		/** SNOW 3G decrypt only (UEA2) */
15093 		TEST_CASE_ST(ut_setup, ut_teardown,
15094 			test_snow3g_decryption_test_case_1),
15095 		TEST_CASE_ST(ut_setup, ut_teardown,
15096 			test_snow3g_decryption_test_case_2),
15097 		TEST_CASE_ST(ut_setup, ut_teardown,
15098 			test_snow3g_decryption_test_case_3),
15099 		TEST_CASE_ST(ut_setup, ut_teardown,
15100 			test_snow3g_decryption_test_case_4),
15101 		TEST_CASE_ST(ut_setup, ut_teardown,
15102 			test_snow3g_decryption_test_case_5),
15103 		TEST_CASE_ST(ut_setup, ut_teardown,
15104 			test_snow3g_decryption_with_digest_test_case_1),
15105 		TEST_CASE_ST(ut_setup, ut_teardown,
15106 			test_snow3g_hash_generate_test_case_1),
15107 		TEST_CASE_ST(ut_setup, ut_teardown,
15108 			test_snow3g_hash_generate_test_case_2),
15109 		TEST_CASE_ST(ut_setup, ut_teardown,
15110 			test_snow3g_hash_generate_test_case_3),
15111 
15112 		/* Tests with buffers which length is not byte-aligned */
15113 		TEST_CASE_ST(ut_setup, ut_teardown,
15114 			test_snow3g_hash_generate_test_case_4),
15115 		TEST_CASE_ST(ut_setup, ut_teardown,
15116 			test_snow3g_hash_generate_test_case_5),
15117 		TEST_CASE_ST(ut_setup, ut_teardown,
15118 			test_snow3g_hash_generate_test_case_6),
15119 		TEST_CASE_ST(ut_setup, ut_teardown,
15120 			test_snow3g_hash_verify_test_case_1),
15121 		TEST_CASE_ST(ut_setup, ut_teardown,
15122 			test_snow3g_hash_verify_test_case_2),
15123 		TEST_CASE_ST(ut_setup, ut_teardown,
15124 			test_snow3g_hash_verify_test_case_3),
15125 
15126 		/* Tests with buffers which length is not byte-aligned */
15127 		TEST_CASE_ST(ut_setup, ut_teardown,
15128 			test_snow3g_hash_verify_test_case_4),
15129 		TEST_CASE_ST(ut_setup, ut_teardown,
15130 			test_snow3g_hash_verify_test_case_5),
15131 		TEST_CASE_ST(ut_setup, ut_teardown,
15132 			test_snow3g_hash_verify_test_case_6),
15133 		TEST_CASE_ST(ut_setup, ut_teardown,
15134 			test_snow3g_cipher_auth_test_case_1),
15135 		TEST_CASE_ST(ut_setup, ut_teardown,
15136 			test_snow3g_auth_cipher_with_digest_test_case_1),
15137 		TEST_CASES_END()
15138 	}
15139 };
15140 
15141 static struct unit_test_suite cryptodev_zuc_testsuite  = {
15142 	.suite_name = "ZUC Test Suite",
15143 	.setup = zuc_testsuite_setup,
15144 	.unit_test_cases = {
15145 		/** ZUC encrypt only (EEA3) */
15146 		TEST_CASE_ST(ut_setup, ut_teardown,
15147 			test_zuc_encryption_test_case_1),
15148 		TEST_CASE_ST(ut_setup, ut_teardown,
15149 			test_zuc_encryption_test_case_2),
15150 		TEST_CASE_ST(ut_setup, ut_teardown,
15151 			test_zuc_encryption_test_case_3),
15152 		TEST_CASE_ST(ut_setup, ut_teardown,
15153 			test_zuc_encryption_test_case_4),
15154 		TEST_CASE_ST(ut_setup, ut_teardown,
15155 			test_zuc_encryption_test_case_5),
15156 		TEST_CASE_ST(ut_setup, ut_teardown,
15157 			test_zuc_encryption_test_case_6_sgl),
15158 
15159 		/** ZUC authenticate (EIA3) */
15160 		TEST_CASE_ST(ut_setup, ut_teardown,
15161 			test_zuc_hash_generate_test_case_1),
15162 		TEST_CASE_ST(ut_setup, ut_teardown,
15163 			test_zuc_hash_generate_test_case_2),
15164 		TEST_CASE_ST(ut_setup, ut_teardown,
15165 			test_zuc_hash_generate_test_case_3),
15166 		TEST_CASE_ST(ut_setup, ut_teardown,
15167 			test_zuc_hash_generate_test_case_4),
15168 		TEST_CASE_ST(ut_setup, ut_teardown,
15169 			test_zuc_hash_generate_test_case_5),
15170 		TEST_CASE_ST(ut_setup, ut_teardown,
15171 			test_zuc_hash_generate_test_case_6),
15172 		TEST_CASE_ST(ut_setup, ut_teardown,
15173 			test_zuc_hash_generate_test_case_7),
15174 		TEST_CASE_ST(ut_setup, ut_teardown,
15175 			test_zuc_hash_generate_test_case_8),
15176 		TEST_CASE_ST(ut_setup, ut_teardown,
15177 			test_zuc_hash_generate_test_case_9),
15178 		TEST_CASE_ST(ut_setup, ut_teardown,
15179 			test_zuc_hash_generate_test_case_10),
15180 		TEST_CASE_ST(ut_setup, ut_teardown,
15181 			test_zuc_hash_generate_test_case_11),
15182 
15183 
15184 		/** ZUC alg-chain (EEA3/EIA3) */
15185 		TEST_CASE_ST(ut_setup, ut_teardown,
15186 			test_zuc_cipher_auth_test_case_1),
15187 		TEST_CASE_ST(ut_setup, ut_teardown,
15188 			test_zuc_cipher_auth_test_case_2),
15189 
15190 		/** ZUC generate auth, then encrypt (EEA3) */
15191 		TEST_CASE_ST(ut_setup, ut_teardown,
15192 			test_zuc_auth_cipher_test_case_1),
15193 		TEST_CASE_ST(ut_setup, ut_teardown,
15194 			test_zuc_auth_cipher_test_case_1_oop),
15195 		TEST_CASE_ST(ut_setup, ut_teardown,
15196 			test_zuc_auth_cipher_test_case_1_sgl),
15197 		TEST_CASE_ST(ut_setup, ut_teardown,
15198 			test_zuc_auth_cipher_test_case_1_oop_sgl),
15199 
15200 		/** ZUC decrypt (EEA3), then verify auth */
15201 		TEST_CASE_ST(ut_setup, ut_teardown,
15202 			test_zuc_auth_cipher_verify_test_case_1),
15203 		TEST_CASE_ST(ut_setup, ut_teardown,
15204 			test_zuc_auth_cipher_verify_test_case_1_oop),
15205 		TEST_CASE_ST(ut_setup, ut_teardown,
15206 			test_zuc_auth_cipher_verify_test_case_1_sgl),
15207 		TEST_CASE_ST(ut_setup, ut_teardown,
15208 			test_zuc_auth_cipher_verify_test_case_1_oop_sgl),
15209 
15210 		/** ZUC-256 encrypt only **/
15211 		TEST_CASE_ST(ut_setup, ut_teardown,
15212 			test_zuc256_encryption_test_case_1),
15213 		TEST_CASE_ST(ut_setup, ut_teardown,
15214 			test_zuc256_encryption_test_case_2),
15215 
15216 		/** ZUC-256 authentication only **/
15217 		TEST_CASE_ST(ut_setup, ut_teardown,
15218 			test_zuc256_authentication_test_case_1),
15219 		TEST_CASE_ST(ut_setup, ut_teardown,
15220 			test_zuc256_authentication_test_case_2),
15221 
15222 		TEST_CASES_END()
15223 	}
15224 };
15225 
15226 static struct unit_test_suite cryptodev_hmac_md5_auth_testsuite  = {
15227 	.suite_name = "HMAC_MD5 Authentication Test Suite",
15228 	.setup = hmac_md5_auth_testsuite_setup,
15229 	.unit_test_cases = {
15230 		TEST_CASE_ST(ut_setup, ut_teardown,
15231 			test_MD5_HMAC_generate_case_1),
15232 		TEST_CASE_ST(ut_setup, ut_teardown,
15233 			test_MD5_HMAC_verify_case_1),
15234 		TEST_CASE_ST(ut_setup, ut_teardown,
15235 			test_MD5_HMAC_generate_case_2),
15236 		TEST_CASE_ST(ut_setup, ut_teardown,
15237 			test_MD5_HMAC_verify_case_2),
15238 		TEST_CASES_END()
15239 	}
15240 };
15241 
15242 static struct unit_test_suite cryptodev_kasumi_testsuite  = {
15243 	.suite_name = "Kasumi Test Suite",
15244 	.setup = kasumi_testsuite_setup,
15245 	.unit_test_cases = {
15246 		/** KASUMI hash only (UIA1) */
15247 		TEST_CASE_ST(ut_setup, ut_teardown,
15248 			test_kasumi_hash_generate_test_case_1),
15249 		TEST_CASE_ST(ut_setup, ut_teardown,
15250 			test_kasumi_hash_generate_test_case_2),
15251 		TEST_CASE_ST(ut_setup, ut_teardown,
15252 			test_kasumi_hash_generate_test_case_3),
15253 		TEST_CASE_ST(ut_setup, ut_teardown,
15254 			test_kasumi_hash_generate_test_case_4),
15255 		TEST_CASE_ST(ut_setup, ut_teardown,
15256 			test_kasumi_hash_generate_test_case_5),
15257 		TEST_CASE_ST(ut_setup, ut_teardown,
15258 			test_kasumi_hash_generate_test_case_6),
15259 
15260 		TEST_CASE_ST(ut_setup, ut_teardown,
15261 			test_kasumi_hash_verify_test_case_1),
15262 		TEST_CASE_ST(ut_setup, ut_teardown,
15263 			test_kasumi_hash_verify_test_case_2),
15264 		TEST_CASE_ST(ut_setup, ut_teardown,
15265 			test_kasumi_hash_verify_test_case_3),
15266 		TEST_CASE_ST(ut_setup, ut_teardown,
15267 			test_kasumi_hash_verify_test_case_4),
15268 		TEST_CASE_ST(ut_setup, ut_teardown,
15269 			test_kasumi_hash_verify_test_case_5),
15270 
15271 		/** KASUMI encrypt only (UEA1) */
15272 		TEST_CASE_ST(ut_setup, ut_teardown,
15273 			test_kasumi_encryption_test_case_1),
15274 		TEST_CASE_ST(ut_setup, ut_teardown,
15275 			test_kasumi_encryption_test_case_1_sgl),
15276 		TEST_CASE_ST(ut_setup, ut_teardown,
15277 			test_kasumi_encryption_test_case_1_oop),
15278 		TEST_CASE_ST(ut_setup, ut_teardown,
15279 			test_kasumi_encryption_test_case_1_oop_sgl),
15280 		TEST_CASE_ST(ut_setup, ut_teardown,
15281 			test_kasumi_encryption_test_case_2),
15282 		TEST_CASE_ST(ut_setup, ut_teardown,
15283 			test_kasumi_encryption_test_case_3),
15284 		TEST_CASE_ST(ut_setup, ut_teardown,
15285 			test_kasumi_encryption_test_case_4),
15286 		TEST_CASE_ST(ut_setup, ut_teardown,
15287 			test_kasumi_encryption_test_case_5),
15288 
15289 		/** KASUMI decrypt only (UEA1) */
15290 		TEST_CASE_ST(ut_setup, ut_teardown,
15291 			test_kasumi_decryption_test_case_1),
15292 		TEST_CASE_ST(ut_setup, ut_teardown,
15293 			test_kasumi_decryption_test_case_2),
15294 		TEST_CASE_ST(ut_setup, ut_teardown,
15295 			test_kasumi_decryption_test_case_3),
15296 		TEST_CASE_ST(ut_setup, ut_teardown,
15297 			test_kasumi_decryption_test_case_4),
15298 		TEST_CASE_ST(ut_setup, ut_teardown,
15299 			test_kasumi_decryption_test_case_5),
15300 		TEST_CASE_ST(ut_setup, ut_teardown,
15301 			test_kasumi_decryption_test_case_1_oop),
15302 		TEST_CASE_ST(ut_setup, ut_teardown,
15303 			test_kasumi_cipher_auth_test_case_1),
15304 
15305 		/** KASUMI generate auth, then encrypt (F8) */
15306 		TEST_CASE_ST(ut_setup, ut_teardown,
15307 			test_kasumi_auth_cipher_test_case_1),
15308 		TEST_CASE_ST(ut_setup, ut_teardown,
15309 			test_kasumi_auth_cipher_test_case_2),
15310 		TEST_CASE_ST(ut_setup, ut_teardown,
15311 			test_kasumi_auth_cipher_test_case_2_oop),
15312 		TEST_CASE_ST(ut_setup, ut_teardown,
15313 			test_kasumi_auth_cipher_test_case_2_sgl),
15314 		TEST_CASE_ST(ut_setup, ut_teardown,
15315 			test_kasumi_auth_cipher_test_case_2_oop_sgl),
15316 
15317 		/** KASUMI decrypt (F8), then verify auth */
15318 		TEST_CASE_ST(ut_setup, ut_teardown,
15319 			test_kasumi_auth_cipher_verify_test_case_1),
15320 		TEST_CASE_ST(ut_setup, ut_teardown,
15321 			test_kasumi_auth_cipher_verify_test_case_2),
15322 		TEST_CASE_ST(ut_setup, ut_teardown,
15323 			test_kasumi_auth_cipher_verify_test_case_2_oop),
15324 		TEST_CASE_ST(ut_setup, ut_teardown,
15325 			test_kasumi_auth_cipher_verify_test_case_2_sgl),
15326 		TEST_CASE_ST(ut_setup, ut_teardown,
15327 			test_kasumi_auth_cipher_verify_test_case_2_oop_sgl),
15328 
15329 		TEST_CASES_END()
15330 	}
15331 };
15332 
15333 static struct unit_test_suite cryptodev_esn_testsuite  = {
15334 	.suite_name = "ESN Test Suite",
15335 	.setup = esn_testsuite_setup,
15336 	.unit_test_cases = {
15337 		TEST_CASE_ST(ut_setup, ut_teardown,
15338 			auth_encrypt_AES128CBC_HMAC_SHA1_esn_check),
15339 		TEST_CASE_ST(ut_setup, ut_teardown,
15340 			auth_decrypt_AES128CBC_HMAC_SHA1_esn_check),
15341 		TEST_CASES_END()
15342 	}
15343 };
15344 
15345 static struct unit_test_suite cryptodev_negative_aes_gcm_testsuite  = {
15346 	.suite_name = "Negative AES GCM Test Suite",
15347 	.setup = negative_aes_gcm_testsuite_setup,
15348 	.unit_test_cases = {
15349 		TEST_CASE_ST(ut_setup, ut_teardown,
15350 			test_AES_GCM_auth_encryption_fail_iv_corrupt),
15351 		TEST_CASE_ST(ut_setup, ut_teardown,
15352 			test_AES_GCM_auth_encryption_fail_in_data_corrupt),
15353 		TEST_CASE_ST(ut_setup, ut_teardown,
15354 			test_AES_GCM_auth_encryption_fail_out_data_corrupt),
15355 		TEST_CASE_ST(ut_setup, ut_teardown,
15356 			test_AES_GCM_auth_encryption_fail_aad_len_corrupt),
15357 		TEST_CASE_ST(ut_setup, ut_teardown,
15358 			test_AES_GCM_auth_encryption_fail_aad_corrupt),
15359 		TEST_CASE_ST(ut_setup, ut_teardown,
15360 			test_AES_GCM_auth_encryption_fail_tag_corrupt),
15361 		TEST_CASE_ST(ut_setup, ut_teardown,
15362 			test_AES_GCM_auth_decryption_fail_iv_corrupt),
15363 		TEST_CASE_ST(ut_setup, ut_teardown,
15364 			test_AES_GCM_auth_decryption_fail_in_data_corrupt),
15365 		TEST_CASE_ST(ut_setup, ut_teardown,
15366 			test_AES_GCM_auth_decryption_fail_out_data_corrupt),
15367 		TEST_CASE_ST(ut_setup, ut_teardown,
15368 			test_AES_GCM_auth_decryption_fail_aad_len_corrupt),
15369 		TEST_CASE_ST(ut_setup, ut_teardown,
15370 			test_AES_GCM_auth_decryption_fail_aad_corrupt),
15371 		TEST_CASE_ST(ut_setup, ut_teardown,
15372 			test_AES_GCM_auth_decryption_fail_tag_corrupt),
15373 
15374 		TEST_CASES_END()
15375 	}
15376 };
15377 
15378 static struct unit_test_suite cryptodev_negative_aes_gmac_testsuite  = {
15379 	.suite_name = "Negative AES GMAC Test Suite",
15380 	.setup = negative_aes_gmac_testsuite_setup,
15381 	.unit_test_cases = {
15382 		TEST_CASE_ST(ut_setup, ut_teardown,
15383 			authentication_verify_AES128_GMAC_fail_data_corrupt),
15384 		TEST_CASE_ST(ut_setup, ut_teardown,
15385 			authentication_verify_AES128_GMAC_fail_tag_corrupt),
15386 
15387 		TEST_CASES_END()
15388 	}
15389 };
15390 
15391 static struct unit_test_suite cryptodev_mixed_cipher_hash_testsuite  = {
15392 	.suite_name = "Mixed CIPHER + HASH algorithms Test Suite",
15393 	.setup = mixed_cipher_hash_testsuite_setup,
15394 	.unit_test_cases = {
15395 		/** AUTH AES CMAC + CIPHER AES CTR */
15396 		TEST_CASE_ST(ut_setup, ut_teardown,
15397 			test_aes_cmac_aes_ctr_digest_enc_test_case_1),
15398 		TEST_CASE_ST(ut_setup, ut_teardown,
15399 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15400 		TEST_CASE_ST(ut_setup, ut_teardown,
15401 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15402 		TEST_CASE_ST(ut_setup, ut_teardown,
15403 			test_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15404 		TEST_CASE_ST(ut_setup, ut_teardown,
15405 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1),
15406 		TEST_CASE_ST(ut_setup, ut_teardown,
15407 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop),
15408 		TEST_CASE_ST(ut_setup, ut_teardown,
15409 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_sgl),
15410 		TEST_CASE_ST(ut_setup, ut_teardown,
15411 			test_verify_aes_cmac_aes_ctr_digest_enc_test_case_1_oop_sgl),
15412 
15413 		/** AUTH ZUC + CIPHER SNOW3G */
15414 		TEST_CASE_ST(ut_setup, ut_teardown,
15415 			test_auth_zuc_cipher_snow_test_case_1),
15416 		TEST_CASE_ST(ut_setup, ut_teardown,
15417 			test_verify_auth_zuc_cipher_snow_test_case_1),
15418 		/** AUTH AES CMAC + CIPHER SNOW3G */
15419 		TEST_CASE_ST(ut_setup, ut_teardown,
15420 			test_auth_aes_cmac_cipher_snow_test_case_1),
15421 		TEST_CASE_ST(ut_setup, ut_teardown,
15422 			test_verify_auth_aes_cmac_cipher_snow_test_case_1),
15423 		/** AUTH ZUC + CIPHER AES CTR */
15424 		TEST_CASE_ST(ut_setup, ut_teardown,
15425 			test_auth_zuc_cipher_aes_ctr_test_case_1),
15426 		TEST_CASE_ST(ut_setup, ut_teardown,
15427 			test_verify_auth_zuc_cipher_aes_ctr_test_case_1),
15428 		/** AUTH SNOW3G + CIPHER AES CTR */
15429 		TEST_CASE_ST(ut_setup, ut_teardown,
15430 			test_auth_snow_cipher_aes_ctr_test_case_1),
15431 		TEST_CASE_ST(ut_setup, ut_teardown,
15432 			test_verify_auth_snow_cipher_aes_ctr_test_case_1),
15433 		/** AUTH SNOW3G + CIPHER ZUC */
15434 		TEST_CASE_ST(ut_setup, ut_teardown,
15435 			test_auth_snow_cipher_zuc_test_case_1),
15436 		TEST_CASE_ST(ut_setup, ut_teardown,
15437 			test_verify_auth_snow_cipher_zuc_test_case_1),
15438 		/** AUTH AES CMAC + CIPHER ZUC */
15439 		TEST_CASE_ST(ut_setup, ut_teardown,
15440 			test_auth_aes_cmac_cipher_zuc_test_case_1),
15441 		TEST_CASE_ST(ut_setup, ut_teardown,
15442 			test_verify_auth_aes_cmac_cipher_zuc_test_case_1),
15443 
15444 		/** AUTH NULL + CIPHER SNOW3G */
15445 		TEST_CASE_ST(ut_setup, ut_teardown,
15446 			test_auth_null_cipher_snow_test_case_1),
15447 		TEST_CASE_ST(ut_setup, ut_teardown,
15448 			test_verify_auth_null_cipher_snow_test_case_1),
15449 		/** AUTH NULL + CIPHER ZUC */
15450 		TEST_CASE_ST(ut_setup, ut_teardown,
15451 			test_auth_null_cipher_zuc_test_case_1),
15452 		TEST_CASE_ST(ut_setup, ut_teardown,
15453 			test_verify_auth_null_cipher_zuc_test_case_1),
15454 		/** AUTH SNOW3G + CIPHER NULL */
15455 		TEST_CASE_ST(ut_setup, ut_teardown,
15456 			test_auth_snow_cipher_null_test_case_1),
15457 		TEST_CASE_ST(ut_setup, ut_teardown,
15458 			test_verify_auth_snow_cipher_null_test_case_1),
15459 		/** AUTH ZUC + CIPHER NULL */
15460 		TEST_CASE_ST(ut_setup, ut_teardown,
15461 			test_auth_zuc_cipher_null_test_case_1),
15462 		TEST_CASE_ST(ut_setup, ut_teardown,
15463 			test_verify_auth_zuc_cipher_null_test_case_1),
15464 		/** AUTH NULL + CIPHER AES CTR */
15465 		TEST_CASE_ST(ut_setup, ut_teardown,
15466 			test_auth_null_cipher_aes_ctr_test_case_1),
15467 		TEST_CASE_ST(ut_setup, ut_teardown,
15468 			test_verify_auth_null_cipher_aes_ctr_test_case_1),
15469 		/** AUTH AES CMAC + CIPHER NULL */
15470 		TEST_CASE_ST(ut_setup, ut_teardown,
15471 			test_auth_aes_cmac_cipher_null_test_case_1),
15472 		TEST_CASE_ST(ut_setup, ut_teardown,
15473 			test_verify_auth_aes_cmac_cipher_null_test_case_1),
15474 		TEST_CASES_END()
15475 	}
15476 };
15477 
15478 static int
15479 run_cryptodev_testsuite(const char *pmd_name)
15480 {
15481 	uint8_t ret, j, i = 0, blk_start_idx = 0;
15482 	const enum blockcipher_test_type blk_suites[] = {
15483 		BLKCIPHER_AES_CHAIN_TYPE,
15484 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15485 		BLKCIPHER_AES_DOCSIS_TYPE,
15486 		BLKCIPHER_3DES_CHAIN_TYPE,
15487 		BLKCIPHER_3DES_CIPHERONLY_TYPE,
15488 		BLKCIPHER_DES_CIPHERONLY_TYPE,
15489 		BLKCIPHER_DES_DOCSIS_TYPE,
15490 		BLKCIPHER_AUTHONLY_TYPE};
15491 	struct unit_test_suite *static_suites[] = {
15492 		&cryptodev_multi_session_testsuite,
15493 		&cryptodev_null_testsuite,
15494 		&cryptodev_aes_ccm_auth_testsuite,
15495 		&cryptodev_aes_gcm_auth_testsuite,
15496 		&cryptodev_aes_gmac_auth_testsuite,
15497 		&cryptodev_snow3g_testsuite,
15498 		&cryptodev_chacha20_poly1305_testsuite,
15499 		&cryptodev_zuc_testsuite,
15500 		&cryptodev_hmac_md5_auth_testsuite,
15501 		&cryptodev_kasumi_testsuite,
15502 		&cryptodev_esn_testsuite,
15503 		&cryptodev_negative_aes_gcm_testsuite,
15504 		&cryptodev_negative_aes_gmac_testsuite,
15505 		&cryptodev_mixed_cipher_hash_testsuite,
15506 		&cryptodev_negative_hmac_sha1_testsuite,
15507 		&cryptodev_gen_testsuite,
15508 #ifdef RTE_LIB_SECURITY
15509 		&ipsec_proto_testsuite,
15510 		&pdcp_proto_testsuite,
15511 		&docsis_proto_testsuite,
15512 #endif
15513 		&end_testsuite
15514 	};
15515 	static struct unit_test_suite ts = {
15516 		.suite_name = "Cryptodev Unit Test Suite",
15517 		.setup = testsuite_setup,
15518 		.teardown = testsuite_teardown,
15519 		.unit_test_cases = {TEST_CASES_END()}
15520 	};
15521 
15522 	gbl_driver_id = rte_cryptodev_driver_id_get(pmd_name);
15523 
15524 	if (gbl_driver_id == -1) {
15525 		RTE_LOG(ERR, USER1, "%s PMD must be loaded.\n", pmd_name);
15526 		return TEST_SKIPPED;
15527 	}
15528 
15529 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15530 			(RTE_DIM(blk_suites) + RTE_DIM(static_suites)));
15531 
15532 	ADD_BLOCKCIPHER_TESTSUITE(i, ts, blk_suites, RTE_DIM(blk_suites));
15533 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15534 	ret = unit_test_suite_runner(&ts);
15535 
15536 	FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx, ts, RTE_DIM(blk_suites));
15537 	free(ts.unit_test_suites);
15538 	return ret;
15539 }
15540 
15541 static int
15542 require_feature_flag(const char *pmd_name, uint64_t flag, const char *flag_name)
15543 {
15544 	struct rte_cryptodev_info dev_info;
15545 	uint8_t i, nb_devs;
15546 	int driver_id;
15547 
15548 	driver_id = rte_cryptodev_driver_id_get(pmd_name);
15549 	if (driver_id == -1) {
15550 		RTE_LOG(WARNING, USER1, "%s PMD must be loaded.\n", pmd_name);
15551 		return TEST_SKIPPED;
15552 	}
15553 
15554 	nb_devs = rte_cryptodev_count();
15555 	if (nb_devs < 1) {
15556 		RTE_LOG(WARNING, USER1, "No crypto devices found?\n");
15557 		return TEST_SKIPPED;
15558 	}
15559 
15560 	for (i = 0; i < nb_devs; i++) {
15561 		rte_cryptodev_info_get(i, &dev_info);
15562 		if (dev_info.driver_id == driver_id) {
15563 			if (!(dev_info.feature_flags & flag)) {
15564 				RTE_LOG(INFO, USER1, "%s not supported\n",
15565 						flag_name);
15566 				return TEST_SKIPPED;
15567 			}
15568 			return 0; /* found */
15569 		}
15570 	}
15571 
15572 	RTE_LOG(INFO, USER1, "%s not supported\n", flag_name);
15573 	return TEST_SKIPPED;
15574 }
15575 
15576 static int
15577 test_cryptodev_qat(void)
15578 {
15579 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD));
15580 }
15581 
15582 static int
15583 test_cryptodev_virtio(void)
15584 {
15585 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
15586 }
15587 
15588 static int
15589 test_cryptodev_aesni_mb(void)
15590 {
15591 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15592 }
15593 
15594 static int
15595 test_cryptodev_cpu_aesni_mb(void)
15596 {
15597 	int32_t rc;
15598 	enum rte_security_session_action_type at = gbl_action_type;
15599 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15600 	rc = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
15601 	gbl_action_type = at;
15602 	return rc;
15603 }
15604 
15605 static int
15606 test_cryptodev_chacha_poly_mb(void)
15607 {
15608 	int32_t rc;
15609 	enum rte_security_session_action_type at = gbl_action_type;
15610 	rc = run_cryptodev_testsuite(
15611 			RTE_STR(CRYPTODEV_NAME_CHACHA20_POLY1305_PMD));
15612 	gbl_action_type = at;
15613 	return rc;
15614 }
15615 
15616 static int
15617 test_cryptodev_openssl(void)
15618 {
15619 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
15620 }
15621 
15622 static int
15623 test_cryptodev_aesni_gcm(void)
15624 {
15625 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15626 }
15627 
15628 static int
15629 test_cryptodev_cpu_aesni_gcm(void)
15630 {
15631 	int32_t rc;
15632 	enum rte_security_session_action_type at = gbl_action_type;
15633 	gbl_action_type = RTE_SECURITY_ACTION_TYPE_CPU_CRYPTO;
15634 	rc  = run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
15635 	gbl_action_type = at;
15636 	return rc;
15637 }
15638 
15639 static int
15640 test_cryptodev_mlx5(void)
15641 {
15642 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MLX5_PMD));
15643 }
15644 
15645 static int
15646 test_cryptodev_null(void)
15647 {
15648 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NULL_PMD));
15649 }
15650 
15651 static int
15652 test_cryptodev_sw_snow3g(void)
15653 {
15654 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
15655 }
15656 
15657 static int
15658 test_cryptodev_sw_kasumi(void)
15659 {
15660 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
15661 }
15662 
15663 static int
15664 test_cryptodev_sw_zuc(void)
15665 {
15666 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
15667 }
15668 
15669 static int
15670 test_cryptodev_armv8(void)
15671 {
15672 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
15673 }
15674 
15675 static int
15676 test_cryptodev_mrvl(void)
15677 {
15678 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_MVSAM_PMD));
15679 }
15680 
15681 #ifdef RTE_CRYPTO_SCHEDULER
15682 
15683 static int
15684 test_cryptodev_scheduler(void)
15685 {
15686 	uint8_t ret, sched_i, j, i = 0, blk_start_idx = 0;
15687 	const enum blockcipher_test_type blk_suites[] = {
15688 		BLKCIPHER_AES_CHAIN_TYPE,
15689 		BLKCIPHER_AES_CIPHERONLY_TYPE,
15690 		BLKCIPHER_AUTHONLY_TYPE
15691 	};
15692 	static struct unit_test_suite scheduler_multicore = {
15693 		.suite_name = "Scheduler Multicore Unit Test Suite",
15694 		.setup = scheduler_multicore_testsuite_setup,
15695 		.teardown = scheduler_mode_testsuite_teardown,
15696 		.unit_test_cases = {TEST_CASES_END()}
15697 	};
15698 	static struct unit_test_suite scheduler_round_robin = {
15699 		.suite_name = "Scheduler Round Robin Unit Test Suite",
15700 		.setup = scheduler_roundrobin_testsuite_setup,
15701 		.teardown = scheduler_mode_testsuite_teardown,
15702 		.unit_test_cases = {TEST_CASES_END()}
15703 	};
15704 	static struct unit_test_suite scheduler_failover = {
15705 		.suite_name = "Scheduler Failover Unit Test Suite",
15706 		.setup = scheduler_failover_testsuite_setup,
15707 		.teardown = scheduler_mode_testsuite_teardown,
15708 		.unit_test_cases = {TEST_CASES_END()}
15709 	};
15710 	static struct unit_test_suite scheduler_pkt_size_distr = {
15711 		.suite_name = "Scheduler Pkt Size Distr Unit Test Suite",
15712 		.setup = scheduler_pkt_size_distr_testsuite_setup,
15713 		.teardown = scheduler_mode_testsuite_teardown,
15714 		.unit_test_cases = {TEST_CASES_END()}
15715 	};
15716 	struct unit_test_suite *sched_mode_suites[] = {
15717 		&scheduler_multicore,
15718 		&scheduler_round_robin,
15719 		&scheduler_failover,
15720 		&scheduler_pkt_size_distr
15721 	};
15722 	static struct unit_test_suite scheduler_config = {
15723 		.suite_name = "Crypto Device Scheduler Config Unit Test Suite",
15724 		.unit_test_cases = {
15725 			TEST_CASE(test_scheduler_attach_worker_op),
15726 			TEST_CASE(test_scheduler_mode_multicore_op),
15727 			TEST_CASE(test_scheduler_mode_roundrobin_op),
15728 			TEST_CASE(test_scheduler_mode_failover_op),
15729 			TEST_CASE(test_scheduler_mode_pkt_size_distr_op),
15730 			TEST_CASE(test_scheduler_detach_worker_op),
15731 
15732 			TEST_CASES_END() /**< NULL terminate array */
15733 		}
15734 	};
15735 	struct unit_test_suite *static_suites[] = {
15736 		&scheduler_config,
15737 		&end_testsuite
15738 	};
15739 	static struct unit_test_suite ts = {
15740 		.suite_name = "Scheduler Unit Test Suite",
15741 		.setup = scheduler_testsuite_setup,
15742 		.teardown = testsuite_teardown,
15743 		.unit_test_cases = {TEST_CASES_END()}
15744 	};
15745 
15746 	gbl_driver_id =	rte_cryptodev_driver_id_get(
15747 			RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
15748 
15749 	if (gbl_driver_id == -1) {
15750 		RTE_LOG(ERR, USER1, "SCHEDULER PMD must be loaded.\n");
15751 		return TEST_SKIPPED;
15752 	}
15753 
15754 	if (rte_cryptodev_driver_id_get(
15755 				RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD)) == -1) {
15756 		RTE_LOG(ERR, USER1, "AESNI MB PMD must be loaded.\n");
15757 		return TEST_SKIPPED;
15758 	}
15759 
15760 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15761 		uint8_t blk_i = 0;
15762 		sched_mode_suites[sched_i]->unit_test_suites = malloc(sizeof
15763 				(struct unit_test_suite *) *
15764 				(RTE_DIM(blk_suites) + 1));
15765 		ADD_BLOCKCIPHER_TESTSUITE(blk_i, (*sched_mode_suites[sched_i]),
15766 				blk_suites, RTE_DIM(blk_suites));
15767 		sched_mode_suites[sched_i]->unit_test_suites[blk_i] = &end_testsuite;
15768 	}
15769 
15770 	ts.unit_test_suites = malloc(sizeof(struct unit_test_suite *) *
15771 			(RTE_DIM(static_suites) + RTE_DIM(sched_mode_suites)));
15772 	ADD_STATIC_TESTSUITE(i, ts, sched_mode_suites,
15773 			RTE_DIM(sched_mode_suites));
15774 	ADD_STATIC_TESTSUITE(i, ts, static_suites, RTE_DIM(static_suites));
15775 	ret = unit_test_suite_runner(&ts);
15776 
15777 	for (sched_i = 0; sched_i < RTE_DIM(sched_mode_suites); sched_i++) {
15778 		FREE_BLOCKCIPHER_TESTSUITE(blk_start_idx,
15779 				(*sched_mode_suites[sched_i]),
15780 				RTE_DIM(blk_suites));
15781 		free(sched_mode_suites[sched_i]->unit_test_suites);
15782 	}
15783 	free(ts.unit_test_suites);
15784 	return ret;
15785 }
15786 
15787 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
15788 
15789 #endif
15790 
15791 static int
15792 test_cryptodev_dpaa2_sec(void)
15793 {
15794 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD));
15795 }
15796 
15797 static int
15798 test_cryptodev_dpaa_sec(void)
15799 {
15800 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_DPAA_SEC_PMD));
15801 }
15802 
15803 static int
15804 test_cryptodev_ccp(void)
15805 {
15806 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CCP_PMD));
15807 }
15808 
15809 static int
15810 test_cryptodev_octeontx(void)
15811 {
15812 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
15813 }
15814 
15815 static int
15816 test_cryptodev_caam_jr(void)
15817 {
15818 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CAAM_JR_PMD));
15819 }
15820 
15821 static int
15822 test_cryptodev_nitrox(void)
15823 {
15824 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_NITROX_PMD));
15825 }
15826 
15827 static int
15828 test_cryptodev_bcmfs(void)
15829 {
15830 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_BCMFS_PMD));
15831 }
15832 
15833 static int
15834 test_cryptodev_qat_raw_api(void)
15835 {
15836 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_QAT_SYM_PMD);
15837 	int ret;
15838 
15839 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15840 			"RAW API");
15841 	if (ret)
15842 		return ret;
15843 
15844 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15845 	ret = run_cryptodev_testsuite(pmd_name);
15846 	global_api_test_type = CRYPTODEV_API_TEST;
15847 
15848 	return ret;
15849 }
15850 
15851 static int
15852 test_cryptodev_cn9k(void)
15853 {
15854 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
15855 }
15856 
15857 static int
15858 test_cryptodev_cn10k(void)
15859 {
15860 	return run_cryptodev_testsuite(RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
15861 }
15862 
15863 static int
15864 test_cryptodev_dpaa2_sec_raw_api(void)
15865 {
15866 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15867 	int ret;
15868 
15869 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15870 			"RAW API");
15871 	if (ret)
15872 		return ret;
15873 
15874 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15875 	ret = run_cryptodev_testsuite(pmd_name);
15876 	global_api_test_type = CRYPTODEV_API_TEST;
15877 
15878 	return ret;
15879 }
15880 
15881 static int
15882 test_cryptodev_dpaa_sec_raw_api(void)
15883 {
15884 	static const char *pmd_name = RTE_STR(CRYPTODEV_NAME_DPAA2_SEC_PMD);
15885 	int ret;
15886 
15887 	ret = require_feature_flag(pmd_name, RTE_CRYPTODEV_FF_SYM_RAW_DP,
15888 			"RAW API");
15889 	if (ret)
15890 		return ret;
15891 
15892 	global_api_test_type = CRYPTODEV_RAW_API_TEST;
15893 	ret = run_cryptodev_testsuite(pmd_name);
15894 	global_api_test_type = CRYPTODEV_API_TEST;
15895 
15896 	return ret;
15897 }
15898 
15899 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_raw_api_autotest,
15900 		test_cryptodev_dpaa2_sec_raw_api);
15901 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_raw_api_autotest,
15902 		test_cryptodev_dpaa_sec_raw_api);
15903 REGISTER_TEST_COMMAND(cryptodev_qat_raw_api_autotest,
15904 		test_cryptodev_qat_raw_api);
15905 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
15906 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
15907 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_mb_autotest,
15908 	test_cryptodev_cpu_aesni_mb);
15909 REGISTER_TEST_COMMAND(cryptodev_chacha_poly_mb_autotest,
15910 	test_cryptodev_chacha_poly_mb);
15911 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
15912 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
15913 REGISTER_TEST_COMMAND(cryptodev_cpu_aesni_gcm_autotest,
15914 	test_cryptodev_cpu_aesni_gcm);
15915 REGISTER_TEST_COMMAND(cryptodev_mlx5_autotest, test_cryptodev_mlx5);
15916 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
15917 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
15918 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
15919 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
15920 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
15921 REGISTER_TEST_COMMAND(cryptodev_sw_mvsam_autotest, test_cryptodev_mrvl);
15922 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);
15923 REGISTER_TEST_COMMAND(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);
15924 REGISTER_TEST_COMMAND(cryptodev_ccp_autotest, test_cryptodev_ccp);
15925 REGISTER_TEST_COMMAND(cryptodev_virtio_autotest, test_cryptodev_virtio);
15926 REGISTER_TEST_COMMAND(cryptodev_octeontx_autotest, test_cryptodev_octeontx);
15927 REGISTER_TEST_COMMAND(cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);
15928 REGISTER_TEST_COMMAND(cryptodev_nitrox_autotest, test_cryptodev_nitrox);
15929 REGISTER_TEST_COMMAND(cryptodev_bcmfs_autotest, test_cryptodev_bcmfs);
15930 REGISTER_TEST_COMMAND(cryptodev_cn9k_autotest, test_cryptodev_cn9k);
15931 REGISTER_TEST_COMMAND(cryptodev_cn10k_autotest, test_cryptodev_cn10k);
15932