xref: /dpdk/app/test/test_cryptodev.c (revision 913154ef)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *	 * Redistributions of source code must retain the above copyright
11  *	   notice, this list of conditions and the following disclaimer.
12  *	 * Redistributions in binary form must reproduce the above copyright
13  *	   notice, this list of conditions and the following disclaimer in
14  *	   the documentation and/or other materials provided with the
15  *	   distribution.
16  *	 * Neither the name of Intel Corporation nor the names of its
17  *	   contributors may be used to endorse or promote products derived
18  *	   from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
35 #include <rte_mbuf.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
38 
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
42 
43 #include "test.h"
44 #include "test_cryptodev.h"
45 
46 #include "test_cryptodev_aes.h"
47 #include "test_cryptodev_kasumi_test_vectors.h"
48 #include "test_cryptodev_kasumi_hash_test_vectors.h"
49 #include "test_cryptodev_snow3g_test_vectors.h"
50 #include "test_cryptodev_snow3g_hash_test_vectors.h"
51 #include "test_cryptodev_gcm_test_vectors.h"
52 
53 static enum rte_cryptodev_type gbl_cryptodev_type;
54 
55 struct crypto_testsuite_params {
56 	struct rte_mempool *mbuf_pool;
57 	struct rte_mempool *op_mpool;
58 	struct rte_cryptodev_config conf;
59 	struct rte_cryptodev_qp_conf qp_conf;
60 
61 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
62 	uint8_t valid_dev_count;
63 };
64 
65 struct crypto_unittest_params {
66 	struct rte_crypto_sym_xform cipher_xform;
67 	struct rte_crypto_sym_xform auth_xform;
68 
69 	struct rte_cryptodev_sym_session *sess;
70 
71 	struct rte_crypto_op *op;
72 
73 	struct rte_mbuf *obuf, *ibuf;
74 
75 	uint8_t *digest;
76 };
77 
78 #define ALIGN_POW2_ROUNDUP(num, align) \
79 	(((num) + (align) - 1) & ~((align) - 1))
80 
81 /*
82  * Forward declarations.
83  */
84 static int
85 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
86 		struct crypto_unittest_params *ut_params);
87 
88 static int
89 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
90 		struct crypto_unittest_params *ut_params,
91 		struct crypto_testsuite_params *ts_param);
92 
93 static struct rte_mbuf *
94 setup_test_string(struct rte_mempool *mpool,
95 		const char *string, size_t len, uint8_t blocksize)
96 {
97 	struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
98 	size_t t_len = len - (blocksize ? (len % blocksize) : 0);
99 
100 	memset(m->buf_addr, 0, m->buf_len);
101 	if (m) {
102 		char *dst = rte_pktmbuf_append(m, t_len);
103 
104 		if (!dst) {
105 			rte_pktmbuf_free(m);
106 			return NULL;
107 		}
108 		if (string != NULL)
109 			rte_memcpy(dst, string, t_len);
110 		else
111 			memset(dst, 0, t_len);
112 	}
113 
114 	return m;
115 }
116 
117 /* Get number of bytes in X bits (rounding up) */
118 static uint32_t
119 ceil_byte_length(uint32_t num_bits)
120 {
121 	if (num_bits % 8)
122 		return ((num_bits >> 3) + 1);
123 	else
124 		return (num_bits >> 3);
125 }
126 
127 static struct rte_crypto_op *
128 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
129 {
130 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
131 		printf("Error sending packet for encryption");
132 		return NULL;
133 	}
134 
135 	op = NULL;
136 
137 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
138 		rte_pause();
139 
140 	return op;
141 }
142 
143 static struct crypto_testsuite_params testsuite_params = { NULL };
144 static struct crypto_unittest_params unittest_params;
145 
146 static int
147 testsuite_setup(void)
148 {
149 	struct crypto_testsuite_params *ts_params = &testsuite_params;
150 	struct rte_cryptodev_info info;
151 	unsigned i, nb_devs, dev_id;
152 	int ret;
153 	uint16_t qp_id;
154 
155 	memset(ts_params, 0, sizeof(*ts_params));
156 
157 	ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
158 	if (ts_params->mbuf_pool == NULL) {
159 		/* Not already created so create */
160 		ts_params->mbuf_pool = rte_pktmbuf_pool_create(
161 				"CRYPTO_MBUFPOOL",
162 				NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
163 				rte_socket_id());
164 		if (ts_params->mbuf_pool == NULL) {
165 			RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
166 			return TEST_FAILED;
167 		}
168 	}
169 
170 	ts_params->op_mpool = rte_crypto_op_pool_create(
171 			"MBUF_CRYPTO_SYM_OP_POOL",
172 			RTE_CRYPTO_OP_TYPE_SYMMETRIC,
173 			NUM_MBUFS, MBUF_CACHE_SIZE,
174 			DEFAULT_NUM_XFORMS *
175 			sizeof(struct rte_crypto_sym_xform),
176 			rte_socket_id());
177 	if (ts_params->op_mpool == NULL) {
178 		RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
179 		return TEST_FAILED;
180 	}
181 
182 	/* Create 2 AESNI MB devices if required */
183 	if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
184 		nb_devs = rte_cryptodev_count_devtype(
185 				RTE_CRYPTODEV_AESNI_MB_PMD);
186 		if (nb_devs < 2) {
187 			for (i = nb_devs; i < 2; i++) {
188 				ret = rte_eal_vdev_init(
189 					CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
190 
191 				TEST_ASSERT(ret == 0,
192 					"Failed to create instance %u of"
193 					" pmd : %s",
194 					i, CRYPTODEV_NAME_AESNI_MB_PMD);
195 			}
196 		}
197 	}
198 
199 	/* Create 2 AESNI GCM devices if required */
200 	if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
201 		nb_devs = rte_cryptodev_count_devtype(
202 				RTE_CRYPTODEV_AESNI_GCM_PMD);
203 		if (nb_devs < 2) {
204 			for (i = nb_devs; i < 2; i++) {
205 				TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
206 					CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
207 					"Failed to create instance %u of"
208 					" pmd : %s",
209 					i, CRYPTODEV_NAME_AESNI_GCM_PMD);
210 			}
211 		}
212 	}
213 
214 	/* Create 2 Snow3G devices if required */
215 	if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
216 		nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
217 		if (nb_devs < 2) {
218 			for (i = nb_devs; i < 2; i++) {
219 				TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
220 					CRYPTODEV_NAME_SNOW3G_PMD, NULL),
221 					"Failed to create instance %u of"
222 					" pmd : %s",
223 					i, CRYPTODEV_NAME_SNOW3G_PMD);
224 			}
225 		}
226 	}
227 
228 	/* Create 2 KASUMI devices if required */
229 	if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
230 		nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
231 		if (nb_devs < 2) {
232 			for (i = nb_devs; i < 2; i++) {
233 				TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
234 					CRYPTODEV_NAME_KASUMI_PMD, NULL),
235 					"Failed to create instance %u of"
236 					" pmd : %s",
237 					i, CRYPTODEV_NAME_KASUMI_PMD);
238 			}
239 		}
240 	}
241 
242 	/* Create 2 NULL devices if required */
243 	if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
244 		nb_devs = rte_cryptodev_count_devtype(
245 				RTE_CRYPTODEV_NULL_PMD);
246 		if (nb_devs < 2) {
247 			for (i = nb_devs; i < 2; i++) {
248 				int dev_id = rte_eal_vdev_init(
249 					CRYPTODEV_NAME_NULL_PMD, NULL);
250 
251 				TEST_ASSERT(dev_id >= 0,
252 					"Failed to create instance %u of"
253 					" pmd : %s",
254 					i, CRYPTODEV_NAME_NULL_PMD);
255 			}
256 		}
257 	}
258 
259 	nb_devs = rte_cryptodev_count();
260 	if (nb_devs < 1) {
261 		RTE_LOG(ERR, USER1, "No crypto devices found?");
262 		return TEST_FAILED;
263 	}
264 
265 	/* Create list of valid crypto devs */
266 	for (i = 0; i < nb_devs; i++) {
267 		rte_cryptodev_info_get(i, &info);
268 		if (info.dev_type == gbl_cryptodev_type)
269 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
270 	}
271 
272 	if (ts_params->valid_dev_count < 1)
273 		return TEST_FAILED;
274 
275 	/* Set up all the qps on the first of the valid devices found */
276 	for (i = 0; i < 1; i++) {
277 		dev_id = ts_params->valid_devs[i];
278 
279 		rte_cryptodev_info_get(dev_id, &info);
280 
281 		/*
282 		 * Since we can't free and re-allocate queue memory always set
283 		 * the queues on this device up to max size first so enough
284 		 * memory is allocated for any later re-configures needed by
285 		 * other tests
286 		 */
287 
288 		ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
289 		ts_params->conf.socket_id = SOCKET_ID_ANY;
290 		ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
291 
292 		TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
293 				&ts_params->conf),
294 				"Failed to configure cryptodev %u with %u qps",
295 				dev_id, ts_params->conf.nb_queue_pairs);
296 
297 		ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
298 
299 		for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
300 			TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
301 					dev_id, qp_id, &ts_params->qp_conf,
302 					rte_cryptodev_socket_id(dev_id)),
303 					"Failed to setup queue pair %u on "
304 					"cryptodev %u",
305 					qp_id, dev_id);
306 		}
307 	}
308 
309 	return TEST_SUCCESS;
310 }
311 
312 static void
313 testsuite_teardown(void)
314 {
315 	struct crypto_testsuite_params *ts_params = &testsuite_params;
316 
317 	if (ts_params->mbuf_pool != NULL) {
318 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
319 		rte_mempool_count(ts_params->mbuf_pool));
320 	}
321 
322 	if (ts_params->op_mpool != NULL) {
323 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
324 		rte_mempool_count(ts_params->op_mpool));
325 	}
326 
327 }
328 
329 static int
330 ut_setup(void)
331 {
332 	struct crypto_testsuite_params *ts_params = &testsuite_params;
333 	struct crypto_unittest_params *ut_params = &unittest_params;
334 
335 	uint16_t qp_id;
336 
337 	/* Clear unit test parameters before running test */
338 	memset(ut_params, 0, sizeof(*ut_params));
339 
340 	/* Reconfigure device to default parameters */
341 	ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
342 	ts_params->conf.socket_id = SOCKET_ID_ANY;
343 	ts_params->conf.session_mp.nb_objs =
344 			(gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
345 					DEFAULT_NUM_OPS_INFLIGHT :
346 					DEFAULT_NUM_OPS_INFLIGHT;
347 
348 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
349 			&ts_params->conf),
350 			"Failed to configure cryptodev %u",
351 			ts_params->valid_devs[0]);
352 
353 	/*
354 	 * Now reconfigure queues to size we actually want to use in this
355 	 * test suite.
356 	 */
357 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
358 
359 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
360 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
361 			ts_params->valid_devs[0], qp_id,
362 			&ts_params->qp_conf,
363 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
364 			"Failed to setup queue pair %u on cryptodev %u",
365 			qp_id, ts_params->valid_devs[0]);
366 	}
367 
368 
369 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
370 
371 	/* Start the device */
372 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
373 			"Failed to start cryptodev %u",
374 			ts_params->valid_devs[0]);
375 
376 	return TEST_SUCCESS;
377 }
378 
379 static void
380 ut_teardown(void)
381 {
382 	struct crypto_testsuite_params *ts_params = &testsuite_params;
383 	struct crypto_unittest_params *ut_params = &unittest_params;
384 	struct rte_cryptodev_stats stats;
385 
386 	/* free crypto session structure */
387 	if (ut_params->sess) {
388 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
389 				ut_params->sess);
390 		ut_params->sess = NULL;
391 	}
392 
393 	/* free crypto operation structure */
394 	if (ut_params->op)
395 		rte_crypto_op_free(ut_params->op);
396 
397 	/*
398 	 * free mbuf - both obuf and ibuf are usually the same,
399 	 * but rte copes even if we call free twice
400 	 */
401 	if (ut_params->obuf) {
402 		rte_pktmbuf_free(ut_params->obuf);
403 		ut_params->obuf = 0;
404 	}
405 	if (ut_params->ibuf) {
406 		rte_pktmbuf_free(ut_params->ibuf);
407 		ut_params->ibuf = 0;
408 	}
409 
410 	if (ts_params->mbuf_pool != NULL)
411 		RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
412 				rte_mempool_count(ts_params->mbuf_pool));
413 
414 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
415 
416 	/* Stop the device */
417 	rte_cryptodev_stop(ts_params->valid_devs[0]);
418 }
419 
420 static int
421 test_device_configure_invalid_dev_id(void)
422 {
423 	struct crypto_testsuite_params *ts_params = &testsuite_params;
424 	uint16_t dev_id, num_devs = 0;
425 
426 	TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
427 			"Need at least %d devices for test", 1);
428 
429 	/* valid dev_id values */
430 	dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
431 
432 	/* Stop the device in case it's started so it can be configured */
433 	rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
434 
435 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
436 			"Failed test for rte_cryptodev_configure: "
437 			"invalid dev_num %u", dev_id);
438 
439 	/* invalid dev_id values */
440 	dev_id = num_devs;
441 
442 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
443 			"Failed test for rte_cryptodev_configure: "
444 			"invalid dev_num %u", dev_id);
445 
446 	dev_id = 0xff;
447 
448 	TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
449 			"Failed test for rte_cryptodev_configure:"
450 			"invalid dev_num %u", dev_id);
451 
452 	return TEST_SUCCESS;
453 }
454 
455 static int
456 test_device_configure_invalid_queue_pair_ids(void)
457 {
458 	struct crypto_testsuite_params *ts_params = &testsuite_params;
459 
460 	/* Stop the device in case it's started so it can be configured */
461 	rte_cryptodev_stop(ts_params->valid_devs[0]);
462 
463 	/* valid - one queue pairs */
464 	ts_params->conf.nb_queue_pairs = 1;
465 
466 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
467 			&ts_params->conf),
468 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
469 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
470 
471 
472 	/* valid - max value queue pairs */
473 	ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
474 
475 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
476 			&ts_params->conf),
477 			"Failed to configure cryptodev: dev_id %u, qp_id %u",
478 			ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
479 
480 
481 	/* invalid - zero queue pairs */
482 	ts_params->conf.nb_queue_pairs = 0;
483 
484 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
485 			&ts_params->conf),
486 			"Failed test for rte_cryptodev_configure, dev_id %u,"
487 			" invalid qps: %u",
488 			ts_params->valid_devs[0],
489 			ts_params->conf.nb_queue_pairs);
490 
491 
492 	/* invalid - max value supported by field queue pairs */
493 	ts_params->conf.nb_queue_pairs = UINT16_MAX;
494 
495 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
496 			&ts_params->conf),
497 			"Failed test for rte_cryptodev_configure, dev_id %u,"
498 			" invalid qps: %u",
499 			ts_params->valid_devs[0],
500 			ts_params->conf.nb_queue_pairs);
501 
502 
503 	/* invalid - max value + 1 queue pairs */
504 	ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
505 
506 	TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
507 			&ts_params->conf),
508 			"Failed test for rte_cryptodev_configure, dev_id %u,"
509 			" invalid qps: %u",
510 			ts_params->valid_devs[0],
511 			ts_params->conf.nb_queue_pairs);
512 
513 	return TEST_SUCCESS;
514 }
515 
516 static int
517 test_queue_pair_descriptor_setup(void)
518 {
519 	struct crypto_testsuite_params *ts_params = &testsuite_params;
520 	struct rte_cryptodev_info dev_info;
521 	struct rte_cryptodev_qp_conf qp_conf = {
522 		.nb_descriptors = MAX_NUM_OPS_INFLIGHT
523 	};
524 
525 	uint16_t qp_id;
526 
527 	/* Stop the device in case it's started so it can be configured */
528 	rte_cryptodev_stop(ts_params->valid_devs[0]);
529 
530 
531 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
532 
533 	ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
534 
535 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
536 			&ts_params->conf), "Failed to configure cryptodev %u",
537 			ts_params->valid_devs[0]);
538 
539 
540 	/*
541 	 * Test various ring sizes on this device. memzones can't be
542 	 * freed so are re-used if ring is released and re-created.
543 	 */
544 	qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
545 
546 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
547 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
548 				ts_params->valid_devs[0], qp_id, &qp_conf,
549 				rte_cryptodev_socket_id(
550 						ts_params->valid_devs[0])),
551 				"Failed test for "
552 				"rte_cryptodev_queue_pair_setup: num_inflights "
553 				"%u on qp %u on cryptodev %u",
554 				qp_conf.nb_descriptors, qp_id,
555 				ts_params->valid_devs[0]);
556 	}
557 
558 	qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
559 
560 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
561 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
562 				ts_params->valid_devs[0], qp_id, &qp_conf,
563 				rte_cryptodev_socket_id(
564 						ts_params->valid_devs[0])),
565 				"Failed test for"
566 				" rte_cryptodev_queue_pair_setup: num_inflights"
567 				" %u on qp %u on cryptodev %u",
568 				qp_conf.nb_descriptors, qp_id,
569 				ts_params->valid_devs[0]);
570 	}
571 
572 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
573 
574 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
575 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
576 				ts_params->valid_devs[0], qp_id, &qp_conf,
577 				rte_cryptodev_socket_id(
578 						ts_params->valid_devs[0])),
579 				"Failed test for "
580 				"rte_cryptodev_queue_pair_setup: num_inflights"
581 				" %u on qp %u on cryptodev %u",
582 				qp_conf.nb_descriptors, qp_id,
583 				ts_params->valid_devs[0]);
584 	}
585 
586 	/* invalid number of descriptors - max supported + 2 */
587 	qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
588 
589 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
590 		TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
591 				ts_params->valid_devs[0], qp_id, &qp_conf,
592 				rte_cryptodev_socket_id(
593 						ts_params->valid_devs[0])),
594 				"Unexpectedly passed test for "
595 				"rte_cryptodev_queue_pair_setup:"
596 				"num_inflights %u on qp %u on cryptodev %u",
597 				qp_conf.nb_descriptors, qp_id,
598 				ts_params->valid_devs[0]);
599 	}
600 
601 	/* invalid number of descriptors - max value of parameter */
602 	qp_conf.nb_descriptors = UINT32_MAX-1;
603 
604 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
605 		TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
606 				ts_params->valid_devs[0], qp_id, &qp_conf,
607 				rte_cryptodev_socket_id(
608 						ts_params->valid_devs[0])),
609 				"Unexpectedly passed test for "
610 				"rte_cryptodev_queue_pair_setup:"
611 				"num_inflights %u on qp %u on cryptodev %u",
612 				qp_conf.nb_descriptors, qp_id,
613 				ts_params->valid_devs[0]);
614 	}
615 
616 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
617 
618 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
619 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
620 				ts_params->valid_devs[0], qp_id, &qp_conf,
621 				rte_cryptodev_socket_id(
622 						ts_params->valid_devs[0])),
623 				"Failed test for"
624 				" rte_cryptodev_queue_pair_setup:"
625 				"num_inflights %u on qp %u on cryptodev %u",
626 				qp_conf.nb_descriptors, qp_id,
627 				ts_params->valid_devs[0]);
628 	}
629 
630 	/* invalid number of descriptors - max supported + 1 */
631 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
632 
633 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
634 		TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
635 				ts_params->valid_devs[0], qp_id, &qp_conf,
636 				rte_cryptodev_socket_id(
637 						ts_params->valid_devs[0])),
638 				"Unexpectedly passed test for "
639 				"rte_cryptodev_queue_pair_setup:"
640 				"num_inflights %u on qp %u on cryptodev %u",
641 				qp_conf.nb_descriptors, qp_id,
642 				ts_params->valid_devs[0]);
643 	}
644 
645 	/* test invalid queue pair id */
646 	qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;	/*valid */
647 
648 	qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE;		/*invalid */
649 
650 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
651 			ts_params->valid_devs[0],
652 			qp_id, &qp_conf,
653 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
654 			"Failed test for rte_cryptodev_queue_pair_setup:"
655 			"invalid qp %u on cryptodev %u",
656 			qp_id, ts_params->valid_devs[0]);
657 
658 	qp_id = 0xffff; /*invalid*/
659 
660 	TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
661 			ts_params->valid_devs[0],
662 			qp_id, &qp_conf,
663 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
664 			"Failed test for rte_cryptodev_queue_pair_setup:"
665 			"invalid qp %u on cryptodev %u",
666 			qp_id, ts_params->valid_devs[0]);
667 
668 	return TEST_SUCCESS;
669 }
670 
671 /* ***** Plaintext data for tests ***** */
672 
673 const char catch_22_quote_1[] =
674 		"There was only one catch and that was Catch-22, which "
675 		"specified that a concern for one's safety in the face of "
676 		"dangers that were real and immediate was the process of a "
677 		"rational mind. Orr was crazy and could be grounded. All he "
678 		"had to do was ask; and as soon as he did, he would no longer "
679 		"be crazy and would have to fly more missions. Orr would be "
680 		"crazy to fly more missions and sane if he didn't, but if he "
681 		"was sane he had to fly them. If he flew them he was crazy "
682 		"and didn't have to; but if he didn't want to he was sane and "
683 		"had to. Yossarian was moved very deeply by the absolute "
684 		"simplicity of this clause of Catch-22 and let out a "
685 		"respectful whistle. \"That's some catch, that Catch-22\", he "
686 		"observed. \"It's the best there is,\" Doc Daneeka agreed.";
687 
688 const char catch_22_quote[] =
689 		"What a lousy earth! He wondered how many people were "
690 		"destitute that same night even in his own prosperous country, "
691 		"how many homes were shanties, how many husbands were drunk "
692 		"and wives socked, and how many children were bullied, abused, "
693 		"or abandoned. How many families hungered for food they could "
694 		"not afford to buy? How many hearts were broken? How many "
695 		"suicides would take place that same night, how many people "
696 		"would go insane? How many cockroaches and landlords would "
697 		"triumph? How many winners were losers, successes failures, "
698 		"and rich men poor men? How many wise guys were stupid? How "
699 		"many happy endings were unhappy endings? How many honest men "
700 		"were liars, brave men cowards, loyal men traitors, how many "
701 		"sainted men were corrupt, how many people in positions of "
702 		"trust had sold their souls to bodyguards, how many had never "
703 		"had souls? How many straight-and-narrow paths were crooked "
704 		"paths? How many best families were worst families and how "
705 		"many good people were bad people? When you added them all up "
706 		"and then subtracted, you might be left with only the children, "
707 		"and perhaps with Albert Einstein and an old violinist or "
708 		"sculptor somewhere.";
709 
710 #define QUOTE_480_BYTES		(480)
711 #define QUOTE_512_BYTES		(512)
712 #define QUOTE_768_BYTES		(768)
713 #define QUOTE_1024_BYTES	(1024)
714 
715 
716 
717 /* ***** SHA1 Hash Tests ***** */
718 
719 #define HMAC_KEY_LENGTH_SHA1	(DIGEST_BYTE_LENGTH_SHA1)
720 
721 static uint8_t hmac_sha1_key[] = {
722 	0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
723 	0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
724 	0xDE, 0xF4, 0xDE, 0xAD };
725 
726 /* ***** SHA224 Hash Tests ***** */
727 
728 #define HMAC_KEY_LENGTH_SHA224	(DIGEST_BYTE_LENGTH_SHA224)
729 
730 
731 /* ***** AES-CBC Cipher Tests ***** */
732 
733 #define CIPHER_KEY_LENGTH_AES_CBC	(16)
734 #define CIPHER_IV_LENGTH_AES_CBC	(CIPHER_KEY_LENGTH_AES_CBC)
735 
736 static uint8_t aes_cbc_key[] = {
737 	0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
738 	0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
739 
740 static uint8_t aes_cbc_iv[] = {
741 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
742 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
743 
744 
745 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
746 
747 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
748 	0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
749 	0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
750 	0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
751 	0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
752 	0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
753 	0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
754 	0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
755 	0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
756 	0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
757 	0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
758 	0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
759 	0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
760 	0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
761 	0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
762 	0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
763 	0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
764 	0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
765 	0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
766 	0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
767 	0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
768 	0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
769 	0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
770 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
771 	0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
772 	0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
773 	0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
774 	0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
775 	0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
776 	0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
777 	0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
778 	0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
779 	0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
780 	0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
781 	0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
782 	0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
783 	0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
784 	0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
785 	0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
786 	0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
787 	0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
788 	0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
789 	0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
790 	0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
791 	0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
792 	0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
793 	0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
794 	0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
795 	0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
796 	0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
797 	0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
798 	0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
799 	0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
800 	0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
801 	0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
802 	0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
803 	0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
804 	0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
805 	0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
806 	0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
807 	0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
808 	0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
809 	0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
810 	0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
811 	0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
812 };
813 
814 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
815 	0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
816 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
817 	0x18, 0x8c, 0x1d, 0x32
818 };
819 
820 
821 static int
822 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
823 {
824 	struct crypto_testsuite_params *ts_params = &testsuite_params;
825 	struct crypto_unittest_params *ut_params = &unittest_params;
826 
827 	/* Generate test mbuf data and space for digest */
828 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
829 			catch_22_quote,	QUOTE_512_BYTES, 0);
830 
831 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
832 			DIGEST_BYTE_LENGTH_SHA1);
833 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
834 
835 	/* Setup Cipher Parameters */
836 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
837 	ut_params->cipher_xform.next = &ut_params->auth_xform;
838 
839 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
840 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
841 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
842 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
843 
844 	/* Setup HMAC Parameters */
845 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
846 
847 	ut_params->auth_xform.next = NULL;
848 
849 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
850 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
851 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
852 	ut_params->auth_xform.auth.key.data = hmac_sha1_key;
853 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
854 
855 	/* Create crypto session*/
856 	ut_params->sess = rte_cryptodev_sym_session_create(
857 			ts_params->valid_devs[0],
858 			&ut_params->cipher_xform);
859 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
860 
861 	/* Generate crypto op data structure */
862 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
863 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
864 	TEST_ASSERT_NOT_NULL(ut_params->op,
865 			"Failed to allocate symmetric crypto operation struct");
866 
867 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
868 
869 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
870 
871 	/* set crypto operation source mbuf */
872 	sym_op->m_src = ut_params->ibuf;
873 
874 	/* Set crypto operation authentication parameters */
875 	sym_op->auth.digest.data = ut_params->digest;
876 	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
877 			ut_params->ibuf, QUOTE_512_BYTES);
878 	sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
879 
880 	sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
881 	sym_op->auth.data.length = QUOTE_512_BYTES;
882 
883 	/* Set crypto operation cipher parameters */
884 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
885 			CIPHER_IV_LENGTH_AES_CBC);
886 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
887 	sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
888 
889 	rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
890 			CIPHER_IV_LENGTH_AES_CBC);
891 
892 	sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
893 	sym_op->cipher.data.length = QUOTE_512_BYTES;
894 
895 	/* Process crypto operation */
896 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
897 			ut_params->op), "failed to process sym crypto op");
898 
899 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
900 			"crypto op processing failed");
901 
902 	/* Validate obuf */
903 	uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
904 			uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
905 
906 	TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
907 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
908 			QUOTE_512_BYTES,
909 			"ciphertext data not as expected");
910 
911 	uint8_t *digest = ciphertext + QUOTE_512_BYTES;
912 
913 	TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
914 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
915 			gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
916 					TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
917 					DIGEST_BYTE_LENGTH_SHA1,
918 			"Generated digest data not as expected");
919 
920 	return TEST_SUCCESS;
921 }
922 
923 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
924 
925 #define HMAC_KEY_LENGTH_SHA512  (DIGEST_BYTE_LENGTH_SHA512)
926 
927 static uint8_t hmac_sha512_key[] = {
928 	0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
929 	0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
930 	0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
931 	0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
932 	0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
933 	0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
934 	0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
935 	0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
936 
937 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
938 	0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
939 	0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
940 	0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
941 	0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
942 	0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
943 	0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
944 	0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
945 	0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
946 
947 
948 
949 static int
950 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
951 		struct crypto_unittest_params *ut_params);
952 
953 static int
954 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
955 		struct crypto_unittest_params *ut_params,
956 		struct crypto_testsuite_params *ts_params);
957 
958 
959 static int
960 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
961 		struct crypto_unittest_params *ut_params)
962 {
963 
964 	/* Setup Cipher Parameters */
965 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
966 	ut_params->cipher_xform.next = NULL;
967 
968 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
969 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
970 	ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
971 	ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
972 
973 	/* Setup HMAC Parameters */
974 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
975 	ut_params->auth_xform.next = &ut_params->cipher_xform;
976 
977 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
978 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
979 	ut_params->auth_xform.auth.key.data = hmac_sha512_key;
980 	ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
981 	ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
982 
983 	return TEST_SUCCESS;
984 }
985 
986 
987 static int
988 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
989 		struct crypto_unittest_params *ut_params,
990 		struct crypto_testsuite_params *ts_params)
991 {
992 	/* Generate test mbuf data and digest */
993 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
994 			(const char *)
995 			catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
996 			QUOTE_512_BYTES, 0);
997 
998 	ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
999 			DIGEST_BYTE_LENGTH_SHA512);
1000 	TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1001 
1002 	rte_memcpy(ut_params->digest,
1003 			catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1004 			DIGEST_BYTE_LENGTH_SHA512);
1005 
1006 	/* Generate Crypto op data structure */
1007 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1008 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1009 	TEST_ASSERT_NOT_NULL(ut_params->op,
1010 			"Failed to allocate symmetric crypto operation struct");
1011 
1012 	rte_crypto_op_attach_sym_session(ut_params->op, sess);
1013 
1014 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1015 
1016 	/* set crypto operation source mbuf */
1017 	sym_op->m_src = ut_params->ibuf;
1018 
1019 	sym_op->auth.digest.data = ut_params->digest;
1020 	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1021 			ut_params->ibuf, QUOTE_512_BYTES);
1022 	sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1023 
1024 	sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1025 	sym_op->auth.data.length = QUOTE_512_BYTES;
1026 
1027 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1028 			ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1029 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1030 			ut_params->ibuf, 0);
1031 	sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1032 
1033 	rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1034 			CIPHER_IV_LENGTH_AES_CBC);
1035 
1036 	sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1037 	sym_op->cipher.data.length = QUOTE_512_BYTES;
1038 
1039 	/* Process crypto operation */
1040 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1041 			ut_params->op), "failed to process sym crypto op");
1042 
1043 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1044 			"crypto op processing failed");
1045 
1046 	ut_params->obuf = ut_params->op->sym->m_src;
1047 
1048 	/* Validate obuf */
1049 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
1050 			rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1051 			CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1052 			QUOTE_512_BYTES,
1053 			"Plaintext data not as expected");
1054 
1055 	/* Validate obuf */
1056 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1057 			"Digest verification failed");
1058 
1059 	return TEST_SUCCESS;
1060 }
1061 
1062 static int
1063 test_AES_mb_all(void)
1064 {
1065 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1066 	int status;
1067 
1068 	status = test_AES_all_tests(ts_params->mbuf_pool,
1069 		ts_params->op_mpool, ts_params->valid_devs[0],
1070 		RTE_CRYPTODEV_AESNI_MB_PMD);
1071 
1072 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1073 
1074 	return TEST_SUCCESS;
1075 }
1076 
1077 static int
1078 test_AES_qat_all(void)
1079 {
1080 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1081 	int status;
1082 
1083 	status = test_AES_all_tests(ts_params->mbuf_pool,
1084 		ts_params->op_mpool, ts_params->valid_devs[0],
1085 		RTE_CRYPTODEV_QAT_SYM_PMD);
1086 
1087 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1088 
1089 	return TEST_SUCCESS;
1090 }
1091 
1092 /* ***** Snow3G Tests ***** */
1093 static int
1094 create_snow3g_kasumi_hash_session(uint8_t dev_id,
1095 	const uint8_t *key, const uint8_t key_len,
1096 	const uint8_t aad_len, const uint8_t auth_len,
1097 	enum rte_crypto_auth_operation op,
1098 	enum rte_crypto_auth_algorithm algo)
1099 {
1100 	uint8_t hash_key[key_len];
1101 
1102 	struct crypto_unittest_params *ut_params = &unittest_params;
1103 
1104 	memcpy(hash_key, key, key_len);
1105 
1106 	TEST_HEXDUMP(stdout, "key:", key, key_len);
1107 
1108 	/* Setup Authentication Parameters */
1109 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1110 	ut_params->auth_xform.next = NULL;
1111 
1112 	ut_params->auth_xform.auth.op = op;
1113 	ut_params->auth_xform.auth.algo = algo;
1114 	ut_params->auth_xform.auth.key.length = key_len;
1115 	ut_params->auth_xform.auth.key.data = hash_key;
1116 	ut_params->auth_xform.auth.digest_length = auth_len;
1117 	ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1118 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1119 				&ut_params->auth_xform);
1120 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1121 	return 0;
1122 }
1123 
1124 static int
1125 create_snow3g_kasumi_cipher_session(uint8_t dev_id,
1126 			enum rte_crypto_cipher_operation op,
1127 			enum rte_crypto_cipher_algorithm algo,
1128 			const uint8_t *key, const uint8_t key_len)
1129 {
1130 	uint8_t cipher_key[key_len];
1131 
1132 	struct crypto_unittest_params *ut_params = &unittest_params;
1133 
1134 	memcpy(cipher_key, key, key_len);
1135 
1136 	/* Setup Cipher Parameters */
1137 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1138 	ut_params->cipher_xform.next = NULL;
1139 
1140 	ut_params->cipher_xform.cipher.algo = algo;
1141 	ut_params->cipher_xform.cipher.op = op;
1142 	ut_params->cipher_xform.cipher.key.data = cipher_key;
1143 	ut_params->cipher_xform.cipher.key.length = key_len;
1144 
1145 	TEST_HEXDUMP(stdout, "key:", key, key_len);
1146 
1147 	/* Create Crypto session */
1148 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1149 						&ut_params->
1150 						cipher_xform);
1151 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1152 	return 0;
1153 }
1154 
1155 static int
1156 create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1157 			const unsigned cipher_len,
1158 			const unsigned cipher_offset,
1159 			enum rte_crypto_cipher_algorithm algo)
1160 {
1161 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1162 	struct crypto_unittest_params *ut_params = &unittest_params;
1163 	unsigned iv_pad_len = 0;
1164 
1165 	/* Generate Crypto op data structure */
1166 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1167 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1168 	TEST_ASSERT_NOT_NULL(ut_params->op,
1169 				"Failed to allocate pktmbuf offload");
1170 
1171 	/* Set crypto operation data parameters */
1172 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1173 
1174 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1175 
1176 	/* set crypto operation source mbuf */
1177 	sym_op->m_src = ut_params->ibuf;
1178 
1179 	/* iv */
1180 	if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1181 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1182 	else
1183 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1184 
1185 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1186 			, iv_pad_len);
1187 
1188 	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1189 
1190 	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1191 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1192 	sym_op->cipher.iv.length = iv_pad_len;
1193 
1194 	rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1195 	sym_op->cipher.data.length = cipher_len;
1196 	sym_op->cipher.data.offset = cipher_offset;
1197 	return 0;
1198 }
1199 
1200 static int
1201 create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1202 			const unsigned cipher_len,
1203 			const unsigned cipher_offset,
1204 			enum rte_crypto_cipher_algorithm algo)
1205 {
1206 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1207 	struct crypto_unittest_params *ut_params = &unittest_params;
1208 	unsigned iv_pad_len = 0;
1209 
1210 	/* Generate Crypto op data structure */
1211 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1212 				RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1213 	TEST_ASSERT_NOT_NULL(ut_params->op,
1214 				"Failed to allocate pktmbuf offload");
1215 
1216 	/* Set crypto operation data parameters */
1217 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1218 
1219 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1220 
1221 	/* set crypto operation source mbuf */
1222 	sym_op->m_src = ut_params->ibuf;
1223 	sym_op->m_dst = ut_params->obuf;
1224 
1225 	/* iv */
1226 	if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1227 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1228 	else
1229 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1230 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1231 					iv_pad_len);
1232 
1233 	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1234 
1235 	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1236 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1237 	sym_op->cipher.iv.length = iv_pad_len;
1238 
1239 	rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1240 	sym_op->cipher.data.length = cipher_len;
1241 	sym_op->cipher.data.offset = cipher_offset;
1242 	return 0;
1243 }
1244 
1245 static int
1246 create_snow3g_kasumi_cipher_auth_session(uint8_t dev_id,
1247 		enum rte_crypto_cipher_operation cipher_op,
1248 		enum rte_crypto_auth_operation auth_op,
1249 		enum rte_crypto_auth_algorithm auth_algo,
1250 		enum rte_crypto_cipher_algorithm cipher_algo,
1251 		const uint8_t *key, const uint8_t key_len,
1252 		const uint8_t aad_len, const uint8_t auth_len)
1253 
1254 {
1255 	uint8_t cipher_auth_key[key_len];
1256 
1257 	struct crypto_unittest_params *ut_params = &unittest_params;
1258 
1259 	memcpy(cipher_auth_key, key, key_len);
1260 
1261 	/* Setup Authentication Parameters */
1262 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1263 	ut_params->auth_xform.next = NULL;
1264 
1265 	ut_params->auth_xform.auth.op = auth_op;
1266 	ut_params->auth_xform.auth.algo = auth_algo;
1267 	ut_params->auth_xform.auth.key.length = key_len;
1268 	/* Hash key = cipher key */
1269 	ut_params->auth_xform.auth.key.data = cipher_auth_key;
1270 	ut_params->auth_xform.auth.digest_length = auth_len;
1271 	ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1272 
1273 	/* Setup Cipher Parameters */
1274 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1275 	ut_params->cipher_xform.next = &ut_params->auth_xform;
1276 
1277 	ut_params->cipher_xform.cipher.algo = cipher_algo;
1278 	ut_params->cipher_xform.cipher.op = cipher_op;
1279 	ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1280 	ut_params->cipher_xform.cipher.key.length = key_len;
1281 
1282 	TEST_HEXDUMP(stdout, "key:", key, key_len);
1283 
1284 	/* Create Crypto session*/
1285 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1286 				&ut_params->cipher_xform);
1287 
1288 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1289 	return 0;
1290 }
1291 
1292 static int
1293 create_snow3g_kasumi_auth_cipher_session(uint8_t dev_id,
1294 		enum rte_crypto_cipher_operation cipher_op,
1295 		enum rte_crypto_auth_operation auth_op,
1296 		enum rte_crypto_auth_algorithm auth_algo,
1297 		enum rte_crypto_cipher_algorithm cipher_algo,
1298 		const uint8_t *key, const uint8_t key_len,
1299 		const uint8_t aad_len, const uint8_t auth_len)
1300 {
1301 	uint8_t auth_cipher_key[key_len];
1302 
1303 	struct crypto_unittest_params *ut_params = &unittest_params;
1304 
1305 	memcpy(auth_cipher_key, key, key_len);
1306 
1307 	/* Setup Authentication Parameters */
1308 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1309 	ut_params->auth_xform.auth.op = auth_op;
1310 	ut_params->auth_xform.next = &ut_params->cipher_xform;
1311 	ut_params->auth_xform.auth.algo = auth_algo;
1312 	ut_params->auth_xform.auth.key.length = key_len;
1313 	ut_params->auth_xform.auth.key.data = auth_cipher_key;
1314 	ut_params->auth_xform.auth.digest_length = auth_len;
1315 	ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1316 
1317 	/* Setup Cipher Parameters */
1318 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1319 	ut_params->cipher_xform.next = NULL;
1320 	ut_params->cipher_xform.cipher.algo = cipher_algo;
1321 	ut_params->cipher_xform.cipher.op = cipher_op;
1322 	ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1323 	ut_params->cipher_xform.cipher.key.length = key_len;
1324 
1325 	TEST_HEXDUMP(stdout, "key:", key, key_len);
1326 
1327 	/* Create Crypto session*/
1328 	ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1329 				&ut_params->auth_xform);
1330 
1331 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1332 
1333 	return 0;
1334 }
1335 
1336 static int
1337 create_snow3g_kasumi_hash_operation(const uint8_t *auth_tag,
1338 		const unsigned auth_tag_len,
1339 		const uint8_t *aad, const unsigned aad_len,
1340 		unsigned data_pad_len,
1341 		enum rte_crypto_auth_operation op,
1342 		enum rte_crypto_auth_algorithm algo,
1343 		const unsigned auth_len, const unsigned auth_offset)
1344 {
1345 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1346 
1347 	struct crypto_unittest_params *ut_params = &unittest_params;
1348 
1349 	unsigned aad_buffer_len;
1350 
1351 	/* Generate Crypto op data structure */
1352 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1353 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1354 	TEST_ASSERT_NOT_NULL(ut_params->op,
1355 		"Failed to allocate pktmbuf offload");
1356 
1357 	/* Set crypto operation data parameters */
1358 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1359 
1360 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1361 
1362 	/* set crypto operation source mbuf */
1363 	sym_op->m_src = ut_params->ibuf;
1364 
1365 	/* aad */
1366 	/*
1367 	* Always allocate the aad up to the block size.
1368 	* The cryptodev API calls out -
1369 	*  - the array must be big enough to hold the AAD, plus any
1370 	*   space to round this up to the nearest multiple of the
1371 	*   block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
1372 	*/
1373 	if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1374 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1375 	else
1376 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1377 	sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1378 			ut_params->ibuf, aad_buffer_len);
1379 	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1380 					"no room to prepend aad");
1381 	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1382 			ut_params->ibuf);
1383 	sym_op->auth.aad.length = aad_len;
1384 
1385 	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1386 	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1387 
1388 	TEST_HEXDUMP(stdout, "aad:",
1389 			sym_op->auth.aad.data, aad_len);
1390 
1391 	/* digest */
1392 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1393 					ut_params->ibuf, auth_tag_len);
1394 
1395 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1396 				"no room to append auth tag");
1397 	ut_params->digest = sym_op->auth.digest.data;
1398 	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1399 			ut_params->ibuf, data_pad_len + aad_len);
1400 	sym_op->auth.digest.length = auth_tag_len;
1401 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1402 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
1403 	else
1404 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1405 
1406 	TEST_HEXDUMP(stdout, "digest:",
1407 		sym_op->auth.digest.data,
1408 		sym_op->auth.digest.length);
1409 
1410 	sym_op->auth.data.length = auth_len;
1411 	sym_op->auth.data.offset = auth_offset;
1412 
1413 	return 0;
1414 }
1415 
1416 static int
1417 create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
1418 		const unsigned auth_tag_len,
1419 		const uint8_t *aad, const uint8_t aad_len,
1420 		unsigned data_pad_len,
1421 		enum rte_crypto_auth_operation op,
1422 		enum rte_crypto_auth_algorithm auth_algo,
1423 		enum rte_crypto_cipher_algorithm cipher_algo,
1424 		const uint8_t *iv, const uint8_t iv_len,
1425 		const unsigned cipher_len, const unsigned cipher_offset,
1426 		const unsigned auth_len, const unsigned auth_offset)
1427 {
1428 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1429 	struct crypto_unittest_params *ut_params = &unittest_params;
1430 
1431 	unsigned iv_pad_len = 0;
1432 	unsigned aad_buffer_len;
1433 
1434 	/* Generate Crypto op data structure */
1435 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1436 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1437 	TEST_ASSERT_NOT_NULL(ut_params->op,
1438 			"Failed to allocate pktmbuf offload");
1439 	/* Set crypto operation data parameters */
1440 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1441 
1442 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1443 
1444 	/* set crypto operation source mbuf */
1445 	sym_op->m_src = ut_params->ibuf;
1446 
1447 
1448 	/* iv */
1449 	if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1450 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1451 	else
1452 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1453 
1454 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1455 		ut_params->ibuf, iv_pad_len);
1456 	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1457 
1458 	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1459 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1460 	sym_op->cipher.iv.length = iv_pad_len;
1461 
1462 	rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1463 
1464 	sym_op->cipher.data.length = cipher_len;
1465 	sym_op->cipher.data.offset = cipher_offset;
1466 
1467 	/* aad */
1468 	/*
1469 	* Always allocate the aad up to the block size.
1470 	* The cryptodev API calls out -
1471 	*  - the array must be big enough to hold the AAD, plus any
1472 	*   space to round this up to the nearest multiple of the
1473 	*   block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
1474 	*/
1475 	if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1476 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1477 	else
1478 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1479 
1480 	sym_op->auth.aad.data =
1481 			(uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1482 	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1483 			"no room to prepend aad");
1484 	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1485 			ut_params->ibuf);
1486 	sym_op->auth.aad.length = aad_len;
1487 
1488 	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1489 	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1490 
1491 	TEST_HEXDUMP(stdout, "aad:",
1492 			sym_op->auth.aad.data, aad_len);
1493 
1494 	/* digest */
1495 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1496 			ut_params->ibuf, auth_tag_len);
1497 
1498 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1499 			"no room to append auth tag");
1500 	ut_params->digest = sym_op->auth.digest.data;
1501 	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1502 			ut_params->ibuf, data_pad_len + aad_len);
1503 	sym_op->auth.digest.length = auth_tag_len;
1504 	if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1505 		memset(sym_op->auth.digest.data, 0, auth_tag_len);
1506 	else
1507 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1508 
1509 	TEST_HEXDUMP(stdout, "digest:",
1510 		sym_op->auth.digest.data,
1511 		sym_op->auth.digest.length);
1512 
1513 	sym_op->auth.data.length = auth_len;
1514 	sym_op->auth.data.offset = auth_offset;
1515 
1516 	return 0;
1517 }
1518 
1519 static int
1520 create_snow3g_kasumi_auth_cipher_operation(const unsigned auth_tag_len,
1521 		const uint8_t *iv, const uint8_t iv_len,
1522 		const uint8_t *aad, const uint8_t aad_len,
1523 		unsigned data_pad_len,
1524 		const unsigned cipher_len, const unsigned cipher_offset,
1525 		const unsigned auth_len, const unsigned auth_offset,
1526 		enum rte_crypto_auth_algorithm auth_algo,
1527 		enum rte_crypto_cipher_algorithm cipher_algo)
1528 {
1529 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1530 	struct crypto_unittest_params *ut_params = &unittest_params;
1531 
1532 	unsigned iv_pad_len = 0;
1533 	unsigned aad_buffer_len = 0;
1534 
1535 	/* Generate Crypto op data structure */
1536 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1537 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1538 	TEST_ASSERT_NOT_NULL(ut_params->op,
1539 			"Failed to allocate pktmbuf offload");
1540 
1541 	/* Set crypto operation data parameters */
1542 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1543 
1544 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1545 
1546 	/* set crypto operation source mbuf */
1547 	sym_op->m_src = ut_params->ibuf;
1548 
1549 	/* digest */
1550 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1551 			ut_params->ibuf, auth_tag_len);
1552 
1553 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1554 			"no room to append auth tag");
1555 
1556 	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1557 			ut_params->ibuf, data_pad_len);
1558 	sym_op->auth.digest.length = auth_tag_len;
1559 
1560 	memset(sym_op->auth.digest.data, 0, auth_tag_len);
1561 
1562 	TEST_HEXDUMP(stdout, "digest:",
1563 			sym_op->auth.digest.data,
1564 			sym_op->auth.digest.length);
1565 
1566 	/* iv */
1567 	if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1568 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1569 	else
1570 		iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1571 
1572 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1573 		ut_params->ibuf, iv_pad_len);
1574 	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1575 
1576 	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1577 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1578 	sym_op->cipher.iv.length = iv_pad_len;
1579 
1580 	rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1581 
1582 	/* aad */
1583 	/*
1584 	* Always allocate the aad up to the block size.
1585 	* The cryptodev API calls out -
1586 	*  - the array must be big enough to hold the AAD, plus any
1587 	*   space to round this up to the nearest multiple of the
1588 	*   block size (8 bytes for KASUMI 16 bytes).
1589 	*/
1590 	if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1591 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1592 	else
1593 		aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1594 
1595 	sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1596 	ut_params->ibuf, aad_buffer_len);
1597 	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1598 				"no room to prepend aad");
1599 	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1600 				ut_params->ibuf);
1601 	sym_op->auth.aad.length = aad_len;
1602 
1603 	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1604 	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1605 
1606 	TEST_HEXDUMP(stdout, "aad:",
1607 			sym_op->auth.aad.data, aad_len);
1608 
1609 	sym_op->cipher.data.length = cipher_len;
1610 	sym_op->cipher.data.offset = auth_offset + cipher_offset;
1611 
1612 	sym_op->auth.data.length = auth_len;
1613 	sym_op->auth.data.offset = auth_offset + cipher_offset;
1614 
1615 	return 0;
1616 }
1617 
1618 static int
1619 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1620 {
1621 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1622 	struct crypto_unittest_params *ut_params = &unittest_params;
1623 
1624 	int retval;
1625 	unsigned plaintext_pad_len;
1626 	unsigned plaintext_len;
1627 	uint8_t *plaintext;
1628 
1629 	/* Create SNOW3G session */
1630 	retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1631 			tdata->key.data, tdata->key.len,
1632 			tdata->aad.len, tdata->digest.len,
1633 			RTE_CRYPTO_AUTH_OP_GENERATE,
1634 			RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1635 	if (retval < 0)
1636 		return retval;
1637 
1638 	/* alloc mbuf and set payload */
1639 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1640 
1641 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1642 	rte_pktmbuf_tailroom(ut_params->ibuf));
1643 
1644 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
1645 	/* Append data which is padded to a multiple of */
1646 	/* the algorithms block size */
1647 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1648 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1649 				plaintext_pad_len);
1650 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1651 
1652 	/* Create SNOW3G operation */
1653 	retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1654 			tdata->aad.data, tdata->aad.len,
1655 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1656 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1657 			tdata->validAuthLenInBits.len,
1658 			tdata->validAuthOffsetLenInBits.len);
1659 	if (retval < 0)
1660 		return retval;
1661 
1662 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1663 				ut_params->op);
1664 	ut_params->obuf = ut_params->op->sym->m_src;
1665 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1666 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1667 			+ plaintext_pad_len + tdata->aad.len;
1668 
1669 	/* Validate obuf */
1670 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
1671 	ut_params->digest,
1672 	tdata->digest.data,
1673 	DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1674 	"Snow3G Generated auth tag not as expected");
1675 
1676 	return 0;
1677 }
1678 
1679 static int
1680 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1681 {
1682 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1683 	struct crypto_unittest_params *ut_params = &unittest_params;
1684 
1685 	int retval;
1686 	unsigned plaintext_pad_len;
1687 	unsigned plaintext_len;
1688 	uint8_t *plaintext;
1689 
1690 	/* Create SNOW3G session */
1691 	retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1692 				tdata->key.data, tdata->key.len,
1693 				tdata->aad.len, tdata->digest.len,
1694 				RTE_CRYPTO_AUTH_OP_VERIFY,
1695 				RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1696 	if (retval < 0)
1697 		return retval;
1698 	/* alloc mbuf and set payload */
1699 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1700 
1701 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1702 	rte_pktmbuf_tailroom(ut_params->ibuf));
1703 
1704 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
1705 	/* Append data which is padded to a multiple of */
1706 	/* the algorithms block size */
1707 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1708 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1709 				plaintext_pad_len);
1710 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1711 
1712 	/* Create SNOW3G operation */
1713 	retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1714 			tdata->digest.len,
1715 			tdata->aad.data, tdata->aad.len,
1716 			plaintext_pad_len,
1717 			RTE_CRYPTO_AUTH_OP_VERIFY,
1718 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1719 			tdata->validAuthLenInBits.len,
1720 			tdata->validAuthOffsetLenInBits.len);
1721 	if (retval < 0)
1722 		return retval;
1723 
1724 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1725 				ut_params->op);
1726 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1727 	ut_params->obuf = ut_params->op->sym->m_src;
1728 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1729 				+ plaintext_pad_len + tdata->aad.len;
1730 
1731 	/* Validate obuf */
1732 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1733 		return 0;
1734 	else
1735 		return -1;
1736 
1737 	return 0;
1738 }
1739 
1740 static int
1741 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1742 {
1743 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1744 	struct crypto_unittest_params *ut_params = &unittest_params;
1745 
1746 	int retval;
1747 	unsigned plaintext_pad_len;
1748 	unsigned plaintext_len;
1749 	uint8_t *plaintext;
1750 
1751 	/* Create KASUMI session */
1752 	retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1753 			tdata->key.data, tdata->key.len,
1754 			tdata->aad.len, tdata->digest.len,
1755 			RTE_CRYPTO_AUTH_OP_GENERATE,
1756 			RTE_CRYPTO_AUTH_KASUMI_F9);
1757 	if (retval < 0)
1758 		return retval;
1759 
1760 	/* alloc mbuf and set payload */
1761 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1762 
1763 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1764 	rte_pktmbuf_tailroom(ut_params->ibuf));
1765 
1766 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
1767 	/* Append data which is padded to a multiple of */
1768 	/* the algorithms block size */
1769 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1770 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1771 				plaintext_pad_len);
1772 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1773 
1774 	/* Create KASUMI operation */
1775 	retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1776 			tdata->aad.data, tdata->aad.len,
1777 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1778 			RTE_CRYPTO_AUTH_KASUMI_F9,
1779 			tdata->validAuthLenInBits.len,
1780 			tdata->validAuthOffsetLenInBits.len);
1781 	if (retval < 0)
1782 		return retval;
1783 
1784 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1785 				ut_params->op);
1786 	ut_params->obuf = ut_params->op->sym->m_src;
1787 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1788 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1789 			+ plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1790 
1791 	/* Validate obuf */
1792 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
1793 	ut_params->digest,
1794 	tdata->digest.data,
1795 	DIGEST_BYTE_LENGTH_KASUMI_F9,
1796 	"KASUMI Generated auth tag not as expected");
1797 
1798 	return 0;
1799 }
1800 
1801 static int
1802 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1803 {
1804 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1805 	struct crypto_unittest_params *ut_params = &unittest_params;
1806 
1807 	int retval;
1808 	unsigned plaintext_pad_len;
1809 	unsigned plaintext_len;
1810 	uint8_t *plaintext;
1811 
1812 	/* Create KASUMI session */
1813 	retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1814 				tdata->key.data, tdata->key.len,
1815 				tdata->aad.len, tdata->digest.len,
1816 				RTE_CRYPTO_AUTH_OP_VERIFY,
1817 				RTE_CRYPTO_AUTH_KASUMI_F9);
1818 	if (retval < 0)
1819 		return retval;
1820 	/* alloc mbuf and set payload */
1821 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1822 
1823 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1824 	rte_pktmbuf_tailroom(ut_params->ibuf));
1825 
1826 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
1827 	/* Append data which is padded to a multiple */
1828 	/* of the algorithms block size */
1829 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1830 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1831 				plaintext_pad_len);
1832 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1833 
1834 	/* Create KASUMI operation */
1835 	retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1836 			tdata->digest.len,
1837 			tdata->aad.data, tdata->aad.len,
1838 			plaintext_pad_len,
1839 			RTE_CRYPTO_AUTH_OP_VERIFY,
1840 			RTE_CRYPTO_AUTH_KASUMI_F9,
1841 			tdata->validAuthLenInBits.len,
1842 			tdata->validAuthOffsetLenInBits.len);
1843 	if (retval < 0)
1844 		return retval;
1845 
1846 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1847 				ut_params->op);
1848 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1849 	ut_params->obuf = ut_params->op->sym->m_src;
1850 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1851 				+ plaintext_pad_len + tdata->aad.len;
1852 
1853 	/* Validate obuf */
1854 	if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1855 		return 0;
1856 	else
1857 		return -1;
1858 
1859 	return 0;
1860 }
1861 
1862 static int
1863 test_snow3g_hash_generate_test_case_1(void)
1864 {
1865 	return test_snow3g_authentication(&snow3g_hash_test_case_1);
1866 }
1867 
1868 static int
1869 test_snow3g_hash_generate_test_case_2(void)
1870 {
1871 	return test_snow3g_authentication(&snow3g_hash_test_case_2);
1872 }
1873 
1874 static int
1875 test_snow3g_hash_generate_test_case_3(void)
1876 {
1877 	return test_snow3g_authentication(&snow3g_hash_test_case_3);
1878 }
1879 
1880 static int
1881 test_snow3g_hash_generate_test_case_4(void)
1882 {
1883 	return test_snow3g_authentication(&snow3g_hash_test_case_4);
1884 }
1885 
1886 static int
1887 test_snow3g_hash_generate_test_case_5(void)
1888 {
1889 	return test_snow3g_authentication(&snow3g_hash_test_case_5);
1890 }
1891 
1892 static int
1893 test_snow3g_hash_generate_test_case_6(void)
1894 {
1895 	return test_snow3g_authentication(&snow3g_hash_test_case_6);
1896 }
1897 
1898 static int
1899 test_snow3g_hash_verify_test_case_1(void)
1900 {
1901 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1902 
1903 }
1904 
1905 static int
1906 test_snow3g_hash_verify_test_case_2(void)
1907 {
1908 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1909 }
1910 
1911 static int
1912 test_snow3g_hash_verify_test_case_3(void)
1913 {
1914 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1915 }
1916 
1917 static int
1918 test_snow3g_hash_verify_test_case_4(void)
1919 {
1920 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
1921 }
1922 
1923 static int
1924 test_snow3g_hash_verify_test_case_5(void)
1925 {
1926 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
1927 }
1928 
1929 static int
1930 test_snow3g_hash_verify_test_case_6(void)
1931 {
1932 	return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
1933 }
1934 
1935 static int
1936 test_kasumi_hash_generate_test_case_1(void)
1937 {
1938 	return test_kasumi_authentication(&kasumi_hash_test_case_1);
1939 }
1940 
1941 static int
1942 test_kasumi_hash_generate_test_case_2(void)
1943 {
1944 	return test_kasumi_authentication(&kasumi_hash_test_case_2);
1945 }
1946 
1947 static int
1948 test_kasumi_hash_generate_test_case_3(void)
1949 {
1950 	return test_kasumi_authentication(&kasumi_hash_test_case_3);
1951 }
1952 
1953 static int
1954 test_kasumi_hash_generate_test_case_4(void)
1955 {
1956 	return test_kasumi_authentication(&kasumi_hash_test_case_4);
1957 }
1958 
1959 static int
1960 test_kasumi_hash_generate_test_case_5(void)
1961 {
1962 	return test_kasumi_authentication(&kasumi_hash_test_case_5);
1963 }
1964 
1965 static int
1966 test_kasumi_hash_verify_test_case_1(void)
1967 {
1968 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
1969 }
1970 
1971 static int
1972 test_kasumi_hash_verify_test_case_2(void)
1973 {
1974 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
1975 }
1976 
1977 static int
1978 test_kasumi_hash_verify_test_case_3(void)
1979 {
1980 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
1981 }
1982 
1983 static int
1984 test_kasumi_hash_verify_test_case_4(void)
1985 {
1986 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
1987 }
1988 
1989 static int
1990 test_kasumi_hash_verify_test_case_5(void)
1991 {
1992 	return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
1993 }
1994 
1995 static int
1996 test_kasumi_encryption(const struct kasumi_test_data *tdata)
1997 {
1998 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1999 	struct crypto_unittest_params *ut_params = &unittest_params;
2000 
2001 	int retval;
2002 	uint8_t *plaintext, *ciphertext;
2003 	unsigned plaintext_pad_len;
2004 	unsigned plaintext_len;
2005 
2006 	/* Create KASUMI session */
2007 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2008 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2009 					RTE_CRYPTO_CIPHER_KASUMI_F8,
2010 					tdata->key.data, tdata->key.len);
2011 	if (retval < 0)
2012 		return retval;
2013 
2014 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2015 
2016 	/* Clear mbuf payload */
2017 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2018 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2019 
2020 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2021 	/* Append data which is padded to a multiple */
2022 	/* of the algorithms block size */
2023 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2024 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2025 				plaintext_pad_len);
2026 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2027 
2028 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2029 
2030 	/* Create KASUMI operation */
2031 	retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2032 					tdata->plaintext.len,
2033 					tdata->validCipherOffsetLenInBits.len,
2034 					RTE_CRYPTO_CIPHER_KASUMI_F8);
2035 	if (retval < 0)
2036 		return retval;
2037 
2038 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2039 						ut_params->op);
2040 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2041 
2042 	ut_params->obuf = ut_params->op->sym->m_dst;
2043 	if (ut_params->obuf)
2044 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2045 				+ tdata->iv.len;
2046 	else
2047 		ciphertext = plaintext;
2048 
2049 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2050 
2051 	/* Validate obuf */
2052 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2053 		ciphertext,
2054 		tdata->ciphertext.data,
2055 		tdata->validCipherLenInBits.len,
2056 		"KASUMI Ciphertext data not as expected");
2057 	return 0;
2058 }
2059 
2060 static int
2061 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2062 {
2063 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2064 	struct crypto_unittest_params *ut_params = &unittest_params;
2065 
2066 	int retval;
2067 	uint8_t *plaintext, *ciphertext;
2068 	unsigned plaintext_pad_len;
2069 	unsigned plaintext_len;
2070 
2071 	/* Create KASUMI session */
2072 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2073 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2074 					RTE_CRYPTO_CIPHER_KASUMI_F8,
2075 					tdata->key.data, tdata->key.len);
2076 	if (retval < 0)
2077 		return retval;
2078 
2079 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2080 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2081 
2082 	/* Clear mbuf payload */
2083 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2084 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2085 
2086 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2087 	/* Append data which is padded to a multiple */
2088 	/* of the algorithms block size */
2089 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2090 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2091 				plaintext_pad_len);
2092 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2093 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2094 
2095 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2096 
2097 	/* Create KASUMI operation */
2098 	retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2099 					tdata->iv.len,
2100 					tdata->plaintext.len,
2101 					tdata->validCipherOffsetLenInBits.len,
2102 					RTE_CRYPTO_CIPHER_KASUMI_F8);
2103 	if (retval < 0)
2104 		return retval;
2105 
2106 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2107 						ut_params->op);
2108 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2109 
2110 	ut_params->obuf = ut_params->op->sym->m_dst;
2111 	if (ut_params->obuf)
2112 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2113 				+ tdata->iv.len;
2114 	else
2115 		ciphertext = plaintext;
2116 
2117 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2118 
2119 	/* Validate obuf */
2120 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2121 		ciphertext,
2122 		tdata->ciphertext.data,
2123 		tdata->validCipherLenInBits.len,
2124 		"KASUMI Ciphertext data not as expected");
2125 	return 0;
2126 }
2127 
2128 static int
2129 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2130 {
2131 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2132 	struct crypto_unittest_params *ut_params = &unittest_params;
2133 
2134 	int retval;
2135 	uint8_t *ciphertext, *plaintext;
2136 	unsigned ciphertext_pad_len;
2137 	unsigned ciphertext_len;
2138 
2139 	/* Create KASUMI session */
2140 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2141 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
2142 					RTE_CRYPTO_CIPHER_KASUMI_F8,
2143 					tdata->key.data, tdata->key.len);
2144 	if (retval < 0)
2145 		return retval;
2146 
2147 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2148 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2149 
2150 	/* Clear mbuf payload */
2151 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2152 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2153 
2154 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2155 	/* Append data which is padded to a multiple */
2156 	/* of the algorithms block size */
2157 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2158 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2159 				ciphertext_pad_len);
2160 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2161 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2162 
2163 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2164 
2165 	/* Create KASUMI operation */
2166 	retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2167 					tdata->iv.len,
2168 					tdata->ciphertext.len,
2169 					tdata->validCipherOffsetLenInBits.len,
2170 					RTE_CRYPTO_CIPHER_KASUMI_F8);
2171 	if (retval < 0)
2172 		return retval;
2173 
2174 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2175 						ut_params->op);
2176 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2177 
2178 	ut_params->obuf = ut_params->op->sym->m_dst;
2179 	if (ut_params->obuf)
2180 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2181 				+ tdata->iv.len;
2182 	else
2183 		plaintext = ciphertext;
2184 
2185 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2186 
2187 	/* Validate obuf */
2188 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2189 		plaintext,
2190 		tdata->plaintext.data,
2191 		tdata->validCipherLenInBits.len,
2192 		"KASUMI Plaintext data not as expected");
2193 	return 0;
2194 }
2195 
2196 static int
2197 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2198 {
2199 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2200 	struct crypto_unittest_params *ut_params = &unittest_params;
2201 
2202 	int retval;
2203 	uint8_t *ciphertext, *plaintext;
2204 	unsigned ciphertext_pad_len;
2205 	unsigned ciphertext_len;
2206 
2207 	/* Create KASUMI session */
2208 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2209 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
2210 					RTE_CRYPTO_CIPHER_KASUMI_F8,
2211 					tdata->key.data, tdata->key.len);
2212 	if (retval < 0)
2213 		return retval;
2214 
2215 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2216 
2217 	/* Clear mbuf payload */
2218 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2219 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2220 
2221 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2222 	/* Append data which is padded to a multiple */
2223 	/* of the algorithms block size */
2224 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2225 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2226 				ciphertext_pad_len);
2227 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2228 
2229 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2230 
2231 	/* Create KASUMI operation */
2232 	retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data,
2233 					tdata->iv.len,
2234 					tdata->ciphertext.len,
2235 					tdata->validCipherOffsetLenInBits.len,
2236 					RTE_CRYPTO_CIPHER_KASUMI_F8);
2237 	if (retval < 0)
2238 		return retval;
2239 
2240 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2241 						ut_params->op);
2242 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2243 
2244 	ut_params->obuf = ut_params->op->sym->m_dst;
2245 	if (ut_params->obuf)
2246 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2247 				+ tdata->iv.len;
2248 	else
2249 		plaintext = ciphertext;
2250 
2251 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2252 
2253 	/* Validate obuf */
2254 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2255 		plaintext,
2256 		tdata->plaintext.data,
2257 		tdata->validCipherLenInBits.len,
2258 		"KASUMI Plaintext data not as expected");
2259 	return 0;
2260 }
2261 
2262 static int
2263 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2264 {
2265 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2266 	struct crypto_unittest_params *ut_params = &unittest_params;
2267 
2268 	int retval;
2269 	uint8_t *plaintext, *ciphertext;
2270 	unsigned plaintext_pad_len;
2271 	unsigned plaintext_len;
2272 
2273 	/* Create SNOW3G session */
2274 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2275 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2276 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2277 					tdata->key.data, tdata->key.len);
2278 	if (retval < 0)
2279 		return retval;
2280 
2281 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2282 
2283 	/* Clear mbuf payload */
2284 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2285 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2286 
2287 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2288 	/* Append data which is padded to a multiple of */
2289 	/* the algorithms block size */
2290 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2291 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2292 				plaintext_pad_len);
2293 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2294 
2295 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2296 
2297 	/* Create SNOW3G operation */
2298 	retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2299 					tdata->validCipherLenInBits.len,
2300 					tdata->validCipherOffsetLenInBits.len,
2301 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2302 	if (retval < 0)
2303 		return retval;
2304 
2305 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2306 						ut_params->op);
2307 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2308 
2309 	ut_params->obuf = ut_params->op->sym->m_dst;
2310 	if (ut_params->obuf)
2311 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2312 				+ tdata->iv.len;
2313 	else
2314 		ciphertext = plaintext;
2315 
2316 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2317 
2318 	/* Validate obuf */
2319 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2320 		ciphertext,
2321 		tdata->ciphertext.data,
2322 		tdata->validDataLenInBits.len,
2323 		"Snow3G Ciphertext data not as expected");
2324 	return 0;
2325 }
2326 
2327 
2328 static int
2329 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2330 {
2331 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2332 	struct crypto_unittest_params *ut_params = &unittest_params;
2333 	uint8_t *plaintext, *ciphertext;
2334 
2335 	int retval;
2336 	unsigned plaintext_pad_len;
2337 	unsigned plaintext_len;
2338 
2339 	/* Create SNOW3G session */
2340 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2341 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2342 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2343 					tdata->key.data, tdata->key.len);
2344 	if (retval < 0)
2345 		return retval;
2346 
2347 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2348 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2349 
2350 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2351 			"Failed to allocate input buffer in mempool");
2352 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
2353 			"Failed to allocate output buffer in mempool");
2354 
2355 	/* Clear mbuf payload */
2356 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2357 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2358 
2359 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2360 	/* Append data which is padded to a multiple of */
2361 	/* the algorithms block size */
2362 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2363 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2364 				plaintext_pad_len);
2365 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2366 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2367 
2368 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2369 
2370 	/* Create SNOW3G operation */
2371 	retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2372 					tdata->iv.len,
2373 					tdata->validCipherLenInBits.len,
2374 					tdata->validCipherOffsetLenInBits.len,
2375 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2376 	if (retval < 0)
2377 		return retval;
2378 
2379 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2380 						ut_params->op);
2381 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2382 
2383 	ut_params->obuf = ut_params->op->sym->m_dst;
2384 	if (ut_params->obuf)
2385 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2386 				+ tdata->iv.len;
2387 	else
2388 		ciphertext = plaintext;
2389 
2390 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2391 
2392 	/* Validate obuf */
2393 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2394 		ciphertext,
2395 		tdata->ciphertext.data,
2396 		tdata->validDataLenInBits.len,
2397 		"Snow3G Ciphertext data not as expected");
2398 	return 0;
2399 }
2400 
2401 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2402 static void
2403 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2404 {
2405 	uint8_t curr_byte, prev_byte;
2406 	uint32_t length_in_bytes = ceil_byte_length(length + offset);
2407 	uint8_t lower_byte_mask = (1 << offset) - 1;
2408 	unsigned i;
2409 
2410 	prev_byte = buffer[0];
2411 	buffer[0] >>= offset;
2412 
2413 	for (i = 1; i < length_in_bytes; i++) {
2414 		curr_byte = buffer[i];
2415 		buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2416 				(curr_byte >> offset);
2417 		prev_byte = curr_byte;
2418 	}
2419 }
2420 
2421 static int
2422 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2423 {
2424 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2425 	struct crypto_unittest_params *ut_params = &unittest_params;
2426 	uint8_t *plaintext, *ciphertext;
2427 	int retval;
2428 	uint32_t plaintext_len;
2429 	uint32_t plaintext_pad_len;
2430 	uint8_t extra_offset = 4;
2431 	uint8_t *expected_ciphertext_shifted;
2432 
2433 	/* Create SNOW3G session */
2434 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2435 					RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2436 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2437 					tdata->key.data, tdata->key.len);
2438 	if (retval < 0)
2439 		return retval;
2440 
2441 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2442 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2443 
2444 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2445 			"Failed to allocate input buffer in mempool");
2446 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
2447 			"Failed to allocate output buffer in mempool");
2448 
2449 	/* Clear mbuf payload */
2450 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2451 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2452 
2453 	plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2454 	/*
2455 	 * Append data which is padded to a
2456 	 * multiple of the algorithms block size
2457 	 */
2458 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2459 
2460 	plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2461 						plaintext_pad_len);
2462 
2463 	rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2464 
2465 	memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2466 	buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2467 
2468 #ifdef RTE_APP_TEST_DEBUG
2469 	rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2470 #endif
2471 	/* Create SNOW3G operation */
2472 	retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2473 					tdata->iv.len,
2474 					tdata->validCipherLenInBits.len,
2475 					tdata->validCipherOffsetLenInBits.len +
2476 					extra_offset,
2477 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2478 	if (retval < 0)
2479 		return retval;
2480 
2481 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2482 						ut_params->op);
2483 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2484 
2485 	ut_params->obuf = ut_params->op->sym->m_dst;
2486 	if (ut_params->obuf)
2487 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2488 				+ tdata->iv.len;
2489 	else
2490 		ciphertext = plaintext;
2491 
2492 #ifdef RTE_APP_TEST_DEBUG
2493 	rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2494 #endif
2495 
2496 	expected_ciphertext_shifted = rte_malloc(NULL,
2497 			ceil_byte_length(plaintext_len + extra_offset), 0);
2498 
2499 	TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2500 			"failed to reserve memory for ciphertext shifted\n");
2501 
2502 	memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2503 			ceil_byte_length(tdata->ciphertext.len));
2504 	buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2505 			extra_offset);
2506 	/* Validate obuf */
2507 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2508 		ciphertext,
2509 		expected_ciphertext_shifted,
2510 		tdata->validDataLenInBits.len,
2511 		extra_offset,
2512 		"Snow3G Ciphertext data not as expected");
2513 	return 0;
2514 }
2515 
2516 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2517 {
2518 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2519 	struct crypto_unittest_params *ut_params = &unittest_params;
2520 
2521 	int retval;
2522 
2523 	uint8_t *plaintext, *ciphertext;
2524 	unsigned ciphertext_pad_len;
2525 	unsigned ciphertext_len;
2526 
2527 	/* Create SNOW3G session */
2528 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2529 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
2530 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2531 					tdata->key.data, tdata->key.len);
2532 	if (retval < 0)
2533 		return retval;
2534 
2535 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2536 
2537 	/* Clear mbuf payload */
2538 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2539 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2540 
2541 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2542 	/* Append data which is padded to a multiple of */
2543 	/* the algorithms block size */
2544 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2545 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2546 				ciphertext_pad_len);
2547 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2548 
2549 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2550 
2551 	/* Create SNOW3G operation */
2552 	retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2553 					tdata->validCipherLenInBits.len,
2554 					tdata->validCipherOffsetLenInBits.len,
2555 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2556 	if (retval < 0)
2557 		return retval;
2558 
2559 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2560 						ut_params->op);
2561 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2562 	ut_params->obuf = ut_params->op->sym->m_dst;
2563 	if (ut_params->obuf)
2564 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2565 				+ tdata->iv.len;
2566 	else
2567 		plaintext = ciphertext;
2568 
2569 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2570 
2571 	/* Validate obuf */
2572 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2573 				tdata->plaintext.data,
2574 				tdata->validDataLenInBits.len,
2575 				"Snow3G Plaintext data not as expected");
2576 	return 0;
2577 }
2578 
2579 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2580 {
2581 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2582 	struct crypto_unittest_params *ut_params = &unittest_params;
2583 
2584 	int retval;
2585 
2586 	uint8_t *plaintext, *ciphertext;
2587 	unsigned ciphertext_pad_len;
2588 	unsigned ciphertext_len;
2589 
2590 	/* Create SNOW3G session */
2591 	retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2592 					RTE_CRYPTO_CIPHER_OP_DECRYPT,
2593 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2594 					tdata->key.data, tdata->key.len);
2595 	if (retval < 0)
2596 		return retval;
2597 
2598 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2599 	ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2600 
2601 	TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2602 			"Failed to allocate input buffer");
2603 	TEST_ASSERT_NOT_NULL(ut_params->obuf,
2604 			"Failed to allocate output buffer");
2605 
2606 	/* Clear mbuf payload */
2607 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2608 	       rte_pktmbuf_tailroom(ut_params->ibuf));
2609 
2610 	memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2611 		       rte_pktmbuf_tailroom(ut_params->obuf));
2612 
2613 	ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2614 	/* Append data which is padded to a multiple of */
2615 	/* the algorithms block size */
2616 	ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2617 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2618 				ciphertext_pad_len);
2619 	rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2620 	memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2621 
2622 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2623 
2624 	/* Create SNOW3G operation */
2625 	retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2626 					tdata->iv.len,
2627 					tdata->validCipherLenInBits.len,
2628 					tdata->validCipherOffsetLenInBits.len,
2629 					RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2630 	if (retval < 0)
2631 		return retval;
2632 
2633 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2634 						ut_params->op);
2635 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2636 	ut_params->obuf = ut_params->op->sym->m_dst;
2637 	if (ut_params->obuf)
2638 		plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2639 				+ tdata->iv.len;
2640 	else
2641 		plaintext = ciphertext;
2642 
2643 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2644 
2645 	/* Validate obuf */
2646 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2647 				tdata->plaintext.data,
2648 				tdata->validDataLenInBits.len,
2649 				"Snow3G Plaintext data not as expected");
2650 	return 0;
2651 }
2652 
2653 static int
2654 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2655 {
2656 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2657 	struct crypto_unittest_params *ut_params = &unittest_params;
2658 
2659 	int retval;
2660 
2661 	uint8_t *plaintext, *ciphertext;
2662 	unsigned plaintext_pad_len;
2663 	unsigned plaintext_len;
2664 
2665 	/* Create SNOW3G session */
2666 	retval = create_snow3g_kasumi_cipher_auth_session(ts_params->valid_devs[0],
2667 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2668 			RTE_CRYPTO_AUTH_OP_GENERATE,
2669 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2670 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2671 			tdata->key.data, tdata->key.len,
2672 			tdata->aad.len, tdata->digest.len);
2673 	if (retval < 0)
2674 		return retval;
2675 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2676 
2677 	/* clear mbuf payload */
2678 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2679 			rte_pktmbuf_tailroom(ut_params->ibuf));
2680 
2681 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2682 	/* Append data which is padded to a multiple of */
2683 	/* the algorithms block size */
2684 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2685 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2686 				plaintext_pad_len);
2687 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2688 
2689 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2690 
2691 	/* Create SNOW3G operation */
2692 	retval = create_snow3g_kasumi_cipher_hash_operation(tdata->digest.data,
2693 			tdata->digest.len, tdata->aad.data,
2694 			tdata->aad.len, /*tdata->plaintext.len,*/
2695 			plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2696 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2697 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2698 			tdata->iv.data, tdata->iv.len,
2699 			tdata->validCipherLenInBits.len,
2700 			tdata->validCipherOffsetLenInBits.len,
2701 			tdata->validAuthLenInBits.len,
2702 			tdata->validAuthOffsetLenInBits.len
2703 			);
2704 	if (retval < 0)
2705 		return retval;
2706 
2707 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2708 			ut_params->op);
2709 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2710 	ut_params->obuf = ut_params->op->sym->m_src;
2711 	if (ut_params->obuf)
2712 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2713 				+ tdata->iv.len;
2714 	else
2715 		ciphertext = plaintext;
2716 
2717 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2718 
2719 	/* Validate obuf */
2720 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2721 			ciphertext,
2722 			tdata->ciphertext.data,
2723 			tdata->validDataLenInBits.len,
2724 			"Snow3G Ciphertext data not as expected");
2725 
2726 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2727 	    + plaintext_pad_len + tdata->aad.len;
2728 
2729 	/* Validate obuf */
2730 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2731 			ut_params->digest,
2732 			tdata->digest.data,
2733 			DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2734 			"Snow3G Generated auth tag not as expected");
2735 	return 0;
2736 }
2737 static int
2738 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2739 {
2740 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2741 	struct crypto_unittest_params *ut_params = &unittest_params;
2742 
2743 	int retval;
2744 
2745 	uint8_t *plaintext, *ciphertext;
2746 	unsigned plaintext_pad_len;
2747 	unsigned plaintext_len;
2748 
2749 	/* Create SNOW3G session */
2750 	retval = create_snow3g_kasumi_auth_cipher_session(ts_params->valid_devs[0],
2751 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2752 			RTE_CRYPTO_AUTH_OP_GENERATE,
2753 			RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2754 			RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2755 			tdata->key.data, tdata->key.len,
2756 			tdata->aad.len, tdata->digest.len);
2757 	if (retval < 0)
2758 		return retval;
2759 
2760 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2761 
2762 	/* clear mbuf payload */
2763 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2764 			rte_pktmbuf_tailroom(ut_params->ibuf));
2765 
2766 	plaintext_len = ceil_byte_length(tdata->plaintext.len);
2767 	/* Append data which is padded to a multiple of */
2768 	/* the algorithms block size */
2769 	plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2770 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2771 				plaintext_pad_len);
2772 	memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2773 
2774 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2775 
2776 	/* Create SNOW3G operation */
2777 	retval = create_snow3g_kasumi_auth_cipher_operation(
2778 		tdata->digest.len,
2779 		tdata->iv.data, tdata->iv.len,
2780 		tdata->aad.data, tdata->aad.len,
2781 		plaintext_pad_len,
2782 		tdata->validCipherLenInBits.len,
2783 		tdata->validCipherOffsetLenInBits.len,
2784 		tdata->validAuthLenInBits.len,
2785 		tdata->validAuthOffsetLenInBits.len,
2786 		RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2787 		RTE_CRYPTO_CIPHER_SNOW3G_UEA2
2788 	);
2789 
2790 	if (retval < 0)
2791 		return retval;
2792 
2793 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2794 			ut_params->op);
2795 	TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2796 	ut_params->obuf = ut_params->op->sym->m_src;
2797 	if (ut_params->obuf)
2798 		ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2799 				+ tdata->aad.len + tdata->iv.len;
2800 	else
2801 		ciphertext = plaintext;
2802 
2803 	ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2804 			+ plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2805 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2806 
2807 	/* Validate obuf */
2808 	TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2809 		ciphertext,
2810 		tdata->ciphertext.data,
2811 		tdata->validDataLenInBits.len,
2812 		"Snow3G Ciphertext data not as expected");
2813 
2814 	/* Validate obuf */
2815 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
2816 		ut_params->digest,
2817 		tdata->digest.data,
2818 		DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2819 		"Snow3G Generated auth tag not as expected");
2820 	return 0;
2821 }
2822 
2823 static int
2824 test_kasumi_encryption_test_case_1(void)
2825 {
2826 	return test_kasumi_encryption(&kasumi_test_case_1);
2827 }
2828 
2829 static int
2830 test_kasumi_encryption_test_case_1_oop(void)
2831 {
2832 	return test_kasumi_encryption_oop(&kasumi_test_case_1);
2833 }
2834 
2835 static int
2836 test_kasumi_encryption_test_case_2(void)
2837 {
2838 	return test_kasumi_encryption(&kasumi_test_case_2);
2839 }
2840 
2841 static int
2842 test_kasumi_encryption_test_case_3(void)
2843 {
2844 	return test_kasumi_encryption(&kasumi_test_case_3);
2845 }
2846 
2847 static int
2848 test_kasumi_encryption_test_case_4(void)
2849 {
2850 	return test_kasumi_encryption(&kasumi_test_case_4);
2851 }
2852 
2853 static int
2854 test_kasumi_encryption_test_case_5(void)
2855 {
2856 	return test_kasumi_encryption(&kasumi_test_case_5);
2857 }
2858 
2859 static int
2860 test_kasumi_decryption_test_case_1(void)
2861 {
2862 	return test_kasumi_decryption(&kasumi_test_case_1);
2863 }
2864 
2865 static int
2866 test_kasumi_decryption_test_case_1_oop(void)
2867 {
2868 	return test_kasumi_decryption_oop(&kasumi_test_case_1);
2869 }
2870 
2871 static int
2872 test_kasumi_decryption_test_case_2(void)
2873 {
2874 	return test_kasumi_decryption(&kasumi_test_case_2);
2875 }
2876 
2877 static int
2878 test_kasumi_decryption_test_case_3(void)
2879 {
2880 	return test_kasumi_decryption(&kasumi_test_case_3);
2881 }
2882 
2883 static int
2884 test_kasumi_decryption_test_case_4(void)
2885 {
2886 	return test_kasumi_decryption(&kasumi_test_case_4);
2887 }
2888 
2889 static int
2890 test_kasumi_decryption_test_case_5(void)
2891 {
2892 	return test_kasumi_decryption(&kasumi_test_case_5);
2893 }
2894 static int
2895 test_snow3g_encryption_test_case_1(void)
2896 {
2897 	return test_snow3g_encryption(&snow3g_test_case_1);
2898 }
2899 
2900 static int
2901 test_snow3g_encryption_test_case_1_oop(void)
2902 {
2903 	return test_snow3g_encryption_oop(&snow3g_test_case_1);
2904 }
2905 
2906 static int
2907 test_snow3g_encryption_test_case_1_offset_oop(void)
2908 {
2909 	return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
2910 }
2911 
2912 static int
2913 test_snow3g_encryption_test_case_2(void)
2914 {
2915 	return test_snow3g_encryption(&snow3g_test_case_2);
2916 }
2917 
2918 static int
2919 test_snow3g_encryption_test_case_3(void)
2920 {
2921 	return test_snow3g_encryption(&snow3g_test_case_3);
2922 }
2923 
2924 static int
2925 test_snow3g_encryption_test_case_4(void)
2926 {
2927 	return test_snow3g_encryption(&snow3g_test_case_4);
2928 }
2929 
2930 static int
2931 test_snow3g_encryption_test_case_5(void)
2932 {
2933 	return test_snow3g_encryption(&snow3g_test_case_5);
2934 }
2935 
2936 static int
2937 test_snow3g_decryption_test_case_1(void)
2938 {
2939 	return test_snow3g_decryption(&snow3g_test_case_1);
2940 }
2941 
2942 static int
2943 test_snow3g_decryption_test_case_1_oop(void)
2944 {
2945 	return test_snow3g_decryption_oop(&snow3g_test_case_1);
2946 }
2947 
2948 static int
2949 test_snow3g_decryption_test_case_2(void)
2950 {
2951 	return test_snow3g_decryption(&snow3g_test_case_2);
2952 }
2953 
2954 static int
2955 test_snow3g_decryption_test_case_3(void)
2956 {
2957 	return test_snow3g_decryption(&snow3g_test_case_3);
2958 }
2959 
2960 static int
2961 test_snow3g_decryption_test_case_4(void)
2962 {
2963 	return test_snow3g_decryption(&snow3g_test_case_4);
2964 }
2965 
2966 static int
2967 test_snow3g_decryption_test_case_5(void)
2968 {
2969 	return test_snow3g_decryption(&snow3g_test_case_5);
2970 }
2971 static int
2972 test_snow3g_authenticated_encryption_test_case_1(void)
2973 {
2974 	return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2975 }
2976 
2977 static int
2978 test_snow3g_encrypted_authentication_test_case_1(void)
2979 {
2980 	return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2981 }
2982 
2983 /* ***** AES-GCM Tests ***** */
2984 
2985 static int
2986 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2987 		const uint8_t *key, const uint8_t key_len,
2988 		const uint8_t aad_len, const uint8_t auth_len)
2989 {
2990 	uint8_t cipher_key[key_len];
2991 
2992 	struct crypto_unittest_params *ut_params = &unittest_params;
2993 
2994 
2995 	memcpy(cipher_key, key, key_len);
2996 
2997 	/* Setup Cipher Parameters */
2998 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2999 	ut_params->cipher_xform.next = NULL;
3000 
3001 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3002 	ut_params->cipher_xform.cipher.op = op;
3003 	ut_params->cipher_xform.cipher.key.data = cipher_key;
3004 	ut_params->cipher_xform.cipher.key.length = key_len;
3005 
3006 	TEST_HEXDUMP(stdout, "key:", key, key_len);
3007 
3008 	/* Setup Authentication Parameters */
3009 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3010 	ut_params->auth_xform.next = NULL;
3011 
3012 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3013 
3014 	ut_params->auth_xform.auth.digest_length = auth_len;
3015 	ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3016 	ut_params->auth_xform.auth.key.length = 0;
3017 	ut_params->auth_xform.auth.key.data = NULL;
3018 
3019 	if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3020 		ut_params->cipher_xform.next = &ut_params->auth_xform;
3021 
3022 		/* Create Crypto session*/
3023 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3024 				&ut_params->cipher_xform);
3025 	} else {/* Create Crypto session*/
3026 		ut_params->auth_xform.next = &ut_params->cipher_xform;
3027 		ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3028 				&ut_params->auth_xform);
3029 	}
3030 
3031 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3032 
3033 	return 0;
3034 }
3035 
3036 static int
3037 create_gcm_operation(enum rte_crypto_cipher_operation op,
3038 		const uint8_t *auth_tag, const unsigned auth_tag_len,
3039 		const uint8_t *iv, const unsigned iv_len,
3040 		const uint8_t *aad, const unsigned aad_len,
3041 		const unsigned data_len, unsigned data_pad_len)
3042 {
3043 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3044 	struct crypto_unittest_params *ut_params = &unittest_params;
3045 
3046 	unsigned iv_pad_len = 0, aad_buffer_len;
3047 
3048 	/* Generate Crypto op data structure */
3049 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3050 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3051 	TEST_ASSERT_NOT_NULL(ut_params->op,
3052 			"Failed to allocate symmetric crypto operation struct");
3053 
3054 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3055 
3056 
3057 
3058 	sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3059 			ut_params->ibuf, auth_tag_len);
3060 	TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3061 			"no room to append digest");
3062 	sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3063 			ut_params->ibuf, data_pad_len);
3064 	sym_op->auth.digest.length = auth_tag_len;
3065 
3066 	if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3067 		rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3068 		TEST_HEXDUMP(stdout, "digest:",
3069 				sym_op->auth.digest.data,
3070 				sym_op->auth.digest.length);
3071 	}
3072 
3073 	/* iv */
3074 	iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3075 
3076 	sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3077 			ut_params->ibuf, iv_pad_len);
3078 	TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3079 
3080 	memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3081 	sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3082 	sym_op->cipher.iv.length = iv_pad_len;
3083 
3084 	rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3085 
3086 	/* CalcY0 */
3087 	if (iv_len != 16)
3088 		sym_op->cipher.iv.data[15] = 1;
3089 
3090 	/*
3091 	 * Always allocate the aad up to the block size.
3092 	 * The cryptodev API calls out -
3093 	 *  - the array must be big enough to hold the AAD, plus any
3094 	 *   space to round this up to the nearest multiple of the
3095 	 *   block size (16 bytes).
3096 	 */
3097 	aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3098 
3099 	sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3100 			ut_params->ibuf, aad_buffer_len);
3101 	TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3102 			"no room to prepend aad");
3103 	sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3104 			ut_params->ibuf);
3105 	sym_op->auth.aad.length = aad_len;
3106 
3107 	memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3108 	rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3109 
3110 	TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3111 	TEST_HEXDUMP(stdout, "aad:",
3112 			sym_op->auth.aad.data, aad_len);
3113 
3114 	sym_op->cipher.data.length = data_len;
3115 	sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3116 
3117 	sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3118 	sym_op->auth.data.length = data_len;
3119 
3120 	return 0;
3121 }
3122 
3123 static int
3124 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3125 {
3126 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3127 	struct crypto_unittest_params *ut_params = &unittest_params;
3128 
3129 	int retval;
3130 
3131 	uint8_t *plaintext, *ciphertext, *auth_tag;
3132 	uint16_t plaintext_pad_len;
3133 
3134 	/* Create GCM session */
3135 	retval = create_gcm_session(ts_params->valid_devs[0],
3136 			RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3137 			tdata->key.data, tdata->key.len,
3138 			tdata->aad.len, tdata->auth_tag.len);
3139 	if (retval < 0)
3140 		return retval;
3141 
3142 
3143 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3144 
3145 	/* clear mbuf payload */
3146 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3147 			rte_pktmbuf_tailroom(ut_params->ibuf));
3148 
3149 	/*
3150 	 * Append data which is padded to a multiple
3151 	 * of the algorithms block size
3152 	 */
3153 	plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3154 
3155 	plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3156 			plaintext_pad_len);
3157 	memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3158 
3159 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3160 
3161 	/* Create GCM opertaion */
3162 	retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3163 			tdata->auth_tag.data, tdata->auth_tag.len,
3164 			tdata->iv.data, tdata->iv.len,
3165 			tdata->aad.data, tdata->aad.len,
3166 			tdata->plaintext.len, plaintext_pad_len);
3167 	if (retval < 0)
3168 		return retval;
3169 
3170 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3171 
3172 	ut_params->op->sym->m_src = ut_params->ibuf;
3173 
3174 	/* Process crypto operation */
3175 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3176 			ut_params->op), "failed to process sym crypto op");
3177 
3178 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3179 			"crypto op processing failed");
3180 
3181 	if (ut_params->op->sym->m_dst) {
3182 		ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3183 				uint8_t *);
3184 		auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3185 				uint8_t *, plaintext_pad_len);
3186 	} else {
3187 		ciphertext = plaintext;
3188 		auth_tag = plaintext + plaintext_pad_len;
3189 	}
3190 
3191 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3192 	TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3193 
3194 	/* Validate obuf */
3195 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3196 			ciphertext,
3197 			tdata->ciphertext.data,
3198 			tdata->ciphertext.len,
3199 			"GCM Ciphertext data not as expected");
3200 
3201 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3202 			auth_tag,
3203 			tdata->auth_tag.data,
3204 			tdata->auth_tag.len,
3205 			"GCM Generated auth tag not as expected");
3206 
3207 	return 0;
3208 
3209 }
3210 
3211 static int
3212 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3213 {
3214 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3215 }
3216 
3217 static int
3218 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3219 {
3220 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3221 }
3222 
3223 static int
3224 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3225 {
3226 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3227 }
3228 
3229 static int
3230 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3231 {
3232 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3233 }
3234 
3235 static int
3236 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3237 {
3238 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3239 }
3240 
3241 static int
3242 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3243 {
3244 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3245 }
3246 
3247 static int
3248 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3249 {
3250 	return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3251 }
3252 
3253 static int
3254 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3255 {
3256 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3257 	struct crypto_unittest_params *ut_params = &unittest_params;
3258 
3259 	int retval;
3260 
3261 	uint8_t *plaintext, *ciphertext;
3262 	uint16_t ciphertext_pad_len;
3263 
3264 	/* Create GCM session */
3265 	retval = create_gcm_session(ts_params->valid_devs[0],
3266 			RTE_CRYPTO_CIPHER_OP_DECRYPT,
3267 			tdata->key.data, tdata->key.len,
3268 			tdata->aad.len, tdata->auth_tag.len);
3269 	if (retval < 0)
3270 		return retval;
3271 
3272 
3273 	/* alloc mbuf and set payload */
3274 	ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3275 
3276 	memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3277 			rte_pktmbuf_tailroom(ut_params->ibuf));
3278 
3279 	ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3280 
3281 	ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3282 			ciphertext_pad_len);
3283 	memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3284 
3285 	TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3286 
3287 	/* Create GCM opertaion */
3288 	retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3289 			tdata->auth_tag.data, tdata->auth_tag.len,
3290 			tdata->iv.data, tdata->iv.len,
3291 			tdata->aad.data, tdata->aad.len,
3292 			tdata->ciphertext.len, ciphertext_pad_len);
3293 	if (retval < 0)
3294 		return retval;
3295 
3296 
3297 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3298 
3299 	ut_params->op->sym->m_src = ut_params->ibuf;
3300 
3301 	/* Process crypto operation */
3302 	TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3303 			ut_params->op), "failed to process sym crypto op");
3304 
3305 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3306 			"crypto op processing failed");
3307 
3308 	if (ut_params->op->sym->m_dst)
3309 		plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3310 				uint8_t *);
3311 	else
3312 		plaintext = ciphertext;
3313 
3314 	TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3315 
3316 	/* Validate obuf */
3317 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3318 			plaintext,
3319 			tdata->plaintext.data,
3320 			tdata->plaintext.len,
3321 			"GCM plaintext data not as expected");
3322 
3323 	TEST_ASSERT_EQUAL(ut_params->op->status,
3324 			RTE_CRYPTO_OP_STATUS_SUCCESS,
3325 			"GCM authentication failed");
3326 	return 0;
3327 }
3328 
3329 static int
3330 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3331 {
3332 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3333 }
3334 
3335 static int
3336 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3337 {
3338 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3339 }
3340 
3341 static int
3342 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3343 {
3344 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3345 }
3346 
3347 static int
3348 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3349 {
3350 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3351 }
3352 
3353 static int
3354 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3355 {
3356 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3357 }
3358 
3359 static int
3360 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3361 {
3362 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3363 }
3364 
3365 static int
3366 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3367 {
3368 	return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3369 }
3370 
3371 static int
3372 test_stats(void)
3373 {
3374 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3375 	struct rte_cryptodev_stats stats;
3376 	struct rte_cryptodev *dev;
3377 	cryptodev_stats_get_t temp_pfn;
3378 
3379 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3380 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3381 			&stats) == -ENODEV),
3382 		"rte_cryptodev_stats_get invalid dev failed");
3383 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3384 		"rte_cryptodev_stats_get invalid Param failed");
3385 	dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3386 	temp_pfn = dev->dev_ops->stats_get;
3387 	dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3388 	TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3389 			== -ENOTSUP),
3390 		"rte_cryptodev_stats_get invalid Param failed");
3391 	dev->dev_ops->stats_get = temp_pfn;
3392 
3393 	/* Test expected values */
3394 	ut_setup();
3395 	test_AES_CBC_HMAC_SHA1_encrypt_digest();
3396 	ut_teardown();
3397 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3398 			&stats),
3399 		"rte_cryptodev_stats_get failed");
3400 	TEST_ASSERT((stats.enqueued_count == 1),
3401 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3402 	TEST_ASSERT((stats.dequeued_count == 1),
3403 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3404 	TEST_ASSERT((stats.enqueue_err_count == 0),
3405 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3406 	TEST_ASSERT((stats.dequeue_err_count == 0),
3407 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3408 
3409 	/* invalid device but should ignore and not reset device stats*/
3410 	rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3411 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3412 			&stats),
3413 		"rte_cryptodev_stats_get failed");
3414 	TEST_ASSERT((stats.enqueued_count == 1),
3415 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3416 
3417 	/* check that a valid reset clears stats */
3418 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3419 	TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3420 			&stats),
3421 					  "rte_cryptodev_stats_get failed");
3422 	TEST_ASSERT((stats.enqueued_count == 0),
3423 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3424 	TEST_ASSERT((stats.dequeued_count == 0),
3425 		"rte_cryptodev_stats_get returned unexpected enqueued stat");
3426 
3427 	return TEST_SUCCESS;
3428 }
3429 
3430 
3431 static int
3432 test_multi_session(void)
3433 {
3434 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3435 	struct crypto_unittest_params *ut_params = &unittest_params;
3436 
3437 	struct rte_cryptodev_info dev_info;
3438 	struct rte_cryptodev_sym_session **sessions;
3439 
3440 	uint16_t i;
3441 
3442 	test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3443 
3444 
3445 	rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3446 
3447 	sessions = rte_malloc(NULL,
3448 			(sizeof(struct rte_cryptodev_sym_session *) *
3449 			dev_info.sym.max_nb_sessions) + 1, 0);
3450 
3451 	/* Create multiple crypto sessions*/
3452 	for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3453 		sessions[i] = rte_cryptodev_sym_session_create(
3454 				ts_params->valid_devs[0],
3455 			&ut_params->auth_xform);
3456 		TEST_ASSERT_NOT_NULL(sessions[i],
3457 				"Session creation failed at session number %u",
3458 				i);
3459 
3460 		/* Attempt to send a request on each session */
3461 		TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3462 				sessions[i], ut_params, ts_params),
3463 				"Failed to perform decrypt on request "
3464 				"number %u.", i);
3465 		/* free crypto operation structure */
3466 		if (ut_params->op)
3467 			rte_crypto_op_free(ut_params->op);
3468 
3469 		/*
3470 		 * free mbuf - both obuf and ibuf are usually the same,
3471 		 * but rte copes even if we call free twice
3472 		 */
3473 		if (ut_params->obuf) {
3474 			rte_pktmbuf_free(ut_params->obuf);
3475 			ut_params->obuf = 0;
3476 		}
3477 	}
3478 
3479 	/* Next session create should fail */
3480 	sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3481 			&ut_params->auth_xform);
3482 	TEST_ASSERT_NULL(sessions[i],
3483 			"Session creation succeeded unexpectedly!");
3484 
3485 	for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3486 		rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3487 				sessions[i]);
3488 
3489 	rte_free(sessions);
3490 
3491 	return TEST_SUCCESS;
3492 }
3493 
3494 static int
3495 test_null_cipher_only_operation(void)
3496 {
3497 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3498 	struct crypto_unittest_params *ut_params = &unittest_params;
3499 
3500 	/* Generate test mbuf data and space for digest */
3501 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3502 			catch_22_quote, QUOTE_512_BYTES, 0);
3503 
3504 	/* Setup Cipher Parameters */
3505 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3506 	ut_params->cipher_xform.next = NULL;
3507 
3508 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3509 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3510 
3511 	/* Create Crypto session*/
3512 	ut_params->sess = rte_cryptodev_sym_session_create(
3513 			ts_params->valid_devs[0], &ut_params->cipher_xform);
3514 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3515 
3516 	/* Generate Crypto op data structure */
3517 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3518 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3519 	TEST_ASSERT_NOT_NULL(ut_params->op,
3520 			"Failed to allocate symmetric crypto operation struct");
3521 
3522 	/* Set crypto operation data parameters */
3523 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3524 
3525 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3526 
3527 	/* set crypto operation source mbuf */
3528 	sym_op->m_src = ut_params->ibuf;
3529 
3530 	sym_op->cipher.data.offset = 0;
3531 	sym_op->cipher.data.length = QUOTE_512_BYTES;
3532 
3533 	/* Process crypto operation */
3534 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3535 			ut_params->op);
3536 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3537 
3538 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3539 			"crypto operation processing failed");
3540 
3541 	/* Validate obuf */
3542 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3543 			rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3544 			catch_22_quote,
3545 			QUOTE_512_BYTES,
3546 			"Ciphertext data not as expected");
3547 
3548 	return TEST_SUCCESS;
3549 }
3550 
3551 static int
3552 test_null_auth_only_operation(void)
3553 {
3554 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3555 	struct crypto_unittest_params *ut_params = &unittest_params;
3556 
3557 	/* Generate test mbuf data and space for digest */
3558 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3559 			catch_22_quote, QUOTE_512_BYTES, 0);
3560 
3561 	/* Setup HMAC Parameters */
3562 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3563 	ut_params->auth_xform.next = NULL;
3564 
3565 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3566 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3567 
3568 	/* Create Crypto session*/
3569 	ut_params->sess = rte_cryptodev_sym_session_create(
3570 			ts_params->valid_devs[0], &ut_params->auth_xform);
3571 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3572 
3573 	/* Generate Crypto op data structure */
3574 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3575 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3576 	TEST_ASSERT_NOT_NULL(ut_params->op,
3577 			"Failed to allocate symmetric crypto operation struct");
3578 
3579 	/* Set crypto operation data parameters */
3580 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3581 
3582 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3583 
3584 	sym_op->m_src = ut_params->ibuf;
3585 
3586 	sym_op->auth.data.offset = 0;
3587 	sym_op->auth.data.length = QUOTE_512_BYTES;
3588 
3589 	/* Process crypto operation */
3590 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3591 			ut_params->op);
3592 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3593 
3594 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3595 			"crypto operation processing failed");
3596 
3597 	return TEST_SUCCESS;
3598 }
3599 
3600 static int
3601 test_null_cipher_auth_operation(void)
3602 {
3603 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3604 	struct crypto_unittest_params *ut_params = &unittest_params;
3605 
3606 	/* Generate test mbuf data and space for digest */
3607 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3608 			catch_22_quote, QUOTE_512_BYTES, 0);
3609 
3610 	/* Setup Cipher Parameters */
3611 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3612 	ut_params->cipher_xform.next = &ut_params->auth_xform;
3613 
3614 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3615 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3616 
3617 	/* Setup HMAC Parameters */
3618 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3619 	ut_params->auth_xform.next = NULL;
3620 
3621 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3622 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3623 
3624 	/* Create Crypto session*/
3625 	ut_params->sess = rte_cryptodev_sym_session_create(
3626 			ts_params->valid_devs[0], &ut_params->cipher_xform);
3627 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3628 
3629 	/* Generate Crypto op data structure */
3630 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3631 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3632 	TEST_ASSERT_NOT_NULL(ut_params->op,
3633 			"Failed to allocate symmetric crypto operation struct");
3634 
3635 	/* Set crypto operation data parameters */
3636 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3637 
3638 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3639 
3640 	sym_op->m_src = ut_params->ibuf;
3641 
3642 	sym_op->cipher.data.offset = 0;
3643 	sym_op->cipher.data.length = QUOTE_512_BYTES;
3644 
3645 	sym_op->auth.data.offset = 0;
3646 	sym_op->auth.data.length = QUOTE_512_BYTES;
3647 
3648 	/* Process crypto operation */
3649 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3650 			ut_params->op);
3651 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3652 
3653 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3654 			"crypto operation processing failed");
3655 
3656 	/* Validate obuf */
3657 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3658 			rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3659 			catch_22_quote,
3660 			QUOTE_512_BYTES,
3661 			"Ciphertext data not as expected");
3662 
3663 	return TEST_SUCCESS;
3664 }
3665 
3666 static int
3667 test_null_auth_cipher_operation(void)
3668 {
3669 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3670 	struct crypto_unittest_params *ut_params = &unittest_params;
3671 
3672 	/* Generate test mbuf data and space for digest */
3673 	ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3674 			catch_22_quote, QUOTE_512_BYTES, 0);
3675 
3676 	/* Setup Cipher Parameters */
3677 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3678 	ut_params->cipher_xform.next = NULL;
3679 
3680 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3681 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3682 
3683 	/* Setup HMAC Parameters */
3684 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3685 	ut_params->auth_xform.next = &ut_params->cipher_xform;
3686 
3687 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3688 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3689 
3690 	/* Create Crypto session*/
3691 	ut_params->sess = rte_cryptodev_sym_session_create(
3692 			ts_params->valid_devs[0], &ut_params->cipher_xform);
3693 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3694 
3695 	/* Generate Crypto op data structure */
3696 	ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3697 			RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3698 	TEST_ASSERT_NOT_NULL(ut_params->op,
3699 			"Failed to allocate symmetric crypto operation struct");
3700 
3701 	/* Set crypto operation data parameters */
3702 	rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3703 
3704 	struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3705 
3706 	sym_op->m_src = ut_params->ibuf;
3707 
3708 	sym_op->cipher.data.offset = 0;
3709 	sym_op->cipher.data.length = QUOTE_512_BYTES;
3710 
3711 	sym_op->auth.data.offset = 0;
3712 	sym_op->auth.data.length = QUOTE_512_BYTES;
3713 
3714 	/* Process crypto operation */
3715 	ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3716 			ut_params->op);
3717 	TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3718 
3719 	TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3720 			"crypto operation processing failed");
3721 
3722 	/* Validate obuf */
3723 	TEST_ASSERT_BUFFERS_ARE_EQUAL(
3724 			rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3725 			catch_22_quote,
3726 			QUOTE_512_BYTES,
3727 			"Ciphertext data not as expected");
3728 
3729 	return TEST_SUCCESS;
3730 }
3731 
3732 
3733 static int
3734 test_null_invalid_operation(void)
3735 {
3736 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3737 	struct crypto_unittest_params *ut_params = &unittest_params;
3738 
3739 	/* Setup Cipher Parameters */
3740 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3741 	ut_params->cipher_xform.next = NULL;
3742 
3743 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3744 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3745 
3746 	/* Create Crypto session*/
3747 	ut_params->sess = rte_cryptodev_sym_session_create(
3748 			ts_params->valid_devs[0], &ut_params->cipher_xform);
3749 	TEST_ASSERT_NULL(ut_params->sess,
3750 			"Session creation succeeded unexpectedly");
3751 
3752 
3753 	/* Setup HMAC Parameters */
3754 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3755 	ut_params->auth_xform.next = NULL;
3756 
3757 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3758 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3759 
3760 	/* Create Crypto session*/
3761 	ut_params->sess = rte_cryptodev_sym_session_create(
3762 			ts_params->valid_devs[0], &ut_params->auth_xform);
3763 	TEST_ASSERT_NULL(ut_params->sess,
3764 			"Session creation succeeded unexpectedly");
3765 
3766 	return TEST_SUCCESS;
3767 }
3768 
3769 
3770 #define NULL_BURST_LENGTH (32)
3771 
3772 static int
3773 test_null_burst_operation(void)
3774 {
3775 	struct crypto_testsuite_params *ts_params = &testsuite_params;
3776 	struct crypto_unittest_params *ut_params = &unittest_params;
3777 
3778 	unsigned i, burst_len = NULL_BURST_LENGTH;
3779 
3780 	struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3781 	struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3782 
3783 	/* Setup Cipher Parameters */
3784 	ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3785 	ut_params->cipher_xform.next = &ut_params->auth_xform;
3786 
3787 	ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3788 	ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3789 
3790 	/* Setup HMAC Parameters */
3791 	ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3792 	ut_params->auth_xform.next = NULL;
3793 
3794 	ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3795 	ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3796 
3797 	/* Create Crypto session*/
3798 	ut_params->sess = rte_cryptodev_sym_session_create(
3799 			ts_params->valid_devs[0], &ut_params->cipher_xform);
3800 	TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3801 
3802 	TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3803 			RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3804 			burst_len, "failed to generate burst of crypto ops");
3805 
3806 	/* Generate an operation for each mbuf in burst */
3807 	for (i = 0; i < burst_len; i++) {
3808 		struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3809 
3810 		TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3811 
3812 		unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3813 				sizeof(unsigned));
3814 		*data = i;
3815 
3816 		rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3817 
3818 		burst[i]->sym->m_src = m;
3819 	}
3820 
3821 	/* Process crypto operation */
3822 	TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3823 			0, burst, burst_len),
3824 			burst_len,
3825 			"Error enqueuing burst");
3826 
3827 	TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3828 			0, burst_dequeued, burst_len),
3829 			burst_len,
3830 			"Error dequeuing burst");
3831 
3832 
3833 	for (i = 0; i < burst_len; i++) {
3834 		TEST_ASSERT_EQUAL(
3835 			*rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3836 			*rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3837 					uint32_t *),
3838 			"data not as expected");
3839 
3840 		rte_pktmbuf_free(burst[i]->sym->m_src);
3841 		rte_crypto_op_free(burst[i]);
3842 	}
3843 
3844 	return TEST_SUCCESS;
3845 }
3846 
3847 
3848 
3849 
3850 static struct unit_test_suite cryptodev_qat_testsuite  = {
3851 	.suite_name = "Crypto QAT Unit Test Suite",
3852 	.setup = testsuite_setup,
3853 	.teardown = testsuite_teardown,
3854 	.unit_test_cases = {
3855 		TEST_CASE_ST(ut_setup, ut_teardown,
3856 				test_device_configure_invalid_dev_id),
3857 		TEST_CASE_ST(ut_setup, ut_teardown,
3858 				test_device_configure_invalid_queue_pair_ids),
3859 		TEST_CASE_ST(ut_setup, ut_teardown,
3860 				test_queue_pair_descriptor_setup),
3861 		TEST_CASE_ST(ut_setup, ut_teardown,
3862 				test_multi_session),
3863 
3864 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3865 		TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3866 
3867 		/** AES GCM Authenticated Encryption */
3868 		TEST_CASE_ST(ut_setup, ut_teardown,
3869 			test_mb_AES_GCM_authenticated_encryption_test_case_1),
3870 		TEST_CASE_ST(ut_setup, ut_teardown,
3871 			test_mb_AES_GCM_authenticated_encryption_test_case_2),
3872 		TEST_CASE_ST(ut_setup, ut_teardown,
3873 			test_mb_AES_GCM_authenticated_encryption_test_case_3),
3874 		TEST_CASE_ST(ut_setup, ut_teardown,
3875 			test_mb_AES_GCM_authenticated_encryption_test_case_4),
3876 		TEST_CASE_ST(ut_setup, ut_teardown,
3877 			test_mb_AES_GCM_authenticated_encryption_test_case_5),
3878 		TEST_CASE_ST(ut_setup, ut_teardown,
3879 			test_mb_AES_GCM_authenticated_encryption_test_case_6),
3880 		TEST_CASE_ST(ut_setup, ut_teardown,
3881 			test_mb_AES_GCM_authenticated_encryption_test_case_7),
3882 
3883 		/** AES GCM Authenticated Decryption */
3884 		TEST_CASE_ST(ut_setup, ut_teardown,
3885 			test_mb_AES_GCM_authenticated_decryption_test_case_1),
3886 		TEST_CASE_ST(ut_setup, ut_teardown,
3887 			test_mb_AES_GCM_authenticated_decryption_test_case_2),
3888 		TEST_CASE_ST(ut_setup, ut_teardown,
3889 			test_mb_AES_GCM_authenticated_decryption_test_case_3),
3890 		TEST_CASE_ST(ut_setup, ut_teardown,
3891 			test_mb_AES_GCM_authenticated_decryption_test_case_4),
3892 		TEST_CASE_ST(ut_setup, ut_teardown,
3893 			test_mb_AES_GCM_authenticated_decryption_test_case_5),
3894 		TEST_CASE_ST(ut_setup, ut_teardown,
3895 			test_mb_AES_GCM_authenticated_decryption_test_case_6),
3896 		TEST_CASE_ST(ut_setup, ut_teardown,
3897 			test_mb_AES_GCM_authenticated_decryption_test_case_7),
3898 
3899 		/** Snow3G encrypt only (UEA2) */
3900 		TEST_CASE_ST(ut_setup, ut_teardown,
3901 			test_snow3g_encryption_test_case_1),
3902 		TEST_CASE_ST(ut_setup, ut_teardown,
3903 			test_snow3g_encryption_test_case_2),
3904 		TEST_CASE_ST(ut_setup, ut_teardown,
3905 			test_snow3g_encryption_test_case_3),
3906 		TEST_CASE_ST(ut_setup, ut_teardown,
3907 			test_snow3g_encryption_test_case_4),
3908 		TEST_CASE_ST(ut_setup, ut_teardown,
3909 			test_snow3g_encryption_test_case_5),
3910 
3911 		TEST_CASE_ST(ut_setup, ut_teardown,
3912 			test_snow3g_encryption_test_case_1_oop),
3913 		TEST_CASE_ST(ut_setup, ut_teardown,
3914 			test_snow3g_decryption_test_case_1_oop),
3915 
3916 		/** Snow3G decrypt only (UEA2) */
3917 		TEST_CASE_ST(ut_setup, ut_teardown,
3918 			test_snow3g_decryption_test_case_1),
3919 		TEST_CASE_ST(ut_setup, ut_teardown,
3920 			test_snow3g_decryption_test_case_2),
3921 		TEST_CASE_ST(ut_setup, ut_teardown,
3922 			test_snow3g_decryption_test_case_3),
3923 		TEST_CASE_ST(ut_setup, ut_teardown,
3924 			test_snow3g_decryption_test_case_4),
3925 		TEST_CASE_ST(ut_setup, ut_teardown,
3926 			test_snow3g_decryption_test_case_5),
3927 		TEST_CASE_ST(ut_setup, ut_teardown,
3928 			test_snow3g_hash_generate_test_case_1),
3929 		TEST_CASE_ST(ut_setup, ut_teardown,
3930 			test_snow3g_hash_generate_test_case_2),
3931 		TEST_CASE_ST(ut_setup, ut_teardown,
3932 			test_snow3g_hash_generate_test_case_3),
3933 		TEST_CASE_ST(ut_setup, ut_teardown,
3934 			test_snow3g_hash_verify_test_case_1),
3935 		TEST_CASE_ST(ut_setup, ut_teardown,
3936 			test_snow3g_hash_verify_test_case_2),
3937 		TEST_CASE_ST(ut_setup, ut_teardown,
3938 			test_snow3g_hash_verify_test_case_3),
3939 		TEST_CASE_ST(ut_setup, ut_teardown,
3940 			test_snow3g_authenticated_encryption_test_case_1),
3941 		TEST_CASE_ST(ut_setup, ut_teardown,
3942 			test_snow3g_encrypted_authentication_test_case_1),
3943 		TEST_CASES_END() /**< NULL terminate unit test array */
3944 	}
3945 };
3946 
3947 static struct unit_test_suite cryptodev_aesni_mb_testsuite  = {
3948 	.suite_name = "Crypto Device AESNI MB Unit Test Suite",
3949 	.setup = testsuite_setup,
3950 	.teardown = testsuite_teardown,
3951 	.unit_test_cases = {
3952 		TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3953 
3954 		TEST_CASES_END() /**< NULL terminate unit test array */
3955 	}
3956 };
3957 
3958 static struct unit_test_suite cryptodev_aesni_gcm_testsuite  = {
3959 	.suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3960 	.setup = testsuite_setup,
3961 	.teardown = testsuite_teardown,
3962 	.unit_test_cases = {
3963 		/** AES GCM Authenticated Encryption */
3964 		TEST_CASE_ST(ut_setup, ut_teardown,
3965 			test_mb_AES_GCM_authenticated_encryption_test_case_1),
3966 		TEST_CASE_ST(ut_setup, ut_teardown,
3967 			test_mb_AES_GCM_authenticated_encryption_test_case_2),
3968 		TEST_CASE_ST(ut_setup, ut_teardown,
3969 			test_mb_AES_GCM_authenticated_encryption_test_case_3),
3970 		TEST_CASE_ST(ut_setup, ut_teardown,
3971 			test_mb_AES_GCM_authenticated_encryption_test_case_4),
3972 		TEST_CASE_ST(ut_setup, ut_teardown,
3973 			test_mb_AES_GCM_authenticated_encryption_test_case_5),
3974 		TEST_CASE_ST(ut_setup, ut_teardown,
3975 			test_mb_AES_GCM_authenticated_encryption_test_case_6),
3976 		TEST_CASE_ST(ut_setup, ut_teardown,
3977 			test_mb_AES_GCM_authenticated_encryption_test_case_7),
3978 
3979 		/** AES GCM Authenticated Decryption */
3980 		TEST_CASE_ST(ut_setup, ut_teardown,
3981 			test_mb_AES_GCM_authenticated_decryption_test_case_1),
3982 		TEST_CASE_ST(ut_setup, ut_teardown,
3983 			test_mb_AES_GCM_authenticated_decryption_test_case_2),
3984 		TEST_CASE_ST(ut_setup, ut_teardown,
3985 			test_mb_AES_GCM_authenticated_decryption_test_case_3),
3986 		TEST_CASE_ST(ut_setup, ut_teardown,
3987 			test_mb_AES_GCM_authenticated_decryption_test_case_4),
3988 		TEST_CASE_ST(ut_setup, ut_teardown,
3989 			test_mb_AES_GCM_authenticated_decryption_test_case_5),
3990 		TEST_CASE_ST(ut_setup, ut_teardown,
3991 			test_mb_AES_GCM_authenticated_decryption_test_case_6),
3992 		TEST_CASE_ST(ut_setup, ut_teardown,
3993 			test_mb_AES_GCM_authenticated_decryption_test_case_7),
3994 
3995 		TEST_CASES_END() /**< NULL terminate unit test array */
3996 	}
3997 };
3998 
3999 static struct unit_test_suite cryptodev_sw_kasumi_testsuite  = {
4000 	.suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4001 	.setup = testsuite_setup,
4002 	.teardown = testsuite_teardown,
4003 	.unit_test_cases = {
4004 		/** KASUMI encrypt only (UEA1) */
4005 		TEST_CASE_ST(ut_setup, ut_teardown,
4006 			test_kasumi_encryption_test_case_1),
4007 		TEST_CASE_ST(ut_setup, ut_teardown,
4008 			test_kasumi_encryption_test_case_2),
4009 		TEST_CASE_ST(ut_setup, ut_teardown,
4010 			test_kasumi_encryption_test_case_3),
4011 		TEST_CASE_ST(ut_setup, ut_teardown,
4012 			test_kasumi_encryption_test_case_4),
4013 		TEST_CASE_ST(ut_setup, ut_teardown,
4014 			test_kasumi_encryption_test_case_5),
4015 		/** KASUMI decrypt only (UEA1) */
4016 		TEST_CASE_ST(ut_setup, ut_teardown,
4017 			test_kasumi_decryption_test_case_1),
4018 		TEST_CASE_ST(ut_setup, ut_teardown,
4019 			test_kasumi_decryption_test_case_2),
4020 		TEST_CASE_ST(ut_setup, ut_teardown,
4021 			test_kasumi_decryption_test_case_3),
4022 		TEST_CASE_ST(ut_setup, ut_teardown,
4023 			test_kasumi_decryption_test_case_4),
4024 		TEST_CASE_ST(ut_setup, ut_teardown,
4025 			test_kasumi_decryption_test_case_5),
4026 
4027 		TEST_CASE_ST(ut_setup, ut_teardown,
4028 			test_kasumi_encryption_test_case_1_oop),
4029 		TEST_CASE_ST(ut_setup, ut_teardown,
4030 			test_kasumi_decryption_test_case_1_oop),
4031 
4032 		/** KASUMI hash only (UIA1) */
4033 		TEST_CASE_ST(ut_setup, ut_teardown,
4034 			test_kasumi_hash_generate_test_case_1),
4035 		TEST_CASE_ST(ut_setup, ut_teardown,
4036 			test_kasumi_hash_generate_test_case_2),
4037 		TEST_CASE_ST(ut_setup, ut_teardown,
4038 			test_kasumi_hash_generate_test_case_3),
4039 		TEST_CASE_ST(ut_setup, ut_teardown,
4040 			test_kasumi_hash_generate_test_case_4),
4041 		TEST_CASE_ST(ut_setup, ut_teardown,
4042 			test_kasumi_hash_generate_test_case_5),
4043 		TEST_CASE_ST(ut_setup, ut_teardown,
4044 			test_kasumi_hash_verify_test_case_1),
4045 		TEST_CASE_ST(ut_setup, ut_teardown,
4046 			test_kasumi_hash_verify_test_case_2),
4047 		TEST_CASE_ST(ut_setup, ut_teardown,
4048 			test_kasumi_hash_verify_test_case_3),
4049 		TEST_CASE_ST(ut_setup, ut_teardown,
4050 			test_kasumi_hash_verify_test_case_4),
4051 		TEST_CASE_ST(ut_setup, ut_teardown,
4052 			test_kasumi_hash_verify_test_case_5),
4053 
4054 		TEST_CASES_END() /**< NULL terminate unit test array */
4055 	}
4056 };
4057 static struct unit_test_suite cryptodev_sw_snow3g_testsuite  = {
4058 	.suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4059 	.setup = testsuite_setup,
4060 	.teardown = testsuite_teardown,
4061 	.unit_test_cases = {
4062 		/** Snow3G encrypt only (UEA2) */
4063 		TEST_CASE_ST(ut_setup, ut_teardown,
4064 			test_snow3g_encryption_test_case_1),
4065 		TEST_CASE_ST(ut_setup, ut_teardown,
4066 			test_snow3g_encryption_test_case_2),
4067 		TEST_CASE_ST(ut_setup, ut_teardown,
4068 			test_snow3g_encryption_test_case_3),
4069 		TEST_CASE_ST(ut_setup, ut_teardown,
4070 			test_snow3g_encryption_test_case_4),
4071 		TEST_CASE_ST(ut_setup, ut_teardown,
4072 			test_snow3g_encryption_test_case_5),
4073 
4074 		TEST_CASE_ST(ut_setup, ut_teardown,
4075 			test_snow3g_encryption_test_case_1_oop),
4076 		TEST_CASE_ST(ut_setup, ut_teardown,
4077 			test_snow3g_decryption_test_case_1_oop),
4078 
4079 		TEST_CASE_ST(ut_setup, ut_teardown,
4080 			test_snow3g_encryption_test_case_1_offset_oop),
4081 
4082 		/** Snow3G decrypt only (UEA2) */
4083 		TEST_CASE_ST(ut_setup, ut_teardown,
4084 			test_snow3g_decryption_test_case_1),
4085 		TEST_CASE_ST(ut_setup, ut_teardown,
4086 			test_snow3g_decryption_test_case_2),
4087 		TEST_CASE_ST(ut_setup, ut_teardown,
4088 			test_snow3g_decryption_test_case_3),
4089 		TEST_CASE_ST(ut_setup, ut_teardown,
4090 			test_snow3g_decryption_test_case_4),
4091 		TEST_CASE_ST(ut_setup, ut_teardown,
4092 			test_snow3g_decryption_test_case_5),
4093 		TEST_CASE_ST(ut_setup, ut_teardown,
4094 			test_snow3g_hash_generate_test_case_1),
4095 		TEST_CASE_ST(ut_setup, ut_teardown,
4096 			test_snow3g_hash_generate_test_case_2),
4097 		TEST_CASE_ST(ut_setup, ut_teardown,
4098 			test_snow3g_hash_generate_test_case_3),
4099 		/* Tests with buffers which length is not byte-aligned */
4100 		TEST_CASE_ST(ut_setup, ut_teardown,
4101 			test_snow3g_hash_generate_test_case_4),
4102 		TEST_CASE_ST(ut_setup, ut_teardown,
4103 			test_snow3g_hash_generate_test_case_5),
4104 		TEST_CASE_ST(ut_setup, ut_teardown,
4105 			test_snow3g_hash_generate_test_case_6),
4106 		TEST_CASE_ST(ut_setup, ut_teardown,
4107 			test_snow3g_hash_verify_test_case_1),
4108 		TEST_CASE_ST(ut_setup, ut_teardown,
4109 			test_snow3g_hash_verify_test_case_2),
4110 		TEST_CASE_ST(ut_setup, ut_teardown,
4111 			test_snow3g_hash_verify_test_case_3),
4112 		/* Tests with buffers which length is not byte-aligned */
4113 		TEST_CASE_ST(ut_setup, ut_teardown,
4114 			test_snow3g_hash_verify_test_case_4),
4115 		TEST_CASE_ST(ut_setup, ut_teardown,
4116 			test_snow3g_hash_verify_test_case_5),
4117 		TEST_CASE_ST(ut_setup, ut_teardown,
4118 			test_snow3g_hash_verify_test_case_6),
4119 		TEST_CASE_ST(ut_setup, ut_teardown,
4120 			test_snow3g_authenticated_encryption_test_case_1),
4121 		TEST_CASE_ST(ut_setup, ut_teardown,
4122 			test_snow3g_encrypted_authentication_test_case_1),
4123 
4124 		TEST_CASES_END() /**< NULL terminate unit test array */
4125 	}
4126 };
4127 
4128 static struct unit_test_suite cryptodev_null_testsuite  = {
4129 	.suite_name = "Crypto Device NULL Unit Test Suite",
4130 	.setup = testsuite_setup,
4131 	.teardown = testsuite_teardown,
4132 	.unit_test_cases = {
4133 		TEST_CASE_ST(ut_setup, ut_teardown,
4134 			test_null_auth_only_operation),
4135 		TEST_CASE_ST(ut_setup, ut_teardown,
4136 			test_null_cipher_only_operation),
4137 		TEST_CASE_ST(ut_setup, ut_teardown,
4138 			test_null_cipher_auth_operation),
4139 		TEST_CASE_ST(ut_setup, ut_teardown,
4140 			test_null_auth_cipher_operation),
4141 		TEST_CASE_ST(ut_setup, ut_teardown,
4142 			test_null_invalid_operation),
4143 		TEST_CASE_ST(ut_setup, ut_teardown,
4144 			test_null_burst_operation),
4145 
4146 		TEST_CASES_END() /**< NULL terminate unit test array */
4147 	}
4148 };
4149 
4150 static int
4151 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4152 {
4153 	gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4154 	return unit_test_suite_runner(&cryptodev_qat_testsuite);
4155 }
4156 static struct test_command cryptodev_qat_cmd = {
4157 	.command = "cryptodev_qat_autotest",
4158 	.callback = test_cryptodev_qat,
4159 };
4160 
4161 static int
4162 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4163 {
4164 	gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4165 
4166 	return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4167 }
4168 
4169 static struct test_command cryptodev_aesni_mb_cmd = {
4170 	.command = "cryptodev_aesni_mb_autotest",
4171 	.callback = test_cryptodev_aesni_mb,
4172 };
4173 
4174 static int
4175 test_cryptodev_aesni_gcm(void)
4176 {
4177 	gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4178 
4179 	return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4180 }
4181 
4182 static struct test_command cryptodev_aesni_gcm_cmd = {
4183 	.command = "cryptodev_aesni_gcm_autotest",
4184 	.callback = test_cryptodev_aesni_gcm,
4185 };
4186 
4187 static int
4188 test_cryptodev_null(void)
4189 {
4190 	gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4191 
4192 	return unit_test_suite_runner(&cryptodev_null_testsuite);
4193 }
4194 
4195 static struct test_command cryptodev_null_cmd = {
4196 	.command = "cryptodev_null_autotest",
4197 	.callback = test_cryptodev_null,
4198 };
4199 
4200 static int
4201 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4202 {
4203 	gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4204 
4205 	return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4206 }
4207 
4208 static struct test_command cryptodev_sw_snow3g_cmd = {
4209 	.command = "cryptodev_sw_snow3g_autotest",
4210 	.callback = test_cryptodev_sw_snow3g,
4211 };
4212 
4213 static int
4214 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
4215 {
4216 	gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
4217 
4218 	return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
4219 }
4220 
4221 static struct test_command cryptodev_sw_kasumi_cmd = {
4222 	.command = "cryptodev_sw_kasumi_autotest",
4223 	.callback = test_cryptodev_sw_kasumi,
4224 };
4225 
4226 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4227 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4228 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4229 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4230 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);
4231 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_cmd);
4232