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