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"
53 static enum rte_cryptodev_type gbl_cryptodev_type;
55 struct crypto_testsuite_params {
56 struct rte_mempool *mbuf_pool;
57 struct rte_mempool *op_mpool;
58 struct rte_cryptodev_config conf;
59 struct rte_cryptodev_qp_conf qp_conf;
61 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
62 uint8_t valid_dev_count;
65 struct crypto_unittest_params {
66 struct rte_crypto_sym_xform cipher_xform;
67 struct rte_crypto_sym_xform auth_xform;
69 struct rte_cryptodev_sym_session *sess;
71 struct rte_crypto_op *op;
73 struct rte_mbuf *obuf, *ibuf;
78 #define ALIGN_POW2_ROUNDUP(num, align) \
79 (((num) + (align) - 1) & ~((align) - 1))
82 * Forward declarations.
85 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
86 struct crypto_unittest_params *ut_params);
89 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
90 struct crypto_unittest_params *ut_params,
91 struct crypto_testsuite_params *ts_param);
93 static struct rte_mbuf *
94 setup_test_string(struct rte_mempool *mpool,
95 const char *string, size_t len, uint8_t blocksize)
97 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
98 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
100 memset(m->buf_addr, 0, m->buf_len);
102 char *dst = rte_pktmbuf_append(m, t_len);
109 rte_memcpy(dst, string, t_len);
111 memset(dst, 0, t_len);
117 /* Get number of bytes in X bits (rounding up) */
119 ceil_byte_length(uint32_t num_bits)
122 return ((num_bits >> 3) + 1);
124 return (num_bits >> 3);
127 static struct rte_crypto_op *
128 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
130 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
131 printf("Error sending packet for encryption");
137 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
143 static struct crypto_testsuite_params testsuite_params = { NULL };
144 static struct crypto_unittest_params unittest_params;
147 testsuite_setup(void)
149 struct crypto_testsuite_params *ts_params = &testsuite_params;
150 struct rte_cryptodev_info info;
151 unsigned i, nb_devs, dev_id;
155 memset(ts_params, 0, sizeof(*ts_params));
157 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
158 if (ts_params->mbuf_pool == NULL) {
159 /* Not already created so create */
160 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
162 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
164 if (ts_params->mbuf_pool == NULL) {
165 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
170 ts_params->op_mpool = rte_crypto_op_pool_create(
171 "MBUF_CRYPTO_SYM_OP_POOL",
172 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
173 NUM_MBUFS, MBUF_CACHE_SIZE,
175 sizeof(struct rte_crypto_sym_xform),
177 if (ts_params->op_mpool == NULL) {
178 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
182 /* Create 2 AESNI MB devices if required */
183 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
184 nb_devs = rte_cryptodev_count_devtype(
185 RTE_CRYPTODEV_AESNI_MB_PMD);
187 for (i = nb_devs; i < 2; i++) {
188 ret = rte_eal_vdev_init(
189 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
191 TEST_ASSERT(ret == 0,
192 "Failed to create instance %u of"
194 i, CRYPTODEV_NAME_AESNI_MB_PMD);
199 /* Create 2 AESNI GCM devices if required */
200 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
201 nb_devs = rte_cryptodev_count_devtype(
202 RTE_CRYPTODEV_AESNI_GCM_PMD);
204 for (i = nb_devs; i < 2; i++) {
205 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
206 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
207 "Failed to create instance %u of"
209 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
214 /* Create 2 Snow3G devices if required */
215 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
216 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
218 for (i = nb_devs; i < 2; i++) {
219 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
220 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
221 "Failed to create instance %u of"
223 i, CRYPTODEV_NAME_SNOW3G_PMD);
228 /* Create 2 KASUMI devices if required */
229 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
230 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
232 for (i = nb_devs; i < 2; i++) {
233 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
234 CRYPTODEV_NAME_KASUMI_PMD, NULL),
235 "Failed to create instance %u of"
237 i, CRYPTODEV_NAME_KASUMI_PMD);
242 /* Create 2 NULL devices if required */
243 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
244 nb_devs = rte_cryptodev_count_devtype(
245 RTE_CRYPTODEV_NULL_PMD);
247 for (i = nb_devs; i < 2; i++) {
248 int dev_id = rte_eal_vdev_init(
249 CRYPTODEV_NAME_NULL_PMD, NULL);
251 TEST_ASSERT(dev_id >= 0,
252 "Failed to create instance %u of"
254 i, CRYPTODEV_NAME_NULL_PMD);
259 nb_devs = rte_cryptodev_count();
261 RTE_LOG(ERR, USER1, "No crypto devices found?");
265 /* Create list of valid crypto devs */
266 for (i = 0; i < nb_devs; i++) {
267 rte_cryptodev_info_get(i, &info);
268 if (info.dev_type == gbl_cryptodev_type)
269 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
272 if (ts_params->valid_dev_count < 1)
275 /* Set up all the qps on the first of the valid devices found */
276 for (i = 0; i < 1; i++) {
277 dev_id = ts_params->valid_devs[i];
279 rte_cryptodev_info_get(dev_id, &info);
282 * Since we can't free and re-allocate queue memory always set
283 * the queues on this device up to max size first so enough
284 * memory is allocated for any later re-configures needed by
288 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
289 ts_params->conf.socket_id = SOCKET_ID_ANY;
290 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
292 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
294 "Failed to configure cryptodev %u with %u qps",
295 dev_id, ts_params->conf.nb_queue_pairs);
297 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
299 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
300 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
301 dev_id, qp_id, &ts_params->qp_conf,
302 rte_cryptodev_socket_id(dev_id)),
303 "Failed to setup queue pair %u on "
313 testsuite_teardown(void)
315 struct crypto_testsuite_params *ts_params = &testsuite_params;
317 if (ts_params->mbuf_pool != NULL) {
318 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
319 rte_mempool_count(ts_params->mbuf_pool));
322 if (ts_params->op_mpool != NULL) {
323 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
324 rte_mempool_count(ts_params->op_mpool));
332 struct crypto_testsuite_params *ts_params = &testsuite_params;
333 struct crypto_unittest_params *ut_params = &unittest_params;
337 /* Clear unit test parameters before running test */
338 memset(ut_params, 0, sizeof(*ut_params));
340 /* Reconfigure device to default parameters */
341 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
342 ts_params->conf.socket_id = SOCKET_ID_ANY;
343 ts_params->conf.session_mp.nb_objs =
344 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
345 DEFAULT_NUM_OPS_INFLIGHT :
346 DEFAULT_NUM_OPS_INFLIGHT;
348 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
350 "Failed to configure cryptodev %u",
351 ts_params->valid_devs[0]);
354 * Now reconfigure queues to size we actually want to use in this
357 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
359 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
360 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
361 ts_params->valid_devs[0], qp_id,
363 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
364 "Failed to setup queue pair %u on cryptodev %u",
365 qp_id, ts_params->valid_devs[0]);
369 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
371 /* Start the device */
372 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
373 "Failed to start cryptodev %u",
374 ts_params->valid_devs[0]);
382 struct crypto_testsuite_params *ts_params = &testsuite_params;
383 struct crypto_unittest_params *ut_params = &unittest_params;
384 struct rte_cryptodev_stats stats;
386 /* free crypto session structure */
387 if (ut_params->sess) {
388 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
390 ut_params->sess = NULL;
393 /* free crypto operation structure */
395 rte_crypto_op_free(ut_params->op);
398 * free mbuf - both obuf and ibuf are usually the same,
399 * but rte copes even if we call free twice
401 if (ut_params->obuf) {
402 rte_pktmbuf_free(ut_params->obuf);
405 if (ut_params->ibuf) {
406 rte_pktmbuf_free(ut_params->ibuf);
410 if (ts_params->mbuf_pool != NULL)
411 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
412 rte_mempool_count(ts_params->mbuf_pool));
414 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
416 /* Stop the device */
417 rte_cryptodev_stop(ts_params->valid_devs[0]);
421 test_device_configure_invalid_dev_id(void)
423 struct crypto_testsuite_params *ts_params = &testsuite_params;
424 uint16_t dev_id, num_devs = 0;
426 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
427 "Need at least %d devices for test", 1);
429 /* valid dev_id values */
430 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
432 /* Stop the device in case it's started so it can be configured */
433 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
435 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
436 "Failed test for rte_cryptodev_configure: "
437 "invalid dev_num %u", dev_id);
439 /* invalid dev_id values */
442 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
443 "Failed test for rte_cryptodev_configure: "
444 "invalid dev_num %u", dev_id);
448 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
449 "Failed test for rte_cryptodev_configure:"
450 "invalid dev_num %u", dev_id);
456 test_device_configure_invalid_queue_pair_ids(void)
458 struct crypto_testsuite_params *ts_params = &testsuite_params;
460 /* Stop the device in case it's started so it can be configured */
461 rte_cryptodev_stop(ts_params->valid_devs[0]);
463 /* valid - one queue pairs */
464 ts_params->conf.nb_queue_pairs = 1;
466 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
468 "Failed to configure cryptodev: dev_id %u, qp_id %u",
469 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
472 /* valid - max value queue pairs */
473 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
475 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
477 "Failed to configure cryptodev: dev_id %u, qp_id %u",
478 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
481 /* invalid - zero queue pairs */
482 ts_params->conf.nb_queue_pairs = 0;
484 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
486 "Failed test for rte_cryptodev_configure, dev_id %u,"
488 ts_params->valid_devs[0],
489 ts_params->conf.nb_queue_pairs);
492 /* invalid - max value supported by field queue pairs */
493 ts_params->conf.nb_queue_pairs = UINT16_MAX;
495 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
497 "Failed test for rte_cryptodev_configure, dev_id %u,"
499 ts_params->valid_devs[0],
500 ts_params->conf.nb_queue_pairs);
503 /* invalid - max value + 1 queue pairs */
504 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
506 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
508 "Failed test for rte_cryptodev_configure, dev_id %u,"
510 ts_params->valid_devs[0],
511 ts_params->conf.nb_queue_pairs);
517 test_queue_pair_descriptor_setup(void)
519 struct crypto_testsuite_params *ts_params = &testsuite_params;
520 struct rte_cryptodev_info dev_info;
521 struct rte_cryptodev_qp_conf qp_conf = {
522 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
527 /* Stop the device in case it's started so it can be configured */
528 rte_cryptodev_stop(ts_params->valid_devs[0]);
531 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
533 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
535 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
536 &ts_params->conf), "Failed to configure cryptodev %u",
537 ts_params->valid_devs[0]);
541 * Test various ring sizes on this device. memzones can't be
542 * freed so are re-used if ring is released and re-created.
544 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
546 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
547 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
548 ts_params->valid_devs[0], qp_id, &qp_conf,
549 rte_cryptodev_socket_id(
550 ts_params->valid_devs[0])),
552 "rte_cryptodev_queue_pair_setup: num_inflights "
553 "%u on qp %u on cryptodev %u",
554 qp_conf.nb_descriptors, qp_id,
555 ts_params->valid_devs[0]);
558 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
560 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
561 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
562 ts_params->valid_devs[0], qp_id, &qp_conf,
563 rte_cryptodev_socket_id(
564 ts_params->valid_devs[0])),
566 " rte_cryptodev_queue_pair_setup: num_inflights"
567 " %u on qp %u on cryptodev %u",
568 qp_conf.nb_descriptors, qp_id,
569 ts_params->valid_devs[0]);
572 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
574 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
575 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
576 ts_params->valid_devs[0], qp_id, &qp_conf,
577 rte_cryptodev_socket_id(
578 ts_params->valid_devs[0])),
580 "rte_cryptodev_queue_pair_setup: num_inflights"
581 " %u on qp %u on cryptodev %u",
582 qp_conf.nb_descriptors, qp_id,
583 ts_params->valid_devs[0]);
586 /* invalid number of descriptors - max supported + 2 */
587 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
589 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
590 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
591 ts_params->valid_devs[0], qp_id, &qp_conf,
592 rte_cryptodev_socket_id(
593 ts_params->valid_devs[0])),
594 "Unexpectedly passed test for "
595 "rte_cryptodev_queue_pair_setup:"
596 "num_inflights %u on qp %u on cryptodev %u",
597 qp_conf.nb_descriptors, qp_id,
598 ts_params->valid_devs[0]);
601 /* invalid number of descriptors - max value of parameter */
602 qp_conf.nb_descriptors = UINT32_MAX-1;
604 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
605 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
606 ts_params->valid_devs[0], qp_id, &qp_conf,
607 rte_cryptodev_socket_id(
608 ts_params->valid_devs[0])),
609 "Unexpectedly passed test for "
610 "rte_cryptodev_queue_pair_setup:"
611 "num_inflights %u on qp %u on cryptodev %u",
612 qp_conf.nb_descriptors, qp_id,
613 ts_params->valid_devs[0]);
616 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
618 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
619 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
620 ts_params->valid_devs[0], qp_id, &qp_conf,
621 rte_cryptodev_socket_id(
622 ts_params->valid_devs[0])),
624 " rte_cryptodev_queue_pair_setup:"
625 "num_inflights %u on qp %u on cryptodev %u",
626 qp_conf.nb_descriptors, qp_id,
627 ts_params->valid_devs[0]);
630 /* invalid number of descriptors - max supported + 1 */
631 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
633 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
634 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
635 ts_params->valid_devs[0], qp_id, &qp_conf,
636 rte_cryptodev_socket_id(
637 ts_params->valid_devs[0])),
638 "Unexpectedly passed test for "
639 "rte_cryptodev_queue_pair_setup:"
640 "num_inflights %u on qp %u on cryptodev %u",
641 qp_conf.nb_descriptors, qp_id,
642 ts_params->valid_devs[0]);
645 /* test invalid queue pair id */
646 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
648 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
650 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
651 ts_params->valid_devs[0],
653 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
654 "Failed test for rte_cryptodev_queue_pair_setup:"
655 "invalid qp %u on cryptodev %u",
656 qp_id, ts_params->valid_devs[0]);
658 qp_id = 0xffff; /*invalid*/
660 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
661 ts_params->valid_devs[0],
663 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
664 "Failed test for rte_cryptodev_queue_pair_setup:"
665 "invalid qp %u on cryptodev %u",
666 qp_id, ts_params->valid_devs[0]);
671 /* ***** Plaintext data for tests ***** */
673 const char catch_22_quote_1[] =
674 "There was only one catch and that was Catch-22, which "
675 "specified that a concern for one's safety in the face of "
676 "dangers that were real and immediate was the process of a "
677 "rational mind. Orr was crazy and could be grounded. All he "
678 "had to do was ask; and as soon as he did, he would no longer "
679 "be crazy and would have to fly more missions. Orr would be "
680 "crazy to fly more missions and sane if he didn't, but if he "
681 "was sane he had to fly them. If he flew them he was crazy "
682 "and didn't have to; but if he didn't want to he was sane and "
683 "had to. Yossarian was moved very deeply by the absolute "
684 "simplicity of this clause of Catch-22 and let out a "
685 "respectful whistle. \"That's some catch, that Catch-22\", he "
686 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
688 const char catch_22_quote[] =
689 "What a lousy earth! He wondered how many people were "
690 "destitute that same night even in his own prosperous country, "
691 "how many homes were shanties, how many husbands were drunk "
692 "and wives socked, and how many children were bullied, abused, "
693 "or abandoned. How many families hungered for food they could "
694 "not afford to buy? How many hearts were broken? How many "
695 "suicides would take place that same night, how many people "
696 "would go insane? How many cockroaches and landlords would "
697 "triumph? How many winners were losers, successes failures, "
698 "and rich men poor men? How many wise guys were stupid? How "
699 "many happy endings were unhappy endings? How many honest men "
700 "were liars, brave men cowards, loyal men traitors, how many "
701 "sainted men were corrupt, how many people in positions of "
702 "trust had sold their souls to bodyguards, how many had never "
703 "had souls? How many straight-and-narrow paths were crooked "
704 "paths? How many best families were worst families and how "
705 "many good people were bad people? When you added them all up "
706 "and then subtracted, you might be left with only the children, "
707 "and perhaps with Albert Einstein and an old violinist or "
708 "sculptor somewhere.";
710 #define QUOTE_480_BYTES (480)
711 #define QUOTE_512_BYTES (512)
712 #define QUOTE_768_BYTES (768)
713 #define QUOTE_1024_BYTES (1024)
717 /* ***** SHA1 Hash Tests ***** */
719 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
721 static uint8_t hmac_sha1_key[] = {
722 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
723 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
724 0xDE, 0xF4, 0xDE, 0xAD };
726 /* ***** SHA224 Hash Tests ***** */
728 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
731 /* ***** AES-CBC Cipher Tests ***** */
733 #define CIPHER_KEY_LENGTH_AES_CBC (16)
734 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
736 static uint8_t aes_cbc_key[] = {
737 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
738 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
740 static uint8_t aes_cbc_iv[] = {
741 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
742 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
745 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
747 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
748 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
749 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
750 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
751 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
752 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
753 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
754 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
755 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
756 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
757 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
758 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
759 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
760 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
761 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
762 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
763 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
764 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
765 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
766 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
767 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
768 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
769 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
770 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
771 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
772 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
773 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
774 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
775 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
776 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
777 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
778 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
779 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
780 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
781 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
782 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
783 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
784 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
785 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
786 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
787 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
788 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
789 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
790 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
791 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
792 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
793 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
794 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
795 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
796 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
797 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
798 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
799 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
800 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
801 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
802 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
803 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
804 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
805 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
806 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
807 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
808 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
809 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
810 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
811 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
814 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
815 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
816 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
817 0x18, 0x8c, 0x1d, 0x32
822 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
824 struct crypto_testsuite_params *ts_params = &testsuite_params;
825 struct crypto_unittest_params *ut_params = &unittest_params;
827 /* Generate test mbuf data and space for digest */
828 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
829 catch_22_quote, QUOTE_512_BYTES, 0);
831 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
832 DIGEST_BYTE_LENGTH_SHA1);
833 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
835 /* Setup Cipher Parameters */
836 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
837 ut_params->cipher_xform.next = &ut_params->auth_xform;
839 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
840 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
841 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
842 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
844 /* Setup HMAC Parameters */
845 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
847 ut_params->auth_xform.next = NULL;
849 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
850 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
851 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
852 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
853 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
855 /* Create crypto session*/
856 ut_params->sess = rte_cryptodev_sym_session_create(
857 ts_params->valid_devs[0],
858 &ut_params->cipher_xform);
859 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
861 /* Generate crypto op data structure */
862 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
863 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
864 TEST_ASSERT_NOT_NULL(ut_params->op,
865 "Failed to allocate symmetric crypto operation struct");
867 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
869 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
871 /* set crypto operation source mbuf */
872 sym_op->m_src = ut_params->ibuf;
874 /* Set crypto operation authentication parameters */
875 sym_op->auth.digest.data = ut_params->digest;
876 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
877 ut_params->ibuf, QUOTE_512_BYTES);
878 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
880 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
881 sym_op->auth.data.length = QUOTE_512_BYTES;
883 /* Set crypto operation cipher parameters */
884 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
885 CIPHER_IV_LENGTH_AES_CBC);
886 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
887 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
889 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
890 CIPHER_IV_LENGTH_AES_CBC);
892 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
893 sym_op->cipher.data.length = QUOTE_512_BYTES;
895 /* Process crypto operation */
896 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
897 ut_params->op), "failed to process sym crypto op");
899 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
900 "crypto op processing failed");
903 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
904 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
906 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
907 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
909 "ciphertext data not as expected");
911 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
913 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
914 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
915 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
916 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
917 DIGEST_BYTE_LENGTH_SHA1,
918 "Generated digest data not as expected");
923 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
925 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
927 static uint8_t hmac_sha512_key[] = {
928 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
929 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
930 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
931 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
932 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
933 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
934 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
935 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
937 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
938 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
939 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
940 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
941 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
942 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
943 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
944 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
945 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
950 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
951 struct crypto_unittest_params *ut_params);
954 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
955 struct crypto_unittest_params *ut_params,
956 struct crypto_testsuite_params *ts_params);
960 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
961 struct crypto_unittest_params *ut_params)
964 /* Setup Cipher Parameters */
965 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
966 ut_params->cipher_xform.next = NULL;
968 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
969 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
970 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
971 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
973 /* Setup HMAC Parameters */
974 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
975 ut_params->auth_xform.next = &ut_params->cipher_xform;
977 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
978 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
979 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
980 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
981 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
988 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
989 struct crypto_unittest_params *ut_params,
990 struct crypto_testsuite_params *ts_params)
992 /* Generate test mbuf data and digest */
993 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
995 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
998 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
999 DIGEST_BYTE_LENGTH_SHA512);
1000 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1002 rte_memcpy(ut_params->digest,
1003 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1004 DIGEST_BYTE_LENGTH_SHA512);
1006 /* Generate Crypto op data structure */
1007 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1008 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1009 TEST_ASSERT_NOT_NULL(ut_params->op,
1010 "Failed to allocate symmetric crypto operation struct");
1012 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1014 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1016 /* set crypto operation source mbuf */
1017 sym_op->m_src = ut_params->ibuf;
1019 sym_op->auth.digest.data = ut_params->digest;
1020 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1021 ut_params->ibuf, QUOTE_512_BYTES);
1022 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1024 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1025 sym_op->auth.data.length = QUOTE_512_BYTES;
1027 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1028 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1029 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1030 ut_params->ibuf, 0);
1031 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1033 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1034 CIPHER_IV_LENGTH_AES_CBC);
1036 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1037 sym_op->cipher.data.length = QUOTE_512_BYTES;
1039 /* Process crypto operation */
1040 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1041 ut_params->op), "failed to process sym crypto op");
1043 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1044 "crypto op processing failed");
1046 ut_params->obuf = ut_params->op->sym->m_src;
1049 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1050 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1051 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1053 "Plaintext data not as expected");
1056 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1057 "Digest verification failed");
1059 return TEST_SUCCESS;
1063 test_AES_mb_all(void)
1065 struct crypto_testsuite_params *ts_params = &testsuite_params;
1068 status = test_AES_all_tests(ts_params->mbuf_pool,
1069 ts_params->op_mpool, ts_params->valid_devs[0],
1070 RTE_CRYPTODEV_AESNI_MB_PMD);
1072 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1074 return TEST_SUCCESS;
1078 test_AES_qat_all(void)
1080 struct crypto_testsuite_params *ts_params = &testsuite_params;
1083 status = test_AES_all_tests(ts_params->mbuf_pool,
1084 ts_params->op_mpool, ts_params->valid_devs[0],
1085 RTE_CRYPTODEV_QAT_SYM_PMD);
1087 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1089 return TEST_SUCCESS;
1092 /* ***** Snow3G Tests ***** */
1094 create_snow3g_kasumi_hash_session(uint8_t dev_id,
1095 const uint8_t *key, const uint8_t key_len,
1096 const uint8_t aad_len, const uint8_t auth_len,
1097 enum rte_crypto_auth_operation op,
1098 enum rte_crypto_auth_algorithm algo)
1100 uint8_t hash_key[key_len];
1102 struct crypto_unittest_params *ut_params = &unittest_params;
1104 memcpy(hash_key, key, key_len);
1106 TEST_HEXDUMP(stdout, "key:", key, key_len);
1108 /* Setup Authentication Parameters */
1109 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1110 ut_params->auth_xform.next = NULL;
1112 ut_params->auth_xform.auth.op = op;
1113 ut_params->auth_xform.auth.algo = algo;
1114 ut_params->auth_xform.auth.key.length = key_len;
1115 ut_params->auth_xform.auth.key.data = hash_key;
1116 ut_params->auth_xform.auth.digest_length = auth_len;
1117 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1118 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1119 &ut_params->auth_xform);
1120 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1125 create_snow3g_kasumi_cipher_session(uint8_t dev_id,
1126 enum rte_crypto_cipher_operation op,
1127 enum rte_crypto_cipher_algorithm algo,
1128 const uint8_t *key, const uint8_t key_len)
1130 uint8_t cipher_key[key_len];
1132 struct crypto_unittest_params *ut_params = &unittest_params;
1134 memcpy(cipher_key, key, key_len);
1136 /* Setup Cipher Parameters */
1137 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1138 ut_params->cipher_xform.next = NULL;
1140 ut_params->cipher_xform.cipher.algo = algo;
1141 ut_params->cipher_xform.cipher.op = op;
1142 ut_params->cipher_xform.cipher.key.data = cipher_key;
1143 ut_params->cipher_xform.cipher.key.length = key_len;
1145 TEST_HEXDUMP(stdout, "key:", key, key_len);
1147 /* Create Crypto session */
1148 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1151 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1156 create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1157 const unsigned cipher_len,
1158 const unsigned cipher_offset,
1159 enum rte_crypto_cipher_algorithm algo)
1161 struct crypto_testsuite_params *ts_params = &testsuite_params;
1162 struct crypto_unittest_params *ut_params = &unittest_params;
1163 unsigned iv_pad_len = 0;
1165 /* Generate Crypto op data structure */
1166 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1167 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1168 TEST_ASSERT_NOT_NULL(ut_params->op,
1169 "Failed to allocate pktmbuf offload");
1171 /* Set crypto operation data parameters */
1172 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1174 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1176 /* set crypto operation source mbuf */
1177 sym_op->m_src = ut_params->ibuf;
1180 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1181 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1183 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1185 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1188 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1190 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1191 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1192 sym_op->cipher.iv.length = iv_pad_len;
1194 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1195 sym_op->cipher.data.length = cipher_len;
1196 sym_op->cipher.data.offset = cipher_offset;
1201 create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1202 const unsigned cipher_len,
1203 const unsigned cipher_offset,
1204 enum rte_crypto_cipher_algorithm algo)
1206 struct crypto_testsuite_params *ts_params = &testsuite_params;
1207 struct crypto_unittest_params *ut_params = &unittest_params;
1208 unsigned iv_pad_len = 0;
1210 /* Generate Crypto op data structure */
1211 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1212 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1213 TEST_ASSERT_NOT_NULL(ut_params->op,
1214 "Failed to allocate pktmbuf offload");
1216 /* Set crypto operation data parameters */
1217 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1219 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1221 /* set crypto operation source mbuf */
1222 sym_op->m_src = ut_params->ibuf;
1223 sym_op->m_dst = ut_params->obuf;
1226 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1227 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1229 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1230 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1233 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1235 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1236 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1237 sym_op->cipher.iv.length = iv_pad_len;
1239 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1240 sym_op->cipher.data.length = cipher_len;
1241 sym_op->cipher.data.offset = cipher_offset;
1246 create_snow3g_kasumi_cipher_auth_session(uint8_t dev_id,
1247 enum rte_crypto_cipher_operation cipher_op,
1248 enum rte_crypto_auth_operation auth_op,
1249 enum rte_crypto_auth_algorithm auth_algo,
1250 enum rte_crypto_cipher_algorithm cipher_algo,
1251 const uint8_t *key, const uint8_t key_len,
1252 const uint8_t aad_len, const uint8_t auth_len)
1255 uint8_t cipher_auth_key[key_len];
1257 struct crypto_unittest_params *ut_params = &unittest_params;
1259 memcpy(cipher_auth_key, key, key_len);
1261 /* Setup Authentication Parameters */
1262 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1263 ut_params->auth_xform.next = NULL;
1265 ut_params->auth_xform.auth.op = auth_op;
1266 ut_params->auth_xform.auth.algo = auth_algo;
1267 ut_params->auth_xform.auth.key.length = key_len;
1268 /* Hash key = cipher key */
1269 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1270 ut_params->auth_xform.auth.digest_length = auth_len;
1271 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1273 /* Setup Cipher Parameters */
1274 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1275 ut_params->cipher_xform.next = &ut_params->auth_xform;
1277 ut_params->cipher_xform.cipher.algo = cipher_algo;
1278 ut_params->cipher_xform.cipher.op = cipher_op;
1279 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1280 ut_params->cipher_xform.cipher.key.length = key_len;
1282 TEST_HEXDUMP(stdout, "key:", key, key_len);
1284 /* Create Crypto session*/
1285 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1286 &ut_params->cipher_xform);
1288 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1293 create_snow3g_kasumi_auth_cipher_session(uint8_t dev_id,
1294 enum rte_crypto_cipher_operation cipher_op,
1295 enum rte_crypto_auth_operation auth_op,
1296 enum rte_crypto_auth_algorithm auth_algo,
1297 enum rte_crypto_cipher_algorithm cipher_algo,
1298 const uint8_t *key, const uint8_t key_len,
1299 const uint8_t aad_len, const uint8_t auth_len)
1301 uint8_t auth_cipher_key[key_len];
1303 struct crypto_unittest_params *ut_params = &unittest_params;
1305 memcpy(auth_cipher_key, key, key_len);
1307 /* Setup Authentication Parameters */
1308 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1309 ut_params->auth_xform.auth.op = auth_op;
1310 ut_params->auth_xform.next = &ut_params->cipher_xform;
1311 ut_params->auth_xform.auth.algo = auth_algo;
1312 ut_params->auth_xform.auth.key.length = key_len;
1313 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1314 ut_params->auth_xform.auth.digest_length = auth_len;
1315 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1317 /* Setup Cipher Parameters */
1318 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1319 ut_params->cipher_xform.next = NULL;
1320 ut_params->cipher_xform.cipher.algo = cipher_algo;
1321 ut_params->cipher_xform.cipher.op = cipher_op;
1322 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1323 ut_params->cipher_xform.cipher.key.length = key_len;
1325 TEST_HEXDUMP(stdout, "key:", key, key_len);
1327 /* Create Crypto session*/
1328 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1329 &ut_params->auth_xform);
1331 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1337 create_snow3g_kasumi_hash_operation(const uint8_t *auth_tag,
1338 const unsigned auth_tag_len,
1339 const uint8_t *aad, const unsigned aad_len,
1340 unsigned data_pad_len,
1341 enum rte_crypto_auth_operation op,
1342 enum rte_crypto_auth_algorithm algo,
1343 const unsigned auth_len, const unsigned auth_offset)
1345 struct crypto_testsuite_params *ts_params = &testsuite_params;
1347 struct crypto_unittest_params *ut_params = &unittest_params;
1349 unsigned aad_buffer_len;
1351 /* Generate Crypto op data structure */
1352 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1353 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1354 TEST_ASSERT_NOT_NULL(ut_params->op,
1355 "Failed to allocate pktmbuf offload");
1357 /* Set crypto operation data parameters */
1358 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1360 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1362 /* set crypto operation source mbuf */
1363 sym_op->m_src = ut_params->ibuf;
1367 * Always allocate the aad up to the block size.
1368 * The cryptodev API calls out -
1369 * - the array must be big enough to hold the AAD, plus any
1370 * space to round this up to the nearest multiple of the
1371 * block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
1373 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1374 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1376 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1377 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1378 ut_params->ibuf, aad_buffer_len);
1379 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1380 "no room to prepend aad");
1381 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1383 sym_op->auth.aad.length = aad_len;
1385 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1386 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1388 TEST_HEXDUMP(stdout, "aad:",
1389 sym_op->auth.aad.data, aad_len);
1392 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1393 ut_params->ibuf, auth_tag_len);
1395 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1396 "no room to append auth tag");
1397 ut_params->digest = sym_op->auth.digest.data;
1398 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1399 ut_params->ibuf, data_pad_len + aad_len);
1400 sym_op->auth.digest.length = auth_tag_len;
1401 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1402 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1404 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1406 TEST_HEXDUMP(stdout, "digest:",
1407 sym_op->auth.digest.data,
1408 sym_op->auth.digest.length);
1410 sym_op->auth.data.length = auth_len;
1411 sym_op->auth.data.offset = auth_offset;
1417 create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
1418 const unsigned auth_tag_len,
1419 const uint8_t *aad, const uint8_t aad_len,
1420 unsigned data_pad_len,
1421 enum rte_crypto_auth_operation op,
1422 enum rte_crypto_auth_algorithm auth_algo,
1423 enum rte_crypto_cipher_algorithm cipher_algo,
1424 const uint8_t *iv, const uint8_t iv_len,
1425 const unsigned cipher_len, const unsigned cipher_offset,
1426 const unsigned auth_len, const unsigned auth_offset)
1428 struct crypto_testsuite_params *ts_params = &testsuite_params;
1429 struct crypto_unittest_params *ut_params = &unittest_params;
1431 unsigned iv_pad_len = 0;
1432 unsigned aad_buffer_len;
1434 /* Generate Crypto op data structure */
1435 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1436 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1437 TEST_ASSERT_NOT_NULL(ut_params->op,
1438 "Failed to allocate pktmbuf offload");
1439 /* Set crypto operation data parameters */
1440 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1442 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1444 /* set crypto operation source mbuf */
1445 sym_op->m_src = ut_params->ibuf;
1449 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1450 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1452 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1454 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1455 ut_params->ibuf, iv_pad_len);
1456 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1458 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1459 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1460 sym_op->cipher.iv.length = iv_pad_len;
1462 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1464 sym_op->cipher.data.length = cipher_len;
1465 sym_op->cipher.data.offset = cipher_offset;
1469 * Always allocate the aad up to the block size.
1470 * The cryptodev API calls out -
1471 * - the array must be big enough to hold the AAD, plus any
1472 * space to round this up to the nearest multiple of the
1473 * block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
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);
1480 sym_op->auth.aad.data =
1481 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1482 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1483 "no room to prepend aad");
1484 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1486 sym_op->auth.aad.length = aad_len;
1488 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1489 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1491 TEST_HEXDUMP(stdout, "aad:",
1492 sym_op->auth.aad.data, aad_len);
1495 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1496 ut_params->ibuf, auth_tag_len);
1498 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1499 "no room to append auth tag");
1500 ut_params->digest = sym_op->auth.digest.data;
1501 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1502 ut_params->ibuf, data_pad_len + aad_len);
1503 sym_op->auth.digest.length = auth_tag_len;
1504 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1505 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1507 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1509 TEST_HEXDUMP(stdout, "digest:",
1510 sym_op->auth.digest.data,
1511 sym_op->auth.digest.length);
1513 sym_op->auth.data.length = auth_len;
1514 sym_op->auth.data.offset = auth_offset;
1520 create_snow3g_kasumi_auth_cipher_operation(const unsigned auth_tag_len,
1521 const uint8_t *iv, const uint8_t iv_len,
1522 const uint8_t *aad, const uint8_t aad_len,
1523 unsigned data_pad_len,
1524 const unsigned cipher_len, const unsigned cipher_offset,
1525 const unsigned auth_len, const unsigned auth_offset,
1526 enum rte_crypto_auth_algorithm auth_algo,
1527 enum rte_crypto_cipher_algorithm cipher_algo)
1529 struct crypto_testsuite_params *ts_params = &testsuite_params;
1530 struct crypto_unittest_params *ut_params = &unittest_params;
1532 unsigned iv_pad_len = 0;
1533 unsigned aad_buffer_len = 0;
1535 /* Generate Crypto op data structure */
1536 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1537 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1538 TEST_ASSERT_NOT_NULL(ut_params->op,
1539 "Failed to allocate pktmbuf offload");
1541 /* Set crypto operation data parameters */
1542 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1544 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1546 /* set crypto operation source mbuf */
1547 sym_op->m_src = ut_params->ibuf;
1550 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1551 ut_params->ibuf, auth_tag_len);
1553 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1554 "no room to append auth tag");
1556 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1557 ut_params->ibuf, data_pad_len);
1558 sym_op->auth.digest.length = auth_tag_len;
1560 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1562 TEST_HEXDUMP(stdout, "digest:",
1563 sym_op->auth.digest.data,
1564 sym_op->auth.digest.length);
1567 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1568 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1570 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1572 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1573 ut_params->ibuf, iv_pad_len);
1574 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1576 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1577 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1578 sym_op->cipher.iv.length = iv_pad_len;
1580 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1584 * Always allocate the aad up to the block size.
1585 * The cryptodev API calls out -
1586 * - the array must be big enough to hold the AAD, plus any
1587 * space to round this up to the nearest multiple of the
1588 * block size (8 bytes for KASUMI 16 bytes).
1590 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1591 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1593 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1595 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1596 ut_params->ibuf, aad_buffer_len);
1597 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1598 "no room to prepend aad");
1599 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1601 sym_op->auth.aad.length = aad_len;
1603 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1604 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1606 TEST_HEXDUMP(stdout, "aad:",
1607 sym_op->auth.aad.data, aad_len);
1609 sym_op->cipher.data.length = cipher_len;
1610 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1612 sym_op->auth.data.length = auth_len;
1613 sym_op->auth.data.offset = auth_offset + cipher_offset;
1619 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1621 struct crypto_testsuite_params *ts_params = &testsuite_params;
1622 struct crypto_unittest_params *ut_params = &unittest_params;
1625 unsigned plaintext_pad_len;
1626 unsigned plaintext_len;
1629 /* Create SNOW3G session */
1630 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1631 tdata->key.data, tdata->key.len,
1632 tdata->aad.len, tdata->digest.len,
1633 RTE_CRYPTO_AUTH_OP_GENERATE,
1634 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1638 /* alloc mbuf and set payload */
1639 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1641 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1642 rte_pktmbuf_tailroom(ut_params->ibuf));
1644 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1645 /* Append data which is padded to a multiple of */
1646 /* the algorithms block size */
1647 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1648 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1650 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1652 /* Create SNOW3G operation */
1653 retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1654 tdata->aad.data, tdata->aad.len,
1655 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1656 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1657 tdata->validAuthLenInBits.len,
1658 tdata->validAuthOffsetLenInBits.len);
1662 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1664 ut_params->obuf = ut_params->op->sym->m_src;
1665 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1666 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1667 + plaintext_pad_len + tdata->aad.len;
1670 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1673 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1674 "Snow3G Generated auth tag not as expected");
1680 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1682 struct crypto_testsuite_params *ts_params = &testsuite_params;
1683 struct crypto_unittest_params *ut_params = &unittest_params;
1686 unsigned plaintext_pad_len;
1687 unsigned plaintext_len;
1690 /* Create SNOW3G session */
1691 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1692 tdata->key.data, tdata->key.len,
1693 tdata->aad.len, tdata->digest.len,
1694 RTE_CRYPTO_AUTH_OP_VERIFY,
1695 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1698 /* alloc mbuf and set payload */
1699 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1701 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1702 rte_pktmbuf_tailroom(ut_params->ibuf));
1704 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1705 /* Append data which is padded to a multiple of */
1706 /* the algorithms block size */
1707 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1708 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1710 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1712 /* Create SNOW3G operation */
1713 retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1715 tdata->aad.data, tdata->aad.len,
1717 RTE_CRYPTO_AUTH_OP_VERIFY,
1718 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1719 tdata->validAuthLenInBits.len,
1720 tdata->validAuthOffsetLenInBits.len);
1724 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1726 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1727 ut_params->obuf = ut_params->op->sym->m_src;
1728 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1729 + plaintext_pad_len + tdata->aad.len;
1732 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1741 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1743 struct crypto_testsuite_params *ts_params = &testsuite_params;
1744 struct crypto_unittest_params *ut_params = &unittest_params;
1747 unsigned plaintext_pad_len;
1748 unsigned plaintext_len;
1751 /* Create KASUMI session */
1752 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1753 tdata->key.data, tdata->key.len,
1754 tdata->aad.len, tdata->digest.len,
1755 RTE_CRYPTO_AUTH_OP_GENERATE,
1756 RTE_CRYPTO_AUTH_KASUMI_F9);
1760 /* alloc mbuf and set payload */
1761 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1763 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1764 rte_pktmbuf_tailroom(ut_params->ibuf));
1766 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1767 /* Append data which is padded to a multiple of */
1768 /* the algorithms block size */
1769 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1770 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1772 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1774 /* Create KASUMI operation */
1775 retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1776 tdata->aad.data, tdata->aad.len,
1777 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1778 RTE_CRYPTO_AUTH_KASUMI_F9,
1779 tdata->validAuthLenInBits.len,
1780 tdata->validAuthOffsetLenInBits.len);
1784 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1786 ut_params->obuf = ut_params->op->sym->m_src;
1787 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1788 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1789 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1792 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1795 DIGEST_BYTE_LENGTH_KASUMI_F9,
1796 "KASUMI Generated auth tag not as expected");
1802 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1804 struct crypto_testsuite_params *ts_params = &testsuite_params;
1805 struct crypto_unittest_params *ut_params = &unittest_params;
1808 unsigned plaintext_pad_len;
1809 unsigned plaintext_len;
1812 /* Create KASUMI session */
1813 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1814 tdata->key.data, tdata->key.len,
1815 tdata->aad.len, tdata->digest.len,
1816 RTE_CRYPTO_AUTH_OP_VERIFY,
1817 RTE_CRYPTO_AUTH_KASUMI_F9);
1820 /* alloc mbuf and set payload */
1821 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1823 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1824 rte_pktmbuf_tailroom(ut_params->ibuf));
1826 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1827 /* Append data which is padded to a multiple */
1828 /* of the algorithms block size */
1829 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1830 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1832 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1834 /* Create KASUMI operation */
1835 retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1837 tdata->aad.data, tdata->aad.len,
1839 RTE_CRYPTO_AUTH_OP_VERIFY,
1840 RTE_CRYPTO_AUTH_KASUMI_F9,
1841 tdata->validAuthLenInBits.len,
1842 tdata->validAuthOffsetLenInBits.len);
1846 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1848 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1849 ut_params->obuf = ut_params->op->sym->m_src;
1850 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1851 + plaintext_pad_len + tdata->aad.len;
1854 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1863 test_snow3g_hash_generate_test_case_1(void)
1865 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1869 test_snow3g_hash_generate_test_case_2(void)
1871 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1875 test_snow3g_hash_generate_test_case_3(void)
1877 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1881 test_snow3g_hash_generate_test_case_4(void)
1883 return test_snow3g_authentication(&snow3g_hash_test_case_4);
1887 test_snow3g_hash_generate_test_case_5(void)
1889 return test_snow3g_authentication(&snow3g_hash_test_case_5);
1893 test_snow3g_hash_generate_test_case_6(void)
1895 return test_snow3g_authentication(&snow3g_hash_test_case_6);
1899 test_snow3g_hash_verify_test_case_1(void)
1901 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1906 test_snow3g_hash_verify_test_case_2(void)
1908 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1912 test_snow3g_hash_verify_test_case_3(void)
1914 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1918 test_snow3g_hash_verify_test_case_4(void)
1920 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
1924 test_snow3g_hash_verify_test_case_5(void)
1926 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
1930 test_snow3g_hash_verify_test_case_6(void)
1932 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
1936 test_kasumi_hash_generate_test_case_1(void)
1938 return test_kasumi_authentication(&kasumi_hash_test_case_1);
1942 test_kasumi_hash_generate_test_case_2(void)
1944 return test_kasumi_authentication(&kasumi_hash_test_case_2);
1948 test_kasumi_hash_generate_test_case_3(void)
1950 return test_kasumi_authentication(&kasumi_hash_test_case_3);
1954 test_kasumi_hash_generate_test_case_4(void)
1956 return test_kasumi_authentication(&kasumi_hash_test_case_4);
1960 test_kasumi_hash_generate_test_case_5(void)
1962 return test_kasumi_authentication(&kasumi_hash_test_case_5);
1966 test_kasumi_hash_verify_test_case_1(void)
1968 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
1972 test_kasumi_hash_verify_test_case_2(void)
1974 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
1978 test_kasumi_hash_verify_test_case_3(void)
1980 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
1984 test_kasumi_hash_verify_test_case_4(void)
1986 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
1990 test_kasumi_hash_verify_test_case_5(void)
1992 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
1996 test_kasumi_encryption(const struct kasumi_test_data *tdata)
1998 struct crypto_testsuite_params *ts_params = &testsuite_params;
1999 struct crypto_unittest_params *ut_params = &unittest_params;
2002 uint8_t *plaintext, *ciphertext;
2003 unsigned plaintext_pad_len;
2004 unsigned plaintext_len;
2006 /* Create KASUMI session */
2007 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2008 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2009 RTE_CRYPTO_CIPHER_KASUMI_F8,
2010 tdata->key.data, tdata->key.len);
2014 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2016 /* Clear mbuf payload */
2017 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2018 rte_pktmbuf_tailroom(ut_params->ibuf));
2020 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2021 /* Append data which is padded to a multiple */
2022 /* of the algorithms block size */
2023 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2024 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2026 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2028 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2030 /* Create KASUMI operation */
2031 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2032 tdata->plaintext.len,
2033 tdata->validCipherOffsetLenInBits.len,
2034 RTE_CRYPTO_CIPHER_KASUMI_F8);
2038 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2040 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2042 ut_params->obuf = ut_params->op->sym->m_dst;
2043 if (ut_params->obuf)
2044 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2047 ciphertext = plaintext;
2049 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2052 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2054 tdata->ciphertext.data,
2055 tdata->validCipherLenInBits.len,
2056 "KASUMI Ciphertext data not as expected");
2061 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2063 struct crypto_testsuite_params *ts_params = &testsuite_params;
2064 struct crypto_unittest_params *ut_params = &unittest_params;
2067 uint8_t *plaintext, *ciphertext;
2068 unsigned plaintext_pad_len;
2069 unsigned plaintext_len;
2071 /* Create KASUMI session */
2072 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2073 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2074 RTE_CRYPTO_CIPHER_KASUMI_F8,
2075 tdata->key.data, tdata->key.len);
2079 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2080 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2082 /* Clear mbuf payload */
2083 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2084 rte_pktmbuf_tailroom(ut_params->ibuf));
2086 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2087 /* Append data which is padded to a multiple */
2088 /* of the algorithms block size */
2089 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2090 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2092 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2093 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2095 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2097 /* Create KASUMI operation */
2098 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2100 tdata->plaintext.len,
2101 tdata->validCipherOffsetLenInBits.len,
2102 RTE_CRYPTO_CIPHER_KASUMI_F8);
2106 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2108 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2110 ut_params->obuf = ut_params->op->sym->m_dst;
2111 if (ut_params->obuf)
2112 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2115 ciphertext = plaintext;
2117 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2120 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2122 tdata->ciphertext.data,
2123 tdata->validCipherLenInBits.len,
2124 "KASUMI Ciphertext data not as expected");
2129 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2131 struct crypto_testsuite_params *ts_params = &testsuite_params;
2132 struct crypto_unittest_params *ut_params = &unittest_params;
2135 uint8_t *ciphertext, *plaintext;
2136 unsigned ciphertext_pad_len;
2137 unsigned ciphertext_len;
2139 /* Create KASUMI session */
2140 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2141 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2142 RTE_CRYPTO_CIPHER_KASUMI_F8,
2143 tdata->key.data, tdata->key.len);
2147 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2148 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2150 /* Clear mbuf payload */
2151 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2152 rte_pktmbuf_tailroom(ut_params->ibuf));
2154 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2155 /* Append data which is padded to a multiple */
2156 /* of the algorithms block size */
2157 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2158 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2159 ciphertext_pad_len);
2160 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2161 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2163 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2165 /* Create KASUMI operation */
2166 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2168 tdata->ciphertext.len,
2169 tdata->validCipherOffsetLenInBits.len,
2170 RTE_CRYPTO_CIPHER_KASUMI_F8);
2174 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2176 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2178 ut_params->obuf = ut_params->op->sym->m_dst;
2179 if (ut_params->obuf)
2180 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2183 plaintext = ciphertext;
2185 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2188 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2190 tdata->plaintext.data,
2191 tdata->validCipherLenInBits.len,
2192 "KASUMI Plaintext data not as expected");
2197 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2199 struct crypto_testsuite_params *ts_params = &testsuite_params;
2200 struct crypto_unittest_params *ut_params = &unittest_params;
2203 uint8_t *ciphertext, *plaintext;
2204 unsigned ciphertext_pad_len;
2205 unsigned ciphertext_len;
2207 /* Create KASUMI session */
2208 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2209 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2210 RTE_CRYPTO_CIPHER_KASUMI_F8,
2211 tdata->key.data, tdata->key.len);
2215 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2217 /* Clear mbuf payload */
2218 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2219 rte_pktmbuf_tailroom(ut_params->ibuf));
2221 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2222 /* Append data which is padded to a multiple */
2223 /* of the algorithms block size */
2224 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2225 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2226 ciphertext_pad_len);
2227 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2229 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2231 /* Create KASUMI operation */
2232 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data,
2234 tdata->ciphertext.len,
2235 tdata->validCipherOffsetLenInBits.len,
2236 RTE_CRYPTO_CIPHER_KASUMI_F8);
2240 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2242 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2244 ut_params->obuf = ut_params->op->sym->m_dst;
2245 if (ut_params->obuf)
2246 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2249 plaintext = ciphertext;
2251 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2254 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2256 tdata->plaintext.data,
2257 tdata->validCipherLenInBits.len,
2258 "KASUMI Plaintext data not as expected");
2263 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2265 struct crypto_testsuite_params *ts_params = &testsuite_params;
2266 struct crypto_unittest_params *ut_params = &unittest_params;
2269 uint8_t *plaintext, *ciphertext;
2270 unsigned plaintext_pad_len;
2271 unsigned plaintext_len;
2273 /* Create SNOW3G session */
2274 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2275 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2276 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2277 tdata->key.data, tdata->key.len);
2281 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2283 /* Clear mbuf payload */
2284 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2285 rte_pktmbuf_tailroom(ut_params->ibuf));
2287 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2288 /* Append data which is padded to a multiple of */
2289 /* the algorithms block size */
2290 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2291 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2293 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2295 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2297 /* Create SNOW3G operation */
2298 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2299 tdata->validCipherLenInBits.len,
2300 tdata->validCipherOffsetLenInBits.len,
2301 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2305 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2307 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2309 ut_params->obuf = ut_params->op->sym->m_dst;
2310 if (ut_params->obuf)
2311 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2314 ciphertext = plaintext;
2316 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2319 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2321 tdata->ciphertext.data,
2322 tdata->validDataLenInBits.len,
2323 "Snow3G Ciphertext data not as expected");
2329 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2331 struct crypto_testsuite_params *ts_params = &testsuite_params;
2332 struct crypto_unittest_params *ut_params = &unittest_params;
2333 uint8_t *plaintext, *ciphertext;
2336 unsigned plaintext_pad_len;
2337 unsigned plaintext_len;
2339 /* Create SNOW3G session */
2340 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2341 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2342 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2343 tdata->key.data, tdata->key.len);
2347 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2348 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2350 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2351 "Failed to allocate input buffer in mempool");
2352 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2353 "Failed to allocate output buffer in mempool");
2355 /* Clear mbuf payload */
2356 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2357 rte_pktmbuf_tailroom(ut_params->ibuf));
2359 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2360 /* Append data which is padded to a multiple of */
2361 /* the algorithms block size */
2362 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2363 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2365 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2366 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2368 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2370 /* Create SNOW3G operation */
2371 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2373 tdata->validCipherLenInBits.len,
2374 tdata->validCipherOffsetLenInBits.len,
2375 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2379 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2381 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2383 ut_params->obuf = ut_params->op->sym->m_dst;
2384 if (ut_params->obuf)
2385 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2388 ciphertext = plaintext;
2390 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2393 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2395 tdata->ciphertext.data,
2396 tdata->validDataLenInBits.len,
2397 "Snow3G Ciphertext data not as expected");
2401 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2403 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2405 uint8_t curr_byte, prev_byte;
2406 uint32_t length_in_bytes = ceil_byte_length(length + offset);
2407 uint8_t lower_byte_mask = (1 << offset) - 1;
2410 prev_byte = buffer[0];
2411 buffer[0] >>= offset;
2413 for (i = 1; i < length_in_bytes; i++) {
2414 curr_byte = buffer[i];
2415 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2416 (curr_byte >> offset);
2417 prev_byte = curr_byte;
2422 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2424 struct crypto_testsuite_params *ts_params = &testsuite_params;
2425 struct crypto_unittest_params *ut_params = &unittest_params;
2426 uint8_t *plaintext, *ciphertext;
2428 uint32_t plaintext_len;
2429 uint32_t plaintext_pad_len;
2430 uint8_t extra_offset = 4;
2431 uint8_t *expected_ciphertext_shifted;
2433 /* Create SNOW3G session */
2434 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2435 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2436 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2437 tdata->key.data, tdata->key.len);
2441 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2442 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2444 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2445 "Failed to allocate input buffer in mempool");
2446 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2447 "Failed to allocate output buffer in mempool");
2449 /* Clear mbuf payload */
2450 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2451 rte_pktmbuf_tailroom(ut_params->ibuf));
2453 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2455 * Append data which is padded to a
2456 * multiple of the algorithms block size
2458 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2460 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2463 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2465 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2466 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2468 #ifdef RTE_APP_TEST_DEBUG
2469 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2471 /* Create SNOW3G operation */
2472 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2474 tdata->validCipherLenInBits.len,
2475 tdata->validCipherOffsetLenInBits.len +
2477 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2481 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2483 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2485 ut_params->obuf = ut_params->op->sym->m_dst;
2486 if (ut_params->obuf)
2487 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2490 ciphertext = plaintext;
2492 #ifdef RTE_APP_TEST_DEBUG
2493 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2496 expected_ciphertext_shifted = rte_malloc(NULL,
2497 ceil_byte_length(plaintext_len + extra_offset), 0);
2499 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2500 "failed to reserve memory for ciphertext shifted\n");
2502 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2503 ceil_byte_length(tdata->ciphertext.len));
2504 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2507 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2509 expected_ciphertext_shifted,
2510 tdata->validDataLenInBits.len,
2512 "Snow3G Ciphertext data not as expected");
2516 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2518 struct crypto_testsuite_params *ts_params = &testsuite_params;
2519 struct crypto_unittest_params *ut_params = &unittest_params;
2523 uint8_t *plaintext, *ciphertext;
2524 unsigned ciphertext_pad_len;
2525 unsigned ciphertext_len;
2527 /* Create SNOW3G session */
2528 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2529 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2530 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2531 tdata->key.data, tdata->key.len);
2535 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2537 /* Clear mbuf payload */
2538 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2539 rte_pktmbuf_tailroom(ut_params->ibuf));
2541 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2542 /* Append data which is padded to a multiple of */
2543 /* the algorithms block size */
2544 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2545 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2546 ciphertext_pad_len);
2547 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2549 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2551 /* Create SNOW3G operation */
2552 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2553 tdata->validCipherLenInBits.len,
2554 tdata->validCipherOffsetLenInBits.len,
2555 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2559 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2561 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2562 ut_params->obuf = ut_params->op->sym->m_dst;
2563 if (ut_params->obuf)
2564 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2567 plaintext = ciphertext;
2569 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2572 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2573 tdata->plaintext.data,
2574 tdata->validDataLenInBits.len,
2575 "Snow3G Plaintext data not as expected");
2579 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2581 struct crypto_testsuite_params *ts_params = &testsuite_params;
2582 struct crypto_unittest_params *ut_params = &unittest_params;
2586 uint8_t *plaintext, *ciphertext;
2587 unsigned ciphertext_pad_len;
2588 unsigned ciphertext_len;
2590 /* Create SNOW3G session */
2591 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2592 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2593 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2594 tdata->key.data, tdata->key.len);
2598 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2599 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2601 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2602 "Failed to allocate input buffer");
2603 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2604 "Failed to allocate output buffer");
2606 /* Clear mbuf payload */
2607 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2608 rte_pktmbuf_tailroom(ut_params->ibuf));
2610 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2611 rte_pktmbuf_tailroom(ut_params->obuf));
2613 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2614 /* Append data which is padded to a multiple of */
2615 /* the algorithms block size */
2616 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2617 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2618 ciphertext_pad_len);
2619 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2620 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2622 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2624 /* Create SNOW3G operation */
2625 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2627 tdata->validCipherLenInBits.len,
2628 tdata->validCipherOffsetLenInBits.len,
2629 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2633 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2635 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2636 ut_params->obuf = ut_params->op->sym->m_dst;
2637 if (ut_params->obuf)
2638 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2641 plaintext = ciphertext;
2643 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2646 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2647 tdata->plaintext.data,
2648 tdata->validDataLenInBits.len,
2649 "Snow3G Plaintext data not as expected");
2654 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2656 struct crypto_testsuite_params *ts_params = &testsuite_params;
2657 struct crypto_unittest_params *ut_params = &unittest_params;
2661 uint8_t *plaintext, *ciphertext;
2662 unsigned plaintext_pad_len;
2663 unsigned plaintext_len;
2665 /* Create SNOW3G session */
2666 retval = create_snow3g_kasumi_cipher_auth_session(ts_params->valid_devs[0],
2667 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2668 RTE_CRYPTO_AUTH_OP_GENERATE,
2669 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2670 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2671 tdata->key.data, tdata->key.len,
2672 tdata->aad.len, tdata->digest.len);
2675 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2677 /* clear mbuf payload */
2678 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2679 rte_pktmbuf_tailroom(ut_params->ibuf));
2681 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2682 /* Append data which is padded to a multiple of */
2683 /* the algorithms block size */
2684 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2685 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2687 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2689 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2691 /* Create SNOW3G operation */
2692 retval = create_snow3g_kasumi_cipher_hash_operation(tdata->digest.data,
2693 tdata->digest.len, tdata->aad.data,
2694 tdata->aad.len, /*tdata->plaintext.len,*/
2695 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2696 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2697 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2698 tdata->iv.data, tdata->iv.len,
2699 tdata->validCipherLenInBits.len,
2700 tdata->validCipherOffsetLenInBits.len,
2701 tdata->validAuthLenInBits.len,
2702 tdata->validAuthOffsetLenInBits.len
2707 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2709 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2710 ut_params->obuf = ut_params->op->sym->m_src;
2711 if (ut_params->obuf)
2712 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2715 ciphertext = plaintext;
2717 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2720 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2722 tdata->ciphertext.data,
2723 tdata->validDataLenInBits.len,
2724 "Snow3G Ciphertext data not as expected");
2726 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2727 + plaintext_pad_len + tdata->aad.len;
2730 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2733 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2734 "Snow3G Generated auth tag not as expected");
2738 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2740 struct crypto_testsuite_params *ts_params = &testsuite_params;
2741 struct crypto_unittest_params *ut_params = &unittest_params;
2745 uint8_t *plaintext, *ciphertext;
2746 unsigned plaintext_pad_len;
2747 unsigned plaintext_len;
2749 /* Create SNOW3G session */
2750 retval = create_snow3g_kasumi_auth_cipher_session(ts_params->valid_devs[0],
2751 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2752 RTE_CRYPTO_AUTH_OP_GENERATE,
2753 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2754 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2755 tdata->key.data, tdata->key.len,
2756 tdata->aad.len, tdata->digest.len);
2760 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2762 /* clear mbuf payload */
2763 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2764 rte_pktmbuf_tailroom(ut_params->ibuf));
2766 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2767 /* Append data which is padded to a multiple of */
2768 /* the algorithms block size */
2769 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2770 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2772 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2774 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2776 /* Create SNOW3G operation */
2777 retval = create_snow3g_kasumi_auth_cipher_operation(
2779 tdata->iv.data, tdata->iv.len,
2780 tdata->aad.data, tdata->aad.len,
2782 tdata->validCipherLenInBits.len,
2783 tdata->validCipherOffsetLenInBits.len,
2784 tdata->validAuthLenInBits.len,
2785 tdata->validAuthOffsetLenInBits.len,
2786 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2787 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
2793 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2795 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2796 ut_params->obuf = ut_params->op->sym->m_src;
2797 if (ut_params->obuf)
2798 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2799 + tdata->aad.len + tdata->iv.len;
2801 ciphertext = plaintext;
2803 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2804 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2805 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2808 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2810 tdata->ciphertext.data,
2811 tdata->validDataLenInBits.len,
2812 "Snow3G Ciphertext data not as expected");
2815 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2818 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2819 "Snow3G Generated auth tag not as expected");
2824 test_kasumi_encryption_test_case_1(void)
2826 return test_kasumi_encryption(&kasumi_test_case_1);
2830 test_kasumi_encryption_test_case_1_oop(void)
2832 return test_kasumi_encryption_oop(&kasumi_test_case_1);
2836 test_kasumi_encryption_test_case_2(void)
2838 return test_kasumi_encryption(&kasumi_test_case_2);
2842 test_kasumi_encryption_test_case_3(void)
2844 return test_kasumi_encryption(&kasumi_test_case_3);
2848 test_kasumi_encryption_test_case_4(void)
2850 return test_kasumi_encryption(&kasumi_test_case_4);
2854 test_kasumi_encryption_test_case_5(void)
2856 return test_kasumi_encryption(&kasumi_test_case_5);
2860 test_kasumi_decryption_test_case_1(void)
2862 return test_kasumi_decryption(&kasumi_test_case_1);
2866 test_kasumi_decryption_test_case_1_oop(void)
2868 return test_kasumi_decryption_oop(&kasumi_test_case_1);
2872 test_kasumi_decryption_test_case_2(void)
2874 return test_kasumi_decryption(&kasumi_test_case_2);
2878 test_kasumi_decryption_test_case_3(void)
2880 return test_kasumi_decryption(&kasumi_test_case_3);
2884 test_kasumi_decryption_test_case_4(void)
2886 return test_kasumi_decryption(&kasumi_test_case_4);
2890 test_kasumi_decryption_test_case_5(void)
2892 return test_kasumi_decryption(&kasumi_test_case_5);
2895 test_snow3g_encryption_test_case_1(void)
2897 return test_snow3g_encryption(&snow3g_test_case_1);
2901 test_snow3g_encryption_test_case_1_oop(void)
2903 return test_snow3g_encryption_oop(&snow3g_test_case_1);
2907 test_snow3g_encryption_test_case_1_offset_oop(void)
2909 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
2913 test_snow3g_encryption_test_case_2(void)
2915 return test_snow3g_encryption(&snow3g_test_case_2);
2919 test_snow3g_encryption_test_case_3(void)
2921 return test_snow3g_encryption(&snow3g_test_case_3);
2925 test_snow3g_encryption_test_case_4(void)
2927 return test_snow3g_encryption(&snow3g_test_case_4);
2931 test_snow3g_encryption_test_case_5(void)
2933 return test_snow3g_encryption(&snow3g_test_case_5);
2937 test_snow3g_decryption_test_case_1(void)
2939 return test_snow3g_decryption(&snow3g_test_case_1);
2943 test_snow3g_decryption_test_case_1_oop(void)
2945 return test_snow3g_decryption_oop(&snow3g_test_case_1);
2949 test_snow3g_decryption_test_case_2(void)
2951 return test_snow3g_decryption(&snow3g_test_case_2);
2955 test_snow3g_decryption_test_case_3(void)
2957 return test_snow3g_decryption(&snow3g_test_case_3);
2961 test_snow3g_decryption_test_case_4(void)
2963 return test_snow3g_decryption(&snow3g_test_case_4);
2967 test_snow3g_decryption_test_case_5(void)
2969 return test_snow3g_decryption(&snow3g_test_case_5);
2972 test_snow3g_authenticated_encryption_test_case_1(void)
2974 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2978 test_snow3g_encrypted_authentication_test_case_1(void)
2980 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2983 /* ***** AES-GCM Tests ***** */
2986 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2987 const uint8_t *key, const uint8_t key_len,
2988 const uint8_t aad_len, const uint8_t auth_len)
2990 uint8_t cipher_key[key_len];
2992 struct crypto_unittest_params *ut_params = &unittest_params;
2995 memcpy(cipher_key, key, key_len);
2997 /* Setup Cipher Parameters */
2998 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2999 ut_params->cipher_xform.next = NULL;
3001 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3002 ut_params->cipher_xform.cipher.op = op;
3003 ut_params->cipher_xform.cipher.key.data = cipher_key;
3004 ut_params->cipher_xform.cipher.key.length = key_len;
3006 TEST_HEXDUMP(stdout, "key:", key, key_len);
3008 /* Setup Authentication Parameters */
3009 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3010 ut_params->auth_xform.next = NULL;
3012 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3014 ut_params->auth_xform.auth.digest_length = auth_len;
3015 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3016 ut_params->auth_xform.auth.key.length = 0;
3017 ut_params->auth_xform.auth.key.data = NULL;
3019 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3020 ut_params->cipher_xform.next = &ut_params->auth_xform;
3022 /* Create Crypto session*/
3023 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3024 &ut_params->cipher_xform);
3025 } else {/* Create Crypto session*/
3026 ut_params->auth_xform.next = &ut_params->cipher_xform;
3027 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3028 &ut_params->auth_xform);
3031 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3037 create_gcm_operation(enum rte_crypto_cipher_operation op,
3038 const uint8_t *auth_tag, const unsigned auth_tag_len,
3039 const uint8_t *iv, const unsigned iv_len,
3040 const uint8_t *aad, const unsigned aad_len,
3041 const unsigned data_len, unsigned data_pad_len)
3043 struct crypto_testsuite_params *ts_params = &testsuite_params;
3044 struct crypto_unittest_params *ut_params = &unittest_params;
3046 unsigned iv_pad_len = 0, aad_buffer_len;
3048 /* Generate Crypto op data structure */
3049 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3050 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3051 TEST_ASSERT_NOT_NULL(ut_params->op,
3052 "Failed to allocate symmetric crypto operation struct");
3054 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3058 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3059 ut_params->ibuf, auth_tag_len);
3060 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3061 "no room to append digest");
3062 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3063 ut_params->ibuf, data_pad_len);
3064 sym_op->auth.digest.length = auth_tag_len;
3066 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3067 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3068 TEST_HEXDUMP(stdout, "digest:",
3069 sym_op->auth.digest.data,
3070 sym_op->auth.digest.length);
3074 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3076 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3077 ut_params->ibuf, iv_pad_len);
3078 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3080 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3081 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3082 sym_op->cipher.iv.length = iv_pad_len;
3084 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3088 sym_op->cipher.iv.data[15] = 1;
3091 * Always allocate the aad up to the block size.
3092 * The cryptodev API calls out -
3093 * - the array must be big enough to hold the AAD, plus any
3094 * space to round this up to the nearest multiple of the
3095 * block size (16 bytes).
3097 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3099 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3100 ut_params->ibuf, aad_buffer_len);
3101 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3102 "no room to prepend aad");
3103 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3105 sym_op->auth.aad.length = aad_len;
3107 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3108 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3110 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3111 TEST_HEXDUMP(stdout, "aad:",
3112 sym_op->auth.aad.data, aad_len);
3114 sym_op->cipher.data.length = data_len;
3115 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3117 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3118 sym_op->auth.data.length = data_len;
3124 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3126 struct crypto_testsuite_params *ts_params = &testsuite_params;
3127 struct crypto_unittest_params *ut_params = &unittest_params;
3131 uint8_t *plaintext, *ciphertext, *auth_tag;
3132 uint16_t plaintext_pad_len;
3134 /* Create GCM session */
3135 retval = create_gcm_session(ts_params->valid_devs[0],
3136 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3137 tdata->key.data, tdata->key.len,
3138 tdata->aad.len, tdata->auth_tag.len);
3143 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3145 /* clear mbuf payload */
3146 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3147 rte_pktmbuf_tailroom(ut_params->ibuf));
3150 * Append data which is padded to a multiple
3151 * of the algorithms block size
3153 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3155 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3157 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3159 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3161 /* Create GCM opertaion */
3162 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3163 tdata->auth_tag.data, tdata->auth_tag.len,
3164 tdata->iv.data, tdata->iv.len,
3165 tdata->aad.data, tdata->aad.len,
3166 tdata->plaintext.len, plaintext_pad_len);
3170 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3172 ut_params->op->sym->m_src = ut_params->ibuf;
3174 /* Process crypto operation */
3175 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3176 ut_params->op), "failed to process sym crypto op");
3178 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3179 "crypto op processing failed");
3181 if (ut_params->op->sym->m_dst) {
3182 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3184 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3185 uint8_t *, plaintext_pad_len);
3187 ciphertext = plaintext;
3188 auth_tag = plaintext + plaintext_pad_len;
3191 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3192 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3195 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3197 tdata->ciphertext.data,
3198 tdata->ciphertext.len,
3199 "GCM Ciphertext data not as expected");
3201 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3203 tdata->auth_tag.data,
3204 tdata->auth_tag.len,
3205 "GCM Generated auth tag not as expected");
3212 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3214 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3218 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3220 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3224 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3226 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3230 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3232 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3236 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3238 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3242 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3244 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3248 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3250 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3254 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3256 struct crypto_testsuite_params *ts_params = &testsuite_params;
3257 struct crypto_unittest_params *ut_params = &unittest_params;
3261 uint8_t *plaintext, *ciphertext;
3262 uint16_t ciphertext_pad_len;
3264 /* Create GCM session */
3265 retval = create_gcm_session(ts_params->valid_devs[0],
3266 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3267 tdata->key.data, tdata->key.len,
3268 tdata->aad.len, tdata->auth_tag.len);
3273 /* alloc mbuf and set payload */
3274 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3276 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3277 rte_pktmbuf_tailroom(ut_params->ibuf));
3279 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3281 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3282 ciphertext_pad_len);
3283 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3285 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3287 /* Create GCM opertaion */
3288 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3289 tdata->auth_tag.data, tdata->auth_tag.len,
3290 tdata->iv.data, tdata->iv.len,
3291 tdata->aad.data, tdata->aad.len,
3292 tdata->ciphertext.len, ciphertext_pad_len);
3297 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3299 ut_params->op->sym->m_src = ut_params->ibuf;
3301 /* Process crypto operation */
3302 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3303 ut_params->op), "failed to process sym crypto op");
3305 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3306 "crypto op processing failed");
3308 if (ut_params->op->sym->m_dst)
3309 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3312 plaintext = ciphertext;
3314 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3317 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3319 tdata->plaintext.data,
3320 tdata->plaintext.len,
3321 "GCM plaintext data not as expected");
3323 TEST_ASSERT_EQUAL(ut_params->op->status,
3324 RTE_CRYPTO_OP_STATUS_SUCCESS,
3325 "GCM authentication failed");
3330 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3332 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3336 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3338 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3342 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3344 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3348 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3350 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3354 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3356 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3360 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3362 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3366 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3368 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3374 struct crypto_testsuite_params *ts_params = &testsuite_params;
3375 struct rte_cryptodev_stats stats;
3376 struct rte_cryptodev *dev;
3377 cryptodev_stats_get_t temp_pfn;
3379 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3380 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3381 &stats) == -ENODEV),
3382 "rte_cryptodev_stats_get invalid dev failed");
3383 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3384 "rte_cryptodev_stats_get invalid Param failed");
3385 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3386 temp_pfn = dev->dev_ops->stats_get;
3387 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3388 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3390 "rte_cryptodev_stats_get invalid Param failed");
3391 dev->dev_ops->stats_get = temp_pfn;
3393 /* Test expected values */
3395 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3397 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3399 "rte_cryptodev_stats_get failed");
3400 TEST_ASSERT((stats.enqueued_count == 1),
3401 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3402 TEST_ASSERT((stats.dequeued_count == 1),
3403 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3404 TEST_ASSERT((stats.enqueue_err_count == 0),
3405 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3406 TEST_ASSERT((stats.dequeue_err_count == 0),
3407 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3409 /* invalid device but should ignore and not reset device stats*/
3410 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3411 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3413 "rte_cryptodev_stats_get failed");
3414 TEST_ASSERT((stats.enqueued_count == 1),
3415 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3417 /* check that a valid reset clears stats */
3418 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3419 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3421 "rte_cryptodev_stats_get failed");
3422 TEST_ASSERT((stats.enqueued_count == 0),
3423 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3424 TEST_ASSERT((stats.dequeued_count == 0),
3425 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3427 return TEST_SUCCESS;
3432 test_multi_session(void)
3434 struct crypto_testsuite_params *ts_params = &testsuite_params;
3435 struct crypto_unittest_params *ut_params = &unittest_params;
3437 struct rte_cryptodev_info dev_info;
3438 struct rte_cryptodev_sym_session **sessions;
3442 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3445 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3447 sessions = rte_malloc(NULL,
3448 (sizeof(struct rte_cryptodev_sym_session *) *
3449 dev_info.sym.max_nb_sessions) + 1, 0);
3451 /* Create multiple crypto sessions*/
3452 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3453 sessions[i] = rte_cryptodev_sym_session_create(
3454 ts_params->valid_devs[0],
3455 &ut_params->auth_xform);
3456 TEST_ASSERT_NOT_NULL(sessions[i],
3457 "Session creation failed at session number %u",
3460 /* Attempt to send a request on each session */
3461 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3462 sessions[i], ut_params, ts_params),
3463 "Failed to perform decrypt on request "
3465 /* free crypto operation structure */
3467 rte_crypto_op_free(ut_params->op);
3470 * free mbuf - both obuf and ibuf are usually the same,
3471 * but rte copes even if we call free twice
3473 if (ut_params->obuf) {
3474 rte_pktmbuf_free(ut_params->obuf);
3475 ut_params->obuf = 0;
3479 /* Next session create should fail */
3480 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3481 &ut_params->auth_xform);
3482 TEST_ASSERT_NULL(sessions[i],
3483 "Session creation succeeded unexpectedly!");
3485 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3486 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3491 return TEST_SUCCESS;
3495 test_null_cipher_only_operation(void)
3497 struct crypto_testsuite_params *ts_params = &testsuite_params;
3498 struct crypto_unittest_params *ut_params = &unittest_params;
3500 /* Generate test mbuf data and space for digest */
3501 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3502 catch_22_quote, QUOTE_512_BYTES, 0);
3504 /* Setup Cipher Parameters */
3505 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3506 ut_params->cipher_xform.next = NULL;
3508 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3509 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3511 /* Create Crypto session*/
3512 ut_params->sess = rte_cryptodev_sym_session_create(
3513 ts_params->valid_devs[0], &ut_params->cipher_xform);
3514 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3516 /* Generate Crypto op data structure */
3517 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3518 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3519 TEST_ASSERT_NOT_NULL(ut_params->op,
3520 "Failed to allocate symmetric crypto operation struct");
3522 /* Set crypto operation data parameters */
3523 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3525 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3527 /* set crypto operation source mbuf */
3528 sym_op->m_src = ut_params->ibuf;
3530 sym_op->cipher.data.offset = 0;
3531 sym_op->cipher.data.length = QUOTE_512_BYTES;
3533 /* Process crypto operation */
3534 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3536 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3538 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3539 "crypto operation processing failed");
3542 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3543 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3546 "Ciphertext data not as expected");
3548 return TEST_SUCCESS;
3552 test_null_auth_only_operation(void)
3554 struct crypto_testsuite_params *ts_params = &testsuite_params;
3555 struct crypto_unittest_params *ut_params = &unittest_params;
3557 /* Generate test mbuf data and space for digest */
3558 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3559 catch_22_quote, QUOTE_512_BYTES, 0);
3561 /* Setup HMAC Parameters */
3562 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3563 ut_params->auth_xform.next = NULL;
3565 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3566 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3568 /* Create Crypto session*/
3569 ut_params->sess = rte_cryptodev_sym_session_create(
3570 ts_params->valid_devs[0], &ut_params->auth_xform);
3571 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3573 /* Generate Crypto op data structure */
3574 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3575 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3576 TEST_ASSERT_NOT_NULL(ut_params->op,
3577 "Failed to allocate symmetric crypto operation struct");
3579 /* Set crypto operation data parameters */
3580 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3582 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3584 sym_op->m_src = ut_params->ibuf;
3586 sym_op->auth.data.offset = 0;
3587 sym_op->auth.data.length = QUOTE_512_BYTES;
3589 /* Process crypto operation */
3590 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3592 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3594 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3595 "crypto operation processing failed");
3597 return TEST_SUCCESS;
3601 test_null_cipher_auth_operation(void)
3603 struct crypto_testsuite_params *ts_params = &testsuite_params;
3604 struct crypto_unittest_params *ut_params = &unittest_params;
3606 /* Generate test mbuf data and space for digest */
3607 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3608 catch_22_quote, QUOTE_512_BYTES, 0);
3610 /* Setup Cipher Parameters */
3611 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3612 ut_params->cipher_xform.next = &ut_params->auth_xform;
3614 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3615 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3617 /* Setup HMAC Parameters */
3618 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3619 ut_params->auth_xform.next = NULL;
3621 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3622 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3624 /* Create Crypto session*/
3625 ut_params->sess = rte_cryptodev_sym_session_create(
3626 ts_params->valid_devs[0], &ut_params->cipher_xform);
3627 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3629 /* Generate Crypto op data structure */
3630 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3631 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3632 TEST_ASSERT_NOT_NULL(ut_params->op,
3633 "Failed to allocate symmetric crypto operation struct");
3635 /* Set crypto operation data parameters */
3636 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3638 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3640 sym_op->m_src = ut_params->ibuf;
3642 sym_op->cipher.data.offset = 0;
3643 sym_op->cipher.data.length = QUOTE_512_BYTES;
3645 sym_op->auth.data.offset = 0;
3646 sym_op->auth.data.length = QUOTE_512_BYTES;
3648 /* Process crypto operation */
3649 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3651 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3653 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3654 "crypto operation processing failed");
3657 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3658 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3661 "Ciphertext data not as expected");
3663 return TEST_SUCCESS;
3667 test_null_auth_cipher_operation(void)
3669 struct crypto_testsuite_params *ts_params = &testsuite_params;
3670 struct crypto_unittest_params *ut_params = &unittest_params;
3672 /* Generate test mbuf data and space for digest */
3673 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3674 catch_22_quote, QUOTE_512_BYTES, 0);
3676 /* Setup Cipher Parameters */
3677 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3678 ut_params->cipher_xform.next = NULL;
3680 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3681 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3683 /* Setup HMAC Parameters */
3684 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3685 ut_params->auth_xform.next = &ut_params->cipher_xform;
3687 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3688 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3690 /* Create Crypto session*/
3691 ut_params->sess = rte_cryptodev_sym_session_create(
3692 ts_params->valid_devs[0], &ut_params->cipher_xform);
3693 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3695 /* Generate Crypto op data structure */
3696 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3697 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3698 TEST_ASSERT_NOT_NULL(ut_params->op,
3699 "Failed to allocate symmetric crypto operation struct");
3701 /* Set crypto operation data parameters */
3702 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3704 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3706 sym_op->m_src = ut_params->ibuf;
3708 sym_op->cipher.data.offset = 0;
3709 sym_op->cipher.data.length = QUOTE_512_BYTES;
3711 sym_op->auth.data.offset = 0;
3712 sym_op->auth.data.length = QUOTE_512_BYTES;
3714 /* Process crypto operation */
3715 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3717 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3719 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3720 "crypto operation processing failed");
3723 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3724 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3727 "Ciphertext data not as expected");
3729 return TEST_SUCCESS;
3734 test_null_invalid_operation(void)
3736 struct crypto_testsuite_params *ts_params = &testsuite_params;
3737 struct crypto_unittest_params *ut_params = &unittest_params;
3739 /* Setup Cipher Parameters */
3740 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3741 ut_params->cipher_xform.next = NULL;
3743 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3744 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3746 /* Create Crypto session*/
3747 ut_params->sess = rte_cryptodev_sym_session_create(
3748 ts_params->valid_devs[0], &ut_params->cipher_xform);
3749 TEST_ASSERT_NULL(ut_params->sess,
3750 "Session creation succeeded unexpectedly");
3753 /* Setup HMAC Parameters */
3754 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3755 ut_params->auth_xform.next = NULL;
3757 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3758 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3760 /* Create Crypto session*/
3761 ut_params->sess = rte_cryptodev_sym_session_create(
3762 ts_params->valid_devs[0], &ut_params->auth_xform);
3763 TEST_ASSERT_NULL(ut_params->sess,
3764 "Session creation succeeded unexpectedly");
3766 return TEST_SUCCESS;
3770 #define NULL_BURST_LENGTH (32)
3773 test_null_burst_operation(void)
3775 struct crypto_testsuite_params *ts_params = &testsuite_params;
3776 struct crypto_unittest_params *ut_params = &unittest_params;
3778 unsigned i, burst_len = NULL_BURST_LENGTH;
3780 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3781 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3783 /* Setup Cipher Parameters */
3784 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3785 ut_params->cipher_xform.next = &ut_params->auth_xform;
3787 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3788 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3790 /* Setup HMAC Parameters */
3791 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3792 ut_params->auth_xform.next = NULL;
3794 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3795 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3797 /* Create Crypto session*/
3798 ut_params->sess = rte_cryptodev_sym_session_create(
3799 ts_params->valid_devs[0], &ut_params->cipher_xform);
3800 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3802 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3803 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3804 burst_len, "failed to generate burst of crypto ops");
3806 /* Generate an operation for each mbuf in burst */
3807 for (i = 0; i < burst_len; i++) {
3808 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3810 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3812 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3816 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3818 burst[i]->sym->m_src = m;
3821 /* Process crypto operation */
3822 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3823 0, burst, burst_len),
3825 "Error enqueuing burst");
3827 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3828 0, burst_dequeued, burst_len),
3830 "Error dequeuing burst");
3833 for (i = 0; i < burst_len; i++) {
3835 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3836 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3838 "data not as expected");
3840 rte_pktmbuf_free(burst[i]->sym->m_src);
3841 rte_crypto_op_free(burst[i]);
3844 return TEST_SUCCESS;
3850 static struct unit_test_suite cryptodev_qat_testsuite = {
3851 .suite_name = "Crypto QAT Unit Test Suite",
3852 .setup = testsuite_setup,
3853 .teardown = testsuite_teardown,
3854 .unit_test_cases = {
3855 TEST_CASE_ST(ut_setup, ut_teardown,
3856 test_device_configure_invalid_dev_id),
3857 TEST_CASE_ST(ut_setup, ut_teardown,
3858 test_device_configure_invalid_queue_pair_ids),
3859 TEST_CASE_ST(ut_setup, ut_teardown,
3860 test_queue_pair_descriptor_setup),
3861 TEST_CASE_ST(ut_setup, ut_teardown,
3862 test_multi_session),
3864 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3865 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3867 /** AES GCM Authenticated Encryption */
3868 TEST_CASE_ST(ut_setup, ut_teardown,
3869 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3870 TEST_CASE_ST(ut_setup, ut_teardown,
3871 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3872 TEST_CASE_ST(ut_setup, ut_teardown,
3873 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3874 TEST_CASE_ST(ut_setup, ut_teardown,
3875 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3876 TEST_CASE_ST(ut_setup, ut_teardown,
3877 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3878 TEST_CASE_ST(ut_setup, ut_teardown,
3879 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3880 TEST_CASE_ST(ut_setup, ut_teardown,
3881 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3883 /** AES GCM Authenticated Decryption */
3884 TEST_CASE_ST(ut_setup, ut_teardown,
3885 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3886 TEST_CASE_ST(ut_setup, ut_teardown,
3887 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3888 TEST_CASE_ST(ut_setup, ut_teardown,
3889 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3890 TEST_CASE_ST(ut_setup, ut_teardown,
3891 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3892 TEST_CASE_ST(ut_setup, ut_teardown,
3893 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3894 TEST_CASE_ST(ut_setup, ut_teardown,
3895 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3896 TEST_CASE_ST(ut_setup, ut_teardown,
3897 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3899 /** Snow3G encrypt only (UEA2) */
3900 TEST_CASE_ST(ut_setup, ut_teardown,
3901 test_snow3g_encryption_test_case_1),
3902 TEST_CASE_ST(ut_setup, ut_teardown,
3903 test_snow3g_encryption_test_case_2),
3904 TEST_CASE_ST(ut_setup, ut_teardown,
3905 test_snow3g_encryption_test_case_3),
3906 TEST_CASE_ST(ut_setup, ut_teardown,
3907 test_snow3g_encryption_test_case_4),
3908 TEST_CASE_ST(ut_setup, ut_teardown,
3909 test_snow3g_encryption_test_case_5),
3911 TEST_CASE_ST(ut_setup, ut_teardown,
3912 test_snow3g_encryption_test_case_1_oop),
3913 TEST_CASE_ST(ut_setup, ut_teardown,
3914 test_snow3g_decryption_test_case_1_oop),
3916 /** Snow3G decrypt only (UEA2) */
3917 TEST_CASE_ST(ut_setup, ut_teardown,
3918 test_snow3g_decryption_test_case_1),
3919 TEST_CASE_ST(ut_setup, ut_teardown,
3920 test_snow3g_decryption_test_case_2),
3921 TEST_CASE_ST(ut_setup, ut_teardown,
3922 test_snow3g_decryption_test_case_3),
3923 TEST_CASE_ST(ut_setup, ut_teardown,
3924 test_snow3g_decryption_test_case_4),
3925 TEST_CASE_ST(ut_setup, ut_teardown,
3926 test_snow3g_decryption_test_case_5),
3927 TEST_CASE_ST(ut_setup, ut_teardown,
3928 test_snow3g_hash_generate_test_case_1),
3929 TEST_CASE_ST(ut_setup, ut_teardown,
3930 test_snow3g_hash_generate_test_case_2),
3931 TEST_CASE_ST(ut_setup, ut_teardown,
3932 test_snow3g_hash_generate_test_case_3),
3933 TEST_CASE_ST(ut_setup, ut_teardown,
3934 test_snow3g_hash_verify_test_case_1),
3935 TEST_CASE_ST(ut_setup, ut_teardown,
3936 test_snow3g_hash_verify_test_case_2),
3937 TEST_CASE_ST(ut_setup, ut_teardown,
3938 test_snow3g_hash_verify_test_case_3),
3939 TEST_CASE_ST(ut_setup, ut_teardown,
3940 test_snow3g_authenticated_encryption_test_case_1),
3941 TEST_CASE_ST(ut_setup, ut_teardown,
3942 test_snow3g_encrypted_authentication_test_case_1),
3943 TEST_CASES_END() /**< NULL terminate unit test array */
3947 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3948 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3949 .setup = testsuite_setup,
3950 .teardown = testsuite_teardown,
3951 .unit_test_cases = {
3952 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3954 TEST_CASES_END() /**< NULL terminate unit test array */
3958 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
3959 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3960 .setup = testsuite_setup,
3961 .teardown = testsuite_teardown,
3962 .unit_test_cases = {
3963 /** AES GCM Authenticated Encryption */
3964 TEST_CASE_ST(ut_setup, ut_teardown,
3965 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3966 TEST_CASE_ST(ut_setup, ut_teardown,
3967 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3968 TEST_CASE_ST(ut_setup, ut_teardown,
3969 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3970 TEST_CASE_ST(ut_setup, ut_teardown,
3971 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3972 TEST_CASE_ST(ut_setup, ut_teardown,
3973 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3974 TEST_CASE_ST(ut_setup, ut_teardown,
3975 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3976 TEST_CASE_ST(ut_setup, ut_teardown,
3977 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3979 /** AES GCM Authenticated Decryption */
3980 TEST_CASE_ST(ut_setup, ut_teardown,
3981 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3982 TEST_CASE_ST(ut_setup, ut_teardown,
3983 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3984 TEST_CASE_ST(ut_setup, ut_teardown,
3985 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3986 TEST_CASE_ST(ut_setup, ut_teardown,
3987 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3988 TEST_CASE_ST(ut_setup, ut_teardown,
3989 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3990 TEST_CASE_ST(ut_setup, ut_teardown,
3991 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3992 TEST_CASE_ST(ut_setup, ut_teardown,
3993 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3995 TEST_CASES_END() /**< NULL terminate unit test array */
3999 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
4000 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4001 .setup = testsuite_setup,
4002 .teardown = testsuite_teardown,
4003 .unit_test_cases = {
4004 /** KASUMI encrypt only (UEA1) */
4005 TEST_CASE_ST(ut_setup, ut_teardown,
4006 test_kasumi_encryption_test_case_1),
4007 TEST_CASE_ST(ut_setup, ut_teardown,
4008 test_kasumi_encryption_test_case_2),
4009 TEST_CASE_ST(ut_setup, ut_teardown,
4010 test_kasumi_encryption_test_case_3),
4011 TEST_CASE_ST(ut_setup, ut_teardown,
4012 test_kasumi_encryption_test_case_4),
4013 TEST_CASE_ST(ut_setup, ut_teardown,
4014 test_kasumi_encryption_test_case_5),
4015 /** KASUMI decrypt only (UEA1) */
4016 TEST_CASE_ST(ut_setup, ut_teardown,
4017 test_kasumi_decryption_test_case_1),
4018 TEST_CASE_ST(ut_setup, ut_teardown,
4019 test_kasumi_decryption_test_case_2),
4020 TEST_CASE_ST(ut_setup, ut_teardown,
4021 test_kasumi_decryption_test_case_3),
4022 TEST_CASE_ST(ut_setup, ut_teardown,
4023 test_kasumi_decryption_test_case_4),
4024 TEST_CASE_ST(ut_setup, ut_teardown,
4025 test_kasumi_decryption_test_case_5),
4027 TEST_CASE_ST(ut_setup, ut_teardown,
4028 test_kasumi_encryption_test_case_1_oop),
4029 TEST_CASE_ST(ut_setup, ut_teardown,
4030 test_kasumi_decryption_test_case_1_oop),
4032 /** KASUMI hash only (UIA1) */
4033 TEST_CASE_ST(ut_setup, ut_teardown,
4034 test_kasumi_hash_generate_test_case_1),
4035 TEST_CASE_ST(ut_setup, ut_teardown,
4036 test_kasumi_hash_generate_test_case_2),
4037 TEST_CASE_ST(ut_setup, ut_teardown,
4038 test_kasumi_hash_generate_test_case_3),
4039 TEST_CASE_ST(ut_setup, ut_teardown,
4040 test_kasumi_hash_generate_test_case_4),
4041 TEST_CASE_ST(ut_setup, ut_teardown,
4042 test_kasumi_hash_generate_test_case_5),
4043 TEST_CASE_ST(ut_setup, ut_teardown,
4044 test_kasumi_hash_verify_test_case_1),
4045 TEST_CASE_ST(ut_setup, ut_teardown,
4046 test_kasumi_hash_verify_test_case_2),
4047 TEST_CASE_ST(ut_setup, ut_teardown,
4048 test_kasumi_hash_verify_test_case_3),
4049 TEST_CASE_ST(ut_setup, ut_teardown,
4050 test_kasumi_hash_verify_test_case_4),
4051 TEST_CASE_ST(ut_setup, ut_teardown,
4052 test_kasumi_hash_verify_test_case_5),
4054 TEST_CASES_END() /**< NULL terminate unit test array */
4057 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4058 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4059 .setup = testsuite_setup,
4060 .teardown = testsuite_teardown,
4061 .unit_test_cases = {
4062 /** Snow3G encrypt only (UEA2) */
4063 TEST_CASE_ST(ut_setup, ut_teardown,
4064 test_snow3g_encryption_test_case_1),
4065 TEST_CASE_ST(ut_setup, ut_teardown,
4066 test_snow3g_encryption_test_case_2),
4067 TEST_CASE_ST(ut_setup, ut_teardown,
4068 test_snow3g_encryption_test_case_3),
4069 TEST_CASE_ST(ut_setup, ut_teardown,
4070 test_snow3g_encryption_test_case_4),
4071 TEST_CASE_ST(ut_setup, ut_teardown,
4072 test_snow3g_encryption_test_case_5),
4074 TEST_CASE_ST(ut_setup, ut_teardown,
4075 test_snow3g_encryption_test_case_1_oop),
4076 TEST_CASE_ST(ut_setup, ut_teardown,
4077 test_snow3g_decryption_test_case_1_oop),
4079 TEST_CASE_ST(ut_setup, ut_teardown,
4080 test_snow3g_encryption_test_case_1_offset_oop),
4082 /** Snow3G decrypt only (UEA2) */
4083 TEST_CASE_ST(ut_setup, ut_teardown,
4084 test_snow3g_decryption_test_case_1),
4085 TEST_CASE_ST(ut_setup, ut_teardown,
4086 test_snow3g_decryption_test_case_2),
4087 TEST_CASE_ST(ut_setup, ut_teardown,
4088 test_snow3g_decryption_test_case_3),
4089 TEST_CASE_ST(ut_setup, ut_teardown,
4090 test_snow3g_decryption_test_case_4),
4091 TEST_CASE_ST(ut_setup, ut_teardown,
4092 test_snow3g_decryption_test_case_5),
4093 TEST_CASE_ST(ut_setup, ut_teardown,
4094 test_snow3g_hash_generate_test_case_1),
4095 TEST_CASE_ST(ut_setup, ut_teardown,
4096 test_snow3g_hash_generate_test_case_2),
4097 TEST_CASE_ST(ut_setup, ut_teardown,
4098 test_snow3g_hash_generate_test_case_3),
4099 /* Tests with buffers which length is not byte-aligned */
4100 TEST_CASE_ST(ut_setup, ut_teardown,
4101 test_snow3g_hash_generate_test_case_4),
4102 TEST_CASE_ST(ut_setup, ut_teardown,
4103 test_snow3g_hash_generate_test_case_5),
4104 TEST_CASE_ST(ut_setup, ut_teardown,
4105 test_snow3g_hash_generate_test_case_6),
4106 TEST_CASE_ST(ut_setup, ut_teardown,
4107 test_snow3g_hash_verify_test_case_1),
4108 TEST_CASE_ST(ut_setup, ut_teardown,
4109 test_snow3g_hash_verify_test_case_2),
4110 TEST_CASE_ST(ut_setup, ut_teardown,
4111 test_snow3g_hash_verify_test_case_3),
4112 /* Tests with buffers which length is not byte-aligned */
4113 TEST_CASE_ST(ut_setup, ut_teardown,
4114 test_snow3g_hash_verify_test_case_4),
4115 TEST_CASE_ST(ut_setup, ut_teardown,
4116 test_snow3g_hash_verify_test_case_5),
4117 TEST_CASE_ST(ut_setup, ut_teardown,
4118 test_snow3g_hash_verify_test_case_6),
4119 TEST_CASE_ST(ut_setup, ut_teardown,
4120 test_snow3g_authenticated_encryption_test_case_1),
4121 TEST_CASE_ST(ut_setup, ut_teardown,
4122 test_snow3g_encrypted_authentication_test_case_1),
4124 TEST_CASES_END() /**< NULL terminate unit test array */
4128 static struct unit_test_suite cryptodev_null_testsuite = {
4129 .suite_name = "Crypto Device NULL Unit Test Suite",
4130 .setup = testsuite_setup,
4131 .teardown = testsuite_teardown,
4132 .unit_test_cases = {
4133 TEST_CASE_ST(ut_setup, ut_teardown,
4134 test_null_auth_only_operation),
4135 TEST_CASE_ST(ut_setup, ut_teardown,
4136 test_null_cipher_only_operation),
4137 TEST_CASE_ST(ut_setup, ut_teardown,
4138 test_null_cipher_auth_operation),
4139 TEST_CASE_ST(ut_setup, ut_teardown,
4140 test_null_auth_cipher_operation),
4141 TEST_CASE_ST(ut_setup, ut_teardown,
4142 test_null_invalid_operation),
4143 TEST_CASE_ST(ut_setup, ut_teardown,
4144 test_null_burst_operation),
4146 TEST_CASES_END() /**< NULL terminate unit test array */
4151 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4153 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4154 return unit_test_suite_runner(&cryptodev_qat_testsuite);
4156 static struct test_command cryptodev_qat_cmd = {
4157 .command = "cryptodev_qat_autotest",
4158 .callback = test_cryptodev_qat,
4162 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4164 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4166 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4169 static struct test_command cryptodev_aesni_mb_cmd = {
4170 .command = "cryptodev_aesni_mb_autotest",
4171 .callback = test_cryptodev_aesni_mb,
4175 test_cryptodev_aesni_gcm(void)
4177 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4179 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4182 static struct test_command cryptodev_aesni_gcm_cmd = {
4183 .command = "cryptodev_aesni_gcm_autotest",
4184 .callback = test_cryptodev_aesni_gcm,
4188 test_cryptodev_null(void)
4190 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4192 return unit_test_suite_runner(&cryptodev_null_testsuite);
4195 static struct test_command cryptodev_null_cmd = {
4196 .command = "cryptodev_null_autotest",
4197 .callback = test_cryptodev_null,
4201 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4203 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4205 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4208 static struct test_command cryptodev_sw_snow3g_cmd = {
4209 .command = "cryptodev_sw_snow3g_autotest",
4210 .callback = test_cryptodev_sw_snow3g,
4214 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
4216 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
4218 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
4221 static struct test_command cryptodev_sw_kasumi_cmd = {
4222 .command = "cryptodev_sw_kasumi_autotest",
4223 .callback = test_cryptodev_sw_kasumi,
4226 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4227 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4228 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4229 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4230 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);
4231 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_cmd);