4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
44 #include "test_cryptodev.h"
46 #include "test_cryptodev_aes.h"
47 #include "test_cryptodev_snow3g_test_vectors.h"
48 #include "test_cryptodev_snow3g_hash_test_vectors.h"
49 #include "test_cryptodev_gcm_test_vectors.h"
51 static enum rte_cryptodev_type gbl_cryptodev_type;
53 struct crypto_testsuite_params {
54 struct rte_mempool *mbuf_pool;
55 struct rte_mempool *op_mpool;
56 struct rte_cryptodev_config conf;
57 struct rte_cryptodev_qp_conf qp_conf;
59 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
60 uint8_t valid_dev_count;
63 struct crypto_unittest_params {
64 struct rte_crypto_sym_xform cipher_xform;
65 struct rte_crypto_sym_xform auth_xform;
67 struct rte_cryptodev_sym_session *sess;
69 struct rte_crypto_op *op;
71 struct rte_mbuf *obuf, *ibuf;
76 #define ALIGN_POW2_ROUNDUP(num, align) \
77 (((num) + (align) - 1) & ~((align) - 1))
80 * Forward declarations.
83 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
84 struct crypto_unittest_params *ut_params);
87 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
88 struct crypto_unittest_params *ut_params,
89 struct crypto_testsuite_params *ts_param);
91 static struct rte_mbuf *
92 setup_test_string(struct rte_mempool *mpool,
93 const char *string, size_t len, uint8_t blocksize)
95 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
96 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
98 memset(m->buf_addr, 0, m->buf_len);
100 char *dst = rte_pktmbuf_append(m, t_len);
107 rte_memcpy(dst, string, t_len);
109 memset(dst, 0, t_len);
115 static struct rte_crypto_op *
116 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
118 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
119 printf("Error sending packet for encryption");
125 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
131 static struct crypto_testsuite_params testsuite_params = { NULL };
132 static struct crypto_unittest_params unittest_params;
135 testsuite_setup(void)
137 struct crypto_testsuite_params *ts_params = &testsuite_params;
138 struct rte_cryptodev_info info;
139 unsigned i, nb_devs, dev_id;
143 memset(ts_params, 0, sizeof(*ts_params));
145 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
146 if (ts_params->mbuf_pool == NULL) {
147 /* Not already created so create */
148 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
150 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
152 if (ts_params->mbuf_pool == NULL) {
153 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
158 ts_params->op_mpool = rte_crypto_op_pool_create(
159 "MBUF_CRYPTO_SYM_OP_POOL",
160 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
161 NUM_MBUFS, MBUF_CACHE_SIZE,
163 sizeof(struct rte_crypto_sym_xform),
165 if (ts_params->op_mpool == NULL) {
166 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
170 /* Create 2 AESNI MB devices if required */
171 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
172 nb_devs = rte_cryptodev_count_devtype(
173 RTE_CRYPTODEV_AESNI_MB_PMD);
175 for (i = nb_devs; i < 2; i++) {
176 ret = rte_eal_vdev_init(
177 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
179 TEST_ASSERT(ret == 0,
180 "Failed to create instance %u of"
182 i, CRYPTODEV_NAME_AESNI_MB_PMD);
187 /* Create 2 AESNI GCM devices if required */
188 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
189 nb_devs = rte_cryptodev_count_devtype(
190 RTE_CRYPTODEV_AESNI_GCM_PMD);
192 for (i = nb_devs; i < 2; i++) {
193 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
194 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
195 "Failed to create instance %u of"
197 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
202 /* Create 2 Snow3G devices if required */
203 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
204 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
206 for (i = nb_devs; i < 2; i++) {
207 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
208 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
209 "Failed to create instance %u of"
211 i, CRYPTODEV_NAME_SNOW3G_PMD);
216 /* Create 2 NULL devices if required */
217 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
218 nb_devs = rte_cryptodev_count_devtype(
219 RTE_CRYPTODEV_NULL_PMD);
221 for (i = nb_devs; i < 2; i++) {
222 int dev_id = rte_eal_vdev_init(
223 CRYPTODEV_NAME_NULL_PMD, NULL);
225 TEST_ASSERT(dev_id >= 0,
226 "Failed to create instance %u of"
228 i, CRYPTODEV_NAME_NULL_PMD);
233 nb_devs = rte_cryptodev_count();
235 RTE_LOG(ERR, USER1, "No crypto devices found?");
239 /* Create list of valid crypto devs */
240 for (i = 0; i < nb_devs; i++) {
241 rte_cryptodev_info_get(i, &info);
242 if (info.dev_type == gbl_cryptodev_type)
243 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
246 if (ts_params->valid_dev_count < 1)
249 /* Set up all the qps on the first of the valid devices found */
250 for (i = 0; i < 1; i++) {
251 dev_id = ts_params->valid_devs[i];
253 rte_cryptodev_info_get(dev_id, &info);
256 * Since we can't free and re-allocate queue memory always set
257 * the queues on this device up to max size first so enough
258 * memory is allocated for any later re-configures needed by
262 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
263 ts_params->conf.socket_id = SOCKET_ID_ANY;
264 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
266 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
268 "Failed to configure cryptodev %u with %u qps",
269 dev_id, ts_params->conf.nb_queue_pairs);
271 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
273 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
274 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
275 dev_id, qp_id, &ts_params->qp_conf,
276 rte_cryptodev_socket_id(dev_id)),
277 "Failed to setup queue pair %u on "
287 testsuite_teardown(void)
289 struct crypto_testsuite_params *ts_params = &testsuite_params;
291 if (ts_params->mbuf_pool != NULL) {
292 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
293 rte_mempool_count(ts_params->mbuf_pool));
296 if (ts_params->op_mpool != NULL) {
297 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
298 rte_mempool_count(ts_params->op_mpool));
306 struct crypto_testsuite_params *ts_params = &testsuite_params;
307 struct crypto_unittest_params *ut_params = &unittest_params;
311 /* Clear unit test parameters before running test */
312 memset(ut_params, 0, sizeof(*ut_params));
314 /* Reconfigure device to default parameters */
315 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
316 ts_params->conf.socket_id = SOCKET_ID_ANY;
317 ts_params->conf.session_mp.nb_objs =
318 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
319 DEFAULT_NUM_OPS_INFLIGHT :
320 DEFAULT_NUM_OPS_INFLIGHT;
322 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
324 "Failed to configure cryptodev %u",
325 ts_params->valid_devs[0]);
328 * Now reconfigure queues to size we actually want to use in this
331 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
333 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
334 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
335 ts_params->valid_devs[0], qp_id,
337 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
338 "Failed to setup queue pair %u on cryptodev %u",
339 qp_id, ts_params->valid_devs[0]);
343 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
345 /* Start the device */
346 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
347 "Failed to start cryptodev %u",
348 ts_params->valid_devs[0]);
356 struct crypto_testsuite_params *ts_params = &testsuite_params;
357 struct crypto_unittest_params *ut_params = &unittest_params;
358 struct rte_cryptodev_stats stats;
360 /* free crypto session structure */
361 if (ut_params->sess) {
362 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
364 ut_params->sess = NULL;
367 /* free crypto operation structure */
369 rte_crypto_op_free(ut_params->op);
372 * free mbuf - both obuf and ibuf are usually the same,
373 * but rte copes even if we call free twice
375 if (ut_params->obuf) {
376 rte_pktmbuf_free(ut_params->obuf);
379 if (ut_params->ibuf) {
380 rte_pktmbuf_free(ut_params->ibuf);
384 if (ts_params->mbuf_pool != NULL)
385 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
386 rte_mempool_count(ts_params->mbuf_pool));
388 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
390 /* Stop the device */
391 rte_cryptodev_stop(ts_params->valid_devs[0]);
395 test_device_configure_invalid_dev_id(void)
397 struct crypto_testsuite_params *ts_params = &testsuite_params;
398 uint16_t dev_id, num_devs = 0;
400 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
401 "Need at least %d devices for test", 1);
403 /* valid dev_id values */
404 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
406 /* Stop the device in case it's started so it can be configured */
407 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
409 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
410 "Failed test for rte_cryptodev_configure: "
411 "invalid dev_num %u", dev_id);
413 /* invalid dev_id values */
416 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
417 "Failed test for rte_cryptodev_configure: "
418 "invalid dev_num %u", dev_id);
422 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
423 "Failed test for rte_cryptodev_configure:"
424 "invalid dev_num %u", dev_id);
430 test_device_configure_invalid_queue_pair_ids(void)
432 struct crypto_testsuite_params *ts_params = &testsuite_params;
434 /* Stop the device in case it's started so it can be configured */
435 rte_cryptodev_stop(ts_params->valid_devs[0]);
437 /* valid - one queue pairs */
438 ts_params->conf.nb_queue_pairs = 1;
440 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
442 "Failed to configure cryptodev: dev_id %u, qp_id %u",
443 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
446 /* valid - max value queue pairs */
447 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
449 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
451 "Failed to configure cryptodev: dev_id %u, qp_id %u",
452 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
455 /* invalid - zero queue pairs */
456 ts_params->conf.nb_queue_pairs = 0;
458 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
460 "Failed test for rte_cryptodev_configure, dev_id %u,"
462 ts_params->valid_devs[0],
463 ts_params->conf.nb_queue_pairs);
466 /* invalid - max value supported by field queue pairs */
467 ts_params->conf.nb_queue_pairs = UINT16_MAX;
469 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
471 "Failed test for rte_cryptodev_configure, dev_id %u,"
473 ts_params->valid_devs[0],
474 ts_params->conf.nb_queue_pairs);
477 /* invalid - max value + 1 queue pairs */
478 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
480 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
482 "Failed test for rte_cryptodev_configure, dev_id %u,"
484 ts_params->valid_devs[0],
485 ts_params->conf.nb_queue_pairs);
491 test_queue_pair_descriptor_setup(void)
493 struct crypto_testsuite_params *ts_params = &testsuite_params;
494 struct rte_cryptodev_info dev_info;
495 struct rte_cryptodev_qp_conf qp_conf = {
496 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
501 /* Stop the device in case it's started so it can be configured */
502 rte_cryptodev_stop(ts_params->valid_devs[0]);
505 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
507 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
509 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
510 &ts_params->conf), "Failed to configure cryptodev %u",
511 ts_params->valid_devs[0]);
515 * Test various ring sizes on this device. memzones can't be
516 * freed so are re-used if ring is released and re-created.
518 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
520 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
521 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
522 ts_params->valid_devs[0], qp_id, &qp_conf,
523 rte_cryptodev_socket_id(
524 ts_params->valid_devs[0])),
526 "rte_cryptodev_queue_pair_setup: num_inflights "
527 "%u on qp %u on cryptodev %u",
528 qp_conf.nb_descriptors, qp_id,
529 ts_params->valid_devs[0]);
532 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
534 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
535 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
536 ts_params->valid_devs[0], qp_id, &qp_conf,
537 rte_cryptodev_socket_id(
538 ts_params->valid_devs[0])),
540 " rte_cryptodev_queue_pair_setup: num_inflights"
541 " %u on qp %u on cryptodev %u",
542 qp_conf.nb_descriptors, qp_id,
543 ts_params->valid_devs[0]);
546 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
548 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
549 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
550 ts_params->valid_devs[0], qp_id, &qp_conf,
551 rte_cryptodev_socket_id(
552 ts_params->valid_devs[0])),
554 "rte_cryptodev_queue_pair_setup: num_inflights"
555 " %u on qp %u on cryptodev %u",
556 qp_conf.nb_descriptors, qp_id,
557 ts_params->valid_devs[0]);
560 /* invalid number of descriptors - max supported + 2 */
561 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
563 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
564 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
565 ts_params->valid_devs[0], qp_id, &qp_conf,
566 rte_cryptodev_socket_id(
567 ts_params->valid_devs[0])),
568 "Unexpectedly passed test for "
569 "rte_cryptodev_queue_pair_setup:"
570 "num_inflights %u on qp %u on cryptodev %u",
571 qp_conf.nb_descriptors, qp_id,
572 ts_params->valid_devs[0]);
575 /* invalid number of descriptors - max value of parameter */
576 qp_conf.nb_descriptors = UINT32_MAX-1;
578 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
579 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
580 ts_params->valid_devs[0], qp_id, &qp_conf,
581 rte_cryptodev_socket_id(
582 ts_params->valid_devs[0])),
583 "Unexpectedly passed test for "
584 "rte_cryptodev_queue_pair_setup:"
585 "num_inflights %u on qp %u on cryptodev %u",
586 qp_conf.nb_descriptors, qp_id,
587 ts_params->valid_devs[0]);
590 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
592 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
593 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
594 ts_params->valid_devs[0], qp_id, &qp_conf,
595 rte_cryptodev_socket_id(
596 ts_params->valid_devs[0])),
598 " rte_cryptodev_queue_pair_setup:"
599 "num_inflights %u on qp %u on cryptodev %u",
600 qp_conf.nb_descriptors, qp_id,
601 ts_params->valid_devs[0]);
604 /* invalid number of descriptors - max supported + 1 */
605 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
607 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
608 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
609 ts_params->valid_devs[0], qp_id, &qp_conf,
610 rte_cryptodev_socket_id(
611 ts_params->valid_devs[0])),
612 "Unexpectedly passed test for "
613 "rte_cryptodev_queue_pair_setup:"
614 "num_inflights %u on qp %u on cryptodev %u",
615 qp_conf.nb_descriptors, qp_id,
616 ts_params->valid_devs[0]);
619 /* test invalid queue pair id */
620 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
622 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
624 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
625 ts_params->valid_devs[0],
627 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
628 "Failed test for rte_cryptodev_queue_pair_setup:"
629 "invalid qp %u on cryptodev %u",
630 qp_id, ts_params->valid_devs[0]);
632 qp_id = 0xffff; /*invalid*/
634 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
635 ts_params->valid_devs[0],
637 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
638 "Failed test for rte_cryptodev_queue_pair_setup:"
639 "invalid qp %u on cryptodev %u",
640 qp_id, ts_params->valid_devs[0]);
645 /* ***** Plaintext data for tests ***** */
647 const char catch_22_quote_1[] =
648 "There was only one catch and that was Catch-22, which "
649 "specified that a concern for one's safety in the face of "
650 "dangers that were real and immediate was the process of a "
651 "rational mind. Orr was crazy and could be grounded. All he "
652 "had to do was ask; and as soon as he did, he would no longer "
653 "be crazy and would have to fly more missions. Orr would be "
654 "crazy to fly more missions and sane if he didn't, but if he "
655 "was sane he had to fly them. If he flew them he was crazy "
656 "and didn't have to; but if he didn't want to he was sane and "
657 "had to. Yossarian was moved very deeply by the absolute "
658 "simplicity of this clause of Catch-22 and let out a "
659 "respectful whistle. \"That's some catch, that Catch-22\", he "
660 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
662 const char catch_22_quote[] =
663 "What a lousy earth! He wondered how many people were "
664 "destitute that same night even in his own prosperous country, "
665 "how many homes were shanties, how many husbands were drunk "
666 "and wives socked, and how many children were bullied, abused, "
667 "or abandoned. How many families hungered for food they could "
668 "not afford to buy? How many hearts were broken? How many "
669 "suicides would take place that same night, how many people "
670 "would go insane? How many cockroaches and landlords would "
671 "triumph? How many winners were losers, successes failures, "
672 "and rich men poor men? How many wise guys were stupid? How "
673 "many happy endings were unhappy endings? How many honest men "
674 "were liars, brave men cowards, loyal men traitors, how many "
675 "sainted men were corrupt, how many people in positions of "
676 "trust had sold their souls to bodyguards, how many had never "
677 "had souls? How many straight-and-narrow paths were crooked "
678 "paths? How many best families were worst families and how "
679 "many good people were bad people? When you added them all up "
680 "and then subtracted, you might be left with only the children, "
681 "and perhaps with Albert Einstein and an old violinist or "
682 "sculptor somewhere.";
684 #define QUOTE_480_BYTES (480)
685 #define QUOTE_512_BYTES (512)
686 #define QUOTE_768_BYTES (768)
687 #define QUOTE_1024_BYTES (1024)
691 /* ***** SHA1 Hash Tests ***** */
693 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
695 static uint8_t hmac_sha1_key[] = {
696 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
697 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
698 0xDE, 0xF4, 0xDE, 0xAD };
700 /* ***** SHA224 Hash Tests ***** */
702 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
705 /* ***** AES-CBC Cipher Tests ***** */
707 #define CIPHER_KEY_LENGTH_AES_CBC (16)
708 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
710 static uint8_t aes_cbc_key[] = {
711 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
712 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
714 static uint8_t aes_cbc_iv[] = {
715 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
716 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
719 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
721 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
722 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
723 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
724 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
725 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
726 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
727 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
728 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
729 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
730 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
731 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
732 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
733 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
734 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
735 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
736 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
737 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
738 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
739 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
740 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
741 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
742 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
743 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
744 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
745 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
746 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
747 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
748 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
749 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
750 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
751 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
752 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
753 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
754 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
755 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
756 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
757 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
758 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
759 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
760 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
761 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
762 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
763 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
764 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
765 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
766 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
767 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
768 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
769 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
770 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
771 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
772 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
773 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
774 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
775 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
776 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
777 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
778 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
779 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
780 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
781 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
782 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
783 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
784 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
785 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
788 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
789 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
790 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
791 0x18, 0x8c, 0x1d, 0x32
796 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
798 struct crypto_testsuite_params *ts_params = &testsuite_params;
799 struct crypto_unittest_params *ut_params = &unittest_params;
801 /* Generate test mbuf data and space for digest */
802 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
803 catch_22_quote, QUOTE_512_BYTES, 0);
805 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
806 DIGEST_BYTE_LENGTH_SHA1);
807 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
809 /* Setup Cipher Parameters */
810 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
811 ut_params->cipher_xform.next = &ut_params->auth_xform;
813 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
814 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
815 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
816 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
818 /* Setup HMAC Parameters */
819 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
821 ut_params->auth_xform.next = NULL;
823 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
824 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
825 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
826 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
827 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
829 /* Create crypto session*/
830 ut_params->sess = rte_cryptodev_sym_session_create(
831 ts_params->valid_devs[0],
832 &ut_params->cipher_xform);
833 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
835 /* Generate crypto op data structure */
836 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
837 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
838 TEST_ASSERT_NOT_NULL(ut_params->op,
839 "Failed to allocate symmetric crypto operation struct");
841 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
843 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
845 /* set crypto operation source mbuf */
846 sym_op->m_src = ut_params->ibuf;
848 /* Set crypto operation authentication parameters */
849 sym_op->auth.digest.data = ut_params->digest;
850 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
851 ut_params->ibuf, QUOTE_512_BYTES);
852 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
854 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
855 sym_op->auth.data.length = QUOTE_512_BYTES;
857 /* Set crypto operation cipher parameters */
858 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
859 CIPHER_IV_LENGTH_AES_CBC);
860 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
861 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
863 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
864 CIPHER_IV_LENGTH_AES_CBC);
866 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
867 sym_op->cipher.data.length = QUOTE_512_BYTES;
869 /* Process crypto operation */
870 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
871 ut_params->op), "failed to process sym crypto op");
873 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
874 "crypto op processing failed");
877 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
878 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
880 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
881 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
883 "ciphertext data not as expected");
885 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
887 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
888 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
889 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
890 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
891 DIGEST_BYTE_LENGTH_SHA1,
892 "Generated digest data not as expected");
897 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
899 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
901 static uint8_t hmac_sha512_key[] = {
902 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
903 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
904 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
905 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
906 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
907 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
908 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
909 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
911 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
912 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
913 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
914 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
915 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
916 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
917 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
918 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
919 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
924 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
925 struct crypto_unittest_params *ut_params);
928 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
929 struct crypto_unittest_params *ut_params,
930 struct crypto_testsuite_params *ts_params);
934 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
935 struct crypto_unittest_params *ut_params)
938 /* Setup Cipher Parameters */
939 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
940 ut_params->cipher_xform.next = NULL;
942 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
943 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
944 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
945 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
947 /* Setup HMAC Parameters */
948 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
949 ut_params->auth_xform.next = &ut_params->cipher_xform;
951 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
952 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
953 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
954 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
955 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
962 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
963 struct crypto_unittest_params *ut_params,
964 struct crypto_testsuite_params *ts_params)
966 /* Generate test mbuf data and digest */
967 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
969 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
972 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
973 DIGEST_BYTE_LENGTH_SHA512);
974 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
976 rte_memcpy(ut_params->digest,
977 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
978 DIGEST_BYTE_LENGTH_SHA512);
980 /* Generate Crypto op data structure */
981 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
982 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
983 TEST_ASSERT_NOT_NULL(ut_params->op,
984 "Failed to allocate symmetric crypto operation struct");
986 rte_crypto_op_attach_sym_session(ut_params->op, sess);
988 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
990 /* set crypto operation source mbuf */
991 sym_op->m_src = ut_params->ibuf;
993 sym_op->auth.digest.data = ut_params->digest;
994 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
995 ut_params->ibuf, QUOTE_512_BYTES);
996 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
998 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
999 sym_op->auth.data.length = QUOTE_512_BYTES;
1001 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1002 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1003 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1004 ut_params->ibuf, 0);
1005 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1007 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1008 CIPHER_IV_LENGTH_AES_CBC);
1010 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1011 sym_op->cipher.data.length = QUOTE_512_BYTES;
1013 /* Process crypto operation */
1014 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1015 ut_params->op), "failed to process sym crypto op");
1017 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1018 "crypto op processing failed");
1020 ut_params->obuf = ut_params->op->sym->m_src;
1023 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1024 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1025 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1027 "Plaintext data not as expected");
1030 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1031 "Digest verification failed");
1033 return TEST_SUCCESS;
1037 test_AES_mb_all(void)
1039 struct crypto_testsuite_params *ts_params = &testsuite_params;
1042 status = test_AES_all_tests(ts_params->mbuf_pool,
1043 ts_params->op_mpool, ts_params->valid_devs[0],
1044 RTE_CRYPTODEV_AESNI_MB_PMD);
1046 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1048 return TEST_SUCCESS;
1052 test_AES_qat_all(void)
1054 struct crypto_testsuite_params *ts_params = &testsuite_params;
1057 status = test_AES_all_tests(ts_params->mbuf_pool,
1058 ts_params->op_mpool, ts_params->valid_devs[0],
1059 RTE_CRYPTODEV_QAT_SYM_PMD);
1061 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1063 return TEST_SUCCESS;
1066 /* ***** Snow3G Tests ***** */
1068 create_snow3g_hash_session(uint8_t dev_id,
1069 const uint8_t *key, const uint8_t key_len,
1070 const uint8_t aad_len, const uint8_t auth_len,
1071 enum rte_crypto_auth_operation op)
1073 uint8_t hash_key[key_len];
1075 struct crypto_unittest_params *ut_params = &unittest_params;
1077 memcpy(hash_key, key, key_len);
1079 TEST_HEXDUMP(stdout, "key:", key, key_len);
1081 /* Setup Authentication Parameters */
1082 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1083 ut_params->auth_xform.next = NULL;
1085 ut_params->auth_xform.auth.op = op;
1086 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1087 ut_params->auth_xform.auth.key.length = key_len;
1088 ut_params->auth_xform.auth.key.data = hash_key;
1089 ut_params->auth_xform.auth.digest_length = auth_len;
1090 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1091 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1092 &ut_params->auth_xform);
1093 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1097 create_snow3g_cipher_session(uint8_t dev_id,
1098 enum rte_crypto_cipher_operation op,
1099 const uint8_t *key, const uint8_t key_len)
1101 uint8_t cipher_key[key_len];
1103 struct crypto_unittest_params *ut_params = &unittest_params;
1105 memcpy(cipher_key, key, key_len);
1107 /* Setup Cipher Parameters */
1108 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1109 ut_params->cipher_xform.next = NULL;
1111 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1112 ut_params->cipher_xform.cipher.op = op;
1113 ut_params->cipher_xform.cipher.key.data = cipher_key;
1114 ut_params->cipher_xform.cipher.key.length = key_len;
1116 TEST_HEXDUMP(stdout, "key:", key, key_len);
1118 /* Create Crypto session */
1119 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1122 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1127 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1128 const unsigned cipher_len,
1129 const unsigned cipher_offset)
1131 struct crypto_testsuite_params *ts_params = &testsuite_params;
1132 struct crypto_unittest_params *ut_params = &unittest_params;
1133 unsigned iv_pad_len = 0;
1135 /* Generate Crypto op data structure */
1136 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1137 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1138 TEST_ASSERT_NOT_NULL(ut_params->op,
1139 "Failed to allocate pktmbuf offload");
1141 /* Set crypto operation data parameters */
1142 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1144 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1146 /* set crypto operation source mbuf */
1147 sym_op->m_src = ut_params->ibuf;
1150 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1151 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1154 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1156 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1157 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1158 sym_op->cipher.iv.length = iv_pad_len;
1160 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1161 sym_op->cipher.data.length = cipher_len;
1162 sym_op->cipher.data.offset = cipher_offset;
1167 create_snow3g_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1168 const unsigned cipher_len,
1169 const unsigned cipher_offset)
1171 struct crypto_testsuite_params *ts_params = &testsuite_params;
1172 struct crypto_unittest_params *ut_params = &unittest_params;
1173 unsigned iv_pad_len = 0;
1175 /* Generate Crypto op data structure */
1176 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1177 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1178 TEST_ASSERT_NOT_NULL(ut_params->op,
1179 "Failed to allocate pktmbuf offload");
1181 /* Set crypto operation data parameters */
1182 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1184 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1186 /* set crypto operation source mbuf */
1187 sym_op->m_src = ut_params->ibuf;
1188 sym_op->m_dst = ut_params->obuf;
1191 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1192 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1195 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1197 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1198 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1199 sym_op->cipher.iv.length = iv_pad_len;
1201 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1202 sym_op->cipher.data.length = cipher_len;
1203 sym_op->cipher.data.offset = cipher_offset;
1208 create_snow3g_cipher_auth_session(uint8_t dev_id,
1209 enum rte_crypto_cipher_operation cipher_op,
1210 enum rte_crypto_auth_operation auth_op,
1211 const uint8_t *key, const uint8_t key_len,
1212 const uint8_t aad_len, const uint8_t auth_len)
1214 uint8_t cipher_auth_key[key_len];
1216 struct crypto_unittest_params *ut_params = &unittest_params;
1218 memcpy(cipher_auth_key, key, key_len);
1220 /* Setup Authentication Parameters */
1221 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1222 ut_params->auth_xform.next = NULL;
1224 ut_params->auth_xform.auth.op = auth_op;
1225 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1226 ut_params->auth_xform.auth.key.length = key_len;
1227 /* Hash key = cipher key */
1228 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1229 ut_params->auth_xform.auth.digest_length = auth_len;
1230 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1232 /* Setup Cipher Parameters */
1233 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1234 ut_params->cipher_xform.next = &ut_params->auth_xform;
1236 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1237 ut_params->cipher_xform.cipher.op = cipher_op;
1238 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1239 ut_params->cipher_xform.cipher.key.length = key_len;
1241 TEST_HEXDUMP(stdout, "key:", key, key_len);
1243 /* Create Crypto session*/
1244 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1245 &ut_params->cipher_xform);
1247 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1252 create_snow3g_auth_cipher_session(uint8_t dev_id,
1253 enum rte_crypto_cipher_operation cipher_op,
1254 enum rte_crypto_auth_operation auth_op,
1255 const uint8_t *key, const uint8_t key_len,
1256 const uint8_t aad_len, const uint8_t auth_len)
1258 uint8_t auth_cipher_key[key_len];
1260 struct crypto_unittest_params *ut_params = &unittest_params;
1262 memcpy(auth_cipher_key, key, key_len);
1264 /* Setup Authentication Parameters */
1265 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1266 ut_params->auth_xform.auth.op = auth_op;
1267 ut_params->auth_xform.next = &ut_params->cipher_xform;
1268 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1269 ut_params->auth_xform.auth.key.length = key_len;
1270 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1271 ut_params->auth_xform.auth.digest_length = auth_len;
1272 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1274 /* Setup Cipher Parameters */
1275 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1276 ut_params->cipher_xform.next = NULL;
1277 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1278 ut_params->cipher_xform.cipher.op = cipher_op;
1279 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1280 ut_params->cipher_xform.cipher.key.length = key_len;
1282 TEST_HEXDUMP(stdout, "key:", key, key_len);
1284 /* Create Crypto session*/
1285 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1286 &ut_params->auth_xform);
1288 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1294 create_snow3g_hash_operation(const uint8_t *auth_tag,
1295 const unsigned auth_tag_len,
1296 const uint8_t *aad, const unsigned aad_len,
1297 unsigned data_pad_len,
1298 enum rte_crypto_auth_operation op,
1299 const unsigned auth_len, const unsigned auth_offset)
1301 struct crypto_testsuite_params *ts_params = &testsuite_params;
1303 struct crypto_unittest_params *ut_params = &unittest_params;
1305 unsigned aad_buffer_len;
1307 /* Generate Crypto op data structure */
1308 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1309 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1310 TEST_ASSERT_NOT_NULL(ut_params->op,
1311 "Failed to allocate pktmbuf offload");
1313 /* Set crypto operation data parameters */
1314 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1316 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1318 /* set crypto operation source mbuf */
1319 sym_op->m_src = ut_params->ibuf;
1323 * Always allocate the aad up to the block size.
1324 * The cryptodev API calls out -
1325 * - the array must be big enough to hold the AAD, plus any
1326 * space to round this up to the nearest multiple of the
1327 * block size (16 bytes).
1329 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1330 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1331 ut_params->ibuf, aad_buffer_len);
1332 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1333 "no room to prepend aad");
1334 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1336 sym_op->auth.aad.length = aad_len;
1338 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1339 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1341 TEST_HEXDUMP(stdout, "aad:",
1342 sym_op->auth.aad.data, aad_len);
1345 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1346 ut_params->ibuf, auth_tag_len);
1348 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1349 "no room to append auth tag");
1350 ut_params->digest = sym_op->auth.digest.data;
1351 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1352 ut_params->ibuf, data_pad_len + aad_len);
1353 sym_op->auth.digest.length = auth_tag_len;
1354 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1355 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1357 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1359 TEST_HEXDUMP(stdout, "digest:",
1360 sym_op->auth.digest.data,
1361 sym_op->auth.digest.length);
1363 sym_op->auth.data.length = auth_len;
1364 sym_op->auth.data.offset = auth_offset;
1370 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
1371 const unsigned auth_tag_len,
1372 const uint8_t *aad, const uint8_t aad_len,
1373 unsigned data_pad_len,
1374 enum rte_crypto_auth_operation op,
1375 const uint8_t *iv, const uint8_t iv_len,
1376 const unsigned cipher_len, const unsigned cipher_offset,
1377 const unsigned auth_len, const unsigned auth_offset)
1379 struct crypto_testsuite_params *ts_params = &testsuite_params;
1380 struct crypto_unittest_params *ut_params = &unittest_params;
1382 unsigned iv_pad_len = 0;
1383 unsigned aad_buffer_len;
1385 /* Generate Crypto op data structure */
1386 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1387 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1388 TEST_ASSERT_NOT_NULL(ut_params->op,
1389 "Failed to allocate pktmbuf offload");
1390 /* Set crypto operation data parameters */
1391 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1393 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1395 /* set crypto operation source mbuf */
1396 sym_op->m_src = ut_params->ibuf;
1400 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1402 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1403 ut_params->ibuf, iv_pad_len);
1404 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1406 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1407 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1408 sym_op->cipher.iv.length = iv_pad_len;
1410 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1412 sym_op->cipher.data.length = cipher_len;
1413 sym_op->cipher.data.offset = cipher_offset;
1417 * Always allocate the aad up to the block size.
1418 * The cryptodev API calls out -
1419 * - the array must be big enough to hold the AAD, plus any
1420 * space to round this up to the nearest multiple of the
1421 * block size (16 bytes).
1423 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1425 sym_op->auth.aad.data =
1426 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1427 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1428 "no room to prepend aad");
1429 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1431 sym_op->auth.aad.length = aad_len;
1433 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1434 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1436 TEST_HEXDUMP(stdout, "aad:",
1437 sym_op->auth.aad.data, aad_len);
1440 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1441 ut_params->ibuf, auth_tag_len);
1443 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1444 "no room to append auth tag");
1445 ut_params->digest = sym_op->auth.digest.data;
1446 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1447 ut_params->ibuf, data_pad_len + aad_len);
1448 sym_op->auth.digest.length = auth_tag_len;
1449 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1450 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1452 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1454 TEST_HEXDUMP(stdout, "digest:",
1455 sym_op->auth.digest.data,
1456 sym_op->auth.digest.length);
1458 sym_op->auth.data.length = auth_len;
1459 sym_op->auth.data.offset = auth_offset;
1465 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
1466 const uint8_t *iv, const uint8_t iv_len,
1467 const uint8_t *aad, const uint8_t aad_len,
1468 unsigned data_pad_len,
1469 const unsigned cipher_len, const unsigned cipher_offset,
1470 const unsigned auth_len, const unsigned auth_offset)
1472 struct crypto_testsuite_params *ts_params = &testsuite_params;
1473 struct crypto_unittest_params *ut_params = &unittest_params;
1475 unsigned iv_pad_len = 0;
1476 unsigned aad_buffer_len = 0;
1478 /* Generate Crypto op data structure */
1479 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1480 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1481 TEST_ASSERT_NOT_NULL(ut_params->op,
1482 "Failed to allocate pktmbuf offload");
1484 /* Set crypto operation data parameters */
1485 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1487 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1489 /* set crypto operation source mbuf */
1490 sym_op->m_src = ut_params->ibuf;
1493 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1494 ut_params->ibuf, auth_tag_len);
1496 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1497 "no room to append auth tag");
1499 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1500 ut_params->ibuf, data_pad_len);
1501 sym_op->auth.digest.length = auth_tag_len;
1503 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1505 TEST_HEXDUMP(stdout, "digest:",
1506 sym_op->auth.digest.data,
1507 sym_op->auth.digest.length);
1510 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1512 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1513 ut_params->ibuf, iv_pad_len);
1514 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1516 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1517 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1518 sym_op->cipher.iv.length = iv_pad_len;
1520 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1524 * Always allocate the aad up to the block size.
1525 * The cryptodev API calls out -
1526 * - the array must be big enough to hold the AAD, plus any
1527 * space to round this up to the nearest multiple of the
1528 * block size (16 bytes).
1530 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1532 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1533 ut_params->ibuf, aad_buffer_len);
1534 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1535 "no room to prepend aad");
1536 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1538 sym_op->auth.aad.length = aad_len;
1540 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1541 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1543 TEST_HEXDUMP(stdout, "aad:",
1544 sym_op->auth.aad.data, aad_len);
1546 sym_op->cipher.data.length = cipher_len;
1547 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1549 sym_op->auth.data.length = auth_len;
1550 sym_op->auth.data.offset = auth_offset + cipher_offset;
1556 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1558 struct crypto_testsuite_params *ts_params = &testsuite_params;
1559 struct crypto_unittest_params *ut_params = &unittest_params;
1562 unsigned plaintext_pad_len;
1565 /* Create SNOW3G session */
1566 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1567 tdata->key.data, tdata->key.len,
1568 tdata->aad.len, tdata->digest.len,
1569 RTE_CRYPTO_AUTH_OP_GENERATE);
1573 /* alloc mbuf and set payload */
1574 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1576 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1577 rte_pktmbuf_tailroom(ut_params->ibuf));
1579 /* Append data which is padded to a multiple of */
1580 /* the algorithms block size */
1581 plaintext_pad_len = tdata->plaintext.len >> 3;
1582 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1584 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1586 /* Create SNOW3G opertaion */
1587 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1588 tdata->aad.data, tdata->aad.len,
1589 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1590 tdata->validAuthLenInBits.len,
1591 tdata->validAuthOffsetLenInBits.len);
1595 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1597 ut_params->obuf = ut_params->op->sym->m_src;
1598 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1599 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1600 + plaintext_pad_len + tdata->aad.len;
1603 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1606 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1607 "Snow3G Generated auth tag not as expected");
1613 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1615 struct crypto_testsuite_params *ts_params = &testsuite_params;
1616 struct crypto_unittest_params *ut_params = &unittest_params;
1619 unsigned plaintext_pad_len;
1622 /* Create SNOW3G session */
1623 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1624 tdata->key.data, tdata->key.len,
1625 tdata->aad.len, tdata->digest.len,
1626 RTE_CRYPTO_AUTH_OP_VERIFY);
1629 /* alloc mbuf and set payload */
1630 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1632 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1633 rte_pktmbuf_tailroom(ut_params->ibuf));
1635 /* Append data which is padded to a multiple */
1636 /* of the algorithms block size */
1637 plaintext_pad_len = tdata->plaintext.len >> 3;
1638 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1640 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1642 /* Create SNOW3G operation */
1643 retval = create_snow3g_hash_operation(tdata->digest.data,
1645 tdata->aad.data, tdata->aad.len,
1647 RTE_CRYPTO_AUTH_OP_VERIFY,
1648 tdata->validAuthLenInBits.len,
1649 tdata->validAuthOffsetLenInBits.len);
1653 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1655 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1656 ut_params->obuf = ut_params->op->sym->m_src;
1657 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1658 + plaintext_pad_len + tdata->aad.len;
1661 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1671 test_snow3g_hash_generate_test_case_1(void)
1673 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1677 test_snow3g_hash_generate_test_case_2(void)
1679 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1683 test_snow3g_hash_generate_test_case_3(void)
1685 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1689 test_snow3g_hash_verify_test_case_1(void)
1691 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1696 test_snow3g_hash_verify_test_case_2(void)
1698 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1702 test_snow3g_hash_verify_test_case_3(void)
1704 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1708 test_snow3g_encryption(const struct snow3g_test_data *tdata)
1710 struct crypto_testsuite_params *ts_params = &testsuite_params;
1711 struct crypto_unittest_params *ut_params = &unittest_params;
1714 uint8_t *plaintext, *ciphertext;
1715 uint8_t plaintext_pad_len;
1716 uint8_t lastByteValidBits = 8;
1717 uint8_t lastByteMask = 0xFF;
1719 /* Create SNOW3G session */
1720 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1721 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1722 tdata->key.data, tdata->key.len);
1726 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1728 /* Clear mbuf payload */
1729 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1730 rte_pktmbuf_tailroom(ut_params->ibuf));
1733 * Append data which is padded to a
1734 * multiple of the algorithms block size
1736 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1737 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1739 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1741 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1743 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1745 /* Create SNOW3G operation */
1746 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1747 tdata->validCipherLenInBits.len,
1748 tdata->validCipherOffsetLenInBits.len);
1752 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1754 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1756 ut_params->obuf = ut_params->op->sym->m_dst;
1757 if (ut_params->obuf)
1758 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1761 ciphertext = plaintext;
1763 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1764 if (lastByteValidBits == 0)
1765 lastByteValidBits = 8;
1766 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1767 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1769 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1772 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1774 tdata->ciphertext.data,
1775 tdata->ciphertext.len >> 3,
1776 "Snow3G Ciphertext data not as expected");
1782 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
1784 struct crypto_testsuite_params *ts_params = &testsuite_params;
1785 struct crypto_unittest_params *ut_params = &unittest_params;
1786 uint8_t *plaintext, *ciphertext;
1789 uint8_t plaintext_pad_len;
1790 uint8_t lastByteValidBits = 8;
1791 uint8_t lastByteMask = 0xFF;
1793 /* Create SNOW3G session */
1794 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1795 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1796 tdata->key.data, tdata->key.len);
1800 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1801 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1803 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1804 "Failed to allocate input buffer in mempool");
1805 TEST_ASSERT_NOT_NULL(ut_params->obuf,
1806 "Failed to allocate output buffer in mempool");
1808 /* Clear mbuf payload */
1809 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1810 rte_pktmbuf_tailroom(ut_params->ibuf));
1813 * Append data which is padded to a
1814 * multiple of the algorithms block size
1816 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1817 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1819 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1822 rte_pktmbuf_append(ut_params->obuf,
1825 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1827 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1829 /* Create SNOW3G operation */
1830 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1832 tdata->validCipherLenInBits.len,
1833 tdata->validCipherOffsetLenInBits.len);
1837 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1839 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1841 ut_params->obuf = ut_params->op->sym->m_dst;
1842 if (ut_params->obuf)
1843 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1846 ciphertext = plaintext;
1848 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1849 if (lastByteValidBits == 0)
1850 lastByteValidBits = 8;
1851 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1852 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1854 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1857 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1859 tdata->ciphertext.data,
1860 tdata->ciphertext.len >> 3,
1861 "Snow3G Ciphertext data not as expected");
1866 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
1868 struct crypto_testsuite_params *ts_params = &testsuite_params;
1869 struct crypto_unittest_params *ut_params = &unittest_params;
1873 uint8_t *plaintext, *ciphertext;
1874 uint8_t ciphertext_pad_len;
1875 uint8_t lastByteValidBits = 8;
1876 uint8_t lastByteMask = 0xFF;
1878 /* Create SNOW3G session */
1879 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1880 RTE_CRYPTO_CIPHER_OP_DECRYPT,
1881 tdata->key.data, tdata->key.len);
1885 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1887 /* Clear mbuf payload */
1888 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1889 rte_pktmbuf_tailroom(ut_params->ibuf));
1892 * Append data which is padded to a
1893 * multiple of the algorithms block size
1895 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1897 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1898 ciphertext_pad_len);
1899 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1901 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1903 /* Create SNOW3G operation */
1904 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1905 tdata->validCipherLenInBits.len,
1906 tdata->validCipherOffsetLenInBits.len);
1910 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1912 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1913 ut_params->obuf = ut_params->op->sym->m_src;
1914 if (ut_params->obuf)
1915 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1918 plaintext = ciphertext;
1919 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1920 if (lastByteValidBits == 0)
1921 lastByteValidBits = 8;
1922 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1923 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1925 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1928 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1929 tdata->plaintext.data,
1930 tdata->plaintext.len >> 3,
1931 "Snow3G Plaintext data not as expected");
1935 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
1937 struct crypto_testsuite_params *ts_params = &testsuite_params;
1938 struct crypto_unittest_params *ut_params = &unittest_params;
1942 uint8_t *plaintext, *ciphertext;
1943 uint8_t ciphertext_pad_len;
1944 uint8_t lastByteValidBits = 8;
1945 uint8_t lastByteMask = 0xFF;
1947 /* Create SNOW3G session */
1948 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1949 RTE_CRYPTO_CIPHER_OP_DECRYPT,
1950 tdata->key.data, tdata->key.len);
1954 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1955 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1957 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1958 "Failed to allocate input buffer");
1959 TEST_ASSERT_NOT_NULL(ut_params->obuf,
1960 "Failed to allocate output buffer");
1962 /* Clear mbuf payload */
1963 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1964 rte_pktmbuf_tailroom(ut_params->ibuf));
1966 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
1967 rte_pktmbuf_tailroom(ut_params->obuf));
1970 * Append data which is padded to a
1971 * multiple of the algorithms block size
1973 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1975 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1976 ciphertext_pad_len);
1978 rte_pktmbuf_append(ut_params->obuf,
1979 ciphertext_pad_len);
1981 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1983 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1985 /* Create SNOW3G operation */
1986 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1988 tdata->validCipherLenInBits.len,
1989 tdata->validCipherOffsetLenInBits.len);
1993 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1995 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1996 ut_params->obuf = ut_params->op->sym->m_dst;
1997 if (ut_params->obuf)
1998 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2001 plaintext = ciphertext;
2002 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2003 if (lastByteValidBits == 0)
2004 lastByteValidBits = 8;
2005 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2006 (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2008 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2011 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2012 tdata->plaintext.data,
2013 tdata->plaintext.len >> 3,
2014 "Snow3G Plaintext data not as expected");
2019 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2021 struct crypto_testsuite_params *ts_params = &testsuite_params;
2022 struct crypto_unittest_params *ut_params = &unittest_params;
2026 uint8_t *plaintext, *ciphertext;
2027 uint8_t plaintext_pad_len;
2028 uint8_t lastByteValidBits = 8;
2029 uint8_t lastByteMask = 0xFF;
2031 /* Create SNOW3G session */
2032 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2033 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2034 RTE_CRYPTO_AUTH_OP_GENERATE,
2035 tdata->key.data, tdata->key.len,
2036 tdata->aad.len, tdata->digest.len);
2039 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2041 /* clear mbuf payload */
2042 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2043 rte_pktmbuf_tailroom(ut_params->ibuf));
2045 /* Append data which is padded to a multiple */
2046 /* of the algorithms block size */
2047 plaintext_pad_len = tdata->plaintext.len >> 3;
2049 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2051 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2053 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2055 /* Create SNOW3G operation */
2056 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2057 tdata->digest.len, tdata->aad.data,
2058 tdata->aad.len, /*tdata->plaintext.len,*/
2059 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2060 tdata->iv.data, tdata->iv.len,
2061 tdata->validCipherLenInBits.len,
2062 tdata->validCipherOffsetLenInBits.len,
2063 tdata->validAuthLenInBits.len,
2064 tdata->validAuthOffsetLenInBits.len);
2068 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2070 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2071 ut_params->obuf = ut_params->op->sym->m_src;
2072 if (ut_params->obuf)
2073 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2076 ciphertext = plaintext;
2077 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2078 if (lastByteValidBits == 0)
2079 lastByteValidBits = 8;
2080 lastByteMask = lastByteMask << (8-lastByteValidBits);
2081 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2083 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2086 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2088 tdata->ciphertext.data,
2089 tdata->ciphertext.len >> 3,
2090 "Snow3G Ciphertext data not as expected");
2092 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2093 + plaintext_pad_len + tdata->aad.len;
2096 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2099 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2100 "Snow3G Generated auth tag not as expected");
2104 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2106 struct crypto_testsuite_params *ts_params = &testsuite_params;
2107 struct crypto_unittest_params *ut_params = &unittest_params;
2111 uint8_t *plaintext, *ciphertext;
2112 uint8_t plaintext_pad_len;
2113 uint8_t lastByteValidBits = 8;
2114 uint8_t lastByteMask = 0xFF;
2116 /* Create SNOW3G session */
2117 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2118 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2119 RTE_CRYPTO_AUTH_OP_GENERATE,
2120 tdata->key.data, tdata->key.len,
2121 tdata->aad.len, tdata->digest.len);
2125 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2127 /* clear mbuf payload */
2128 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2129 rte_pktmbuf_tailroom(ut_params->ibuf));
2131 /* Append data which is padded to a multiple */
2132 /* of the algorithms block size */
2133 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2135 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2137 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2139 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2141 /* Create SNOW3G operation */
2142 retval = create_snow3g_auth_cipher_operation(
2144 tdata->iv.data, tdata->iv.len,
2145 tdata->aad.data, tdata->aad.len,
2147 tdata->validCipherLenInBits.len,
2148 tdata->validCipherOffsetLenInBits.len,
2149 tdata->validAuthLenInBits.len,
2150 tdata->validAuthOffsetLenInBits.len
2156 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2158 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2159 ut_params->obuf = ut_params->op->sym->m_src;
2160 if (ut_params->obuf)
2161 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2162 + tdata->aad.len + tdata->iv.len;
2164 ciphertext = plaintext;
2166 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2167 if (lastByteValidBits == 0)
2168 lastByteValidBits = 8;
2169 lastByteMask = lastByteMask << (8-lastByteValidBits);
2170 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2171 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2172 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2173 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2176 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2178 tdata->ciphertext.data,
2179 tdata->ciphertext.len >> 3,
2180 "Snow3G Ciphertext data not as expected");
2183 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2186 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2187 "Snow3G Generated auth tag not as expected");
2192 test_snow3g_encryption_test_case_1(void)
2194 return test_snow3g_encryption(&snow3g_test_case_1);
2198 test_snow3g_encryption_test_case_1_oop(void)
2200 return test_snow3g_encryption_oop(&snow3g_test_case_1);
2204 test_snow3g_encryption_test_case_2(void)
2206 return test_snow3g_encryption(&snow3g_test_case_2);
2210 test_snow3g_encryption_test_case_3(void)
2212 return test_snow3g_encryption(&snow3g_test_case_3);
2216 test_snow3g_encryption_test_case_4(void)
2218 return test_snow3g_encryption(&snow3g_test_case_4);
2222 test_snow3g_encryption_test_case_5(void)
2224 return test_snow3g_encryption(&snow3g_test_case_5);
2228 test_snow3g_decryption_test_case_1(void)
2230 return test_snow3g_decryption(&snow3g_test_case_1);
2234 test_snow3g_decryption_test_case_1_oop(void)
2236 return test_snow3g_decryption_oop(&snow3g_test_case_1);
2240 test_snow3g_decryption_test_case_2(void)
2242 return test_snow3g_decryption(&snow3g_test_case_2);
2246 test_snow3g_decryption_test_case_3(void)
2248 return test_snow3g_decryption(&snow3g_test_case_3);
2252 test_snow3g_decryption_test_case_4(void)
2254 return test_snow3g_decryption(&snow3g_test_case_4);
2258 test_snow3g_decryption_test_case_5(void)
2260 return test_snow3g_decryption(&snow3g_test_case_5);
2263 test_snow3g_authenticated_encryption_test_case_1(void)
2265 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2269 test_snow3g_encrypted_authentication_test_case_1(void)
2271 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2274 /* ***** AES-GCM Tests ***** */
2277 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2278 const uint8_t *key, const uint8_t key_len,
2279 const uint8_t aad_len, const uint8_t auth_len)
2281 uint8_t cipher_key[key_len];
2283 struct crypto_unittest_params *ut_params = &unittest_params;
2286 memcpy(cipher_key, key, key_len);
2288 /* Setup Cipher Parameters */
2289 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2290 ut_params->cipher_xform.next = NULL;
2292 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2293 ut_params->cipher_xform.cipher.op = op;
2294 ut_params->cipher_xform.cipher.key.data = cipher_key;
2295 ut_params->cipher_xform.cipher.key.length = key_len;
2297 TEST_HEXDUMP(stdout, "key:", key, key_len);
2299 /* Setup Authentication Parameters */
2300 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2301 ut_params->auth_xform.next = NULL;
2303 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2305 ut_params->auth_xform.auth.digest_length = auth_len;
2306 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2307 ut_params->auth_xform.auth.key.length = 0;
2308 ut_params->auth_xform.auth.key.data = NULL;
2310 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2311 ut_params->cipher_xform.next = &ut_params->auth_xform;
2313 /* Create Crypto session*/
2314 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2315 &ut_params->cipher_xform);
2316 } else {/* Create Crypto session*/
2317 ut_params->auth_xform.next = &ut_params->cipher_xform;
2318 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2319 &ut_params->auth_xform);
2322 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2328 create_gcm_operation(enum rte_crypto_cipher_operation op,
2329 const uint8_t *auth_tag, const unsigned auth_tag_len,
2330 const uint8_t *iv, const unsigned iv_len,
2331 const uint8_t *aad, const unsigned aad_len,
2332 const unsigned data_len, unsigned data_pad_len)
2334 struct crypto_testsuite_params *ts_params = &testsuite_params;
2335 struct crypto_unittest_params *ut_params = &unittest_params;
2337 unsigned iv_pad_len = 0, aad_buffer_len;
2339 /* Generate Crypto op data structure */
2340 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2341 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2342 TEST_ASSERT_NOT_NULL(ut_params->op,
2343 "Failed to allocate symmetric crypto operation struct");
2345 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2349 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2350 ut_params->ibuf, auth_tag_len);
2351 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2352 "no room to append digest");
2353 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2354 ut_params->ibuf, data_pad_len);
2355 sym_op->auth.digest.length = auth_tag_len;
2357 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2358 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2359 TEST_HEXDUMP(stdout, "digest:",
2360 sym_op->auth.digest.data,
2361 sym_op->auth.digest.length);
2365 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2367 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2368 ut_params->ibuf, iv_pad_len);
2369 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2371 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2372 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2373 sym_op->cipher.iv.length = iv_pad_len;
2375 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2379 sym_op->cipher.iv.data[15] = 1;
2382 * Always allocate the aad up to the block size.
2383 * The cryptodev API calls out -
2384 * - the array must be big enough to hold the AAD, plus any
2385 * space to round this up to the nearest multiple of the
2386 * block size (16 bytes).
2388 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2390 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2391 ut_params->ibuf, aad_buffer_len);
2392 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2393 "no room to prepend aad");
2394 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2396 sym_op->auth.aad.length = aad_len;
2398 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2399 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2401 TEST_HEXDUMP(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
2402 TEST_HEXDUMP(stdout, "aad:",
2403 sym_op->auth.aad.data, aad_len);
2405 sym_op->cipher.data.length = data_len;
2406 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2408 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2409 sym_op->auth.data.length = data_len;
2415 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2417 struct crypto_testsuite_params *ts_params = &testsuite_params;
2418 struct crypto_unittest_params *ut_params = &unittest_params;
2422 uint8_t *plaintext, *ciphertext, *auth_tag;
2423 uint16_t plaintext_pad_len;
2425 /* Create GCM session */
2426 retval = create_gcm_session(ts_params->valid_devs[0],
2427 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2428 tdata->key.data, tdata->key.len,
2429 tdata->aad.len, tdata->auth_tag.len);
2434 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2436 /* clear mbuf payload */
2437 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2438 rte_pktmbuf_tailroom(ut_params->ibuf));
2441 * Append data which is padded to a multiple
2442 * of the algorithms block size
2444 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2446 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2448 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2450 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2452 /* Create GCM opertaion */
2453 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2454 tdata->auth_tag.data, tdata->auth_tag.len,
2455 tdata->iv.data, tdata->iv.len,
2456 tdata->aad.data, tdata->aad.len,
2457 tdata->plaintext.len, plaintext_pad_len);
2461 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2463 ut_params->op->sym->m_src = ut_params->ibuf;
2465 /* Process crypto operation */
2466 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2467 ut_params->op), "failed to process sym crypto op");
2469 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2470 "crypto op processing failed");
2472 if (ut_params->op->sym->m_dst) {
2473 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2475 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
2476 uint8_t *, plaintext_pad_len);
2478 ciphertext = plaintext;
2479 auth_tag = plaintext + plaintext_pad_len;
2482 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2483 TEST_HEXDUMP(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
2486 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2488 tdata->ciphertext.data,
2489 tdata->ciphertext.len,
2490 "GCM Ciphertext data not as expected");
2492 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2494 tdata->auth_tag.data,
2495 tdata->auth_tag.len,
2496 "GCM Generated auth tag not as expected");
2503 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
2505 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
2509 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
2511 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
2515 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
2517 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
2521 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
2523 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
2527 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
2529 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
2533 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
2535 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
2539 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
2541 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
2545 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
2547 struct crypto_testsuite_params *ts_params = &testsuite_params;
2548 struct crypto_unittest_params *ut_params = &unittest_params;
2552 uint8_t *plaintext, *ciphertext;
2553 uint16_t ciphertext_pad_len;
2555 /* Create GCM session */
2556 retval = create_gcm_session(ts_params->valid_devs[0],
2557 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2558 tdata->key.data, tdata->key.len,
2559 tdata->aad.len, tdata->auth_tag.len);
2564 /* alloc mbuf and set payload */
2565 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2567 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2568 rte_pktmbuf_tailroom(ut_params->ibuf));
2570 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2572 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2573 ciphertext_pad_len);
2574 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2576 TEST_HEXDUMP(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2578 /* Create GCM opertaion */
2579 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
2580 tdata->auth_tag.data, tdata->auth_tag.len,
2581 tdata->iv.data, tdata->iv.len,
2582 tdata->aad.data, tdata->aad.len,
2583 tdata->ciphertext.len, ciphertext_pad_len);
2588 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2590 ut_params->op->sym->m_src = ut_params->ibuf;
2592 /* Process crypto operation */
2593 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2594 ut_params->op), "failed to process sym crypto op");
2596 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2597 "crypto op processing failed");
2599 if (ut_params->op->sym->m_dst)
2600 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2603 plaintext = ciphertext;
2605 TEST_HEXDUMP(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
2608 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2610 tdata->plaintext.data,
2611 tdata->plaintext.len,
2612 "GCM plaintext data not as expected");
2614 TEST_ASSERT_EQUAL(ut_params->op->status,
2615 RTE_CRYPTO_OP_STATUS_SUCCESS,
2616 "GCM authentication failed");
2621 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
2623 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
2627 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
2629 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
2633 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
2635 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
2639 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
2641 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
2645 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
2647 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
2651 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
2653 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
2657 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
2659 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
2665 struct crypto_testsuite_params *ts_params = &testsuite_params;
2666 struct rte_cryptodev_stats stats;
2667 struct rte_cryptodev *dev;
2668 cryptodev_stats_get_t temp_pfn;
2670 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2671 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2672 &stats) == -ENODEV),
2673 "rte_cryptodev_stats_get invalid dev failed");
2674 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2675 "rte_cryptodev_stats_get invalid Param failed");
2676 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2677 temp_pfn = dev->dev_ops->stats_get;
2678 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2679 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2681 "rte_cryptodev_stats_get invalid Param failed");
2682 dev->dev_ops->stats_get = temp_pfn;
2684 /* Test expected values */
2686 test_AES_CBC_HMAC_SHA1_encrypt_digest();
2688 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2690 "rte_cryptodev_stats_get failed");
2691 TEST_ASSERT((stats.enqueued_count == 1),
2692 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2693 TEST_ASSERT((stats.dequeued_count == 1),
2694 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2695 TEST_ASSERT((stats.enqueue_err_count == 0),
2696 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2697 TEST_ASSERT((stats.dequeue_err_count == 0),
2698 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2700 /* invalid device but should ignore and not reset device stats*/
2701 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2702 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2704 "rte_cryptodev_stats_get failed");
2705 TEST_ASSERT((stats.enqueued_count == 1),
2706 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2708 /* check that a valid reset clears stats */
2709 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2710 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2712 "rte_cryptodev_stats_get failed");
2713 TEST_ASSERT((stats.enqueued_count == 0),
2714 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2715 TEST_ASSERT((stats.dequeued_count == 0),
2716 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2718 return TEST_SUCCESS;
2723 test_multi_session(void)
2725 struct crypto_testsuite_params *ts_params = &testsuite_params;
2726 struct crypto_unittest_params *ut_params = &unittest_params;
2728 struct rte_cryptodev_info dev_info;
2729 struct rte_cryptodev_sym_session **sessions;
2733 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2736 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2738 sessions = rte_malloc(NULL,
2739 (sizeof(struct rte_cryptodev_sym_session *) *
2740 dev_info.sym.max_nb_sessions) + 1, 0);
2742 /* Create multiple crypto sessions*/
2743 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2744 sessions[i] = rte_cryptodev_sym_session_create(
2745 ts_params->valid_devs[0],
2746 &ut_params->auth_xform);
2747 TEST_ASSERT_NOT_NULL(sessions[i],
2748 "Session creation failed at session number %u",
2751 /* Attempt to send a request on each session */
2752 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2753 sessions[i], ut_params, ts_params),
2754 "Failed to perform decrypt on request "
2756 /* free crypto operation structure */
2758 rte_crypto_op_free(ut_params->op);
2761 * free mbuf - both obuf and ibuf are usually the same,
2762 * but rte copes even if we call free twice
2764 if (ut_params->obuf) {
2765 rte_pktmbuf_free(ut_params->obuf);
2766 ut_params->obuf = 0;
2770 /* Next session create should fail */
2771 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2772 &ut_params->auth_xform);
2773 TEST_ASSERT_NULL(sessions[i],
2774 "Session creation succeeded unexpectedly!");
2776 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2777 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2782 return TEST_SUCCESS;
2786 test_null_cipher_only_operation(void)
2788 struct crypto_testsuite_params *ts_params = &testsuite_params;
2789 struct crypto_unittest_params *ut_params = &unittest_params;
2791 /* Generate test mbuf data and space for digest */
2792 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2793 catch_22_quote, QUOTE_512_BYTES, 0);
2795 /* Setup Cipher Parameters */
2796 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2797 ut_params->cipher_xform.next = NULL;
2799 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2800 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2802 /* Create Crypto session*/
2803 ut_params->sess = rte_cryptodev_sym_session_create(
2804 ts_params->valid_devs[0], &ut_params->cipher_xform);
2805 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2807 /* Generate Crypto op data structure */
2808 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2809 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2810 TEST_ASSERT_NOT_NULL(ut_params->op,
2811 "Failed to allocate symmetric crypto operation struct");
2813 /* Set crypto operation data parameters */
2814 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2816 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2818 /* set crypto operation source mbuf */
2819 sym_op->m_src = ut_params->ibuf;
2821 sym_op->cipher.data.offset = 0;
2822 sym_op->cipher.data.length = QUOTE_512_BYTES;
2824 /* Process crypto operation */
2825 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2827 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2829 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2830 "crypto operation processing failed");
2833 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2834 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2837 "Ciphertext data not as expected");
2839 return TEST_SUCCESS;
2843 test_null_auth_only_operation(void)
2845 struct crypto_testsuite_params *ts_params = &testsuite_params;
2846 struct crypto_unittest_params *ut_params = &unittest_params;
2848 /* Generate test mbuf data and space for digest */
2849 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2850 catch_22_quote, QUOTE_512_BYTES, 0);
2852 /* Setup HMAC Parameters */
2853 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2854 ut_params->auth_xform.next = NULL;
2856 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2857 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2859 /* Create Crypto session*/
2860 ut_params->sess = rte_cryptodev_sym_session_create(
2861 ts_params->valid_devs[0], &ut_params->auth_xform);
2862 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2864 /* Generate Crypto op data structure */
2865 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2866 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2867 TEST_ASSERT_NOT_NULL(ut_params->op,
2868 "Failed to allocate symmetric crypto operation struct");
2870 /* Set crypto operation data parameters */
2871 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2873 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2875 sym_op->m_src = ut_params->ibuf;
2877 sym_op->auth.data.offset = 0;
2878 sym_op->auth.data.length = QUOTE_512_BYTES;
2880 /* Process crypto operation */
2881 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2883 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2885 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2886 "crypto operation processing failed");
2888 return TEST_SUCCESS;
2892 test_null_cipher_auth_operation(void)
2894 struct crypto_testsuite_params *ts_params = &testsuite_params;
2895 struct crypto_unittest_params *ut_params = &unittest_params;
2897 /* Generate test mbuf data and space for digest */
2898 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2899 catch_22_quote, QUOTE_512_BYTES, 0);
2901 /* Setup Cipher Parameters */
2902 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2903 ut_params->cipher_xform.next = &ut_params->auth_xform;
2905 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2906 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2908 /* Setup HMAC Parameters */
2909 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2910 ut_params->auth_xform.next = NULL;
2912 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2913 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2915 /* Create Crypto session*/
2916 ut_params->sess = rte_cryptodev_sym_session_create(
2917 ts_params->valid_devs[0], &ut_params->cipher_xform);
2918 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2920 /* Generate Crypto op data structure */
2921 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2922 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2923 TEST_ASSERT_NOT_NULL(ut_params->op,
2924 "Failed to allocate symmetric crypto operation struct");
2926 /* Set crypto operation data parameters */
2927 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2929 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2931 sym_op->m_src = ut_params->ibuf;
2933 sym_op->cipher.data.offset = 0;
2934 sym_op->cipher.data.length = QUOTE_512_BYTES;
2936 sym_op->auth.data.offset = 0;
2937 sym_op->auth.data.length = QUOTE_512_BYTES;
2939 /* Process crypto operation */
2940 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2942 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2944 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2945 "crypto operation processing failed");
2948 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2949 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2952 "Ciphertext data not as expected");
2954 return TEST_SUCCESS;
2958 test_null_auth_cipher_operation(void)
2960 struct crypto_testsuite_params *ts_params = &testsuite_params;
2961 struct crypto_unittest_params *ut_params = &unittest_params;
2963 /* Generate test mbuf data and space for digest */
2964 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2965 catch_22_quote, QUOTE_512_BYTES, 0);
2967 /* Setup Cipher Parameters */
2968 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2969 ut_params->cipher_xform.next = NULL;
2971 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2972 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2974 /* Setup HMAC Parameters */
2975 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2976 ut_params->auth_xform.next = &ut_params->cipher_xform;
2978 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2979 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2981 /* Create Crypto session*/
2982 ut_params->sess = rte_cryptodev_sym_session_create(
2983 ts_params->valid_devs[0], &ut_params->cipher_xform);
2984 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2986 /* Generate Crypto op data structure */
2987 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2988 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2989 TEST_ASSERT_NOT_NULL(ut_params->op,
2990 "Failed to allocate symmetric crypto operation struct");
2992 /* Set crypto operation data parameters */
2993 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2995 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2997 sym_op->m_src = ut_params->ibuf;
2999 sym_op->cipher.data.offset = 0;
3000 sym_op->cipher.data.length = QUOTE_512_BYTES;
3002 sym_op->auth.data.offset = 0;
3003 sym_op->auth.data.length = QUOTE_512_BYTES;
3005 /* Process crypto operation */
3006 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3008 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3010 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3011 "crypto operation processing failed");
3014 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3015 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3018 "Ciphertext data not as expected");
3020 return TEST_SUCCESS;
3025 test_null_invalid_operation(void)
3027 struct crypto_testsuite_params *ts_params = &testsuite_params;
3028 struct crypto_unittest_params *ut_params = &unittest_params;
3030 /* Setup Cipher Parameters */
3031 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3032 ut_params->cipher_xform.next = NULL;
3034 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3035 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3037 /* Create Crypto session*/
3038 ut_params->sess = rte_cryptodev_sym_session_create(
3039 ts_params->valid_devs[0], &ut_params->cipher_xform);
3040 TEST_ASSERT_NULL(ut_params->sess,
3041 "Session creation succeeded unexpectedly");
3044 /* Setup HMAC Parameters */
3045 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3046 ut_params->auth_xform.next = NULL;
3048 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3049 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3051 /* Create Crypto session*/
3052 ut_params->sess = rte_cryptodev_sym_session_create(
3053 ts_params->valid_devs[0], &ut_params->auth_xform);
3054 TEST_ASSERT_NULL(ut_params->sess,
3055 "Session creation succeeded unexpectedly");
3057 return TEST_SUCCESS;
3061 #define NULL_BURST_LENGTH (32)
3064 test_null_burst_operation(void)
3066 struct crypto_testsuite_params *ts_params = &testsuite_params;
3067 struct crypto_unittest_params *ut_params = &unittest_params;
3069 unsigned i, burst_len = NULL_BURST_LENGTH;
3071 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3072 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3074 /* Setup Cipher Parameters */
3075 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3076 ut_params->cipher_xform.next = &ut_params->auth_xform;
3078 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3079 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3081 /* Setup HMAC Parameters */
3082 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3083 ut_params->auth_xform.next = NULL;
3085 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3086 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3088 /* Create Crypto session*/
3089 ut_params->sess = rte_cryptodev_sym_session_create(
3090 ts_params->valid_devs[0], &ut_params->cipher_xform);
3091 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3093 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3094 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3095 burst_len, "failed to generate burst of crypto ops");
3097 /* Generate an operation for each mbuf in burst */
3098 for (i = 0; i < burst_len; i++) {
3099 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3101 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3103 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3107 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3109 burst[i]->sym->m_src = m;
3112 /* Process crypto operation */
3113 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3114 0, burst, burst_len),
3116 "Error enqueuing burst");
3118 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3119 0, burst_dequeued, burst_len),
3121 "Error dequeuing burst");
3124 for (i = 0; i < burst_len; i++) {
3126 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3127 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3129 "data not as expected");
3131 rte_pktmbuf_free(burst[i]->sym->m_src);
3132 rte_crypto_op_free(burst[i]);
3135 return TEST_SUCCESS;
3141 static struct unit_test_suite cryptodev_qat_testsuite = {
3142 .suite_name = "Crypto QAT Unit Test Suite",
3143 .setup = testsuite_setup,
3144 .teardown = testsuite_teardown,
3145 .unit_test_cases = {
3146 TEST_CASE_ST(ut_setup, ut_teardown,
3147 test_device_configure_invalid_dev_id),
3148 TEST_CASE_ST(ut_setup, ut_teardown,
3149 test_device_configure_invalid_queue_pair_ids),
3150 TEST_CASE_ST(ut_setup, ut_teardown,
3151 test_queue_pair_descriptor_setup),
3152 TEST_CASE_ST(ut_setup, ut_teardown,
3153 test_multi_session),
3155 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3156 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3158 /** AES GCM Authenticated Encryption */
3159 TEST_CASE_ST(ut_setup, ut_teardown,
3160 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3161 TEST_CASE_ST(ut_setup, ut_teardown,
3162 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3163 TEST_CASE_ST(ut_setup, ut_teardown,
3164 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3165 TEST_CASE_ST(ut_setup, ut_teardown,
3166 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3167 TEST_CASE_ST(ut_setup, ut_teardown,
3168 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3169 TEST_CASE_ST(ut_setup, ut_teardown,
3170 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3171 TEST_CASE_ST(ut_setup, ut_teardown,
3172 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3174 /** AES GCM Authenticated Decryption */
3175 TEST_CASE_ST(ut_setup, ut_teardown,
3176 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3177 TEST_CASE_ST(ut_setup, ut_teardown,
3178 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3179 TEST_CASE_ST(ut_setup, ut_teardown,
3180 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3181 TEST_CASE_ST(ut_setup, ut_teardown,
3182 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3183 TEST_CASE_ST(ut_setup, ut_teardown,
3184 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3185 TEST_CASE_ST(ut_setup, ut_teardown,
3186 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3187 TEST_CASE_ST(ut_setup, ut_teardown,
3188 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3190 /** Snow3G encrypt only (UEA2) */
3191 TEST_CASE_ST(ut_setup, ut_teardown,
3192 test_snow3g_encryption_test_case_1),
3193 TEST_CASE_ST(ut_setup, ut_teardown,
3194 test_snow3g_encryption_test_case_2),
3195 TEST_CASE_ST(ut_setup, ut_teardown,
3196 test_snow3g_encryption_test_case_3),
3197 TEST_CASE_ST(ut_setup, ut_teardown,
3198 test_snow3g_encryption_test_case_4),
3199 TEST_CASE_ST(ut_setup, ut_teardown,
3200 test_snow3g_encryption_test_case_5),
3202 TEST_CASE_ST(ut_setup, ut_teardown,
3203 test_snow3g_encryption_test_case_1_oop),
3204 TEST_CASE_ST(ut_setup, ut_teardown,
3205 test_snow3g_decryption_test_case_1_oop),
3207 /** Snow3G decrypt only (UEA2) */
3208 TEST_CASE_ST(ut_setup, ut_teardown,
3209 test_snow3g_decryption_test_case_1),
3210 TEST_CASE_ST(ut_setup, ut_teardown,
3211 test_snow3g_decryption_test_case_2),
3212 TEST_CASE_ST(ut_setup, ut_teardown,
3213 test_snow3g_decryption_test_case_3),
3214 TEST_CASE_ST(ut_setup, ut_teardown,
3215 test_snow3g_decryption_test_case_4),
3216 TEST_CASE_ST(ut_setup, ut_teardown,
3217 test_snow3g_decryption_test_case_5),
3218 TEST_CASE_ST(ut_setup, ut_teardown,
3219 test_snow3g_hash_generate_test_case_1),
3220 TEST_CASE_ST(ut_setup, ut_teardown,
3221 test_snow3g_hash_generate_test_case_2),
3222 TEST_CASE_ST(ut_setup, ut_teardown,
3223 test_snow3g_hash_generate_test_case_3),
3224 TEST_CASE_ST(ut_setup, ut_teardown,
3225 test_snow3g_hash_verify_test_case_1),
3226 TEST_CASE_ST(ut_setup, ut_teardown,
3227 test_snow3g_hash_verify_test_case_2),
3228 TEST_CASE_ST(ut_setup, ut_teardown,
3229 test_snow3g_hash_verify_test_case_3),
3230 TEST_CASE_ST(ut_setup, ut_teardown,
3231 test_snow3g_authenticated_encryption_test_case_1),
3232 TEST_CASE_ST(ut_setup, ut_teardown,
3233 test_snow3g_encrypted_authentication_test_case_1),
3234 TEST_CASES_END() /**< NULL terminate unit test array */
3238 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3239 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3240 .setup = testsuite_setup,
3241 .teardown = testsuite_teardown,
3242 .unit_test_cases = {
3243 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3245 TEST_CASES_END() /**< NULL terminate unit test array */
3249 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
3250 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3251 .setup = testsuite_setup,
3252 .teardown = testsuite_teardown,
3253 .unit_test_cases = {
3254 /** AES GCM Authenticated Encryption */
3255 TEST_CASE_ST(ut_setup, ut_teardown,
3256 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3257 TEST_CASE_ST(ut_setup, ut_teardown,
3258 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3259 TEST_CASE_ST(ut_setup, ut_teardown,
3260 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3261 TEST_CASE_ST(ut_setup, ut_teardown,
3262 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3263 TEST_CASE_ST(ut_setup, ut_teardown,
3264 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3265 TEST_CASE_ST(ut_setup, ut_teardown,
3266 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3267 TEST_CASE_ST(ut_setup, ut_teardown,
3268 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3270 /** AES GCM Authenticated Decryption */
3271 TEST_CASE_ST(ut_setup, ut_teardown,
3272 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3273 TEST_CASE_ST(ut_setup, ut_teardown,
3274 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3275 TEST_CASE_ST(ut_setup, ut_teardown,
3276 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3277 TEST_CASE_ST(ut_setup, ut_teardown,
3278 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3279 TEST_CASE_ST(ut_setup, ut_teardown,
3280 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3281 TEST_CASE_ST(ut_setup, ut_teardown,
3282 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3283 TEST_CASE_ST(ut_setup, ut_teardown,
3284 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3286 TEST_CASES_END() /**< NULL terminate unit test array */
3290 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
3291 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3292 .setup = testsuite_setup,
3293 .teardown = testsuite_teardown,
3294 .unit_test_cases = {
3295 /** Snow3G encrypt only (UEA2) */
3296 TEST_CASE_ST(ut_setup, ut_teardown,
3297 test_snow3g_encryption_test_case_1),
3298 TEST_CASE_ST(ut_setup, ut_teardown,
3299 test_snow3g_encryption_test_case_2),
3300 TEST_CASE_ST(ut_setup, ut_teardown,
3301 test_snow3g_encryption_test_case_3),
3302 TEST_CASE_ST(ut_setup, ut_teardown,
3303 test_snow3g_encryption_test_case_4),
3304 TEST_CASE_ST(ut_setup, ut_teardown,
3305 test_snow3g_encryption_test_case_5),
3308 /** Snow3G decrypt only (UEA2) */
3309 TEST_CASE_ST(ut_setup, ut_teardown,
3310 test_snow3g_decryption_test_case_1),
3311 TEST_CASE_ST(ut_setup, ut_teardown,
3312 test_snow3g_decryption_test_case_2),
3313 TEST_CASE_ST(ut_setup, ut_teardown,
3314 test_snow3g_decryption_test_case_3),
3315 TEST_CASE_ST(ut_setup, ut_teardown,
3316 test_snow3g_decryption_test_case_4),
3317 TEST_CASE_ST(ut_setup, ut_teardown,
3318 test_snow3g_decryption_test_case_5),
3319 TEST_CASE_ST(ut_setup, ut_teardown,
3320 test_snow3g_hash_generate_test_case_1),
3321 TEST_CASE_ST(ut_setup, ut_teardown,
3322 test_snow3g_hash_generate_test_case_2),
3323 TEST_CASE_ST(ut_setup, ut_teardown,
3324 test_snow3g_hash_generate_test_case_3),
3325 TEST_CASE_ST(ut_setup, ut_teardown,
3326 test_snow3g_hash_verify_test_case_1),
3327 TEST_CASE_ST(ut_setup, ut_teardown,
3328 test_snow3g_hash_verify_test_case_2),
3329 TEST_CASE_ST(ut_setup, ut_teardown,
3330 test_snow3g_hash_verify_test_case_3),
3331 TEST_CASE_ST(ut_setup, ut_teardown,
3332 test_snow3g_authenticated_encryption_test_case_1),
3333 TEST_CASE_ST(ut_setup, ut_teardown,
3334 test_snow3g_encrypted_authentication_test_case_1),
3336 TEST_CASES_END() /**< NULL terminate unit test array */
3340 static struct unit_test_suite cryptodev_null_testsuite = {
3341 .suite_name = "Crypto Device NULL Unit Test Suite",
3342 .setup = testsuite_setup,
3343 .teardown = testsuite_teardown,
3344 .unit_test_cases = {
3345 TEST_CASE_ST(ut_setup, ut_teardown,
3346 test_null_auth_only_operation),
3347 TEST_CASE_ST(ut_setup, ut_teardown,
3348 test_null_cipher_only_operation),
3349 TEST_CASE_ST(ut_setup, ut_teardown,
3350 test_null_cipher_auth_operation),
3351 TEST_CASE_ST(ut_setup, ut_teardown,
3352 test_null_auth_cipher_operation),
3353 TEST_CASE_ST(ut_setup, ut_teardown,
3354 test_null_invalid_operation),
3355 TEST_CASE_ST(ut_setup, ut_teardown,
3356 test_null_burst_operation),
3358 TEST_CASES_END() /**< NULL terminate unit test array */
3363 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3365 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3366 return unit_test_suite_runner(&cryptodev_qat_testsuite);
3368 static struct test_command cryptodev_qat_cmd = {
3369 .command = "cryptodev_qat_autotest",
3370 .callback = test_cryptodev_qat,
3374 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3376 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3378 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3381 static struct test_command cryptodev_aesni_mb_cmd = {
3382 .command = "cryptodev_aesni_mb_autotest",
3383 .callback = test_cryptodev_aesni_mb,
3387 test_cryptodev_aesni_gcm(void)
3389 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
3391 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
3394 static struct test_command cryptodev_aesni_gcm_cmd = {
3395 .command = "cryptodev_aesni_gcm_autotest",
3396 .callback = test_cryptodev_aesni_gcm,
3400 test_cryptodev_null(void)
3402 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
3404 return unit_test_suite_runner(&cryptodev_null_testsuite);
3407 static struct test_command cryptodev_null_cmd = {
3408 .command = "cryptodev_null_autotest",
3409 .callback = test_cryptodev_null,
3413 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3415 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3417 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3420 static struct test_command cryptodev_sw_snow3g_cmd = {
3421 .command = "cryptodev_sw_snow3g_autotest",
3422 .callback = test_cryptodev_sw_snow3g,
3425 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3426 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3427 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
3428 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
3429 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);