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"
45 #include "test_cryptodev_snow3g_test_vectors.h"
46 #include "test_cryptodev_snow3g_hash_test_vectors.h"
47 #include "test_cryptodev_gcm_test_vectors.h"
49 static enum rte_cryptodev_type gbl_cryptodev_type;
51 struct crypto_testsuite_params {
52 struct rte_mempool *mbuf_pool;
53 struct rte_mempool *op_mpool;
54 struct rte_cryptodev_config conf;
55 struct rte_cryptodev_qp_conf qp_conf;
57 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
58 uint8_t valid_dev_count;
61 struct crypto_unittest_params {
62 struct rte_crypto_sym_xform cipher_xform;
63 struct rte_crypto_sym_xform auth_xform;
65 struct rte_cryptodev_sym_session *sess;
67 struct rte_crypto_op *op;
69 struct rte_mbuf *obuf, *ibuf;
74 #define ALIGN_POW2_ROUNDUP(num, align) \
75 (((num) + (align) - 1) & ~((align) - 1))
78 * Forward declarations.
81 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
82 struct crypto_unittest_params *ut_params);
85 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
86 struct crypto_unittest_params *ut_params,
87 struct crypto_testsuite_params *ts_param);
89 static struct rte_mbuf *
90 setup_test_string(struct rte_mempool *mpool,
91 const char *string, size_t len, uint8_t blocksize)
93 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
94 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
96 memset(m->buf_addr, 0, m->buf_len);
98 char *dst = rte_pktmbuf_append(m, t_len);
105 rte_memcpy(dst, string, t_len);
107 memset(dst, 0, t_len);
113 setup_oop_test_mbufs(struct rte_mbuf **ibuf, struct rte_mbuf **obuf,
114 struct rte_mempool *mpool, const char *string, size_t len,
116 *ibuf = setup_test_string(mpool, string, len, blocksize);
119 *obuf = setup_test_string(mpool, NULL, len, blocksize);
128 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
130 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
134 static struct rte_crypto_op *
135 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
138 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
141 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
142 printf("Error sending packet for encryption");
148 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
153 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
159 static struct crypto_testsuite_params testsuite_params = { NULL };
160 static struct crypto_unittest_params unittest_params;
163 testsuite_setup(void)
165 struct crypto_testsuite_params *ts_params = &testsuite_params;
166 struct rte_cryptodev_info info;
167 unsigned i, nb_devs, dev_id;
171 memset(ts_params, 0, sizeof(*ts_params));
173 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
174 if (ts_params->mbuf_pool == NULL) {
175 /* Not already created so create */
176 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
178 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
180 if (ts_params->mbuf_pool == NULL) {
181 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
186 ts_params->op_mpool = rte_crypto_op_pool_create(
187 "MBUF_CRYPTO_SYM_OP_POOL",
188 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
189 NUM_MBUFS, MBUF_CACHE_SIZE,
191 sizeof(struct rte_crypto_sym_xform),
193 if (ts_params->op_mpool == NULL) {
194 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
198 /* Create 2 AESNI MB devices if required */
199 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
200 nb_devs = rte_cryptodev_count_devtype(
201 RTE_CRYPTODEV_AESNI_MB_PMD);
203 for (i = nb_devs; i < 2; i++) {
204 ret = rte_eal_vdev_init(
205 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
207 TEST_ASSERT(ret == 0,
208 "Failed to create instance %u of"
210 i, CRYPTODEV_NAME_AESNI_MB_PMD);
215 /* Create 2 AESNI GCM devices if required */
216 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
217 nb_devs = rte_cryptodev_count_devtype(
218 RTE_CRYPTODEV_AESNI_GCM_PMD);
220 for (i = nb_devs; i < 2; i++) {
221 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
222 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
223 "Failed to create instance %u of"
225 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
230 /* Create 2 Snow3G devices if required */
231 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
232 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
234 for (i = nb_devs; i < 2; i++) {
235 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
236 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
237 "Failed to create instance %u of"
239 i, CRYPTODEV_NAME_SNOW3G_PMD);
244 /* Create 2 NULL devices if required */
245 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
246 nb_devs = rte_cryptodev_count_devtype(
247 RTE_CRYPTODEV_NULL_PMD);
249 for (i = nb_devs; i < 2; i++) {
250 int dev_id = rte_eal_vdev_init(
251 CRYPTODEV_NAME_NULL_PMD, NULL);
253 TEST_ASSERT(dev_id >= 0,
254 "Failed to create instance %u of"
256 i, CRYPTODEV_NAME_NULL_PMD);
261 nb_devs = rte_cryptodev_count();
263 RTE_LOG(ERR, USER1, "No crypto devices found?");
267 /* Create list of valid crypto devs */
268 for (i = 0; i < nb_devs; i++) {
269 rte_cryptodev_info_get(i, &info);
270 if (info.dev_type == gbl_cryptodev_type)
271 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
274 if (ts_params->valid_dev_count < 1)
277 /* Set up all the qps on the first of the valid devices found */
278 for (i = 0; i < 1; i++) {
279 dev_id = ts_params->valid_devs[i];
281 rte_cryptodev_info_get(dev_id, &info);
284 * Since we can't free and re-allocate queue memory always set
285 * the queues on this device up to max size first so enough
286 * memory is allocated for any later re-configures needed by
290 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
291 ts_params->conf.socket_id = SOCKET_ID_ANY;
292 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
294 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
296 "Failed to configure cryptodev %u with %u qps",
297 dev_id, ts_params->conf.nb_queue_pairs);
299 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
301 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
302 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
303 dev_id, qp_id, &ts_params->qp_conf,
304 rte_cryptodev_socket_id(dev_id)),
305 "Failed to setup queue pair %u on "
315 testsuite_teardown(void)
317 struct crypto_testsuite_params *ts_params = &testsuite_params;
319 if (ts_params->mbuf_pool != NULL) {
320 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
321 rte_mempool_count(ts_params->mbuf_pool));
324 if (ts_params->op_mpool != NULL) {
325 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
326 rte_mempool_count(ts_params->op_mpool));
334 struct crypto_testsuite_params *ts_params = &testsuite_params;
335 struct crypto_unittest_params *ut_params = &unittest_params;
339 /* Clear unit test parameters before running test */
340 memset(ut_params, 0, sizeof(*ut_params));
342 /* Reconfigure device to default parameters */
343 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
344 ts_params->conf.socket_id = SOCKET_ID_ANY;
345 ts_params->conf.session_mp.nb_objs =
346 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
347 DEFAULT_NUM_OPS_INFLIGHT :
348 DEFAULT_NUM_OPS_INFLIGHT;
350 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
352 "Failed to configure cryptodev %u",
353 ts_params->valid_devs[0]);
356 * Now reconfigure queues to size we actually want to use in this
359 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
361 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
362 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
363 ts_params->valid_devs[0], qp_id,
365 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
366 "Failed to setup queue pair %u on cryptodev %u",
367 qp_id, ts_params->valid_devs[0]);
371 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
373 /* Start the device */
374 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
375 "Failed to start cryptodev %u",
376 ts_params->valid_devs[0]);
384 struct crypto_testsuite_params *ts_params = &testsuite_params;
385 struct crypto_unittest_params *ut_params = &unittest_params;
386 struct rte_cryptodev_stats stats;
388 /* free crypto session structure */
389 if (ut_params->sess) {
390 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
392 ut_params->sess = NULL;
395 /* free crypto operation structure */
397 rte_crypto_op_free(ut_params->op);
400 * free mbuf - both obuf and ibuf are usually the same,
401 * but rte copes even if we call free twice
403 if (ut_params->obuf) {
404 rte_pktmbuf_free(ut_params->obuf);
407 if (ut_params->ibuf) {
408 rte_pktmbuf_free(ut_params->ibuf);
412 if (ts_params->mbuf_pool != NULL)
413 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
414 rte_mempool_count(ts_params->mbuf_pool));
416 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
418 /* Stop the device */
419 rte_cryptodev_stop(ts_params->valid_devs[0]);
423 test_device_configure_invalid_dev_id(void)
425 struct crypto_testsuite_params *ts_params = &testsuite_params;
426 uint16_t dev_id, num_devs = 0;
428 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
429 "Need at least %d devices for test", 1);
431 /* valid dev_id values */
432 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
434 /* Stop the device in case it's started so it can be configured */
435 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
437 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
438 "Failed test for rte_cryptodev_configure: "
439 "invalid dev_num %u", dev_id);
441 /* invalid dev_id values */
444 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
445 "Failed test for rte_cryptodev_configure: "
446 "invalid dev_num %u", dev_id);
450 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
451 "Failed test for rte_cryptodev_configure:"
452 "invalid dev_num %u", dev_id);
458 test_device_configure_invalid_queue_pair_ids(void)
460 struct crypto_testsuite_params *ts_params = &testsuite_params;
462 /* Stop the device in case it's started so it can be configured */
463 rte_cryptodev_stop(ts_params->valid_devs[0]);
465 /* valid - one queue pairs */
466 ts_params->conf.nb_queue_pairs = 1;
468 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
470 "Failed to configure cryptodev: dev_id %u, qp_id %u",
471 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
474 /* valid - max value queue pairs */
475 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
477 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
479 "Failed to configure cryptodev: dev_id %u, qp_id %u",
480 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
483 /* invalid - zero queue pairs */
484 ts_params->conf.nb_queue_pairs = 0;
486 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
488 "Failed test for rte_cryptodev_configure, dev_id %u,"
490 ts_params->valid_devs[0],
491 ts_params->conf.nb_queue_pairs);
494 /* invalid - max value supported by field queue pairs */
495 ts_params->conf.nb_queue_pairs = UINT16_MAX;
497 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
499 "Failed test for rte_cryptodev_configure, dev_id %u,"
501 ts_params->valid_devs[0],
502 ts_params->conf.nb_queue_pairs);
505 /* invalid - max value + 1 queue pairs */
506 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
508 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
510 "Failed test for rte_cryptodev_configure, dev_id %u,"
512 ts_params->valid_devs[0],
513 ts_params->conf.nb_queue_pairs);
519 test_queue_pair_descriptor_setup(void)
521 struct crypto_testsuite_params *ts_params = &testsuite_params;
522 struct rte_cryptodev_info dev_info;
523 struct rte_cryptodev_qp_conf qp_conf = {
524 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
529 /* Stop the device in case it's started so it can be configured */
530 rte_cryptodev_stop(ts_params->valid_devs[0]);
533 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
535 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
537 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
538 &ts_params->conf), "Failed to configure cryptodev %u",
539 ts_params->valid_devs[0]);
543 * Test various ring sizes on this device. memzones can't be
544 * freed so are re-used if ring is released and re-created.
546 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
548 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
549 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
550 ts_params->valid_devs[0], qp_id, &qp_conf,
551 rte_cryptodev_socket_id(
552 ts_params->valid_devs[0])),
554 "rte_cryptodev_queue_pair_setup: num_inflights "
555 "%u on qp %u on cryptodev %u",
556 qp_conf.nb_descriptors, qp_id,
557 ts_params->valid_devs[0]);
560 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
562 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
563 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
564 ts_params->valid_devs[0], qp_id, &qp_conf,
565 rte_cryptodev_socket_id(
566 ts_params->valid_devs[0])),
568 " rte_cryptodev_queue_pair_setup: num_inflights"
569 " %u on qp %u on cryptodev %u",
570 qp_conf.nb_descriptors, qp_id,
571 ts_params->valid_devs[0]);
574 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
576 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
577 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
578 ts_params->valid_devs[0], qp_id, &qp_conf,
579 rte_cryptodev_socket_id(
580 ts_params->valid_devs[0])),
582 "rte_cryptodev_queue_pair_setup: num_inflights"
583 " %u on qp %u on cryptodev %u",
584 qp_conf.nb_descriptors, qp_id,
585 ts_params->valid_devs[0]);
588 /* invalid number of descriptors - max supported + 2 */
589 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
591 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
592 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
593 ts_params->valid_devs[0], qp_id, &qp_conf,
594 rte_cryptodev_socket_id(
595 ts_params->valid_devs[0])),
596 "Unexpectedly passed test for "
597 "rte_cryptodev_queue_pair_setup:"
598 "num_inflights %u on qp %u on cryptodev %u",
599 qp_conf.nb_descriptors, qp_id,
600 ts_params->valid_devs[0]);
603 /* invalid number of descriptors - max value of parameter */
604 qp_conf.nb_descriptors = UINT32_MAX-1;
606 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
607 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
608 ts_params->valid_devs[0], qp_id, &qp_conf,
609 rte_cryptodev_socket_id(
610 ts_params->valid_devs[0])),
611 "Unexpectedly passed test for "
612 "rte_cryptodev_queue_pair_setup:"
613 "num_inflights %u on qp %u on cryptodev %u",
614 qp_conf.nb_descriptors, qp_id,
615 ts_params->valid_devs[0]);
618 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
620 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
621 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
622 ts_params->valid_devs[0], qp_id, &qp_conf,
623 rte_cryptodev_socket_id(
624 ts_params->valid_devs[0])),
626 " rte_cryptodev_queue_pair_setup:"
627 "num_inflights %u on qp %u on cryptodev %u",
628 qp_conf.nb_descriptors, qp_id,
629 ts_params->valid_devs[0]);
632 /* invalid number of descriptors - max supported + 1 */
633 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
635 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
636 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
637 ts_params->valid_devs[0], qp_id, &qp_conf,
638 rte_cryptodev_socket_id(
639 ts_params->valid_devs[0])),
640 "Unexpectedly passed test for "
641 "rte_cryptodev_queue_pair_setup:"
642 "num_inflights %u on qp %u on cryptodev %u",
643 qp_conf.nb_descriptors, qp_id,
644 ts_params->valid_devs[0]);
647 /* test invalid queue pair id */
648 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
650 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
652 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
653 ts_params->valid_devs[0],
655 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
656 "Failed test for rte_cryptodev_queue_pair_setup:"
657 "invalid qp %u on cryptodev %u",
658 qp_id, ts_params->valid_devs[0]);
660 qp_id = 0xffff; /*invalid*/
662 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
663 ts_params->valid_devs[0],
665 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
666 "Failed test for rte_cryptodev_queue_pair_setup:"
667 "invalid qp %u on cryptodev %u",
668 qp_id, ts_params->valid_devs[0]);
673 /* ***** Plaintext data for tests ***** */
675 const char catch_22_quote_1[] =
676 "There was only one catch and that was Catch-22, which "
677 "specified that a concern for one's safety in the face of "
678 "dangers that were real and immediate was the process of a "
679 "rational mind. Orr was crazy and could be grounded. All he "
680 "had to do was ask; and as soon as he did, he would no longer "
681 "be crazy and would have to fly more missions. Orr would be "
682 "crazy to fly more missions and sane if he didn't, but if he "
683 "was sane he had to fly them. If he flew them he was crazy "
684 "and didn't have to; but if he didn't want to he was sane and "
685 "had to. Yossarian was moved very deeply by the absolute "
686 "simplicity of this clause of Catch-22 and let out a "
687 "respectful whistle. \"That's some catch, that Catch-22\", he "
688 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
690 const char catch_22_quote[] =
691 "What a lousy earth! He wondered how many people were "
692 "destitute that same night even in his own prosperous country, "
693 "how many homes were shanties, how many husbands were drunk "
694 "and wives socked, and how many children were bullied, abused, "
695 "or abandoned. How many families hungered for food they could "
696 "not afford to buy? How many hearts were broken? How many "
697 "suicides would take place that same night, how many people "
698 "would go insane? How many cockroaches and landlords would "
699 "triumph? How many winners were losers, successes failures, "
700 "and rich men poor men? How many wise guys were stupid? How "
701 "many happy endings were unhappy endings? How many honest men "
702 "were liars, brave men cowards, loyal men traitors, how many "
703 "sainted men were corrupt, how many people in positions of "
704 "trust had sold their souls to bodyguards, how many had never "
705 "had souls? How many straight-and-narrow paths were crooked "
706 "paths? How many best families were worst families and how "
707 "many good people were bad people? When you added them all up "
708 "and then subtracted, you might be left with only the children, "
709 "and perhaps with Albert Einstein and an old violinist or "
710 "sculptor somewhere.";
712 #define QUOTE_480_BYTES (480)
713 #define QUOTE_512_BYTES (512)
714 #define QUOTE_768_BYTES (768)
715 #define QUOTE_1024_BYTES (1024)
719 /* ***** SHA1 Hash Tests ***** */
721 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
723 static uint8_t hmac_sha1_key[] = {
724 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
725 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
726 0xDE, 0xF4, 0xDE, 0xAD };
728 /* ***** SHA224 Hash Tests ***** */
730 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
733 /* ***** AES-CBC Cipher Tests ***** */
735 #define CIPHER_KEY_LENGTH_AES_CBC (16)
736 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
738 static uint8_t aes_cbc_key[] = {
739 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
740 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
742 static uint8_t aes_cbc_iv[] = {
743 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
744 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
747 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
749 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
750 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
751 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
752 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
753 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
754 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
755 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
756 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
757 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
758 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
759 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
760 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
761 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
762 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
763 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
764 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
765 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
766 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
767 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
768 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
769 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
770 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
771 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
772 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
773 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
774 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
775 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
776 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
777 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
778 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
779 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
780 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
781 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
782 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
783 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
784 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
785 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
786 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
787 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
788 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
789 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
790 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
791 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
792 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
793 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
794 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
795 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
796 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
797 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
798 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
799 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
800 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
801 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
802 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
803 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
804 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
805 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
806 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
807 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
808 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
809 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
810 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
811 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
812 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
813 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
816 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
817 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
818 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
819 0x18, 0x8c, 0x1d, 0x32
824 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
826 struct crypto_testsuite_params *ts_params = &testsuite_params;
827 struct crypto_unittest_params *ut_params = &unittest_params;
829 /* Generate test mbuf data and space for digest */
830 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
831 catch_22_quote, QUOTE_512_BYTES, 0);
833 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
834 DIGEST_BYTE_LENGTH_SHA1);
835 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
837 /* Setup Cipher Parameters */
838 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
839 ut_params->cipher_xform.next = &ut_params->auth_xform;
841 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
842 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
843 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
844 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
846 /* Setup HMAC Parameters */
847 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
849 ut_params->auth_xform.next = NULL;
851 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
852 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
853 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
854 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
855 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
857 /* Create crypto session*/
858 ut_params->sess = rte_cryptodev_sym_session_create(
859 ts_params->valid_devs[0],
860 &ut_params->cipher_xform);
861 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
863 /* Generate crypto op data structure */
864 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
865 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
866 TEST_ASSERT_NOT_NULL(ut_params->op,
867 "Failed to allocate symmetric crypto operation struct");
869 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
871 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
873 /* set crypto operation source mbuf */
874 sym_op->m_src = ut_params->ibuf;
876 /* Set crypto operation authentication parameters */
877 sym_op->auth.digest.data = ut_params->digest;
878 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
879 ut_params->ibuf, QUOTE_512_BYTES);
880 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
882 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
883 sym_op->auth.data.length = QUOTE_512_BYTES;
885 /* Set crypto operation cipher parameters */
886 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
887 CIPHER_IV_LENGTH_AES_CBC);
888 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
889 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
891 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
892 CIPHER_IV_LENGTH_AES_CBC);
894 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
895 sym_op->cipher.data.length = QUOTE_512_BYTES;
897 /* Process crypto operation */
898 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
899 ut_params->op), "failed to process sym crypto op");
901 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
902 "crypto op processing failed");
905 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
906 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
908 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
909 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
911 "ciphertext data not as expected");
913 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
915 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
916 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
917 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
918 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
919 DIGEST_BYTE_LENGTH_SHA1,
920 "Generated digest data not as expected");
927 test_AES_CBC_HMAC_SHA1_encrypt_digest_oop(void)
929 struct crypto_testsuite_params *ts_params = &testsuite_params;
930 struct crypto_unittest_params *ut_params = &unittest_params;
932 /* Generate test mbuf data and space for digest */
934 TEST_ASSERT_EQUAL(setup_oop_test_mbufs(&ut_params->ibuf,
935 &ut_params->obuf, ts_params->mbuf_pool, catch_22_quote,
936 QUOTE_512_BYTES, 0), 0,
937 "Allocation of rte_mbuf failed");
939 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->obuf,
940 DIGEST_BYTE_LENGTH_SHA1);
942 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
944 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
945 ut_params->cipher_xform.next = &ut_params->auth_xform;
947 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
948 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
949 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
950 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
952 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
953 ut_params->auth_xform.next = NULL;
955 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
956 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
957 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
958 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
959 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
961 ut_params->sess = rte_cryptodev_sym_session_create(
962 ts_params->valid_devs[0],
963 &ut_params->cipher_xform);
965 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
967 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
968 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
971 TEST_ASSERT_NOT_NULL(ut_params->op,
972 "Failed to allocate symmetric crypto operation struct");
974 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
976 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
978 /* set crypto operation source mbuf */
979 sym_op->m_src = ut_params->ibuf;
980 sym_op->m_dst = ut_params->obuf;
982 sym_op->auth.digest.data = ut_params->digest;
984 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
985 ut_params->obuf, QUOTE_512_BYTES);
987 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
988 sym_op->auth.data.length = QUOTE_512_BYTES;
990 /* Set crypto operation cipher parameters */
991 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
992 CIPHER_IV_LENGTH_AES_CBC);
994 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
995 "Failed to prepend place for iv input");
997 TEST_ASSERT_NOT_NULL(rte_pktmbuf_prepend(ut_params->obuf,
998 CIPHER_IV_LENGTH_AES_CBC),
999 "Failed to prepend place for iv output");
1001 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1003 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1004 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1006 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1007 CIPHER_IV_LENGTH_AES_CBC);
1009 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1010 sym_op->cipher.data.length = QUOTE_512_BYTES;
1013 /* Process crypto operation */
1014 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1015 ut_params->op), "failed to process sym crypto op");
1017 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1018 "crypto op processing failed");
1021 uint8_t *ciphertext;
1023 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
1024 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
1026 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1027 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1029 "ciphertext data not as expected");
1031 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1033 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1034 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1035 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1036 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1037 DIGEST_BYTE_LENGTH_SHA1,
1038 "Generated digest data not as expected");
1041 return TEST_SUCCESS;
1046 test_AES_CBC_HMAC_SHA1_decrypt_digest_oop_ver(void)
1048 struct crypto_testsuite_params *ts_params = &testsuite_params;
1049 struct crypto_unittest_params *ut_params = &unittest_params;
1051 /* Generate test mbuf data and digest */
1053 TEST_ASSERT_EQUAL(setup_oop_test_mbufs(&ut_params->ibuf,
1054 &ut_params->obuf, ts_params->mbuf_pool,
1056 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1057 QUOTE_512_BYTES, 0), 0,
1058 "Allocation of rte_mbuf failed");
1060 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1061 DIGEST_BYTE_LENGTH_SHA1);
1063 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1065 rte_memcpy(ut_params->digest,
1066 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1067 DIGEST_BYTE_LENGTH_SHA1);
1069 /* Setup Cipher Parameters */
1070 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1071 ut_params->cipher_xform.next = NULL;
1073 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1074 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1075 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1076 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1078 /* Setup HMAC Parameters */
1079 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1080 ut_params->auth_xform.next = &ut_params->cipher_xform;
1082 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1083 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1084 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1085 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1086 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1088 /* Create Crypto session*/
1090 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1091 &ut_params->auth_xform);
1092 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1094 /* Generate Crypto op data structure */
1095 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1096 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1097 TEST_ASSERT_NOT_NULL(ut_params->op,
1098 "Failed to allocate symmetric crypto operation struct");
1100 /* attach symmetric crypto session to crypto operations */
1101 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1103 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1105 /* set crypto operation source mbuf */
1106 sym_op->m_src = ut_params->ibuf;
1107 sym_op->m_dst = ut_params->obuf;
1109 sym_op->auth.digest.data = ut_params->digest;
1110 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1111 ut_params->ibuf, QUOTE_512_BYTES);
1112 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1114 sym_op->auth.data.length = QUOTE_512_BYTES;
1116 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1117 CIPHER_IV_LENGTH_AES_CBC);
1119 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
1120 "Failed to prepend place for iv input");
1122 TEST_ASSERT_NOT_NULL(rte_pktmbuf_prepend(ut_params->obuf,
1123 CIPHER_IV_LENGTH_AES_CBC),
1124 "Failed to prepend place for iv output");
1126 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1128 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1129 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1131 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1132 CIPHER_IV_LENGTH_AES_CBC);
1134 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1135 sym_op->cipher.data.length = QUOTE_512_BYTES;
1138 /* Process crypto operation */
1139 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1140 ut_params->op), "failed to process sym crypto op");
1142 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1143 "Digest verification failed");
1145 ut_params->obuf = ut_params->op->sym->m_dst;
1148 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1149 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1150 CIPHER_IV_LENGTH_AES_CBC,
1153 "Ciphertext data not as expected");
1156 return TEST_SUCCESS;
1161 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
1163 struct crypto_testsuite_params *ts_params = &testsuite_params;
1164 struct crypto_unittest_params *ut_params = &unittest_params;
1166 /* Generate test mbuf data and space for digest */
1167 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1168 catch_22_quote, QUOTE_512_BYTES, 0);
1170 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1171 DIGEST_BYTE_LENGTH_SHA1);
1172 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1174 /* Generate Crypto op data structure */
1175 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1176 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1177 TEST_ASSERT_NOT_NULL(ut_params->op,
1178 "Failed to allocate symmetric crypto operation struct");
1180 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
1181 "failed to allocate space for crypto transforms");
1183 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1185 /* set crypto operation source mbuf */
1186 sym_op->m_src = ut_params->ibuf;
1188 /* Set crypto operation data parameters */
1189 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1191 /* cipher parameters */
1192 sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1193 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1194 sym_op->xform->cipher.key.data = aes_cbc_key;
1195 sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1197 /* hash parameters */
1198 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
1200 sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1201 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1202 sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
1203 sym_op->xform->next->auth.key.data = hmac_sha1_key;
1204 sym_op->xform->next->auth.digest_length =
1205 DIGEST_BYTE_LENGTH_SHA1;
1207 sym_op->auth.digest.data = ut_params->digest;
1208 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1209 ut_params->ibuf, QUOTE_512_BYTES);
1210 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1213 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1214 sym_op->auth.data.length = QUOTE_512_BYTES;
1216 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1217 CIPHER_IV_LENGTH_AES_CBC);
1218 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1219 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1221 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1222 CIPHER_IV_LENGTH_AES_CBC);
1224 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1225 sym_op->cipher.data.length = QUOTE_512_BYTES;
1227 /* Process crypto operation */
1228 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1229 ut_params->op), "failed to process sym crypto op");
1231 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1232 "crypto op processing failed");
1234 ut_params->obuf = ut_params->op->sym->m_src;
1237 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1238 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1239 CIPHER_IV_LENGTH_AES_CBC,
1240 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1242 "Ciphertext data not as expected");
1244 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1245 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1246 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1247 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1248 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1249 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1250 DIGEST_BYTE_LENGTH_SHA1,
1251 "Generated digest data not as expected");
1254 return TEST_SUCCESS;
1258 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
1260 struct crypto_testsuite_params *ts_params = &testsuite_params;
1261 struct crypto_unittest_params *ut_params = &unittest_params;
1263 /* Generate test mbuf data and digest */
1264 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1266 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1267 QUOTE_512_BYTES, 0);
1269 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1270 DIGEST_BYTE_LENGTH_SHA1);
1271 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1273 rte_memcpy(ut_params->digest,
1274 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1275 DIGEST_BYTE_LENGTH_SHA1);
1277 /* Setup Cipher Parameters */
1278 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1279 ut_params->cipher_xform.next = NULL;
1281 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1282 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1283 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1284 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1286 /* Setup HMAC Parameters */
1287 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1288 ut_params->auth_xform.next = &ut_params->cipher_xform;
1290 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1291 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1292 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1293 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1294 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1296 /* Create Crypto session*/
1298 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1299 &ut_params->auth_xform);
1300 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1302 /* Generate Crypto op data structure */
1303 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1304 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1305 TEST_ASSERT_NOT_NULL(ut_params->op,
1306 "Failed to allocate symmetric crypto operation struct");
1308 /* attach symmetric crypto session to crypto operations */
1309 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1311 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1313 /* set crypto operation source mbuf */
1314 sym_op->m_src = ut_params->ibuf;
1316 sym_op->auth.digest.data = ut_params->digest;
1317 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1318 ut_params->ibuf, QUOTE_512_BYTES);
1319 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1321 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1322 sym_op->auth.data.length = QUOTE_512_BYTES;
1324 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1325 CIPHER_IV_LENGTH_AES_CBC);
1326 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1327 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1329 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1330 CIPHER_IV_LENGTH_AES_CBC);
1332 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1333 sym_op->cipher.data.length = QUOTE_512_BYTES;
1336 /* Process crypto operation */
1337 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1338 ut_params->op), "failed to process sym crypto op");
1340 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1341 "crypto op processing failed");
1343 ut_params->obuf = ut_params->op->sym->m_src;
1347 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1348 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1349 CIPHER_IV_LENGTH_AES_CBC,
1352 "Ciphertext data not as expected");
1354 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1355 "Digest verification failed");
1358 return TEST_SUCCESS;
1362 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1364 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1366 static uint8_t hmac_sha256_key[] = {
1367 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1368 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1369 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1370 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1372 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1373 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1374 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1375 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1376 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1379 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1381 struct crypto_testsuite_params *ts_params = &testsuite_params;
1382 struct crypto_unittest_params *ut_params = &unittest_params;
1384 /* Generate test mbuf data and space for digest */
1385 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1386 catch_22_quote, QUOTE_512_BYTES, 0);
1388 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1389 DIGEST_BYTE_LENGTH_SHA256);
1390 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1392 /* Setup Cipher Parameters */
1393 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1394 ut_params->cipher_xform.next = &ut_params->auth_xform;
1396 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1397 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1398 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1399 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1401 /* Setup HMAC Parameters */
1402 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1403 ut_params->auth_xform.next = NULL;
1405 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1406 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1407 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1408 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1409 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1411 /* Create Crypto session*/
1412 ut_params->sess = rte_cryptodev_sym_session_create(
1413 ts_params->valid_devs[0],
1414 &ut_params->cipher_xform);
1415 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1417 /* Generate Crypto op data structure */
1418 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1419 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1420 TEST_ASSERT_NOT_NULL(ut_params->op,
1421 "Failed to allocate symmetric crypto operation struct");
1423 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1425 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1427 /* set crypto operation source mbuf */
1428 sym_op->m_src = ut_params->ibuf;
1430 sym_op->auth.digest.data = ut_params->digest;
1431 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1432 ut_params->ibuf, QUOTE_512_BYTES);
1433 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1435 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1436 sym_op->auth.data.length = QUOTE_512_BYTES;
1438 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1439 CIPHER_IV_LENGTH_AES_CBC);
1440 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1441 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1443 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1444 CIPHER_IV_LENGTH_AES_CBC);
1446 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1447 sym_op->cipher.data.length = QUOTE_512_BYTES;
1449 /* Process crypto operation */
1450 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1451 ut_params->op), "failed to process sym crypto op");
1453 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1454 "crypto op processing failed");
1456 ut_params->obuf = ut_params->op->sym->m_src;
1459 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1460 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1461 CIPHER_IV_LENGTH_AES_CBC,
1462 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1464 "Ciphertext data not as expected");
1466 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1467 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1468 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1469 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1470 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1471 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1472 DIGEST_BYTE_LENGTH_SHA256,
1473 "Generated digest data not as expected");
1476 return TEST_SUCCESS;
1480 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1482 struct crypto_testsuite_params *ts_params = &testsuite_params;
1483 struct crypto_unittest_params *ut_params = &unittest_params;
1485 /* Generate test mbuf data and digest */
1486 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1488 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1489 QUOTE_512_BYTES, 0);
1491 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1492 DIGEST_BYTE_LENGTH_SHA256);
1493 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1495 rte_memcpy(ut_params->digest,
1496 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1497 DIGEST_BYTE_LENGTH_SHA256);
1499 /* Setup Cipher Parameters */
1500 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1501 ut_params->cipher_xform.next = NULL;
1503 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1504 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1505 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1506 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1508 /* Setup HMAC Parameters */
1509 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1510 ut_params->auth_xform.next = &ut_params->cipher_xform;
1512 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1513 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1514 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1515 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1516 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1518 /* Create Crypto session*/
1520 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1521 &ut_params->auth_xform);
1522 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1524 /* Generate Crypto op data structure */
1525 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1526 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1527 TEST_ASSERT_NOT_NULL(ut_params->op,
1528 "Failed to allocate symmetric crypto operation struct");
1531 /* Set crypto operation data parameters */
1532 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1534 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1536 /* set crypto operation source mbuf */
1537 sym_op->m_src = ut_params->ibuf;
1539 sym_op->auth.digest.data = ut_params->digest;
1540 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1541 ut_params->ibuf, QUOTE_512_BYTES);
1542 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1544 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1545 sym_op->auth.data.length = QUOTE_512_BYTES;
1547 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1548 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1549 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1550 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1552 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1553 CIPHER_IV_LENGTH_AES_CBC);
1555 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1556 sym_op->cipher.data.length = QUOTE_512_BYTES;
1558 /* Process crypto operation */
1559 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1560 ut_params->op), "failed to process sym crypto op");
1562 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1563 "crypto op processing failed");
1565 ut_params->obuf = ut_params->op->sym->m_src;
1568 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1569 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1570 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1572 "Plaintext data not as expected");
1574 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1575 "Digest verification failed");
1577 return TEST_SUCCESS;
1580 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1582 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1584 static uint8_t hmac_sha512_key[] = {
1585 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1586 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1587 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1588 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1589 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1590 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1591 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1592 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1594 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1595 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1596 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1597 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1598 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1599 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1600 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1601 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1602 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1605 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1607 struct crypto_testsuite_params *ts_params = &testsuite_params;
1608 struct crypto_unittest_params *ut_params = &unittest_params;
1610 /* Generate test mbuf data and space for digest */
1611 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1612 catch_22_quote, QUOTE_512_BYTES, 0);
1614 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1615 DIGEST_BYTE_LENGTH_SHA512);
1616 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1618 /* Setup Cipher Parameters */
1619 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1620 ut_params->cipher_xform.next = &ut_params->auth_xform;
1622 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1623 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1624 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1625 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1627 /* Setup HMAC Parameters */
1628 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1629 ut_params->auth_xform.next = NULL;
1631 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1632 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1633 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1634 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1635 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1637 /* Create Crypto session*/
1639 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1640 &ut_params->cipher_xform);
1642 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1644 /* Generate Crypto op data structure */
1645 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1646 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1647 TEST_ASSERT_NOT_NULL(ut_params->op,
1648 "Failed to allocate symmetric crypto operation struct");
1650 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1652 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1654 /* set crypto operation source mbuf */
1655 sym_op->m_src = ut_params->ibuf;
1657 sym_op->auth.digest.data = ut_params->digest;
1658 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1659 ut_params->ibuf, QUOTE_512_BYTES);
1660 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1662 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1663 sym_op->auth.data.length = QUOTE_512_BYTES;
1665 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1666 CIPHER_IV_LENGTH_AES_CBC);
1667 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1668 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1670 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1671 CIPHER_IV_LENGTH_AES_CBC);
1673 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1674 sym_op->cipher.data.length = QUOTE_512_BYTES;
1676 /* Process crypto operation */
1677 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1678 ut_params->op), "failed to process sym crypto op");
1680 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1681 "crypto op processing failed");
1683 ut_params->obuf = ut_params->op->sym->m_src;
1686 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1687 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1688 CIPHER_IV_LENGTH_AES_CBC,
1689 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1691 "Ciphertext data not as expected");
1693 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1694 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1695 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1696 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1697 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1698 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1699 DIGEST_BYTE_LENGTH_SHA512,
1700 "Generated digest data not as expected");
1702 return TEST_SUCCESS;
1707 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1708 struct crypto_unittest_params *ut_params);
1711 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1712 struct crypto_unittest_params *ut_params,
1713 struct crypto_testsuite_params *ts_params);
1716 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1718 struct crypto_unittest_params *ut_params = &unittest_params;
1719 struct crypto_testsuite_params *ts_params = &testsuite_params;
1721 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1722 ut_params) == TEST_SUCCESS,
1723 "Failed to create session params");
1725 /* Create Crypto session*/
1727 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1728 &ut_params->auth_xform);
1729 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1731 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1732 ut_params, ts_params);
1736 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1737 struct crypto_unittest_params *ut_params)
1740 /* Setup Cipher Parameters */
1741 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1742 ut_params->cipher_xform.next = NULL;
1744 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1745 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1746 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1747 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1749 /* Setup HMAC Parameters */
1750 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1751 ut_params->auth_xform.next = &ut_params->cipher_xform;
1753 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1754 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1755 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1756 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1757 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1759 return TEST_SUCCESS;
1764 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1765 struct crypto_unittest_params *ut_params,
1766 struct crypto_testsuite_params *ts_params)
1768 /* Generate test mbuf data and digest */
1769 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1771 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1772 QUOTE_512_BYTES, 0);
1774 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1775 DIGEST_BYTE_LENGTH_SHA512);
1776 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1778 rte_memcpy(ut_params->digest,
1779 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1780 DIGEST_BYTE_LENGTH_SHA512);
1782 /* Generate Crypto op data structure */
1783 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1784 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1785 TEST_ASSERT_NOT_NULL(ut_params->op,
1786 "Failed to allocate symmetric crypto operation struct");
1788 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1790 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1792 /* set crypto operation source mbuf */
1793 sym_op->m_src = ut_params->ibuf;
1795 sym_op->auth.digest.data = ut_params->digest;
1796 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1797 ut_params->ibuf, QUOTE_512_BYTES);
1798 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1800 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1801 sym_op->auth.data.length = QUOTE_512_BYTES;
1803 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1804 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1805 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1806 ut_params->ibuf, 0);
1807 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1809 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1810 CIPHER_IV_LENGTH_AES_CBC);
1812 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1813 sym_op->cipher.data.length = QUOTE_512_BYTES;
1815 /* Process crypto operation */
1816 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1817 ut_params->op), "failed to process sym crypto op");
1819 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1820 "crypto op processing failed");
1822 ut_params->obuf = ut_params->op->sym->m_src;
1825 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1826 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1827 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1829 "Plaintext data not as expected");
1832 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1833 "Digest verification failed");
1835 return TEST_SUCCESS;
1838 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1840 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1841 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1842 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1845 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1846 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1847 0x77, 0x1D, 0x8B, 0x75
1851 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1853 struct crypto_testsuite_params *ts_params = &testsuite_params;
1854 struct crypto_unittest_params *ut_params = &unittest_params;
1856 /* Generate test mbuf data and space for digest */
1857 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1858 catch_22_quote, QUOTE_512_BYTES, 0);
1860 /* Setup Cipher Parameters */
1861 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1862 ut_params->cipher_xform.next = &ut_params->auth_xform;
1864 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1865 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1866 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1867 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1869 /* Setup HMAC Parameters */
1870 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1871 ut_params->auth_xform.next = NULL;
1873 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1874 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1875 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1876 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1877 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1879 /* Create Crypto session*/
1880 ut_params->sess = rte_cryptodev_sym_session_create(
1881 ts_params->valid_devs[0],
1882 &ut_params->cipher_xform);
1883 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1885 /* Generate Crypto op data structure */
1886 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1887 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1888 TEST_ASSERT_NOT_NULL(ut_params->op,
1889 "Failed to allocate symmetric crypto operation struct");
1891 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1893 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1895 /* set crypto operation source mbuf */
1896 sym_op->m_src = ut_params->ibuf;
1898 /* Set operation cipher parameters */
1899 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1900 sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
1901 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1902 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1904 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1905 CIPHER_IV_LENGTH_AES_CBC);
1907 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1908 sym_op->cipher.data.length = QUOTE_512_BYTES;
1910 /* Set operation authentication parameters */
1911 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1912 sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
1913 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1915 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
1916 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1918 memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
1920 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1921 sym_op->auth.data.length = QUOTE_512_BYTES;
1924 /* Process crypto operation */
1925 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1927 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
1929 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1930 "crypto op processing failed");
1933 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1934 rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1935 uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
1936 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1938 "Ciphertext data not as expected");
1940 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1941 rte_pktmbuf_mtod_offset(
1942 ut_params->op->sym->m_src, uint8_t *,
1943 CIPHER_IV_LENGTH_AES_CBC +
1945 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1946 DIGEST_BYTE_LENGTH_AES_XCBC,
1947 "Generated digest data not as expected");
1949 return TEST_SUCCESS;
1953 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1955 struct crypto_testsuite_params *ts_params = &testsuite_params;
1956 struct crypto_unittest_params *ut_params = &unittest_params;
1958 /* Generate test mbuf data and space for digest */
1959 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1960 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1961 QUOTE_512_BYTES, 0);
1963 /* Setup Cipher Parameters */
1964 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1965 ut_params->cipher_xform.next = NULL;
1967 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1968 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1969 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1970 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1972 /* Setup HMAC Parameters */
1973 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1974 ut_params->auth_xform.next = &ut_params->cipher_xform;
1976 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1977 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1978 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1979 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1980 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1982 /* Create Crypto session*/
1984 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1985 &ut_params->auth_xform);
1986 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1988 /* Generate Crypto op data structure */
1989 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1990 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1991 TEST_ASSERT_NOT_NULL(ut_params->op,
1992 "Failed to allocate symmetric crypto operation struct");
1994 /* Set crypto operation data parameters */
1995 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1997 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1999 /* set crypto operation source mbuf */
2000 sym_op->m_src = ut_params->ibuf;
2003 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2004 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
2005 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2006 "no room to append digest");
2008 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2009 ut_params->ibuf, QUOTE_512_BYTES);
2010 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
2012 rte_memcpy(sym_op->auth.digest.data,
2013 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
2014 DIGEST_BYTE_LENGTH_AES_XCBC);
2016 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2017 sym_op->auth.data.length = QUOTE_512_BYTES;
2019 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2020 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2021 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2022 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2024 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2025 CIPHER_IV_LENGTH_AES_CBC);
2027 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2028 sym_op->cipher.data.length = QUOTE_512_BYTES;
2030 /* Process crypto operation */
2031 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2032 ut_params->op), "failed to process sym crypto op");
2034 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2035 "crypto op processing failed");
2037 ut_params->obuf = ut_params->op->sym->m_src;
2040 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2041 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
2042 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
2044 "Ciphertext data not as expected");
2046 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2047 "Digest verification failed");
2049 return TEST_SUCCESS;
2052 /* ***** Snow3G Tests ***** */
2054 create_snow3g_hash_session(uint8_t dev_id,
2055 const uint8_t *key, const uint8_t key_len,
2056 const uint8_t aad_len, const uint8_t auth_len,
2057 enum rte_crypto_auth_operation op)
2059 uint8_t hash_key[key_len];
2061 struct crypto_unittest_params *ut_params = &unittest_params;
2063 memcpy(hash_key, key, key_len);
2064 #ifdef RTE_APP_TEST_DEBUG
2065 rte_hexdump(stdout, "key:", key, key_len);
2067 /* Setup Authentication Parameters */
2068 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2069 ut_params->auth_xform.next = NULL;
2071 ut_params->auth_xform.auth.op = op;
2072 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2073 ut_params->auth_xform.auth.key.length = key_len;
2074 ut_params->auth_xform.auth.key.data = hash_key;
2075 ut_params->auth_xform.auth.digest_length = auth_len;
2076 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2077 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2078 &ut_params->auth_xform);
2079 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2083 create_snow3g_cipher_session(uint8_t dev_id,
2084 enum rte_crypto_cipher_operation op,
2085 const uint8_t *key, const uint8_t key_len)
2087 uint8_t cipher_key[key_len];
2089 struct crypto_unittest_params *ut_params = &unittest_params;
2091 memcpy(cipher_key, key, key_len);
2093 /* Setup Cipher Parameters */
2094 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2095 ut_params->cipher_xform.next = NULL;
2097 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2098 ut_params->cipher_xform.cipher.op = op;
2099 ut_params->cipher_xform.cipher.key.data = cipher_key;
2100 ut_params->cipher_xform.cipher.key.length = key_len;
2102 #ifdef RTE_APP_TEST_DEBUG
2103 rte_hexdump(stdout, "key:", key, key_len);
2105 /* Create Crypto session */
2106 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2109 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2114 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
2115 const unsigned cipher_len,
2116 const unsigned cipher_offset)
2118 struct crypto_testsuite_params *ts_params = &testsuite_params;
2119 struct crypto_unittest_params *ut_params = &unittest_params;
2120 unsigned iv_pad_len = 0;
2122 /* Generate Crypto op data structure */
2123 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2124 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2125 TEST_ASSERT_NOT_NULL(ut_params->op,
2126 "Failed to allocate pktmbuf offload");
2128 /* Set crypto operation data parameters */
2129 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2131 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2133 /* set crypto operation source mbuf */
2134 sym_op->m_src = ut_params->ibuf;
2137 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2138 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
2141 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2143 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2144 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2145 sym_op->cipher.iv.length = iv_pad_len;
2147 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2148 sym_op->cipher.data.length = cipher_len;
2149 sym_op->cipher.data.offset = cipher_offset;
2154 create_snow3g_cipher_operation_oop(const uint8_t *iv, const unsigned iv_len,
2155 const unsigned cipher_len,
2156 const unsigned cipher_offset)
2158 struct crypto_testsuite_params *ts_params = &testsuite_params;
2159 struct crypto_unittest_params *ut_params = &unittest_params;
2160 unsigned iv_pad_len = 0;
2162 /* Generate Crypto op data structure */
2163 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2164 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2165 TEST_ASSERT_NOT_NULL(ut_params->op,
2166 "Failed to allocate pktmbuf offload");
2168 /* Set crypto operation data parameters */
2169 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2171 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2173 /* set crypto operation source mbuf */
2174 sym_op->m_src = ut_params->ibuf;
2175 sym_op->m_dst = ut_params->obuf;
2178 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2179 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
2182 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2184 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2185 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2186 sym_op->cipher.iv.length = iv_pad_len;
2188 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2189 sym_op->cipher.data.length = cipher_len;
2190 sym_op->cipher.data.offset = cipher_offset;
2195 create_snow3g_cipher_auth_session(uint8_t dev_id,
2196 enum rte_crypto_cipher_operation cipher_op,
2197 enum rte_crypto_auth_operation auth_op,
2198 const uint8_t *key, const uint8_t key_len,
2199 const uint8_t aad_len, const uint8_t auth_len)
2201 uint8_t cipher_auth_key[key_len];
2203 struct crypto_unittest_params *ut_params = &unittest_params;
2205 memcpy(cipher_auth_key, key, key_len);
2207 /* Setup Authentication Parameters */
2208 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2209 ut_params->auth_xform.next = NULL;
2211 ut_params->auth_xform.auth.op = auth_op;
2212 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2213 ut_params->auth_xform.auth.key.length = key_len;
2214 /* Hash key = cipher key */
2215 ut_params->auth_xform.auth.key.data = cipher_auth_key;
2216 ut_params->auth_xform.auth.digest_length = auth_len;
2217 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2219 /* Setup Cipher Parameters */
2220 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2221 ut_params->cipher_xform.next = &ut_params->auth_xform;
2223 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2224 ut_params->cipher_xform.cipher.op = cipher_op;
2225 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2226 ut_params->cipher_xform.cipher.key.length = key_len;
2228 #ifdef RTE_APP_TEST_DEBUG
2229 rte_hexdump(stdout, "key:", key, key_len);
2231 /* Create Crypto session*/
2232 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2233 &ut_params->cipher_xform);
2235 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2240 create_snow3g_auth_cipher_session(uint8_t dev_id,
2241 enum rte_crypto_cipher_operation cipher_op,
2242 enum rte_crypto_auth_operation auth_op,
2243 const uint8_t *key, const uint8_t key_len,
2244 const uint8_t aad_len, const uint8_t auth_len)
2246 uint8_t auth_cipher_key[key_len];
2248 struct crypto_unittest_params *ut_params = &unittest_params;
2250 memcpy(auth_cipher_key, key, key_len);
2252 /* Setup Authentication Parameters */
2253 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2254 ut_params->auth_xform.auth.op = auth_op;
2255 ut_params->auth_xform.next = &ut_params->cipher_xform;
2256 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2257 ut_params->auth_xform.auth.key.length = key_len;
2258 ut_params->auth_xform.auth.key.data = auth_cipher_key;
2259 ut_params->auth_xform.auth.digest_length = auth_len;
2260 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2262 /* Setup Cipher Parameters */
2263 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2264 ut_params->cipher_xform.next = NULL;
2265 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2266 ut_params->cipher_xform.cipher.op = cipher_op;
2267 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2268 ut_params->cipher_xform.cipher.key.length = key_len;
2270 #ifdef RTE_APP_TEST_DEBUG
2271 rte_hexdump(stdout, "key:", key, key_len);
2273 /* Create Crypto session*/
2274 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2275 &ut_params->auth_xform);
2277 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2283 create_snow3g_hash_operation(const uint8_t *auth_tag,
2284 const unsigned auth_tag_len,
2285 const uint8_t *aad, const unsigned aad_len,
2286 unsigned data_pad_len,
2287 enum rte_crypto_auth_operation op,
2288 const unsigned auth_len, const unsigned auth_offset)
2290 struct crypto_testsuite_params *ts_params = &testsuite_params;
2292 struct crypto_unittest_params *ut_params = &unittest_params;
2294 unsigned aad_buffer_len;
2296 /* Generate Crypto op data structure */
2297 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2298 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2299 TEST_ASSERT_NOT_NULL(ut_params->op,
2300 "Failed to allocate pktmbuf offload");
2302 /* Set crypto operation data parameters */
2303 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2305 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2307 /* set crypto operation source mbuf */
2308 sym_op->m_src = ut_params->ibuf;
2312 * Always allocate the aad up to the block size.
2313 * The cryptodev API calls out -
2314 * - the array must be big enough to hold the AAD, plus any
2315 * space to round this up to the nearest multiple of the
2316 * block size (16 bytes).
2318 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2319 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2320 ut_params->ibuf, aad_buffer_len);
2321 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2322 "no room to prepend aad");
2323 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2325 sym_op->auth.aad.length = aad_len;
2327 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2328 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2330 #ifdef RTE_APP_TEST_DEBUG
2331 rte_hexdump(stdout, "aad:",
2332 sym_op->auth.aad.data, aad_len);
2336 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2337 ut_params->ibuf, auth_tag_len);
2339 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2340 "no room to append auth tag");
2341 ut_params->digest = sym_op->auth.digest.data;
2342 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2343 ut_params->ibuf, data_pad_len + aad_len);
2344 sym_op->auth.digest.length = auth_tag_len;
2345 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2346 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2348 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2350 #ifdef RTE_APP_TEST_DEBUG
2351 rte_hexdump(stdout, "digest:",
2352 sym_op->auth.digest.data,
2353 sym_op->auth.digest.length);
2356 sym_op->auth.data.length = auth_len;
2357 sym_op->auth.data.offset = auth_offset;
2363 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2364 const unsigned auth_tag_len,
2365 const uint8_t *aad, const unsigned aad_len,
2366 unsigned data_pad_len,
2367 enum rte_crypto_auth_operation op,
2368 const uint8_t *iv, const unsigned iv_len,
2369 const unsigned cipher_len, const unsigned cipher_offset,
2370 const unsigned auth_len, const unsigned auth_offset)
2372 struct crypto_testsuite_params *ts_params = &testsuite_params;
2373 struct crypto_unittest_params *ut_params = &unittest_params;
2375 unsigned iv_pad_len = 0;
2376 unsigned aad_buffer_len;
2378 /* Generate Crypto op data structure */
2379 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2380 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2381 TEST_ASSERT_NOT_NULL(ut_params->op,
2382 "Failed to allocate pktmbuf offload");
2383 /* Set crypto operation data parameters */
2384 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2386 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2388 /* set crypto operation source mbuf */
2389 sym_op->m_src = ut_params->ibuf;
2393 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2395 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2396 ut_params->ibuf, iv_pad_len);
2397 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2399 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2400 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2401 sym_op->cipher.iv.length = iv_pad_len;
2403 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2405 sym_op->cipher.data.length = cipher_len;
2406 sym_op->cipher.data.offset = cipher_offset;
2410 * Always allocate the aad up to the block size.
2411 * The cryptodev API calls out -
2412 * - the array must be big enough to hold the AAD, plus any
2413 * space to round this up to the nearest multiple of the
2414 * block size (16 bytes).
2416 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2418 sym_op->auth.aad.data =
2419 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2420 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2421 "no room to prepend aad");
2422 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2424 sym_op->auth.aad.length = aad_len;
2426 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2427 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2429 #ifdef RTE_APP_TEST_DEBUG
2430 rte_hexdump(stdout, "aad:",
2431 sym_op->auth.aad.data, aad_len);
2435 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2436 ut_params->ibuf, auth_tag_len);
2438 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2439 "no room to append auth tag");
2440 ut_params->digest = sym_op->auth.digest.data;
2441 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2442 ut_params->ibuf, data_pad_len + aad_len);
2443 sym_op->auth.digest.length = auth_tag_len;
2444 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2445 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2447 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2449 #ifdef RTE_APP_TEST_DEBUG
2450 rte_hexdump(stdout, "digest:",
2451 sym_op->auth.digest.data,
2452 sym_op->auth.digest.length);
2455 sym_op->auth.data.length = auth_len;
2456 sym_op->auth.data.offset = auth_offset;
2462 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2463 const uint8_t *iv, const unsigned iv_len,
2464 const uint8_t *aad, const unsigned aad_len,
2465 unsigned data_pad_len,
2466 const unsigned cipher_len, const unsigned cipher_offset,
2467 const unsigned auth_len, const unsigned auth_offset)
2469 struct crypto_testsuite_params *ts_params = &testsuite_params;
2470 struct crypto_unittest_params *ut_params = &unittest_params;
2472 unsigned iv_pad_len = 0;
2473 unsigned aad_buffer_len = 0;
2475 /* Generate Crypto op data structure */
2476 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2477 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2478 TEST_ASSERT_NOT_NULL(ut_params->op,
2479 "Failed to allocate pktmbuf offload");
2481 /* Set crypto operation data parameters */
2482 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2484 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2486 /* set crypto operation source mbuf */
2487 sym_op->m_src = ut_params->ibuf;
2490 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2491 ut_params->ibuf, auth_tag_len);
2493 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2494 "no room to append auth tag");
2496 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2497 ut_params->ibuf, data_pad_len);
2498 sym_op->auth.digest.length = auth_tag_len;
2500 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2502 #ifdef RTE_APP_TEST_DEBUG
2503 rte_hexdump(stdout, "digest:",
2504 sym_op->auth.digest.data,
2505 sym_op->auth.digest.length);
2508 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2510 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2511 ut_params->ibuf, iv_pad_len);
2512 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2514 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2515 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2516 sym_op->cipher.iv.length = iv_pad_len;
2518 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2522 * Always allocate the aad up to the block size.
2523 * The cryptodev API calls out -
2524 * - the array must be big enough to hold the AAD, plus any
2525 * space to round this up to the nearest multiple of the
2526 * block size (16 bytes).
2528 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2530 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2531 ut_params->ibuf, aad_buffer_len);
2532 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2533 "no room to prepend aad");
2534 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2536 sym_op->auth.aad.length = aad_len;
2538 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2539 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2541 #ifdef RTE_APP_TEST_DEBUG
2542 rte_hexdump(stdout, "aad:",
2543 sym_op->auth.aad.data, aad_len);
2546 sym_op->cipher.data.length = cipher_len;
2547 sym_op->cipher.data.offset = auth_offset + cipher_offset;
2549 sym_op->auth.data.length = auth_len;
2550 sym_op->auth.data.offset = auth_offset + cipher_offset;
2556 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2558 struct crypto_testsuite_params *ts_params = &testsuite_params;
2559 struct crypto_unittest_params *ut_params = &unittest_params;
2562 unsigned plaintext_pad_len;
2565 /* Create SNOW3G session */
2566 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2567 tdata->key.data, tdata->key.len,
2568 tdata->aad.len, tdata->digest.len,
2569 RTE_CRYPTO_AUTH_OP_GENERATE);
2573 /* alloc mbuf and set payload */
2574 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2576 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2577 rte_pktmbuf_tailroom(ut_params->ibuf));
2579 /* Append data which is padded to a multiple of */
2580 /* the algorithms block size */
2581 plaintext_pad_len = tdata->plaintext.len >> 3;
2582 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2584 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2586 /* Create SNOW3G opertaion */
2587 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2588 tdata->aad.data, tdata->aad.len,
2589 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2590 tdata->validAuthLenInBits.len,
2591 tdata->validAuthOffsetLenInBits.len);
2595 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2597 ut_params->obuf = ut_params->op->sym->m_src;
2598 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2599 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2600 + plaintext_pad_len + tdata->aad.len;
2603 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2606 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2607 "Snow3G Generated auth tag not as expected");
2613 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2615 struct crypto_testsuite_params *ts_params = &testsuite_params;
2616 struct crypto_unittest_params *ut_params = &unittest_params;
2619 unsigned plaintext_pad_len;
2622 /* Create SNOW3G session */
2623 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2624 tdata->key.data, tdata->key.len,
2625 tdata->aad.len, tdata->digest.len,
2626 RTE_CRYPTO_AUTH_OP_VERIFY);
2629 /* alloc mbuf and set payload */
2630 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2632 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2633 rte_pktmbuf_tailroom(ut_params->ibuf));
2635 /* Append data which is padded to a multiple */
2636 /* of the algorithms block size */
2637 plaintext_pad_len = tdata->plaintext.len >> 3;
2638 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2640 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2642 /* Create SNOW3G operation */
2643 retval = create_snow3g_hash_operation(tdata->digest.data,
2645 tdata->aad.data, tdata->aad.len,
2647 RTE_CRYPTO_AUTH_OP_VERIFY,
2648 tdata->validAuthLenInBits.len,
2649 tdata->validAuthOffsetLenInBits.len);
2653 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2655 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2656 ut_params->obuf = ut_params->op->sym->m_src;
2657 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2658 + plaintext_pad_len + tdata->aad.len;
2661 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2671 test_snow3g_hash_generate_test_case_1(void)
2673 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2677 test_snow3g_hash_generate_test_case_2(void)
2679 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2683 test_snow3g_hash_generate_test_case_3(void)
2685 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2689 test_snow3g_hash_verify_test_case_1(void)
2691 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2696 test_snow3g_hash_verify_test_case_2(void)
2698 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2702 test_snow3g_hash_verify_test_case_3(void)
2704 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2708 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2710 struct crypto_testsuite_params *ts_params = &testsuite_params;
2711 struct crypto_unittest_params *ut_params = &unittest_params;
2714 uint8_t *plaintext, *ciphertext;
2715 uint8_t plaintext_pad_len;
2716 uint8_t lastByteValidBits = 8;
2717 uint8_t lastByteMask = 0xFF;
2719 /* Create SNOW3G session */
2720 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2721 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2722 tdata->key.data, tdata->key.len);
2726 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2728 /* Clear mbuf payload */
2729 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2730 rte_pktmbuf_tailroom(ut_params->ibuf));
2733 * Append data which is padded to a
2734 * multiple of the algorithms block size
2736 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2737 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2739 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2741 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2743 #ifdef RTE_APP_TEST_DEBUG
2744 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2746 /* Create SNOW3G operation */
2747 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2748 tdata->validCipherLenInBits.len,
2749 tdata->validCipherOffsetLenInBits.len);
2753 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2755 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2757 ut_params->obuf = ut_params->op->sym->m_dst;
2758 if (ut_params->obuf)
2759 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2762 ciphertext = plaintext;
2764 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2765 if (lastByteValidBits == 0)
2766 lastByteValidBits = 8;
2767 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2768 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2770 #ifdef RTE_APP_TEST_DEBUG
2771 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2774 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2776 tdata->ciphertext.data,
2777 tdata->ciphertext.len >> 3,
2778 "Snow3G Ciphertext data not as expected");
2784 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2786 struct crypto_testsuite_params *ts_params = &testsuite_params;
2787 struct crypto_unittest_params *ut_params = &unittest_params;
2788 uint8_t *plaintext, *ciphertext;
2791 uint8_t plaintext_pad_len;
2792 uint8_t lastByteValidBits = 8;
2793 uint8_t lastByteMask = 0xFF;
2795 /* Create SNOW3G session */
2796 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2797 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2798 tdata->key.data, tdata->key.len);
2802 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2803 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2805 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2806 "Failed to allocate input buffer in mempool");
2807 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2808 "Failed to allocate output buffer in mempool");
2810 /* Clear mbuf payload */
2811 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2812 rte_pktmbuf_tailroom(ut_params->ibuf));
2815 * Append data which is padded to a
2816 * multiple of the algorithms block size
2818 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2819 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2821 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2824 rte_pktmbuf_append(ut_params->obuf,
2827 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2829 #ifdef RTE_APP_TEST_DEBUG
2830 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2832 /* Create SNOW3G operation */
2833 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2835 tdata->validCipherLenInBits.len,
2836 tdata->validCipherOffsetLenInBits.len);
2840 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2842 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2844 ut_params->obuf = ut_params->op->sym->m_dst;
2845 if (ut_params->obuf)
2846 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2849 ciphertext = plaintext;
2851 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2852 if (lastByteValidBits == 0)
2853 lastByteValidBits = 8;
2854 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2855 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2857 #ifdef RTE_APP_TEST_DEBUG
2858 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2861 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2863 tdata->ciphertext.data,
2864 tdata->ciphertext.len >> 3,
2865 "Snow3G Ciphertext data not as expected");
2870 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2872 struct crypto_testsuite_params *ts_params = &testsuite_params;
2873 struct crypto_unittest_params *ut_params = &unittest_params;
2877 uint8_t *plaintext, *ciphertext;
2878 uint8_t ciphertext_pad_len;
2879 uint8_t lastByteValidBits = 8;
2880 uint8_t lastByteMask = 0xFF;
2882 /* Create SNOW3G session */
2883 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2884 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2885 tdata->key.data, tdata->key.len);
2889 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2891 /* Clear mbuf payload */
2892 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2893 rte_pktmbuf_tailroom(ut_params->ibuf));
2896 * Append data which is padded to a
2897 * multiple of the algorithms block size
2899 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2901 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2902 ciphertext_pad_len);
2903 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2905 #ifdef RTE_APP_TEST_DEBUG
2906 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2908 /* Create SNOW3G operation */
2909 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2910 tdata->validCipherLenInBits.len,
2911 tdata->validCipherOffsetLenInBits.len);
2915 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2917 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2918 ut_params->obuf = ut_params->op->sym->m_src;
2919 if (ut_params->obuf)
2920 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2923 plaintext = ciphertext;
2924 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2925 if (lastByteValidBits == 0)
2926 lastByteValidBits = 8;
2927 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2928 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2930 #ifdef RTE_APP_TEST_DEBUG
2931 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2934 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2935 tdata->plaintext.data,
2936 tdata->plaintext.len >> 3,
2937 "Snow3G Plaintext data not as expected");
2941 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2943 struct crypto_testsuite_params *ts_params = &testsuite_params;
2944 struct crypto_unittest_params *ut_params = &unittest_params;
2948 uint8_t *plaintext, *ciphertext;
2949 uint8_t ciphertext_pad_len;
2950 uint8_t lastByteValidBits = 8;
2951 uint8_t lastByteMask = 0xFF;
2953 /* Create SNOW3G session */
2954 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2955 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2956 tdata->key.data, tdata->key.len);
2960 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2961 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2963 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2964 "Failed to allocate input buffer");
2965 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2966 "Failed to allocate output buffer");
2968 /* Clear mbuf payload */
2969 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2970 rte_pktmbuf_tailroom(ut_params->ibuf));
2972 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2973 rte_pktmbuf_tailroom(ut_params->obuf));
2976 * Append data which is padded to a
2977 * multiple of the algorithms block size
2979 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2981 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2982 ciphertext_pad_len);
2984 rte_pktmbuf_append(ut_params->obuf,
2985 ciphertext_pad_len);
2987 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2989 #ifdef RTE_APP_TEST_DEBUG
2990 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2992 /* Create SNOW3G operation */
2993 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2995 tdata->validCipherLenInBits.len,
2996 tdata->validCipherOffsetLenInBits.len);
3000 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3002 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3003 ut_params->obuf = ut_params->op->sym->m_dst;
3004 if (ut_params->obuf)
3005 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3008 plaintext = ciphertext;
3009 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3010 if (lastByteValidBits == 0)
3011 lastByteValidBits = 8;
3012 lastByteMask = lastByteMask << (8 - lastByteValidBits);
3013 (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3015 #ifdef RTE_APP_TEST_DEBUG
3016 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3019 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
3020 tdata->plaintext.data,
3021 tdata->plaintext.len >> 3,
3022 "Snow3G Plaintext data not as expected");
3027 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
3029 struct crypto_testsuite_params *ts_params = &testsuite_params;
3030 struct crypto_unittest_params *ut_params = &unittest_params;
3034 uint8_t *plaintext, *ciphertext;
3035 uint8_t plaintext_pad_len;
3036 uint8_t lastByteValidBits = 8;
3037 uint8_t lastByteMask = 0xFF;
3039 /* Create SNOW3G session */
3040 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
3041 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3042 RTE_CRYPTO_AUTH_OP_GENERATE,
3043 tdata->key.data, tdata->key.len,
3044 tdata->aad.len, tdata->digest.len);
3047 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3049 /* clear mbuf payload */
3050 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3051 rte_pktmbuf_tailroom(ut_params->ibuf));
3053 /* Append data which is padded to a multiple */
3054 /* of the algorithms block size */
3055 plaintext_pad_len = tdata->plaintext.len >> 3;
3057 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3059 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
3061 #ifdef RTE_APP_TEST_DEBUG
3062 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3065 /* Create SNOW3G operation */
3066 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
3067 tdata->digest.len, tdata->aad.data,
3068 tdata->aad.len, /*tdata->plaintext.len,*/
3069 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3070 tdata->iv.data, tdata->iv.len,
3071 tdata->validCipherLenInBits.len,
3072 tdata->validCipherOffsetLenInBits.len,
3073 tdata->validAuthLenInBits.len,
3074 tdata->validAuthOffsetLenInBits.len);
3078 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3080 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3081 ut_params->obuf = ut_params->op->sym->m_src;
3082 if (ut_params->obuf)
3083 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3086 ciphertext = plaintext;
3087 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3088 if (lastByteValidBits == 0)
3089 lastByteValidBits = 8;
3090 lastByteMask = lastByteMask << (8-lastByteValidBits);
3091 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3093 #ifdef RTE_APP_TEST_DEBUG
3094 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3097 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3099 tdata->ciphertext.data,
3100 tdata->ciphertext.len >> 3,
3101 "Snow3G Ciphertext data not as expected");
3103 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3104 + plaintext_pad_len + tdata->aad.len;
3107 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3110 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3111 "Snow3G Generated auth tag not as expected");
3115 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
3117 struct crypto_testsuite_params *ts_params = &testsuite_params;
3118 struct crypto_unittest_params *ut_params = &unittest_params;
3122 uint8_t *plaintext, *ciphertext;
3123 uint8_t plaintext_pad_len;
3124 uint8_t lastByteValidBits = 8;
3125 uint8_t lastByteMask = 0xFF;
3127 /* Create SNOW3G session */
3128 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
3129 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3130 RTE_CRYPTO_AUTH_OP_GENERATE,
3131 tdata->key.data, tdata->key.len,
3132 tdata->aad.len, tdata->digest.len);
3136 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3138 /* clear mbuf payload */
3139 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3140 rte_pktmbuf_tailroom(ut_params->ibuf));
3142 /* Append data which is padded to a multiple */
3143 /* of the algorithms block size */
3144 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
3146 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3148 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
3150 #ifdef RTE_APP_TEST_DEBUG
3151 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3154 /* Create SNOW3G operation */
3155 retval = create_snow3g_auth_cipher_operation(
3157 tdata->iv.data, tdata->iv.len,
3158 tdata->aad.data, tdata->aad.len,
3160 tdata->validCipherLenInBits.len,
3161 tdata->validCipherOffsetLenInBits.len,
3162 tdata->validAuthLenInBits.len,
3163 tdata->validAuthOffsetLenInBits.len
3169 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3171 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3172 ut_params->obuf = ut_params->op->sym->m_src;
3173 if (ut_params->obuf)
3174 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3175 + tdata->aad.len + tdata->iv.len;
3177 ciphertext = plaintext;
3179 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3180 if (lastByteValidBits == 0)
3181 lastByteValidBits = 8;
3182 lastByteMask = lastByteMask << (8-lastByteValidBits);
3183 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3184 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3185 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3186 #ifdef RTE_APP_TEST_DEBUG
3187 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3190 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3192 tdata->ciphertext.data,
3193 tdata->ciphertext.len >> 3,
3194 "Snow3G Ciphertext data not as expected");
3197 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3200 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3201 "Snow3G Generated auth tag not as expected");
3206 test_snow3g_encryption_test_case_1(void)
3208 return test_snow3g_encryption(&snow3g_test_case_1);
3212 test_snow3g_encryption_test_case_1_oop(void)
3214 return test_snow3g_encryption_oop(&snow3g_test_case_1);
3218 test_snow3g_encryption_test_case_2(void)
3220 return test_snow3g_encryption(&snow3g_test_case_2);
3224 test_snow3g_encryption_test_case_3(void)
3226 return test_snow3g_encryption(&snow3g_test_case_3);
3230 test_snow3g_encryption_test_case_4(void)
3232 return test_snow3g_encryption(&snow3g_test_case_4);
3236 test_snow3g_encryption_test_case_5(void)
3238 return test_snow3g_encryption(&snow3g_test_case_5);
3242 test_snow3g_decryption_test_case_1(void)
3244 return test_snow3g_decryption(&snow3g_test_case_1);
3248 test_snow3g_decryption_test_case_1_oop(void)
3250 return test_snow3g_decryption_oop(&snow3g_test_case_1);
3254 test_snow3g_decryption_test_case_2(void)
3256 return test_snow3g_decryption(&snow3g_test_case_2);
3260 test_snow3g_decryption_test_case_3(void)
3262 return test_snow3g_decryption(&snow3g_test_case_3);
3266 test_snow3g_decryption_test_case_4(void)
3268 return test_snow3g_decryption(&snow3g_test_case_4);
3272 test_snow3g_decryption_test_case_5(void)
3274 return test_snow3g_decryption(&snow3g_test_case_5);
3277 test_snow3g_authenticated_encryption_test_case_1(void)
3279 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
3283 test_snow3g_encrypted_authentication_test_case_1(void)
3285 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
3288 /* ***** AES-GCM Tests ***** */
3291 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3292 const uint8_t *key, const uint8_t key_len,
3293 const uint8_t aad_len, const uint8_t auth_len)
3295 uint8_t cipher_key[key_len];
3297 struct crypto_unittest_params *ut_params = &unittest_params;
3300 memcpy(cipher_key, key, key_len);
3302 /* Setup Cipher Parameters */
3303 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3304 ut_params->cipher_xform.next = NULL;
3306 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3307 ut_params->cipher_xform.cipher.op = op;
3308 ut_params->cipher_xform.cipher.key.data = cipher_key;
3309 ut_params->cipher_xform.cipher.key.length = key_len;
3311 #ifdef RTE_APP_TEST_DEBUG
3312 rte_hexdump(stdout, "key:", key, key_len);
3314 /* Setup Authentication Parameters */
3315 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3316 ut_params->auth_xform.next = NULL;
3318 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3320 ut_params->auth_xform.auth.digest_length = auth_len;
3321 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3322 ut_params->auth_xform.auth.key.length = 0;
3323 ut_params->auth_xform.auth.key.data = NULL;
3325 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3326 ut_params->cipher_xform.next = &ut_params->auth_xform;
3328 /* Create Crypto session*/
3329 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3330 &ut_params->cipher_xform);
3331 } else {/* Create Crypto session*/
3332 ut_params->auth_xform.next = &ut_params->cipher_xform;
3333 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3334 &ut_params->auth_xform);
3337 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3343 create_gcm_operation(enum rte_crypto_cipher_operation op,
3344 const uint8_t *auth_tag, const unsigned auth_tag_len,
3345 const uint8_t *iv, const unsigned iv_len,
3346 const uint8_t *aad, const unsigned aad_len,
3347 const unsigned data_len, unsigned data_pad_len)
3349 struct crypto_testsuite_params *ts_params = &testsuite_params;
3350 struct crypto_unittest_params *ut_params = &unittest_params;
3352 unsigned iv_pad_len = 0, aad_buffer_len;
3354 /* Generate Crypto op data structure */
3355 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3356 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3357 TEST_ASSERT_NOT_NULL(ut_params->op,
3358 "Failed to allocate symmetric crypto operation struct");
3360 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3364 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3365 ut_params->ibuf, auth_tag_len);
3366 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3367 "no room to append digest");
3368 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3369 ut_params->ibuf, data_pad_len);
3370 sym_op->auth.digest.length = auth_tag_len;
3372 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3373 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3374 #ifdef RTE_APP_TEST_DEBUG
3375 rte_hexdump(stdout, "digest:",
3376 ut_params->op->digest.data,
3377 ut_params->op->digest.length);
3382 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3384 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3385 ut_params->ibuf, iv_pad_len);
3386 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3388 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3389 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3390 sym_op->cipher.iv.length = iv_pad_len;
3392 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3396 sym_op->cipher.iv.data[15] = 1;
3399 * Always allocate the aad up to the block size.
3400 * The cryptodev API calls out -
3401 * - the array must be big enough to hold the AAD, plus any
3402 * space to round this up to the nearest multiple of the
3403 * block size (16 bytes).
3405 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3407 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3408 ut_params->ibuf, aad_buffer_len);
3409 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3410 "no room to prepend aad");
3411 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3413 sym_op->auth.aad.length = aad_len;
3415 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3416 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3418 #ifdef RTE_APP_TEST_DEBUG
3419 rte_hexdump(stdout, "iv:", ut_params->op->iv.data, iv_pad_len);
3420 rte_hexdump(stdout, "aad:",
3421 ut_params->op->additional_auth.data, aad_len);
3423 sym_op->cipher.data.length = data_len;
3424 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3426 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3427 sym_op->auth.data.length = data_len;
3433 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3435 struct crypto_testsuite_params *ts_params = &testsuite_params;
3436 struct crypto_unittest_params *ut_params = &unittest_params;
3440 uint8_t *plaintext, *ciphertext, *auth_tag;
3441 uint16_t plaintext_pad_len;
3443 /* Create GCM session */
3444 retval = create_gcm_session(ts_params->valid_devs[0],
3445 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3446 tdata->key.data, tdata->key.len,
3447 tdata->aad.len, tdata->auth_tag.len);
3452 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3454 /* clear mbuf payload */
3455 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3456 rte_pktmbuf_tailroom(ut_params->ibuf));
3459 * Append data which is padded to a multiple
3460 * of the algorithms block size
3462 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3464 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3466 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3468 #ifdef RTE_APP_TEST_DEBUG
3469 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3471 /* Create GCM opertaion */
3472 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3473 tdata->auth_tag.data, tdata->auth_tag.len,
3474 tdata->iv.data, tdata->iv.len,
3475 tdata->aad.data, tdata->aad.len,
3476 tdata->plaintext.len, plaintext_pad_len);
3480 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3482 ut_params->op->sym->m_src = ut_params->ibuf;
3484 /* Process crypto operation */
3485 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3486 ut_params->op), "failed to process sym crypto op");
3488 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3489 "crypto op processing failed");
3491 if (ut_params->op->sym->m_dst) {
3492 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3494 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3495 uint8_t *, plaintext_pad_len);
3497 ciphertext = plaintext;
3498 auth_tag = plaintext + plaintext_pad_len;
3501 #ifdef RTE_APP_TEST_DEBUG
3502 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3503 rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3506 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3508 tdata->ciphertext.data,
3509 tdata->ciphertext.len,
3510 "GCM Ciphertext data not as expected");
3512 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3514 tdata->auth_tag.data,
3515 tdata->auth_tag.len,
3516 "GCM Generated auth tag not as expected");
3523 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3525 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3529 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3531 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3535 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3537 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3541 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3543 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3547 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3549 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3553 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3555 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3559 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3561 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3565 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3567 struct crypto_testsuite_params *ts_params = &testsuite_params;
3568 struct crypto_unittest_params *ut_params = &unittest_params;
3572 uint8_t *plaintext, *ciphertext;
3573 uint16_t ciphertext_pad_len;
3575 /* Create GCM session */
3576 retval = create_gcm_session(ts_params->valid_devs[0],
3577 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3578 tdata->key.data, tdata->key.len,
3579 tdata->aad.len, tdata->auth_tag.len);
3584 /* alloc mbuf and set payload */
3585 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3587 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3588 rte_pktmbuf_tailroom(ut_params->ibuf));
3590 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3592 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3593 ciphertext_pad_len);
3594 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3596 #ifdef RTE_APP_TEST_DEBUG
3597 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3599 /* Create GCM opertaion */
3600 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3601 tdata->auth_tag.data, tdata->auth_tag.len,
3602 tdata->iv.data, tdata->iv.len,
3603 tdata->aad.data, tdata->aad.len,
3604 tdata->ciphertext.len, ciphertext_pad_len);
3609 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3611 ut_params->op->sym->m_src = ut_params->ibuf;
3613 /* Process crypto operation */
3614 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3615 ut_params->op), "failed to process sym crypto op");
3617 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3618 "crypto op processing failed");
3620 if (ut_params->op->sym->m_dst)
3621 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3624 plaintext = ciphertext;
3626 #ifdef RTE_APP_TEST_DEBUG
3627 rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3630 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3632 tdata->plaintext.data,
3633 tdata->plaintext.len,
3634 "GCM plaintext data not as expected");
3636 TEST_ASSERT_EQUAL(ut_params->op->status,
3637 RTE_CRYPTO_OP_STATUS_SUCCESS,
3638 "GCM authentication failed");
3643 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3645 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3649 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3651 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3655 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3657 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3661 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3663 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3667 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3669 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3673 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3675 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3679 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3681 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3687 struct crypto_testsuite_params *ts_params = &testsuite_params;
3688 struct rte_cryptodev_stats stats;
3689 struct rte_cryptodev *dev;
3690 cryptodev_stats_get_t temp_pfn;
3692 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3693 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3694 &stats) == -ENODEV),
3695 "rte_cryptodev_stats_get invalid dev failed");
3696 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3697 "rte_cryptodev_stats_get invalid Param failed");
3698 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3699 temp_pfn = dev->dev_ops->stats_get;
3700 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3701 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3703 "rte_cryptodev_stats_get invalid Param failed");
3704 dev->dev_ops->stats_get = temp_pfn;
3706 /* Test expected values */
3708 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3710 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3712 "rte_cryptodev_stats_get failed");
3713 TEST_ASSERT((stats.enqueued_count == 1),
3714 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3715 TEST_ASSERT((stats.dequeued_count == 1),
3716 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3717 TEST_ASSERT((stats.enqueue_err_count == 0),
3718 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3719 TEST_ASSERT((stats.dequeue_err_count == 0),
3720 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3722 /* invalid device but should ignore and not reset device stats*/
3723 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3724 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3726 "rte_cryptodev_stats_get failed");
3727 TEST_ASSERT((stats.enqueued_count == 1),
3728 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3730 /* check that a valid reset clears stats */
3731 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3732 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3734 "rte_cryptodev_stats_get failed");
3735 TEST_ASSERT((stats.enqueued_count == 0),
3736 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3737 TEST_ASSERT((stats.dequeued_count == 0),
3738 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3740 return TEST_SUCCESS;
3745 test_multi_session(void)
3747 struct crypto_testsuite_params *ts_params = &testsuite_params;
3748 struct crypto_unittest_params *ut_params = &unittest_params;
3750 struct rte_cryptodev_info dev_info;
3751 struct rte_cryptodev_sym_session **sessions;
3755 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3758 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3760 sessions = rte_malloc(NULL,
3761 (sizeof(struct rte_cryptodev_sym_session *) *
3762 dev_info.sym.max_nb_sessions) + 1, 0);
3764 /* Create multiple crypto sessions*/
3765 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3766 sessions[i] = rte_cryptodev_sym_session_create(
3767 ts_params->valid_devs[0],
3768 &ut_params->auth_xform);
3769 TEST_ASSERT_NOT_NULL(sessions[i],
3770 "Session creation failed at session number %u",
3773 /* Attempt to send a request on each session */
3774 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3775 sessions[i], ut_params, ts_params),
3776 "Failed to perform decrypt on request "
3778 /* free crypto operation structure */
3780 rte_crypto_op_free(ut_params->op);
3783 * free mbuf - both obuf and ibuf are usually the same,
3784 * but rte copes even if we call free twice
3786 if (ut_params->obuf) {
3787 rte_pktmbuf_free(ut_params->obuf);
3788 ut_params->obuf = 0;
3792 /* Next session create should fail */
3793 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3794 &ut_params->auth_xform);
3795 TEST_ASSERT_NULL(sessions[i],
3796 "Session creation succeeded unexpectedly!");
3798 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3799 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3804 return TEST_SUCCESS;
3808 test_not_in_place_crypto(void)
3810 struct crypto_testsuite_params *ts_params = &testsuite_params;
3811 struct crypto_unittest_params *ut_params = &unittest_params;
3812 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3814 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3816 /* Create multiple crypto sessions*/
3818 ut_params->sess = rte_cryptodev_sym_session_create(
3819 ts_params->valid_devs[0], &ut_params->auth_xform);
3821 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3824 /* Generate test mbuf data and digest */
3825 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3827 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
3828 QUOTE_512_BYTES, 0);
3830 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3831 DIGEST_BYTE_LENGTH_SHA512);
3832 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
3834 rte_memcpy(ut_params->digest,
3835 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
3836 DIGEST_BYTE_LENGTH_SHA512);
3838 /* Generate Crypto op data structure */
3839 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3840 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3841 TEST_ASSERT_NOT_NULL(ut_params->op,
3842 "Failed to allocate symmetric crypto operation struct");
3845 /* Set crypto operation data parameters */
3846 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3848 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3850 /* set crypto operation source mbuf */
3851 sym_op->m_src = ut_params->ibuf;
3852 sym_op->m_dst = dst_m;
3854 sym_op->auth.digest.data = ut_params->digest;
3855 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3856 ut_params->ibuf, QUOTE_512_BYTES);
3857 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
3859 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
3860 sym_op->auth.data.length = QUOTE_512_BYTES;
3863 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3864 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
3865 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
3866 ut_params->ibuf, 0);
3867 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
3869 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
3870 CIPHER_IV_LENGTH_AES_CBC);
3872 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
3873 sym_op->cipher.data.length = QUOTE_512_BYTES;
3875 /* Process crypto operation */
3876 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3878 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3880 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3881 "crypto operation processing failed");
3884 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3885 rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
3888 "Plaintext data not as expected");
3890 return TEST_SUCCESS;
3894 test_null_cipher_only_operation(void)
3896 struct crypto_testsuite_params *ts_params = &testsuite_params;
3897 struct crypto_unittest_params *ut_params = &unittest_params;
3899 /* Generate test mbuf data and space for digest */
3900 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3901 catch_22_quote, QUOTE_512_BYTES, 0);
3903 /* Setup Cipher Parameters */
3904 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3905 ut_params->cipher_xform.next = NULL;
3907 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3908 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3910 /* Create Crypto session*/
3911 ut_params->sess = rte_cryptodev_sym_session_create(
3912 ts_params->valid_devs[0], &ut_params->cipher_xform);
3913 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3915 /* Generate Crypto op data structure */
3916 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3917 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3918 TEST_ASSERT_NOT_NULL(ut_params->op,
3919 "Failed to allocate symmetric crypto operation struct");
3921 /* Set crypto operation data parameters */
3922 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3924 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3926 /* set crypto operation source mbuf */
3927 sym_op->m_src = ut_params->ibuf;
3929 sym_op->cipher.data.offset = 0;
3930 sym_op->cipher.data.length = QUOTE_512_BYTES;
3932 /* Process crypto operation */
3933 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3935 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3937 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3938 "crypto operation processing failed");
3941 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3942 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3945 "Ciphertext data not as expected");
3947 return TEST_SUCCESS;
3951 test_null_auth_only_operation(void)
3953 struct crypto_testsuite_params *ts_params = &testsuite_params;
3954 struct crypto_unittest_params *ut_params = &unittest_params;
3956 /* Generate test mbuf data and space for digest */
3957 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3958 catch_22_quote, QUOTE_512_BYTES, 0);
3960 /* Setup HMAC Parameters */
3961 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3962 ut_params->auth_xform.next = NULL;
3964 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3965 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3967 /* Create Crypto session*/
3968 ut_params->sess = rte_cryptodev_sym_session_create(
3969 ts_params->valid_devs[0], &ut_params->auth_xform);
3970 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3972 /* Generate Crypto op data structure */
3973 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3974 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3975 TEST_ASSERT_NOT_NULL(ut_params->op,
3976 "Failed to allocate symmetric crypto operation struct");
3978 /* Set crypto operation data parameters */
3979 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3981 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3983 sym_op->m_src = ut_params->ibuf;
3985 sym_op->auth.data.offset = 0;
3986 sym_op->auth.data.length = QUOTE_512_BYTES;
3988 /* Process crypto operation */
3989 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3991 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3993 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3994 "crypto operation processing failed");
3996 return TEST_SUCCESS;
4000 test_null_cipher_auth_operation(void)
4002 struct crypto_testsuite_params *ts_params = &testsuite_params;
4003 struct crypto_unittest_params *ut_params = &unittest_params;
4005 /* Generate test mbuf data and space for digest */
4006 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4007 catch_22_quote, QUOTE_512_BYTES, 0);
4009 /* Setup Cipher Parameters */
4010 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4011 ut_params->cipher_xform.next = &ut_params->auth_xform;
4013 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4014 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4016 /* Setup HMAC Parameters */
4017 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4018 ut_params->auth_xform.next = NULL;
4020 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4021 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4023 /* Create Crypto session*/
4024 ut_params->sess = rte_cryptodev_sym_session_create(
4025 ts_params->valid_devs[0], &ut_params->cipher_xform);
4026 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4028 /* Generate Crypto op data structure */
4029 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4030 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4031 TEST_ASSERT_NOT_NULL(ut_params->op,
4032 "Failed to allocate symmetric crypto operation struct");
4034 /* Set crypto operation data parameters */
4035 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4037 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4039 sym_op->m_src = ut_params->ibuf;
4041 sym_op->cipher.data.offset = 0;
4042 sym_op->cipher.data.length = QUOTE_512_BYTES;
4044 sym_op->auth.data.offset = 0;
4045 sym_op->auth.data.length = QUOTE_512_BYTES;
4047 /* Process crypto operation */
4048 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4050 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4052 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4053 "crypto operation processing failed");
4056 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4057 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4060 "Ciphertext data not as expected");
4062 return TEST_SUCCESS;
4066 test_null_auth_cipher_operation(void)
4068 struct crypto_testsuite_params *ts_params = &testsuite_params;
4069 struct crypto_unittest_params *ut_params = &unittest_params;
4071 /* Generate test mbuf data and space for digest */
4072 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4073 catch_22_quote, QUOTE_512_BYTES, 0);
4075 /* Setup Cipher Parameters */
4076 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4077 ut_params->cipher_xform.next = NULL;
4079 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4080 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4082 /* Setup HMAC Parameters */
4083 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4084 ut_params->auth_xform.next = &ut_params->cipher_xform;
4086 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4087 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4089 /* Create Crypto session*/
4090 ut_params->sess = rte_cryptodev_sym_session_create(
4091 ts_params->valid_devs[0], &ut_params->cipher_xform);
4092 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4094 /* Generate Crypto op data structure */
4095 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4096 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4097 TEST_ASSERT_NOT_NULL(ut_params->op,
4098 "Failed to allocate symmetric crypto operation struct");
4100 /* Set crypto operation data parameters */
4101 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4103 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4105 sym_op->m_src = ut_params->ibuf;
4107 sym_op->cipher.data.offset = 0;
4108 sym_op->cipher.data.length = QUOTE_512_BYTES;
4110 sym_op->auth.data.offset = 0;
4111 sym_op->auth.data.length = QUOTE_512_BYTES;
4113 /* Process crypto operation */
4114 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4116 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4118 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4119 "crypto operation processing failed");
4122 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4123 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4126 "Ciphertext data not as expected");
4128 return TEST_SUCCESS;
4133 test_null_invalid_operation(void)
4135 struct crypto_testsuite_params *ts_params = &testsuite_params;
4136 struct crypto_unittest_params *ut_params = &unittest_params;
4138 /* Setup Cipher Parameters */
4139 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4140 ut_params->cipher_xform.next = NULL;
4142 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4143 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4145 /* Create Crypto session*/
4146 ut_params->sess = rte_cryptodev_sym_session_create(
4147 ts_params->valid_devs[0], &ut_params->cipher_xform);
4148 TEST_ASSERT_NULL(ut_params->sess,
4149 "Session creation succeeded unexpectedly");
4152 /* Setup HMAC Parameters */
4153 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4154 ut_params->auth_xform.next = NULL;
4156 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4157 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4159 /* Create Crypto session*/
4160 ut_params->sess = rte_cryptodev_sym_session_create(
4161 ts_params->valid_devs[0], &ut_params->auth_xform);
4162 TEST_ASSERT_NULL(ut_params->sess,
4163 "Session creation succeeded unexpectedly");
4165 return TEST_SUCCESS;
4169 #define NULL_BURST_LENGTH (32)
4172 test_null_burst_operation(void)
4174 struct crypto_testsuite_params *ts_params = &testsuite_params;
4175 struct crypto_unittest_params *ut_params = &unittest_params;
4177 unsigned i, burst_len = NULL_BURST_LENGTH;
4179 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4180 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4182 /* Setup Cipher Parameters */
4183 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4184 ut_params->cipher_xform.next = &ut_params->auth_xform;
4186 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4187 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4189 /* Setup HMAC Parameters */
4190 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4191 ut_params->auth_xform.next = NULL;
4193 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4194 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4196 /* Create Crypto session*/
4197 ut_params->sess = rte_cryptodev_sym_session_create(
4198 ts_params->valid_devs[0], &ut_params->cipher_xform);
4199 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4201 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4202 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4203 burst_len, "failed to generate burst of crypto ops");
4205 /* Generate an operation for each mbuf in burst */
4206 for (i = 0; i < burst_len; i++) {
4207 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4209 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
4211 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
4215 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
4217 burst[i]->sym->m_src = m;
4220 /* Process crypto operation */
4221 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
4222 0, burst, burst_len),
4224 "Error enqueuing burst");
4226 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4227 0, burst_dequeued, burst_len),
4229 "Error dequeuing burst");
4232 for (i = 0; i < burst_len; i++) {
4234 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4235 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4237 "data not as expected");
4239 rte_pktmbuf_free(burst[i]->sym->m_src);
4240 rte_crypto_op_free(burst[i]);
4243 return TEST_SUCCESS;
4249 static struct unit_test_suite cryptodev_qat_testsuite = {
4250 .suite_name = "Crypto QAT Unit Test Suite",
4251 .setup = testsuite_setup,
4252 .teardown = testsuite_teardown,
4253 .unit_test_cases = {
4254 TEST_CASE_ST(ut_setup, ut_teardown,
4255 test_device_configure_invalid_dev_id),
4256 TEST_CASE_ST(ut_setup, ut_teardown,
4257 test_device_configure_invalid_queue_pair_ids),
4258 TEST_CASE_ST(ut_setup, ut_teardown,
4259 test_queue_pair_descriptor_setup),
4260 TEST_CASE_ST(ut_setup, ut_teardown,
4261 test_multi_session),
4263 TEST_CASE_ST(ut_setup, ut_teardown,
4264 test_AES_CBC_HMAC_SHA1_encrypt_digest_oop),
4265 TEST_CASE_ST(ut_setup, ut_teardown,
4266 test_AES_CBC_HMAC_SHA1_decrypt_digest_oop_ver),
4268 TEST_CASE_ST(ut_setup, ut_teardown,
4269 test_AES_CBC_HMAC_SHA1_encrypt_digest),
4270 TEST_CASE_ST(ut_setup, ut_teardown,
4271 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
4273 TEST_CASE_ST(ut_setup, ut_teardown,
4274 test_AES_CBC_HMAC_SHA256_encrypt_digest),
4275 TEST_CASE_ST(ut_setup, ut_teardown,
4276 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
4278 TEST_CASE_ST(ut_setup, ut_teardown,
4279 test_AES_CBC_HMAC_SHA512_encrypt_digest),
4280 TEST_CASE_ST(ut_setup, ut_teardown,
4281 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
4283 TEST_CASE_ST(ut_setup, ut_teardown,
4284 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
4285 TEST_CASE_ST(ut_setup, ut_teardown,
4286 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
4287 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4289 /** AES GCM Authenticated Encryption */
4290 TEST_CASE_ST(ut_setup, ut_teardown,
4291 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4292 TEST_CASE_ST(ut_setup, ut_teardown,
4293 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4294 TEST_CASE_ST(ut_setup, ut_teardown,
4295 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4296 TEST_CASE_ST(ut_setup, ut_teardown,
4297 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4298 TEST_CASE_ST(ut_setup, ut_teardown,
4299 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4300 TEST_CASE_ST(ut_setup, ut_teardown,
4301 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4302 TEST_CASE_ST(ut_setup, ut_teardown,
4303 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4305 /** AES GCM Authenticated Decryption */
4306 TEST_CASE_ST(ut_setup, ut_teardown,
4307 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4308 TEST_CASE_ST(ut_setup, ut_teardown,
4309 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4310 TEST_CASE_ST(ut_setup, ut_teardown,
4311 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4312 TEST_CASE_ST(ut_setup, ut_teardown,
4313 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4314 TEST_CASE_ST(ut_setup, ut_teardown,
4315 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4316 TEST_CASE_ST(ut_setup, ut_teardown,
4317 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4318 TEST_CASE_ST(ut_setup, ut_teardown,
4319 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4321 /** Snow3G encrypt only (UEA2) */
4322 TEST_CASE_ST(ut_setup, ut_teardown,
4323 test_snow3g_encryption_test_case_1),
4324 TEST_CASE_ST(ut_setup, ut_teardown,
4325 test_snow3g_encryption_test_case_2),
4326 TEST_CASE_ST(ut_setup, ut_teardown,
4327 test_snow3g_encryption_test_case_3),
4328 TEST_CASE_ST(ut_setup, ut_teardown,
4329 test_snow3g_encryption_test_case_4),
4330 TEST_CASE_ST(ut_setup, ut_teardown,
4331 test_snow3g_encryption_test_case_5),
4333 TEST_CASE_ST(ut_setup, ut_teardown,
4334 test_snow3g_encryption_test_case_1_oop),
4335 TEST_CASE_ST(ut_setup, ut_teardown,
4336 test_snow3g_decryption_test_case_1_oop),
4338 /** Snow3G decrypt only (UEA2) */
4339 TEST_CASE_ST(ut_setup, ut_teardown,
4340 test_snow3g_decryption_test_case_1),
4341 TEST_CASE_ST(ut_setup, ut_teardown,
4342 test_snow3g_decryption_test_case_2),
4343 TEST_CASE_ST(ut_setup, ut_teardown,
4344 test_snow3g_decryption_test_case_3),
4345 TEST_CASE_ST(ut_setup, ut_teardown,
4346 test_snow3g_decryption_test_case_4),
4347 TEST_CASE_ST(ut_setup, ut_teardown,
4348 test_snow3g_decryption_test_case_5),
4349 TEST_CASE_ST(ut_setup, ut_teardown,
4350 test_snow3g_hash_generate_test_case_1),
4351 TEST_CASE_ST(ut_setup, ut_teardown,
4352 test_snow3g_hash_generate_test_case_2),
4353 TEST_CASE_ST(ut_setup, ut_teardown,
4354 test_snow3g_hash_generate_test_case_3),
4355 TEST_CASE_ST(ut_setup, ut_teardown,
4356 test_snow3g_hash_verify_test_case_1),
4357 TEST_CASE_ST(ut_setup, ut_teardown,
4358 test_snow3g_hash_verify_test_case_2),
4359 TEST_CASE_ST(ut_setup, ut_teardown,
4360 test_snow3g_hash_verify_test_case_3),
4361 TEST_CASE_ST(ut_setup, ut_teardown,
4362 test_snow3g_authenticated_encryption_test_case_1),
4363 TEST_CASE_ST(ut_setup, ut_teardown,
4364 test_snow3g_encrypted_authentication_test_case_1),
4365 TEST_CASES_END() /**< NULL terminate unit test array */
4369 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
4370 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4371 .setup = testsuite_setup,
4372 .teardown = testsuite_teardown,
4373 .unit_test_cases = {
4374 TEST_CASE_ST(ut_setup, ut_teardown,
4375 test_AES_CBC_HMAC_SHA1_encrypt_digest),
4376 TEST_CASE_ST(ut_setup, ut_teardown,
4377 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
4379 TEST_CASE_ST(ut_setup, ut_teardown,
4380 test_AES_CBC_HMAC_SHA256_encrypt_digest),
4381 TEST_CASE_ST(ut_setup, ut_teardown,
4382 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
4384 TEST_CASE_ST(ut_setup, ut_teardown,
4385 test_AES_CBC_HMAC_SHA512_encrypt_digest),
4386 TEST_CASE_ST(ut_setup, ut_teardown,
4387 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
4389 TEST_CASE_ST(ut_setup, ut_teardown,
4390 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
4391 TEST_CASE_ST(ut_setup, ut_teardown,
4392 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
4394 TEST_CASE_ST(ut_setup, ut_teardown,
4395 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
4397 TEST_CASE_ST(ut_setup, ut_teardown,
4398 test_not_in_place_crypto),
4400 TEST_CASES_END() /**< NULL terminate unit test array */
4404 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
4405 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4406 .setup = testsuite_setup,
4407 .teardown = testsuite_teardown,
4408 .unit_test_cases = {
4409 /** AES GCM Authenticated Encryption */
4410 TEST_CASE_ST(ut_setup, ut_teardown,
4411 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4412 TEST_CASE_ST(ut_setup, ut_teardown,
4413 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4414 TEST_CASE_ST(ut_setup, ut_teardown,
4415 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4416 TEST_CASE_ST(ut_setup, ut_teardown,
4417 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4418 TEST_CASE_ST(ut_setup, ut_teardown,
4419 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4420 TEST_CASE_ST(ut_setup, ut_teardown,
4421 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4422 TEST_CASE_ST(ut_setup, ut_teardown,
4423 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4425 /** AES GCM Authenticated Decryption */
4426 TEST_CASE_ST(ut_setup, ut_teardown,
4427 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4428 TEST_CASE_ST(ut_setup, ut_teardown,
4429 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4430 TEST_CASE_ST(ut_setup, ut_teardown,
4431 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4432 TEST_CASE_ST(ut_setup, ut_teardown,
4433 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4434 TEST_CASE_ST(ut_setup, ut_teardown,
4435 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4436 TEST_CASE_ST(ut_setup, ut_teardown,
4437 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4438 TEST_CASE_ST(ut_setup, ut_teardown,
4439 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4441 TEST_CASES_END() /**< NULL terminate unit test array */
4445 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4446 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4447 .setup = testsuite_setup,
4448 .teardown = testsuite_teardown,
4449 .unit_test_cases = {
4450 /** Snow3G encrypt only (UEA2) */
4451 TEST_CASE_ST(ut_setup, ut_teardown,
4452 test_snow3g_encryption_test_case_1),
4453 TEST_CASE_ST(ut_setup, ut_teardown,
4454 test_snow3g_encryption_test_case_2),
4455 TEST_CASE_ST(ut_setup, ut_teardown,
4456 test_snow3g_encryption_test_case_3),
4457 TEST_CASE_ST(ut_setup, ut_teardown,
4458 test_snow3g_encryption_test_case_4),
4459 TEST_CASE_ST(ut_setup, ut_teardown,
4460 test_snow3g_encryption_test_case_5),
4463 /** Snow3G decrypt only (UEA2) */
4464 TEST_CASE_ST(ut_setup, ut_teardown,
4465 test_snow3g_decryption_test_case_1),
4466 TEST_CASE_ST(ut_setup, ut_teardown,
4467 test_snow3g_decryption_test_case_2),
4468 TEST_CASE_ST(ut_setup, ut_teardown,
4469 test_snow3g_decryption_test_case_3),
4470 TEST_CASE_ST(ut_setup, ut_teardown,
4471 test_snow3g_decryption_test_case_4),
4472 TEST_CASE_ST(ut_setup, ut_teardown,
4473 test_snow3g_decryption_test_case_5),
4474 TEST_CASE_ST(ut_setup, ut_teardown,
4475 test_snow3g_hash_generate_test_case_1),
4476 TEST_CASE_ST(ut_setup, ut_teardown,
4477 test_snow3g_hash_generate_test_case_2),
4478 TEST_CASE_ST(ut_setup, ut_teardown,
4479 test_snow3g_hash_generate_test_case_3),
4480 TEST_CASE_ST(ut_setup, ut_teardown,
4481 test_snow3g_hash_verify_test_case_1),
4482 TEST_CASE_ST(ut_setup, ut_teardown,
4483 test_snow3g_hash_verify_test_case_2),
4484 TEST_CASE_ST(ut_setup, ut_teardown,
4485 test_snow3g_hash_verify_test_case_3),
4486 TEST_CASE_ST(ut_setup, ut_teardown,
4487 test_snow3g_authenticated_encryption_test_case_1),
4488 TEST_CASE_ST(ut_setup, ut_teardown,
4489 test_snow3g_encrypted_authentication_test_case_1),
4491 TEST_CASES_END() /**< NULL terminate unit test array */
4495 static struct unit_test_suite cryptodev_null_testsuite = {
4496 .suite_name = "Crypto Device NULL Unit Test Suite",
4497 .setup = testsuite_setup,
4498 .teardown = testsuite_teardown,
4499 .unit_test_cases = {
4500 TEST_CASE_ST(ut_setup, ut_teardown,
4501 test_null_auth_only_operation),
4502 TEST_CASE_ST(ut_setup, ut_teardown,
4503 test_null_cipher_only_operation),
4504 TEST_CASE_ST(ut_setup, ut_teardown,
4505 test_null_cipher_auth_operation),
4506 TEST_CASE_ST(ut_setup, ut_teardown,
4507 test_null_auth_cipher_operation),
4508 TEST_CASE_ST(ut_setup, ut_teardown,
4509 test_null_invalid_operation),
4510 TEST_CASE_ST(ut_setup, ut_teardown,
4511 test_null_burst_operation),
4513 TEST_CASES_END() /**< NULL terminate unit test array */
4518 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4520 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4521 return unit_test_suite_runner(&cryptodev_qat_testsuite);
4523 static struct test_command cryptodev_qat_cmd = {
4524 .command = "cryptodev_qat_autotest",
4525 .callback = test_cryptodev_qat,
4529 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4531 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4533 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4536 static struct test_command cryptodev_aesni_mb_cmd = {
4537 .command = "cryptodev_aesni_mb_autotest",
4538 .callback = test_cryptodev_aesni_mb,
4542 test_cryptodev_aesni_gcm(void)
4544 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4546 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4549 static struct test_command cryptodev_aesni_gcm_cmd = {
4550 .command = "cryptodev_aesni_gcm_autotest",
4551 .callback = test_cryptodev_aesni_gcm,
4555 test_cryptodev_null(void)
4557 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4559 return unit_test_suite_runner(&cryptodev_null_testsuite);
4562 static struct test_command cryptodev_null_cmd = {
4563 .command = "cryptodev_null_autotest",
4564 .callback = test_cryptodev_null,
4568 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4570 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4572 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4575 static struct test_command cryptodev_sw_snow3g_cmd = {
4576 .command = "cryptodev_sw_snow3g_autotest",
4577 .callback = test_cryptodev_sw_snow3g,
4580 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4581 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4582 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4583 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4584 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);