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);
1078 #ifdef RTE_APP_TEST_DEBUG
1079 rte_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 #ifdef RTE_APP_TEST_DEBUG
1117 rte_hexdump(stdout, "key:", key, key_len);
1119 /* Create Crypto session */
1120 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1123 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1128 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1129 const unsigned cipher_len,
1130 const unsigned cipher_offset)
1132 struct crypto_testsuite_params *ts_params = &testsuite_params;
1133 struct crypto_unittest_params *ut_params = &unittest_params;
1134 unsigned iv_pad_len = 0;
1136 /* Generate Crypto op data structure */
1137 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1138 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1139 TEST_ASSERT_NOT_NULL(ut_params->op,
1140 "Failed to allocate pktmbuf offload");
1142 /* Set crypto operation data parameters */
1143 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1145 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1147 /* set crypto operation source mbuf */
1148 sym_op->m_src = ut_params->ibuf;
1151 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1152 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1155 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1157 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1158 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1159 sym_op->cipher.iv.length = iv_pad_len;
1161 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1162 sym_op->cipher.data.length = cipher_len;
1163 sym_op->cipher.data.offset = cipher_offset;
1168 create_snow3g_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1169 const unsigned cipher_len,
1170 const unsigned cipher_offset)
1172 struct crypto_testsuite_params *ts_params = &testsuite_params;
1173 struct crypto_unittest_params *ut_params = &unittest_params;
1174 unsigned iv_pad_len = 0;
1176 /* Generate Crypto op data structure */
1177 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1178 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1179 TEST_ASSERT_NOT_NULL(ut_params->op,
1180 "Failed to allocate pktmbuf offload");
1182 /* Set crypto operation data parameters */
1183 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1185 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1187 /* set crypto operation source mbuf */
1188 sym_op->m_src = ut_params->ibuf;
1189 sym_op->m_dst = ut_params->obuf;
1192 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1193 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1196 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1198 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1199 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1200 sym_op->cipher.iv.length = iv_pad_len;
1202 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1203 sym_op->cipher.data.length = cipher_len;
1204 sym_op->cipher.data.offset = cipher_offset;
1209 create_snow3g_cipher_auth_session(uint8_t dev_id,
1210 enum rte_crypto_cipher_operation cipher_op,
1211 enum rte_crypto_auth_operation auth_op,
1212 const uint8_t *key, const uint8_t key_len,
1213 const uint8_t aad_len, const uint8_t auth_len)
1215 uint8_t cipher_auth_key[key_len];
1217 struct crypto_unittest_params *ut_params = &unittest_params;
1219 memcpy(cipher_auth_key, key, key_len);
1221 /* Setup Authentication Parameters */
1222 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1223 ut_params->auth_xform.next = NULL;
1225 ut_params->auth_xform.auth.op = auth_op;
1226 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1227 ut_params->auth_xform.auth.key.length = key_len;
1228 /* Hash key = cipher key */
1229 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1230 ut_params->auth_xform.auth.digest_length = auth_len;
1231 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1233 /* Setup Cipher Parameters */
1234 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1235 ut_params->cipher_xform.next = &ut_params->auth_xform;
1237 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1238 ut_params->cipher_xform.cipher.op = cipher_op;
1239 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1240 ut_params->cipher_xform.cipher.key.length = key_len;
1242 #ifdef RTE_APP_TEST_DEBUG
1243 rte_hexdump(stdout, "key:", key, key_len);
1245 /* Create Crypto session*/
1246 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1247 &ut_params->cipher_xform);
1249 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1254 create_snow3g_auth_cipher_session(uint8_t dev_id,
1255 enum rte_crypto_cipher_operation cipher_op,
1256 enum rte_crypto_auth_operation auth_op,
1257 const uint8_t *key, const uint8_t key_len,
1258 const uint8_t aad_len, const uint8_t auth_len)
1260 uint8_t auth_cipher_key[key_len];
1262 struct crypto_unittest_params *ut_params = &unittest_params;
1264 memcpy(auth_cipher_key, key, key_len);
1266 /* Setup Authentication Parameters */
1267 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1268 ut_params->auth_xform.auth.op = auth_op;
1269 ut_params->auth_xform.next = &ut_params->cipher_xform;
1270 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1271 ut_params->auth_xform.auth.key.length = key_len;
1272 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1273 ut_params->auth_xform.auth.digest_length = auth_len;
1274 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1276 /* Setup Cipher Parameters */
1277 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1278 ut_params->cipher_xform.next = NULL;
1279 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1280 ut_params->cipher_xform.cipher.op = cipher_op;
1281 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1282 ut_params->cipher_xform.cipher.key.length = key_len;
1284 #ifdef RTE_APP_TEST_DEBUG
1285 rte_hexdump(stdout, "key:", key, key_len);
1287 /* Create Crypto session*/
1288 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1289 &ut_params->auth_xform);
1291 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1297 create_snow3g_hash_operation(const uint8_t *auth_tag,
1298 const unsigned auth_tag_len,
1299 const uint8_t *aad, const unsigned aad_len,
1300 unsigned data_pad_len,
1301 enum rte_crypto_auth_operation op,
1302 const unsigned auth_len, const unsigned auth_offset)
1304 struct crypto_testsuite_params *ts_params = &testsuite_params;
1306 struct crypto_unittest_params *ut_params = &unittest_params;
1308 unsigned aad_buffer_len;
1310 /* Generate Crypto op data structure */
1311 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1312 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1313 TEST_ASSERT_NOT_NULL(ut_params->op,
1314 "Failed to allocate pktmbuf offload");
1316 /* Set crypto operation data parameters */
1317 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1319 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1321 /* set crypto operation source mbuf */
1322 sym_op->m_src = ut_params->ibuf;
1326 * Always allocate the aad up to the block size.
1327 * The cryptodev API calls out -
1328 * - the array must be big enough to hold the AAD, plus any
1329 * space to round this up to the nearest multiple of the
1330 * block size (16 bytes).
1332 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1333 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1334 ut_params->ibuf, aad_buffer_len);
1335 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1336 "no room to prepend aad");
1337 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1339 sym_op->auth.aad.length = aad_len;
1341 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1342 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1344 #ifdef RTE_APP_TEST_DEBUG
1345 rte_hexdump(stdout, "aad:",
1346 sym_op->auth.aad.data, aad_len);
1350 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1351 ut_params->ibuf, auth_tag_len);
1353 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1354 "no room to append auth tag");
1355 ut_params->digest = sym_op->auth.digest.data;
1356 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1357 ut_params->ibuf, data_pad_len + aad_len);
1358 sym_op->auth.digest.length = auth_tag_len;
1359 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1360 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1362 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1364 #ifdef RTE_APP_TEST_DEBUG
1365 rte_hexdump(stdout, "digest:",
1366 sym_op->auth.digest.data,
1367 sym_op->auth.digest.length);
1370 sym_op->auth.data.length = auth_len;
1371 sym_op->auth.data.offset = auth_offset;
1377 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
1378 const unsigned auth_tag_len,
1379 const uint8_t *aad, const uint8_t aad_len,
1380 unsigned data_pad_len,
1381 enum rte_crypto_auth_operation op,
1382 const uint8_t *iv, const uint8_t iv_len,
1383 const unsigned cipher_len, const unsigned cipher_offset,
1384 const unsigned auth_len, const unsigned auth_offset)
1386 struct crypto_testsuite_params *ts_params = &testsuite_params;
1387 struct crypto_unittest_params *ut_params = &unittest_params;
1389 unsigned iv_pad_len = 0;
1390 unsigned aad_buffer_len;
1392 /* Generate Crypto op data structure */
1393 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1394 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1395 TEST_ASSERT_NOT_NULL(ut_params->op,
1396 "Failed to allocate pktmbuf offload");
1397 /* Set crypto operation data parameters */
1398 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1400 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1402 /* set crypto operation source mbuf */
1403 sym_op->m_src = ut_params->ibuf;
1407 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1409 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1410 ut_params->ibuf, iv_pad_len);
1411 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1413 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1414 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1415 sym_op->cipher.iv.length = iv_pad_len;
1417 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1419 sym_op->cipher.data.length = cipher_len;
1420 sym_op->cipher.data.offset = cipher_offset;
1424 * Always allocate the aad up to the block size.
1425 * The cryptodev API calls out -
1426 * - the array must be big enough to hold the AAD, plus any
1427 * space to round this up to the nearest multiple of the
1428 * block size (16 bytes).
1430 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1432 sym_op->auth.aad.data =
1433 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1434 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1435 "no room to prepend aad");
1436 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1438 sym_op->auth.aad.length = aad_len;
1440 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1441 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1443 #ifdef RTE_APP_TEST_DEBUG
1444 rte_hexdump(stdout, "aad:",
1445 sym_op->auth.aad.data, aad_len);
1449 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1450 ut_params->ibuf, auth_tag_len);
1452 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1453 "no room to append auth tag");
1454 ut_params->digest = sym_op->auth.digest.data;
1455 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1456 ut_params->ibuf, data_pad_len + aad_len);
1457 sym_op->auth.digest.length = auth_tag_len;
1458 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1459 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1461 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1463 #ifdef RTE_APP_TEST_DEBUG
1464 rte_hexdump(stdout, "digest:",
1465 sym_op->auth.digest.data,
1466 sym_op->auth.digest.length);
1469 sym_op->auth.data.length = auth_len;
1470 sym_op->auth.data.offset = auth_offset;
1476 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
1477 const uint8_t *iv, const uint8_t iv_len,
1478 const uint8_t *aad, const uint8_t aad_len,
1479 unsigned data_pad_len,
1480 const unsigned cipher_len, const unsigned cipher_offset,
1481 const unsigned auth_len, const unsigned auth_offset)
1483 struct crypto_testsuite_params *ts_params = &testsuite_params;
1484 struct crypto_unittest_params *ut_params = &unittest_params;
1486 unsigned iv_pad_len = 0;
1487 unsigned aad_buffer_len = 0;
1489 /* Generate Crypto op data structure */
1490 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1491 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1492 TEST_ASSERT_NOT_NULL(ut_params->op,
1493 "Failed to allocate pktmbuf offload");
1495 /* Set crypto operation data parameters */
1496 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1498 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1500 /* set crypto operation source mbuf */
1501 sym_op->m_src = ut_params->ibuf;
1504 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1505 ut_params->ibuf, auth_tag_len);
1507 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1508 "no room to append auth tag");
1510 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1511 ut_params->ibuf, data_pad_len);
1512 sym_op->auth.digest.length = auth_tag_len;
1514 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1516 #ifdef RTE_APP_TEST_DEBUG
1517 rte_hexdump(stdout, "digest:",
1518 sym_op->auth.digest.data,
1519 sym_op->auth.digest.length);
1522 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1524 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1525 ut_params->ibuf, iv_pad_len);
1526 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1528 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1529 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1530 sym_op->cipher.iv.length = iv_pad_len;
1532 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1536 * Always allocate the aad up to the block size.
1537 * The cryptodev API calls out -
1538 * - the array must be big enough to hold the AAD, plus any
1539 * space to round this up to the nearest multiple of the
1540 * block size (16 bytes).
1542 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1544 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1545 ut_params->ibuf, aad_buffer_len);
1546 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1547 "no room to prepend aad");
1548 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1550 sym_op->auth.aad.length = aad_len;
1552 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1553 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1555 #ifdef RTE_APP_TEST_DEBUG
1556 rte_hexdump(stdout, "aad:",
1557 sym_op->auth.aad.data, aad_len);
1560 sym_op->cipher.data.length = cipher_len;
1561 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1563 sym_op->auth.data.length = auth_len;
1564 sym_op->auth.data.offset = auth_offset + cipher_offset;
1570 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1572 struct crypto_testsuite_params *ts_params = &testsuite_params;
1573 struct crypto_unittest_params *ut_params = &unittest_params;
1576 unsigned plaintext_pad_len;
1579 /* Create SNOW3G session */
1580 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1581 tdata->key.data, tdata->key.len,
1582 tdata->aad.len, tdata->digest.len,
1583 RTE_CRYPTO_AUTH_OP_GENERATE);
1587 /* alloc mbuf and set payload */
1588 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1590 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1591 rte_pktmbuf_tailroom(ut_params->ibuf));
1593 /* Append data which is padded to a multiple of */
1594 /* the algorithms block size */
1595 plaintext_pad_len = tdata->plaintext.len >> 3;
1596 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1598 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1600 /* Create SNOW3G opertaion */
1601 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1602 tdata->aad.data, tdata->aad.len,
1603 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1604 tdata->validAuthLenInBits.len,
1605 tdata->validAuthOffsetLenInBits.len);
1609 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1611 ut_params->obuf = ut_params->op->sym->m_src;
1612 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1613 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1614 + plaintext_pad_len + tdata->aad.len;
1617 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1620 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1621 "Snow3G Generated auth tag not as expected");
1627 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1629 struct crypto_testsuite_params *ts_params = &testsuite_params;
1630 struct crypto_unittest_params *ut_params = &unittest_params;
1633 unsigned plaintext_pad_len;
1636 /* Create SNOW3G session */
1637 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1638 tdata->key.data, tdata->key.len,
1639 tdata->aad.len, tdata->digest.len,
1640 RTE_CRYPTO_AUTH_OP_VERIFY);
1643 /* alloc mbuf and set payload */
1644 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1646 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1647 rte_pktmbuf_tailroom(ut_params->ibuf));
1649 /* Append data which is padded to a multiple */
1650 /* of the algorithms block size */
1651 plaintext_pad_len = tdata->plaintext.len >> 3;
1652 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1654 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1656 /* Create SNOW3G operation */
1657 retval = create_snow3g_hash_operation(tdata->digest.data,
1659 tdata->aad.data, tdata->aad.len,
1661 RTE_CRYPTO_AUTH_OP_VERIFY,
1662 tdata->validAuthLenInBits.len,
1663 tdata->validAuthOffsetLenInBits.len);
1667 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1669 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1670 ut_params->obuf = ut_params->op->sym->m_src;
1671 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1672 + plaintext_pad_len + tdata->aad.len;
1675 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1685 test_snow3g_hash_generate_test_case_1(void)
1687 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1691 test_snow3g_hash_generate_test_case_2(void)
1693 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1697 test_snow3g_hash_generate_test_case_3(void)
1699 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1703 test_snow3g_hash_verify_test_case_1(void)
1705 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1710 test_snow3g_hash_verify_test_case_2(void)
1712 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1716 test_snow3g_hash_verify_test_case_3(void)
1718 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1722 test_snow3g_encryption(const struct snow3g_test_data *tdata)
1724 struct crypto_testsuite_params *ts_params = &testsuite_params;
1725 struct crypto_unittest_params *ut_params = &unittest_params;
1728 uint8_t *plaintext, *ciphertext;
1729 uint8_t plaintext_pad_len;
1730 uint8_t lastByteValidBits = 8;
1731 uint8_t lastByteMask = 0xFF;
1733 /* Create SNOW3G session */
1734 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1735 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1736 tdata->key.data, tdata->key.len);
1740 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1742 /* Clear mbuf payload */
1743 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1744 rte_pktmbuf_tailroom(ut_params->ibuf));
1747 * Append data which is padded to a
1748 * multiple of the algorithms block size
1750 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1751 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1753 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1755 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1757 #ifdef RTE_APP_TEST_DEBUG
1758 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1760 /* Create SNOW3G operation */
1761 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1762 tdata->validCipherLenInBits.len,
1763 tdata->validCipherOffsetLenInBits.len);
1767 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1769 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1771 ut_params->obuf = ut_params->op->sym->m_dst;
1772 if (ut_params->obuf)
1773 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1776 ciphertext = plaintext;
1778 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1779 if (lastByteValidBits == 0)
1780 lastByteValidBits = 8;
1781 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1782 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1784 #ifdef RTE_APP_TEST_DEBUG
1785 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1788 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1790 tdata->ciphertext.data,
1791 tdata->ciphertext.len >> 3,
1792 "Snow3G Ciphertext data not as expected");
1798 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
1800 struct crypto_testsuite_params *ts_params = &testsuite_params;
1801 struct crypto_unittest_params *ut_params = &unittest_params;
1802 uint8_t *plaintext, *ciphertext;
1805 uint8_t plaintext_pad_len;
1806 uint8_t lastByteValidBits = 8;
1807 uint8_t lastByteMask = 0xFF;
1809 /* Create SNOW3G session */
1810 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1811 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1812 tdata->key.data, tdata->key.len);
1816 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1817 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1819 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1820 "Failed to allocate input buffer in mempool");
1821 TEST_ASSERT_NOT_NULL(ut_params->obuf,
1822 "Failed to allocate output buffer in mempool");
1824 /* Clear mbuf payload */
1825 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1826 rte_pktmbuf_tailroom(ut_params->ibuf));
1829 * Append data which is padded to a
1830 * multiple of the algorithms block size
1832 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1833 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1835 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1838 rte_pktmbuf_append(ut_params->obuf,
1841 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1843 #ifdef RTE_APP_TEST_DEBUG
1844 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1846 /* Create SNOW3G operation */
1847 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1849 tdata->validCipherLenInBits.len,
1850 tdata->validCipherOffsetLenInBits.len);
1854 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1856 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1858 ut_params->obuf = ut_params->op->sym->m_dst;
1859 if (ut_params->obuf)
1860 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1863 ciphertext = plaintext;
1865 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1866 if (lastByteValidBits == 0)
1867 lastByteValidBits = 8;
1868 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1869 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1871 #ifdef RTE_APP_TEST_DEBUG
1872 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1875 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1877 tdata->ciphertext.data,
1878 tdata->ciphertext.len >> 3,
1879 "Snow3G Ciphertext data not as expected");
1884 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
1886 struct crypto_testsuite_params *ts_params = &testsuite_params;
1887 struct crypto_unittest_params *ut_params = &unittest_params;
1891 uint8_t *plaintext, *ciphertext;
1892 uint8_t ciphertext_pad_len;
1893 uint8_t lastByteValidBits = 8;
1894 uint8_t lastByteMask = 0xFF;
1896 /* Create SNOW3G session */
1897 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1898 RTE_CRYPTO_CIPHER_OP_DECRYPT,
1899 tdata->key.data, tdata->key.len);
1903 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1905 /* Clear mbuf payload */
1906 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1907 rte_pktmbuf_tailroom(ut_params->ibuf));
1910 * Append data which is padded to a
1911 * multiple of the algorithms block size
1913 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1915 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1916 ciphertext_pad_len);
1917 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1919 #ifdef RTE_APP_TEST_DEBUG
1920 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1922 /* Create SNOW3G operation */
1923 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1924 tdata->validCipherLenInBits.len,
1925 tdata->validCipherOffsetLenInBits.len);
1929 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1931 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1932 ut_params->obuf = ut_params->op->sym->m_src;
1933 if (ut_params->obuf)
1934 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1937 plaintext = ciphertext;
1938 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1939 if (lastByteValidBits == 0)
1940 lastByteValidBits = 8;
1941 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1942 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1944 #ifdef RTE_APP_TEST_DEBUG
1945 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1948 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1949 tdata->plaintext.data,
1950 tdata->plaintext.len >> 3,
1951 "Snow3G Plaintext data not as expected");
1955 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
1957 struct crypto_testsuite_params *ts_params = &testsuite_params;
1958 struct crypto_unittest_params *ut_params = &unittest_params;
1962 uint8_t *plaintext, *ciphertext;
1963 uint8_t ciphertext_pad_len;
1964 uint8_t lastByteValidBits = 8;
1965 uint8_t lastByteMask = 0xFF;
1967 /* Create SNOW3G session */
1968 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1969 RTE_CRYPTO_CIPHER_OP_DECRYPT,
1970 tdata->key.data, tdata->key.len);
1974 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1975 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1977 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1978 "Failed to allocate input buffer");
1979 TEST_ASSERT_NOT_NULL(ut_params->obuf,
1980 "Failed to allocate output buffer");
1982 /* Clear mbuf payload */
1983 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1984 rte_pktmbuf_tailroom(ut_params->ibuf));
1986 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
1987 rte_pktmbuf_tailroom(ut_params->obuf));
1990 * Append data which is padded to a
1991 * multiple of the algorithms block size
1993 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1995 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1996 ciphertext_pad_len);
1998 rte_pktmbuf_append(ut_params->obuf,
1999 ciphertext_pad_len);
2001 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2003 #ifdef RTE_APP_TEST_DEBUG
2004 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2006 /* Create SNOW3G operation */
2007 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2009 tdata->validCipherLenInBits.len,
2010 tdata->validCipherOffsetLenInBits.len);
2014 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2016 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2017 ut_params->obuf = ut_params->op->sym->m_dst;
2018 if (ut_params->obuf)
2019 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2022 plaintext = ciphertext;
2023 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2024 if (lastByteValidBits == 0)
2025 lastByteValidBits = 8;
2026 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2027 (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2029 #ifdef RTE_APP_TEST_DEBUG
2030 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2033 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2034 tdata->plaintext.data,
2035 tdata->plaintext.len >> 3,
2036 "Snow3G Plaintext data not as expected");
2041 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2043 struct crypto_testsuite_params *ts_params = &testsuite_params;
2044 struct crypto_unittest_params *ut_params = &unittest_params;
2048 uint8_t *plaintext, *ciphertext;
2049 uint8_t plaintext_pad_len;
2050 uint8_t lastByteValidBits = 8;
2051 uint8_t lastByteMask = 0xFF;
2053 /* Create SNOW3G session */
2054 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2055 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2056 RTE_CRYPTO_AUTH_OP_GENERATE,
2057 tdata->key.data, tdata->key.len,
2058 tdata->aad.len, tdata->digest.len);
2061 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2063 /* clear mbuf payload */
2064 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2065 rte_pktmbuf_tailroom(ut_params->ibuf));
2067 /* Append data which is padded to a multiple */
2068 /* of the algorithms block size */
2069 plaintext_pad_len = tdata->plaintext.len >> 3;
2071 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2073 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2075 #ifdef RTE_APP_TEST_DEBUG
2076 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2079 /* Create SNOW3G operation */
2080 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2081 tdata->digest.len, tdata->aad.data,
2082 tdata->aad.len, /*tdata->plaintext.len,*/
2083 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2084 tdata->iv.data, tdata->iv.len,
2085 tdata->validCipherLenInBits.len,
2086 tdata->validCipherOffsetLenInBits.len,
2087 tdata->validAuthLenInBits.len,
2088 tdata->validAuthOffsetLenInBits.len);
2092 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2094 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2095 ut_params->obuf = ut_params->op->sym->m_src;
2096 if (ut_params->obuf)
2097 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2100 ciphertext = plaintext;
2101 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2102 if (lastByteValidBits == 0)
2103 lastByteValidBits = 8;
2104 lastByteMask = lastByteMask << (8-lastByteValidBits);
2105 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2107 #ifdef RTE_APP_TEST_DEBUG
2108 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2111 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2113 tdata->ciphertext.data,
2114 tdata->ciphertext.len >> 3,
2115 "Snow3G Ciphertext data not as expected");
2117 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2118 + plaintext_pad_len + tdata->aad.len;
2121 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2124 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2125 "Snow3G Generated auth tag not as expected");
2129 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2131 struct crypto_testsuite_params *ts_params = &testsuite_params;
2132 struct crypto_unittest_params *ut_params = &unittest_params;
2136 uint8_t *plaintext, *ciphertext;
2137 uint8_t plaintext_pad_len;
2138 uint8_t lastByteValidBits = 8;
2139 uint8_t lastByteMask = 0xFF;
2141 /* Create SNOW3G session */
2142 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2143 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2144 RTE_CRYPTO_AUTH_OP_GENERATE,
2145 tdata->key.data, tdata->key.len,
2146 tdata->aad.len, tdata->digest.len);
2150 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2152 /* clear mbuf payload */
2153 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2154 rte_pktmbuf_tailroom(ut_params->ibuf));
2156 /* Append data which is padded to a multiple */
2157 /* of the algorithms block size */
2158 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2160 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2162 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2164 #ifdef RTE_APP_TEST_DEBUG
2165 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2168 /* Create SNOW3G operation */
2169 retval = create_snow3g_auth_cipher_operation(
2171 tdata->iv.data, tdata->iv.len,
2172 tdata->aad.data, tdata->aad.len,
2174 tdata->validCipherLenInBits.len,
2175 tdata->validCipherOffsetLenInBits.len,
2176 tdata->validAuthLenInBits.len,
2177 tdata->validAuthOffsetLenInBits.len
2183 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2185 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2186 ut_params->obuf = ut_params->op->sym->m_src;
2187 if (ut_params->obuf)
2188 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2189 + tdata->aad.len + tdata->iv.len;
2191 ciphertext = plaintext;
2193 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2194 if (lastByteValidBits == 0)
2195 lastByteValidBits = 8;
2196 lastByteMask = lastByteMask << (8-lastByteValidBits);
2197 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2198 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2199 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2200 #ifdef RTE_APP_TEST_DEBUG
2201 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2204 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2206 tdata->ciphertext.data,
2207 tdata->ciphertext.len >> 3,
2208 "Snow3G Ciphertext data not as expected");
2211 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2214 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2215 "Snow3G Generated auth tag not as expected");
2220 test_snow3g_encryption_test_case_1(void)
2222 return test_snow3g_encryption(&snow3g_test_case_1);
2226 test_snow3g_encryption_test_case_1_oop(void)
2228 return test_snow3g_encryption_oop(&snow3g_test_case_1);
2232 test_snow3g_encryption_test_case_2(void)
2234 return test_snow3g_encryption(&snow3g_test_case_2);
2238 test_snow3g_encryption_test_case_3(void)
2240 return test_snow3g_encryption(&snow3g_test_case_3);
2244 test_snow3g_encryption_test_case_4(void)
2246 return test_snow3g_encryption(&snow3g_test_case_4);
2250 test_snow3g_encryption_test_case_5(void)
2252 return test_snow3g_encryption(&snow3g_test_case_5);
2256 test_snow3g_decryption_test_case_1(void)
2258 return test_snow3g_decryption(&snow3g_test_case_1);
2262 test_snow3g_decryption_test_case_1_oop(void)
2264 return test_snow3g_decryption_oop(&snow3g_test_case_1);
2268 test_snow3g_decryption_test_case_2(void)
2270 return test_snow3g_decryption(&snow3g_test_case_2);
2274 test_snow3g_decryption_test_case_3(void)
2276 return test_snow3g_decryption(&snow3g_test_case_3);
2280 test_snow3g_decryption_test_case_4(void)
2282 return test_snow3g_decryption(&snow3g_test_case_4);
2286 test_snow3g_decryption_test_case_5(void)
2288 return test_snow3g_decryption(&snow3g_test_case_5);
2291 test_snow3g_authenticated_encryption_test_case_1(void)
2293 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2297 test_snow3g_encrypted_authentication_test_case_1(void)
2299 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2302 /* ***** AES-GCM Tests ***** */
2305 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2306 const uint8_t *key, const uint8_t key_len,
2307 const uint8_t aad_len, const uint8_t auth_len)
2309 uint8_t cipher_key[key_len];
2311 struct crypto_unittest_params *ut_params = &unittest_params;
2314 memcpy(cipher_key, key, key_len);
2316 /* Setup Cipher Parameters */
2317 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2318 ut_params->cipher_xform.next = NULL;
2320 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2321 ut_params->cipher_xform.cipher.op = op;
2322 ut_params->cipher_xform.cipher.key.data = cipher_key;
2323 ut_params->cipher_xform.cipher.key.length = key_len;
2325 #ifdef RTE_APP_TEST_DEBUG
2326 rte_hexdump(stdout, "key:", key, key_len);
2328 /* Setup Authentication Parameters */
2329 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2330 ut_params->auth_xform.next = NULL;
2332 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2334 ut_params->auth_xform.auth.digest_length = auth_len;
2335 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2336 ut_params->auth_xform.auth.key.length = 0;
2337 ut_params->auth_xform.auth.key.data = NULL;
2339 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2340 ut_params->cipher_xform.next = &ut_params->auth_xform;
2342 /* Create Crypto session*/
2343 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2344 &ut_params->cipher_xform);
2345 } else {/* Create Crypto session*/
2346 ut_params->auth_xform.next = &ut_params->cipher_xform;
2347 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2348 &ut_params->auth_xform);
2351 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2357 create_gcm_operation(enum rte_crypto_cipher_operation op,
2358 const uint8_t *auth_tag, const unsigned auth_tag_len,
2359 const uint8_t *iv, const unsigned iv_len,
2360 const uint8_t *aad, const unsigned aad_len,
2361 const unsigned data_len, unsigned data_pad_len)
2363 struct crypto_testsuite_params *ts_params = &testsuite_params;
2364 struct crypto_unittest_params *ut_params = &unittest_params;
2366 unsigned iv_pad_len = 0, aad_buffer_len;
2368 /* Generate Crypto op data structure */
2369 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2370 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2371 TEST_ASSERT_NOT_NULL(ut_params->op,
2372 "Failed to allocate symmetric crypto operation struct");
2374 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2378 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2379 ut_params->ibuf, auth_tag_len);
2380 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2381 "no room to append digest");
2382 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2383 ut_params->ibuf, data_pad_len);
2384 sym_op->auth.digest.length = auth_tag_len;
2386 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2387 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2388 #ifdef RTE_APP_TEST_DEBUG
2389 rte_hexdump(stdout, "digest:",
2390 sym_op->auth.digest.data,
2391 sym_op->auth.digest.length);
2396 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2398 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2399 ut_params->ibuf, iv_pad_len);
2400 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2402 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2403 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2404 sym_op->cipher.iv.length = iv_pad_len;
2406 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2410 sym_op->cipher.iv.data[15] = 1;
2413 * Always allocate the aad up to the block size.
2414 * The cryptodev API calls out -
2415 * - the array must be big enough to hold the AAD, plus any
2416 * space to round this up to the nearest multiple of the
2417 * block size (16 bytes).
2419 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2421 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2422 ut_params->ibuf, aad_buffer_len);
2423 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2424 "no room to prepend aad");
2425 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2427 sym_op->auth.aad.length = aad_len;
2429 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2430 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2432 #ifdef RTE_APP_TEST_DEBUG
2433 rte_hexdump(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
2434 rte_hexdump(stdout, "aad:",
2435 sym_op->auth.aad.data, aad_len);
2437 sym_op->cipher.data.length = data_len;
2438 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2440 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2441 sym_op->auth.data.length = data_len;
2447 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2449 struct crypto_testsuite_params *ts_params = &testsuite_params;
2450 struct crypto_unittest_params *ut_params = &unittest_params;
2454 uint8_t *plaintext, *ciphertext, *auth_tag;
2455 uint16_t plaintext_pad_len;
2457 /* Create GCM session */
2458 retval = create_gcm_session(ts_params->valid_devs[0],
2459 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2460 tdata->key.data, tdata->key.len,
2461 tdata->aad.len, tdata->auth_tag.len);
2466 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2468 /* clear mbuf payload */
2469 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2470 rte_pktmbuf_tailroom(ut_params->ibuf));
2473 * Append data which is padded to a multiple
2474 * of the algorithms block size
2476 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2478 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2480 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2482 #ifdef RTE_APP_TEST_DEBUG
2483 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2485 /* Create GCM opertaion */
2486 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2487 tdata->auth_tag.data, tdata->auth_tag.len,
2488 tdata->iv.data, tdata->iv.len,
2489 tdata->aad.data, tdata->aad.len,
2490 tdata->plaintext.len, plaintext_pad_len);
2494 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2496 ut_params->op->sym->m_src = ut_params->ibuf;
2498 /* Process crypto operation */
2499 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2500 ut_params->op), "failed to process sym crypto op");
2502 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2503 "crypto op processing failed");
2505 if (ut_params->op->sym->m_dst) {
2506 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2508 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
2509 uint8_t *, plaintext_pad_len);
2511 ciphertext = plaintext;
2512 auth_tag = plaintext + plaintext_pad_len;
2515 #ifdef RTE_APP_TEST_DEBUG
2516 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2517 rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
2520 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2522 tdata->ciphertext.data,
2523 tdata->ciphertext.len,
2524 "GCM Ciphertext data not as expected");
2526 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2528 tdata->auth_tag.data,
2529 tdata->auth_tag.len,
2530 "GCM Generated auth tag not as expected");
2537 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
2539 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
2543 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
2545 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
2549 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
2551 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
2555 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
2557 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
2561 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
2563 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
2567 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
2569 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
2573 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
2575 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
2579 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
2581 struct crypto_testsuite_params *ts_params = &testsuite_params;
2582 struct crypto_unittest_params *ut_params = &unittest_params;
2586 uint8_t *plaintext, *ciphertext;
2587 uint16_t ciphertext_pad_len;
2589 /* Create GCM session */
2590 retval = create_gcm_session(ts_params->valid_devs[0],
2591 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2592 tdata->key.data, tdata->key.len,
2593 tdata->aad.len, tdata->auth_tag.len);
2598 /* alloc mbuf and set payload */
2599 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2601 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2602 rte_pktmbuf_tailroom(ut_params->ibuf));
2604 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2606 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2607 ciphertext_pad_len);
2608 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2610 #ifdef RTE_APP_TEST_DEBUG
2611 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2613 /* Create GCM opertaion */
2614 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
2615 tdata->auth_tag.data, tdata->auth_tag.len,
2616 tdata->iv.data, tdata->iv.len,
2617 tdata->aad.data, tdata->aad.len,
2618 tdata->ciphertext.len, ciphertext_pad_len);
2623 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2625 ut_params->op->sym->m_src = ut_params->ibuf;
2627 /* Process crypto operation */
2628 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2629 ut_params->op), "failed to process sym crypto op");
2631 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2632 "crypto op processing failed");
2634 if (ut_params->op->sym->m_dst)
2635 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2638 plaintext = ciphertext;
2640 #ifdef RTE_APP_TEST_DEBUG
2641 rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
2644 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2646 tdata->plaintext.data,
2647 tdata->plaintext.len,
2648 "GCM plaintext data not as expected");
2650 TEST_ASSERT_EQUAL(ut_params->op->status,
2651 RTE_CRYPTO_OP_STATUS_SUCCESS,
2652 "GCM authentication failed");
2657 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
2659 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
2663 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
2665 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
2669 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
2671 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
2675 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
2677 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
2681 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
2683 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
2687 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
2689 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
2693 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
2695 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
2701 struct crypto_testsuite_params *ts_params = &testsuite_params;
2702 struct rte_cryptodev_stats stats;
2703 struct rte_cryptodev *dev;
2704 cryptodev_stats_get_t temp_pfn;
2706 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2707 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2708 &stats) == -ENODEV),
2709 "rte_cryptodev_stats_get invalid dev failed");
2710 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2711 "rte_cryptodev_stats_get invalid Param failed");
2712 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2713 temp_pfn = dev->dev_ops->stats_get;
2714 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2715 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2717 "rte_cryptodev_stats_get invalid Param failed");
2718 dev->dev_ops->stats_get = temp_pfn;
2720 /* Test expected values */
2722 test_AES_CBC_HMAC_SHA1_encrypt_digest();
2724 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2726 "rte_cryptodev_stats_get failed");
2727 TEST_ASSERT((stats.enqueued_count == 1),
2728 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2729 TEST_ASSERT((stats.dequeued_count == 1),
2730 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2731 TEST_ASSERT((stats.enqueue_err_count == 0),
2732 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2733 TEST_ASSERT((stats.dequeue_err_count == 0),
2734 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2736 /* invalid device but should ignore and not reset device stats*/
2737 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2738 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2740 "rte_cryptodev_stats_get failed");
2741 TEST_ASSERT((stats.enqueued_count == 1),
2742 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2744 /* check that a valid reset clears stats */
2745 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2746 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2748 "rte_cryptodev_stats_get failed");
2749 TEST_ASSERT((stats.enqueued_count == 0),
2750 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2751 TEST_ASSERT((stats.dequeued_count == 0),
2752 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2754 return TEST_SUCCESS;
2759 test_multi_session(void)
2761 struct crypto_testsuite_params *ts_params = &testsuite_params;
2762 struct crypto_unittest_params *ut_params = &unittest_params;
2764 struct rte_cryptodev_info dev_info;
2765 struct rte_cryptodev_sym_session **sessions;
2769 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2772 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2774 sessions = rte_malloc(NULL,
2775 (sizeof(struct rte_cryptodev_sym_session *) *
2776 dev_info.sym.max_nb_sessions) + 1, 0);
2778 /* Create multiple crypto sessions*/
2779 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2780 sessions[i] = rte_cryptodev_sym_session_create(
2781 ts_params->valid_devs[0],
2782 &ut_params->auth_xform);
2783 TEST_ASSERT_NOT_NULL(sessions[i],
2784 "Session creation failed at session number %u",
2787 /* Attempt to send a request on each session */
2788 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2789 sessions[i], ut_params, ts_params),
2790 "Failed to perform decrypt on request "
2792 /* free crypto operation structure */
2794 rte_crypto_op_free(ut_params->op);
2797 * free mbuf - both obuf and ibuf are usually the same,
2798 * but rte copes even if we call free twice
2800 if (ut_params->obuf) {
2801 rte_pktmbuf_free(ut_params->obuf);
2802 ut_params->obuf = 0;
2806 /* Next session create should fail */
2807 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2808 &ut_params->auth_xform);
2809 TEST_ASSERT_NULL(sessions[i],
2810 "Session creation succeeded unexpectedly!");
2812 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2813 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2818 return TEST_SUCCESS;
2822 test_null_cipher_only_operation(void)
2824 struct crypto_testsuite_params *ts_params = &testsuite_params;
2825 struct crypto_unittest_params *ut_params = &unittest_params;
2827 /* Generate test mbuf data and space for digest */
2828 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2829 catch_22_quote, QUOTE_512_BYTES, 0);
2831 /* Setup Cipher Parameters */
2832 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2833 ut_params->cipher_xform.next = NULL;
2835 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2836 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2838 /* Create Crypto session*/
2839 ut_params->sess = rte_cryptodev_sym_session_create(
2840 ts_params->valid_devs[0], &ut_params->cipher_xform);
2841 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2843 /* Generate Crypto op data structure */
2844 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2845 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2846 TEST_ASSERT_NOT_NULL(ut_params->op,
2847 "Failed to allocate symmetric crypto operation struct");
2849 /* Set crypto operation data parameters */
2850 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2852 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2854 /* set crypto operation source mbuf */
2855 sym_op->m_src = ut_params->ibuf;
2857 sym_op->cipher.data.offset = 0;
2858 sym_op->cipher.data.length = QUOTE_512_BYTES;
2860 /* Process crypto operation */
2861 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2863 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2865 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2866 "crypto operation processing failed");
2869 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2870 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2873 "Ciphertext data not as expected");
2875 return TEST_SUCCESS;
2879 test_null_auth_only_operation(void)
2881 struct crypto_testsuite_params *ts_params = &testsuite_params;
2882 struct crypto_unittest_params *ut_params = &unittest_params;
2884 /* Generate test mbuf data and space for digest */
2885 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2886 catch_22_quote, QUOTE_512_BYTES, 0);
2888 /* Setup HMAC Parameters */
2889 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2890 ut_params->auth_xform.next = NULL;
2892 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2893 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2895 /* Create Crypto session*/
2896 ut_params->sess = rte_cryptodev_sym_session_create(
2897 ts_params->valid_devs[0], &ut_params->auth_xform);
2898 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2900 /* Generate Crypto op data structure */
2901 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2902 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2903 TEST_ASSERT_NOT_NULL(ut_params->op,
2904 "Failed to allocate symmetric crypto operation struct");
2906 /* Set crypto operation data parameters */
2907 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2909 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2911 sym_op->m_src = ut_params->ibuf;
2913 sym_op->auth.data.offset = 0;
2914 sym_op->auth.data.length = QUOTE_512_BYTES;
2916 /* Process crypto operation */
2917 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2919 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2921 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2922 "crypto operation processing failed");
2924 return TEST_SUCCESS;
2928 test_null_cipher_auth_operation(void)
2930 struct crypto_testsuite_params *ts_params = &testsuite_params;
2931 struct crypto_unittest_params *ut_params = &unittest_params;
2933 /* Generate test mbuf data and space for digest */
2934 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2935 catch_22_quote, QUOTE_512_BYTES, 0);
2937 /* Setup Cipher Parameters */
2938 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2939 ut_params->cipher_xform.next = &ut_params->auth_xform;
2941 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2942 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2944 /* Setup HMAC Parameters */
2945 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2946 ut_params->auth_xform.next = NULL;
2948 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2949 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2951 /* Create Crypto session*/
2952 ut_params->sess = rte_cryptodev_sym_session_create(
2953 ts_params->valid_devs[0], &ut_params->cipher_xform);
2954 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2956 /* Generate Crypto op data structure */
2957 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2958 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2959 TEST_ASSERT_NOT_NULL(ut_params->op,
2960 "Failed to allocate symmetric crypto operation struct");
2962 /* Set crypto operation data parameters */
2963 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2965 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2967 sym_op->m_src = ut_params->ibuf;
2969 sym_op->cipher.data.offset = 0;
2970 sym_op->cipher.data.length = QUOTE_512_BYTES;
2972 sym_op->auth.data.offset = 0;
2973 sym_op->auth.data.length = QUOTE_512_BYTES;
2975 /* Process crypto operation */
2976 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2978 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2980 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2981 "crypto operation processing failed");
2984 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2985 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2988 "Ciphertext data not as expected");
2990 return TEST_SUCCESS;
2994 test_null_auth_cipher_operation(void)
2996 struct crypto_testsuite_params *ts_params = &testsuite_params;
2997 struct crypto_unittest_params *ut_params = &unittest_params;
2999 /* Generate test mbuf data and space for digest */
3000 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3001 catch_22_quote, QUOTE_512_BYTES, 0);
3003 /* Setup Cipher Parameters */
3004 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3005 ut_params->cipher_xform.next = NULL;
3007 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3008 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3010 /* Setup HMAC Parameters */
3011 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3012 ut_params->auth_xform.next = &ut_params->cipher_xform;
3014 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3015 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3017 /* Create Crypto session*/
3018 ut_params->sess = rte_cryptodev_sym_session_create(
3019 ts_params->valid_devs[0], &ut_params->cipher_xform);
3020 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3022 /* Generate Crypto op data structure */
3023 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3024 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3025 TEST_ASSERT_NOT_NULL(ut_params->op,
3026 "Failed to allocate symmetric crypto operation struct");
3028 /* Set crypto operation data parameters */
3029 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3031 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3033 sym_op->m_src = ut_params->ibuf;
3035 sym_op->cipher.data.offset = 0;
3036 sym_op->cipher.data.length = QUOTE_512_BYTES;
3038 sym_op->auth.data.offset = 0;
3039 sym_op->auth.data.length = QUOTE_512_BYTES;
3041 /* Process crypto operation */
3042 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3044 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3046 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3047 "crypto operation processing failed");
3050 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3051 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3054 "Ciphertext data not as expected");
3056 return TEST_SUCCESS;
3061 test_null_invalid_operation(void)
3063 struct crypto_testsuite_params *ts_params = &testsuite_params;
3064 struct crypto_unittest_params *ut_params = &unittest_params;
3066 /* Setup Cipher Parameters */
3067 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3068 ut_params->cipher_xform.next = NULL;
3070 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3071 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3073 /* Create Crypto session*/
3074 ut_params->sess = rte_cryptodev_sym_session_create(
3075 ts_params->valid_devs[0], &ut_params->cipher_xform);
3076 TEST_ASSERT_NULL(ut_params->sess,
3077 "Session creation succeeded unexpectedly");
3080 /* Setup HMAC Parameters */
3081 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3082 ut_params->auth_xform.next = NULL;
3084 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3085 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3087 /* Create Crypto session*/
3088 ut_params->sess = rte_cryptodev_sym_session_create(
3089 ts_params->valid_devs[0], &ut_params->auth_xform);
3090 TEST_ASSERT_NULL(ut_params->sess,
3091 "Session creation succeeded unexpectedly");
3093 return TEST_SUCCESS;
3097 #define NULL_BURST_LENGTH (32)
3100 test_null_burst_operation(void)
3102 struct crypto_testsuite_params *ts_params = &testsuite_params;
3103 struct crypto_unittest_params *ut_params = &unittest_params;
3105 unsigned i, burst_len = NULL_BURST_LENGTH;
3107 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3108 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3110 /* Setup Cipher Parameters */
3111 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3112 ut_params->cipher_xform.next = &ut_params->auth_xform;
3114 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3115 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3117 /* Setup HMAC Parameters */
3118 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3119 ut_params->auth_xform.next = NULL;
3121 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3122 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3124 /* Create Crypto session*/
3125 ut_params->sess = rte_cryptodev_sym_session_create(
3126 ts_params->valid_devs[0], &ut_params->cipher_xform);
3127 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3129 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3130 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3131 burst_len, "failed to generate burst of crypto ops");
3133 /* Generate an operation for each mbuf in burst */
3134 for (i = 0; i < burst_len; i++) {
3135 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3137 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3139 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3143 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3145 burst[i]->sym->m_src = m;
3148 /* Process crypto operation */
3149 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3150 0, burst, burst_len),
3152 "Error enqueuing burst");
3154 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3155 0, burst_dequeued, burst_len),
3157 "Error dequeuing burst");
3160 for (i = 0; i < burst_len; i++) {
3162 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3163 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3165 "data not as expected");
3167 rte_pktmbuf_free(burst[i]->sym->m_src);
3168 rte_crypto_op_free(burst[i]);
3171 return TEST_SUCCESS;
3177 static struct unit_test_suite cryptodev_qat_testsuite = {
3178 .suite_name = "Crypto QAT Unit Test Suite",
3179 .setup = testsuite_setup,
3180 .teardown = testsuite_teardown,
3181 .unit_test_cases = {
3182 TEST_CASE_ST(ut_setup, ut_teardown,
3183 test_device_configure_invalid_dev_id),
3184 TEST_CASE_ST(ut_setup, ut_teardown,
3185 test_device_configure_invalid_queue_pair_ids),
3186 TEST_CASE_ST(ut_setup, ut_teardown,
3187 test_queue_pair_descriptor_setup),
3188 TEST_CASE_ST(ut_setup, ut_teardown,
3189 test_multi_session),
3191 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3192 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3194 /** AES GCM Authenticated Encryption */
3195 TEST_CASE_ST(ut_setup, ut_teardown,
3196 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3197 TEST_CASE_ST(ut_setup, ut_teardown,
3198 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3199 TEST_CASE_ST(ut_setup, ut_teardown,
3200 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3201 TEST_CASE_ST(ut_setup, ut_teardown,
3202 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3203 TEST_CASE_ST(ut_setup, ut_teardown,
3204 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3205 TEST_CASE_ST(ut_setup, ut_teardown,
3206 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3207 TEST_CASE_ST(ut_setup, ut_teardown,
3208 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3210 /** AES GCM Authenticated Decryption */
3211 TEST_CASE_ST(ut_setup, ut_teardown,
3212 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3213 TEST_CASE_ST(ut_setup, ut_teardown,
3214 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3215 TEST_CASE_ST(ut_setup, ut_teardown,
3216 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3217 TEST_CASE_ST(ut_setup, ut_teardown,
3218 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3219 TEST_CASE_ST(ut_setup, ut_teardown,
3220 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3221 TEST_CASE_ST(ut_setup, ut_teardown,
3222 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3223 TEST_CASE_ST(ut_setup, ut_teardown,
3224 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3226 /** Snow3G encrypt only (UEA2) */
3227 TEST_CASE_ST(ut_setup, ut_teardown,
3228 test_snow3g_encryption_test_case_1),
3229 TEST_CASE_ST(ut_setup, ut_teardown,
3230 test_snow3g_encryption_test_case_2),
3231 TEST_CASE_ST(ut_setup, ut_teardown,
3232 test_snow3g_encryption_test_case_3),
3233 TEST_CASE_ST(ut_setup, ut_teardown,
3234 test_snow3g_encryption_test_case_4),
3235 TEST_CASE_ST(ut_setup, ut_teardown,
3236 test_snow3g_encryption_test_case_5),
3238 TEST_CASE_ST(ut_setup, ut_teardown,
3239 test_snow3g_encryption_test_case_1_oop),
3240 TEST_CASE_ST(ut_setup, ut_teardown,
3241 test_snow3g_decryption_test_case_1_oop),
3243 /** Snow3G decrypt only (UEA2) */
3244 TEST_CASE_ST(ut_setup, ut_teardown,
3245 test_snow3g_decryption_test_case_1),
3246 TEST_CASE_ST(ut_setup, ut_teardown,
3247 test_snow3g_decryption_test_case_2),
3248 TEST_CASE_ST(ut_setup, ut_teardown,
3249 test_snow3g_decryption_test_case_3),
3250 TEST_CASE_ST(ut_setup, ut_teardown,
3251 test_snow3g_decryption_test_case_4),
3252 TEST_CASE_ST(ut_setup, ut_teardown,
3253 test_snow3g_decryption_test_case_5),
3254 TEST_CASE_ST(ut_setup, ut_teardown,
3255 test_snow3g_hash_generate_test_case_1),
3256 TEST_CASE_ST(ut_setup, ut_teardown,
3257 test_snow3g_hash_generate_test_case_2),
3258 TEST_CASE_ST(ut_setup, ut_teardown,
3259 test_snow3g_hash_generate_test_case_3),
3260 TEST_CASE_ST(ut_setup, ut_teardown,
3261 test_snow3g_hash_verify_test_case_1),
3262 TEST_CASE_ST(ut_setup, ut_teardown,
3263 test_snow3g_hash_verify_test_case_2),
3264 TEST_CASE_ST(ut_setup, ut_teardown,
3265 test_snow3g_hash_verify_test_case_3),
3266 TEST_CASE_ST(ut_setup, ut_teardown,
3267 test_snow3g_authenticated_encryption_test_case_1),
3268 TEST_CASE_ST(ut_setup, ut_teardown,
3269 test_snow3g_encrypted_authentication_test_case_1),
3270 TEST_CASES_END() /**< NULL terminate unit test array */
3274 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3275 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3276 .setup = testsuite_setup,
3277 .teardown = testsuite_teardown,
3278 .unit_test_cases = {
3279 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3281 TEST_CASES_END() /**< NULL terminate unit test array */
3285 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
3286 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3287 .setup = testsuite_setup,
3288 .teardown = testsuite_teardown,
3289 .unit_test_cases = {
3290 /** AES GCM Authenticated Encryption */
3291 TEST_CASE_ST(ut_setup, ut_teardown,
3292 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3293 TEST_CASE_ST(ut_setup, ut_teardown,
3294 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3295 TEST_CASE_ST(ut_setup, ut_teardown,
3296 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3297 TEST_CASE_ST(ut_setup, ut_teardown,
3298 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3299 TEST_CASE_ST(ut_setup, ut_teardown,
3300 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3301 TEST_CASE_ST(ut_setup, ut_teardown,
3302 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3303 TEST_CASE_ST(ut_setup, ut_teardown,
3304 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3306 /** AES GCM Authenticated Decryption */
3307 TEST_CASE_ST(ut_setup, ut_teardown,
3308 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3309 TEST_CASE_ST(ut_setup, ut_teardown,
3310 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3311 TEST_CASE_ST(ut_setup, ut_teardown,
3312 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3313 TEST_CASE_ST(ut_setup, ut_teardown,
3314 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3315 TEST_CASE_ST(ut_setup, ut_teardown,
3316 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3317 TEST_CASE_ST(ut_setup, ut_teardown,
3318 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3319 TEST_CASE_ST(ut_setup, ut_teardown,
3320 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3322 TEST_CASES_END() /**< NULL terminate unit test array */
3326 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
3327 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3328 .setup = testsuite_setup,
3329 .teardown = testsuite_teardown,
3330 .unit_test_cases = {
3331 /** Snow3G encrypt only (UEA2) */
3332 TEST_CASE_ST(ut_setup, ut_teardown,
3333 test_snow3g_encryption_test_case_1),
3334 TEST_CASE_ST(ut_setup, ut_teardown,
3335 test_snow3g_encryption_test_case_2),
3336 TEST_CASE_ST(ut_setup, ut_teardown,
3337 test_snow3g_encryption_test_case_3),
3338 TEST_CASE_ST(ut_setup, ut_teardown,
3339 test_snow3g_encryption_test_case_4),
3340 TEST_CASE_ST(ut_setup, ut_teardown,
3341 test_snow3g_encryption_test_case_5),
3344 /** Snow3G decrypt only (UEA2) */
3345 TEST_CASE_ST(ut_setup, ut_teardown,
3346 test_snow3g_decryption_test_case_1),
3347 TEST_CASE_ST(ut_setup, ut_teardown,
3348 test_snow3g_decryption_test_case_2),
3349 TEST_CASE_ST(ut_setup, ut_teardown,
3350 test_snow3g_decryption_test_case_3),
3351 TEST_CASE_ST(ut_setup, ut_teardown,
3352 test_snow3g_decryption_test_case_4),
3353 TEST_CASE_ST(ut_setup, ut_teardown,
3354 test_snow3g_decryption_test_case_5),
3355 TEST_CASE_ST(ut_setup, ut_teardown,
3356 test_snow3g_hash_generate_test_case_1),
3357 TEST_CASE_ST(ut_setup, ut_teardown,
3358 test_snow3g_hash_generate_test_case_2),
3359 TEST_CASE_ST(ut_setup, ut_teardown,
3360 test_snow3g_hash_generate_test_case_3),
3361 TEST_CASE_ST(ut_setup, ut_teardown,
3362 test_snow3g_hash_verify_test_case_1),
3363 TEST_CASE_ST(ut_setup, ut_teardown,
3364 test_snow3g_hash_verify_test_case_2),
3365 TEST_CASE_ST(ut_setup, ut_teardown,
3366 test_snow3g_hash_verify_test_case_3),
3367 TEST_CASE_ST(ut_setup, ut_teardown,
3368 test_snow3g_authenticated_encryption_test_case_1),
3369 TEST_CASE_ST(ut_setup, ut_teardown,
3370 test_snow3g_encrypted_authentication_test_case_1),
3372 TEST_CASES_END() /**< NULL terminate unit test array */
3376 static struct unit_test_suite cryptodev_null_testsuite = {
3377 .suite_name = "Crypto Device NULL Unit Test Suite",
3378 .setup = testsuite_setup,
3379 .teardown = testsuite_teardown,
3380 .unit_test_cases = {
3381 TEST_CASE_ST(ut_setup, ut_teardown,
3382 test_null_auth_only_operation),
3383 TEST_CASE_ST(ut_setup, ut_teardown,
3384 test_null_cipher_only_operation),
3385 TEST_CASE_ST(ut_setup, ut_teardown,
3386 test_null_cipher_auth_operation),
3387 TEST_CASE_ST(ut_setup, ut_teardown,
3388 test_null_auth_cipher_operation),
3389 TEST_CASE_ST(ut_setup, ut_teardown,
3390 test_null_invalid_operation),
3391 TEST_CASE_ST(ut_setup, ut_teardown,
3392 test_null_burst_operation),
3394 TEST_CASES_END() /**< NULL terminate unit test array */
3399 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3401 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3402 return unit_test_suite_runner(&cryptodev_qat_testsuite);
3404 static struct test_command cryptodev_qat_cmd = {
3405 .command = "cryptodev_qat_autotest",
3406 .callback = test_cryptodev_qat,
3410 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3412 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3414 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3417 static struct test_command cryptodev_aesni_mb_cmd = {
3418 .command = "cryptodev_aesni_mb_autotest",
3419 .callback = test_cryptodev_aesni_mb,
3423 test_cryptodev_aesni_gcm(void)
3425 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
3427 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
3430 static struct test_command cryptodev_aesni_gcm_cmd = {
3431 .command = "cryptodev_aesni_gcm_autotest",
3432 .callback = test_cryptodev_aesni_gcm,
3436 test_cryptodev_null(void)
3438 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
3440 return unit_test_suite_runner(&cryptodev_null_testsuite);
3443 static struct test_command cryptodev_null_cmd = {
3444 .command = "cryptodev_null_autotest",
3445 .callback = test_cryptodev_null,
3449 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3451 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3453 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3456 static struct test_command cryptodev_sw_snow3g_cmd = {
3457 .command = "cryptodev_sw_snow3g_autotest",
3458 .callback = test_cryptodev_sw_snow3g,
3461 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3462 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3463 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
3464 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
3465 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);