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