4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
44 #include "test_cryptodev.h"
46 #include "test_cryptodev_blockcipher.h"
47 #include "test_cryptodev_aes_test_vectors.h"
48 #include "test_cryptodev_kasumi_test_vectors.h"
49 #include "test_cryptodev_kasumi_hash_test_vectors.h"
50 #include "test_cryptodev_snow3g_test_vectors.h"
51 #include "test_cryptodev_snow3g_hash_test_vectors.h"
52 #include "test_cryptodev_zuc_test_vectors.h"
53 #include "test_cryptodev_zuc_hash_test_vectors.h"
54 #include "test_cryptodev_gcm_test_vectors.h"
55 #include "test_cryptodev_hmac_test_vectors.h"
57 static enum rte_cryptodev_type gbl_cryptodev_type;
59 struct crypto_testsuite_params {
60 struct rte_mempool *mbuf_pool;
61 struct rte_mempool *op_mpool;
62 struct rte_cryptodev_config conf;
63 struct rte_cryptodev_qp_conf qp_conf;
65 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
66 uint8_t valid_dev_count;
69 struct crypto_unittest_params {
70 struct rte_crypto_sym_xform cipher_xform;
71 struct rte_crypto_sym_xform auth_xform;
73 struct rte_cryptodev_sym_session *sess;
75 struct rte_crypto_op *op;
77 struct rte_mbuf *obuf, *ibuf;
82 #define ALIGN_POW2_ROUNDUP(num, align) \
83 (((num) + (align) - 1) & ~((align) - 1))
86 * Forward declarations.
89 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
90 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
94 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
95 struct crypto_unittest_params *ut_params,
96 struct crypto_testsuite_params *ts_param,
97 const uint8_t *cipher,
98 const uint8_t *digest,
101 static struct rte_mbuf *
102 setup_test_string(struct rte_mempool *mpool,
103 const char *string, size_t len, uint8_t blocksize)
105 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
106 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
108 memset(m->buf_addr, 0, m->buf_len);
110 char *dst = rte_pktmbuf_append(m, t_len);
117 rte_memcpy(dst, string, t_len);
119 memset(dst, 0, t_len);
125 /* Get number of bytes in X bits (rounding up) */
127 ceil_byte_length(uint32_t num_bits)
130 return ((num_bits >> 3) + 1);
132 return (num_bits >> 3);
135 static struct rte_crypto_op *
136 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
138 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
139 printf("Error sending packet for encryption");
145 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
151 static struct crypto_testsuite_params testsuite_params = { NULL };
152 static struct crypto_unittest_params unittest_params;
155 testsuite_setup(void)
157 struct crypto_testsuite_params *ts_params = &testsuite_params;
158 struct rte_cryptodev_info info;
159 unsigned i, nb_devs, dev_id;
163 memset(ts_params, 0, sizeof(*ts_params));
165 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
166 if (ts_params->mbuf_pool == NULL) {
167 /* Not already created so create */
168 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
170 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
172 if (ts_params->mbuf_pool == NULL) {
173 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
178 ts_params->op_mpool = rte_crypto_op_pool_create(
179 "MBUF_CRYPTO_SYM_OP_POOL",
180 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
181 NUM_MBUFS, MBUF_CACHE_SIZE,
183 sizeof(struct rte_crypto_sym_xform),
185 if (ts_params->op_mpool == NULL) {
186 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
190 /* Create 2 AESNI MB devices if required */
191 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
192 #ifndef RTE_LIBRTE_PMD_AESNI_MB
193 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
194 " enabled in config file to run this testsuite.\n");
197 nb_devs = rte_cryptodev_count_devtype(
198 RTE_CRYPTODEV_AESNI_MB_PMD);
200 for (i = nb_devs; i < 2; i++) {
201 ret = rte_eal_vdev_init(
202 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
204 TEST_ASSERT(ret == 0,
205 "Failed to create instance %u of"
207 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
212 /* Create 2 AESNI GCM devices if required */
213 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
214 #ifndef RTE_LIBRTE_PMD_AESNI_GCM
215 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be"
216 " enabled in config file to run this testsuite.\n");
219 nb_devs = rte_cryptodev_count_devtype(
220 RTE_CRYPTODEV_AESNI_GCM_PMD);
222 for (i = nb_devs; i < 2; i++) {
223 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
224 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
225 "Failed to create instance %u of"
227 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
232 /* Create 2 SNOW 3G devices if required */
233 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
234 #ifndef RTE_LIBRTE_PMD_SNOW3G
235 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be"
236 " enabled in config file to run this testsuite.\n");
239 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
241 for (i = nb_devs; i < 2; i++) {
242 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
243 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
244 "Failed to create instance %u of"
246 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
251 /* Create 2 KASUMI devices if required */
252 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
253 #ifndef RTE_LIBRTE_PMD_KASUMI
254 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be"
255 " enabled in config file to run this testsuite.\n");
258 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
260 for (i = nb_devs; i < 2; i++) {
261 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
262 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
263 "Failed to create instance %u of"
265 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
270 /* Create 2 ZUC devices if required */
271 if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) {
272 #ifndef RTE_LIBRTE_PMD_ZUC
273 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be"
274 " enabled in config file to run this testsuite.\n");
277 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD);
279 for (i = nb_devs; i < 2; i++) {
280 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
281 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
282 "Failed to create instance %u of"
284 i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
289 /* Create 2 NULL devices if required */
290 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
291 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO
292 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be"
293 " enabled in config file to run this testsuite.\n");
296 nb_devs = rte_cryptodev_count_devtype(
297 RTE_CRYPTODEV_NULL_PMD);
299 for (i = nb_devs; i < 2; i++) {
300 int dev_id = rte_eal_vdev_init(
301 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
303 TEST_ASSERT(dev_id >= 0,
304 "Failed to create instance %u of"
306 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD));
311 #ifndef RTE_LIBRTE_PMD_QAT
312 if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) {
313 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled "
314 "in config file to run this testsuite.\n");
319 nb_devs = rte_cryptodev_count();
321 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
325 /* Create list of valid crypto devs */
326 for (i = 0; i < nb_devs; i++) {
327 rte_cryptodev_info_get(i, &info);
328 if (info.dev_type == gbl_cryptodev_type)
329 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
332 if (ts_params->valid_dev_count < 1)
335 /* Set up all the qps on the first of the valid devices found */
336 for (i = 0; i < 1; i++) {
337 dev_id = ts_params->valid_devs[i];
339 rte_cryptodev_info_get(dev_id, &info);
342 * Since we can't free and re-allocate queue memory always set
343 * the queues on this device up to max size first so enough
344 * memory is allocated for any later re-configures needed by
348 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
349 ts_params->conf.socket_id = SOCKET_ID_ANY;
350 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
352 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
354 "Failed to configure cryptodev %u with %u qps",
355 dev_id, ts_params->conf.nb_queue_pairs);
357 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
359 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
360 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
361 dev_id, qp_id, &ts_params->qp_conf,
362 rte_cryptodev_socket_id(dev_id)),
363 "Failed to setup queue pair %u on "
373 testsuite_teardown(void)
375 struct crypto_testsuite_params *ts_params = &testsuite_params;
377 if (ts_params->mbuf_pool != NULL) {
378 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
379 rte_mempool_avail_count(ts_params->mbuf_pool));
382 if (ts_params->op_mpool != NULL) {
383 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
384 rte_mempool_avail_count(ts_params->op_mpool));
392 struct crypto_testsuite_params *ts_params = &testsuite_params;
393 struct crypto_unittest_params *ut_params = &unittest_params;
397 /* Clear unit test parameters before running test */
398 memset(ut_params, 0, sizeof(*ut_params));
400 /* Reconfigure device to default parameters */
401 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
402 ts_params->conf.socket_id = SOCKET_ID_ANY;
403 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT;
405 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
407 "Failed to configure cryptodev %u",
408 ts_params->valid_devs[0]);
411 * Now reconfigure queues to size we actually want to use in this
414 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
416 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
417 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
418 ts_params->valid_devs[0], qp_id,
420 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
421 "Failed to setup queue pair %u on cryptodev %u",
422 qp_id, ts_params->valid_devs[0]);
426 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
428 /* Start the device */
429 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
430 "Failed to start cryptodev %u",
431 ts_params->valid_devs[0]);
439 struct crypto_testsuite_params *ts_params = &testsuite_params;
440 struct crypto_unittest_params *ut_params = &unittest_params;
441 struct rte_cryptodev_stats stats;
443 /* free crypto session structure */
444 if (ut_params->sess) {
445 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
447 ut_params->sess = NULL;
450 /* free crypto operation structure */
452 rte_crypto_op_free(ut_params->op);
455 * free mbuf - both obuf and ibuf are usually the same,
456 * so check if they point at the same address is necessary,
457 * to avoid freeing the mbuf twice.
459 if (ut_params->obuf) {
460 rte_pktmbuf_free(ut_params->obuf);
461 if (ut_params->ibuf == ut_params->obuf)
465 if (ut_params->ibuf) {
466 rte_pktmbuf_free(ut_params->ibuf);
470 if (ts_params->mbuf_pool != NULL)
471 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
472 rte_mempool_avail_count(ts_params->mbuf_pool));
474 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
476 /* Stop the device */
477 rte_cryptodev_stop(ts_params->valid_devs[0]);
481 test_device_configure_invalid_dev_id(void)
483 struct crypto_testsuite_params *ts_params = &testsuite_params;
484 uint16_t dev_id, num_devs = 0;
486 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
487 "Need at least %d devices for test", 1);
489 /* valid dev_id values */
490 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
492 /* Stop the device in case it's started so it can be configured */
493 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
495 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
496 "Failed test for rte_cryptodev_configure: "
497 "invalid dev_num %u", dev_id);
499 /* invalid dev_id values */
502 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
503 "Failed test for rte_cryptodev_configure: "
504 "invalid dev_num %u", dev_id);
508 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
509 "Failed test for rte_cryptodev_configure:"
510 "invalid dev_num %u", dev_id);
516 test_device_configure_invalid_queue_pair_ids(void)
518 struct crypto_testsuite_params *ts_params = &testsuite_params;
520 /* Stop the device in case it's started so it can be configured */
521 rte_cryptodev_stop(ts_params->valid_devs[0]);
523 /* valid - one queue pairs */
524 ts_params->conf.nb_queue_pairs = 1;
526 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
528 "Failed to configure cryptodev: dev_id %u, qp_id %u",
529 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
532 /* valid - max value queue pairs */
533 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
535 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
537 "Failed to configure cryptodev: dev_id %u, qp_id %u",
538 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
541 /* invalid - zero queue pairs */
542 ts_params->conf.nb_queue_pairs = 0;
544 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
546 "Failed test for rte_cryptodev_configure, dev_id %u,"
548 ts_params->valid_devs[0],
549 ts_params->conf.nb_queue_pairs);
552 /* invalid - max value supported by field queue pairs */
553 ts_params->conf.nb_queue_pairs = UINT16_MAX;
555 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
557 "Failed test for rte_cryptodev_configure, dev_id %u,"
559 ts_params->valid_devs[0],
560 ts_params->conf.nb_queue_pairs);
563 /* invalid - max value + 1 queue pairs */
564 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
566 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
568 "Failed test for rte_cryptodev_configure, dev_id %u,"
570 ts_params->valid_devs[0],
571 ts_params->conf.nb_queue_pairs);
577 test_queue_pair_descriptor_setup(void)
579 struct crypto_testsuite_params *ts_params = &testsuite_params;
580 struct rte_cryptodev_info dev_info;
581 struct rte_cryptodev_qp_conf qp_conf = {
582 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
587 /* Stop the device in case it's started so it can be configured */
588 rte_cryptodev_stop(ts_params->valid_devs[0]);
591 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
593 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
595 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
596 &ts_params->conf), "Failed to configure cryptodev %u",
597 ts_params->valid_devs[0]);
601 * Test various ring sizes on this device. memzones can't be
602 * freed so are re-used if ring is released and re-created.
604 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
606 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
607 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
608 ts_params->valid_devs[0], qp_id, &qp_conf,
609 rte_cryptodev_socket_id(
610 ts_params->valid_devs[0])),
612 "rte_cryptodev_queue_pair_setup: num_inflights "
613 "%u on qp %u on cryptodev %u",
614 qp_conf.nb_descriptors, qp_id,
615 ts_params->valid_devs[0]);
618 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
620 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
621 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
622 ts_params->valid_devs[0], qp_id, &qp_conf,
623 rte_cryptodev_socket_id(
624 ts_params->valid_devs[0])),
626 " rte_cryptodev_queue_pair_setup: num_inflights"
627 " %u on qp %u on cryptodev %u",
628 qp_conf.nb_descriptors, qp_id,
629 ts_params->valid_devs[0]);
632 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
634 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
635 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
636 ts_params->valid_devs[0], qp_id, &qp_conf,
637 rte_cryptodev_socket_id(
638 ts_params->valid_devs[0])),
640 "rte_cryptodev_queue_pair_setup: num_inflights"
641 " %u on qp %u on cryptodev %u",
642 qp_conf.nb_descriptors, qp_id,
643 ts_params->valid_devs[0]);
646 /* invalid number of descriptors - max supported + 2 */
647 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
649 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
650 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
651 ts_params->valid_devs[0], qp_id, &qp_conf,
652 rte_cryptodev_socket_id(
653 ts_params->valid_devs[0])),
654 "Unexpectedly passed test for "
655 "rte_cryptodev_queue_pair_setup:"
656 "num_inflights %u on qp %u on cryptodev %u",
657 qp_conf.nb_descriptors, qp_id,
658 ts_params->valid_devs[0]);
661 /* invalid number of descriptors - max value of parameter */
662 qp_conf.nb_descriptors = UINT32_MAX-1;
664 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
665 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
666 ts_params->valid_devs[0], qp_id, &qp_conf,
667 rte_cryptodev_socket_id(
668 ts_params->valid_devs[0])),
669 "Unexpectedly passed test for "
670 "rte_cryptodev_queue_pair_setup:"
671 "num_inflights %u on qp %u on cryptodev %u",
672 qp_conf.nb_descriptors, qp_id,
673 ts_params->valid_devs[0]);
676 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
678 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
679 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
680 ts_params->valid_devs[0], qp_id, &qp_conf,
681 rte_cryptodev_socket_id(
682 ts_params->valid_devs[0])),
684 " rte_cryptodev_queue_pair_setup:"
685 "num_inflights %u on qp %u on cryptodev %u",
686 qp_conf.nb_descriptors, qp_id,
687 ts_params->valid_devs[0]);
690 /* invalid number of descriptors - max supported + 1 */
691 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
693 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
694 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
695 ts_params->valid_devs[0], qp_id, &qp_conf,
696 rte_cryptodev_socket_id(
697 ts_params->valid_devs[0])),
698 "Unexpectedly passed test for "
699 "rte_cryptodev_queue_pair_setup:"
700 "num_inflights %u on qp %u on cryptodev %u",
701 qp_conf.nb_descriptors, qp_id,
702 ts_params->valid_devs[0]);
705 /* test invalid queue pair id */
706 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
708 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
710 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
711 ts_params->valid_devs[0],
713 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
714 "Failed test for rte_cryptodev_queue_pair_setup:"
715 "invalid qp %u on cryptodev %u",
716 qp_id, ts_params->valid_devs[0]);
718 qp_id = 0xffff; /*invalid*/
720 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
721 ts_params->valid_devs[0],
723 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
724 "Failed test for rte_cryptodev_queue_pair_setup:"
725 "invalid qp %u on cryptodev %u",
726 qp_id, ts_params->valid_devs[0]);
731 /* ***** Plaintext data for tests ***** */
733 const char catch_22_quote_1[] =
734 "There was only one catch and that was Catch-22, which "
735 "specified that a concern for one's safety in the face of "
736 "dangers that were real and immediate was the process of a "
737 "rational mind. Orr was crazy and could be grounded. All he "
738 "had to do was ask; and as soon as he did, he would no longer "
739 "be crazy and would have to fly more missions. Orr would be "
740 "crazy to fly more missions and sane if he didn't, but if he "
741 "was sane he had to fly them. If he flew them he was crazy "
742 "and didn't have to; but if he didn't want to he was sane and "
743 "had to. Yossarian was moved very deeply by the absolute "
744 "simplicity of this clause of Catch-22 and let out a "
745 "respectful whistle. \"That's some catch, that Catch-22\", he "
746 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
748 const char catch_22_quote[] =
749 "What a lousy earth! He wondered how many people were "
750 "destitute that same night even in his own prosperous country, "
751 "how many homes were shanties, how many husbands were drunk "
752 "and wives socked, and how many children were bullied, abused, "
753 "or abandoned. How many families hungered for food they could "
754 "not afford to buy? How many hearts were broken? How many "
755 "suicides would take place that same night, how many people "
756 "would go insane? How many cockroaches and landlords would "
757 "triumph? How many winners were losers, successes failures, "
758 "and rich men poor men? How many wise guys were stupid? How "
759 "many happy endings were unhappy endings? How many honest men "
760 "were liars, brave men cowards, loyal men traitors, how many "
761 "sainted men were corrupt, how many people in positions of "
762 "trust had sold their souls to bodyguards, how many had never "
763 "had souls? How many straight-and-narrow paths were crooked "
764 "paths? How many best families were worst families and how "
765 "many good people were bad people? When you added them all up "
766 "and then subtracted, you might be left with only the children, "
767 "and perhaps with Albert Einstein and an old violinist or "
768 "sculptor somewhere.";
770 #define QUOTE_480_BYTES (480)
771 #define QUOTE_512_BYTES (512)
772 #define QUOTE_768_BYTES (768)
773 #define QUOTE_1024_BYTES (1024)
777 /* ***** SHA1 Hash Tests ***** */
779 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
781 static uint8_t hmac_sha1_key[] = {
782 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
783 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
784 0xDE, 0xF4, 0xDE, 0xAD };
786 /* ***** SHA224 Hash Tests ***** */
788 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
791 /* ***** AES-CBC Cipher Tests ***** */
793 #define CIPHER_KEY_LENGTH_AES_CBC (16)
794 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
796 static uint8_t aes_cbc_key[] = {
797 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
798 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
800 static uint8_t aes_cbc_iv[] = {
801 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
802 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
805 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
807 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
808 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
809 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
810 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
811 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
812 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
813 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
814 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
815 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
816 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
817 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
818 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
819 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
820 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
821 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
822 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
823 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
824 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
825 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
826 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
827 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
828 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
829 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
830 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
831 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
832 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
833 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
834 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
835 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
836 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
837 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
838 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
839 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
840 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
841 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
842 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
843 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
844 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
845 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
846 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
847 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
848 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
849 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
850 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
851 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
852 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
853 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
854 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
855 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
856 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
857 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
858 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
859 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
860 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
861 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
862 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
863 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
864 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
865 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
866 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
867 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
868 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
869 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
870 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
871 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
874 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
875 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
876 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
877 0x18, 0x8c, 0x1d, 0x32
881 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
883 struct crypto_testsuite_params *ts_params = &testsuite_params;
884 struct crypto_unittest_params *ut_params = &unittest_params;
886 /* Generate test mbuf data and space for digest */
887 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
888 catch_22_quote, QUOTE_512_BYTES, 0);
890 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
891 DIGEST_BYTE_LENGTH_SHA1);
892 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
894 /* Setup Cipher Parameters */
895 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
896 ut_params->cipher_xform.next = &ut_params->auth_xform;
898 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
899 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
900 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
901 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
903 /* Setup HMAC Parameters */
904 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
906 ut_params->auth_xform.next = NULL;
908 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
909 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
910 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
911 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
912 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
914 /* Create crypto session*/
915 ut_params->sess = rte_cryptodev_sym_session_create(
916 ts_params->valid_devs[0],
917 &ut_params->cipher_xform);
918 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
920 /* Generate crypto op data structure */
921 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
922 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
923 TEST_ASSERT_NOT_NULL(ut_params->op,
924 "Failed to allocate symmetric crypto operation struct");
926 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
928 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
930 /* set crypto operation source mbuf */
931 sym_op->m_src = ut_params->ibuf;
933 /* Set crypto operation authentication parameters */
934 sym_op->auth.digest.data = ut_params->digest;
935 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
936 ut_params->ibuf, QUOTE_512_BYTES);
937 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
939 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
940 sym_op->auth.data.length = QUOTE_512_BYTES;
942 /* Set crypto operation cipher parameters */
943 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
944 CIPHER_IV_LENGTH_AES_CBC);
945 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
946 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
948 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
949 CIPHER_IV_LENGTH_AES_CBC);
951 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
952 sym_op->cipher.data.length = QUOTE_512_BYTES;
954 /* Process crypto operation */
955 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
956 ut_params->op), "failed to process sym crypto op");
958 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
959 "crypto op processing failed");
962 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
963 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
965 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
966 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
968 "ciphertext data not as expected");
970 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
972 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
973 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
974 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
975 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
976 DIGEST_BYTE_LENGTH_SHA1,
977 "Generated digest data not as expected");
982 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
984 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
986 static uint8_t hmac_sha512_key[] = {
987 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
988 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
989 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
990 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
991 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
992 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
993 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
994 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
996 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
997 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
998 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
999 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1000 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1001 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1002 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1003 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1004 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1009 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1010 struct crypto_unittest_params *ut_params,
1011 uint8_t *cipher_key,
1015 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1016 struct crypto_unittest_params *ut_params,
1017 struct crypto_testsuite_params *ts_params,
1018 const uint8_t *cipher,
1019 const uint8_t *digest,
1024 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1025 struct crypto_unittest_params *ut_params,
1026 uint8_t *cipher_key,
1030 /* Setup Cipher Parameters */
1031 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1032 ut_params->cipher_xform.next = NULL;
1034 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1035 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1036 ut_params->cipher_xform.cipher.key.data = cipher_key;
1037 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1039 /* Setup HMAC Parameters */
1040 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1041 ut_params->auth_xform.next = &ut_params->cipher_xform;
1043 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1044 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1045 ut_params->auth_xform.auth.key.data = hmac_key;
1046 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1047 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1049 return TEST_SUCCESS;
1054 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1055 struct crypto_unittest_params *ut_params,
1056 struct crypto_testsuite_params *ts_params,
1057 const uint8_t *cipher,
1058 const uint8_t *digest,
1061 /* Generate test mbuf data and digest */
1062 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1065 QUOTE_512_BYTES, 0);
1067 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1068 DIGEST_BYTE_LENGTH_SHA512);
1069 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1071 rte_memcpy(ut_params->digest,
1073 DIGEST_BYTE_LENGTH_SHA512);
1075 /* Generate Crypto op data structure */
1076 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1077 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1078 TEST_ASSERT_NOT_NULL(ut_params->op,
1079 "Failed to allocate symmetric crypto operation struct");
1081 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1083 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1085 /* set crypto operation source mbuf */
1086 sym_op->m_src = ut_params->ibuf;
1088 sym_op->auth.digest.data = ut_params->digest;
1089 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1090 ut_params->ibuf, QUOTE_512_BYTES);
1091 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1093 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1094 sym_op->auth.data.length = QUOTE_512_BYTES;
1096 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1097 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1098 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1099 ut_params->ibuf, 0);
1100 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1102 rte_memcpy(sym_op->cipher.iv.data, iv,
1103 CIPHER_IV_LENGTH_AES_CBC);
1105 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1106 sym_op->cipher.data.length = QUOTE_512_BYTES;
1108 /* Process crypto operation */
1109 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1110 ut_params->op), "failed to process sym crypto op");
1112 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1113 "crypto op processing failed");
1115 ut_params->obuf = ut_params->op->sym->m_src;
1118 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1119 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1120 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1122 "Plaintext data not as expected");
1125 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1126 "Digest verification failed");
1128 return TEST_SUCCESS;
1132 test_AES_chain_mb_all(void)
1134 struct crypto_testsuite_params *ts_params = &testsuite_params;
1137 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1138 ts_params->op_mpool, ts_params->valid_devs[0],
1139 RTE_CRYPTODEV_AESNI_MB_PMD,
1140 BLKCIPHER_AES_CHAIN_TYPE);
1142 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1144 return TEST_SUCCESS;
1148 test_AES_chain_qat_all(void)
1150 struct crypto_testsuite_params *ts_params = &testsuite_params;
1153 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1154 ts_params->op_mpool, ts_params->valid_devs[0],
1155 RTE_CRYPTODEV_QAT_SYM_PMD,
1156 BLKCIPHER_AES_CHAIN_TYPE);
1158 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1160 return TEST_SUCCESS;
1163 /* ***** SNOW 3G Tests ***** */
1165 create_wireless_algo_hash_session(uint8_t dev_id,
1166 const uint8_t *key, const uint8_t key_len,
1167 const uint8_t aad_len, const uint8_t auth_len,
1168 enum rte_crypto_auth_operation op,
1169 enum rte_crypto_auth_algorithm algo)
1171 uint8_t hash_key[key_len];
1173 struct crypto_unittest_params *ut_params = &unittest_params;
1175 memcpy(hash_key, key, key_len);
1177 TEST_HEXDUMP(stdout, "key:", key, key_len);
1179 /* Setup Authentication Parameters */
1180 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1181 ut_params->auth_xform.next = NULL;
1183 ut_params->auth_xform.auth.op = op;
1184 ut_params->auth_xform.auth.algo = algo;
1185 ut_params->auth_xform.auth.key.length = key_len;
1186 ut_params->auth_xform.auth.key.data = hash_key;
1187 ut_params->auth_xform.auth.digest_length = auth_len;
1188 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1189 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1190 &ut_params->auth_xform);
1191 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1196 create_wireless_algo_cipher_session(uint8_t dev_id,
1197 enum rte_crypto_cipher_operation op,
1198 enum rte_crypto_cipher_algorithm algo,
1199 const uint8_t *key, const uint8_t key_len)
1201 uint8_t cipher_key[key_len];
1203 struct crypto_unittest_params *ut_params = &unittest_params;
1205 memcpy(cipher_key, key, key_len);
1207 /* Setup Cipher Parameters */
1208 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1209 ut_params->cipher_xform.next = NULL;
1211 ut_params->cipher_xform.cipher.algo = algo;
1212 ut_params->cipher_xform.cipher.op = op;
1213 ut_params->cipher_xform.cipher.key.data = cipher_key;
1214 ut_params->cipher_xform.cipher.key.length = key_len;
1216 TEST_HEXDUMP(stdout, "key:", key, key_len);
1218 /* Create Crypto session */
1219 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1222 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1227 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1228 const unsigned cipher_len,
1229 const unsigned cipher_offset,
1230 enum rte_crypto_cipher_algorithm algo)
1232 struct crypto_testsuite_params *ts_params = &testsuite_params;
1233 struct crypto_unittest_params *ut_params = &unittest_params;
1234 unsigned iv_pad_len = 0;
1236 /* Generate Crypto op data structure */
1237 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1238 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1239 TEST_ASSERT_NOT_NULL(ut_params->op,
1240 "Failed to allocate pktmbuf offload");
1242 /* Set crypto operation data parameters */
1243 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1245 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1247 /* set crypto operation source mbuf */
1248 sym_op->m_src = ut_params->ibuf;
1251 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1252 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1254 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1256 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1259 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1261 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1262 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1263 sym_op->cipher.iv.length = iv_pad_len;
1265 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1266 sym_op->cipher.data.length = cipher_len;
1267 sym_op->cipher.data.offset = cipher_offset;
1272 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1273 const unsigned cipher_len,
1274 const unsigned cipher_offset,
1275 enum rte_crypto_cipher_algorithm algo)
1277 struct crypto_testsuite_params *ts_params = &testsuite_params;
1278 struct crypto_unittest_params *ut_params = &unittest_params;
1279 unsigned iv_pad_len = 0;
1281 /* Generate Crypto op data structure */
1282 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1283 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1284 TEST_ASSERT_NOT_NULL(ut_params->op,
1285 "Failed to allocate pktmbuf offload");
1287 /* Set crypto operation data parameters */
1288 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1290 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1292 /* set crypto operation source mbuf */
1293 sym_op->m_src = ut_params->ibuf;
1294 sym_op->m_dst = ut_params->obuf;
1297 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1298 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1300 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1301 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1304 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1306 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1307 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1308 sym_op->cipher.iv.length = iv_pad_len;
1310 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1311 sym_op->cipher.data.length = cipher_len;
1312 sym_op->cipher.data.offset = cipher_offset;
1317 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1318 enum rte_crypto_cipher_operation cipher_op,
1319 enum rte_crypto_auth_operation auth_op,
1320 enum rte_crypto_auth_algorithm auth_algo,
1321 enum rte_crypto_cipher_algorithm cipher_algo,
1322 const uint8_t *key, const uint8_t key_len,
1323 const uint8_t aad_len, const uint8_t auth_len)
1326 uint8_t cipher_auth_key[key_len];
1328 struct crypto_unittest_params *ut_params = &unittest_params;
1330 memcpy(cipher_auth_key, key, key_len);
1332 /* Setup Authentication Parameters */
1333 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1334 ut_params->auth_xform.next = NULL;
1336 ut_params->auth_xform.auth.op = auth_op;
1337 ut_params->auth_xform.auth.algo = auth_algo;
1338 ut_params->auth_xform.auth.key.length = key_len;
1339 /* Hash key = cipher key */
1340 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1341 ut_params->auth_xform.auth.digest_length = auth_len;
1342 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1344 /* Setup Cipher Parameters */
1345 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1346 ut_params->cipher_xform.next = &ut_params->auth_xform;
1348 ut_params->cipher_xform.cipher.algo = cipher_algo;
1349 ut_params->cipher_xform.cipher.op = cipher_op;
1350 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1351 ut_params->cipher_xform.cipher.key.length = key_len;
1353 TEST_HEXDUMP(stdout, "key:", key, key_len);
1355 /* Create Crypto session*/
1356 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1357 &ut_params->cipher_xform);
1359 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1364 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
1365 enum rte_crypto_cipher_operation cipher_op,
1366 enum rte_crypto_auth_operation auth_op,
1367 enum rte_crypto_auth_algorithm auth_algo,
1368 enum rte_crypto_cipher_algorithm cipher_algo,
1369 const uint8_t *key, const uint8_t key_len,
1370 const uint8_t aad_len, const uint8_t auth_len)
1372 uint8_t auth_cipher_key[key_len];
1374 struct crypto_unittest_params *ut_params = &unittest_params;
1376 memcpy(auth_cipher_key, key, key_len);
1378 /* Setup Authentication Parameters */
1379 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1380 ut_params->auth_xform.auth.op = auth_op;
1381 ut_params->auth_xform.next = &ut_params->cipher_xform;
1382 ut_params->auth_xform.auth.algo = auth_algo;
1383 ut_params->auth_xform.auth.key.length = key_len;
1384 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1385 ut_params->auth_xform.auth.digest_length = auth_len;
1386 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1388 /* Setup Cipher Parameters */
1389 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1390 ut_params->cipher_xform.next = NULL;
1391 ut_params->cipher_xform.cipher.algo = cipher_algo;
1392 ut_params->cipher_xform.cipher.op = cipher_op;
1393 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1394 ut_params->cipher_xform.cipher.key.length = key_len;
1396 TEST_HEXDUMP(stdout, "key:", key, key_len);
1398 /* Create Crypto session*/
1399 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1400 &ut_params->auth_xform);
1402 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1408 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
1409 const unsigned auth_tag_len,
1410 const uint8_t *aad, const unsigned aad_len,
1411 unsigned data_pad_len,
1412 enum rte_crypto_auth_operation op,
1413 enum rte_crypto_auth_algorithm algo,
1414 const unsigned auth_len, const unsigned auth_offset)
1416 struct crypto_testsuite_params *ts_params = &testsuite_params;
1418 struct crypto_unittest_params *ut_params = &unittest_params;
1420 unsigned aad_buffer_len;
1422 /* Generate Crypto op data structure */
1423 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1424 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1425 TEST_ASSERT_NOT_NULL(ut_params->op,
1426 "Failed to allocate pktmbuf offload");
1428 /* Set crypto operation data parameters */
1429 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1431 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1433 /* set crypto operation source mbuf */
1434 sym_op->m_src = ut_params->ibuf;
1438 * Always allocate the aad up to the block size.
1439 * The cryptodev API calls out -
1440 * - the array must be big enough to hold the AAD, plus any
1441 * space to round this up to the nearest multiple of the
1442 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1444 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1445 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1447 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1448 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1449 ut_params->ibuf, aad_buffer_len);
1450 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1451 "no room to prepend aad");
1452 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1454 sym_op->auth.aad.length = aad_len;
1456 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1457 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1459 TEST_HEXDUMP(stdout, "aad:",
1460 sym_op->auth.aad.data, aad_len);
1463 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1464 ut_params->ibuf, auth_tag_len);
1466 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1467 "no room to append auth tag");
1468 ut_params->digest = sym_op->auth.digest.data;
1469 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1470 ut_params->ibuf, data_pad_len + aad_len);
1471 sym_op->auth.digest.length = auth_tag_len;
1472 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1473 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1475 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1477 TEST_HEXDUMP(stdout, "digest:",
1478 sym_op->auth.digest.data,
1479 sym_op->auth.digest.length);
1481 sym_op->auth.data.length = auth_len;
1482 sym_op->auth.data.offset = auth_offset;
1488 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
1489 const unsigned auth_tag_len,
1490 const uint8_t *aad, const uint8_t aad_len,
1491 unsigned data_pad_len,
1492 enum rte_crypto_auth_operation op,
1493 enum rte_crypto_auth_algorithm auth_algo,
1494 enum rte_crypto_cipher_algorithm cipher_algo,
1495 const uint8_t *iv, const uint8_t iv_len,
1496 const unsigned cipher_len, const unsigned cipher_offset,
1497 const unsigned auth_len, const unsigned auth_offset)
1499 struct crypto_testsuite_params *ts_params = &testsuite_params;
1500 struct crypto_unittest_params *ut_params = &unittest_params;
1502 unsigned iv_pad_len = 0;
1503 unsigned aad_buffer_len;
1505 /* Generate Crypto op data structure */
1506 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1507 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1508 TEST_ASSERT_NOT_NULL(ut_params->op,
1509 "Failed to allocate pktmbuf offload");
1510 /* Set crypto operation data parameters */
1511 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1513 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1515 /* set crypto operation source mbuf */
1516 sym_op->m_src = ut_params->ibuf;
1519 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1520 ut_params->ibuf, auth_tag_len);
1522 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1523 "no room to append auth tag");
1524 ut_params->digest = sym_op->auth.digest.data;
1525 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1526 ut_params->ibuf, data_pad_len);
1527 sym_op->auth.digest.length = auth_tag_len;
1528 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1529 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1531 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1533 TEST_HEXDUMP(stdout, "digest:",
1534 sym_op->auth.digest.data,
1535 sym_op->auth.digest.length);
1539 * Always allocate the aad up to the block size.
1540 * The cryptodev API calls out -
1541 * - the array must be big enough to hold the AAD, plus any
1542 * space to round this up to the nearest multiple of the
1543 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1545 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1546 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1548 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1549 sym_op->auth.aad.data =
1550 (uint8_t *)rte_pktmbuf_prepend(
1551 ut_params->ibuf, aad_buffer_len);
1552 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1553 "no room to prepend aad");
1554 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1556 sym_op->auth.aad.length = aad_len;
1557 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1558 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1559 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1562 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1563 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1565 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1566 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1567 ut_params->ibuf, iv_pad_len);
1569 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1570 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1571 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1572 sym_op->cipher.iv.length = iv_pad_len;
1573 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1574 sym_op->cipher.data.length = cipher_len;
1575 sym_op->cipher.data.offset = cipher_offset + auth_offset;
1576 sym_op->auth.data.length = auth_len;
1577 sym_op->auth.data.offset = auth_offset + cipher_offset;
1583 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
1584 const uint8_t *iv, const uint8_t iv_len,
1585 const uint8_t *aad, const uint8_t aad_len,
1586 unsigned data_pad_len,
1587 const unsigned cipher_len, const unsigned cipher_offset,
1588 const unsigned auth_len, const unsigned auth_offset,
1589 enum rte_crypto_auth_algorithm auth_algo,
1590 enum rte_crypto_cipher_algorithm cipher_algo)
1592 struct crypto_testsuite_params *ts_params = &testsuite_params;
1593 struct crypto_unittest_params *ut_params = &unittest_params;
1595 unsigned iv_pad_len = 0;
1596 unsigned aad_buffer_len = 0;
1598 /* Generate Crypto op data structure */
1599 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1600 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1601 TEST_ASSERT_NOT_NULL(ut_params->op,
1602 "Failed to allocate pktmbuf offload");
1604 /* Set crypto operation data parameters */
1605 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1607 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1609 /* set crypto operation source mbuf */
1610 sym_op->m_src = ut_params->ibuf;
1613 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1614 ut_params->ibuf, auth_tag_len);
1616 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1617 "no room to append auth tag");
1619 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1620 ut_params->ibuf, data_pad_len);
1621 sym_op->auth.digest.length = auth_tag_len;
1623 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1625 TEST_HEXDUMP(stdout, "digest:",
1626 sym_op->auth.digest.data,
1627 sym_op->auth.digest.length);
1631 * Always allocate the aad up to the block size.
1632 * The cryptodev API calls out -
1633 * - the array must be big enough to hold the AAD, plus any
1634 * space to round this up to the nearest multiple of the
1635 * block size (8 bytes for KASUMI 16 bytes).
1637 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1638 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1640 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1641 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1642 ut_params->ibuf, aad_buffer_len);
1643 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1644 "no room to prepend aad");
1645 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1647 sym_op->auth.aad.length = aad_len;
1648 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1649 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1650 TEST_HEXDUMP(stdout, "aad:",
1651 sym_op->auth.aad.data, aad_len);
1654 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1655 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1657 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1659 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1660 ut_params->ibuf, iv_pad_len);
1661 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1663 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1664 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1665 sym_op->cipher.iv.length = iv_pad_len;
1667 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1669 sym_op->cipher.data.length = cipher_len;
1670 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1672 sym_op->auth.data.length = auth_len;
1673 sym_op->auth.data.offset = auth_offset + cipher_offset;
1679 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1681 struct crypto_testsuite_params *ts_params = &testsuite_params;
1682 struct crypto_unittest_params *ut_params = &unittest_params;
1685 unsigned plaintext_pad_len;
1686 unsigned plaintext_len;
1689 /* Create SNOW 3G session */
1690 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1691 tdata->key.data, tdata->key.len,
1692 tdata->aad.len, tdata->digest.len,
1693 RTE_CRYPTO_AUTH_OP_GENERATE,
1694 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1698 /* alloc mbuf and set payload */
1699 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1701 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1702 rte_pktmbuf_tailroom(ut_params->ibuf));
1704 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1705 /* Append data which is padded to a multiple of */
1706 /* the algorithms block size */
1707 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1708 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1710 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1712 /* Create SNOW 3G operation */
1713 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
1714 tdata->aad.data, tdata->aad.len,
1715 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1716 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1717 tdata->validAuthLenInBits.len,
1718 tdata->validAuthOffsetLenInBits.len);
1722 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1724 ut_params->obuf = ut_params->op->sym->m_src;
1725 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1726 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1727 + plaintext_pad_len + tdata->aad.len;
1730 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1733 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1734 "SNOW 3G Generated auth tag not as expected");
1740 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1742 struct crypto_testsuite_params *ts_params = &testsuite_params;
1743 struct crypto_unittest_params *ut_params = &unittest_params;
1746 unsigned plaintext_pad_len;
1747 unsigned plaintext_len;
1750 /* Create SNOW 3G session */
1751 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1752 tdata->key.data, tdata->key.len,
1753 tdata->aad.len, tdata->digest.len,
1754 RTE_CRYPTO_AUTH_OP_VERIFY,
1755 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
1758 /* alloc mbuf and set payload */
1759 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1761 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1762 rte_pktmbuf_tailroom(ut_params->ibuf));
1764 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1765 /* Append data which is padded to a multiple of */
1766 /* the algorithms block size */
1767 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
1768 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1770 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1772 /* Create SNOW 3G operation */
1773 retval = create_wireless_algo_hash_operation(tdata->digest.data,
1775 tdata->aad.data, tdata->aad.len,
1777 RTE_CRYPTO_AUTH_OP_VERIFY,
1778 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
1779 tdata->validAuthLenInBits.len,
1780 tdata->validAuthOffsetLenInBits.len);
1784 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1786 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1787 ut_params->obuf = ut_params->op->sym->m_src;
1788 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1789 + plaintext_pad_len + tdata->aad.len;
1792 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1801 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
1803 struct crypto_testsuite_params *ts_params = &testsuite_params;
1804 struct crypto_unittest_params *ut_params = &unittest_params;
1807 unsigned plaintext_pad_len;
1808 unsigned plaintext_len;
1811 /* Create KASUMI session */
1812 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1813 tdata->key.data, tdata->key.len,
1814 tdata->aad.len, tdata->digest.len,
1815 RTE_CRYPTO_AUTH_OP_GENERATE,
1816 RTE_CRYPTO_AUTH_KASUMI_F9);
1820 /* alloc mbuf and set payload */
1821 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1823 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1824 rte_pktmbuf_tailroom(ut_params->ibuf));
1826 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1827 /* Append data which is padded to a multiple of */
1828 /* the algorithms block size */
1829 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1830 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1832 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1834 /* Create KASUMI operation */
1835 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
1836 tdata->aad.data, tdata->aad.len,
1837 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1838 RTE_CRYPTO_AUTH_KASUMI_F9,
1839 tdata->validAuthLenInBits.len,
1840 tdata->validAuthOffsetLenInBits.len);
1844 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1846 ut_params->obuf = ut_params->op->sym->m_src;
1847 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1848 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1849 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
1852 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1855 DIGEST_BYTE_LENGTH_KASUMI_F9,
1856 "KASUMI Generated auth tag not as expected");
1862 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
1864 struct crypto_testsuite_params *ts_params = &testsuite_params;
1865 struct crypto_unittest_params *ut_params = &unittest_params;
1868 unsigned plaintext_pad_len;
1869 unsigned plaintext_len;
1872 /* Create KASUMI session */
1873 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
1874 tdata->key.data, tdata->key.len,
1875 tdata->aad.len, tdata->digest.len,
1876 RTE_CRYPTO_AUTH_OP_VERIFY,
1877 RTE_CRYPTO_AUTH_KASUMI_F9);
1880 /* alloc mbuf and set payload */
1881 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1883 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1884 rte_pktmbuf_tailroom(ut_params->ibuf));
1886 plaintext_len = ceil_byte_length(tdata->plaintext.len);
1887 /* Append data which is padded to a multiple */
1888 /* of the algorithms block size */
1889 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
1890 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1892 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
1894 /* Create KASUMI operation */
1895 retval = create_wireless_algo_hash_operation(tdata->digest.data,
1897 tdata->aad.data, tdata->aad.len,
1899 RTE_CRYPTO_AUTH_OP_VERIFY,
1900 RTE_CRYPTO_AUTH_KASUMI_F9,
1901 tdata->validAuthLenInBits.len,
1902 tdata->validAuthOffsetLenInBits.len);
1906 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1908 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1909 ut_params->obuf = ut_params->op->sym->m_src;
1910 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1911 + plaintext_pad_len + tdata->aad.len;
1914 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1923 test_snow3g_hash_generate_test_case_1(void)
1925 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1929 test_snow3g_hash_generate_test_case_2(void)
1931 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1935 test_snow3g_hash_generate_test_case_3(void)
1937 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1941 test_snow3g_hash_generate_test_case_4(void)
1943 return test_snow3g_authentication(&snow3g_hash_test_case_4);
1947 test_snow3g_hash_generate_test_case_5(void)
1949 return test_snow3g_authentication(&snow3g_hash_test_case_5);
1953 test_snow3g_hash_generate_test_case_6(void)
1955 return test_snow3g_authentication(&snow3g_hash_test_case_6);
1959 test_snow3g_hash_verify_test_case_1(void)
1961 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1966 test_snow3g_hash_verify_test_case_2(void)
1968 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1972 test_snow3g_hash_verify_test_case_3(void)
1974 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1978 test_snow3g_hash_verify_test_case_4(void)
1980 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
1984 test_snow3g_hash_verify_test_case_5(void)
1986 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
1990 test_snow3g_hash_verify_test_case_6(void)
1992 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
1996 test_kasumi_hash_generate_test_case_1(void)
1998 return test_kasumi_authentication(&kasumi_hash_test_case_1);
2002 test_kasumi_hash_generate_test_case_2(void)
2004 return test_kasumi_authentication(&kasumi_hash_test_case_2);
2008 test_kasumi_hash_generate_test_case_3(void)
2010 return test_kasumi_authentication(&kasumi_hash_test_case_3);
2014 test_kasumi_hash_generate_test_case_4(void)
2016 return test_kasumi_authentication(&kasumi_hash_test_case_4);
2020 test_kasumi_hash_generate_test_case_5(void)
2022 return test_kasumi_authentication(&kasumi_hash_test_case_5);
2026 test_kasumi_hash_generate_test_case_6(void)
2028 return test_kasumi_authentication(&kasumi_hash_test_case_6);
2032 test_kasumi_hash_verify_test_case_1(void)
2034 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2038 test_kasumi_hash_verify_test_case_2(void)
2040 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2044 test_kasumi_hash_verify_test_case_3(void)
2046 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2050 test_kasumi_hash_verify_test_case_4(void)
2052 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2056 test_kasumi_hash_verify_test_case_5(void)
2058 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2062 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2064 struct crypto_testsuite_params *ts_params = &testsuite_params;
2065 struct crypto_unittest_params *ut_params = &unittest_params;
2068 uint8_t *plaintext, *ciphertext;
2069 unsigned plaintext_pad_len;
2070 unsigned plaintext_len;
2072 /* Create KASUMI session */
2073 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2074 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2075 RTE_CRYPTO_CIPHER_KASUMI_F8,
2076 tdata->key.data, tdata->key.len);
2080 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2082 /* Clear mbuf payload */
2083 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2084 rte_pktmbuf_tailroom(ut_params->ibuf));
2086 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2087 /* Append data which is padded to a multiple */
2088 /* of the algorithms block size */
2089 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2090 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2092 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2094 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2096 /* Create KASUMI operation */
2097 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2098 tdata->plaintext.len,
2099 tdata->validCipherOffsetLenInBits.len,
2100 RTE_CRYPTO_CIPHER_KASUMI_F8);
2104 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2106 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2108 ut_params->obuf = ut_params->op->sym->m_dst;
2109 if (ut_params->obuf)
2110 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2113 ciphertext = plaintext;
2115 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2118 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2120 tdata->ciphertext.data,
2121 tdata->validCipherLenInBits.len,
2122 "KASUMI Ciphertext data not as expected");
2127 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2129 struct crypto_testsuite_params *ts_params = &testsuite_params;
2130 struct crypto_unittest_params *ut_params = &unittest_params;
2133 uint8_t *plaintext, *ciphertext;
2134 unsigned plaintext_pad_len;
2135 unsigned plaintext_len;
2137 /* Create KASUMI session */
2138 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2139 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2140 RTE_CRYPTO_CIPHER_KASUMI_F8,
2141 tdata->key.data, tdata->key.len);
2145 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2146 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2148 /* Clear mbuf payload */
2149 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2150 rte_pktmbuf_tailroom(ut_params->ibuf));
2152 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2153 /* Append data which is padded to a multiple */
2154 /* of the algorithms block size */
2155 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2156 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2158 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2159 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2161 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2163 /* Create KASUMI operation */
2164 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2166 tdata->plaintext.len,
2167 tdata->validCipherOffsetLenInBits.len,
2168 RTE_CRYPTO_CIPHER_KASUMI_F8);
2172 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2174 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2176 ut_params->obuf = ut_params->op->sym->m_dst;
2177 if (ut_params->obuf)
2178 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2181 ciphertext = plaintext;
2183 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2186 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2188 tdata->ciphertext.data,
2189 tdata->validCipherLenInBits.len,
2190 "KASUMI Ciphertext data not as expected");
2195 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2197 struct crypto_testsuite_params *ts_params = &testsuite_params;
2198 struct crypto_unittest_params *ut_params = &unittest_params;
2201 uint8_t *ciphertext, *plaintext;
2202 unsigned ciphertext_pad_len;
2203 unsigned ciphertext_len;
2205 /* Create KASUMI session */
2206 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2207 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2208 RTE_CRYPTO_CIPHER_KASUMI_F8,
2209 tdata->key.data, tdata->key.len);
2213 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2214 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2216 /* Clear mbuf payload */
2217 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2218 rte_pktmbuf_tailroom(ut_params->ibuf));
2220 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2221 /* Append data which is padded to a multiple */
2222 /* of the algorithms block size */
2223 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2224 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2225 ciphertext_pad_len);
2226 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2227 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2229 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2231 /* Create KASUMI operation */
2232 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2234 tdata->ciphertext.len,
2235 tdata->validCipherOffsetLenInBits.len,
2236 RTE_CRYPTO_CIPHER_KASUMI_F8);
2240 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2242 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2244 ut_params->obuf = ut_params->op->sym->m_dst;
2245 if (ut_params->obuf)
2246 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2249 plaintext = ciphertext;
2251 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2254 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2256 tdata->plaintext.data,
2257 tdata->validCipherLenInBits.len,
2258 "KASUMI Plaintext data not as expected");
2263 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2265 struct crypto_testsuite_params *ts_params = &testsuite_params;
2266 struct crypto_unittest_params *ut_params = &unittest_params;
2269 uint8_t *ciphertext, *plaintext;
2270 unsigned ciphertext_pad_len;
2271 unsigned ciphertext_len;
2273 /* Create KASUMI session */
2274 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2275 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2276 RTE_CRYPTO_CIPHER_KASUMI_F8,
2277 tdata->key.data, tdata->key.len);
2281 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2283 /* Clear mbuf payload */
2284 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2285 rte_pktmbuf_tailroom(ut_params->ibuf));
2287 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2288 /* Append data which is padded to a multiple */
2289 /* of the algorithms block size */
2290 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2291 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2292 ciphertext_pad_len);
2293 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2295 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2297 /* Create KASUMI operation */
2298 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2300 tdata->ciphertext.len,
2301 tdata->validCipherOffsetLenInBits.len,
2302 RTE_CRYPTO_CIPHER_KASUMI_F8);
2306 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2308 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2310 ut_params->obuf = ut_params->op->sym->m_dst;
2311 if (ut_params->obuf)
2312 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2315 plaintext = ciphertext;
2317 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2320 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2322 tdata->plaintext.data,
2323 tdata->validCipherLenInBits.len,
2324 "KASUMI Plaintext data not as expected");
2329 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2331 struct crypto_testsuite_params *ts_params = &testsuite_params;
2332 struct crypto_unittest_params *ut_params = &unittest_params;
2335 uint8_t *plaintext, *ciphertext;
2336 unsigned plaintext_pad_len;
2337 unsigned plaintext_len;
2339 /* Create SNOW 3G session */
2340 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2341 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2342 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2343 tdata->key.data, tdata->key.len);
2347 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2349 /* Clear mbuf payload */
2350 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2351 rte_pktmbuf_tailroom(ut_params->ibuf));
2353 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2354 /* Append data which is padded to a multiple of */
2355 /* the algorithms block size */
2356 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2357 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2359 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2361 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2363 /* Create SNOW 3G operation */
2364 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2365 tdata->validCipherLenInBits.len,
2366 tdata->validCipherOffsetLenInBits.len,
2367 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2371 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2373 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2375 ut_params->obuf = ut_params->op->sym->m_dst;
2376 if (ut_params->obuf)
2377 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2380 ciphertext = plaintext;
2382 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2385 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2387 tdata->ciphertext.data,
2388 tdata->validDataLenInBits.len,
2389 "SNOW 3G Ciphertext data not as expected");
2395 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2397 struct crypto_testsuite_params *ts_params = &testsuite_params;
2398 struct crypto_unittest_params *ut_params = &unittest_params;
2399 uint8_t *plaintext, *ciphertext;
2402 unsigned plaintext_pad_len;
2403 unsigned plaintext_len;
2405 /* Create SNOW 3G session */
2406 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2407 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2408 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2409 tdata->key.data, tdata->key.len);
2413 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2414 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2416 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2417 "Failed to allocate input buffer in mempool");
2418 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2419 "Failed to allocate output buffer in mempool");
2421 /* Clear mbuf payload */
2422 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2423 rte_pktmbuf_tailroom(ut_params->ibuf));
2425 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2426 /* Append data which is padded to a multiple of */
2427 /* the algorithms block size */
2428 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2429 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2431 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2432 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2434 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2436 /* Create SNOW 3G operation */
2437 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2439 tdata->validCipherLenInBits.len,
2440 tdata->validCipherOffsetLenInBits.len,
2441 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2445 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2447 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2449 ut_params->obuf = ut_params->op->sym->m_dst;
2450 if (ut_params->obuf)
2451 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2454 ciphertext = plaintext;
2456 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2459 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2461 tdata->ciphertext.data,
2462 tdata->validDataLenInBits.len,
2463 "SNOW 3G Ciphertext data not as expected");
2467 /* Shift right a buffer by "offset" bits, "offset" < 8 */
2469 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
2471 uint8_t curr_byte, prev_byte;
2472 uint32_t length_in_bytes = ceil_byte_length(length + offset);
2473 uint8_t lower_byte_mask = (1 << offset) - 1;
2476 prev_byte = buffer[0];
2477 buffer[0] >>= offset;
2479 for (i = 1; i < length_in_bytes; i++) {
2480 curr_byte = buffer[i];
2481 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
2482 (curr_byte >> offset);
2483 prev_byte = curr_byte;
2488 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
2490 struct crypto_testsuite_params *ts_params = &testsuite_params;
2491 struct crypto_unittest_params *ut_params = &unittest_params;
2492 uint8_t *plaintext, *ciphertext;
2494 uint32_t plaintext_len;
2495 uint32_t plaintext_pad_len;
2496 uint8_t extra_offset = 4;
2497 uint8_t *expected_ciphertext_shifted;
2499 /* Create SNOW 3G session */
2500 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2501 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2502 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2503 tdata->key.data, tdata->key.len);
2507 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2508 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2510 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2511 "Failed to allocate input buffer in mempool");
2512 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2513 "Failed to allocate output buffer in mempool");
2515 /* Clear mbuf payload */
2516 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2517 rte_pktmbuf_tailroom(ut_params->ibuf));
2519 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
2521 * Append data which is padded to a
2522 * multiple of the algorithms block size
2524 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2526 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2529 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2531 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2532 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
2534 #ifdef RTE_APP_TEST_DEBUG
2535 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2537 /* Create SNOW 3G operation */
2538 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2540 tdata->validCipherLenInBits.len,
2541 tdata->validCipherOffsetLenInBits.len +
2543 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2547 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2549 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2551 ut_params->obuf = ut_params->op->sym->m_dst;
2552 if (ut_params->obuf)
2553 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2556 ciphertext = plaintext;
2558 #ifdef RTE_APP_TEST_DEBUG
2559 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
2562 expected_ciphertext_shifted = rte_malloc(NULL,
2563 ceil_byte_length(plaintext_len + extra_offset), 0);
2565 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
2566 "failed to reserve memory for ciphertext shifted\n");
2568 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
2569 ceil_byte_length(tdata->ciphertext.len));
2570 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
2573 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
2575 expected_ciphertext_shifted,
2576 tdata->validDataLenInBits.len,
2578 "SNOW 3G Ciphertext data not as expected");
2582 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2584 struct crypto_testsuite_params *ts_params = &testsuite_params;
2585 struct crypto_unittest_params *ut_params = &unittest_params;
2589 uint8_t *plaintext, *ciphertext;
2590 unsigned ciphertext_pad_len;
2591 unsigned ciphertext_len;
2593 /* Create SNOW 3G session */
2594 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2595 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2596 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2597 tdata->key.data, tdata->key.len);
2601 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2603 /* Clear mbuf payload */
2604 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2605 rte_pktmbuf_tailroom(ut_params->ibuf));
2607 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2608 /* Append data which is padded to a multiple of */
2609 /* the algorithms block size */
2610 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2611 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2612 ciphertext_pad_len);
2613 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2615 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2617 /* Create SNOW 3G operation */
2618 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2619 tdata->validCipherLenInBits.len,
2620 tdata->validCipherOffsetLenInBits.len,
2621 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2625 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2627 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2628 ut_params->obuf = ut_params->op->sym->m_dst;
2629 if (ut_params->obuf)
2630 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2633 plaintext = ciphertext;
2635 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2638 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2639 tdata->plaintext.data,
2640 tdata->validDataLenInBits.len,
2641 "SNOW 3G Plaintext data not as expected");
2645 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
2647 struct crypto_testsuite_params *ts_params = &testsuite_params;
2648 struct crypto_unittest_params *ut_params = &unittest_params;
2652 uint8_t *plaintext, *ciphertext;
2653 unsigned ciphertext_pad_len;
2654 unsigned ciphertext_len;
2656 /* Create SNOW 3G session */
2657 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2658 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2659 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2660 tdata->key.data, tdata->key.len);
2664 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2665 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2667 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
2668 "Failed to allocate input buffer");
2669 TEST_ASSERT_NOT_NULL(ut_params->obuf,
2670 "Failed to allocate output buffer");
2672 /* Clear mbuf payload */
2673 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2674 rte_pktmbuf_tailroom(ut_params->ibuf));
2676 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2677 rte_pktmbuf_tailroom(ut_params->obuf));
2679 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2680 /* Append data which is padded to a multiple of */
2681 /* the algorithms block size */
2682 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
2683 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2684 ciphertext_pad_len);
2685 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2686 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2688 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2690 /* Create SNOW 3G operation */
2691 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2693 tdata->validCipherLenInBits.len,
2694 tdata->validCipherOffsetLenInBits.len,
2695 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2699 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2701 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2702 ut_params->obuf = ut_params->op->sym->m_dst;
2703 if (ut_params->obuf)
2704 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2707 plaintext = ciphertext;
2709 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2712 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
2713 tdata->plaintext.data,
2714 tdata->validDataLenInBits.len,
2715 "SNOW 3G Plaintext data not as expected");
2720 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
2722 struct crypto_testsuite_params *ts_params = &testsuite_params;
2723 struct crypto_unittest_params *ut_params = &unittest_params;
2727 uint8_t *plaintext, *ciphertext;
2728 unsigned plaintext_pad_len;
2729 unsigned plaintext_len;
2731 /* Create SNOW 3G session */
2732 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
2733 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2734 RTE_CRYPTO_AUTH_OP_GENERATE,
2735 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2736 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2737 tdata->key.data, tdata->key.len,
2738 tdata->aad.len, tdata->digest.len);
2741 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2743 /* clear mbuf payload */
2744 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2745 rte_pktmbuf_tailroom(ut_params->ibuf));
2747 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2748 /* Append data which is padded to a multiple of */
2749 /* the algorithms block size */
2750 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2751 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2753 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2755 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2757 /* Create SNOW 3G operation */
2758 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
2759 tdata->digest.len, tdata->aad.data,
2760 tdata->aad.len, /*tdata->plaintext.len,*/
2761 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2762 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2763 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2764 tdata->iv.data, tdata->iv.len,
2765 tdata->validCipherLenInBits.len,
2766 tdata->validCipherOffsetLenInBits.len,
2767 tdata->validAuthLenInBits.len,
2768 tdata->validAuthOffsetLenInBits.len
2773 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2775 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2776 ut_params->obuf = ut_params->op->sym->m_src;
2777 if (ut_params->obuf)
2778 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2779 + tdata->iv.len + tdata->aad.len;
2781 ciphertext = plaintext;
2783 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2785 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2787 tdata->ciphertext.data,
2788 tdata->validDataLenInBits.len,
2789 "SNOW 3G Ciphertext data not as expected");
2791 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2792 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2795 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2798 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2799 "SNOW 3G Generated auth tag not as expected");
2803 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
2805 struct crypto_testsuite_params *ts_params = &testsuite_params;
2806 struct crypto_unittest_params *ut_params = &unittest_params;
2810 uint8_t *plaintext, *ciphertext;
2811 unsigned plaintext_pad_len;
2812 unsigned plaintext_len;
2814 /* Create SNOW 3G session */
2815 retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
2816 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2817 RTE_CRYPTO_AUTH_OP_GENERATE,
2818 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2819 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2820 tdata->key.data, tdata->key.len,
2821 tdata->aad.len, tdata->digest.len);
2825 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2827 /* clear mbuf payload */
2828 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2829 rte_pktmbuf_tailroom(ut_params->ibuf));
2831 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2832 /* Append data which is padded to a multiple of */
2833 /* the algorithms block size */
2834 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2835 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2837 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2839 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2841 /* Create SNOW 3G operation */
2842 retval = create_wireless_algo_auth_cipher_operation(
2844 tdata->iv.data, tdata->iv.len,
2845 tdata->aad.data, tdata->aad.len,
2847 tdata->validCipherLenInBits.len,
2848 tdata->validCipherOffsetLenInBits.len,
2849 tdata->validAuthLenInBits.len,
2850 tdata->validAuthOffsetLenInBits.len,
2851 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2852 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
2858 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2860 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2861 ut_params->obuf = ut_params->op->sym->m_src;
2862 if (ut_params->obuf)
2863 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2864 + tdata->aad.len + tdata->iv.len;
2866 ciphertext = plaintext;
2868 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2869 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2870 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2873 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2875 tdata->ciphertext.data,
2876 tdata->validDataLenInBits.len,
2877 "SNOW 3G Ciphertext data not as expected");
2880 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2883 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2884 "SNOW 3G Generated auth tag not as expected");
2889 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
2891 struct crypto_testsuite_params *ts_params = &testsuite_params;
2892 struct crypto_unittest_params *ut_params = &unittest_params;
2896 uint8_t *plaintext, *ciphertext;
2897 unsigned plaintext_pad_len;
2898 unsigned plaintext_len;
2900 /* Create KASUMI session */
2901 retval = create_wireless_algo_auth_cipher_session(
2902 ts_params->valid_devs[0],
2903 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2904 RTE_CRYPTO_AUTH_OP_GENERATE,
2905 RTE_CRYPTO_AUTH_KASUMI_F9,
2906 RTE_CRYPTO_CIPHER_KASUMI_F8,
2907 tdata->key.data, tdata->key.len,
2908 tdata->aad.len, tdata->digest.len);
2911 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2913 /* clear mbuf payload */
2914 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2915 rte_pktmbuf_tailroom(ut_params->ibuf));
2917 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2918 /* Append data which is padded to a multiple of */
2919 /* the algorithms block size */
2920 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2921 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2923 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2925 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2927 /* Create KASUMI operation */
2928 retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
2929 tdata->iv.data, tdata->iv.len,
2930 tdata->aad.data, tdata->aad.len,
2932 tdata->validCipherLenInBits.len,
2933 tdata->validCipherOffsetLenInBits.len,
2934 tdata->validAuthLenInBits.len,
2935 tdata->validAuthOffsetLenInBits.len,
2936 RTE_CRYPTO_AUTH_KASUMI_F9,
2937 RTE_CRYPTO_CIPHER_KASUMI_F8
2943 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2945 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2946 ut_params->obuf = ut_params->op->sym->m_src;
2947 if (ut_params->obuf)
2948 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2949 + tdata->iv.len + tdata->aad.len;
2951 ciphertext = plaintext;
2954 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2956 tdata->ciphertext.data,
2957 tdata->validCipherLenInBits.len,
2958 "KASUMI Ciphertext data not as expected");
2959 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2960 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2963 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2966 DIGEST_BYTE_LENGTH_KASUMI_F9,
2967 "KASUMI Generated auth tag not as expected");
2972 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
2974 struct crypto_testsuite_params *ts_params = &testsuite_params;
2975 struct crypto_unittest_params *ut_params = &unittest_params;
2979 uint8_t *plaintext, *ciphertext;
2980 unsigned plaintext_pad_len;
2981 unsigned plaintext_len;
2983 /* Create KASUMI session */
2984 retval = create_wireless_algo_cipher_auth_session(
2985 ts_params->valid_devs[0],
2986 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2987 RTE_CRYPTO_AUTH_OP_GENERATE,
2988 RTE_CRYPTO_AUTH_KASUMI_F9,
2989 RTE_CRYPTO_CIPHER_KASUMI_F8,
2990 tdata->key.data, tdata->key.len,
2991 tdata->aad.len, tdata->digest.len);
2995 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2997 /* clear mbuf payload */
2998 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2999 rte_pktmbuf_tailroom(ut_params->ibuf));
3001 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3002 /* Append data which is padded to a multiple of */
3003 /* the algorithms block size */
3004 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3005 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3007 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3009 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3011 /* Create KASUMI operation */
3012 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3013 tdata->digest.len, tdata->aad.data,
3015 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3016 RTE_CRYPTO_AUTH_KASUMI_F9,
3017 RTE_CRYPTO_CIPHER_KASUMI_F8,
3018 tdata->iv.data, tdata->iv.len,
3019 tdata->validCipherLenInBits.len,
3020 tdata->validCipherOffsetLenInBits.len,
3021 tdata->validAuthLenInBits.len,
3022 tdata->validAuthOffsetLenInBits.len
3027 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3029 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3030 ut_params->obuf = ut_params->op->sym->m_src;
3031 if (ut_params->obuf)
3032 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3033 + tdata->aad.len + tdata->iv.len;
3035 ciphertext = plaintext;
3037 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3038 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3041 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3043 tdata->ciphertext.data,
3044 tdata->validCipherLenInBits.len,
3045 "KASUMI Ciphertext data not as expected");
3048 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3051 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3052 "KASUMI Generated auth tag not as expected");
3057 test_zuc_encryption(const struct zuc_test_data *tdata)
3059 struct crypto_testsuite_params *ts_params = &testsuite_params;
3060 struct crypto_unittest_params *ut_params = &unittest_params;
3063 uint8_t *plaintext, *ciphertext;
3064 unsigned plaintext_pad_len;
3065 unsigned plaintext_len;
3067 /* Create ZUC session */
3068 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3069 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3070 RTE_CRYPTO_CIPHER_ZUC_EEA3,
3071 tdata->key.data, tdata->key.len);
3075 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3077 /* Clear mbuf payload */
3078 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3079 rte_pktmbuf_tailroom(ut_params->ibuf));
3081 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3082 /* Append data which is padded to a multiple */
3083 /* of the algorithms block size */
3084 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3085 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3087 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3089 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3091 /* Create ZUC operation */
3092 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3093 tdata->plaintext.len,
3094 tdata->validCipherOffsetLenInBits.len,
3095 RTE_CRYPTO_CIPHER_ZUC_EEA3);
3099 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3101 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3103 ut_params->obuf = ut_params->op->sym->m_dst;
3104 if (ut_params->obuf)
3105 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3108 ciphertext = plaintext;
3110 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3113 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3115 tdata->ciphertext.data,
3116 tdata->validCipherLenInBits.len,
3117 "ZUC Ciphertext data not as expected");
3122 test_zuc_authentication(const struct zuc_hash_test_data *tdata)
3124 struct crypto_testsuite_params *ts_params = &testsuite_params;
3125 struct crypto_unittest_params *ut_params = &unittest_params;
3128 unsigned plaintext_pad_len;
3129 unsigned plaintext_len;
3132 /* Create ZUC session */
3133 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3134 tdata->key.data, tdata->key.len,
3135 tdata->aad.len, tdata->digest.len,
3136 RTE_CRYPTO_AUTH_OP_GENERATE,
3137 RTE_CRYPTO_AUTH_ZUC_EIA3);
3141 /* alloc mbuf and set payload */
3142 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3144 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3145 rte_pktmbuf_tailroom(ut_params->ibuf));
3147 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3148 /* Append data which is padded to a multiple of */
3149 /* the algorithms block size */
3150 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3151 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3153 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3155 /* Create ZUC operation */
3156 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3157 tdata->aad.data, tdata->aad.len,
3158 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3159 RTE_CRYPTO_AUTH_ZUC_EIA3,
3160 tdata->validAuthLenInBits.len,
3161 tdata->validAuthOffsetLenInBits.len);
3165 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3167 ut_params->obuf = ut_params->op->sym->m_src;
3168 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3169 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3170 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
3173 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3176 DIGEST_BYTE_LENGTH_KASUMI_F9,
3177 "ZUC Generated auth tag not as expected");
3183 test_kasumi_encryption_test_case_1(void)
3185 return test_kasumi_encryption(&kasumi_test_case_1);
3189 test_kasumi_encryption_test_case_1_oop(void)
3191 return test_kasumi_encryption_oop(&kasumi_test_case_1);
3195 test_kasumi_encryption_test_case_2(void)
3197 return test_kasumi_encryption(&kasumi_test_case_2);
3201 test_kasumi_encryption_test_case_3(void)
3203 return test_kasumi_encryption(&kasumi_test_case_3);
3207 test_kasumi_encryption_test_case_4(void)
3209 return test_kasumi_encryption(&kasumi_test_case_4);
3213 test_kasumi_encryption_test_case_5(void)
3215 return test_kasumi_encryption(&kasumi_test_case_5);
3219 test_kasumi_decryption_test_case_1(void)
3221 return test_kasumi_decryption(&kasumi_test_case_1);
3225 test_kasumi_decryption_test_case_1_oop(void)
3227 return test_kasumi_decryption_oop(&kasumi_test_case_1);
3231 test_kasumi_decryption_test_case_2(void)
3233 return test_kasumi_decryption(&kasumi_test_case_2);
3237 test_kasumi_decryption_test_case_3(void)
3239 return test_kasumi_decryption(&kasumi_test_case_3);
3243 test_kasumi_decryption_test_case_4(void)
3245 return test_kasumi_decryption(&kasumi_test_case_4);
3249 test_kasumi_decryption_test_case_5(void)
3251 return test_kasumi_decryption(&kasumi_test_case_5);
3254 test_snow3g_encryption_test_case_1(void)
3256 return test_snow3g_encryption(&snow3g_test_case_1);
3260 test_snow3g_encryption_test_case_1_oop(void)
3262 return test_snow3g_encryption_oop(&snow3g_test_case_1);
3266 test_snow3g_encryption_test_case_1_offset_oop(void)
3268 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
3272 test_snow3g_encryption_test_case_2(void)
3274 return test_snow3g_encryption(&snow3g_test_case_2);
3278 test_snow3g_encryption_test_case_3(void)
3280 return test_snow3g_encryption(&snow3g_test_case_3);
3284 test_snow3g_encryption_test_case_4(void)
3286 return test_snow3g_encryption(&snow3g_test_case_4);
3290 test_snow3g_encryption_test_case_5(void)
3292 return test_snow3g_encryption(&snow3g_test_case_5);
3296 test_snow3g_decryption_test_case_1(void)
3298 return test_snow3g_decryption(&snow3g_test_case_1);
3302 test_snow3g_decryption_test_case_1_oop(void)
3304 return test_snow3g_decryption_oop(&snow3g_test_case_1);
3308 test_snow3g_decryption_test_case_2(void)
3310 return test_snow3g_decryption(&snow3g_test_case_2);
3314 test_snow3g_decryption_test_case_3(void)
3316 return test_snow3g_decryption(&snow3g_test_case_3);
3320 test_snow3g_decryption_test_case_4(void)
3322 return test_snow3g_decryption(&snow3g_test_case_4);
3326 test_snow3g_decryption_test_case_5(void)
3328 return test_snow3g_decryption(&snow3g_test_case_5);
3331 test_snow3g_cipher_auth_test_case_1(void)
3333 return test_snow3g_cipher_auth(&snow3g_test_case_3);
3337 test_snow3g_auth_cipher_test_case_1(void)
3339 return test_snow3g_auth_cipher(&snow3g_test_case_6);
3343 test_kasumi_auth_cipher_test_case_1(void)
3345 return test_kasumi_auth_cipher(&kasumi_test_case_3);
3349 test_kasumi_cipher_auth_test_case_1(void)
3351 return test_kasumi_cipher_auth(&kasumi_test_case_6);
3355 test_zuc_encryption_test_case_1(void)
3357 return test_zuc_encryption(&zuc_test_case_1);
3361 test_zuc_encryption_test_case_2(void)
3363 return test_zuc_encryption(&zuc_test_case_2);
3367 test_zuc_encryption_test_case_3(void)
3369 return test_zuc_encryption(&zuc_test_case_3);
3373 test_zuc_encryption_test_case_4(void)
3375 return test_zuc_encryption(&zuc_test_case_4);
3379 test_zuc_encryption_test_case_5(void)
3381 return test_zuc_encryption(&zuc_test_case_5);
3385 test_zuc_hash_generate_test_case_1(void)
3387 return test_zuc_authentication(&zuc_hash_test_case_1);
3391 test_zuc_hash_generate_test_case_2(void)
3393 return test_zuc_authentication(&zuc_hash_test_case_2);
3397 test_zuc_hash_generate_test_case_3(void)
3399 return test_zuc_authentication(&zuc_hash_test_case_3);
3403 test_zuc_hash_generate_test_case_4(void)
3405 return test_zuc_authentication(&zuc_hash_test_case_4);
3409 test_zuc_hash_generate_test_case_5(void)
3411 return test_zuc_authentication(&zuc_hash_test_case_5);
3414 /* ***** AES-GCM Tests ***** */
3417 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3418 const uint8_t *key, const uint8_t key_len,
3419 const uint8_t aad_len, const uint8_t auth_len,
3420 enum rte_crypto_auth_operation auth_op)
3422 uint8_t cipher_key[key_len];
3424 struct crypto_unittest_params *ut_params = &unittest_params;
3426 memcpy(cipher_key, key, key_len);
3428 /* Setup Cipher Parameters */
3429 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3430 ut_params->cipher_xform.next = NULL;
3432 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3433 ut_params->auth_xform.auth.op = auth_op;
3434 ut_params->cipher_xform.cipher.op = op;
3435 ut_params->cipher_xform.cipher.key.data = cipher_key;
3436 ut_params->cipher_xform.cipher.key.length = key_len;
3438 TEST_HEXDUMP(stdout, "key:", key, key_len);
3440 /* Setup Authentication Parameters */
3441 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3442 ut_params->auth_xform.next = NULL;
3444 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3446 ut_params->auth_xform.auth.digest_length = auth_len;
3447 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3448 ut_params->auth_xform.auth.key.length = 0;
3449 ut_params->auth_xform.auth.key.data = NULL;
3451 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3452 ut_params->cipher_xform.next = &ut_params->auth_xform;
3454 /* Create Crypto session*/
3455 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3456 &ut_params->cipher_xform);
3457 } else {/* Create Crypto session*/
3458 ut_params->auth_xform.next = &ut_params->cipher_xform;
3459 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3460 &ut_params->auth_xform);
3463 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3469 create_gcm_operation(enum rte_crypto_cipher_operation op,
3470 const uint8_t *auth_tag, const unsigned auth_tag_len,
3471 const uint8_t *iv, const unsigned iv_len,
3472 const uint8_t *aad, const unsigned aad_len,
3473 const unsigned data_len, unsigned data_pad_len)
3475 struct crypto_testsuite_params *ts_params = &testsuite_params;
3476 struct crypto_unittest_params *ut_params = &unittest_params;
3478 unsigned iv_pad_len = 0, aad_buffer_len;
3480 /* Generate Crypto op data structure */
3481 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3482 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3483 TEST_ASSERT_NOT_NULL(ut_params->op,
3484 "Failed to allocate symmetric crypto operation struct");
3486 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3488 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3489 ut_params->ibuf, auth_tag_len);
3490 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3491 "no room to append digest");
3492 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3493 ut_params->ibuf, data_pad_len);
3494 sym_op->auth.digest.length = auth_tag_len;
3496 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3497 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3498 TEST_HEXDUMP(stdout, "digest:",
3499 sym_op->auth.digest.data,
3500 sym_op->auth.digest.length);
3504 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3506 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3507 ut_params->ibuf, iv_pad_len);
3508 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3510 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3511 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3512 sym_op->cipher.iv.length = iv_len;
3514 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3517 * Always allocate the aad up to the block size.
3518 * The cryptodev API calls out -
3519 * - the array must be big enough to hold the AAD, plus any
3520 * space to round this up to the nearest multiple of the
3521 * block size (16 bytes).
3523 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3525 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3526 ut_params->ibuf, aad_buffer_len);
3527 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3528 "no room to prepend aad");
3529 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3531 sym_op->auth.aad.length = aad_len;
3533 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3534 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3536 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
3537 TEST_HEXDUMP(stdout, "aad:",
3538 sym_op->auth.aad.data, aad_len);
3540 sym_op->cipher.data.length = data_len;
3541 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3543 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3544 sym_op->auth.data.length = data_len;
3550 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3552 struct crypto_testsuite_params *ts_params = &testsuite_params;
3553 struct crypto_unittest_params *ut_params = &unittest_params;
3557 uint8_t *plaintext, *ciphertext, *auth_tag;
3558 uint16_t plaintext_pad_len;
3560 /* Create GCM session */
3561 retval = create_gcm_session(ts_params->valid_devs[0],
3562 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3563 tdata->key.data, tdata->key.len,
3564 tdata->aad.len, tdata->auth_tag.len,
3565 RTE_CRYPTO_AUTH_OP_GENERATE);
3570 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3572 /* clear mbuf payload */
3573 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3574 rte_pktmbuf_tailroom(ut_params->ibuf));
3577 * Append data which is padded to a multiple
3578 * of the algorithms block size
3580 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3582 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3584 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3586 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3588 /* Create GCM opertaion */
3589 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3590 tdata->auth_tag.data, tdata->auth_tag.len,
3591 tdata->iv.data, tdata->iv.len,
3592 tdata->aad.data, tdata->aad.len,
3593 tdata->plaintext.len, plaintext_pad_len);
3597 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3599 ut_params->op->sym->m_src = ut_params->ibuf;
3601 /* Process crypto operation */
3602 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3603 ut_params->op), "failed to process sym crypto op");
3605 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3606 "crypto op processing failed");
3608 if (ut_params->op->sym->m_dst) {
3609 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3611 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3612 uint8_t *, plaintext_pad_len);
3614 ciphertext = plaintext;
3615 auth_tag = plaintext + plaintext_pad_len;
3618 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3619 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3622 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3624 tdata->ciphertext.data,
3625 tdata->ciphertext.len,
3626 "GCM Ciphertext data not as expected");
3628 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3630 tdata->auth_tag.data,
3631 tdata->auth_tag.len,
3632 "GCM Generated auth tag not as expected");
3639 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3641 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3645 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3647 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3651 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3653 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3657 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3659 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3663 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3665 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3669 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3671 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3675 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3677 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3681 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3683 struct crypto_testsuite_params *ts_params = &testsuite_params;
3684 struct crypto_unittest_params *ut_params = &unittest_params;
3688 uint8_t *plaintext, *ciphertext;
3689 uint16_t ciphertext_pad_len;
3691 /* Create GCM session */
3692 retval = create_gcm_session(ts_params->valid_devs[0],
3693 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3694 tdata->key.data, tdata->key.len,
3695 tdata->aad.len, tdata->auth_tag.len,
3696 RTE_CRYPTO_AUTH_OP_VERIFY);
3701 /* alloc mbuf and set payload */
3702 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3704 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3705 rte_pktmbuf_tailroom(ut_params->ibuf));
3707 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3709 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3710 ciphertext_pad_len);
3711 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3713 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3715 /* Create GCM opertaion */
3716 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3717 tdata->auth_tag.data, tdata->auth_tag.len,
3718 tdata->iv.data, tdata->iv.len,
3719 tdata->aad.data, tdata->aad.len,
3720 tdata->ciphertext.len, ciphertext_pad_len);
3725 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3727 ut_params->op->sym->m_src = ut_params->ibuf;
3729 /* Process crypto operation */
3730 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3731 ut_params->op), "failed to process sym crypto op");
3733 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3734 "crypto op processing failed");
3736 if (ut_params->op->sym->m_dst)
3737 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3740 plaintext = ciphertext;
3742 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3745 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3747 tdata->plaintext.data,
3748 tdata->plaintext.len,
3749 "GCM plaintext data not as expected");
3751 TEST_ASSERT_EQUAL(ut_params->op->status,
3752 RTE_CRYPTO_OP_STATUS_SUCCESS,
3753 "GCM authentication failed");
3758 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3760 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3764 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3766 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3770 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3772 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3776 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3778 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3782 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3784 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3788 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3790 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3794 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3796 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3802 struct crypto_testsuite_params *ts_params = &testsuite_params;
3803 struct rte_cryptodev_stats stats;
3804 struct rte_cryptodev *dev;
3805 cryptodev_stats_get_t temp_pfn;
3807 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3808 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3809 &stats) == -ENODEV),
3810 "rte_cryptodev_stats_get invalid dev failed");
3811 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3812 "rte_cryptodev_stats_get invalid Param failed");
3813 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3814 temp_pfn = dev->dev_ops->stats_get;
3815 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3816 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3818 "rte_cryptodev_stats_get invalid Param failed");
3819 dev->dev_ops->stats_get = temp_pfn;
3821 /* Test expected values */
3823 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3825 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3827 "rte_cryptodev_stats_get failed");
3828 TEST_ASSERT((stats.enqueued_count == 1),
3829 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3830 TEST_ASSERT((stats.dequeued_count == 1),
3831 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3832 TEST_ASSERT((stats.enqueue_err_count == 0),
3833 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3834 TEST_ASSERT((stats.dequeue_err_count == 0),
3835 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3837 /* invalid device but should ignore and not reset device stats*/
3838 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3839 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3841 "rte_cryptodev_stats_get failed");
3842 TEST_ASSERT((stats.enqueued_count == 1),
3843 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3845 /* check that a valid reset clears stats */
3846 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3847 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3849 "rte_cryptodev_stats_get failed");
3850 TEST_ASSERT((stats.enqueued_count == 0),
3851 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3852 TEST_ASSERT((stats.dequeued_count == 0),
3853 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3855 return TEST_SUCCESS;
3858 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
3859 struct crypto_unittest_params *ut_params,
3860 enum rte_crypto_auth_operation op,
3861 const struct HMAC_MD5_vector *test_case)
3865 memcpy(key, test_case->key.data, test_case->key.len);
3867 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3868 ut_params->auth_xform.next = NULL;
3869 ut_params->auth_xform.auth.op = op;
3871 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
3873 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
3874 ut_params->auth_xform.auth.add_auth_data_length = 0;
3875 ut_params->auth_xform.auth.key.length = test_case->key.len;
3876 ut_params->auth_xform.auth.key.data = key;
3878 ut_params->sess = rte_cryptodev_sym_session_create(
3879 ts_params->valid_devs[0], &ut_params->auth_xform);
3881 if (ut_params->sess == NULL)
3884 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3886 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3887 rte_pktmbuf_tailroom(ut_params->ibuf));
3892 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
3893 const struct HMAC_MD5_vector *test_case,
3894 uint8_t **plaintext)
3896 uint16_t plaintext_pad_len;
3898 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3900 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3903 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3905 memcpy(*plaintext, test_case->plaintext.data,
3906 test_case->plaintext.len);
3908 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3909 ut_params->ibuf, MD5_DIGEST_LEN);
3910 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3911 "no room to append digest");
3912 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3913 ut_params->ibuf, plaintext_pad_len);
3914 sym_op->auth.digest.length = MD5_DIGEST_LEN;
3916 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
3917 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
3918 test_case->auth_tag.len);
3921 sym_op->auth.data.offset = 0;
3922 sym_op->auth.data.length = test_case->plaintext.len;
3924 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3925 ut_params->op->sym->m_src = ut_params->ibuf;
3931 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
3933 uint16_t plaintext_pad_len;
3934 uint8_t *plaintext, *auth_tag;
3936 struct crypto_testsuite_params *ts_params = &testsuite_params;
3937 struct crypto_unittest_params *ut_params = &unittest_params;
3939 if (MD5_HMAC_create_session(ts_params, ut_params,
3940 RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
3943 /* Generate Crypto op data structure */
3944 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3945 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3946 TEST_ASSERT_NOT_NULL(ut_params->op,
3947 "Failed to allocate symmetric crypto operation struct");
3949 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
3952 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3955 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3956 ut_params->op), "failed to process sym crypto op");
3958 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3959 "crypto op processing failed");
3961 if (ut_params->op->sym->m_dst) {
3962 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3963 uint8_t *, plaintext_pad_len);
3965 auth_tag = plaintext + plaintext_pad_len;
3968 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3970 test_case->auth_tag.data,
3971 test_case->auth_tag.len,
3972 "HMAC_MD5 generated tag not as expected");
3974 return TEST_SUCCESS;
3978 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
3982 struct crypto_testsuite_params *ts_params = &testsuite_params;
3983 struct crypto_unittest_params *ut_params = &unittest_params;
3985 if (MD5_HMAC_create_session(ts_params, ut_params,
3986 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
3990 /* Generate Crypto op data structure */
3991 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3992 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3993 TEST_ASSERT_NOT_NULL(ut_params->op,
3994 "Failed to allocate symmetric crypto operation struct");
3996 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
3999 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4000 ut_params->op), "failed to process sym crypto op");
4002 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4003 "HMAC_MD5 crypto op processing failed");
4005 return TEST_SUCCESS;
4009 test_MD5_HMAC_generate_case_1(void)
4011 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
4015 test_MD5_HMAC_verify_case_1(void)
4017 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
4021 test_MD5_HMAC_generate_case_2(void)
4023 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
4027 test_MD5_HMAC_verify_case_2(void)
4029 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
4033 test_multi_session(void)
4035 struct crypto_testsuite_params *ts_params = &testsuite_params;
4036 struct crypto_unittest_params *ut_params = &unittest_params;
4038 struct rte_cryptodev_info dev_info;
4039 struct rte_cryptodev_sym_session **sessions;
4043 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
4044 aes_cbc_key, hmac_sha512_key);
4047 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4049 sessions = rte_malloc(NULL,
4050 (sizeof(struct rte_cryptodev_sym_session *) *
4051 dev_info.sym.max_nb_sessions) + 1, 0);
4053 /* Create multiple crypto sessions*/
4054 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4055 sessions[i] = rte_cryptodev_sym_session_create(
4056 ts_params->valid_devs[0],
4057 &ut_params->auth_xform);
4058 TEST_ASSERT_NOT_NULL(sessions[i],
4059 "Session creation failed at session number %u",
4062 /* Attempt to send a request on each session */
4063 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
4067 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
4068 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
4070 "Failed to perform decrypt on request number %u.", i);
4071 /* free crypto operation structure */
4073 rte_crypto_op_free(ut_params->op);
4076 * free mbuf - both obuf and ibuf are usually the same,
4077 * so check if they point at the same address is necessary,
4078 * to avoid freeing the mbuf twice.
4080 if (ut_params->obuf) {
4081 rte_pktmbuf_free(ut_params->obuf);
4082 if (ut_params->ibuf == ut_params->obuf)
4083 ut_params->ibuf = 0;
4084 ut_params->obuf = 0;
4086 if (ut_params->ibuf) {
4087 rte_pktmbuf_free(ut_params->ibuf);
4088 ut_params->ibuf = 0;
4092 /* Next session create should fail */
4093 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4094 &ut_params->auth_xform);
4095 TEST_ASSERT_NULL(sessions[i],
4096 "Session creation succeeded unexpectedly!");
4098 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4099 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4104 return TEST_SUCCESS;
4108 test_null_cipher_only_operation(void)
4110 struct crypto_testsuite_params *ts_params = &testsuite_params;
4111 struct crypto_unittest_params *ut_params = &unittest_params;
4113 /* Generate test mbuf data and space for digest */
4114 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4115 catch_22_quote, QUOTE_512_BYTES, 0);
4117 /* Setup Cipher Parameters */
4118 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4119 ut_params->cipher_xform.next = NULL;
4121 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4122 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4124 /* Create Crypto session*/
4125 ut_params->sess = rte_cryptodev_sym_session_create(
4126 ts_params->valid_devs[0], &ut_params->cipher_xform);
4127 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4129 /* Generate Crypto op data structure */
4130 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4131 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4132 TEST_ASSERT_NOT_NULL(ut_params->op,
4133 "Failed to allocate symmetric crypto operation struct");
4135 /* Set crypto operation data parameters */
4136 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4138 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4140 /* set crypto operation source mbuf */
4141 sym_op->m_src = ut_params->ibuf;
4143 sym_op->cipher.data.offset = 0;
4144 sym_op->cipher.data.length = QUOTE_512_BYTES;
4146 /* Process crypto operation */
4147 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4149 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4151 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4152 "crypto operation processing failed");
4155 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4156 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4159 "Ciphertext data not as expected");
4161 return TEST_SUCCESS;
4165 test_null_auth_only_operation(void)
4167 struct crypto_testsuite_params *ts_params = &testsuite_params;
4168 struct crypto_unittest_params *ut_params = &unittest_params;
4170 /* Generate test mbuf data and space for digest */
4171 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4172 catch_22_quote, QUOTE_512_BYTES, 0);
4174 /* Setup HMAC Parameters */
4175 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4176 ut_params->auth_xform.next = NULL;
4178 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4179 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4181 /* Create Crypto session*/
4182 ut_params->sess = rte_cryptodev_sym_session_create(
4183 ts_params->valid_devs[0], &ut_params->auth_xform);
4184 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4186 /* Generate Crypto op data structure */
4187 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4188 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4189 TEST_ASSERT_NOT_NULL(ut_params->op,
4190 "Failed to allocate symmetric crypto operation struct");
4192 /* Set crypto operation data parameters */
4193 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4195 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4197 sym_op->m_src = ut_params->ibuf;
4199 sym_op->auth.data.offset = 0;
4200 sym_op->auth.data.length = QUOTE_512_BYTES;
4202 /* Process crypto operation */
4203 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4205 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4207 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4208 "crypto operation processing failed");
4210 return TEST_SUCCESS;
4214 test_null_cipher_auth_operation(void)
4216 struct crypto_testsuite_params *ts_params = &testsuite_params;
4217 struct crypto_unittest_params *ut_params = &unittest_params;
4219 /* Generate test mbuf data and space for digest */
4220 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4221 catch_22_quote, QUOTE_512_BYTES, 0);
4223 /* Setup Cipher Parameters */
4224 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4225 ut_params->cipher_xform.next = &ut_params->auth_xform;
4227 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4228 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4230 /* Setup HMAC Parameters */
4231 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4232 ut_params->auth_xform.next = NULL;
4234 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4235 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4237 /* Create Crypto session*/
4238 ut_params->sess = rte_cryptodev_sym_session_create(
4239 ts_params->valid_devs[0], &ut_params->cipher_xform);
4240 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4242 /* Generate Crypto op data structure */
4243 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4244 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4245 TEST_ASSERT_NOT_NULL(ut_params->op,
4246 "Failed to allocate symmetric crypto operation struct");
4248 /* Set crypto operation data parameters */
4249 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4251 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4253 sym_op->m_src = ut_params->ibuf;
4255 sym_op->cipher.data.offset = 0;
4256 sym_op->cipher.data.length = QUOTE_512_BYTES;
4258 sym_op->auth.data.offset = 0;
4259 sym_op->auth.data.length = QUOTE_512_BYTES;
4261 /* Process crypto operation */
4262 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4264 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4266 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4267 "crypto operation processing failed");
4270 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4271 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4274 "Ciphertext data not as expected");
4276 return TEST_SUCCESS;
4280 test_null_auth_cipher_operation(void)
4282 struct crypto_testsuite_params *ts_params = &testsuite_params;
4283 struct crypto_unittest_params *ut_params = &unittest_params;
4285 /* Generate test mbuf data and space for digest */
4286 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4287 catch_22_quote, QUOTE_512_BYTES, 0);
4289 /* Setup Cipher Parameters */
4290 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4291 ut_params->cipher_xform.next = NULL;
4293 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4294 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4296 /* Setup HMAC Parameters */
4297 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4298 ut_params->auth_xform.next = &ut_params->cipher_xform;
4300 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4301 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4303 /* Create Crypto session*/
4304 ut_params->sess = rte_cryptodev_sym_session_create(
4305 ts_params->valid_devs[0], &ut_params->cipher_xform);
4306 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4308 /* Generate Crypto op data structure */
4309 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4310 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4311 TEST_ASSERT_NOT_NULL(ut_params->op,
4312 "Failed to allocate symmetric crypto operation struct");
4314 /* Set crypto operation data parameters */
4315 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4317 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4319 sym_op->m_src = ut_params->ibuf;
4321 sym_op->cipher.data.offset = 0;
4322 sym_op->cipher.data.length = QUOTE_512_BYTES;
4324 sym_op->auth.data.offset = 0;
4325 sym_op->auth.data.length = QUOTE_512_BYTES;
4327 /* Process crypto operation */
4328 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4330 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4332 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4333 "crypto operation processing failed");
4336 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4337 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4340 "Ciphertext data not as expected");
4342 return TEST_SUCCESS;
4347 test_null_invalid_operation(void)
4349 struct crypto_testsuite_params *ts_params = &testsuite_params;
4350 struct crypto_unittest_params *ut_params = &unittest_params;
4352 /* Setup Cipher Parameters */
4353 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4354 ut_params->cipher_xform.next = NULL;
4356 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4357 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4359 /* Create Crypto session*/
4360 ut_params->sess = rte_cryptodev_sym_session_create(
4361 ts_params->valid_devs[0], &ut_params->cipher_xform);
4362 TEST_ASSERT_NULL(ut_params->sess,
4363 "Session creation succeeded unexpectedly");
4366 /* Setup HMAC Parameters */
4367 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4368 ut_params->auth_xform.next = NULL;
4370 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4371 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4373 /* Create Crypto session*/
4374 ut_params->sess = rte_cryptodev_sym_session_create(
4375 ts_params->valid_devs[0], &ut_params->auth_xform);
4376 TEST_ASSERT_NULL(ut_params->sess,
4377 "Session creation succeeded unexpectedly");
4379 return TEST_SUCCESS;
4383 #define NULL_BURST_LENGTH (32)
4386 test_null_burst_operation(void)
4388 struct crypto_testsuite_params *ts_params = &testsuite_params;
4389 struct crypto_unittest_params *ut_params = &unittest_params;
4391 unsigned i, burst_len = NULL_BURST_LENGTH;
4393 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4394 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4396 /* Setup Cipher Parameters */
4397 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4398 ut_params->cipher_xform.next = &ut_params->auth_xform;
4400 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4401 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4403 /* Setup HMAC Parameters */
4404 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4405 ut_params->auth_xform.next = NULL;
4407 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4408 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4410 /* Create Crypto session*/
4411 ut_params->sess = rte_cryptodev_sym_session_create(
4412 ts_params->valid_devs[0], &ut_params->cipher_xform);
4413 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4415 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4416 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4417 burst_len, "failed to generate burst of crypto ops");
4419 /* Generate an operation for each mbuf in burst */
4420 for (i = 0; i < burst_len; i++) {
4421 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4423 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
4425 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
4429 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
4431 burst[i]->sym->m_src = m;
4434 /* Process crypto operation */
4435 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
4436 0, burst, burst_len),
4438 "Error enqueuing burst");
4440 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4441 0, burst_dequeued, burst_len),
4443 "Error dequeuing burst");
4446 for (i = 0; i < burst_len; i++) {
4448 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4449 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4451 "data not as expected");
4453 rte_pktmbuf_free(burst[i]->sym->m_src);
4454 rte_crypto_op_free(burst[i]);
4457 return TEST_SUCCESS;
4461 create_gmac_operation(enum rte_crypto_auth_operation op,
4462 const struct gmac_test_data *tdata)
4464 struct crypto_testsuite_params *ts_params = &testsuite_params;
4465 struct crypto_unittest_params *ut_params = &unittest_params;
4466 struct rte_crypto_sym_op *sym_op;
4468 unsigned iv_pad_len;
4469 unsigned aad_pad_len;
4471 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
4472 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4474 /* Generate Crypto op data structure */
4475 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4476 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4477 TEST_ASSERT_NOT_NULL(ut_params->op,
4478 "Failed to allocate symmetric crypto operation struct");
4480 sym_op = ut_params->op->sym;
4481 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4483 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4484 "no room to append aad");
4486 sym_op->auth.aad.length = tdata->aad.len;
4487 sym_op->auth.aad.phys_addr =
4488 rte_pktmbuf_mtophys(ut_params->ibuf);
4489 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
4491 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4492 ut_params->ibuf, tdata->gmac_tag.len);
4493 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4494 "no room to append digest");
4496 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4497 ut_params->ibuf, aad_pad_len);
4498 sym_op->auth.digest.length = tdata->gmac_tag.len;
4500 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
4501 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
4502 tdata->gmac_tag.len);
4503 TEST_HEXDUMP(stdout, "digest:",
4504 sym_op->auth.digest.data,
4505 sym_op->auth.digest.length);
4508 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4509 ut_params->ibuf, iv_pad_len);
4510 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4512 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4513 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4514 sym_op->cipher.iv.length = tdata->iv.len;
4516 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
4518 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
4520 sym_op->cipher.data.length = 0;
4521 sym_op->cipher.data.offset = 0;
4523 sym_op->auth.data.offset = 0;
4524 sym_op->auth.data.length = 0;
4529 static int create_gmac_session(uint8_t dev_id,
4530 enum rte_crypto_cipher_operation op,
4531 const struct gmac_test_data *tdata,
4532 enum rte_crypto_auth_operation auth_op)
4534 uint8_t cipher_key[tdata->key.len];
4536 struct crypto_unittest_params *ut_params = &unittest_params;
4538 memcpy(cipher_key, tdata->key.data, tdata->key.len);
4540 /* For GMAC we setup cipher parameters */
4541 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4542 ut_params->cipher_xform.next = NULL;
4543 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4544 ut_params->cipher_xform.cipher.op = op;
4545 ut_params->cipher_xform.cipher.key.data = cipher_key;
4546 ut_params->cipher_xform.cipher.key.length = tdata->key.len;
4548 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4549 ut_params->auth_xform.next = NULL;
4551 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
4552 ut_params->auth_xform.auth.op = auth_op;
4553 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
4554 ut_params->auth_xform.auth.add_auth_data_length = 0;
4555 ut_params->auth_xform.auth.key.length = 0;
4556 ut_params->auth_xform.auth.key.data = NULL;
4558 ut_params->cipher_xform.next = &ut_params->auth_xform;
4560 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4561 &ut_params->cipher_xform);
4563 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4569 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
4571 struct crypto_testsuite_params *ts_params = &testsuite_params;
4572 struct crypto_unittest_params *ut_params = &unittest_params;
4576 uint8_t *auth_tag, *p;
4577 uint16_t aad_pad_len;
4579 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
4580 "No GMAC length in the source data");
4582 retval = create_gmac_session(ts_params->valid_devs[0],
4583 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4584 tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
4589 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4591 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4592 rte_pktmbuf_tailroom(ut_params->ibuf));
4594 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
4596 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
4598 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
4604 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4606 ut_params->op->sym->m_src = ut_params->ibuf;
4608 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4609 ut_params->op), "failed to process sym crypto op");
4611 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4612 "crypto op processing failed");
4614 if (ut_params->op->sym->m_dst) {
4615 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4616 uint8_t *, aad_pad_len);
4618 auth_tag = p + aad_pad_len;
4621 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
4623 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4625 tdata->gmac_tag.data,
4626 tdata->gmac_tag.len,
4627 "GMAC Generated auth tag not as expected");
4633 test_AES_GMAC_authentication_test_case_1(void)
4635 return test_AES_GMAC_authentication(&gmac_test_case_1);
4639 test_AES_GMAC_authentication_test_case_2(void)
4641 return test_AES_GMAC_authentication(&gmac_test_case_2);
4645 test_AES_GMAC_authentication_test_case_3(void)
4647 return test_AES_GMAC_authentication(&gmac_test_case_3);
4651 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
4653 struct crypto_testsuite_params *ts_params = &testsuite_params;
4654 struct crypto_unittest_params *ut_params = &unittest_params;
4657 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
4658 "No GMAC length in the source data");
4660 retval = create_gmac_session(ts_params->valid_devs[0],
4661 RTE_CRYPTO_CIPHER_OP_DECRYPT,
4662 tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
4667 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4669 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4670 rte_pktmbuf_tailroom(ut_params->ibuf));
4672 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
4678 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4680 ut_params->op->sym->m_src = ut_params->ibuf;
4682 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4683 ut_params->op), "failed to process sym crypto op");
4685 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4686 "crypto op processing failed");
4693 test_AES_GMAC_authentication_verify_test_case_1(void)
4695 return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
4699 test_AES_GMAC_authentication_verify_test_case_2(void)
4701 return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
4705 test_AES_GMAC_authentication_verify_test_case_3(void)
4707 return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
4710 static struct unit_test_suite cryptodev_qat_testsuite = {
4711 .suite_name = "Crypto QAT Unit Test Suite",
4712 .setup = testsuite_setup,
4713 .teardown = testsuite_teardown,
4714 .unit_test_cases = {
4715 TEST_CASE_ST(ut_setup, ut_teardown,
4716 test_device_configure_invalid_dev_id),
4717 TEST_CASE_ST(ut_setup, ut_teardown,
4718 test_device_configure_invalid_queue_pair_ids),
4719 TEST_CASE_ST(ut_setup, ut_teardown,
4720 test_queue_pair_descriptor_setup),
4721 TEST_CASE_ST(ut_setup, ut_teardown,
4722 test_multi_session),
4724 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
4725 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4727 /** AES GCM Authenticated Encryption */
4728 TEST_CASE_ST(ut_setup, ut_teardown,
4729 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4730 TEST_CASE_ST(ut_setup, ut_teardown,
4731 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4732 TEST_CASE_ST(ut_setup, ut_teardown,
4733 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4734 TEST_CASE_ST(ut_setup, ut_teardown,
4735 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4736 TEST_CASE_ST(ut_setup, ut_teardown,
4737 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4738 TEST_CASE_ST(ut_setup, ut_teardown,
4739 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4740 TEST_CASE_ST(ut_setup, ut_teardown,
4741 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4743 /** AES GCM Authenticated Decryption */
4744 TEST_CASE_ST(ut_setup, ut_teardown,
4745 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4746 TEST_CASE_ST(ut_setup, ut_teardown,
4747 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4748 TEST_CASE_ST(ut_setup, ut_teardown,
4749 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4750 TEST_CASE_ST(ut_setup, ut_teardown,
4751 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4752 TEST_CASE_ST(ut_setup, ut_teardown,
4753 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4754 TEST_CASE_ST(ut_setup, ut_teardown,
4755 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4756 TEST_CASE_ST(ut_setup, ut_teardown,
4757 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4759 /** AES GMAC Authentication */
4760 TEST_CASE_ST(ut_setup, ut_teardown,
4761 test_AES_GMAC_authentication_test_case_1),
4762 TEST_CASE_ST(ut_setup, ut_teardown,
4763 test_AES_GMAC_authentication_verify_test_case_1),
4764 TEST_CASE_ST(ut_setup, ut_teardown,
4765 test_AES_GMAC_authentication_test_case_2),
4766 TEST_CASE_ST(ut_setup, ut_teardown,
4767 test_AES_GMAC_authentication_verify_test_case_2),
4768 TEST_CASE_ST(ut_setup, ut_teardown,
4769 test_AES_GMAC_authentication_test_case_3),
4770 TEST_CASE_ST(ut_setup, ut_teardown,
4771 test_AES_GMAC_authentication_verify_test_case_3),
4773 /** SNOW 3G encrypt only (UEA2) */
4774 TEST_CASE_ST(ut_setup, ut_teardown,
4775 test_snow3g_encryption_test_case_1),
4776 TEST_CASE_ST(ut_setup, ut_teardown,
4777 test_snow3g_encryption_test_case_2),
4778 TEST_CASE_ST(ut_setup, ut_teardown,
4779 test_snow3g_encryption_test_case_3),
4780 TEST_CASE_ST(ut_setup, ut_teardown,
4781 test_snow3g_encryption_test_case_4),
4782 TEST_CASE_ST(ut_setup, ut_teardown,
4783 test_snow3g_encryption_test_case_5),
4785 TEST_CASE_ST(ut_setup, ut_teardown,
4786 test_snow3g_encryption_test_case_1_oop),
4787 TEST_CASE_ST(ut_setup, ut_teardown,
4788 test_snow3g_decryption_test_case_1_oop),
4790 /** SNOW 3G decrypt only (UEA2) */
4791 TEST_CASE_ST(ut_setup, ut_teardown,
4792 test_snow3g_decryption_test_case_1),
4793 TEST_CASE_ST(ut_setup, ut_teardown,
4794 test_snow3g_decryption_test_case_2),
4795 TEST_CASE_ST(ut_setup, ut_teardown,
4796 test_snow3g_decryption_test_case_3),
4797 TEST_CASE_ST(ut_setup, ut_teardown,
4798 test_snow3g_decryption_test_case_4),
4799 TEST_CASE_ST(ut_setup, ut_teardown,
4800 test_snow3g_decryption_test_case_5),
4801 TEST_CASE_ST(ut_setup, ut_teardown,
4802 test_snow3g_hash_generate_test_case_1),
4803 TEST_CASE_ST(ut_setup, ut_teardown,
4804 test_snow3g_hash_generate_test_case_2),
4805 TEST_CASE_ST(ut_setup, ut_teardown,
4806 test_snow3g_hash_generate_test_case_3),
4807 TEST_CASE_ST(ut_setup, ut_teardown,
4808 test_snow3g_hash_verify_test_case_1),
4809 TEST_CASE_ST(ut_setup, ut_teardown,
4810 test_snow3g_hash_verify_test_case_2),
4811 TEST_CASE_ST(ut_setup, ut_teardown,
4812 test_snow3g_hash_verify_test_case_3),
4813 TEST_CASE_ST(ut_setup, ut_teardown,
4814 test_snow3g_cipher_auth_test_case_1),
4815 TEST_CASE_ST(ut_setup, ut_teardown,
4816 test_snow3g_auth_cipher_test_case_1),
4818 /** HMAC_MD5 Authentication */
4819 TEST_CASE_ST(ut_setup, ut_teardown,
4820 test_MD5_HMAC_generate_case_1),
4821 TEST_CASE_ST(ut_setup, ut_teardown,
4822 test_MD5_HMAC_verify_case_1),
4823 TEST_CASE_ST(ut_setup, ut_teardown,
4824 test_MD5_HMAC_generate_case_2),
4825 TEST_CASE_ST(ut_setup, ut_teardown,
4826 test_MD5_HMAC_verify_case_2),
4829 TEST_CASE_ST(ut_setup, ut_teardown,
4830 test_null_auth_only_operation),
4831 TEST_CASE_ST(ut_setup, ut_teardown,
4832 test_null_cipher_only_operation),
4833 TEST_CASE_ST(ut_setup, ut_teardown,
4834 test_null_cipher_auth_operation),
4835 TEST_CASE_ST(ut_setup, ut_teardown,
4836 test_null_auth_cipher_operation),
4838 TEST_CASE_ST(ut_setup, ut_teardown,
4839 test_kasumi_hash_generate_test_case_6),
4842 TEST_CASE_ST(ut_setup, ut_teardown,
4843 test_kasumi_encryption_test_case_1),
4844 TEST_CASE_ST(ut_setup, ut_teardown,
4845 test_kasumi_encryption_test_case_3),
4846 TEST_CASE_ST(ut_setup, ut_teardown,
4847 test_kasumi_auth_cipher_test_case_1),
4848 TEST_CASE_ST(ut_setup, ut_teardown,
4849 test_kasumi_cipher_auth_test_case_1),
4851 TEST_CASES_END() /**< NULL terminate unit test array */
4855 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
4856 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4857 .setup = testsuite_setup,
4858 .teardown = testsuite_teardown,
4859 .unit_test_cases = {
4860 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
4862 TEST_CASES_END() /**< NULL terminate unit test array */
4866 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
4867 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4868 .setup = testsuite_setup,
4869 .teardown = testsuite_teardown,
4870 .unit_test_cases = {
4871 /** AES GCM Authenticated Encryption */
4872 TEST_CASE_ST(ut_setup, ut_teardown,
4873 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4874 TEST_CASE_ST(ut_setup, ut_teardown,
4875 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4876 TEST_CASE_ST(ut_setup, ut_teardown,
4877 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4878 TEST_CASE_ST(ut_setup, ut_teardown,
4879 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4880 TEST_CASE_ST(ut_setup, ut_teardown,
4881 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4882 TEST_CASE_ST(ut_setup, ut_teardown,
4883 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4884 TEST_CASE_ST(ut_setup, ut_teardown,
4885 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4887 /** AES GCM Authenticated Decryption */
4888 TEST_CASE_ST(ut_setup, ut_teardown,
4889 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4890 TEST_CASE_ST(ut_setup, ut_teardown,
4891 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4892 TEST_CASE_ST(ut_setup, ut_teardown,
4893 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4894 TEST_CASE_ST(ut_setup, ut_teardown,
4895 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4896 TEST_CASE_ST(ut_setup, ut_teardown,
4897 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4898 TEST_CASE_ST(ut_setup, ut_teardown,
4899 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4900 TEST_CASE_ST(ut_setup, ut_teardown,
4901 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4903 TEST_CASES_END() /**< NULL terminate unit test array */
4907 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
4908 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
4909 .setup = testsuite_setup,
4910 .teardown = testsuite_teardown,
4911 .unit_test_cases = {
4912 /** KASUMI encrypt only (UEA1) */
4913 TEST_CASE_ST(ut_setup, ut_teardown,
4914 test_kasumi_encryption_test_case_1),
4915 TEST_CASE_ST(ut_setup, ut_teardown,
4916 test_kasumi_encryption_test_case_2),
4917 TEST_CASE_ST(ut_setup, ut_teardown,
4918 test_kasumi_encryption_test_case_3),
4919 TEST_CASE_ST(ut_setup, ut_teardown,
4920 test_kasumi_encryption_test_case_4),
4921 TEST_CASE_ST(ut_setup, ut_teardown,
4922 test_kasumi_encryption_test_case_5),
4923 /** KASUMI decrypt only (UEA1) */
4924 TEST_CASE_ST(ut_setup, ut_teardown,
4925 test_kasumi_decryption_test_case_1),
4926 TEST_CASE_ST(ut_setup, ut_teardown,
4927 test_kasumi_decryption_test_case_2),
4928 TEST_CASE_ST(ut_setup, ut_teardown,
4929 test_kasumi_decryption_test_case_3),
4930 TEST_CASE_ST(ut_setup, ut_teardown,
4931 test_kasumi_decryption_test_case_4),
4932 TEST_CASE_ST(ut_setup, ut_teardown,
4933 test_kasumi_decryption_test_case_5),
4935 TEST_CASE_ST(ut_setup, ut_teardown,
4936 test_kasumi_encryption_test_case_1_oop),
4937 TEST_CASE_ST(ut_setup, ut_teardown,
4938 test_kasumi_decryption_test_case_1_oop),
4940 /** KASUMI hash only (UIA1) */
4941 TEST_CASE_ST(ut_setup, ut_teardown,
4942 test_kasumi_hash_generate_test_case_1),
4943 TEST_CASE_ST(ut_setup, ut_teardown,
4944 test_kasumi_hash_generate_test_case_2),
4945 TEST_CASE_ST(ut_setup, ut_teardown,
4946 test_kasumi_hash_generate_test_case_3),
4947 TEST_CASE_ST(ut_setup, ut_teardown,
4948 test_kasumi_hash_generate_test_case_4),
4949 TEST_CASE_ST(ut_setup, ut_teardown,
4950 test_kasumi_hash_generate_test_case_5),
4951 TEST_CASE_ST(ut_setup, ut_teardown,
4952 test_kasumi_hash_generate_test_case_6),
4953 TEST_CASE_ST(ut_setup, ut_teardown,
4954 test_kasumi_hash_verify_test_case_1),
4955 TEST_CASE_ST(ut_setup, ut_teardown,
4956 test_kasumi_hash_verify_test_case_2),
4957 TEST_CASE_ST(ut_setup, ut_teardown,
4958 test_kasumi_hash_verify_test_case_3),
4959 TEST_CASE_ST(ut_setup, ut_teardown,
4960 test_kasumi_hash_verify_test_case_4),
4961 TEST_CASE_ST(ut_setup, ut_teardown,
4962 test_kasumi_hash_verify_test_case_5),
4963 TEST_CASE_ST(ut_setup, ut_teardown,
4964 test_kasumi_auth_cipher_test_case_1),
4965 TEST_CASE_ST(ut_setup, ut_teardown,
4966 test_kasumi_cipher_auth_test_case_1),
4967 TEST_CASES_END() /**< NULL terminate unit test array */
4970 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4971 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
4972 .setup = testsuite_setup,
4973 .teardown = testsuite_teardown,
4974 .unit_test_cases = {
4975 /** SNOW 3G encrypt only (UEA2) */
4976 TEST_CASE_ST(ut_setup, ut_teardown,
4977 test_snow3g_encryption_test_case_1),
4978 TEST_CASE_ST(ut_setup, ut_teardown,
4979 test_snow3g_encryption_test_case_2),
4980 TEST_CASE_ST(ut_setup, ut_teardown,
4981 test_snow3g_encryption_test_case_3),
4982 TEST_CASE_ST(ut_setup, ut_teardown,
4983 test_snow3g_encryption_test_case_4),
4984 TEST_CASE_ST(ut_setup, ut_teardown,
4985 test_snow3g_encryption_test_case_5),
4987 TEST_CASE_ST(ut_setup, ut_teardown,
4988 test_snow3g_encryption_test_case_1_oop),
4989 TEST_CASE_ST(ut_setup, ut_teardown,
4990 test_snow3g_decryption_test_case_1_oop),
4992 TEST_CASE_ST(ut_setup, ut_teardown,
4993 test_snow3g_encryption_test_case_1_offset_oop),
4995 /** SNOW 3G decrypt only (UEA2) */
4996 TEST_CASE_ST(ut_setup, ut_teardown,
4997 test_snow3g_decryption_test_case_1),
4998 TEST_CASE_ST(ut_setup, ut_teardown,
4999 test_snow3g_decryption_test_case_2),
5000 TEST_CASE_ST(ut_setup, ut_teardown,
5001 test_snow3g_decryption_test_case_3),
5002 TEST_CASE_ST(ut_setup, ut_teardown,
5003 test_snow3g_decryption_test_case_4),
5004 TEST_CASE_ST(ut_setup, ut_teardown,
5005 test_snow3g_decryption_test_case_5),
5006 TEST_CASE_ST(ut_setup, ut_teardown,
5007 test_snow3g_hash_generate_test_case_1),
5008 TEST_CASE_ST(ut_setup, ut_teardown,
5009 test_snow3g_hash_generate_test_case_2),
5010 TEST_CASE_ST(ut_setup, ut_teardown,
5011 test_snow3g_hash_generate_test_case_3),
5012 /* Tests with buffers which length is not byte-aligned */
5013 TEST_CASE_ST(ut_setup, ut_teardown,
5014 test_snow3g_hash_generate_test_case_4),
5015 TEST_CASE_ST(ut_setup, ut_teardown,
5016 test_snow3g_hash_generate_test_case_5),
5017 TEST_CASE_ST(ut_setup, ut_teardown,
5018 test_snow3g_hash_generate_test_case_6),
5019 TEST_CASE_ST(ut_setup, ut_teardown,
5020 test_snow3g_hash_verify_test_case_1),
5021 TEST_CASE_ST(ut_setup, ut_teardown,
5022 test_snow3g_hash_verify_test_case_2),
5023 TEST_CASE_ST(ut_setup, ut_teardown,
5024 test_snow3g_hash_verify_test_case_3),
5025 /* Tests with buffers which length is not byte-aligned */
5026 TEST_CASE_ST(ut_setup, ut_teardown,
5027 test_snow3g_hash_verify_test_case_4),
5028 TEST_CASE_ST(ut_setup, ut_teardown,
5029 test_snow3g_hash_verify_test_case_5),
5030 TEST_CASE_ST(ut_setup, ut_teardown,
5031 test_snow3g_hash_verify_test_case_6),
5032 TEST_CASE_ST(ut_setup, ut_teardown,
5033 test_snow3g_cipher_auth_test_case_1),
5034 TEST_CASE_ST(ut_setup, ut_teardown,
5035 test_snow3g_auth_cipher_test_case_1),
5037 TEST_CASES_END() /**< NULL terminate unit test array */
5041 static struct unit_test_suite cryptodev_sw_zuc_testsuite = {
5042 .suite_name = "Crypto Device SW ZUC Unit Test Suite",
5043 .setup = testsuite_setup,
5044 .teardown = testsuite_teardown,
5045 .unit_test_cases = {
5046 /** ZUC encrypt only (EEA3) */
5047 TEST_CASE_ST(ut_setup, ut_teardown,
5048 test_zuc_encryption_test_case_1),
5049 TEST_CASE_ST(ut_setup, ut_teardown,
5050 test_zuc_encryption_test_case_2),
5051 TEST_CASE_ST(ut_setup, ut_teardown,
5052 test_zuc_encryption_test_case_3),
5053 TEST_CASE_ST(ut_setup, ut_teardown,
5054 test_zuc_encryption_test_case_4),
5055 TEST_CASE_ST(ut_setup, ut_teardown,
5056 test_zuc_encryption_test_case_5),
5057 TEST_CASE_ST(ut_setup, ut_teardown,
5058 test_zuc_hash_generate_test_case_1),
5059 TEST_CASE_ST(ut_setup, ut_teardown,
5060 test_zuc_hash_generate_test_case_2),
5061 TEST_CASE_ST(ut_setup, ut_teardown,
5062 test_zuc_hash_generate_test_case_3),
5063 TEST_CASE_ST(ut_setup, ut_teardown,
5064 test_zuc_hash_generate_test_case_4),
5065 TEST_CASE_ST(ut_setup, ut_teardown,
5066 test_zuc_hash_generate_test_case_5),
5067 TEST_CASES_END() /**< NULL terminate unit test array */
5071 static struct unit_test_suite cryptodev_null_testsuite = {
5072 .suite_name = "Crypto Device NULL Unit Test Suite",
5073 .setup = testsuite_setup,
5074 .teardown = testsuite_teardown,
5075 .unit_test_cases = {
5076 TEST_CASE_ST(ut_setup, ut_teardown,
5077 test_null_auth_only_operation),
5078 TEST_CASE_ST(ut_setup, ut_teardown,
5079 test_null_cipher_only_operation),
5080 TEST_CASE_ST(ut_setup, ut_teardown,
5081 test_null_cipher_auth_operation),
5082 TEST_CASE_ST(ut_setup, ut_teardown,
5083 test_null_auth_cipher_operation),
5084 TEST_CASE_ST(ut_setup, ut_teardown,
5085 test_null_invalid_operation),
5086 TEST_CASE_ST(ut_setup, ut_teardown,
5087 test_null_burst_operation),
5089 TEST_CASES_END() /**< NULL terminate unit test array */
5094 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
5096 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
5097 return unit_test_suite_runner(&cryptodev_qat_testsuite);
5101 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
5103 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
5105 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
5109 test_cryptodev_aesni_gcm(void)
5111 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
5113 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
5117 test_cryptodev_null(void)
5119 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
5121 return unit_test_suite_runner(&cryptodev_null_testsuite);
5125 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
5127 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
5129 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
5133 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
5135 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
5137 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
5141 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
5143 gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
5145 return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
5148 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
5149 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
5150 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
5151 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
5152 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
5153 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
5154 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);