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);
113 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
115 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
119 static struct rte_crypto_op *
120 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
123 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
126 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
127 printf("Error sending packet for encryption");
133 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
138 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
144 static struct crypto_testsuite_params testsuite_params = { NULL };
145 static struct crypto_unittest_params unittest_params;
148 testsuite_setup(void)
150 struct crypto_testsuite_params *ts_params = &testsuite_params;
151 struct rte_cryptodev_info info;
152 unsigned i, nb_devs, dev_id;
156 memset(ts_params, 0, sizeof(*ts_params));
158 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
159 if (ts_params->mbuf_pool == NULL) {
160 /* Not already created so create */
161 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
163 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
165 if (ts_params->mbuf_pool == NULL) {
166 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
171 ts_params->op_mpool = rte_crypto_op_pool_create(
172 "MBUF_CRYPTO_SYM_OP_POOL",
173 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
174 NUM_MBUFS, MBUF_CACHE_SIZE,
176 sizeof(struct rte_crypto_sym_xform),
178 if (ts_params->op_mpool == NULL) {
179 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
183 /* Create 2 AESNI MB devices if required */
184 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
185 nb_devs = rte_cryptodev_count_devtype(
186 RTE_CRYPTODEV_AESNI_MB_PMD);
188 for (i = nb_devs; i < 2; i++) {
189 ret = rte_eal_vdev_init(
190 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
192 TEST_ASSERT(ret == 0,
193 "Failed to create instance %u of"
195 i, CRYPTODEV_NAME_AESNI_MB_PMD);
200 /* Create 2 AESNI GCM devices if required */
201 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
202 nb_devs = rte_cryptodev_count_devtype(
203 RTE_CRYPTODEV_AESNI_GCM_PMD);
205 for (i = nb_devs; i < 2; i++) {
206 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
207 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
208 "Failed to create instance %u of"
210 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
215 /* Create 2 Snow3G devices if required */
216 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
217 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
219 for (i = nb_devs; i < 2; i++) {
220 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
221 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
222 "Failed to create instance %u of"
224 i, CRYPTODEV_NAME_SNOW3G_PMD);
229 /* Create 2 NULL devices if required */
230 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
231 nb_devs = rte_cryptodev_count_devtype(
232 RTE_CRYPTODEV_NULL_PMD);
234 for (i = nb_devs; i < 2; i++) {
235 int dev_id = rte_eal_vdev_init(
236 CRYPTODEV_NAME_NULL_PMD, NULL);
238 TEST_ASSERT(dev_id >= 0,
239 "Failed to create instance %u of"
241 i, CRYPTODEV_NAME_NULL_PMD);
246 nb_devs = rte_cryptodev_count();
248 RTE_LOG(ERR, USER1, "No crypto devices found?");
252 /* Create list of valid crypto devs */
253 for (i = 0; i < nb_devs; i++) {
254 rte_cryptodev_info_get(i, &info);
255 if (info.dev_type == gbl_cryptodev_type)
256 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
259 if (ts_params->valid_dev_count < 1)
262 /* Set up all the qps on the first of the valid devices found */
263 for (i = 0; i < 1; i++) {
264 dev_id = ts_params->valid_devs[i];
266 rte_cryptodev_info_get(dev_id, &info);
269 * Since we can't free and re-allocate queue memory always set
270 * the queues on this device up to max size first so enough
271 * memory is allocated for any later re-configures needed by
275 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
276 ts_params->conf.socket_id = SOCKET_ID_ANY;
277 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
279 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
281 "Failed to configure cryptodev %u with %u qps",
282 dev_id, ts_params->conf.nb_queue_pairs);
284 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
286 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
287 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
288 dev_id, qp_id, &ts_params->qp_conf,
289 rte_cryptodev_socket_id(dev_id)),
290 "Failed to setup queue pair %u on "
300 testsuite_teardown(void)
302 struct crypto_testsuite_params *ts_params = &testsuite_params;
304 if (ts_params->mbuf_pool != NULL) {
305 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
306 rte_mempool_count(ts_params->mbuf_pool));
309 if (ts_params->op_mpool != NULL) {
310 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
311 rte_mempool_count(ts_params->op_mpool));
319 struct crypto_testsuite_params *ts_params = &testsuite_params;
320 struct crypto_unittest_params *ut_params = &unittest_params;
324 /* Clear unit test parameters before running test */
325 memset(ut_params, 0, sizeof(*ut_params));
327 /* Reconfigure device to default parameters */
328 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
329 ts_params->conf.socket_id = SOCKET_ID_ANY;
330 ts_params->conf.session_mp.nb_objs =
331 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
332 DEFAULT_NUM_OPS_INFLIGHT :
333 DEFAULT_NUM_OPS_INFLIGHT;
335 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
337 "Failed to configure cryptodev %u",
338 ts_params->valid_devs[0]);
341 * Now reconfigure queues to size we actually want to use in this
344 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
346 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
347 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
348 ts_params->valid_devs[0], qp_id,
350 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
351 "Failed to setup queue pair %u on cryptodev %u",
352 qp_id, ts_params->valid_devs[0]);
356 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
358 /* Start the device */
359 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
360 "Failed to start cryptodev %u",
361 ts_params->valid_devs[0]);
369 struct crypto_testsuite_params *ts_params = &testsuite_params;
370 struct crypto_unittest_params *ut_params = &unittest_params;
371 struct rte_cryptodev_stats stats;
373 /* free crypto session structure */
374 if (ut_params->sess) {
375 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
377 ut_params->sess = NULL;
380 /* free crypto operation structure */
382 rte_crypto_op_free(ut_params->op);
385 * free mbuf - both obuf and ibuf are usually the same,
386 * but rte copes even if we call free twice
388 if (ut_params->obuf) {
389 rte_pktmbuf_free(ut_params->obuf);
392 if (ut_params->ibuf) {
393 rte_pktmbuf_free(ut_params->ibuf);
397 if (ts_params->mbuf_pool != NULL)
398 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
399 rte_mempool_count(ts_params->mbuf_pool));
401 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
403 /* Stop the device */
404 rte_cryptodev_stop(ts_params->valid_devs[0]);
408 test_device_configure_invalid_dev_id(void)
410 struct crypto_testsuite_params *ts_params = &testsuite_params;
411 uint16_t dev_id, num_devs = 0;
413 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
414 "Need at least %d devices for test", 1);
416 /* valid dev_id values */
417 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
419 /* Stop the device in case it's started so it can be configured */
420 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
422 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
423 "Failed test for rte_cryptodev_configure: "
424 "invalid dev_num %u", dev_id);
426 /* invalid dev_id values */
429 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
430 "Failed test for rte_cryptodev_configure: "
431 "invalid dev_num %u", dev_id);
435 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
436 "Failed test for rte_cryptodev_configure:"
437 "invalid dev_num %u", dev_id);
443 test_device_configure_invalid_queue_pair_ids(void)
445 struct crypto_testsuite_params *ts_params = &testsuite_params;
447 /* Stop the device in case it's started so it can be configured */
448 rte_cryptodev_stop(ts_params->valid_devs[0]);
450 /* valid - one queue pairs */
451 ts_params->conf.nb_queue_pairs = 1;
453 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
455 "Failed to configure cryptodev: dev_id %u, qp_id %u",
456 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
459 /* valid - max value queue pairs */
460 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
462 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
464 "Failed to configure cryptodev: dev_id %u, qp_id %u",
465 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
468 /* invalid - zero queue pairs */
469 ts_params->conf.nb_queue_pairs = 0;
471 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
473 "Failed test for rte_cryptodev_configure, dev_id %u,"
475 ts_params->valid_devs[0],
476 ts_params->conf.nb_queue_pairs);
479 /* invalid - max value supported by field queue pairs */
480 ts_params->conf.nb_queue_pairs = UINT16_MAX;
482 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
484 "Failed test for rte_cryptodev_configure, dev_id %u,"
486 ts_params->valid_devs[0],
487 ts_params->conf.nb_queue_pairs);
490 /* invalid - max value + 1 queue pairs */
491 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
493 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
495 "Failed test for rte_cryptodev_configure, dev_id %u,"
497 ts_params->valid_devs[0],
498 ts_params->conf.nb_queue_pairs);
504 test_queue_pair_descriptor_setup(void)
506 struct crypto_testsuite_params *ts_params = &testsuite_params;
507 struct rte_cryptodev_info dev_info;
508 struct rte_cryptodev_qp_conf qp_conf = {
509 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
514 /* Stop the device in case it's started so it can be configured */
515 rte_cryptodev_stop(ts_params->valid_devs[0]);
518 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
520 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
522 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
523 &ts_params->conf), "Failed to configure cryptodev %u",
524 ts_params->valid_devs[0]);
528 * Test various ring sizes on this device. memzones can't be
529 * freed so are re-used if ring is released and re-created.
531 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
533 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
534 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
535 ts_params->valid_devs[0], qp_id, &qp_conf,
536 rte_cryptodev_socket_id(
537 ts_params->valid_devs[0])),
539 "rte_cryptodev_queue_pair_setup: num_inflights "
540 "%u on qp %u on cryptodev %u",
541 qp_conf.nb_descriptors, qp_id,
542 ts_params->valid_devs[0]);
545 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
547 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
548 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
549 ts_params->valid_devs[0], qp_id, &qp_conf,
550 rte_cryptodev_socket_id(
551 ts_params->valid_devs[0])),
553 " rte_cryptodev_queue_pair_setup: num_inflights"
554 " %u on qp %u on cryptodev %u",
555 qp_conf.nb_descriptors, qp_id,
556 ts_params->valid_devs[0]);
559 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
561 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
562 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
563 ts_params->valid_devs[0], qp_id, &qp_conf,
564 rte_cryptodev_socket_id(
565 ts_params->valid_devs[0])),
567 "rte_cryptodev_queue_pair_setup: num_inflights"
568 " %u on qp %u on cryptodev %u",
569 qp_conf.nb_descriptors, qp_id,
570 ts_params->valid_devs[0]);
573 /* invalid number of descriptors - max supported + 2 */
574 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
576 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
577 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
578 ts_params->valid_devs[0], qp_id, &qp_conf,
579 rte_cryptodev_socket_id(
580 ts_params->valid_devs[0])),
581 "Unexpectedly passed test for "
582 "rte_cryptodev_queue_pair_setup:"
583 "num_inflights %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 value of parameter */
589 qp_conf.nb_descriptors = UINT32_MAX-1;
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 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
605 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
606 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
607 ts_params->valid_devs[0], qp_id, &qp_conf,
608 rte_cryptodev_socket_id(
609 ts_params->valid_devs[0])),
611 " rte_cryptodev_queue_pair_setup:"
612 "num_inflights %u on qp %u on cryptodev %u",
613 qp_conf.nb_descriptors, qp_id,
614 ts_params->valid_devs[0]);
617 /* invalid number of descriptors - max supported + 1 */
618 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
620 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
621 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
622 ts_params->valid_devs[0], qp_id, &qp_conf,
623 rte_cryptodev_socket_id(
624 ts_params->valid_devs[0])),
625 "Unexpectedly passed test for "
626 "rte_cryptodev_queue_pair_setup:"
627 "num_inflights %u on qp %u on cryptodev %u",
628 qp_conf.nb_descriptors, qp_id,
629 ts_params->valid_devs[0]);
632 /* test invalid queue pair id */
633 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
635 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
637 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
638 ts_params->valid_devs[0],
640 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
641 "Failed test for rte_cryptodev_queue_pair_setup:"
642 "invalid qp %u on cryptodev %u",
643 qp_id, ts_params->valid_devs[0]);
645 qp_id = 0xffff; /*invalid*/
647 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
648 ts_params->valid_devs[0],
650 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
651 "Failed test for rte_cryptodev_queue_pair_setup:"
652 "invalid qp %u on cryptodev %u",
653 qp_id, ts_params->valid_devs[0]);
658 /* ***** Plaintext data for tests ***** */
660 const char catch_22_quote_1[] =
661 "There was only one catch and that was Catch-22, which "
662 "specified that a concern for one's safety in the face of "
663 "dangers that were real and immediate was the process of a "
664 "rational mind. Orr was crazy and could be grounded. All he "
665 "had to do was ask; and as soon as he did, he would no longer "
666 "be crazy and would have to fly more missions. Orr would be "
667 "crazy to fly more missions and sane if he didn't, but if he "
668 "was sane he had to fly them. If he flew them he was crazy "
669 "and didn't have to; but if he didn't want to he was sane and "
670 "had to. Yossarian was moved very deeply by the absolute "
671 "simplicity of this clause of Catch-22 and let out a "
672 "respectful whistle. \"That's some catch, that Catch-22\", he "
673 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
675 const char catch_22_quote[] =
676 "What a lousy earth! He wondered how many people were "
677 "destitute that same night even in his own prosperous country, "
678 "how many homes were shanties, how many husbands were drunk "
679 "and wives socked, and how many children were bullied, abused, "
680 "or abandoned. How many families hungered for food they could "
681 "not afford to buy? How many hearts were broken? How many "
682 "suicides would take place that same night, how many people "
683 "would go insane? How many cockroaches and landlords would "
684 "triumph? How many winners were losers, successes failures, "
685 "and rich men poor men? How many wise guys were stupid? How "
686 "many happy endings were unhappy endings? How many honest men "
687 "were liars, brave men cowards, loyal men traitors, how many "
688 "sainted men were corrupt, how many people in positions of "
689 "trust had sold their souls to bodyguards, how many had never "
690 "had souls? How many straight-and-narrow paths were crooked "
691 "paths? How many best families were worst families and how "
692 "many good people were bad people? When you added them all up "
693 "and then subtracted, you might be left with only the children, "
694 "and perhaps with Albert Einstein and an old violinist or "
695 "sculptor somewhere.";
697 #define QUOTE_480_BYTES (480)
698 #define QUOTE_512_BYTES (512)
699 #define QUOTE_768_BYTES (768)
700 #define QUOTE_1024_BYTES (1024)
704 /* ***** SHA1 Hash Tests ***** */
706 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
708 static uint8_t hmac_sha1_key[] = {
709 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
710 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
711 0xDE, 0xF4, 0xDE, 0xAD };
713 /* ***** SHA224 Hash Tests ***** */
715 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
718 /* ***** AES-CBC Cipher Tests ***** */
720 #define CIPHER_KEY_LENGTH_AES_CBC (16)
721 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
723 static uint8_t aes_cbc_key[] = {
724 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
725 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
727 static uint8_t aes_cbc_iv[] = {
728 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
729 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
732 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
734 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
735 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
736 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
737 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
738 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
739 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
740 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
741 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
742 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
743 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
744 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
745 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
746 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
747 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
748 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
749 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
750 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
751 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
752 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
753 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
754 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
755 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
756 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
757 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
758 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
759 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
760 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
761 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
762 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
763 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
764 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
765 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
766 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
767 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
768 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
769 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
770 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
771 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
772 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
773 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
774 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
775 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
776 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
777 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
778 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
779 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
780 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
781 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
782 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
783 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
784 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
785 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
786 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
787 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
788 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
789 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
790 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
791 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
792 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
793 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
794 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
795 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
796 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
797 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
798 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
801 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
802 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
803 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
804 0x18, 0x8c, 0x1d, 0x32
809 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
811 struct crypto_testsuite_params *ts_params = &testsuite_params;
812 struct crypto_unittest_params *ut_params = &unittest_params;
814 /* Generate test mbuf data and space for digest */
815 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
816 catch_22_quote, QUOTE_512_BYTES, 0);
818 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
819 DIGEST_BYTE_LENGTH_SHA1);
820 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
822 /* Setup Cipher Parameters */
823 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
824 ut_params->cipher_xform.next = &ut_params->auth_xform;
826 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
827 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
828 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
829 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
831 /* Setup HMAC Parameters */
832 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
834 ut_params->auth_xform.next = NULL;
836 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
837 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
838 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
839 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
840 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
842 /* Create crypto session*/
843 ut_params->sess = rte_cryptodev_sym_session_create(
844 ts_params->valid_devs[0],
845 &ut_params->cipher_xform);
846 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
848 /* Generate crypto op data structure */
849 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
850 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
851 TEST_ASSERT_NOT_NULL(ut_params->op,
852 "Failed to allocate symmetric crypto operation struct");
854 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
856 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
858 /* set crypto operation source mbuf */
859 sym_op->m_src = ut_params->ibuf;
861 /* Set crypto operation authentication parameters */
862 sym_op->auth.digest.data = ut_params->digest;
863 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
864 ut_params->ibuf, QUOTE_512_BYTES);
865 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
867 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
868 sym_op->auth.data.length = QUOTE_512_BYTES;
870 /* Set crypto operation cipher parameters */
871 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
872 CIPHER_IV_LENGTH_AES_CBC);
873 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
874 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
876 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
877 CIPHER_IV_LENGTH_AES_CBC);
879 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
880 sym_op->cipher.data.length = QUOTE_512_BYTES;
882 /* Process crypto operation */
883 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
884 ut_params->op), "failed to process sym crypto op");
886 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
887 "crypto op processing failed");
890 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
891 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
893 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
894 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
896 "ciphertext data not as expected");
898 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
900 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
901 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
902 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
903 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
904 DIGEST_BYTE_LENGTH_SHA1,
905 "Generated digest data not as expected");
911 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
913 struct crypto_testsuite_params *ts_params = &testsuite_params;
914 struct crypto_unittest_params *ut_params = &unittest_params;
916 /* Generate test mbuf data and space for digest */
917 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
918 catch_22_quote, QUOTE_512_BYTES, 0);
920 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
921 DIGEST_BYTE_LENGTH_SHA1);
922 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
924 /* Generate Crypto op data structure */
925 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
926 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
927 TEST_ASSERT_NOT_NULL(ut_params->op,
928 "Failed to allocate symmetric crypto operation struct");
930 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
931 "failed to allocate space for crypto transforms");
933 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
935 /* set crypto operation source mbuf */
936 sym_op->m_src = ut_params->ibuf;
938 /* Set crypto operation data parameters */
939 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
941 /* cipher parameters */
942 sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
943 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
944 sym_op->xform->cipher.key.data = aes_cbc_key;
945 sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
947 /* hash parameters */
948 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
950 sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
951 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
952 sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
953 sym_op->xform->next->auth.key.data = hmac_sha1_key;
954 sym_op->xform->next->auth.digest_length =
955 DIGEST_BYTE_LENGTH_SHA1;
957 sym_op->auth.digest.data = ut_params->digest;
958 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
959 ut_params->ibuf, QUOTE_512_BYTES);
960 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
963 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
964 sym_op->auth.data.length = QUOTE_512_BYTES;
966 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
967 CIPHER_IV_LENGTH_AES_CBC);
968 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
969 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
971 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
972 CIPHER_IV_LENGTH_AES_CBC);
974 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
975 sym_op->cipher.data.length = QUOTE_512_BYTES;
977 /* Process crypto operation */
978 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
979 ut_params->op), "failed to process sym crypto op");
981 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
982 "crypto op processing failed");
984 ut_params->obuf = ut_params->op->sym->m_src;
987 TEST_ASSERT_BUFFERS_ARE_EQUAL(
988 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
989 CIPHER_IV_LENGTH_AES_CBC,
990 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
992 "Ciphertext data not as expected");
994 TEST_ASSERT_BUFFERS_ARE_EQUAL(
995 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
996 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
997 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
998 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
999 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1000 DIGEST_BYTE_LENGTH_SHA1,
1001 "Generated digest data not as expected");
1004 return TEST_SUCCESS;
1008 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
1010 struct crypto_testsuite_params *ts_params = &testsuite_params;
1011 struct crypto_unittest_params *ut_params = &unittest_params;
1013 /* Generate test mbuf data and digest */
1014 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1016 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1017 QUOTE_512_BYTES, 0);
1019 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1020 DIGEST_BYTE_LENGTH_SHA1);
1021 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1023 rte_memcpy(ut_params->digest,
1024 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1025 DIGEST_BYTE_LENGTH_SHA1);
1027 /* Setup Cipher Parameters */
1028 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1029 ut_params->cipher_xform.next = NULL;
1031 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1032 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1033 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1034 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1036 /* Setup HMAC Parameters */
1037 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1038 ut_params->auth_xform.next = &ut_params->cipher_xform;
1040 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1041 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1042 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1043 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1044 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1046 /* Create Crypto session*/
1048 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1049 &ut_params->auth_xform);
1050 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1052 /* Generate Crypto op data structure */
1053 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1054 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1055 TEST_ASSERT_NOT_NULL(ut_params->op,
1056 "Failed to allocate symmetric crypto operation struct");
1058 /* attach symmetric crypto session to crypto operations */
1059 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1061 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1063 /* set crypto operation source mbuf */
1064 sym_op->m_src = ut_params->ibuf;
1066 sym_op->auth.digest.data = ut_params->digest;
1067 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1068 ut_params->ibuf, QUOTE_512_BYTES);
1069 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1071 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1072 sym_op->auth.data.length = QUOTE_512_BYTES;
1074 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1075 CIPHER_IV_LENGTH_AES_CBC);
1076 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1077 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1079 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1080 CIPHER_IV_LENGTH_AES_CBC);
1082 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1083 sym_op->cipher.data.length = QUOTE_512_BYTES;
1086 /* Process crypto operation */
1087 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1088 ut_params->op), "failed to process sym crypto op");
1090 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1091 "crypto op processing failed");
1093 ut_params->obuf = ut_params->op->sym->m_src;
1097 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1098 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1099 CIPHER_IV_LENGTH_AES_CBC,
1102 "Ciphertext data not as expected");
1104 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1105 "Digest verification failed");
1108 return TEST_SUCCESS;
1112 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1114 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1116 static uint8_t hmac_sha256_key[] = {
1117 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1118 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1119 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1120 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1122 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1123 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1124 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1125 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1126 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1129 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1131 struct crypto_testsuite_params *ts_params = &testsuite_params;
1132 struct crypto_unittest_params *ut_params = &unittest_params;
1134 /* Generate test mbuf data and space for digest */
1135 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1136 catch_22_quote, QUOTE_512_BYTES, 0);
1138 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1139 DIGEST_BYTE_LENGTH_SHA256);
1140 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1142 /* Setup Cipher Parameters */
1143 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1144 ut_params->cipher_xform.next = &ut_params->auth_xform;
1146 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1147 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1148 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1149 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1151 /* Setup HMAC Parameters */
1152 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1153 ut_params->auth_xform.next = NULL;
1155 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1156 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1157 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1158 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1159 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1161 /* Create Crypto session*/
1162 ut_params->sess = rte_cryptodev_sym_session_create(
1163 ts_params->valid_devs[0],
1164 &ut_params->cipher_xform);
1165 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1167 /* Generate Crypto op data structure */
1168 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1169 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1170 TEST_ASSERT_NOT_NULL(ut_params->op,
1171 "Failed to allocate symmetric crypto operation struct");
1173 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1175 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1177 /* set crypto operation source mbuf */
1178 sym_op->m_src = ut_params->ibuf;
1180 sym_op->auth.digest.data = ut_params->digest;
1181 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1182 ut_params->ibuf, QUOTE_512_BYTES);
1183 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1185 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1186 sym_op->auth.data.length = QUOTE_512_BYTES;
1188 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1189 CIPHER_IV_LENGTH_AES_CBC);
1190 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1191 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1193 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1194 CIPHER_IV_LENGTH_AES_CBC);
1196 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1197 sym_op->cipher.data.length = QUOTE_512_BYTES;
1199 /* Process crypto operation */
1200 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1201 ut_params->op), "failed to process sym crypto op");
1203 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1204 "crypto op processing failed");
1206 ut_params->obuf = ut_params->op->sym->m_src;
1209 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1210 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1211 CIPHER_IV_LENGTH_AES_CBC,
1212 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1214 "Ciphertext data not as expected");
1216 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1217 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1218 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1219 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1220 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1221 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1222 DIGEST_BYTE_LENGTH_SHA256,
1223 "Generated digest data not as expected");
1226 return TEST_SUCCESS;
1230 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1232 struct crypto_testsuite_params *ts_params = &testsuite_params;
1233 struct crypto_unittest_params *ut_params = &unittest_params;
1235 /* Generate test mbuf data and digest */
1236 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1238 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1239 QUOTE_512_BYTES, 0);
1241 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1242 DIGEST_BYTE_LENGTH_SHA256);
1243 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1245 rte_memcpy(ut_params->digest,
1246 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1247 DIGEST_BYTE_LENGTH_SHA256);
1249 /* Setup Cipher Parameters */
1250 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1251 ut_params->cipher_xform.next = NULL;
1253 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1254 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1255 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1256 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1258 /* Setup HMAC Parameters */
1259 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1260 ut_params->auth_xform.next = &ut_params->cipher_xform;
1262 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1263 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1264 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1265 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1266 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1268 /* Create Crypto session*/
1270 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1271 &ut_params->auth_xform);
1272 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1274 /* Generate Crypto op data structure */
1275 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1276 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1277 TEST_ASSERT_NOT_NULL(ut_params->op,
1278 "Failed to allocate symmetric crypto operation struct");
1281 /* Set crypto operation data parameters */
1282 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1284 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1286 /* set crypto operation source mbuf */
1287 sym_op->m_src = ut_params->ibuf;
1289 sym_op->auth.digest.data = ut_params->digest;
1290 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1291 ut_params->ibuf, QUOTE_512_BYTES);
1292 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1294 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1295 sym_op->auth.data.length = QUOTE_512_BYTES;
1297 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1298 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1299 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1300 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1302 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1303 CIPHER_IV_LENGTH_AES_CBC);
1305 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1306 sym_op->cipher.data.length = QUOTE_512_BYTES;
1308 /* Process crypto operation */
1309 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1310 ut_params->op), "failed to process sym crypto op");
1312 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1313 "crypto op processing failed");
1315 ut_params->obuf = ut_params->op->sym->m_src;
1318 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1319 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1320 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1322 "Plaintext data not as expected");
1324 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1325 "Digest verification failed");
1327 return TEST_SUCCESS;
1330 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1332 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1334 static uint8_t hmac_sha512_key[] = {
1335 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1336 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1337 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1338 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1339 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1340 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1341 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1342 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1344 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1345 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1346 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1347 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1348 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1349 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1350 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1351 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1352 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1355 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1357 struct crypto_testsuite_params *ts_params = &testsuite_params;
1358 struct crypto_unittest_params *ut_params = &unittest_params;
1360 /* Generate test mbuf data and space for digest */
1361 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1362 catch_22_quote, QUOTE_512_BYTES, 0);
1364 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1365 DIGEST_BYTE_LENGTH_SHA512);
1366 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1368 /* Setup Cipher Parameters */
1369 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1370 ut_params->cipher_xform.next = &ut_params->auth_xform;
1372 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1373 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1374 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1375 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1377 /* Setup HMAC Parameters */
1378 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1379 ut_params->auth_xform.next = NULL;
1381 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1382 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1383 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1384 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1385 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1387 /* Create Crypto session*/
1389 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1390 &ut_params->cipher_xform);
1392 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1394 /* Generate Crypto op data structure */
1395 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1396 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1397 TEST_ASSERT_NOT_NULL(ut_params->op,
1398 "Failed to allocate symmetric crypto operation struct");
1400 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1402 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1404 /* set crypto operation source mbuf */
1405 sym_op->m_src = ut_params->ibuf;
1407 sym_op->auth.digest.data = ut_params->digest;
1408 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1409 ut_params->ibuf, QUOTE_512_BYTES);
1410 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1412 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1413 sym_op->auth.data.length = QUOTE_512_BYTES;
1415 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1416 CIPHER_IV_LENGTH_AES_CBC);
1417 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1418 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1420 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1421 CIPHER_IV_LENGTH_AES_CBC);
1423 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1424 sym_op->cipher.data.length = QUOTE_512_BYTES;
1426 /* Process crypto operation */
1427 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1428 ut_params->op), "failed to process sym crypto op");
1430 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1431 "crypto op processing failed");
1433 ut_params->obuf = ut_params->op->sym->m_src;
1436 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1437 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1438 CIPHER_IV_LENGTH_AES_CBC,
1439 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1441 "Ciphertext data not as expected");
1443 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1444 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1445 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1446 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1447 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1448 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1449 DIGEST_BYTE_LENGTH_SHA512,
1450 "Generated digest data not as expected");
1452 return TEST_SUCCESS;
1457 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1458 struct crypto_unittest_params *ut_params);
1461 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1462 struct crypto_unittest_params *ut_params,
1463 struct crypto_testsuite_params *ts_params);
1466 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1468 struct crypto_unittest_params *ut_params = &unittest_params;
1469 struct crypto_testsuite_params *ts_params = &testsuite_params;
1471 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1472 ut_params) == TEST_SUCCESS,
1473 "Failed to create session params");
1475 /* Create Crypto session*/
1477 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1478 &ut_params->auth_xform);
1479 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1481 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1482 ut_params, ts_params);
1486 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1487 struct crypto_unittest_params *ut_params)
1490 /* Setup Cipher Parameters */
1491 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1492 ut_params->cipher_xform.next = NULL;
1494 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1495 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1496 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1497 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1499 /* Setup HMAC Parameters */
1500 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1501 ut_params->auth_xform.next = &ut_params->cipher_xform;
1503 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1504 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1505 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1506 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1507 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1509 return TEST_SUCCESS;
1514 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1515 struct crypto_unittest_params *ut_params,
1516 struct crypto_testsuite_params *ts_params)
1518 /* Generate test mbuf data and digest */
1519 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1521 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1522 QUOTE_512_BYTES, 0);
1524 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1525 DIGEST_BYTE_LENGTH_SHA512);
1526 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1528 rte_memcpy(ut_params->digest,
1529 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1530 DIGEST_BYTE_LENGTH_SHA512);
1532 /* Generate Crypto op data structure */
1533 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1534 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1535 TEST_ASSERT_NOT_NULL(ut_params->op,
1536 "Failed to allocate symmetric crypto operation struct");
1538 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1540 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1542 /* set crypto operation source mbuf */
1543 sym_op->m_src = ut_params->ibuf;
1545 sym_op->auth.digest.data = ut_params->digest;
1546 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1547 ut_params->ibuf, QUOTE_512_BYTES);
1548 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1550 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1551 sym_op->auth.data.length = QUOTE_512_BYTES;
1553 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1554 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1555 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1556 ut_params->ibuf, 0);
1557 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1559 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1560 CIPHER_IV_LENGTH_AES_CBC);
1562 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1563 sym_op->cipher.data.length = QUOTE_512_BYTES;
1565 /* Process crypto operation */
1566 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1567 ut_params->op), "failed to process sym crypto op");
1569 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1570 "crypto op processing failed");
1572 ut_params->obuf = ut_params->op->sym->m_src;
1575 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1576 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1577 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1579 "Plaintext data not as expected");
1582 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1583 "Digest verification failed");
1585 return TEST_SUCCESS;
1588 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1590 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1591 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1592 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1595 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1596 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1597 0x77, 0x1D, 0x8B, 0x75
1601 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1603 struct crypto_testsuite_params *ts_params = &testsuite_params;
1604 struct crypto_unittest_params *ut_params = &unittest_params;
1606 /* Generate test mbuf data and space for digest */
1607 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1608 catch_22_quote, QUOTE_512_BYTES, 0);
1610 /* Setup Cipher Parameters */
1611 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1612 ut_params->cipher_xform.next = &ut_params->auth_xform;
1614 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1615 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1616 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1617 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1619 /* Setup HMAC Parameters */
1620 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1621 ut_params->auth_xform.next = NULL;
1623 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1624 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1625 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1626 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1627 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1629 /* Create Crypto session*/
1630 ut_params->sess = rte_cryptodev_sym_session_create(
1631 ts_params->valid_devs[0],
1632 &ut_params->cipher_xform);
1633 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1635 /* Generate Crypto op data structure */
1636 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1637 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1638 TEST_ASSERT_NOT_NULL(ut_params->op,
1639 "Failed to allocate symmetric crypto operation struct");
1641 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1643 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1645 /* set crypto operation source mbuf */
1646 sym_op->m_src = ut_params->ibuf;
1648 /* Set operation cipher parameters */
1649 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1650 sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
1651 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1652 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1654 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1655 CIPHER_IV_LENGTH_AES_CBC);
1657 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1658 sym_op->cipher.data.length = QUOTE_512_BYTES;
1660 /* Set operation authentication parameters */
1661 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1662 sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
1663 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1665 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
1666 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1668 memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
1670 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1671 sym_op->auth.data.length = QUOTE_512_BYTES;
1674 /* Process crypto operation */
1675 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1677 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
1679 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1680 "crypto op processing failed");
1683 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1684 rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1685 uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
1686 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1688 "Ciphertext data not as expected");
1690 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1691 rte_pktmbuf_mtod_offset(
1692 ut_params->op->sym->m_src, uint8_t *,
1693 CIPHER_IV_LENGTH_AES_CBC +
1695 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1696 DIGEST_BYTE_LENGTH_AES_XCBC,
1697 "Generated digest data not as expected");
1699 return TEST_SUCCESS;
1703 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1705 struct crypto_testsuite_params *ts_params = &testsuite_params;
1706 struct crypto_unittest_params *ut_params = &unittest_params;
1708 /* Generate test mbuf data and space for digest */
1709 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1710 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1711 QUOTE_512_BYTES, 0);
1713 /* Setup Cipher Parameters */
1714 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1715 ut_params->cipher_xform.next = NULL;
1717 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1718 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1719 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1720 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1722 /* Setup HMAC Parameters */
1723 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1724 ut_params->auth_xform.next = &ut_params->cipher_xform;
1726 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1727 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1728 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1729 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1730 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1732 /* Create Crypto session*/
1734 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1735 &ut_params->auth_xform);
1736 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1738 /* Generate Crypto op data structure */
1739 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1740 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1741 TEST_ASSERT_NOT_NULL(ut_params->op,
1742 "Failed to allocate symmetric crypto operation struct");
1744 /* Set crypto operation data parameters */
1745 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1747 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1749 /* set crypto operation source mbuf */
1750 sym_op->m_src = ut_params->ibuf;
1753 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1754 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
1755 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1756 "no room to append digest");
1758 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1759 ut_params->ibuf, QUOTE_512_BYTES);
1760 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1762 rte_memcpy(sym_op->auth.digest.data,
1763 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1764 DIGEST_BYTE_LENGTH_AES_XCBC);
1766 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1767 sym_op->auth.data.length = QUOTE_512_BYTES;
1769 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1770 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1771 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1772 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1774 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1775 CIPHER_IV_LENGTH_AES_CBC);
1777 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1778 sym_op->cipher.data.length = QUOTE_512_BYTES;
1780 /* Process crypto operation */
1781 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1782 ut_params->op), "failed to process sym crypto op");
1784 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1785 "crypto op processing failed");
1787 ut_params->obuf = ut_params->op->sym->m_src;
1790 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1791 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1792 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1794 "Ciphertext data not as expected");
1796 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1797 "Digest verification failed");
1799 return TEST_SUCCESS;
1802 /* ***** Snow3G Tests ***** */
1804 create_snow3g_hash_session(uint8_t dev_id,
1805 const uint8_t *key, const uint8_t key_len,
1806 const uint8_t aad_len, const uint8_t auth_len,
1807 enum rte_crypto_auth_operation op)
1809 uint8_t hash_key[key_len];
1811 struct crypto_unittest_params *ut_params = &unittest_params;
1813 memcpy(hash_key, key, key_len);
1814 #ifdef RTE_APP_TEST_DEBUG
1815 rte_hexdump(stdout, "key:", key, key_len);
1817 /* Setup Authentication Parameters */
1818 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1819 ut_params->auth_xform.next = NULL;
1821 ut_params->auth_xform.auth.op = op;
1822 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1823 ut_params->auth_xform.auth.key.length = key_len;
1824 ut_params->auth_xform.auth.key.data = hash_key;
1825 ut_params->auth_xform.auth.digest_length = auth_len;
1826 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1827 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1828 &ut_params->auth_xform);
1829 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1833 create_snow3g_cipher_session(uint8_t dev_id,
1834 enum rte_crypto_cipher_operation op,
1835 const uint8_t *key, const uint8_t key_len)
1837 uint8_t cipher_key[key_len];
1839 struct crypto_unittest_params *ut_params = &unittest_params;
1841 memcpy(cipher_key, key, key_len);
1843 /* Setup Cipher Parameters */
1844 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1845 ut_params->cipher_xform.next = NULL;
1847 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1848 ut_params->cipher_xform.cipher.op = op;
1849 ut_params->cipher_xform.cipher.key.data = cipher_key;
1850 ut_params->cipher_xform.cipher.key.length = key_len;
1852 #ifdef RTE_APP_TEST_DEBUG
1853 rte_hexdump(stdout, "key:", key, key_len);
1855 /* Create Crypto session */
1856 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1859 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1864 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1865 const unsigned cipher_len,
1866 const unsigned cipher_offset)
1868 struct crypto_testsuite_params *ts_params = &testsuite_params;
1869 struct crypto_unittest_params *ut_params = &unittest_params;
1870 unsigned iv_pad_len = 0;
1872 /* Generate Crypto op data structure */
1873 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1874 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1875 TEST_ASSERT_NOT_NULL(ut_params->op,
1876 "Failed to allocate pktmbuf offload");
1878 /* Set crypto operation data parameters */
1879 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1881 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1883 /* set crypto operation source mbuf */
1884 sym_op->m_src = ut_params->ibuf;
1887 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1888 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1891 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1893 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1894 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1895 sym_op->cipher.iv.length = iv_pad_len;
1897 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1898 sym_op->cipher.data.length = cipher_len;
1899 sym_op->cipher.data.offset = cipher_offset;
1905 create_snow3g_cipher_auth_session(uint8_t dev_id,
1906 enum rte_crypto_cipher_operation cipher_op,
1907 enum rte_crypto_auth_operation auth_op,
1908 const uint8_t *key, const uint8_t key_len,
1909 const uint8_t aad_len, const uint8_t auth_len)
1911 uint8_t cipher_auth_key[key_len];
1913 struct crypto_unittest_params *ut_params = &unittest_params;
1915 memcpy(cipher_auth_key, key, key_len);
1917 /* Setup Authentication Parameters */
1918 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1919 ut_params->auth_xform.next = NULL;
1921 ut_params->auth_xform.auth.op = auth_op;
1922 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1923 ut_params->auth_xform.auth.key.length = key_len;
1924 /* Hash key = cipher key */
1925 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1926 ut_params->auth_xform.auth.digest_length = auth_len;
1927 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1929 /* Setup Cipher Parameters */
1930 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1931 ut_params->cipher_xform.next = &ut_params->auth_xform;
1933 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1934 ut_params->cipher_xform.cipher.op = cipher_op;
1935 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1936 ut_params->cipher_xform.cipher.key.length = key_len;
1938 #ifdef RTE_APP_TEST_DEBUG
1939 rte_hexdump(stdout, "key:", key, key_len);
1941 /* Create Crypto session*/
1942 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1943 &ut_params->cipher_xform);
1945 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1950 create_snow3g_auth_cipher_session(uint8_t dev_id,
1951 enum rte_crypto_cipher_operation cipher_op,
1952 enum rte_crypto_auth_operation auth_op,
1953 const uint8_t *key, const uint8_t key_len,
1954 const uint8_t aad_len, const uint8_t auth_len)
1956 uint8_t auth_cipher_key[key_len];
1958 struct crypto_unittest_params *ut_params = &unittest_params;
1960 memcpy(auth_cipher_key, key, key_len);
1962 /* Setup Authentication Parameters */
1963 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1964 ut_params->auth_xform.auth.op = auth_op;
1965 ut_params->auth_xform.next = &ut_params->cipher_xform;
1966 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1967 ut_params->auth_xform.auth.key.length = key_len;
1968 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1969 ut_params->auth_xform.auth.digest_length = auth_len;
1970 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1972 /* Setup Cipher Parameters */
1973 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1974 ut_params->cipher_xform.next = NULL;
1975 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1976 ut_params->cipher_xform.cipher.op = cipher_op;
1977 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1978 ut_params->cipher_xform.cipher.key.length = key_len;
1980 #ifdef RTE_APP_TEST_DEBUG
1981 rte_hexdump(stdout, "key:", key, key_len);
1983 /* Create Crypto session*/
1984 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1985 &ut_params->auth_xform);
1987 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1993 create_snow3g_hash_operation(const uint8_t *auth_tag,
1994 const unsigned auth_tag_len,
1995 const uint8_t *aad, const unsigned aad_len,
1996 unsigned data_pad_len,
1997 enum rte_crypto_auth_operation op,
1998 const unsigned auth_len, const unsigned auth_offset)
2000 struct crypto_testsuite_params *ts_params = &testsuite_params;
2002 struct crypto_unittest_params *ut_params = &unittest_params;
2004 unsigned aad_buffer_len;
2006 /* Generate Crypto op data structure */
2007 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2008 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2009 TEST_ASSERT_NOT_NULL(ut_params->op,
2010 "Failed to allocate pktmbuf offload");
2012 /* Set crypto operation data parameters */
2013 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2015 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2017 /* set crypto operation source mbuf */
2018 sym_op->m_src = ut_params->ibuf;
2022 * Always allocate the aad up to the block size.
2023 * The cryptodev API calls out -
2024 * - the array must be big enough to hold the AAD, plus any
2025 * space to round this up to the nearest multiple of the
2026 * block size (16 bytes).
2028 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2029 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2030 ut_params->ibuf, aad_buffer_len);
2031 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2032 "no room to prepend aad");
2033 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2035 sym_op->auth.aad.length = aad_len;
2037 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2038 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2040 #ifdef RTE_APP_TEST_DEBUG
2041 rte_hexdump(stdout, "aad:",
2042 sym_op->auth.aad.data, aad_len);
2046 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2047 ut_params->ibuf, auth_tag_len);
2049 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2050 "no room to append auth tag");
2051 ut_params->digest = sym_op->auth.digest.data;
2052 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2053 ut_params->ibuf, data_pad_len + aad_len);
2054 sym_op->auth.digest.length = auth_tag_len;
2055 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2056 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2058 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2060 #ifdef RTE_APP_TEST_DEBUG
2061 rte_hexdump(stdout, "digest:",
2062 sym_op->auth.digest.data,
2063 sym_op->auth.digest.length);
2066 sym_op->auth.data.length = auth_len;
2067 sym_op->auth.data.offset = auth_offset;
2073 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2074 const unsigned auth_tag_len,
2075 const uint8_t *aad, const unsigned aad_len,
2076 unsigned data_pad_len,
2077 enum rte_crypto_auth_operation op,
2078 const uint8_t *iv, const unsigned iv_len,
2079 const unsigned cipher_len, const unsigned cipher_offset,
2080 const unsigned auth_len, const unsigned auth_offset)
2082 struct crypto_testsuite_params *ts_params = &testsuite_params;
2083 struct crypto_unittest_params *ut_params = &unittest_params;
2085 unsigned iv_pad_len = 0;
2086 unsigned aad_buffer_len;
2088 /* Generate Crypto op data structure */
2089 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2090 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2091 TEST_ASSERT_NOT_NULL(ut_params->op,
2092 "Failed to allocate pktmbuf offload");
2093 /* Set crypto operation data parameters */
2094 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2096 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2098 /* set crypto operation source mbuf */
2099 sym_op->m_src = ut_params->ibuf;
2103 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2105 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2106 ut_params->ibuf, iv_pad_len);
2107 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2109 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2110 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2111 sym_op->cipher.iv.length = iv_pad_len;
2113 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2115 sym_op->cipher.data.length = cipher_len;
2116 sym_op->cipher.data.offset = cipher_offset;
2120 * Always allocate the aad up to the block size.
2121 * The cryptodev API calls out -
2122 * - the array must be big enough to hold the AAD, plus any
2123 * space to round this up to the nearest multiple of the
2124 * block size (16 bytes).
2126 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2128 sym_op->auth.aad.data =
2129 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2130 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2131 "no room to prepend aad");
2132 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2134 sym_op->auth.aad.length = aad_len;
2136 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2137 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2139 #ifdef RTE_APP_TEST_DEBUG
2140 rte_hexdump(stdout, "aad:",
2141 sym_op->auth.aad.data, aad_len);
2145 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2146 ut_params->ibuf, auth_tag_len);
2148 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2149 "no room to append auth tag");
2150 ut_params->digest = sym_op->auth.digest.data;
2151 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2152 ut_params->ibuf, data_pad_len + aad_len);
2153 sym_op->auth.digest.length = auth_tag_len;
2154 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2155 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2157 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2159 #ifdef RTE_APP_TEST_DEBUG
2160 rte_hexdump(stdout, "digest:",
2161 sym_op->auth.digest.data,
2162 sym_op->auth.digest.length);
2165 sym_op->auth.data.length = auth_len;
2166 sym_op->auth.data.offset = auth_offset;
2172 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2173 const uint8_t *iv, const unsigned iv_len,
2174 const uint8_t *aad, const unsigned aad_len,
2175 unsigned data_pad_len,
2176 const unsigned cipher_len, const unsigned cipher_offset,
2177 const unsigned auth_len, const unsigned auth_offset)
2179 struct crypto_testsuite_params *ts_params = &testsuite_params;
2180 struct crypto_unittest_params *ut_params = &unittest_params;
2182 unsigned iv_pad_len = 0;
2183 unsigned aad_buffer_len = 0;
2185 /* Generate Crypto op data structure */
2186 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2187 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2188 TEST_ASSERT_NOT_NULL(ut_params->op,
2189 "Failed to allocate pktmbuf offload");
2191 /* Set crypto operation data parameters */
2192 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2194 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2196 /* set crypto operation source mbuf */
2197 sym_op->m_src = ut_params->ibuf;
2200 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2201 ut_params->ibuf, auth_tag_len);
2203 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2204 "no room to append auth tag");
2206 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2207 ut_params->ibuf, data_pad_len);
2208 sym_op->auth.digest.length = auth_tag_len;
2210 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2212 #ifdef RTE_APP_TEST_DEBUG
2213 rte_hexdump(stdout, "digest:",
2214 sym_op->auth.digest.data,
2215 sym_op->auth.digest.length);
2218 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2220 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2221 ut_params->ibuf, iv_pad_len);
2222 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2224 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2225 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2226 sym_op->cipher.iv.length = iv_pad_len;
2228 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2232 * Always allocate the aad up to the block size.
2233 * The cryptodev API calls out -
2234 * - the array must be big enough to hold the AAD, plus any
2235 * space to round this up to the nearest multiple of the
2236 * block size (16 bytes).
2238 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2240 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2241 ut_params->ibuf, aad_buffer_len);
2242 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2243 "no room to prepend aad");
2244 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2246 sym_op->auth.aad.length = aad_len;
2248 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2249 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2251 #ifdef RTE_APP_TEST_DEBUG
2252 rte_hexdump(stdout, "aad:",
2253 sym_op->auth.aad.data, aad_len);
2256 sym_op->cipher.data.length = cipher_len;
2257 sym_op->cipher.data.offset = auth_offset + cipher_offset;
2259 sym_op->auth.data.length = auth_len;
2260 sym_op->auth.data.offset = auth_offset + cipher_offset;
2266 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2268 struct crypto_testsuite_params *ts_params = &testsuite_params;
2269 struct crypto_unittest_params *ut_params = &unittest_params;
2272 unsigned plaintext_pad_len;
2275 /* Create SNOW3G session */
2276 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2277 tdata->key.data, tdata->key.len,
2278 tdata->aad.len, tdata->digest.len,
2279 RTE_CRYPTO_AUTH_OP_GENERATE);
2283 /* alloc mbuf and set payload */
2284 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2286 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2287 rte_pktmbuf_tailroom(ut_params->ibuf));
2289 /* Append data which is padded to a multiple of */
2290 /* the algorithms block size */
2291 plaintext_pad_len = tdata->plaintext.len >> 3;
2292 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2294 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2296 /* Create SNOW3G opertaion */
2297 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2298 tdata->aad.data, tdata->aad.len,
2299 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2300 tdata->validAuthLenInBits.len,
2301 tdata->validAuthOffsetLenInBits.len);
2305 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2307 ut_params->obuf = ut_params->op->sym->m_src;
2308 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2309 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2310 + plaintext_pad_len + tdata->aad.len;
2313 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2316 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2317 "Snow3G Generated auth tag not as expected");
2323 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2325 struct crypto_testsuite_params *ts_params = &testsuite_params;
2326 struct crypto_unittest_params *ut_params = &unittest_params;
2329 unsigned plaintext_pad_len;
2332 /* Create SNOW3G session */
2333 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2334 tdata->key.data, tdata->key.len,
2335 tdata->aad.len, tdata->digest.len,
2336 RTE_CRYPTO_AUTH_OP_VERIFY);
2339 /* alloc mbuf and set payload */
2340 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2342 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2343 rte_pktmbuf_tailroom(ut_params->ibuf));
2345 /* Append data which is padded to a multiple */
2346 /* of the algorithms block size */
2347 plaintext_pad_len = tdata->plaintext.len >> 3;
2348 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2350 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2352 /* Create SNOW3G operation */
2353 retval = create_snow3g_hash_operation(tdata->digest.data,
2355 tdata->aad.data, tdata->aad.len,
2357 RTE_CRYPTO_AUTH_OP_VERIFY,
2358 tdata->validAuthLenInBits.len,
2359 tdata->validAuthOffsetLenInBits.len);
2363 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2365 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2366 ut_params->obuf = ut_params->op->sym->m_src;
2367 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2368 + plaintext_pad_len + tdata->aad.len;
2371 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2381 test_snow3g_hash_generate_test_case_1(void)
2383 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2387 test_snow3g_hash_generate_test_case_2(void)
2389 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2393 test_snow3g_hash_generate_test_case_3(void)
2395 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2399 test_snow3g_hash_verify_test_case_1(void)
2401 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2406 test_snow3g_hash_verify_test_case_2(void)
2408 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2412 test_snow3g_hash_verify_test_case_3(void)
2414 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2418 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2420 struct crypto_testsuite_params *ts_params = &testsuite_params;
2421 struct crypto_unittest_params *ut_params = &unittest_params;
2425 uint8_t *plaintext, *ciphertext;
2426 uint8_t plaintext_pad_len;
2427 uint8_t lastByteValidBits = 8;
2428 uint8_t lastByteMask = 0xFF;
2430 /* Create SNOW3G session */
2431 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2432 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2433 tdata->key.data, tdata->key.len);
2437 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2439 /* Clear mbuf payload */
2440 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2441 rte_pktmbuf_tailroom(ut_params->ibuf));
2444 * Append data which is padded to a
2445 * multiple of the algorithms block size
2447 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2448 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2450 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2452 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2454 #ifdef RTE_APP_TEST_DEBUG
2455 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2457 /* Create SNOW3G operation */
2458 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2459 tdata->validCipherLenInBits.len,
2460 tdata->validCipherOffsetLenInBits.len);
2464 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2466 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2468 ut_params->obuf = ut_params->op->sym->m_src;
2469 if (ut_params->obuf)
2470 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2473 ciphertext = plaintext;
2475 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2476 if (lastByteValidBits == 0)
2477 lastByteValidBits = 8;
2478 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2479 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2481 #ifdef RTE_APP_TEST_DEBUG
2482 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2485 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2487 tdata->ciphertext.data,
2488 tdata->ciphertext.len >> 3,
2489 "Snow3G Ciphertext data not as expected");
2493 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2495 struct crypto_testsuite_params *ts_params = &testsuite_params;
2496 struct crypto_unittest_params *ut_params = &unittest_params;
2500 uint8_t *plaintext, *ciphertext;
2501 uint8_t ciphertext_pad_len;
2502 uint8_t lastByteValidBits = 8;
2503 uint8_t lastByteMask = 0xFF;
2505 /* Create SNOW3G session */
2506 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2507 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2508 tdata->key.data, tdata->key.len);
2512 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2514 /* Clear mbuf payload */
2515 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2516 rte_pktmbuf_tailroom(ut_params->ibuf));
2519 * Append data which is padded to a
2520 * multiple of the algorithms block size
2522 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2524 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2525 ciphertext_pad_len);
2526 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2528 #ifdef RTE_APP_TEST_DEBUG
2529 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2531 /* Create SNOW3G operation */
2532 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2533 tdata->validCipherLenInBits.len,
2534 tdata->validCipherOffsetLenInBits.len);
2538 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2540 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2541 ut_params->obuf = ut_params->op->sym->m_src;
2542 if (ut_params->obuf)
2543 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2546 plaintext = ciphertext;
2547 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2548 if (lastByteValidBits == 0)
2549 lastByteValidBits = 8;
2550 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2551 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2553 #ifdef RTE_APP_TEST_DEBUG
2554 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2557 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2558 tdata->plaintext.data,
2559 tdata->plaintext.len >> 3,
2560 "Snow3G Plaintext data not as expected");
2565 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2567 struct crypto_testsuite_params *ts_params = &testsuite_params;
2568 struct crypto_unittest_params *ut_params = &unittest_params;
2572 uint8_t *plaintext, *ciphertext;
2573 uint8_t plaintext_pad_len;
2574 uint8_t lastByteValidBits = 8;
2575 uint8_t lastByteMask = 0xFF;
2577 /* Create SNOW3G session */
2578 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2579 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2580 RTE_CRYPTO_AUTH_OP_GENERATE,
2581 tdata->key.data, tdata->key.len,
2582 tdata->aad.len, tdata->digest.len);
2585 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2587 /* clear mbuf payload */
2588 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2589 rte_pktmbuf_tailroom(ut_params->ibuf));
2591 /* Append data which is padded to a multiple */
2592 /* of the algorithms block size */
2593 plaintext_pad_len = tdata->plaintext.len >> 3;
2595 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2597 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2599 #ifdef RTE_APP_TEST_DEBUG
2600 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2603 /* Create SNOW3G operation */
2604 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2605 tdata->digest.len, tdata->aad.data,
2606 tdata->aad.len, /*tdata->plaintext.len,*/
2607 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2608 tdata->iv.data, tdata->iv.len,
2609 tdata->validCipherLenInBits.len,
2610 tdata->validCipherOffsetLenInBits.len,
2611 tdata->validAuthLenInBits.len,
2612 tdata->validAuthOffsetLenInBits.len);
2616 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2618 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2619 ut_params->obuf = ut_params->op->sym->m_src;
2620 if (ut_params->obuf)
2621 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2624 ciphertext = plaintext;
2625 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2626 if (lastByteValidBits == 0)
2627 lastByteValidBits = 8;
2628 lastByteMask = lastByteMask << (8-lastByteValidBits);
2629 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2631 #ifdef RTE_APP_TEST_DEBUG
2632 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2635 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2637 tdata->ciphertext.data,
2638 tdata->ciphertext.len >> 3,
2639 "Snow3G Ciphertext data not as expected");
2641 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2642 + plaintext_pad_len + tdata->aad.len;
2645 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2648 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2649 "Snow3G Generated auth tag not as expected");
2653 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2655 struct crypto_testsuite_params *ts_params = &testsuite_params;
2656 struct crypto_unittest_params *ut_params = &unittest_params;
2660 uint8_t *plaintext, *ciphertext;
2661 uint8_t plaintext_pad_len;
2662 uint8_t lastByteValidBits = 8;
2663 uint8_t lastByteMask = 0xFF;
2665 /* Create SNOW3G session */
2666 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2667 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2668 RTE_CRYPTO_AUTH_OP_GENERATE,
2669 tdata->key.data, tdata->key.len,
2670 tdata->aad.len, tdata->digest.len);
2674 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2676 /* clear mbuf payload */
2677 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2678 rte_pktmbuf_tailroom(ut_params->ibuf));
2680 /* Append data which is padded to a multiple */
2681 /* of the algorithms block size */
2682 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2684 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2686 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2688 #ifdef RTE_APP_TEST_DEBUG
2689 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2692 /* Create SNOW3G operation */
2693 retval = create_snow3g_auth_cipher_operation(
2695 tdata->iv.data, tdata->iv.len,
2696 tdata->aad.data, tdata->aad.len,
2698 tdata->validCipherLenInBits.len,
2699 tdata->validCipherOffsetLenInBits.len,
2700 tdata->validAuthLenInBits.len,
2701 tdata->validAuthOffsetLenInBits.len
2707 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2709 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2710 ut_params->obuf = ut_params->op->sym->m_src;
2711 if (ut_params->obuf)
2712 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2713 + tdata->aad.len + tdata->iv.len;
2715 ciphertext = plaintext;
2717 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2718 if (lastByteValidBits == 0)
2719 lastByteValidBits = 8;
2720 lastByteMask = lastByteMask << (8-lastByteValidBits);
2721 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2722 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2723 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2724 #ifdef RTE_APP_TEST_DEBUG
2725 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2728 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2730 tdata->ciphertext.data,
2731 tdata->ciphertext.len >> 3,
2732 "Snow3G Ciphertext data not as expected");
2735 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2738 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2739 "Snow3G Generated auth tag not as expected");
2744 test_snow3g_encryption_test_case_1(void)
2746 return test_snow3g_encryption(&snow3g_test_case_1);
2750 test_snow3g_encryption_test_case_2(void)
2752 return test_snow3g_encryption(&snow3g_test_case_2);
2756 test_snow3g_encryption_test_case_3(void)
2758 return test_snow3g_encryption(&snow3g_test_case_3);
2762 test_snow3g_encryption_test_case_4(void)
2764 return test_snow3g_encryption(&snow3g_test_case_4);
2768 test_snow3g_encryption_test_case_5(void)
2770 return test_snow3g_encryption(&snow3g_test_case_5);
2774 test_snow3g_decryption_test_case_1(void)
2776 return test_snow3g_decryption(&snow3g_test_case_1);
2780 test_snow3g_decryption_test_case_2(void)
2782 return test_snow3g_decryption(&snow3g_test_case_2);
2786 test_snow3g_decryption_test_case_3(void)
2788 return test_snow3g_decryption(&snow3g_test_case_3);
2792 test_snow3g_decryption_test_case_4(void)
2794 return test_snow3g_decryption(&snow3g_test_case_4);
2798 test_snow3g_decryption_test_case_5(void)
2800 return test_snow3g_decryption(&snow3g_test_case_5);
2803 test_snow3g_authenticated_encryption_test_case_1(void)
2805 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2809 test_snow3g_encrypted_authentication_test_case_1(void)
2811 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2814 /* ***** AES-GCM Tests ***** */
2817 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2818 const uint8_t *key, const uint8_t key_len,
2819 const uint8_t aad_len, const uint8_t auth_len)
2821 uint8_t cipher_key[key_len];
2823 struct crypto_unittest_params *ut_params = &unittest_params;
2826 memcpy(cipher_key, key, key_len);
2828 /* Setup Cipher Parameters */
2829 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2830 ut_params->cipher_xform.next = NULL;
2832 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2833 ut_params->cipher_xform.cipher.op = op;
2834 ut_params->cipher_xform.cipher.key.data = cipher_key;
2835 ut_params->cipher_xform.cipher.key.length = key_len;
2837 #ifdef RTE_APP_TEST_DEBUG
2838 rte_hexdump(stdout, "key:", key, key_len);
2840 /* Setup Authentication Parameters */
2841 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2842 ut_params->auth_xform.next = NULL;
2844 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2846 ut_params->auth_xform.auth.digest_length = auth_len;
2847 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2848 ut_params->auth_xform.auth.key.length = 0;
2849 ut_params->auth_xform.auth.key.data = NULL;
2851 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2852 ut_params->cipher_xform.next = &ut_params->auth_xform;
2854 /* Create Crypto session*/
2855 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2856 &ut_params->cipher_xform);
2857 } else {/* Create Crypto session*/
2858 ut_params->auth_xform.next = &ut_params->cipher_xform;
2859 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2860 &ut_params->auth_xform);
2863 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2869 create_gcm_operation(enum rte_crypto_cipher_operation op,
2870 const uint8_t *auth_tag, const unsigned auth_tag_len,
2871 const uint8_t *iv, const unsigned iv_len,
2872 const uint8_t *aad, const unsigned aad_len,
2873 const unsigned data_len, unsigned data_pad_len)
2875 struct crypto_testsuite_params *ts_params = &testsuite_params;
2876 struct crypto_unittest_params *ut_params = &unittest_params;
2878 unsigned iv_pad_len = 0, aad_buffer_len;
2880 /* Generate Crypto op data structure */
2881 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2882 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2883 TEST_ASSERT_NOT_NULL(ut_params->op,
2884 "Failed to allocate symmetric crypto operation struct");
2886 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2890 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2891 ut_params->ibuf, auth_tag_len);
2892 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2893 "no room to append digest");
2894 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2895 ut_params->ibuf, data_pad_len);
2896 sym_op->auth.digest.length = auth_tag_len;
2898 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2899 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2900 #ifdef RTE_APP_TEST_DEBUG
2901 rte_hexdump(stdout, "digest:",
2902 ut_params->op->digest.data,
2903 ut_params->op->digest.length);
2908 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2910 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2911 ut_params->ibuf, iv_pad_len);
2912 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2914 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2915 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2916 sym_op->cipher.iv.length = iv_pad_len;
2918 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2922 sym_op->cipher.iv.data[15] = 1;
2925 * Always allocate the aad up to the block size.
2926 * The cryptodev API calls out -
2927 * - the array must be big enough to hold the AAD, plus any
2928 * space to round this up to the nearest multiple of the
2929 * block size (16 bytes).
2931 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2933 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2934 ut_params->ibuf, aad_buffer_len);
2935 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2936 "no room to prepend aad");
2937 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2939 sym_op->auth.aad.length = aad_len;
2941 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2942 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2944 #ifdef RTE_APP_TEST_DEBUG
2945 rte_hexdump(stdout, "iv:", ut_params->op->iv.data, iv_pad_len);
2946 rte_hexdump(stdout, "aad:",
2947 ut_params->op->additional_auth.data, aad_len);
2949 sym_op->cipher.data.length = data_len;
2950 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2952 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2953 sym_op->auth.data.length = data_len;
2959 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2961 struct crypto_testsuite_params *ts_params = &testsuite_params;
2962 struct crypto_unittest_params *ut_params = &unittest_params;
2966 uint8_t *plaintext, *ciphertext, *auth_tag;
2967 uint16_t plaintext_pad_len;
2969 /* Create GCM session */
2970 retval = create_gcm_session(ts_params->valid_devs[0],
2971 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2972 tdata->key.data, tdata->key.len,
2973 tdata->aad.len, tdata->auth_tag.len);
2978 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2980 /* clear mbuf payload */
2981 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2982 rte_pktmbuf_tailroom(ut_params->ibuf));
2985 * Append data which is padded to a multiple
2986 * of the algorithms block size
2988 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2990 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2992 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2994 #ifdef RTE_APP_TEST_DEBUG
2995 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2997 /* Create GCM opertaion */
2998 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2999 tdata->auth_tag.data, tdata->auth_tag.len,
3000 tdata->iv.data, tdata->iv.len,
3001 tdata->aad.data, tdata->aad.len,
3002 tdata->plaintext.len, plaintext_pad_len);
3006 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3008 ut_params->op->sym->m_src = ut_params->ibuf;
3010 /* Process crypto operation */
3011 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3012 ut_params->op), "failed to process sym crypto op");
3014 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3015 "crypto op processing failed");
3017 if (ut_params->op->sym->m_dst) {
3018 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3020 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3021 uint8_t *, plaintext_pad_len);
3023 ciphertext = plaintext;
3024 auth_tag = plaintext + plaintext_pad_len;
3027 #ifdef RTE_APP_TEST_DEBUG
3028 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3029 rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3032 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3034 tdata->ciphertext.data,
3035 tdata->ciphertext.len,
3036 "GCM Ciphertext data not as expected");
3038 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3040 tdata->auth_tag.data,
3041 tdata->auth_tag.len,
3042 "GCM Generated auth tag not as expected");
3049 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3051 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3055 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3057 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3061 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3063 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3067 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3069 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3073 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3075 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3079 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3081 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3085 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3087 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3091 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3093 struct crypto_testsuite_params *ts_params = &testsuite_params;
3094 struct crypto_unittest_params *ut_params = &unittest_params;
3098 uint8_t *plaintext, *ciphertext;
3099 uint16_t ciphertext_pad_len;
3101 /* Create GCM session */
3102 retval = create_gcm_session(ts_params->valid_devs[0],
3103 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3104 tdata->key.data, tdata->key.len,
3105 tdata->aad.len, tdata->auth_tag.len);
3110 /* alloc mbuf and set payload */
3111 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3113 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3114 rte_pktmbuf_tailroom(ut_params->ibuf));
3116 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3118 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3119 ciphertext_pad_len);
3120 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3122 #ifdef RTE_APP_TEST_DEBUG
3123 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3125 /* Create GCM opertaion */
3126 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3127 tdata->auth_tag.data, tdata->auth_tag.len,
3128 tdata->iv.data, tdata->iv.len,
3129 tdata->aad.data, tdata->aad.len,
3130 tdata->ciphertext.len, ciphertext_pad_len);
3135 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3137 ut_params->op->sym->m_src = ut_params->ibuf;
3139 /* Process crypto operation */
3140 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3141 ut_params->op), "failed to process sym crypto op");
3143 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3144 "crypto op processing failed");
3146 if (ut_params->op->sym->m_dst)
3147 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3150 plaintext = ciphertext;
3152 #ifdef RTE_APP_TEST_DEBUG
3153 rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3156 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3158 tdata->plaintext.data,
3159 tdata->plaintext.len,
3160 "GCM plaintext data not as expected");
3162 TEST_ASSERT_EQUAL(ut_params->op->status,
3163 RTE_CRYPTO_OP_STATUS_SUCCESS,
3164 "GCM authentication failed");
3169 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3171 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3175 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3177 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3181 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3183 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3187 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3189 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3193 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3195 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3199 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3201 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3205 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3207 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3213 struct crypto_testsuite_params *ts_params = &testsuite_params;
3214 struct rte_cryptodev_stats stats;
3215 struct rte_cryptodev *dev;
3216 cryptodev_stats_get_t temp_pfn;
3218 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3219 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3220 &stats) == -ENODEV),
3221 "rte_cryptodev_stats_get invalid dev failed");
3222 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3223 "rte_cryptodev_stats_get invalid Param failed");
3224 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3225 temp_pfn = dev->dev_ops->stats_get;
3226 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3227 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3229 "rte_cryptodev_stats_get invalid Param failed");
3230 dev->dev_ops->stats_get = temp_pfn;
3232 /* Test expected values */
3234 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3236 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3238 "rte_cryptodev_stats_get failed");
3239 TEST_ASSERT((stats.enqueued_count == 1),
3240 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3241 TEST_ASSERT((stats.dequeued_count == 1),
3242 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3243 TEST_ASSERT((stats.enqueue_err_count == 0),
3244 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3245 TEST_ASSERT((stats.dequeue_err_count == 0),
3246 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3248 /* invalid device but should ignore and not reset device stats*/
3249 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3250 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3252 "rte_cryptodev_stats_get failed");
3253 TEST_ASSERT((stats.enqueued_count == 1),
3254 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3256 /* check that a valid reset clears stats */
3257 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3258 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3260 "rte_cryptodev_stats_get failed");
3261 TEST_ASSERT((stats.enqueued_count == 0),
3262 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3263 TEST_ASSERT((stats.dequeued_count == 0),
3264 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3266 return TEST_SUCCESS;
3271 test_multi_session(void)
3273 struct crypto_testsuite_params *ts_params = &testsuite_params;
3274 struct crypto_unittest_params *ut_params = &unittest_params;
3276 struct rte_cryptodev_info dev_info;
3277 struct rte_cryptodev_sym_session **sessions;
3281 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3284 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3286 sessions = rte_malloc(NULL,
3287 (sizeof(struct rte_cryptodev_sym_session *) *
3288 dev_info.sym.max_nb_sessions) + 1, 0);
3290 /* Create multiple crypto sessions*/
3291 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3292 sessions[i] = rte_cryptodev_sym_session_create(
3293 ts_params->valid_devs[0],
3294 &ut_params->auth_xform);
3295 TEST_ASSERT_NOT_NULL(sessions[i],
3296 "Session creation failed at session number %u",
3299 /* Attempt to send a request on each session */
3300 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3301 sessions[i], ut_params, ts_params),
3302 "Failed to perform decrypt on request "
3304 /* free crypto operation structure */
3306 rte_crypto_op_free(ut_params->op);
3309 * free mbuf - both obuf and ibuf are usually the same,
3310 * but rte copes even if we call free twice
3312 if (ut_params->obuf) {
3313 rte_pktmbuf_free(ut_params->obuf);
3314 ut_params->obuf = 0;
3318 /* Next session create should fail */
3319 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3320 &ut_params->auth_xform);
3321 TEST_ASSERT_NULL(sessions[i],
3322 "Session creation succeeded unexpectedly!");
3324 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3325 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3330 return TEST_SUCCESS;
3334 test_not_in_place_crypto(void)
3336 struct crypto_testsuite_params *ts_params = &testsuite_params;
3337 struct crypto_unittest_params *ut_params = &unittest_params;
3338 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3340 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3342 /* Create multiple crypto sessions*/
3344 ut_params->sess = rte_cryptodev_sym_session_create(
3345 ts_params->valid_devs[0], &ut_params->auth_xform);
3347 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3350 /* Generate test mbuf data and digest */
3351 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3353 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
3354 QUOTE_512_BYTES, 0);
3356 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3357 DIGEST_BYTE_LENGTH_SHA512);
3358 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
3360 rte_memcpy(ut_params->digest,
3361 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
3362 DIGEST_BYTE_LENGTH_SHA512);
3364 /* Generate Crypto op data structure */
3365 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3366 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3367 TEST_ASSERT_NOT_NULL(ut_params->op,
3368 "Failed to allocate symmetric crypto operation struct");
3371 /* Set crypto operation data parameters */
3372 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3374 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3376 /* set crypto operation source mbuf */
3377 sym_op->m_src = ut_params->ibuf;
3378 sym_op->m_dst = dst_m;
3380 sym_op->auth.digest.data = ut_params->digest;
3381 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3382 ut_params->ibuf, QUOTE_512_BYTES);
3383 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
3385 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
3386 sym_op->auth.data.length = QUOTE_512_BYTES;
3389 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3390 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
3391 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
3392 ut_params->ibuf, 0);
3393 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
3395 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
3396 CIPHER_IV_LENGTH_AES_CBC);
3398 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
3399 sym_op->cipher.data.length = QUOTE_512_BYTES;
3401 /* Process crypto operation */
3402 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3404 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3406 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3407 "crypto operation processing failed");
3410 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3411 rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
3414 "Plaintext data not as expected");
3416 return TEST_SUCCESS;
3420 test_null_cipher_only_operation(void)
3422 struct crypto_testsuite_params *ts_params = &testsuite_params;
3423 struct crypto_unittest_params *ut_params = &unittest_params;
3425 /* Generate test mbuf data and space for digest */
3426 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3427 catch_22_quote, QUOTE_512_BYTES, 0);
3429 /* Setup Cipher Parameters */
3430 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3431 ut_params->cipher_xform.next = NULL;
3433 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3434 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3436 /* Create Crypto session*/
3437 ut_params->sess = rte_cryptodev_sym_session_create(
3438 ts_params->valid_devs[0], &ut_params->cipher_xform);
3439 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3441 /* Generate Crypto op data structure */
3442 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3443 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3444 TEST_ASSERT_NOT_NULL(ut_params->op,
3445 "Failed to allocate symmetric crypto operation struct");
3447 /* Set crypto operation data parameters */
3448 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3450 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3452 /* set crypto operation source mbuf */
3453 sym_op->m_src = ut_params->ibuf;
3455 sym_op->cipher.data.offset = 0;
3456 sym_op->cipher.data.length = QUOTE_512_BYTES;
3458 /* Process crypto operation */
3459 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3461 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3463 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3464 "crypto operation processing failed");
3467 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3468 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3471 "Ciphertext data not as expected");
3473 return TEST_SUCCESS;
3477 test_null_auth_only_operation(void)
3479 struct crypto_testsuite_params *ts_params = &testsuite_params;
3480 struct crypto_unittest_params *ut_params = &unittest_params;
3482 /* Generate test mbuf data and space for digest */
3483 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3484 catch_22_quote, QUOTE_512_BYTES, 0);
3486 /* Setup HMAC Parameters */
3487 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3488 ut_params->auth_xform.next = NULL;
3490 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3491 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3493 /* Create Crypto session*/
3494 ut_params->sess = rte_cryptodev_sym_session_create(
3495 ts_params->valid_devs[0], &ut_params->auth_xform);
3496 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3498 /* Generate Crypto op data structure */
3499 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3500 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3501 TEST_ASSERT_NOT_NULL(ut_params->op,
3502 "Failed to allocate symmetric crypto operation struct");
3504 /* Set crypto operation data parameters */
3505 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3507 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3509 sym_op->m_src = ut_params->ibuf;
3511 sym_op->auth.data.offset = 0;
3512 sym_op->auth.data.length = QUOTE_512_BYTES;
3514 /* Process crypto operation */
3515 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3517 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3519 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3520 "crypto operation processing failed");
3522 return TEST_SUCCESS;
3526 test_null_cipher_auth_operation(void)
3528 struct crypto_testsuite_params *ts_params = &testsuite_params;
3529 struct crypto_unittest_params *ut_params = &unittest_params;
3531 /* Generate test mbuf data and space for digest */
3532 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3533 catch_22_quote, QUOTE_512_BYTES, 0);
3535 /* Setup Cipher Parameters */
3536 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3537 ut_params->cipher_xform.next = &ut_params->auth_xform;
3539 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3540 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3542 /* Setup HMAC Parameters */
3543 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3544 ut_params->auth_xform.next = NULL;
3546 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3547 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3549 /* Create Crypto session*/
3550 ut_params->sess = rte_cryptodev_sym_session_create(
3551 ts_params->valid_devs[0], &ut_params->cipher_xform);
3552 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3554 /* Generate Crypto op data structure */
3555 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3556 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3557 TEST_ASSERT_NOT_NULL(ut_params->op,
3558 "Failed to allocate symmetric crypto operation struct");
3560 /* Set crypto operation data parameters */
3561 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3563 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3565 sym_op->m_src = ut_params->ibuf;
3567 sym_op->cipher.data.offset = 0;
3568 sym_op->cipher.data.length = QUOTE_512_BYTES;
3570 sym_op->auth.data.offset = 0;
3571 sym_op->auth.data.length = QUOTE_512_BYTES;
3573 /* Process crypto operation */
3574 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3576 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3578 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3579 "crypto operation processing failed");
3582 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3583 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3586 "Ciphertext data not as expected");
3588 return TEST_SUCCESS;
3592 test_null_auth_cipher_operation(void)
3594 struct crypto_testsuite_params *ts_params = &testsuite_params;
3595 struct crypto_unittest_params *ut_params = &unittest_params;
3597 /* Generate test mbuf data and space for digest */
3598 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3599 catch_22_quote, QUOTE_512_BYTES, 0);
3601 /* Setup Cipher Parameters */
3602 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3603 ut_params->cipher_xform.next = NULL;
3605 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3606 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3608 /* Setup HMAC Parameters */
3609 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3610 ut_params->auth_xform.next = &ut_params->cipher_xform;
3612 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3613 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3615 /* Create Crypto session*/
3616 ut_params->sess = rte_cryptodev_sym_session_create(
3617 ts_params->valid_devs[0], &ut_params->cipher_xform);
3618 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3620 /* Generate Crypto op data structure */
3621 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3622 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3623 TEST_ASSERT_NOT_NULL(ut_params->op,
3624 "Failed to allocate symmetric crypto operation struct");
3626 /* Set crypto operation data parameters */
3627 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3629 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3631 sym_op->m_src = ut_params->ibuf;
3633 sym_op->cipher.data.offset = 0;
3634 sym_op->cipher.data.length = QUOTE_512_BYTES;
3636 sym_op->auth.data.offset = 0;
3637 sym_op->auth.data.length = QUOTE_512_BYTES;
3639 /* Process crypto operation */
3640 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3642 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3644 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3645 "crypto operation processing failed");
3648 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3649 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3652 "Ciphertext data not as expected");
3654 return TEST_SUCCESS;
3659 test_null_invalid_operation(void)
3661 struct crypto_testsuite_params *ts_params = &testsuite_params;
3662 struct crypto_unittest_params *ut_params = &unittest_params;
3664 /* Setup Cipher Parameters */
3665 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3666 ut_params->cipher_xform.next = NULL;
3668 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3669 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3671 /* Create Crypto session*/
3672 ut_params->sess = rte_cryptodev_sym_session_create(
3673 ts_params->valid_devs[0], &ut_params->cipher_xform);
3674 TEST_ASSERT_NULL(ut_params->sess,
3675 "Session creation succeeded unexpectedly");
3678 /* Setup HMAC Parameters */
3679 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3680 ut_params->auth_xform.next = NULL;
3682 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3683 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3685 /* Create Crypto session*/
3686 ut_params->sess = rte_cryptodev_sym_session_create(
3687 ts_params->valid_devs[0], &ut_params->auth_xform);
3688 TEST_ASSERT_NULL(ut_params->sess,
3689 "Session creation succeeded unexpectedly");
3691 return TEST_SUCCESS;
3695 #define NULL_BURST_LENGTH (32)
3698 test_null_burst_operation(void)
3700 struct crypto_testsuite_params *ts_params = &testsuite_params;
3701 struct crypto_unittest_params *ut_params = &unittest_params;
3703 unsigned i, burst_len = NULL_BURST_LENGTH;
3705 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3706 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3708 /* Setup Cipher Parameters */
3709 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3710 ut_params->cipher_xform.next = &ut_params->auth_xform;
3712 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3713 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3715 /* Setup HMAC Parameters */
3716 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3717 ut_params->auth_xform.next = NULL;
3719 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3720 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3722 /* Create Crypto session*/
3723 ut_params->sess = rte_cryptodev_sym_session_create(
3724 ts_params->valid_devs[0], &ut_params->cipher_xform);
3725 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3727 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3728 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3729 burst_len, "failed to generate burst of crypto ops");
3731 /* Generate an operation for each mbuf in burst */
3732 for (i = 0; i < burst_len; i++) {
3733 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3735 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3737 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3741 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3743 burst[i]->sym->m_src = m;
3746 /* Process crypto operation */
3747 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3748 0, burst, burst_len),
3750 "Error enqueuing burst");
3752 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3753 0, burst_dequeued, burst_len),
3755 "Error dequeuing burst");
3758 for (i = 0; i < burst_len; i++) {
3760 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3761 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3763 "data not as expected");
3765 rte_pktmbuf_free(burst[i]->sym->m_src);
3766 rte_crypto_op_free(burst[i]);
3769 return TEST_SUCCESS;
3772 static struct unit_test_suite cryptodev_qat_testsuite = {
3773 .suite_name = "Crypto QAT Unit Test Suite",
3774 .setup = testsuite_setup,
3775 .teardown = testsuite_teardown,
3776 .unit_test_cases = {
3777 TEST_CASE_ST(ut_setup, ut_teardown,
3778 test_device_configure_invalid_dev_id),
3779 TEST_CASE_ST(ut_setup, ut_teardown,
3780 test_device_configure_invalid_queue_pair_ids),
3781 TEST_CASE_ST(ut_setup, ut_teardown,
3782 test_queue_pair_descriptor_setup),
3783 TEST_CASE_ST(ut_setup, ut_teardown,
3784 test_multi_session),
3786 TEST_CASE_ST(ut_setup, ut_teardown,
3787 test_AES_CBC_HMAC_SHA1_encrypt_digest),
3788 TEST_CASE_ST(ut_setup, ut_teardown,
3789 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
3791 TEST_CASE_ST(ut_setup, ut_teardown,
3792 test_AES_CBC_HMAC_SHA256_encrypt_digest),
3793 TEST_CASE_ST(ut_setup, ut_teardown,
3794 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3796 TEST_CASE_ST(ut_setup, ut_teardown,
3797 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3798 TEST_CASE_ST(ut_setup, ut_teardown,
3799 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3801 TEST_CASE_ST(ut_setup, ut_teardown,
3802 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3803 TEST_CASE_ST(ut_setup, ut_teardown,
3804 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3805 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3807 /** AES GCM Authenticated Encryption */
3808 TEST_CASE_ST(ut_setup, ut_teardown,
3809 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3810 TEST_CASE_ST(ut_setup, ut_teardown,
3811 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3812 TEST_CASE_ST(ut_setup, ut_teardown,
3813 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3814 TEST_CASE_ST(ut_setup, ut_teardown,
3815 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3816 TEST_CASE_ST(ut_setup, ut_teardown,
3817 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3818 TEST_CASE_ST(ut_setup, ut_teardown,
3819 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3820 TEST_CASE_ST(ut_setup, ut_teardown,
3821 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3823 /** AES GCM Authenticated Decryption */
3824 TEST_CASE_ST(ut_setup, ut_teardown,
3825 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3826 TEST_CASE_ST(ut_setup, ut_teardown,
3827 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3828 TEST_CASE_ST(ut_setup, ut_teardown,
3829 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3830 TEST_CASE_ST(ut_setup, ut_teardown,
3831 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3832 TEST_CASE_ST(ut_setup, ut_teardown,
3833 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3834 TEST_CASE_ST(ut_setup, ut_teardown,
3835 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3836 TEST_CASE_ST(ut_setup, ut_teardown,
3837 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3839 /** Snow3G encrypt only (UEA2) */
3840 TEST_CASE_ST(ut_setup, ut_teardown,
3841 test_snow3g_encryption_test_case_1),
3842 TEST_CASE_ST(ut_setup, ut_teardown,
3843 test_snow3g_encryption_test_case_2),
3844 TEST_CASE_ST(ut_setup, ut_teardown,
3845 test_snow3g_encryption_test_case_3),
3846 TEST_CASE_ST(ut_setup, ut_teardown,
3847 test_snow3g_encryption_test_case_4),
3848 TEST_CASE_ST(ut_setup, ut_teardown,
3849 test_snow3g_encryption_test_case_5),
3851 /** Snow3G decrypt only (UEA2) */
3852 TEST_CASE_ST(ut_setup, ut_teardown,
3853 test_snow3g_decryption_test_case_1),
3854 TEST_CASE_ST(ut_setup, ut_teardown,
3855 test_snow3g_decryption_test_case_2),
3856 TEST_CASE_ST(ut_setup, ut_teardown,
3857 test_snow3g_decryption_test_case_3),
3858 TEST_CASE_ST(ut_setup, ut_teardown,
3859 test_snow3g_decryption_test_case_4),
3860 TEST_CASE_ST(ut_setup, ut_teardown,
3861 test_snow3g_decryption_test_case_5),
3862 TEST_CASE_ST(ut_setup, ut_teardown,
3863 test_snow3g_hash_generate_test_case_1),
3864 TEST_CASE_ST(ut_setup, ut_teardown,
3865 test_snow3g_hash_generate_test_case_2),
3866 TEST_CASE_ST(ut_setup, ut_teardown,
3867 test_snow3g_hash_generate_test_case_3),
3868 TEST_CASE_ST(ut_setup, ut_teardown,
3869 test_snow3g_hash_verify_test_case_1),
3870 TEST_CASE_ST(ut_setup, ut_teardown,
3871 test_snow3g_hash_verify_test_case_2),
3872 TEST_CASE_ST(ut_setup, ut_teardown,
3873 test_snow3g_hash_verify_test_case_3),
3874 TEST_CASE_ST(ut_setup, ut_teardown,
3875 test_snow3g_authenticated_encryption_test_case_1),
3876 TEST_CASE_ST(ut_setup, ut_teardown,
3877 test_snow3g_encrypted_authentication_test_case_1),
3878 TEST_CASES_END() /**< NULL terminate unit test array */
3882 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3883 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3884 .setup = testsuite_setup,
3885 .teardown = testsuite_teardown,
3886 .unit_test_cases = {
3887 TEST_CASE_ST(ut_setup, ut_teardown,
3888 test_AES_CBC_HMAC_SHA1_encrypt_digest),
3889 TEST_CASE_ST(ut_setup, ut_teardown,
3890 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
3892 TEST_CASE_ST(ut_setup, ut_teardown,
3893 test_AES_CBC_HMAC_SHA256_encrypt_digest),
3894 TEST_CASE_ST(ut_setup, ut_teardown,
3895 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3897 TEST_CASE_ST(ut_setup, ut_teardown,
3898 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3899 TEST_CASE_ST(ut_setup, ut_teardown,
3900 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3902 TEST_CASE_ST(ut_setup, ut_teardown,
3903 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3904 TEST_CASE_ST(ut_setup, ut_teardown,
3905 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3907 TEST_CASE_ST(ut_setup, ut_teardown,
3908 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
3910 TEST_CASE_ST(ut_setup, ut_teardown,
3911 test_not_in_place_crypto),
3913 TEST_CASES_END() /**< NULL terminate unit test array */
3917 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
3918 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3919 .setup = testsuite_setup,
3920 .teardown = testsuite_teardown,
3921 .unit_test_cases = {
3922 /** AES GCM Authenticated Encryption */
3923 TEST_CASE_ST(ut_setup, ut_teardown,
3924 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3925 TEST_CASE_ST(ut_setup, ut_teardown,
3926 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3927 TEST_CASE_ST(ut_setup, ut_teardown,
3928 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3929 TEST_CASE_ST(ut_setup, ut_teardown,
3930 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3931 TEST_CASE_ST(ut_setup, ut_teardown,
3932 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3933 TEST_CASE_ST(ut_setup, ut_teardown,
3934 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3935 TEST_CASE_ST(ut_setup, ut_teardown,
3936 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3938 /** AES GCM Authenticated Decryption */
3939 TEST_CASE_ST(ut_setup, ut_teardown,
3940 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3941 TEST_CASE_ST(ut_setup, ut_teardown,
3942 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3943 TEST_CASE_ST(ut_setup, ut_teardown,
3944 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3945 TEST_CASE_ST(ut_setup, ut_teardown,
3946 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3947 TEST_CASE_ST(ut_setup, ut_teardown,
3948 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3949 TEST_CASE_ST(ut_setup, ut_teardown,
3950 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3951 TEST_CASE_ST(ut_setup, ut_teardown,
3952 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3954 TEST_CASES_END() /**< NULL terminate unit test array */
3958 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
3959 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3960 .setup = testsuite_setup,
3961 .teardown = testsuite_teardown,
3962 .unit_test_cases = {
3963 /** Snow3G encrypt only (UEA2) */
3964 TEST_CASE_ST(ut_setup, ut_teardown,
3965 test_snow3g_encryption_test_case_1),
3966 TEST_CASE_ST(ut_setup, ut_teardown,
3967 test_snow3g_encryption_test_case_2),
3968 TEST_CASE_ST(ut_setup, ut_teardown,
3969 test_snow3g_encryption_test_case_3),
3970 TEST_CASE_ST(ut_setup, ut_teardown,
3971 test_snow3g_encryption_test_case_4),
3972 TEST_CASE_ST(ut_setup, ut_teardown,
3973 test_snow3g_encryption_test_case_5),
3976 /** Snow3G decrypt only (UEA2) */
3977 TEST_CASE_ST(ut_setup, ut_teardown,
3978 test_snow3g_decryption_test_case_1),
3979 TEST_CASE_ST(ut_setup, ut_teardown,
3980 test_snow3g_decryption_test_case_2),
3981 TEST_CASE_ST(ut_setup, ut_teardown,
3982 test_snow3g_decryption_test_case_3),
3983 TEST_CASE_ST(ut_setup, ut_teardown,
3984 test_snow3g_decryption_test_case_4),
3985 TEST_CASE_ST(ut_setup, ut_teardown,
3986 test_snow3g_decryption_test_case_5),
3987 TEST_CASE_ST(ut_setup, ut_teardown,
3988 test_snow3g_hash_generate_test_case_1),
3989 TEST_CASE_ST(ut_setup, ut_teardown,
3990 test_snow3g_hash_generate_test_case_2),
3991 TEST_CASE_ST(ut_setup, ut_teardown,
3992 test_snow3g_hash_generate_test_case_3),
3993 TEST_CASE_ST(ut_setup, ut_teardown,
3994 test_snow3g_hash_verify_test_case_1),
3995 TEST_CASE_ST(ut_setup, ut_teardown,
3996 test_snow3g_hash_verify_test_case_2),
3997 TEST_CASE_ST(ut_setup, ut_teardown,
3998 test_snow3g_hash_verify_test_case_3),
3999 TEST_CASE_ST(ut_setup, ut_teardown,
4000 test_snow3g_authenticated_encryption_test_case_1),
4001 TEST_CASE_ST(ut_setup, ut_teardown,
4002 test_snow3g_encrypted_authentication_test_case_1),
4004 TEST_CASES_END() /**< NULL terminate unit test array */
4008 static struct unit_test_suite cryptodev_null_testsuite = {
4009 .suite_name = "Crypto Device NULL Unit Test Suite",
4010 .setup = testsuite_setup,
4011 .teardown = testsuite_teardown,
4012 .unit_test_cases = {
4013 TEST_CASE_ST(ut_setup, ut_teardown,
4014 test_null_auth_only_operation),
4015 TEST_CASE_ST(ut_setup, ut_teardown,
4016 test_null_cipher_only_operation),
4017 TEST_CASE_ST(ut_setup, ut_teardown,
4018 test_null_cipher_auth_operation),
4019 TEST_CASE_ST(ut_setup, ut_teardown,
4020 test_null_auth_cipher_operation),
4021 TEST_CASE_ST(ut_setup, ut_teardown,
4022 test_null_invalid_operation),
4023 TEST_CASE_ST(ut_setup, ut_teardown,
4024 test_null_burst_operation),
4026 TEST_CASES_END() /**< NULL terminate unit test array */
4031 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4033 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4034 return unit_test_suite_runner(&cryptodev_qat_testsuite);
4036 static struct test_command cryptodev_qat_cmd = {
4037 .command = "cryptodev_qat_autotest",
4038 .callback = test_cryptodev_qat,
4042 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4044 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4046 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4049 static struct test_command cryptodev_aesni_mb_cmd = {
4050 .command = "cryptodev_aesni_mb_autotest",
4051 .callback = test_cryptodev_aesni_mb,
4055 test_cryptodev_aesni_gcm(void)
4057 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4059 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4062 static struct test_command cryptodev_aesni_gcm_cmd = {
4063 .command = "cryptodev_aesni_gcm_autotest",
4064 .callback = test_cryptodev_aesni_gcm,
4068 test_cryptodev_null(void)
4070 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4072 return unit_test_suite_runner(&cryptodev_null_testsuite);
4075 static struct test_command cryptodev_null_cmd = {
4076 .command = "cryptodev_null_autotest",
4077 .callback = test_cryptodev_null,
4081 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4083 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4085 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4088 static struct test_command cryptodev_sw_snow3g_cmd = {
4089 .command = "cryptodev_sw_snow3g_autotest",
4090 .callback = test_cryptodev_sw_snow3g,
4093 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4094 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4095 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4096 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4097 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);