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