4 * Copyright(c) 2015-2017 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>
38 #include <rte_pause.h>
40 #include <rte_crypto.h>
41 #include <rte_cryptodev.h>
42 #include <rte_cryptodev_pmd.h>
44 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
45 #include <rte_cryptodev_scheduler.h>
46 #include <rte_cryptodev_scheduler_operations.h>
50 #include "test_cryptodev.h"
52 #include "test_cryptodev_blockcipher.h"
53 #include "test_cryptodev_aes_test_vectors.h"
54 #include "test_cryptodev_des_test_vectors.h"
55 #include "test_cryptodev_hash_test_vectors.h"
56 #include "test_cryptodev_kasumi_test_vectors.h"
57 #include "test_cryptodev_kasumi_hash_test_vectors.h"
58 #include "test_cryptodev_snow3g_test_vectors.h"
59 #include "test_cryptodev_snow3g_hash_test_vectors.h"
60 #include "test_cryptodev_zuc_test_vectors.h"
61 #include "test_cryptodev_gcm_test_vectors.h"
62 #include "test_cryptodev_hmac_test_vectors.h"
64 static enum rte_cryptodev_type gbl_cryptodev_type;
66 struct crypto_testsuite_params {
67 struct rte_mempool *mbuf_pool;
68 struct rte_mempool *large_mbuf_pool;
69 struct rte_mempool *op_mpool;
70 struct rte_cryptodev_config conf;
71 struct rte_cryptodev_qp_conf qp_conf;
73 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
74 uint8_t valid_dev_count;
77 struct crypto_unittest_params {
78 struct rte_crypto_sym_xform cipher_xform;
79 struct rte_crypto_sym_xform auth_xform;
81 struct rte_cryptodev_sym_session *sess;
83 struct rte_crypto_op *op;
85 struct rte_mbuf *obuf, *ibuf;
90 #define ALIGN_POW2_ROUNDUP(num, align) \
91 (((num) + (align) - 1) & ~((align) - 1))
94 * Forward declarations.
97 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
98 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
102 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
103 struct crypto_unittest_params *ut_params,
104 struct crypto_testsuite_params *ts_param,
105 const uint8_t *cipher,
106 const uint8_t *digest,
109 static struct rte_mbuf *
110 setup_test_string(struct rte_mempool *mpool,
111 const char *string, size_t len, uint8_t blocksize)
113 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
114 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
116 memset(m->buf_addr, 0, m->buf_len);
118 char *dst = rte_pktmbuf_append(m, t_len);
125 rte_memcpy(dst, string, t_len);
127 memset(dst, 0, t_len);
133 /* Get number of bytes in X bits (rounding up) */
135 ceil_byte_length(uint32_t num_bits)
138 return ((num_bits >> 3) + 1);
140 return (num_bits >> 3);
143 static struct rte_crypto_op *
144 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
146 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
147 printf("Error sending packet for encryption");
153 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
159 static struct crypto_testsuite_params testsuite_params = { NULL };
160 static struct crypto_unittest_params unittest_params;
163 testsuite_setup(void)
165 struct crypto_testsuite_params *ts_params = &testsuite_params;
166 struct rte_cryptodev_info info;
167 uint32_t i = 0, nb_devs, dev_id;
171 memset(ts_params, 0, sizeof(*ts_params));
173 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
174 if (ts_params->mbuf_pool == NULL) {
175 /* Not already created so create */
176 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
178 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
180 if (ts_params->mbuf_pool == NULL) {
181 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
186 ts_params->large_mbuf_pool = rte_mempool_lookup(
187 "CRYPTO_LARGE_MBUFPOOL");
188 if (ts_params->large_mbuf_pool == NULL) {
189 /* Not already created so create */
190 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
191 "CRYPTO_LARGE_MBUFPOOL",
194 if (ts_params->large_mbuf_pool == NULL) {
196 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
201 ts_params->op_mpool = rte_crypto_op_pool_create(
202 "MBUF_CRYPTO_SYM_OP_POOL",
203 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
204 NUM_MBUFS, MBUF_CACHE_SIZE,
206 sizeof(struct rte_crypto_sym_xform),
208 if (ts_params->op_mpool == NULL) {
209 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
213 /* Create an AESNI MB device if required */
214 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
215 #ifndef RTE_LIBRTE_PMD_AESNI_MB
216 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
217 " enabled in config file to run this testsuite.\n");
220 nb_devs = rte_cryptodev_count_devtype(
221 RTE_CRYPTODEV_AESNI_MB_PMD);
224 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
226 TEST_ASSERT(ret == 0,
227 "Failed to create instance of"
229 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
233 /* Create an AESNI GCM device if required */
234 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
235 #ifndef RTE_LIBRTE_PMD_AESNI_GCM
236 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be"
237 " enabled in config file to run this testsuite.\n");
240 nb_devs = rte_cryptodev_count_devtype(
241 RTE_CRYPTODEV_AESNI_GCM_PMD);
243 TEST_ASSERT_SUCCESS(rte_vdev_init(
244 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
245 "Failed to create instance of"
247 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
251 /* Create a SNOW 3G device if required */
252 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
253 #ifndef RTE_LIBRTE_PMD_SNOW3G
254 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be"
255 " enabled in config file to run this testsuite.\n");
258 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
260 TEST_ASSERT_SUCCESS(rte_vdev_init(
261 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
262 "Failed to create instance of"
264 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
268 /* Create a KASUMI device if required */
269 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
270 #ifndef RTE_LIBRTE_PMD_KASUMI
271 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be"
272 " enabled in config file to run this testsuite.\n");
275 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
277 TEST_ASSERT_SUCCESS(rte_vdev_init(
278 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
279 "Failed to create instance of"
281 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
285 /* Create a ZUC device if required */
286 if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) {
287 #ifndef RTE_LIBRTE_PMD_ZUC
288 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be"
289 " enabled in config file to run this testsuite.\n");
292 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD);
294 TEST_ASSERT_SUCCESS(rte_vdev_init(
295 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
296 "Failed to create instance of"
298 RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
302 /* Create a NULL device if required */
303 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
304 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO
305 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be"
306 " enabled in config file to run this testsuite.\n");
309 nb_devs = rte_cryptodev_count_devtype(
310 RTE_CRYPTODEV_NULL_PMD);
313 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
315 TEST_ASSERT(ret == 0,
316 "Failed to create instance of"
318 RTE_STR(CRYPTODEV_NAME_NULL_PMD));
322 /* Create an OPENSSL device if required */
323 if (gbl_cryptodev_type == RTE_CRYPTODEV_OPENSSL_PMD) {
324 #ifndef RTE_LIBRTE_PMD_OPENSSL
325 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_OPENSSL must be"
326 " enabled in config file to run this testsuite.\n");
329 nb_devs = rte_cryptodev_count_devtype(
330 RTE_CRYPTODEV_OPENSSL_PMD);
333 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
336 TEST_ASSERT(ret == 0, "Failed to create "
337 "instance of pmd : %s",
338 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
342 /* Create a ARMv8 device if required */
343 if (gbl_cryptodev_type == RTE_CRYPTODEV_ARMV8_PMD) {
344 #ifndef RTE_LIBRTE_PMD_ARMV8_CRYPTO
345 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ARMV8_CRYPTO must be"
346 " enabled in config file to run this testsuite.\n");
349 nb_devs = rte_cryptodev_count_devtype(
350 RTE_CRYPTODEV_ARMV8_PMD);
353 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD),
356 TEST_ASSERT(ret == 0, "Failed to create "
357 "instance of pmd : %s",
358 RTE_STR(CRYPTODEV_NAME_ARMV8_PMD));
362 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
363 if (gbl_cryptodev_type == RTE_CRYPTODEV_SCHEDULER_PMD) {
365 #ifndef RTE_LIBRTE_PMD_AESNI_MB
366 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
367 " enabled in config file to run this testsuite.\n");
370 nb_devs = rte_cryptodev_count_devtype(
371 RTE_CRYPTODEV_SCHEDULER_PMD);
374 RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD),
377 TEST_ASSERT(ret == 0,
378 "Failed to create instance %u of"
380 i, RTE_STR(CRYPTODEV_NAME_SCHEDULER_PMD));
383 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
385 #ifndef RTE_LIBRTE_PMD_QAT
386 if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) {
387 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled "
388 "in config file to run this testsuite.\n");
393 nb_devs = rte_cryptodev_count();
395 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
399 /* Create list of valid crypto devs */
400 for (i = 0; i < nb_devs; i++) {
401 rte_cryptodev_info_get(i, &info);
402 if (info.dev_type == gbl_cryptodev_type)
403 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
406 if (ts_params->valid_dev_count < 1)
409 /* Set up all the qps on the first of the valid devices found */
411 dev_id = ts_params->valid_devs[0];
413 rte_cryptodev_info_get(dev_id, &info);
415 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
416 ts_params->conf.socket_id = SOCKET_ID_ANY;
417 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
419 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
421 "Failed to configure cryptodev %u with %u qps",
422 dev_id, ts_params->conf.nb_queue_pairs);
424 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
426 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
427 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
428 dev_id, qp_id, &ts_params->qp_conf,
429 rte_cryptodev_socket_id(dev_id)),
430 "Failed to setup queue pair %u on cryptodev %u",
438 testsuite_teardown(void)
440 struct crypto_testsuite_params *ts_params = &testsuite_params;
442 if (ts_params->mbuf_pool != NULL) {
443 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
444 rte_mempool_avail_count(ts_params->mbuf_pool));
447 if (ts_params->op_mpool != NULL) {
448 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
449 rte_mempool_avail_count(ts_params->op_mpool));
457 struct crypto_testsuite_params *ts_params = &testsuite_params;
458 struct crypto_unittest_params *ut_params = &unittest_params;
462 /* Clear unit test parameters before running test */
463 memset(ut_params, 0, sizeof(*ut_params));
465 /* Reconfigure device to default parameters */
466 ts_params->conf.socket_id = SOCKET_ID_ANY;
467 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT;
469 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
471 "Failed to configure cryptodev %u",
472 ts_params->valid_devs[0]);
474 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
475 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
476 ts_params->valid_devs[0], qp_id,
478 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
479 "Failed to setup queue pair %u on cryptodev %u",
480 qp_id, ts_params->valid_devs[0]);
484 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
486 /* Start the device */
487 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
488 "Failed to start cryptodev %u",
489 ts_params->valid_devs[0]);
497 struct crypto_testsuite_params *ts_params = &testsuite_params;
498 struct crypto_unittest_params *ut_params = &unittest_params;
499 struct rte_cryptodev_stats stats;
501 /* free crypto session structure */
502 if (ut_params->sess) {
503 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
505 ut_params->sess = NULL;
508 /* free crypto operation structure */
510 rte_crypto_op_free(ut_params->op);
513 * free mbuf - both obuf and ibuf are usually the same,
514 * so check if they point at the same address is necessary,
515 * to avoid freeing the mbuf twice.
517 if (ut_params->obuf) {
518 rte_pktmbuf_free(ut_params->obuf);
519 if (ut_params->ibuf == ut_params->obuf)
523 if (ut_params->ibuf) {
524 rte_pktmbuf_free(ut_params->ibuf);
528 if (ts_params->mbuf_pool != NULL)
529 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
530 rte_mempool_avail_count(ts_params->mbuf_pool));
532 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
534 /* Stop the device */
535 rte_cryptodev_stop(ts_params->valid_devs[0]);
539 test_device_configure_invalid_dev_id(void)
541 struct crypto_testsuite_params *ts_params = &testsuite_params;
542 uint16_t dev_id, num_devs = 0;
544 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
545 "Need at least %d devices for test", 1);
547 /* valid dev_id values */
548 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
550 /* Stop the device in case it's started so it can be configured */
551 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
553 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
554 "Failed test for rte_cryptodev_configure: "
555 "invalid dev_num %u", dev_id);
557 /* invalid dev_id values */
560 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
561 "Failed test for rte_cryptodev_configure: "
562 "invalid dev_num %u", dev_id);
566 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
567 "Failed test for rte_cryptodev_configure:"
568 "invalid dev_num %u", dev_id);
574 test_device_configure_invalid_queue_pair_ids(void)
576 struct crypto_testsuite_params *ts_params = &testsuite_params;
577 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
579 /* Stop the device in case it's started so it can be configured */
580 rte_cryptodev_stop(ts_params->valid_devs[0]);
582 /* valid - one queue pairs */
583 ts_params->conf.nb_queue_pairs = 1;
585 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
587 "Failed to configure cryptodev: dev_id %u, qp_id %u",
588 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
591 /* valid - max value queue pairs */
592 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
594 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
596 "Failed to configure cryptodev: dev_id %u, qp_id %u",
597 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
600 /* invalid - zero queue pairs */
601 ts_params->conf.nb_queue_pairs = 0;
603 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
605 "Failed test for rte_cryptodev_configure, dev_id %u,"
607 ts_params->valid_devs[0],
608 ts_params->conf.nb_queue_pairs);
611 /* invalid - max value supported by field queue pairs */
612 ts_params->conf.nb_queue_pairs = UINT16_MAX;
614 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
616 "Failed test for rte_cryptodev_configure, dev_id %u,"
618 ts_params->valid_devs[0],
619 ts_params->conf.nb_queue_pairs);
622 /* invalid - max value + 1 queue pairs */
623 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
625 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
627 "Failed test for rte_cryptodev_configure, dev_id %u,"
629 ts_params->valid_devs[0],
630 ts_params->conf.nb_queue_pairs);
632 /* revert to original testsuite value */
633 ts_params->conf.nb_queue_pairs = orig_nb_qps;
639 test_queue_pair_descriptor_setup(void)
641 struct crypto_testsuite_params *ts_params = &testsuite_params;
642 struct rte_cryptodev_info dev_info;
643 struct rte_cryptodev_qp_conf qp_conf = {
644 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
649 /* Stop the device in case it's started so it can be configured */
650 rte_cryptodev_stop(ts_params->valid_devs[0]);
653 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
655 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
657 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
658 &ts_params->conf), "Failed to configure cryptodev %u",
659 ts_params->valid_devs[0]);
663 * Test various ring sizes on this device. memzones can't be
664 * freed so are re-used if ring is released and re-created.
666 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
668 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
669 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
670 ts_params->valid_devs[0], qp_id, &qp_conf,
671 rte_cryptodev_socket_id(
672 ts_params->valid_devs[0])),
674 "rte_cryptodev_queue_pair_setup: num_inflights "
675 "%u on qp %u on cryptodev %u",
676 qp_conf.nb_descriptors, qp_id,
677 ts_params->valid_devs[0]);
680 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
682 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
683 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
684 ts_params->valid_devs[0], qp_id, &qp_conf,
685 rte_cryptodev_socket_id(
686 ts_params->valid_devs[0])),
688 " rte_cryptodev_queue_pair_setup: num_inflights"
689 " %u on qp %u on cryptodev %u",
690 qp_conf.nb_descriptors, qp_id,
691 ts_params->valid_devs[0]);
694 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
696 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
697 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
698 ts_params->valid_devs[0], qp_id, &qp_conf,
699 rte_cryptodev_socket_id(
700 ts_params->valid_devs[0])),
702 "rte_cryptodev_queue_pair_setup: num_inflights"
703 " %u on qp %u on cryptodev %u",
704 qp_conf.nb_descriptors, qp_id,
705 ts_params->valid_devs[0]);
708 /* invalid number of descriptors - max supported + 2 */
709 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
711 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
712 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
713 ts_params->valid_devs[0], qp_id, &qp_conf,
714 rte_cryptodev_socket_id(
715 ts_params->valid_devs[0])),
716 "Unexpectedly passed test for "
717 "rte_cryptodev_queue_pair_setup:"
718 "num_inflights %u on qp %u on cryptodev %u",
719 qp_conf.nb_descriptors, qp_id,
720 ts_params->valid_devs[0]);
723 /* invalid number of descriptors - max value of parameter */
724 qp_conf.nb_descriptors = UINT32_MAX-1;
726 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
727 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
728 ts_params->valid_devs[0], qp_id, &qp_conf,
729 rte_cryptodev_socket_id(
730 ts_params->valid_devs[0])),
731 "Unexpectedly passed test for "
732 "rte_cryptodev_queue_pair_setup:"
733 "num_inflights %u on qp %u on cryptodev %u",
734 qp_conf.nb_descriptors, qp_id,
735 ts_params->valid_devs[0]);
738 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
740 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
741 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
742 ts_params->valid_devs[0], qp_id, &qp_conf,
743 rte_cryptodev_socket_id(
744 ts_params->valid_devs[0])),
746 " rte_cryptodev_queue_pair_setup:"
747 "num_inflights %u on qp %u on cryptodev %u",
748 qp_conf.nb_descriptors, qp_id,
749 ts_params->valid_devs[0]);
752 /* invalid number of descriptors - max supported + 1 */
753 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
755 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
756 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
757 ts_params->valid_devs[0], qp_id, &qp_conf,
758 rte_cryptodev_socket_id(
759 ts_params->valid_devs[0])),
760 "Unexpectedly passed test for "
761 "rte_cryptodev_queue_pair_setup:"
762 "num_inflights %u on qp %u on cryptodev %u",
763 qp_conf.nb_descriptors, qp_id,
764 ts_params->valid_devs[0]);
767 /* test invalid queue pair id */
768 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
770 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
772 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
773 ts_params->valid_devs[0],
775 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
776 "Failed test for rte_cryptodev_queue_pair_setup:"
777 "invalid qp %u on cryptodev %u",
778 qp_id, ts_params->valid_devs[0]);
780 qp_id = 0xffff; /*invalid*/
782 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
783 ts_params->valid_devs[0],
785 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
786 "Failed test for rte_cryptodev_queue_pair_setup:"
787 "invalid qp %u on cryptodev %u",
788 qp_id, ts_params->valid_devs[0]);
793 /* ***** Plaintext data for tests ***** */
795 const char catch_22_quote_1[] =
796 "There was only one catch and that was Catch-22, which "
797 "specified that a concern for one's safety in the face of "
798 "dangers that were real and immediate was the process of a "
799 "rational mind. Orr was crazy and could be grounded. All he "
800 "had to do was ask; and as soon as he did, he would no longer "
801 "be crazy and would have to fly more missions. Orr would be "
802 "crazy to fly more missions and sane if he didn't, but if he "
803 "was sane he had to fly them. If he flew them he was crazy "
804 "and didn't have to; but if he didn't want to he was sane and "
805 "had to. Yossarian was moved very deeply by the absolute "
806 "simplicity of this clause of Catch-22 and let out a "
807 "respectful whistle. \"That's some catch, that Catch-22\", he "
808 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
810 const char catch_22_quote[] =
811 "What a lousy earth! He wondered how many people were "
812 "destitute that same night even in his own prosperous country, "
813 "how many homes were shanties, how many husbands were drunk "
814 "and wives socked, and how many children were bullied, abused, "
815 "or abandoned. How many families hungered for food they could "
816 "not afford to buy? How many hearts were broken? How many "
817 "suicides would take place that same night, how many people "
818 "would go insane? How many cockroaches and landlords would "
819 "triumph? How many winners were losers, successes failures, "
820 "and rich men poor men? How many wise guys were stupid? How "
821 "many happy endings were unhappy endings? How many honest men "
822 "were liars, brave men cowards, loyal men traitors, how many "
823 "sainted men were corrupt, how many people in positions of "
824 "trust had sold their souls to bodyguards, how many had never "
825 "had souls? How many straight-and-narrow paths were crooked "
826 "paths? How many best families were worst families and how "
827 "many good people were bad people? When you added them all up "
828 "and then subtracted, you might be left with only the children, "
829 "and perhaps with Albert Einstein and an old violinist or "
830 "sculptor somewhere.";
832 #define QUOTE_480_BYTES (480)
833 #define QUOTE_512_BYTES (512)
834 #define QUOTE_768_BYTES (768)
835 #define QUOTE_1024_BYTES (1024)
839 /* ***** SHA1 Hash Tests ***** */
841 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
843 static uint8_t hmac_sha1_key[] = {
844 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
845 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
846 0xDE, 0xF4, 0xDE, 0xAD };
848 /* ***** SHA224 Hash Tests ***** */
850 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
853 /* ***** AES-CBC Cipher Tests ***** */
855 #define CIPHER_KEY_LENGTH_AES_CBC (16)
856 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
858 static uint8_t aes_cbc_key[] = {
859 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
860 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
862 static uint8_t aes_cbc_iv[] = {
863 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
864 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
867 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
869 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
870 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
871 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
872 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
873 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
874 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
875 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
876 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
877 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
878 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
879 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
880 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
881 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
882 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
883 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
884 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
885 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
886 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
887 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
888 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
889 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
890 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
891 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
892 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
893 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
894 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
895 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
896 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
897 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
898 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
899 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
900 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
901 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
902 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
903 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
904 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
905 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
906 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
907 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
908 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
909 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
910 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
911 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
912 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
913 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
914 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
915 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
916 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
917 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
918 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
919 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
920 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
921 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
922 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
923 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
924 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
925 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
926 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
927 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
928 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
929 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
930 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
931 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
932 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
933 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
936 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
937 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
938 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
939 0x18, 0x8c, 0x1d, 0x32
943 /* Multisession Vector context Test */
945 static uint8_t ms_aes_cbc_key0[] = {
946 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
947 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
950 static uint8_t ms_aes_cbc_iv0[] = {
951 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
952 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
955 static const uint8_t ms_aes_cbc_cipher0[] = {
956 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
957 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
958 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
959 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
960 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
961 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
962 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
963 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
964 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
965 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
966 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
967 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
968 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
969 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
970 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
971 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
972 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
973 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
974 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
975 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
976 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
977 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
978 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
979 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
980 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
981 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
982 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
983 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
984 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
985 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
986 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
987 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
988 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
989 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
990 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
991 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
992 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
993 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
994 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
995 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
996 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
997 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
998 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
999 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
1000 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
1001 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
1002 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
1003 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
1004 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
1005 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
1006 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
1007 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
1008 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
1009 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
1010 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
1011 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
1012 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
1013 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
1014 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
1015 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
1016 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
1017 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
1018 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
1019 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
1023 static uint8_t ms_hmac_key0[] = {
1024 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1025 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1026 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1027 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1028 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1029 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1030 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1031 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1034 static const uint8_t ms_hmac_digest0[] = {
1035 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1036 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1037 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1038 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1039 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1040 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1041 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1042 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1046 /* Begin session 1 */
1048 static uint8_t ms_aes_cbc_key1[] = {
1049 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1050 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1053 static uint8_t ms_aes_cbc_iv1[] = {
1054 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1055 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1058 static const uint8_t ms_aes_cbc_cipher1[] = {
1059 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1060 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1061 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1062 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1063 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1064 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1065 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1066 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1067 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1068 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1069 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1070 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1071 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1072 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1073 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1074 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1075 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1076 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1077 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1078 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1079 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1080 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1081 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1082 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1083 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1084 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1085 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1086 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1087 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1088 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1089 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1090 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1091 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1092 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1093 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1094 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1095 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1096 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1097 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1098 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1099 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1100 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1101 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1102 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1103 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1104 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1105 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1106 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1107 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1108 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1109 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1110 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1111 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1112 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1113 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1114 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1115 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1116 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1117 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1118 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1119 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1120 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1121 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1122 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1126 static uint8_t ms_hmac_key1[] = {
1127 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1128 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1129 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1130 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1131 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1132 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1133 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1134 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1137 static const uint8_t ms_hmac_digest1[] = {
1138 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1139 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1140 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1141 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1142 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1143 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1144 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1145 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1148 /* Begin Session 2 */
1149 static uint8_t ms_aes_cbc_key2[] = {
1150 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1151 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1154 static uint8_t ms_aes_cbc_iv2[] = {
1155 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1156 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1159 static const uint8_t ms_aes_cbc_cipher2[] = {
1160 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1161 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1162 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1163 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1164 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1165 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1166 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1167 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1168 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1169 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1170 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1171 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1172 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1173 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1174 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1175 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1176 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1177 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1178 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1179 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1180 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1181 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1182 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1183 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1184 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1185 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1186 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1187 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1188 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1189 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1190 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1191 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1192 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1193 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1194 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1195 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1196 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1197 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1198 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1199 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1200 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1201 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1202 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1203 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1204 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1205 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1206 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1207 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1208 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1209 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1210 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1211 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1212 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1213 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1214 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1215 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1216 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1217 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1218 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1219 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1220 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1221 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1222 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1223 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1226 static uint8_t ms_hmac_key2[] = {
1227 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1228 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1229 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1230 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1231 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1232 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1233 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1234 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1237 static const uint8_t ms_hmac_digest2[] = {
1238 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1239 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1240 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1241 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1242 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1243 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1244 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1245 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1252 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1254 struct crypto_testsuite_params *ts_params = &testsuite_params;
1255 struct crypto_unittest_params *ut_params = &unittest_params;
1257 /* Generate test mbuf data and space for digest */
1258 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1259 catch_22_quote, QUOTE_512_BYTES, 0);
1261 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1262 DIGEST_BYTE_LENGTH_SHA1);
1263 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1265 /* Setup Cipher Parameters */
1266 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1267 ut_params->cipher_xform.next = &ut_params->auth_xform;
1269 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1270 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1271 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1272 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1274 /* Setup HMAC Parameters */
1275 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1277 ut_params->auth_xform.next = NULL;
1279 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1280 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1281 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1282 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1283 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1285 /* Create crypto session*/
1286 ut_params->sess = rte_cryptodev_sym_session_create(
1287 ts_params->valid_devs[0],
1288 &ut_params->cipher_xform);
1289 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1291 /* Generate crypto op data structure */
1292 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1293 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1294 TEST_ASSERT_NOT_NULL(ut_params->op,
1295 "Failed to allocate symmetric crypto operation struct");
1297 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1299 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1301 /* set crypto operation source mbuf */
1302 sym_op->m_src = ut_params->ibuf;
1304 /* Set crypto operation authentication parameters */
1305 sym_op->auth.digest.data = ut_params->digest;
1306 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1307 ut_params->ibuf, QUOTE_512_BYTES);
1308 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1310 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1311 sym_op->auth.data.length = QUOTE_512_BYTES;
1313 /* Set crypto operation cipher parameters */
1314 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1315 CIPHER_IV_LENGTH_AES_CBC);
1316 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1317 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1319 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1320 CIPHER_IV_LENGTH_AES_CBC);
1322 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1323 sym_op->cipher.data.length = QUOTE_512_BYTES;
1325 /* Process crypto operation */
1326 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1327 ut_params->op), "failed to process sym crypto op");
1329 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1330 "crypto op processing failed");
1333 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1334 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
1336 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1337 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1339 "ciphertext data not as expected");
1341 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1343 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1344 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1345 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1346 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1347 DIGEST_BYTE_LENGTH_SHA1,
1348 "Generated digest data not as expected");
1350 return TEST_SUCCESS;
1353 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1355 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1357 static uint8_t hmac_sha512_key[] = {
1358 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1359 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1360 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1361 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1362 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1363 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1364 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1365 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1367 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1368 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1369 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1370 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1371 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1372 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1373 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1374 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1375 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1380 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1381 struct crypto_unittest_params *ut_params,
1382 uint8_t *cipher_key,
1386 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1387 struct crypto_unittest_params *ut_params,
1388 struct crypto_testsuite_params *ts_params,
1389 const uint8_t *cipher,
1390 const uint8_t *digest,
1395 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1396 struct crypto_unittest_params *ut_params,
1397 uint8_t *cipher_key,
1401 /* Setup Cipher Parameters */
1402 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1403 ut_params->cipher_xform.next = NULL;
1405 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1406 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1407 ut_params->cipher_xform.cipher.key.data = cipher_key;
1408 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1410 /* Setup HMAC Parameters */
1411 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1412 ut_params->auth_xform.next = &ut_params->cipher_xform;
1414 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1415 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1416 ut_params->auth_xform.auth.key.data = hmac_key;
1417 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1418 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1420 return TEST_SUCCESS;
1425 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1426 struct crypto_unittest_params *ut_params,
1427 struct crypto_testsuite_params *ts_params,
1428 const uint8_t *cipher,
1429 const uint8_t *digest,
1432 /* Generate test mbuf data and digest */
1433 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1436 QUOTE_512_BYTES, 0);
1438 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1439 DIGEST_BYTE_LENGTH_SHA512);
1440 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1442 rte_memcpy(ut_params->digest,
1444 DIGEST_BYTE_LENGTH_SHA512);
1446 /* Generate Crypto op data structure */
1447 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1448 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1449 TEST_ASSERT_NOT_NULL(ut_params->op,
1450 "Failed to allocate symmetric crypto operation struct");
1452 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1454 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1456 /* set crypto operation source mbuf */
1457 sym_op->m_src = ut_params->ibuf;
1459 sym_op->auth.digest.data = ut_params->digest;
1460 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1461 ut_params->ibuf, QUOTE_512_BYTES);
1462 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1464 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1465 sym_op->auth.data.length = QUOTE_512_BYTES;
1467 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1468 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1469 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1470 ut_params->ibuf, 0);
1471 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1473 rte_memcpy(sym_op->cipher.iv.data, iv,
1474 CIPHER_IV_LENGTH_AES_CBC);
1476 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1477 sym_op->cipher.data.length = QUOTE_512_BYTES;
1479 /* Process crypto operation */
1480 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1481 ut_params->op), "failed to process sym crypto op");
1483 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1484 "crypto op processing failed");
1486 ut_params->obuf = ut_params->op->sym->m_src;
1489 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1490 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1491 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1493 "Plaintext data not as expected");
1496 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1497 "Digest verification failed");
1499 return TEST_SUCCESS;
1503 test_AES_cipheronly_mb_all(void)
1505 struct crypto_testsuite_params *ts_params = &testsuite_params;
1508 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1509 ts_params->op_mpool, ts_params->valid_devs[0],
1510 RTE_CRYPTODEV_AESNI_MB_PMD,
1511 BLKCIPHER_AES_CIPHERONLY_TYPE);
1513 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1515 return TEST_SUCCESS;
1519 test_AES_docsis_mb_all(void)
1521 struct crypto_testsuite_params *ts_params = &testsuite_params;
1524 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1525 ts_params->op_mpool, ts_params->valid_devs[0],
1526 RTE_CRYPTODEV_AESNI_MB_PMD,
1527 BLKCIPHER_AES_DOCSIS_TYPE);
1529 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1531 return TEST_SUCCESS;
1535 test_AES_docsis_qat_all(void)
1537 struct crypto_testsuite_params *ts_params = &testsuite_params;
1540 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1541 ts_params->op_mpool, ts_params->valid_devs[0],
1542 RTE_CRYPTODEV_QAT_SYM_PMD,
1543 BLKCIPHER_AES_DOCSIS_TYPE);
1545 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1547 return TEST_SUCCESS;
1551 test_DES_docsis_qat_all(void)
1553 struct crypto_testsuite_params *ts_params = &testsuite_params;
1556 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1557 ts_params->op_mpool, ts_params->valid_devs[0],
1558 RTE_CRYPTODEV_QAT_SYM_PMD,
1559 BLKCIPHER_DES_DOCSIS_TYPE);
1561 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1563 return TEST_SUCCESS;
1567 test_authonly_mb_all(void)
1569 struct crypto_testsuite_params *ts_params = &testsuite_params;
1572 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1573 ts_params->op_mpool, ts_params->valid_devs[0],
1574 RTE_CRYPTODEV_AESNI_MB_PMD,
1575 BLKCIPHER_AUTHONLY_TYPE);
1577 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1579 return TEST_SUCCESS;
1583 test_AES_chain_mb_all(void)
1585 struct crypto_testsuite_params *ts_params = &testsuite_params;
1588 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1589 ts_params->op_mpool, ts_params->valid_devs[0],
1590 RTE_CRYPTODEV_AESNI_MB_PMD,
1591 BLKCIPHER_AES_CHAIN_TYPE);
1593 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1595 return TEST_SUCCESS;
1598 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
1601 test_AES_cipheronly_scheduler_all(void)
1603 struct crypto_testsuite_params *ts_params = &testsuite_params;
1606 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1607 ts_params->op_mpool, ts_params->valid_devs[0],
1608 RTE_CRYPTODEV_SCHEDULER_PMD,
1609 BLKCIPHER_AES_CIPHERONLY_TYPE);
1611 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1613 return TEST_SUCCESS;
1617 test_AES_chain_scheduler_all(void)
1619 struct crypto_testsuite_params *ts_params = &testsuite_params;
1622 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1623 ts_params->op_mpool, ts_params->valid_devs[0],
1624 RTE_CRYPTODEV_SCHEDULER_PMD,
1625 BLKCIPHER_AES_CHAIN_TYPE);
1627 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1629 return TEST_SUCCESS;
1633 test_authonly_scheduler_all(void)
1635 struct crypto_testsuite_params *ts_params = &testsuite_params;
1638 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1639 ts_params->op_mpool, ts_params->valid_devs[0],
1640 RTE_CRYPTODEV_SCHEDULER_PMD,
1641 BLKCIPHER_AUTHONLY_TYPE);
1643 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1645 return TEST_SUCCESS;
1648 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
1651 test_AES_chain_openssl_all(void)
1653 struct crypto_testsuite_params *ts_params = &testsuite_params;
1656 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1657 ts_params->op_mpool, ts_params->valid_devs[0],
1658 RTE_CRYPTODEV_OPENSSL_PMD,
1659 BLKCIPHER_AES_CHAIN_TYPE);
1661 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1663 return TEST_SUCCESS;
1667 test_AES_cipheronly_openssl_all(void)
1669 struct crypto_testsuite_params *ts_params = &testsuite_params;
1672 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1673 ts_params->op_mpool, ts_params->valid_devs[0],
1674 RTE_CRYPTODEV_OPENSSL_PMD,
1675 BLKCIPHER_AES_CIPHERONLY_TYPE);
1677 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1679 return TEST_SUCCESS;
1683 test_AES_chain_qat_all(void)
1685 struct crypto_testsuite_params *ts_params = &testsuite_params;
1688 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1689 ts_params->op_mpool, ts_params->valid_devs[0],
1690 RTE_CRYPTODEV_QAT_SYM_PMD,
1691 BLKCIPHER_AES_CHAIN_TYPE);
1693 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1695 return TEST_SUCCESS;
1699 test_AES_cipheronly_qat_all(void)
1701 struct crypto_testsuite_params *ts_params = &testsuite_params;
1704 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1705 ts_params->op_mpool, ts_params->valid_devs[0],
1706 RTE_CRYPTODEV_QAT_SYM_PMD,
1707 BLKCIPHER_AES_CIPHERONLY_TYPE);
1709 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1711 return TEST_SUCCESS;
1715 test_AES_chain_dpaa2_sec_all(void)
1717 struct crypto_testsuite_params *ts_params = &testsuite_params;
1720 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1721 ts_params->op_mpool, ts_params->valid_devs[0],
1722 RTE_CRYPTODEV_DPAA2_SEC_PMD,
1723 BLKCIPHER_AES_CHAIN_TYPE);
1725 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1727 return TEST_SUCCESS;
1731 test_AES_cipheronly_dpaa2_sec_all(void)
1733 struct crypto_testsuite_params *ts_params = &testsuite_params;
1736 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1737 ts_params->op_mpool, ts_params->valid_devs[0],
1738 RTE_CRYPTODEV_DPAA2_SEC_PMD,
1739 BLKCIPHER_AES_CIPHERONLY_TYPE);
1741 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1743 return TEST_SUCCESS;
1747 test_authonly_openssl_all(void)
1749 struct crypto_testsuite_params *ts_params = &testsuite_params;
1752 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1753 ts_params->op_mpool, ts_params->valid_devs[0],
1754 RTE_CRYPTODEV_OPENSSL_PMD,
1755 BLKCIPHER_AUTHONLY_TYPE);
1757 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1759 return TEST_SUCCESS;
1763 test_AES_chain_armv8_all(void)
1765 struct crypto_testsuite_params *ts_params = &testsuite_params;
1768 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1769 ts_params->op_mpool, ts_params->valid_devs[0],
1770 RTE_CRYPTODEV_ARMV8_PMD,
1771 BLKCIPHER_AES_CHAIN_TYPE);
1773 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1775 return TEST_SUCCESS;
1778 /* ***** SNOW 3G Tests ***** */
1780 create_wireless_algo_hash_session(uint8_t dev_id,
1781 const uint8_t *key, const uint8_t key_len,
1782 const uint8_t aad_len, const uint8_t auth_len,
1783 enum rte_crypto_auth_operation op,
1784 enum rte_crypto_auth_algorithm algo)
1786 uint8_t hash_key[key_len];
1788 struct crypto_unittest_params *ut_params = &unittest_params;
1790 memcpy(hash_key, key, key_len);
1792 TEST_HEXDUMP(stdout, "key:", key, key_len);
1794 /* Setup Authentication Parameters */
1795 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1796 ut_params->auth_xform.next = NULL;
1798 ut_params->auth_xform.auth.op = op;
1799 ut_params->auth_xform.auth.algo = algo;
1800 ut_params->auth_xform.auth.key.length = key_len;
1801 ut_params->auth_xform.auth.key.data = hash_key;
1802 ut_params->auth_xform.auth.digest_length = auth_len;
1803 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1804 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1805 &ut_params->auth_xform);
1806 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1811 create_wireless_algo_cipher_session(uint8_t dev_id,
1812 enum rte_crypto_cipher_operation op,
1813 enum rte_crypto_cipher_algorithm algo,
1814 const uint8_t *key, const uint8_t key_len)
1816 uint8_t cipher_key[key_len];
1818 struct crypto_unittest_params *ut_params = &unittest_params;
1820 memcpy(cipher_key, key, key_len);
1822 /* Setup Cipher Parameters */
1823 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1824 ut_params->cipher_xform.next = NULL;
1826 ut_params->cipher_xform.cipher.algo = algo;
1827 ut_params->cipher_xform.cipher.op = op;
1828 ut_params->cipher_xform.cipher.key.data = cipher_key;
1829 ut_params->cipher_xform.cipher.key.length = key_len;
1831 TEST_HEXDUMP(stdout, "key:", key, key_len);
1833 /* Create Crypto session */
1834 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1837 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1842 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1843 const unsigned cipher_len,
1844 const unsigned cipher_offset,
1845 enum rte_crypto_cipher_algorithm algo)
1847 struct crypto_testsuite_params *ts_params = &testsuite_params;
1848 struct crypto_unittest_params *ut_params = &unittest_params;
1849 unsigned iv_pad_len = 0;
1851 /* Generate Crypto op data structure */
1852 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1853 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1854 TEST_ASSERT_NOT_NULL(ut_params->op,
1855 "Failed to allocate pktmbuf offload");
1857 /* Set crypto operation data parameters */
1858 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1860 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1862 /* set crypto operation source mbuf */
1863 sym_op->m_src = ut_params->ibuf;
1866 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1867 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1869 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1871 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1874 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1876 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1877 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1878 sym_op->cipher.iv.length = iv_pad_len;
1880 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1881 sym_op->cipher.data.length = cipher_len;
1882 sym_op->cipher.data.offset = cipher_offset;
1887 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1888 const unsigned cipher_len,
1889 const unsigned cipher_offset,
1890 enum rte_crypto_cipher_algorithm algo)
1892 struct crypto_testsuite_params *ts_params = &testsuite_params;
1893 struct crypto_unittest_params *ut_params = &unittest_params;
1894 unsigned iv_pad_len = 0;
1896 /* Generate Crypto op data structure */
1897 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1898 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1899 TEST_ASSERT_NOT_NULL(ut_params->op,
1900 "Failed to allocate pktmbuf offload");
1902 /* Set crypto operation data parameters */
1903 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1905 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1907 /* set crypto operation source mbuf */
1908 sym_op->m_src = ut_params->ibuf;
1909 sym_op->m_dst = ut_params->obuf;
1912 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1913 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1915 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1916 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1919 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1921 /* For OOP operation both buffers must have the same size */
1922 if (ut_params->obuf)
1923 rte_pktmbuf_prepend(ut_params->obuf, iv_pad_len);
1925 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1926 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1927 sym_op->cipher.iv.length = iv_pad_len;
1929 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1930 sym_op->cipher.data.length = cipher_len;
1931 sym_op->cipher.data.offset = cipher_offset;
1936 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1937 enum rte_crypto_cipher_operation cipher_op,
1938 enum rte_crypto_auth_operation auth_op,
1939 enum rte_crypto_auth_algorithm auth_algo,
1940 enum rte_crypto_cipher_algorithm cipher_algo,
1941 const uint8_t *key, const uint8_t key_len,
1942 const uint8_t aad_len, const uint8_t auth_len)
1945 uint8_t cipher_auth_key[key_len];
1947 struct crypto_unittest_params *ut_params = &unittest_params;
1949 memcpy(cipher_auth_key, key, key_len);
1951 /* Setup Authentication Parameters */
1952 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1953 ut_params->auth_xform.next = NULL;
1955 ut_params->auth_xform.auth.op = auth_op;
1956 ut_params->auth_xform.auth.algo = auth_algo;
1957 ut_params->auth_xform.auth.key.length = key_len;
1958 /* Hash key = cipher key */
1959 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1960 ut_params->auth_xform.auth.digest_length = auth_len;
1961 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1963 /* Setup Cipher Parameters */
1964 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1965 ut_params->cipher_xform.next = &ut_params->auth_xform;
1967 ut_params->cipher_xform.cipher.algo = cipher_algo;
1968 ut_params->cipher_xform.cipher.op = cipher_op;
1969 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1970 ut_params->cipher_xform.cipher.key.length = key_len;
1972 TEST_HEXDUMP(stdout, "key:", key, key_len);
1974 /* Create Crypto session*/
1975 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1976 &ut_params->cipher_xform);
1978 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1983 create_wireless_cipher_auth_session(uint8_t dev_id,
1984 enum rte_crypto_cipher_operation cipher_op,
1985 enum rte_crypto_auth_operation auth_op,
1986 enum rte_crypto_auth_algorithm auth_algo,
1987 enum rte_crypto_cipher_algorithm cipher_algo,
1988 const struct wireless_test_data *tdata)
1990 const uint8_t key_len = tdata->key.len;
1991 uint8_t cipher_auth_key[key_len];
1993 struct crypto_unittest_params *ut_params = &unittest_params;
1994 const uint8_t *key = tdata->key.data;
1995 const uint8_t aad_len = tdata->aad.len;
1996 const uint8_t auth_len = tdata->digest.len;
1998 memcpy(cipher_auth_key, key, key_len);
2000 /* Setup Authentication Parameters */
2001 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2002 ut_params->auth_xform.next = NULL;
2004 ut_params->auth_xform.auth.op = auth_op;
2005 ut_params->auth_xform.auth.algo = auth_algo;
2006 ut_params->auth_xform.auth.key.length = key_len;
2007 /* Hash key = cipher key */
2008 ut_params->auth_xform.auth.key.data = cipher_auth_key;
2009 ut_params->auth_xform.auth.digest_length = auth_len;
2010 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2012 /* Setup Cipher Parameters */
2013 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2014 ut_params->cipher_xform.next = &ut_params->auth_xform;
2016 ut_params->cipher_xform.cipher.algo = cipher_algo;
2017 ut_params->cipher_xform.cipher.op = cipher_op;
2018 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2019 ut_params->cipher_xform.cipher.key.length = key_len;
2021 TEST_HEXDUMP(stdout, "key:", key, key_len);
2023 /* Create Crypto session*/
2024 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2025 &ut_params->cipher_xform);
2027 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2032 create_zuc_cipher_auth_encrypt_generate_session(uint8_t dev_id,
2033 const struct wireless_test_data *tdata)
2035 return create_wireless_cipher_auth_session(dev_id,
2036 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2037 RTE_CRYPTO_AUTH_OP_GENERATE, RTE_CRYPTO_AUTH_ZUC_EIA3,
2038 RTE_CRYPTO_CIPHER_ZUC_EEA3, tdata);
2042 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
2043 enum rte_crypto_cipher_operation cipher_op,
2044 enum rte_crypto_auth_operation auth_op,
2045 enum rte_crypto_auth_algorithm auth_algo,
2046 enum rte_crypto_cipher_algorithm cipher_algo,
2047 const uint8_t *key, const uint8_t key_len,
2048 const uint8_t aad_len, const uint8_t auth_len)
2050 uint8_t auth_cipher_key[key_len];
2052 struct crypto_unittest_params *ut_params = &unittest_params;
2054 memcpy(auth_cipher_key, key, key_len);
2056 /* Setup Authentication Parameters */
2057 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2058 ut_params->auth_xform.auth.op = auth_op;
2059 ut_params->auth_xform.next = &ut_params->cipher_xform;
2060 ut_params->auth_xform.auth.algo = auth_algo;
2061 ut_params->auth_xform.auth.key.length = key_len;
2062 ut_params->auth_xform.auth.key.data = auth_cipher_key;
2063 ut_params->auth_xform.auth.digest_length = auth_len;
2064 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2066 /* Setup Cipher Parameters */
2067 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2068 ut_params->cipher_xform.next = NULL;
2069 ut_params->cipher_xform.cipher.algo = cipher_algo;
2070 ut_params->cipher_xform.cipher.op = cipher_op;
2071 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2072 ut_params->cipher_xform.cipher.key.length = key_len;
2074 TEST_HEXDUMP(stdout, "key:", key, key_len);
2076 /* Create Crypto session*/
2077 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2078 &ut_params->auth_xform);
2080 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2086 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
2087 const unsigned auth_tag_len,
2088 const uint8_t *aad, const unsigned aad_len,
2089 unsigned data_pad_len,
2090 enum rte_crypto_auth_operation op,
2091 enum rte_crypto_auth_algorithm algo,
2092 const unsigned auth_len, const unsigned auth_offset)
2094 struct crypto_testsuite_params *ts_params = &testsuite_params;
2096 struct crypto_unittest_params *ut_params = &unittest_params;
2098 unsigned aad_buffer_len;
2100 /* Generate Crypto op data structure */
2101 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2102 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2103 TEST_ASSERT_NOT_NULL(ut_params->op,
2104 "Failed to allocate pktmbuf offload");
2106 /* Set crypto operation data parameters */
2107 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2109 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2111 /* set crypto operation source mbuf */
2112 sym_op->m_src = ut_params->ibuf;
2116 * Always allocate the aad up to the block size.
2117 * The cryptodev API calls out -
2118 * - the array must be big enough to hold the AAD, plus any
2119 * space to round this up to the nearest multiple of the
2120 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
2122 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2123 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2125 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2126 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2127 ut_params->ibuf, aad_buffer_len);
2128 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2129 "no room to prepend aad");
2130 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2132 sym_op->auth.aad.length = aad_len;
2134 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2135 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2137 TEST_HEXDUMP(stdout, "aad:",
2138 sym_op->auth.aad.data, aad_len);
2141 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2142 ut_params->ibuf, auth_tag_len);
2144 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2145 "no room to append auth tag");
2146 ut_params->digest = sym_op->auth.digest.data;
2147 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2148 ut_params->ibuf, data_pad_len + aad_len);
2149 sym_op->auth.digest.length = auth_tag_len;
2150 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2151 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2153 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2155 TEST_HEXDUMP(stdout, "digest:",
2156 sym_op->auth.digest.data,
2157 sym_op->auth.digest.length);
2159 sym_op->auth.data.length = auth_len;
2160 sym_op->auth.data.offset = auth_offset;
2166 create_wireless_cipher_hash_operation(const struct wireless_test_data *tdata,
2167 enum rte_crypto_auth_operation op,
2168 enum rte_crypto_auth_algorithm auth_algo,
2169 enum rte_crypto_cipher_algorithm cipher_algo)
2171 struct crypto_testsuite_params *ts_params = &testsuite_params;
2172 struct crypto_unittest_params *ut_params = &unittest_params;
2174 const uint8_t *auth_tag = tdata->digest.data;
2175 const unsigned int auth_tag_len = tdata->digest.len;
2176 const uint8_t *aad = tdata->aad.data;
2177 const uint8_t aad_len = tdata->aad.len;
2178 unsigned int plaintext_len = ceil_byte_length(tdata->plaintext.len);
2179 unsigned int data_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2181 const uint8_t *iv = tdata->iv.data;
2182 const uint8_t iv_len = tdata->iv.len;
2183 const unsigned int cipher_len = tdata->validCipherLenInBits.len;
2184 const unsigned int cipher_offset = tdata->iv.len << 3;
2185 const unsigned int auth_len = tdata->validAuthLenInBits.len;
2186 const unsigned int auth_offset = tdata->aad.len << 3;
2188 unsigned int iv_pad_len = 0;
2189 unsigned int aad_buffer_len;
2191 /* Generate Crypto op data structure */
2192 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2193 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2194 TEST_ASSERT_NOT_NULL(ut_params->op,
2195 "Failed to allocate pktmbuf offload");
2196 /* Set crypto operation data parameters */
2197 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2199 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2201 /* set crypto operation source mbuf */
2202 sym_op->m_src = ut_params->ibuf;
2205 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2206 ut_params->ibuf, auth_tag_len);
2208 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2209 "no room to append auth tag");
2210 ut_params->digest = sym_op->auth.digest.data;
2211 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2212 ut_params->ibuf, data_pad_len);
2213 sym_op->auth.digest.length = auth_tag_len;
2214 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2215 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2217 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2219 TEST_HEXDUMP(stdout, "digest:",
2220 sym_op->auth.digest.data,
2221 sym_op->auth.digest.length);
2225 * Always allocate the aad up to the block size.
2226 * The cryptodev API calls out -
2227 * - the array must be big enough to hold the AAD, plus any
2228 * space to round this up to the nearest multiple of the
2229 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
2231 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2232 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2234 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2235 sym_op->auth.aad.data =
2236 (uint8_t *)rte_pktmbuf_prepend(
2237 ut_params->ibuf, aad_buffer_len);
2238 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2239 "no room to prepend aad");
2240 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2242 sym_op->auth.aad.length = aad_len;
2243 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2244 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2245 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
2248 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2249 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2251 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2252 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2253 ut_params->ibuf, iv_pad_len);
2255 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2256 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2257 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2258 sym_op->cipher.iv.length = iv_pad_len;
2259 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2260 sym_op->cipher.data.length = cipher_len;
2261 sym_op->cipher.data.offset = cipher_offset + auth_offset;
2262 sym_op->auth.data.length = auth_len;
2263 sym_op->auth.data.offset = auth_offset + cipher_offset;
2269 create_zuc_cipher_hash_generate_operation(
2270 const struct wireless_test_data *tdata)
2272 return create_wireless_cipher_hash_operation(tdata,
2273 RTE_CRYPTO_AUTH_OP_GENERATE,
2274 RTE_CRYPTO_AUTH_ZUC_EIA3,
2275 RTE_CRYPTO_CIPHER_ZUC_EEA3);
2279 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
2280 const unsigned auth_tag_len,
2281 const uint8_t *aad, const uint8_t aad_len,
2282 unsigned data_pad_len,
2283 enum rte_crypto_auth_operation op,
2284 enum rte_crypto_auth_algorithm auth_algo,
2285 enum rte_crypto_cipher_algorithm cipher_algo,
2286 const uint8_t *iv, const uint8_t iv_len,
2287 const unsigned cipher_len, const unsigned cipher_offset,
2288 const unsigned auth_len, const unsigned auth_offset)
2290 struct crypto_testsuite_params *ts_params = &testsuite_params;
2291 struct crypto_unittest_params *ut_params = &unittest_params;
2293 unsigned iv_pad_len = 0;
2294 unsigned aad_buffer_len;
2296 /* Generate Crypto op data structure */
2297 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2298 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2299 TEST_ASSERT_NOT_NULL(ut_params->op,
2300 "Failed to allocate pktmbuf offload");
2301 /* Set crypto operation data parameters */
2302 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2304 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2306 /* set crypto operation source mbuf */
2307 sym_op->m_src = ut_params->ibuf;
2310 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2311 ut_params->ibuf, auth_tag_len);
2313 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2314 "no room to append auth tag");
2315 ut_params->digest = sym_op->auth.digest.data;
2316 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2317 ut_params->ibuf, data_pad_len);
2318 sym_op->auth.digest.length = auth_tag_len;
2319 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2320 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2322 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2324 TEST_HEXDUMP(stdout, "digest:",
2325 sym_op->auth.digest.data,
2326 sym_op->auth.digest.length);
2330 * Always allocate the aad up to the block size.
2331 * The cryptodev API calls out -
2332 * - the array must be big enough to hold the AAD, plus any
2333 * space to round this up to the nearest multiple of the
2334 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
2336 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2337 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2339 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2340 sym_op->auth.aad.data =
2341 (uint8_t *)rte_pktmbuf_prepend(
2342 ut_params->ibuf, aad_buffer_len);
2343 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2344 "no room to prepend aad");
2345 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2347 sym_op->auth.aad.length = aad_len;
2348 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2349 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2350 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
2353 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2354 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2356 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2357 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2358 ut_params->ibuf, iv_pad_len);
2360 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2361 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2362 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2363 sym_op->cipher.iv.length = iv_pad_len;
2364 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2365 sym_op->cipher.data.length = cipher_len;
2366 sym_op->cipher.data.offset = cipher_offset + auth_offset;
2367 sym_op->auth.data.length = auth_len;
2368 sym_op->auth.data.offset = auth_offset + cipher_offset;
2374 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
2375 const uint8_t *iv, const uint8_t iv_len,
2376 const uint8_t *aad, const uint8_t aad_len,
2377 unsigned data_pad_len,
2378 const unsigned cipher_len, const unsigned cipher_offset,
2379 const unsigned auth_len, const unsigned auth_offset,
2380 enum rte_crypto_auth_algorithm auth_algo,
2381 enum rte_crypto_cipher_algorithm cipher_algo)
2383 struct crypto_testsuite_params *ts_params = &testsuite_params;
2384 struct crypto_unittest_params *ut_params = &unittest_params;
2386 unsigned iv_pad_len = 0;
2387 unsigned aad_buffer_len = 0;
2389 /* Generate Crypto op data structure */
2390 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2391 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2392 TEST_ASSERT_NOT_NULL(ut_params->op,
2393 "Failed to allocate pktmbuf offload");
2395 /* Set crypto operation data parameters */
2396 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2398 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2400 /* set crypto operation source mbuf */
2401 sym_op->m_src = ut_params->ibuf;
2404 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2405 ut_params->ibuf, auth_tag_len);
2407 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2408 "no room to append auth tag");
2410 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2411 ut_params->ibuf, data_pad_len);
2412 sym_op->auth.digest.length = auth_tag_len;
2414 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2416 TEST_HEXDUMP(stdout, "digest:",
2417 sym_op->auth.digest.data,
2418 sym_op->auth.digest.length);
2422 * Always allocate the aad up to the block size.
2423 * The cryptodev API calls out -
2424 * - the array must be big enough to hold the AAD, plus any
2425 * space to round this up to the nearest multiple of the
2426 * block size (8 bytes for KASUMI 16 bytes).
2428 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2429 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2431 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2432 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2433 ut_params->ibuf, aad_buffer_len);
2434 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2435 "no room to prepend aad");
2436 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2438 sym_op->auth.aad.length = aad_len;
2439 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2440 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2441 TEST_HEXDUMP(stdout, "aad:",
2442 sym_op->auth.aad.data, aad_len);
2445 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2446 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2448 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2450 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2451 ut_params->ibuf, iv_pad_len);
2452 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2454 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2455 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2456 sym_op->cipher.iv.length = iv_pad_len;
2458 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2460 sym_op->cipher.data.length = cipher_len;
2461 sym_op->cipher.data.offset = auth_offset + cipher_offset;
2463 sym_op->auth.data.length = auth_len;
2464 sym_op->auth.data.offset = auth_offset + cipher_offset;
2470 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2472 struct crypto_testsuite_params *ts_params = &testsuite_params;
2473 struct crypto_unittest_params *ut_params = &unittest_params;
2476 unsigned plaintext_pad_len;
2477 unsigned plaintext_len;
2480 /* Create SNOW 3G session */
2481 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2482 tdata->key.data, tdata->key.len,
2483 tdata->aad.len, tdata->digest.len,
2484 RTE_CRYPTO_AUTH_OP_GENERATE,
2485 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2489 /* alloc mbuf and set payload */
2490 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2492 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2493 rte_pktmbuf_tailroom(ut_params->ibuf));
2495 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2496 /* Append data which is padded to a multiple of */
2497 /* the algorithms block size */
2498 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2499 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2501 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2503 /* Create SNOW 3G operation */
2504 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2505 tdata->aad.data, tdata->aad.len,
2506 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2507 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2508 tdata->validAuthLenInBits.len,
2509 (tdata->aad.len << 3));
2513 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2515 ut_params->obuf = ut_params->op->sym->m_src;
2516 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2517 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2518 + plaintext_pad_len + tdata->aad.len;
2521 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2524 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2525 "SNOW 3G Generated auth tag not as expected");
2531 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2533 struct crypto_testsuite_params *ts_params = &testsuite_params;
2534 struct crypto_unittest_params *ut_params = &unittest_params;
2537 unsigned plaintext_pad_len;
2538 unsigned plaintext_len;
2541 /* Create SNOW 3G session */
2542 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2543 tdata->key.data, tdata->key.len,
2544 tdata->aad.len, tdata->digest.len,
2545 RTE_CRYPTO_AUTH_OP_VERIFY,
2546 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2549 /* alloc mbuf and set payload */
2550 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2552 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2553 rte_pktmbuf_tailroom(ut_params->ibuf));
2555 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2556 /* Append data which is padded to a multiple of */
2557 /* the algorithms block size */
2558 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2559 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2561 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2563 /* Create SNOW 3G operation */
2564 retval = create_wireless_algo_hash_operation(tdata->digest.data,
2566 tdata->aad.data, tdata->aad.len,
2568 RTE_CRYPTO_AUTH_OP_VERIFY,
2569 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2570 tdata->validAuthLenInBits.len,
2571 (tdata->aad.len << 3));
2575 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2577 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2578 ut_params->obuf = ut_params->op->sym->m_src;
2579 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2580 + plaintext_pad_len + tdata->aad.len;
2583 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2592 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2594 struct crypto_testsuite_params *ts_params = &testsuite_params;
2595 struct crypto_unittest_params *ut_params = &unittest_params;
2598 unsigned plaintext_pad_len;
2599 unsigned plaintext_len;
2602 /* Create KASUMI session */
2603 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2604 tdata->key.data, tdata->key.len,
2605 tdata->aad.len, tdata->digest.len,
2606 RTE_CRYPTO_AUTH_OP_GENERATE,
2607 RTE_CRYPTO_AUTH_KASUMI_F9);
2611 /* alloc mbuf and set payload */
2612 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2614 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2615 rte_pktmbuf_tailroom(ut_params->ibuf));
2617 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2618 /* Append data which is padded to a multiple of */
2619 /* the algorithms block size */
2620 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2621 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2623 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2625 /* Create KASUMI operation */
2626 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2627 tdata->aad.data, tdata->aad.len,
2628 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2629 RTE_CRYPTO_AUTH_KASUMI_F9,
2630 tdata->validAuthLenInBits.len,
2631 (tdata->aad.len << 3));
2635 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2637 ut_params->obuf = ut_params->op->sym->m_src;
2638 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2639 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2640 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
2643 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2646 DIGEST_BYTE_LENGTH_KASUMI_F9,
2647 "KASUMI Generated auth tag not as expected");
2653 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2655 struct crypto_testsuite_params *ts_params = &testsuite_params;
2656 struct crypto_unittest_params *ut_params = &unittest_params;
2659 unsigned plaintext_pad_len;
2660 unsigned plaintext_len;
2663 /* Create KASUMI session */
2664 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2665 tdata->key.data, tdata->key.len,
2666 tdata->aad.len, tdata->digest.len,
2667 RTE_CRYPTO_AUTH_OP_VERIFY,
2668 RTE_CRYPTO_AUTH_KASUMI_F9);
2671 /* alloc mbuf and set payload */
2672 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2674 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2675 rte_pktmbuf_tailroom(ut_params->ibuf));
2677 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2678 /* Append data which is padded to a multiple */
2679 /* of the algorithms block size */
2680 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2681 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2683 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2685 /* Create KASUMI operation */
2686 retval = create_wireless_algo_hash_operation(tdata->digest.data,
2688 tdata->aad.data, tdata->aad.len,
2690 RTE_CRYPTO_AUTH_OP_VERIFY,
2691 RTE_CRYPTO_AUTH_KASUMI_F9,
2692 tdata->validAuthLenInBits.len,
2693 (tdata->aad.len << 3));
2697 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2699 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2700 ut_params->obuf = ut_params->op->sym->m_src;
2701 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2702 + plaintext_pad_len + tdata->aad.len;
2705 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2714 test_snow3g_hash_generate_test_case_1(void)
2716 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2720 test_snow3g_hash_generate_test_case_2(void)
2722 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2726 test_snow3g_hash_generate_test_case_3(void)
2728 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2732 test_snow3g_hash_generate_test_case_4(void)
2734 return test_snow3g_authentication(&snow3g_hash_test_case_4);
2738 test_snow3g_hash_generate_test_case_5(void)
2740 return test_snow3g_authentication(&snow3g_hash_test_case_5);
2744 test_snow3g_hash_generate_test_case_6(void)
2746 return test_snow3g_authentication(&snow3g_hash_test_case_6);
2750 test_snow3g_hash_verify_test_case_1(void)
2752 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2757 test_snow3g_hash_verify_test_case_2(void)
2759 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2763 test_snow3g_hash_verify_test_case_3(void)
2765 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2769 test_snow3g_hash_verify_test_case_4(void)
2771 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2775 test_snow3g_hash_verify_test_case_5(void)
2777 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2781 test_snow3g_hash_verify_test_case_6(void)
2783 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2787 test_kasumi_hash_generate_test_case_1(void)
2789 return test_kasumi_authentication(&kasumi_hash_test_case_1);
2793 test_kasumi_hash_generate_test_case_2(void)
2795 return test_kasumi_authentication(&kasumi_hash_test_case_2);
2799 test_kasumi_hash_generate_test_case_3(void)
2801 return test_kasumi_authentication(&kasumi_hash_test_case_3);
2805 test_kasumi_hash_generate_test_case_4(void)
2807 return test_kasumi_authentication(&kasumi_hash_test_case_4);
2811 test_kasumi_hash_generate_test_case_5(void)
2813 return test_kasumi_authentication(&kasumi_hash_test_case_5);
2817 test_kasumi_hash_generate_test_case_6(void)
2819 return test_kasumi_authentication(&kasumi_hash_test_case_6);
2823 test_kasumi_hash_verify_test_case_1(void)
2825 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2829 test_kasumi_hash_verify_test_case_2(void)
2831 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2835 test_kasumi_hash_verify_test_case_3(void)
2837 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2841 test_kasumi_hash_verify_test_case_4(void)
2843 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2847 test_kasumi_hash_verify_test_case_5(void)
2849 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2853 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2855 struct crypto_testsuite_params *ts_params = &testsuite_params;
2856 struct crypto_unittest_params *ut_params = &unittest_params;
2859 uint8_t *plaintext, *ciphertext;
2860 unsigned plaintext_pad_len;
2861 unsigned plaintext_len;
2863 /* Create KASUMI session */
2864 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2865 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2866 RTE_CRYPTO_CIPHER_KASUMI_F8,
2867 tdata->key.data, tdata->key.len);
2871 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2873 /* Clear mbuf payload */
2874 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2875 rte_pktmbuf_tailroom(ut_params->ibuf));
2877 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2878 /* Append data which is padded to a multiple */
2879 /* of the algorithms block size */
2880 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2881 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2883 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2885 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2887 /* Create KASUMI operation */
2888 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2889 tdata->plaintext.len,
2890 (tdata->iv.len << 3),
2891 RTE_CRYPTO_CIPHER_KASUMI_F8);
2895 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2897 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2899 ut_params->obuf = ut_params->op->sym->m_dst;
2900 if (ut_params->obuf)
2901 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2904 ciphertext = plaintext;
2906 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2909 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2911 tdata->ciphertext.data,
2912 tdata->validCipherLenInBits.len,
2913 "KASUMI Ciphertext data not as expected");
2918 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
2920 struct crypto_testsuite_params *ts_params = &testsuite_params;
2921 struct crypto_unittest_params *ut_params = &unittest_params;
2925 unsigned int plaintext_pad_len;
2926 unsigned int plaintext_len;
2928 uint8_t buffer[10000];
2929 const uint8_t *ciphertext;
2931 struct rte_cryptodev_info dev_info;
2933 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2934 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
2935 printf("Device doesn't support scatter-gather. "
2940 /* Create KASUMI session */
2941 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2942 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2943 RTE_CRYPTO_CIPHER_KASUMI_F8,
2944 tdata->key.data, tdata->key.len);
2948 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2951 /* Append data which is padded to a multiple */
2952 /* of the algorithms block size */
2953 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2955 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
2956 plaintext_pad_len, 10, 0);
2958 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
2960 /* Create KASUMI operation */
2961 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2963 tdata->plaintext.len,
2964 (tdata->iv.len << 3),
2965 RTE_CRYPTO_CIPHER_KASUMI_F8);
2969 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2971 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2973 ut_params->obuf = ut_params->op->sym->m_dst;
2975 if (ut_params->obuf)
2976 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len,
2977 plaintext_len, buffer);
2979 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len,
2980 plaintext_len, buffer);
2983 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2986 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2988 tdata->ciphertext.data,
2989 tdata->validCipherLenInBits.len,
2990 "KASUMI Ciphertext data not as expected");
2995 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2997 struct crypto_testsuite_params *ts_params = &testsuite_params;
2998 struct crypto_unittest_params *ut_params = &unittest_params;
3001 uint8_t *plaintext, *ciphertext;
3002 unsigned plaintext_pad_len;
3003 unsigned plaintext_len;
3005 /* Create KASUMI session */
3006 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3007 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3008 RTE_CRYPTO_CIPHER_KASUMI_F8,
3009 tdata->key.data, tdata->key.len);
3013 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3014 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3016 /* Clear mbuf payload */
3017 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3018 rte_pktmbuf_tailroom(ut_params->ibuf));
3020 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3021 /* Append data which is padded to a multiple */
3022 /* of the algorithms block size */
3023 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3024 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3026 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3027 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3029 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3031 /* Create KASUMI operation */
3032 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3034 tdata->plaintext.len,
3035 (tdata->iv.len << 3),
3036 RTE_CRYPTO_CIPHER_KASUMI_F8);
3040 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3042 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3044 ut_params->obuf = ut_params->op->sym->m_dst;
3045 if (ut_params->obuf)
3046 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3049 ciphertext = plaintext;
3051 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3054 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3056 tdata->ciphertext.data,
3057 tdata->validCipherLenInBits.len,
3058 "KASUMI Ciphertext data not as expected");
3063 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
3065 struct crypto_testsuite_params *ts_params = &testsuite_params;
3066 struct crypto_unittest_params *ut_params = &unittest_params;
3069 unsigned int plaintext_pad_len;
3070 unsigned int plaintext_len;
3072 const uint8_t *ciphertext;
3073 uint8_t buffer[2048];
3075 struct rte_cryptodev_info dev_info;
3077 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3078 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3079 printf("Device doesn't support scatter-gather. "
3084 /* Create KASUMI session */
3085 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3086 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3087 RTE_CRYPTO_CIPHER_KASUMI_F8,
3088 tdata->key.data, tdata->key.len);
3092 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3093 /* Append data which is padded to a multiple */
3094 /* of the algorithms block size */
3095 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3097 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3098 plaintext_pad_len, 10, 0);
3099 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3100 plaintext_pad_len, 3, 0);
3102 /* Append data which is padded to a multiple */
3103 /* of the algorithms block size */
3104 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3106 /* Create KASUMI operation */
3107 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3109 tdata->plaintext.len,
3110 (tdata->iv.len << 3),
3111 RTE_CRYPTO_CIPHER_KASUMI_F8);
3115 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3117 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3119 ut_params->obuf = ut_params->op->sym->m_dst;
3120 if (ut_params->obuf)
3121 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len,
3122 plaintext_pad_len, buffer);
3124 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len,
3125 plaintext_pad_len, buffer);
3128 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3130 tdata->ciphertext.data,
3131 tdata->validCipherLenInBits.len,
3132 "KASUMI Ciphertext data not as expected");
3138 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
3140 struct crypto_testsuite_params *ts_params = &testsuite_params;
3141 struct crypto_unittest_params *ut_params = &unittest_params;
3144 uint8_t *ciphertext, *plaintext;
3145 unsigned ciphertext_pad_len;
3146 unsigned ciphertext_len;
3148 /* Create KASUMI session */
3149 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3150 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3151 RTE_CRYPTO_CIPHER_KASUMI_F8,
3152 tdata->key.data, tdata->key.len);
3156 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3157 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3159 /* Clear mbuf payload */
3160 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3161 rte_pktmbuf_tailroom(ut_params->ibuf));
3163 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3164 /* Append data which is padded to a multiple */
3165 /* of the algorithms block size */
3166 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3167 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3168 ciphertext_pad_len);
3169 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3170 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3172 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3174 /* Create KASUMI operation */
3175 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3177 tdata->ciphertext.len,
3178 (tdata->iv.len << 3),
3179 RTE_CRYPTO_CIPHER_KASUMI_F8);
3183 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3185 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3187 ut_params->obuf = ut_params->op->sym->m_dst;
3188 if (ut_params->obuf)
3189 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3192 plaintext = ciphertext;
3194 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3197 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3199 tdata->plaintext.data,
3200 tdata->validCipherLenInBits.len,
3201 "KASUMI Plaintext data not as expected");
3206 test_kasumi_decryption(const struct kasumi_test_data *tdata)
3208 struct crypto_testsuite_params *ts_params = &testsuite_params;
3209 struct crypto_unittest_params *ut_params = &unittest_params;
3212 uint8_t *ciphertext, *plaintext;
3213 unsigned ciphertext_pad_len;
3214 unsigned ciphertext_len;
3216 /* Create KASUMI session */
3217 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3218 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3219 RTE_CRYPTO_CIPHER_KASUMI_F8,
3220 tdata->key.data, tdata->key.len);
3224 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3226 /* Clear mbuf payload */
3227 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3228 rte_pktmbuf_tailroom(ut_params->ibuf));
3230 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3231 /* Append data which is padded to a multiple */
3232 /* of the algorithms block size */
3233 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
3234 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3235 ciphertext_pad_len);
3236 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3238 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3240 /* Create KASUMI operation */
3241 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
3243 tdata->ciphertext.len,
3244 (tdata->iv.len << 3),
3245 RTE_CRYPTO_CIPHER_KASUMI_F8);
3249 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3251 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3253 ut_params->obuf = ut_params->op->sym->m_dst;
3254 if (ut_params->obuf)
3255 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3258 plaintext = ciphertext;
3260 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3263 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3265 tdata->plaintext.data,
3266 tdata->validCipherLenInBits.len,
3267 "KASUMI Plaintext data not as expected");
3272 test_snow3g_encryption(const struct snow3g_test_data *tdata)
3274 struct crypto_testsuite_params *ts_params = &testsuite_params;
3275 struct crypto_unittest_params *ut_params = &unittest_params;
3278 uint8_t *plaintext, *ciphertext;
3279 unsigned plaintext_pad_len;
3280 unsigned plaintext_len;
3282 /* Create SNOW 3G session */
3283 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3284 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3285 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3286 tdata->key.data, tdata->key.len);
3290 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3292 /* Clear mbuf payload */
3293 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3294 rte_pktmbuf_tailroom(ut_params->ibuf));
3296 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3297 /* Append data which is padded to a multiple of */
3298 /* the algorithms block size */
3299 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3300 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3302 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3304 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3306 /* Create SNOW 3G operation */
3307 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3308 tdata->validCipherLenInBits.len,
3309 (tdata->iv.len << 3),
3310 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3314 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3316 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3318 ut_params->obuf = ut_params->op->sym->m_dst;
3319 if (ut_params->obuf)
3320 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3323 ciphertext = plaintext;
3325 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3328 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3330 tdata->ciphertext.data,
3331 tdata->validDataLenInBits.len,
3332 "SNOW 3G Ciphertext data not as expected");
3338 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3340 struct crypto_testsuite_params *ts_params = &testsuite_params;
3341 struct crypto_unittest_params *ut_params = &unittest_params;
3342 uint8_t *plaintext, *ciphertext;
3345 unsigned plaintext_pad_len;
3346 unsigned plaintext_len;
3348 /* Create SNOW 3G session */
3349 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3350 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3351 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3352 tdata->key.data, tdata->key.len);
3356 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3357 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3359 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3360 "Failed to allocate input buffer in mempool");
3361 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3362 "Failed to allocate output buffer in mempool");
3364 /* Clear mbuf payload */
3365 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3366 rte_pktmbuf_tailroom(ut_params->ibuf));
3368 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3369 /* Append data which is padded to a multiple of */
3370 /* the algorithms block size */
3371 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3372 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3374 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3375 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3377 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3379 /* Create SNOW 3G operation */
3380 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3382 tdata->validCipherLenInBits.len,
3383 (tdata->iv.len << 3),
3384 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3388 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3390 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3392 ut_params->obuf = ut_params->op->sym->m_dst;
3393 if (ut_params->obuf)
3394 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3397 ciphertext = plaintext;
3399 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3402 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3404 tdata->ciphertext.data,
3405 tdata->validDataLenInBits.len,
3406 "SNOW 3G Ciphertext data not as expected");
3411 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3413 struct crypto_testsuite_params *ts_params = &testsuite_params;
3414 struct crypto_unittest_params *ut_params = &unittest_params;
3417 unsigned int plaintext_pad_len;
3418 unsigned int plaintext_len;
3419 uint8_t buffer[10000];
3420 const uint8_t *ciphertext;
3422 struct rte_cryptodev_info dev_info;
3424 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3425 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3426 printf("Device doesn't support scatter-gather. "
3431 /* Create SNOW 3G session */
3432 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3433 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3434 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3435 tdata->key.data, tdata->key.len);
3439 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3440 /* Append data which is padded to a multiple of */
3441 /* the algorithms block size */
3442 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3444 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3445 plaintext_pad_len, 10, 0);
3446 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3447 plaintext_pad_len, 3, 0);
3449 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3450 "Failed to allocate input buffer in mempool");
3451 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3452 "Failed to allocate output buffer in mempool");
3454 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3456 /* Create SNOW 3G operation */
3457 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3459 tdata->validCipherLenInBits.len,
3460 (tdata->iv.len << 3),
3461 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3465 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3467 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3469 ut_params->obuf = ut_params->op->sym->m_dst;
3470 if (ut_params->obuf)
3471 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len,
3472 plaintext_len, buffer);
3474 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len,
3475 plaintext_len, buffer);
3477 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3480 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3482 tdata->ciphertext.data,
3483 tdata->validDataLenInBits.len,
3484 "SNOW 3G Ciphertext data not as expected");
3489 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3491 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3493 uint8_t curr_byte, prev_byte;
3494 uint32_t length_in_bytes = ceil_byte_length(length + offset);
3495 uint8_t lower_byte_mask = (1 << offset) - 1;
3498 prev_byte = buffer[0];
3499 buffer[0] >>= offset;
3501 for (i = 1; i < length_in_bytes; i++) {
3502 curr_byte = buffer[i];
3503 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3504 (curr_byte >> offset);
3505 prev_byte = curr_byte;
3510 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3512 struct crypto_testsuite_params *ts_params = &testsuite_params;
3513 struct crypto_unittest_params *ut_params = &unittest_params;
3514 uint8_t *plaintext, *ciphertext;
3516 uint32_t plaintext_len;
3517 uint32_t plaintext_pad_len;
3518 uint8_t extra_offset = 4;
3519 uint8_t *expected_ciphertext_shifted;
3521 /* Create SNOW 3G session */
3522 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3523 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3524 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3525 tdata->key.data, tdata->key.len);
3529 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3530 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3532 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3533 "Failed to allocate input buffer in mempool");
3534 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3535 "Failed to allocate output buffer in mempool");
3537 /* Clear mbuf payload */
3538 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3539 rte_pktmbuf_tailroom(ut_params->ibuf));
3541 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3543 * Append data which is padded to a
3544 * multiple of the algorithms block size
3546 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3548 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3551 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3553 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3554 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
3556 #ifdef RTE_APP_TEST_DEBUG
3557 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3559 /* Create SNOW 3G operation */
3560 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3562 tdata->validCipherLenInBits.len,
3563 (tdata->iv.len << 3) +
3565 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3569 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3571 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3573 ut_params->obuf = ut_params->op->sym->m_dst;
3574 if (ut_params->obuf)
3575 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3578 ciphertext = plaintext;
3580 #ifdef RTE_APP_TEST_DEBUG
3581 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3584 expected_ciphertext_shifted = rte_malloc(NULL, plaintext_len, 8);
3586 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
3587 "failed to reserve memory for ciphertext shifted\n");
3589 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3590 ceil_byte_length(tdata->ciphertext.len));
3591 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3594 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3596 expected_ciphertext_shifted,
3597 tdata->validDataLenInBits.len,
3599 "SNOW 3G Ciphertext data not as expected");
3603 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3605 struct crypto_testsuite_params *ts_params = &testsuite_params;
3606 struct crypto_unittest_params *ut_params = &unittest_params;
3610 uint8_t *plaintext, *ciphertext;
3611 unsigned ciphertext_pad_len;
3612 unsigned ciphertext_len;
3614 /* Create SNOW 3G session */
3615 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3616 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3617 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3618 tdata->key.data, tdata->key.len);
3622 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3624 /* Clear mbuf payload */
3625 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3626 rte_pktmbuf_tailroom(ut_params->ibuf));
3628 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3629 /* Append data which is padded to a multiple of */
3630 /* the algorithms block size */
3631 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3632 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3633 ciphertext_pad_len);
3634 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3636 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3638 /* Create SNOW 3G operation */
3639 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3640 tdata->validCipherLenInBits.len,
3641 (tdata->iv.len << 3),
3642 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3646 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3648 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3649 ut_params->obuf = ut_params->op->sym->m_dst;
3650 if (ut_params->obuf)
3651 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3654 plaintext = ciphertext;
3656 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3659 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3660 tdata->plaintext.data,
3661 tdata->validDataLenInBits.len,
3662 "SNOW 3G Plaintext data not as expected");
3666 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3668 struct crypto_testsuite_params *ts_params = &testsuite_params;
3669 struct crypto_unittest_params *ut_params = &unittest_params;
3673 uint8_t *plaintext, *ciphertext;
3674 unsigned ciphertext_pad_len;
3675 unsigned ciphertext_len;
3677 /* Create SNOW 3G session */
3678 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3679 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3680 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3681 tdata->key.data, tdata->key.len);
3685 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3686 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3688 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3689 "Failed to allocate input buffer");
3690 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3691 "Failed to allocate output buffer");
3693 /* Clear mbuf payload */
3694 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3695 rte_pktmbuf_tailroom(ut_params->ibuf));
3697 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3698 rte_pktmbuf_tailroom(ut_params->obuf));
3700 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3701 /* Append data which is padded to a multiple of */
3702 /* the algorithms block size */
3703 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3704 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3705 ciphertext_pad_len);
3706 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3707 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3709 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3711 /* Create SNOW 3G operation */
3712 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3714 tdata->validCipherLenInBits.len,
3715 (tdata->iv.len << 3),
3716 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3720 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3722 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3723 ut_params->obuf = ut_params->op->sym->m_dst;
3724 if (ut_params->obuf)
3725 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3728 plaintext = ciphertext;
3730 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3733 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3734 tdata->plaintext.data,
3735 tdata->validDataLenInBits.len,
3736 "SNOW 3G Plaintext data not as expected");
3741 test_zuc_cipher_auth(const struct wireless_test_data *tdata)
3743 struct crypto_testsuite_params *ts_params = &testsuite_params;
3744 struct crypto_unittest_params *ut_params = &unittest_params;
3748 uint8_t *plaintext, *ciphertext;
3749 unsigned int plaintext_pad_len;
3750 unsigned int plaintext_len;
3752 struct rte_cryptodev_sym_capability_idx cap_idx;
3754 /* Check if device supports ZUC EEA3 */
3755 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3756 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
3758 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3762 /* Check if device supports ZUC EIA3 */
3763 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3764 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
3766 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
3770 /* Create ZUC session */
3771 retval = create_zuc_cipher_auth_encrypt_generate_session(
3772 ts_params->valid_devs[0],
3776 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3778 /* clear mbuf payload */
3779 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3780 rte_pktmbuf_tailroom(ut_params->ibuf));
3782 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3783 /* Append data which is padded to a multiple of */
3784 /* the algorithms block size */
3785 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3786 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3788 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3790 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3792 /* Create ZUC operation */
3793 retval = create_zuc_cipher_hash_generate_operation(tdata);
3797 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3799 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3800 ut_params->obuf = ut_params->op->sym->m_src;
3801 if (ut_params->obuf)
3802 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3803 + tdata->iv.len + tdata->aad.len;
3805 ciphertext = plaintext;
3807 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3809 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3811 tdata->ciphertext.data,
3812 tdata->validDataLenInBits.len,
3813 "ZUC Ciphertext data not as expected");
3815 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3816 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3819 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3823 "ZUC Generated auth tag not as expected");
3828 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
3830 struct crypto_testsuite_params *ts_params = &testsuite_params;
3831 struct crypto_unittest_params *ut_params = &unittest_params;
3835 uint8_t *plaintext, *ciphertext;
3836 unsigned plaintext_pad_len;
3837 unsigned plaintext_len;
3839 /* Create SNOW 3G session */
3840 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
3841 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3842 RTE_CRYPTO_AUTH_OP_GENERATE,
3843 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3844 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3845 tdata->key.data, tdata->key.len,
3846 tdata->aad.len, tdata->digest.len);
3849 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3851 /* clear mbuf payload */
3852 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3853 rte_pktmbuf_tailroom(ut_params->ibuf));
3855 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3856 /* Append data which is padded to a multiple of */
3857 /* the algorithms block size */
3858 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3859 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3861 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3863 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3865 /* Create SNOW 3G operation */
3866 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3867 tdata->digest.len, tdata->aad.data,
3868 tdata->aad.len, /*tdata->plaintext.len,*/
3869 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3870 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3871 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3872 tdata->iv.data, tdata->iv.len,
3873 tdata->validCipherLenInBits.len,
3874 (tdata->iv.len << 3),
3875 tdata->validAuthLenInBits.len,
3876 (tdata->aad.len << 3)
3881 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3883 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3884 ut_params->obuf = ut_params->op->sym->m_src;
3885 if (ut_params->obuf)
3886 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3887 + tdata->iv.len + tdata->aad.len;
3889 ciphertext = plaintext;
3891 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3893 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3895 tdata->ciphertext.data,
3896 tdata->validDataLenInBits.len,
3897 "SNOW 3G Ciphertext data not as expected");
3899 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3900 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3903 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3906 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3907 "SNOW 3G Generated auth tag not as expected");
3911 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
3913 struct crypto_testsuite_params *ts_params = &testsuite_params;
3914 struct crypto_unittest_params *ut_params = &unittest_params;
3918 uint8_t *plaintext, *ciphertext;
3919 unsigned plaintext_pad_len;
3920 unsigned plaintext_len;
3922 /* Create SNOW 3G session */
3923 retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
3924 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3925 RTE_CRYPTO_AUTH_OP_GENERATE,
3926 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3927 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3928 tdata->key.data, tdata->key.len,
3929 tdata->aad.len, tdata->digest.len);
3933 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3935 /* clear mbuf payload */
3936 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3937 rte_pktmbuf_tailroom(ut_params->ibuf));
3939 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3940 /* Append data which is padded to a multiple of */
3941 /* the algorithms block size */
3942 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3943 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3945 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3947 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3949 /* Create SNOW 3G operation */
3950 retval = create_wireless_algo_auth_cipher_operation(
3952 tdata->iv.data, tdata->iv.len,
3953 tdata->aad.data, tdata->aad.len,
3955 tdata->validCipherLenInBits.len,
3956 (tdata->iv.len << 3),
3957 tdata->validAuthLenInBits.len,
3958 (tdata->aad.len << 3),
3959 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3960 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
3966 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3968 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3969 ut_params->obuf = ut_params->op->sym->m_src;
3970 if (ut_params->obuf)
3971 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3972 + tdata->aad.len + tdata->iv.len;
3974 ciphertext = plaintext;
3976 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3977 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3978 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3981 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3983 tdata->ciphertext.data,
3984 tdata->validDataLenInBits.len,
3985 "SNOW 3G Ciphertext data not as expected");
3988 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3991 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3992 "SNOW 3G Generated auth tag not as expected");
3997 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
3999 struct crypto_testsuite_params *ts_params = &testsuite_params;
4000 struct crypto_unittest_params *ut_params = &unittest_params;
4004 uint8_t *plaintext, *ciphertext;
4005 unsigned plaintext_pad_len;
4006 unsigned plaintext_len;
4008 /* Create KASUMI session */
4009 retval = create_wireless_algo_auth_cipher_session(
4010 ts_params->valid_devs[0],
4011 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4012 RTE_CRYPTO_AUTH_OP_GENERATE,
4013 RTE_CRYPTO_AUTH_KASUMI_F9,
4014 RTE_CRYPTO_CIPHER_KASUMI_F8,
4015 tdata->key.data, tdata->key.len,
4016 tdata->aad.len, tdata->digest.len);
4019 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4021 /* clear mbuf payload */
4022 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4023 rte_pktmbuf_tailroom(ut_params->ibuf));
4025 plaintext_len = ceil_byte_length(tdata->plaintext.len);
4026 /* Append data which is padded to a multiple of */
4027 /* the algorithms block size */
4028 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4029 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4031 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4033 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
4035 /* Create KASUMI operation */
4036 retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
4037 tdata->iv.data, tdata->iv.len,
4038 tdata->aad.data, tdata->aad.len,
4040 tdata->validCipherLenInBits.len,
4041 (tdata->iv.len << 3),
4042 tdata->validAuthLenInBits.len,
4043 (tdata->aad.len << 3),
4044 RTE_CRYPTO_AUTH_KASUMI_F9,
4045 RTE_CRYPTO_CIPHER_KASUMI_F8
4051 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4053 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4054 ut_params->obuf = ut_params->op->sym->m_src;
4055 if (ut_params->obuf)
4056 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4057 + tdata->iv.len + tdata->aad.len;
4059 ciphertext = plaintext;
4062 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4064 tdata->ciphertext.data,
4065 tdata->validCipherLenInBits.len,
4066 "KASUMI Ciphertext data not as expected");
4067 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4068 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
4071 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4074 DIGEST_BYTE_LENGTH_KASUMI_F9,
4075 "KASUMI Generated auth tag not as expected");
4080 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
4082 struct crypto_testsuite_params *ts_params = &testsuite_params;
4083 struct crypto_unittest_params *ut_params = &unittest_params;
4087 uint8_t *plaintext, *ciphertext;
4088 unsigned plaintext_pad_len;
4089 unsigned plaintext_len;
4091 /* Create KASUMI session */
4092 retval = create_wireless_algo_cipher_auth_session(
4093 ts_params->valid_devs[0],
4094 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4095 RTE_CRYPTO_AUTH_OP_GENERATE,
4096 RTE_CRYPTO_AUTH_KASUMI_F9,
4097 RTE_CRYPTO_CIPHER_KASUMI_F8,
4098 tdata->key.data, tdata->key.len,
4099 tdata->aad.len, tdata->digest.len);
4103 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4105 /* clear mbuf payload */
4106 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4107 rte_pktmbuf_tailroom(ut_params->ibuf));
4109 plaintext_len = ceil_byte_length(tdata->plaintext.len);
4110 /* Append data which is padded to a multiple of */
4111 /* the algorithms block size */
4112 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
4113 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4115 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4117 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
4119 /* Create KASUMI operation */
4120 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
4121 tdata->digest.len, tdata->aad.data,
4123 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4124 RTE_CRYPTO_AUTH_KASUMI_F9,
4125 RTE_CRYPTO_CIPHER_KASUMI_F8,
4126 tdata->iv.data, tdata->iv.len,
4127 tdata->validCipherLenInBits.len,
4128 (tdata->iv.len << 3),
4129 tdata->validAuthLenInBits.len,
4130 (tdata->aad.len << 3)
4135 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4137 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4138 ut_params->obuf = ut_params->op->sym->m_src;
4139 if (ut_params->obuf)
4140 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4141 + tdata->aad.len + tdata->iv.len;
4143 ciphertext = plaintext;
4145 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4146 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
4149 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4151 tdata->ciphertext.data,
4152 tdata->validCipherLenInBits.len,
4153 "KASUMI Ciphertext data not as expected");
4156 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4159 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
4160 "KASUMI Generated auth tag not as expected");
4165 test_zuc_encryption(const struct wireless_test_data *tdata)
4167 struct crypto_testsuite_params *ts_params = &testsuite_params;
4168 struct crypto_unittest_params *ut_params = &unittest_params;
4171 uint8_t *plaintext, *ciphertext;
4172 unsigned plaintext_pad_len;
4173 unsigned plaintext_len;
4175 struct rte_cryptodev_sym_capability_idx cap_idx;
4177 /* Check if device supports ZUC EEA3 */
4178 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4179 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4181 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4185 /* Create ZUC session */
4186 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4187 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4188 RTE_CRYPTO_CIPHER_ZUC_EEA3,
4189 tdata->key.data, tdata->key.len);
4193 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4195 /* Clear mbuf payload */
4196 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4197 rte_pktmbuf_tailroom(ut_params->ibuf));
4199 plaintext_len = ceil_byte_length(tdata->plaintext.len);
4200 /* Append data which is padded to a multiple */
4201 /* of the algorithms block size */
4202 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4203 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4205 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4207 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
4209 /* Create ZUC operation */
4210 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
4211 tdata->plaintext.len,
4212 (tdata->iv.len << 3),
4213 RTE_CRYPTO_CIPHER_ZUC_EEA3);
4217 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4219 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4221 ut_params->obuf = ut_params->op->sym->m_dst;
4222 if (ut_params->obuf)
4223 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4226 ciphertext = plaintext;
4228 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
4231 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4233 tdata->ciphertext.data,
4234 tdata->validCipherLenInBits.len,
4235 "ZUC Ciphertext data not as expected");
4240 test_zuc_encryption_sgl(const struct wireless_test_data *tdata)
4242 struct crypto_testsuite_params *ts_params = &testsuite_params;
4243 struct crypto_unittest_params *ut_params = &unittest_params;
4247 unsigned int plaintext_pad_len;
4248 unsigned int plaintext_len;
4249 const uint8_t *ciphertext;
4250 uint8_t ciphertext_buffer[2048];
4251 struct rte_cryptodev_info dev_info;
4253 struct rte_cryptodev_sym_capability_idx cap_idx;
4255 /* Check if device supports ZUC EEA3 */
4256 cap_idx.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4257 cap_idx.algo.cipher = RTE_CRYPTO_CIPHER_ZUC_EEA3;
4259 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4263 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4264 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
4265 printf("Device doesn't support scatter-gather. "
4270 plaintext_len = ceil_byte_length(tdata->plaintext.len);
4272 /* Append data which is padded to a multiple */
4273 /* of the algorithms block size */
4274 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4276 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
4277 plaintext_pad_len, 10, 0);
4279 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
4280 tdata->plaintext.data);
4282 /* Create ZUC session */
4283 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
4284 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4285 RTE_CRYPTO_CIPHER_ZUC_EEA3,
4286 tdata->key.data, tdata->key.len);
4290 /* Clear mbuf payload */
4292 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
4294 /* Create ZUC operation */
4295 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
4296 tdata->iv.len, tdata->plaintext.len,
4297 (tdata->iv.len << 3),
4298 RTE_CRYPTO_CIPHER_ZUC_EEA3);
4302 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4304 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4306 ut_params->obuf = ut_params->op->sym->m_dst;
4307 if (ut_params->obuf)
4308 ciphertext = rte_pktmbuf_read(ut_params->obuf,
4309 tdata->iv.len, plaintext_len, ciphertext_buffer);
4311 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
4312 tdata->iv.len, plaintext_len, ciphertext_buffer);
4315 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
4318 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
4320 tdata->ciphertext.data,
4321 tdata->validCipherLenInBits.len,
4322 "ZUC Ciphertext data not as expected");
4328 test_zuc_authentication(const struct wireless_test_data *tdata)
4330 struct crypto_testsuite_params *ts_params = &testsuite_params;
4331 struct crypto_unittest_params *ut_params = &unittest_params;
4334 unsigned plaintext_pad_len;
4335 unsigned plaintext_len;
4338 struct rte_cryptodev_sym_capability_idx cap_idx;
4340 /* Check if device supports ZUC EIA3 */
4341 cap_idx.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4342 cap_idx.algo.auth = RTE_CRYPTO_AUTH_ZUC_EIA3;
4344 if (rte_cryptodev_sym_capability_get(ts_params->valid_devs[0],
4348 /* Create ZUC session */
4349 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
4350 tdata->key.data, tdata->key.len,
4351 tdata->aad.len, tdata->digest.len,
4352 RTE_CRYPTO_AUTH_OP_GENERATE,
4353 RTE_CRYPTO_AUTH_ZUC_EIA3);
4357 /* alloc mbuf and set payload */
4358 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4360 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4361 rte_pktmbuf_tailroom(ut_params->ibuf));
4363 plaintext_len = ceil_byte_length(tdata->plaintext.len);
4364 /* Append data which is padded to a multiple of */
4365 /* the algorithms block size */
4366 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
4367 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4369 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
4371 /* Create ZUC operation */
4372 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
4373 tdata->aad.data, tdata->aad.len,
4374 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
4375 RTE_CRYPTO_AUTH_ZUC_EIA3,
4376 tdata->validAuthLenInBits.len,
4377 (tdata->aad.len << 3));
4381 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4383 ut_params->obuf = ut_params->op->sym->m_src;
4384 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
4385 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
4386 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
4389 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4392 DIGEST_BYTE_LENGTH_KASUMI_F9,
4393 "ZUC Generated auth tag not as expected");
4399 test_kasumi_encryption_test_case_1(void)
4401 return test_kasumi_encryption(&kasumi_test_case_1);
4405 test_kasumi_encryption_test_case_1_sgl(void)
4407 return test_kasumi_encryption_sgl(&kasumi_test_case_1);
4411 test_kasumi_encryption_test_case_1_oop(void)
4413 return test_kasumi_encryption_oop(&kasumi_test_case_1);
4417 test_kasumi_encryption_test_case_1_oop_sgl(void)
4419 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
4423 test_kasumi_encryption_test_case_2(void)
4425 return test_kasumi_encryption(&kasumi_test_case_2);
4429 test_kasumi_encryption_test_case_3(void)
4431 return test_kasumi_encryption(&kasumi_test_case_3);
4435 test_kasumi_encryption_test_case_4(void)
4437 return test_kasumi_encryption(&kasumi_test_case_4);
4441 test_kasumi_encryption_test_case_5(void)
4443 return test_kasumi_encryption(&kasumi_test_case_5);
4447 test_kasumi_decryption_test_case_1(void)
4449 return test_kasumi_decryption(&kasumi_test_case_1);
4453 test_kasumi_decryption_test_case_1_oop(void)
4455 return test_kasumi_decryption_oop(&kasumi_test_case_1);
4459 test_kasumi_decryption_test_case_2(void)
4461 return test_kasumi_decryption(&kasumi_test_case_2);
4465 test_kasumi_decryption_test_case_3(void)
4467 return test_kasumi_decryption(&kasumi_test_case_3);
4471 test_kasumi_decryption_test_case_4(void)
4473 return test_kasumi_decryption(&kasumi_test_case_4);
4477 test_kasumi_decryption_test_case_5(void)
4479 return test_kasumi_decryption(&kasumi_test_case_5);
4482 test_snow3g_encryption_test_case_1(void)
4484 return test_snow3g_encryption(&snow3g_test_case_1);
4488 test_snow3g_encryption_test_case_1_oop(void)
4490 return test_snow3g_encryption_oop(&snow3g_test_case_1);
4494 test_snow3g_encryption_test_case_1_oop_sgl(void)
4496 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
4501 test_snow3g_encryption_test_case_1_offset_oop(void)
4503 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
4507 test_snow3g_encryption_test_case_2(void)
4509 return test_snow3g_encryption(&snow3g_test_case_2);
4513 test_snow3g_encryption_test_case_3(void)
4515 return test_snow3g_encryption(&snow3g_test_case_3);
4519 test_snow3g_encryption_test_case_4(void)
4521 return test_snow3g_encryption(&snow3g_test_case_4);
4525 test_snow3g_encryption_test_case_5(void)
4527 return test_snow3g_encryption(&snow3g_test_case_5);
4531 test_snow3g_decryption_test_case_1(void)
4533 return test_snow3g_decryption(&snow3g_test_case_1);
4537 test_snow3g_decryption_test_case_1_oop(void)
4539 return test_snow3g_decryption_oop(&snow3g_test_case_1);
4543 test_snow3g_decryption_test_case_2(void)
4545 return test_snow3g_decryption(&snow3g_test_case_2);
4549 test_snow3g_decryption_test_case_3(void)
4551 return test_snow3g_decryption(&snow3g_test_case_3);
4555 test_snow3g_decryption_test_case_4(void)
4557 return test_snow3g_decryption(&snow3g_test_case_4);
4561 test_snow3g_decryption_test_case_5(void)
4563 return test_snow3g_decryption(&snow3g_test_case_5);
4566 test_snow3g_cipher_auth_test_case_1(void)
4568 return test_snow3g_cipher_auth(&snow3g_test_case_3);
4572 test_snow3g_auth_cipher_test_case_1(void)
4574 return test_snow3g_auth_cipher(&snow3g_test_case_6);
4578 test_kasumi_auth_cipher_test_case_1(void)
4580 return test_kasumi_auth_cipher(&kasumi_test_case_3);
4584 test_kasumi_cipher_auth_test_case_1(void)
4586 return test_kasumi_cipher_auth(&kasumi_test_case_6);
4590 test_zuc_encryption_test_case_1(void)
4592 return test_zuc_encryption(&zuc_test_case_cipher_193b);
4596 test_zuc_encryption_test_case_2(void)
4598 return test_zuc_encryption(&zuc_test_case_cipher_800b);
4602 test_zuc_encryption_test_case_3(void)
4604 return test_zuc_encryption(&zuc_test_case_cipher_1570b);
4608 test_zuc_encryption_test_case_4(void)
4610 return test_zuc_encryption(&zuc_test_case_cipher_2798b);
4614 test_zuc_encryption_test_case_5(void)
4616 return test_zuc_encryption(&zuc_test_case_cipher_4019b);
4620 test_zuc_encryption_test_case_6_sgl(void)
4622 return test_zuc_encryption_sgl(&zuc_test_case_cipher_193b);
4626 test_zuc_hash_generate_test_case_1(void)
4628 return test_zuc_authentication(&zuc_test_case_auth_1b);
4632 test_zuc_hash_generate_test_case_2(void)
4634 return test_zuc_authentication(&zuc_test_case_auth_90b);
4638 test_zuc_hash_generate_test_case_3(void)
4640 return test_zuc_authentication(&zuc_test_case_auth_577b);
4644 test_zuc_hash_generate_test_case_4(void)
4646 return test_zuc_authentication(&zuc_test_case_auth_2079b);
4650 test_zuc_hash_generate_test_case_5(void)
4652 return test_zuc_authentication(&zuc_test_auth_5670b);
4656 test_zuc_hash_generate_test_case_6(void)
4658 return test_zuc_authentication(&zuc_test_case_auth_128b);
4662 test_zuc_hash_generate_test_case_7(void)
4664 return test_zuc_authentication(&zuc_test_case_auth_2080b);
4668 test_zuc_hash_generate_test_case_8(void)
4670 return test_zuc_authentication(&zuc_test_case_auth_584b);
4674 test_zuc_cipher_auth_test_case_1(void)
4676 return test_zuc_cipher_auth(&zuc_test_case_cipher_200b_auth_200b);
4680 test_zuc_cipher_auth_test_case_2(void)
4682 return test_zuc_cipher_auth(&zuc_test_case_cipher_800b_auth_120b);
4686 test_3DES_chain_qat_all(void)
4688 struct crypto_testsuite_params *ts_params = &testsuite_params;
4691 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4692 ts_params->op_mpool, ts_params->valid_devs[0],
4693 RTE_CRYPTODEV_QAT_SYM_PMD,
4694 BLKCIPHER_3DES_CHAIN_TYPE);
4696 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4698 return TEST_SUCCESS;
4702 test_DES_cipheronly_qat_all(void)
4704 struct crypto_testsuite_params *ts_params = &testsuite_params;
4707 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4708 ts_params->op_mpool, ts_params->valid_devs[0],
4709 RTE_CRYPTODEV_QAT_SYM_PMD,
4710 BLKCIPHER_DES_CIPHERONLY_TYPE);
4712 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4714 return TEST_SUCCESS;
4718 test_DES_docsis_openssl_all(void)
4720 struct crypto_testsuite_params *ts_params = &testsuite_params;
4723 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4724 ts_params->op_mpool, ts_params->valid_devs[0],
4725 RTE_CRYPTODEV_OPENSSL_PMD,
4726 BLKCIPHER_DES_DOCSIS_TYPE);
4728 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4730 return TEST_SUCCESS;
4734 test_3DES_chain_dpaa2_sec_all(void)
4736 struct crypto_testsuite_params *ts_params = &testsuite_params;
4739 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4740 ts_params->op_mpool, ts_params->valid_devs[0],
4741 RTE_CRYPTODEV_DPAA2_SEC_PMD,
4742 BLKCIPHER_3DES_CHAIN_TYPE);
4744 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4746 return TEST_SUCCESS;
4750 test_3DES_cipheronly_dpaa2_sec_all(void)
4752 struct crypto_testsuite_params *ts_params = &testsuite_params;
4755 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4756 ts_params->op_mpool, ts_params->valid_devs[0],
4757 RTE_CRYPTODEV_DPAA2_SEC_PMD,
4758 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4760 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4762 return TEST_SUCCESS;
4766 test_3DES_cipheronly_qat_all(void)
4768 struct crypto_testsuite_params *ts_params = &testsuite_params;
4771 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4772 ts_params->op_mpool, ts_params->valid_devs[0],
4773 RTE_CRYPTODEV_QAT_SYM_PMD,
4774 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4776 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4778 return TEST_SUCCESS;
4782 test_3DES_chain_openssl_all(void)
4784 struct crypto_testsuite_params *ts_params = &testsuite_params;
4787 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4788 ts_params->op_mpool, ts_params->valid_devs[0],
4789 RTE_CRYPTODEV_OPENSSL_PMD,
4790 BLKCIPHER_3DES_CHAIN_TYPE);
4792 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4794 return TEST_SUCCESS;
4798 test_3DES_cipheronly_openssl_all(void)
4800 struct crypto_testsuite_params *ts_params = &testsuite_params;
4803 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4804 ts_params->op_mpool, ts_params->valid_devs[0],
4805 RTE_CRYPTODEV_OPENSSL_PMD,
4806 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4808 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4810 return TEST_SUCCESS;
4813 /* ***** AES-GCM Tests ***** */
4816 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
4817 const uint8_t *key, const uint8_t key_len,
4818 const uint8_t aad_len, const uint8_t auth_len,
4819 enum rte_crypto_auth_operation auth_op)
4821 uint8_t cipher_key[key_len];
4823 struct crypto_unittest_params *ut_params = &unittest_params;
4825 memcpy(cipher_key, key, key_len);
4827 /* Setup Cipher Parameters */
4828 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4829 ut_params->cipher_xform.next = NULL;
4831 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4832 ut_params->auth_xform.auth.op = auth_op;
4833 ut_params->cipher_xform.cipher.op = op;
4834 ut_params->cipher_xform.cipher.key.data = cipher_key;
4835 ut_params->cipher_xform.cipher.key.length = key_len;
4837 TEST_HEXDUMP(stdout, "key:", key, key_len);
4839 /* Setup Authentication Parameters */
4840 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4841 ut_params->auth_xform.next = NULL;
4843 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
4845 ut_params->auth_xform.auth.digest_length = auth_len;
4846 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
4847 ut_params->auth_xform.auth.key.length = 0;
4848 ut_params->auth_xform.auth.key.data = NULL;
4850 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
4851 ut_params->cipher_xform.next = &ut_params->auth_xform;
4853 /* Create Crypto session*/
4854 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4855 &ut_params->cipher_xform);
4856 } else {/* Create Crypto session*/
4857 ut_params->auth_xform.next = &ut_params->cipher_xform;
4858 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4859 &ut_params->auth_xform);
4862 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4868 create_gcm_xforms(struct rte_crypto_op *op,
4869 enum rte_crypto_cipher_operation cipher_op,
4870 uint8_t *key, const uint8_t key_len,
4871 const uint8_t aad_len, const uint8_t auth_len,
4872 enum rte_crypto_auth_operation auth_op)
4874 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(op, 2),
4875 "failed to allocate space for crypto transforms");
4877 struct rte_crypto_sym_op *sym_op = op->sym;
4879 /* Setup Cipher Parameters */
4880 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4881 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4882 sym_op->xform->cipher.op = cipher_op;
4883 sym_op->xform->cipher.key.data = key;
4884 sym_op->xform->cipher.key.length = key_len;
4886 TEST_HEXDUMP(stdout, "key:", key, key_len);
4888 /* Setup Authentication Parameters */
4889 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
4890 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
4891 sym_op->xform->next->auth.op = auth_op;
4892 sym_op->xform->next->auth.digest_length = auth_len;
4893 sym_op->xform->next->auth.add_auth_data_length = aad_len;
4894 sym_op->xform->next->auth.key.length = 0;
4895 sym_op->xform->next->auth.key.data = NULL;
4896 sym_op->xform->next->next = NULL;
4902 create_gcm_operation(enum rte_crypto_cipher_operation op,
4903 const struct gcm_test_data *tdata)
4905 struct crypto_testsuite_params *ts_params = &testsuite_params;
4906 struct crypto_unittest_params *ut_params = &unittest_params;
4908 uint8_t *plaintext, *ciphertext;
4909 unsigned int iv_pad_len, aad_pad_len, plaintext_pad_len;
4911 /* Generate Crypto op data structure */
4912 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4913 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4914 TEST_ASSERT_NOT_NULL(ut_params->op,
4915 "Failed to allocate symmetric crypto operation struct");
4917 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4919 /* Append aad data */
4920 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4921 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4923 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4924 "no room to append aad");
4926 sym_op->auth.aad.length = tdata->aad.len;
4927 sym_op->auth.aad.phys_addr =
4928 rte_pktmbuf_mtophys(ut_params->ibuf);
4929 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
4930 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data,
4931 sym_op->auth.aad.length);
4934 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
4935 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4936 ut_params->ibuf, iv_pad_len);
4937 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4939 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4940 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4941 sym_op->cipher.iv.length = tdata->iv.len;
4943 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
4944 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data,
4945 sym_op->cipher.iv.length);
4947 /* Append plaintext/ciphertext */
4948 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
4949 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4950 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4952 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
4954 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
4955 TEST_HEXDUMP(stdout, "plaintext:", plaintext,
4956 tdata->plaintext.len);
4958 if (ut_params->obuf) {
4959 ciphertext = (uint8_t *)rte_pktmbuf_append(
4961 plaintext_pad_len + aad_pad_len +
4963 TEST_ASSERT_NOT_NULL(ciphertext,
4964 "no room to append ciphertext");
4966 memset(ciphertext + aad_pad_len + iv_pad_len, 0,
4967 tdata->ciphertext.len);
4970 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
4971 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4973 TEST_ASSERT_NOT_NULL(ciphertext,
4974 "no room to append ciphertext");
4976 memcpy(ciphertext, tdata->ciphertext.data,
4977 tdata->ciphertext.len);
4978 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext,
4979 tdata->ciphertext.len);
4981 if (ut_params->obuf) {
4982 plaintext = (uint8_t *)rte_pktmbuf_append(
4984 plaintext_pad_len + aad_pad_len +
4986 TEST_ASSERT_NOT_NULL(plaintext,
4987 "no room to append plaintext");
4989 memset(plaintext + aad_pad_len + iv_pad_len, 0,
4990 tdata->plaintext.len);
4994 /* Append digest data */
4995 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
4996 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4997 ut_params->obuf ? ut_params->obuf :
4999 tdata->auth_tag.len);
5000 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5001 "no room to append digest");
5002 memset(sym_op->auth.digest.data, 0, tdata->auth_tag.len);
5003 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5004 ut_params->obuf ? ut_params->obuf :
5007 aad_pad_len + iv_pad_len);
5008 sym_op->auth.digest.length = tdata->auth_tag.len;
5010 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5011 ut_params->ibuf, tdata->auth_tag.len);
5012 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5013 "no room to append digest");
5014 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5016 plaintext_pad_len + aad_pad_len + iv_pad_len);
5017 sym_op->auth.digest.length = tdata->auth_tag.len;
5019 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data,
5020 tdata->auth_tag.len);
5021 TEST_HEXDUMP(stdout, "digest:",
5022 sym_op->auth.digest.data,
5023 sym_op->auth.digest.length);
5026 sym_op->cipher.data.length = tdata->plaintext.len;
5027 sym_op->cipher.data.offset = aad_pad_len + iv_pad_len;
5029 sym_op->auth.data.length = tdata->plaintext.len;
5030 sym_op->auth.data.offset = aad_pad_len + iv_pad_len;
5036 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
5038 struct crypto_testsuite_params *ts_params = &testsuite_params;
5039 struct crypto_unittest_params *ut_params = &unittest_params;
5042 uint8_t *ciphertext, *auth_tag;
5043 uint16_t plaintext_pad_len;
5046 /* Create GCM session */
5047 retval = create_gcm_session(ts_params->valid_devs[0],
5048 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5049 tdata->key.data, tdata->key.len,
5050 tdata->aad.len, tdata->auth_tag.len,
5051 RTE_CRYPTO_AUTH_OP_GENERATE);
5055 if (tdata->aad.len > MBUF_SIZE) {
5056 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5057 /* Populate full size of add data */
5058 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
5059 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5061 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5063 /* clear mbuf payload */
5064 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5065 rte_pktmbuf_tailroom(ut_params->ibuf));
5067 /* Create GCM operation */
5068 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
5072 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5074 ut_params->op->sym->m_src = ut_params->ibuf;
5076 /* Process crypto operation */
5077 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5078 ut_params->op), "failed to process sym crypto op");
5080 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5081 "crypto op processing failed");
5083 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5085 if (ut_params->op->sym->m_dst) {
5086 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5088 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5089 uint8_t *, plaintext_pad_len);
5091 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5093 ut_params->op->sym->cipher.data.offset);
5094 auth_tag = ciphertext + plaintext_pad_len;
5097 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5098 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5101 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5103 tdata->ciphertext.data,
5104 tdata->ciphertext.len,
5105 "GCM Ciphertext data not as expected");
5107 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5109 tdata->auth_tag.data,
5110 tdata->auth_tag.len,
5111 "GCM Generated auth tag not as expected");
5118 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
5120 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
5124 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
5126 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
5130 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
5132 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
5136 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
5138 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
5142 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
5144 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
5148 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
5150 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
5154 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
5156 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
5160 test_mb_AES_GCM_auth_encryption_test_case_256_1(void)
5162 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_1);
5166 test_mb_AES_GCM_auth_encryption_test_case_256_2(void)
5168 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_2);
5172 test_mb_AES_GCM_auth_encryption_test_case_256_3(void)
5174 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_3);
5178 test_mb_AES_GCM_auth_encryption_test_case_256_4(void)
5180 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_4);
5184 test_mb_AES_GCM_auth_encryption_test_case_256_5(void)
5186 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_5);
5190 test_mb_AES_GCM_auth_encryption_test_case_256_6(void)
5192 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_6);
5196 test_mb_AES_GCM_auth_encryption_test_case_256_7(void)
5198 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_256_7);
5202 test_mb_AES_GCM_auth_encryption_test_case_aad_1(void)
5204 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_1);
5208 test_mb_AES_GCM_auth_encryption_test_case_aad_2(void)
5210 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_aad_2);
5214 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
5216 struct crypto_testsuite_params *ts_params = &testsuite_params;
5217 struct crypto_unittest_params *ut_params = &unittest_params;
5223 /* Create GCM session */
5224 retval = create_gcm_session(ts_params->valid_devs[0],
5225 RTE_CRYPTO_CIPHER_OP_DECRYPT,
5226 tdata->key.data, tdata->key.len,
5227 tdata->aad.len, tdata->auth_tag.len,
5228 RTE_CRYPTO_AUTH_OP_VERIFY);
5232 /* alloc mbuf and set payload */
5233 if (tdata->aad.len > MBUF_SIZE) {
5234 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5235 /* Populate full size of add data */
5236 for (i = 32; i < GCM_MAX_AAD_LENGTH; i += 32)
5237 memcpy(&tdata->aad.data[i], &tdata->aad.data[0], 32);
5239 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5241 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5242 rte_pktmbuf_tailroom(ut_params->ibuf));
5244 /* Create GCM operation */
5245 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
5249 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5251 ut_params->op->sym->m_src = ut_params->ibuf;
5253 /* Process crypto operation */
5254 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5255 ut_params->op), "failed to process sym crypto op");
5257 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5258 "crypto op processing failed");
5260 if (ut_params->op->sym->m_dst)
5261 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
5264 plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
5266 ut_params->op->sym->cipher.data.offset);
5268 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5271 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5273 tdata->plaintext.data,
5274 tdata->plaintext.len,
5275 "GCM plaintext data not as expected");
5277 TEST_ASSERT_EQUAL(ut_params->op->status,
5278 RTE_CRYPTO_OP_STATUS_SUCCESS,
5279 "GCM authentication failed");
5284 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
5286 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
5290 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
5292 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
5296 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
5298 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
5302 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
5304 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
5308 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
5310 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
5314 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
5316 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
5320 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
5322 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
5326 test_mb_AES_GCM_auth_decryption_test_case_256_1(void)
5328 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_1);
5332 test_mb_AES_GCM_auth_decryption_test_case_256_2(void)
5334 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_2);
5338 test_mb_AES_GCM_auth_decryption_test_case_256_3(void)
5340 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_3);
5344 test_mb_AES_GCM_auth_decryption_test_case_256_4(void)
5346 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_4);
5350 test_mb_AES_GCM_auth_decryption_test_case_256_5(void)
5352 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_5);
5356 test_mb_AES_GCM_auth_decryption_test_case_256_6(void)
5358 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_6);
5362 test_mb_AES_GCM_auth_decryption_test_case_256_7(void)
5364 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_256_7);
5368 test_mb_AES_GCM_auth_decryption_test_case_aad_1(void)
5370 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_1);
5374 test_mb_AES_GCM_auth_decryption_test_case_aad_2(void)
5376 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_aad_2);
5380 test_AES_GCM_authenticated_encryption_oop(const struct gcm_test_data *tdata)
5382 struct crypto_testsuite_params *ts_params = &testsuite_params;
5383 struct crypto_unittest_params *ut_params = &unittest_params;
5386 uint8_t *ciphertext, *auth_tag;
5387 uint16_t plaintext_pad_len;
5389 /* Create GCM session */
5390 retval = create_gcm_session(ts_params->valid_devs[0],
5391 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5392 tdata->key.data, tdata->key.len,
5393 tdata->aad.len, tdata->auth_tag.len,
5394 RTE_CRYPTO_AUTH_OP_GENERATE);
5398 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5399 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5401 /* clear mbuf payload */
5402 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5403 rte_pktmbuf_tailroom(ut_params->ibuf));
5404 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5405 rte_pktmbuf_tailroom(ut_params->obuf));
5407 /* Create GCM operation */
5408 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
5412 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5414 ut_params->op->sym->m_src = ut_params->ibuf;
5415 ut_params->op->sym->m_dst = ut_params->obuf;
5417 /* Process crypto operation */
5418 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5419 ut_params->op), "failed to process sym crypto op");
5421 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5422 "crypto op processing failed");
5424 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5426 ciphertext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5427 ut_params->op->sym->cipher.data.offset);
5428 auth_tag = ciphertext + plaintext_pad_len;
5430 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5431 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5434 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5436 tdata->ciphertext.data,
5437 tdata->ciphertext.len,
5438 "GCM Ciphertext data not as expected");
5440 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5442 tdata->auth_tag.data,
5443 tdata->auth_tag.len,
5444 "GCM Generated auth tag not as expected");
5451 test_mb_AES_GCM_authenticated_encryption_oop(void)
5453 return test_AES_GCM_authenticated_encryption_oop(&gcm_test_case_5);
5457 test_AES_GCM_authenticated_decryption_oop(const struct gcm_test_data *tdata)
5459 struct crypto_testsuite_params *ts_params = &testsuite_params;
5460 struct crypto_unittest_params *ut_params = &unittest_params;
5465 /* Create GCM session */
5466 retval = create_gcm_session(ts_params->valid_devs[0],
5467 RTE_CRYPTO_CIPHER_OP_DECRYPT,
5468 tdata->key.data, tdata->key.len,
5469 tdata->aad.len, tdata->auth_tag.len,
5470 RTE_CRYPTO_AUTH_OP_VERIFY);
5474 /* alloc mbuf and set payload */
5475 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5476 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5478 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5479 rte_pktmbuf_tailroom(ut_params->ibuf));
5480 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
5481 rte_pktmbuf_tailroom(ut_params->obuf));
5483 /* Create GCM operation */
5484 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
5488 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5490 ut_params->op->sym->m_src = ut_params->ibuf;
5491 ut_params->op->sym->m_dst = ut_params->obuf;
5493 /* Process crypto operation */
5494 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5495 ut_params->op), "failed to process sym crypto op");
5497 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5498 "crypto op processing failed");
5500 plaintext = rte_pktmbuf_mtod_offset(ut_params->obuf, uint8_t *,
5501 ut_params->op->sym->cipher.data.offset);
5503 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5506 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5508 tdata->plaintext.data,
5509 tdata->plaintext.len,
5510 "GCM plaintext data not as expected");
5512 TEST_ASSERT_EQUAL(ut_params->op->status,
5513 RTE_CRYPTO_OP_STATUS_SUCCESS,
5514 "GCM authentication failed");
5519 test_mb_AES_GCM_authenticated_decryption_oop(void)
5521 return test_AES_GCM_authenticated_decryption_oop(&gcm_test_case_5);
5525 test_AES_GCM_authenticated_encryption_sessionless(
5526 const struct gcm_test_data *tdata)
5528 struct crypto_testsuite_params *ts_params = &testsuite_params;
5529 struct crypto_unittest_params *ut_params = &unittest_params;
5532 uint8_t *ciphertext, *auth_tag;
5533 uint16_t plaintext_pad_len;
5534 uint8_t key[tdata->key.len + 1];
5536 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5538 /* clear mbuf payload */
5539 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5540 rte_pktmbuf_tailroom(ut_params->ibuf));
5542 /* Create GCM operation */
5543 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT, tdata);
5547 /* Create GCM xforms */
5548 memcpy(key, tdata->key.data, tdata->key.len);
5549 retval = create_gcm_xforms(ut_params->op,
5550 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5551 key, tdata->key.len,
5552 tdata->aad.len, tdata->auth_tag.len,
5553 RTE_CRYPTO_AUTH_OP_GENERATE);
5557 ut_params->op->sym->m_src = ut_params->ibuf;
5559 TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type,
5560 RTE_CRYPTO_SYM_OP_SESSIONLESS,
5561 "crypto op session type not sessionless");
5563 /* Process crypto operation */
5564 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5565 ut_params->op), "failed to process sym crypto op");
5567 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5569 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5570 "crypto op status not success");
5572 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
5574 ciphertext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5575 ut_params->op->sym->cipher.data.offset);
5576 auth_tag = ciphertext + plaintext_pad_len;
5578 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
5579 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
5582 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5584 tdata->ciphertext.data,
5585 tdata->ciphertext.len,
5586 "GCM Ciphertext data not as expected");
5588 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5590 tdata->auth_tag.data,
5591 tdata->auth_tag.len,
5592 "GCM Generated auth tag not as expected");
5599 test_mb_AES_GCM_authenticated_encryption_sessionless(void)
5601 return test_AES_GCM_authenticated_encryption_sessionless(
5606 test_AES_GCM_authenticated_decryption_sessionless(
5607 const struct gcm_test_data *tdata)
5609 struct crypto_testsuite_params *ts_params = &testsuite_params;
5610 struct crypto_unittest_params *ut_params = &unittest_params;
5614 uint8_t key[tdata->key.len + 1];
5616 /* alloc mbuf and set payload */
5617 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5619 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5620 rte_pktmbuf_tailroom(ut_params->ibuf));
5622 /* Create GCM operation */
5623 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT, tdata);
5627 /* Create GCM xforms */
5628 memcpy(key, tdata->key.data, tdata->key.len);
5629 retval = create_gcm_xforms(ut_params->op,
5630 RTE_CRYPTO_CIPHER_OP_DECRYPT,
5631 key, tdata->key.len,
5632 tdata->aad.len, tdata->auth_tag.len,
5633 RTE_CRYPTO_AUTH_OP_VERIFY);
5637 ut_params->op->sym->m_src = ut_params->ibuf;
5639 TEST_ASSERT_EQUAL(ut_params->op->sym->sess_type,
5640 RTE_CRYPTO_SYM_OP_SESSIONLESS,
5641 "crypto op session type not sessionless");
5643 /* Process crypto operation */
5644 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5645 ut_params->op), "failed to process sym crypto op");
5647 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
5649 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5650 "crypto op status not success");
5652 plaintext = rte_pktmbuf_mtod_offset(ut_params->ibuf, uint8_t *,
5653 ut_params->op->sym->cipher.data.offset);
5655 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
5658 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5660 tdata->plaintext.data,
5661 tdata->plaintext.len,
5662 "GCM plaintext data not as expected");
5664 TEST_ASSERT_EQUAL(ut_params->op->status,
5665 RTE_CRYPTO_OP_STATUS_SUCCESS,
5666 "GCM authentication failed");
5671 test_mb_AES_GCM_authenticated_decryption_sessionless(void)
5673 return test_AES_GCM_authenticated_decryption_sessionless(
5680 struct crypto_testsuite_params *ts_params = &testsuite_params;
5681 struct rte_cryptodev_stats stats;
5682 struct rte_cryptodev *dev;
5683 cryptodev_stats_get_t temp_pfn;
5685 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5686 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
5687 &stats) == -ENODEV),
5688 "rte_cryptodev_stats_get invalid dev failed");
5689 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
5690 "rte_cryptodev_stats_get invalid Param failed");
5691 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
5692 temp_pfn = dev->dev_ops->stats_get;
5693 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
5694 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
5696 "rte_cryptodev_stats_get invalid Param failed");
5697 dev->dev_ops->stats_get = temp_pfn;
5699 /* Test expected values */
5701 test_AES_CBC_HMAC_SHA1_encrypt_digest();
5703 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5705 "rte_cryptodev_stats_get failed");
5706 TEST_ASSERT((stats.enqueued_count == 1),
5707 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5708 TEST_ASSERT((stats.dequeued_count == 1),
5709 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5710 TEST_ASSERT((stats.enqueue_err_count == 0),
5711 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5712 TEST_ASSERT((stats.dequeue_err_count == 0),
5713 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5715 /* invalid device but should ignore and not reset device stats*/
5716 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
5717 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5719 "rte_cryptodev_stats_get failed");
5720 TEST_ASSERT((stats.enqueued_count == 1),
5721 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5723 /* check that a valid reset clears stats */
5724 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
5725 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
5727 "rte_cryptodev_stats_get failed");
5728 TEST_ASSERT((stats.enqueued_count == 0),
5729 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5730 TEST_ASSERT((stats.dequeued_count == 0),
5731 "rte_cryptodev_stats_get returned unexpected enqueued stat");
5733 return TEST_SUCCESS;
5736 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
5737 struct crypto_unittest_params *ut_params,
5738 enum rte_crypto_auth_operation op,
5739 const struct HMAC_MD5_vector *test_case)
5743 memcpy(key, test_case->key.data, test_case->key.len);
5745 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5746 ut_params->auth_xform.next = NULL;
5747 ut_params->auth_xform.auth.op = op;
5749 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
5751 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
5752 ut_params->auth_xform.auth.add_auth_data_length = 0;
5753 ut_params->auth_xform.auth.key.length = test_case->key.len;
5754 ut_params->auth_xform.auth.key.data = key;
5756 ut_params->sess = rte_cryptodev_sym_session_create(
5757 ts_params->valid_devs[0], &ut_params->auth_xform);
5759 if (ut_params->sess == NULL)
5762 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5764 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5765 rte_pktmbuf_tailroom(ut_params->ibuf));
5770 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
5771 const struct HMAC_MD5_vector *test_case,
5772 uint8_t **plaintext)
5774 uint16_t plaintext_pad_len;
5776 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5778 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5781 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5783 memcpy(*plaintext, test_case->plaintext.data,
5784 test_case->plaintext.len);
5786 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5787 ut_params->ibuf, MD5_DIGEST_LEN);
5788 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5789 "no room to append digest");
5790 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5791 ut_params->ibuf, plaintext_pad_len);
5792 sym_op->auth.digest.length = MD5_DIGEST_LEN;
5794 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5795 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
5796 test_case->auth_tag.len);
5799 sym_op->auth.data.offset = 0;
5800 sym_op->auth.data.length = test_case->plaintext.len;
5802 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5803 ut_params->op->sym->m_src = ut_params->ibuf;
5809 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
5811 uint16_t plaintext_pad_len;
5812 uint8_t *plaintext, *auth_tag;
5814 struct crypto_testsuite_params *ts_params = &testsuite_params;
5815 struct crypto_unittest_params *ut_params = &unittest_params;
5817 if (MD5_HMAC_create_session(ts_params, ut_params,
5818 RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
5821 /* Generate Crypto op data structure */
5822 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5823 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5824 TEST_ASSERT_NOT_NULL(ut_params->op,
5825 "Failed to allocate symmetric crypto operation struct");
5827 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
5830 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5833 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5834 ut_params->op), "failed to process sym crypto op");
5836 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5837 "crypto op processing failed");
5839 if (ut_params->op->sym->m_dst) {
5840 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5841 uint8_t *, plaintext_pad_len);
5843 auth_tag = plaintext + plaintext_pad_len;
5846 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5848 test_case->auth_tag.data,
5849 test_case->auth_tag.len,
5850 "HMAC_MD5 generated tag not as expected");
5852 return TEST_SUCCESS;
5856 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
5860 struct crypto_testsuite_params *ts_params = &testsuite_params;
5861 struct crypto_unittest_params *ut_params = &unittest_params;
5863 if (MD5_HMAC_create_session(ts_params, ut_params,
5864 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
5868 /* Generate Crypto op data structure */
5869 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5870 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5871 TEST_ASSERT_NOT_NULL(ut_params->op,
5872 "Failed to allocate symmetric crypto operation struct");
5874 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
5877 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5878 ut_params->op), "failed to process sym crypto op");
5880 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5881 "HMAC_MD5 crypto op processing failed");
5883 return TEST_SUCCESS;
5887 test_MD5_HMAC_generate_case_1(void)
5889 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
5893 test_MD5_HMAC_verify_case_1(void)
5895 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
5899 test_MD5_HMAC_generate_case_2(void)
5901 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
5905 test_MD5_HMAC_verify_case_2(void)
5907 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
5911 test_multi_session(void)
5913 struct crypto_testsuite_params *ts_params = &testsuite_params;
5914 struct crypto_unittest_params *ut_params = &unittest_params;
5916 struct rte_cryptodev_info dev_info;
5917 struct rte_cryptodev_sym_session **sessions;
5921 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
5922 aes_cbc_key, hmac_sha512_key);
5925 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5927 sessions = rte_malloc(NULL,
5928 (sizeof(struct rte_cryptodev_sym_session *) *
5929 dev_info.sym.max_nb_sessions) + 1, 0);
5931 /* Create multiple crypto sessions*/
5932 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
5933 sessions[i] = rte_cryptodev_sym_session_create(
5934 ts_params->valid_devs[0],
5935 &ut_params->auth_xform);
5936 TEST_ASSERT_NOT_NULL(sessions[i],
5937 "Session creation failed at session number %u",
5940 /* Attempt to send a request on each session */
5941 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
5945 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
5946 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
5948 "Failed to perform decrypt on request number %u.", i);
5949 /* free crypto operation structure */
5951 rte_crypto_op_free(ut_params->op);
5954 * free mbuf - both obuf and ibuf are usually the same,
5955 * so check if they point at the same address is necessary,
5956 * to avoid freeing the mbuf twice.
5958 if (ut_params->obuf) {
5959 rte_pktmbuf_free(ut_params->obuf);
5960 if (ut_params->ibuf == ut_params->obuf)
5961 ut_params->ibuf = 0;
5962 ut_params->obuf = 0;
5964 if (ut_params->ibuf) {
5965 rte_pktmbuf_free(ut_params->ibuf);
5966 ut_params->ibuf = 0;
5970 /* Next session create should fail */
5971 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
5972 &ut_params->auth_xform);
5973 TEST_ASSERT_NULL(sessions[i],
5974 "Session creation succeeded unexpectedly!");
5976 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
5977 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
5982 return TEST_SUCCESS;
5985 struct multi_session_params {
5986 struct crypto_unittest_params ut_params;
5987 uint8_t *cipher_key;
5989 const uint8_t *cipher;
5990 const uint8_t *digest;
5994 #define MB_SESSION_NUMBER 3
5997 test_multi_session_random_usage(void)
5999 struct crypto_testsuite_params *ts_params = &testsuite_params;
6000 struct rte_cryptodev_info dev_info;
6001 struct rte_cryptodev_sym_session **sessions;
6003 struct multi_session_params ut_paramz[] = {
6006 .cipher_key = ms_aes_cbc_key0,
6007 .hmac_key = ms_hmac_key0,
6008 .cipher = ms_aes_cbc_cipher0,
6009 .digest = ms_hmac_digest0,
6010 .iv = ms_aes_cbc_iv0
6013 .cipher_key = ms_aes_cbc_key1,
6014 .hmac_key = ms_hmac_key1,
6015 .cipher = ms_aes_cbc_cipher1,
6016 .digest = ms_hmac_digest1,
6017 .iv = ms_aes_cbc_iv1
6020 .cipher_key = ms_aes_cbc_key2,
6021 .hmac_key = ms_hmac_key2,
6022 .cipher = ms_aes_cbc_cipher2,
6023 .digest = ms_hmac_digest2,
6024 .iv = ms_aes_cbc_iv2
6029 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
6031 sessions = rte_malloc(NULL,
6032 (sizeof(struct rte_cryptodev_sym_session *)
6033 * dev_info.sym.max_nb_sessions) + 1, 0);
6035 for (i = 0; i < MB_SESSION_NUMBER; i++) {
6036 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
6037 sizeof(struct crypto_unittest_params));
6039 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
6040 &ut_paramz[i].ut_params,
6041 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
6043 /* Create multiple crypto sessions*/
6044 sessions[i] = rte_cryptodev_sym_session_create(
6045 ts_params->valid_devs[0],
6046 &ut_paramz[i].ut_params.auth_xform);
6048 TEST_ASSERT_NOT_NULL(sessions[i],
6049 "Session creation failed at session number %u",
6055 for (i = 0; i < 40000; i++) {
6057 j = rand() % MB_SESSION_NUMBER;
6059 TEST_ASSERT_SUCCESS(
6060 test_AES_CBC_HMAC_SHA512_decrypt_perform(
6062 &ut_paramz[j].ut_params,
6063 ts_params, ut_paramz[j].cipher,
6064 ut_paramz[j].digest,
6066 "Failed to perform decrypt on request number %u.", i);
6068 if (ut_paramz[j].ut_params.op)
6069 rte_crypto_op_free(ut_paramz[j].ut_params.op);
6072 * free mbuf - both obuf and ibuf are usually the same,
6073 * so check if they point at the same address is necessary,
6074 * to avoid freeing the mbuf twice.
6076 if (ut_paramz[j].ut_params.obuf) {
6077 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
6078 if (ut_paramz[j].ut_params.ibuf
6079 == ut_paramz[j].ut_params.obuf)
6080 ut_paramz[j].ut_params.ibuf = 0;
6081 ut_paramz[j].ut_params.obuf = 0;
6083 if (ut_paramz[j].ut_params.ibuf) {
6084 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
6085 ut_paramz[j].ut_params.ibuf = 0;
6089 for (i = 0; i < MB_SESSION_NUMBER; i++)
6090 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
6095 return TEST_SUCCESS;
6099 test_null_cipher_only_operation(void)
6101 struct crypto_testsuite_params *ts_params = &testsuite_params;
6102 struct crypto_unittest_params *ut_params = &unittest_params;
6104 /* Generate test mbuf data and space for digest */
6105 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6106 catch_22_quote, QUOTE_512_BYTES, 0);
6108 /* Setup Cipher Parameters */
6109 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6110 ut_params->cipher_xform.next = NULL;
6112 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6113 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6115 /* Create Crypto session*/
6116 ut_params->sess = rte_cryptodev_sym_session_create(
6117 ts_params->valid_devs[0], &ut_params->cipher_xform);
6118 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6120 /* Generate Crypto op data structure */
6121 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6122 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6123 TEST_ASSERT_NOT_NULL(ut_params->op,
6124 "Failed to allocate symmetric crypto operation struct");
6126 /* Set crypto operation data parameters */
6127 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6129 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6131 /* set crypto operation source mbuf */
6132 sym_op->m_src = ut_params->ibuf;
6134 sym_op->cipher.data.offset = 0;
6135 sym_op->cipher.data.length = QUOTE_512_BYTES;
6137 /* Process crypto operation */
6138 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6140 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6142 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6143 "crypto operation processing failed");
6146 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6147 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6150 "Ciphertext data not as expected");
6152 return TEST_SUCCESS;
6156 test_null_auth_only_operation(void)
6158 struct crypto_testsuite_params *ts_params = &testsuite_params;
6159 struct crypto_unittest_params *ut_params = &unittest_params;
6161 /* Generate test mbuf data and space for digest */
6162 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6163 catch_22_quote, QUOTE_512_BYTES, 0);
6165 /* Setup HMAC Parameters */
6166 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6167 ut_params->auth_xform.next = NULL;
6169 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6170 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6172 /* Create Crypto session*/
6173 ut_params->sess = rte_cryptodev_sym_session_create(
6174 ts_params->valid_devs[0], &ut_params->auth_xform);
6175 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6177 /* Generate Crypto op data structure */
6178 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6179 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6180 TEST_ASSERT_NOT_NULL(ut_params->op,
6181 "Failed to allocate symmetric crypto operation struct");
6183 /* Set crypto operation data parameters */
6184 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6186 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6188 sym_op->m_src = ut_params->ibuf;
6190 sym_op->auth.data.offset = 0;
6191 sym_op->auth.data.length = QUOTE_512_BYTES;
6193 /* Process crypto operation */
6194 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6196 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6198 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6199 "crypto operation processing failed");
6201 return TEST_SUCCESS;
6205 test_null_cipher_auth_operation(void)
6207 struct crypto_testsuite_params *ts_params = &testsuite_params;
6208 struct crypto_unittest_params *ut_params = &unittest_params;
6210 /* Generate test mbuf data and space for digest */
6211 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6212 catch_22_quote, QUOTE_512_BYTES, 0);
6214 /* Setup Cipher Parameters */
6215 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6216 ut_params->cipher_xform.next = &ut_params->auth_xform;
6218 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6219 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6221 /* Setup HMAC Parameters */
6222 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6223 ut_params->auth_xform.next = NULL;
6225 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6226 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6228 /* Create Crypto session*/
6229 ut_params->sess = rte_cryptodev_sym_session_create(
6230 ts_params->valid_devs[0], &ut_params->cipher_xform);
6231 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6233 /* Generate Crypto op data structure */
6234 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6235 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6236 TEST_ASSERT_NOT_NULL(ut_params->op,
6237 "Failed to allocate symmetric crypto operation struct");
6239 /* Set crypto operation data parameters */
6240 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6242 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6244 sym_op->m_src = ut_params->ibuf;
6246 sym_op->cipher.data.offset = 0;
6247 sym_op->cipher.data.length = QUOTE_512_BYTES;
6249 sym_op->auth.data.offset = 0;
6250 sym_op->auth.data.length = QUOTE_512_BYTES;
6252 /* Process crypto operation */
6253 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6255 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6257 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6258 "crypto operation processing failed");
6261 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6262 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6265 "Ciphertext data not as expected");
6267 return TEST_SUCCESS;
6271 test_null_auth_cipher_operation(void)
6273 struct crypto_testsuite_params *ts_params = &testsuite_params;
6274 struct crypto_unittest_params *ut_params = &unittest_params;
6276 /* Generate test mbuf data and space for digest */
6277 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
6278 catch_22_quote, QUOTE_512_BYTES, 0);
6280 /* Setup Cipher Parameters */
6281 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6282 ut_params->cipher_xform.next = NULL;
6284 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6285 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6287 /* Setup HMAC Parameters */
6288 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6289 ut_params->auth_xform.next = &ut_params->cipher_xform;
6291 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6292 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6294 /* Create Crypto session*/
6295 ut_params->sess = rte_cryptodev_sym_session_create(
6296 ts_params->valid_devs[0], &ut_params->cipher_xform);
6297 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6299 /* Generate Crypto op data structure */
6300 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6301 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6302 TEST_ASSERT_NOT_NULL(ut_params->op,
6303 "Failed to allocate symmetric crypto operation struct");
6305 /* Set crypto operation data parameters */
6306 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6308 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6310 sym_op->m_src = ut_params->ibuf;
6312 sym_op->cipher.data.offset = 0;
6313 sym_op->cipher.data.length = QUOTE_512_BYTES;
6315 sym_op->auth.data.offset = 0;
6316 sym_op->auth.data.length = QUOTE_512_BYTES;
6318 /* Process crypto operation */
6319 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6321 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
6323 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6324 "crypto operation processing failed");
6327 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6328 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
6331 "Ciphertext data not as expected");
6333 return TEST_SUCCESS;
6338 test_null_invalid_operation(void)
6340 struct crypto_testsuite_params *ts_params = &testsuite_params;
6341 struct crypto_unittest_params *ut_params = &unittest_params;
6343 /* Setup Cipher Parameters */
6344 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6345 ut_params->cipher_xform.next = NULL;
6347 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
6348 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6350 /* Create Crypto session*/
6351 ut_params->sess = rte_cryptodev_sym_session_create(
6352 ts_params->valid_devs[0], &ut_params->cipher_xform);
6353 TEST_ASSERT_NULL(ut_params->sess,
6354 "Session creation succeeded unexpectedly");
6357 /* Setup HMAC Parameters */
6358 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6359 ut_params->auth_xform.next = NULL;
6361 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
6362 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6364 /* Create Crypto session*/
6365 ut_params->sess = rte_cryptodev_sym_session_create(
6366 ts_params->valid_devs[0], &ut_params->auth_xform);
6367 TEST_ASSERT_NULL(ut_params->sess,
6368 "Session creation succeeded unexpectedly");
6370 return TEST_SUCCESS;
6374 #define NULL_BURST_LENGTH (32)
6377 test_null_burst_operation(void)
6379 struct crypto_testsuite_params *ts_params = &testsuite_params;
6380 struct crypto_unittest_params *ut_params = &unittest_params;
6382 unsigned i, burst_len = NULL_BURST_LENGTH;
6384 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
6385 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
6387 /* Setup Cipher Parameters */
6388 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6389 ut_params->cipher_xform.next = &ut_params->auth_xform;
6391 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
6392 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
6394 /* Setup HMAC Parameters */
6395 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6396 ut_params->auth_xform.next = NULL;
6398 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
6399 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
6401 /* Create Crypto session*/
6402 ut_params->sess = rte_cryptodev_sym_session_create(
6403 ts_params->valid_devs[0], &ut_params->cipher_xform);
6404 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6406 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
6407 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
6408 burst_len, "failed to generate burst of crypto ops");
6410 /* Generate an operation for each mbuf in burst */
6411 for (i = 0; i < burst_len; i++) {
6412 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6414 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
6416 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
6420 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
6422 burst[i]->sym->m_src = m;
6425 /* Process crypto operation */
6426 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
6427 0, burst, burst_len),
6429 "Error enqueuing burst");
6431 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
6432 0, burst_dequeued, burst_len),
6434 "Error dequeuing burst");
6437 for (i = 0; i < burst_len; i++) {
6439 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
6440 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
6442 "data not as expected");
6444 rte_pktmbuf_free(burst[i]->sym->m_src);
6445 rte_crypto_op_free(burst[i]);
6448 return TEST_SUCCESS;
6452 generate_gmac_large_plaintext(uint8_t *data)
6456 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
6457 memcpy(&data[i], &data[0], 32);
6461 create_gmac_operation(enum rte_crypto_auth_operation op,
6462 const struct gmac_test_data *tdata)
6464 struct crypto_testsuite_params *ts_params = &testsuite_params;
6465 struct crypto_unittest_params *ut_params = &unittest_params;
6466 struct rte_crypto_sym_op *sym_op;
6468 unsigned iv_pad_len;
6469 unsigned aad_pad_len;
6471 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
6472 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
6475 * Runtime generate the large plain text instead of use hard code
6476 * plain text vector. It is done to avoid create huge source file
6477 * with the test vector.
6479 if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH)
6480 generate_gmac_large_plaintext(tdata->aad.data);
6482 /* Generate Crypto op data structure */
6483 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6484 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6485 TEST_ASSERT_NOT_NULL(ut_params->op,
6486 "Failed to allocate symmetric crypto operation struct");
6488 sym_op = ut_params->op->sym;
6489 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6491 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
6492 "no room to append aad");
6494 sym_op->auth.aad.length = tdata->aad.len;
6495 sym_op->auth.aad.phys_addr =
6496 rte_pktmbuf_mtophys(ut_params->ibuf);
6497 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
6499 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6500 ut_params->ibuf, tdata->gmac_tag.len);
6501 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6502 "no room to append digest");
6504 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6505 ut_params->ibuf, aad_pad_len);
6506 sym_op->auth.digest.length = tdata->gmac_tag.len;
6508 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
6509 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
6510 tdata->gmac_tag.len);
6511 TEST_HEXDUMP(stdout, "digest:",
6512 sym_op->auth.digest.data,
6513 sym_op->auth.digest.length);
6516 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6517 ut_params->ibuf, iv_pad_len);
6518 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
6520 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
6521 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6522 sym_op->cipher.iv.length = tdata->iv.len;
6524 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
6526 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
6528 sym_op->cipher.data.length = 0;
6529 sym_op->cipher.data.offset = 0;
6531 sym_op->auth.data.offset = 0;
6532 sym_op->auth.data.length = 0;
6537 static int create_gmac_session(uint8_t dev_id,
6538 enum rte_crypto_cipher_operation op,
6539 const struct gmac_test_data *tdata,
6540 enum rte_crypto_auth_operation auth_op)
6542 uint8_t cipher_key[tdata->key.len];
6544 struct crypto_unittest_params *ut_params = &unittest_params;
6546 memcpy(cipher_key, tdata->key.data, tdata->key.len);
6548 /* For GMAC we setup cipher parameters */
6549 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6550 ut_params->cipher_xform.next = NULL;
6551 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
6552 ut_params->cipher_xform.cipher.op = op;
6553 ut_params->cipher_xform.cipher.key.data = cipher_key;
6554 ut_params->cipher_xform.cipher.key.length = tdata->key.len;
6556 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6557 ut_params->auth_xform.next = NULL;
6559 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
6560 ut_params->auth_xform.auth.op = auth_op;
6561 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
6562 ut_params->auth_xform.auth.add_auth_data_length = 0;
6563 ut_params->auth_xform.auth.key.length = 0;
6564 ut_params->auth_xform.auth.key.data = NULL;
6566 ut_params->cipher_xform.next = &ut_params->auth_xform;
6568 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6569 &ut_params->cipher_xform);
6571 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6577 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
6579 struct crypto_testsuite_params *ts_params = &testsuite_params;
6580 struct crypto_unittest_params *ut_params = &unittest_params;
6584 uint8_t *auth_tag, *p;
6585 uint16_t aad_pad_len;
6587 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6588 "No GMAC length in the source data");
6590 retval = create_gmac_session(ts_params->valid_devs[0],
6591 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6592 tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
6597 if (tdata->aad.len > MBUF_SIZE)
6598 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6600 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6601 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6602 "Failed to allocate input buffer in mempool");
6604 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6605 rte_pktmbuf_tailroom(ut_params->ibuf));
6607 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
6609 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
6611 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
6617 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6619 ut_params->op->sym->m_src = ut_params->ibuf;
6621 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6622 ut_params->op), "failed to process sym crypto op");
6624 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6625 "crypto op processing failed");
6627 if (ut_params->op->sym->m_dst) {
6628 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6629 uint8_t *, aad_pad_len);
6631 auth_tag = p + aad_pad_len;
6634 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
6636 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6638 tdata->gmac_tag.data,
6639 tdata->gmac_tag.len,
6640 "GMAC Generated auth tag not as expected");
6646 test_AES_GMAC_authentication_test_case_1(void)
6648 return test_AES_GMAC_authentication(&gmac_test_case_1);
6652 test_AES_GMAC_authentication_test_case_2(void)
6654 return test_AES_GMAC_authentication(&gmac_test_case_2);
6658 test_AES_GMAC_authentication_test_case_3(void)
6660 return test_AES_GMAC_authentication(&gmac_test_case_3);
6664 test_AES_GMAC_authentication_test_case_4(void)
6666 return test_AES_GMAC_authentication(&gmac_test_case_4);
6670 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
6672 struct crypto_testsuite_params *ts_params = &testsuite_params;
6673 struct crypto_unittest_params *ut_params = &unittest_params;
6676 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
6677 "No GMAC length in the source data");
6679 retval = create_gmac_session(ts_params->valid_devs[0],
6680 RTE_CRYPTO_CIPHER_OP_DECRYPT,
6681 tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
6686 if (tdata->aad.len > MBUF_SIZE)
6687 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
6689 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6690 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6691 "Failed to allocate input buffer in mempool");
6693 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6694 rte_pktmbuf_tailroom(ut_params->ibuf));
6696 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
6702 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6704 ut_params->op->sym->m_src = ut_params->ibuf;
6706 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6707 ut_params->op), "failed to process sym crypto op");
6709 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6710 "crypto op processing failed");
6717 test_AES_GMAC_authentication_verify_test_case_1(void)
6719 return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
6723 test_AES_GMAC_authentication_verify_test_case_2(void)
6725 return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
6729 test_AES_GMAC_authentication_verify_test_case_3(void)
6731 return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
6735 test_AES_GMAC_authentication_verify_test_case_4(void)
6737 return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
6740 struct test_crypto_vector {
6741 enum rte_crypto_cipher_algorithm crypto_algo;
6754 const uint8_t *data;
6759 const uint8_t *data;
6763 enum rte_crypto_auth_algorithm auth_algo;
6771 const uint8_t *data;
6781 static const struct test_crypto_vector
6782 hmac_sha1_test_crypto_vector = {
6783 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6785 .data = plaintext_hash,
6790 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6791 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6792 0xDE, 0xF4, 0xDE, 0xAD
6798 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
6799 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
6800 0x3F, 0x91, 0x64, 0x59
6806 static const struct test_crypto_vector
6807 aes128_gmac_test_vector = {
6808 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
6809 .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM,
6811 .data = plaintext_hash,
6816 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6817 0x08, 0x09, 0x0A, 0x0B
6823 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6824 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
6830 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
6831 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
6837 static const struct test_crypto_vector
6838 aes128cbc_hmac_sha1_test_vector = {
6839 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
6842 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
6843 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
6849 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
6850 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
6855 .data = plaintext_hash,
6859 .data = ciphertext512_aes128cbc,
6862 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
6865 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
6866 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
6867 0xDE, 0xF4, 0xDE, 0xAD
6873 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
6874 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
6875 0x18, 0x8C, 0x1D, 0x32
6882 data_corruption(uint8_t *data)
6888 tag_corruption(uint8_t *data, unsigned int tag_offset)
6890 data[tag_offset] += 1;
6894 create_auth_session(struct crypto_unittest_params *ut_params,
6896 const struct test_crypto_vector *reference,
6897 enum rte_crypto_auth_operation auth_op)
6899 uint8_t auth_key[reference->auth_key.len + 1];
6901 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6903 /* Setup Authentication Parameters */
6904 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6905 ut_params->auth_xform.auth.op = auth_op;
6906 ut_params->auth_xform.next = NULL;
6907 ut_params->auth_xform.auth.algo = reference->auth_algo;
6908 ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6909 ut_params->auth_xform.auth.key.data = auth_key;
6910 ut_params->auth_xform.auth.digest_length = reference->digest.len;
6911 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
6913 /* Create Crypto session*/
6914 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6915 &ut_params->auth_xform);
6917 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6923 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
6925 const struct test_crypto_vector *reference,
6926 enum rte_crypto_auth_operation auth_op,
6927 enum rte_crypto_cipher_operation cipher_op)
6929 uint8_t cipher_key[reference->cipher_key.len + 1];
6930 uint8_t auth_key[reference->auth_key.len + 1];
6932 memcpy(cipher_key, reference->cipher_key.data,
6933 reference->cipher_key.len);
6934 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
6936 /* Setup Authentication Parameters */
6937 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
6938 ut_params->auth_xform.auth.op = auth_op;
6939 ut_params->auth_xform.next = &ut_params->cipher_xform;
6940 ut_params->auth_xform.auth.algo = reference->auth_algo;
6941 ut_params->auth_xform.auth.key.length = reference->auth_key.len;
6942 ut_params->auth_xform.auth.key.data = auth_key;
6943 ut_params->auth_xform.auth.digest_length = reference->digest.len;
6944 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
6946 /* Setup Cipher Parameters */
6947 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
6948 ut_params->cipher_xform.next = NULL;
6949 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
6950 ut_params->cipher_xform.cipher.op = cipher_op;
6951 ut_params->cipher_xform.cipher.key.data = cipher_key;
6952 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
6954 /* Create Crypto session*/
6955 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
6956 &ut_params->auth_xform);
6958 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
6964 create_auth_operation(struct crypto_testsuite_params *ts_params,
6965 struct crypto_unittest_params *ut_params,
6966 const struct test_crypto_vector *reference,
6967 unsigned int auth_generate)
6969 /* Generate Crypto op data structure */
6970 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6971 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6972 TEST_ASSERT_NOT_NULL(ut_params->op,
6973 "Failed to allocate pktmbuf offload");
6975 /* Set crypto operation data parameters */
6976 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6978 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6980 /* set crypto operation source mbuf */
6981 sym_op->m_src = ut_params->ibuf;
6984 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6985 ut_params->ibuf, reference->digest.len);
6987 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6988 "no room to append auth tag");
6990 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6991 ut_params->ibuf, reference->plaintext.len);
6992 sym_op->auth.digest.length = reference->digest.len;
6995 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6997 memcpy(sym_op->auth.digest.data,
6998 reference->digest.data,
6999 reference->digest.len);
7001 TEST_HEXDUMP(stdout, "digest:",
7002 sym_op->auth.digest.data,
7003 sym_op->auth.digest.length);
7005 sym_op->auth.data.length = reference->plaintext.len;
7006 sym_op->auth.data.offset = 0;
7012 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
7013 struct crypto_unittest_params *ut_params,
7014 const struct test_crypto_vector *reference,
7015 unsigned int auth_generate)
7017 /* Generate Crypto op data structure */
7018 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7019 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7020 TEST_ASSERT_NOT_NULL(ut_params->op,
7021 "Failed to allocate pktmbuf offload");
7023 /* Set crypto operation data parameters */
7024 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7026 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7028 /* set crypto operation source mbuf */
7029 sym_op->m_src = ut_params->ibuf;
7032 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7033 reference->aad.len);
7034 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD");
7035 memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len);
7037 TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len);
7039 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
7040 sym_op->auth.aad.length = reference->aad.len;
7043 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7044 ut_params->ibuf, reference->digest.len);
7046 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7047 "no room to append auth tag");
7049 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
7050 ut_params->ibuf, reference->ciphertext.len);
7051 sym_op->auth.digest.length = reference->digest.len;
7054 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7056 memcpy(sym_op->auth.digest.data,
7057 reference->digest.data,
7058 reference->digest.len);
7060 TEST_HEXDUMP(stdout, "digest:",
7061 sym_op->auth.digest.data,
7062 sym_op->auth.digest.length);
7064 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
7065 ut_params->ibuf, reference->iv.len);
7066 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
7068 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
7069 sym_op->cipher.iv.length = reference->iv.len;
7071 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
7073 sym_op->cipher.data.length = 0;
7074 sym_op->cipher.data.offset = 0;
7076 sym_op->auth.data.length = 0;
7077 sym_op->auth.data.offset = 0;
7083 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
7084 struct crypto_unittest_params *ut_params,
7085 const struct test_crypto_vector *reference,
7086 unsigned int auth_generate)
7088 /* Generate Crypto op data structure */
7089 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7090 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7091 TEST_ASSERT_NOT_NULL(ut_params->op,
7092 "Failed to allocate pktmbuf offload");
7094 /* Set crypto operation data parameters */
7095 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7097 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7099 /* set crypto operation source mbuf */
7100 sym_op->m_src = ut_params->ibuf;
7103 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
7104 ut_params->ibuf, reference->digest.len);
7106 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7107 "no room to append auth tag");
7109 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
7110 ut_params->ibuf, reference->ciphertext.len);
7111 sym_op->auth.digest.length = reference->digest.len;
7114 memset(sym_op->auth.digest.data, 0, reference->digest.len);
7116 memcpy(sym_op->auth.digest.data,
7117 reference->digest.data,
7118 reference->digest.len);
7120 TEST_HEXDUMP(stdout, "digest:",
7121 sym_op->auth.digest.data,
7122 sym_op->auth.digest.length);
7124 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
7125 ut_params->ibuf, reference->iv.len);
7126 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
7128 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
7129 sym_op->cipher.iv.length = reference->iv.len;
7131 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
7133 sym_op->cipher.data.length = reference->ciphertext.len;
7134 sym_op->cipher.data.offset = reference->iv.len;
7136 sym_op->auth.data.length = reference->ciphertext.len;
7137 sym_op->auth.data.offset = reference->iv.len;
7143 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7144 struct crypto_unittest_params *ut_params,
7145 const struct test_crypto_vector *reference)
7147 return create_auth_operation(ts_params, ut_params, reference, 0);
7151 create_auth_verify_GMAC_operation(
7152 struct crypto_testsuite_params *ts_params,
7153 struct crypto_unittest_params *ut_params,
7154 const struct test_crypto_vector *reference)
7156 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
7160 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
7161 struct crypto_unittest_params *ut_params,
7162 const struct test_crypto_vector *reference)
7164 return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
7168 test_authentication_verify_fail_when_data_corruption(
7169 struct crypto_testsuite_params *ts_params,
7170 struct crypto_unittest_params *ut_params,
7171 const struct test_crypto_vector *reference,
7172 unsigned int data_corrupted)
7178 /* Create session */
7179 retval = create_auth_session(ut_params,
7180 ts_params->valid_devs[0],
7182 RTE_CRYPTO_AUTH_OP_VERIFY);
7186 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7187 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7188 "Failed to allocate input buffer in mempool");
7190 /* clear mbuf payload */
7191 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7192 rte_pktmbuf_tailroom(ut_params->ibuf));
7194 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7195 reference->plaintext.len);
7196 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
7197 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
7199 TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
7201 /* Create operation */
7202 retval = create_auth_verify_operation(ts_params, ut_params, reference);
7208 data_corruption(plaintext);
7210 tag_corruption(plaintext, reference->plaintext.len);
7212 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7214 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7215 TEST_ASSERT_EQUAL(ut_params->op->status,
7216 RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7217 "authentication not failed");
7219 ut_params->obuf = ut_params->op->sym->m_src;
7220 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7226 test_authentication_verify_GMAC_fail_when_corruption(
7227 struct crypto_testsuite_params *ts_params,
7228 struct crypto_unittest_params *ut_params,
7229 const struct test_crypto_vector *reference,
7230 unsigned int data_corrupted)
7234 /* Create session */
7235 retval = create_auth_cipher_session(ut_params,
7236 ts_params->valid_devs[0],
7238 RTE_CRYPTO_AUTH_OP_VERIFY,
7239 RTE_CRYPTO_CIPHER_OP_DECRYPT);
7243 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7244 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7245 "Failed to allocate input buffer in mempool");
7247 /* clear mbuf payload */
7248 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7249 rte_pktmbuf_tailroom(ut_params->ibuf));
7251 /* Create operation */
7252 retval = create_auth_verify_GMAC_operation(ts_params,
7260 data_corruption(ut_params->op->sym->auth.aad.data);
7262 tag_corruption(ut_params->op->sym->auth.aad.data,
7263 reference->aad.len);
7265 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7267 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7268 TEST_ASSERT_EQUAL(ut_params->op->status,
7269 RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7270 "authentication not failed");
7272 ut_params->obuf = ut_params->op->sym->m_src;
7273 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7279 test_authenticated_decryption_fail_when_corruption(
7280 struct crypto_testsuite_params *ts_params,
7281 struct crypto_unittest_params *ut_params,
7282 const struct test_crypto_vector *reference,
7283 unsigned int data_corrupted)
7287 uint8_t *ciphertext;
7289 /* Create session */
7290 retval = create_auth_cipher_session(ut_params,
7291 ts_params->valid_devs[0],
7293 RTE_CRYPTO_AUTH_OP_VERIFY,
7294 RTE_CRYPTO_CIPHER_OP_DECRYPT);
7298 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7299 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
7300 "Failed to allocate input buffer in mempool");
7302 /* clear mbuf payload */
7303 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7304 rte_pktmbuf_tailroom(ut_params->ibuf));
7306 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7307 reference->ciphertext.len);
7308 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
7309 memcpy(ciphertext, reference->ciphertext.data,
7310 reference->ciphertext.len);
7312 /* Create operation */
7313 retval = create_cipher_auth_verify_operation(ts_params,
7321 data_corruption(ciphertext);
7323 tag_corruption(ciphertext, reference->ciphertext.len);
7325 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
7328 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
7329 TEST_ASSERT_EQUAL(ut_params->op->status,
7330 RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
7331 "authentication not failed");
7333 ut_params->obuf = ut_params->op->sym->m_src;
7334 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
7340 create_gcm_operation_SGL(enum rte_crypto_cipher_operation op,
7341 const struct gcm_test_data *tdata,
7342 void *digest_mem, uint64_t digest_phys)
7344 struct crypto_testsuite_params *ts_params = &testsuite_params;
7345 struct crypto_unittest_params *ut_params = &unittest_params;
7347 const unsigned int auth_tag_len = tdata->auth_tag.len;
7348 const unsigned int iv_len = tdata->iv.len;
7349 const unsigned int aad_len = tdata->aad.len;
7351 unsigned int iv_pad_len = 0;
7353 /* Generate Crypto op data structure */
7354 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
7355 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
7356 TEST_ASSERT_NOT_NULL(ut_params->op,
7357 "Failed to allocate symmetric crypto operation struct");
7359 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
7361 sym_op->auth.digest.data = digest_mem;
7363 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
7364 "no room to append digest");
7366 sym_op->auth.digest.phys_addr = digest_phys;
7367 sym_op->auth.digest.length = auth_tag_len;
7369 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
7370 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data,
7372 TEST_HEXDUMP(stdout, "digest:",
7373 sym_op->auth.digest.data,
7374 sym_op->auth.digest.length);
7377 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
7379 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
7380 ut_params->ibuf, iv_pad_len);
7382 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
7383 "no room to prepend iv");
7385 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
7386 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
7387 sym_op->cipher.iv.length = iv_len;
7389 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, iv_pad_len);
7391 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
7392 ut_params->ibuf, aad_len);
7393 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
7394 "no room to prepend aad");
7395 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
7397 sym_op->auth.aad.length = aad_len;
7399 memset(sym_op->auth.aad.data, 0, aad_len);
7400 rte_memcpy(sym_op->auth.aad.data, tdata->aad.data, aad_len);
7402 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
7403 TEST_HEXDUMP(stdout, "aad:",
7404 sym_op->auth.aad.data, aad_len);
7406 sym_op->cipher.data.length = tdata->plaintext.len;
7407 sym_op->cipher.data.offset = aad_len + iv_pad_len;
7409 sym_op->auth.data.offset = aad_len + iv_pad_len;
7410 sym_op->auth.data.length = tdata->plaintext.len;
7415 #define SGL_MAX_NO 16
7418 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata,
7419 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
7421 struct crypto_testsuite_params *ts_params = &testsuite_params;
7422 struct crypto_unittest_params *ut_params = &unittest_params;
7423 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
7426 int to_trn_tbl[SGL_MAX_NO];
7428 unsigned int trn_data = 0;
7429 uint8_t *plaintext, *ciphertext, *auth_tag;
7431 if (fragsz > tdata->plaintext.len)
7432 fragsz = tdata->plaintext.len;
7434 uint16_t plaintext_len = fragsz;
7435 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
7437 if (fragsz_oop > tdata->plaintext.len)
7438 frag_size_oop = tdata->plaintext.len;
7441 void *digest_mem = NULL;
7443 uint32_t prepend_len = ALIGN_POW2_ROUNDUP(tdata->iv.len, 16)
7446 if (tdata->plaintext.len % fragsz != 0) {
7447 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
7450 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
7455 * For out-op-place we need to alloc another mbuf
7458 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7459 rte_pktmbuf_append(ut_params->obuf,
7460 frag_size_oop + prepend_len);
7461 buf_oop = ut_params->obuf;
7464 /* Create GCM session */
7465 retval = create_gcm_session(ts_params->valid_devs[0],
7466 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7467 tdata->key.data, tdata->key.len,
7468 tdata->aad.len, tdata->auth_tag.len,
7469 RTE_CRYPTO_AUTH_OP_GENERATE);
7473 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7475 /* clear mbuf payload */
7476 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
7477 rte_pktmbuf_tailroom(ut_params->ibuf));
7479 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7482 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
7484 trn_data += plaintext_len;
7486 buf = ut_params->ibuf;
7489 * Loop until no more fragments
7492 while (trn_data < tdata->plaintext.len) {
7494 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
7495 (tdata->plaintext.len - trn_data) : fragsz;
7497 to_trn_tbl[ecx++] = to_trn;
7499 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
7502 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
7503 rte_pktmbuf_tailroom(buf));
7506 if (oop && !fragsz_oop) {
7507 buf_last_oop = buf_oop->next =
7508 rte_pktmbuf_alloc(ts_params->mbuf_pool);
7509 buf_oop = buf_oop->next;
7510 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7511 0, rte_pktmbuf_tailroom(buf_oop));
7512 rte_pktmbuf_append(buf_oop, to_trn);
7515 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
7518 memcpy(plaintext, tdata->plaintext.data + trn_data,
7521 if (trn_data == tdata->plaintext.len) {
7524 digest_mem = rte_pktmbuf_append(buf_oop,
7525 tdata->auth_tag.len);
7527 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
7528 tdata->auth_tag.len);
7532 uint64_t digest_phys = 0;
7534 ut_params->ibuf->nb_segs = segs;
7537 if (fragsz_oop && oop) {
7541 if (frag_size_oop == tdata->plaintext.len) {
7542 digest_mem = rte_pktmbuf_append(ut_params->obuf,
7543 tdata->auth_tag.len);
7545 digest_phys = rte_pktmbuf_mtophys_offset(
7547 tdata->plaintext.len + prepend_len);
7550 trn_data = frag_size_oop;
7551 while (trn_data < tdata->plaintext.len) {
7554 (tdata->plaintext.len - trn_data <
7556 (tdata->plaintext.len - trn_data) :
7559 to_trn_tbl[ecx++] = to_trn;
7561 buf_last_oop = buf_oop->next =
7562 rte_pktmbuf_alloc(ts_params->mbuf_pool);
7563 buf_oop = buf_oop->next;
7564 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
7565 0, rte_pktmbuf_tailroom(buf_oop));
7566 rte_pktmbuf_append(buf_oop, to_trn);
7570 if (trn_data == tdata->plaintext.len) {
7571 digest_mem = rte_pktmbuf_append(buf_oop,
7572 tdata->auth_tag.len);
7576 ut_params->obuf->nb_segs = segs;
7580 * Place digest at the end of the last buffer
7583 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn;
7584 if (oop && buf_last_oop)
7585 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn;
7587 if (!digest_mem && !oop) {
7588 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
7589 + tdata->auth_tag.len);
7590 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf,
7591 tdata->plaintext.len);
7594 /* Create GCM opertaion */
7595 retval = create_gcm_operation_SGL(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
7596 tdata, digest_mem, digest_phys);
7601 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
7603 ut_params->op->sym->m_src = ut_params->ibuf;
7605 ut_params->op->sym->m_dst = ut_params->obuf;
7607 /* Process crypto operation */
7608 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
7609 ut_params->op), "failed to process sym crypto op");
7611 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
7612 "crypto op processing failed");
7615 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
7616 uint8_t *, prepend_len);
7618 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
7619 uint8_t *, prepend_len);
7623 fragsz = fragsz_oop;
7625 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7627 tdata->ciphertext.data,
7629 "GCM Ciphertext data not as expected");
7631 buf = ut_params->op->sym->m_src->next;
7633 buf = ut_params->op->sym->m_dst->next;
7635 unsigned int off = fragsz;
7639 ciphertext = rte_pktmbuf_mtod(buf,
7642 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7644 tdata->ciphertext.data + off,
7646 "GCM Ciphertext data not as expected");
7648 off += to_trn_tbl[ecx++];
7652 auth_tag = digest_mem;
7653 TEST_ASSERT_BUFFERS_ARE_EQUAL(
7655 tdata->auth_tag.data,
7656 tdata->auth_tag.len,
7657 "GCM Generated auth tag not as expected");
7663 #define OUT_OF_PLACE 1
7666 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
7668 return test_AES_GCM_authenticated_encryption_SGL(
7669 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
7673 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
7675 return test_AES_GCM_authenticated_encryption_SGL(
7676 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
7680 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
7682 return test_AES_GCM_authenticated_encryption_SGL(
7683 &gcm_test_case_8, OUT_OF_PLACE, 400,
7684 gcm_test_case_8.plaintext.len);
7688 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
7691 return test_AES_GCM_authenticated_encryption_SGL(
7692 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
7696 test_authentication_verify_fail_when_data_corrupted(
7697 struct crypto_testsuite_params *ts_params,
7698 struct crypto_unittest_params *ut_params,
7699 const struct test_crypto_vector *reference)
7701 return test_authentication_verify_fail_when_data_corruption(
7702 ts_params, ut_params, reference, 1);
7706 test_authentication_verify_fail_when_tag_corrupted(
7707 struct crypto_testsuite_params *ts_params,
7708 struct crypto_unittest_params *ut_params,
7709 const struct test_crypto_vector *reference)
7711 return test_authentication_verify_fail_when_data_corruption(
7712 ts_params, ut_params, reference, 0);
7716 test_authentication_verify_GMAC_fail_when_data_corrupted(
7717 struct crypto_testsuite_params *ts_params,
7718 struct crypto_unittest_params *ut_params,
7719 const struct test_crypto_vector *reference)
7721 return test_authentication_verify_GMAC_fail_when_corruption(
7722 ts_params, ut_params, reference, 1);
7726 test_authentication_verify_GMAC_fail_when_tag_corrupted(
7727 struct crypto_testsuite_params *ts_params,
7728 struct crypto_unittest_params *ut_params,
7729 const struct test_crypto_vector *reference)
7731 return test_authentication_verify_GMAC_fail_when_corruption(
7732 ts_params, ut_params, reference, 0);
7736 test_authenticated_decryption_fail_when_data_corrupted(
7737 struct crypto_testsuite_params *ts_params,
7738 struct crypto_unittest_params *ut_params,
7739 const struct test_crypto_vector *reference)
7741 return test_authenticated_decryption_fail_when_corruption(
7742 ts_params, ut_params, reference, 1);
7746 test_authenticated_decryption_fail_when_tag_corrupted(
7747 struct crypto_testsuite_params *ts_params,
7748 struct crypto_unittest_params *ut_params,
7749 const struct test_crypto_vector *reference)
7751 return test_authenticated_decryption_fail_when_corruption(
7752 ts_params, ut_params, reference, 0);
7756 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
7758 return test_authentication_verify_fail_when_data_corrupted(
7759 &testsuite_params, &unittest_params,
7760 &hmac_sha1_test_crypto_vector);
7764 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
7766 return test_authentication_verify_fail_when_tag_corrupted(
7767 &testsuite_params, &unittest_params,
7768 &hmac_sha1_test_crypto_vector);
7772 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
7774 return test_authentication_verify_GMAC_fail_when_data_corrupted(
7775 &testsuite_params, &unittest_params,
7776 &aes128_gmac_test_vector);
7780 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
7782 return test_authentication_verify_GMAC_fail_when_tag_corrupted(
7783 &testsuite_params, &unittest_params,
7784 &aes128_gmac_test_vector);
7788 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
7790 return test_authenticated_decryption_fail_when_data_corrupted(
7793 &aes128cbc_hmac_sha1_test_vector);
7797 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
7799 return test_authenticated_decryption_fail_when_tag_corrupted(
7802 &aes128cbc_hmac_sha1_test_vector);
7805 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
7807 /* global AESNI slave IDs for the scheduler test */
7808 uint8_t aesni_ids[2];
7811 test_scheduler_attach_slave_op(void)
7813 struct crypto_testsuite_params *ts_params = &testsuite_params;
7814 uint8_t sched_id = ts_params->valid_devs[0];
7815 uint32_t nb_devs, i, nb_devs_attached = 0;
7819 /* create 2 AESNI_MB if necessary */
7820 nb_devs = rte_cryptodev_count_devtype(
7821 RTE_CRYPTODEV_AESNI_MB_PMD);
7823 for (i = nb_devs; i < 2; i++) {
7824 snprintf(vdev_name, sizeof(vdev_name), "%s_%u",
7825 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD),
7827 ret = rte_vdev_init(vdev_name, NULL);
7829 TEST_ASSERT(ret == 0,
7830 "Failed to create instance %u of"
7832 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
7836 /* attach 2 AESNI_MB cdevs */
7837 for (i = 0; i < rte_cryptodev_count() && nb_devs_attached < 2;
7839 struct rte_cryptodev_info info;
7841 rte_cryptodev_info_get(i, &info);
7842 if (info.dev_type != RTE_CRYPTODEV_AESNI_MB_PMD)
7845 ret = rte_cryptodev_scheduler_slave_attach(sched_id,
7848 TEST_ASSERT(ret == 0,
7849 "Failed to attach device %u of pmd : %s", i,
7850 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
7852 aesni_ids[nb_devs_attached] = (uint8_t)i;
7861 test_scheduler_detach_slave_op(void)
7863 struct crypto_testsuite_params *ts_params = &testsuite_params;
7864 uint8_t sched_id = ts_params->valid_devs[0];
7868 for (i = 0; i < 2; i++) {
7869 ret = rte_cryptodev_scheduler_slave_detach(sched_id,
7871 TEST_ASSERT(ret == 0,
7872 "Failed to detach device %u", aesni_ids[i]);
7879 test_scheduler_mode_op(void)
7881 struct crypto_testsuite_params *ts_params = &testsuite_params;
7882 uint8_t sched_id = ts_params->valid_devs[0];
7883 struct rte_cryptodev_scheduler_ops op = {0};
7884 struct rte_cryptodev_scheduler dummy_scheduler = {
7885 .description = "dummy scheduler to test mode",
7886 .name = "dummy scheduler",
7887 .mode = CDEV_SCHED_MODE_USERDEFINED,
7892 /* set user defined mode */
7893 ret = rte_cryptodev_scheduler_load_user_scheduler(sched_id,
7895 TEST_ASSERT(ret == 0,
7896 "Failed to set cdev %u to user defined mode", sched_id);
7898 /* set round robin mode */
7899 ret = rte_cryptodev_scheduler_mode_set(sched_id,
7900 CDEV_SCHED_MODE_ROUNDROBIN);
7901 TEST_ASSERT(ret == 0,
7902 "Failed to set cdev %u to round-robin mode", sched_id);
7903 TEST_ASSERT(rte_cryptodev_scheduler_mode_get(sched_id) ==
7904 CDEV_SCHED_MODE_ROUNDROBIN, "Scheduling Mode "
7910 static struct unit_test_suite cryptodev_scheduler_testsuite = {
7911 .suite_name = "Crypto Device Scheduler Unit Test Suite",
7912 .setup = testsuite_setup,
7913 .teardown = testsuite_teardown,
7914 .unit_test_cases = {
7915 TEST_CASE_ST(NULL, NULL, test_scheduler_attach_slave_op),
7916 TEST_CASE_ST(NULL, NULL, test_scheduler_mode_op),
7917 TEST_CASE_ST(ut_setup, ut_teardown,
7918 test_AES_chain_scheduler_all),
7919 TEST_CASE_ST(ut_setup, ut_teardown,
7920 test_AES_cipheronly_scheduler_all),
7921 TEST_CASE_ST(ut_setup, ut_teardown,
7922 test_authonly_scheduler_all),
7923 TEST_CASE_ST(NULL, NULL, test_scheduler_detach_slave_op),
7924 TEST_CASES_END() /**< NULL terminate unit test array */
7928 #endif /* RTE_LIBRTE_PMD_CRYPTO_SCHEDULER */
7930 static struct unit_test_suite cryptodev_qat_testsuite = {
7931 .suite_name = "Crypto QAT Unit Test Suite",
7932 .setup = testsuite_setup,
7933 .teardown = testsuite_teardown,
7934 .unit_test_cases = {
7935 TEST_CASE_ST(ut_setup, ut_teardown,
7936 test_device_configure_invalid_dev_id),
7937 TEST_CASE_ST(ut_setup, ut_teardown,
7938 test_device_configure_invalid_queue_pair_ids),
7939 TEST_CASE_ST(ut_setup, ut_teardown,
7940 test_queue_pair_descriptor_setup),
7941 TEST_CASE_ST(ut_setup, ut_teardown,
7942 test_multi_session),
7944 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
7945 TEST_CASE_ST(ut_setup, ut_teardown,
7946 test_AES_cipheronly_qat_all),
7947 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
7948 TEST_CASE_ST(ut_setup, ut_teardown,
7949 test_3DES_cipheronly_qat_all),
7950 TEST_CASE_ST(ut_setup, ut_teardown,
7951 test_DES_cipheronly_qat_all),
7952 TEST_CASE_ST(ut_setup, ut_teardown,
7953 test_AES_docsis_qat_all),
7954 TEST_CASE_ST(ut_setup, ut_teardown,
7955 test_DES_docsis_qat_all),
7956 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
7958 /** AES GCM Authenticated Encryption */
7959 TEST_CASE_ST(ut_setup, ut_teardown,
7960 test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
7961 TEST_CASE_ST(ut_setup, ut_teardown,
7962 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
7963 TEST_CASE_ST(ut_setup, ut_teardown,
7964 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
7965 TEST_CASE_ST(ut_setup, ut_teardown,
7966 test_mb_AES_GCM_authenticated_encryption_test_case_1),
7967 TEST_CASE_ST(ut_setup, ut_teardown,
7968 test_mb_AES_GCM_authenticated_encryption_test_case_2),
7969 TEST_CASE_ST(ut_setup, ut_teardown,
7970 test_mb_AES_GCM_authenticated_encryption_test_case_3),
7971 TEST_CASE_ST(ut_setup, ut_teardown,
7972 test_mb_AES_GCM_authenticated_encryption_test_case_4),
7973 TEST_CASE_ST(ut_setup, ut_teardown,
7974 test_mb_AES_GCM_authenticated_encryption_test_case_5),
7975 TEST_CASE_ST(ut_setup, ut_teardown,
7976 test_mb_AES_GCM_authenticated_encryption_test_case_6),
7977 TEST_CASE_ST(ut_setup, ut_teardown,
7978 test_mb_AES_GCM_authenticated_encryption_test_case_7),
7980 /** AES GCM Authenticated Decryption */
7981 TEST_CASE_ST(ut_setup, ut_teardown,
7982 test_mb_AES_GCM_authenticated_decryption_test_case_1),
7983 TEST_CASE_ST(ut_setup, ut_teardown,
7984 test_mb_AES_GCM_authenticated_decryption_test_case_2),
7985 TEST_CASE_ST(ut_setup, ut_teardown,
7986 test_mb_AES_GCM_authenticated_decryption_test_case_3),
7987 TEST_CASE_ST(ut_setup, ut_teardown,
7988 test_mb_AES_GCM_authenticated_decryption_test_case_4),
7989 TEST_CASE_ST(ut_setup, ut_teardown,
7990 test_mb_AES_GCM_authenticated_decryption_test_case_5),
7991 TEST_CASE_ST(ut_setup, ut_teardown,
7992 test_mb_AES_GCM_authenticated_decryption_test_case_6),
7993 TEST_CASE_ST(ut_setup, ut_teardown,
7994 test_mb_AES_GCM_authenticated_decryption_test_case_7),
7996 /** AES GMAC Authentication */
7997 TEST_CASE_ST(ut_setup, ut_teardown,
7998 test_AES_GMAC_authentication_test_case_1),
7999 TEST_CASE_ST(ut_setup, ut_teardown,
8000 test_AES_GMAC_authentication_verify_test_case_1),
8001 TEST_CASE_ST(ut_setup, ut_teardown,
8002 test_AES_GMAC_authentication_test_case_2),
8003 TEST_CASE_ST(ut_setup, ut_teardown,
8004 test_AES_GMAC_authentication_verify_test_case_2),
8005 TEST_CASE_ST(ut_setup, ut_teardown,
8006 test_AES_GMAC_authentication_test_case_3),
8007 TEST_CASE_ST(ut_setup, ut_teardown,
8008 test_AES_GMAC_authentication_verify_test_case_3),
8010 /** SNOW 3G encrypt only (UEA2) */
8011 TEST_CASE_ST(ut_setup, ut_teardown,
8012 test_snow3g_encryption_test_case_1),
8013 TEST_CASE_ST(ut_setup, ut_teardown,
8014 test_snow3g_encryption_test_case_2),
8015 TEST_CASE_ST(ut_setup, ut_teardown,
8016 test_snow3g_encryption_test_case_3),
8017 TEST_CASE_ST(ut_setup, ut_teardown,
8018 test_snow3g_encryption_test_case_4),
8019 TEST_CASE_ST(ut_setup, ut_teardown,
8020 test_snow3g_encryption_test_case_5),
8022 TEST_CASE_ST(ut_setup, ut_teardown,
8023 test_snow3g_encryption_test_case_1_oop),
8024 TEST_CASE_ST(ut_setup, ut_teardown,
8025 test_snow3g_decryption_test_case_1_oop),
8027 /** SNOW 3G decrypt only (UEA2) */
8028 TEST_CASE_ST(ut_setup, ut_teardown,
8029 test_snow3g_decryption_test_case_1),
8030 TEST_CASE_ST(ut_setup, ut_teardown,
8031 test_snow3g_decryption_test_case_2),
8032 TEST_CASE_ST(ut_setup, ut_teardown,
8033 test_snow3g_decryption_test_case_3),
8034 TEST_CASE_ST(ut_setup, ut_teardown,
8035 test_snow3g_decryption_test_case_4),
8036 TEST_CASE_ST(ut_setup, ut_teardown,
8037 test_snow3g_decryption_test_case_5),
8038 TEST_CASE_ST(ut_setup, ut_teardown,
8039 test_snow3g_hash_generate_test_case_1),
8040 TEST_CASE_ST(ut_setup, ut_teardown,
8041 test_snow3g_hash_generate_test_case_2),
8042 TEST_CASE_ST(ut_setup, ut_teardown,
8043 test_snow3g_hash_generate_test_case_3),
8044 TEST_CASE_ST(ut_setup, ut_teardown,
8045 test_snow3g_hash_verify_test_case_1),
8046 TEST_CASE_ST(ut_setup, ut_teardown,
8047 test_snow3g_hash_verify_test_case_2),
8048 TEST_CASE_ST(ut_setup, ut_teardown,
8049 test_snow3g_hash_verify_test_case_3),
8050 TEST_CASE_ST(ut_setup, ut_teardown,
8051 test_snow3g_cipher_auth_test_case_1),
8052 TEST_CASE_ST(ut_setup, ut_teardown,
8053 test_snow3g_auth_cipher_test_case_1),
8055 /** ZUC encrypt only (EEA3) */
8056 TEST_CASE_ST(ut_setup, ut_teardown,
8057 test_zuc_encryption_test_case_1),
8058 TEST_CASE_ST(ut_setup, ut_teardown,
8059 test_zuc_encryption_test_case_2),
8060 TEST_CASE_ST(ut_setup, ut_teardown,
8061 test_zuc_encryption_test_case_3),
8062 TEST_CASE_ST(ut_setup, ut_teardown,
8063 test_zuc_encryption_test_case_4),
8064 TEST_CASE_ST(ut_setup, ut_teardown,
8065 test_zuc_encryption_test_case_5),
8067 /** ZUC authenticate (EIA3) */
8068 TEST_CASE_ST(ut_setup, ut_teardown,
8069 test_zuc_hash_generate_test_case_6),
8070 TEST_CASE_ST(ut_setup, ut_teardown,
8071 test_zuc_hash_generate_test_case_7),
8072 TEST_CASE_ST(ut_setup, ut_teardown,
8073 test_zuc_hash_generate_test_case_8),
8075 /** ZUC alg-chain (EEA3/EIA3) */
8076 TEST_CASE_ST(ut_setup, ut_teardown,
8077 test_zuc_cipher_auth_test_case_1),
8078 TEST_CASE_ST(ut_setup, ut_teardown,
8079 test_zuc_cipher_auth_test_case_2),
8081 /** HMAC_MD5 Authentication */
8082 TEST_CASE_ST(ut_setup, ut_teardown,
8083 test_MD5_HMAC_generate_case_1),
8084 TEST_CASE_ST(ut_setup, ut_teardown,
8085 test_MD5_HMAC_verify_case_1),
8086 TEST_CASE_ST(ut_setup, ut_teardown,
8087 test_MD5_HMAC_generate_case_2),
8088 TEST_CASE_ST(ut_setup, ut_teardown,
8089 test_MD5_HMAC_verify_case_2),
8092 TEST_CASE_ST(ut_setup, ut_teardown,
8093 test_null_auth_only_operation),
8094 TEST_CASE_ST(ut_setup, ut_teardown,
8095 test_null_cipher_only_operation),
8096 TEST_CASE_ST(ut_setup, ut_teardown,
8097 test_null_cipher_auth_operation),
8098 TEST_CASE_ST(ut_setup, ut_teardown,
8099 test_null_auth_cipher_operation),
8101 TEST_CASE_ST(ut_setup, ut_teardown,
8102 test_kasumi_hash_generate_test_case_6),
8105 TEST_CASE_ST(ut_setup, ut_teardown,
8106 test_kasumi_encryption_test_case_1),
8107 TEST_CASE_ST(ut_setup, ut_teardown,
8108 test_kasumi_encryption_test_case_3),
8109 TEST_CASE_ST(ut_setup, ut_teardown,
8110 test_kasumi_auth_cipher_test_case_1),
8111 TEST_CASE_ST(ut_setup, ut_teardown,
8112 test_kasumi_cipher_auth_test_case_1),
8114 /** Negative tests */
8115 TEST_CASE_ST(ut_setup, ut_teardown,
8116 authentication_verify_HMAC_SHA1_fail_data_corrupt),
8117 TEST_CASE_ST(ut_setup, ut_teardown,
8118 authentication_verify_HMAC_SHA1_fail_tag_corrupt),
8119 TEST_CASE_ST(ut_setup, ut_teardown,
8120 authentication_verify_AES128_GMAC_fail_data_corrupt),
8121 TEST_CASE_ST(ut_setup, ut_teardown,
8122 authentication_verify_AES128_GMAC_fail_tag_corrupt),
8123 TEST_CASE_ST(ut_setup, ut_teardown,
8124 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8125 TEST_CASE_ST(ut_setup, ut_teardown,
8126 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8128 TEST_CASES_END() /**< NULL terminate unit test array */
8132 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
8133 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
8134 .setup = testsuite_setup,
8135 .teardown = testsuite_teardown,
8136 .unit_test_cases = {
8137 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
8138 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
8139 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_docsis_mb_all),
8140 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
8142 TEST_CASES_END() /**< NULL terminate unit test array */
8146 static struct unit_test_suite cryptodev_openssl_testsuite = {
8147 .suite_name = "Crypto Device OPENSSL Unit Test Suite",
8148 .setup = testsuite_setup,
8149 .teardown = testsuite_teardown,
8150 .unit_test_cases = {
8151 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
8152 TEST_CASE_ST(ut_setup, ut_teardown,
8153 test_multi_session_random_usage),
8154 TEST_CASE_ST(ut_setup, ut_teardown,
8155 test_AES_chain_openssl_all),
8156 TEST_CASE_ST(ut_setup, ut_teardown,
8157 test_AES_cipheronly_openssl_all),
8158 TEST_CASE_ST(ut_setup, ut_teardown,
8159 test_3DES_chain_openssl_all),
8160 TEST_CASE_ST(ut_setup, ut_teardown,
8161 test_3DES_cipheronly_openssl_all),
8162 TEST_CASE_ST(ut_setup, ut_teardown,
8163 test_DES_docsis_openssl_all),
8164 TEST_CASE_ST(ut_setup, ut_teardown,
8165 test_authonly_openssl_all),
8167 /** AES GCM Authenticated Encryption */
8168 TEST_CASE_ST(ut_setup, ut_teardown,
8169 test_mb_AES_GCM_authenticated_encryption_test_case_1),
8170 TEST_CASE_ST(ut_setup, ut_teardown,
8171 test_mb_AES_GCM_authenticated_encryption_test_case_2),
8172 TEST_CASE_ST(ut_setup, ut_teardown,
8173 test_mb_AES_GCM_authenticated_encryption_test_case_3),
8174 TEST_CASE_ST(ut_setup, ut_teardown,
8175 test_mb_AES_GCM_authenticated_encryption_test_case_4),
8176 TEST_CASE_ST(ut_setup, ut_teardown,
8177 test_mb_AES_GCM_authenticated_encryption_test_case_5),
8178 TEST_CASE_ST(ut_setup, ut_teardown,
8179 test_mb_AES_GCM_authenticated_encryption_test_case_6),
8180 TEST_CASE_ST(ut_setup, ut_teardown,
8181 test_mb_AES_GCM_authenticated_encryption_test_case_7),
8183 /** AES GCM Authenticated Decryption */
8184 TEST_CASE_ST(ut_setup, ut_teardown,
8185 test_mb_AES_GCM_authenticated_decryption_test_case_1),
8186 TEST_CASE_ST(ut_setup, ut_teardown,
8187 test_mb_AES_GCM_authenticated_decryption_test_case_2),
8188 TEST_CASE_ST(ut_setup, ut_teardown,
8189 test_mb_AES_GCM_authenticated_decryption_test_case_3),
8190 TEST_CASE_ST(ut_setup, ut_teardown,
8191 test_mb_AES_GCM_authenticated_decryption_test_case_4),
8192 TEST_CASE_ST(ut_setup, ut_teardown,
8193 test_mb_AES_GCM_authenticated_decryption_test_case_5),
8194 TEST_CASE_ST(ut_setup, ut_teardown,
8195 test_mb_AES_GCM_authenticated_decryption_test_case_6),
8196 TEST_CASE_ST(ut_setup, ut_teardown,
8197 test_mb_AES_GCM_authenticated_decryption_test_case_7),
8199 /** AES GMAC Authentication */
8200 TEST_CASE_ST(ut_setup, ut_teardown,
8201 test_AES_GMAC_authentication_test_case_1),
8202 TEST_CASE_ST(ut_setup, ut_teardown,
8203 test_AES_GMAC_authentication_verify_test_case_1),
8204 TEST_CASE_ST(ut_setup, ut_teardown,
8205 test_AES_GMAC_authentication_test_case_2),
8206 TEST_CASE_ST(ut_setup, ut_teardown,
8207 test_AES_GMAC_authentication_verify_test_case_2),
8208 TEST_CASE_ST(ut_setup, ut_teardown,
8209 test_AES_GMAC_authentication_test_case_3),
8210 TEST_CASE_ST(ut_setup, ut_teardown,
8211 test_AES_GMAC_authentication_verify_test_case_3),
8212 TEST_CASE_ST(ut_setup, ut_teardown,
8213 test_AES_GMAC_authentication_test_case_4),
8214 TEST_CASE_ST(ut_setup, ut_teardown,
8215 test_AES_GMAC_authentication_verify_test_case_4),
8217 /** Scatter-Gather */
8218 TEST_CASE_ST(ut_setup, ut_teardown,
8219 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
8221 /** Negative tests */
8222 TEST_CASE_ST(ut_setup, ut_teardown,
8223 authentication_verify_HMAC_SHA1_fail_data_corrupt),
8224 TEST_CASE_ST(ut_setup, ut_teardown,
8225 authentication_verify_HMAC_SHA1_fail_tag_corrupt),
8226 TEST_CASE_ST(ut_setup, ut_teardown,
8227 authentication_verify_AES128_GMAC_fail_data_corrupt),
8228 TEST_CASE_ST(ut_setup, ut_teardown,
8229 authentication_verify_AES128_GMAC_fail_tag_corrupt),
8230 TEST_CASE_ST(ut_setup, ut_teardown,
8231 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8232 TEST_CASE_ST(ut_setup, ut_teardown,
8233 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8235 TEST_CASES_END() /**< NULL terminate unit test array */
8239 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
8240 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
8241 .setup = testsuite_setup,
8242 .teardown = testsuite_teardown,
8243 .unit_test_cases = {
8244 /** AES GCM Authenticated Encryption */
8245 TEST_CASE_ST(ut_setup, ut_teardown,
8246 test_mb_AES_GCM_authenticated_encryption_test_case_1),
8247 TEST_CASE_ST(ut_setup, ut_teardown,
8248 test_mb_AES_GCM_authenticated_encryption_test_case_2),
8249 TEST_CASE_ST(ut_setup, ut_teardown,
8250 test_mb_AES_GCM_authenticated_encryption_test_case_3),
8251 TEST_CASE_ST(ut_setup, ut_teardown,
8252 test_mb_AES_GCM_authenticated_encryption_test_case_4),
8253 TEST_CASE_ST(ut_setup, ut_teardown,
8254 test_mb_AES_GCM_authenticated_encryption_test_case_5),
8255 TEST_CASE_ST(ut_setup, ut_teardown,
8256 test_mb_AES_GCM_authenticated_encryption_test_case_6),
8257 TEST_CASE_ST(ut_setup, ut_teardown,
8258 test_mb_AES_GCM_authenticated_encryption_test_case_7),
8260 /** AES GCM Authenticated Decryption */
8261 TEST_CASE_ST(ut_setup, ut_teardown,
8262 test_mb_AES_GCM_authenticated_decryption_test_case_1),
8263 TEST_CASE_ST(ut_setup, ut_teardown,
8264 test_mb_AES_GCM_authenticated_decryption_test_case_2),
8265 TEST_CASE_ST(ut_setup, ut_teardown,
8266 test_mb_AES_GCM_authenticated_decryption_test_case_3),
8267 TEST_CASE_ST(ut_setup, ut_teardown,
8268 test_mb_AES_GCM_authenticated_decryption_test_case_4),
8269 TEST_CASE_ST(ut_setup, ut_teardown,
8270 test_mb_AES_GCM_authenticated_decryption_test_case_5),
8271 TEST_CASE_ST(ut_setup, ut_teardown,
8272 test_mb_AES_GCM_authenticated_decryption_test_case_6),
8273 TEST_CASE_ST(ut_setup, ut_teardown,
8274 test_mb_AES_GCM_authenticated_decryption_test_case_7),
8276 /** AES GCM Authenticated Encryption 256 bits key */
8277 TEST_CASE_ST(ut_setup, ut_teardown,
8278 test_mb_AES_GCM_auth_encryption_test_case_256_1),
8279 TEST_CASE_ST(ut_setup, ut_teardown,
8280 test_mb_AES_GCM_auth_encryption_test_case_256_2),
8281 TEST_CASE_ST(ut_setup, ut_teardown,
8282 test_mb_AES_GCM_auth_encryption_test_case_256_3),
8283 TEST_CASE_ST(ut_setup, ut_teardown,
8284 test_mb_AES_GCM_auth_encryption_test_case_256_4),
8285 TEST_CASE_ST(ut_setup, ut_teardown,
8286 test_mb_AES_GCM_auth_encryption_test_case_256_5),
8287 TEST_CASE_ST(ut_setup, ut_teardown,
8288 test_mb_AES_GCM_auth_encryption_test_case_256_6),
8289 TEST_CASE_ST(ut_setup, ut_teardown,
8290 test_mb_AES_GCM_auth_encryption_test_case_256_7),
8292 /** AES GCM Authenticated Decryption 256 bits key */
8293 TEST_CASE_ST(ut_setup, ut_teardown,
8294 test_mb_AES_GCM_auth_decryption_test_case_256_1),
8295 TEST_CASE_ST(ut_setup, ut_teardown,
8296 test_mb_AES_GCM_auth_decryption_test_case_256_2),
8297 TEST_CASE_ST(ut_setup, ut_teardown,
8298 test_mb_AES_GCM_auth_decryption_test_case_256_3),
8299 TEST_CASE_ST(ut_setup, ut_teardown,
8300 test_mb_AES_GCM_auth_decryption_test_case_256_4),
8301 TEST_CASE_ST(ut_setup, ut_teardown,
8302 test_mb_AES_GCM_auth_decryption_test_case_256_5),
8303 TEST_CASE_ST(ut_setup, ut_teardown,
8304 test_mb_AES_GCM_auth_decryption_test_case_256_6),
8305 TEST_CASE_ST(ut_setup, ut_teardown,
8306 test_mb_AES_GCM_auth_decryption_test_case_256_7),
8308 /** AES GCM Authenticated Encryption big aad size */
8309 TEST_CASE_ST(ut_setup, ut_teardown,
8310 test_mb_AES_GCM_auth_encryption_test_case_aad_1),
8311 TEST_CASE_ST(ut_setup, ut_teardown,
8312 test_mb_AES_GCM_auth_encryption_test_case_aad_2),
8314 /** AES GCM Authenticated Decryption big aad size */
8315 TEST_CASE_ST(ut_setup, ut_teardown,
8316 test_mb_AES_GCM_auth_decryption_test_case_aad_1),
8317 TEST_CASE_ST(ut_setup, ut_teardown,
8318 test_mb_AES_GCM_auth_decryption_test_case_aad_2),
8320 /** AES GMAC Authentication */
8321 TEST_CASE_ST(ut_setup, ut_teardown,
8322 test_AES_GMAC_authentication_test_case_1),
8323 TEST_CASE_ST(ut_setup, ut_teardown,
8324 test_AES_GMAC_authentication_verify_test_case_1),
8325 TEST_CASE_ST(ut_setup, ut_teardown,
8326 test_AES_GMAC_authentication_test_case_3),
8327 TEST_CASE_ST(ut_setup, ut_teardown,
8328 test_AES_GMAC_authentication_verify_test_case_3),
8329 TEST_CASE_ST(ut_setup, ut_teardown,
8330 test_AES_GMAC_authentication_test_case_4),
8331 TEST_CASE_ST(ut_setup, ut_teardown,
8332 test_AES_GMAC_authentication_verify_test_case_4),
8334 /** Negative tests */
8335 TEST_CASE_ST(ut_setup, ut_teardown,
8336 authentication_verify_AES128_GMAC_fail_data_corrupt),
8337 TEST_CASE_ST(ut_setup, ut_teardown,
8338 authentication_verify_AES128_GMAC_fail_tag_corrupt),
8340 /** Out of place tests */
8341 TEST_CASE_ST(ut_setup, ut_teardown,
8342 test_mb_AES_GCM_authenticated_encryption_oop),
8343 TEST_CASE_ST(ut_setup, ut_teardown,
8344 test_mb_AES_GCM_authenticated_decryption_oop),
8346 /** Session-less tests */
8347 TEST_CASE_ST(ut_setup, ut_teardown,
8348 test_mb_AES_GCM_authenticated_encryption_sessionless),
8349 TEST_CASE_ST(ut_setup, ut_teardown,
8350 test_mb_AES_GCM_authenticated_decryption_sessionless),
8352 /** Scatter-Gather */
8353 TEST_CASE_ST(ut_setup, ut_teardown,
8354 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
8356 TEST_CASES_END() /**< NULL terminate unit test array */
8360 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
8361 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
8362 .setup = testsuite_setup,
8363 .teardown = testsuite_teardown,
8364 .unit_test_cases = {
8365 /** KASUMI encrypt only (UEA1) */
8366 TEST_CASE_ST(ut_setup, ut_teardown,
8367 test_kasumi_encryption_test_case_1),
8368 TEST_CASE_ST(ut_setup, ut_teardown,
8369 test_kasumi_encryption_test_case_1_sgl),
8370 TEST_CASE_ST(ut_setup, ut_teardown,
8371 test_kasumi_encryption_test_case_2),
8372 TEST_CASE_ST(ut_setup, ut_teardown,
8373 test_kasumi_encryption_test_case_3),
8374 TEST_CASE_ST(ut_setup, ut_teardown,
8375 test_kasumi_encryption_test_case_4),
8376 TEST_CASE_ST(ut_setup, ut_teardown,
8377 test_kasumi_encryption_test_case_5),
8378 /** KASUMI decrypt only (UEA1) */
8379 TEST_CASE_ST(ut_setup, ut_teardown,
8380 test_kasumi_decryption_test_case_1),
8381 TEST_CASE_ST(ut_setup, ut_teardown,
8382 test_kasumi_decryption_test_case_2),
8383 TEST_CASE_ST(ut_setup, ut_teardown,
8384 test_kasumi_decryption_test_case_3),
8385 TEST_CASE_ST(ut_setup, ut_teardown,
8386 test_kasumi_decryption_test_case_4),
8387 TEST_CASE_ST(ut_setup, ut_teardown,
8388 test_kasumi_decryption_test_case_5),
8390 TEST_CASE_ST(ut_setup, ut_teardown,
8391 test_kasumi_encryption_test_case_1_oop),
8392 TEST_CASE_ST(ut_setup, ut_teardown,
8393 test_kasumi_encryption_test_case_1_oop_sgl),
8396 TEST_CASE_ST(ut_setup, ut_teardown,
8397 test_kasumi_decryption_test_case_1_oop),
8399 /** KASUMI hash only (UIA1) */
8400 TEST_CASE_ST(ut_setup, ut_teardown,
8401 test_kasumi_hash_generate_test_case_1),
8402 TEST_CASE_ST(ut_setup, ut_teardown,
8403 test_kasumi_hash_generate_test_case_2),
8404 TEST_CASE_ST(ut_setup, ut_teardown,
8405 test_kasumi_hash_generate_test_case_3),
8406 TEST_CASE_ST(ut_setup, ut_teardown,
8407 test_kasumi_hash_generate_test_case_4),
8408 TEST_CASE_ST(ut_setup, ut_teardown,
8409 test_kasumi_hash_generate_test_case_5),
8410 TEST_CASE_ST(ut_setup, ut_teardown,
8411 test_kasumi_hash_generate_test_case_6),
8412 TEST_CASE_ST(ut_setup, ut_teardown,
8413 test_kasumi_hash_verify_test_case_1),
8414 TEST_CASE_ST(ut_setup, ut_teardown,
8415 test_kasumi_hash_verify_test_case_2),
8416 TEST_CASE_ST(ut_setup, ut_teardown,
8417 test_kasumi_hash_verify_test_case_3),
8418 TEST_CASE_ST(ut_setup, ut_teardown,
8419 test_kasumi_hash_verify_test_case_4),
8420 TEST_CASE_ST(ut_setup, ut_teardown,
8421 test_kasumi_hash_verify_test_case_5),
8422 TEST_CASE_ST(ut_setup, ut_teardown,
8423 test_kasumi_auth_cipher_test_case_1),
8424 TEST_CASE_ST(ut_setup, ut_teardown,
8425 test_kasumi_cipher_auth_test_case_1),
8426 TEST_CASES_END() /**< NULL terminate unit test array */
8429 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
8430 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
8431 .setup = testsuite_setup,
8432 .teardown = testsuite_teardown,
8433 .unit_test_cases = {
8434 /** SNOW 3G encrypt only (UEA2) */
8435 TEST_CASE_ST(ut_setup, ut_teardown,
8436 test_snow3g_encryption_test_case_1),
8437 TEST_CASE_ST(ut_setup, ut_teardown,
8438 test_snow3g_encryption_test_case_2),
8439 TEST_CASE_ST(ut_setup, ut_teardown,
8440 test_snow3g_encryption_test_case_3),
8441 TEST_CASE_ST(ut_setup, ut_teardown,
8442 test_snow3g_encryption_test_case_4),
8443 TEST_CASE_ST(ut_setup, ut_teardown,
8444 test_snow3g_encryption_test_case_5),
8446 TEST_CASE_ST(ut_setup, ut_teardown,
8447 test_snow3g_encryption_test_case_1_oop),
8448 TEST_CASE_ST(ut_setup, ut_teardown,
8449 test_snow3g_encryption_test_case_1_oop_sgl),
8450 TEST_CASE_ST(ut_setup, ut_teardown,
8451 test_snow3g_decryption_test_case_1_oop),
8453 TEST_CASE_ST(ut_setup, ut_teardown,
8454 test_snow3g_encryption_test_case_1_offset_oop),
8456 /** SNOW 3G decrypt only (UEA2) */
8457 TEST_CASE_ST(ut_setup, ut_teardown,
8458 test_snow3g_decryption_test_case_1),
8459 TEST_CASE_ST(ut_setup, ut_teardown,
8460 test_snow3g_decryption_test_case_2),
8461 TEST_CASE_ST(ut_setup, ut_teardown,
8462 test_snow3g_decryption_test_case_3),
8463 TEST_CASE_ST(ut_setup, ut_teardown,
8464 test_snow3g_decryption_test_case_4),
8465 TEST_CASE_ST(ut_setup, ut_teardown,
8466 test_snow3g_decryption_test_case_5),
8467 TEST_CASE_ST(ut_setup, ut_teardown,
8468 test_snow3g_hash_generate_test_case_1),
8469 TEST_CASE_ST(ut_setup, ut_teardown,
8470 test_snow3g_hash_generate_test_case_2),
8471 TEST_CASE_ST(ut_setup, ut_teardown,
8472 test_snow3g_hash_generate_test_case_3),
8473 /* Tests with buffers which length is not byte-aligned */
8474 TEST_CASE_ST(ut_setup, ut_teardown,
8475 test_snow3g_hash_generate_test_case_4),
8476 TEST_CASE_ST(ut_setup, ut_teardown,
8477 test_snow3g_hash_generate_test_case_5),
8478 TEST_CASE_ST(ut_setup, ut_teardown,
8479 test_snow3g_hash_generate_test_case_6),
8480 TEST_CASE_ST(ut_setup, ut_teardown,
8481 test_snow3g_hash_verify_test_case_1),
8482 TEST_CASE_ST(ut_setup, ut_teardown,
8483 test_snow3g_hash_verify_test_case_2),
8484 TEST_CASE_ST(ut_setup, ut_teardown,
8485 test_snow3g_hash_verify_test_case_3),
8486 /* Tests with buffers which length is not byte-aligned */
8487 TEST_CASE_ST(ut_setup, ut_teardown,
8488 test_snow3g_hash_verify_test_case_4),
8489 TEST_CASE_ST(ut_setup, ut_teardown,
8490 test_snow3g_hash_verify_test_case_5),
8491 TEST_CASE_ST(ut_setup, ut_teardown,
8492 test_snow3g_hash_verify_test_case_6),
8493 TEST_CASE_ST(ut_setup, ut_teardown,
8494 test_snow3g_cipher_auth_test_case_1),
8495 TEST_CASE_ST(ut_setup, ut_teardown,
8496 test_snow3g_auth_cipher_test_case_1),
8498 TEST_CASES_END() /**< NULL terminate unit test array */
8502 static struct unit_test_suite cryptodev_sw_zuc_testsuite = {
8503 .suite_name = "Crypto Device SW ZUC Unit Test Suite",
8504 .setup = testsuite_setup,
8505 .teardown = testsuite_teardown,
8506 .unit_test_cases = {
8507 /** ZUC encrypt only (EEA3) */
8508 TEST_CASE_ST(ut_setup, ut_teardown,
8509 test_zuc_encryption_test_case_1),
8510 TEST_CASE_ST(ut_setup, ut_teardown,
8511 test_zuc_encryption_test_case_2),
8512 TEST_CASE_ST(ut_setup, ut_teardown,
8513 test_zuc_encryption_test_case_3),
8514 TEST_CASE_ST(ut_setup, ut_teardown,
8515 test_zuc_encryption_test_case_4),
8516 TEST_CASE_ST(ut_setup, ut_teardown,
8517 test_zuc_encryption_test_case_5),
8518 TEST_CASE_ST(ut_setup, ut_teardown,
8519 test_zuc_hash_generate_test_case_1),
8520 TEST_CASE_ST(ut_setup, ut_teardown,
8521 test_zuc_hash_generate_test_case_2),
8522 TEST_CASE_ST(ut_setup, ut_teardown,
8523 test_zuc_hash_generate_test_case_3),
8524 TEST_CASE_ST(ut_setup, ut_teardown,
8525 test_zuc_hash_generate_test_case_4),
8526 TEST_CASE_ST(ut_setup, ut_teardown,
8527 test_zuc_hash_generate_test_case_5),
8528 TEST_CASE_ST(ut_setup, ut_teardown,
8529 test_zuc_encryption_test_case_6_sgl),
8530 TEST_CASES_END() /**< NULL terminate unit test array */
8534 static struct unit_test_suite cryptodev_dpaa2_sec_testsuite = {
8535 .suite_name = "Crypto DPAA2_SEC Unit Test Suite",
8536 .setup = testsuite_setup,
8537 .teardown = testsuite_teardown,
8538 .unit_test_cases = {
8539 TEST_CASE_ST(ut_setup, ut_teardown,
8540 test_device_configure_invalid_dev_id),
8541 TEST_CASE_ST(ut_setup, ut_teardown,
8542 test_multi_session),
8544 TEST_CASE_ST(ut_setup, ut_teardown,
8545 test_AES_chain_dpaa2_sec_all),
8546 TEST_CASE_ST(ut_setup, ut_teardown,
8547 test_3DES_chain_dpaa2_sec_all),
8548 TEST_CASE_ST(ut_setup, ut_teardown,
8549 test_AES_cipheronly_dpaa2_sec_all),
8550 TEST_CASE_ST(ut_setup, ut_teardown,
8551 test_3DES_cipheronly_dpaa2_sec_all),
8553 /** HMAC_MD5 Authentication */
8554 TEST_CASE_ST(ut_setup, ut_teardown,
8555 test_MD5_HMAC_generate_case_1),
8556 TEST_CASE_ST(ut_setup, ut_teardown,
8557 test_MD5_HMAC_verify_case_1),
8558 TEST_CASE_ST(ut_setup, ut_teardown,
8559 test_MD5_HMAC_generate_case_2),
8560 TEST_CASE_ST(ut_setup, ut_teardown,
8561 test_MD5_HMAC_verify_case_2),
8563 TEST_CASES_END() /**< NULL terminate unit test array */
8567 static struct unit_test_suite cryptodev_null_testsuite = {
8568 .suite_name = "Crypto Device NULL Unit Test Suite",
8569 .setup = testsuite_setup,
8570 .teardown = testsuite_teardown,
8571 .unit_test_cases = {
8572 TEST_CASE_ST(ut_setup, ut_teardown,
8573 test_null_auth_only_operation),
8574 TEST_CASE_ST(ut_setup, ut_teardown,
8575 test_null_cipher_only_operation),
8576 TEST_CASE_ST(ut_setup, ut_teardown,
8577 test_null_cipher_auth_operation),
8578 TEST_CASE_ST(ut_setup, ut_teardown,
8579 test_null_auth_cipher_operation),
8580 TEST_CASE_ST(ut_setup, ut_teardown,
8581 test_null_invalid_operation),
8582 TEST_CASE_ST(ut_setup, ut_teardown,
8583 test_null_burst_operation),
8585 TEST_CASES_END() /**< NULL terminate unit test array */
8589 static struct unit_test_suite cryptodev_armv8_testsuite = {
8590 .suite_name = "Crypto Device ARMv8 Unit Test Suite",
8591 .setup = testsuite_setup,
8592 .teardown = testsuite_teardown,
8593 .unit_test_cases = {
8594 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_armv8_all),
8596 /** Negative tests */
8597 TEST_CASE_ST(ut_setup, ut_teardown,
8598 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
8599 TEST_CASE_ST(ut_setup, ut_teardown,
8600 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
8602 TEST_CASES_END() /**< NULL terminate unit test array */
8607 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
8609 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
8610 return unit_test_suite_runner(&cryptodev_qat_testsuite);
8614 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
8616 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
8618 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
8622 test_cryptodev_openssl(void)
8624 gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD;
8626 return unit_test_suite_runner(&cryptodev_openssl_testsuite);
8630 test_cryptodev_aesni_gcm(void)
8632 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
8634 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
8638 test_cryptodev_null(void)
8640 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
8642 return unit_test_suite_runner(&cryptodev_null_testsuite);
8646 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
8648 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
8650 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
8654 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
8656 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
8658 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
8662 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
8664 gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
8666 return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
8670 test_cryptodev_armv8(void)
8672 gbl_cryptodev_type = RTE_CRYPTODEV_ARMV8_PMD;
8674 return unit_test_suite_runner(&cryptodev_armv8_testsuite);
8677 #ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER
8680 test_cryptodev_scheduler(void /*argv __rte_unused, int argc __rte_unused*/)
8682 gbl_cryptodev_type = RTE_CRYPTODEV_SCHEDULER_PMD;
8683 return unit_test_suite_runner(&cryptodev_scheduler_testsuite);
8686 REGISTER_TEST_COMMAND(cryptodev_scheduler_autotest, test_cryptodev_scheduler);
8691 test_cryptodev_dpaa2_sec(void /*argv __rte_unused, int argc __rte_unused*/)
8693 gbl_cryptodev_type = RTE_CRYPTODEV_DPAA2_SEC_PMD;
8694 return unit_test_suite_runner(&cryptodev_dpaa2_sec_testsuite);
8697 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
8698 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
8699 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
8700 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
8701 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
8702 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
8703 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
8704 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);
8705 REGISTER_TEST_COMMAND(cryptodev_sw_armv8_autotest, test_cryptodev_armv8);
8706 REGISTER_TEST_COMMAND(cryptodev_dpaa2_sec_autotest, test_cryptodev_dpaa2_sec);