4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
44 #include "test_cryptodev.h"
46 #include "test_cryptodev_aes.h"
47 #include "test_cryptodev_kasumi_test_vectors.h"
48 #include "test_cryptodev_kasumi_hash_test_vectors.h"
49 #include "test_cryptodev_snow3g_test_vectors.h"
50 #include "test_cryptodev_snow3g_hash_test_vectors.h"
51 #include "test_cryptodev_gcm_test_vectors.h"
52 #include "test_cryptodev_hmac_test_vectors.h"
54 static enum rte_cryptodev_type gbl_cryptodev_type;
56 struct crypto_testsuite_params {
57 struct rte_mempool *mbuf_pool;
58 struct rte_mempool *op_mpool;
59 struct rte_cryptodev_config conf;
60 struct rte_cryptodev_qp_conf qp_conf;
62 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
63 uint8_t valid_dev_count;
66 struct crypto_unittest_params {
67 struct rte_crypto_sym_xform cipher_xform;
68 struct rte_crypto_sym_xform auth_xform;
70 struct rte_cryptodev_sym_session *sess;
72 struct rte_crypto_op *op;
74 struct rte_mbuf *obuf, *ibuf;
79 #define ALIGN_POW2_ROUNDUP(num, align) \
80 (((num) + (align) - 1) & ~((align) - 1))
83 * Forward declarations.
86 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
87 struct crypto_unittest_params *ut_params);
90 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
91 struct crypto_unittest_params *ut_params,
92 struct crypto_testsuite_params *ts_param);
94 static struct rte_mbuf *
95 setup_test_string(struct rte_mempool *mpool,
96 const char *string, size_t len, uint8_t blocksize)
98 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
99 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
101 memset(m->buf_addr, 0, m->buf_len);
103 char *dst = rte_pktmbuf_append(m, t_len);
110 rte_memcpy(dst, string, t_len);
112 memset(dst, 0, t_len);
118 /* Get number of bytes in X bits (rounding up) */
120 ceil_byte_length(uint32_t num_bits)
123 return ((num_bits >> 3) + 1);
125 return (num_bits >> 3);
128 static struct rte_crypto_op *
129 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
131 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
132 printf("Error sending packet for encryption");
138 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
144 static struct crypto_testsuite_params testsuite_params = { NULL };
145 static struct crypto_unittest_params unittest_params;
148 testsuite_setup(void)
150 struct crypto_testsuite_params *ts_params = &testsuite_params;
151 struct rte_cryptodev_info info;
152 unsigned i, nb_devs, dev_id;
156 memset(ts_params, 0, sizeof(*ts_params));
158 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
159 if (ts_params->mbuf_pool == NULL) {
160 /* Not already created so create */
161 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
163 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
165 if (ts_params->mbuf_pool == NULL) {
166 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
171 ts_params->op_mpool = rte_crypto_op_pool_create(
172 "MBUF_CRYPTO_SYM_OP_POOL",
173 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
174 NUM_MBUFS, MBUF_CACHE_SIZE,
176 sizeof(struct rte_crypto_sym_xform),
178 if (ts_params->op_mpool == NULL) {
179 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
183 /* Create 2 AESNI MB devices if required */
184 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
185 nb_devs = rte_cryptodev_count_devtype(
186 RTE_CRYPTODEV_AESNI_MB_PMD);
188 for (i = nb_devs; i < 2; i++) {
189 ret = rte_eal_vdev_init(
190 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
192 TEST_ASSERT(ret == 0,
193 "Failed to create instance %u of"
195 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
200 /* Create 2 AESNI GCM devices if required */
201 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
202 nb_devs = rte_cryptodev_count_devtype(
203 RTE_CRYPTODEV_AESNI_GCM_PMD);
205 for (i = nb_devs; i < 2; i++) {
206 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
207 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
208 "Failed to create instance %u of"
210 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
215 /* Create 2 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 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
222 "Failed to create instance %u of"
224 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
229 /* Create 2 KASUMI devices if required */
230 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
231 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
233 for (i = nb_devs; i < 2; i++) {
234 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
235 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
236 "Failed to create instance %u of"
238 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
243 /* Create 2 NULL devices if required */
244 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
245 nb_devs = rte_cryptodev_count_devtype(
246 RTE_CRYPTODEV_NULL_PMD);
248 for (i = nb_devs; i < 2; i++) {
249 int dev_id = rte_eal_vdev_init(
250 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
252 TEST_ASSERT(dev_id >= 0,
253 "Failed to create instance %u of"
255 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD));
260 nb_devs = rte_cryptodev_count();
262 RTE_LOG(ERR, USER1, "No crypto devices found?");
266 /* Create list of valid crypto devs */
267 for (i = 0; i < nb_devs; i++) {
268 rte_cryptodev_info_get(i, &info);
269 if (info.dev_type == gbl_cryptodev_type)
270 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
273 if (ts_params->valid_dev_count < 1)
276 /* Set up all the qps on the first of the valid devices found */
277 for (i = 0; i < 1; i++) {
278 dev_id = ts_params->valid_devs[i];
280 rte_cryptodev_info_get(dev_id, &info);
283 * Since we can't free and re-allocate queue memory always set
284 * the queues on this device up to max size first so enough
285 * memory is allocated for any later re-configures needed by
289 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
290 ts_params->conf.socket_id = SOCKET_ID_ANY;
291 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
293 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
295 "Failed to configure cryptodev %u with %u qps",
296 dev_id, ts_params->conf.nb_queue_pairs);
298 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
300 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
301 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
302 dev_id, qp_id, &ts_params->qp_conf,
303 rte_cryptodev_socket_id(dev_id)),
304 "Failed to setup queue pair %u on "
314 testsuite_teardown(void)
316 struct crypto_testsuite_params *ts_params = &testsuite_params;
318 if (ts_params->mbuf_pool != NULL) {
319 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
320 rte_mempool_avail_count(ts_params->mbuf_pool));
323 if (ts_params->op_mpool != NULL) {
324 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
325 rte_mempool_avail_count(ts_params->op_mpool));
333 struct crypto_testsuite_params *ts_params = &testsuite_params;
334 struct crypto_unittest_params *ut_params = &unittest_params;
338 /* Clear unit test parameters before running test */
339 memset(ut_params, 0, sizeof(*ut_params));
341 /* Reconfigure device to default parameters */
342 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
343 ts_params->conf.socket_id = SOCKET_ID_ANY;
344 ts_params->conf.session_mp.nb_objs =
345 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
346 DEFAULT_NUM_OPS_INFLIGHT :
347 DEFAULT_NUM_OPS_INFLIGHT;
349 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
351 "Failed to configure cryptodev %u",
352 ts_params->valid_devs[0]);
355 * Now reconfigure queues to size we actually want to use in this
358 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
360 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
361 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
362 ts_params->valid_devs[0], qp_id,
364 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
365 "Failed to setup queue pair %u on cryptodev %u",
366 qp_id, ts_params->valid_devs[0]);
370 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
372 /* Start the device */
373 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
374 "Failed to start cryptodev %u",
375 ts_params->valid_devs[0]);
383 struct crypto_testsuite_params *ts_params = &testsuite_params;
384 struct crypto_unittest_params *ut_params = &unittest_params;
385 struct rte_cryptodev_stats stats;
387 /* free crypto session structure */
388 if (ut_params->sess) {
389 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
391 ut_params->sess = NULL;
394 /* free crypto operation structure */
396 rte_crypto_op_free(ut_params->op);
399 * free mbuf - both obuf and ibuf are usually the same,
400 * so check if they point at the same address is necessary,
401 * to avoid freeing the mbuf twice.
403 if (ut_params->obuf) {
404 rte_pktmbuf_free(ut_params->obuf);
405 if (ut_params->ibuf == ut_params->obuf)
409 if (ut_params->ibuf) {
410 rte_pktmbuf_free(ut_params->ibuf);
414 if (ts_params->mbuf_pool != NULL)
415 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
416 rte_mempool_avail_count(ts_params->mbuf_pool));
418 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
420 /* Stop the device */
421 rte_cryptodev_stop(ts_params->valid_devs[0]);
425 test_device_configure_invalid_dev_id(void)
427 struct crypto_testsuite_params *ts_params = &testsuite_params;
428 uint16_t dev_id, num_devs = 0;
430 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
431 "Need at least %d devices for test", 1);
433 /* valid dev_id values */
434 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
436 /* Stop the device in case it's started so it can be configured */
437 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
439 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
440 "Failed test for rte_cryptodev_configure: "
441 "invalid dev_num %u", dev_id);
443 /* invalid dev_id values */
446 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
447 "Failed test for rte_cryptodev_configure: "
448 "invalid dev_num %u", dev_id);
452 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
453 "Failed test for rte_cryptodev_configure:"
454 "invalid dev_num %u", dev_id);
460 test_device_configure_invalid_queue_pair_ids(void)
462 struct crypto_testsuite_params *ts_params = &testsuite_params;
464 /* Stop the device in case it's started so it can be configured */
465 rte_cryptodev_stop(ts_params->valid_devs[0]);
467 /* valid - one queue pairs */
468 ts_params->conf.nb_queue_pairs = 1;
470 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
472 "Failed to configure cryptodev: dev_id %u, qp_id %u",
473 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
476 /* valid - max value queue pairs */
477 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
479 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
481 "Failed to configure cryptodev: dev_id %u, qp_id %u",
482 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
485 /* invalid - zero queue pairs */
486 ts_params->conf.nb_queue_pairs = 0;
488 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
490 "Failed test for rte_cryptodev_configure, dev_id %u,"
492 ts_params->valid_devs[0],
493 ts_params->conf.nb_queue_pairs);
496 /* invalid - max value supported by field queue pairs */
497 ts_params->conf.nb_queue_pairs = UINT16_MAX;
499 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
501 "Failed test for rte_cryptodev_configure, dev_id %u,"
503 ts_params->valid_devs[0],
504 ts_params->conf.nb_queue_pairs);
507 /* invalid - max value + 1 queue pairs */
508 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
510 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
512 "Failed test for rte_cryptodev_configure, dev_id %u,"
514 ts_params->valid_devs[0],
515 ts_params->conf.nb_queue_pairs);
521 test_queue_pair_descriptor_setup(void)
523 struct crypto_testsuite_params *ts_params = &testsuite_params;
524 struct rte_cryptodev_info dev_info;
525 struct rte_cryptodev_qp_conf qp_conf = {
526 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
531 /* Stop the device in case it's started so it can be configured */
532 rte_cryptodev_stop(ts_params->valid_devs[0]);
535 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
537 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
539 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
540 &ts_params->conf), "Failed to configure cryptodev %u",
541 ts_params->valid_devs[0]);
545 * Test various ring sizes on this device. memzones can't be
546 * freed so are re-used if ring is released and re-created.
548 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
550 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
551 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
552 ts_params->valid_devs[0], qp_id, &qp_conf,
553 rte_cryptodev_socket_id(
554 ts_params->valid_devs[0])),
556 "rte_cryptodev_queue_pair_setup: num_inflights "
557 "%u on qp %u on cryptodev %u",
558 qp_conf.nb_descriptors, qp_id,
559 ts_params->valid_devs[0]);
562 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
564 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
565 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
566 ts_params->valid_devs[0], qp_id, &qp_conf,
567 rte_cryptodev_socket_id(
568 ts_params->valid_devs[0])),
570 " rte_cryptodev_queue_pair_setup: num_inflights"
571 " %u on qp %u on cryptodev %u",
572 qp_conf.nb_descriptors, qp_id,
573 ts_params->valid_devs[0]);
576 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
578 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
579 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
580 ts_params->valid_devs[0], qp_id, &qp_conf,
581 rte_cryptodev_socket_id(
582 ts_params->valid_devs[0])),
584 "rte_cryptodev_queue_pair_setup: num_inflights"
585 " %u on qp %u on cryptodev %u",
586 qp_conf.nb_descriptors, qp_id,
587 ts_params->valid_devs[0]);
590 /* invalid number of descriptors - max supported + 2 */
591 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
593 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
594 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
595 ts_params->valid_devs[0], qp_id, &qp_conf,
596 rte_cryptodev_socket_id(
597 ts_params->valid_devs[0])),
598 "Unexpectedly passed test for "
599 "rte_cryptodev_queue_pair_setup:"
600 "num_inflights %u on qp %u on cryptodev %u",
601 qp_conf.nb_descriptors, qp_id,
602 ts_params->valid_devs[0]);
605 /* invalid number of descriptors - max value of parameter */
606 qp_conf.nb_descriptors = UINT32_MAX-1;
608 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
609 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
610 ts_params->valid_devs[0], qp_id, &qp_conf,
611 rte_cryptodev_socket_id(
612 ts_params->valid_devs[0])),
613 "Unexpectedly passed test for "
614 "rte_cryptodev_queue_pair_setup:"
615 "num_inflights %u on qp %u on cryptodev %u",
616 qp_conf.nb_descriptors, qp_id,
617 ts_params->valid_devs[0]);
620 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
622 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
623 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
624 ts_params->valid_devs[0], qp_id, &qp_conf,
625 rte_cryptodev_socket_id(
626 ts_params->valid_devs[0])),
628 " rte_cryptodev_queue_pair_setup:"
629 "num_inflights %u on qp %u on cryptodev %u",
630 qp_conf.nb_descriptors, qp_id,
631 ts_params->valid_devs[0]);
634 /* invalid number of descriptors - max supported + 1 */
635 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
637 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
638 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
639 ts_params->valid_devs[0], qp_id, &qp_conf,
640 rte_cryptodev_socket_id(
641 ts_params->valid_devs[0])),
642 "Unexpectedly passed test for "
643 "rte_cryptodev_queue_pair_setup:"
644 "num_inflights %u on qp %u on cryptodev %u",
645 qp_conf.nb_descriptors, qp_id,
646 ts_params->valid_devs[0]);
649 /* test invalid queue pair id */
650 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
652 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
654 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
655 ts_params->valid_devs[0],
657 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
658 "Failed test for rte_cryptodev_queue_pair_setup:"
659 "invalid qp %u on cryptodev %u",
660 qp_id, ts_params->valid_devs[0]);
662 qp_id = 0xffff; /*invalid*/
664 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
665 ts_params->valid_devs[0],
667 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
668 "Failed test for rte_cryptodev_queue_pair_setup:"
669 "invalid qp %u on cryptodev %u",
670 qp_id, ts_params->valid_devs[0]);
675 /* ***** Plaintext data for tests ***** */
677 const char catch_22_quote_1[] =
678 "There was only one catch and that was Catch-22, which "
679 "specified that a concern for one's safety in the face of "
680 "dangers that were real and immediate was the process of a "
681 "rational mind. Orr was crazy and could be grounded. All he "
682 "had to do was ask; and as soon as he did, he would no longer "
683 "be crazy and would have to fly more missions. Orr would be "
684 "crazy to fly more missions and sane if he didn't, but if he "
685 "was sane he had to fly them. If he flew them he was crazy "
686 "and didn't have to; but if he didn't want to he was sane and "
687 "had to. Yossarian was moved very deeply by the absolute "
688 "simplicity of this clause of Catch-22 and let out a "
689 "respectful whistle. \"That's some catch, that Catch-22\", he "
690 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
692 const char catch_22_quote[] =
693 "What a lousy earth! He wondered how many people were "
694 "destitute that same night even in his own prosperous country, "
695 "how many homes were shanties, how many husbands were drunk "
696 "and wives socked, and how many children were bullied, abused, "
697 "or abandoned. How many families hungered for food they could "
698 "not afford to buy? How many hearts were broken? How many "
699 "suicides would take place that same night, how many people "
700 "would go insane? How many cockroaches and landlords would "
701 "triumph? How many winners were losers, successes failures, "
702 "and rich men poor men? How many wise guys were stupid? How "
703 "many happy endings were unhappy endings? How many honest men "
704 "were liars, brave men cowards, loyal men traitors, how many "
705 "sainted men were corrupt, how many people in positions of "
706 "trust had sold their souls to bodyguards, how many had never "
707 "had souls? How many straight-and-narrow paths were crooked "
708 "paths? How many best families were worst families and how "
709 "many good people were bad people? When you added them all up "
710 "and then subtracted, you might be left with only the children, "
711 "and perhaps with Albert Einstein and an old violinist or "
712 "sculptor somewhere.";
714 #define QUOTE_480_BYTES (480)
715 #define QUOTE_512_BYTES (512)
716 #define QUOTE_768_BYTES (768)
717 #define QUOTE_1024_BYTES (1024)
721 /* ***** SHA1 Hash Tests ***** */
723 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
725 static uint8_t hmac_sha1_key[] = {
726 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
727 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
728 0xDE, 0xF4, 0xDE, 0xAD };
730 /* ***** SHA224 Hash Tests ***** */
732 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
735 /* ***** AES-CBC Cipher Tests ***** */
737 #define CIPHER_KEY_LENGTH_AES_CBC (16)
738 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
740 static uint8_t aes_cbc_key[] = {
741 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
742 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
744 static uint8_t aes_cbc_iv[] = {
745 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
746 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
749 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
751 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
752 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
753 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
754 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
755 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
756 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
757 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
758 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
759 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
760 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
761 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
762 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
763 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
764 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
765 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
766 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
767 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
768 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
769 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
770 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
771 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
772 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
773 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
774 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
775 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
776 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
777 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
778 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
779 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
780 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
781 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
782 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
783 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
784 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
785 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
786 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
787 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
788 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
789 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
790 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
791 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
792 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
793 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
794 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
795 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
796 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
797 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
798 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
799 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
800 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
801 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
802 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
803 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
804 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
805 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
806 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
807 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
808 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
809 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
810 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
811 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
812 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
813 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
814 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
815 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
818 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
819 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
820 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
821 0x18, 0x8c, 0x1d, 0x32
826 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
828 struct crypto_testsuite_params *ts_params = &testsuite_params;
829 struct crypto_unittest_params *ut_params = &unittest_params;
831 /* Generate test mbuf data and space for digest */
832 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
833 catch_22_quote, QUOTE_512_BYTES, 0);
835 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
836 DIGEST_BYTE_LENGTH_SHA1);
837 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
839 /* Setup Cipher Parameters */
840 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
841 ut_params->cipher_xform.next = &ut_params->auth_xform;
843 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
844 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
845 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
846 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
848 /* Setup HMAC Parameters */
849 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
851 ut_params->auth_xform.next = NULL;
853 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
854 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
855 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
856 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
857 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
859 /* Create crypto session*/
860 ut_params->sess = rte_cryptodev_sym_session_create(
861 ts_params->valid_devs[0],
862 &ut_params->cipher_xform);
863 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
865 /* Generate crypto op data structure */
866 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
867 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
868 TEST_ASSERT_NOT_NULL(ut_params->op,
869 "Failed to allocate symmetric crypto operation struct");
871 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
873 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
875 /* set crypto operation source mbuf */
876 sym_op->m_src = ut_params->ibuf;
878 /* Set crypto operation authentication parameters */
879 sym_op->auth.digest.data = ut_params->digest;
880 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
881 ut_params->ibuf, QUOTE_512_BYTES);
882 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
884 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
885 sym_op->auth.data.length = QUOTE_512_BYTES;
887 /* Set crypto operation cipher parameters */
888 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
889 CIPHER_IV_LENGTH_AES_CBC);
890 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
891 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
893 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
894 CIPHER_IV_LENGTH_AES_CBC);
896 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
897 sym_op->cipher.data.length = QUOTE_512_BYTES;
899 /* Process crypto operation */
900 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
901 ut_params->op), "failed to process sym crypto op");
903 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
904 "crypto op processing failed");
907 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
908 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
910 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
911 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
913 "ciphertext data not as expected");
915 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
917 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
918 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
919 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
920 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
921 DIGEST_BYTE_LENGTH_SHA1,
922 "Generated digest data not as expected");
927 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
929 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
931 static uint8_t hmac_sha512_key[] = {
932 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
933 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
934 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
935 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
936 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
937 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
938 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
939 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
941 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
942 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
943 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
944 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
945 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
946 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
947 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
948 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
949 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
954 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
955 struct crypto_unittest_params *ut_params);
958 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
959 struct crypto_unittest_params *ut_params,
960 struct crypto_testsuite_params *ts_params);
964 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
965 struct crypto_unittest_params *ut_params)
968 /* Setup Cipher Parameters */
969 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
970 ut_params->cipher_xform.next = NULL;
972 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
973 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
974 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
975 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
977 /* Setup HMAC Parameters */
978 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
979 ut_params->auth_xform.next = &ut_params->cipher_xform;
981 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
982 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
983 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
984 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
985 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
992 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
993 struct crypto_unittest_params *ut_params,
994 struct crypto_testsuite_params *ts_params)
996 /* Generate test mbuf data and digest */
997 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
999 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1000 QUOTE_512_BYTES, 0);
1002 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1003 DIGEST_BYTE_LENGTH_SHA512);
1004 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1006 rte_memcpy(ut_params->digest,
1007 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1008 DIGEST_BYTE_LENGTH_SHA512);
1010 /* Generate Crypto op data structure */
1011 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1012 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1013 TEST_ASSERT_NOT_NULL(ut_params->op,
1014 "Failed to allocate symmetric crypto operation struct");
1016 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1018 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1020 /* set crypto operation source mbuf */
1021 sym_op->m_src = ut_params->ibuf;
1023 sym_op->auth.digest.data = ut_params->digest;
1024 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1025 ut_params->ibuf, QUOTE_512_BYTES);
1026 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1028 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1029 sym_op->auth.data.length = QUOTE_512_BYTES;
1031 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1032 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1033 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1034 ut_params->ibuf, 0);
1035 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1037 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1038 CIPHER_IV_LENGTH_AES_CBC);
1040 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1041 sym_op->cipher.data.length = QUOTE_512_BYTES;
1043 /* Process crypto operation */
1044 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1045 ut_params->op), "failed to process sym crypto op");
1047 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1048 "crypto op processing failed");
1050 ut_params->obuf = ut_params->op->sym->m_src;
1053 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1054 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1055 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1057 "Plaintext data not as expected");
1060 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1061 "Digest verification failed");
1063 return TEST_SUCCESS;
1067 test_AES_mb_all(void)
1069 struct crypto_testsuite_params *ts_params = &testsuite_params;
1072 status = test_AES_all_tests(ts_params->mbuf_pool,
1073 ts_params->op_mpool, ts_params->valid_devs[0],
1074 RTE_CRYPTODEV_AESNI_MB_PMD);
1076 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1078 return TEST_SUCCESS;
1082 test_AES_qat_all(void)
1084 struct crypto_testsuite_params *ts_params = &testsuite_params;
1087 status = test_AES_all_tests(ts_params->mbuf_pool,
1088 ts_params->op_mpool, ts_params->valid_devs[0],
1089 RTE_CRYPTODEV_QAT_SYM_PMD);
1091 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1093 return TEST_SUCCESS;
1096 /* ***** Snow3G Tests ***** */
1098 create_snow3g_kasumi_hash_session(uint8_t dev_id,
1099 const uint8_t *key, const uint8_t key_len,
1100 const uint8_t aad_len, const uint8_t auth_len,
1101 enum rte_crypto_auth_operation op,
1102 enum rte_crypto_auth_algorithm algo)
1104 uint8_t hash_key[key_len];
1106 struct crypto_unittest_params *ut_params = &unittest_params;
1108 memcpy(hash_key, key, key_len);
1110 TEST_HEXDUMP(stdout, "key:", key, key_len);
1112 /* Setup Authentication Parameters */
1113 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1114 ut_params->auth_xform.next = NULL;
1116 ut_params->auth_xform.auth.op = op;
1117 ut_params->auth_xform.auth.algo = algo;
1118 ut_params->auth_xform.auth.key.length = key_len;
1119 ut_params->auth_xform.auth.key.data = hash_key;
1120 ut_params->auth_xform.auth.digest_length = auth_len;
1121 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1122 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1123 &ut_params->auth_xform);
1124 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1129 create_snow3g_kasumi_cipher_session(uint8_t dev_id,
1130 enum rte_crypto_cipher_operation op,
1131 enum rte_crypto_cipher_algorithm algo,
1132 const uint8_t *key, const uint8_t key_len)
1134 uint8_t cipher_key[key_len];
1136 struct crypto_unittest_params *ut_params = &unittest_params;
1138 memcpy(cipher_key, key, key_len);
1140 /* Setup Cipher Parameters */
1141 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1142 ut_params->cipher_xform.next = NULL;
1144 ut_params->cipher_xform.cipher.algo = algo;
1145 ut_params->cipher_xform.cipher.op = op;
1146 ut_params->cipher_xform.cipher.key.data = cipher_key;
1147 ut_params->cipher_xform.cipher.key.length = key_len;
1149 TEST_HEXDUMP(stdout, "key:", key, key_len);
1151 /* Create Crypto session */
1152 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1155 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1160 create_snow3g_kasumi_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1161 const unsigned cipher_len,
1162 const unsigned cipher_offset,
1163 enum rte_crypto_cipher_algorithm algo)
1165 struct crypto_testsuite_params *ts_params = &testsuite_params;
1166 struct crypto_unittest_params *ut_params = &unittest_params;
1167 unsigned iv_pad_len = 0;
1169 /* Generate Crypto op data structure */
1170 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1171 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1172 TEST_ASSERT_NOT_NULL(ut_params->op,
1173 "Failed to allocate pktmbuf offload");
1175 /* Set crypto operation data parameters */
1176 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1178 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1180 /* set crypto operation source mbuf */
1181 sym_op->m_src = ut_params->ibuf;
1184 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1185 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1187 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1189 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1192 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1194 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1195 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1196 sym_op->cipher.iv.length = iv_pad_len;
1198 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1199 sym_op->cipher.data.length = cipher_len;
1200 sym_op->cipher.data.offset = cipher_offset;
1205 create_snow3g_kasumi_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1206 const unsigned cipher_len,
1207 const unsigned cipher_offset,
1208 enum rte_crypto_cipher_algorithm algo)
1210 struct crypto_testsuite_params *ts_params = &testsuite_params;
1211 struct crypto_unittest_params *ut_params = &unittest_params;
1212 unsigned iv_pad_len = 0;
1214 /* Generate Crypto op data structure */
1215 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1216 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1217 TEST_ASSERT_NOT_NULL(ut_params->op,
1218 "Failed to allocate pktmbuf offload");
1220 /* Set crypto operation data parameters */
1221 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1223 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1225 /* set crypto operation source mbuf */
1226 sym_op->m_src = ut_params->ibuf;
1227 sym_op->m_dst = ut_params->obuf;
1230 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1231 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1233 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1234 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1237 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1239 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1240 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1241 sym_op->cipher.iv.length = iv_pad_len;
1243 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1244 sym_op->cipher.data.length = cipher_len;
1245 sym_op->cipher.data.offset = cipher_offset;
1250 create_snow3g_kasumi_cipher_auth_session(uint8_t dev_id,
1251 enum rte_crypto_cipher_operation cipher_op,
1252 enum rte_crypto_auth_operation auth_op,
1253 enum rte_crypto_auth_algorithm auth_algo,
1254 enum rte_crypto_cipher_algorithm cipher_algo,
1255 const uint8_t *key, const uint8_t key_len,
1256 const uint8_t aad_len, const uint8_t auth_len)
1259 uint8_t cipher_auth_key[key_len];
1261 struct crypto_unittest_params *ut_params = &unittest_params;
1263 memcpy(cipher_auth_key, key, key_len);
1265 /* Setup Authentication Parameters */
1266 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1267 ut_params->auth_xform.next = NULL;
1269 ut_params->auth_xform.auth.op = auth_op;
1270 ut_params->auth_xform.auth.algo = auth_algo;
1271 ut_params->auth_xform.auth.key.length = key_len;
1272 /* Hash key = cipher key */
1273 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1274 ut_params->auth_xform.auth.digest_length = auth_len;
1275 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1277 /* Setup Cipher Parameters */
1278 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1279 ut_params->cipher_xform.next = &ut_params->auth_xform;
1281 ut_params->cipher_xform.cipher.algo = cipher_algo;
1282 ut_params->cipher_xform.cipher.op = cipher_op;
1283 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1284 ut_params->cipher_xform.cipher.key.length = key_len;
1286 TEST_HEXDUMP(stdout, "key:", key, key_len);
1288 /* Create Crypto session*/
1289 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1290 &ut_params->cipher_xform);
1292 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1297 create_snow3g_kasumi_auth_cipher_session(uint8_t dev_id,
1298 enum rte_crypto_cipher_operation cipher_op,
1299 enum rte_crypto_auth_operation auth_op,
1300 enum rte_crypto_auth_algorithm auth_algo,
1301 enum rte_crypto_cipher_algorithm cipher_algo,
1302 const uint8_t *key, const uint8_t key_len,
1303 const uint8_t aad_len, const uint8_t auth_len)
1305 uint8_t auth_cipher_key[key_len];
1307 struct crypto_unittest_params *ut_params = &unittest_params;
1309 memcpy(auth_cipher_key, key, key_len);
1311 /* Setup Authentication Parameters */
1312 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1313 ut_params->auth_xform.auth.op = auth_op;
1314 ut_params->auth_xform.next = &ut_params->cipher_xform;
1315 ut_params->auth_xform.auth.algo = auth_algo;
1316 ut_params->auth_xform.auth.key.length = key_len;
1317 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1318 ut_params->auth_xform.auth.digest_length = auth_len;
1319 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1321 /* Setup Cipher Parameters */
1322 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1323 ut_params->cipher_xform.next = NULL;
1324 ut_params->cipher_xform.cipher.algo = cipher_algo;
1325 ut_params->cipher_xform.cipher.op = cipher_op;
1326 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1327 ut_params->cipher_xform.cipher.key.length = key_len;
1329 TEST_HEXDUMP(stdout, "key:", key, key_len);
1331 /* Create Crypto session*/
1332 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1333 &ut_params->auth_xform);
1335 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1341 create_snow3g_kasumi_hash_operation(const uint8_t *auth_tag,
1342 const unsigned auth_tag_len,
1343 const uint8_t *aad, const unsigned aad_len,
1344 unsigned data_pad_len,
1345 enum rte_crypto_auth_operation op,
1346 enum rte_crypto_auth_algorithm algo,
1347 const unsigned auth_len, const unsigned auth_offset)
1349 struct crypto_testsuite_params *ts_params = &testsuite_params;
1351 struct crypto_unittest_params *ut_params = &unittest_params;
1353 unsigned aad_buffer_len;
1355 /* Generate Crypto op data structure */
1356 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1357 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1358 TEST_ASSERT_NOT_NULL(ut_params->op,
1359 "Failed to allocate pktmbuf offload");
1361 /* Set crypto operation data parameters */
1362 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1364 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1366 /* set crypto operation source mbuf */
1367 sym_op->m_src = ut_params->ibuf;
1371 * Always allocate the aad up to the block size.
1372 * The cryptodev API calls out -
1373 * - the array must be big enough to hold the AAD, plus any
1374 * space to round this up to the nearest multiple of the
1375 * block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
1377 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1378 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1380 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1381 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1382 ut_params->ibuf, aad_buffer_len);
1383 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1384 "no room to prepend aad");
1385 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1387 sym_op->auth.aad.length = aad_len;
1389 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1390 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1392 TEST_HEXDUMP(stdout, "aad:",
1393 sym_op->auth.aad.data, aad_len);
1396 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1397 ut_params->ibuf, auth_tag_len);
1399 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1400 "no room to append auth tag");
1401 ut_params->digest = sym_op->auth.digest.data;
1402 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1403 ut_params->ibuf, data_pad_len + aad_len);
1404 sym_op->auth.digest.length = auth_tag_len;
1405 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1406 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1408 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1410 TEST_HEXDUMP(stdout, "digest:",
1411 sym_op->auth.digest.data,
1412 sym_op->auth.digest.length);
1414 sym_op->auth.data.length = auth_len;
1415 sym_op->auth.data.offset = auth_offset;
1421 create_snow3g_kasumi_cipher_hash_operation(const uint8_t *auth_tag,
1422 const unsigned auth_tag_len,
1423 const uint8_t *aad, const uint8_t aad_len,
1424 unsigned data_pad_len,
1425 enum rte_crypto_auth_operation op,
1426 enum rte_crypto_auth_algorithm auth_algo,
1427 enum rte_crypto_cipher_algorithm cipher_algo,
1428 const uint8_t *iv, const uint8_t iv_len,
1429 const unsigned cipher_len, const unsigned cipher_offset,
1430 const unsigned auth_len, const unsigned auth_offset)
1432 struct crypto_testsuite_params *ts_params = &testsuite_params;
1433 struct crypto_unittest_params *ut_params = &unittest_params;
1435 unsigned iv_pad_len = 0;
1436 unsigned aad_buffer_len;
1438 /* Generate Crypto op data structure */
1439 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1440 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1441 TEST_ASSERT_NOT_NULL(ut_params->op,
1442 "Failed to allocate pktmbuf offload");
1443 /* Set crypto operation data parameters */
1444 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1446 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1448 /* set crypto operation source mbuf */
1449 sym_op->m_src = ut_params->ibuf;
1452 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1453 ut_params->ibuf, auth_tag_len);
1455 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1456 "no room to append auth tag");
1457 ut_params->digest = sym_op->auth.digest.data;
1458 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1459 ut_params->ibuf, data_pad_len);
1460 sym_op->auth.digest.length = auth_tag_len;
1461 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1462 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1464 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1466 TEST_HEXDUMP(stdout, "digest:",
1467 sym_op->auth.digest.data,
1468 sym_op->auth.digest.length);
1472 * Always allocate the aad up to the block size.
1473 * The cryptodev API calls out -
1474 * - the array must be big enough to hold the AAD, plus any
1475 * space to round this up to the nearest multiple of the
1476 * block size (8 bytes for KASUMI and 16 bytes for SNOW3G).
1478 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1479 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1481 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1482 sym_op->auth.aad.data =
1483 (uint8_t *)rte_pktmbuf_prepend(
1484 ut_params->ibuf, aad_buffer_len);
1485 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1486 "no room to prepend aad");
1487 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1489 sym_op->auth.aad.length = aad_len;
1490 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1491 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1492 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1495 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1496 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1498 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1499 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1500 ut_params->ibuf, iv_pad_len);
1502 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1503 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1504 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1505 sym_op->cipher.iv.length = iv_pad_len;
1506 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1507 sym_op->cipher.data.length = cipher_len;
1508 sym_op->cipher.data.offset = cipher_offset + auth_offset;
1509 sym_op->auth.data.length = auth_len;
1510 sym_op->auth.data.offset = auth_offset + cipher_offset;
1516 create_snow3g_kasumi_auth_cipher_operation(const unsigned auth_tag_len,
1517 const uint8_t *iv, const uint8_t iv_len,
1518 const uint8_t *aad, const uint8_t aad_len,
1519 unsigned data_pad_len,
1520 const unsigned cipher_len, const unsigned cipher_offset,
1521 const unsigned auth_len, const unsigned auth_offset,
1522 enum rte_crypto_auth_algorithm auth_algo,
1523 enum rte_crypto_cipher_algorithm cipher_algo)
1525 struct crypto_testsuite_params *ts_params = &testsuite_params;
1526 struct crypto_unittest_params *ut_params = &unittest_params;
1528 unsigned iv_pad_len = 0;
1529 unsigned aad_buffer_len = 0;
1531 /* Generate Crypto op data structure */
1532 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1533 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1534 TEST_ASSERT_NOT_NULL(ut_params->op,
1535 "Failed to allocate pktmbuf offload");
1537 /* Set crypto operation data parameters */
1538 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->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;
1546 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1547 ut_params->ibuf, auth_tag_len);
1549 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1550 "no room to append auth tag");
1552 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1553 ut_params->ibuf, data_pad_len);
1554 sym_op->auth.digest.length = auth_tag_len;
1556 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1558 TEST_HEXDUMP(stdout, "digest:",
1559 sym_op->auth.digest.data,
1560 sym_op->auth.digest.length);
1564 * Always allocate the aad up to the block size.
1565 * The cryptodev API calls out -
1566 * - the array must be big enough to hold the AAD, plus any
1567 * space to round this up to the nearest multiple of the
1568 * block size (8 bytes for KASUMI 16 bytes).
1570 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1571 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1573 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1575 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1576 ut_params->ibuf, aad_buffer_len);
1577 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1578 "no room to prepend aad");
1579 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1581 sym_op->auth.aad.length = aad_len;
1583 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1584 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1586 TEST_HEXDUMP(stdout, "aad:",
1587 sym_op->auth.aad.data, aad_len);
1590 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1591 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1593 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1595 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1596 ut_params->ibuf, iv_pad_len);
1597 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1599 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1600 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1601 sym_op->cipher.iv.length = iv_pad_len;
1603 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1605 sym_op->cipher.data.length = cipher_len;
1606 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1608 sym_op->auth.data.length = auth_len;
1609 sym_op->auth.data.offset = auth_offset + cipher_offset;
1615 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1617 struct crypto_testsuite_params *ts_params = &testsuite_params;
1618 struct crypto_unittest_params *ut_params = &unittest_params;
1621 unsigned plaintext_pad_len;
1622 unsigned plaintext_len;
1625 /* Create SNOW3G session */
1626 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1627 tdata->key.data, tdata->key.len,
1628 tdata->aad.len, tdata->digest.len,
1629 RTE_CRYPTO_AUTH_OP_GENERATE,
1630 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1634 /* alloc mbuf and set payload */
1635 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1637 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1638 rte_pktmbuf_tailroom(ut_params->ibuf));
1640 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1641 /* Append data which is padded to a multiple of */
1642 /* the algorithms block size */
1643 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1644 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1646 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1648 /* Create SNOW3G operation */
1649 retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1650 tdata->aad.data, tdata->aad.len,
1651 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1652 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1653 tdata->validAuthLenInBits.len,
1654 tdata->validAuthOffsetLenInBits.len);
1658 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1660 ut_params->obuf = ut_params->op->sym->m_src;
1661 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1662 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1663 + plaintext_pad_len + tdata->aad.len;
1666 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1669 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1670 "Snow3G Generated auth tag not as expected");
1676 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1678 struct crypto_testsuite_params *ts_params = &testsuite_params;
1679 struct crypto_unittest_params *ut_params = &unittest_params;
1682 unsigned plaintext_pad_len;
1683 unsigned plaintext_len;
1686 /* Create SNOW3G session */
1687 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1688 tdata->key.data, tdata->key.len,
1689 tdata->aad.len, tdata->digest.len,
1690 RTE_CRYPTO_AUTH_OP_VERIFY,
1691 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1694 /* alloc mbuf and set payload */
1695 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1697 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1698 rte_pktmbuf_tailroom(ut_params->ibuf));
1700 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1701 /* Append data which is padded to a multiple of */
1702 /* the algorithms block size */
1703 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1704 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1706 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1708 /* Create SNOW3G operation */
1709 retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1711 tdata->aad.data, tdata->aad.len,
1713 RTE_CRYPTO_AUTH_OP_VERIFY,
1714 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1715 tdata->validAuthLenInBits.len,
1716 tdata->validAuthOffsetLenInBits.len);
1720 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1722 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1723 ut_params->obuf = ut_params->op->sym->m_src;
1724 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1725 + plaintext_pad_len + tdata->aad.len;
1728 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1737 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1739 struct crypto_testsuite_params *ts_params = &testsuite_params;
1740 struct crypto_unittest_params *ut_params = &unittest_params;
1743 unsigned plaintext_pad_len;
1744 unsigned plaintext_len;
1747 /* Create KASUMI session */
1748 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1749 tdata->key.data, tdata->key.len,
1750 tdata->aad.len, tdata->digest.len,
1751 RTE_CRYPTO_AUTH_OP_GENERATE,
1752 RTE_CRYPTO_AUTH_KASUMI_F9);
1756 /* alloc mbuf and set payload */
1757 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1759 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1760 rte_pktmbuf_tailroom(ut_params->ibuf));
1762 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1763 /* Append data which is padded to a multiple of */
1764 /* the algorithms block size */
1765 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1766 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1768 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1770 /* Create KASUMI operation */
1771 retval = create_snow3g_kasumi_hash_operation(NULL, tdata->digest.len,
1772 tdata->aad.data, tdata->aad.len,
1773 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1774 RTE_CRYPTO_AUTH_KASUMI_F9,
1775 tdata->validAuthLenInBits.len,
1776 tdata->validAuthOffsetLenInBits.len);
1780 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1782 ut_params->obuf = ut_params->op->sym->m_src;
1783 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1784 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1785 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1788 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1791 DIGEST_BYTE_LENGTH_KASUMI_F9,
1792 "KASUMI Generated auth tag not as expected");
1798 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1800 struct crypto_testsuite_params *ts_params = &testsuite_params;
1801 struct crypto_unittest_params *ut_params = &unittest_params;
1804 unsigned plaintext_pad_len;
1805 unsigned plaintext_len;
1808 /* Create KASUMI session */
1809 retval = create_snow3g_kasumi_hash_session(ts_params->valid_devs[0],
1810 tdata->key.data, tdata->key.len,
1811 tdata->aad.len, tdata->digest.len,
1812 RTE_CRYPTO_AUTH_OP_VERIFY,
1813 RTE_CRYPTO_AUTH_KASUMI_F9);
1816 /* alloc mbuf and set payload */
1817 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1819 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1820 rte_pktmbuf_tailroom(ut_params->ibuf));
1822 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1823 /* Append data which is padded to a multiple */
1824 /* of the algorithms block size */
1825 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1826 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1828 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1830 /* Create KASUMI operation */
1831 retval = create_snow3g_kasumi_hash_operation(tdata->digest.data,
1833 tdata->aad.data, tdata->aad.len,
1835 RTE_CRYPTO_AUTH_OP_VERIFY,
1836 RTE_CRYPTO_AUTH_KASUMI_F9,
1837 tdata->validAuthLenInBits.len,
1838 tdata->validAuthOffsetLenInBits.len);
1842 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1844 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1845 ut_params->obuf = ut_params->op->sym->m_src;
1846 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1847 + plaintext_pad_len + tdata->aad.len;
1850 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1859 test_snow3g_hash_generate_test_case_1(void)
1861 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1865 test_snow3g_hash_generate_test_case_2(void)
1867 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1871 test_snow3g_hash_generate_test_case_3(void)
1873 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1877 test_snow3g_hash_generate_test_case_4(void)
1879 return test_snow3g_authentication(&snow3g_hash_test_case_4);
1883 test_snow3g_hash_generate_test_case_5(void)
1885 return test_snow3g_authentication(&snow3g_hash_test_case_5);
1889 test_snow3g_hash_generate_test_case_6(void)
1891 return test_snow3g_authentication(&snow3g_hash_test_case_6);
1895 test_snow3g_hash_verify_test_case_1(void)
1897 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1902 test_snow3g_hash_verify_test_case_2(void)
1904 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1908 test_snow3g_hash_verify_test_case_3(void)
1910 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1914 test_snow3g_hash_verify_test_case_4(void)
1916 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
1920 test_snow3g_hash_verify_test_case_5(void)
1922 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
1926 test_snow3g_hash_verify_test_case_6(void)
1928 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
1932 test_kasumi_hash_generate_test_case_1(void)
1934 return test_kasumi_authentication(&kasumi_hash_test_case_1);
1938 test_kasumi_hash_generate_test_case_2(void)
1940 return test_kasumi_authentication(&kasumi_hash_test_case_2);
1944 test_kasumi_hash_generate_test_case_3(void)
1946 return test_kasumi_authentication(&kasumi_hash_test_case_3);
1950 test_kasumi_hash_generate_test_case_4(void)
1952 return test_kasumi_authentication(&kasumi_hash_test_case_4);
1956 test_kasumi_hash_generate_test_case_5(void)
1958 return test_kasumi_authentication(&kasumi_hash_test_case_5);
1962 test_kasumi_hash_verify_test_case_1(void)
1964 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
1968 test_kasumi_hash_verify_test_case_2(void)
1970 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
1974 test_kasumi_hash_verify_test_case_3(void)
1976 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
1980 test_kasumi_hash_verify_test_case_4(void)
1982 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
1986 test_kasumi_hash_verify_test_case_5(void)
1988 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
1992 test_kasumi_encryption(const struct kasumi_test_data *tdata)
1994 struct crypto_testsuite_params *ts_params = &testsuite_params;
1995 struct crypto_unittest_params *ut_params = &unittest_params;
1998 uint8_t *plaintext, *ciphertext;
1999 unsigned plaintext_pad_len;
2000 unsigned plaintext_len;
2002 /* Create KASUMI session */
2003 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2004 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2005 RTE_CRYPTO_CIPHER_KASUMI_F8,
2006 tdata->key.data, tdata->key.len);
2010 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2012 /* Clear mbuf payload */
2013 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2014 rte_pktmbuf_tailroom(ut_params->ibuf));
2016 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2017 /* Append data which is padded to a multiple */
2018 /* of the algorithms block size */
2019 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2020 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2022 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2024 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2026 /* Create KASUMI operation */
2027 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2028 tdata->plaintext.len,
2029 tdata->validCipherOffsetLenInBits.len,
2030 RTE_CRYPTO_CIPHER_KASUMI_F8);
2034 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2036 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2038 ut_params->obuf = ut_params->op->sym->m_dst;
2039 if (ut_params->obuf)
2040 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2043 ciphertext = plaintext;
2045 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2048 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2050 tdata->ciphertext.data,
2051 tdata->validCipherLenInBits.len,
2052 "KASUMI Ciphertext data not as expected");
2057 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2059 struct crypto_testsuite_params *ts_params = &testsuite_params;
2060 struct crypto_unittest_params *ut_params = &unittest_params;
2063 uint8_t *plaintext, *ciphertext;
2064 unsigned plaintext_pad_len;
2065 unsigned plaintext_len;
2067 /* Create KASUMI session */
2068 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2069 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2070 RTE_CRYPTO_CIPHER_KASUMI_F8,
2071 tdata->key.data, tdata->key.len);
2075 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2076 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2078 /* Clear mbuf payload */
2079 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2080 rte_pktmbuf_tailroom(ut_params->ibuf));
2082 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2083 /* Append data which is padded to a multiple */
2084 /* of the algorithms block size */
2085 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2086 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2088 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2089 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2091 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2093 /* Create KASUMI operation */
2094 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2096 tdata->plaintext.len,
2097 tdata->validCipherOffsetLenInBits.len,
2098 RTE_CRYPTO_CIPHER_KASUMI_F8);
2102 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2104 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2106 ut_params->obuf = ut_params->op->sym->m_dst;
2107 if (ut_params->obuf)
2108 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2111 ciphertext = plaintext;
2113 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2116 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2118 tdata->ciphertext.data,
2119 tdata->validCipherLenInBits.len,
2120 "KASUMI Ciphertext data not as expected");
2125 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2127 struct crypto_testsuite_params *ts_params = &testsuite_params;
2128 struct crypto_unittest_params *ut_params = &unittest_params;
2131 uint8_t *ciphertext, *plaintext;
2132 unsigned ciphertext_pad_len;
2133 unsigned ciphertext_len;
2135 /* Create KASUMI session */
2136 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2137 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2138 RTE_CRYPTO_CIPHER_KASUMI_F8,
2139 tdata->key.data, tdata->key.len);
2143 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2144 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2146 /* Clear mbuf payload */
2147 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2148 rte_pktmbuf_tailroom(ut_params->ibuf));
2150 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2151 /* Append data which is padded to a multiple */
2152 /* of the algorithms block size */
2153 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2154 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2155 ciphertext_pad_len);
2156 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2157 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2159 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2161 /* Create KASUMI operation */
2162 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2164 tdata->ciphertext.len,
2165 tdata->validCipherOffsetLenInBits.len,
2166 RTE_CRYPTO_CIPHER_KASUMI_F8);
2170 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2172 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2174 ut_params->obuf = ut_params->op->sym->m_dst;
2175 if (ut_params->obuf)
2176 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2179 plaintext = ciphertext;
2181 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2184 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2186 tdata->plaintext.data,
2187 tdata->validCipherLenInBits.len,
2188 "KASUMI Plaintext data not as expected");
2193 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2195 struct crypto_testsuite_params *ts_params = &testsuite_params;
2196 struct crypto_unittest_params *ut_params = &unittest_params;
2199 uint8_t *ciphertext, *plaintext;
2200 unsigned ciphertext_pad_len;
2201 unsigned ciphertext_len;
2203 /* Create KASUMI session */
2204 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2205 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2206 RTE_CRYPTO_CIPHER_KASUMI_F8,
2207 tdata->key.data, tdata->key.len);
2211 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2213 /* Clear mbuf payload */
2214 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2215 rte_pktmbuf_tailroom(ut_params->ibuf));
2217 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2218 /* Append data which is padded to a multiple */
2219 /* of the algorithms block size */
2220 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2221 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2222 ciphertext_pad_len);
2223 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2225 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2227 /* Create KASUMI operation */
2228 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data,
2230 tdata->ciphertext.len,
2231 tdata->validCipherOffsetLenInBits.len,
2232 RTE_CRYPTO_CIPHER_KASUMI_F8);
2236 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2238 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2240 ut_params->obuf = ut_params->op->sym->m_dst;
2241 if (ut_params->obuf)
2242 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2245 plaintext = ciphertext;
2247 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2250 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2252 tdata->plaintext.data,
2253 tdata->validCipherLenInBits.len,
2254 "KASUMI Plaintext data not as expected");
2259 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2261 struct crypto_testsuite_params *ts_params = &testsuite_params;
2262 struct crypto_unittest_params *ut_params = &unittest_params;
2265 uint8_t *plaintext, *ciphertext;
2266 unsigned plaintext_pad_len;
2267 unsigned plaintext_len;
2269 /* Create SNOW3G session */
2270 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2271 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2272 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2273 tdata->key.data, tdata->key.len);
2277 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2279 /* Clear mbuf payload */
2280 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2281 rte_pktmbuf_tailroom(ut_params->ibuf));
2283 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2284 /* Append data which is padded to a multiple of */
2285 /* the algorithms block size */
2286 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2287 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2289 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2291 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2293 /* Create SNOW3G operation */
2294 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2295 tdata->validCipherLenInBits.len,
2296 tdata->validCipherOffsetLenInBits.len,
2297 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2301 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2303 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2305 ut_params->obuf = ut_params->op->sym->m_dst;
2306 if (ut_params->obuf)
2307 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2310 ciphertext = plaintext;
2312 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2315 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2317 tdata->ciphertext.data,
2318 tdata->validDataLenInBits.len,
2319 "Snow3G Ciphertext data not as expected");
2325 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2327 struct crypto_testsuite_params *ts_params = &testsuite_params;
2328 struct crypto_unittest_params *ut_params = &unittest_params;
2329 uint8_t *plaintext, *ciphertext;
2332 unsigned plaintext_pad_len;
2333 unsigned plaintext_len;
2335 /* Create SNOW3G session */
2336 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2337 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2338 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2339 tdata->key.data, tdata->key.len);
2343 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2344 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2346 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2347 "Failed to allocate input buffer in mempool");
2348 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2349 "Failed to allocate output buffer in mempool");
2351 /* Clear mbuf payload */
2352 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2353 rte_pktmbuf_tailroom(ut_params->ibuf));
2355 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2356 /* Append data which is padded to a multiple of */
2357 /* the algorithms block size */
2358 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2359 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2361 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2362 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2364 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2366 /* Create SNOW3G operation */
2367 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2369 tdata->validCipherLenInBits.len,
2370 tdata->validCipherOffsetLenInBits.len,
2371 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2375 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2377 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2379 ut_params->obuf = ut_params->op->sym->m_dst;
2380 if (ut_params->obuf)
2381 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2384 ciphertext = plaintext;
2386 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2389 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2391 tdata->ciphertext.data,
2392 tdata->validDataLenInBits.len,
2393 "Snow3G Ciphertext data not as expected");
2397 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2399 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2401 uint8_t curr_byte, prev_byte;
2402 uint32_t length_in_bytes = ceil_byte_length(length + offset);
2403 uint8_t lower_byte_mask = (1 << offset) - 1;
2406 prev_byte = buffer[0];
2407 buffer[0] >>= offset;
2409 for (i = 1; i < length_in_bytes; i++) {
2410 curr_byte = buffer[i];
2411 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2412 (curr_byte >> offset);
2413 prev_byte = curr_byte;
2418 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2420 struct crypto_testsuite_params *ts_params = &testsuite_params;
2421 struct crypto_unittest_params *ut_params = &unittest_params;
2422 uint8_t *plaintext, *ciphertext;
2424 uint32_t plaintext_len;
2425 uint32_t plaintext_pad_len;
2426 uint8_t extra_offset = 4;
2427 uint8_t *expected_ciphertext_shifted;
2429 /* Create SNOW3G session */
2430 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2431 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2432 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2433 tdata->key.data, tdata->key.len);
2437 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2438 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2440 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2441 "Failed to allocate input buffer in mempool");
2442 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2443 "Failed to allocate output buffer in mempool");
2445 /* Clear mbuf payload */
2446 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2447 rte_pktmbuf_tailroom(ut_params->ibuf));
2449 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2451 * Append data which is padded to a
2452 * multiple of the algorithms block size
2454 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2456 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2459 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2461 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2462 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2464 #ifdef RTE_APP_TEST_DEBUG
2465 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2467 /* Create SNOW3G operation */
2468 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2470 tdata->validCipherLenInBits.len,
2471 tdata->validCipherOffsetLenInBits.len +
2473 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2477 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2479 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2481 ut_params->obuf = ut_params->op->sym->m_dst;
2482 if (ut_params->obuf)
2483 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2486 ciphertext = plaintext;
2488 #ifdef RTE_APP_TEST_DEBUG
2489 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2492 expected_ciphertext_shifted = rte_malloc(NULL,
2493 ceil_byte_length(plaintext_len + extra_offset), 0);
2495 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2496 "failed to reserve memory for ciphertext shifted\n");
2498 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2499 ceil_byte_length(tdata->ciphertext.len));
2500 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2503 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2505 expected_ciphertext_shifted,
2506 tdata->validDataLenInBits.len,
2508 "Snow3G Ciphertext data not as expected");
2512 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2514 struct crypto_testsuite_params *ts_params = &testsuite_params;
2515 struct crypto_unittest_params *ut_params = &unittest_params;
2519 uint8_t *plaintext, *ciphertext;
2520 unsigned ciphertext_pad_len;
2521 unsigned ciphertext_len;
2523 /* Create SNOW3G session */
2524 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2525 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2526 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2527 tdata->key.data, tdata->key.len);
2531 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2533 /* Clear mbuf payload */
2534 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2535 rte_pktmbuf_tailroom(ut_params->ibuf));
2537 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2538 /* Append data which is padded to a multiple of */
2539 /* the algorithms block size */
2540 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2541 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2542 ciphertext_pad_len);
2543 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2545 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2547 /* Create SNOW3G operation */
2548 retval = create_snow3g_kasumi_cipher_operation(tdata->iv.data, tdata->iv.len,
2549 tdata->validCipherLenInBits.len,
2550 tdata->validCipherOffsetLenInBits.len,
2551 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2555 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2557 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2558 ut_params->obuf = ut_params->op->sym->m_dst;
2559 if (ut_params->obuf)
2560 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2563 plaintext = ciphertext;
2565 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2568 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2569 tdata->plaintext.data,
2570 tdata->validDataLenInBits.len,
2571 "Snow3G Plaintext data not as expected");
2575 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2577 struct crypto_testsuite_params *ts_params = &testsuite_params;
2578 struct crypto_unittest_params *ut_params = &unittest_params;
2582 uint8_t *plaintext, *ciphertext;
2583 unsigned ciphertext_pad_len;
2584 unsigned ciphertext_len;
2586 /* Create SNOW3G session */
2587 retval = create_snow3g_kasumi_cipher_session(ts_params->valid_devs[0],
2588 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2589 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2590 tdata->key.data, tdata->key.len);
2594 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2595 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2597 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2598 "Failed to allocate input buffer");
2599 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2600 "Failed to allocate output buffer");
2602 /* Clear mbuf payload */
2603 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2604 rte_pktmbuf_tailroom(ut_params->ibuf));
2606 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2607 rte_pktmbuf_tailroom(ut_params->obuf));
2609 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2610 /* Append data which is padded to a multiple of */
2611 /* the algorithms block size */
2612 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2613 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2614 ciphertext_pad_len);
2615 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2616 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2618 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2620 /* Create SNOW3G operation */
2621 retval = create_snow3g_kasumi_cipher_operation_oop(tdata->iv.data,
2623 tdata->validCipherLenInBits.len,
2624 tdata->validCipherOffsetLenInBits.len,
2625 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2629 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2631 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2632 ut_params->obuf = ut_params->op->sym->m_dst;
2633 if (ut_params->obuf)
2634 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2637 plaintext = ciphertext;
2639 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2642 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2643 tdata->plaintext.data,
2644 tdata->validDataLenInBits.len,
2645 "Snow3G Plaintext data not as expected");
2650 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2652 struct crypto_testsuite_params *ts_params = &testsuite_params;
2653 struct crypto_unittest_params *ut_params = &unittest_params;
2657 uint8_t *plaintext, *ciphertext;
2658 unsigned plaintext_pad_len;
2659 unsigned plaintext_len;
2661 /* Create SNOW3G session */
2662 retval = create_snow3g_kasumi_cipher_auth_session(ts_params->valid_devs[0],
2663 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2664 RTE_CRYPTO_AUTH_OP_GENERATE,
2665 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2666 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2667 tdata->key.data, tdata->key.len,
2668 tdata->aad.len, tdata->digest.len);
2671 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2673 /* clear mbuf payload */
2674 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2675 rte_pktmbuf_tailroom(ut_params->ibuf));
2677 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2678 /* Append data which is padded to a multiple of */
2679 /* the algorithms block size */
2680 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2681 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2683 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2685 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2687 /* Create SNOW3G operation */
2688 retval = create_snow3g_kasumi_cipher_hash_operation(tdata->digest.data,
2689 tdata->digest.len, tdata->aad.data,
2690 tdata->aad.len, /*tdata->plaintext.len,*/
2691 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2692 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2693 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2694 tdata->iv.data, tdata->iv.len,
2695 tdata->validCipherLenInBits.len,
2696 tdata->validCipherOffsetLenInBits.len,
2697 tdata->validAuthLenInBits.len,
2698 tdata->validAuthOffsetLenInBits.len
2703 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2705 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2706 ut_params->obuf = ut_params->op->sym->m_src;
2707 if (ut_params->obuf)
2708 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2709 + tdata->iv.len + tdata->aad.len;
2711 ciphertext = plaintext;
2713 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2715 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2717 tdata->ciphertext.data,
2718 tdata->validDataLenInBits.len,
2719 "Snow3G Ciphertext data not as expected");
2721 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2722 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2725 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2728 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2729 "Snow3G Generated auth tag not as expected");
2733 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2735 struct crypto_testsuite_params *ts_params = &testsuite_params;
2736 struct crypto_unittest_params *ut_params = &unittest_params;
2740 uint8_t *plaintext, *ciphertext;
2741 unsigned plaintext_pad_len;
2742 unsigned plaintext_len;
2744 /* Create SNOW3G session */
2745 retval = create_snow3g_kasumi_auth_cipher_session(ts_params->valid_devs[0],
2746 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2747 RTE_CRYPTO_AUTH_OP_GENERATE,
2748 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2749 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2750 tdata->key.data, tdata->key.len,
2751 tdata->aad.len, tdata->digest.len);
2755 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2757 /* clear mbuf payload */
2758 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2759 rte_pktmbuf_tailroom(ut_params->ibuf));
2761 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2762 /* Append data which is padded to a multiple of */
2763 /* the algorithms block size */
2764 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2765 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2767 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2769 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2771 /* Create SNOW3G operation */
2772 retval = create_snow3g_kasumi_auth_cipher_operation(
2774 tdata->iv.data, tdata->iv.len,
2775 tdata->aad.data, tdata->aad.len,
2777 tdata->validCipherLenInBits.len,
2778 tdata->validCipherOffsetLenInBits.len,
2779 tdata->validAuthLenInBits.len,
2780 tdata->validAuthOffsetLenInBits.len,
2781 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2782 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
2788 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2790 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2791 ut_params->obuf = ut_params->op->sym->m_src;
2792 if (ut_params->obuf)
2793 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2794 + tdata->aad.len + tdata->iv.len;
2796 ciphertext = plaintext;
2798 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2799 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2800 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2803 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2805 tdata->ciphertext.data,
2806 tdata->validDataLenInBits.len,
2807 "Snow3G Ciphertext data not as expected");
2810 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2813 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2814 "Snow3G Generated auth tag not as expected");
2819 test_kasumi_encryption_test_case_1(void)
2821 return test_kasumi_encryption(&kasumi_test_case_1);
2825 test_kasumi_encryption_test_case_1_oop(void)
2827 return test_kasumi_encryption_oop(&kasumi_test_case_1);
2831 test_kasumi_encryption_test_case_2(void)
2833 return test_kasumi_encryption(&kasumi_test_case_2);
2837 test_kasumi_encryption_test_case_3(void)
2839 return test_kasumi_encryption(&kasumi_test_case_3);
2843 test_kasumi_encryption_test_case_4(void)
2845 return test_kasumi_encryption(&kasumi_test_case_4);
2849 test_kasumi_encryption_test_case_5(void)
2851 return test_kasumi_encryption(&kasumi_test_case_5);
2855 test_kasumi_decryption_test_case_1(void)
2857 return test_kasumi_decryption(&kasumi_test_case_1);
2861 test_kasumi_decryption_test_case_1_oop(void)
2863 return test_kasumi_decryption_oop(&kasumi_test_case_1);
2867 test_kasumi_decryption_test_case_2(void)
2869 return test_kasumi_decryption(&kasumi_test_case_2);
2873 test_kasumi_decryption_test_case_3(void)
2875 return test_kasumi_decryption(&kasumi_test_case_3);
2879 test_kasumi_decryption_test_case_4(void)
2881 return test_kasumi_decryption(&kasumi_test_case_4);
2885 test_kasumi_decryption_test_case_5(void)
2887 return test_kasumi_decryption(&kasumi_test_case_5);
2890 test_snow3g_encryption_test_case_1(void)
2892 return test_snow3g_encryption(&snow3g_test_case_1);
2896 test_snow3g_encryption_test_case_1_oop(void)
2898 return test_snow3g_encryption_oop(&snow3g_test_case_1);
2902 test_snow3g_encryption_test_case_1_offset_oop(void)
2904 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
2908 test_snow3g_encryption_test_case_2(void)
2910 return test_snow3g_encryption(&snow3g_test_case_2);
2914 test_snow3g_encryption_test_case_3(void)
2916 return test_snow3g_encryption(&snow3g_test_case_3);
2920 test_snow3g_encryption_test_case_4(void)
2922 return test_snow3g_encryption(&snow3g_test_case_4);
2926 test_snow3g_encryption_test_case_5(void)
2928 return test_snow3g_encryption(&snow3g_test_case_5);
2932 test_snow3g_decryption_test_case_1(void)
2934 return test_snow3g_decryption(&snow3g_test_case_1);
2938 test_snow3g_decryption_test_case_1_oop(void)
2940 return test_snow3g_decryption_oop(&snow3g_test_case_1);
2944 test_snow3g_decryption_test_case_2(void)
2946 return test_snow3g_decryption(&snow3g_test_case_2);
2950 test_snow3g_decryption_test_case_3(void)
2952 return test_snow3g_decryption(&snow3g_test_case_3);
2956 test_snow3g_decryption_test_case_4(void)
2958 return test_snow3g_decryption(&snow3g_test_case_4);
2962 test_snow3g_decryption_test_case_5(void)
2964 return test_snow3g_decryption(&snow3g_test_case_5);
2967 test_snow3g_authenticated_encryption_test_case_1(void)
2969 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2973 test_snow3g_encrypted_authentication_test_case_1(void)
2975 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2978 /* ***** AES-GCM Tests ***** */
2981 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2982 const uint8_t *key, const uint8_t key_len,
2983 const uint8_t aad_len, const uint8_t auth_len)
2985 uint8_t cipher_key[key_len];
2987 struct crypto_unittest_params *ut_params = &unittest_params;
2990 memcpy(cipher_key, key, key_len);
2992 /* Setup Cipher Parameters */
2993 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2994 ut_params->cipher_xform.next = NULL;
2996 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2997 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2998 ut_params->cipher_xform.cipher.op = op;
2999 ut_params->cipher_xform.cipher.key.data = cipher_key;
3000 ut_params->cipher_xform.cipher.key.length = key_len;
3002 TEST_HEXDUMP(stdout, "key:", key, key_len);
3004 /* Setup Authentication Parameters */
3005 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3006 ut_params->auth_xform.next = NULL;
3008 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3010 ut_params->auth_xform.auth.digest_length = auth_len;
3011 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3012 ut_params->auth_xform.auth.key.length = 0;
3013 ut_params->auth_xform.auth.key.data = NULL;
3015 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3016 ut_params->cipher_xform.next = &ut_params->auth_xform;
3018 /* Create Crypto session*/
3019 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3020 &ut_params->cipher_xform);
3021 } else {/* Create Crypto session*/
3022 ut_params->auth_xform.next = &ut_params->cipher_xform;
3023 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3024 &ut_params->auth_xform);
3027 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3033 create_gcm_operation(enum rte_crypto_cipher_operation op,
3034 const uint8_t *auth_tag, const unsigned auth_tag_len,
3035 const uint8_t *iv, const unsigned iv_len,
3036 const uint8_t *aad, const unsigned aad_len,
3037 const unsigned data_len, unsigned data_pad_len)
3039 struct crypto_testsuite_params *ts_params = &testsuite_params;
3040 struct crypto_unittest_params *ut_params = &unittest_params;
3042 unsigned iv_pad_len = 0, aad_buffer_len;
3044 /* Generate Crypto op data structure */
3045 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3046 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3047 TEST_ASSERT_NOT_NULL(ut_params->op,
3048 "Failed to allocate symmetric crypto operation struct");
3050 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3054 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3055 ut_params->ibuf, auth_tag_len);
3056 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3057 "no room to append digest");
3058 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3059 ut_params->ibuf, data_pad_len);
3060 sym_op->auth.digest.length = auth_tag_len;
3062 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3063 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3064 TEST_HEXDUMP(stdout, "digest:",
3065 sym_op->auth.digest.data,
3066 sym_op->auth.digest.length);
3070 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3072 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3073 ut_params->ibuf, iv_pad_len);
3074 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3076 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3077 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3078 sym_op->cipher.iv.length = iv_pad_len;
3080 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3084 sym_op->cipher.iv.data[15] = 1;
3087 * Always allocate the aad up to the block size.
3088 * The cryptodev API calls out -
3089 * - the array must be big enough to hold the AAD, plus any
3090 * space to round this up to the nearest multiple of the
3091 * block size (16 bytes).
3093 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3095 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3096 ut_params->ibuf, aad_buffer_len);
3097 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3098 "no room to prepend aad");
3099 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3101 sym_op->auth.aad.length = aad_len;
3103 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3104 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3106 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3107 TEST_HEXDUMP(stdout, "aad:",
3108 sym_op->auth.aad.data, aad_len);
3110 sym_op->cipher.data.length = data_len;
3111 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3113 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3114 sym_op->auth.data.length = data_len;
3120 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3122 struct crypto_testsuite_params *ts_params = &testsuite_params;
3123 struct crypto_unittest_params *ut_params = &unittest_params;
3127 uint8_t *plaintext, *ciphertext, *auth_tag;
3128 uint16_t plaintext_pad_len;
3130 /* Create GCM session */
3131 retval = create_gcm_session(ts_params->valid_devs[0],
3132 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3133 tdata->key.data, tdata->key.len,
3134 tdata->aad.len, tdata->auth_tag.len);
3139 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3141 /* clear mbuf payload */
3142 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3143 rte_pktmbuf_tailroom(ut_params->ibuf));
3146 * Append data which is padded to a multiple
3147 * of the algorithms block size
3149 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3151 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3153 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3155 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3157 /* Create GCM opertaion */
3158 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3159 tdata->auth_tag.data, tdata->auth_tag.len,
3160 tdata->iv.data, tdata->iv.len,
3161 tdata->aad.data, tdata->aad.len,
3162 tdata->plaintext.len, plaintext_pad_len);
3166 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3168 ut_params->op->sym->m_src = ut_params->ibuf;
3170 /* Process crypto operation */
3171 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3172 ut_params->op), "failed to process sym crypto op");
3174 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3175 "crypto op processing failed");
3177 if (ut_params->op->sym->m_dst) {
3178 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3180 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3181 uint8_t *, plaintext_pad_len);
3183 ciphertext = plaintext;
3184 auth_tag = plaintext + plaintext_pad_len;
3187 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3188 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3191 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3193 tdata->ciphertext.data,
3194 tdata->ciphertext.len,
3195 "GCM Ciphertext data not as expected");
3197 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3199 tdata->auth_tag.data,
3200 tdata->auth_tag.len,
3201 "GCM Generated auth tag not as expected");
3208 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3210 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3214 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3216 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3220 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3222 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3226 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3228 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3232 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3234 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3238 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3240 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3244 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3246 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3250 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3252 struct crypto_testsuite_params *ts_params = &testsuite_params;
3253 struct crypto_unittest_params *ut_params = &unittest_params;
3257 uint8_t *plaintext, *ciphertext;
3258 uint16_t ciphertext_pad_len;
3260 /* Create GCM session */
3261 retval = create_gcm_session(ts_params->valid_devs[0],
3262 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3263 tdata->key.data, tdata->key.len,
3264 tdata->aad.len, tdata->auth_tag.len);
3269 /* alloc mbuf and set payload */
3270 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3272 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3273 rte_pktmbuf_tailroom(ut_params->ibuf));
3275 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3277 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3278 ciphertext_pad_len);
3279 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3281 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3283 /* Create GCM opertaion */
3284 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3285 tdata->auth_tag.data, tdata->auth_tag.len,
3286 tdata->iv.data, tdata->iv.len,
3287 tdata->aad.data, tdata->aad.len,
3288 tdata->ciphertext.len, ciphertext_pad_len);
3293 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3295 ut_params->op->sym->m_src = ut_params->ibuf;
3297 /* Process crypto operation */
3298 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3299 ut_params->op), "failed to process sym crypto op");
3301 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3302 "crypto op processing failed");
3304 if (ut_params->op->sym->m_dst)
3305 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3308 plaintext = ciphertext;
3310 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3313 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3315 tdata->plaintext.data,
3316 tdata->plaintext.len,
3317 "GCM plaintext data not as expected");
3319 TEST_ASSERT_EQUAL(ut_params->op->status,
3320 RTE_CRYPTO_OP_STATUS_SUCCESS,
3321 "GCM authentication failed");
3326 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3328 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3332 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3334 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3338 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3340 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3344 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3346 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3350 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3352 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3356 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3358 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3362 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3364 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3370 struct crypto_testsuite_params *ts_params = &testsuite_params;
3371 struct rte_cryptodev_stats stats;
3372 struct rte_cryptodev *dev;
3373 cryptodev_stats_get_t temp_pfn;
3375 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3376 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3377 &stats) == -ENODEV),
3378 "rte_cryptodev_stats_get invalid dev failed");
3379 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3380 "rte_cryptodev_stats_get invalid Param failed");
3381 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3382 temp_pfn = dev->dev_ops->stats_get;
3383 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3384 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3386 "rte_cryptodev_stats_get invalid Param failed");
3387 dev->dev_ops->stats_get = temp_pfn;
3389 /* Test expected values */
3391 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3393 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3395 "rte_cryptodev_stats_get failed");
3396 TEST_ASSERT((stats.enqueued_count == 1),
3397 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3398 TEST_ASSERT((stats.dequeued_count == 1),
3399 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3400 TEST_ASSERT((stats.enqueue_err_count == 0),
3401 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3402 TEST_ASSERT((stats.dequeue_err_count == 0),
3403 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3405 /* invalid device but should ignore and not reset device stats*/
3406 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3407 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3409 "rte_cryptodev_stats_get failed");
3410 TEST_ASSERT((stats.enqueued_count == 1),
3411 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3413 /* check that a valid reset clears stats */
3414 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3415 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3417 "rte_cryptodev_stats_get failed");
3418 TEST_ASSERT((stats.enqueued_count == 0),
3419 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3420 TEST_ASSERT((stats.dequeued_count == 0),
3421 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3423 return TEST_SUCCESS;
3426 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
3427 struct crypto_unittest_params *ut_params,
3428 enum rte_crypto_auth_operation op,
3429 const struct HMAC_MD5_vector *test_case)
3433 memcpy(key, test_case->key.data, test_case->key.len);
3435 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3436 ut_params->auth_xform.next = NULL;
3437 ut_params->auth_xform.auth.op = op;
3439 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
3441 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
3442 ut_params->auth_xform.auth.add_auth_data_length = 0;
3443 ut_params->auth_xform.auth.key.length = test_case->key.len;
3444 ut_params->auth_xform.auth.key.data = key;
3446 ut_params->sess = rte_cryptodev_sym_session_create(
3447 ts_params->valid_devs[0], &ut_params->auth_xform);
3449 if (ut_params->sess == NULL)
3452 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3454 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3455 rte_pktmbuf_tailroom(ut_params->ibuf));
3460 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
3461 const struct HMAC_MD5_vector *test_case,
3462 uint8_t **plaintext)
3464 uint16_t plaintext_pad_len;
3466 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3468 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3471 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3473 memcpy(*plaintext, test_case->plaintext.data,
3474 test_case->plaintext.len);
3476 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3477 ut_params->ibuf, MD5_DIGEST_LEN);
3478 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3479 "no room to append digest");
3480 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3481 ut_params->ibuf, plaintext_pad_len);
3482 sym_op->auth.digest.length = MD5_DIGEST_LEN;
3484 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
3485 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
3486 test_case->auth_tag.len);
3489 sym_op->auth.data.offset = 0;
3490 sym_op->auth.data.length = test_case->plaintext.len;
3492 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3493 ut_params->op->sym->m_src = ut_params->ibuf;
3499 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
3501 uint16_t plaintext_pad_len;
3502 uint8_t *plaintext, *auth_tag;
3504 struct crypto_testsuite_params *ts_params = &testsuite_params;
3505 struct crypto_unittest_params *ut_params = &unittest_params;
3507 if (MD5_HMAC_create_session(ts_params, ut_params,
3508 RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
3511 /* Generate Crypto op data structure */
3512 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3513 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3514 TEST_ASSERT_NOT_NULL(ut_params->op,
3515 "Failed to allocate symmetric crypto operation struct");
3517 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3520 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3523 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3524 ut_params->op), "failed to process sym crypto op");
3526 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3527 "crypto op processing failed");
3529 if (ut_params->op->sym->m_dst) {
3530 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3531 uint8_t *, plaintext_pad_len);
3533 auth_tag = plaintext + plaintext_pad_len;
3536 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3538 test_case->auth_tag.data,
3539 test_case->auth_tag.len,
3540 "HMAC_MD5 generated tag not as expected");
3542 return TEST_SUCCESS;
3546 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
3550 struct crypto_testsuite_params *ts_params = &testsuite_params;
3551 struct crypto_unittest_params *ut_params = &unittest_params;
3553 if (MD5_HMAC_create_session(ts_params, ut_params,
3554 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
3558 /* Generate Crypto op data structure */
3559 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3560 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3561 TEST_ASSERT_NOT_NULL(ut_params->op,
3562 "Failed to allocate symmetric crypto operation struct");
3564 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3567 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3568 ut_params->op), "failed to process sym crypto op");
3570 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3571 "HMAC_MD5 crypto op processing failed");
3573 return TEST_SUCCESS;
3577 test_MD5_HMAC_generate_case_1(void)
3579 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
3583 test_MD5_HMAC_verify_case_1(void)
3585 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
3589 test_MD5_HMAC_generate_case_2(void)
3591 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
3595 test_MD5_HMAC_verify_case_2(void)
3597 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
3601 test_multi_session(void)
3603 struct crypto_testsuite_params *ts_params = &testsuite_params;
3604 struct crypto_unittest_params *ut_params = &unittest_params;
3606 struct rte_cryptodev_info dev_info;
3607 struct rte_cryptodev_sym_session **sessions;
3611 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3614 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3616 sessions = rte_malloc(NULL,
3617 (sizeof(struct rte_cryptodev_sym_session *) *
3618 dev_info.sym.max_nb_sessions) + 1, 0);
3620 /* Create multiple crypto sessions*/
3621 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3622 sessions[i] = rte_cryptodev_sym_session_create(
3623 ts_params->valid_devs[0],
3624 &ut_params->auth_xform);
3625 TEST_ASSERT_NOT_NULL(sessions[i],
3626 "Session creation failed at session number %u",
3629 /* Attempt to send a request on each session */
3630 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3631 sessions[i], ut_params, ts_params),
3632 "Failed to perform decrypt on request "
3634 /* free crypto operation structure */
3636 rte_crypto_op_free(ut_params->op);
3639 * free mbuf - both obuf and ibuf are usually the same,
3640 * so check if they point at the same address is necessary,
3641 * to avoid freeing the mbuf twice.
3643 if (ut_params->obuf) {
3644 rte_pktmbuf_free(ut_params->obuf);
3645 if (ut_params->ibuf == ut_params->obuf)
3646 ut_params->ibuf = 0;
3647 ut_params->obuf = 0;
3649 if (ut_params->ibuf) {
3650 rte_pktmbuf_free(ut_params->ibuf);
3651 ut_params->ibuf = 0;
3655 /* Next session create should fail */
3656 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3657 &ut_params->auth_xform);
3658 TEST_ASSERT_NULL(sessions[i],
3659 "Session creation succeeded unexpectedly!");
3661 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3662 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3667 return TEST_SUCCESS;
3671 test_null_cipher_only_operation(void)
3673 struct crypto_testsuite_params *ts_params = &testsuite_params;
3674 struct crypto_unittest_params *ut_params = &unittest_params;
3676 /* Generate test mbuf data and space for digest */
3677 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3678 catch_22_quote, QUOTE_512_BYTES, 0);
3680 /* Setup Cipher Parameters */
3681 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3682 ut_params->cipher_xform.next = NULL;
3684 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3685 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3687 /* Create Crypto session*/
3688 ut_params->sess = rte_cryptodev_sym_session_create(
3689 ts_params->valid_devs[0], &ut_params->cipher_xform);
3690 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3692 /* Generate Crypto op data structure */
3693 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3694 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3695 TEST_ASSERT_NOT_NULL(ut_params->op,
3696 "Failed to allocate symmetric crypto operation struct");
3698 /* Set crypto operation data parameters */
3699 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3701 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3703 /* set crypto operation source mbuf */
3704 sym_op->m_src = ut_params->ibuf;
3706 sym_op->cipher.data.offset = 0;
3707 sym_op->cipher.data.length = QUOTE_512_BYTES;
3709 /* Process crypto operation */
3710 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3712 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3714 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3715 "crypto operation processing failed");
3718 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3719 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3722 "Ciphertext data not as expected");
3724 return TEST_SUCCESS;
3728 test_null_auth_only_operation(void)
3730 struct crypto_testsuite_params *ts_params = &testsuite_params;
3731 struct crypto_unittest_params *ut_params = &unittest_params;
3733 /* Generate test mbuf data and space for digest */
3734 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3735 catch_22_quote, QUOTE_512_BYTES, 0);
3737 /* Setup HMAC Parameters */
3738 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3739 ut_params->auth_xform.next = NULL;
3741 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3742 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3744 /* Create Crypto session*/
3745 ut_params->sess = rte_cryptodev_sym_session_create(
3746 ts_params->valid_devs[0], &ut_params->auth_xform);
3747 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3749 /* Generate Crypto op data structure */
3750 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3751 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3752 TEST_ASSERT_NOT_NULL(ut_params->op,
3753 "Failed to allocate symmetric crypto operation struct");
3755 /* Set crypto operation data parameters */
3756 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3758 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3760 sym_op->m_src = ut_params->ibuf;
3762 sym_op->auth.data.offset = 0;
3763 sym_op->auth.data.length = QUOTE_512_BYTES;
3765 /* Process crypto operation */
3766 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3768 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3770 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3771 "crypto operation processing failed");
3773 return TEST_SUCCESS;
3777 test_null_cipher_auth_operation(void)
3779 struct crypto_testsuite_params *ts_params = &testsuite_params;
3780 struct crypto_unittest_params *ut_params = &unittest_params;
3782 /* Generate test mbuf data and space for digest */
3783 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3784 catch_22_quote, QUOTE_512_BYTES, 0);
3786 /* Setup Cipher Parameters */
3787 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3788 ut_params->cipher_xform.next = &ut_params->auth_xform;
3790 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3791 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3793 /* Setup HMAC Parameters */
3794 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3795 ut_params->auth_xform.next = NULL;
3797 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3798 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3800 /* Create Crypto session*/
3801 ut_params->sess = rte_cryptodev_sym_session_create(
3802 ts_params->valid_devs[0], &ut_params->cipher_xform);
3803 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3805 /* Generate Crypto op data structure */
3806 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3807 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3808 TEST_ASSERT_NOT_NULL(ut_params->op,
3809 "Failed to allocate symmetric crypto operation struct");
3811 /* Set crypto operation data parameters */
3812 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3814 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3816 sym_op->m_src = ut_params->ibuf;
3818 sym_op->cipher.data.offset = 0;
3819 sym_op->cipher.data.length = QUOTE_512_BYTES;
3821 sym_op->auth.data.offset = 0;
3822 sym_op->auth.data.length = QUOTE_512_BYTES;
3824 /* Process crypto operation */
3825 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3827 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3829 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3830 "crypto operation processing failed");
3833 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3834 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3837 "Ciphertext data not as expected");
3839 return TEST_SUCCESS;
3843 test_null_auth_cipher_operation(void)
3845 struct crypto_testsuite_params *ts_params = &testsuite_params;
3846 struct crypto_unittest_params *ut_params = &unittest_params;
3848 /* Generate test mbuf data and space for digest */
3849 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3850 catch_22_quote, QUOTE_512_BYTES, 0);
3852 /* Setup Cipher Parameters */
3853 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3854 ut_params->cipher_xform.next = NULL;
3856 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3857 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3859 /* Setup HMAC Parameters */
3860 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3861 ut_params->auth_xform.next = &ut_params->cipher_xform;
3863 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3864 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3866 /* Create Crypto session*/
3867 ut_params->sess = rte_cryptodev_sym_session_create(
3868 ts_params->valid_devs[0], &ut_params->cipher_xform);
3869 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3871 /* Generate Crypto op data structure */
3872 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3873 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3874 TEST_ASSERT_NOT_NULL(ut_params->op,
3875 "Failed to allocate symmetric crypto operation struct");
3877 /* Set crypto operation data parameters */
3878 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3880 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3882 sym_op->m_src = ut_params->ibuf;
3884 sym_op->cipher.data.offset = 0;
3885 sym_op->cipher.data.length = QUOTE_512_BYTES;
3887 sym_op->auth.data.offset = 0;
3888 sym_op->auth.data.length = QUOTE_512_BYTES;
3890 /* Process crypto operation */
3891 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3893 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3895 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3896 "crypto operation processing failed");
3899 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3900 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3903 "Ciphertext data not as expected");
3905 return TEST_SUCCESS;
3910 test_null_invalid_operation(void)
3912 struct crypto_testsuite_params *ts_params = &testsuite_params;
3913 struct crypto_unittest_params *ut_params = &unittest_params;
3915 /* Setup Cipher Parameters */
3916 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3917 ut_params->cipher_xform.next = NULL;
3919 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3920 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3922 /* Create Crypto session*/
3923 ut_params->sess = rte_cryptodev_sym_session_create(
3924 ts_params->valid_devs[0], &ut_params->cipher_xform);
3925 TEST_ASSERT_NULL(ut_params->sess,
3926 "Session creation succeeded unexpectedly");
3929 /* Setup HMAC Parameters */
3930 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3931 ut_params->auth_xform.next = NULL;
3933 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3934 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3936 /* Create Crypto session*/
3937 ut_params->sess = rte_cryptodev_sym_session_create(
3938 ts_params->valid_devs[0], &ut_params->auth_xform);
3939 TEST_ASSERT_NULL(ut_params->sess,
3940 "Session creation succeeded unexpectedly");
3942 return TEST_SUCCESS;
3946 #define NULL_BURST_LENGTH (32)
3949 test_null_burst_operation(void)
3951 struct crypto_testsuite_params *ts_params = &testsuite_params;
3952 struct crypto_unittest_params *ut_params = &unittest_params;
3954 unsigned i, burst_len = NULL_BURST_LENGTH;
3956 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3957 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3959 /* Setup Cipher Parameters */
3960 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3961 ut_params->cipher_xform.next = &ut_params->auth_xform;
3963 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3964 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3966 /* Setup HMAC Parameters */
3967 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3968 ut_params->auth_xform.next = NULL;
3970 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3971 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3973 /* Create Crypto session*/
3974 ut_params->sess = rte_cryptodev_sym_session_create(
3975 ts_params->valid_devs[0], &ut_params->cipher_xform);
3976 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3978 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3979 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3980 burst_len, "failed to generate burst of crypto ops");
3982 /* Generate an operation for each mbuf in burst */
3983 for (i = 0; i < burst_len; i++) {
3984 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3986 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3988 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3992 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3994 burst[i]->sym->m_src = m;
3997 /* Process crypto operation */
3998 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3999 0, burst, burst_len),
4001 "Error enqueuing burst");
4003 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4004 0, burst_dequeued, burst_len),
4006 "Error dequeuing burst");
4009 for (i = 0; i < burst_len; i++) {
4011 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4012 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4014 "data not as expected");
4016 rte_pktmbuf_free(burst[i]->sym->m_src);
4017 rte_crypto_op_free(burst[i]);
4020 return TEST_SUCCESS;
4026 static struct unit_test_suite cryptodev_qat_testsuite = {
4027 .suite_name = "Crypto QAT Unit Test Suite",
4028 .setup = testsuite_setup,
4029 .teardown = testsuite_teardown,
4030 .unit_test_cases = {
4031 TEST_CASE_ST(ut_setup, ut_teardown,
4032 test_device_configure_invalid_dev_id),
4033 TEST_CASE_ST(ut_setup, ut_teardown,
4034 test_device_configure_invalid_queue_pair_ids),
4035 TEST_CASE_ST(ut_setup, ut_teardown,
4036 test_queue_pair_descriptor_setup),
4037 TEST_CASE_ST(ut_setup, ut_teardown,
4038 test_multi_session),
4040 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
4041 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4043 /** AES GCM Authenticated Encryption */
4044 TEST_CASE_ST(ut_setup, ut_teardown,
4045 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4046 TEST_CASE_ST(ut_setup, ut_teardown,
4047 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4048 TEST_CASE_ST(ut_setup, ut_teardown,
4049 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4050 TEST_CASE_ST(ut_setup, ut_teardown,
4051 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4052 TEST_CASE_ST(ut_setup, ut_teardown,
4053 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4054 TEST_CASE_ST(ut_setup, ut_teardown,
4055 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4056 TEST_CASE_ST(ut_setup, ut_teardown,
4057 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4059 /** AES GCM Authenticated Decryption */
4060 TEST_CASE_ST(ut_setup, ut_teardown,
4061 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4062 TEST_CASE_ST(ut_setup, ut_teardown,
4063 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4064 TEST_CASE_ST(ut_setup, ut_teardown,
4065 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4066 TEST_CASE_ST(ut_setup, ut_teardown,
4067 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4068 TEST_CASE_ST(ut_setup, ut_teardown,
4069 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4070 TEST_CASE_ST(ut_setup, ut_teardown,
4071 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4072 TEST_CASE_ST(ut_setup, ut_teardown,
4073 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4075 /** Snow3G encrypt only (UEA2) */
4076 TEST_CASE_ST(ut_setup, ut_teardown,
4077 test_snow3g_encryption_test_case_1),
4078 TEST_CASE_ST(ut_setup, ut_teardown,
4079 test_snow3g_encryption_test_case_2),
4080 TEST_CASE_ST(ut_setup, ut_teardown,
4081 test_snow3g_encryption_test_case_3),
4082 TEST_CASE_ST(ut_setup, ut_teardown,
4083 test_snow3g_encryption_test_case_4),
4084 TEST_CASE_ST(ut_setup, ut_teardown,
4085 test_snow3g_encryption_test_case_5),
4087 TEST_CASE_ST(ut_setup, ut_teardown,
4088 test_snow3g_encryption_test_case_1_oop),
4089 TEST_CASE_ST(ut_setup, ut_teardown,
4090 test_snow3g_decryption_test_case_1_oop),
4092 /** Snow3G decrypt only (UEA2) */
4093 TEST_CASE_ST(ut_setup, ut_teardown,
4094 test_snow3g_decryption_test_case_1),
4095 TEST_CASE_ST(ut_setup, ut_teardown,
4096 test_snow3g_decryption_test_case_2),
4097 TEST_CASE_ST(ut_setup, ut_teardown,
4098 test_snow3g_decryption_test_case_3),
4099 TEST_CASE_ST(ut_setup, ut_teardown,
4100 test_snow3g_decryption_test_case_4),
4101 TEST_CASE_ST(ut_setup, ut_teardown,
4102 test_snow3g_decryption_test_case_5),
4103 TEST_CASE_ST(ut_setup, ut_teardown,
4104 test_snow3g_hash_generate_test_case_1),
4105 TEST_CASE_ST(ut_setup, ut_teardown,
4106 test_snow3g_hash_generate_test_case_2),
4107 TEST_CASE_ST(ut_setup, ut_teardown,
4108 test_snow3g_hash_generate_test_case_3),
4109 TEST_CASE_ST(ut_setup, ut_teardown,
4110 test_snow3g_hash_verify_test_case_1),
4111 TEST_CASE_ST(ut_setup, ut_teardown,
4112 test_snow3g_hash_verify_test_case_2),
4113 TEST_CASE_ST(ut_setup, ut_teardown,
4114 test_snow3g_hash_verify_test_case_3),
4115 TEST_CASE_ST(ut_setup, ut_teardown,
4116 test_snow3g_authenticated_encryption_test_case_1),
4117 TEST_CASE_ST(ut_setup, ut_teardown,
4118 test_snow3g_encrypted_authentication_test_case_1),
4120 /** HMAC_MD5 Authentication */
4121 TEST_CASE_ST(ut_setup, ut_teardown,
4122 test_MD5_HMAC_generate_case_1),
4123 TEST_CASE_ST(ut_setup, ut_teardown,
4124 test_MD5_HMAC_verify_case_1),
4125 TEST_CASE_ST(ut_setup, ut_teardown,
4126 test_MD5_HMAC_generate_case_2),
4127 TEST_CASE_ST(ut_setup, ut_teardown,
4128 test_MD5_HMAC_verify_case_2),
4131 TEST_CASE_ST(ut_setup, ut_teardown,
4132 test_null_auth_only_operation),
4133 TEST_CASE_ST(ut_setup, ut_teardown,
4134 test_null_cipher_only_operation),
4135 TEST_CASE_ST(ut_setup, ut_teardown,
4136 test_null_cipher_auth_operation),
4137 TEST_CASE_ST(ut_setup, ut_teardown,
4138 test_null_auth_cipher_operation),
4140 TEST_CASES_END() /**< NULL terminate unit test array */
4144 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
4145 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4146 .setup = testsuite_setup,
4147 .teardown = testsuite_teardown,
4148 .unit_test_cases = {
4149 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
4151 TEST_CASES_END() /**< NULL terminate unit test array */
4155 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
4156 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4157 .setup = testsuite_setup,
4158 .teardown = testsuite_teardown,
4159 .unit_test_cases = {
4160 /** AES GCM Authenticated Encryption */
4161 TEST_CASE_ST(ut_setup, ut_teardown,
4162 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4163 TEST_CASE_ST(ut_setup, ut_teardown,
4164 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4165 TEST_CASE_ST(ut_setup, ut_teardown,
4166 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4167 TEST_CASE_ST(ut_setup, ut_teardown,
4168 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4169 TEST_CASE_ST(ut_setup, ut_teardown,
4170 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4171 TEST_CASE_ST(ut_setup, ut_teardown,
4172 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4173 TEST_CASE_ST(ut_setup, ut_teardown,
4174 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4176 /** AES GCM Authenticated Decryption */
4177 TEST_CASE_ST(ut_setup, ut_teardown,
4178 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4179 TEST_CASE_ST(ut_setup, ut_teardown,
4180 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4181 TEST_CASE_ST(ut_setup, ut_teardown,
4182 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4183 TEST_CASE_ST(ut_setup, ut_teardown,
4184 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4185 TEST_CASE_ST(ut_setup, ut_teardown,
4186 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4187 TEST_CASE_ST(ut_setup, ut_teardown,
4188 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4189 TEST_CASE_ST(ut_setup, ut_teardown,
4190 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4192 TEST_CASES_END() /**< NULL terminate unit test array */
4196 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
4197 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4198 .setup = testsuite_setup,
4199 .teardown = testsuite_teardown,
4200 .unit_test_cases = {
4201 /** KASUMI encrypt only (UEA1) */
4202 TEST_CASE_ST(ut_setup, ut_teardown,
4203 test_kasumi_encryption_test_case_1),
4204 TEST_CASE_ST(ut_setup, ut_teardown,
4205 test_kasumi_encryption_test_case_2),
4206 TEST_CASE_ST(ut_setup, ut_teardown,
4207 test_kasumi_encryption_test_case_3),
4208 TEST_CASE_ST(ut_setup, ut_teardown,
4209 test_kasumi_encryption_test_case_4),
4210 TEST_CASE_ST(ut_setup, ut_teardown,
4211 test_kasumi_encryption_test_case_5),
4212 /** KASUMI decrypt only (UEA1) */
4213 TEST_CASE_ST(ut_setup, ut_teardown,
4214 test_kasumi_decryption_test_case_1),
4215 TEST_CASE_ST(ut_setup, ut_teardown,
4216 test_kasumi_decryption_test_case_2),
4217 TEST_CASE_ST(ut_setup, ut_teardown,
4218 test_kasumi_decryption_test_case_3),
4219 TEST_CASE_ST(ut_setup, ut_teardown,
4220 test_kasumi_decryption_test_case_4),
4221 TEST_CASE_ST(ut_setup, ut_teardown,
4222 test_kasumi_decryption_test_case_5),
4224 TEST_CASE_ST(ut_setup, ut_teardown,
4225 test_kasumi_encryption_test_case_1_oop),
4226 TEST_CASE_ST(ut_setup, ut_teardown,
4227 test_kasumi_decryption_test_case_1_oop),
4229 /** KASUMI hash only (UIA1) */
4230 TEST_CASE_ST(ut_setup, ut_teardown,
4231 test_kasumi_hash_generate_test_case_1),
4232 TEST_CASE_ST(ut_setup, ut_teardown,
4233 test_kasumi_hash_generate_test_case_2),
4234 TEST_CASE_ST(ut_setup, ut_teardown,
4235 test_kasumi_hash_generate_test_case_3),
4236 TEST_CASE_ST(ut_setup, ut_teardown,
4237 test_kasumi_hash_generate_test_case_4),
4238 TEST_CASE_ST(ut_setup, ut_teardown,
4239 test_kasumi_hash_generate_test_case_5),
4240 TEST_CASE_ST(ut_setup, ut_teardown,
4241 test_kasumi_hash_verify_test_case_1),
4242 TEST_CASE_ST(ut_setup, ut_teardown,
4243 test_kasumi_hash_verify_test_case_2),
4244 TEST_CASE_ST(ut_setup, ut_teardown,
4245 test_kasumi_hash_verify_test_case_3),
4246 TEST_CASE_ST(ut_setup, ut_teardown,
4247 test_kasumi_hash_verify_test_case_4),
4248 TEST_CASE_ST(ut_setup, ut_teardown,
4249 test_kasumi_hash_verify_test_case_5),
4251 TEST_CASES_END() /**< NULL terminate unit test array */
4254 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4255 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4256 .setup = testsuite_setup,
4257 .teardown = testsuite_teardown,
4258 .unit_test_cases = {
4259 /** Snow3G encrypt only (UEA2) */
4260 TEST_CASE_ST(ut_setup, ut_teardown,
4261 test_snow3g_encryption_test_case_1),
4262 TEST_CASE_ST(ut_setup, ut_teardown,
4263 test_snow3g_encryption_test_case_2),
4264 TEST_CASE_ST(ut_setup, ut_teardown,
4265 test_snow3g_encryption_test_case_3),
4266 TEST_CASE_ST(ut_setup, ut_teardown,
4267 test_snow3g_encryption_test_case_4),
4268 TEST_CASE_ST(ut_setup, ut_teardown,
4269 test_snow3g_encryption_test_case_5),
4271 TEST_CASE_ST(ut_setup, ut_teardown,
4272 test_snow3g_encryption_test_case_1_oop),
4273 TEST_CASE_ST(ut_setup, ut_teardown,
4274 test_snow3g_decryption_test_case_1_oop),
4276 TEST_CASE_ST(ut_setup, ut_teardown,
4277 test_snow3g_encryption_test_case_1_offset_oop),
4279 /** Snow3G decrypt only (UEA2) */
4280 TEST_CASE_ST(ut_setup, ut_teardown,
4281 test_snow3g_decryption_test_case_1),
4282 TEST_CASE_ST(ut_setup, ut_teardown,
4283 test_snow3g_decryption_test_case_2),
4284 TEST_CASE_ST(ut_setup, ut_teardown,
4285 test_snow3g_decryption_test_case_3),
4286 TEST_CASE_ST(ut_setup, ut_teardown,
4287 test_snow3g_decryption_test_case_4),
4288 TEST_CASE_ST(ut_setup, ut_teardown,
4289 test_snow3g_decryption_test_case_5),
4290 TEST_CASE_ST(ut_setup, ut_teardown,
4291 test_snow3g_hash_generate_test_case_1),
4292 TEST_CASE_ST(ut_setup, ut_teardown,
4293 test_snow3g_hash_generate_test_case_2),
4294 TEST_CASE_ST(ut_setup, ut_teardown,
4295 test_snow3g_hash_generate_test_case_3),
4296 /* Tests with buffers which length is not byte-aligned */
4297 TEST_CASE_ST(ut_setup, ut_teardown,
4298 test_snow3g_hash_generate_test_case_4),
4299 TEST_CASE_ST(ut_setup, ut_teardown,
4300 test_snow3g_hash_generate_test_case_5),
4301 TEST_CASE_ST(ut_setup, ut_teardown,
4302 test_snow3g_hash_generate_test_case_6),
4303 TEST_CASE_ST(ut_setup, ut_teardown,
4304 test_snow3g_hash_verify_test_case_1),
4305 TEST_CASE_ST(ut_setup, ut_teardown,
4306 test_snow3g_hash_verify_test_case_2),
4307 TEST_CASE_ST(ut_setup, ut_teardown,
4308 test_snow3g_hash_verify_test_case_3),
4309 /* Tests with buffers which length is not byte-aligned */
4310 TEST_CASE_ST(ut_setup, ut_teardown,
4311 test_snow3g_hash_verify_test_case_4),
4312 TEST_CASE_ST(ut_setup, ut_teardown,
4313 test_snow3g_hash_verify_test_case_5),
4314 TEST_CASE_ST(ut_setup, ut_teardown,
4315 test_snow3g_hash_verify_test_case_6),
4316 TEST_CASE_ST(ut_setup, ut_teardown,
4317 test_snow3g_authenticated_encryption_test_case_1),
4318 TEST_CASE_ST(ut_setup, ut_teardown,
4319 test_snow3g_encrypted_authentication_test_case_1),
4321 TEST_CASES_END() /**< NULL terminate unit test array */
4325 static struct unit_test_suite cryptodev_null_testsuite = {
4326 .suite_name = "Crypto Device NULL Unit Test Suite",
4327 .setup = testsuite_setup,
4328 .teardown = testsuite_teardown,
4329 .unit_test_cases = {
4330 TEST_CASE_ST(ut_setup, ut_teardown,
4331 test_null_auth_only_operation),
4332 TEST_CASE_ST(ut_setup, ut_teardown,
4333 test_null_cipher_only_operation),
4334 TEST_CASE_ST(ut_setup, ut_teardown,
4335 test_null_cipher_auth_operation),
4336 TEST_CASE_ST(ut_setup, ut_teardown,
4337 test_null_auth_cipher_operation),
4338 TEST_CASE_ST(ut_setup, ut_teardown,
4339 test_null_invalid_operation),
4340 TEST_CASE_ST(ut_setup, ut_teardown,
4341 test_null_burst_operation),
4343 TEST_CASES_END() /**< NULL terminate unit test array */
4348 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4350 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4351 return unit_test_suite_runner(&cryptodev_qat_testsuite);
4355 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4357 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4359 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4363 test_cryptodev_aesni_gcm(void)
4365 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4367 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4371 test_cryptodev_null(void)
4373 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4375 return unit_test_suite_runner(&cryptodev_null_testsuite);
4379 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4381 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4383 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4387 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
4389 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
4391 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
4394 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
4395 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
4396 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
4397 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
4398 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
4399 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);