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_des_test_vectors.h"
49 #include "test_cryptodev_hash_test_vectors.h"
50 #include "test_cryptodev_kasumi_test_vectors.h"
51 #include "test_cryptodev_kasumi_hash_test_vectors.h"
52 #include "test_cryptodev_snow3g_test_vectors.h"
53 #include "test_cryptodev_snow3g_hash_test_vectors.h"
54 #include "test_cryptodev_zuc_test_vectors.h"
55 #include "test_cryptodev_zuc_hash_test_vectors.h"
56 #include "test_cryptodev_gcm_test_vectors.h"
57 #include "test_cryptodev_hmac_test_vectors.h"
59 static enum rte_cryptodev_type gbl_cryptodev_type;
61 struct crypto_testsuite_params {
62 struct rte_mempool *mbuf_pool;
63 struct rte_mempool *large_mbuf_pool;
64 struct rte_mempool *op_mpool;
65 struct rte_cryptodev_config conf;
66 struct rte_cryptodev_qp_conf qp_conf;
68 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
69 uint8_t valid_dev_count;
72 struct crypto_unittest_params {
73 struct rte_crypto_sym_xform cipher_xform;
74 struct rte_crypto_sym_xform auth_xform;
76 struct rte_cryptodev_sym_session *sess;
78 struct rte_crypto_op *op;
80 struct rte_mbuf *obuf, *ibuf;
85 #define ALIGN_POW2_ROUNDUP(num, align) \
86 (((num) + (align) - 1) & ~((align) - 1))
89 * Forward declarations.
92 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
93 struct crypto_unittest_params *ut_params, uint8_t *cipher_key,
97 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
98 struct crypto_unittest_params *ut_params,
99 struct crypto_testsuite_params *ts_param,
100 const uint8_t *cipher,
101 const uint8_t *digest,
104 static struct rte_mbuf *
105 setup_test_string(struct rte_mempool *mpool,
106 const char *string, size_t len, uint8_t blocksize)
108 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
109 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
111 memset(m->buf_addr, 0, m->buf_len);
113 char *dst = rte_pktmbuf_append(m, t_len);
120 rte_memcpy(dst, string, t_len);
122 memset(dst, 0, t_len);
128 /* Get number of bytes in X bits (rounding up) */
130 ceil_byte_length(uint32_t num_bits)
133 return ((num_bits >> 3) + 1);
135 return (num_bits >> 3);
138 static struct rte_crypto_op *
139 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
141 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
142 printf("Error sending packet for encryption");
148 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
154 static struct crypto_testsuite_params testsuite_params = { NULL };
155 static struct crypto_unittest_params unittest_params;
158 testsuite_setup(void)
160 struct crypto_testsuite_params *ts_params = &testsuite_params;
161 struct rte_cryptodev_info info;
162 unsigned i, nb_devs, dev_id;
166 memset(ts_params, 0, sizeof(*ts_params));
168 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
169 if (ts_params->mbuf_pool == NULL) {
170 /* Not already created so create */
171 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
173 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
175 if (ts_params->mbuf_pool == NULL) {
176 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
181 ts_params->large_mbuf_pool = rte_mempool_lookup(
182 "CRYPTO_LARGE_MBUFPOOL");
183 if (ts_params->large_mbuf_pool == NULL) {
184 /* Not already created so create */
185 ts_params->large_mbuf_pool = rte_pktmbuf_pool_create(
186 "CRYPTO_LARGE_MBUFPOOL",
189 if (ts_params->large_mbuf_pool == NULL) {
191 "Can't create CRYPTO_LARGE_MBUFPOOL\n");
196 ts_params->op_mpool = rte_crypto_op_pool_create(
197 "MBUF_CRYPTO_SYM_OP_POOL",
198 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
199 NUM_MBUFS, MBUF_CACHE_SIZE,
201 sizeof(struct rte_crypto_sym_xform),
203 if (ts_params->op_mpool == NULL) {
204 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
208 /* Create 2 AESNI MB devices if required */
209 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
210 #ifndef RTE_LIBRTE_PMD_AESNI_MB
211 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_MB must be"
212 " enabled in config file to run this testsuite.\n");
215 nb_devs = rte_cryptodev_count_devtype(
216 RTE_CRYPTODEV_AESNI_MB_PMD);
218 for (i = nb_devs; i < 2; i++) {
219 ret = rte_eal_vdev_init(
220 RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD), NULL);
222 TEST_ASSERT(ret == 0,
223 "Failed to create instance %u of"
225 i, RTE_STR(CRYPTODEV_NAME_AESNI_MB_PMD));
230 /* Create 2 AESNI GCM devices if required */
231 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
232 #ifndef RTE_LIBRTE_PMD_AESNI_GCM
233 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_AESNI_GCM must be"
234 " enabled in config file to run this testsuite.\n");
237 nb_devs = rte_cryptodev_count_devtype(
238 RTE_CRYPTODEV_AESNI_GCM_PMD);
240 for (i = nb_devs; i < 2; i++) {
241 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
242 RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD), NULL),
243 "Failed to create instance %u of"
245 i, RTE_STR(CRYPTODEV_NAME_AESNI_GCM_PMD));
250 /* Create 2 SNOW 3G devices if required */
251 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
252 #ifndef RTE_LIBRTE_PMD_SNOW3G
253 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_SNOW3G must be"
254 " enabled in config file to run this testsuite.\n");
257 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
259 for (i = nb_devs; i < 2; i++) {
260 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
261 RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD), NULL),
262 "Failed to create instance %u of"
264 i, RTE_STR(CRYPTODEV_NAME_SNOW3G_PMD));
269 /* Create 2 KASUMI devices if required */
270 if (gbl_cryptodev_type == RTE_CRYPTODEV_KASUMI_PMD) {
271 #ifndef RTE_LIBRTE_PMD_KASUMI
272 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_KASUMI must be"
273 " enabled in config file to run this testsuite.\n");
276 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_KASUMI_PMD);
278 for (i = nb_devs; i < 2; i++) {
279 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
280 RTE_STR(CRYPTODEV_NAME_KASUMI_PMD), NULL),
281 "Failed to create instance %u of"
283 i, RTE_STR(CRYPTODEV_NAME_KASUMI_PMD));
288 /* Create 2 ZUC devices if required */
289 if (gbl_cryptodev_type == RTE_CRYPTODEV_ZUC_PMD) {
290 #ifndef RTE_LIBRTE_PMD_ZUC
291 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_ZUC must be"
292 " enabled in config file to run this testsuite.\n");
295 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_ZUC_PMD);
297 for (i = nb_devs; i < 2; i++) {
298 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
299 RTE_STR(CRYPTODEV_NAME_ZUC_PMD), NULL),
300 "Failed to create instance %u of"
302 i, RTE_STR(CRYPTODEV_NAME_ZUC_PMD));
307 /* Create 2 NULL devices if required */
308 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
309 #ifndef RTE_LIBRTE_PMD_NULL_CRYPTO
310 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_NULL_CRYPTO must be"
311 " enabled in config file to run this testsuite.\n");
314 nb_devs = rte_cryptodev_count_devtype(
315 RTE_CRYPTODEV_NULL_PMD);
317 for (i = nb_devs; i < 2; i++) {
318 int dev_id = rte_eal_vdev_init(
319 RTE_STR(CRYPTODEV_NAME_NULL_PMD), NULL);
321 TEST_ASSERT(dev_id >= 0,
322 "Failed to create instance %u of"
324 i, RTE_STR(CRYPTODEV_NAME_NULL_PMD));
329 /* Create 2 OPENSSL devices if required */
330 if (gbl_cryptodev_type == RTE_CRYPTODEV_OPENSSL_PMD) {
331 #ifndef RTE_LIBRTE_PMD_OPENSSL
332 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_OPENSSL must be"
333 " enabled in config file to run this testsuite.\n");
336 nb_devs = rte_cryptodev_count_devtype(
337 RTE_CRYPTODEV_OPENSSL_PMD);
339 for (i = nb_devs; i < 2; i++) {
340 ret = rte_eal_vdev_init(
341 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
344 TEST_ASSERT(ret == 0, "Failed to create "
345 "instance %u of pmd : %s", i,
346 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
351 #ifndef RTE_LIBRTE_PMD_QAT
352 if (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) {
353 RTE_LOG(ERR, USER1, "CONFIG_RTE_LIBRTE_PMD_QAT must be enabled "
354 "in config file to run this testsuite.\n");
359 nb_devs = rte_cryptodev_count();
361 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
365 /* Create list of valid crypto devs */
366 for (i = 0; i < nb_devs; i++) {
367 rte_cryptodev_info_get(i, &info);
368 if (info.dev_type == gbl_cryptodev_type)
369 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
372 if (ts_params->valid_dev_count < 1)
375 /* Set up all the qps on the first of the valid devices found */
377 dev_id = ts_params->valid_devs[0];
379 rte_cryptodev_info_get(dev_id, &info);
381 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
382 ts_params->conf.socket_id = SOCKET_ID_ANY;
383 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
385 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
387 "Failed to configure cryptodev %u with %u qps",
388 dev_id, ts_params->conf.nb_queue_pairs);
390 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
392 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
393 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
394 dev_id, qp_id, &ts_params->qp_conf,
395 rte_cryptodev_socket_id(dev_id)),
396 "Failed to setup queue pair %u on cryptodev %u",
404 testsuite_teardown(void)
406 struct crypto_testsuite_params *ts_params = &testsuite_params;
408 if (ts_params->mbuf_pool != NULL) {
409 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
410 rte_mempool_avail_count(ts_params->mbuf_pool));
413 if (ts_params->op_mpool != NULL) {
414 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
415 rte_mempool_avail_count(ts_params->op_mpool));
423 struct crypto_testsuite_params *ts_params = &testsuite_params;
424 struct crypto_unittest_params *ut_params = &unittest_params;
428 /* Clear unit test parameters before running test */
429 memset(ut_params, 0, sizeof(*ut_params));
431 /* Reconfigure device to default parameters */
432 ts_params->conf.socket_id = SOCKET_ID_ANY;
433 ts_params->conf.session_mp.nb_objs = DEFAULT_NUM_OPS_INFLIGHT;
435 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
437 "Failed to configure cryptodev %u",
438 ts_params->valid_devs[0]);
440 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
441 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
442 ts_params->valid_devs[0], qp_id,
444 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
445 "Failed to setup queue pair %u on cryptodev %u",
446 qp_id, ts_params->valid_devs[0]);
450 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
452 /* Start the device */
453 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
454 "Failed to start cryptodev %u",
455 ts_params->valid_devs[0]);
463 struct crypto_testsuite_params *ts_params = &testsuite_params;
464 struct crypto_unittest_params *ut_params = &unittest_params;
465 struct rte_cryptodev_stats stats;
467 /* free crypto session structure */
468 if (ut_params->sess) {
469 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
471 ut_params->sess = NULL;
474 /* free crypto operation structure */
476 rte_crypto_op_free(ut_params->op);
479 * free mbuf - both obuf and ibuf are usually the same,
480 * so check if they point at the same address is necessary,
481 * to avoid freeing the mbuf twice.
483 if (ut_params->obuf) {
484 rte_pktmbuf_free(ut_params->obuf);
485 if (ut_params->ibuf == ut_params->obuf)
489 if (ut_params->ibuf) {
490 rte_pktmbuf_free(ut_params->ibuf);
494 if (ts_params->mbuf_pool != NULL)
495 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
496 rte_mempool_avail_count(ts_params->mbuf_pool));
498 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
500 /* Stop the device */
501 rte_cryptodev_stop(ts_params->valid_devs[0]);
505 test_device_configure_invalid_dev_id(void)
507 struct crypto_testsuite_params *ts_params = &testsuite_params;
508 uint16_t dev_id, num_devs = 0;
510 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
511 "Need at least %d devices for test", 1);
513 /* valid dev_id values */
514 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
516 /* Stop the device in case it's started so it can be configured */
517 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
519 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
520 "Failed test for rte_cryptodev_configure: "
521 "invalid dev_num %u", dev_id);
523 /* invalid dev_id values */
526 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
527 "Failed test for rte_cryptodev_configure: "
528 "invalid dev_num %u", dev_id);
532 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
533 "Failed test for rte_cryptodev_configure:"
534 "invalid dev_num %u", dev_id);
540 test_device_configure_invalid_queue_pair_ids(void)
542 struct crypto_testsuite_params *ts_params = &testsuite_params;
543 uint16_t orig_nb_qps = ts_params->conf.nb_queue_pairs;
545 /* Stop the device in case it's started so it can be configured */
546 rte_cryptodev_stop(ts_params->valid_devs[0]);
548 /* valid - one queue pairs */
549 ts_params->conf.nb_queue_pairs = 1;
551 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
553 "Failed to configure cryptodev: dev_id %u, qp_id %u",
554 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
557 /* valid - max value queue pairs */
558 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
560 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
562 "Failed to configure cryptodev: dev_id %u, qp_id %u",
563 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
566 /* invalid - zero queue pairs */
567 ts_params->conf.nb_queue_pairs = 0;
569 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
571 "Failed test for rte_cryptodev_configure, dev_id %u,"
573 ts_params->valid_devs[0],
574 ts_params->conf.nb_queue_pairs);
577 /* invalid - max value supported by field queue pairs */
578 ts_params->conf.nb_queue_pairs = UINT16_MAX;
580 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
582 "Failed test for rte_cryptodev_configure, dev_id %u,"
584 ts_params->valid_devs[0],
585 ts_params->conf.nb_queue_pairs);
588 /* invalid - max value + 1 queue pairs */
589 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
591 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
593 "Failed test for rte_cryptodev_configure, dev_id %u,"
595 ts_params->valid_devs[0],
596 ts_params->conf.nb_queue_pairs);
598 /* revert to original testsuite value */
599 ts_params->conf.nb_queue_pairs = orig_nb_qps;
605 test_queue_pair_descriptor_setup(void)
607 struct crypto_testsuite_params *ts_params = &testsuite_params;
608 struct rte_cryptodev_info dev_info;
609 struct rte_cryptodev_qp_conf qp_conf = {
610 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
615 /* Stop the device in case it's started so it can be configured */
616 rte_cryptodev_stop(ts_params->valid_devs[0]);
619 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
621 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
623 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
624 &ts_params->conf), "Failed to configure cryptodev %u",
625 ts_params->valid_devs[0]);
629 * Test various ring sizes on this device. memzones can't be
630 * freed so are re-used if ring is released and re-created.
632 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
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 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
648 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
649 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
650 ts_params->valid_devs[0], qp_id, &qp_conf,
651 rte_cryptodev_socket_id(
652 ts_params->valid_devs[0])),
654 " rte_cryptodev_queue_pair_setup: num_inflights"
655 " %u on qp %u on cryptodev %u",
656 qp_conf.nb_descriptors, qp_id,
657 ts_params->valid_devs[0]);
660 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
662 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
663 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
664 ts_params->valid_devs[0], qp_id, &qp_conf,
665 rte_cryptodev_socket_id(
666 ts_params->valid_devs[0])),
668 "rte_cryptodev_queue_pair_setup: num_inflights"
669 " %u on qp %u on cryptodev %u",
670 qp_conf.nb_descriptors, qp_id,
671 ts_params->valid_devs[0]);
674 /* invalid number of descriptors - max supported + 2 */
675 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
677 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
678 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
679 ts_params->valid_devs[0], qp_id, &qp_conf,
680 rte_cryptodev_socket_id(
681 ts_params->valid_devs[0])),
682 "Unexpectedly passed test for "
683 "rte_cryptodev_queue_pair_setup:"
684 "num_inflights %u on qp %u on cryptodev %u",
685 qp_conf.nb_descriptors, qp_id,
686 ts_params->valid_devs[0]);
689 /* invalid number of descriptors - max value of parameter */
690 qp_conf.nb_descriptors = UINT32_MAX-1;
692 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
693 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
694 ts_params->valid_devs[0], qp_id, &qp_conf,
695 rte_cryptodev_socket_id(
696 ts_params->valid_devs[0])),
697 "Unexpectedly passed test for "
698 "rte_cryptodev_queue_pair_setup:"
699 "num_inflights %u on qp %u on cryptodev %u",
700 qp_conf.nb_descriptors, qp_id,
701 ts_params->valid_devs[0]);
704 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
706 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
707 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
708 ts_params->valid_devs[0], qp_id, &qp_conf,
709 rte_cryptodev_socket_id(
710 ts_params->valid_devs[0])),
712 " rte_cryptodev_queue_pair_setup:"
713 "num_inflights %u on qp %u on cryptodev %u",
714 qp_conf.nb_descriptors, qp_id,
715 ts_params->valid_devs[0]);
718 /* invalid number of descriptors - max supported + 1 */
719 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
721 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
722 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
723 ts_params->valid_devs[0], qp_id, &qp_conf,
724 rte_cryptodev_socket_id(
725 ts_params->valid_devs[0])),
726 "Unexpectedly passed test for "
727 "rte_cryptodev_queue_pair_setup:"
728 "num_inflights %u on qp %u on cryptodev %u",
729 qp_conf.nb_descriptors, qp_id,
730 ts_params->valid_devs[0]);
733 /* test invalid queue pair id */
734 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
736 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
738 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
739 ts_params->valid_devs[0],
741 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
742 "Failed test for rte_cryptodev_queue_pair_setup:"
743 "invalid qp %u on cryptodev %u",
744 qp_id, ts_params->valid_devs[0]);
746 qp_id = 0xffff; /*invalid*/
748 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
749 ts_params->valid_devs[0],
751 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
752 "Failed test for rte_cryptodev_queue_pair_setup:"
753 "invalid qp %u on cryptodev %u",
754 qp_id, ts_params->valid_devs[0]);
759 /* ***** Plaintext data for tests ***** */
761 const char catch_22_quote_1[] =
762 "There was only one catch and that was Catch-22, which "
763 "specified that a concern for one's safety in the face of "
764 "dangers that were real and immediate was the process of a "
765 "rational mind. Orr was crazy and could be grounded. All he "
766 "had to do was ask; and as soon as he did, he would no longer "
767 "be crazy and would have to fly more missions. Orr would be "
768 "crazy to fly more missions and sane if he didn't, but if he "
769 "was sane he had to fly them. If he flew them he was crazy "
770 "and didn't have to; but if he didn't want to he was sane and "
771 "had to. Yossarian was moved very deeply by the absolute "
772 "simplicity of this clause of Catch-22 and let out a "
773 "respectful whistle. \"That's some catch, that Catch-22\", he "
774 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
776 const char catch_22_quote[] =
777 "What a lousy earth! He wondered how many people were "
778 "destitute that same night even in his own prosperous country, "
779 "how many homes were shanties, how many husbands were drunk "
780 "and wives socked, and how many children were bullied, abused, "
781 "or abandoned. How many families hungered for food they could "
782 "not afford to buy? How many hearts were broken? How many "
783 "suicides would take place that same night, how many people "
784 "would go insane? How many cockroaches and landlords would "
785 "triumph? How many winners were losers, successes failures, "
786 "and rich men poor men? How many wise guys were stupid? How "
787 "many happy endings were unhappy endings? How many honest men "
788 "were liars, brave men cowards, loyal men traitors, how many "
789 "sainted men were corrupt, how many people in positions of "
790 "trust had sold their souls to bodyguards, how many had never "
791 "had souls? How many straight-and-narrow paths were crooked "
792 "paths? How many best families were worst families and how "
793 "many good people were bad people? When you added them all up "
794 "and then subtracted, you might be left with only the children, "
795 "and perhaps with Albert Einstein and an old violinist or "
796 "sculptor somewhere.";
798 #define QUOTE_480_BYTES (480)
799 #define QUOTE_512_BYTES (512)
800 #define QUOTE_768_BYTES (768)
801 #define QUOTE_1024_BYTES (1024)
805 /* ***** SHA1 Hash Tests ***** */
807 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
809 static uint8_t hmac_sha1_key[] = {
810 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
811 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
812 0xDE, 0xF4, 0xDE, 0xAD };
814 /* ***** SHA224 Hash Tests ***** */
816 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
819 /* ***** AES-CBC Cipher Tests ***** */
821 #define CIPHER_KEY_LENGTH_AES_CBC (16)
822 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
824 static uint8_t aes_cbc_key[] = {
825 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
826 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
828 static uint8_t aes_cbc_iv[] = {
829 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
830 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
833 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
835 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
836 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
837 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
838 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
839 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
840 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
841 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
842 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
843 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
844 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
845 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
846 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
847 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
848 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
849 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
850 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
851 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
852 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
853 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
854 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
855 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
856 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
857 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
858 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
859 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
860 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
861 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
862 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
863 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
864 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
865 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
866 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
867 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
868 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
869 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
870 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
871 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
872 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
873 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
874 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
875 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
876 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
877 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
878 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
879 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
880 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
881 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
882 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
883 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
884 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
885 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
886 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
887 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
888 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
889 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
890 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
891 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
892 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
893 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
894 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
895 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
896 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
897 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
898 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
899 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
902 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
903 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
904 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
905 0x18, 0x8c, 0x1d, 0x32
909 /* Multisession Vector context Test */
911 static uint8_t ms_aes_cbc_key0[] = {
912 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
913 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
916 static uint8_t ms_aes_cbc_iv0[] = {
917 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
918 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
921 static const uint8_t ms_aes_cbc_cipher0[] = {
922 0x3C, 0xE4, 0xEE, 0x42, 0xB6, 0x9B, 0xC3, 0x38,
923 0x5F, 0xAD, 0x54, 0xDC, 0xA8, 0x32, 0x81, 0xDC,
924 0x7A, 0x6F, 0x85, 0x58, 0x07, 0x35, 0xED, 0xEB,
925 0xAD, 0x79, 0x79, 0x96, 0xD3, 0x0E, 0xA6, 0xD9,
926 0xAA, 0x86, 0xA4, 0x8F, 0xB5, 0xD6, 0x6E, 0x6D,
927 0x0C, 0x91, 0x2F, 0xC4, 0x67, 0x98, 0x0E, 0xC4,
928 0x8D, 0x83, 0x68, 0x69, 0xC4, 0xD3, 0x94, 0x34,
929 0xC4, 0x5D, 0x60, 0x55, 0x22, 0x87, 0x8F, 0x6F,
930 0x17, 0x8E, 0x75, 0xE4, 0x02, 0xF5, 0x1B, 0x99,
931 0xC8, 0x39, 0xA9, 0xAB, 0x23, 0x91, 0x12, 0xED,
932 0x08, 0xE7, 0xD9, 0x25, 0x89, 0x24, 0x4F, 0x8D,
933 0x68, 0xF3, 0x10, 0x39, 0x0A, 0xEE, 0x45, 0x24,
934 0xDF, 0x7A, 0x9D, 0x00, 0x25, 0xE5, 0x35, 0x71,
935 0x4E, 0x40, 0x59, 0x6F, 0x0A, 0x13, 0xB3, 0x72,
936 0x1D, 0x98, 0x63, 0x94, 0x89, 0xA5, 0x39, 0x8E,
937 0xD3, 0x9C, 0x8A, 0x7F, 0x71, 0x2F, 0xC7, 0xCD,
938 0x81, 0x05, 0xDC, 0xC0, 0x8D, 0xCE, 0x6D, 0x18,
939 0x30, 0xC4, 0x72, 0x51, 0xF0, 0x27, 0xC8, 0xF6,
940 0x60, 0x5B, 0x7C, 0xB2, 0xE3, 0x49, 0x0C, 0x29,
941 0xC6, 0x9F, 0x39, 0x57, 0x80, 0x55, 0x24, 0x2C,
942 0x9B, 0x0F, 0x5A, 0xB3, 0x89, 0x55, 0x31, 0x96,
943 0x0D, 0xCD, 0xF6, 0x51, 0x03, 0x2D, 0x89, 0x26,
944 0x74, 0x44, 0xD6, 0xE8, 0xDC, 0xEA, 0x44, 0x55,
945 0x64, 0x71, 0x9C, 0x9F, 0x5D, 0xBA, 0x39, 0x46,
946 0xA8, 0x17, 0xA1, 0x9C, 0x52, 0x9D, 0xBC, 0x6B,
947 0x4A, 0x98, 0xE6, 0xEA, 0x33, 0xEC, 0x58, 0xB4,
948 0x43, 0xF0, 0x32, 0x45, 0xA4, 0xC1, 0x55, 0xB7,
949 0x5D, 0xB5, 0x59, 0xB2, 0xE3, 0x96, 0xFF, 0xA5,
950 0xAF, 0xE1, 0x86, 0x1B, 0x42, 0xE6, 0x3B, 0xA0,
951 0x90, 0x4A, 0xE8, 0x8C, 0x21, 0x7F, 0x36, 0x1E,
952 0x5B, 0x65, 0x25, 0xD1, 0xC1, 0x5A, 0xCA, 0x3D,
953 0x10, 0xED, 0x2D, 0x79, 0xD0, 0x0F, 0x58, 0x44,
954 0x69, 0x81, 0xF5, 0xD4, 0xC9, 0x0F, 0x90, 0x76,
955 0x1F, 0x54, 0xD2, 0xD5, 0x97, 0xCE, 0x2C, 0xE3,
956 0xEF, 0xF4, 0xB7, 0xC6, 0x3A, 0x87, 0x7F, 0x83,
957 0x2A, 0xAF, 0xCD, 0x90, 0x12, 0xA7, 0x7D, 0x85,
958 0x1D, 0x62, 0xD3, 0x85, 0x25, 0x05, 0xDB, 0x45,
959 0x92, 0xA3, 0xF6, 0xA2, 0xA8, 0x41, 0xE4, 0x25,
960 0x86, 0x87, 0x67, 0x24, 0xEC, 0x89, 0x23, 0x2A,
961 0x9B, 0x20, 0x4D, 0x93, 0xEE, 0xE2, 0x2E, 0xC1,
962 0x0B, 0x15, 0x33, 0xCF, 0x00, 0xD1, 0x1A, 0xDA,
963 0x93, 0xFD, 0x28, 0x21, 0x5B, 0xCF, 0xD1, 0xF3,
964 0x5A, 0x81, 0xBA, 0x82, 0x5E, 0x2F, 0x61, 0xB4,
965 0x05, 0x71, 0xB5, 0xF4, 0x39, 0x3C, 0x1F, 0x60,
966 0x00, 0x7A, 0xC4, 0xF8, 0x35, 0x20, 0x6C, 0x3A,
967 0xCC, 0x03, 0x8F, 0x7B, 0xA2, 0xB6, 0x65, 0x8A,
968 0xB6, 0x5F, 0xFD, 0x25, 0xD3, 0x5F, 0x92, 0xF9,
969 0xAE, 0x17, 0x9B, 0x5E, 0x6E, 0x9A, 0xE4, 0x55,
970 0x10, 0x25, 0x07, 0xA4, 0xAF, 0x21, 0x69, 0x13,
971 0xD8, 0xFA, 0x31, 0xED, 0xF7, 0xA7, 0xA7, 0x3B,
972 0xB8, 0x96, 0x8E, 0x10, 0x86, 0x74, 0xD8, 0xB1,
973 0x34, 0x9E, 0x9B, 0x6A, 0x26, 0xA8, 0xD4, 0xD0,
974 0xB5, 0xF6, 0xDE, 0xE7, 0xCA, 0x06, 0xDC, 0xA3,
975 0x6F, 0xEE, 0x6B, 0x1E, 0xB5, 0x30, 0x99, 0x23,
976 0xF9, 0x76, 0xF0, 0xA0, 0xCF, 0x3B, 0x94, 0x7B,
977 0x19, 0x8D, 0xA5, 0x0C, 0x18, 0xA6, 0x1D, 0x07,
978 0x89, 0xBE, 0x5B, 0x61, 0xE5, 0xF1, 0x42, 0xDB,
979 0xD4, 0x2E, 0x02, 0x1F, 0xCE, 0xEF, 0x92, 0xB1,
980 0x1B, 0x56, 0x50, 0xF2, 0x16, 0xE5, 0xE7, 0x4F,
981 0xFD, 0xBB, 0x3E, 0xD2, 0xFC, 0x3C, 0xC6, 0x0F,
982 0xF9, 0x12, 0x4E, 0xCB, 0x1E, 0x0C, 0x15, 0x84,
983 0x2A, 0x14, 0x8A, 0x02, 0xE4, 0x7E, 0x95, 0x5B,
984 0x86, 0xDB, 0x9B, 0x62, 0x5B, 0x19, 0xD2, 0x17,
985 0xFA, 0x13, 0xBB, 0x6B, 0x3F, 0x45, 0x9F, 0xBF
989 static uint8_t ms_hmac_key0[] = {
990 0xFF, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
991 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
992 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
993 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
994 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
995 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
996 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
997 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1000 static const uint8_t ms_hmac_digest0[] = {
1001 0x43, 0x52, 0xED, 0x34, 0xAB, 0x36, 0xB2, 0x51,
1002 0xFB, 0xA3, 0xA6, 0x7C, 0x38, 0xFC, 0x42, 0x8F,
1003 0x57, 0x64, 0xAB, 0x81, 0xA7, 0x89, 0xB7, 0x6C,
1004 0xA0, 0xDC, 0xB9, 0x4D, 0xC4, 0x30, 0xF9, 0xD4,
1005 0x10, 0x82, 0x55, 0xD0, 0xAB, 0x32, 0xFB, 0x56,
1006 0x0D, 0xE4, 0x68, 0x3D, 0x76, 0xD0, 0x7B, 0xE4,
1007 0xA6, 0x2C, 0x34, 0x9E, 0x8C, 0x41, 0xF8, 0x23,
1008 0x28, 0x1B, 0x3A, 0x90, 0x26, 0x34, 0x47, 0x90
1012 /* Begin session 1 */
1014 static uint8_t ms_aes_cbc_key1[] = {
1015 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1016 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1019 static uint8_t ms_aes_cbc_iv1[] = {
1020 0xf1, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1021 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1024 static const uint8_t ms_aes_cbc_cipher1[] = {
1025 0x5A, 0x7A, 0x67, 0x5D, 0xB8, 0xE1, 0xDC, 0x71,
1026 0x39, 0xA8, 0x74, 0x93, 0x9C, 0x4C, 0xFE, 0x23,
1027 0x61, 0xCD, 0xA4, 0xB3, 0xD9, 0xCE, 0x99, 0x09,
1028 0x2A, 0x23, 0xF3, 0x29, 0xBF, 0x4C, 0xB4, 0x6A,
1029 0x1B, 0x6B, 0x73, 0x4D, 0x48, 0x0C, 0xCF, 0x6C,
1030 0x5E, 0x34, 0x9E, 0x7F, 0xBC, 0x8F, 0xCC, 0x8F,
1031 0x75, 0x1D, 0x3D, 0x77, 0x10, 0x76, 0xC8, 0xB9,
1032 0x99, 0x6F, 0xD6, 0x56, 0x75, 0xA9, 0xB2, 0x66,
1033 0xC2, 0x24, 0x2B, 0x9C, 0xFE, 0x40, 0x8E, 0x43,
1034 0x20, 0x97, 0x1B, 0xFA, 0xD0, 0xCF, 0x04, 0xAB,
1035 0xBB, 0xF6, 0x5D, 0xF5, 0xA0, 0x19, 0x7C, 0x23,
1036 0x5D, 0x80, 0x8C, 0x49, 0xF6, 0x76, 0x88, 0x29,
1037 0x27, 0x4C, 0x59, 0x2B, 0x43, 0xA6, 0xB2, 0x26,
1038 0x27, 0x78, 0xBE, 0x1B, 0xE1, 0x4F, 0x5A, 0x1F,
1039 0xFC, 0x68, 0x08, 0xE7, 0xC4, 0xD1, 0x34, 0x68,
1040 0xB7, 0x13, 0x14, 0x41, 0x62, 0x6B, 0x1F, 0x77,
1041 0x0C, 0x68, 0x1D, 0x0D, 0xED, 0x89, 0xAA, 0xD8,
1042 0x97, 0x02, 0xBA, 0x5E, 0xD4, 0x84, 0x25, 0x97,
1043 0x03, 0xA5, 0xA6, 0x13, 0x66, 0x02, 0xF4, 0xC3,
1044 0xF3, 0xD3, 0xCC, 0x95, 0xC3, 0x87, 0x46, 0x90,
1045 0x1F, 0x6E, 0x14, 0xA8, 0x00, 0xF2, 0x6F, 0xD5,
1046 0xA1, 0xAD, 0xD5, 0x40, 0xA2, 0x0F, 0x32, 0x7E,
1047 0x99, 0xA3, 0xF5, 0x53, 0xC3, 0x26, 0xA1, 0x45,
1048 0x01, 0x88, 0x57, 0x84, 0x3E, 0x7B, 0x4E, 0x0B,
1049 0x3C, 0xB5, 0x3E, 0x9E, 0xE9, 0x78, 0x77, 0xC5,
1050 0xC0, 0x89, 0xA8, 0xF8, 0xF1, 0xA5, 0x2D, 0x5D,
1051 0xF9, 0xC6, 0xFB, 0xCB, 0x05, 0x23, 0xBD, 0x6E,
1052 0x5E, 0x14, 0xC6, 0x57, 0x73, 0xCF, 0x98, 0xBD,
1053 0x10, 0x8B, 0x18, 0xA6, 0x01, 0x5B, 0x13, 0xAE,
1054 0x8E, 0xDE, 0x1F, 0xB5, 0xB7, 0x40, 0x6C, 0xC1,
1055 0x1E, 0xA1, 0x19, 0x20, 0x9E, 0x95, 0xE0, 0x2F,
1056 0x1C, 0xF5, 0xD9, 0xD0, 0x2B, 0x1E, 0x82, 0x25,
1057 0x62, 0xB4, 0xEB, 0xA1, 0x1F, 0xCE, 0x44, 0xA1,
1058 0xCB, 0x92, 0x01, 0x6B, 0xE4, 0x26, 0x23, 0xE3,
1059 0xC5, 0x67, 0x35, 0x55, 0xDA, 0xE5, 0x27, 0xEE,
1060 0x8D, 0x12, 0x84, 0xB7, 0xBA, 0xA7, 0x1C, 0xD6,
1061 0x32, 0x3F, 0x67, 0xED, 0xFB, 0x5B, 0x8B, 0x52,
1062 0x46, 0x8C, 0xF9, 0x69, 0xCD, 0xAE, 0x79, 0xAA,
1063 0x37, 0x78, 0x49, 0xEB, 0xC6, 0x8E, 0x76, 0x63,
1064 0x84, 0xFF, 0x9D, 0x22, 0x99, 0x51, 0xB7, 0x5E,
1065 0x83, 0x4C, 0x8B, 0xDF, 0x5A, 0x07, 0xCC, 0xBA,
1066 0x42, 0xA5, 0x98, 0xB6, 0x47, 0x0E, 0x66, 0xEB,
1067 0x23, 0x0E, 0xBA, 0x44, 0xA8, 0xAA, 0x20, 0x71,
1068 0x79, 0x9C, 0x77, 0x5F, 0xF5, 0xFE, 0xEC, 0xEF,
1069 0xC6, 0x64, 0x3D, 0x84, 0xD0, 0x2B, 0xA7, 0x0A,
1070 0xC3, 0x72, 0x5B, 0x9C, 0xFA, 0xA8, 0x87, 0x95,
1071 0x94, 0x11, 0x38, 0xA7, 0x1E, 0x58, 0xE3, 0x73,
1072 0xC6, 0xC9, 0xD1, 0x7B, 0x92, 0xDB, 0x0F, 0x49,
1073 0x74, 0xC2, 0xA2, 0x0E, 0x35, 0x57, 0xAC, 0xDB,
1074 0x9A, 0x1C, 0xCF, 0x5A, 0x32, 0x3E, 0x26, 0x9B,
1075 0xEC, 0xB3, 0xEF, 0x9C, 0xFE, 0xBE, 0x52, 0xAC,
1076 0xB1, 0x29, 0xDD, 0xFD, 0x07, 0xE2, 0xEE, 0xED,
1077 0xE4, 0x46, 0x37, 0xFE, 0xD1, 0xDC, 0xCD, 0x02,
1078 0xF9, 0x31, 0xB0, 0xFB, 0x36, 0xB7, 0x34, 0xA4,
1079 0x76, 0xE8, 0x57, 0xBF, 0x99, 0x92, 0xC7, 0xAF,
1080 0x98, 0x10, 0xE2, 0x70, 0xCA, 0xC9, 0x2B, 0x82,
1081 0x06, 0x96, 0x88, 0x0D, 0xB3, 0xAC, 0x9E, 0x6D,
1082 0x43, 0xBC, 0x5B, 0x31, 0xCF, 0x65, 0x8D, 0xA6,
1083 0xC7, 0xFE, 0x73, 0xE1, 0x54, 0xF7, 0x10, 0xF9,
1084 0x86, 0xF7, 0xDF, 0xA1, 0xA1, 0xD8, 0xAE, 0x35,
1085 0xB3, 0x90, 0xDC, 0x6F, 0x43, 0x7A, 0x8B, 0xE0,
1086 0xFE, 0x8F, 0x33, 0x4D, 0x29, 0x6C, 0x45, 0x53,
1087 0x73, 0xDD, 0x21, 0x0B, 0x85, 0x30, 0xB5, 0xA5,
1088 0xF3, 0x5D, 0xEC, 0x79, 0x61, 0x9D, 0x9E, 0xB3
1092 static uint8_t ms_hmac_key1[] = {
1093 0xFE, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1094 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1095 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1096 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1097 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1098 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1099 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1100 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1103 static const uint8_t ms_hmac_digest1[] = {
1104 0xCE, 0x6E, 0x5F, 0x77, 0x96, 0x9A, 0xB1, 0x69,
1105 0x2D, 0x5E, 0xF3, 0x2F, 0x32, 0x10, 0xCB, 0x50,
1106 0x0E, 0x09, 0x56, 0x25, 0x07, 0x34, 0xC9, 0x20,
1107 0xEC, 0x13, 0x43, 0x23, 0x5C, 0x08, 0x8B, 0xCD,
1108 0xDC, 0x86, 0x8C, 0xEE, 0x0A, 0x95, 0x2E, 0xB9,
1109 0x8C, 0x7B, 0x02, 0x7A, 0xD4, 0xE1, 0x49, 0xB4,
1110 0x45, 0xB5, 0x52, 0x37, 0xC6, 0xFF, 0xFE, 0xAA,
1111 0x0A, 0x87, 0xB8, 0x51, 0xF9, 0x2A, 0x01, 0x8F
1114 /* Begin Session 2 */
1115 static uint8_t ms_aes_cbc_key2[] = {
1116 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1117 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1120 static uint8_t ms_aes_cbc_iv2[] = {
1121 0xff, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
1122 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
1125 static const uint8_t ms_aes_cbc_cipher2[] = {
1126 0xBB, 0x3C, 0x68, 0x25, 0xFD, 0xB6, 0xA2, 0x91,
1127 0x20, 0x56, 0xF6, 0x30, 0x35, 0xFC, 0x9E, 0x97,
1128 0xF2, 0x90, 0xFC, 0x7E, 0x3E, 0x0A, 0x75, 0xC8,
1129 0x4C, 0xF2, 0x2D, 0xAC, 0xD3, 0x93, 0xF0, 0xC5,
1130 0x14, 0x88, 0x8A, 0x23, 0xC2, 0x59, 0x9A, 0x98,
1131 0x4B, 0xD5, 0x2C, 0xDA, 0x43, 0xA9, 0x34, 0x69,
1132 0x7C, 0x6D, 0xDB, 0xDC, 0xCB, 0xC0, 0xA0, 0x09,
1133 0xA7, 0x86, 0x16, 0x4B, 0xBF, 0xA8, 0xB6, 0xCF,
1134 0x7F, 0x74, 0x1F, 0x22, 0xF0, 0xF6, 0xBB, 0x44,
1135 0x8B, 0x4C, 0x9E, 0x23, 0xF8, 0x9F, 0xFC, 0x5B,
1136 0x9E, 0x9C, 0x2A, 0x79, 0x30, 0x8F, 0xBF, 0xA9,
1137 0x68, 0xA1, 0x20, 0x71, 0x7C, 0x77, 0x22, 0x34,
1138 0x07, 0xCD, 0xC6, 0xF6, 0x50, 0x0A, 0x08, 0x99,
1139 0x17, 0x98, 0xE3, 0x93, 0x8A, 0xB0, 0xEE, 0xDF,
1140 0xC2, 0xBA, 0x3B, 0x44, 0x73, 0xDF, 0xDD, 0xDC,
1141 0x14, 0x4D, 0x3B, 0xBB, 0x5E, 0x58, 0xC1, 0x26,
1142 0xA7, 0xAE, 0x47, 0xF3, 0x24, 0x6D, 0x4F, 0xD3,
1143 0x6E, 0x3E, 0x33, 0xE6, 0x7F, 0xCA, 0x50, 0xAF,
1144 0x5D, 0x3D, 0xA0, 0xDD, 0xC9, 0xF3, 0x30, 0xD3,
1145 0x6E, 0x8B, 0x2E, 0x12, 0x24, 0x34, 0xF0, 0xD3,
1146 0xC7, 0x8D, 0x23, 0x29, 0xAA, 0x05, 0xE1, 0xFA,
1147 0x2E, 0xF6, 0x8D, 0x37, 0x86, 0xC0, 0x6D, 0x13,
1148 0x2D, 0x98, 0xF3, 0x52, 0x39, 0x22, 0xCE, 0x38,
1149 0xC2, 0x1A, 0x72, 0xED, 0xFB, 0xCC, 0xE4, 0x71,
1150 0x5A, 0x0C, 0x0D, 0x09, 0xF8, 0xE8, 0x1B, 0xBC,
1151 0x53, 0xC8, 0xD8, 0x8F, 0xE5, 0x98, 0x5A, 0xB1,
1152 0x06, 0xA6, 0x5B, 0xE6, 0xA2, 0x88, 0x21, 0x9E,
1153 0x36, 0xC0, 0x34, 0xF9, 0xFB, 0x3B, 0x0A, 0x22,
1154 0x00, 0x00, 0x39, 0x48, 0x8D, 0x23, 0x74, 0x62,
1155 0x72, 0x91, 0xE6, 0x36, 0xAA, 0x77, 0x9C, 0x72,
1156 0x9D, 0xA8, 0xC3, 0xA9, 0xD5, 0x44, 0x72, 0xA6,
1157 0xB9, 0x28, 0x8F, 0x64, 0x4C, 0x8A, 0x64, 0xE6,
1158 0x4E, 0xFA, 0xEF, 0x87, 0xDE, 0x7B, 0x22, 0x44,
1159 0xB0, 0xDF, 0x2E, 0x5F, 0x0B, 0xA5, 0xF2, 0x24,
1160 0x07, 0x5C, 0x2D, 0x39, 0xB7, 0x3D, 0x8A, 0xE5,
1161 0x0E, 0x9D, 0x4E, 0x50, 0xED, 0x03, 0x99, 0x8E,
1162 0xF0, 0x06, 0x55, 0x4E, 0xA2, 0x24, 0xE7, 0x17,
1163 0x46, 0xDF, 0x6C, 0xCD, 0xC6, 0x44, 0xE8, 0xF9,
1164 0xB9, 0x1B, 0x36, 0xF6, 0x7F, 0x10, 0xA4, 0x7D,
1165 0x90, 0xBD, 0xE4, 0xAA, 0xD6, 0x9E, 0x18, 0x9D,
1166 0x22, 0x35, 0xD6, 0x55, 0x54, 0xAA, 0xF7, 0x22,
1167 0xA3, 0x3E, 0xEF, 0xC8, 0xA2, 0x34, 0x8D, 0xA9,
1168 0x37, 0x63, 0xA6, 0xC3, 0x57, 0xCB, 0x0C, 0x49,
1169 0x7D, 0x02, 0xBE, 0xAA, 0x13, 0x75, 0xB7, 0x4E,
1170 0x52, 0x62, 0xA5, 0xC2, 0x33, 0xC7, 0x6C, 0x1B,
1171 0xF6, 0x34, 0xF6, 0x09, 0xA5, 0x0C, 0xC7, 0xA2,
1172 0x61, 0x48, 0x62, 0x7D, 0x17, 0x15, 0xE3, 0x95,
1173 0xC8, 0x63, 0xD2, 0xA4, 0x43, 0xA9, 0x49, 0x07,
1174 0xB2, 0x3B, 0x2B, 0x62, 0x7D, 0xCB, 0x51, 0xB3,
1175 0x25, 0x33, 0x47, 0x0E, 0x14, 0x67, 0xDC, 0x6A,
1176 0x9B, 0x51, 0xAC, 0x9D, 0x8F, 0xA2, 0x2B, 0x57,
1177 0x8C, 0x5C, 0x5F, 0x76, 0x23, 0x92, 0x0F, 0x84,
1178 0x46, 0x0E, 0x40, 0x85, 0x38, 0x60, 0xFA, 0x61,
1179 0x20, 0xC5, 0xE3, 0xF1, 0x70, 0xAC, 0x1B, 0xBF,
1180 0xC4, 0x2B, 0xC5, 0x67, 0xD1, 0x43, 0xC5, 0x17,
1181 0x74, 0x71, 0x69, 0x6F, 0x82, 0x89, 0x19, 0x8A,
1182 0x70, 0x43, 0x92, 0x01, 0xC4, 0x63, 0x7E, 0xB1,
1183 0x59, 0x4E, 0xCD, 0xEA, 0x93, 0xA4, 0x52, 0x53,
1184 0x9B, 0x61, 0x5B, 0xD2, 0x3E, 0x19, 0x39, 0xB7,
1185 0x32, 0xEA, 0x8E, 0xF8, 0x1D, 0x76, 0x5C, 0xB2,
1186 0x73, 0x2D, 0x91, 0xC0, 0x18, 0xED, 0x25, 0x2A,
1187 0x53, 0x64, 0xF0, 0x92, 0x31, 0x55, 0x21, 0xA8,
1188 0x24, 0xA9, 0xD1, 0x02, 0xF6, 0x6C, 0x2B, 0x70,
1189 0xA9, 0x59, 0xC1, 0xD6, 0xC3, 0x57, 0x5B, 0x92
1192 static uint8_t ms_hmac_key2[] = {
1193 0xFC, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
1194 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1195 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1196 0x9A, 0xAF, 0x88, 0x1B, 0xB6, 0x8F, 0xF8, 0x60,
1197 0xA2, 0x5A, 0x7F, 0x3F, 0xF4, 0x72, 0x70, 0xF1,
1198 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1199 0x47, 0x3A, 0x75, 0x61, 0x5C, 0xA2, 0x10, 0x76,
1200 0x9A, 0xAF, 0x77, 0x5B, 0xB6, 0x7F, 0xF7, 0x60
1203 static const uint8_t ms_hmac_digest2[] = {
1204 0xA5, 0x0F, 0x9C, 0xFB, 0x08, 0x62, 0x59, 0xFF,
1205 0x80, 0x2F, 0xEB, 0x4B, 0xE1, 0x46, 0x21, 0xD6,
1206 0x02, 0x98, 0xF2, 0x8E, 0xF4, 0xEC, 0xD4, 0x77,
1207 0x86, 0x4C, 0x31, 0x28, 0xC8, 0x25, 0x80, 0x27,
1208 0x3A, 0x72, 0x5D, 0x6A, 0x56, 0x8A, 0xD3, 0x82,
1209 0xB0, 0xEC, 0x31, 0x6D, 0x8B, 0x6B, 0xB4, 0x24,
1210 0xE7, 0x62, 0xC1, 0x52, 0xBC, 0x14, 0x1B, 0x8E,
1211 0xEC, 0x9A, 0xF1, 0x47, 0x80, 0xD2, 0xB0, 0x59
1218 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
1220 struct crypto_testsuite_params *ts_params = &testsuite_params;
1221 struct crypto_unittest_params *ut_params = &unittest_params;
1223 /* Generate test mbuf data and space for digest */
1224 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1225 catch_22_quote, QUOTE_512_BYTES, 0);
1227 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1228 DIGEST_BYTE_LENGTH_SHA1);
1229 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1231 /* Setup Cipher Parameters */
1232 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1233 ut_params->cipher_xform.next = &ut_params->auth_xform;
1235 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1236 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1237 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1238 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1240 /* Setup HMAC Parameters */
1241 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1243 ut_params->auth_xform.next = NULL;
1245 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1246 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1247 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1248 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1249 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1251 /* Create crypto session*/
1252 ut_params->sess = rte_cryptodev_sym_session_create(
1253 ts_params->valid_devs[0],
1254 &ut_params->cipher_xform);
1255 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1257 /* Generate crypto op data structure */
1258 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1259 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1260 TEST_ASSERT_NOT_NULL(ut_params->op,
1261 "Failed to allocate symmetric crypto operation struct");
1263 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1265 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1267 /* set crypto operation source mbuf */
1268 sym_op->m_src = ut_params->ibuf;
1270 /* Set crypto operation authentication parameters */
1271 sym_op->auth.digest.data = ut_params->digest;
1272 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1273 ut_params->ibuf, QUOTE_512_BYTES);
1274 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1276 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1277 sym_op->auth.data.length = QUOTE_512_BYTES;
1279 /* Set crypto operation cipher parameters */
1280 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1281 CIPHER_IV_LENGTH_AES_CBC);
1282 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1283 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1285 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1286 CIPHER_IV_LENGTH_AES_CBC);
1288 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1289 sym_op->cipher.data.length = QUOTE_512_BYTES;
1291 /* Process crypto operation */
1292 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1293 ut_params->op), "failed to process sym crypto op");
1295 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1296 "crypto op processing failed");
1299 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1300 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
1302 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1303 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1305 "ciphertext data not as expected");
1307 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1309 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1310 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1311 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1312 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1313 DIGEST_BYTE_LENGTH_SHA1,
1314 "Generated digest data not as expected");
1316 return TEST_SUCCESS;
1319 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1321 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1323 static uint8_t hmac_sha512_key[] = {
1324 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1325 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1326 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1327 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1328 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1329 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1330 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1331 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1333 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1334 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1335 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1336 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1337 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1338 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1339 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1340 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1341 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1346 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1347 struct crypto_unittest_params *ut_params,
1348 uint8_t *cipher_key,
1352 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1353 struct crypto_unittest_params *ut_params,
1354 struct crypto_testsuite_params *ts_params,
1355 const uint8_t *cipher,
1356 const uint8_t *digest,
1361 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1362 struct crypto_unittest_params *ut_params,
1363 uint8_t *cipher_key,
1367 /* Setup Cipher Parameters */
1368 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1369 ut_params->cipher_xform.next = NULL;
1371 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1372 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1373 ut_params->cipher_xform.cipher.key.data = cipher_key;
1374 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1376 /* Setup HMAC Parameters */
1377 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1378 ut_params->auth_xform.next = &ut_params->cipher_xform;
1380 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1381 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1382 ut_params->auth_xform.auth.key.data = hmac_key;
1383 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1384 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1386 return TEST_SUCCESS;
1391 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1392 struct crypto_unittest_params *ut_params,
1393 struct crypto_testsuite_params *ts_params,
1394 const uint8_t *cipher,
1395 const uint8_t *digest,
1398 /* Generate test mbuf data and digest */
1399 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1402 QUOTE_512_BYTES, 0);
1404 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1405 DIGEST_BYTE_LENGTH_SHA512);
1406 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1408 rte_memcpy(ut_params->digest,
1410 DIGEST_BYTE_LENGTH_SHA512);
1412 /* Generate Crypto op data structure */
1413 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1414 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1415 TEST_ASSERT_NOT_NULL(ut_params->op,
1416 "Failed to allocate symmetric crypto operation struct");
1418 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1420 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1422 /* set crypto operation source mbuf */
1423 sym_op->m_src = ut_params->ibuf;
1425 sym_op->auth.digest.data = ut_params->digest;
1426 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1427 ut_params->ibuf, QUOTE_512_BYTES);
1428 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1430 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1431 sym_op->auth.data.length = QUOTE_512_BYTES;
1433 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1434 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1435 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1436 ut_params->ibuf, 0);
1437 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1439 rte_memcpy(sym_op->cipher.iv.data, iv,
1440 CIPHER_IV_LENGTH_AES_CBC);
1442 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1443 sym_op->cipher.data.length = QUOTE_512_BYTES;
1445 /* Process crypto operation */
1446 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1447 ut_params->op), "failed to process sym crypto op");
1449 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1450 "crypto op processing failed");
1452 ut_params->obuf = ut_params->op->sym->m_src;
1455 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1456 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1457 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1459 "Plaintext data not as expected");
1462 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1463 "Digest verification failed");
1465 return TEST_SUCCESS;
1469 test_AES_cipheronly_mb_all(void)
1471 struct crypto_testsuite_params *ts_params = &testsuite_params;
1474 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1475 ts_params->op_mpool, ts_params->valid_devs[0],
1476 RTE_CRYPTODEV_AESNI_MB_PMD,
1477 BLKCIPHER_AES_CIPHERONLY_TYPE);
1479 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1481 return TEST_SUCCESS;
1485 test_authonly_mb_all(void)
1487 struct crypto_testsuite_params *ts_params = &testsuite_params;
1490 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1491 ts_params->op_mpool, ts_params->valid_devs[0],
1492 RTE_CRYPTODEV_AESNI_MB_PMD,
1493 BLKCIPHER_AUTHONLY_TYPE);
1495 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1497 return TEST_SUCCESS;
1501 test_AES_chain_mb_all(void)
1503 struct crypto_testsuite_params *ts_params = &testsuite_params;
1506 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1507 ts_params->op_mpool, ts_params->valid_devs[0],
1508 RTE_CRYPTODEV_AESNI_MB_PMD,
1509 BLKCIPHER_AES_CHAIN_TYPE);
1511 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1513 return TEST_SUCCESS;
1517 test_AES_chain_openssl_all(void)
1519 struct crypto_testsuite_params *ts_params = &testsuite_params;
1522 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1523 ts_params->op_mpool, ts_params->valid_devs[0],
1524 RTE_CRYPTODEV_OPENSSL_PMD,
1525 BLKCIPHER_AES_CHAIN_TYPE);
1527 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1529 return TEST_SUCCESS;
1533 test_AES_cipheronly_openssl_all(void)
1535 struct crypto_testsuite_params *ts_params = &testsuite_params;
1538 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1539 ts_params->op_mpool, ts_params->valid_devs[0],
1540 RTE_CRYPTODEV_OPENSSL_PMD,
1541 BLKCIPHER_AES_CIPHERONLY_TYPE);
1543 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1545 return TEST_SUCCESS;
1549 test_AES_chain_qat_all(void)
1551 struct crypto_testsuite_params *ts_params = &testsuite_params;
1554 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1555 ts_params->op_mpool, ts_params->valid_devs[0],
1556 RTE_CRYPTODEV_QAT_SYM_PMD,
1557 BLKCIPHER_AES_CHAIN_TYPE);
1559 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1561 return TEST_SUCCESS;
1565 test_AES_cipheronly_qat_all(void)
1567 struct crypto_testsuite_params *ts_params = &testsuite_params;
1570 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1571 ts_params->op_mpool, ts_params->valid_devs[0],
1572 RTE_CRYPTODEV_QAT_SYM_PMD,
1573 BLKCIPHER_AES_CIPHERONLY_TYPE);
1575 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1577 return TEST_SUCCESS;
1581 test_authonly_openssl_all(void)
1583 struct crypto_testsuite_params *ts_params = &testsuite_params;
1586 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
1587 ts_params->op_mpool, ts_params->valid_devs[0],
1588 RTE_CRYPTODEV_OPENSSL_PMD,
1589 BLKCIPHER_AUTHONLY_TYPE);
1591 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1593 return TEST_SUCCESS;
1596 /* ***** SNOW 3G Tests ***** */
1598 create_wireless_algo_hash_session(uint8_t dev_id,
1599 const uint8_t *key, const uint8_t key_len,
1600 const uint8_t aad_len, const uint8_t auth_len,
1601 enum rte_crypto_auth_operation op,
1602 enum rte_crypto_auth_algorithm algo)
1604 uint8_t hash_key[key_len];
1606 struct crypto_unittest_params *ut_params = &unittest_params;
1608 memcpy(hash_key, key, key_len);
1610 TEST_HEXDUMP(stdout, "key:", key, key_len);
1612 /* Setup Authentication Parameters */
1613 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1614 ut_params->auth_xform.next = NULL;
1616 ut_params->auth_xform.auth.op = op;
1617 ut_params->auth_xform.auth.algo = algo;
1618 ut_params->auth_xform.auth.key.length = key_len;
1619 ut_params->auth_xform.auth.key.data = hash_key;
1620 ut_params->auth_xform.auth.digest_length = auth_len;
1621 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1622 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1623 &ut_params->auth_xform);
1624 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1629 create_wireless_algo_cipher_session(uint8_t dev_id,
1630 enum rte_crypto_cipher_operation op,
1631 enum rte_crypto_cipher_algorithm algo,
1632 const uint8_t *key, const uint8_t key_len)
1634 uint8_t cipher_key[key_len];
1636 struct crypto_unittest_params *ut_params = &unittest_params;
1638 memcpy(cipher_key, key, key_len);
1640 /* Setup Cipher Parameters */
1641 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1642 ut_params->cipher_xform.next = NULL;
1644 ut_params->cipher_xform.cipher.algo = algo;
1645 ut_params->cipher_xform.cipher.op = op;
1646 ut_params->cipher_xform.cipher.key.data = cipher_key;
1647 ut_params->cipher_xform.cipher.key.length = key_len;
1649 TEST_HEXDUMP(stdout, "key:", key, key_len);
1651 /* Create Crypto session */
1652 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1655 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1660 create_wireless_algo_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1661 const unsigned cipher_len,
1662 const unsigned cipher_offset,
1663 enum rte_crypto_cipher_algorithm algo)
1665 struct crypto_testsuite_params *ts_params = &testsuite_params;
1666 struct crypto_unittest_params *ut_params = &unittest_params;
1667 unsigned iv_pad_len = 0;
1669 /* Generate Crypto op data structure */
1670 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1671 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1672 TEST_ASSERT_NOT_NULL(ut_params->op,
1673 "Failed to allocate pktmbuf offload");
1675 /* Set crypto operation data parameters */
1676 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1678 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1680 /* set crypto operation source mbuf */
1681 sym_op->m_src = ut_params->ibuf;
1684 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1685 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1687 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1689 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1692 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1694 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1695 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1696 sym_op->cipher.iv.length = iv_pad_len;
1698 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1699 sym_op->cipher.data.length = cipher_len;
1700 sym_op->cipher.data.offset = cipher_offset;
1705 create_wireless_algo_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1706 const unsigned cipher_len,
1707 const unsigned cipher_offset,
1708 enum rte_crypto_cipher_algorithm algo)
1710 struct crypto_testsuite_params *ts_params = &testsuite_params;
1711 struct crypto_unittest_params *ut_params = &unittest_params;
1712 unsigned iv_pad_len = 0;
1714 /* Generate Crypto op data structure */
1715 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1716 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1717 TEST_ASSERT_NOT_NULL(ut_params->op,
1718 "Failed to allocate pktmbuf offload");
1720 /* Set crypto operation data parameters */
1721 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1723 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1725 /* set crypto operation source mbuf */
1726 sym_op->m_src = ut_params->ibuf;
1727 sym_op->m_dst = ut_params->obuf;
1730 if (algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
1731 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
1733 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1734 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1737 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1739 /* For OOP operation both buffers must have the same size */
1740 if (ut_params->obuf)
1741 rte_pktmbuf_prepend(ut_params->obuf, iv_pad_len);
1743 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1744 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1745 sym_op->cipher.iv.length = iv_pad_len;
1747 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1748 sym_op->cipher.data.length = cipher_len;
1749 sym_op->cipher.data.offset = cipher_offset;
1754 create_wireless_algo_cipher_auth_session(uint8_t dev_id,
1755 enum rte_crypto_cipher_operation cipher_op,
1756 enum rte_crypto_auth_operation auth_op,
1757 enum rte_crypto_auth_algorithm auth_algo,
1758 enum rte_crypto_cipher_algorithm cipher_algo,
1759 const uint8_t *key, const uint8_t key_len,
1760 const uint8_t aad_len, const uint8_t auth_len)
1763 uint8_t cipher_auth_key[key_len];
1765 struct crypto_unittest_params *ut_params = &unittest_params;
1767 memcpy(cipher_auth_key, key, key_len);
1769 /* Setup Authentication Parameters */
1770 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1771 ut_params->auth_xform.next = NULL;
1773 ut_params->auth_xform.auth.op = auth_op;
1774 ut_params->auth_xform.auth.algo = auth_algo;
1775 ut_params->auth_xform.auth.key.length = key_len;
1776 /* Hash key = cipher key */
1777 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1778 ut_params->auth_xform.auth.digest_length = auth_len;
1779 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1781 /* Setup Cipher Parameters */
1782 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1783 ut_params->cipher_xform.next = &ut_params->auth_xform;
1785 ut_params->cipher_xform.cipher.algo = cipher_algo;
1786 ut_params->cipher_xform.cipher.op = cipher_op;
1787 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1788 ut_params->cipher_xform.cipher.key.length = key_len;
1790 TEST_HEXDUMP(stdout, "key:", key, key_len);
1792 /* Create Crypto session*/
1793 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1794 &ut_params->cipher_xform);
1796 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1801 create_wireless_algo_auth_cipher_session(uint8_t dev_id,
1802 enum rte_crypto_cipher_operation cipher_op,
1803 enum rte_crypto_auth_operation auth_op,
1804 enum rte_crypto_auth_algorithm auth_algo,
1805 enum rte_crypto_cipher_algorithm cipher_algo,
1806 const uint8_t *key, const uint8_t key_len,
1807 const uint8_t aad_len, const uint8_t auth_len)
1809 uint8_t auth_cipher_key[key_len];
1811 struct crypto_unittest_params *ut_params = &unittest_params;
1813 memcpy(auth_cipher_key, key, key_len);
1815 /* Setup Authentication Parameters */
1816 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1817 ut_params->auth_xform.auth.op = auth_op;
1818 ut_params->auth_xform.next = &ut_params->cipher_xform;
1819 ut_params->auth_xform.auth.algo = auth_algo;
1820 ut_params->auth_xform.auth.key.length = key_len;
1821 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1822 ut_params->auth_xform.auth.digest_length = auth_len;
1823 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1825 /* Setup Cipher Parameters */
1826 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1827 ut_params->cipher_xform.next = NULL;
1828 ut_params->cipher_xform.cipher.algo = cipher_algo;
1829 ut_params->cipher_xform.cipher.op = cipher_op;
1830 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1831 ut_params->cipher_xform.cipher.key.length = key_len;
1833 TEST_HEXDUMP(stdout, "key:", key, key_len);
1835 /* Create Crypto session*/
1836 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1837 &ut_params->auth_xform);
1839 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1845 create_wireless_algo_hash_operation(const uint8_t *auth_tag,
1846 const unsigned auth_tag_len,
1847 const uint8_t *aad, const unsigned aad_len,
1848 unsigned data_pad_len,
1849 enum rte_crypto_auth_operation op,
1850 enum rte_crypto_auth_algorithm algo,
1851 const unsigned auth_len, const unsigned auth_offset)
1853 struct crypto_testsuite_params *ts_params = &testsuite_params;
1855 struct crypto_unittest_params *ut_params = &unittest_params;
1857 unsigned aad_buffer_len;
1859 /* Generate Crypto op data structure */
1860 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1861 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1862 TEST_ASSERT_NOT_NULL(ut_params->op,
1863 "Failed to allocate pktmbuf offload");
1865 /* Set crypto operation data parameters */
1866 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1868 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1870 /* set crypto operation source mbuf */
1871 sym_op->m_src = ut_params->ibuf;
1875 * Always allocate the aad up to the block size.
1876 * The cryptodev API calls out -
1877 * - the array must be big enough to hold the AAD, plus any
1878 * space to round this up to the nearest multiple of the
1879 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1881 if (algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1882 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1884 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1885 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1886 ut_params->ibuf, aad_buffer_len);
1887 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1888 "no room to prepend aad");
1889 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1891 sym_op->auth.aad.length = aad_len;
1893 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1894 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1896 TEST_HEXDUMP(stdout, "aad:",
1897 sym_op->auth.aad.data, aad_len);
1900 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1901 ut_params->ibuf, auth_tag_len);
1903 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1904 "no room to append auth tag");
1905 ut_params->digest = sym_op->auth.digest.data;
1906 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1907 ut_params->ibuf, data_pad_len + aad_len);
1908 sym_op->auth.digest.length = auth_tag_len;
1909 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1910 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1912 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1914 TEST_HEXDUMP(stdout, "digest:",
1915 sym_op->auth.digest.data,
1916 sym_op->auth.digest.length);
1918 sym_op->auth.data.length = auth_len;
1919 sym_op->auth.data.offset = auth_offset;
1925 create_wireless_algo_cipher_hash_operation(const uint8_t *auth_tag,
1926 const unsigned auth_tag_len,
1927 const uint8_t *aad, const uint8_t aad_len,
1928 unsigned data_pad_len,
1929 enum rte_crypto_auth_operation op,
1930 enum rte_crypto_auth_algorithm auth_algo,
1931 enum rte_crypto_cipher_algorithm cipher_algo,
1932 const uint8_t *iv, const uint8_t iv_len,
1933 const unsigned cipher_len, const unsigned cipher_offset,
1934 const unsigned auth_len, const unsigned auth_offset)
1936 struct crypto_testsuite_params *ts_params = &testsuite_params;
1937 struct crypto_unittest_params *ut_params = &unittest_params;
1939 unsigned iv_pad_len = 0;
1940 unsigned aad_buffer_len;
1942 /* Generate Crypto op data structure */
1943 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1944 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1945 TEST_ASSERT_NOT_NULL(ut_params->op,
1946 "Failed to allocate pktmbuf offload");
1947 /* Set crypto operation data parameters */
1948 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1950 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1952 /* set crypto operation source mbuf */
1953 sym_op->m_src = ut_params->ibuf;
1956 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1957 ut_params->ibuf, auth_tag_len);
1959 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1960 "no room to append auth tag");
1961 ut_params->digest = sym_op->auth.digest.data;
1962 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1963 ut_params->ibuf, data_pad_len);
1964 sym_op->auth.digest.length = auth_tag_len;
1965 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1966 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1968 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1970 TEST_HEXDUMP(stdout, "digest:",
1971 sym_op->auth.digest.data,
1972 sym_op->auth.digest.length);
1976 * Always allocate the aad up to the block size.
1977 * The cryptodev API calls out -
1978 * - the array must be big enough to hold the AAD, plus any
1979 * space to round this up to the nearest multiple of the
1980 * block size (8 bytes for KASUMI and 16 bytes for SNOW 3G).
1982 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
1983 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
1985 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1986 sym_op->auth.aad.data =
1987 (uint8_t *)rte_pktmbuf_prepend(
1988 ut_params->ibuf, aad_buffer_len);
1989 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1990 "no room to prepend aad");
1991 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1993 sym_op->auth.aad.length = aad_len;
1994 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1995 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1996 TEST_HEXDUMP(stdout, "aad:", sym_op->auth.aad.data, aad_len);
1999 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2000 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2002 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2003 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2004 ut_params->ibuf, iv_pad_len);
2006 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2007 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2008 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2009 sym_op->cipher.iv.length = iv_pad_len;
2010 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2011 sym_op->cipher.data.length = cipher_len;
2012 sym_op->cipher.data.offset = cipher_offset + auth_offset;
2013 sym_op->auth.data.length = auth_len;
2014 sym_op->auth.data.offset = auth_offset + cipher_offset;
2020 create_wireless_algo_auth_cipher_operation(const unsigned auth_tag_len,
2021 const uint8_t *iv, const uint8_t iv_len,
2022 const uint8_t *aad, const uint8_t aad_len,
2023 unsigned data_pad_len,
2024 const unsigned cipher_len, const unsigned cipher_offset,
2025 const unsigned auth_len, const unsigned auth_offset,
2026 enum rte_crypto_auth_algorithm auth_algo,
2027 enum rte_crypto_cipher_algorithm cipher_algo)
2029 struct crypto_testsuite_params *ts_params = &testsuite_params;
2030 struct crypto_unittest_params *ut_params = &unittest_params;
2032 unsigned iv_pad_len = 0;
2033 unsigned aad_buffer_len = 0;
2035 /* Generate Crypto op data structure */
2036 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2037 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2038 TEST_ASSERT_NOT_NULL(ut_params->op,
2039 "Failed to allocate pktmbuf offload");
2041 /* Set crypto operation data parameters */
2042 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2044 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2046 /* set crypto operation source mbuf */
2047 sym_op->m_src = ut_params->ibuf;
2050 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2051 ut_params->ibuf, auth_tag_len);
2053 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2054 "no room to append auth tag");
2056 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2057 ut_params->ibuf, data_pad_len);
2058 sym_op->auth.digest.length = auth_tag_len;
2060 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2062 TEST_HEXDUMP(stdout, "digest:",
2063 sym_op->auth.digest.data,
2064 sym_op->auth.digest.length);
2068 * Always allocate the aad up to the block size.
2069 * The cryptodev API calls out -
2070 * - the array must be big enough to hold the AAD, plus any
2071 * space to round this up to the nearest multiple of the
2072 * block size (8 bytes for KASUMI 16 bytes).
2074 if (auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9)
2075 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 8);
2077 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2078 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2079 ut_params->ibuf, aad_buffer_len);
2080 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2081 "no room to prepend aad");
2082 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2084 sym_op->auth.aad.length = aad_len;
2085 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2086 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2087 TEST_HEXDUMP(stdout, "aad:",
2088 sym_op->auth.aad.data, aad_len);
2091 if (cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8)
2092 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 8);
2094 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2096 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2097 ut_params->ibuf, iv_pad_len);
2098 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2100 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2101 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2102 sym_op->cipher.iv.length = iv_pad_len;
2104 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2106 sym_op->cipher.data.length = cipher_len;
2107 sym_op->cipher.data.offset = auth_offset + cipher_offset;
2109 sym_op->auth.data.length = auth_len;
2110 sym_op->auth.data.offset = auth_offset + cipher_offset;
2116 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2118 struct crypto_testsuite_params *ts_params = &testsuite_params;
2119 struct crypto_unittest_params *ut_params = &unittest_params;
2122 unsigned plaintext_pad_len;
2123 unsigned plaintext_len;
2126 /* Create SNOW 3G session */
2127 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2128 tdata->key.data, tdata->key.len,
2129 tdata->aad.len, tdata->digest.len,
2130 RTE_CRYPTO_AUTH_OP_GENERATE,
2131 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2135 /* alloc mbuf and set payload */
2136 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2138 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2139 rte_pktmbuf_tailroom(ut_params->ibuf));
2141 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2142 /* Append data which is padded to a multiple of */
2143 /* the algorithms block size */
2144 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2145 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2147 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2149 /* Create SNOW 3G operation */
2150 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2151 tdata->aad.data, tdata->aad.len,
2152 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2153 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2154 tdata->validAuthLenInBits.len,
2155 tdata->validAuthOffsetLenInBits.len);
2159 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2161 ut_params->obuf = ut_params->op->sym->m_src;
2162 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2163 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2164 + plaintext_pad_len + tdata->aad.len;
2167 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2170 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2171 "SNOW 3G Generated auth tag not as expected");
2177 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2179 struct crypto_testsuite_params *ts_params = &testsuite_params;
2180 struct crypto_unittest_params *ut_params = &unittest_params;
2183 unsigned plaintext_pad_len;
2184 unsigned plaintext_len;
2187 /* Create SNOW 3G session */
2188 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2189 tdata->key.data, tdata->key.len,
2190 tdata->aad.len, tdata->digest.len,
2191 RTE_CRYPTO_AUTH_OP_VERIFY,
2192 RTE_CRYPTO_AUTH_SNOW3G_UIA2);
2195 /* alloc mbuf and set payload */
2196 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2198 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2199 rte_pktmbuf_tailroom(ut_params->ibuf));
2201 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2202 /* Append data which is padded to a multiple of */
2203 /* the algorithms block size */
2204 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2205 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2207 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2209 /* Create SNOW 3G operation */
2210 retval = create_wireless_algo_hash_operation(tdata->digest.data,
2212 tdata->aad.data, tdata->aad.len,
2214 RTE_CRYPTO_AUTH_OP_VERIFY,
2215 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
2216 tdata->validAuthLenInBits.len,
2217 tdata->validAuthOffsetLenInBits.len);
2221 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2223 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2224 ut_params->obuf = ut_params->op->sym->m_src;
2225 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2226 + plaintext_pad_len + tdata->aad.len;
2229 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2238 test_kasumi_authentication(const struct kasumi_hash_test_data *tdata)
2240 struct crypto_testsuite_params *ts_params = &testsuite_params;
2241 struct crypto_unittest_params *ut_params = &unittest_params;
2244 unsigned plaintext_pad_len;
2245 unsigned plaintext_len;
2248 /* Create KASUMI session */
2249 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2250 tdata->key.data, tdata->key.len,
2251 tdata->aad.len, tdata->digest.len,
2252 RTE_CRYPTO_AUTH_OP_GENERATE,
2253 RTE_CRYPTO_AUTH_KASUMI_F9);
2257 /* alloc mbuf and set payload */
2258 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2260 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2261 rte_pktmbuf_tailroom(ut_params->ibuf));
2263 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2264 /* Append data which is padded to a multiple of */
2265 /* the algorithms block size */
2266 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2267 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2269 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2271 /* Create KASUMI operation */
2272 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
2273 tdata->aad.data, tdata->aad.len,
2274 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2275 RTE_CRYPTO_AUTH_KASUMI_F9,
2276 tdata->validAuthLenInBits.len,
2277 tdata->validAuthOffsetLenInBits.len);
2281 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2283 ut_params->obuf = ut_params->op->sym->m_src;
2284 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2285 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2286 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
2289 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2292 DIGEST_BYTE_LENGTH_KASUMI_F9,
2293 "KASUMI Generated auth tag not as expected");
2299 test_kasumi_authentication_verify(const struct kasumi_hash_test_data *tdata)
2301 struct crypto_testsuite_params *ts_params = &testsuite_params;
2302 struct crypto_unittest_params *ut_params = &unittest_params;
2305 unsigned plaintext_pad_len;
2306 unsigned plaintext_len;
2309 /* Create KASUMI session */
2310 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
2311 tdata->key.data, tdata->key.len,
2312 tdata->aad.len, tdata->digest.len,
2313 RTE_CRYPTO_AUTH_OP_VERIFY,
2314 RTE_CRYPTO_AUTH_KASUMI_F9);
2317 /* alloc mbuf and set payload */
2318 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2320 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2321 rte_pktmbuf_tailroom(ut_params->ibuf));
2323 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2324 /* Append data which is padded to a multiple */
2325 /* of the algorithms block size */
2326 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2327 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2329 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2331 /* Create KASUMI operation */
2332 retval = create_wireless_algo_hash_operation(tdata->digest.data,
2334 tdata->aad.data, tdata->aad.len,
2336 RTE_CRYPTO_AUTH_OP_VERIFY,
2337 RTE_CRYPTO_AUTH_KASUMI_F9,
2338 tdata->validAuthLenInBits.len,
2339 tdata->validAuthOffsetLenInBits.len);
2343 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2345 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2346 ut_params->obuf = ut_params->op->sym->m_src;
2347 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2348 + plaintext_pad_len + tdata->aad.len;
2351 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2360 test_snow3g_hash_generate_test_case_1(void)
2362 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2366 test_snow3g_hash_generate_test_case_2(void)
2368 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2372 test_snow3g_hash_generate_test_case_3(void)
2374 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2378 test_snow3g_hash_generate_test_case_4(void)
2380 return test_snow3g_authentication(&snow3g_hash_test_case_4);
2384 test_snow3g_hash_generate_test_case_5(void)
2386 return test_snow3g_authentication(&snow3g_hash_test_case_5);
2390 test_snow3g_hash_generate_test_case_6(void)
2392 return test_snow3g_authentication(&snow3g_hash_test_case_6);
2396 test_snow3g_hash_verify_test_case_1(void)
2398 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2403 test_snow3g_hash_verify_test_case_2(void)
2405 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2409 test_snow3g_hash_verify_test_case_3(void)
2411 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2415 test_snow3g_hash_verify_test_case_4(void)
2417 return test_snow3g_authentication_verify(&snow3g_hash_test_case_4);
2421 test_snow3g_hash_verify_test_case_5(void)
2423 return test_snow3g_authentication_verify(&snow3g_hash_test_case_5);
2427 test_snow3g_hash_verify_test_case_6(void)
2429 return test_snow3g_authentication_verify(&snow3g_hash_test_case_6);
2433 test_kasumi_hash_generate_test_case_1(void)
2435 return test_kasumi_authentication(&kasumi_hash_test_case_1);
2439 test_kasumi_hash_generate_test_case_2(void)
2441 return test_kasumi_authentication(&kasumi_hash_test_case_2);
2445 test_kasumi_hash_generate_test_case_3(void)
2447 return test_kasumi_authentication(&kasumi_hash_test_case_3);
2451 test_kasumi_hash_generate_test_case_4(void)
2453 return test_kasumi_authentication(&kasumi_hash_test_case_4);
2457 test_kasumi_hash_generate_test_case_5(void)
2459 return test_kasumi_authentication(&kasumi_hash_test_case_5);
2463 test_kasumi_hash_generate_test_case_6(void)
2465 return test_kasumi_authentication(&kasumi_hash_test_case_6);
2469 test_kasumi_hash_verify_test_case_1(void)
2471 return test_kasumi_authentication_verify(&kasumi_hash_test_case_1);
2475 test_kasumi_hash_verify_test_case_2(void)
2477 return test_kasumi_authentication_verify(&kasumi_hash_test_case_2);
2481 test_kasumi_hash_verify_test_case_3(void)
2483 return test_kasumi_authentication_verify(&kasumi_hash_test_case_3);
2487 test_kasumi_hash_verify_test_case_4(void)
2489 return test_kasumi_authentication_verify(&kasumi_hash_test_case_4);
2493 test_kasumi_hash_verify_test_case_5(void)
2495 return test_kasumi_authentication_verify(&kasumi_hash_test_case_5);
2499 test_kasumi_encryption(const struct kasumi_test_data *tdata)
2501 struct crypto_testsuite_params *ts_params = &testsuite_params;
2502 struct crypto_unittest_params *ut_params = &unittest_params;
2505 uint8_t *plaintext, *ciphertext;
2506 unsigned plaintext_pad_len;
2507 unsigned plaintext_len;
2509 /* Create KASUMI session */
2510 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2511 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2512 RTE_CRYPTO_CIPHER_KASUMI_F8,
2513 tdata->key.data, tdata->key.len);
2517 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2519 /* Clear mbuf payload */
2520 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2521 rte_pktmbuf_tailroom(ut_params->ibuf));
2523 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2524 /* Append data which is padded to a multiple */
2525 /* of the algorithms block size */
2526 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2527 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2529 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2531 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2533 /* Create KASUMI operation */
2534 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2535 tdata->plaintext.len,
2536 tdata->validCipherOffsetLenInBits.len,
2537 RTE_CRYPTO_CIPHER_KASUMI_F8);
2541 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2543 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2545 ut_params->obuf = ut_params->op->sym->m_dst;
2546 if (ut_params->obuf)
2547 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2550 ciphertext = plaintext;
2552 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2555 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2557 tdata->ciphertext.data,
2558 tdata->validCipherLenInBits.len,
2559 "KASUMI Ciphertext data not as expected");
2564 test_kasumi_encryption_sgl(const struct kasumi_test_data *tdata)
2566 struct crypto_testsuite_params *ts_params = &testsuite_params;
2567 struct crypto_unittest_params *ut_params = &unittest_params;
2571 unsigned int plaintext_pad_len;
2572 unsigned int plaintext_len;
2574 uint8_t buffer[10000];
2575 const uint8_t *ciphertext;
2577 struct rte_cryptodev_info dev_info;
2579 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2580 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
2581 printf("Device doesn't support scatter-gather. "
2586 /* Create KASUMI session */
2587 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2588 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2589 RTE_CRYPTO_CIPHER_KASUMI_F8,
2590 tdata->key.data, tdata->key.len);
2594 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2597 /* Append data which is padded to a multiple */
2598 /* of the algorithms block size */
2599 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2601 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
2602 plaintext_pad_len, 10, 0);
2604 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
2606 /* Create KASUMI operation */
2607 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2609 tdata->plaintext.len,
2610 tdata->validCipherOffsetLenInBits.len,
2611 RTE_CRYPTO_CIPHER_KASUMI_F8);
2615 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2617 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2619 ut_params->obuf = ut_params->op->sym->m_dst;
2621 if (ut_params->obuf)
2622 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len,
2623 plaintext_len, buffer);
2625 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len,
2626 plaintext_len, buffer);
2629 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2632 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2634 tdata->ciphertext.data,
2635 tdata->validCipherLenInBits.len,
2636 "KASUMI Ciphertext data not as expected");
2641 test_kasumi_encryption_oop(const struct kasumi_test_data *tdata)
2643 struct crypto_testsuite_params *ts_params = &testsuite_params;
2644 struct crypto_unittest_params *ut_params = &unittest_params;
2647 uint8_t *plaintext, *ciphertext;
2648 unsigned plaintext_pad_len;
2649 unsigned plaintext_len;
2651 /* Create KASUMI session */
2652 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2653 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2654 RTE_CRYPTO_CIPHER_KASUMI_F8,
2655 tdata->key.data, tdata->key.len);
2659 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2660 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2662 /* Clear mbuf payload */
2663 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2664 rte_pktmbuf_tailroom(ut_params->ibuf));
2666 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2667 /* Append data which is padded to a multiple */
2668 /* of the algorithms block size */
2669 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2670 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2672 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
2673 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2675 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2677 /* Create KASUMI operation */
2678 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2680 tdata->plaintext.len,
2681 tdata->validCipherOffsetLenInBits.len,
2682 RTE_CRYPTO_CIPHER_KASUMI_F8);
2686 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2688 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2690 ut_params->obuf = ut_params->op->sym->m_dst;
2691 if (ut_params->obuf)
2692 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2695 ciphertext = plaintext;
2697 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2700 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2702 tdata->ciphertext.data,
2703 tdata->validCipherLenInBits.len,
2704 "KASUMI Ciphertext data not as expected");
2709 test_kasumi_encryption_oop_sgl(const struct kasumi_test_data *tdata)
2711 struct crypto_testsuite_params *ts_params = &testsuite_params;
2712 struct crypto_unittest_params *ut_params = &unittest_params;
2715 unsigned int plaintext_pad_len;
2716 unsigned int plaintext_len;
2718 const uint8_t *ciphertext;
2719 uint8_t buffer[2048];
2721 struct rte_cryptodev_info dev_info;
2723 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2724 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
2725 printf("Device doesn't support scatter-gather. "
2730 /* Create KASUMI session */
2731 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2732 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2733 RTE_CRYPTO_CIPHER_KASUMI_F8,
2734 tdata->key.data, tdata->key.len);
2738 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2739 /* Append data which is padded to a multiple */
2740 /* of the algorithms block size */
2741 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
2743 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
2744 plaintext_pad_len, 10, 0);
2745 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
2746 plaintext_pad_len, 3, 0);
2748 /* Append data which is padded to a multiple */
2749 /* of the algorithms block size */
2750 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
2752 /* Create KASUMI operation */
2753 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2755 tdata->plaintext.len,
2756 tdata->validCipherOffsetLenInBits.len,
2757 RTE_CRYPTO_CIPHER_KASUMI_F8);
2761 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2763 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2765 ut_params->obuf = ut_params->op->sym->m_dst;
2766 if (ut_params->obuf)
2767 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len,
2768 plaintext_pad_len, buffer);
2770 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len,
2771 plaintext_pad_len, buffer);
2774 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2776 tdata->ciphertext.data,
2777 tdata->validCipherLenInBits.len,
2778 "KASUMI Ciphertext data not as expected");
2784 test_kasumi_decryption_oop(const struct kasumi_test_data *tdata)
2786 struct crypto_testsuite_params *ts_params = &testsuite_params;
2787 struct crypto_unittest_params *ut_params = &unittest_params;
2790 uint8_t *ciphertext, *plaintext;
2791 unsigned ciphertext_pad_len;
2792 unsigned ciphertext_len;
2794 /* Create KASUMI session */
2795 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2796 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2797 RTE_CRYPTO_CIPHER_KASUMI_F8,
2798 tdata->key.data, tdata->key.len);
2802 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2803 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2805 /* Clear mbuf payload */
2806 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2807 rte_pktmbuf_tailroom(ut_params->ibuf));
2809 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2810 /* Append data which is padded to a multiple */
2811 /* of the algorithms block size */
2812 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2813 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2814 ciphertext_pad_len);
2815 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
2816 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2818 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2820 /* Create KASUMI operation */
2821 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
2823 tdata->ciphertext.len,
2824 tdata->validCipherOffsetLenInBits.len,
2825 RTE_CRYPTO_CIPHER_KASUMI_F8);
2829 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2831 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2833 ut_params->obuf = ut_params->op->sym->m_dst;
2834 if (ut_params->obuf)
2835 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2838 plaintext = ciphertext;
2840 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2843 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2845 tdata->plaintext.data,
2846 tdata->validCipherLenInBits.len,
2847 "KASUMI Plaintext data not as expected");
2852 test_kasumi_decryption(const struct kasumi_test_data *tdata)
2854 struct crypto_testsuite_params *ts_params = &testsuite_params;
2855 struct crypto_unittest_params *ut_params = &unittest_params;
2858 uint8_t *ciphertext, *plaintext;
2859 unsigned ciphertext_pad_len;
2860 unsigned ciphertext_len;
2862 /* Create KASUMI session */
2863 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2864 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2865 RTE_CRYPTO_CIPHER_KASUMI_F8,
2866 tdata->key.data, tdata->key.len);
2870 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2872 /* Clear mbuf payload */
2873 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2874 rte_pktmbuf_tailroom(ut_params->ibuf));
2876 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
2877 /* Append data which is padded to a multiple */
2878 /* of the algorithms block size */
2879 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 8);
2880 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2881 ciphertext_pad_len);
2882 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
2884 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
2886 /* Create KASUMI operation */
2887 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
2889 tdata->ciphertext.len,
2890 tdata->validCipherOffsetLenInBits.len,
2891 RTE_CRYPTO_CIPHER_KASUMI_F8);
2895 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2897 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2899 ut_params->obuf = ut_params->op->sym->m_dst;
2900 if (ut_params->obuf)
2901 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2904 plaintext = ciphertext;
2906 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
2909 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2911 tdata->plaintext.data,
2912 tdata->validCipherLenInBits.len,
2913 "KASUMI Plaintext data not as expected");
2918 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2920 struct crypto_testsuite_params *ts_params = &testsuite_params;
2921 struct crypto_unittest_params *ut_params = &unittest_params;
2924 uint8_t *plaintext, *ciphertext;
2925 unsigned plaintext_pad_len;
2926 unsigned plaintext_len;
2928 /* Create SNOW 3G session */
2929 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2930 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2931 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2932 tdata->key.data, tdata->key.len);
2936 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2938 /* Clear mbuf payload */
2939 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2940 rte_pktmbuf_tailroom(ut_params->ibuf));
2942 plaintext_len = ceil_byte_length(tdata->plaintext.len);
2943 /* Append data which is padded to a multiple of */
2944 /* the algorithms block size */
2945 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
2946 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2948 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
2950 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
2952 /* Create SNOW 3G operation */
2953 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
2954 tdata->validCipherLenInBits.len,
2955 tdata->validCipherOffsetLenInBits.len,
2956 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
2960 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2962 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2964 ut_params->obuf = ut_params->op->sym->m_dst;
2965 if (ut_params->obuf)
2966 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2969 ciphertext = plaintext;
2971 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
2974 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
2976 tdata->ciphertext.data,
2977 tdata->validDataLenInBits.len,
2978 "SNOW 3G Ciphertext data not as expected");
2984 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
2986 struct crypto_testsuite_params *ts_params = &testsuite_params;
2987 struct crypto_unittest_params *ut_params = &unittest_params;
2988 uint8_t *plaintext, *ciphertext;
2991 unsigned plaintext_pad_len;
2992 unsigned plaintext_len;
2994 /* Create SNOW 3G session */
2995 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
2996 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2997 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
2998 tdata->key.data, tdata->key.len);
3002 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3003 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3005 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3006 "Failed to allocate input buffer in mempool");
3007 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3008 "Failed to allocate output buffer in mempool");
3010 /* Clear mbuf payload */
3011 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3012 rte_pktmbuf_tailroom(ut_params->ibuf));
3014 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3015 /* Append data which is padded to a multiple of */
3016 /* the algorithms block size */
3017 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3018 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3020 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3021 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3023 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3025 /* Create SNOW 3G operation */
3026 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3028 tdata->validCipherLenInBits.len,
3029 tdata->validCipherOffsetLenInBits.len,
3030 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3034 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3036 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3038 ut_params->obuf = ut_params->op->sym->m_dst;
3039 if (ut_params->obuf)
3040 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3043 ciphertext = plaintext;
3045 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3048 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3050 tdata->ciphertext.data,
3051 tdata->validDataLenInBits.len,
3052 "SNOW 3G Ciphertext data not as expected");
3057 test_snow3g_encryption_oop_sgl(const struct snow3g_test_data *tdata)
3059 struct crypto_testsuite_params *ts_params = &testsuite_params;
3060 struct crypto_unittest_params *ut_params = &unittest_params;
3063 unsigned int plaintext_pad_len;
3064 unsigned int plaintext_len;
3065 uint8_t buffer[10000];
3066 const uint8_t *ciphertext;
3068 struct rte_cryptodev_info dev_info;
3070 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3071 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3072 printf("Device doesn't support scatter-gather. "
3077 /* Create SNOW 3G session */
3078 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3079 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3080 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3081 tdata->key.data, tdata->key.len);
3085 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3086 /* Append data which is padded to a multiple of */
3087 /* the algorithms block size */
3088 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3090 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3091 plaintext_pad_len, 10, 0);
3092 ut_params->obuf = create_segmented_mbuf(ts_params->mbuf_pool,
3093 plaintext_pad_len, 3, 0);
3095 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3096 "Failed to allocate input buffer in mempool");
3097 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3098 "Failed to allocate output buffer in mempool");
3100 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3102 /* Create SNOW 3G operation */
3103 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3105 tdata->validCipherLenInBits.len,
3106 tdata->validCipherOffsetLenInBits.len,
3107 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3111 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3113 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3115 ut_params->obuf = ut_params->op->sym->m_dst;
3116 if (ut_params->obuf)
3117 ciphertext = rte_pktmbuf_read(ut_params->obuf, tdata->iv.len,
3118 plaintext_len, buffer);
3120 ciphertext = rte_pktmbuf_read(ut_params->ibuf, tdata->iv.len,
3121 plaintext_len, buffer);
3123 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3126 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3128 tdata->ciphertext.data,
3129 tdata->validDataLenInBits.len,
3130 "SNOW 3G Ciphertext data not as expected");
3135 /* Shift right a buffer by "offset" bits, "offset" < 8 */
3137 buffer_shift_right(uint8_t *buffer, uint32_t length, uint8_t offset)
3139 uint8_t curr_byte, prev_byte;
3140 uint32_t length_in_bytes = ceil_byte_length(length + offset);
3141 uint8_t lower_byte_mask = (1 << offset) - 1;
3144 prev_byte = buffer[0];
3145 buffer[0] >>= offset;
3147 for (i = 1; i < length_in_bytes; i++) {
3148 curr_byte = buffer[i];
3149 buffer[i] = ((prev_byte & lower_byte_mask) << (8 - offset)) |
3150 (curr_byte >> offset);
3151 prev_byte = curr_byte;
3156 test_snow3g_encryption_offset_oop(const struct snow3g_test_data *tdata)
3158 struct crypto_testsuite_params *ts_params = &testsuite_params;
3159 struct crypto_unittest_params *ut_params = &unittest_params;
3160 uint8_t *plaintext, *ciphertext;
3162 uint32_t plaintext_len;
3163 uint32_t plaintext_pad_len;
3164 uint8_t extra_offset = 4;
3165 uint8_t *expected_ciphertext_shifted;
3167 /* Create SNOW 3G session */
3168 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3169 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3170 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3171 tdata->key.data, tdata->key.len);
3175 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3176 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3178 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3179 "Failed to allocate input buffer in mempool");
3180 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3181 "Failed to allocate output buffer in mempool");
3183 /* Clear mbuf payload */
3184 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3185 rte_pktmbuf_tailroom(ut_params->ibuf));
3187 plaintext_len = ceil_byte_length(tdata->plaintext.len + extra_offset);
3189 * Append data which is padded to a
3190 * multiple of the algorithms block size
3192 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3194 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3197 rte_pktmbuf_append(ut_params->obuf, plaintext_pad_len);
3199 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3200 buffer_shift_right(plaintext, tdata->plaintext.len, extra_offset);
3202 #ifdef RTE_APP_TEST_DEBUG
3203 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3205 /* Create SNOW 3G operation */
3206 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3208 tdata->validCipherLenInBits.len,
3209 tdata->validCipherOffsetLenInBits.len +
3211 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3215 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3217 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3219 ut_params->obuf = ut_params->op->sym->m_dst;
3220 if (ut_params->obuf)
3221 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3224 ciphertext = plaintext;
3226 #ifdef RTE_APP_TEST_DEBUG
3227 rte_hexdump(stdout, "ciphertext:", ciphertext, plaintext_len);
3230 expected_ciphertext_shifted = rte_malloc(NULL,
3231 ceil_byte_length(plaintext_len + extra_offset), 0);
3233 TEST_ASSERT_NOT_NULL(expected_ciphertext_shifted,
3234 "failed to reserve memory for ciphertext shifted\n");
3236 memcpy(expected_ciphertext_shifted, tdata->ciphertext.data,
3237 ceil_byte_length(tdata->ciphertext.len));
3238 buffer_shift_right(expected_ciphertext_shifted, tdata->ciphertext.len,
3241 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT_OFFSET(
3243 expected_ciphertext_shifted,
3244 tdata->validDataLenInBits.len,
3246 "SNOW 3G Ciphertext data not as expected");
3250 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3252 struct crypto_testsuite_params *ts_params = &testsuite_params;
3253 struct crypto_unittest_params *ut_params = &unittest_params;
3257 uint8_t *plaintext, *ciphertext;
3258 unsigned ciphertext_pad_len;
3259 unsigned ciphertext_len;
3261 /* Create SNOW 3G session */
3262 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3263 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3264 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3265 tdata->key.data, tdata->key.len);
3269 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3271 /* Clear mbuf payload */
3272 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3273 rte_pktmbuf_tailroom(ut_params->ibuf));
3275 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3276 /* Append data which is padded to a multiple of */
3277 /* the algorithms block size */
3278 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3279 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3280 ciphertext_pad_len);
3281 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3283 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3285 /* Create SNOW 3G operation */
3286 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3287 tdata->validCipherLenInBits.len,
3288 tdata->validCipherOffsetLenInBits.len,
3289 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3293 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3295 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3296 ut_params->obuf = ut_params->op->sym->m_dst;
3297 if (ut_params->obuf)
3298 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3301 plaintext = ciphertext;
3303 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3306 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3307 tdata->plaintext.data,
3308 tdata->validDataLenInBits.len,
3309 "SNOW 3G Plaintext data not as expected");
3313 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3315 struct crypto_testsuite_params *ts_params = &testsuite_params;
3316 struct crypto_unittest_params *ut_params = &unittest_params;
3320 uint8_t *plaintext, *ciphertext;
3321 unsigned ciphertext_pad_len;
3322 unsigned ciphertext_len;
3324 /* Create SNOW 3G session */
3325 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3326 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3327 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3328 tdata->key.data, tdata->key.len);
3332 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3333 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3335 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3336 "Failed to allocate input buffer");
3337 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3338 "Failed to allocate output buffer");
3340 /* Clear mbuf payload */
3341 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3342 rte_pktmbuf_tailroom(ut_params->ibuf));
3344 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3345 rte_pktmbuf_tailroom(ut_params->obuf));
3347 ciphertext_len = ceil_byte_length(tdata->ciphertext.len);
3348 /* Append data which is padded to a multiple of */
3349 /* the algorithms block size */
3350 ciphertext_pad_len = RTE_ALIGN_CEIL(ciphertext_len, 16);
3351 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3352 ciphertext_pad_len);
3353 rte_pktmbuf_append(ut_params->obuf, ciphertext_pad_len);
3354 memcpy(ciphertext, tdata->ciphertext.data, ciphertext_len);
3356 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, ciphertext_len);
3358 /* Create SNOW 3G operation */
3359 retval = create_wireless_algo_cipher_operation_oop(tdata->iv.data,
3361 tdata->validCipherLenInBits.len,
3362 tdata->validCipherOffsetLenInBits.len,
3363 RTE_CRYPTO_CIPHER_SNOW3G_UEA2);
3367 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3369 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3370 ut_params->obuf = ut_params->op->sym->m_dst;
3371 if (ut_params->obuf)
3372 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3375 plaintext = ciphertext;
3377 TEST_HEXDUMP(stdout, "plaintext:", plaintext, ciphertext_len);
3380 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(plaintext,
3381 tdata->plaintext.data,
3382 tdata->validDataLenInBits.len,
3383 "SNOW 3G Plaintext data not as expected");
3388 test_snow3g_cipher_auth(const struct snow3g_test_data *tdata)
3390 struct crypto_testsuite_params *ts_params = &testsuite_params;
3391 struct crypto_unittest_params *ut_params = &unittest_params;
3395 uint8_t *plaintext, *ciphertext;
3396 unsigned plaintext_pad_len;
3397 unsigned plaintext_len;
3399 /* Create SNOW 3G session */
3400 retval = create_wireless_algo_cipher_auth_session(ts_params->valid_devs[0],
3401 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3402 RTE_CRYPTO_AUTH_OP_GENERATE,
3403 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3404 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3405 tdata->key.data, tdata->key.len,
3406 tdata->aad.len, tdata->digest.len);
3409 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3411 /* clear mbuf payload */
3412 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3413 rte_pktmbuf_tailroom(ut_params->ibuf));
3415 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3416 /* Append data which is padded to a multiple of */
3417 /* the algorithms block size */
3418 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3419 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3421 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3423 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3425 /* Create SNOW 3G operation */
3426 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3427 tdata->digest.len, tdata->aad.data,
3428 tdata->aad.len, /*tdata->plaintext.len,*/
3429 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3430 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3431 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3432 tdata->iv.data, tdata->iv.len,
3433 tdata->validCipherLenInBits.len,
3434 tdata->validCipherOffsetLenInBits.len,
3435 tdata->validAuthLenInBits.len,
3436 tdata->validAuthOffsetLenInBits.len
3441 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3443 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3444 ut_params->obuf = ut_params->op->sym->m_src;
3445 if (ut_params->obuf)
3446 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3447 + tdata->iv.len + tdata->aad.len;
3449 ciphertext = plaintext;
3451 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3453 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3455 tdata->ciphertext.data,
3456 tdata->validDataLenInBits.len,
3457 "SNOW 3G Ciphertext data not as expected");
3459 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3460 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3463 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3466 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3467 "SNOW 3G Generated auth tag not as expected");
3471 test_snow3g_auth_cipher(const struct snow3g_test_data *tdata)
3473 struct crypto_testsuite_params *ts_params = &testsuite_params;
3474 struct crypto_unittest_params *ut_params = &unittest_params;
3478 uint8_t *plaintext, *ciphertext;
3479 unsigned plaintext_pad_len;
3480 unsigned plaintext_len;
3482 /* Create SNOW 3G session */
3483 retval = create_wireless_algo_auth_cipher_session(ts_params->valid_devs[0],
3484 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3485 RTE_CRYPTO_AUTH_OP_GENERATE,
3486 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3487 RTE_CRYPTO_CIPHER_SNOW3G_UEA2,
3488 tdata->key.data, tdata->key.len,
3489 tdata->aad.len, tdata->digest.len);
3493 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3495 /* clear mbuf payload */
3496 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3497 rte_pktmbuf_tailroom(ut_params->ibuf));
3499 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3500 /* Append data which is padded to a multiple of */
3501 /* the algorithms block size */
3502 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3503 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3505 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3507 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3509 /* Create SNOW 3G operation */
3510 retval = create_wireless_algo_auth_cipher_operation(
3512 tdata->iv.data, tdata->iv.len,
3513 tdata->aad.data, tdata->aad.len,
3515 tdata->validCipherLenInBits.len,
3516 tdata->validCipherOffsetLenInBits.len,
3517 tdata->validAuthLenInBits.len,
3518 tdata->validAuthOffsetLenInBits.len,
3519 RTE_CRYPTO_AUTH_SNOW3G_UIA2,
3520 RTE_CRYPTO_CIPHER_SNOW3G_UEA2
3526 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3528 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3529 ut_params->obuf = ut_params->op->sym->m_src;
3530 if (ut_params->obuf)
3531 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3532 + tdata->aad.len + tdata->iv.len;
3534 ciphertext = plaintext;
3536 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3537 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3538 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3541 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3543 tdata->ciphertext.data,
3544 tdata->validDataLenInBits.len,
3545 "SNOW 3G Ciphertext data not as expected");
3548 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3551 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3552 "SNOW 3G Generated auth tag not as expected");
3557 test_kasumi_auth_cipher(const struct kasumi_test_data *tdata)
3559 struct crypto_testsuite_params *ts_params = &testsuite_params;
3560 struct crypto_unittest_params *ut_params = &unittest_params;
3564 uint8_t *plaintext, *ciphertext;
3565 unsigned plaintext_pad_len;
3566 unsigned plaintext_len;
3568 /* Create KASUMI session */
3569 retval = create_wireless_algo_auth_cipher_session(
3570 ts_params->valid_devs[0],
3571 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3572 RTE_CRYPTO_AUTH_OP_GENERATE,
3573 RTE_CRYPTO_AUTH_KASUMI_F9,
3574 RTE_CRYPTO_CIPHER_KASUMI_F8,
3575 tdata->key.data, tdata->key.len,
3576 tdata->aad.len, tdata->digest.len);
3579 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3581 /* clear mbuf payload */
3582 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3583 rte_pktmbuf_tailroom(ut_params->ibuf));
3585 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3586 /* Append data which is padded to a multiple of */
3587 /* the algorithms block size */
3588 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3589 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3591 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3593 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3595 /* Create KASUMI operation */
3596 retval = create_wireless_algo_auth_cipher_operation(tdata->digest.len,
3597 tdata->iv.data, tdata->iv.len,
3598 tdata->aad.data, tdata->aad.len,
3600 tdata->validCipherLenInBits.len,
3601 tdata->validCipherOffsetLenInBits.len,
3602 tdata->validAuthLenInBits.len,
3603 tdata->validAuthOffsetLenInBits.len,
3604 RTE_CRYPTO_AUTH_KASUMI_F9,
3605 RTE_CRYPTO_CIPHER_KASUMI_F8
3611 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3613 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3614 ut_params->obuf = ut_params->op->sym->m_src;
3615 if (ut_params->obuf)
3616 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3617 + tdata->iv.len + tdata->aad.len;
3619 ciphertext = plaintext;
3622 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3624 tdata->ciphertext.data,
3625 tdata->validCipherLenInBits.len,
3626 "KASUMI Ciphertext data not as expected");
3627 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3628 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3631 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3634 DIGEST_BYTE_LENGTH_KASUMI_F9,
3635 "KASUMI Generated auth tag not as expected");
3640 test_kasumi_cipher_auth(const struct kasumi_test_data *tdata)
3642 struct crypto_testsuite_params *ts_params = &testsuite_params;
3643 struct crypto_unittest_params *ut_params = &unittest_params;
3647 uint8_t *plaintext, *ciphertext;
3648 unsigned plaintext_pad_len;
3649 unsigned plaintext_len;
3651 /* Create KASUMI session */
3652 retval = create_wireless_algo_cipher_auth_session(
3653 ts_params->valid_devs[0],
3654 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3655 RTE_CRYPTO_AUTH_OP_GENERATE,
3656 RTE_CRYPTO_AUTH_KASUMI_F9,
3657 RTE_CRYPTO_CIPHER_KASUMI_F8,
3658 tdata->key.data, tdata->key.len,
3659 tdata->aad.len, tdata->digest.len);
3663 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3665 /* clear mbuf payload */
3666 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3667 rte_pktmbuf_tailroom(ut_params->ibuf));
3669 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3670 /* Append data which is padded to a multiple of */
3671 /* the algorithms block size */
3672 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 16);
3673 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3675 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3677 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3679 /* Create KASUMI operation */
3680 retval = create_wireless_algo_cipher_hash_operation(tdata->digest.data,
3681 tdata->digest.len, tdata->aad.data,
3683 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3684 RTE_CRYPTO_AUTH_KASUMI_F9,
3685 RTE_CRYPTO_CIPHER_KASUMI_F8,
3686 tdata->iv.data, tdata->iv.len,
3687 tdata->validCipherLenInBits.len,
3688 tdata->validCipherOffsetLenInBits.len,
3689 tdata->validAuthLenInBits.len,
3690 tdata->validAuthOffsetLenInBits.len
3695 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3697 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3698 ut_params->obuf = ut_params->op->sym->m_src;
3699 if (ut_params->obuf)
3700 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3701 + tdata->aad.len + tdata->iv.len;
3703 ciphertext = plaintext;
3705 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3706 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3709 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3711 tdata->ciphertext.data,
3712 tdata->validCipherLenInBits.len,
3713 "KASUMI Ciphertext data not as expected");
3716 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3719 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3720 "KASUMI Generated auth tag not as expected");
3725 test_zuc_encryption(const struct zuc_test_data *tdata)
3727 struct crypto_testsuite_params *ts_params = &testsuite_params;
3728 struct crypto_unittest_params *ut_params = &unittest_params;
3731 uint8_t *plaintext, *ciphertext;
3732 unsigned plaintext_pad_len;
3733 unsigned plaintext_len;
3735 /* Create ZUC session */
3736 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3737 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3738 RTE_CRYPTO_CIPHER_ZUC_EEA3,
3739 tdata->key.data, tdata->key.len);
3743 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3745 /* Clear mbuf payload */
3746 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3747 rte_pktmbuf_tailroom(ut_params->ibuf));
3749 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3750 /* Append data which is padded to a multiple */
3751 /* of the algorithms block size */
3752 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3753 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3755 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3757 TEST_HEXDUMP(stdout, "plaintext:", plaintext, plaintext_len);
3759 /* Create ZUC operation */
3760 retval = create_wireless_algo_cipher_operation(tdata->iv.data, tdata->iv.len,
3761 tdata->plaintext.len,
3762 tdata->validCipherOffsetLenInBits.len,
3763 RTE_CRYPTO_CIPHER_ZUC_EEA3);
3767 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3769 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3771 ut_params->obuf = ut_params->op->sym->m_dst;
3772 if (ut_params->obuf)
3773 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3776 ciphertext = plaintext;
3778 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3781 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3783 tdata->ciphertext.data,
3784 tdata->validCipherLenInBits.len,
3785 "ZUC Ciphertext data not as expected");
3790 test_zuc_encryption_sgl(const struct zuc_test_data *tdata)
3792 struct crypto_testsuite_params *ts_params = &testsuite_params;
3793 struct crypto_unittest_params *ut_params = &unittest_params;
3797 unsigned int plaintext_pad_len;
3798 unsigned int plaintext_len;
3799 const uint8_t *ciphertext;
3800 uint8_t ciphertext_buffer[2048];
3801 struct rte_cryptodev_info dev_info;
3803 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3804 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER)) {
3805 printf("Device doesn't support scatter-gather. "
3810 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3812 /* Append data which is padded to a multiple */
3813 /* of the algorithms block size */
3814 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3816 ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool,
3817 plaintext_pad_len, 10, 0);
3819 pktmbuf_write(ut_params->ibuf, 0, plaintext_len,
3820 tdata->plaintext.data);
3822 /* Create ZUC session */
3823 retval = create_wireless_algo_cipher_session(ts_params->valid_devs[0],
3824 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3825 RTE_CRYPTO_CIPHER_ZUC_EEA3,
3826 tdata->key.data, tdata->key.len);
3830 /* Clear mbuf payload */
3832 pktmbuf_write(ut_params->ibuf, 0, plaintext_len, tdata->plaintext.data);
3834 /* Create ZUC operation */
3835 retval = create_wireless_algo_cipher_operation(tdata->iv.data,
3836 tdata->iv.len, tdata->plaintext.len,
3837 tdata->validCipherOffsetLenInBits.len,
3838 RTE_CRYPTO_CIPHER_ZUC_EEA3);
3842 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3844 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3846 ut_params->obuf = ut_params->op->sym->m_dst;
3847 if (ut_params->obuf)
3848 ciphertext = rte_pktmbuf_read(ut_params->obuf,
3849 tdata->iv.len, plaintext_len, ciphertext_buffer);
3851 ciphertext = rte_pktmbuf_read(ut_params->ibuf,
3852 tdata->iv.len, plaintext_len, ciphertext_buffer);
3855 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, plaintext_len);
3858 TEST_ASSERT_BUFFERS_ARE_EQUAL_BIT(
3860 tdata->ciphertext.data,
3861 tdata->validCipherLenInBits.len,
3862 "ZUC Ciphertext data not as expected");
3868 test_zuc_authentication(const struct zuc_hash_test_data *tdata)
3870 struct crypto_testsuite_params *ts_params = &testsuite_params;
3871 struct crypto_unittest_params *ut_params = &unittest_params;
3874 unsigned plaintext_pad_len;
3875 unsigned plaintext_len;
3878 /* Create ZUC session */
3879 retval = create_wireless_algo_hash_session(ts_params->valid_devs[0],
3880 tdata->key.data, tdata->key.len,
3881 tdata->aad.len, tdata->digest.len,
3882 RTE_CRYPTO_AUTH_OP_GENERATE,
3883 RTE_CRYPTO_AUTH_ZUC_EIA3);
3887 /* alloc mbuf and set payload */
3888 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3890 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3891 rte_pktmbuf_tailroom(ut_params->ibuf));
3893 plaintext_len = ceil_byte_length(tdata->plaintext.len);
3894 /* Append data which is padded to a multiple of */
3895 /* the algorithms block size */
3896 plaintext_pad_len = RTE_ALIGN_CEIL(plaintext_len, 8);
3897 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3899 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
3901 /* Create ZUC operation */
3902 retval = create_wireless_algo_hash_operation(NULL, tdata->digest.len,
3903 tdata->aad.data, tdata->aad.len,
3904 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3905 RTE_CRYPTO_AUTH_ZUC_EIA3,
3906 tdata->validAuthLenInBits.len,
3907 tdata->validAuthOffsetLenInBits.len);
3911 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3913 ut_params->obuf = ut_params->op->sym->m_src;
3914 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3915 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3916 + plaintext_pad_len + ALIGN_POW2_ROUNDUP(tdata->aad.len, 8);
3919 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3922 DIGEST_BYTE_LENGTH_KASUMI_F9,
3923 "ZUC Generated auth tag not as expected");
3929 test_kasumi_encryption_test_case_1(void)
3931 return test_kasumi_encryption(&kasumi_test_case_1);
3935 test_kasumi_encryption_test_case_1_sgl(void)
3937 return test_kasumi_encryption_sgl(&kasumi_test_case_1);
3941 test_kasumi_encryption_test_case_1_oop(void)
3943 return test_kasumi_encryption_oop(&kasumi_test_case_1);
3947 test_kasumi_encryption_test_case_1_oop_sgl(void)
3949 return test_kasumi_encryption_oop_sgl(&kasumi_test_case_1);
3953 test_kasumi_encryption_test_case_2(void)
3955 return test_kasumi_encryption(&kasumi_test_case_2);
3959 test_kasumi_encryption_test_case_3(void)
3961 return test_kasumi_encryption(&kasumi_test_case_3);
3965 test_kasumi_encryption_test_case_4(void)
3967 return test_kasumi_encryption(&kasumi_test_case_4);
3971 test_kasumi_encryption_test_case_5(void)
3973 return test_kasumi_encryption(&kasumi_test_case_5);
3977 test_kasumi_decryption_test_case_1(void)
3979 return test_kasumi_decryption(&kasumi_test_case_1);
3983 test_kasumi_decryption_test_case_1_oop(void)
3985 return test_kasumi_decryption_oop(&kasumi_test_case_1);
3989 test_kasumi_decryption_test_case_2(void)
3991 return test_kasumi_decryption(&kasumi_test_case_2);
3995 test_kasumi_decryption_test_case_3(void)
3997 return test_kasumi_decryption(&kasumi_test_case_3);
4001 test_kasumi_decryption_test_case_4(void)
4003 return test_kasumi_decryption(&kasumi_test_case_4);
4007 test_kasumi_decryption_test_case_5(void)
4009 return test_kasumi_decryption(&kasumi_test_case_5);
4012 test_snow3g_encryption_test_case_1(void)
4014 return test_snow3g_encryption(&snow3g_test_case_1);
4018 test_snow3g_encryption_test_case_1_oop(void)
4020 return test_snow3g_encryption_oop(&snow3g_test_case_1);
4024 test_snow3g_encryption_test_case_1_oop_sgl(void)
4026 return test_snow3g_encryption_oop_sgl(&snow3g_test_case_1);
4031 test_snow3g_encryption_test_case_1_offset_oop(void)
4033 return test_snow3g_encryption_offset_oop(&snow3g_test_case_1);
4037 test_snow3g_encryption_test_case_2(void)
4039 return test_snow3g_encryption(&snow3g_test_case_2);
4043 test_snow3g_encryption_test_case_3(void)
4045 return test_snow3g_encryption(&snow3g_test_case_3);
4049 test_snow3g_encryption_test_case_4(void)
4051 return test_snow3g_encryption(&snow3g_test_case_4);
4055 test_snow3g_encryption_test_case_5(void)
4057 return test_snow3g_encryption(&snow3g_test_case_5);
4061 test_snow3g_decryption_test_case_1(void)
4063 return test_snow3g_decryption(&snow3g_test_case_1);
4067 test_snow3g_decryption_test_case_1_oop(void)
4069 return test_snow3g_decryption_oop(&snow3g_test_case_1);
4073 test_snow3g_decryption_test_case_2(void)
4075 return test_snow3g_decryption(&snow3g_test_case_2);
4079 test_snow3g_decryption_test_case_3(void)
4081 return test_snow3g_decryption(&snow3g_test_case_3);
4085 test_snow3g_decryption_test_case_4(void)
4087 return test_snow3g_decryption(&snow3g_test_case_4);
4091 test_snow3g_decryption_test_case_5(void)
4093 return test_snow3g_decryption(&snow3g_test_case_5);
4096 test_snow3g_cipher_auth_test_case_1(void)
4098 return test_snow3g_cipher_auth(&snow3g_test_case_3);
4102 test_snow3g_auth_cipher_test_case_1(void)
4104 return test_snow3g_auth_cipher(&snow3g_test_case_6);
4108 test_kasumi_auth_cipher_test_case_1(void)
4110 return test_kasumi_auth_cipher(&kasumi_test_case_3);
4114 test_kasumi_cipher_auth_test_case_1(void)
4116 return test_kasumi_cipher_auth(&kasumi_test_case_6);
4120 test_zuc_encryption_test_case_1(void)
4122 return test_zuc_encryption(&zuc_test_case_1);
4126 test_zuc_encryption_test_case_2(void)
4128 return test_zuc_encryption(&zuc_test_case_2);
4132 test_zuc_encryption_test_case_3(void)
4134 return test_zuc_encryption(&zuc_test_case_3);
4138 test_zuc_encryption_test_case_4(void)
4140 return test_zuc_encryption(&zuc_test_case_4);
4144 test_zuc_encryption_test_case_5(void)
4146 return test_zuc_encryption(&zuc_test_case_5);
4150 test_zuc_encryption_test_case_6_sgl(void)
4152 return test_zuc_encryption_sgl(&zuc_test_case_1);
4156 test_zuc_hash_generate_test_case_1(void)
4158 return test_zuc_authentication(&zuc_hash_test_case_1);
4162 test_zuc_hash_generate_test_case_2(void)
4164 return test_zuc_authentication(&zuc_hash_test_case_2);
4168 test_zuc_hash_generate_test_case_3(void)
4170 return test_zuc_authentication(&zuc_hash_test_case_3);
4174 test_zuc_hash_generate_test_case_4(void)
4176 return test_zuc_authentication(&zuc_hash_test_case_4);
4180 test_zuc_hash_generate_test_case_5(void)
4182 return test_zuc_authentication(&zuc_hash_test_case_5);
4186 test_3DES_chain_qat_all(void)
4188 struct crypto_testsuite_params *ts_params = &testsuite_params;
4191 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4192 ts_params->op_mpool, ts_params->valid_devs[0],
4193 RTE_CRYPTODEV_QAT_SYM_PMD,
4194 BLKCIPHER_3DES_CHAIN_TYPE);
4196 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4198 return TEST_SUCCESS;
4202 test_DES_cipheronly_qat_all(void)
4204 struct crypto_testsuite_params *ts_params = &testsuite_params;
4207 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4208 ts_params->op_mpool, ts_params->valid_devs[0],
4209 RTE_CRYPTODEV_QAT_SYM_PMD,
4210 BLKCIPHER_DES_CIPHERONLY_TYPE);
4212 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4214 return TEST_SUCCESS;
4218 test_3DES_cipheronly_qat_all(void)
4220 struct crypto_testsuite_params *ts_params = &testsuite_params;
4223 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4224 ts_params->op_mpool, ts_params->valid_devs[0],
4225 RTE_CRYPTODEV_QAT_SYM_PMD,
4226 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4228 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4230 return TEST_SUCCESS;
4234 test_3DES_chain_openssl_all(void)
4236 struct crypto_testsuite_params *ts_params = &testsuite_params;
4239 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4240 ts_params->op_mpool, ts_params->valid_devs[0],
4241 RTE_CRYPTODEV_OPENSSL_PMD,
4242 BLKCIPHER_3DES_CHAIN_TYPE);
4244 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4246 return TEST_SUCCESS;
4250 test_3DES_cipheronly_openssl_all(void)
4252 struct crypto_testsuite_params *ts_params = &testsuite_params;
4255 status = test_blockcipher_all_tests(ts_params->mbuf_pool,
4256 ts_params->op_mpool, ts_params->valid_devs[0],
4257 RTE_CRYPTODEV_OPENSSL_PMD,
4258 BLKCIPHER_3DES_CIPHERONLY_TYPE);
4260 TEST_ASSERT_EQUAL(status, 0, "Test failed");
4262 return TEST_SUCCESS;
4265 /* ***** AES-GCM Tests ***** */
4268 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
4269 const uint8_t *key, const uint8_t key_len,
4270 const uint8_t aad_len, const uint8_t auth_len,
4271 enum rte_crypto_auth_operation auth_op)
4273 uint8_t cipher_key[key_len];
4275 struct crypto_unittest_params *ut_params = &unittest_params;
4277 memcpy(cipher_key, key, key_len);
4279 /* Setup Cipher Parameters */
4280 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4281 ut_params->cipher_xform.next = NULL;
4283 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
4284 ut_params->auth_xform.auth.op = auth_op;
4285 ut_params->cipher_xform.cipher.op = op;
4286 ut_params->cipher_xform.cipher.key.data = cipher_key;
4287 ut_params->cipher_xform.cipher.key.length = key_len;
4289 TEST_HEXDUMP(stdout, "key:", key, key_len);
4291 /* Setup Authentication Parameters */
4292 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4293 ut_params->auth_xform.next = NULL;
4295 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
4297 ut_params->auth_xform.auth.digest_length = auth_len;
4298 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
4299 ut_params->auth_xform.auth.key.length = 0;
4300 ut_params->auth_xform.auth.key.data = NULL;
4302 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
4303 ut_params->cipher_xform.next = &ut_params->auth_xform;
4305 /* Create Crypto session*/
4306 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4307 &ut_params->cipher_xform);
4308 } else {/* Create Crypto session*/
4309 ut_params->auth_xform.next = &ut_params->cipher_xform;
4310 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
4311 &ut_params->auth_xform);
4314 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4320 create_gcm_operation(enum rte_crypto_cipher_operation op,
4321 const uint8_t *auth_tag, const unsigned auth_tag_len,
4322 const uint8_t *iv, const unsigned iv_len,
4323 const uint8_t *aad, const unsigned aad_len,
4324 const unsigned data_len, unsigned data_pad_len)
4326 struct crypto_testsuite_params *ts_params = &testsuite_params;
4327 struct crypto_unittest_params *ut_params = &unittest_params;
4329 unsigned iv_pad_len = 0, aad_buffer_len;
4331 /* Generate Crypto op data structure */
4332 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4333 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4334 TEST_ASSERT_NOT_NULL(ut_params->op,
4335 "Failed to allocate symmetric crypto operation struct");
4337 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4339 if (ut_params->obuf) {
4340 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4341 ut_params->obuf, auth_tag_len);
4342 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4343 "no room to append digest");
4344 sym_op->auth.digest.phys_addr = pktmbuf_mtophys_offset(
4345 ut_params->obuf, data_pad_len);
4347 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4348 ut_params->ibuf, auth_tag_len);
4349 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4350 "no room to append digest");
4351 sym_op->auth.digest.phys_addr = pktmbuf_mtophys_offset(
4352 ut_params->ibuf, data_pad_len);
4354 sym_op->auth.digest.length = auth_tag_len;
4356 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
4357 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
4358 TEST_HEXDUMP(stdout, "digest:",
4359 sym_op->auth.digest.data,
4360 sym_op->auth.digest.length);
4364 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
4366 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4367 ut_params->ibuf, iv_pad_len);
4368 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
4370 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
4371 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
4372 sym_op->cipher.iv.length = iv_len;
4374 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
4377 * Always allocate the aad up to the block size.
4378 * The cryptodev API calls out -
4379 * - the array must be big enough to hold the AAD, plus any
4380 * space to round this up to the nearest multiple of the
4381 * block size (16 bytes).
4383 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
4385 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
4386 ut_params->ibuf, aad_buffer_len);
4387 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
4388 "no room to prepend aad");
4389 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
4391 sym_op->auth.aad.length = aad_len;
4393 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
4394 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
4396 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
4397 TEST_HEXDUMP(stdout, "aad:",
4398 sym_op->auth.aad.data, aad_len);
4400 if (ut_params->obuf) {
4401 rte_pktmbuf_prepend(ut_params->obuf, iv_pad_len);
4402 rte_pktmbuf_prepend(ut_params->obuf, aad_buffer_len);
4405 sym_op->cipher.data.length = data_len;
4406 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
4408 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
4409 sym_op->auth.data.length = data_len;
4415 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
4417 struct crypto_testsuite_params *ts_params = &testsuite_params;
4418 struct crypto_unittest_params *ut_params = &unittest_params;
4422 uint8_t *plaintext, *ciphertext, *auth_tag;
4423 uint16_t plaintext_pad_len;
4425 /* Create GCM session */
4426 retval = create_gcm_session(ts_params->valid_devs[0],
4427 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4428 tdata->key.data, tdata->key.len,
4429 tdata->aad.len, tdata->auth_tag.len,
4430 RTE_CRYPTO_AUTH_OP_GENERATE);
4435 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4437 /* clear mbuf payload */
4438 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4439 rte_pktmbuf_tailroom(ut_params->ibuf));
4442 * Append data which is padded to a multiple
4443 * of the algorithms block size
4445 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
4447 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4449 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
4451 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
4453 /* Create GCM opertaion */
4454 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
4455 tdata->auth_tag.data, tdata->auth_tag.len,
4456 tdata->iv.data, tdata->iv.len,
4457 tdata->aad.data, tdata->aad.len,
4458 tdata->plaintext.len, plaintext_pad_len);
4462 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4464 ut_params->op->sym->m_src = ut_params->ibuf;
4466 /* Process crypto operation */
4467 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4468 ut_params->op), "failed to process sym crypto op");
4470 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4471 "crypto op processing failed");
4473 if (ut_params->op->sym->m_dst) {
4474 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4476 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4477 uint8_t *, plaintext_pad_len);
4479 ciphertext = plaintext;
4480 auth_tag = plaintext + plaintext_pad_len;
4483 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4484 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
4487 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4489 tdata->ciphertext.data,
4490 tdata->ciphertext.len,
4491 "GCM Ciphertext data not as expected");
4493 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4495 tdata->auth_tag.data,
4496 tdata->auth_tag.len,
4497 "GCM Generated auth tag not as expected");
4504 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
4506 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
4510 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
4512 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
4516 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
4518 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
4522 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
4524 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
4528 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
4530 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
4534 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
4536 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
4540 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
4542 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
4546 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
4548 struct crypto_testsuite_params *ts_params = &testsuite_params;
4549 struct crypto_unittest_params *ut_params = &unittest_params;
4553 uint8_t *plaintext, *ciphertext;
4554 uint16_t ciphertext_pad_len;
4556 /* Create GCM session */
4557 retval = create_gcm_session(ts_params->valid_devs[0],
4558 RTE_CRYPTO_CIPHER_OP_DECRYPT,
4559 tdata->key.data, tdata->key.len,
4560 tdata->aad.len, tdata->auth_tag.len,
4561 RTE_CRYPTO_AUTH_OP_VERIFY);
4566 /* alloc mbuf and set payload */
4567 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4569 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4570 rte_pktmbuf_tailroom(ut_params->ibuf));
4572 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
4574 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4575 ciphertext_pad_len);
4576 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
4578 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
4580 /* Create GCM opertaion */
4581 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
4582 tdata->auth_tag.data, tdata->auth_tag.len,
4583 tdata->iv.data, tdata->iv.len,
4584 tdata->aad.data, tdata->aad.len,
4585 tdata->ciphertext.len, ciphertext_pad_len);
4590 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4592 ut_params->op->sym->m_src = ut_params->ibuf;
4594 /* Process crypto operation */
4595 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4596 ut_params->op), "failed to process sym crypto op");
4598 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4599 "crypto op processing failed");
4601 if (ut_params->op->sym->m_dst)
4602 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
4605 plaintext = ciphertext;
4607 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
4610 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4612 tdata->plaintext.data,
4613 tdata->plaintext.len,
4614 "GCM plaintext data not as expected");
4616 TEST_ASSERT_EQUAL(ut_params->op->status,
4617 RTE_CRYPTO_OP_STATUS_SUCCESS,
4618 "GCM authentication failed");
4623 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
4625 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
4629 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
4631 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
4635 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
4637 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
4641 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
4643 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
4647 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
4649 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
4653 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
4655 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
4659 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
4661 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
4667 struct crypto_testsuite_params *ts_params = &testsuite_params;
4668 struct rte_cryptodev_stats stats;
4669 struct rte_cryptodev *dev;
4670 cryptodev_stats_get_t temp_pfn;
4672 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
4673 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
4674 &stats) == -ENODEV),
4675 "rte_cryptodev_stats_get invalid dev failed");
4676 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
4677 "rte_cryptodev_stats_get invalid Param failed");
4678 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
4679 temp_pfn = dev->dev_ops->stats_get;
4680 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
4681 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
4683 "rte_cryptodev_stats_get invalid Param failed");
4684 dev->dev_ops->stats_get = temp_pfn;
4686 /* Test expected values */
4688 test_AES_CBC_HMAC_SHA1_encrypt_digest();
4690 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4692 "rte_cryptodev_stats_get failed");
4693 TEST_ASSERT((stats.enqueued_count == 1),
4694 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4695 TEST_ASSERT((stats.dequeued_count == 1),
4696 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4697 TEST_ASSERT((stats.enqueue_err_count == 0),
4698 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4699 TEST_ASSERT((stats.dequeue_err_count == 0),
4700 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4702 /* invalid device but should ignore and not reset device stats*/
4703 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
4704 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4706 "rte_cryptodev_stats_get failed");
4707 TEST_ASSERT((stats.enqueued_count == 1),
4708 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4710 /* check that a valid reset clears stats */
4711 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
4712 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
4714 "rte_cryptodev_stats_get failed");
4715 TEST_ASSERT((stats.enqueued_count == 0),
4716 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4717 TEST_ASSERT((stats.dequeued_count == 0),
4718 "rte_cryptodev_stats_get returned unexpected enqueued stat");
4720 return TEST_SUCCESS;
4723 static int MD5_HMAC_create_session(struct crypto_testsuite_params *ts_params,
4724 struct crypto_unittest_params *ut_params,
4725 enum rte_crypto_auth_operation op,
4726 const struct HMAC_MD5_vector *test_case)
4730 memcpy(key, test_case->key.data, test_case->key.len);
4732 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4733 ut_params->auth_xform.next = NULL;
4734 ut_params->auth_xform.auth.op = op;
4736 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_MD5_HMAC;
4738 ut_params->auth_xform.auth.digest_length = MD5_DIGEST_LEN;
4739 ut_params->auth_xform.auth.add_auth_data_length = 0;
4740 ut_params->auth_xform.auth.key.length = test_case->key.len;
4741 ut_params->auth_xform.auth.key.data = key;
4743 ut_params->sess = rte_cryptodev_sym_session_create(
4744 ts_params->valid_devs[0], &ut_params->auth_xform);
4746 if (ut_params->sess == NULL)
4749 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4751 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
4752 rte_pktmbuf_tailroom(ut_params->ibuf));
4757 static int MD5_HMAC_create_op(struct crypto_unittest_params *ut_params,
4758 const struct HMAC_MD5_vector *test_case,
4759 uint8_t **plaintext)
4761 uint16_t plaintext_pad_len;
4763 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4765 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
4768 *plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4770 memcpy(*plaintext, test_case->plaintext.data,
4771 test_case->plaintext.len);
4773 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
4774 ut_params->ibuf, MD5_DIGEST_LEN);
4775 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
4776 "no room to append digest");
4777 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4778 ut_params->ibuf, plaintext_pad_len);
4779 sym_op->auth.digest.length = MD5_DIGEST_LEN;
4781 if (ut_params->auth_xform.auth.op == RTE_CRYPTO_AUTH_OP_VERIFY) {
4782 rte_memcpy(sym_op->auth.digest.data, test_case->auth_tag.data,
4783 test_case->auth_tag.len);
4786 sym_op->auth.data.offset = 0;
4787 sym_op->auth.data.length = test_case->plaintext.len;
4789 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4790 ut_params->op->sym->m_src = ut_params->ibuf;
4796 test_MD5_HMAC_generate(const struct HMAC_MD5_vector *test_case)
4798 uint16_t plaintext_pad_len;
4799 uint8_t *plaintext, *auth_tag;
4801 struct crypto_testsuite_params *ts_params = &testsuite_params;
4802 struct crypto_unittest_params *ut_params = &unittest_params;
4804 if (MD5_HMAC_create_session(ts_params, ut_params,
4805 RTE_CRYPTO_AUTH_OP_GENERATE, test_case))
4808 /* Generate Crypto op data structure */
4809 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4810 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4811 TEST_ASSERT_NOT_NULL(ut_params->op,
4812 "Failed to allocate symmetric crypto operation struct");
4814 plaintext_pad_len = RTE_ALIGN_CEIL(test_case->plaintext.len,
4817 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
4820 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4821 ut_params->op), "failed to process sym crypto op");
4823 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4824 "crypto op processing failed");
4826 if (ut_params->op->sym->m_dst) {
4827 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
4828 uint8_t *, plaintext_pad_len);
4830 auth_tag = plaintext + plaintext_pad_len;
4833 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4835 test_case->auth_tag.data,
4836 test_case->auth_tag.len,
4837 "HMAC_MD5 generated tag not as expected");
4839 return TEST_SUCCESS;
4843 test_MD5_HMAC_verify(const struct HMAC_MD5_vector *test_case)
4847 struct crypto_testsuite_params *ts_params = &testsuite_params;
4848 struct crypto_unittest_params *ut_params = &unittest_params;
4850 if (MD5_HMAC_create_session(ts_params, ut_params,
4851 RTE_CRYPTO_AUTH_OP_VERIFY, test_case)) {
4855 /* Generate Crypto op data structure */
4856 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4857 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4858 TEST_ASSERT_NOT_NULL(ut_params->op,
4859 "Failed to allocate symmetric crypto operation struct");
4861 if (MD5_HMAC_create_op(ut_params, test_case, &plaintext))
4864 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
4865 ut_params->op), "failed to process sym crypto op");
4867 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4868 "HMAC_MD5 crypto op processing failed");
4870 return TEST_SUCCESS;
4874 test_MD5_HMAC_generate_case_1(void)
4876 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_1);
4880 test_MD5_HMAC_verify_case_1(void)
4882 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_1);
4886 test_MD5_HMAC_generate_case_2(void)
4888 return test_MD5_HMAC_generate(&HMAC_MD5_test_case_2);
4892 test_MD5_HMAC_verify_case_2(void)
4894 return test_MD5_HMAC_verify(&HMAC_MD5_test_case_2);
4898 test_multi_session(void)
4900 struct crypto_testsuite_params *ts_params = &testsuite_params;
4901 struct crypto_unittest_params *ut_params = &unittest_params;
4903 struct rte_cryptodev_info dev_info;
4904 struct rte_cryptodev_sym_session **sessions;
4908 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params,
4909 aes_cbc_key, hmac_sha512_key);
4912 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4914 sessions = rte_malloc(NULL,
4915 (sizeof(struct rte_cryptodev_sym_session *) *
4916 dev_info.sym.max_nb_sessions) + 1, 0);
4918 /* Create multiple crypto sessions*/
4919 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4920 sessions[i] = rte_cryptodev_sym_session_create(
4921 ts_params->valid_devs[0],
4922 &ut_params->auth_xform);
4923 TEST_ASSERT_NOT_NULL(sessions[i],
4924 "Session creation failed at session number %u",
4927 /* Attempt to send a request on each session */
4928 TEST_ASSERT_SUCCESS( test_AES_CBC_HMAC_SHA512_decrypt_perform(
4932 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
4933 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
4935 "Failed to perform decrypt on request number %u.", i);
4936 /* free crypto operation structure */
4938 rte_crypto_op_free(ut_params->op);
4941 * free mbuf - both obuf and ibuf are usually the same,
4942 * so check if they point at the same address is necessary,
4943 * to avoid freeing the mbuf twice.
4945 if (ut_params->obuf) {
4946 rte_pktmbuf_free(ut_params->obuf);
4947 if (ut_params->ibuf == ut_params->obuf)
4948 ut_params->ibuf = 0;
4949 ut_params->obuf = 0;
4951 if (ut_params->ibuf) {
4952 rte_pktmbuf_free(ut_params->ibuf);
4953 ut_params->ibuf = 0;
4957 /* Next session create should fail */
4958 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4959 &ut_params->auth_xform);
4960 TEST_ASSERT_NULL(sessions[i],
4961 "Session creation succeeded unexpectedly!");
4963 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4964 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4969 return TEST_SUCCESS;
4972 struct multi_session_params {
4973 struct crypto_unittest_params ut_params;
4974 uint8_t *cipher_key;
4976 const uint8_t *cipher;
4977 const uint8_t *digest;
4981 #define MB_SESSION_NUMBER 3
4984 test_multi_session_random_usage(void)
4986 struct crypto_testsuite_params *ts_params = &testsuite_params;
4987 struct rte_cryptodev_info dev_info;
4988 struct rte_cryptodev_sym_session **sessions;
4990 struct multi_session_params ut_paramz[] = {
4993 .cipher_key = ms_aes_cbc_key0,
4994 .hmac_key = ms_hmac_key0,
4995 .cipher = ms_aes_cbc_cipher0,
4996 .digest = ms_hmac_digest0,
4997 .iv = ms_aes_cbc_iv0
5000 .cipher_key = ms_aes_cbc_key1,
5001 .hmac_key = ms_hmac_key1,
5002 .cipher = ms_aes_cbc_cipher1,
5003 .digest = ms_hmac_digest1,
5004 .iv = ms_aes_cbc_iv1
5007 .cipher_key = ms_aes_cbc_key2,
5008 .hmac_key = ms_hmac_key2,
5009 .cipher = ms_aes_cbc_cipher2,
5010 .digest = ms_hmac_digest2,
5011 .iv = ms_aes_cbc_iv2
5016 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
5018 sessions = rte_malloc(NULL,
5019 (sizeof(struct rte_cryptodev_sym_session *)
5020 * dev_info.sym.max_nb_sessions) + 1, 0);
5022 for (i = 0; i < MB_SESSION_NUMBER; i++) {
5023 rte_memcpy(&ut_paramz[i].ut_params, &testsuite_params,
5024 sizeof(struct crypto_unittest_params));
5026 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
5027 &ut_paramz[i].ut_params,
5028 ut_paramz[i].cipher_key, ut_paramz[i].hmac_key);
5030 /* Create multiple crypto sessions*/
5031 sessions[i] = rte_cryptodev_sym_session_create(
5032 ts_params->valid_devs[0],
5033 &ut_paramz[i].ut_params.auth_xform);
5035 TEST_ASSERT_NOT_NULL(sessions[i],
5036 "Session creation failed at session number %u",
5042 for (i = 0; i < 40000; i++) {
5044 j = rand() % MB_SESSION_NUMBER;
5046 TEST_ASSERT_SUCCESS(
5047 test_AES_CBC_HMAC_SHA512_decrypt_perform(
5049 &ut_paramz[j].ut_params,
5050 ts_params, ut_paramz[j].cipher,
5051 ut_paramz[j].digest,
5053 "Failed to perform decrypt on request number %u.", i);
5055 if (ut_paramz[j].ut_params.op)
5056 rte_crypto_op_free(ut_paramz[j].ut_params.op);
5059 * free mbuf - both obuf and ibuf are usually the same,
5060 * so check if they point at the same address is necessary,
5061 * to avoid freeing the mbuf twice.
5063 if (ut_paramz[j].ut_params.obuf) {
5064 rte_pktmbuf_free(ut_paramz[j].ut_params.obuf);
5065 if (ut_paramz[j].ut_params.ibuf
5066 == ut_paramz[j].ut_params.obuf)
5067 ut_paramz[j].ut_params.ibuf = 0;
5068 ut_paramz[j].ut_params.obuf = 0;
5070 if (ut_paramz[j].ut_params.ibuf) {
5071 rte_pktmbuf_free(ut_paramz[j].ut_params.ibuf);
5072 ut_paramz[j].ut_params.ibuf = 0;
5076 for (i = 0; i < MB_SESSION_NUMBER; i++)
5077 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
5082 return TEST_SUCCESS;
5086 test_null_cipher_only_operation(void)
5088 struct crypto_testsuite_params *ts_params = &testsuite_params;
5089 struct crypto_unittest_params *ut_params = &unittest_params;
5091 /* Generate test mbuf data and space for digest */
5092 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5093 catch_22_quote, QUOTE_512_BYTES, 0);
5095 /* Setup Cipher Parameters */
5096 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5097 ut_params->cipher_xform.next = NULL;
5099 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5100 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5102 /* Create Crypto session*/
5103 ut_params->sess = rte_cryptodev_sym_session_create(
5104 ts_params->valid_devs[0], &ut_params->cipher_xform);
5105 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5107 /* Generate Crypto op data structure */
5108 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5109 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5110 TEST_ASSERT_NOT_NULL(ut_params->op,
5111 "Failed to allocate symmetric crypto operation struct");
5113 /* Set crypto operation data parameters */
5114 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5116 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5118 /* set crypto operation source mbuf */
5119 sym_op->m_src = ut_params->ibuf;
5121 sym_op->cipher.data.offset = 0;
5122 sym_op->cipher.data.length = QUOTE_512_BYTES;
5124 /* Process crypto operation */
5125 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5127 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5129 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5130 "crypto operation processing failed");
5133 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5134 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5137 "Ciphertext data not as expected");
5139 return TEST_SUCCESS;
5143 test_null_auth_only_operation(void)
5145 struct crypto_testsuite_params *ts_params = &testsuite_params;
5146 struct crypto_unittest_params *ut_params = &unittest_params;
5148 /* Generate test mbuf data and space for digest */
5149 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5150 catch_22_quote, QUOTE_512_BYTES, 0);
5152 /* Setup HMAC Parameters */
5153 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5154 ut_params->auth_xform.next = NULL;
5156 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5157 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5159 /* Create Crypto session*/
5160 ut_params->sess = rte_cryptodev_sym_session_create(
5161 ts_params->valid_devs[0], &ut_params->auth_xform);
5162 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5164 /* Generate Crypto op data structure */
5165 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5166 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5167 TEST_ASSERT_NOT_NULL(ut_params->op,
5168 "Failed to allocate symmetric crypto operation struct");
5170 /* Set crypto operation data parameters */
5171 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5173 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5175 sym_op->m_src = ut_params->ibuf;
5177 sym_op->auth.data.offset = 0;
5178 sym_op->auth.data.length = QUOTE_512_BYTES;
5180 /* Process crypto operation */
5181 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5183 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5185 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5186 "crypto operation processing failed");
5188 return TEST_SUCCESS;
5192 test_null_cipher_auth_operation(void)
5194 struct crypto_testsuite_params *ts_params = &testsuite_params;
5195 struct crypto_unittest_params *ut_params = &unittest_params;
5197 /* Generate test mbuf data and space for digest */
5198 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5199 catch_22_quote, QUOTE_512_BYTES, 0);
5201 /* Setup Cipher Parameters */
5202 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5203 ut_params->cipher_xform.next = &ut_params->auth_xform;
5205 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5206 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5208 /* Setup HMAC Parameters */
5209 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5210 ut_params->auth_xform.next = NULL;
5212 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5213 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5215 /* Create Crypto session*/
5216 ut_params->sess = rte_cryptodev_sym_session_create(
5217 ts_params->valid_devs[0], &ut_params->cipher_xform);
5218 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5220 /* Generate Crypto op data structure */
5221 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5222 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5223 TEST_ASSERT_NOT_NULL(ut_params->op,
5224 "Failed to allocate symmetric crypto operation struct");
5226 /* Set crypto operation data parameters */
5227 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5229 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5231 sym_op->m_src = ut_params->ibuf;
5233 sym_op->cipher.data.offset = 0;
5234 sym_op->cipher.data.length = QUOTE_512_BYTES;
5236 sym_op->auth.data.offset = 0;
5237 sym_op->auth.data.length = QUOTE_512_BYTES;
5239 /* Process crypto operation */
5240 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5242 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5244 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5245 "crypto operation processing failed");
5248 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5249 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5252 "Ciphertext data not as expected");
5254 return TEST_SUCCESS;
5258 test_null_auth_cipher_operation(void)
5260 struct crypto_testsuite_params *ts_params = &testsuite_params;
5261 struct crypto_unittest_params *ut_params = &unittest_params;
5263 /* Generate test mbuf data and space for digest */
5264 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
5265 catch_22_quote, QUOTE_512_BYTES, 0);
5267 /* Setup Cipher Parameters */
5268 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5269 ut_params->cipher_xform.next = NULL;
5271 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5272 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5274 /* Setup HMAC Parameters */
5275 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5276 ut_params->auth_xform.next = &ut_params->cipher_xform;
5278 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5279 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5281 /* Create Crypto session*/
5282 ut_params->sess = rte_cryptodev_sym_session_create(
5283 ts_params->valid_devs[0], &ut_params->cipher_xform);
5284 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5286 /* Generate Crypto op data structure */
5287 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5288 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5289 TEST_ASSERT_NOT_NULL(ut_params->op,
5290 "Failed to allocate symmetric crypto operation struct");
5292 /* Set crypto operation data parameters */
5293 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5295 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5297 sym_op->m_src = ut_params->ibuf;
5299 sym_op->cipher.data.offset = 0;
5300 sym_op->cipher.data.length = QUOTE_512_BYTES;
5302 sym_op->auth.data.offset = 0;
5303 sym_op->auth.data.length = QUOTE_512_BYTES;
5305 /* Process crypto operation */
5306 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
5308 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
5310 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5311 "crypto operation processing failed");
5314 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5315 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
5318 "Ciphertext data not as expected");
5320 return TEST_SUCCESS;
5325 test_null_invalid_operation(void)
5327 struct crypto_testsuite_params *ts_params = &testsuite_params;
5328 struct crypto_unittest_params *ut_params = &unittest_params;
5330 /* Setup Cipher Parameters */
5331 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5332 ut_params->cipher_xform.next = NULL;
5334 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
5335 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5337 /* Create Crypto session*/
5338 ut_params->sess = rte_cryptodev_sym_session_create(
5339 ts_params->valid_devs[0], &ut_params->cipher_xform);
5340 TEST_ASSERT_NULL(ut_params->sess,
5341 "Session creation succeeded unexpectedly");
5344 /* Setup HMAC Parameters */
5345 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5346 ut_params->auth_xform.next = NULL;
5348 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
5349 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5351 /* Create Crypto session*/
5352 ut_params->sess = rte_cryptodev_sym_session_create(
5353 ts_params->valid_devs[0], &ut_params->auth_xform);
5354 TEST_ASSERT_NULL(ut_params->sess,
5355 "Session creation succeeded unexpectedly");
5357 return TEST_SUCCESS;
5361 #define NULL_BURST_LENGTH (32)
5364 test_null_burst_operation(void)
5366 struct crypto_testsuite_params *ts_params = &testsuite_params;
5367 struct crypto_unittest_params *ut_params = &unittest_params;
5369 unsigned i, burst_len = NULL_BURST_LENGTH;
5371 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
5372 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
5374 /* Setup Cipher Parameters */
5375 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5376 ut_params->cipher_xform.next = &ut_params->auth_xform;
5378 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
5379 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
5381 /* Setup HMAC Parameters */
5382 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5383 ut_params->auth_xform.next = NULL;
5385 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
5386 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
5388 /* Create Crypto session*/
5389 ut_params->sess = rte_cryptodev_sym_session_create(
5390 ts_params->valid_devs[0], &ut_params->cipher_xform);
5391 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5393 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
5394 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
5395 burst_len, "failed to generate burst of crypto ops");
5397 /* Generate an operation for each mbuf in burst */
5398 for (i = 0; i < burst_len; i++) {
5399 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5401 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
5403 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
5407 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
5409 burst[i]->sym->m_src = m;
5412 /* Process crypto operation */
5413 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
5414 0, burst, burst_len),
5416 "Error enqueuing burst");
5418 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
5419 0, burst_dequeued, burst_len),
5421 "Error dequeuing burst");
5424 for (i = 0; i < burst_len; i++) {
5426 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
5427 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
5429 "data not as expected");
5431 rte_pktmbuf_free(burst[i]->sym->m_src);
5432 rte_crypto_op_free(burst[i]);
5435 return TEST_SUCCESS;
5439 generate_gmac_large_plaintext(uint8_t *data)
5443 for (i = 32; i < GMAC_LARGE_PLAINTEXT_LENGTH; i += 32)
5444 memcpy(&data[i], &data[0], 32);
5448 create_gmac_operation(enum rte_crypto_auth_operation op,
5449 const struct gmac_test_data *tdata)
5451 struct crypto_testsuite_params *ts_params = &testsuite_params;
5452 struct crypto_unittest_params *ut_params = &unittest_params;
5453 struct rte_crypto_sym_op *sym_op;
5455 unsigned iv_pad_len;
5456 unsigned aad_pad_len;
5458 iv_pad_len = RTE_ALIGN_CEIL(tdata->iv.len, 16);
5459 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5462 * Runtime generate the large plain text instead of use hard code
5463 * plain text vector. It is done to avoid create huge source file
5464 * with the test vector.
5466 if (tdata->aad.len == GMAC_LARGE_PLAINTEXT_LENGTH)
5467 generate_gmac_large_plaintext(tdata->aad.data);
5469 /* Generate Crypto op data structure */
5470 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5471 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5472 TEST_ASSERT_NOT_NULL(ut_params->op,
5473 "Failed to allocate symmetric crypto operation struct");
5475 sym_op = ut_params->op->sym;
5476 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
5478 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
5479 "no room to append aad");
5481 sym_op->auth.aad.length = tdata->aad.len;
5482 sym_op->auth.aad.phys_addr =
5483 rte_pktmbuf_mtophys(ut_params->ibuf);
5484 memcpy(sym_op->auth.aad.data, tdata->aad.data, tdata->aad.len);
5486 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5487 ut_params->ibuf, tdata->gmac_tag.len);
5488 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5489 "no room to append digest");
5491 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5492 ut_params->ibuf, aad_pad_len);
5493 sym_op->auth.digest.length = tdata->gmac_tag.len;
5495 if (op == RTE_CRYPTO_AUTH_OP_VERIFY) {
5496 rte_memcpy(sym_op->auth.digest.data, tdata->gmac_tag.data,
5497 tdata->gmac_tag.len);
5498 TEST_HEXDUMP(stdout, "digest:",
5499 sym_op->auth.digest.data,
5500 sym_op->auth.digest.length);
5503 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
5504 ut_params->ibuf, iv_pad_len);
5505 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
5507 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
5508 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
5509 sym_op->cipher.iv.length = tdata->iv.len;
5511 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, tdata->iv.len);
5513 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
5515 sym_op->cipher.data.length = 0;
5516 sym_op->cipher.data.offset = 0;
5518 sym_op->auth.data.offset = 0;
5519 sym_op->auth.data.length = 0;
5524 static int create_gmac_session(uint8_t dev_id,
5525 enum rte_crypto_cipher_operation op,
5526 const struct gmac_test_data *tdata,
5527 enum rte_crypto_auth_operation auth_op)
5529 uint8_t cipher_key[tdata->key.len];
5531 struct crypto_unittest_params *ut_params = &unittest_params;
5533 memcpy(cipher_key, tdata->key.data, tdata->key.len);
5535 /* For GMAC we setup cipher parameters */
5536 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5537 ut_params->cipher_xform.next = NULL;
5538 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
5539 ut_params->cipher_xform.cipher.op = op;
5540 ut_params->cipher_xform.cipher.key.data = cipher_key;
5541 ut_params->cipher_xform.cipher.key.length = tdata->key.len;
5543 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5544 ut_params->auth_xform.next = NULL;
5546 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GMAC;
5547 ut_params->auth_xform.auth.op = auth_op;
5548 ut_params->auth_xform.auth.digest_length = tdata->gmac_tag.len;
5549 ut_params->auth_xform.auth.add_auth_data_length = 0;
5550 ut_params->auth_xform.auth.key.length = 0;
5551 ut_params->auth_xform.auth.key.data = NULL;
5553 ut_params->cipher_xform.next = &ut_params->auth_xform;
5555 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5556 &ut_params->cipher_xform);
5558 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5564 test_AES_GMAC_authentication(const struct gmac_test_data *tdata)
5566 struct crypto_testsuite_params *ts_params = &testsuite_params;
5567 struct crypto_unittest_params *ut_params = &unittest_params;
5571 uint8_t *auth_tag, *p;
5572 uint16_t aad_pad_len;
5574 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
5575 "No GMAC length in the source data");
5577 retval = create_gmac_session(ts_params->valid_devs[0],
5578 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
5579 tdata, RTE_CRYPTO_AUTH_OP_GENERATE);
5584 if (tdata->aad.len > MBUF_SIZE)
5585 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5587 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5588 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5589 "Failed to allocate input buffer in mempool");
5591 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5592 rte_pktmbuf_tailroom(ut_params->ibuf));
5594 aad_pad_len = RTE_ALIGN_CEIL(tdata->aad.len, 16);
5596 p = rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
5598 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_GENERATE,
5604 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5606 ut_params->op->sym->m_src = ut_params->ibuf;
5608 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5609 ut_params->op), "failed to process sym crypto op");
5611 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5612 "crypto op processing failed");
5614 if (ut_params->op->sym->m_dst) {
5615 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
5616 uint8_t *, aad_pad_len);
5618 auth_tag = p + aad_pad_len;
5621 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->gmac_tag.len);
5623 TEST_ASSERT_BUFFERS_ARE_EQUAL(
5625 tdata->gmac_tag.data,
5626 tdata->gmac_tag.len,
5627 "GMAC Generated auth tag not as expected");
5633 test_AES_GMAC_authentication_test_case_1(void)
5635 return test_AES_GMAC_authentication(&gmac_test_case_1);
5639 test_AES_GMAC_authentication_test_case_2(void)
5641 return test_AES_GMAC_authentication(&gmac_test_case_2);
5645 test_AES_GMAC_authentication_test_case_3(void)
5647 return test_AES_GMAC_authentication(&gmac_test_case_3);
5651 test_AES_GMAC_authentication_test_case_4(void)
5653 return test_AES_GMAC_authentication(&gmac_test_case_4);
5657 test_AES_GMAC_authentication_verify(const struct gmac_test_data *tdata)
5659 struct crypto_testsuite_params *ts_params = &testsuite_params;
5660 struct crypto_unittest_params *ut_params = &unittest_params;
5663 TEST_ASSERT_NOT_EQUAL(tdata->gmac_tag.len, 0,
5664 "No GMAC length in the source data");
5666 retval = create_gmac_session(ts_params->valid_devs[0],
5667 RTE_CRYPTO_CIPHER_OP_DECRYPT,
5668 tdata, RTE_CRYPTO_AUTH_OP_VERIFY);
5673 if (tdata->aad.len > MBUF_SIZE)
5674 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->large_mbuf_pool);
5676 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
5677 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
5678 "Failed to allocate input buffer in mempool");
5680 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
5681 rte_pktmbuf_tailroom(ut_params->ibuf));
5683 retval = create_gmac_operation(RTE_CRYPTO_AUTH_OP_VERIFY,
5689 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5691 ut_params->op->sym->m_src = ut_params->ibuf;
5693 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
5694 ut_params->op), "failed to process sym crypto op");
5696 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
5697 "crypto op processing failed");
5704 test_AES_GMAC_authentication_verify_test_case_1(void)
5706 return test_AES_GMAC_authentication_verify(&gmac_test_case_1);
5710 test_AES_GMAC_authentication_verify_test_case_2(void)
5712 return test_AES_GMAC_authentication_verify(&gmac_test_case_2);
5716 test_AES_GMAC_authentication_verify_test_case_3(void)
5718 return test_AES_GMAC_authentication_verify(&gmac_test_case_3);
5722 test_AES_GMAC_authentication_verify_test_case_4(void)
5724 return test_AES_GMAC_authentication_verify(&gmac_test_case_4);
5727 struct test_crypto_vector {
5728 enum rte_crypto_cipher_algorithm crypto_algo;
5741 const uint8_t *data;
5746 const uint8_t *data;
5750 enum rte_crypto_auth_algorithm auth_algo;
5758 const uint8_t *data;
5768 static const struct test_crypto_vector
5769 hmac_sha1_test_crypto_vector = {
5770 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
5772 .data = plaintext_hash,
5777 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
5778 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
5779 0xDE, 0xF4, 0xDE, 0xAD
5785 0xC4, 0xB7, 0x0E, 0x6B, 0xDE, 0xD1, 0xE7, 0x77,
5786 0x7E, 0x2E, 0x8F, 0xFC, 0x48, 0x39, 0x46, 0x17,
5787 0x3F, 0x91, 0x64, 0x59
5793 static const struct test_crypto_vector
5794 aes128_gmac_test_vector = {
5795 .auth_algo = RTE_CRYPTO_AUTH_AES_GMAC,
5796 .crypto_algo = RTE_CRYPTO_CIPHER_AES_GCM,
5798 .data = plaintext_hash,
5803 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5804 0x08, 0x09, 0x0A, 0x0B
5810 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
5811 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA
5817 0xCA, 0x00, 0x99, 0x8B, 0x30, 0x7E, 0x74, 0x56,
5818 0x32, 0xA7, 0x87, 0xB5, 0xE9, 0xB2, 0x34, 0x5A
5824 static const struct test_crypto_vector
5825 aes128cbc_hmac_sha1_test_vector = {
5826 .crypto_algo = RTE_CRYPTO_CIPHER_AES_CBC,
5829 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
5830 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A
5836 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
5837 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
5842 .data = plaintext_hash,
5846 .data = ciphertext512_aes128cbc,
5849 .auth_algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
5852 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
5853 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
5854 0xDE, 0xF4, 0xDE, 0xAD
5860 0x9A, 0x4F, 0x88, 0x1B, 0xB6, 0x8F, 0xD8, 0x60,
5861 0x42, 0x1A, 0x7D, 0x3D, 0xF5, 0x82, 0x80, 0xF1,
5862 0x18, 0x8C, 0x1D, 0x32
5869 data_corruption(uint8_t *data)
5875 tag_corruption(uint8_t *data, unsigned int tag_offset)
5877 data[tag_offset] += 1;
5881 create_auth_session(struct crypto_unittest_params *ut_params,
5883 const struct test_crypto_vector *reference,
5884 enum rte_crypto_auth_operation auth_op)
5886 uint8_t auth_key[reference->auth_key.len + 1];
5888 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
5890 /* Setup Authentication Parameters */
5891 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5892 ut_params->auth_xform.auth.op = auth_op;
5893 ut_params->auth_xform.next = NULL;
5894 ut_params->auth_xform.auth.algo = reference->auth_algo;
5895 ut_params->auth_xform.auth.key.length = reference->auth_key.len;
5896 ut_params->auth_xform.auth.key.data = auth_key;
5897 ut_params->auth_xform.auth.digest_length = reference->digest.len;
5898 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
5900 /* Create Crypto session*/
5901 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5902 &ut_params->auth_xform);
5904 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5910 create_auth_cipher_session(struct crypto_unittest_params *ut_params,
5912 const struct test_crypto_vector *reference,
5913 enum rte_crypto_auth_operation auth_op,
5914 enum rte_crypto_cipher_operation cipher_op)
5916 uint8_t cipher_key[reference->cipher_key.len + 1];
5917 uint8_t auth_key[reference->auth_key.len + 1];
5919 memcpy(cipher_key, reference->cipher_key.data,
5920 reference->cipher_key.len);
5921 memcpy(auth_key, reference->auth_key.data, reference->auth_key.len);
5923 /* Setup Authentication Parameters */
5924 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
5925 ut_params->auth_xform.auth.op = auth_op;
5926 ut_params->auth_xform.next = &ut_params->cipher_xform;
5927 ut_params->auth_xform.auth.algo = reference->auth_algo;
5928 ut_params->auth_xform.auth.key.length = reference->auth_key.len;
5929 ut_params->auth_xform.auth.key.data = auth_key;
5930 ut_params->auth_xform.auth.digest_length = reference->digest.len;
5931 ut_params->auth_xform.auth.add_auth_data_length = reference->aad.len;
5933 /* Setup Cipher Parameters */
5934 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
5935 ut_params->cipher_xform.next = NULL;
5936 ut_params->cipher_xform.cipher.algo = reference->crypto_algo;
5937 ut_params->cipher_xform.cipher.op = cipher_op;
5938 ut_params->cipher_xform.cipher.key.data = cipher_key;
5939 ut_params->cipher_xform.cipher.key.length = reference->cipher_key.len;
5941 /* Create Crypto session*/
5942 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
5943 &ut_params->auth_xform);
5945 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
5951 create_auth_operation(struct crypto_testsuite_params *ts_params,
5952 struct crypto_unittest_params *ut_params,
5953 const struct test_crypto_vector *reference,
5954 unsigned int auth_generate)
5956 /* Generate Crypto op data structure */
5957 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
5958 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
5959 TEST_ASSERT_NOT_NULL(ut_params->op,
5960 "Failed to allocate pktmbuf offload");
5962 /* Set crypto operation data parameters */
5963 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
5965 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
5967 /* set crypto operation source mbuf */
5968 sym_op->m_src = ut_params->ibuf;
5971 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
5972 ut_params->ibuf, reference->digest.len);
5974 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
5975 "no room to append auth tag");
5977 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
5978 ut_params->ibuf, reference->plaintext.len);
5979 sym_op->auth.digest.length = reference->digest.len;
5982 memset(sym_op->auth.digest.data, 0, reference->digest.len);
5984 memcpy(sym_op->auth.digest.data,
5985 reference->digest.data,
5986 reference->digest.len);
5988 TEST_HEXDUMP(stdout, "digest:",
5989 sym_op->auth.digest.data,
5990 sym_op->auth.digest.length);
5992 sym_op->auth.data.length = reference->plaintext.len;
5993 sym_op->auth.data.offset = 0;
5999 create_auth_GMAC_operation(struct crypto_testsuite_params *ts_params,
6000 struct crypto_unittest_params *ut_params,
6001 const struct test_crypto_vector *reference,
6002 unsigned int auth_generate)
6004 /* Generate Crypto op data structure */
6005 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6006 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6007 TEST_ASSERT_NOT_NULL(ut_params->op,
6008 "Failed to allocate pktmbuf offload");
6010 /* Set crypto operation data parameters */
6011 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6013 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6015 /* set crypto operation source mbuf */
6016 sym_op->m_src = ut_params->ibuf;
6019 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6020 reference->aad.len);
6021 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data, "no room to append AAD");
6022 memcpy(sym_op->auth.aad.data, reference->aad.data, reference->aad.len);
6024 TEST_HEXDUMP(stdout, "AAD:", sym_op->auth.aad.data, reference->aad.len);
6026 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6027 sym_op->auth.aad.length = reference->aad.len;
6030 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6031 ut_params->ibuf, reference->digest.len);
6033 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6034 "no room to append auth tag");
6036 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6037 ut_params->ibuf, reference->ciphertext.len);
6038 sym_op->auth.digest.length = reference->digest.len;
6041 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6043 memcpy(sym_op->auth.digest.data,
6044 reference->digest.data,
6045 reference->digest.len);
6047 TEST_HEXDUMP(stdout, "digest:",
6048 sym_op->auth.digest.data,
6049 sym_op->auth.digest.length);
6051 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6052 ut_params->ibuf, reference->iv.len);
6053 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
6055 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6056 sym_op->cipher.iv.length = reference->iv.len;
6058 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
6060 sym_op->cipher.data.length = 0;
6061 sym_op->cipher.data.offset = 0;
6063 sym_op->auth.data.length = 0;
6064 sym_op->auth.data.offset = 0;
6070 create_cipher_auth_operation(struct crypto_testsuite_params *ts_params,
6071 struct crypto_unittest_params *ut_params,
6072 const struct test_crypto_vector *reference,
6073 unsigned int auth_generate)
6075 /* Generate Crypto op data structure */
6076 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6077 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6078 TEST_ASSERT_NOT_NULL(ut_params->op,
6079 "Failed to allocate pktmbuf offload");
6081 /* Set crypto operation data parameters */
6082 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6084 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6086 /* set crypto operation source mbuf */
6087 sym_op->m_src = ut_params->ibuf;
6090 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
6091 ut_params->ibuf, reference->digest.len);
6093 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6094 "no room to append auth tag");
6096 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
6097 ut_params->ibuf, reference->ciphertext.len);
6098 sym_op->auth.digest.length = reference->digest.len;
6101 memset(sym_op->auth.digest.data, 0, reference->digest.len);
6103 memcpy(sym_op->auth.digest.data,
6104 reference->digest.data,
6105 reference->digest.len);
6107 TEST_HEXDUMP(stdout, "digest:",
6108 sym_op->auth.digest.data,
6109 sym_op->auth.digest.length);
6111 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6112 ut_params->ibuf, reference->iv.len);
6113 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
6115 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6116 sym_op->cipher.iv.length = reference->iv.len;
6118 memcpy(sym_op->cipher.iv.data, reference->iv.data, reference->iv.len);
6120 sym_op->cipher.data.length = reference->ciphertext.len;
6121 sym_op->cipher.data.offset = reference->iv.len;
6123 sym_op->auth.data.length = reference->ciphertext.len;
6124 sym_op->auth.data.offset = reference->iv.len;
6130 create_auth_verify_operation(struct crypto_testsuite_params *ts_params,
6131 struct crypto_unittest_params *ut_params,
6132 const struct test_crypto_vector *reference)
6134 return create_auth_operation(ts_params, ut_params, reference, 0);
6138 create_auth_verify_GMAC_operation(
6139 struct crypto_testsuite_params *ts_params,
6140 struct crypto_unittest_params *ut_params,
6141 const struct test_crypto_vector *reference)
6143 return create_auth_GMAC_operation(ts_params, ut_params, reference, 0);
6147 create_cipher_auth_verify_operation(struct crypto_testsuite_params *ts_params,
6148 struct crypto_unittest_params *ut_params,
6149 const struct test_crypto_vector *reference)
6151 return create_cipher_auth_operation(ts_params, ut_params, reference, 0);
6155 test_authentication_verify_fail_when_data_corruption(
6156 struct crypto_testsuite_params *ts_params,
6157 struct crypto_unittest_params *ut_params,
6158 const struct test_crypto_vector *reference,
6159 unsigned int data_corrupted)
6165 /* Create session */
6166 retval = create_auth_session(ut_params,
6167 ts_params->valid_devs[0],
6169 RTE_CRYPTO_AUTH_OP_VERIFY);
6173 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6174 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6175 "Failed to allocate input buffer in mempool");
6177 /* clear mbuf payload */
6178 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6179 rte_pktmbuf_tailroom(ut_params->ibuf));
6181 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6182 reference->plaintext.len);
6183 TEST_ASSERT_NOT_NULL(plaintext, "no room to append plaintext");
6184 memcpy(plaintext, reference->plaintext.data, reference->plaintext.len);
6186 TEST_HEXDUMP(stdout, "plaintext:", plaintext, reference->plaintext.len);
6188 /* Create operation */
6189 retval = create_auth_verify_operation(ts_params, ut_params, reference);
6195 data_corruption(plaintext);
6197 tag_corruption(plaintext, reference->plaintext.len);
6199 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6201 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6202 TEST_ASSERT_EQUAL(ut_params->op->status,
6203 RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6204 "authentication not failed");
6206 ut_params->obuf = ut_params->op->sym->m_src;
6207 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6213 test_authentication_verify_GMAC_fail_when_corruption(
6214 struct crypto_testsuite_params *ts_params,
6215 struct crypto_unittest_params *ut_params,
6216 const struct test_crypto_vector *reference,
6217 unsigned int data_corrupted)
6221 /* Create session */
6222 retval = create_auth_cipher_session(ut_params,
6223 ts_params->valid_devs[0],
6225 RTE_CRYPTO_AUTH_OP_VERIFY,
6226 RTE_CRYPTO_CIPHER_OP_DECRYPT);
6230 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6231 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6232 "Failed to allocate input buffer in mempool");
6234 /* clear mbuf payload */
6235 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6236 rte_pktmbuf_tailroom(ut_params->ibuf));
6238 /* Create operation */
6239 retval = create_auth_verify_GMAC_operation(ts_params,
6247 data_corruption(ut_params->op->sym->auth.aad.data);
6249 tag_corruption(ut_params->op->sym->auth.aad.data,
6250 reference->aad.len);
6252 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6254 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6255 TEST_ASSERT_EQUAL(ut_params->op->status,
6256 RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6257 "authentication not failed");
6259 ut_params->obuf = ut_params->op->sym->m_src;
6260 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6266 test_authenticated_decryption_fail_when_corruption(
6267 struct crypto_testsuite_params *ts_params,
6268 struct crypto_unittest_params *ut_params,
6269 const struct test_crypto_vector *reference,
6270 unsigned int data_corrupted)
6274 uint8_t *ciphertext;
6276 /* Create session */
6277 retval = create_auth_cipher_session(ut_params,
6278 ts_params->valid_devs[0],
6280 RTE_CRYPTO_AUTH_OP_VERIFY,
6281 RTE_CRYPTO_CIPHER_OP_DECRYPT);
6285 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6286 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
6287 "Failed to allocate input buffer in mempool");
6289 /* clear mbuf payload */
6290 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6291 rte_pktmbuf_tailroom(ut_params->ibuf));
6293 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6294 reference->ciphertext.len);
6295 TEST_ASSERT_NOT_NULL(ciphertext, "no room to append ciphertext");
6296 memcpy(ciphertext, reference->ciphertext.data,
6297 reference->ciphertext.len);
6299 /* Create operation */
6300 retval = create_cipher_auth_verify_operation(ts_params,
6308 data_corruption(ciphertext);
6310 tag_corruption(ciphertext, reference->ciphertext.len);
6312 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
6315 TEST_ASSERT_NOT_NULL(ut_params->op, "failed crypto process");
6316 TEST_ASSERT_EQUAL(ut_params->op->status,
6317 RTE_CRYPTO_OP_STATUS_AUTH_FAILED,
6318 "authentication not failed");
6320 ut_params->obuf = ut_params->op->sym->m_src;
6321 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
6327 create_gcm_operation_SGL(enum rte_crypto_cipher_operation op,
6328 const struct gcm_test_data *tdata,
6329 void *digest_mem, uint64_t digest_phys)
6331 struct crypto_testsuite_params *ts_params = &testsuite_params;
6332 struct crypto_unittest_params *ut_params = &unittest_params;
6334 const unsigned int auth_tag_len = tdata->auth_tag.len;
6335 const unsigned int iv_len = tdata->iv.len;
6336 const unsigned int aad_len = tdata->aad.len;
6338 unsigned int iv_pad_len = 0;
6340 /* Generate Crypto op data structure */
6341 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
6342 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
6343 TEST_ASSERT_NOT_NULL(ut_params->op,
6344 "Failed to allocate symmetric crypto operation struct");
6346 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
6348 sym_op->auth.digest.data = digest_mem;
6350 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
6351 "no room to append digest");
6353 sym_op->auth.digest.phys_addr = digest_phys;
6354 sym_op->auth.digest.length = auth_tag_len;
6356 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
6357 rte_memcpy(sym_op->auth.digest.data, tdata->auth_tag.data,
6359 TEST_HEXDUMP(stdout, "digest:",
6360 sym_op->auth.digest.data,
6361 sym_op->auth.digest.length);
6364 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
6366 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
6367 ut_params->ibuf, iv_pad_len);
6369 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
6370 "no room to prepend iv");
6372 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
6373 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
6374 sym_op->cipher.iv.length = iv_len;
6376 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data, iv_pad_len);
6378 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
6379 ut_params->ibuf, aad_len);
6380 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
6381 "no room to prepend aad");
6382 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
6384 sym_op->auth.aad.length = aad_len;
6386 memset(sym_op->auth.aad.data, 0, aad_len);
6387 rte_memcpy(sym_op->auth.aad.data, tdata->aad.data, aad_len);
6389 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
6390 TEST_HEXDUMP(stdout, "aad:",
6391 sym_op->auth.aad.data, aad_len);
6393 sym_op->cipher.data.length = tdata->plaintext.len;
6394 sym_op->cipher.data.offset = aad_len + iv_pad_len;
6396 sym_op->auth.data.offset = aad_len + iv_pad_len;
6397 sym_op->auth.data.length = tdata->plaintext.len;
6402 #define SGL_MAX_NO 16
6405 test_AES_GCM_authenticated_encryption_SGL(const struct gcm_test_data *tdata,
6406 const int oop, uint32_t fragsz, uint32_t fragsz_oop)
6408 struct crypto_testsuite_params *ts_params = &testsuite_params;
6409 struct crypto_unittest_params *ut_params = &unittest_params;
6410 struct rte_mbuf *buf, *buf_oop = NULL, *buf_last_oop = NULL;
6413 int to_trn_tbl[SGL_MAX_NO];
6415 unsigned int trn_data = 0;
6416 uint8_t *plaintext, *ciphertext, *auth_tag;
6418 if (fragsz > tdata->plaintext.len)
6419 fragsz = tdata->plaintext.len;
6421 uint16_t plaintext_len = fragsz;
6422 uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz;
6424 if (fragsz_oop > tdata->plaintext.len)
6425 frag_size_oop = tdata->plaintext.len;
6428 void *digest_mem = NULL;
6430 uint32_t prepend_len = ALIGN_POW2_ROUNDUP(tdata->iv.len, 16)
6433 if (tdata->plaintext.len % fragsz != 0) {
6434 if (tdata->plaintext.len / fragsz + 1 > SGL_MAX_NO)
6437 if (tdata->plaintext.len / fragsz > SGL_MAX_NO)
6442 * For out-op-place we need to alloc another mbuf
6445 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6446 rte_pktmbuf_append(ut_params->obuf,
6447 frag_size_oop + prepend_len);
6448 buf_oop = ut_params->obuf;
6451 /* Create GCM session */
6452 retval = create_gcm_session(ts_params->valid_devs[0],
6453 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6454 tdata->key.data, tdata->key.len,
6455 tdata->aad.len, tdata->auth_tag.len,
6456 RTE_CRYPTO_AUTH_OP_GENERATE);
6460 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6462 /* clear mbuf payload */
6463 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
6464 rte_pktmbuf_tailroom(ut_params->ibuf));
6466 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6469 memcpy(plaintext, tdata->plaintext.data, plaintext_len);
6471 trn_data += plaintext_len;
6473 buf = ut_params->ibuf;
6476 * Loop until no more fragments
6479 while (trn_data < tdata->plaintext.len) {
6481 to_trn = (tdata->plaintext.len - trn_data < fragsz) ?
6482 (tdata->plaintext.len - trn_data) : fragsz;
6484 to_trn_tbl[ecx++] = to_trn;
6486 buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool);
6489 memset(rte_pktmbuf_mtod(buf, uint8_t *), 0,
6490 rte_pktmbuf_tailroom(buf));
6493 if (oop && !fragsz_oop) {
6494 buf_last_oop = buf_oop->next =
6495 rte_pktmbuf_alloc(ts_params->mbuf_pool);
6496 buf_oop = buf_oop->next;
6497 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
6498 0, rte_pktmbuf_tailroom(buf_oop));
6499 rte_pktmbuf_append(buf_oop, to_trn);
6502 plaintext = (uint8_t *)rte_pktmbuf_append(buf,
6505 memcpy(plaintext, tdata->plaintext.data + trn_data,
6508 if (trn_data == tdata->plaintext.len) {
6511 digest_mem = rte_pktmbuf_append(buf_oop,
6512 tdata->auth_tag.len);
6514 digest_mem = (uint8_t *)rte_pktmbuf_append(buf,
6515 tdata->auth_tag.len);
6519 uint64_t digest_phys = 0;
6521 ut_params->ibuf->nb_segs = segs;
6524 if (fragsz_oop && oop) {
6528 if (frag_size_oop == tdata->plaintext.len) {
6529 digest_mem = rte_pktmbuf_append(ut_params->obuf,
6530 tdata->auth_tag.len);
6532 digest_phys = rte_pktmbuf_mtophys_offset(
6534 tdata->plaintext.len + prepend_len);
6537 trn_data = frag_size_oop;
6538 while (trn_data < tdata->plaintext.len) {
6541 (tdata->plaintext.len - trn_data <
6543 (tdata->plaintext.len - trn_data) :
6546 to_trn_tbl[ecx++] = to_trn;
6548 buf_last_oop = buf_oop->next =
6549 rte_pktmbuf_alloc(ts_params->mbuf_pool);
6550 buf_oop = buf_oop->next;
6551 memset(rte_pktmbuf_mtod(buf_oop, uint8_t *),
6552 0, rte_pktmbuf_tailroom(buf_oop));
6553 rte_pktmbuf_append(buf_oop, to_trn);
6557 if (trn_data == tdata->plaintext.len) {
6558 digest_mem = rte_pktmbuf_append(buf_oop,
6559 tdata->auth_tag.len);
6563 ut_params->obuf->nb_segs = segs;
6567 * Place digest at the end of the last buffer
6570 digest_phys = rte_pktmbuf_mtophys(buf) + to_trn;
6571 if (oop && buf_last_oop)
6572 digest_phys = rte_pktmbuf_mtophys(buf_last_oop) + to_trn;
6574 if (!digest_mem && !oop) {
6575 digest_mem = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
6576 + tdata->auth_tag.len);
6577 digest_phys = rte_pktmbuf_mtophys_offset(ut_params->ibuf,
6578 tdata->plaintext.len);
6581 /* Create GCM opertaion */
6582 retval = create_gcm_operation_SGL(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
6583 tdata, digest_mem, digest_phys);
6588 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
6590 ut_params->op->sym->m_src = ut_params->ibuf;
6592 ut_params->op->sym->m_dst = ut_params->obuf;
6594 /* Process crypto operation */
6595 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
6596 ut_params->op), "failed to process sym crypto op");
6598 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
6599 "crypto op processing failed");
6602 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
6603 uint8_t *, prepend_len);
6605 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
6606 uint8_t *, prepend_len);
6610 fragsz = fragsz_oop;
6612 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6614 tdata->ciphertext.data,
6616 "GCM Ciphertext data not as expected");
6618 buf = ut_params->op->sym->m_src->next;
6620 buf = ut_params->op->sym->m_dst->next;
6622 unsigned int off = fragsz;
6626 ciphertext = rte_pktmbuf_mtod(buf,
6629 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6631 tdata->ciphertext.data + off,
6633 "GCM Ciphertext data not as expected");
6635 off += to_trn_tbl[ecx++];
6639 auth_tag = digest_mem;
6640 TEST_ASSERT_BUFFERS_ARE_EQUAL(
6642 tdata->auth_tag.data,
6643 tdata->auth_tag.len,
6644 "GCM Generated auth tag not as expected");
6650 #define OUT_OF_PLACE 1
6653 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B(void)
6655 return test_AES_GCM_authenticated_encryption_SGL(
6656 &gcm_test_case_SGL_1, OUT_OF_PLACE, 400, 400);
6660 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B(void)
6662 return test_AES_GCM_authenticated_encryption_SGL(
6663 &gcm_test_case_SGL_1, OUT_OF_PLACE, 1500, 2000);
6667 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg(void)
6669 return test_AES_GCM_authenticated_encryption_SGL(
6670 &gcm_test_case_8, OUT_OF_PLACE, 400,
6671 gcm_test_case_8.plaintext.len);
6675 test_AES_GCM_auth_encrypt_SGL_in_place_1500B(void)
6678 return test_AES_GCM_authenticated_encryption_SGL(
6679 &gcm_test_case_SGL_1, IN_PLACE, 1500, 0);
6683 test_authentication_verify_fail_when_data_corrupted(
6684 struct crypto_testsuite_params *ts_params,
6685 struct crypto_unittest_params *ut_params,
6686 const struct test_crypto_vector *reference)
6688 return test_authentication_verify_fail_when_data_corruption(
6689 ts_params, ut_params, reference, 1);
6693 test_authentication_verify_fail_when_tag_corrupted(
6694 struct crypto_testsuite_params *ts_params,
6695 struct crypto_unittest_params *ut_params,
6696 const struct test_crypto_vector *reference)
6698 return test_authentication_verify_fail_when_data_corruption(
6699 ts_params, ut_params, reference, 0);
6703 test_authentication_verify_GMAC_fail_when_data_corrupted(
6704 struct crypto_testsuite_params *ts_params,
6705 struct crypto_unittest_params *ut_params,
6706 const struct test_crypto_vector *reference)
6708 return test_authentication_verify_GMAC_fail_when_corruption(
6709 ts_params, ut_params, reference, 1);
6713 test_authentication_verify_GMAC_fail_when_tag_corrupted(
6714 struct crypto_testsuite_params *ts_params,
6715 struct crypto_unittest_params *ut_params,
6716 const struct test_crypto_vector *reference)
6718 return test_authentication_verify_GMAC_fail_when_corruption(
6719 ts_params, ut_params, reference, 0);
6723 test_authenticated_decryption_fail_when_data_corrupted(
6724 struct crypto_testsuite_params *ts_params,
6725 struct crypto_unittest_params *ut_params,
6726 const struct test_crypto_vector *reference)
6728 return test_authenticated_decryption_fail_when_corruption(
6729 ts_params, ut_params, reference, 1);
6733 test_authenticated_decryption_fail_when_tag_corrupted(
6734 struct crypto_testsuite_params *ts_params,
6735 struct crypto_unittest_params *ut_params,
6736 const struct test_crypto_vector *reference)
6738 return test_authenticated_decryption_fail_when_corruption(
6739 ts_params, ut_params, reference, 0);
6743 authentication_verify_HMAC_SHA1_fail_data_corrupt(void)
6745 return test_authentication_verify_fail_when_data_corrupted(
6746 &testsuite_params, &unittest_params,
6747 &hmac_sha1_test_crypto_vector);
6751 authentication_verify_HMAC_SHA1_fail_tag_corrupt(void)
6753 return test_authentication_verify_fail_when_tag_corrupted(
6754 &testsuite_params, &unittest_params,
6755 &hmac_sha1_test_crypto_vector);
6759 authentication_verify_AES128_GMAC_fail_data_corrupt(void)
6761 return test_authentication_verify_GMAC_fail_when_data_corrupted(
6762 &testsuite_params, &unittest_params,
6763 &aes128_gmac_test_vector);
6767 authentication_verify_AES128_GMAC_fail_tag_corrupt(void)
6769 return test_authentication_verify_GMAC_fail_when_tag_corrupted(
6770 &testsuite_params, &unittest_params,
6771 &aes128_gmac_test_vector);
6775 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt(void)
6777 return test_authenticated_decryption_fail_when_data_corrupted(
6780 &aes128cbc_hmac_sha1_test_vector);
6784 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt(void)
6786 return test_authenticated_decryption_fail_when_tag_corrupted(
6789 &aes128cbc_hmac_sha1_test_vector);
6792 static struct unit_test_suite cryptodev_qat_testsuite = {
6793 .suite_name = "Crypto QAT Unit Test Suite",
6794 .setup = testsuite_setup,
6795 .teardown = testsuite_teardown,
6796 .unit_test_cases = {
6797 TEST_CASE_ST(ut_setup, ut_teardown,
6798 test_device_configure_invalid_dev_id),
6799 TEST_CASE_ST(ut_setup, ut_teardown,
6800 test_device_configure_invalid_queue_pair_ids),
6801 TEST_CASE_ST(ut_setup, ut_teardown,
6802 test_queue_pair_descriptor_setup),
6803 TEST_CASE_ST(ut_setup, ut_teardown,
6804 test_multi_session),
6806 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_qat_all),
6807 TEST_CASE_ST(ut_setup, ut_teardown,
6808 test_AES_cipheronly_qat_all),
6809 TEST_CASE_ST(ut_setup, ut_teardown, test_3DES_chain_qat_all),
6810 TEST_CASE_ST(ut_setup, ut_teardown,
6811 test_3DES_cipheronly_qat_all),
6812 TEST_CASE_ST(ut_setup, ut_teardown,
6813 test_DES_cipheronly_qat_all),
6814 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
6816 /** AES GCM Authenticated Encryption */
6817 TEST_CASE_ST(ut_setup, ut_teardown,
6818 test_AES_GCM_auth_encrypt_SGL_in_place_1500B),
6819 TEST_CASE_ST(ut_setup, ut_teardown,
6820 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_400B),
6821 TEST_CASE_ST(ut_setup, ut_teardown,
6822 test_AES_GCM_auth_encrypt_SGL_out_of_place_1500B_2000B),
6823 TEST_CASE_ST(ut_setup, ut_teardown,
6824 test_mb_AES_GCM_authenticated_encryption_test_case_1),
6825 TEST_CASE_ST(ut_setup, ut_teardown,
6826 test_mb_AES_GCM_authenticated_encryption_test_case_2),
6827 TEST_CASE_ST(ut_setup, ut_teardown,
6828 test_mb_AES_GCM_authenticated_encryption_test_case_3),
6829 TEST_CASE_ST(ut_setup, ut_teardown,
6830 test_mb_AES_GCM_authenticated_encryption_test_case_4),
6831 TEST_CASE_ST(ut_setup, ut_teardown,
6832 test_mb_AES_GCM_authenticated_encryption_test_case_5),
6833 TEST_CASE_ST(ut_setup, ut_teardown,
6834 test_mb_AES_GCM_authenticated_encryption_test_case_6),
6835 TEST_CASE_ST(ut_setup, ut_teardown,
6836 test_mb_AES_GCM_authenticated_encryption_test_case_7),
6838 /** AES GCM Authenticated Decryption */
6839 TEST_CASE_ST(ut_setup, ut_teardown,
6840 test_mb_AES_GCM_authenticated_decryption_test_case_1),
6841 TEST_CASE_ST(ut_setup, ut_teardown,
6842 test_mb_AES_GCM_authenticated_decryption_test_case_2),
6843 TEST_CASE_ST(ut_setup, ut_teardown,
6844 test_mb_AES_GCM_authenticated_decryption_test_case_3),
6845 TEST_CASE_ST(ut_setup, ut_teardown,
6846 test_mb_AES_GCM_authenticated_decryption_test_case_4),
6847 TEST_CASE_ST(ut_setup, ut_teardown,
6848 test_mb_AES_GCM_authenticated_decryption_test_case_5),
6849 TEST_CASE_ST(ut_setup, ut_teardown,
6850 test_mb_AES_GCM_authenticated_decryption_test_case_6),
6851 TEST_CASE_ST(ut_setup, ut_teardown,
6852 test_mb_AES_GCM_authenticated_decryption_test_case_7),
6854 /** AES GMAC Authentication */
6855 TEST_CASE_ST(ut_setup, ut_teardown,
6856 test_AES_GMAC_authentication_test_case_1),
6857 TEST_CASE_ST(ut_setup, ut_teardown,
6858 test_AES_GMAC_authentication_verify_test_case_1),
6859 TEST_CASE_ST(ut_setup, ut_teardown,
6860 test_AES_GMAC_authentication_test_case_2),
6861 TEST_CASE_ST(ut_setup, ut_teardown,
6862 test_AES_GMAC_authentication_verify_test_case_2),
6863 TEST_CASE_ST(ut_setup, ut_teardown,
6864 test_AES_GMAC_authentication_test_case_3),
6865 TEST_CASE_ST(ut_setup, ut_teardown,
6866 test_AES_GMAC_authentication_verify_test_case_3),
6868 /** SNOW 3G encrypt only (UEA2) */
6869 TEST_CASE_ST(ut_setup, ut_teardown,
6870 test_snow3g_encryption_test_case_1),
6871 TEST_CASE_ST(ut_setup, ut_teardown,
6872 test_snow3g_encryption_test_case_2),
6873 TEST_CASE_ST(ut_setup, ut_teardown,
6874 test_snow3g_encryption_test_case_3),
6875 TEST_CASE_ST(ut_setup, ut_teardown,
6876 test_snow3g_encryption_test_case_4),
6877 TEST_CASE_ST(ut_setup, ut_teardown,
6878 test_snow3g_encryption_test_case_5),
6880 TEST_CASE_ST(ut_setup, ut_teardown,
6881 test_snow3g_encryption_test_case_1_oop),
6882 TEST_CASE_ST(ut_setup, ut_teardown,
6883 test_snow3g_decryption_test_case_1_oop),
6885 /** SNOW 3G decrypt only (UEA2) */
6886 TEST_CASE_ST(ut_setup, ut_teardown,
6887 test_snow3g_decryption_test_case_1),
6888 TEST_CASE_ST(ut_setup, ut_teardown,
6889 test_snow3g_decryption_test_case_2),
6890 TEST_CASE_ST(ut_setup, ut_teardown,
6891 test_snow3g_decryption_test_case_3),
6892 TEST_CASE_ST(ut_setup, ut_teardown,
6893 test_snow3g_decryption_test_case_4),
6894 TEST_CASE_ST(ut_setup, ut_teardown,
6895 test_snow3g_decryption_test_case_5),
6896 TEST_CASE_ST(ut_setup, ut_teardown,
6897 test_snow3g_hash_generate_test_case_1),
6898 TEST_CASE_ST(ut_setup, ut_teardown,
6899 test_snow3g_hash_generate_test_case_2),
6900 TEST_CASE_ST(ut_setup, ut_teardown,
6901 test_snow3g_hash_generate_test_case_3),
6902 TEST_CASE_ST(ut_setup, ut_teardown,
6903 test_snow3g_hash_verify_test_case_1),
6904 TEST_CASE_ST(ut_setup, ut_teardown,
6905 test_snow3g_hash_verify_test_case_2),
6906 TEST_CASE_ST(ut_setup, ut_teardown,
6907 test_snow3g_hash_verify_test_case_3),
6908 TEST_CASE_ST(ut_setup, ut_teardown,
6909 test_snow3g_cipher_auth_test_case_1),
6910 TEST_CASE_ST(ut_setup, ut_teardown,
6911 test_snow3g_auth_cipher_test_case_1),
6913 /** HMAC_MD5 Authentication */
6914 TEST_CASE_ST(ut_setup, ut_teardown,
6915 test_MD5_HMAC_generate_case_1),
6916 TEST_CASE_ST(ut_setup, ut_teardown,
6917 test_MD5_HMAC_verify_case_1),
6918 TEST_CASE_ST(ut_setup, ut_teardown,
6919 test_MD5_HMAC_generate_case_2),
6920 TEST_CASE_ST(ut_setup, ut_teardown,
6921 test_MD5_HMAC_verify_case_2),
6924 TEST_CASE_ST(ut_setup, ut_teardown,
6925 test_null_auth_only_operation),
6926 TEST_CASE_ST(ut_setup, ut_teardown,
6927 test_null_cipher_only_operation),
6928 TEST_CASE_ST(ut_setup, ut_teardown,
6929 test_null_cipher_auth_operation),
6930 TEST_CASE_ST(ut_setup, ut_teardown,
6931 test_null_auth_cipher_operation),
6933 TEST_CASE_ST(ut_setup, ut_teardown,
6934 test_kasumi_hash_generate_test_case_6),
6937 TEST_CASE_ST(ut_setup, ut_teardown,
6938 test_kasumi_encryption_test_case_1),
6939 TEST_CASE_ST(ut_setup, ut_teardown,
6940 test_kasumi_encryption_test_case_3),
6941 TEST_CASE_ST(ut_setup, ut_teardown,
6942 test_kasumi_auth_cipher_test_case_1),
6943 TEST_CASE_ST(ut_setup, ut_teardown,
6944 test_kasumi_cipher_auth_test_case_1),
6946 /** Negative tests */
6947 TEST_CASE_ST(ut_setup, ut_teardown,
6948 authentication_verify_HMAC_SHA1_fail_data_corrupt),
6949 TEST_CASE_ST(ut_setup, ut_teardown,
6950 authentication_verify_HMAC_SHA1_fail_tag_corrupt),
6951 TEST_CASE_ST(ut_setup, ut_teardown,
6952 authentication_verify_AES128_GMAC_fail_data_corrupt),
6953 TEST_CASE_ST(ut_setup, ut_teardown,
6954 authentication_verify_AES128_GMAC_fail_tag_corrupt),
6955 TEST_CASE_ST(ut_setup, ut_teardown,
6956 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
6957 TEST_CASE_ST(ut_setup, ut_teardown,
6958 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
6960 TEST_CASES_END() /**< NULL terminate unit test array */
6964 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
6965 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
6966 .setup = testsuite_setup,
6967 .teardown = testsuite_teardown,
6968 .unit_test_cases = {
6969 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_chain_mb_all),
6970 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_cipheronly_mb_all),
6971 TEST_CASE_ST(ut_setup, ut_teardown, test_authonly_mb_all),
6973 TEST_CASES_END() /**< NULL terminate unit test array */
6977 static struct unit_test_suite cryptodev_openssl_testsuite = {
6978 .suite_name = "Crypto Device OPENSSL Unit Test Suite",
6979 .setup = testsuite_setup,
6980 .teardown = testsuite_teardown,
6981 .unit_test_cases = {
6982 TEST_CASE_ST(ut_setup, ut_teardown, test_multi_session),
6983 TEST_CASE_ST(ut_setup, ut_teardown,
6984 test_multi_session_random_usage),
6985 TEST_CASE_ST(ut_setup, ut_teardown,
6986 test_AES_chain_openssl_all),
6987 TEST_CASE_ST(ut_setup, ut_teardown,
6988 test_AES_cipheronly_openssl_all),
6989 TEST_CASE_ST(ut_setup, ut_teardown,
6990 test_3DES_chain_openssl_all),
6991 TEST_CASE_ST(ut_setup, ut_teardown,
6992 test_3DES_cipheronly_openssl_all),
6993 TEST_CASE_ST(ut_setup, ut_teardown,
6994 test_authonly_openssl_all),
6996 /** AES GCM Authenticated Encryption */
6997 TEST_CASE_ST(ut_setup, ut_teardown,
6998 test_mb_AES_GCM_authenticated_encryption_test_case_1),
6999 TEST_CASE_ST(ut_setup, ut_teardown,
7000 test_mb_AES_GCM_authenticated_encryption_test_case_2),
7001 TEST_CASE_ST(ut_setup, ut_teardown,
7002 test_mb_AES_GCM_authenticated_encryption_test_case_3),
7003 TEST_CASE_ST(ut_setup, ut_teardown,
7004 test_mb_AES_GCM_authenticated_encryption_test_case_4),
7005 TEST_CASE_ST(ut_setup, ut_teardown,
7006 test_mb_AES_GCM_authenticated_encryption_test_case_5),
7007 TEST_CASE_ST(ut_setup, ut_teardown,
7008 test_mb_AES_GCM_authenticated_encryption_test_case_6),
7009 TEST_CASE_ST(ut_setup, ut_teardown,
7010 test_mb_AES_GCM_authenticated_encryption_test_case_7),
7012 /** AES GCM Authenticated Decryption */
7013 TEST_CASE_ST(ut_setup, ut_teardown,
7014 test_mb_AES_GCM_authenticated_decryption_test_case_1),
7015 TEST_CASE_ST(ut_setup, ut_teardown,
7016 test_mb_AES_GCM_authenticated_decryption_test_case_2),
7017 TEST_CASE_ST(ut_setup, ut_teardown,
7018 test_mb_AES_GCM_authenticated_decryption_test_case_3),
7019 TEST_CASE_ST(ut_setup, ut_teardown,
7020 test_mb_AES_GCM_authenticated_decryption_test_case_4),
7021 TEST_CASE_ST(ut_setup, ut_teardown,
7022 test_mb_AES_GCM_authenticated_decryption_test_case_5),
7023 TEST_CASE_ST(ut_setup, ut_teardown,
7024 test_mb_AES_GCM_authenticated_decryption_test_case_6),
7025 TEST_CASE_ST(ut_setup, ut_teardown,
7026 test_mb_AES_GCM_authenticated_decryption_test_case_7),
7028 /** AES GMAC Authentication */
7029 TEST_CASE_ST(ut_setup, ut_teardown,
7030 test_AES_GMAC_authentication_test_case_1),
7031 TEST_CASE_ST(ut_setup, ut_teardown,
7032 test_AES_GMAC_authentication_verify_test_case_1),
7033 TEST_CASE_ST(ut_setup, ut_teardown,
7034 test_AES_GMAC_authentication_test_case_2),
7035 TEST_CASE_ST(ut_setup, ut_teardown,
7036 test_AES_GMAC_authentication_verify_test_case_2),
7037 TEST_CASE_ST(ut_setup, ut_teardown,
7038 test_AES_GMAC_authentication_test_case_3),
7039 TEST_CASE_ST(ut_setup, ut_teardown,
7040 test_AES_GMAC_authentication_verify_test_case_3),
7041 TEST_CASE_ST(ut_setup, ut_teardown,
7042 test_AES_GMAC_authentication_test_case_4),
7043 TEST_CASE_ST(ut_setup, ut_teardown,
7044 test_AES_GMAC_authentication_verify_test_case_4),
7046 /** Scatter-Gather */
7047 TEST_CASE_ST(ut_setup, ut_teardown,
7048 test_AES_GCM_auth_encrypt_SGL_out_of_place_400B_1seg),
7050 /** Negative tests */
7051 TEST_CASE_ST(ut_setup, ut_teardown,
7052 authentication_verify_HMAC_SHA1_fail_data_corrupt),
7053 TEST_CASE_ST(ut_setup, ut_teardown,
7054 authentication_verify_HMAC_SHA1_fail_tag_corrupt),
7055 TEST_CASE_ST(ut_setup, ut_teardown,
7056 authentication_verify_AES128_GMAC_fail_data_corrupt),
7057 TEST_CASE_ST(ut_setup, ut_teardown,
7058 authentication_verify_AES128_GMAC_fail_tag_corrupt),
7059 TEST_CASE_ST(ut_setup, ut_teardown,
7060 auth_decryption_AES128CBC_HMAC_SHA1_fail_data_corrupt),
7061 TEST_CASE_ST(ut_setup, ut_teardown,
7062 auth_decryption_AES128CBC_HMAC_SHA1_fail_tag_corrupt),
7064 TEST_CASES_END() /**< NULL terminate unit test array */
7068 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
7069 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
7070 .setup = testsuite_setup,
7071 .teardown = testsuite_teardown,
7072 .unit_test_cases = {
7073 /** AES GCM Authenticated Encryption */
7074 TEST_CASE_ST(ut_setup, ut_teardown,
7075 test_mb_AES_GCM_authenticated_encryption_test_case_1),
7076 TEST_CASE_ST(ut_setup, ut_teardown,
7077 test_mb_AES_GCM_authenticated_encryption_test_case_2),
7078 TEST_CASE_ST(ut_setup, ut_teardown,
7079 test_mb_AES_GCM_authenticated_encryption_test_case_3),
7080 TEST_CASE_ST(ut_setup, ut_teardown,
7081 test_mb_AES_GCM_authenticated_encryption_test_case_4),
7082 TEST_CASE_ST(ut_setup, ut_teardown,
7083 test_mb_AES_GCM_authenticated_encryption_test_case_5),
7084 TEST_CASE_ST(ut_setup, ut_teardown,
7085 test_mb_AES_GCM_authenticated_encryption_test_case_6),
7086 TEST_CASE_ST(ut_setup, ut_teardown,
7087 test_mb_AES_GCM_authenticated_encryption_test_case_7),
7089 /** AES GCM Authenticated Decryption */
7090 TEST_CASE_ST(ut_setup, ut_teardown,
7091 test_mb_AES_GCM_authenticated_decryption_test_case_1),
7092 TEST_CASE_ST(ut_setup, ut_teardown,
7093 test_mb_AES_GCM_authenticated_decryption_test_case_2),
7094 TEST_CASE_ST(ut_setup, ut_teardown,
7095 test_mb_AES_GCM_authenticated_decryption_test_case_3),
7096 TEST_CASE_ST(ut_setup, ut_teardown,
7097 test_mb_AES_GCM_authenticated_decryption_test_case_4),
7098 TEST_CASE_ST(ut_setup, ut_teardown,
7099 test_mb_AES_GCM_authenticated_decryption_test_case_5),
7100 TEST_CASE_ST(ut_setup, ut_teardown,
7101 test_mb_AES_GCM_authenticated_decryption_test_case_6),
7102 TEST_CASE_ST(ut_setup, ut_teardown,
7103 test_mb_AES_GCM_authenticated_decryption_test_case_7),
7105 TEST_CASES_END() /**< NULL terminate unit test array */
7109 static struct unit_test_suite cryptodev_sw_kasumi_testsuite = {
7110 .suite_name = "Crypto Device SW KASUMI Unit Test Suite",
7111 .setup = testsuite_setup,
7112 .teardown = testsuite_teardown,
7113 .unit_test_cases = {
7114 /** KASUMI encrypt only (UEA1) */
7115 TEST_CASE_ST(ut_setup, ut_teardown,
7116 test_kasumi_encryption_test_case_1),
7117 TEST_CASE_ST(ut_setup, ut_teardown,
7118 test_kasumi_encryption_test_case_1_sgl),
7119 TEST_CASE_ST(ut_setup, ut_teardown,
7120 test_kasumi_encryption_test_case_2),
7121 TEST_CASE_ST(ut_setup, ut_teardown,
7122 test_kasumi_encryption_test_case_3),
7123 TEST_CASE_ST(ut_setup, ut_teardown,
7124 test_kasumi_encryption_test_case_4),
7125 TEST_CASE_ST(ut_setup, ut_teardown,
7126 test_kasumi_encryption_test_case_5),
7127 /** KASUMI decrypt only (UEA1) */
7128 TEST_CASE_ST(ut_setup, ut_teardown,
7129 test_kasumi_decryption_test_case_1),
7130 TEST_CASE_ST(ut_setup, ut_teardown,
7131 test_kasumi_decryption_test_case_2),
7132 TEST_CASE_ST(ut_setup, ut_teardown,
7133 test_kasumi_decryption_test_case_3),
7134 TEST_CASE_ST(ut_setup, ut_teardown,
7135 test_kasumi_decryption_test_case_4),
7136 TEST_CASE_ST(ut_setup, ut_teardown,
7137 test_kasumi_decryption_test_case_5),
7139 TEST_CASE_ST(ut_setup, ut_teardown,
7140 test_kasumi_encryption_test_case_1_oop),
7141 TEST_CASE_ST(ut_setup, ut_teardown,
7142 test_kasumi_encryption_test_case_1_oop_sgl),
7145 TEST_CASE_ST(ut_setup, ut_teardown,
7146 test_kasumi_decryption_test_case_1_oop),
7148 /** KASUMI hash only (UIA1) */
7149 TEST_CASE_ST(ut_setup, ut_teardown,
7150 test_kasumi_hash_generate_test_case_1),
7151 TEST_CASE_ST(ut_setup, ut_teardown,
7152 test_kasumi_hash_generate_test_case_2),
7153 TEST_CASE_ST(ut_setup, ut_teardown,
7154 test_kasumi_hash_generate_test_case_3),
7155 TEST_CASE_ST(ut_setup, ut_teardown,
7156 test_kasumi_hash_generate_test_case_4),
7157 TEST_CASE_ST(ut_setup, ut_teardown,
7158 test_kasumi_hash_generate_test_case_5),
7159 TEST_CASE_ST(ut_setup, ut_teardown,
7160 test_kasumi_hash_generate_test_case_6),
7161 TEST_CASE_ST(ut_setup, ut_teardown,
7162 test_kasumi_hash_verify_test_case_1),
7163 TEST_CASE_ST(ut_setup, ut_teardown,
7164 test_kasumi_hash_verify_test_case_2),
7165 TEST_CASE_ST(ut_setup, ut_teardown,
7166 test_kasumi_hash_verify_test_case_3),
7167 TEST_CASE_ST(ut_setup, ut_teardown,
7168 test_kasumi_hash_verify_test_case_4),
7169 TEST_CASE_ST(ut_setup, ut_teardown,
7170 test_kasumi_hash_verify_test_case_5),
7171 TEST_CASE_ST(ut_setup, ut_teardown,
7172 test_kasumi_auth_cipher_test_case_1),
7173 TEST_CASE_ST(ut_setup, ut_teardown,
7174 test_kasumi_cipher_auth_test_case_1),
7175 TEST_CASES_END() /**< NULL terminate unit test array */
7178 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
7179 .suite_name = "Crypto Device SW SNOW 3G Unit Test Suite",
7180 .setup = testsuite_setup,
7181 .teardown = testsuite_teardown,
7182 .unit_test_cases = {
7183 /** SNOW 3G encrypt only (UEA2) */
7184 TEST_CASE_ST(ut_setup, ut_teardown,
7185 test_snow3g_encryption_test_case_1),
7186 TEST_CASE_ST(ut_setup, ut_teardown,
7187 test_snow3g_encryption_test_case_2),
7188 TEST_CASE_ST(ut_setup, ut_teardown,
7189 test_snow3g_encryption_test_case_3),
7190 TEST_CASE_ST(ut_setup, ut_teardown,
7191 test_snow3g_encryption_test_case_4),
7192 TEST_CASE_ST(ut_setup, ut_teardown,
7193 test_snow3g_encryption_test_case_5),
7195 TEST_CASE_ST(ut_setup, ut_teardown,
7196 test_snow3g_encryption_test_case_1_oop),
7197 TEST_CASE_ST(ut_setup, ut_teardown,
7198 test_snow3g_encryption_test_case_1_oop_sgl),
7199 TEST_CASE_ST(ut_setup, ut_teardown,
7200 test_snow3g_decryption_test_case_1_oop),
7202 TEST_CASE_ST(ut_setup, ut_teardown,
7203 test_snow3g_encryption_test_case_1_offset_oop),
7205 /** SNOW 3G decrypt only (UEA2) */
7206 TEST_CASE_ST(ut_setup, ut_teardown,
7207 test_snow3g_decryption_test_case_1),
7208 TEST_CASE_ST(ut_setup, ut_teardown,
7209 test_snow3g_decryption_test_case_2),
7210 TEST_CASE_ST(ut_setup, ut_teardown,
7211 test_snow3g_decryption_test_case_3),
7212 TEST_CASE_ST(ut_setup, ut_teardown,
7213 test_snow3g_decryption_test_case_4),
7214 TEST_CASE_ST(ut_setup, ut_teardown,
7215 test_snow3g_decryption_test_case_5),
7216 TEST_CASE_ST(ut_setup, ut_teardown,
7217 test_snow3g_hash_generate_test_case_1),
7218 TEST_CASE_ST(ut_setup, ut_teardown,
7219 test_snow3g_hash_generate_test_case_2),
7220 TEST_CASE_ST(ut_setup, ut_teardown,
7221 test_snow3g_hash_generate_test_case_3),
7222 /* Tests with buffers which length is not byte-aligned */
7223 TEST_CASE_ST(ut_setup, ut_teardown,
7224 test_snow3g_hash_generate_test_case_4),
7225 TEST_CASE_ST(ut_setup, ut_teardown,
7226 test_snow3g_hash_generate_test_case_5),
7227 TEST_CASE_ST(ut_setup, ut_teardown,
7228 test_snow3g_hash_generate_test_case_6),
7229 TEST_CASE_ST(ut_setup, ut_teardown,
7230 test_snow3g_hash_verify_test_case_1),
7231 TEST_CASE_ST(ut_setup, ut_teardown,
7232 test_snow3g_hash_verify_test_case_2),
7233 TEST_CASE_ST(ut_setup, ut_teardown,
7234 test_snow3g_hash_verify_test_case_3),
7235 /* Tests with buffers which length is not byte-aligned */
7236 TEST_CASE_ST(ut_setup, ut_teardown,
7237 test_snow3g_hash_verify_test_case_4),
7238 TEST_CASE_ST(ut_setup, ut_teardown,
7239 test_snow3g_hash_verify_test_case_5),
7240 TEST_CASE_ST(ut_setup, ut_teardown,
7241 test_snow3g_hash_verify_test_case_6),
7242 TEST_CASE_ST(ut_setup, ut_teardown,
7243 test_snow3g_cipher_auth_test_case_1),
7244 TEST_CASE_ST(ut_setup, ut_teardown,
7245 test_snow3g_auth_cipher_test_case_1),
7247 TEST_CASES_END() /**< NULL terminate unit test array */
7251 static struct unit_test_suite cryptodev_sw_zuc_testsuite = {
7252 .suite_name = "Crypto Device SW ZUC Unit Test Suite",
7253 .setup = testsuite_setup,
7254 .teardown = testsuite_teardown,
7255 .unit_test_cases = {
7256 /** ZUC encrypt only (EEA3) */
7257 TEST_CASE_ST(ut_setup, ut_teardown,
7258 test_zuc_encryption_test_case_1),
7259 TEST_CASE_ST(ut_setup, ut_teardown,
7260 test_zuc_encryption_test_case_2),
7261 TEST_CASE_ST(ut_setup, ut_teardown,
7262 test_zuc_encryption_test_case_3),
7263 TEST_CASE_ST(ut_setup, ut_teardown,
7264 test_zuc_encryption_test_case_4),
7265 TEST_CASE_ST(ut_setup, ut_teardown,
7266 test_zuc_encryption_test_case_5),
7267 TEST_CASE_ST(ut_setup, ut_teardown,
7268 test_zuc_hash_generate_test_case_1),
7269 TEST_CASE_ST(ut_setup, ut_teardown,
7270 test_zuc_hash_generate_test_case_2),
7271 TEST_CASE_ST(ut_setup, ut_teardown,
7272 test_zuc_hash_generate_test_case_3),
7273 TEST_CASE_ST(ut_setup, ut_teardown,
7274 test_zuc_hash_generate_test_case_4),
7275 TEST_CASE_ST(ut_setup, ut_teardown,
7276 test_zuc_hash_generate_test_case_5),
7277 TEST_CASE_ST(ut_setup, ut_teardown,
7278 test_zuc_encryption_test_case_6_sgl),
7279 TEST_CASES_END() /**< NULL terminate unit test array */
7283 static struct unit_test_suite cryptodev_null_testsuite = {
7284 .suite_name = "Crypto Device NULL Unit Test Suite",
7285 .setup = testsuite_setup,
7286 .teardown = testsuite_teardown,
7287 .unit_test_cases = {
7288 TEST_CASE_ST(ut_setup, ut_teardown,
7289 test_null_auth_only_operation),
7290 TEST_CASE_ST(ut_setup, ut_teardown,
7291 test_null_cipher_only_operation),
7292 TEST_CASE_ST(ut_setup, ut_teardown,
7293 test_null_cipher_auth_operation),
7294 TEST_CASE_ST(ut_setup, ut_teardown,
7295 test_null_auth_cipher_operation),
7296 TEST_CASE_ST(ut_setup, ut_teardown,
7297 test_null_invalid_operation),
7298 TEST_CASE_ST(ut_setup, ut_teardown,
7299 test_null_burst_operation),
7301 TEST_CASES_END() /**< NULL terminate unit test array */
7306 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
7308 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
7309 return unit_test_suite_runner(&cryptodev_qat_testsuite);
7313 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
7315 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
7317 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
7321 test_cryptodev_openssl(void)
7323 gbl_cryptodev_type = RTE_CRYPTODEV_OPENSSL_PMD;
7325 return unit_test_suite_runner(&cryptodev_openssl_testsuite);
7329 test_cryptodev_aesni_gcm(void)
7331 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
7333 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
7337 test_cryptodev_null(void)
7339 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
7341 return unit_test_suite_runner(&cryptodev_null_testsuite);
7345 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
7347 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
7349 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
7353 test_cryptodev_sw_kasumi(void /*argv __rte_unused, int argc __rte_unused*/)
7355 gbl_cryptodev_type = RTE_CRYPTODEV_KASUMI_PMD;
7357 return unit_test_suite_runner(&cryptodev_sw_kasumi_testsuite);
7361 test_cryptodev_sw_zuc(void /*argv __rte_unused, int argc __rte_unused*/)
7363 gbl_cryptodev_type = RTE_CRYPTODEV_ZUC_PMD;
7365 return unit_test_suite_runner(&cryptodev_sw_zuc_testsuite);
7368 REGISTER_TEST_COMMAND(cryptodev_qat_autotest, test_cryptodev_qat);
7369 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_autotest, test_cryptodev_aesni_mb);
7370 REGISTER_TEST_COMMAND(cryptodev_openssl_autotest, test_cryptodev_openssl);
7371 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_autotest, test_cryptodev_aesni_gcm);
7372 REGISTER_TEST_COMMAND(cryptodev_null_autotest, test_cryptodev_null);
7373 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_autotest, test_cryptodev_sw_snow3g);
7374 REGISTER_TEST_COMMAND(cryptodev_sw_kasumi_autotest, test_cryptodev_sw_kasumi);
7375 REGISTER_TEST_COMMAND(cryptodev_sw_zuc_autotest, test_cryptodev_sw_zuc);