4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
44 #include "test_cryptodev.h"
46 #include "test_cryptodev_aes.h"
47 #include "test_cryptodev_kasumi_test_vectors.h"
48 #include "test_cryptodev_kasumi_hash_test_vectors.h"
49 #include "test_cryptodev_snow3g_test_vectors.h"
50 #include "test_cryptodev_snow3g_hash_test_vectors.h"
51 #include "test_cryptodev_gcm_test_vectors.h"
52 #include "test_cryptodev_hmac_test_vectors.h"
54 static enum rte_cryptodev_type gbl_cryptodev_type;
56 struct crypto_testsuite_params {
57 struct rte_mempool *mbuf_pool;
58 struct rte_mempool *op_mpool;
59 struct rte_cryptodev_config conf;
60 struct rte_cryptodev_qp_conf qp_conf;
62 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
63 uint8_t valid_dev_count;
66 struct crypto_unittest_params {
67 struct rte_crypto_sym_xform cipher_xform;
68 struct rte_crypto_sym_xform auth_xform;
70 struct rte_cryptodev_sym_session *sess;
72 struct rte_crypto_op *op;
74 struct rte_mbuf *obuf, *ibuf;
79 #define ALIGN_POW2_ROUNDUP(num, align) \
80 (((num) + (align) - 1) & ~((align) - 1))
83 * Forward declarations.
86 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
87 struct crypto_unittest_params *ut_params);
90 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
91 struct crypto_unittest_params *ut_params,
92 struct crypto_testsuite_params *ts_param);
94 static struct rte_mbuf *
95 setup_test_string(struct rte_mempool *mpool,
96 const char *string, size_t len, uint8_t blocksize)
98 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
99 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
101 memset(m->buf_addr, 0, m->buf_len);
103 char *dst = rte_pktmbuf_append(m, t_len);
110 rte_memcpy(dst, string, t_len);
112 memset(dst, 0, t_len);
118 /* Get number of bytes in X bits (rounding up) */
120 ceil_byte_length(uint32_t num_bits)
123 return ((num_bits >> 3) + 1);
125 return (num_bits >> 3);
128 static struct rte_crypto_op *
129 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
131 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
132 printf("Error sending packet for encryption");
138 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
144 static struct crypto_testsuite_params testsuite_params = { NULL };
145 static struct crypto_unittest_params unittest_params;
148 testsuite_setup(void)
150 struct crypto_testsuite_params *ts_params = &testsuite_params;
151 struct rte_cryptodev_info info;
152 unsigned i, nb_devs, dev_id;
156 memset(ts_params, 0, sizeof(*ts_params));
158 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
159 if (ts_params->mbuf_pool == NULL) {
160 /* Not already created so create */
161 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
163 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
165 if (ts_params->mbuf_pool == NULL) {
166 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
171 ts_params->op_mpool = rte_crypto_op_pool_create(
172 "MBUF_CRYPTO_SYM_OP_POOL",
173 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
174 NUM_MBUFS, MBUF_CACHE_SIZE,
176 sizeof(struct rte_crypto_sym_xform),
178 if (ts_params->op_mpool == NULL) {
179 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
183 /* Create 2 AESNI MB devices if required */
184 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
185 nb_devs = rte_cryptodev_count_devtype(
186 RTE_CRYPTODEV_AESNI_MB_PMD);
188 for (i = nb_devs; i < 2; i++) {
189 ret = rte_eal_vdev_init(
190 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
192 TEST_ASSERT(ret == 0,
193 "Failed to create instance %u of"
195 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
200 /* Create 2 AESNI GCM devices if required */
201 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
202 nb_devs = rte_cryptodev_count_devtype(
203 RTE_CRYPTODEV_AESNI_GCM_PMD);
205 for (i = nb_devs; i < 2; i++) {
206 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
207 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
208 "Failed to create instance %u of"
210 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
215 /* Create 2 SNOW 3G devices if required */
216 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
217 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
219 for (i = nb_devs; i < 2; i++) {
220 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
221 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
222 "Failed to create instance %u of"
224 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
229 /* Create 2 KASUMI devices if required */
230 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
231 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
233 for (i = nb_devs; i < 2; i++) {
234 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
235 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
236 "Failed to create instance %u of"
238 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
243 /* Create 2 NULL devices if required */
244 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
245 nb_devs = rte_cryptodev_count_devtype(
246 RTE_CRYPTODEV_NULL_PMD);
248 for (i = nb_devs; i < 2; i++) {
249 int dev_id = rte_eal_vdev_init(
250 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
252 TEST_ASSERT(dev_id >= 0,
253 "Failed to create instance %u of"
255 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD));
260 nb_devs = rte_cryptodev_count();
262 RTE_LOG(ERR, USER1, "No crypto devices found?");
266 /* Create list of valid crypto devs */
267 for (i = 0; i < nb_devs; i++) {
268 rte_cryptodev_info_get(i, &info);
269 if (info.dev_type == gbl_cryptodev_type)
270 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
273 if (ts_params->valid_dev_count < 1)
276 /* Set up all the qps on the first of the valid devices found */
277 for (i = 0; i < 1; i++) {
278 dev_id = ts_params->valid_devs[i];
280 rte_cryptodev_info_get(dev_id, &info);
283 * Since we can't free and re-allocate queue memory always set
284 * the queues on this device up to max size first so enough
285 * memory is allocated for any later re-configures needed by
289 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
290 ts_params->conf.socket_id = SOCKET_ID_ANY;
291 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
293 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
295 "Failed to configure cryptodev %u with %u qps",
296 dev_id, ts_params->conf.nb_queue_pairs);
298 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
300 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
301 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
302 dev_id, qp_id, &ts_params->qp_conf,
303 rte_cryptodev_socket_id(dev_id)),
304 "Failed to setup queue pair %u on "
314 testsuite_teardown(void)
316 struct crypto_testsuite_params *ts_params = &testsuite_params;
318 if (ts_params->mbuf_pool != NULL) {
319 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
320 rte_mempool_avail_count(ts_params->mbuf_pool));
323 if (ts_params->op_mpool != NULL) {
324 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
325 rte_mempool_avail_count(ts_params->op_mpool));
333 struct crypto_testsuite_params *ts_params = &testsuite_params;
334 struct crypto_unittest_params *ut_params = &unittest_params;
338 /* Clear unit test parameters before running test */
339 memset(ut_params, 0, sizeof(*ut_params));
341 /* Reconfigure device to default parameters */
342 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
343 ts_params->conf.socket_id = SOCKET_ID_ANY;
344 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT;
346 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
348 "Failed to configure cryptodev %u",
349 ts_params->valid_devs[0]);
352 * Now reconfigure queues to size we actually want to use in this
355 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
357 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
358 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
359 ts_params->valid_devs[0], qp_id,
361 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
362 "Failed to setup queue pair %u on cryptodev %u",
363 qp_id, ts_params->valid_devs[0]);
367 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
369 /* Start the device */
370 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
371 "Failed to start cryptodev %u",
372 ts_params->valid_devs[0]);
380 struct crypto_testsuite_params *ts_params = &testsuite_params;
381 struct crypto_unittest_params *ut_params = &unittest_params;
382 struct rte_cryptodev_stats stats;
384 /* free crypto session structure */
385 if (ut_params->sess) {
386 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
388 ut_params->sess = NULL;
391 /* free crypto operation structure */
393 rte_crypto_op_free(ut_params->op);
396 * free mbuf - both obuf and ibuf are usually the same,
397 * so check if they point at the same address is necessary,
398 * to avoid freeing the mbuf twice.
400 if (ut_params->obuf) {
401 rte_pktmbuf_free(ut_params->obuf);
402 if (ut_params->ibuf == ut_params->obuf)
406 if (ut_params->ibuf) {
407 rte_pktmbuf_free(ut_params->ibuf);
411 if (ts_params->mbuf_pool != NULL)
412 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
413 rte_mempool_avail_count(ts_params->mbuf_pool));
415 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
417 /* Stop the device */
418 rte_cryptodev_stop(ts_params->valid_devs[0]);
422 test_device_configure_invalid_dev_id(void)
424 struct crypto_testsuite_params *ts_params = &testsuite_params;
425 uint16_t dev_id, num_devs = 0;
427 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
428 "Need at least %d devices for test", 1);
430 /* valid dev_id values */
431 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
433 /* Stop the device in case it's started so it can be configured */
434 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
436 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
437 "Failed test for rte_cryptodev_configure: "
438 "invalid dev_num %u", dev_id);
440 /* invalid dev_id values */
443 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
444 "Failed test for rte_cryptodev_configure: "
445 "invalid dev_num %u", dev_id);
449 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
450 "Failed test for rte_cryptodev_configure:"
451 "invalid dev_num %u", dev_id);
457 test_device_configure_invalid_queue_pair_ids(void)
459 struct crypto_testsuite_params *ts_params = &testsuite_params;
461 /* Stop the device in case it's started so it can be configured */
462 rte_cryptodev_stop(ts_params->valid_devs[0]);
464 /* valid - one queue pairs */
465 ts_params->conf.nb_queue_pairs = 1;
467 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
469 "Failed to configure cryptodev: dev_id %u, qp_id %u",
470 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
473 /* valid - max value queue pairs */
474 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
476 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
478 "Failed to configure cryptodev: dev_id %u, qp_id %u",
479 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
482 /* invalid - zero queue pairs */
483 ts_params->conf.nb_queue_pairs = 0;
485 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
487 "Failed test for rte_cryptodev_configure, dev_id %u,"
489 ts_params->valid_devs[0],
490 ts_params->conf.nb_queue_pairs);
493 /* invalid - max value supported by field queue pairs */
494 ts_params->conf.nb_queue_pairs = UINT16_MAX;
496 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
498 "Failed test for rte_cryptodev_configure, dev_id %u,"
500 ts_params->valid_devs[0],
501 ts_params->conf.nb_queue_pairs);
504 /* invalid - max value + 1 queue pairs */
505 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
507 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
509 "Failed test for rte_cryptodev_configure, dev_id %u,"
511 ts_params->valid_devs[0],
512 ts_params->conf.nb_queue_pairs);
518 test_queue_pair_descriptor_setup(void)
520 struct crypto_testsuite_params *ts_params = &testsuite_params;
521 struct rte_cryptodev_info dev_info;
522 struct rte_cryptodev_qp_conf qp_conf = {
523 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
528 /* Stop the device in case it's started so it can be configured */
529 rte_cryptodev_stop(ts_params->valid_devs[0]);
532 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
534 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
536 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
537 &ts_params->conf), "Failed to configure cryptodev %u",
538 ts_params->valid_devs[0]);
542 * Test various ring sizes on this device. memzones can't be
543 * freed so are re-used if ring is released and re-created.
545 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
547 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
548 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
549 ts_params->valid_devs[0], qp_id, &qp_conf,
550 rte_cryptodev_socket_id(
551 ts_params->valid_devs[0])),
553 "rte_cryptodev_queue_pair_setup: num_inflights "
554 "%u on qp %u on cryptodev %u",
555 qp_conf.nb_descriptors, qp_id,
556 ts_params->valid_devs[0]);
559 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
561 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
562 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
563 ts_params->valid_devs[0], qp_id, &qp_conf,
564 rte_cryptodev_socket_id(
565 ts_params->valid_devs[0])),
567 " rte_cryptodev_queue_pair_setup: num_inflights"
568 " %u on qp %u on cryptodev %u",
569 qp_conf.nb_descriptors, qp_id,
570 ts_params->valid_devs[0]);
573 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
575 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
576 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
577 ts_params->valid_devs[0], qp_id, &qp_conf,
578 rte_cryptodev_socket_id(
579 ts_params->valid_devs[0])),
581 "rte_cryptodev_queue_pair_setup: num_inflights"
582 " %u on qp %u on cryptodev %u",
583 qp_conf.nb_descriptors, qp_id,
584 ts_params->valid_devs[0]);
587 /* invalid number of descriptors - max supported + 2 */
588 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
590 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
591 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
592 ts_params->valid_devs[0], qp_id, &qp_conf,
593 rte_cryptodev_socket_id(
594 ts_params->valid_devs[0])),
595 "Unexpectedly passed test for "
596 "rte_cryptodev_queue_pair_setup:"
597 "num_inflights %u on qp %u on cryptodev %u",
598 qp_conf.nb_descriptors, qp_id,
599 ts_params->valid_devs[0]);
602 /* invalid number of descriptors - max value of parameter */
603 qp_conf.nb_descriptors = UINT32_MAX-1;
605 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
606 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
607 ts_params->valid_devs[0], qp_id, &qp_conf,
608 rte_cryptodev_socket_id(
609 ts_params->valid_devs[0])),
610 "Unexpectedly passed test for "
611 "rte_cryptodev_queue_pair_setup:"
612 "num_inflights %u on qp %u on cryptodev %u",
613 qp_conf.nb_descriptors, qp_id,
614 ts_params->valid_devs[0]);
617 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
619 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
620 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
621 ts_params->valid_devs[0], qp_id, &qp_conf,
622 rte_cryptodev_socket_id(
623 ts_params->valid_devs[0])),
625 " rte_cryptodev_queue_pair_setup:"
626 "num_inflights %u on qp %u on cryptodev %u",
627 qp_conf.nb_descriptors, qp_id,
628 ts_params->valid_devs[0]);
631 /* invalid number of descriptors - max supported + 1 */
632 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
634 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
635 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
636 ts_params->valid_devs[0], qp_id, &qp_conf,
637 rte_cryptodev_socket_id(
638 ts_params->valid_devs[0])),
639 "Unexpectedly passed test for "
640 "rte_cryptodev_queue_pair_setup:"
641 "num_inflights %u on qp %u on cryptodev %u",
642 qp_conf.nb_descriptors, qp_id,
643 ts_params->valid_devs[0]);
646 /* test invalid queue pair id */
647 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
649 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
651 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
652 ts_params->valid_devs[0],
654 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
655 "Failed test for rte_cryptodev_queue_pair_setup:"
656 "invalid qp %u on cryptodev %u",
657 qp_id, ts_params->valid_devs[0]);
659 qp_id = 0xffff; /*invalid*/
661 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
662 ts_params->valid_devs[0],
664 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
665 "Failed test for rte_cryptodev_queue_pair_setup:"
666 "invalid qp %u on cryptodev %u",
667 qp_id, ts_params->valid_devs[0]);
672 /* ***** Plaintext data for tests ***** */
674 const char catch_22_quote_1[] =
675 "There was only one catch and that was Catch-22, which "
676 "specified that a concern for one's safety in the face of "
677 "dangers that were real and immediate was the process of a "
678 "rational mind. Orr was crazy and could be grounded. All he "
679 "had to do was ask; and as soon as he did, he would no longer "
680 "be crazy and would have to fly more missions. Orr would be "
681 "crazy to fly more missions and sane if he didn't, but if he "
682 "was sane he had to fly them. If he flew them he was crazy "
683 "and didn't have to; but if he didn't want to he was sane and "
684 "had to. Yossarian was moved very deeply by the absolute "
685 "simplicity of this clause of Catch-22 and let out a "
686 "respectful whistle. \"That's some catch, that Catch-22\", he "
687 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
689 const char catch_22_quote[] =
690 "What a lousy earth! He wondered how many people were "
691 "destitute that same night even in his own prosperous country, "
692 "how many homes were shanties, how many husbands were drunk "
693 "and wives socked, and how many children were bullied, abused, "
694 "or abandoned. How many families hungered for food they could "
695 "not afford to buy? How many hearts were broken? How many "
696 "suicides would take place that same night, how many people "
697 "would go insane? How many cockroaches and landlords would "
698 "triumph? How many winners were losers, successes failures, "
699 "and rich men poor men? How many wise guys were stupid? How "
700 "many happy endings were unhappy endings? How many honest men "
701 "were liars, brave men cowards, loyal men traitors, how many "
702 "sainted men were corrupt, how many people in positions of "
703 "trust had sold their souls to bodyguards, how many had never "
704 "had souls? How many straight-and-narrow paths were crooked "
705 "paths? How many best families were worst families and how "
706 "many good people were bad people? When you added them all up "
707 "and then subtracted, you might be left with only the children, "
708 "and perhaps with Albert Einstein and an old violinist or "
709 "sculptor somewhere.";
711 #define QUOTE_480_BYTES (480)
712 #define QUOTE_512_BYTES (512)
713 #define QUOTE_768_BYTES (768)
714 #define QUOTE_1024_BYTES (1024)
718 /* ***** SHA1 Hash Tests ***** */
720 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
722 static uint8_t hmac_sha1_key[] = {
723 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
724 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
725 0xDE, 0xF4, 0xDE, 0xAD };
727 /* ***** SHA224 Hash Tests ***** */
729 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
732 /* ***** AES-CBC Cipher Tests ***** */
734 #define CIPHER_KEY_LENGTH_AES_CBC (16)
735 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
737 static uint8_t aes_cbc_key[] = {
738 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
739 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
741 static uint8_t aes_cbc_iv[] = {
742 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
743 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
746 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
748 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
749 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
750 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
751 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
752 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
753 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
754 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
755 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
756 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
757 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
758 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
759 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
760 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
761 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
762 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
763 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
764 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
765 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
766 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
767 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
768 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
769 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
770 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
771 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
772 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
773 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
774 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
775 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
776 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
777 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
778 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
779 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
780 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
781 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
782 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
783 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
784 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
785 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
786 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
787 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
788 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
789 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
790 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
791 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
792 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
793 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
794 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
795 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
796 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
797 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
798 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
799 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
800 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
801 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
802 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
803 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
804 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
805 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
806 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
807 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
808 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
809 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
810 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
811 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
812 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
815 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
816 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
817 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
818 0x18, 0x8c, 0x1d, 0x32
823 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
825 struct crypto_testsuite_params *ts_params = &testsuite_params;
826 struct crypto_unittest_params *ut_params = &unittest_params;
828 /* Generate test mbuf data and space for digest */
829 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
830 catch_22_quote, QUOTE_512_BYTES, 0);
832 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
833 DIGEST_BYTE_LENGTH_SHA1);
834 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
836 /* Setup Cipher Parameters */
837 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
838 ut_params->cipher_xform.next = &ut_params->auth_xform;
840 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
841 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
842 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
843 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
845 /* Setup HMAC Parameters */
846 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
848 ut_params->auth_xform.next = NULL;
850 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
851 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
852 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
853 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
854 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
856 /* Create crypto session*/
857 ut_params->sess = rte_cryptodev_sym_session_create(
858 ts_params->valid_devs[0],
859 &ut_params->cipher_xform);
860 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
862 /* Generate crypto op data structure */
863 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
864 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
865 TEST_ASSERT_NOT_NULL(ut_params->op,
866 "Failed to allocate symmetric crypto operation struct");
868 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
870 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
872 /* set crypto operation source mbuf */
873 sym_op->m_src = ut_params->ibuf;
875 /* Set crypto operation authentication parameters */
876 sym_op->auth.digest.data = ut_params->digest;
877 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
878 ut_params->ibuf, QUOTE_512_BYTES);
879 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
881 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
882 sym_op->auth.data.length = QUOTE_512_BYTES;
884 /* Set crypto operation cipher parameters */
885 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
886 CIPHER_IV_LENGTH_AES_CBC);
887 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
888 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
890 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
891 CIPHER_IV_LENGTH_AES_CBC);
893 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
894 sym_op->cipher.data.length = QUOTE_512_BYTES;
896 /* Process crypto operation */
897 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
898 ut_params->op), "failed to process sym crypto op");
900 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
901 "crypto op processing failed");
904 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
905 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
907 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
908 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
910 "ciphertext data not as expected");
912 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
914 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
915 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
916 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
917 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
918 DIGEST_BYTE_LENGTH_SHA1,
919 "Generated digest data not as expected");
924 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
926 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
928 static uint8_t hmac_sha512_key[] = {
929 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
930 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
931 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
932 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
933 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
934 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
935 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
936 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
938 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
939 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
940 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
941 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
942 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
943 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
944 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
945 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
946 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
951 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
952 struct crypto_unittest_params *ut_params);
955 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
956 struct crypto_unittest_params *ut_params,
957 struct crypto_testsuite_params *ts_params);
961 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
962 struct crypto_unittest_params *ut_params)
965 /* Setup Cipher Parameters */
966 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
967 ut_params->cipher_xform.next = NULL;
969 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
970 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
971 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
972 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
974 /* Setup HMAC Parameters */
975 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
976 ut_params->auth_xform.next = &ut_params->cipher_xform;
978 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
979 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
980 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
981 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
982 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
989 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
990 struct crypto_unittest_params *ut_params,
991 struct crypto_testsuite_params *ts_params)
993 /* Generate test mbuf data and digest */
994 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
996 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
999 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1000 DIGEST_BYTE_LENGTH_SHA512);
1001 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1003 rte_memcpy(ut_params->digest,
1004 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1005 DIGEST_BYTE_LENGTH_SHA512);
1007 /* Generate Crypto op data structure */
1008 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1009 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1010 TEST_ASSERT_NOT_NULL(ut_params->op,
1011 "Failed to allocate symmetric crypto operation struct");
1013 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1015 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1017 /* set crypto operation source mbuf */
1018 sym_op->m_src = ut_params->ibuf;
1020 sym_op->auth.digest.data = ut_params->digest;
1021 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1022 ut_params->ibuf, QUOTE_512_BYTES);
1023 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1025 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1026 sym_op->auth.data.length = QUOTE_512_BYTES;
1028 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1029 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1030 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1031 ut_params->ibuf, 0);
1032 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1034 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1035 CIPHER_IV_LENGTH_AES_CBC);
1037 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1038 sym_op->cipher.data.length = QUOTE_512_BYTES;
1040 /* Process crypto operation */
1041 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1042 ut_params->op), "failed to process sym crypto op");
1044 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1045 "crypto op processing failed");
1047 ut_params->obuf = ut_params->op->sym->m_src;
1050 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1051 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1052 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1054 "Plaintext data not as expected");
1057 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1058 "Digest verification failed");
1060 return TEST_SUCCESS;
1064 test_AES_mb_all(void)
1066 struct crypto_testsuite_params *ts_params = &testsuite_params;
1069 status = test_AES_all_tests(ts_params->mbuf_pool,
1070 ts_params->op_mpool, ts_params->valid_devs[0],
1071 RTE_CRYPTODEV_AESNI_MB_PMD);
1073 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1075 return TEST_SUCCESS;
1079 test_AES_qat_all(void)
1081 struct crypto_testsuite_params *ts_params = &testsuite_params;
1084 status = test_AES_all_tests(ts_params->mbuf_pool,
1085 ts_params->op_mpool, ts_params->valid_devs[0],
1086 RTE_CRYPTODEV_QAT_SYM_PMD);
1088 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1090 return TEST_SUCCESS;
1093 /* ***** SNOW 3G Tests ***** */
1095 create_snow3g_kasumi_hash_session(uint8_t dev_id,
1096 const uint8_t *key, const uint8_t key_len,
1097 const uint8_t aad_len, const uint8_t auth_len,
1098 enum rte_crypto_auth_operation op,
1099 enum rte_crypto_auth_algorithm algo)
1101 uint8_t hash_key[key_len];
1103 struct crypto_unittest_params *ut_params = &unittest_params;
1105 memcpy(hash_key, key, key_len);
1107 TEST_HEXDUMP(stdout, "key:", key, key_len);
1109 /* Setup Authentication Parameters */
1110 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1111 ut_params->auth_xform.next = NULL;
1113 ut_params->auth_xform.auth.op = op;
1114 ut_params->auth_xform.auth.algo = algo;
1115 ut_params->auth_xform.auth.key.length = key_len;
1116 ut_params->auth_xform.auth.key.data = hash_key;
1117 ut_params->auth_xform.auth.digest_length = auth_len;
1118 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1119 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1120 &ut_params->auth_xform);
1121 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1126 create_snow3g_kasumi_cipher_session(uint8_t dev_id,
1127 enum rte_crypto_cipher_operation op,
1128 enum rte_crypto_cipher_algorithm algo,
1129 const uint8_t *key, const uint8_t key_len)
1131 uint8_t cipher_key[key_len];
1133 struct crypto_unittest_params *ut_params = &unittest_params;
1135 memcpy(cipher_key, key, key_len);
1137 /* Setup Cipher Parameters */
1138 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1139 ut_params->cipher_xform.next = NULL;
1141 ut_params->cipher_xform.cipher.algo = algo;
1142 ut_params->cipher_xform.cipher.op = op;
1143 ut_params->cipher_xform.cipher.key.data = cipher_key;
1144 ut_params->cipher_xform.cipher.key.length = key_len;
1146 TEST_HEXDUMP(stdout, "key:", key, key_len);
1148 /* Create Crypto session */
1149 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1152 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1157 create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1158 const unsigned cipher_len,
1159 const unsigned cipher_offset,
1160 enum rte_crypto_cipher_algorithm algo)
1162 struct crypto_testsuite_params *ts_params = &testsuite_params;
1163 struct crypto_unittest_params *ut_params = &unittest_params;
1164 unsigned iv_pad_len = 0;
1166 /* Generate Crypto op data structure */
1167 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1168 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1169 TEST_ASSERT_NOT_NULL(ut_params->op,
1170 "Failed to allocate pktmbuf offload");
1172 /* Set crypto operation data parameters */
1173 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1175 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1177 /* set crypto operation source mbuf */
1178 sym_op->m_src = ut_params->ibuf;
1181 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1182 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1184 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1186 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1189 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1191 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1192 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1193 sym_op->cipher.iv.length = iv_pad_len;
1195 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1196 sym_op->cipher.data.length = cipher_len;
1197 sym_op->cipher.data.offset = cipher_offset;
1202 create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1203 const unsigned cipher_len,
1204 const unsigned cipher_offset,
1205 enum rte_crypto_cipher_algorithm algo)
1207 struct crypto_testsuite_params *ts_params = &testsuite_params;
1208 struct crypto_unittest_params *ut_params = &unittest_params;
1209 unsigned iv_pad_len = 0;
1211 /* Generate Crypto op data structure */
1212 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1213 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1214 TEST_ASSERT_NOT_NULL(ut_params->op,
1215 "Failed to allocate pktmbuf offload");
1217 /* Set crypto operation data parameters */
1218 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1220 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1222 /* set crypto operation source mbuf */
1223 sym_op->m_src = ut_params->ibuf;
1224 sym_op->m_dst = ut_params->obuf;
1227 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1228 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1230 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1231 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1234 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1236 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1237 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1238 sym_op->cipher.iv.length = iv_pad_len;
1240 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1241 sym_op->cipher.data.length = cipher_len;
1242 sym_op->cipher.data.offset = cipher_offset;
1247 create_snow3g_kasumi_cipher_auth_session(uint8_t dev_id,
1248 enum rte_crypto_cipher_operation cipher_op,
1249 enum rte_crypto_auth_operation auth_op,
1250 enum rte_crypto_auth_algorithm auth_algo,
1251 enum rte_crypto_cipher_algorithm cipher_algo,
1252 const uint8_t *key, const uint8_t key_len,
1253 const uint8_t aad_len, const uint8_t auth_len)
1256 uint8_t cipher_auth_key[key_len];
1258 struct crypto_unittest_params *ut_params = &unittest_params;
1260 memcpy(cipher_auth_key, key, key_len);
1262 /* Setup Authentication Parameters */
1263 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1264 ut_params->auth_xform.next = NULL;
1266 ut_params->auth_xform.auth.op = auth_op;
1267 ut_params->auth_xform.auth.algo = auth_algo;
1268 ut_params->auth_xform.auth.key.length = key_len;
1269 /* Hash key = cipher key */
1270 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1271 ut_params->auth_xform.auth.digest_length = auth_len;
1272 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1274 /* Setup Cipher Parameters */
1275 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1276 ut_params->cipher_xform.next = &ut_params->auth_xform;
1278 ut_params->cipher_xform.cipher.algo = cipher_algo;
1279 ut_params->cipher_xform.cipher.op = cipher_op;
1280 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1281 ut_params->cipher_xform.cipher.key.length = key_len;
1283 TEST_HEXDUMP(stdout, "key:", key, key_len);
1285 /* Create Crypto session*/
1286 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1287 &ut_params->cipher_xform);
1289 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1294 create_snow3g_kasumi_auth_cipher_session(uint8_t dev_id,
1295 enum rte_crypto_cipher_operation cipher_op,
1296 enum rte_crypto_auth_operation auth_op,
1297 enum rte_crypto_auth_algorithm auth_algo,
1298 enum rte_crypto_cipher_algorithm cipher_algo,
1299 const uint8_t *key, const uint8_t key_len,
1300 const uint8_t aad_len, const uint8_t auth_len)
1302 uint8_t auth_cipher_key[key_len];
1304 struct crypto_unittest_params *ut_params = &unittest_params;
1306 memcpy(auth_cipher_key, key, key_len);
1308 /* Setup Authentication Parameters */
1309 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1310 ut_params->auth_xform.auth.op = auth_op;
1311 ut_params->auth_xform.next = &ut_params->cipher_xform;
1312 ut_params->auth_xform.auth.algo = auth_algo;
1313 ut_params->auth_xform.auth.key.length = key_len;
1314 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1315 ut_params->auth_xform.auth.digest_length = auth_len;
1316 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1318 /* Setup Cipher Parameters */
1319 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1320 ut_params->cipher_xform.next = NULL;
1321 ut_params->cipher_xform.cipher.algo = cipher_algo;
1322 ut_params->cipher_xform.cipher.op = cipher_op;
1323 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1324 ut_params->cipher_xform.cipher.key.length = key_len;
1326 TEST_HEXDUMP(stdout, "key:", key, key_len);
1328 /* Create Crypto session*/
1329 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1330 &ut_params->auth_xform);
1332 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1338 create_snow3g_kasumi_hash_operation(const uint8_t *auth_tag,
1339 const unsigned auth_tag_len,
1340 const uint8_t *aad, const unsigned aad_len,
1341 unsigned data_pad_len,
1342 enum rte_crypto_auth_operation op,
1343 enum rte_crypto_auth_algorithm algo,
1344 const unsigned auth_len, const unsigned auth_offset)
1346 struct crypto_testsuite_params *ts_params = &testsuite_params;
1348 struct crypto_unittest_params *ut_params = &unittest_params;
1350 unsigned aad_buffer_len;
1352 /* Generate Crypto op data structure */
1353 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1354 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1355 TEST_ASSERT_NOT_NULL(ut_params->op,
1356 "Failed to allocate pktmbuf offload");
1358 /* Set crypto operation data parameters */
1359 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1361 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1363 /* set crypto operation source mbuf */
1364 sym_op->m_src = ut_params->ibuf;
1368 * Always allocate the aad up to the block size.
1369 * The cryptodev API calls out -
1370 * - the array must be big enough to hold the AAD, plus any
1371 * space to round this up to the nearest multiple of the
1372 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1374 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1375 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1377 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1378 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1379 ut_params->ibuf, aad_buffer_len);
1380 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1381 "no room to prepend aad");
1382 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1384 sym_op->auth.aad.length = aad_len;
1386 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1387 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1389 TEST_HEXDUMP(stdout, "aad:",
1390 sym_op->auth.aad.data, aad_len);
1393 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1394 ut_params->ibuf, auth_tag_len);
1396 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1397 "no room to append auth tag");
1398 ut_params->digest = sym_op->auth.digest.data;
1399 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1400 ut_params->ibuf, data_pad_len + aad_len);
1401 sym_op->auth.digest.length = auth_tag_len;
1402 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1403 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1405 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1407 TEST_HEXDUMP(stdout, "digest:",
1408 sym_op->auth.digest.data,
1409 sym_op->auth.digest.length);
1411 sym_op->auth.data.length = auth_len;
1412 sym_op->auth.data.offset = auth_offset;
1418 create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
1419 const unsigned auth_tag_len,
1420 const uint8_t *aad, const uint8_t aad_len,
1421 unsigned data_pad_len,
1422 enum rte_crypto_auth_operation op,
1423 enum rte_crypto_auth_algorithm auth_algo,
1424 enum rte_crypto_cipher_algorithm cipher_algo,
1425 const uint8_t *iv, const uint8_t iv_len,
1426 const unsigned cipher_len, const unsigned cipher_offset,
1427 const unsigned auth_len, const unsigned auth_offset)
1429 struct crypto_testsuite_params *ts_params = &testsuite_params;
1430 struct crypto_unittest_params *ut_params = &unittest_params;
1432 unsigned iv_pad_len = 0;
1433 unsigned aad_buffer_len;
1435 /* Generate Crypto op data structure */
1436 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1437 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1438 TEST_ASSERT_NOT_NULL(ut_params->op,
1439 "Failed to allocate pktmbuf offload");
1440 /* Set crypto operation data parameters */
1441 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1443 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1445 /* set crypto operation source mbuf */
1446 sym_op->m_src = ut_params->ibuf;
1449 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1450 ut_params->ibuf, auth_tag_len);
1452 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1453 "no room to append auth tag");
1454 ut_params->digest = sym_op->auth.digest.data;
1455 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1456 ut_params->ibuf, data_pad_len);
1457 sym_op->auth.digest.length = auth_tag_len;
1458 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1459 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1461 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1463 TEST_HEXDUMP(stdout, "digest:",
1464 sym_op->auth.digest.data,
1465 sym_op->auth.digest.length);
1469 * Always allocate the aad up to the block size.
1470 * The cryptodev API calls out -
1471 * - the array must be big enough to hold the AAD, plus any
1472 * space to round this up to the nearest multiple of the
1473 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1475 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1476 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1478 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1479 sym_op->auth.aad.data =
1480 (uint8_t *)rte_pktmbuf_prepend(
1481 ut_params->ibuf, aad_buffer_len);
1482 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1483 "no room to prepend aad");
1484 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1486 sym_op->auth.aad.length = aad_len;
1487 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1488 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1489 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1492 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1493 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1495 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1496 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1497 ut_params->ibuf, iv_pad_len);
1499 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1500 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1501 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1502 sym_op->cipher.iv.length = iv_pad_len;
1503 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1504 sym_op->cipher.data.length = cipher_len;
1505 sym_op->cipher.data.offset = cipher_offset + auth_offset;
1506 sym_op->auth.data.length = auth_len;
1507 sym_op->auth.data.offset = auth_offset + cipher_offset;
1513 create_snow3g_kasumi_auth_cipher_operation(const unsigned auth_tag_len,
1514 const uint8_t *iv, const uint8_t iv_len,
1515 const uint8_t *aad, const uint8_t aad_len,
1516 unsigned data_pad_len,
1517 const unsigned cipher_len, const unsigned cipher_offset,
1518 const unsigned auth_len, const unsigned auth_offset,
1519 enum rte_crypto_auth_algorithm auth_algo,
1520 enum rte_crypto_cipher_algorithm cipher_algo)
1522 struct crypto_testsuite_params *ts_params = &testsuite_params;
1523 struct crypto_unittest_params *ut_params = &unittest_params;
1525 unsigned iv_pad_len = 0;
1526 unsigned aad_buffer_len = 0;
1528 /* Generate Crypto op data structure */
1529 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1530 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1531 TEST_ASSERT_NOT_NULL(ut_params->op,
1532 "Failed to allocate pktmbuf offload");
1534 /* Set crypto operation data parameters */
1535 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1537 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1539 /* set crypto operation source mbuf */
1540 sym_op->m_src = ut_params->ibuf;
1543 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1544 ut_params->ibuf, auth_tag_len);
1546 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1547 "no room to append auth tag");
1549 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1550 ut_params->ibuf, data_pad_len);
1551 sym_op->auth.digest.length = auth_tag_len;
1553 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1555 TEST_HEXDUMP(stdout, "digest:",
1556 sym_op->auth.digest.data,
1557 sym_op->auth.digest.length);
1561 * Always allocate the aad up to the block size.
1562 * The cryptodev API calls out -
1563 * - the array must be big enough to hold the AAD, plus any
1564 * space to round this up to the nearest multiple of the
1565 * block size (8 bytes for KASUMI 16 bytes).
1567 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1568 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1570 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1571 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1572 ut_params->ibuf, aad_buffer_len);
1573 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1574 "no room to prepend aad");
1575 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1577 sym_op->auth.aad.length = aad_len;
1578 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1579 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1580 TEST_HEXDUMP(stdout, "aad:",
1581 sym_op->auth.aad.data, aad_len);
1584 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1585 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1587 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1589 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1590 ut_params->ibuf, iv_pad_len);
1591 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1593 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1594 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1595 sym_op->cipher.iv.length = iv_pad_len;
1597 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1599 sym_op->cipher.data.length = cipher_len;
1600 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1602 sym_op->auth.data.length = auth_len;
1603 sym_op->auth.data.offset = auth_offset + cipher_offset;
1609 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1611 struct crypto_testsuite_params *ts_params = &testsuite_params;
1612 struct crypto_unittest_params *ut_params = &unittest_params;
1615 unsigned plaintext_pad_len;
1616 unsigned plaintext_len;
1619 /* Create SNOW 3G session */
1620 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1621 tdata->key.data, tdata->key.len,
1622 tdata->aad.len, tdata->digest.len,
1623 RTE_CRYPTO_AUTH_OP_GENERATE,
1624 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1628 /* alloc mbuf and set payload */
1629 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1631 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1632 rte_pktmbuf_tailroom(ut_params->ibuf));
1634 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1635 /* Append data which is padded to a multiple of */
1636 /* the algorithms block size */
1637 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1638 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1640 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1642 /* Create SNOW 3G operation */
1643 retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1644 tdata->aad.data, tdata->aad.len,
1645 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1646 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1647 tdata->validAuthLenInBits.len,
1648 tdata->validAuthOffsetLenInBits.len);
1652 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1654 ut_params->obuf = ut_params->op->sym->m_src;
1655 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1656 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1657 + plaintext_pad_len + tdata->aad.len;
1660 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1663 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1664 "SNOW 3G Generated auth tag not as expected");
1670 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1672 struct crypto_testsuite_params *ts_params = &testsuite_params;
1673 struct crypto_unittest_params *ut_params = &unittest_params;
1676 unsigned plaintext_pad_len;
1677 unsigned plaintext_len;
1680 /* Create SNOW 3G session */
1681 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1682 tdata->key.data, tdata->key.len,
1683 tdata->aad.len, tdata->digest.len,
1684 RTE_CRYPTO_AUTH_OP_VERIFY,
1685 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1688 /* alloc mbuf and set payload */
1689 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1691 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1692 rte_pktmbuf_tailroom(ut_params->ibuf));
1694 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1695 /* Append data which is padded to a multiple of */
1696 /* the algorithms block size */
1697 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1698 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1700 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1702 /* Create SNOW 3G operation */
1703 retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1705 tdata->aad.data, tdata->aad.len,
1707 RTE_CRYPTO_AUTH_OP_VERIFY,
1708 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1709 tdata->validAuthLenInBits.len,
1710 tdata->validAuthOffsetLenInBits.len);
1714 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1716 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1717 ut_params->obuf = ut_params->op->sym->m_src;
1718 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1719 + plaintext_pad_len + tdata->aad.len;
1722 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1731 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1733 struct crypto_testsuite_params *ts_params = &testsuite_params;
1734 struct crypto_unittest_params *ut_params = &unittest_params;
1737 unsigned plaintext_pad_len;
1738 unsigned plaintext_len;
1741 /* Create KASUMI session */
1742 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1743 tdata->key.data, tdata->key.len,
1744 tdata->aad.len, tdata->digest.len,
1745 RTE_CRYPTO_AUTH_OP_GENERATE,
1746 RTE_CRYPTO_AUTH_KASUMI_F9);
1750 /* alloc mbuf and set payload */
1751 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1753 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1754 rte_pktmbuf_tailroom(ut_params->ibuf));
1756 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1757 /* Append data which is padded to a multiple of */
1758 /* the algorithms block size */
1759 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1760 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1762 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1764 /* Create KASUMI operation */
1765 retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1766 tdata->aad.data, tdata->aad.len,
1767 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1768 RTE_CRYPTO_AUTH_KASUMI_F9,
1769 tdata->validAuthLenInBits.len,
1770 tdata->validAuthOffsetLenInBits.len);
1774 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1776 ut_params->obuf = ut_params->op->sym->m_src;
1777 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1778 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1779 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1782 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1785 DIGEST_BYTE_LENGTH_KASUMI_F9,
1786 "KASUMI Generated auth tag not as expected");
1792 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1794 struct crypto_testsuite_params *ts_params = &testsuite_params;
1795 struct crypto_unittest_params *ut_params = &unittest_params;
1798 unsigned plaintext_pad_len;
1799 unsigned plaintext_len;
1802 /* Create KASUMI session */
1803 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1804 tdata->key.data, tdata->key.len,
1805 tdata->aad.len, tdata->digest.len,
1806 RTE_CRYPTO_AUTH_OP_VERIFY,
1807 RTE_CRYPTO_AUTH_KASUMI_F9);
1810 /* alloc mbuf and set payload */
1811 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1813 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1814 rte_pktmbuf_tailroom(ut_params->ibuf));
1816 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1817 /* Append data which is padded to a multiple */
1818 /* of the algorithms block size */
1819 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1820 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1822 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1824 /* Create KASUMI operation */
1825 retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1827 tdata->aad.data, tdata->aad.len,
1829 RTE_CRYPTO_AUTH_OP_VERIFY,
1830 RTE_CRYPTO_AUTH_KASUMI_F9,
1831 tdata->validAuthLenInBits.len,
1832 tdata->validAuthOffsetLenInBits.len);
1836 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1838 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1839 ut_params->obuf = ut_params->op->sym->m_src;
1840 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1841 + plaintext_pad_len + tdata->aad.len;
1844 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1853 test_snow3g_hash_generate_test_case_1(void)
1855 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1859 test_snow3g_hash_generate_test_case_2(void)
1861 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1865 test_snow3g_hash_generate_test_case_3(void)
1867 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1871 test_snow3g_hash_generate_test_case_4(void)
1873 return test_snow3g_authentication(&snow3g_hash_test_case_4);
1877 test_snow3g_hash_generate_test_case_5(void)
1879 return test_snow3g_authentication(&snow3g_hash_test_case_5);
1883 test_snow3g_hash_generate_test_case_6(void)
1885 return test_snow3g_authentication(&snow3g_hash_test_case_6);
1889 test_snow3g_hash_verify_test_case_1(void)
1891 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1896 test_snow3g_hash_verify_test_case_2(void)
1898 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1902 test_snow3g_hash_verify_test_case_3(void)
1904 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1908 test_snow3g_hash_verify_test_case_4(void)
1910 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
1914 test_snow3g_hash_verify_test_case_5(void)
1916 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
1920 test_snow3g_hash_verify_test_case_6(void)
1922 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
1926 test_kasumi_hash_generate_test_case_1(void)
1928 return test_kasumi_authentication(&kasumi_hash_test_case_1);
1932 test_kasumi_hash_generate_test_case_2(void)
1934 return test_kasumi_authentication(&kasumi_hash_test_case_2);
1938 test_kasumi_hash_generate_test_case_3(void)
1940 return test_kasumi_authentication(&kasumi_hash_test_case_3);
1944 test_kasumi_hash_generate_test_case_4(void)
1946 return test_kasumi_authentication(&kasumi_hash_test_case_4);
1950 test_kasumi_hash_generate_test_case_5(void)
1952 return test_kasumi_authentication(&kasumi_hash_test_case_5);
1956 test_kasumi_hash_generate_test_case_6(void)
1958 return test_kasumi_authentication(&kasumi_hash_test_case_6);
1962 test_kasumi_hash_verify_test_case_1(void)
1964 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
1968 test_kasumi_hash_verify_test_case_2(void)
1970 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
1974 test_kasumi_hash_verify_test_case_3(void)
1976 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
1980 test_kasumi_hash_verify_test_case_4(void)
1982 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
1986 test_kasumi_hash_verify_test_case_5(void)
1988 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
1992 test_kasumi_encryption(const struct kasumi_test_data *tdata)
1994 struct crypto_testsuite_params *ts_params = &testsuite_params;
1995 struct crypto_unittest_params *ut_params = &unittest_params;
1998 uint8_t *plaintext, *ciphertext;
1999 unsigned plaintext_pad_len;
2000 unsigned plaintext_len;
2002 /* Create KASUMI session */
2003 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2004 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2005 RTE_CRYPTO_CIPHER_KASUMI_F8,
2006 tdata->key.data, tdata->key.len);
2010 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2012 /* Clear mbuf payload */
2013 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2014 rte_pktmbuf_tailroom(ut_params->ibuf));
2016 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2017 /* Append data which is padded to a multiple */
2018 /* of the algorithms block size */
2019 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2020 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2022 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2024 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2026 /* Create KASUMI operation */
2027 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2028 tdata->plaintext.len,
2029 tdata->validCipherOffsetLenInBits.len,
2030 RTE_CRYPTO_CIPHER_KASUMI_F8);
2034 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2036 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2038 ut_params->obuf = ut_params->op->sym->m_dst;
2039 if (ut_params->obuf)
2040 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2043 ciphertext = plaintext;
2045 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2048 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2050 tdata->ciphertext.data,
2051 tdata->validCipherLenInBits.len,
2052 "KASUMI Ciphertext data not as expected");
2057 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2059 struct crypto_testsuite_params *ts_params = &testsuite_params;
2060 struct crypto_unittest_params *ut_params = &unittest_params;
2063 uint8_t *plaintext, *ciphertext;
2064 unsigned plaintext_pad_len;
2065 unsigned plaintext_len;
2067 /* Create KASUMI session */
2068 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2069 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2070 RTE_CRYPTO_CIPHER_KASUMI_F8,
2071 tdata->key.data, tdata->key.len);
2075 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2076 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2078 /* Clear mbuf payload */
2079 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2080 rte_pktmbuf_tailroom(ut_params->ibuf));
2082 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2083 /* Append data which is padded to a multiple */
2084 /* of the algorithms block size */
2085 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2086 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2088 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2089 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2091 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2093 /* Create KASUMI operation */
2094 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2096 tdata->plaintext.len,
2097 tdata->validCipherOffsetLenInBits.len,
2098 RTE_CRYPTO_CIPHER_KASUMI_F8);
2102 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2104 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2106 ut_params->obuf = ut_params->op->sym->m_dst;
2107 if (ut_params->obuf)
2108 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2111 ciphertext = plaintext;
2113 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2116 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2118 tdata->ciphertext.data,
2119 tdata->validCipherLenInBits.len,
2120 "KASUMI Ciphertext data not as expected");
2125 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2127 struct crypto_testsuite_params *ts_params = &testsuite_params;
2128 struct crypto_unittest_params *ut_params = &unittest_params;
2131 uint8_t *ciphertext, *plaintext;
2132 unsigned ciphertext_pad_len;
2133 unsigned ciphertext_len;
2135 /* Create KASUMI session */
2136 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2137 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2138 RTE_CRYPTO_CIPHER_KASUMI_F8,
2139 tdata->key.data, tdata->key.len);
2143 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2144 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2146 /* Clear mbuf payload */
2147 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2148 rte_pktmbuf_tailroom(ut_params->ibuf));
2150 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2151 /* Append data which is padded to a multiple */
2152 /* of the algorithms block size */
2153 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2154 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2155 ciphertext_pad_len);
2156 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2157 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2159 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2161 /* Create KASUMI operation */
2162 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2164 tdata->ciphertext.len,
2165 tdata->validCipherOffsetLenInBits.len,
2166 RTE_CRYPTO_CIPHER_KASUMI_F8);
2170 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2172 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2174 ut_params->obuf = ut_params->op->sym->m_dst;
2175 if (ut_params->obuf)
2176 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2179 plaintext = ciphertext;
2181 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2184 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2186 tdata->plaintext.data,
2187 tdata->validCipherLenInBits.len,
2188 "KASUMI Plaintext data not as expected");
2193 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2195 struct crypto_testsuite_params *ts_params = &testsuite_params;
2196 struct crypto_unittest_params *ut_params = &unittest_params;
2199 uint8_t *ciphertext, *plaintext;
2200 unsigned ciphertext_pad_len;
2201 unsigned ciphertext_len;
2203 /* Create KASUMI session */
2204 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2205 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2206 RTE_CRYPTO_CIPHER_KASUMI_F8,
2207 tdata->key.data, tdata->key.len);
2211 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2213 /* Clear mbuf payload */
2214 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2215 rte_pktmbuf_tailroom(ut_params->ibuf));
2217 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2218 /* Append data which is padded to a multiple */
2219 /* of the algorithms block size */
2220 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2221 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2222 ciphertext_pad_len);
2223 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2225 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2227 /* Create KASUMI operation */
2228 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data,
2230 tdata->ciphertext.len,
2231 tdata->validCipherOffsetLenInBits.len,
2232 RTE_CRYPTO_CIPHER_KASUMI_F8);
2236 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2238 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2240 ut_params->obuf = ut_params->op->sym->m_dst;
2241 if (ut_params->obuf)
2242 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2245 plaintext = ciphertext;
2247 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2250 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2252 tdata->plaintext.data,
2253 tdata->validCipherLenInBits.len,
2254 "KASUMI Plaintext data not as expected");
2259 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2261 struct crypto_testsuite_params *ts_params = &testsuite_params;
2262 struct crypto_unittest_params *ut_params = &unittest_params;
2265 uint8_t *plaintext, *ciphertext;
2266 unsigned plaintext_pad_len;
2267 unsigned plaintext_len;
2269 /* Create SNOW 3G session */
2270 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2271 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2272 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2273 tdata->key.data, tdata->key.len);
2277 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2279 /* Clear mbuf payload */
2280 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2281 rte_pktmbuf_tailroom(ut_params->ibuf));
2283 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2284 /* Append data which is padded to a multiple of */
2285 /* the algorithms block size */
2286 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2287 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2289 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2291 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2293 /* Create SNOW 3G operation */
2294 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2295 tdata->validCipherLenInBits.len,
2296 tdata->validCipherOffsetLenInBits.len,
2297 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2301 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2303 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2305 ut_params->obuf = ut_params->op->sym->m_dst;
2306 if (ut_params->obuf)
2307 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2310 ciphertext = plaintext;
2312 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2315 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2317 tdata->ciphertext.data,
2318 tdata->validDataLenInBits.len,
2319 "SNOW 3G Ciphertext data not as expected");
2325 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2327 struct crypto_testsuite_params *ts_params = &testsuite_params;
2328 struct crypto_unittest_params *ut_params = &unittest_params;
2329 uint8_t *plaintext, *ciphertext;
2332 unsigned plaintext_pad_len;
2333 unsigned plaintext_len;
2335 /* Create SNOW 3G session */
2336 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2337 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2338 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2339 tdata->key.data, tdata->key.len);
2343 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2344 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2346 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2347 "Failed to allocate input buffer in mempool");
2348 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2349 "Failed to allocate output buffer in mempool");
2351 /* Clear mbuf payload */
2352 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2353 rte_pktmbuf_tailroom(ut_params->ibuf));
2355 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2356 /* Append data which is padded to a multiple of */
2357 /* the algorithms block size */
2358 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2359 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2361 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2362 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2364 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2366 /* Create SNOW 3G operation */
2367 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2369 tdata->validCipherLenInBits.len,
2370 tdata->validCipherOffsetLenInBits.len,
2371 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2375 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2377 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2379 ut_params->obuf = ut_params->op->sym->m_dst;
2380 if (ut_params->obuf)
2381 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2384 ciphertext = plaintext;
2386 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2389 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2391 tdata->ciphertext.data,
2392 tdata->validDataLenInBits.len,
2393 "SNOW 3G Ciphertext data not as expected");
2397 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2399 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2401 uint8_t curr_byte, prev_byte;
2402 uint32_t length_in_bytes = ceil_byte_length(length + offset);
2403 uint8_t lower_byte_mask = (1 << offset) - 1;
2406 prev_byte = buffer[0];
2407 buffer[0] >>= offset;
2409 for (i = 1; i < length_in_bytes; i++) {
2410 curr_byte = buffer[i];
2411 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2412 (curr_byte >> offset);
2413 prev_byte = curr_byte;
2418 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2420 struct crypto_testsuite_params *ts_params = &testsuite_params;
2421 struct crypto_unittest_params *ut_params = &unittest_params;
2422 uint8_t *plaintext, *ciphertext;
2424 uint32_t plaintext_len;
2425 uint32_t plaintext_pad_len;
2426 uint8_t extra_offset = 4;
2427 uint8_t *expected_ciphertext_shifted;
2429 /* Create SNOW 3G session */
2430 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2431 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2432 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2433 tdata->key.data, tdata->key.len);
2437 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2438 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2440 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2441 "Failed to allocate input buffer in mempool");
2442 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2443 "Failed to allocate output buffer in mempool");
2445 /* Clear mbuf payload */
2446 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2447 rte_pktmbuf_tailroom(ut_params->ibuf));
2449 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2451 * Append data which is padded to a
2452 * multiple of the algorithms block size
2454 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2456 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2459 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2461 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2462 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2464 #ifdef RTE_APP_TEST_DEBUG
2465 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2467 /* Create SNOW 3G operation */
2468 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2470 tdata->validCipherLenInBits.len,
2471 tdata->validCipherOffsetLenInBits.len +
2473 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2477 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2479 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2481 ut_params->obuf = ut_params->op->sym->m_dst;
2482 if (ut_params->obuf)
2483 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2486 ciphertext = plaintext;
2488 #ifdef RTE_APP_TEST_DEBUG
2489 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2492 expected_ciphertext_shifted = rte_malloc(NULL,
2493 ceil_byte_length(plaintext_len + extra_offset), 0);
2495 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2496 "failed to reserve memory for ciphertext shifted\n");
2498 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2499 ceil_byte_length(tdata->ciphertext.len));
2500 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2503 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2505 expected_ciphertext_shifted,
2506 tdata->validDataLenInBits.len,
2508 "SNOW 3G Ciphertext data not as expected");
2512 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2514 struct crypto_testsuite_params *ts_params = &testsuite_params;
2515 struct crypto_unittest_params *ut_params = &unittest_params;
2519 uint8_t *plaintext, *ciphertext;
2520 unsigned ciphertext_pad_len;
2521 unsigned ciphertext_len;
2523 /* Create SNOW 3G session */
2524 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2525 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2526 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2527 tdata->key.data, tdata->key.len);
2531 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2533 /* Clear mbuf payload */
2534 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2535 rte_pktmbuf_tailroom(ut_params->ibuf));
2537 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2538 /* Append data which is padded to a multiple of */
2539 /* the algorithms block size */
2540 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2541 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2542 ciphertext_pad_len);
2543 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2545 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2547 /* Create SNOW 3G operation */
2548 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2549 tdata->validCipherLenInBits.len,
2550 tdata->validCipherOffsetLenInBits.len,
2551 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2555 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2557 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2558 ut_params->obuf = ut_params->op->sym->m_dst;
2559 if (ut_params->obuf)
2560 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2563 plaintext = ciphertext;
2565 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2568 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2569 tdata->plaintext.data,
2570 tdata->validDataLenInBits.len,
2571 "SNOW 3G Plaintext data not as expected");
2575 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2577 struct crypto_testsuite_params *ts_params = &testsuite_params;
2578 struct crypto_unittest_params *ut_params = &unittest_params;
2582 uint8_t *plaintext, *ciphertext;
2583 unsigned ciphertext_pad_len;
2584 unsigned ciphertext_len;
2586 /* Create SNOW 3G session */
2587 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2588 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2589 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2590 tdata->key.data, tdata->key.len);
2594 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2595 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2597 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2598 "Failed to allocate input buffer");
2599 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2600 "Failed to allocate output buffer");
2602 /* Clear mbuf payload */
2603 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2604 rte_pktmbuf_tailroom(ut_params->ibuf));
2606 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2607 rte_pktmbuf_tailroom(ut_params->obuf));
2609 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2610 /* Append data which is padded to a multiple of */
2611 /* the algorithms block size */
2612 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2613 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2614 ciphertext_pad_len);
2615 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2616 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2618 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2620 /* Create SNOW 3G operation */
2621 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2623 tdata->validCipherLenInBits.len,
2624 tdata->validCipherOffsetLenInBits.len,
2625 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2629 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2631 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2632 ut_params->obuf = ut_params->op->sym->m_dst;
2633 if (ut_params->obuf)
2634 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2637 plaintext = ciphertext;
2639 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2642 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2643 tdata->plaintext.data,
2644 tdata->validDataLenInBits.len,
2645 "SNOW 3G Plaintext data not as expected");
2650 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
2652 struct crypto_testsuite_params *ts_params = &testsuite_params;
2653 struct crypto_unittest_params *ut_params = &unittest_params;
2657 uint8_t *plaintext, *ciphertext;
2658 unsigned plaintext_pad_len;
2659 unsigned plaintext_len;
2661 /* Create SNOW 3G session */
2662 retval = create_snow3g_kasumi_cipher_auth_session(ts_params->valid_devs[0],
2663 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2664 RTE_CRYPTO_AUTH_OP_GENERATE,
2665 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2666 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2667 tdata->key.data, tdata->key.len,
2668 tdata->aad.len, tdata->digest.len);
2671 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2673 /* clear mbuf payload */
2674 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2675 rte_pktmbuf_tailroom(ut_params->ibuf));
2677 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2678 /* Append data which is padded to a multiple of */
2679 /* the algorithms block size */
2680 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2681 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2683 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2685 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2687 /* Create SNOW 3G operation */
2688 retval = create_snow3g_kasumi_cipher_hash_operation(tdata->digest.data,
2689 tdata->digest.len, tdata->aad.data,
2690 tdata->aad.len, /*tdata->plaintext.len,*/
2691 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2692 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2693 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2694 tdata->iv.data, tdata->iv.len,
2695 tdata->validCipherLenInBits.len,
2696 tdata->validCipherOffsetLenInBits.len,
2697 tdata->validAuthLenInBits.len,
2698 tdata->validAuthOffsetLenInBits.len
2703 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2705 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2706 ut_params->obuf = ut_params->op->sym->m_src;
2707 if (ut_params->obuf)
2708 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2709 + tdata->iv.len + tdata->aad.len;
2711 ciphertext = plaintext;
2713 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2715 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2717 tdata->ciphertext.data,
2718 tdata->validDataLenInBits.len,
2719 "SNOW 3G Ciphertext data not as expected");
2721 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2722 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2725 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2728 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2729 "SNOW 3G Generated auth tag not as expected");
2733 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
2735 struct crypto_testsuite_params *ts_params = &testsuite_params;
2736 struct crypto_unittest_params *ut_params = &unittest_params;
2740 uint8_t *plaintext, *ciphertext;
2741 unsigned plaintext_pad_len;
2742 unsigned plaintext_len;
2744 /* Create SNOW 3G session */
2745 retval = create_snow3g_kasumi_auth_cipher_session(ts_params->valid_devs[0],
2746 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2747 RTE_CRYPTO_AUTH_OP_GENERATE,
2748 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2749 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2750 tdata->key.data, tdata->key.len,
2751 tdata->aad.len, tdata->digest.len);
2755 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2757 /* clear mbuf payload */
2758 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2759 rte_pktmbuf_tailroom(ut_params->ibuf));
2761 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2762 /* Append data which is padded to a multiple of */
2763 /* the algorithms block size */
2764 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2765 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2767 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2769 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2771 /* Create SNOW 3G operation */
2772 retval = create_snow3g_kasumi_auth_cipher_operation(
2774 tdata->iv.data, tdata->iv.len,
2775 tdata->aad.data, tdata->aad.len,
2777 tdata->validCipherLenInBits.len,
2778 tdata->validCipherOffsetLenInBits.len,
2779 tdata->validAuthLenInBits.len,
2780 tdata->validAuthOffsetLenInBits.len,
2781 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2782 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
2788 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2790 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2791 ut_params->obuf = ut_params->op->sym->m_src;
2792 if (ut_params->obuf)
2793 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2794 + tdata->aad.len + tdata->iv.len;
2796 ciphertext = plaintext;
2798 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2799 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2800 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2803 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2805 tdata->ciphertext.data,
2806 tdata->validDataLenInBits.len,
2807 "SNOW 3G Ciphertext data not as expected");
2810 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2813 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2814 "SNOW 3G Generated auth tag not as expected");
2819 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
2821 struct crypto_testsuite_params *ts_params = &testsuite_params;
2822 struct crypto_unittest_params *ut_params = &unittest_params;
2826 uint8_t *plaintext, *ciphertext;
2827 unsigned plaintext_pad_len;
2828 unsigned plaintext_len;
2830 /* Create KASUMI session */
2831 retval = create_snow3g_kasumi_auth_cipher_session(
2832 ts_params->valid_devs[0],
2833 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2834 RTE_CRYPTO_AUTH_OP_GENERATE,
2835 RTE_CRYPTO_AUTH_KASUMI_F9,
2836 RTE_CRYPTO_CIPHER_KASUMI_F8,
2837 tdata->key.data, tdata->key.len,
2838 tdata->aad.len, tdata->digest.len);
2841 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2843 /* clear mbuf payload */
2844 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2845 rte_pktmbuf_tailroom(ut_params->ibuf));
2847 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2848 /* Append data which is padded to a multiple of */
2849 /* the algorithms block size */
2850 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2851 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2853 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2855 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2857 /* Create KASUMI operation */
2858 retval = create_snow3g_kasumi_auth_cipher_operation(tdata->digest.len,
2859 tdata->iv.data, tdata->iv.len,
2860 tdata->aad.data, tdata->aad.len,
2862 tdata->validCipherLenInBits.len,
2863 tdata->validCipherOffsetLenInBits.len,
2864 tdata->validAuthLenInBits.len,
2865 tdata->validAuthOffsetLenInBits.len,
2866 RTE_CRYPTO_AUTH_KASUMI_F9,
2867 RTE_CRYPTO_CIPHER_KASUMI_F8
2873 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2875 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2876 ut_params->obuf = ut_params->op->sym->m_src;
2877 if (ut_params->obuf)
2878 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2879 + tdata->iv.len + tdata->aad.len;
2881 ciphertext = plaintext;
2884 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2886 tdata->ciphertext.data,
2887 tdata->validCipherLenInBits.len,
2888 "KASUMI Ciphertext data not as expected");
2889 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2890 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2893 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2896 DIGEST_BYTE_LENGTH_KASUMI_F9,
2897 "KASUMI Generated auth tag not as expected");
2902 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
2904 struct crypto_testsuite_params *ts_params = &testsuite_params;
2905 struct crypto_unittest_params *ut_params = &unittest_params;
2909 uint8_t *plaintext, *ciphertext;
2910 unsigned plaintext_pad_len;
2911 unsigned plaintext_len;
2913 /* Create KASUMI session */
2914 retval = create_snow3g_kasumi_cipher_auth_session(
2915 ts_params->valid_devs[0],
2916 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2917 RTE_CRYPTO_AUTH_OP_GENERATE,
2918 RTE_CRYPTO_AUTH_KASUMI_F9,
2919 RTE_CRYPTO_CIPHER_KASUMI_F8,
2920 tdata->key.data, tdata->key.len,
2921 tdata->aad.len, tdata->digest.len);
2925 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2927 /* clear mbuf payload */
2928 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2929 rte_pktmbuf_tailroom(ut_params->ibuf));
2931 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2932 /* Append data which is padded to a multiple of */
2933 /* the algorithms block size */
2934 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2935 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2937 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2939 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2941 /* Create KASUMI operation */
2942 retval = create_snow3g_kasumi_cipher_hash_operation(tdata->digest.data,
2943 tdata->digest.len, tdata->aad.data,
2945 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2946 RTE_CRYPTO_AUTH_KASUMI_F9,
2947 RTE_CRYPTO_CIPHER_KASUMI_F8,
2948 tdata->iv.data, tdata->iv.len,
2949 tdata->validCipherLenInBits.len,
2950 tdata->validCipherOffsetLenInBits.len,
2951 tdata->validAuthLenInBits.len,
2952 tdata->validAuthOffsetLenInBits.len
2957 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2959 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2960 ut_params->obuf = ut_params->op->sym->m_src;
2961 if (ut_params->obuf)
2962 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2963 + tdata->aad.len + tdata->iv.len;
2965 ciphertext = plaintext;
2967 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2968 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2971 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2973 tdata->ciphertext.data,
2974 tdata->validCipherLenInBits.len,
2975 "KASUMI Ciphertext data not as expected");
2978 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2981 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2982 "KASUMI Generated auth tag not as expected");
2987 test_kasumi_encryption_test_case_1(void)
2989 return test_kasumi_encryption(&kasumi_test_case_1);
2993 test_kasumi_encryption_test_case_1_oop(void)
2995 return test_kasumi_encryption_oop(&kasumi_test_case_1);
2999 test_kasumi_encryption_test_case_2(void)
3001 return test_kasumi_encryption(&kasumi_test_case_2);
3005 test_kasumi_encryption_test_case_3(void)
3007 return test_kasumi_encryption(&kasumi_test_case_3);
3011 test_kasumi_encryption_test_case_4(void)
3013 return test_kasumi_encryption(&kasumi_test_case_4);
3017 test_kasumi_encryption_test_case_5(void)
3019 return test_kasumi_encryption(&kasumi_test_case_5);
3023 test_kasumi_decryption_test_case_1(void)
3025 return test_kasumi_decryption(&kasumi_test_case_1);
3029 test_kasumi_decryption_test_case_1_oop(void)
3031 return test_kasumi_decryption_oop(&kasumi_test_case_1);
3035 test_kasumi_decryption_test_case_2(void)
3037 return test_kasumi_decryption(&kasumi_test_case_2);
3041 test_kasumi_decryption_test_case_3(void)
3043 return test_kasumi_decryption(&kasumi_test_case_3);
3047 test_kasumi_decryption_test_case_4(void)
3049 return test_kasumi_decryption(&kasumi_test_case_4);
3053 test_kasumi_decryption_test_case_5(void)
3055 return test_kasumi_decryption(&kasumi_test_case_5);
3058 test_snow3g_encryption_test_case_1(void)
3060 return test_snow3g_encryption(&snow3g_test_case_1);
3064 test_snow3g_encryption_test_case_1_oop(void)
3066 return test_snow3g_encryption_oop(&snow3g_test_case_1);
3070 test_snow3g_encryption_test_case_1_offset_oop(void)
3072 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
3076 test_snow3g_encryption_test_case_2(void)
3078 return test_snow3g_encryption(&snow3g_test_case_2);
3082 test_snow3g_encryption_test_case_3(void)
3084 return test_snow3g_encryption(&snow3g_test_case_3);
3088 test_snow3g_encryption_test_case_4(void)
3090 return test_snow3g_encryption(&snow3g_test_case_4);
3094 test_snow3g_encryption_test_case_5(void)
3096 return test_snow3g_encryption(&snow3g_test_case_5);
3100 test_snow3g_decryption_test_case_1(void)
3102 return test_snow3g_decryption(&snow3g_test_case_1);
3106 test_snow3g_decryption_test_case_1_oop(void)
3108 return test_snow3g_decryption_oop(&snow3g_test_case_1);
3112 test_snow3g_decryption_test_case_2(void)
3114 return test_snow3g_decryption(&snow3g_test_case_2);
3118 test_snow3g_decryption_test_case_3(void)
3120 return test_snow3g_decryption(&snow3g_test_case_3);
3124 test_snow3g_decryption_test_case_4(void)
3126 return test_snow3g_decryption(&snow3g_test_case_4);
3130 test_snow3g_decryption_test_case_5(void)
3132 return test_snow3g_decryption(&snow3g_test_case_5);
3135 test_snow3g_cipher_auth_test_case_1(void)
3137 return test_snow3g_cipher_auth(&snow3g_test_case_3);
3141 test_snow3g_auth_cipher_test_case_1(void)
3143 return test_snow3g_auth_cipher(&snow3g_test_case_6);
3147 test_kasumi_auth_cipher_test_case_1(void)
3149 return test_kasumi_auth_cipher(&kasumi_test_case_3);
3153 test_kasumi_cipher_auth_test_case_1(void)
3155 return test_kasumi_cipher_auth(&kasumi_test_case_6);
3159 /* ***** AES-GCM Tests ***** */
3162 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3163 const uint8_t *key, const uint8_t key_len,
3164 const uint8_t aad_len, const uint8_t auth_len,
3165 enum rte_crypto_auth_operation auth_op)
3167 uint8_t cipher_key[key_len];
3169 struct crypto_unittest_params *ut_params = &unittest_params;
3171 memcpy(cipher_key, key, key_len);
3173 /* Setup Cipher Parameters */
3174 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3175 ut_params->cipher_xform.next = NULL;
3177 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3178 ut_params->auth_xform.auth.op = auth_op;
3179 ut_params->cipher_xform.cipher.op = op;
3180 ut_params->cipher_xform.cipher.key.data = cipher_key;
3181 ut_params->cipher_xform.cipher.key.length = key_len;
3183 TEST_HEXDUMP(stdout, "key:", key, key_len);
3185 /* Setup Authentication Parameters */
3186 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3187 ut_params->auth_xform.next = NULL;
3189 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3191 ut_params->auth_xform.auth.digest_length = auth_len;
3192 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3193 ut_params->auth_xform.auth.key.length = 0;
3194 ut_params->auth_xform.auth.key.data = NULL;
3196 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3197 ut_params->cipher_xform.next = &ut_params->auth_xform;
3199 /* Create Crypto session*/
3200 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3201 &ut_params->cipher_xform);
3202 } else {/* Create Crypto session*/
3203 ut_params->auth_xform.next = &ut_params->cipher_xform;
3204 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3205 &ut_params->auth_xform);
3208 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3214 create_gcm_operation(enum rte_crypto_cipher_operation op,
3215 const uint8_t *auth_tag, const unsigned auth_tag_len,
3216 const uint8_t *iv, const unsigned iv_len,
3217 const uint8_t *aad, const unsigned aad_len,
3218 const unsigned data_len, unsigned data_pad_len)
3220 struct crypto_testsuite_params *ts_params = &testsuite_params;
3221 struct crypto_unittest_params *ut_params = &unittest_params;
3223 unsigned iv_pad_len = 0, aad_buffer_len;
3225 /* Generate Crypto op data structure */
3226 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3227 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3228 TEST_ASSERT_NOT_NULL(ut_params->op,
3229 "Failed to allocate symmetric crypto operation struct");
3231 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3233 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3234 ut_params->ibuf, auth_tag_len);
3235 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3236 "no room to append digest");
3237 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3238 ut_params->ibuf, data_pad_len);
3239 sym_op->auth.digest.length = auth_tag_len;
3241 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3242 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3243 TEST_HEXDUMP(stdout, "digest:",
3244 sym_op->auth.digest.data,
3245 sym_op->auth.digest.length);
3249 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3251 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3252 ut_params->ibuf, iv_pad_len);
3253 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3255 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3256 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3257 sym_op->cipher.iv.length = iv_len;
3259 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3262 * Always allocate the aad up to the block size.
3263 * The cryptodev API calls out -
3264 * - the array must be big enough to hold the AAD, plus any
3265 * space to round this up to the nearest multiple of the
3266 * block size (16 bytes).
3268 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3270 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3271 ut_params->ibuf, aad_buffer_len);
3272 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3273 "no room to prepend aad");
3274 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3276 sym_op->auth.aad.length = aad_len;
3278 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3279 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3281 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3282 TEST_HEXDUMP(stdout, "aad:",
3283 sym_op->auth.aad.data, aad_len);
3285 sym_op->cipher.data.length = data_len;
3286 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3288 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3289 sym_op->auth.data.length = data_len;
3295 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3297 struct crypto_testsuite_params *ts_params = &testsuite_params;
3298 struct crypto_unittest_params *ut_params = &unittest_params;
3302 uint8_t *plaintext, *ciphertext, *auth_tag;
3303 uint16_t plaintext_pad_len;
3305 /* Create GCM session */
3306 retval = create_gcm_session(ts_params->valid_devs[0],
3307 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3308 tdata->key.data, tdata->key.len,
3309 tdata->aad.len, tdata->auth_tag.len,
3310 RTE_CRYPTO_AUTH_OP_GENERATE);
3315 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3317 /* clear mbuf payload */
3318 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3319 rte_pktmbuf_tailroom(ut_params->ibuf));
3322 * Append data which is padded to a multiple
3323 * of the algorithms block size
3325 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3327 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3329 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3331 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3333 /* Create GCM opertaion */
3334 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3335 tdata->auth_tag.data, tdata->auth_tag.len,
3336 tdata->iv.data, tdata->iv.len,
3337 tdata->aad.data, tdata->aad.len,
3338 tdata->plaintext.len, plaintext_pad_len);
3342 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3344 ut_params->op->sym->m_src = ut_params->ibuf;
3346 /* Process crypto operation */
3347 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3348 ut_params->op), "failed to process sym crypto op");
3350 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3351 "crypto op processing failed");
3353 if (ut_params->op->sym->m_dst) {
3354 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3356 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3357 uint8_t *, plaintext_pad_len);
3359 ciphertext = plaintext;
3360 auth_tag = plaintext + plaintext_pad_len;
3363 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3364 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3367 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3369 tdata->ciphertext.data,
3370 tdata->ciphertext.len,
3371 "GCM Ciphertext data not as expected");
3373 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3375 tdata->auth_tag.data,
3376 tdata->auth_tag.len,
3377 "GCM Generated auth tag not as expected");
3384 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3386 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3390 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3392 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3396 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3398 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3402 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3404 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3408 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3410 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3414 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3416 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3420 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3422 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3426 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3428 struct crypto_testsuite_params *ts_params = &testsuite_params;
3429 struct crypto_unittest_params *ut_params = &unittest_params;
3433 uint8_t *plaintext, *ciphertext;
3434 uint16_t ciphertext_pad_len;
3436 /* Create GCM session */
3437 retval = create_gcm_session(ts_params->valid_devs[0],
3438 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3439 tdata->key.data, tdata->key.len,
3440 tdata->aad.len, tdata->auth_tag.len,
3441 RTE_CRYPTO_AUTH_OP_VERIFY);
3446 /* alloc mbuf and set payload */
3447 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3449 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3450 rte_pktmbuf_tailroom(ut_params->ibuf));
3452 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3454 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3455 ciphertext_pad_len);
3456 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3458 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3460 /* Create GCM opertaion */
3461 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3462 tdata->auth_tag.data, tdata->auth_tag.len,
3463 tdata->iv.data, tdata->iv.len,
3464 tdata->aad.data, tdata->aad.len,
3465 tdata->ciphertext.len, ciphertext_pad_len);
3470 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3472 ut_params->op->sym->m_src = ut_params->ibuf;
3474 /* Process crypto operation */
3475 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3476 ut_params->op), "failed to process sym crypto op");
3478 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3479 "crypto op processing failed");
3481 if (ut_params->op->sym->m_dst)
3482 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3485 plaintext = ciphertext;
3487 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3490 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3492 tdata->plaintext.data,
3493 tdata->plaintext.len,
3494 "GCM plaintext data not as expected");
3496 TEST_ASSERT_EQUAL(ut_params->op->status,
3497 RTE_CRYPTO_OP_STATUS_SUCCESS,
3498 "GCM authentication failed");
3503 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3505 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3509 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3511 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3515 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3517 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3521 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3523 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3527 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3529 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3533 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3535 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3539 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3541 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3547 struct crypto_testsuite_params *ts_params = &testsuite_params;
3548 struct rte_cryptodev_stats stats;
3549 struct rte_cryptodev *dev;
3550 cryptodev_stats_get_t temp_pfn;
3552 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3553 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3554 &stats) == -ENODEV),
3555 "rte_cryptodev_stats_get invalid dev failed");
3556 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3557 "rte_cryptodev_stats_get invalid Param failed");
3558 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3559 temp_pfn = dev->dev_ops->stats_get;
3560 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3561 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3563 "rte_cryptodev_stats_get invalid Param failed");
3564 dev->dev_ops->stats_get = temp_pfn;
3566 /* Test expected values */
3568 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3570 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3572 "rte_cryptodev_stats_get failed");
3573 TEST_ASSERT((stats.enqueued_count == 1),
3574 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3575 TEST_ASSERT((stats.dequeued_count == 1),
3576 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3577 TEST_ASSERT((stats.enqueue_err_count == 0),
3578 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3579 TEST_ASSERT((stats.dequeue_err_count == 0),
3580 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3582 /* invalid device but should ignore and not reset device stats*/
3583 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3584 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3586 "rte_cryptodev_stats_get failed");
3587 TEST_ASSERT((stats.enqueued_count == 1),
3588 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3590 /* check that a valid reset clears stats */
3591 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3592 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3594 "rte_cryptodev_stats_get failed");
3595 TEST_ASSERT((stats.enqueued_count == 0),
3596 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3597 TEST_ASSERT((stats.dequeued_count == 0),
3598 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3600 return TEST_SUCCESS;
3603 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
3604 struct crypto_unittest_params *ut_params,
3605 enum rte_crypto_auth_operation op,
3606 const struct HMAC_MD5_vector *test_case)
3610 memcpy(key, test_case->key.data, test_case->key.len);
3612 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3613 ut_params->auth_xform.next = NULL;
3614 ut_params->auth_xform.auth.op = op;
3616 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
3618 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
3619 ut_params->auth_xform.auth.add_auth_data_length = 0;
3620 ut_params->auth_xform.auth.key.length = test_case->key.len;
3621 ut_params->auth_xform.auth.key.data = key;
3623 ut_params->sess = rte_cryptodev_sym_session_create(
3624 ts_params->valid_devs[0], &ut_params->auth_xform);
3626 if (ut_params->sess == NULL)
3629 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3631 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3632 rte_pktmbuf_tailroom(ut_params->ibuf));
3637 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
3638 const struct HMAC_MD5_vector *test_case,
3639 uint8_t **plaintext)
3641 uint16_t plaintext_pad_len;
3643 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3645 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3648 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3650 memcpy(*plaintext, test_case->plaintext.data,
3651 test_case->plaintext.len);
3653 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3654 ut_params->ibuf, MD5_DIGEST_LEN);
3655 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3656 "no room to append digest");
3657 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3658 ut_params->ibuf, plaintext_pad_len);
3659 sym_op->auth.digest.length = MD5_DIGEST_LEN;
3661 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
3662 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
3663 test_case->auth_tag.len);
3666 sym_op->auth.data.offset = 0;
3667 sym_op->auth.data.length = test_case->plaintext.len;
3669 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3670 ut_params->op->sym->m_src = ut_params->ibuf;
3676 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
3678 uint16_t plaintext_pad_len;
3679 uint8_t *plaintext, *auth_tag;
3681 struct crypto_testsuite_params *ts_params = &testsuite_params;
3682 struct crypto_unittest_params *ut_params = &unittest_params;
3684 if (MD5_HMAC_create_session(ts_params, ut_params,
3685 RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
3688 /* Generate Crypto op data structure */
3689 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3690 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3691 TEST_ASSERT_NOT_NULL(ut_params->op,
3692 "Failed to allocate symmetric crypto operation struct");
3694 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3697 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3700 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3701 ut_params->op), "failed to process sym crypto op");
3703 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3704 "crypto op processing failed");
3706 if (ut_params->op->sym->m_dst) {
3707 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3708 uint8_t *, plaintext_pad_len);
3710 auth_tag = plaintext + plaintext_pad_len;
3713 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3715 test_case->auth_tag.data,
3716 test_case->auth_tag.len,
3717 "HMAC_MD5 generated tag not as expected");
3719 return TEST_SUCCESS;
3723 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
3727 struct crypto_testsuite_params *ts_params = &testsuite_params;
3728 struct crypto_unittest_params *ut_params = &unittest_params;
3730 if (MD5_HMAC_create_session(ts_params, ut_params,
3731 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
3735 /* Generate Crypto op data structure */
3736 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3737 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3738 TEST_ASSERT_NOT_NULL(ut_params->op,
3739 "Failed to allocate symmetric crypto operation struct");
3741 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3744 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3745 ut_params->op), "failed to process sym crypto op");
3747 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3748 "HMAC_MD5 crypto op processing failed");
3750 return TEST_SUCCESS;
3754 test_MD5_HMAC_generate_case_1(void)
3756 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
3760 test_MD5_HMAC_verify_case_1(void)
3762 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
3766 test_MD5_HMAC_generate_case_2(void)
3768 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
3772 test_MD5_HMAC_verify_case_2(void)
3774 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
3778 test_multi_session(void)
3780 struct crypto_testsuite_params *ts_params = &testsuite_params;
3781 struct crypto_unittest_params *ut_params = &unittest_params;
3783 struct rte_cryptodev_info dev_info;
3784 struct rte_cryptodev_sym_session **sessions;
3788 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3791 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3793 sessions = rte_malloc(NULL,
3794 (sizeof(struct rte_cryptodev_sym_session *) *
3795 dev_info.sym.max_nb_sessions) + 1, 0);
3797 /* Create multiple crypto sessions*/
3798 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3799 sessions[i] = rte_cryptodev_sym_session_create(
3800 ts_params->valid_devs[0],
3801 &ut_params->auth_xform);
3802 TEST_ASSERT_NOT_NULL(sessions[i],
3803 "Session creation failed at session number %u",
3806 /* Attempt to send a request on each session */
3807 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3808 sessions[i], ut_params, ts_params),
3809 "Failed to perform decrypt on request "
3811 /* free crypto operation structure */
3813 rte_crypto_op_free(ut_params->op);
3816 * free mbuf - both obuf and ibuf are usually the same,
3817 * so check if they point at the same address is necessary,
3818 * to avoid freeing the mbuf twice.
3820 if (ut_params->obuf) {
3821 rte_pktmbuf_free(ut_params->obuf);
3822 if (ut_params->ibuf == ut_params->obuf)
3823 ut_params->ibuf = 0;
3824 ut_params->obuf = 0;
3826 if (ut_params->ibuf) {
3827 rte_pktmbuf_free(ut_params->ibuf);
3828 ut_params->ibuf = 0;
3832 /* Next session create should fail */
3833 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3834 &ut_params->auth_xform);
3835 TEST_ASSERT_NULL(sessions[i],
3836 "Session creation succeeded unexpectedly!");
3838 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3839 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3844 return TEST_SUCCESS;
3848 test_null_cipher_only_operation(void)
3850 struct crypto_testsuite_params *ts_params = &testsuite_params;
3851 struct crypto_unittest_params *ut_params = &unittest_params;
3853 /* Generate test mbuf data and space for digest */
3854 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3855 catch_22_quote, QUOTE_512_BYTES, 0);
3857 /* Setup Cipher Parameters */
3858 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3859 ut_params->cipher_xform.next = NULL;
3861 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3862 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3864 /* Create Crypto session*/
3865 ut_params->sess = rte_cryptodev_sym_session_create(
3866 ts_params->valid_devs[0], &ut_params->cipher_xform);
3867 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3869 /* Generate Crypto op data structure */
3870 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3871 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3872 TEST_ASSERT_NOT_NULL(ut_params->op,
3873 "Failed to allocate symmetric crypto operation struct");
3875 /* Set crypto operation data parameters */
3876 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3878 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3880 /* set crypto operation source mbuf */
3881 sym_op->m_src = ut_params->ibuf;
3883 sym_op->cipher.data.offset = 0;
3884 sym_op->cipher.data.length = QUOTE_512_BYTES;
3886 /* Process crypto operation */
3887 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3889 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3891 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3892 "crypto operation processing failed");
3895 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3896 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3899 "Ciphertext data not as expected");
3901 return TEST_SUCCESS;
3905 test_null_auth_only_operation(void)
3907 struct crypto_testsuite_params *ts_params = &testsuite_params;
3908 struct crypto_unittest_params *ut_params = &unittest_params;
3910 /* Generate test mbuf data and space for digest */
3911 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3912 catch_22_quote, QUOTE_512_BYTES, 0);
3914 /* Setup HMAC Parameters */
3915 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3916 ut_params->auth_xform.next = NULL;
3918 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3919 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3921 /* Create Crypto session*/
3922 ut_params->sess = rte_cryptodev_sym_session_create(
3923 ts_params->valid_devs[0], &ut_params->auth_xform);
3924 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3926 /* Generate Crypto op data structure */
3927 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3928 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3929 TEST_ASSERT_NOT_NULL(ut_params->op,
3930 "Failed to allocate symmetric crypto operation struct");
3932 /* Set crypto operation data parameters */
3933 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3935 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3937 sym_op->m_src = ut_params->ibuf;
3939 sym_op->auth.data.offset = 0;
3940 sym_op->auth.data.length = QUOTE_512_BYTES;
3942 /* Process crypto operation */
3943 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3945 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3947 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3948 "crypto operation processing failed");
3950 return TEST_SUCCESS;
3954 test_null_cipher_auth_operation(void)
3956 struct crypto_testsuite_params *ts_params = &testsuite_params;
3957 struct crypto_unittest_params *ut_params = &unittest_params;
3959 /* Generate test mbuf data and space for digest */
3960 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3961 catch_22_quote, QUOTE_512_BYTES, 0);
3963 /* Setup Cipher Parameters */
3964 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3965 ut_params->cipher_xform.next = &ut_params->auth_xform;
3967 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3968 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3970 /* Setup HMAC Parameters */
3971 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3972 ut_params->auth_xform.next = NULL;
3974 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3975 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3977 /* Create Crypto session*/
3978 ut_params->sess = rte_cryptodev_sym_session_create(
3979 ts_params->valid_devs[0], &ut_params->cipher_xform);
3980 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3982 /* Generate Crypto op data structure */
3983 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3984 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3985 TEST_ASSERT_NOT_NULL(ut_params->op,
3986 "Failed to allocate symmetric crypto operation struct");
3988 /* Set crypto operation data parameters */
3989 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3991 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3993 sym_op->m_src = ut_params->ibuf;
3995 sym_op->cipher.data.offset = 0;
3996 sym_op->cipher.data.length = QUOTE_512_BYTES;
3998 sym_op->auth.data.offset = 0;
3999 sym_op->auth.data.length = QUOTE_512_BYTES;
4001 /* Process crypto operation */
4002 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4004 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4006 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4007 "crypto operation processing failed");
4010 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4011 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4014 "Ciphertext data not as expected");
4016 return TEST_SUCCESS;
4020 test_null_auth_cipher_operation(void)
4022 struct crypto_testsuite_params *ts_params = &testsuite_params;
4023 struct crypto_unittest_params *ut_params = &unittest_params;
4025 /* Generate test mbuf data and space for digest */
4026 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4027 catch_22_quote, QUOTE_512_BYTES, 0);
4029 /* Setup Cipher Parameters */
4030 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4031 ut_params->cipher_xform.next = NULL;
4033 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4034 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4036 /* Setup HMAC Parameters */
4037 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4038 ut_params->auth_xform.next = &ut_params->cipher_xform;
4040 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4041 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4043 /* Create Crypto session*/
4044 ut_params->sess = rte_cryptodev_sym_session_create(
4045 ts_params->valid_devs[0], &ut_params->cipher_xform);
4046 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4048 /* Generate Crypto op data structure */
4049 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4050 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4051 TEST_ASSERT_NOT_NULL(ut_params->op,
4052 "Failed to allocate symmetric crypto operation struct");
4054 /* Set crypto operation data parameters */
4055 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4057 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4059 sym_op->m_src = ut_params->ibuf;
4061 sym_op->cipher.data.offset = 0;
4062 sym_op->cipher.data.length = QUOTE_512_BYTES;
4064 sym_op->auth.data.offset = 0;
4065 sym_op->auth.data.length = QUOTE_512_BYTES;
4067 /* Process crypto operation */
4068 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4070 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4072 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4073 "crypto operation processing failed");
4076 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4077 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4080 "Ciphertext data not as expected");
4082 return TEST_SUCCESS;
4087 test_null_invalid_operation(void)
4089 struct crypto_testsuite_params *ts_params = &testsuite_params;
4090 struct crypto_unittest_params *ut_params = &unittest_params;
4092 /* Setup Cipher Parameters */
4093 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4094 ut_params->cipher_xform.next = NULL;
4096 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4097 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4099 /* Create Crypto session*/
4100 ut_params->sess = rte_cryptodev_sym_session_create(
4101 ts_params->valid_devs[0], &ut_params->cipher_xform);
4102 TEST_ASSERT_NULL(ut_params->sess,
4103 "Session creation succeeded unexpectedly");
4106 /* Setup HMAC Parameters */
4107 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4108 ut_params->auth_xform.next = NULL;
4110 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4111 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4113 /* Create Crypto session*/
4114 ut_params->sess = rte_cryptodev_sym_session_create(
4115 ts_params->valid_devs[0], &ut_params->auth_xform);
4116 TEST_ASSERT_NULL(ut_params->sess,
4117 "Session creation succeeded unexpectedly");
4119 return TEST_SUCCESS;
4123 #define NULL_BURST_LENGTH (32)
4126 test_null_burst_operation(void)
4128 struct crypto_testsuite_params *ts_params = &testsuite_params;
4129 struct crypto_unittest_params *ut_params = &unittest_params;
4131 unsigned i, burst_len = NULL_BURST_LENGTH;
4133 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4134 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4136 /* Setup Cipher Parameters */
4137 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4138 ut_params->cipher_xform.next = &ut_params->auth_xform;
4140 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4141 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4143 /* Setup HMAC Parameters */
4144 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4145 ut_params->auth_xform.next = NULL;
4147 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4148 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4150 /* Create Crypto session*/
4151 ut_params->sess = rte_cryptodev_sym_session_create(
4152 ts_params->valid_devs[0], &ut_params->cipher_xform);
4153 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4155 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4156 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4157 burst_len, "failed to generate burst of crypto ops");
4159 /* Generate an operation for each mbuf in burst */
4160 for (i = 0; i < burst_len; i++) {
4161 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4163 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
4165 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
4169 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
4171 burst[i]->sym->m_src = m;
4174 /* Process crypto operation */
4175 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
4176 0, burst, burst_len),
4178 "Error enqueuing burst");
4180 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4181 0, burst_dequeued, burst_len),
4183 "Error dequeuing burst");
4186 for (i = 0; i < burst_len; i++) {
4188 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4189 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4191 "data not as expected");
4193 rte_pktmbuf_free(burst[i]->sym->m_src);
4194 rte_crypto_op_free(burst[i]);
4197 return TEST_SUCCESS;
4201 create_gmac_operation(enum rte_crypto_auth_operation op,
4202 const struct gmac_test_data *tdata)
4204 struct crypto_testsuite_params *ts_params = &testsuite_params;
4205 struct crypto_unittest_params *ut_params = &unittest_params;
4206 struct rte_crypto_sym_op *sym_op;
4208 unsigned iv_pad_len;
4209 unsigned aad_pad_len;
4211 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
4212 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4214 /* Generate Crypto op data structure */
4215 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4216 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4217 TEST_ASSERT_NOT_NULL(ut_params->op,
4218 "Failed to allocate symmetric crypto operation struct");
4220 sym_op = ut_params->op->sym;
4221 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4223 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4224 "no room to append aad");
4226 sym_op->auth.aad.length = tdata->aad.len;
4227 sym_op->auth.aad.phys_addr =
4228 rte_pktmbuf_mtophys(ut_params->ibuf);
4229 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
4231 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4232 ut_params->ibuf, tdata->gmac_tag.len);
4233 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4234 "no room to append digest");
4236 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4237 ut_params->ibuf, aad_pad_len);
4238 sym_op->auth.digest.length = tdata->gmac_tag.len;
4240 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
4241 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
4242 tdata->gmac_tag.len);
4243 TEST_HEXDUMP(stdout, "digest:",
4244 sym_op->auth.digest.data,
4245 sym_op->auth.digest.length);
4248 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4249 ut_params->ibuf, iv_pad_len);
4250 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4252 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4253 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4254 sym_op->cipher.iv.length = tdata->iv.len;
4256 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
4258 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
4260 sym_op->cipher.data.length = 0;
4261 sym_op->cipher.data.offset = 0;
4263 sym_op->auth.data.offset = 0;
4264 sym_op->auth.data.length = 0;
4269 static int create_gmac_session(uint8_t dev_id,
4270 enum rte_crypto_cipher_operation op,
4271 const struct gmac_test_data *tdata,
4272 enum rte_crypto_auth_operation auth_op)
4274 uint8_t cipher_key[tdata->key.len];
4276 struct crypto_unittest_params *ut_params = &unittest_params;
4278 memcpy(cipher_key, tdata->key.data, tdata->key.len);
4280 /* For GMAC we setup cipher parameters */
4281 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4282 ut_params->cipher_xform.next = NULL;
4283 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4284 ut_params->cipher_xform.cipher.op = op;
4285 ut_params->cipher_xform.cipher.key.data = cipher_key;
4286 ut_params->cipher_xform.cipher.key.length = tdata->key.len;
4288 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4289 ut_params->auth_xform.next = NULL;
4291 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
4292 ut_params->auth_xform.auth.op = auth_op;
4293 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
4294 ut_params->auth_xform.auth.add_auth_data_length = 0;
4295 ut_params->auth_xform.auth.key.length = 0;
4296 ut_params->auth_xform.auth.key.data = NULL;
4298 ut_params->cipher_xform.next = &ut_params->auth_xform;
4300 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4301 &ut_params->cipher_xform);
4303 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4309 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
4311 struct crypto_testsuite_params *ts_params = &testsuite_params;
4312 struct crypto_unittest_params *ut_params = &unittest_params;
4316 uint8_t *auth_tag, *p;
4317 uint16_t aad_pad_len;
4319 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
4320 "No GMAC length in the source data");
4322 retval = create_gmac_session(ts_params->valid_devs[0],
4323 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4324 tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
4329 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4331 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4332 rte_pktmbuf_tailroom(ut_params->ibuf));
4334 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4336 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
4338 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
4344 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4346 ut_params->op->sym->m_src = ut_params->ibuf;
4348 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4349 ut_params->op), "failed to process sym crypto op");
4351 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4352 "crypto op processing failed");
4354 if (ut_params->op->sym->m_dst) {
4355 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4356 uint8_t *, aad_pad_len);
4358 auth_tag = p + aad_pad_len;
4361 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
4363 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4365 tdata->gmac_tag.data,
4366 tdata->gmac_tag.len,
4367 "GMAC Generated auth tag not as expected");
4373 test_AES_GMAC_authentication_test_case_1(void)
4375 return test_AES_GMAC_authentication(&gmac_test_case_1);
4379 test_AES_GMAC_authentication_test_case_2(void)
4381 return test_AES_GMAC_authentication(&gmac_test_case_2);
4385 test_AES_GMAC_authentication_test_case_3(void)
4387 return test_AES_GMAC_authentication(&gmac_test_case_3);
4391 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
4393 struct crypto_testsuite_params *ts_params = &testsuite_params;
4394 struct crypto_unittest_params *ut_params = &unittest_params;
4397 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
4398 "No GMAC length in the source data");
4400 retval = create_gmac_session(ts_params->valid_devs[0],
4401 RTE_CRYPTO_CIPHER_OP_DECRYPT,
4402 tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
4407 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4409 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4410 rte_pktmbuf_tailroom(ut_params->ibuf));
4412 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
4418 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4420 ut_params->op->sym->m_src = ut_params->ibuf;
4422 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4423 ut_params->op), "failed to process sym crypto op");
4425 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4426 "crypto op processing failed");
4433 test_AES_GMAC_authentication_verify_test_case_1(void)
4435 return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
4439 test_AES_GMAC_authentication_verify_test_case_2(void)
4441 return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
4445 test_AES_GMAC_authentication_verify_test_case_3(void)
4447 return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
4450 static struct unit_test_suite cryptodev_qat_testsuite = {
4451 .suite_name = "Crypto QAT Unit Test Suite",
4452 .setup = testsuite_setup,
4453 .teardown = testsuite_teardown,
4454 .unit_test_cases = {
4455 TEST_CASE_ST(ut_setup, ut_teardown,
4456 test_device_configure_invalid_dev_id),
4457 TEST_CASE_ST(ut_setup, ut_teardown,
4458 test_device_configure_invalid_queue_pair_ids),
4459 TEST_CASE_ST(ut_setup, ut_teardown,
4460 test_queue_pair_descriptor_setup),
4461 TEST_CASE_ST(ut_setup, ut_teardown,
4462 test_multi_session),
4464 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
4465 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4467 /** AES GCM Authenticated Encryption */
4468 TEST_CASE_ST(ut_setup, ut_teardown,
4469 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4470 TEST_CASE_ST(ut_setup, ut_teardown,
4471 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4472 TEST_CASE_ST(ut_setup, ut_teardown,
4473 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4474 TEST_CASE_ST(ut_setup, ut_teardown,
4475 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4476 TEST_CASE_ST(ut_setup, ut_teardown,
4477 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4478 TEST_CASE_ST(ut_setup, ut_teardown,
4479 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4480 TEST_CASE_ST(ut_setup, ut_teardown,
4481 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4483 /** AES GCM Authenticated Decryption */
4484 TEST_CASE_ST(ut_setup, ut_teardown,
4485 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4486 TEST_CASE_ST(ut_setup, ut_teardown,
4487 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4488 TEST_CASE_ST(ut_setup, ut_teardown,
4489 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4490 TEST_CASE_ST(ut_setup, ut_teardown,
4491 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4492 TEST_CASE_ST(ut_setup, ut_teardown,
4493 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4494 TEST_CASE_ST(ut_setup, ut_teardown,
4495 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4496 TEST_CASE_ST(ut_setup, ut_teardown,
4497 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4499 /** AES GMAC Authentication */
4500 TEST_CASE_ST(ut_setup, ut_teardown,
4501 test_AES_GMAC_authentication_test_case_1),
4502 TEST_CASE_ST(ut_setup, ut_teardown,
4503 test_AES_GMAC_authentication_verify_test_case_1),
4504 TEST_CASE_ST(ut_setup, ut_teardown,
4505 test_AES_GMAC_authentication_test_case_2),
4506 TEST_CASE_ST(ut_setup, ut_teardown,
4507 test_AES_GMAC_authentication_verify_test_case_2),
4508 TEST_CASE_ST(ut_setup, ut_teardown,
4509 test_AES_GMAC_authentication_test_case_3),
4510 TEST_CASE_ST(ut_setup, ut_teardown,
4511 test_AES_GMAC_authentication_verify_test_case_3),
4513 /** SNOW 3G encrypt only (UEA2) */
4514 TEST_CASE_ST(ut_setup, ut_teardown,
4515 test_snow3g_encryption_test_case_1),
4516 TEST_CASE_ST(ut_setup, ut_teardown,
4517 test_snow3g_encryption_test_case_2),
4518 TEST_CASE_ST(ut_setup, ut_teardown,
4519 test_snow3g_encryption_test_case_3),
4520 TEST_CASE_ST(ut_setup, ut_teardown,
4521 test_snow3g_encryption_test_case_4),
4522 TEST_CASE_ST(ut_setup, ut_teardown,
4523 test_snow3g_encryption_test_case_5),
4525 TEST_CASE_ST(ut_setup, ut_teardown,
4526 test_snow3g_encryption_test_case_1_oop),
4527 TEST_CASE_ST(ut_setup, ut_teardown,
4528 test_snow3g_decryption_test_case_1_oop),
4530 /** SNOW 3G decrypt only (UEA2) */
4531 TEST_CASE_ST(ut_setup, ut_teardown,
4532 test_snow3g_decryption_test_case_1),
4533 TEST_CASE_ST(ut_setup, ut_teardown,
4534 test_snow3g_decryption_test_case_2),
4535 TEST_CASE_ST(ut_setup, ut_teardown,
4536 test_snow3g_decryption_test_case_3),
4537 TEST_CASE_ST(ut_setup, ut_teardown,
4538 test_snow3g_decryption_test_case_4),
4539 TEST_CASE_ST(ut_setup, ut_teardown,
4540 test_snow3g_decryption_test_case_5),
4541 TEST_CASE_ST(ut_setup, ut_teardown,
4542 test_snow3g_hash_generate_test_case_1),
4543 TEST_CASE_ST(ut_setup, ut_teardown,
4544 test_snow3g_hash_generate_test_case_2),
4545 TEST_CASE_ST(ut_setup, ut_teardown,
4546 test_snow3g_hash_generate_test_case_3),
4547 TEST_CASE_ST(ut_setup, ut_teardown,
4548 test_snow3g_hash_verify_test_case_1),
4549 TEST_CASE_ST(ut_setup, ut_teardown,
4550 test_snow3g_hash_verify_test_case_2),
4551 TEST_CASE_ST(ut_setup, ut_teardown,
4552 test_snow3g_hash_verify_test_case_3),
4553 TEST_CASE_ST(ut_setup, ut_teardown,
4554 test_snow3g_cipher_auth_test_case_1),
4555 TEST_CASE_ST(ut_setup, ut_teardown,
4556 test_snow3g_auth_cipher_test_case_1),
4558 /** HMAC_MD5 Authentication */
4559 TEST_CASE_ST(ut_setup, ut_teardown,
4560 test_MD5_HMAC_generate_case_1),
4561 TEST_CASE_ST(ut_setup, ut_teardown,
4562 test_MD5_HMAC_verify_case_1),
4563 TEST_CASE_ST(ut_setup, ut_teardown,
4564 test_MD5_HMAC_generate_case_2),
4565 TEST_CASE_ST(ut_setup, ut_teardown,
4566 test_MD5_HMAC_verify_case_2),
4569 TEST_CASE_ST(ut_setup, ut_teardown,
4570 test_null_auth_only_operation),
4571 TEST_CASE_ST(ut_setup, ut_teardown,
4572 test_null_cipher_only_operation),
4573 TEST_CASE_ST(ut_setup, ut_teardown,
4574 test_null_cipher_auth_operation),
4575 TEST_CASE_ST(ut_setup, ut_teardown,
4576 test_null_auth_cipher_operation),
4578 TEST_CASE_ST(ut_setup, ut_teardown,
4579 test_kasumi_hash_generate_test_case_6),
4582 TEST_CASE_ST(ut_setup, ut_teardown,
4583 test_kasumi_encryption_test_case_1),
4584 TEST_CASE_ST(ut_setup, ut_teardown,
4585 test_kasumi_encryption_test_case_3),
4586 TEST_CASE_ST(ut_setup, ut_teardown,
4587 test_kasumi_auth_cipher_test_case_1),
4588 TEST_CASE_ST(ut_setup, ut_teardown,
4589 test_kasumi_cipher_auth_test_case_1),
4591 TEST_CASES_END() /**< NULL terminate unit test array */
4595 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
4596 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4597 .setup = testsuite_setup,
4598 .teardown = testsuite_teardown,
4599 .unit_test_cases = {
4600 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
4602 TEST_CASES_END() /**< NULL terminate unit test array */
4606 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
4607 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4608 .setup = testsuite_setup,
4609 .teardown = testsuite_teardown,
4610 .unit_test_cases = {
4611 /** AES GCM Authenticated Encryption */
4612 TEST_CASE_ST(ut_setup, ut_teardown,
4613 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4614 TEST_CASE_ST(ut_setup, ut_teardown,
4615 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4616 TEST_CASE_ST(ut_setup, ut_teardown,
4617 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4618 TEST_CASE_ST(ut_setup, ut_teardown,
4619 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4620 TEST_CASE_ST(ut_setup, ut_teardown,
4621 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4622 TEST_CASE_ST(ut_setup, ut_teardown,
4623 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4624 TEST_CASE_ST(ut_setup, ut_teardown,
4625 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4627 /** AES GCM Authenticated Decryption */
4628 TEST_CASE_ST(ut_setup, ut_teardown,
4629 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4630 TEST_CASE_ST(ut_setup, ut_teardown,
4631 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4632 TEST_CASE_ST(ut_setup, ut_teardown,
4633 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4634 TEST_CASE_ST(ut_setup, ut_teardown,
4635 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4636 TEST_CASE_ST(ut_setup, ut_teardown,
4637 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4638 TEST_CASE_ST(ut_setup, ut_teardown,
4639 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4640 TEST_CASE_ST(ut_setup, ut_teardown,
4641 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4643 TEST_CASES_END() /**< NULL terminate unit test array */
4647 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
4648 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4649 .setup = testsuite_setup,
4650 .teardown = testsuite_teardown,
4651 .unit_test_cases = {
4652 /** KASUMI encrypt only (UEA1) */
4653 TEST_CASE_ST(ut_setup, ut_teardown,
4654 test_kasumi_encryption_test_case_1),
4655 TEST_CASE_ST(ut_setup, ut_teardown,
4656 test_kasumi_encryption_test_case_2),
4657 TEST_CASE_ST(ut_setup, ut_teardown,
4658 test_kasumi_encryption_test_case_3),
4659 TEST_CASE_ST(ut_setup, ut_teardown,
4660 test_kasumi_encryption_test_case_4),
4661 TEST_CASE_ST(ut_setup, ut_teardown,
4662 test_kasumi_encryption_test_case_5),
4663 /** KASUMI decrypt only (UEA1) */
4664 TEST_CASE_ST(ut_setup, ut_teardown,
4665 test_kasumi_decryption_test_case_1),
4666 TEST_CASE_ST(ut_setup, ut_teardown,
4667 test_kasumi_decryption_test_case_2),
4668 TEST_CASE_ST(ut_setup, ut_teardown,
4669 test_kasumi_decryption_test_case_3),
4670 TEST_CASE_ST(ut_setup, ut_teardown,
4671 test_kasumi_decryption_test_case_4),
4672 TEST_CASE_ST(ut_setup, ut_teardown,
4673 test_kasumi_decryption_test_case_5),
4675 TEST_CASE_ST(ut_setup, ut_teardown,
4676 test_kasumi_encryption_test_case_1_oop),
4677 TEST_CASE_ST(ut_setup, ut_teardown,
4678 test_kasumi_decryption_test_case_1_oop),
4680 /** KASUMI hash only (UIA1) */
4681 TEST_CASE_ST(ut_setup, ut_teardown,
4682 test_kasumi_hash_generate_test_case_1),
4683 TEST_CASE_ST(ut_setup, ut_teardown,
4684 test_kasumi_hash_generate_test_case_2),
4685 TEST_CASE_ST(ut_setup, ut_teardown,
4686 test_kasumi_hash_generate_test_case_3),
4687 TEST_CASE_ST(ut_setup, ut_teardown,
4688 test_kasumi_hash_generate_test_case_4),
4689 TEST_CASE_ST(ut_setup, ut_teardown,
4690 test_kasumi_hash_generate_test_case_5),
4691 TEST_CASE_ST(ut_setup, ut_teardown,
4692 test_kasumi_hash_generate_test_case_6),
4693 TEST_CASE_ST(ut_setup, ut_teardown,
4694 test_kasumi_hash_verify_test_case_1),
4695 TEST_CASE_ST(ut_setup, ut_teardown,
4696 test_kasumi_hash_verify_test_case_2),
4697 TEST_CASE_ST(ut_setup, ut_teardown,
4698 test_kasumi_hash_verify_test_case_3),
4699 TEST_CASE_ST(ut_setup, ut_teardown,
4700 test_kasumi_hash_verify_test_case_4),
4701 TEST_CASE_ST(ut_setup, ut_teardown,
4702 test_kasumi_hash_verify_test_case_5),
4703 TEST_CASE_ST(ut_setup, ut_teardown,
4704 test_kasumi_auth_cipher_test_case_1),
4705 TEST_CASE_ST(ut_setup, ut_teardown,
4706 test_kasumi_cipher_auth_test_case_1),
4707 TEST_CASES_END() /**< NULL terminate unit test array */
4710 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4711 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
4712 .setup = testsuite_setup,
4713 .teardown = testsuite_teardown,
4714 .unit_test_cases = {
4715 /** SNOW 3G encrypt only (UEA2) */
4716 TEST_CASE_ST(ut_setup, ut_teardown,
4717 test_snow3g_encryption_test_case_1),
4718 TEST_CASE_ST(ut_setup, ut_teardown,
4719 test_snow3g_encryption_test_case_2),
4720 TEST_CASE_ST(ut_setup, ut_teardown,
4721 test_snow3g_encryption_test_case_3),
4722 TEST_CASE_ST(ut_setup, ut_teardown,
4723 test_snow3g_encryption_test_case_4),
4724 TEST_CASE_ST(ut_setup, ut_teardown,
4725 test_snow3g_encryption_test_case_5),
4727 TEST_CASE_ST(ut_setup, ut_teardown,
4728 test_snow3g_encryption_test_case_1_oop),
4729 TEST_CASE_ST(ut_setup, ut_teardown,
4730 test_snow3g_decryption_test_case_1_oop),
4732 TEST_CASE_ST(ut_setup, ut_teardown,
4733 test_snow3g_encryption_test_case_1_offset_oop),
4735 /** SNOW 3G decrypt only (UEA2) */
4736 TEST_CASE_ST(ut_setup, ut_teardown,
4737 test_snow3g_decryption_test_case_1),
4738 TEST_CASE_ST(ut_setup, ut_teardown,
4739 test_snow3g_decryption_test_case_2),
4740 TEST_CASE_ST(ut_setup, ut_teardown,
4741 test_snow3g_decryption_test_case_3),
4742 TEST_CASE_ST(ut_setup, ut_teardown,
4743 test_snow3g_decryption_test_case_4),
4744 TEST_CASE_ST(ut_setup, ut_teardown,
4745 test_snow3g_decryption_test_case_5),
4746 TEST_CASE_ST(ut_setup, ut_teardown,
4747 test_snow3g_hash_generate_test_case_1),
4748 TEST_CASE_ST(ut_setup, ut_teardown,
4749 test_snow3g_hash_generate_test_case_2),
4750 TEST_CASE_ST(ut_setup, ut_teardown,
4751 test_snow3g_hash_generate_test_case_3),
4752 /* Tests with buffers which length is not byte-aligned */
4753 TEST_CASE_ST(ut_setup, ut_teardown,
4754 test_snow3g_hash_generate_test_case_4),
4755 TEST_CASE_ST(ut_setup, ut_teardown,
4756 test_snow3g_hash_generate_test_case_5),
4757 TEST_CASE_ST(ut_setup, ut_teardown,
4758 test_snow3g_hash_generate_test_case_6),
4759 TEST_CASE_ST(ut_setup, ut_teardown,
4760 test_snow3g_hash_verify_test_case_1),
4761 TEST_CASE_ST(ut_setup, ut_teardown,
4762 test_snow3g_hash_verify_test_case_2),
4763 TEST_CASE_ST(ut_setup, ut_teardown,
4764 test_snow3g_hash_verify_test_case_3),
4765 /* Tests with buffers which length is not byte-aligned */
4766 TEST_CASE_ST(ut_setup, ut_teardown,
4767 test_snow3g_hash_verify_test_case_4),
4768 TEST_CASE_ST(ut_setup, ut_teardown,
4769 test_snow3g_hash_verify_test_case_5),
4770 TEST_CASE_ST(ut_setup, ut_teardown,
4771 test_snow3g_hash_verify_test_case_6),
4772 TEST_CASE_ST(ut_setup, ut_teardown,
4773 test_snow3g_cipher_auth_test_case_1),
4774 TEST_CASE_ST(ut_setup, ut_teardown,
4775 test_snow3g_auth_cipher_test_case_1),
4777 TEST_CASES_END() /**< NULL terminate unit test array */
4781 static struct unit_test_suite cryptodev_null_testsuite = {
4782 .suite_name = "Crypto Device NULL Unit Test Suite",
4783 .setup = testsuite_setup,
4784 .teardown = testsuite_teardown,
4785 .unit_test_cases = {
4786 TEST_CASE_ST(ut_setup, ut_teardown,
4787 test_null_auth_only_operation),
4788 TEST_CASE_ST(ut_setup, ut_teardown,
4789 test_null_cipher_only_operation),
4790 TEST_CASE_ST(ut_setup, ut_teardown,
4791 test_null_cipher_auth_operation),
4792 TEST_CASE_ST(ut_setup, ut_teardown,
4793 test_null_auth_cipher_operation),
4794 TEST_CASE_ST(ut_setup, ut_teardown,
4795 test_null_invalid_operation),
4796 TEST_CASE_ST(ut_setup, ut_teardown,
4797 test_null_burst_operation),
4799 TEST_CASES_END() /**< NULL terminate unit test array */
4804 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4806 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4807 return unit_test_suite_runner(&cryptodev_qat_testsuite);
4811 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4813 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4815 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4819 test_cryptodev_aesni_gcm(void)
4821 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4823 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4827 test_cryptodev_null(void)
4829 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4831 return unit_test_suite_runner(&cryptodev_null_testsuite);
4835 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4837 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4839 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4843 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
4845 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
4847 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
4850 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
4851 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
4852 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
4853 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
4854 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
4855 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);