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_zuc_test_vectors.h"
52 #include "test_cryptodev_zuc_hash_test_vectors.h"
53 #include "test_cryptodev_gcm_test_vectors.h"
54 #include "test_cryptodev_hmac_test_vectors.h"
56 static enum rte_cryptodev_type gbl_cryptodev_type;
58 struct crypto_testsuite_params {
59 struct rte_mempool *mbuf_pool;
60 struct rte_mempool *op_mpool;
61 struct rte_cryptodev_config conf;
62 struct rte_cryptodev_qp_conf qp_conf;
64 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
65 uint8_t valid_dev_count;
68 struct crypto_unittest_params {
69 struct rte_crypto_sym_xform cipher_xform;
70 struct rte_crypto_sym_xform auth_xform;
72 struct rte_cryptodev_sym_session *sess;
74 struct rte_crypto_op *op;
76 struct rte_mbuf *obuf, *ibuf;
81 #define ALIGN_POW2_ROUNDUP(num, align) \
82 (((num) + (align) - 1) & ~((align) - 1))
85 * Forward declarations.
88 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
89 struct crypto_unittest_params *ut_params);
92 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
93 struct crypto_unittest_params *ut_params,
94 struct crypto_testsuite_params *ts_param);
96 static struct rte_mbuf *
97 setup_test_string(struct rte_mempool *mpool,
98 const char *string, size_t len, uint8_t blocksize)
100 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
101 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
103 memset(m->buf_addr, 0, m->buf_len);
105 char *dst = rte_pktmbuf_append(m, t_len);
112 rte_memcpy(dst, string, t_len);
114 memset(dst, 0, t_len);
120 /* Get number of bytes in X bits (rounding up) */
122 ceil_byte_length(uint32_t num_bits)
125 return ((num_bits >> 3) + 1);
127 return (num_bits >> 3);
130 static struct rte_crypto_op *
131 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
133 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
134 printf("Error sending packet for encryption");
140 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
146 static struct crypto_testsuite_params testsuite_params = { NULL };
147 static struct crypto_unittest_params unittest_params;
150 testsuite_setup(void)
152 struct crypto_testsuite_params *ts_params = &testsuite_params;
153 struct rte_cryptodev_info info;
154 unsigned i, nb_devs, dev_id;
158 memset(ts_params, 0, sizeof(*ts_params));
160 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
161 if (ts_params->mbuf_pool == NULL) {
162 /* Not already created so create */
163 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
165 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
167 if (ts_params->mbuf_pool == NULL) {
168 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
173 ts_params->op_mpool = rte_crypto_op_pool_create(
174 "MBUF_CRYPTO_SYM_OP_POOL",
175 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
176 NUM_MBUFS, MBUF_CACHE_SIZE,
178 sizeof(struct rte_crypto_sym_xform),
180 if (ts_params->op_mpool == NULL) {
181 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
185 /* Create 2 AESNI MB devices if required */
186 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
187 #ifndef RTE_LIBRTE_PMD_AESNI_MB
188 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
189 " enabled in config file to run this testsuite.\n");
192 nb_devs = rte_cryptodev_count_devtype(
193 RTE_CRYPTODEV_AESNI_MB_PMD);
195 for (i = nb_devs; i < 2; i++) {
196 ret = rte_eal_vdev_init(
197 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
199 TEST_ASSERT(ret == 0,
200 "Failed to create instance %u of"
202 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
207 /* Create 2 AESNI GCM devices if required */
208 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
209 #ifndef RTE_LIBRTE_PMD_AESNI_GCM
210 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be"
211 " enabled in config file to run this testsuite.\n");
214 nb_devs = rte_cryptodev_count_devtype(
215 RTE_CRYPTODEV_AESNI_GCM_PMD);
217 for (i = nb_devs; i < 2; i++) {
218 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
219 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
220 "Failed to create instance %u of"
222 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
227 /* Create 2 SNOW 3G devices if required */
228 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
229 #ifndef RTE_LIBRTE_PMD_SNOW3G
230 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be"
231 " enabled in config file to run this testsuite.\n");
234 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
236 for (i = nb_devs; i < 2; i++) {
237 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
238 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
239 "Failed to create instance %u of"
241 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
246 /* Create 2 KASUMI devices if required */
247 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
248 #ifndef RTE_LIBRTE_PMD_KASUMI
249 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be"
250 " enabled in config file to run this testsuite.\n");
253 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
255 for (i = nb_devs; i < 2; i++) {
256 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
257 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
258 "Failed to create instance %u of"
260 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
265 /* Create 2 ZUC devices if required */
266 if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) {
267 #ifndef RTE_LIBRTE_PMD_ZUC
268 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be"
269 " enabled in config file to run this testsuite.\n");
272 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD);
274 for (i = nb_devs; i < 2; i++) {
275 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
276 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
277 "Failed to create instance %u of"
279 i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
284 /* Create 2 NULL devices if required */
285 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
286 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO
287 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be"
288 " enabled in config file to run this testsuite.\n");
291 nb_devs = rte_cryptodev_count_devtype(
292 RTE_CRYPTODEV_NULL_PMD);
294 for (i = nb_devs; i < 2; i++) {
295 int dev_id = rte_eal_vdev_init(
296 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
298 TEST_ASSERT(dev_id >= 0,
299 "Failed to create instance %u of"
301 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD));
306 #ifndef RTE_LIBRTE_PMD_QAT
307 if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) {
308 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled "
309 "in config file to run this testsuite.\n");
314 nb_devs = rte_cryptodev_count();
316 RTE_LOG(ERR, USER1, "No crypto devices found?");
320 /* Create list of valid crypto devs */
321 for (i = 0; i < nb_devs; i++) {
322 rte_cryptodev_info_get(i, &info);
323 if (info.dev_type == gbl_cryptodev_type)
324 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
327 if (ts_params->valid_dev_count < 1)
330 /* Set up all the qps on the first of the valid devices found */
331 for (i = 0; i < 1; i++) {
332 dev_id = ts_params->valid_devs[i];
334 rte_cryptodev_info_get(dev_id, &info);
337 * Since we can't free and re-allocate queue memory always set
338 * the queues on this device up to max size first so enough
339 * memory is allocated for any later re-configures needed by
343 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
344 ts_params->conf.socket_id = SOCKET_ID_ANY;
345 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
347 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
349 "Failed to configure cryptodev %u with %u qps",
350 dev_id, ts_params->conf.nb_queue_pairs);
352 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
354 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
355 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
356 dev_id, qp_id, &ts_params->qp_conf,
357 rte_cryptodev_socket_id(dev_id)),
358 "Failed to setup queue pair %u on "
368 testsuite_teardown(void)
370 struct crypto_testsuite_params *ts_params = &testsuite_params;
372 if (ts_params->mbuf_pool != NULL) {
373 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
374 rte_mempool_avail_count(ts_params->mbuf_pool));
377 if (ts_params->op_mpool != NULL) {
378 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
379 rte_mempool_avail_count(ts_params->op_mpool));
387 struct crypto_testsuite_params *ts_params = &testsuite_params;
388 struct crypto_unittest_params *ut_params = &unittest_params;
392 /* Clear unit test parameters before running test */
393 memset(ut_params, 0, sizeof(*ut_params));
395 /* Reconfigure device to default parameters */
396 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
397 ts_params->conf.socket_id = SOCKET_ID_ANY;
398 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT;
400 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
402 "Failed to configure cryptodev %u",
403 ts_params->valid_devs[0]);
406 * Now reconfigure queues to size we actually want to use in this
409 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
411 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
412 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
413 ts_params->valid_devs[0], qp_id,
415 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
416 "Failed to setup queue pair %u on cryptodev %u",
417 qp_id, ts_params->valid_devs[0]);
421 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
423 /* Start the device */
424 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
425 "Failed to start cryptodev %u",
426 ts_params->valid_devs[0]);
434 struct crypto_testsuite_params *ts_params = &testsuite_params;
435 struct crypto_unittest_params *ut_params = &unittest_params;
436 struct rte_cryptodev_stats stats;
438 /* free crypto session structure */
439 if (ut_params->sess) {
440 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
442 ut_params->sess = NULL;
445 /* free crypto operation structure */
447 rte_crypto_op_free(ut_params->op);
450 * free mbuf - both obuf and ibuf are usually the same,
451 * so check if they point at the same address is necessary,
452 * to avoid freeing the mbuf twice.
454 if (ut_params->obuf) {
455 rte_pktmbuf_free(ut_params->obuf);
456 if (ut_params->ibuf == ut_params->obuf)
460 if (ut_params->ibuf) {
461 rte_pktmbuf_free(ut_params->ibuf);
465 if (ts_params->mbuf_pool != NULL)
466 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
467 rte_mempool_avail_count(ts_params->mbuf_pool));
469 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
471 /* Stop the device */
472 rte_cryptodev_stop(ts_params->valid_devs[0]);
476 test_device_configure_invalid_dev_id(void)
478 struct crypto_testsuite_params *ts_params = &testsuite_params;
479 uint16_t dev_id, num_devs = 0;
481 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
482 "Need at least %d devices for test", 1);
484 /* valid dev_id values */
485 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
487 /* Stop the device in case it's started so it can be configured */
488 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
490 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
491 "Failed test for rte_cryptodev_configure: "
492 "invalid dev_num %u", dev_id);
494 /* invalid dev_id values */
497 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
498 "Failed test for rte_cryptodev_configure: "
499 "invalid dev_num %u", dev_id);
503 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
504 "Failed test for rte_cryptodev_configure:"
505 "invalid dev_num %u", dev_id);
511 test_device_configure_invalid_queue_pair_ids(void)
513 struct crypto_testsuite_params *ts_params = &testsuite_params;
515 /* Stop the device in case it's started so it can be configured */
516 rte_cryptodev_stop(ts_params->valid_devs[0]);
518 /* valid - one queue pairs */
519 ts_params->conf.nb_queue_pairs = 1;
521 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
523 "Failed to configure cryptodev: dev_id %u, qp_id %u",
524 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
527 /* valid - max value queue pairs */
528 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
530 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
532 "Failed to configure cryptodev: dev_id %u, qp_id %u",
533 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
536 /* invalid - zero queue pairs */
537 ts_params->conf.nb_queue_pairs = 0;
539 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
541 "Failed test for rte_cryptodev_configure, dev_id %u,"
543 ts_params->valid_devs[0],
544 ts_params->conf.nb_queue_pairs);
547 /* invalid - max value supported by field queue pairs */
548 ts_params->conf.nb_queue_pairs = UINT16_MAX;
550 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
552 "Failed test for rte_cryptodev_configure, dev_id %u,"
554 ts_params->valid_devs[0],
555 ts_params->conf.nb_queue_pairs);
558 /* invalid - max value + 1 queue pairs */
559 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
561 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
563 "Failed test for rte_cryptodev_configure, dev_id %u,"
565 ts_params->valid_devs[0],
566 ts_params->conf.nb_queue_pairs);
572 test_queue_pair_descriptor_setup(void)
574 struct crypto_testsuite_params *ts_params = &testsuite_params;
575 struct rte_cryptodev_info dev_info;
576 struct rte_cryptodev_qp_conf qp_conf = {
577 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
582 /* Stop the device in case it's started so it can be configured */
583 rte_cryptodev_stop(ts_params->valid_devs[0]);
586 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
588 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
590 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
591 &ts_params->conf), "Failed to configure cryptodev %u",
592 ts_params->valid_devs[0]);
596 * Test various ring sizes on this device. memzones can't be
597 * freed so are re-used if ring is released and re-created.
599 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
601 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
602 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
603 ts_params->valid_devs[0], qp_id, &qp_conf,
604 rte_cryptodev_socket_id(
605 ts_params->valid_devs[0])),
607 "rte_cryptodev_queue_pair_setup: num_inflights "
608 "%u on qp %u on cryptodev %u",
609 qp_conf.nb_descriptors, qp_id,
610 ts_params->valid_devs[0]);
613 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
615 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
616 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
617 ts_params->valid_devs[0], qp_id, &qp_conf,
618 rte_cryptodev_socket_id(
619 ts_params->valid_devs[0])),
621 " rte_cryptodev_queue_pair_setup: num_inflights"
622 " %u on qp %u on cryptodev %u",
623 qp_conf.nb_descriptors, qp_id,
624 ts_params->valid_devs[0]);
627 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
629 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
630 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
631 ts_params->valid_devs[0], qp_id, &qp_conf,
632 rte_cryptodev_socket_id(
633 ts_params->valid_devs[0])),
635 "rte_cryptodev_queue_pair_setup: num_inflights"
636 " %u on qp %u on cryptodev %u",
637 qp_conf.nb_descriptors, qp_id,
638 ts_params->valid_devs[0]);
641 /* invalid number of descriptors - max supported + 2 */
642 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
644 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
645 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
646 ts_params->valid_devs[0], qp_id, &qp_conf,
647 rte_cryptodev_socket_id(
648 ts_params->valid_devs[0])),
649 "Unexpectedly passed test for "
650 "rte_cryptodev_queue_pair_setup:"
651 "num_inflights %u on qp %u on cryptodev %u",
652 qp_conf.nb_descriptors, qp_id,
653 ts_params->valid_devs[0]);
656 /* invalid number of descriptors - max value of parameter */
657 qp_conf.nb_descriptors = UINT32_MAX-1;
659 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
660 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
661 ts_params->valid_devs[0], qp_id, &qp_conf,
662 rte_cryptodev_socket_id(
663 ts_params->valid_devs[0])),
664 "Unexpectedly passed test for "
665 "rte_cryptodev_queue_pair_setup:"
666 "num_inflights %u on qp %u on cryptodev %u",
667 qp_conf.nb_descriptors, qp_id,
668 ts_params->valid_devs[0]);
671 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
673 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
674 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
675 ts_params->valid_devs[0], qp_id, &qp_conf,
676 rte_cryptodev_socket_id(
677 ts_params->valid_devs[0])),
679 " rte_cryptodev_queue_pair_setup:"
680 "num_inflights %u on qp %u on cryptodev %u",
681 qp_conf.nb_descriptors, qp_id,
682 ts_params->valid_devs[0]);
685 /* invalid number of descriptors - max supported + 1 */
686 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
688 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
689 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
690 ts_params->valid_devs[0], qp_id, &qp_conf,
691 rte_cryptodev_socket_id(
692 ts_params->valid_devs[0])),
693 "Unexpectedly passed test for "
694 "rte_cryptodev_queue_pair_setup:"
695 "num_inflights %u on qp %u on cryptodev %u",
696 qp_conf.nb_descriptors, qp_id,
697 ts_params->valid_devs[0]);
700 /* test invalid queue pair id */
701 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
703 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
705 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
706 ts_params->valid_devs[0],
708 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
709 "Failed test for rte_cryptodev_queue_pair_setup:"
710 "invalid qp %u on cryptodev %u",
711 qp_id, ts_params->valid_devs[0]);
713 qp_id = 0xffff; /*invalid*/
715 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
716 ts_params->valid_devs[0],
718 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
719 "Failed test for rte_cryptodev_queue_pair_setup:"
720 "invalid qp %u on cryptodev %u",
721 qp_id, ts_params->valid_devs[0]);
726 /* ***** Plaintext data for tests ***** */
728 const char catch_22_quote_1[] =
729 "There was only one catch and that was Catch-22, which "
730 "specified that a concern for one's safety in the face of "
731 "dangers that were real and immediate was the process of a "
732 "rational mind. Orr was crazy and could be grounded. All he "
733 "had to do was ask; and as soon as he did, he would no longer "
734 "be crazy and would have to fly more missions. Orr would be "
735 "crazy to fly more missions and sane if he didn't, but if he "
736 "was sane he had to fly them. If he flew them he was crazy "
737 "and didn't have to; but if he didn't want to he was sane and "
738 "had to. Yossarian was moved very deeply by the absolute "
739 "simplicity of this clause of Catch-22 and let out a "
740 "respectful whistle. \"That's some catch, that Catch-22\", he "
741 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
743 const char catch_22_quote[] =
744 "What a lousy earth! He wondered how many people were "
745 "destitute that same night even in his own prosperous country, "
746 "how many homes were shanties, how many husbands were drunk "
747 "and wives socked, and how many children were bullied, abused, "
748 "or abandoned. How many families hungered for food they could "
749 "not afford to buy? How many hearts were broken? How many "
750 "suicides would take place that same night, how many people "
751 "would go insane? How many cockroaches and landlords would "
752 "triumph? How many winners were losers, successes failures, "
753 "and rich men poor men? How many wise guys were stupid? How "
754 "many happy endings were unhappy endings? How many honest men "
755 "were liars, brave men cowards, loyal men traitors, how many "
756 "sainted men were corrupt, how many people in positions of "
757 "trust had sold their souls to bodyguards, how many had never "
758 "had souls? How many straight-and-narrow paths were crooked "
759 "paths? How many best families were worst families and how "
760 "many good people were bad people? When you added them all up "
761 "and then subtracted, you might be left with only the children, "
762 "and perhaps with Albert Einstein and an old violinist or "
763 "sculptor somewhere.";
765 #define QUOTE_480_BYTES (480)
766 #define QUOTE_512_BYTES (512)
767 #define QUOTE_768_BYTES (768)
768 #define QUOTE_1024_BYTES (1024)
772 /* ***** SHA1 Hash Tests ***** */
774 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
776 static uint8_t hmac_sha1_key[] = {
777 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
778 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
779 0xDE, 0xF4, 0xDE, 0xAD };
781 /* ***** SHA224 Hash Tests ***** */
783 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
786 /* ***** AES-CBC Cipher Tests ***** */
788 #define CIPHER_KEY_LENGTH_AES_CBC (16)
789 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
791 static uint8_t aes_cbc_key[] = {
792 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
793 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
795 static uint8_t aes_cbc_iv[] = {
796 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
797 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
800 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
802 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
803 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
804 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
805 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
806 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
807 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
808 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
809 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
810 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
811 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
812 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
813 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
814 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
815 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
816 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
817 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
818 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
819 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
820 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
821 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
822 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
823 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
824 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
825 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
826 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
827 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
828 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
829 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
830 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
831 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
832 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
833 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
834 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
835 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
836 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
837 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
838 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
839 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
840 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
841 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
842 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
843 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
844 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
845 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
846 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
847 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
848 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
849 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
850 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
851 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
852 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
853 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
854 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
855 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
856 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
857 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
858 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
859 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
860 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
861 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
862 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
863 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
864 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
865 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
866 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
869 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
870 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
871 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
872 0x18, 0x8c, 0x1d, 0x32
877 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
879 struct crypto_testsuite_params *ts_params = &testsuite_params;
880 struct crypto_unittest_params *ut_params = &unittest_params;
882 /* Generate test mbuf data and space for digest */
883 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
884 catch_22_quote, QUOTE_512_BYTES, 0);
886 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
887 DIGEST_BYTE_LENGTH_SHA1);
888 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
890 /* Setup Cipher Parameters */
891 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
892 ut_params->cipher_xform.next = &ut_params->auth_xform;
894 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
895 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
896 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
897 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
899 /* Setup HMAC Parameters */
900 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
902 ut_params->auth_xform.next = NULL;
904 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
905 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
906 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
907 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
908 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
910 /* Create crypto session*/
911 ut_params->sess = rte_cryptodev_sym_session_create(
912 ts_params->valid_devs[0],
913 &ut_params->cipher_xform);
914 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
916 /* Generate crypto op data structure */
917 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
918 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
919 TEST_ASSERT_NOT_NULL(ut_params->op,
920 "Failed to allocate symmetric crypto operation struct");
922 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
924 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
926 /* set crypto operation source mbuf */
927 sym_op->m_src = ut_params->ibuf;
929 /* Set crypto operation authentication parameters */
930 sym_op->auth.digest.data = ut_params->digest;
931 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
932 ut_params->ibuf, QUOTE_512_BYTES);
933 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
935 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
936 sym_op->auth.data.length = QUOTE_512_BYTES;
938 /* Set crypto operation cipher parameters */
939 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
940 CIPHER_IV_LENGTH_AES_CBC);
941 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
942 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
944 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
945 CIPHER_IV_LENGTH_AES_CBC);
947 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
948 sym_op->cipher.data.length = QUOTE_512_BYTES;
950 /* Process crypto operation */
951 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
952 ut_params->op), "failed to process sym crypto op");
954 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
955 "crypto op processing failed");
958 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
959 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
961 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
962 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
964 "ciphertext data not as expected");
966 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
968 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
969 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
970 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
971 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
972 DIGEST_BYTE_LENGTH_SHA1,
973 "Generated digest data not as expected");
978 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
980 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
982 static uint8_t hmac_sha512_key[] = {
983 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
984 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
985 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
986 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
987 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
988 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
989 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
990 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
992 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
993 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
994 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
995 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
996 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
997 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
998 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
999 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1000 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1005 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1006 struct crypto_unittest_params *ut_params);
1009 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1010 struct crypto_unittest_params *ut_params,
1011 struct crypto_testsuite_params *ts_params);
1015 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1016 struct crypto_unittest_params *ut_params)
1019 /* Setup Cipher Parameters */
1020 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1021 ut_params->cipher_xform.next = NULL;
1023 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1024 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1025 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1026 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1028 /* Setup HMAC Parameters */
1029 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1030 ut_params->auth_xform.next = &ut_params->cipher_xform;
1032 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1033 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1034 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1035 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1036 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1038 return TEST_SUCCESS;
1043 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1044 struct crypto_unittest_params *ut_params,
1045 struct crypto_testsuite_params *ts_params)
1047 /* Generate test mbuf data and digest */
1048 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1050 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1051 QUOTE_512_BYTES, 0);
1053 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1054 DIGEST_BYTE_LENGTH_SHA512);
1055 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1057 rte_memcpy(ut_params->digest,
1058 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1059 DIGEST_BYTE_LENGTH_SHA512);
1061 /* Generate Crypto op data structure */
1062 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1063 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1064 TEST_ASSERT_NOT_NULL(ut_params->op,
1065 "Failed to allocate symmetric crypto operation struct");
1067 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1069 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1071 /* set crypto operation source mbuf */
1072 sym_op->m_src = ut_params->ibuf;
1074 sym_op->auth.digest.data = ut_params->digest;
1075 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1076 ut_params->ibuf, QUOTE_512_BYTES);
1077 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1079 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1080 sym_op->auth.data.length = QUOTE_512_BYTES;
1082 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1083 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1084 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1085 ut_params->ibuf, 0);
1086 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1088 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1089 CIPHER_IV_LENGTH_AES_CBC);
1091 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1092 sym_op->cipher.data.length = QUOTE_512_BYTES;
1094 /* Process crypto operation */
1095 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1096 ut_params->op), "failed to process sym crypto op");
1098 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1099 "crypto op processing failed");
1101 ut_params->obuf = ut_params->op->sym->m_src;
1104 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1105 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1106 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1108 "Plaintext data not as expected");
1111 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1112 "Digest verification failed");
1114 return TEST_SUCCESS;
1118 test_AES_mb_all(void)
1120 struct crypto_testsuite_params *ts_params = &testsuite_params;
1123 status = test_AES_all_tests(ts_params->mbuf_pool,
1124 ts_params->op_mpool, ts_params->valid_devs[0],
1125 RTE_CRYPTODEV_AESNI_MB_PMD);
1127 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1129 return TEST_SUCCESS;
1133 test_AES_qat_all(void)
1135 struct crypto_testsuite_params *ts_params = &testsuite_params;
1138 status = test_AES_all_tests(ts_params->mbuf_pool,
1139 ts_params->op_mpool, ts_params->valid_devs[0],
1140 RTE_CRYPTODEV_QAT_SYM_PMD);
1142 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1144 return TEST_SUCCESS;
1147 /* ***** SNOW 3G Tests ***** */
1149 create_wireless_algo_hash_session(uint8_t dev_id,
1150 const uint8_t *key, const uint8_t key_len,
1151 const uint8_t aad_len, const uint8_t auth_len,
1152 enum rte_crypto_auth_operation op,
1153 enum rte_crypto_auth_algorithm algo)
1155 uint8_t hash_key[key_len];
1157 struct crypto_unittest_params *ut_params = &unittest_params;
1159 memcpy(hash_key, key, key_len);
1161 TEST_HEXDUMP(stdout, "key:", key, key_len);
1163 /* Setup Authentication Parameters */
1164 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1165 ut_params->auth_xform.next = NULL;
1167 ut_params->auth_xform.auth.op = op;
1168 ut_params->auth_xform.auth.algo = algo;
1169 ut_params->auth_xform.auth.key.length = key_len;
1170 ut_params->auth_xform.auth.key.data = hash_key;
1171 ut_params->auth_xform.auth.digest_length = auth_len;
1172 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1173 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1174 &ut_params->auth_xform);
1175 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1180 create_wireless_algo_cipher_session(uint8_t dev_id,
1181 enum rte_crypto_cipher_operation op,
1182 enum rte_crypto_cipher_algorithm algo,
1183 const uint8_t *key, const uint8_t key_len)
1185 uint8_t cipher_key[key_len];
1187 struct crypto_unittest_params *ut_params = &unittest_params;
1189 memcpy(cipher_key, key, key_len);
1191 /* Setup Cipher Parameters */
1192 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1193 ut_params->cipher_xform.next = NULL;
1195 ut_params->cipher_xform.cipher.algo = algo;
1196 ut_params->cipher_xform.cipher.op = op;
1197 ut_params->cipher_xform.cipher.key.data = cipher_key;
1198 ut_params->cipher_xform.cipher.key.length = key_len;
1200 TEST_HEXDUMP(stdout, "key:", key, key_len);
1202 /* Create Crypto session */
1203 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1206 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1211 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1212 const unsigned cipher_len,
1213 const unsigned cipher_offset,
1214 enum rte_crypto_cipher_algorithm algo)
1216 struct crypto_testsuite_params *ts_params = &testsuite_params;
1217 struct crypto_unittest_params *ut_params = &unittest_params;
1218 unsigned iv_pad_len = 0;
1220 /* Generate Crypto op data structure */
1221 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1222 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1223 TEST_ASSERT_NOT_NULL(ut_params->op,
1224 "Failed to allocate pktmbuf offload");
1226 /* Set crypto operation data parameters */
1227 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1229 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1231 /* set crypto operation source mbuf */
1232 sym_op->m_src = ut_params->ibuf;
1235 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1236 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1238 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1240 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1243 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1245 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1246 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1247 sym_op->cipher.iv.length = iv_pad_len;
1249 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1250 sym_op->cipher.data.length = cipher_len;
1251 sym_op->cipher.data.offset = cipher_offset;
1256 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1257 const unsigned cipher_len,
1258 const unsigned cipher_offset,
1259 enum rte_crypto_cipher_algorithm algo)
1261 struct crypto_testsuite_params *ts_params = &testsuite_params;
1262 struct crypto_unittest_params *ut_params = &unittest_params;
1263 unsigned iv_pad_len = 0;
1265 /* Generate Crypto op data structure */
1266 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1267 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1268 TEST_ASSERT_NOT_NULL(ut_params->op,
1269 "Failed to allocate pktmbuf offload");
1271 /* Set crypto operation data parameters */
1272 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1274 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1276 /* set crypto operation source mbuf */
1277 sym_op->m_src = ut_params->ibuf;
1278 sym_op->m_dst = ut_params->obuf;
1281 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1282 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1284 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1285 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1288 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1290 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1291 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1292 sym_op->cipher.iv.length = iv_pad_len;
1294 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1295 sym_op->cipher.data.length = cipher_len;
1296 sym_op->cipher.data.offset = cipher_offset;
1301 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1302 enum rte_crypto_cipher_operation cipher_op,
1303 enum rte_crypto_auth_operation auth_op,
1304 enum rte_crypto_auth_algorithm auth_algo,
1305 enum rte_crypto_cipher_algorithm cipher_algo,
1306 const uint8_t *key, const uint8_t key_len,
1307 const uint8_t aad_len, const uint8_t auth_len)
1310 uint8_t cipher_auth_key[key_len];
1312 struct crypto_unittest_params *ut_params = &unittest_params;
1314 memcpy(cipher_auth_key, key, key_len);
1316 /* Setup Authentication Parameters */
1317 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1318 ut_params->auth_xform.next = NULL;
1320 ut_params->auth_xform.auth.op = auth_op;
1321 ut_params->auth_xform.auth.algo = auth_algo;
1322 ut_params->auth_xform.auth.key.length = key_len;
1323 /* Hash key = cipher key */
1324 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1325 ut_params->auth_xform.auth.digest_length = auth_len;
1326 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1328 /* Setup Cipher Parameters */
1329 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1330 ut_params->cipher_xform.next = &ut_params->auth_xform;
1332 ut_params->cipher_xform.cipher.algo = cipher_algo;
1333 ut_params->cipher_xform.cipher.op = cipher_op;
1334 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1335 ut_params->cipher_xform.cipher.key.length = key_len;
1337 TEST_HEXDUMP(stdout, "key:", key, key_len);
1339 /* Create Crypto session*/
1340 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1341 &ut_params->cipher_xform);
1343 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1348 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
1349 enum rte_crypto_cipher_operation cipher_op,
1350 enum rte_crypto_auth_operation auth_op,
1351 enum rte_crypto_auth_algorithm auth_algo,
1352 enum rte_crypto_cipher_algorithm cipher_algo,
1353 const uint8_t *key, const uint8_t key_len,
1354 const uint8_t aad_len, const uint8_t auth_len)
1356 uint8_t auth_cipher_key[key_len];
1358 struct crypto_unittest_params *ut_params = &unittest_params;
1360 memcpy(auth_cipher_key, key, key_len);
1362 /* Setup Authentication Parameters */
1363 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1364 ut_params->auth_xform.auth.op = auth_op;
1365 ut_params->auth_xform.next = &ut_params->cipher_xform;
1366 ut_params->auth_xform.auth.algo = auth_algo;
1367 ut_params->auth_xform.auth.key.length = key_len;
1368 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1369 ut_params->auth_xform.auth.digest_length = auth_len;
1370 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1372 /* Setup Cipher Parameters */
1373 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1374 ut_params->cipher_xform.next = NULL;
1375 ut_params->cipher_xform.cipher.algo = cipher_algo;
1376 ut_params->cipher_xform.cipher.op = cipher_op;
1377 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1378 ut_params->cipher_xform.cipher.key.length = key_len;
1380 TEST_HEXDUMP(stdout, "key:", key, key_len);
1382 /* Create Crypto session*/
1383 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1384 &ut_params->auth_xform);
1386 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1392 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
1393 const unsigned auth_tag_len,
1394 const uint8_t *aad, const unsigned aad_len,
1395 unsigned data_pad_len,
1396 enum rte_crypto_auth_operation op,
1397 enum rte_crypto_auth_algorithm algo,
1398 const unsigned auth_len, const unsigned auth_offset)
1400 struct crypto_testsuite_params *ts_params = &testsuite_params;
1402 struct crypto_unittest_params *ut_params = &unittest_params;
1404 unsigned aad_buffer_len;
1406 /* Generate Crypto op data structure */
1407 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1408 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1409 TEST_ASSERT_NOT_NULL(ut_params->op,
1410 "Failed to allocate pktmbuf offload");
1412 /* Set crypto operation data parameters */
1413 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1415 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1417 /* set crypto operation source mbuf */
1418 sym_op->m_src = ut_params->ibuf;
1422 * Always allocate the aad up to the block size.
1423 * The cryptodev API calls out -
1424 * - the array must be big enough to hold the AAD, plus any
1425 * space to round this up to the nearest multiple of the
1426 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1428 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1429 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1431 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1432 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1433 ut_params->ibuf, aad_buffer_len);
1434 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1435 "no room to prepend aad");
1436 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1438 sym_op->auth.aad.length = aad_len;
1440 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1441 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1443 TEST_HEXDUMP(stdout, "aad:",
1444 sym_op->auth.aad.data, aad_len);
1447 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1448 ut_params->ibuf, auth_tag_len);
1450 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1451 "no room to append auth tag");
1452 ut_params->digest = sym_op->auth.digest.data;
1453 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1454 ut_params->ibuf, data_pad_len + aad_len);
1455 sym_op->auth.digest.length = auth_tag_len;
1456 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1457 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1459 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1461 TEST_HEXDUMP(stdout, "digest:",
1462 sym_op->auth.digest.data,
1463 sym_op->auth.digest.length);
1465 sym_op->auth.data.length = auth_len;
1466 sym_op->auth.data.offset = auth_offset;
1472 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
1473 const unsigned auth_tag_len,
1474 const uint8_t *aad, const uint8_t aad_len,
1475 unsigned data_pad_len,
1476 enum rte_crypto_auth_operation op,
1477 enum rte_crypto_auth_algorithm auth_algo,
1478 enum rte_crypto_cipher_algorithm cipher_algo,
1479 const uint8_t *iv, const uint8_t iv_len,
1480 const unsigned cipher_len, const unsigned cipher_offset,
1481 const unsigned auth_len, const unsigned auth_offset)
1483 struct crypto_testsuite_params *ts_params = &testsuite_params;
1484 struct crypto_unittest_params *ut_params = &unittest_params;
1486 unsigned iv_pad_len = 0;
1487 unsigned aad_buffer_len;
1489 /* Generate Crypto op data structure */
1490 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1491 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1492 TEST_ASSERT_NOT_NULL(ut_params->op,
1493 "Failed to allocate pktmbuf offload");
1494 /* Set crypto operation data parameters */
1495 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1497 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1499 /* set crypto operation source mbuf */
1500 sym_op->m_src = ut_params->ibuf;
1503 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1504 ut_params->ibuf, auth_tag_len);
1506 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1507 "no room to append auth tag");
1508 ut_params->digest = sym_op->auth.digest.data;
1509 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1510 ut_params->ibuf, data_pad_len);
1511 sym_op->auth.digest.length = auth_tag_len;
1512 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1513 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1515 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1517 TEST_HEXDUMP(stdout, "digest:",
1518 sym_op->auth.digest.data,
1519 sym_op->auth.digest.length);
1523 * Always allocate the aad up to the block size.
1524 * The cryptodev API calls out -
1525 * - the array must be big enough to hold the AAD, plus any
1526 * space to round this up to the nearest multiple of the
1527 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1529 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1530 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1532 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1533 sym_op->auth.aad.data =
1534 (uint8_t *)rte_pktmbuf_prepend(
1535 ut_params->ibuf, aad_buffer_len);
1536 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1537 "no room to prepend aad");
1538 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1540 sym_op->auth.aad.length = aad_len;
1541 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1542 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1543 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1546 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1547 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1549 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1550 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1551 ut_params->ibuf, iv_pad_len);
1553 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1554 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1555 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1556 sym_op->cipher.iv.length = iv_pad_len;
1557 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1558 sym_op->cipher.data.length = cipher_len;
1559 sym_op->cipher.data.offset = cipher_offset + auth_offset;
1560 sym_op->auth.data.length = auth_len;
1561 sym_op->auth.data.offset = auth_offset + cipher_offset;
1567 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
1568 const uint8_t *iv, const uint8_t iv_len,
1569 const uint8_t *aad, const uint8_t aad_len,
1570 unsigned data_pad_len,
1571 const unsigned cipher_len, const unsigned cipher_offset,
1572 const unsigned auth_len, const unsigned auth_offset,
1573 enum rte_crypto_auth_algorithm auth_algo,
1574 enum rte_crypto_cipher_algorithm cipher_algo)
1576 struct crypto_testsuite_params *ts_params = &testsuite_params;
1577 struct crypto_unittest_params *ut_params = &unittest_params;
1579 unsigned iv_pad_len = 0;
1580 unsigned aad_buffer_len = 0;
1582 /* Generate Crypto op data structure */
1583 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1584 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1585 TEST_ASSERT_NOT_NULL(ut_params->op,
1586 "Failed to allocate pktmbuf offload");
1588 /* Set crypto operation data parameters */
1589 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1591 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1593 /* set crypto operation source mbuf */
1594 sym_op->m_src = ut_params->ibuf;
1597 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1598 ut_params->ibuf, auth_tag_len);
1600 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1601 "no room to append auth tag");
1603 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1604 ut_params->ibuf, data_pad_len);
1605 sym_op->auth.digest.length = auth_tag_len;
1607 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1609 TEST_HEXDUMP(stdout, "digest:",
1610 sym_op->auth.digest.data,
1611 sym_op->auth.digest.length);
1615 * Always allocate the aad up to the block size.
1616 * The cryptodev API calls out -
1617 * - the array must be big enough to hold the AAD, plus any
1618 * space to round this up to the nearest multiple of the
1619 * block size (8 bytes for KASUMI 16 bytes).
1621 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1622 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1624 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1625 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1626 ut_params->ibuf, aad_buffer_len);
1627 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1628 "no room to prepend aad");
1629 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1631 sym_op->auth.aad.length = aad_len;
1632 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1633 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1634 TEST_HEXDUMP(stdout, "aad:",
1635 sym_op->auth.aad.data, aad_len);
1638 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1639 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1641 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1643 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1644 ut_params->ibuf, iv_pad_len);
1645 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1647 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1648 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1649 sym_op->cipher.iv.length = iv_pad_len;
1651 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1653 sym_op->cipher.data.length = cipher_len;
1654 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1656 sym_op->auth.data.length = auth_len;
1657 sym_op->auth.data.offset = auth_offset + cipher_offset;
1663 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1665 struct crypto_testsuite_params *ts_params = &testsuite_params;
1666 struct crypto_unittest_params *ut_params = &unittest_params;
1669 unsigned plaintext_pad_len;
1670 unsigned plaintext_len;
1673 /* Create SNOW 3G session */
1674 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1675 tdata->key.data, tdata->key.len,
1676 tdata->aad.len, tdata->digest.len,
1677 RTE_CRYPTO_AUTH_OP_GENERATE,
1678 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1682 /* alloc mbuf and set payload */
1683 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1685 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1686 rte_pktmbuf_tailroom(ut_params->ibuf));
1688 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1689 /* Append data which is padded to a multiple of */
1690 /* the algorithms block size */
1691 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1692 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1694 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1696 /* Create SNOW 3G operation */
1697 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
1698 tdata->aad.data, tdata->aad.len,
1699 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1700 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1701 tdata->validAuthLenInBits.len,
1702 tdata->validAuthOffsetLenInBits.len);
1706 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1708 ut_params->obuf = ut_params->op->sym->m_src;
1709 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1710 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1711 + plaintext_pad_len + tdata->aad.len;
1714 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1717 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1718 "SNOW 3G Generated auth tag not as expected");
1724 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1726 struct crypto_testsuite_params *ts_params = &testsuite_params;
1727 struct crypto_unittest_params *ut_params = &unittest_params;
1730 unsigned plaintext_pad_len;
1731 unsigned plaintext_len;
1734 /* Create SNOW 3G session */
1735 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1736 tdata->key.data, tdata->key.len,
1737 tdata->aad.len, tdata->digest.len,
1738 RTE_CRYPTO_AUTH_OP_VERIFY,
1739 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1742 /* alloc mbuf and set payload */
1743 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1745 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1746 rte_pktmbuf_tailroom(ut_params->ibuf));
1748 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1749 /* Append data which is padded to a multiple of */
1750 /* the algorithms block size */
1751 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1752 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1754 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1756 /* Create SNOW 3G operation */
1757 retval = create_wireless_algo_hash_operation(tdata->digest.data,
1759 tdata->aad.data, tdata->aad.len,
1761 RTE_CRYPTO_AUTH_OP_VERIFY,
1762 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1763 tdata->validAuthLenInBits.len,
1764 tdata->validAuthOffsetLenInBits.len);
1768 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1770 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1771 ut_params->obuf = ut_params->op->sym->m_src;
1772 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1773 + plaintext_pad_len + tdata->aad.len;
1776 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1785 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1787 struct crypto_testsuite_params *ts_params = &testsuite_params;
1788 struct crypto_unittest_params *ut_params = &unittest_params;
1791 unsigned plaintext_pad_len;
1792 unsigned plaintext_len;
1795 /* Create KASUMI session */
1796 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1797 tdata->key.data, tdata->key.len,
1798 tdata->aad.len, tdata->digest.len,
1799 RTE_CRYPTO_AUTH_OP_GENERATE,
1800 RTE_CRYPTO_AUTH_KASUMI_F9);
1804 /* alloc mbuf and set payload */
1805 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1807 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1808 rte_pktmbuf_tailroom(ut_params->ibuf));
1810 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1811 /* Append data which is padded to a multiple of */
1812 /* the algorithms block size */
1813 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1814 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1816 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1818 /* Create KASUMI operation */
1819 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
1820 tdata->aad.data, tdata->aad.len,
1821 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1822 RTE_CRYPTO_AUTH_KASUMI_F9,
1823 tdata->validAuthLenInBits.len,
1824 tdata->validAuthOffsetLenInBits.len);
1828 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1830 ut_params->obuf = ut_params->op->sym->m_src;
1831 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1832 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1833 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1836 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1839 DIGEST_BYTE_LENGTH_KASUMI_F9,
1840 "KASUMI Generated auth tag not as expected");
1846 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1848 struct crypto_testsuite_params *ts_params = &testsuite_params;
1849 struct crypto_unittest_params *ut_params = &unittest_params;
1852 unsigned plaintext_pad_len;
1853 unsigned plaintext_len;
1856 /* Create KASUMI session */
1857 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1858 tdata->key.data, tdata->key.len,
1859 tdata->aad.len, tdata->digest.len,
1860 RTE_CRYPTO_AUTH_OP_VERIFY,
1861 RTE_CRYPTO_AUTH_KASUMI_F9);
1864 /* alloc mbuf and set payload */
1865 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1867 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1868 rte_pktmbuf_tailroom(ut_params->ibuf));
1870 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1871 /* Append data which is padded to a multiple */
1872 /* of the algorithms block size */
1873 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1874 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1876 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1878 /* Create KASUMI operation */
1879 retval = create_wireless_algo_hash_operation(tdata->digest.data,
1881 tdata->aad.data, tdata->aad.len,
1883 RTE_CRYPTO_AUTH_OP_VERIFY,
1884 RTE_CRYPTO_AUTH_KASUMI_F9,
1885 tdata->validAuthLenInBits.len,
1886 tdata->validAuthOffsetLenInBits.len);
1890 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1892 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1893 ut_params->obuf = ut_params->op->sym->m_src;
1894 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1895 + plaintext_pad_len + tdata->aad.len;
1898 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1907 test_snow3g_hash_generate_test_case_1(void)
1909 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1913 test_snow3g_hash_generate_test_case_2(void)
1915 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1919 test_snow3g_hash_generate_test_case_3(void)
1921 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1925 test_snow3g_hash_generate_test_case_4(void)
1927 return test_snow3g_authentication(&snow3g_hash_test_case_4);
1931 test_snow3g_hash_generate_test_case_5(void)
1933 return test_snow3g_authentication(&snow3g_hash_test_case_5);
1937 test_snow3g_hash_generate_test_case_6(void)
1939 return test_snow3g_authentication(&snow3g_hash_test_case_6);
1943 test_snow3g_hash_verify_test_case_1(void)
1945 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1950 test_snow3g_hash_verify_test_case_2(void)
1952 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1956 test_snow3g_hash_verify_test_case_3(void)
1958 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1962 test_snow3g_hash_verify_test_case_4(void)
1964 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
1968 test_snow3g_hash_verify_test_case_5(void)
1970 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
1974 test_snow3g_hash_verify_test_case_6(void)
1976 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
1980 test_kasumi_hash_generate_test_case_1(void)
1982 return test_kasumi_authentication(&kasumi_hash_test_case_1);
1986 test_kasumi_hash_generate_test_case_2(void)
1988 return test_kasumi_authentication(&kasumi_hash_test_case_2);
1992 test_kasumi_hash_generate_test_case_3(void)
1994 return test_kasumi_authentication(&kasumi_hash_test_case_3);
1998 test_kasumi_hash_generate_test_case_4(void)
2000 return test_kasumi_authentication(&kasumi_hash_test_case_4);
2004 test_kasumi_hash_generate_test_case_5(void)
2006 return test_kasumi_authentication(&kasumi_hash_test_case_5);
2010 test_kasumi_hash_generate_test_case_6(void)
2012 return test_kasumi_authentication(&kasumi_hash_test_case_6);
2016 test_kasumi_hash_verify_test_case_1(void)
2018 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2022 test_kasumi_hash_verify_test_case_2(void)
2024 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2028 test_kasumi_hash_verify_test_case_3(void)
2030 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2034 test_kasumi_hash_verify_test_case_4(void)
2036 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2040 test_kasumi_hash_verify_test_case_5(void)
2042 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2046 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2048 struct crypto_testsuite_params *ts_params = &testsuite_params;
2049 struct crypto_unittest_params *ut_params = &unittest_params;
2052 uint8_t *plaintext, *ciphertext;
2053 unsigned plaintext_pad_len;
2054 unsigned plaintext_len;
2056 /* Create KASUMI session */
2057 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2058 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2059 RTE_CRYPTO_CIPHER_KASUMI_F8,
2060 tdata->key.data, tdata->key.len);
2064 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2066 /* Clear mbuf payload */
2067 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2068 rte_pktmbuf_tailroom(ut_params->ibuf));
2070 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2071 /* Append data which is padded to a multiple */
2072 /* of the algorithms block size */
2073 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2074 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2076 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2078 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2080 /* Create KASUMI operation */
2081 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2082 tdata->plaintext.len,
2083 tdata->validCipherOffsetLenInBits.len,
2084 RTE_CRYPTO_CIPHER_KASUMI_F8);
2088 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2090 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2092 ut_params->obuf = ut_params->op->sym->m_dst;
2093 if (ut_params->obuf)
2094 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2097 ciphertext = plaintext;
2099 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2102 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2104 tdata->ciphertext.data,
2105 tdata->validCipherLenInBits.len,
2106 "KASUMI Ciphertext data not as expected");
2111 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2113 struct crypto_testsuite_params *ts_params = &testsuite_params;
2114 struct crypto_unittest_params *ut_params = &unittest_params;
2117 uint8_t *plaintext, *ciphertext;
2118 unsigned plaintext_pad_len;
2119 unsigned plaintext_len;
2121 /* Create KASUMI session */
2122 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2123 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2124 RTE_CRYPTO_CIPHER_KASUMI_F8,
2125 tdata->key.data, tdata->key.len);
2129 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2130 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2132 /* Clear mbuf payload */
2133 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2134 rte_pktmbuf_tailroom(ut_params->ibuf));
2136 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2137 /* Append data which is padded to a multiple */
2138 /* of the algorithms block size */
2139 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2140 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2142 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2143 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2145 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2147 /* Create KASUMI operation */
2148 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2150 tdata->plaintext.len,
2151 tdata->validCipherOffsetLenInBits.len,
2152 RTE_CRYPTO_CIPHER_KASUMI_F8);
2156 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2158 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2160 ut_params->obuf = ut_params->op->sym->m_dst;
2161 if (ut_params->obuf)
2162 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2165 ciphertext = plaintext;
2167 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2170 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2172 tdata->ciphertext.data,
2173 tdata->validCipherLenInBits.len,
2174 "KASUMI Ciphertext data not as expected");
2179 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2181 struct crypto_testsuite_params *ts_params = &testsuite_params;
2182 struct crypto_unittest_params *ut_params = &unittest_params;
2185 uint8_t *ciphertext, *plaintext;
2186 unsigned ciphertext_pad_len;
2187 unsigned ciphertext_len;
2189 /* Create KASUMI session */
2190 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2191 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2192 RTE_CRYPTO_CIPHER_KASUMI_F8,
2193 tdata->key.data, tdata->key.len);
2197 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2198 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2200 /* Clear mbuf payload */
2201 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2202 rte_pktmbuf_tailroom(ut_params->ibuf));
2204 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2205 /* Append data which is padded to a multiple */
2206 /* of the algorithms block size */
2207 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2208 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2209 ciphertext_pad_len);
2210 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2211 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2213 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2215 /* Create KASUMI operation */
2216 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2218 tdata->ciphertext.len,
2219 tdata->validCipherOffsetLenInBits.len,
2220 RTE_CRYPTO_CIPHER_KASUMI_F8);
2224 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2226 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2228 ut_params->obuf = ut_params->op->sym->m_dst;
2229 if (ut_params->obuf)
2230 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2233 plaintext = ciphertext;
2235 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2238 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2240 tdata->plaintext.data,
2241 tdata->validCipherLenInBits.len,
2242 "KASUMI Plaintext data not as expected");
2247 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2249 struct crypto_testsuite_params *ts_params = &testsuite_params;
2250 struct crypto_unittest_params *ut_params = &unittest_params;
2253 uint8_t *ciphertext, *plaintext;
2254 unsigned ciphertext_pad_len;
2255 unsigned ciphertext_len;
2257 /* Create KASUMI session */
2258 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2259 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2260 RTE_CRYPTO_CIPHER_KASUMI_F8,
2261 tdata->key.data, tdata->key.len);
2265 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2267 /* Clear mbuf payload */
2268 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2269 rte_pktmbuf_tailroom(ut_params->ibuf));
2271 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2272 /* Append data which is padded to a multiple */
2273 /* of the algorithms block size */
2274 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2275 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2276 ciphertext_pad_len);
2277 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2279 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2281 /* Create KASUMI operation */
2282 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2284 tdata->ciphertext.len,
2285 tdata->validCipherOffsetLenInBits.len,
2286 RTE_CRYPTO_CIPHER_KASUMI_F8);
2290 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2292 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2294 ut_params->obuf = ut_params->op->sym->m_dst;
2295 if (ut_params->obuf)
2296 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2299 plaintext = ciphertext;
2301 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2304 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2306 tdata->plaintext.data,
2307 tdata->validCipherLenInBits.len,
2308 "KASUMI Plaintext data not as expected");
2313 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2315 struct crypto_testsuite_params *ts_params = &testsuite_params;
2316 struct crypto_unittest_params *ut_params = &unittest_params;
2319 uint8_t *plaintext, *ciphertext;
2320 unsigned plaintext_pad_len;
2321 unsigned plaintext_len;
2323 /* Create SNOW 3G session */
2324 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2325 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2326 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2327 tdata->key.data, tdata->key.len);
2331 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2333 /* Clear mbuf payload */
2334 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2335 rte_pktmbuf_tailroom(ut_params->ibuf));
2337 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2338 /* Append data which is padded to a multiple of */
2339 /* the algorithms block size */
2340 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2341 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2343 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2345 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2347 /* Create SNOW 3G operation */
2348 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2349 tdata->validCipherLenInBits.len,
2350 tdata->validCipherOffsetLenInBits.len,
2351 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2355 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2357 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2359 ut_params->obuf = ut_params->op->sym->m_dst;
2360 if (ut_params->obuf)
2361 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2364 ciphertext = plaintext;
2366 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2369 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2371 tdata->ciphertext.data,
2372 tdata->validDataLenInBits.len,
2373 "SNOW 3G Ciphertext data not as expected");
2379 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2381 struct crypto_testsuite_params *ts_params = &testsuite_params;
2382 struct crypto_unittest_params *ut_params = &unittest_params;
2383 uint8_t *plaintext, *ciphertext;
2386 unsigned plaintext_pad_len;
2387 unsigned plaintext_len;
2389 /* Create SNOW 3G session */
2390 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2391 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2392 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2393 tdata->key.data, tdata->key.len);
2397 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2398 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2400 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2401 "Failed to allocate input buffer in mempool");
2402 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2403 "Failed to allocate output buffer in mempool");
2405 /* Clear mbuf payload */
2406 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2407 rte_pktmbuf_tailroom(ut_params->ibuf));
2409 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2410 /* Append data which is padded to a multiple of */
2411 /* the algorithms block size */
2412 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2413 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2415 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2416 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2418 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2420 /* Create SNOW 3G operation */
2421 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2423 tdata->validCipherLenInBits.len,
2424 tdata->validCipherOffsetLenInBits.len,
2425 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2429 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2431 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2433 ut_params->obuf = ut_params->op->sym->m_dst;
2434 if (ut_params->obuf)
2435 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2438 ciphertext = plaintext;
2440 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2443 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2445 tdata->ciphertext.data,
2446 tdata->validDataLenInBits.len,
2447 "SNOW 3G Ciphertext data not as expected");
2451 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2453 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2455 uint8_t curr_byte, prev_byte;
2456 uint32_t length_in_bytes = ceil_byte_length(length + offset);
2457 uint8_t lower_byte_mask = (1 << offset) - 1;
2460 prev_byte = buffer[0];
2461 buffer[0] >>= offset;
2463 for (i = 1; i < length_in_bytes; i++) {
2464 curr_byte = buffer[i];
2465 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2466 (curr_byte >> offset);
2467 prev_byte = curr_byte;
2472 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2474 struct crypto_testsuite_params *ts_params = &testsuite_params;
2475 struct crypto_unittest_params *ut_params = &unittest_params;
2476 uint8_t *plaintext, *ciphertext;
2478 uint32_t plaintext_len;
2479 uint32_t plaintext_pad_len;
2480 uint8_t extra_offset = 4;
2481 uint8_t *expected_ciphertext_shifted;
2483 /* Create SNOW 3G session */
2484 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2485 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2486 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2487 tdata->key.data, tdata->key.len);
2491 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2492 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2494 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2495 "Failed to allocate input buffer in mempool");
2496 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2497 "Failed to allocate output buffer in mempool");
2499 /* Clear mbuf payload */
2500 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2501 rte_pktmbuf_tailroom(ut_params->ibuf));
2503 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2505 * Append data which is padded to a
2506 * multiple of the algorithms block size
2508 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2510 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2513 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2515 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2516 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2518 #ifdef RTE_APP_TEST_DEBUG
2519 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2521 /* Create SNOW 3G operation */
2522 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2524 tdata->validCipherLenInBits.len,
2525 tdata->validCipherOffsetLenInBits.len +
2527 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2531 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2533 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2535 ut_params->obuf = ut_params->op->sym->m_dst;
2536 if (ut_params->obuf)
2537 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2540 ciphertext = plaintext;
2542 #ifdef RTE_APP_TEST_DEBUG
2543 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2546 expected_ciphertext_shifted = rte_malloc(NULL,
2547 ceil_byte_length(plaintext_len + extra_offset), 0);
2549 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2550 "failed to reserve memory for ciphertext shifted\n");
2552 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2553 ceil_byte_length(tdata->ciphertext.len));
2554 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2557 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2559 expected_ciphertext_shifted,
2560 tdata->validDataLenInBits.len,
2562 "SNOW 3G Ciphertext data not as expected");
2566 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2568 struct crypto_testsuite_params *ts_params = &testsuite_params;
2569 struct crypto_unittest_params *ut_params = &unittest_params;
2573 uint8_t *plaintext, *ciphertext;
2574 unsigned ciphertext_pad_len;
2575 unsigned ciphertext_len;
2577 /* Create SNOW 3G session */
2578 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2579 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2580 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2581 tdata->key.data, tdata->key.len);
2585 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2587 /* Clear mbuf payload */
2588 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2589 rte_pktmbuf_tailroom(ut_params->ibuf));
2591 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2592 /* Append data which is padded to a multiple of */
2593 /* the algorithms block size */
2594 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2595 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2596 ciphertext_pad_len);
2597 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2599 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2601 /* Create SNOW 3G operation */
2602 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2603 tdata->validCipherLenInBits.len,
2604 tdata->validCipherOffsetLenInBits.len,
2605 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2609 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2611 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2612 ut_params->obuf = ut_params->op->sym->m_dst;
2613 if (ut_params->obuf)
2614 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2617 plaintext = ciphertext;
2619 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2622 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2623 tdata->plaintext.data,
2624 tdata->validDataLenInBits.len,
2625 "SNOW 3G Plaintext data not as expected");
2629 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2631 struct crypto_testsuite_params *ts_params = &testsuite_params;
2632 struct crypto_unittest_params *ut_params = &unittest_params;
2636 uint8_t *plaintext, *ciphertext;
2637 unsigned ciphertext_pad_len;
2638 unsigned ciphertext_len;
2640 /* Create SNOW 3G session */
2641 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2642 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2643 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2644 tdata->key.data, tdata->key.len);
2648 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2649 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2651 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2652 "Failed to allocate input buffer");
2653 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2654 "Failed to allocate output buffer");
2656 /* Clear mbuf payload */
2657 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2658 rte_pktmbuf_tailroom(ut_params->ibuf));
2660 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2661 rte_pktmbuf_tailroom(ut_params->obuf));
2663 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2664 /* Append data which is padded to a multiple of */
2665 /* the algorithms block size */
2666 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2667 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2668 ciphertext_pad_len);
2669 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2670 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2672 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2674 /* Create SNOW 3G operation */
2675 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2677 tdata->validCipherLenInBits.len,
2678 tdata->validCipherOffsetLenInBits.len,
2679 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2683 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2685 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2686 ut_params->obuf = ut_params->op->sym->m_dst;
2687 if (ut_params->obuf)
2688 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2691 plaintext = ciphertext;
2693 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2696 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2697 tdata->plaintext.data,
2698 tdata->validDataLenInBits.len,
2699 "SNOW 3G Plaintext data not as expected");
2704 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
2706 struct crypto_testsuite_params *ts_params = &testsuite_params;
2707 struct crypto_unittest_params *ut_params = &unittest_params;
2711 uint8_t *plaintext, *ciphertext;
2712 unsigned plaintext_pad_len;
2713 unsigned plaintext_len;
2715 /* Create SNOW 3G session */
2716 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
2717 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2718 RTE_CRYPTO_AUTH_OP_GENERATE,
2719 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2720 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2721 tdata->key.data, tdata->key.len,
2722 tdata->aad.len, tdata->digest.len);
2725 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2727 /* clear mbuf payload */
2728 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2729 rte_pktmbuf_tailroom(ut_params->ibuf));
2731 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2732 /* Append data which is padded to a multiple of */
2733 /* the algorithms block size */
2734 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2735 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2737 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2739 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2741 /* Create SNOW 3G operation */
2742 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
2743 tdata->digest.len, tdata->aad.data,
2744 tdata->aad.len, /*tdata->plaintext.len,*/
2745 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2746 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2747 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2748 tdata->iv.data, tdata->iv.len,
2749 tdata->validCipherLenInBits.len,
2750 tdata->validCipherOffsetLenInBits.len,
2751 tdata->validAuthLenInBits.len,
2752 tdata->validAuthOffsetLenInBits.len
2757 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2759 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2760 ut_params->obuf = ut_params->op->sym->m_src;
2761 if (ut_params->obuf)
2762 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2763 + tdata->iv.len + tdata->aad.len;
2765 ciphertext = plaintext;
2767 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2769 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2771 tdata->ciphertext.data,
2772 tdata->validDataLenInBits.len,
2773 "SNOW 3G Ciphertext data not as expected");
2775 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2776 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2779 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2782 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2783 "SNOW 3G Generated auth tag not as expected");
2787 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
2789 struct crypto_testsuite_params *ts_params = &testsuite_params;
2790 struct crypto_unittest_params *ut_params = &unittest_params;
2794 uint8_t *plaintext, *ciphertext;
2795 unsigned plaintext_pad_len;
2796 unsigned plaintext_len;
2798 /* Create SNOW 3G session */
2799 retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
2800 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2801 RTE_CRYPTO_AUTH_OP_GENERATE,
2802 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2803 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2804 tdata->key.data, tdata->key.len,
2805 tdata->aad.len, tdata->digest.len);
2809 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2811 /* clear mbuf payload */
2812 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2813 rte_pktmbuf_tailroom(ut_params->ibuf));
2815 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2816 /* Append data which is padded to a multiple of */
2817 /* the algorithms block size */
2818 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2819 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2821 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2823 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2825 /* Create SNOW 3G operation */
2826 retval = create_wireless_algo_auth_cipher_operation(
2828 tdata->iv.data, tdata->iv.len,
2829 tdata->aad.data, tdata->aad.len,
2831 tdata->validCipherLenInBits.len,
2832 tdata->validCipherOffsetLenInBits.len,
2833 tdata->validAuthLenInBits.len,
2834 tdata->validAuthOffsetLenInBits.len,
2835 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2836 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
2842 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2844 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2845 ut_params->obuf = ut_params->op->sym->m_src;
2846 if (ut_params->obuf)
2847 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2848 + tdata->aad.len + tdata->iv.len;
2850 ciphertext = plaintext;
2852 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2853 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2854 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2857 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2859 tdata->ciphertext.data,
2860 tdata->validDataLenInBits.len,
2861 "SNOW 3G Ciphertext data not as expected");
2864 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2867 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2868 "SNOW 3G Generated auth tag not as expected");
2873 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
2875 struct crypto_testsuite_params *ts_params = &testsuite_params;
2876 struct crypto_unittest_params *ut_params = &unittest_params;
2880 uint8_t *plaintext, *ciphertext;
2881 unsigned plaintext_pad_len;
2882 unsigned plaintext_len;
2884 /* Create KASUMI session */
2885 retval = create_wireless_algo_auth_cipher_session(
2886 ts_params->valid_devs[0],
2887 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2888 RTE_CRYPTO_AUTH_OP_GENERATE,
2889 RTE_CRYPTO_AUTH_KASUMI_F9,
2890 RTE_CRYPTO_CIPHER_KASUMI_F8,
2891 tdata->key.data, tdata->key.len,
2892 tdata->aad.len, tdata->digest.len);
2895 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2897 /* clear mbuf payload */
2898 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2899 rte_pktmbuf_tailroom(ut_params->ibuf));
2901 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2902 /* Append data which is padded to a multiple of */
2903 /* the algorithms block size */
2904 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2905 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2907 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2909 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2911 /* Create KASUMI operation */
2912 retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
2913 tdata->iv.data, tdata->iv.len,
2914 tdata->aad.data, tdata->aad.len,
2916 tdata->validCipherLenInBits.len,
2917 tdata->validCipherOffsetLenInBits.len,
2918 tdata->validAuthLenInBits.len,
2919 tdata->validAuthOffsetLenInBits.len,
2920 RTE_CRYPTO_AUTH_KASUMI_F9,
2921 RTE_CRYPTO_CIPHER_KASUMI_F8
2927 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2929 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2930 ut_params->obuf = ut_params->op->sym->m_src;
2931 if (ut_params->obuf)
2932 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2933 + tdata->iv.len + tdata->aad.len;
2935 ciphertext = plaintext;
2938 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2940 tdata->ciphertext.data,
2941 tdata->validCipherLenInBits.len,
2942 "KASUMI Ciphertext data not as expected");
2943 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2944 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2947 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2950 DIGEST_BYTE_LENGTH_KASUMI_F9,
2951 "KASUMI Generated auth tag not as expected");
2956 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
2958 struct crypto_testsuite_params *ts_params = &testsuite_params;
2959 struct crypto_unittest_params *ut_params = &unittest_params;
2963 uint8_t *plaintext, *ciphertext;
2964 unsigned plaintext_pad_len;
2965 unsigned plaintext_len;
2967 /* Create KASUMI session */
2968 retval = create_wireless_algo_cipher_auth_session(
2969 ts_params->valid_devs[0],
2970 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2971 RTE_CRYPTO_AUTH_OP_GENERATE,
2972 RTE_CRYPTO_AUTH_KASUMI_F9,
2973 RTE_CRYPTO_CIPHER_KASUMI_F8,
2974 tdata->key.data, tdata->key.len,
2975 tdata->aad.len, tdata->digest.len);
2979 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2981 /* clear mbuf payload */
2982 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2983 rte_pktmbuf_tailroom(ut_params->ibuf));
2985 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2986 /* Append data which is padded to a multiple of */
2987 /* the algorithms block size */
2988 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2989 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2991 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2993 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2995 /* Create KASUMI operation */
2996 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
2997 tdata->digest.len, tdata->aad.data,
2999 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3000 RTE_CRYPTO_AUTH_KASUMI_F9,
3001 RTE_CRYPTO_CIPHER_KASUMI_F8,
3002 tdata->iv.data, tdata->iv.len,
3003 tdata->validCipherLenInBits.len,
3004 tdata->validCipherOffsetLenInBits.len,
3005 tdata->validAuthLenInBits.len,
3006 tdata->validAuthOffsetLenInBits.len
3011 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3013 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3014 ut_params->obuf = ut_params->op->sym->m_src;
3015 if (ut_params->obuf)
3016 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3017 + tdata->aad.len + tdata->iv.len;
3019 ciphertext = plaintext;
3021 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3022 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3025 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3027 tdata->ciphertext.data,
3028 tdata->validCipherLenInBits.len,
3029 "KASUMI Ciphertext data not as expected");
3032 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3035 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3036 "KASUMI Generated auth tag not as expected");
3041 test_zuc_encryption(const struct zuc_test_data *tdata)
3043 struct crypto_testsuite_params *ts_params = &testsuite_params;
3044 struct crypto_unittest_params *ut_params = &unittest_params;
3047 uint8_t *plaintext, *ciphertext;
3048 unsigned plaintext_pad_len;
3049 unsigned plaintext_len;
3051 /* Create ZUC session */
3052 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3053 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3054 RTE_CRYPTO_CIPHER_ZUC_EEA3,
3055 tdata->key.data, tdata->key.len);
3059 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3061 /* Clear mbuf payload */
3062 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3063 rte_pktmbuf_tailroom(ut_params->ibuf));
3065 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3066 /* Append data which is padded to a multiple */
3067 /* of the algorithms block size */
3068 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3069 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3071 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3073 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3075 /* Create ZUC operation */
3076 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3077 tdata->plaintext.len,
3078 tdata->validCipherOffsetLenInBits.len,
3079 RTE_CRYPTO_CIPHER_ZUC_EEA3);
3083 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3085 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3087 ut_params->obuf = ut_params->op->sym->m_dst;
3088 if (ut_params->obuf)
3089 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3092 ciphertext = plaintext;
3094 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3097 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3099 tdata->ciphertext.data,
3100 tdata->validCipherLenInBits.len,
3101 "ZUC Ciphertext data not as expected");
3106 test_zuc_authentication(const struct zuc_hash_test_data *tdata)
3108 struct crypto_testsuite_params *ts_params = &testsuite_params;
3109 struct crypto_unittest_params *ut_params = &unittest_params;
3112 unsigned plaintext_pad_len;
3113 unsigned plaintext_len;
3116 /* Create ZUC session */
3117 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3118 tdata->key.data, tdata->key.len,
3119 tdata->aad.len, tdata->digest.len,
3120 RTE_CRYPTO_AUTH_OP_GENERATE,
3121 RTE_CRYPTO_AUTH_ZUC_EIA3);
3125 /* alloc mbuf and set payload */
3126 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3128 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3129 rte_pktmbuf_tailroom(ut_params->ibuf));
3131 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3132 /* Append data which is padded to a multiple of */
3133 /* the algorithms block size */
3134 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3135 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3137 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3139 /* Create ZUC operation */
3140 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3141 tdata->aad.data, tdata->aad.len,
3142 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3143 RTE_CRYPTO_AUTH_ZUC_EIA3,
3144 tdata->validAuthLenInBits.len,
3145 tdata->validAuthOffsetLenInBits.len);
3149 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3151 ut_params->obuf = ut_params->op->sym->m_src;
3152 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3153 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3154 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
3157 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3160 DIGEST_BYTE_LENGTH_KASUMI_F9,
3161 "ZUC Generated auth tag not as expected");
3167 test_kasumi_encryption_test_case_1(void)
3169 return test_kasumi_encryption(&kasumi_test_case_1);
3173 test_kasumi_encryption_test_case_1_oop(void)
3175 return test_kasumi_encryption_oop(&kasumi_test_case_1);
3179 test_kasumi_encryption_test_case_2(void)
3181 return test_kasumi_encryption(&kasumi_test_case_2);
3185 test_kasumi_encryption_test_case_3(void)
3187 return test_kasumi_encryption(&kasumi_test_case_3);
3191 test_kasumi_encryption_test_case_4(void)
3193 return test_kasumi_encryption(&kasumi_test_case_4);
3197 test_kasumi_encryption_test_case_5(void)
3199 return test_kasumi_encryption(&kasumi_test_case_5);
3203 test_kasumi_decryption_test_case_1(void)
3205 return test_kasumi_decryption(&kasumi_test_case_1);
3209 test_kasumi_decryption_test_case_1_oop(void)
3211 return test_kasumi_decryption_oop(&kasumi_test_case_1);
3215 test_kasumi_decryption_test_case_2(void)
3217 return test_kasumi_decryption(&kasumi_test_case_2);
3221 test_kasumi_decryption_test_case_3(void)
3223 return test_kasumi_decryption(&kasumi_test_case_3);
3227 test_kasumi_decryption_test_case_4(void)
3229 return test_kasumi_decryption(&kasumi_test_case_4);
3233 test_kasumi_decryption_test_case_5(void)
3235 return test_kasumi_decryption(&kasumi_test_case_5);
3238 test_snow3g_encryption_test_case_1(void)
3240 return test_snow3g_encryption(&snow3g_test_case_1);
3244 test_snow3g_encryption_test_case_1_oop(void)
3246 return test_snow3g_encryption_oop(&snow3g_test_case_1);
3250 test_snow3g_encryption_test_case_1_offset_oop(void)
3252 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
3256 test_snow3g_encryption_test_case_2(void)
3258 return test_snow3g_encryption(&snow3g_test_case_2);
3262 test_snow3g_encryption_test_case_3(void)
3264 return test_snow3g_encryption(&snow3g_test_case_3);
3268 test_snow3g_encryption_test_case_4(void)
3270 return test_snow3g_encryption(&snow3g_test_case_4);
3274 test_snow3g_encryption_test_case_5(void)
3276 return test_snow3g_encryption(&snow3g_test_case_5);
3280 test_snow3g_decryption_test_case_1(void)
3282 return test_snow3g_decryption(&snow3g_test_case_1);
3286 test_snow3g_decryption_test_case_1_oop(void)
3288 return test_snow3g_decryption_oop(&snow3g_test_case_1);
3292 test_snow3g_decryption_test_case_2(void)
3294 return test_snow3g_decryption(&snow3g_test_case_2);
3298 test_snow3g_decryption_test_case_3(void)
3300 return test_snow3g_decryption(&snow3g_test_case_3);
3304 test_snow3g_decryption_test_case_4(void)
3306 return test_snow3g_decryption(&snow3g_test_case_4);
3310 test_snow3g_decryption_test_case_5(void)
3312 return test_snow3g_decryption(&snow3g_test_case_5);
3315 test_snow3g_cipher_auth_test_case_1(void)
3317 return test_snow3g_cipher_auth(&snow3g_test_case_3);
3321 test_snow3g_auth_cipher_test_case_1(void)
3323 return test_snow3g_auth_cipher(&snow3g_test_case_6);
3327 test_kasumi_auth_cipher_test_case_1(void)
3329 return test_kasumi_auth_cipher(&kasumi_test_case_3);
3333 test_kasumi_cipher_auth_test_case_1(void)
3335 return test_kasumi_cipher_auth(&kasumi_test_case_6);
3339 test_zuc_encryption_test_case_1(void)
3341 return test_zuc_encryption(&zuc_test_case_1);
3345 test_zuc_encryption_test_case_2(void)
3347 return test_zuc_encryption(&zuc_test_case_2);
3351 test_zuc_encryption_test_case_3(void)
3353 return test_zuc_encryption(&zuc_test_case_3);
3357 test_zuc_encryption_test_case_4(void)
3359 return test_zuc_encryption(&zuc_test_case_4);
3363 test_zuc_encryption_test_case_5(void)
3365 return test_zuc_encryption(&zuc_test_case_5);
3369 test_zuc_hash_generate_test_case_1(void)
3371 return test_zuc_authentication(&zuc_hash_test_case_1);
3375 test_zuc_hash_generate_test_case_2(void)
3377 return test_zuc_authentication(&zuc_hash_test_case_2);
3381 test_zuc_hash_generate_test_case_3(void)
3383 return test_zuc_authentication(&zuc_hash_test_case_3);
3387 test_zuc_hash_generate_test_case_4(void)
3389 return test_zuc_authentication(&zuc_hash_test_case_4);
3393 test_zuc_hash_generate_test_case_5(void)
3395 return test_zuc_authentication(&zuc_hash_test_case_5);
3398 /* ***** AES-GCM Tests ***** */
3401 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3402 const uint8_t *key, const uint8_t key_len,
3403 const uint8_t aad_len, const uint8_t auth_len,
3404 enum rte_crypto_auth_operation auth_op)
3406 uint8_t cipher_key[key_len];
3408 struct crypto_unittest_params *ut_params = &unittest_params;
3410 memcpy(cipher_key, key, key_len);
3412 /* Setup Cipher Parameters */
3413 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3414 ut_params->cipher_xform.next = NULL;
3416 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3417 ut_params->auth_xform.auth.op = auth_op;
3418 ut_params->cipher_xform.cipher.op = op;
3419 ut_params->cipher_xform.cipher.key.data = cipher_key;
3420 ut_params->cipher_xform.cipher.key.length = key_len;
3422 TEST_HEXDUMP(stdout, "key:", key, key_len);
3424 /* Setup Authentication Parameters */
3425 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3426 ut_params->auth_xform.next = NULL;
3428 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3430 ut_params->auth_xform.auth.digest_length = auth_len;
3431 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3432 ut_params->auth_xform.auth.key.length = 0;
3433 ut_params->auth_xform.auth.key.data = NULL;
3435 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3436 ut_params->cipher_xform.next = &ut_params->auth_xform;
3438 /* Create Crypto session*/
3439 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3440 &ut_params->cipher_xform);
3441 } else {/* Create Crypto session*/
3442 ut_params->auth_xform.next = &ut_params->cipher_xform;
3443 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3444 &ut_params->auth_xform);
3447 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3453 create_gcm_operation(enum rte_crypto_cipher_operation op,
3454 const uint8_t *auth_tag, const unsigned auth_tag_len,
3455 const uint8_t *iv, const unsigned iv_len,
3456 const uint8_t *aad, const unsigned aad_len,
3457 const unsigned data_len, unsigned data_pad_len)
3459 struct crypto_testsuite_params *ts_params = &testsuite_params;
3460 struct crypto_unittest_params *ut_params = &unittest_params;
3462 unsigned iv_pad_len = 0, aad_buffer_len;
3464 /* Generate Crypto op data structure */
3465 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3466 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3467 TEST_ASSERT_NOT_NULL(ut_params->op,
3468 "Failed to allocate symmetric crypto operation struct");
3470 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3472 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3473 ut_params->ibuf, auth_tag_len);
3474 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3475 "no room to append digest");
3476 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3477 ut_params->ibuf, data_pad_len);
3478 sym_op->auth.digest.length = auth_tag_len;
3480 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3481 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3482 TEST_HEXDUMP(stdout, "digest:",
3483 sym_op->auth.digest.data,
3484 sym_op->auth.digest.length);
3488 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3490 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3491 ut_params->ibuf, iv_pad_len);
3492 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3494 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3495 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3496 sym_op->cipher.iv.length = iv_len;
3498 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3501 * Always allocate the aad up to the block size.
3502 * The cryptodev API calls out -
3503 * - the array must be big enough to hold the AAD, plus any
3504 * space to round this up to the nearest multiple of the
3505 * block size (16 bytes).
3507 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3509 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3510 ut_params->ibuf, aad_buffer_len);
3511 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3512 "no room to prepend aad");
3513 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3515 sym_op->auth.aad.length = aad_len;
3517 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3518 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3520 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3521 TEST_HEXDUMP(stdout, "aad:",
3522 sym_op->auth.aad.data, aad_len);
3524 sym_op->cipher.data.length = data_len;
3525 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3527 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3528 sym_op->auth.data.length = data_len;
3534 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3536 struct crypto_testsuite_params *ts_params = &testsuite_params;
3537 struct crypto_unittest_params *ut_params = &unittest_params;
3541 uint8_t *plaintext, *ciphertext, *auth_tag;
3542 uint16_t plaintext_pad_len;
3544 /* Create GCM session */
3545 retval = create_gcm_session(ts_params->valid_devs[0],
3546 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3547 tdata->key.data, tdata->key.len,
3548 tdata->aad.len, tdata->auth_tag.len,
3549 RTE_CRYPTO_AUTH_OP_GENERATE);
3554 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3556 /* clear mbuf payload */
3557 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3558 rte_pktmbuf_tailroom(ut_params->ibuf));
3561 * Append data which is padded to a multiple
3562 * of the algorithms block size
3564 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3566 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3568 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3570 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3572 /* Create GCM opertaion */
3573 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3574 tdata->auth_tag.data, tdata->auth_tag.len,
3575 tdata->iv.data, tdata->iv.len,
3576 tdata->aad.data, tdata->aad.len,
3577 tdata->plaintext.len, plaintext_pad_len);
3581 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3583 ut_params->op->sym->m_src = ut_params->ibuf;
3585 /* Process crypto operation */
3586 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3587 ut_params->op), "failed to process sym crypto op");
3589 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3590 "crypto op processing failed");
3592 if (ut_params->op->sym->m_dst) {
3593 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3595 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3596 uint8_t *, plaintext_pad_len);
3598 ciphertext = plaintext;
3599 auth_tag = plaintext + plaintext_pad_len;
3602 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3603 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3606 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3608 tdata->ciphertext.data,
3609 tdata->ciphertext.len,
3610 "GCM Ciphertext data not as expected");
3612 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3614 tdata->auth_tag.data,
3615 tdata->auth_tag.len,
3616 "GCM Generated auth tag not as expected");
3623 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3625 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3629 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3631 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3635 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3637 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3641 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3643 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3647 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3649 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3653 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3655 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3659 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3661 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3665 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3667 struct crypto_testsuite_params *ts_params = &testsuite_params;
3668 struct crypto_unittest_params *ut_params = &unittest_params;
3672 uint8_t *plaintext, *ciphertext;
3673 uint16_t ciphertext_pad_len;
3675 /* Create GCM session */
3676 retval = create_gcm_session(ts_params->valid_devs[0],
3677 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3678 tdata->key.data, tdata->key.len,
3679 tdata->aad.len, tdata->auth_tag.len,
3680 RTE_CRYPTO_AUTH_OP_VERIFY);
3685 /* alloc mbuf and set payload */
3686 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3688 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3689 rte_pktmbuf_tailroom(ut_params->ibuf));
3691 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3693 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3694 ciphertext_pad_len);
3695 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3697 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3699 /* Create GCM opertaion */
3700 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3701 tdata->auth_tag.data, tdata->auth_tag.len,
3702 tdata->iv.data, tdata->iv.len,
3703 tdata->aad.data, tdata->aad.len,
3704 tdata->ciphertext.len, ciphertext_pad_len);
3709 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3711 ut_params->op->sym->m_src = ut_params->ibuf;
3713 /* Process crypto operation */
3714 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3715 ut_params->op), "failed to process sym crypto op");
3717 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3718 "crypto op processing failed");
3720 if (ut_params->op->sym->m_dst)
3721 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3724 plaintext = ciphertext;
3726 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3729 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3731 tdata->plaintext.data,
3732 tdata->plaintext.len,
3733 "GCM plaintext data not as expected");
3735 TEST_ASSERT_EQUAL(ut_params->op->status,
3736 RTE_CRYPTO_OP_STATUS_SUCCESS,
3737 "GCM authentication failed");
3742 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3744 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3748 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3750 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3754 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3756 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3760 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3762 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3766 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3768 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3772 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3774 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3778 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3780 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3786 struct crypto_testsuite_params *ts_params = &testsuite_params;
3787 struct rte_cryptodev_stats stats;
3788 struct rte_cryptodev *dev;
3789 cryptodev_stats_get_t temp_pfn;
3791 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3792 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3793 &stats) == -ENODEV),
3794 "rte_cryptodev_stats_get invalid dev failed");
3795 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3796 "rte_cryptodev_stats_get invalid Param failed");
3797 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3798 temp_pfn = dev->dev_ops->stats_get;
3799 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3800 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3802 "rte_cryptodev_stats_get invalid Param failed");
3803 dev->dev_ops->stats_get = temp_pfn;
3805 /* Test expected values */
3807 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3809 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3811 "rte_cryptodev_stats_get failed");
3812 TEST_ASSERT((stats.enqueued_count == 1),
3813 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3814 TEST_ASSERT((stats.dequeued_count == 1),
3815 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3816 TEST_ASSERT((stats.enqueue_err_count == 0),
3817 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3818 TEST_ASSERT((stats.dequeue_err_count == 0),
3819 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3821 /* invalid device but should ignore and not reset device stats*/
3822 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3823 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3825 "rte_cryptodev_stats_get failed");
3826 TEST_ASSERT((stats.enqueued_count == 1),
3827 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3829 /* check that a valid reset clears stats */
3830 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3831 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3833 "rte_cryptodev_stats_get failed");
3834 TEST_ASSERT((stats.enqueued_count == 0),
3835 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3836 TEST_ASSERT((stats.dequeued_count == 0),
3837 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3839 return TEST_SUCCESS;
3842 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
3843 struct crypto_unittest_params *ut_params,
3844 enum rte_crypto_auth_operation op,
3845 const struct HMAC_MD5_vector *test_case)
3849 memcpy(key, test_case->key.data, test_case->key.len);
3851 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3852 ut_params->auth_xform.next = NULL;
3853 ut_params->auth_xform.auth.op = op;
3855 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
3857 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
3858 ut_params->auth_xform.auth.add_auth_data_length = 0;
3859 ut_params->auth_xform.auth.key.length = test_case->key.len;
3860 ut_params->auth_xform.auth.key.data = key;
3862 ut_params->sess = rte_cryptodev_sym_session_create(
3863 ts_params->valid_devs[0], &ut_params->auth_xform);
3865 if (ut_params->sess == NULL)
3868 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3870 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3871 rte_pktmbuf_tailroom(ut_params->ibuf));
3876 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
3877 const struct HMAC_MD5_vector *test_case,
3878 uint8_t **plaintext)
3880 uint16_t plaintext_pad_len;
3882 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3884 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3887 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3889 memcpy(*plaintext, test_case->plaintext.data,
3890 test_case->plaintext.len);
3892 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3893 ut_params->ibuf, MD5_DIGEST_LEN);
3894 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3895 "no room to append digest");
3896 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3897 ut_params->ibuf, plaintext_pad_len);
3898 sym_op->auth.digest.length = MD5_DIGEST_LEN;
3900 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
3901 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
3902 test_case->auth_tag.len);
3905 sym_op->auth.data.offset = 0;
3906 sym_op->auth.data.length = test_case->plaintext.len;
3908 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3909 ut_params->op->sym->m_src = ut_params->ibuf;
3915 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
3917 uint16_t plaintext_pad_len;
3918 uint8_t *plaintext, *auth_tag;
3920 struct crypto_testsuite_params *ts_params = &testsuite_params;
3921 struct crypto_unittest_params *ut_params = &unittest_params;
3923 if (MD5_HMAC_create_session(ts_params, ut_params,
3924 RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
3927 /* Generate Crypto op data structure */
3928 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3929 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3930 TEST_ASSERT_NOT_NULL(ut_params->op,
3931 "Failed to allocate symmetric crypto operation struct");
3933 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3936 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3939 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3940 ut_params->op), "failed to process sym crypto op");
3942 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3943 "crypto op processing failed");
3945 if (ut_params->op->sym->m_dst) {
3946 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3947 uint8_t *, plaintext_pad_len);
3949 auth_tag = plaintext + plaintext_pad_len;
3952 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3954 test_case->auth_tag.data,
3955 test_case->auth_tag.len,
3956 "HMAC_MD5 generated tag not as expected");
3958 return TEST_SUCCESS;
3962 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
3966 struct crypto_testsuite_params *ts_params = &testsuite_params;
3967 struct crypto_unittest_params *ut_params = &unittest_params;
3969 if (MD5_HMAC_create_session(ts_params, ut_params,
3970 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
3974 /* Generate Crypto op data structure */
3975 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3976 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3977 TEST_ASSERT_NOT_NULL(ut_params->op,
3978 "Failed to allocate symmetric crypto operation struct");
3980 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3983 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3984 ut_params->op), "failed to process sym crypto op");
3986 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3987 "HMAC_MD5 crypto op processing failed");
3989 return TEST_SUCCESS;
3993 test_MD5_HMAC_generate_case_1(void)
3995 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
3999 test_MD5_HMAC_verify_case_1(void)
4001 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
4005 test_MD5_HMAC_generate_case_2(void)
4007 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
4011 test_MD5_HMAC_verify_case_2(void)
4013 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
4017 test_multi_session(void)
4019 struct crypto_testsuite_params *ts_params = &testsuite_params;
4020 struct crypto_unittest_params *ut_params = &unittest_params;
4022 struct rte_cryptodev_info dev_info;
4023 struct rte_cryptodev_sym_session **sessions;
4027 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
4030 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4032 sessions = rte_malloc(NULL,
4033 (sizeof(struct rte_cryptodev_sym_session *) *
4034 dev_info.sym.max_nb_sessions) + 1, 0);
4036 /* Create multiple crypto sessions*/
4037 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4038 sessions[i] = rte_cryptodev_sym_session_create(
4039 ts_params->valid_devs[0],
4040 &ut_params->auth_xform);
4041 TEST_ASSERT_NOT_NULL(sessions[i],
4042 "Session creation failed at session number %u",
4045 /* Attempt to send a request on each session */
4046 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
4047 sessions[i], ut_params, ts_params),
4048 "Failed to perform decrypt on request "
4050 /* free crypto operation structure */
4052 rte_crypto_op_free(ut_params->op);
4055 * free mbuf - both obuf and ibuf are usually the same,
4056 * so check if they point at the same address is necessary,
4057 * to avoid freeing the mbuf twice.
4059 if (ut_params->obuf) {
4060 rte_pktmbuf_free(ut_params->obuf);
4061 if (ut_params->ibuf == ut_params->obuf)
4062 ut_params->ibuf = 0;
4063 ut_params->obuf = 0;
4065 if (ut_params->ibuf) {
4066 rte_pktmbuf_free(ut_params->ibuf);
4067 ut_params->ibuf = 0;
4071 /* Next session create should fail */
4072 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4073 &ut_params->auth_xform);
4074 TEST_ASSERT_NULL(sessions[i],
4075 "Session creation succeeded unexpectedly!");
4077 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4078 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4083 return TEST_SUCCESS;
4087 test_null_cipher_only_operation(void)
4089 struct crypto_testsuite_params *ts_params = &testsuite_params;
4090 struct crypto_unittest_params *ut_params = &unittest_params;
4092 /* Generate test mbuf data and space for digest */
4093 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4094 catch_22_quote, QUOTE_512_BYTES, 0);
4096 /* Setup Cipher Parameters */
4097 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4098 ut_params->cipher_xform.next = NULL;
4100 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4101 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4103 /* Create Crypto session*/
4104 ut_params->sess = rte_cryptodev_sym_session_create(
4105 ts_params->valid_devs[0], &ut_params->cipher_xform);
4106 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4108 /* Generate Crypto op data structure */
4109 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4110 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4111 TEST_ASSERT_NOT_NULL(ut_params->op,
4112 "Failed to allocate symmetric crypto operation struct");
4114 /* Set crypto operation data parameters */
4115 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4117 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4119 /* set crypto operation source mbuf */
4120 sym_op->m_src = ut_params->ibuf;
4122 sym_op->cipher.data.offset = 0;
4123 sym_op->cipher.data.length = QUOTE_512_BYTES;
4125 /* Process crypto operation */
4126 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4128 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4130 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4131 "crypto operation processing failed");
4134 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4135 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4138 "Ciphertext data not as expected");
4140 return TEST_SUCCESS;
4144 test_null_auth_only_operation(void)
4146 struct crypto_testsuite_params *ts_params = &testsuite_params;
4147 struct crypto_unittest_params *ut_params = &unittest_params;
4149 /* Generate test mbuf data and space for digest */
4150 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4151 catch_22_quote, QUOTE_512_BYTES, 0);
4153 /* Setup HMAC Parameters */
4154 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4155 ut_params->auth_xform.next = NULL;
4157 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4158 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4160 /* Create Crypto session*/
4161 ut_params->sess = rte_cryptodev_sym_session_create(
4162 ts_params->valid_devs[0], &ut_params->auth_xform);
4163 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4165 /* Generate Crypto op data structure */
4166 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4167 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4168 TEST_ASSERT_NOT_NULL(ut_params->op,
4169 "Failed to allocate symmetric crypto operation struct");
4171 /* Set crypto operation data parameters */
4172 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4174 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4176 sym_op->m_src = ut_params->ibuf;
4178 sym_op->auth.data.offset = 0;
4179 sym_op->auth.data.length = QUOTE_512_BYTES;
4181 /* Process crypto operation */
4182 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4184 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4186 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4187 "crypto operation processing failed");
4189 return TEST_SUCCESS;
4193 test_null_cipher_auth_operation(void)
4195 struct crypto_testsuite_params *ts_params = &testsuite_params;
4196 struct crypto_unittest_params *ut_params = &unittest_params;
4198 /* Generate test mbuf data and space for digest */
4199 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4200 catch_22_quote, QUOTE_512_BYTES, 0);
4202 /* Setup Cipher Parameters */
4203 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4204 ut_params->cipher_xform.next = &ut_params->auth_xform;
4206 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4207 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4209 /* Setup HMAC Parameters */
4210 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4211 ut_params->auth_xform.next = NULL;
4213 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4214 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4216 /* Create Crypto session*/
4217 ut_params->sess = rte_cryptodev_sym_session_create(
4218 ts_params->valid_devs[0], &ut_params->cipher_xform);
4219 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4221 /* Generate Crypto op data structure */
4222 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4223 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4224 TEST_ASSERT_NOT_NULL(ut_params->op,
4225 "Failed to allocate symmetric crypto operation struct");
4227 /* Set crypto operation data parameters */
4228 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4230 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4232 sym_op->m_src = ut_params->ibuf;
4234 sym_op->cipher.data.offset = 0;
4235 sym_op->cipher.data.length = QUOTE_512_BYTES;
4237 sym_op->auth.data.offset = 0;
4238 sym_op->auth.data.length = QUOTE_512_BYTES;
4240 /* Process crypto operation */
4241 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4243 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4245 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4246 "crypto operation processing failed");
4249 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4250 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4253 "Ciphertext data not as expected");
4255 return TEST_SUCCESS;
4259 test_null_auth_cipher_operation(void)
4261 struct crypto_testsuite_params *ts_params = &testsuite_params;
4262 struct crypto_unittest_params *ut_params = &unittest_params;
4264 /* Generate test mbuf data and space for digest */
4265 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4266 catch_22_quote, QUOTE_512_BYTES, 0);
4268 /* Setup Cipher Parameters */
4269 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4270 ut_params->cipher_xform.next = NULL;
4272 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4273 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4275 /* Setup HMAC Parameters */
4276 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4277 ut_params->auth_xform.next = &ut_params->cipher_xform;
4279 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4280 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4282 /* Create Crypto session*/
4283 ut_params->sess = rte_cryptodev_sym_session_create(
4284 ts_params->valid_devs[0], &ut_params->cipher_xform);
4285 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4287 /* Generate Crypto op data structure */
4288 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4289 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4290 TEST_ASSERT_NOT_NULL(ut_params->op,
4291 "Failed to allocate symmetric crypto operation struct");
4293 /* Set crypto operation data parameters */
4294 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4296 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4298 sym_op->m_src = ut_params->ibuf;
4300 sym_op->cipher.data.offset = 0;
4301 sym_op->cipher.data.length = QUOTE_512_BYTES;
4303 sym_op->auth.data.offset = 0;
4304 sym_op->auth.data.length = QUOTE_512_BYTES;
4306 /* Process crypto operation */
4307 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4309 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4311 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4312 "crypto operation processing failed");
4315 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4316 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4319 "Ciphertext data not as expected");
4321 return TEST_SUCCESS;
4326 test_null_invalid_operation(void)
4328 struct crypto_testsuite_params *ts_params = &testsuite_params;
4329 struct crypto_unittest_params *ut_params = &unittest_params;
4331 /* Setup Cipher Parameters */
4332 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4333 ut_params->cipher_xform.next = NULL;
4335 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4336 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4338 /* Create Crypto session*/
4339 ut_params->sess = rte_cryptodev_sym_session_create(
4340 ts_params->valid_devs[0], &ut_params->cipher_xform);
4341 TEST_ASSERT_NULL(ut_params->sess,
4342 "Session creation succeeded unexpectedly");
4345 /* Setup HMAC Parameters */
4346 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4347 ut_params->auth_xform.next = NULL;
4349 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4350 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4352 /* Create Crypto session*/
4353 ut_params->sess = rte_cryptodev_sym_session_create(
4354 ts_params->valid_devs[0], &ut_params->auth_xform);
4355 TEST_ASSERT_NULL(ut_params->sess,
4356 "Session creation succeeded unexpectedly");
4358 return TEST_SUCCESS;
4362 #define NULL_BURST_LENGTH (32)
4365 test_null_burst_operation(void)
4367 struct crypto_testsuite_params *ts_params = &testsuite_params;
4368 struct crypto_unittest_params *ut_params = &unittest_params;
4370 unsigned i, burst_len = NULL_BURST_LENGTH;
4372 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4373 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4375 /* Setup Cipher Parameters */
4376 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4377 ut_params->cipher_xform.next = &ut_params->auth_xform;
4379 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4380 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4382 /* Setup HMAC Parameters */
4383 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4384 ut_params->auth_xform.next = NULL;
4386 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4387 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4389 /* Create Crypto session*/
4390 ut_params->sess = rte_cryptodev_sym_session_create(
4391 ts_params->valid_devs[0], &ut_params->cipher_xform);
4392 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4394 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4395 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4396 burst_len, "failed to generate burst of crypto ops");
4398 /* Generate an operation for each mbuf in burst */
4399 for (i = 0; i < burst_len; i++) {
4400 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4402 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
4404 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
4408 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
4410 burst[i]->sym->m_src = m;
4413 /* Process crypto operation */
4414 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
4415 0, burst, burst_len),
4417 "Error enqueuing burst");
4419 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4420 0, burst_dequeued, burst_len),
4422 "Error dequeuing burst");
4425 for (i = 0; i < burst_len; i++) {
4427 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4428 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4430 "data not as expected");
4432 rte_pktmbuf_free(burst[i]->sym->m_src);
4433 rte_crypto_op_free(burst[i]);
4436 return TEST_SUCCESS;
4440 create_gmac_operation(enum rte_crypto_auth_operation op,
4441 const struct gmac_test_data *tdata)
4443 struct crypto_testsuite_params *ts_params = &testsuite_params;
4444 struct crypto_unittest_params *ut_params = &unittest_params;
4445 struct rte_crypto_sym_op *sym_op;
4447 unsigned iv_pad_len;
4448 unsigned aad_pad_len;
4450 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
4451 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4453 /* Generate Crypto op data structure */
4454 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4455 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4456 TEST_ASSERT_NOT_NULL(ut_params->op,
4457 "Failed to allocate symmetric crypto operation struct");
4459 sym_op = ut_params->op->sym;
4460 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4462 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4463 "no room to append aad");
4465 sym_op->auth.aad.length = tdata->aad.len;
4466 sym_op->auth.aad.phys_addr =
4467 rte_pktmbuf_mtophys(ut_params->ibuf);
4468 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
4470 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4471 ut_params->ibuf, tdata->gmac_tag.len);
4472 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4473 "no room to append digest");
4475 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4476 ut_params->ibuf, aad_pad_len);
4477 sym_op->auth.digest.length = tdata->gmac_tag.len;
4479 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
4480 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
4481 tdata->gmac_tag.len);
4482 TEST_HEXDUMP(stdout, "digest:",
4483 sym_op->auth.digest.data,
4484 sym_op->auth.digest.length);
4487 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4488 ut_params->ibuf, iv_pad_len);
4489 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4491 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4492 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4493 sym_op->cipher.iv.length = tdata->iv.len;
4495 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
4497 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
4499 sym_op->cipher.data.length = 0;
4500 sym_op->cipher.data.offset = 0;
4502 sym_op->auth.data.offset = 0;
4503 sym_op->auth.data.length = 0;
4508 static int create_gmac_session(uint8_t dev_id,
4509 enum rte_crypto_cipher_operation op,
4510 const struct gmac_test_data *tdata,
4511 enum rte_crypto_auth_operation auth_op)
4513 uint8_t cipher_key[tdata->key.len];
4515 struct crypto_unittest_params *ut_params = &unittest_params;
4517 memcpy(cipher_key, tdata->key.data, tdata->key.len);
4519 /* For GMAC we setup cipher parameters */
4520 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4521 ut_params->cipher_xform.next = NULL;
4522 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4523 ut_params->cipher_xform.cipher.op = op;
4524 ut_params->cipher_xform.cipher.key.data = cipher_key;
4525 ut_params->cipher_xform.cipher.key.length = tdata->key.len;
4527 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4528 ut_params->auth_xform.next = NULL;
4530 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
4531 ut_params->auth_xform.auth.op = auth_op;
4532 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
4533 ut_params->auth_xform.auth.add_auth_data_length = 0;
4534 ut_params->auth_xform.auth.key.length = 0;
4535 ut_params->auth_xform.auth.key.data = NULL;
4537 ut_params->cipher_xform.next = &ut_params->auth_xform;
4539 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4540 &ut_params->cipher_xform);
4542 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4548 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
4550 struct crypto_testsuite_params *ts_params = &testsuite_params;
4551 struct crypto_unittest_params *ut_params = &unittest_params;
4555 uint8_t *auth_tag, *p;
4556 uint16_t aad_pad_len;
4558 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
4559 "No GMAC length in the source data");
4561 retval = create_gmac_session(ts_params->valid_devs[0],
4562 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4563 tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
4568 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4570 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4571 rte_pktmbuf_tailroom(ut_params->ibuf));
4573 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4575 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
4577 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
4583 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4585 ut_params->op->sym->m_src = ut_params->ibuf;
4587 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4588 ut_params->op), "failed to process sym crypto op");
4590 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4591 "crypto op processing failed");
4593 if (ut_params->op->sym->m_dst) {
4594 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4595 uint8_t *, aad_pad_len);
4597 auth_tag = p + aad_pad_len;
4600 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
4602 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4604 tdata->gmac_tag.data,
4605 tdata->gmac_tag.len,
4606 "GMAC Generated auth tag not as expected");
4612 test_AES_GMAC_authentication_test_case_1(void)
4614 return test_AES_GMAC_authentication(&gmac_test_case_1);
4618 test_AES_GMAC_authentication_test_case_2(void)
4620 return test_AES_GMAC_authentication(&gmac_test_case_2);
4624 test_AES_GMAC_authentication_test_case_3(void)
4626 return test_AES_GMAC_authentication(&gmac_test_case_3);
4630 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
4632 struct crypto_testsuite_params *ts_params = &testsuite_params;
4633 struct crypto_unittest_params *ut_params = &unittest_params;
4636 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
4637 "No GMAC length in the source data");
4639 retval = create_gmac_session(ts_params->valid_devs[0],
4640 RTE_CRYPTO_CIPHER_OP_DECRYPT,
4641 tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
4646 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4648 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4649 rte_pktmbuf_tailroom(ut_params->ibuf));
4651 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
4657 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4659 ut_params->op->sym->m_src = ut_params->ibuf;
4661 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4662 ut_params->op), "failed to process sym crypto op");
4664 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4665 "crypto op processing failed");
4672 test_AES_GMAC_authentication_verify_test_case_1(void)
4674 return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
4678 test_AES_GMAC_authentication_verify_test_case_2(void)
4680 return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
4684 test_AES_GMAC_authentication_verify_test_case_3(void)
4686 return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
4689 static struct unit_test_suite cryptodev_qat_testsuite = {
4690 .suite_name = "Crypto QAT Unit Test Suite",
4691 .setup = testsuite_setup,
4692 .teardown = testsuite_teardown,
4693 .unit_test_cases = {
4694 TEST_CASE_ST(ut_setup, ut_teardown,
4695 test_device_configure_invalid_dev_id),
4696 TEST_CASE_ST(ut_setup, ut_teardown,
4697 test_device_configure_invalid_queue_pair_ids),
4698 TEST_CASE_ST(ut_setup, ut_teardown,
4699 test_queue_pair_descriptor_setup),
4700 TEST_CASE_ST(ut_setup, ut_teardown,
4701 test_multi_session),
4703 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
4704 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4706 /** AES GCM Authenticated Encryption */
4707 TEST_CASE_ST(ut_setup, ut_teardown,
4708 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4709 TEST_CASE_ST(ut_setup, ut_teardown,
4710 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4711 TEST_CASE_ST(ut_setup, ut_teardown,
4712 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4713 TEST_CASE_ST(ut_setup, ut_teardown,
4714 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4715 TEST_CASE_ST(ut_setup, ut_teardown,
4716 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4717 TEST_CASE_ST(ut_setup, ut_teardown,
4718 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4719 TEST_CASE_ST(ut_setup, ut_teardown,
4720 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4722 /** AES GCM Authenticated Decryption */
4723 TEST_CASE_ST(ut_setup, ut_teardown,
4724 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4725 TEST_CASE_ST(ut_setup, ut_teardown,
4726 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4727 TEST_CASE_ST(ut_setup, ut_teardown,
4728 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4729 TEST_CASE_ST(ut_setup, ut_teardown,
4730 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4731 TEST_CASE_ST(ut_setup, ut_teardown,
4732 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4733 TEST_CASE_ST(ut_setup, ut_teardown,
4734 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4735 TEST_CASE_ST(ut_setup, ut_teardown,
4736 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4738 /** AES GMAC Authentication */
4739 TEST_CASE_ST(ut_setup, ut_teardown,
4740 test_AES_GMAC_authentication_test_case_1),
4741 TEST_CASE_ST(ut_setup, ut_teardown,
4742 test_AES_GMAC_authentication_verify_test_case_1),
4743 TEST_CASE_ST(ut_setup, ut_teardown,
4744 test_AES_GMAC_authentication_test_case_2),
4745 TEST_CASE_ST(ut_setup, ut_teardown,
4746 test_AES_GMAC_authentication_verify_test_case_2),
4747 TEST_CASE_ST(ut_setup, ut_teardown,
4748 test_AES_GMAC_authentication_test_case_3),
4749 TEST_CASE_ST(ut_setup, ut_teardown,
4750 test_AES_GMAC_authentication_verify_test_case_3),
4752 /** SNOW 3G encrypt only (UEA2) */
4753 TEST_CASE_ST(ut_setup, ut_teardown,
4754 test_snow3g_encryption_test_case_1),
4755 TEST_CASE_ST(ut_setup, ut_teardown,
4756 test_snow3g_encryption_test_case_2),
4757 TEST_CASE_ST(ut_setup, ut_teardown,
4758 test_snow3g_encryption_test_case_3),
4759 TEST_CASE_ST(ut_setup, ut_teardown,
4760 test_snow3g_encryption_test_case_4),
4761 TEST_CASE_ST(ut_setup, ut_teardown,
4762 test_snow3g_encryption_test_case_5),
4764 TEST_CASE_ST(ut_setup, ut_teardown,
4765 test_snow3g_encryption_test_case_1_oop),
4766 TEST_CASE_ST(ut_setup, ut_teardown,
4767 test_snow3g_decryption_test_case_1_oop),
4769 /** SNOW 3G decrypt only (UEA2) */
4770 TEST_CASE_ST(ut_setup, ut_teardown,
4771 test_snow3g_decryption_test_case_1),
4772 TEST_CASE_ST(ut_setup, ut_teardown,
4773 test_snow3g_decryption_test_case_2),
4774 TEST_CASE_ST(ut_setup, ut_teardown,
4775 test_snow3g_decryption_test_case_3),
4776 TEST_CASE_ST(ut_setup, ut_teardown,
4777 test_snow3g_decryption_test_case_4),
4778 TEST_CASE_ST(ut_setup, ut_teardown,
4779 test_snow3g_decryption_test_case_5),
4780 TEST_CASE_ST(ut_setup, ut_teardown,
4781 test_snow3g_hash_generate_test_case_1),
4782 TEST_CASE_ST(ut_setup, ut_teardown,
4783 test_snow3g_hash_generate_test_case_2),
4784 TEST_CASE_ST(ut_setup, ut_teardown,
4785 test_snow3g_hash_generate_test_case_3),
4786 TEST_CASE_ST(ut_setup, ut_teardown,
4787 test_snow3g_hash_verify_test_case_1),
4788 TEST_CASE_ST(ut_setup, ut_teardown,
4789 test_snow3g_hash_verify_test_case_2),
4790 TEST_CASE_ST(ut_setup, ut_teardown,
4791 test_snow3g_hash_verify_test_case_3),
4792 TEST_CASE_ST(ut_setup, ut_teardown,
4793 test_snow3g_cipher_auth_test_case_1),
4794 TEST_CASE_ST(ut_setup, ut_teardown,
4795 test_snow3g_auth_cipher_test_case_1),
4797 /** HMAC_MD5 Authentication */
4798 TEST_CASE_ST(ut_setup, ut_teardown,
4799 test_MD5_HMAC_generate_case_1),
4800 TEST_CASE_ST(ut_setup, ut_teardown,
4801 test_MD5_HMAC_verify_case_1),
4802 TEST_CASE_ST(ut_setup, ut_teardown,
4803 test_MD5_HMAC_generate_case_2),
4804 TEST_CASE_ST(ut_setup, ut_teardown,
4805 test_MD5_HMAC_verify_case_2),
4808 TEST_CASE_ST(ut_setup, ut_teardown,
4809 test_null_auth_only_operation),
4810 TEST_CASE_ST(ut_setup, ut_teardown,
4811 test_null_cipher_only_operation),
4812 TEST_CASE_ST(ut_setup, ut_teardown,
4813 test_null_cipher_auth_operation),
4814 TEST_CASE_ST(ut_setup, ut_teardown,
4815 test_null_auth_cipher_operation),
4817 TEST_CASE_ST(ut_setup, ut_teardown,
4818 test_kasumi_hash_generate_test_case_6),
4821 TEST_CASE_ST(ut_setup, ut_teardown,
4822 test_kasumi_encryption_test_case_1),
4823 TEST_CASE_ST(ut_setup, ut_teardown,
4824 test_kasumi_encryption_test_case_3),
4825 TEST_CASE_ST(ut_setup, ut_teardown,
4826 test_kasumi_auth_cipher_test_case_1),
4827 TEST_CASE_ST(ut_setup, ut_teardown,
4828 test_kasumi_cipher_auth_test_case_1),
4830 TEST_CASES_END() /**< NULL terminate unit test array */
4834 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
4835 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4836 .setup = testsuite_setup,
4837 .teardown = testsuite_teardown,
4838 .unit_test_cases = {
4839 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
4841 TEST_CASES_END() /**< NULL terminate unit test array */
4845 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
4846 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4847 .setup = testsuite_setup,
4848 .teardown = testsuite_teardown,
4849 .unit_test_cases = {
4850 /** AES GCM Authenticated Encryption */
4851 TEST_CASE_ST(ut_setup, ut_teardown,
4852 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4853 TEST_CASE_ST(ut_setup, ut_teardown,
4854 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4855 TEST_CASE_ST(ut_setup, ut_teardown,
4856 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4857 TEST_CASE_ST(ut_setup, ut_teardown,
4858 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4859 TEST_CASE_ST(ut_setup, ut_teardown,
4860 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4861 TEST_CASE_ST(ut_setup, ut_teardown,
4862 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4863 TEST_CASE_ST(ut_setup, ut_teardown,
4864 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4866 /** AES GCM Authenticated Decryption */
4867 TEST_CASE_ST(ut_setup, ut_teardown,
4868 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4869 TEST_CASE_ST(ut_setup, ut_teardown,
4870 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4871 TEST_CASE_ST(ut_setup, ut_teardown,
4872 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4873 TEST_CASE_ST(ut_setup, ut_teardown,
4874 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4875 TEST_CASE_ST(ut_setup, ut_teardown,
4876 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4877 TEST_CASE_ST(ut_setup, ut_teardown,
4878 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4879 TEST_CASE_ST(ut_setup, ut_teardown,
4880 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4882 TEST_CASES_END() /**< NULL terminate unit test array */
4886 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
4887 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4888 .setup = testsuite_setup,
4889 .teardown = testsuite_teardown,
4890 .unit_test_cases = {
4891 /** KASUMI encrypt only (UEA1) */
4892 TEST_CASE_ST(ut_setup, ut_teardown,
4893 test_kasumi_encryption_test_case_1),
4894 TEST_CASE_ST(ut_setup, ut_teardown,
4895 test_kasumi_encryption_test_case_2),
4896 TEST_CASE_ST(ut_setup, ut_teardown,
4897 test_kasumi_encryption_test_case_3),
4898 TEST_CASE_ST(ut_setup, ut_teardown,
4899 test_kasumi_encryption_test_case_4),
4900 TEST_CASE_ST(ut_setup, ut_teardown,
4901 test_kasumi_encryption_test_case_5),
4902 /** KASUMI decrypt only (UEA1) */
4903 TEST_CASE_ST(ut_setup, ut_teardown,
4904 test_kasumi_decryption_test_case_1),
4905 TEST_CASE_ST(ut_setup, ut_teardown,
4906 test_kasumi_decryption_test_case_2),
4907 TEST_CASE_ST(ut_setup, ut_teardown,
4908 test_kasumi_decryption_test_case_3),
4909 TEST_CASE_ST(ut_setup, ut_teardown,
4910 test_kasumi_decryption_test_case_4),
4911 TEST_CASE_ST(ut_setup, ut_teardown,
4912 test_kasumi_decryption_test_case_5),
4914 TEST_CASE_ST(ut_setup, ut_teardown,
4915 test_kasumi_encryption_test_case_1_oop),
4916 TEST_CASE_ST(ut_setup, ut_teardown,
4917 test_kasumi_decryption_test_case_1_oop),
4919 /** KASUMI hash only (UIA1) */
4920 TEST_CASE_ST(ut_setup, ut_teardown,
4921 test_kasumi_hash_generate_test_case_1),
4922 TEST_CASE_ST(ut_setup, ut_teardown,
4923 test_kasumi_hash_generate_test_case_2),
4924 TEST_CASE_ST(ut_setup, ut_teardown,
4925 test_kasumi_hash_generate_test_case_3),
4926 TEST_CASE_ST(ut_setup, ut_teardown,
4927 test_kasumi_hash_generate_test_case_4),
4928 TEST_CASE_ST(ut_setup, ut_teardown,
4929 test_kasumi_hash_generate_test_case_5),
4930 TEST_CASE_ST(ut_setup, ut_teardown,
4931 test_kasumi_hash_generate_test_case_6),
4932 TEST_CASE_ST(ut_setup, ut_teardown,
4933 test_kasumi_hash_verify_test_case_1),
4934 TEST_CASE_ST(ut_setup, ut_teardown,
4935 test_kasumi_hash_verify_test_case_2),
4936 TEST_CASE_ST(ut_setup, ut_teardown,
4937 test_kasumi_hash_verify_test_case_3),
4938 TEST_CASE_ST(ut_setup, ut_teardown,
4939 test_kasumi_hash_verify_test_case_4),
4940 TEST_CASE_ST(ut_setup, ut_teardown,
4941 test_kasumi_hash_verify_test_case_5),
4942 TEST_CASE_ST(ut_setup, ut_teardown,
4943 test_kasumi_auth_cipher_test_case_1),
4944 TEST_CASE_ST(ut_setup, ut_teardown,
4945 test_kasumi_cipher_auth_test_case_1),
4946 TEST_CASES_END() /**< NULL terminate unit test array */
4949 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4950 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
4951 .setup = testsuite_setup,
4952 .teardown = testsuite_teardown,
4953 .unit_test_cases = {
4954 /** SNOW 3G encrypt only (UEA2) */
4955 TEST_CASE_ST(ut_setup, ut_teardown,
4956 test_snow3g_encryption_test_case_1),
4957 TEST_CASE_ST(ut_setup, ut_teardown,
4958 test_snow3g_encryption_test_case_2),
4959 TEST_CASE_ST(ut_setup, ut_teardown,
4960 test_snow3g_encryption_test_case_3),
4961 TEST_CASE_ST(ut_setup, ut_teardown,
4962 test_snow3g_encryption_test_case_4),
4963 TEST_CASE_ST(ut_setup, ut_teardown,
4964 test_snow3g_encryption_test_case_5),
4966 TEST_CASE_ST(ut_setup, ut_teardown,
4967 test_snow3g_encryption_test_case_1_oop),
4968 TEST_CASE_ST(ut_setup, ut_teardown,
4969 test_snow3g_decryption_test_case_1_oop),
4971 TEST_CASE_ST(ut_setup, ut_teardown,
4972 test_snow3g_encryption_test_case_1_offset_oop),
4974 /** SNOW 3G decrypt only (UEA2) */
4975 TEST_CASE_ST(ut_setup, ut_teardown,
4976 test_snow3g_decryption_test_case_1),
4977 TEST_CASE_ST(ut_setup, ut_teardown,
4978 test_snow3g_decryption_test_case_2),
4979 TEST_CASE_ST(ut_setup, ut_teardown,
4980 test_snow3g_decryption_test_case_3),
4981 TEST_CASE_ST(ut_setup, ut_teardown,
4982 test_snow3g_decryption_test_case_4),
4983 TEST_CASE_ST(ut_setup, ut_teardown,
4984 test_snow3g_decryption_test_case_5),
4985 TEST_CASE_ST(ut_setup, ut_teardown,
4986 test_snow3g_hash_generate_test_case_1),
4987 TEST_CASE_ST(ut_setup, ut_teardown,
4988 test_snow3g_hash_generate_test_case_2),
4989 TEST_CASE_ST(ut_setup, ut_teardown,
4990 test_snow3g_hash_generate_test_case_3),
4991 /* Tests with buffers which length is not byte-aligned */
4992 TEST_CASE_ST(ut_setup, ut_teardown,
4993 test_snow3g_hash_generate_test_case_4),
4994 TEST_CASE_ST(ut_setup, ut_teardown,
4995 test_snow3g_hash_generate_test_case_5),
4996 TEST_CASE_ST(ut_setup, ut_teardown,
4997 test_snow3g_hash_generate_test_case_6),
4998 TEST_CASE_ST(ut_setup, ut_teardown,
4999 test_snow3g_hash_verify_test_case_1),
5000 TEST_CASE_ST(ut_setup, ut_teardown,
5001 test_snow3g_hash_verify_test_case_2),
5002 TEST_CASE_ST(ut_setup, ut_teardown,
5003 test_snow3g_hash_verify_test_case_3),
5004 /* Tests with buffers which length is not byte-aligned */
5005 TEST_CASE_ST(ut_setup, ut_teardown,
5006 test_snow3g_hash_verify_test_case_4),
5007 TEST_CASE_ST(ut_setup, ut_teardown,
5008 test_snow3g_hash_verify_test_case_5),
5009 TEST_CASE_ST(ut_setup, ut_teardown,
5010 test_snow3g_hash_verify_test_case_6),
5011 TEST_CASE_ST(ut_setup, ut_teardown,
5012 test_snow3g_cipher_auth_test_case_1),
5013 TEST_CASE_ST(ut_setup, ut_teardown,
5014 test_snow3g_auth_cipher_test_case_1),
5016 TEST_CASES_END() /**< NULL terminate unit test array */
5020 static struct unit_test_suite cryptodev_sw_zuc_testsuite = {
5021 .suite_name = "Crypto Device SW ZUC Unit Test Suite",
5022 .setup = testsuite_setup,
5023 .teardown = testsuite_teardown,
5024 .unit_test_cases = {
5025 /** ZUC encrypt only (EEA3) */
5026 TEST_CASE_ST(ut_setup, ut_teardown,
5027 test_zuc_encryption_test_case_1),
5028 TEST_CASE_ST(ut_setup, ut_teardown,
5029 test_zuc_encryption_test_case_2),
5030 TEST_CASE_ST(ut_setup, ut_teardown,
5031 test_zuc_encryption_test_case_3),
5032 TEST_CASE_ST(ut_setup, ut_teardown,
5033 test_zuc_encryption_test_case_4),
5034 TEST_CASE_ST(ut_setup, ut_teardown,
5035 test_zuc_encryption_test_case_5),
5036 TEST_CASE_ST(ut_setup, ut_teardown,
5037 test_zuc_hash_generate_test_case_1),
5038 TEST_CASE_ST(ut_setup, ut_teardown,
5039 test_zuc_hash_generate_test_case_2),
5040 TEST_CASE_ST(ut_setup, ut_teardown,
5041 test_zuc_hash_generate_test_case_3),
5042 TEST_CASE_ST(ut_setup, ut_teardown,
5043 test_zuc_hash_generate_test_case_4),
5044 TEST_CASE_ST(ut_setup, ut_teardown,
5045 test_zuc_hash_generate_test_case_5),
5046 TEST_CASES_END() /**< NULL terminate unit test array */
5050 static struct unit_test_suite cryptodev_null_testsuite = {
5051 .suite_name = "Crypto Device NULL Unit Test Suite",
5052 .setup = testsuite_setup,
5053 .teardown = testsuite_teardown,
5054 .unit_test_cases = {
5055 TEST_CASE_ST(ut_setup, ut_teardown,
5056 test_null_auth_only_operation),
5057 TEST_CASE_ST(ut_setup, ut_teardown,
5058 test_null_cipher_only_operation),
5059 TEST_CASE_ST(ut_setup, ut_teardown,
5060 test_null_cipher_auth_operation),
5061 TEST_CASE_ST(ut_setup, ut_teardown,
5062 test_null_auth_cipher_operation),
5063 TEST_CASE_ST(ut_setup, ut_teardown,
5064 test_null_invalid_operation),
5065 TEST_CASE_ST(ut_setup, ut_teardown,
5066 test_null_burst_operation),
5068 TEST_CASES_END() /**< NULL terminate unit test array */
5073 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
5075 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
5076 return unit_test_suite_runner(&cryptodev_qat_testsuite);
5080 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
5082 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
5084 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
5088 test_cryptodev_aesni_gcm(void)
5090 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
5092 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
5096 test_cryptodev_null(void)
5098 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
5100 return unit_test_suite_runner(&cryptodev_null_testsuite);
5104 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
5106 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
5108 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
5112 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
5114 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
5116 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
5120 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
5122 gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
5124 return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
5127 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
5128 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
5129 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
5130 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
5131 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
5132 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
5133 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);