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);
117 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
119 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
123 static struct rte_crypto_op *
124 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
127 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
130 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
131 printf("Error sending packet for encryption");
137 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
142 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
148 static struct crypto_testsuite_params testsuite_params = { NULL };
149 static struct crypto_unittest_params unittest_params;
152 testsuite_setup(void)
154 struct crypto_testsuite_params *ts_params = &testsuite_params;
155 struct rte_cryptodev_info info;
156 unsigned i, nb_devs, dev_id;
160 memset(ts_params, 0, sizeof(*ts_params));
162 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
163 if (ts_params->mbuf_pool == NULL) {
164 /* Not already created so create */
165 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
167 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
169 if (ts_params->mbuf_pool == NULL) {
170 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
175 ts_params->op_mpool = rte_crypto_op_pool_create(
176 "MBUF_CRYPTO_SYM_OP_POOL",
177 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
178 NUM_MBUFS, MBUF_CACHE_SIZE,
180 sizeof(struct rte_crypto_sym_xform),
182 if (ts_params->op_mpool == NULL) {
183 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
187 /* Create 2 AESNI MB devices if required */
188 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
189 nb_devs = rte_cryptodev_count_devtype(
190 RTE_CRYPTODEV_AESNI_MB_PMD);
192 for (i = nb_devs; i < 2; i++) {
193 ret = rte_eal_vdev_init(
194 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
196 TEST_ASSERT(ret == 0,
197 "Failed to create instance %u of"
199 i, CRYPTODEV_NAME_AESNI_MB_PMD);
204 /* Create 2 AESNI GCM devices if required */
205 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
206 nb_devs = rte_cryptodev_count_devtype(
207 RTE_CRYPTODEV_AESNI_GCM_PMD);
209 for (i = nb_devs; i < 2; i++) {
210 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
211 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
212 "Failed to create instance %u of"
214 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
219 /* Create 2 Snow3G devices if required */
220 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
221 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
223 for (i = nb_devs; i < 2; i++) {
224 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
225 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
226 "Failed to create instance %u of"
228 i, CRYPTODEV_NAME_SNOW3G_PMD);
233 /* Create 2 NULL devices if required */
234 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
235 nb_devs = rte_cryptodev_count_devtype(
236 RTE_CRYPTODEV_NULL_PMD);
238 for (i = nb_devs; i < 2; i++) {
239 int dev_id = rte_eal_vdev_init(
240 CRYPTODEV_NAME_NULL_PMD, NULL);
242 TEST_ASSERT(dev_id >= 0,
243 "Failed to create instance %u of"
245 i, CRYPTODEV_NAME_NULL_PMD);
250 nb_devs = rte_cryptodev_count();
252 RTE_LOG(ERR, USER1, "No crypto devices found?");
256 /* Create list of valid crypto devs */
257 for (i = 0; i < nb_devs; i++) {
258 rte_cryptodev_info_get(i, &info);
259 if (info.dev_type == gbl_cryptodev_type)
260 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
263 if (ts_params->valid_dev_count < 1)
266 /* Set up all the qps on the first of the valid devices found */
267 for (i = 0; i < 1; i++) {
268 dev_id = ts_params->valid_devs[i];
270 rte_cryptodev_info_get(dev_id, &info);
273 * Since we can't free and re-allocate queue memory always set
274 * the queues on this device up to max size first so enough
275 * memory is allocated for any later re-configures needed by
279 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
280 ts_params->conf.socket_id = SOCKET_ID_ANY;
281 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
283 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
285 "Failed to configure cryptodev %u with %u qps",
286 dev_id, ts_params->conf.nb_queue_pairs);
288 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
290 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
291 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
292 dev_id, qp_id, &ts_params->qp_conf,
293 rte_cryptodev_socket_id(dev_id)),
294 "Failed to setup queue pair %u on "
304 testsuite_teardown(void)
306 struct crypto_testsuite_params *ts_params = &testsuite_params;
308 if (ts_params->mbuf_pool != NULL) {
309 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
310 rte_mempool_count(ts_params->mbuf_pool));
313 if (ts_params->op_mpool != NULL) {
314 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
315 rte_mempool_count(ts_params->op_mpool));
323 struct crypto_testsuite_params *ts_params = &testsuite_params;
324 struct crypto_unittest_params *ut_params = &unittest_params;
328 /* Clear unit test parameters before running test */
329 memset(ut_params, 0, sizeof(*ut_params));
331 /* Reconfigure device to default parameters */
332 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
333 ts_params->conf.socket_id = SOCKET_ID_ANY;
334 ts_params->conf.session_mp.nb_objs =
335 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
336 DEFAULT_NUM_OPS_INFLIGHT :
337 DEFAULT_NUM_OPS_INFLIGHT;
339 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
341 "Failed to configure cryptodev %u",
342 ts_params->valid_devs[0]);
345 * Now reconfigure queues to size we actually want to use in this
348 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
350 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
351 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
352 ts_params->valid_devs[0], qp_id,
354 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
355 "Failed to setup queue pair %u on cryptodev %u",
356 qp_id, ts_params->valid_devs[0]);
360 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
362 /* Start the device */
363 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
364 "Failed to start cryptodev %u",
365 ts_params->valid_devs[0]);
373 struct crypto_testsuite_params *ts_params = &testsuite_params;
374 struct crypto_unittest_params *ut_params = &unittest_params;
375 struct rte_cryptodev_stats stats;
377 /* free crypto session structure */
378 if (ut_params->sess) {
379 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
381 ut_params->sess = NULL;
384 /* free crypto operation structure */
386 rte_crypto_op_free(ut_params->op);
389 * free mbuf - both obuf and ibuf are usually the same,
390 * but rte copes even if we call free twice
392 if (ut_params->obuf) {
393 rte_pktmbuf_free(ut_params->obuf);
396 if (ut_params->ibuf) {
397 rte_pktmbuf_free(ut_params->ibuf);
401 if (ts_params->mbuf_pool != NULL)
402 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
403 rte_mempool_count(ts_params->mbuf_pool));
405 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
407 /* Stop the device */
408 rte_cryptodev_stop(ts_params->valid_devs[0]);
412 test_device_configure_invalid_dev_id(void)
414 struct crypto_testsuite_params *ts_params = &testsuite_params;
415 uint16_t dev_id, num_devs = 0;
417 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
418 "Need at least %d devices for test", 1);
420 /* valid dev_id values */
421 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
423 /* Stop the device in case it's started so it can be configured */
424 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
426 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
427 "Failed test for rte_cryptodev_configure: "
428 "invalid dev_num %u", dev_id);
430 /* invalid dev_id values */
433 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
434 "Failed test for rte_cryptodev_configure: "
435 "invalid dev_num %u", dev_id);
439 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
440 "Failed test for rte_cryptodev_configure:"
441 "invalid dev_num %u", dev_id);
447 test_device_configure_invalid_queue_pair_ids(void)
449 struct crypto_testsuite_params *ts_params = &testsuite_params;
451 /* Stop the device in case it's started so it can be configured */
452 rte_cryptodev_stop(ts_params->valid_devs[0]);
454 /* valid - one queue pairs */
455 ts_params->conf.nb_queue_pairs = 1;
457 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
459 "Failed to configure cryptodev: dev_id %u, qp_id %u",
460 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
463 /* valid - max value queue pairs */
464 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
466 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
468 "Failed to configure cryptodev: dev_id %u, qp_id %u",
469 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
472 /* invalid - zero queue pairs */
473 ts_params->conf.nb_queue_pairs = 0;
475 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
477 "Failed test for rte_cryptodev_configure, dev_id %u,"
479 ts_params->valid_devs[0],
480 ts_params->conf.nb_queue_pairs);
483 /* invalid - max value supported by field queue pairs */
484 ts_params->conf.nb_queue_pairs = UINT16_MAX;
486 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
488 "Failed test for rte_cryptodev_configure, dev_id %u,"
490 ts_params->valid_devs[0],
491 ts_params->conf.nb_queue_pairs);
494 /* invalid - max value + 1 queue pairs */
495 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
497 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
499 "Failed test for rte_cryptodev_configure, dev_id %u,"
501 ts_params->valid_devs[0],
502 ts_params->conf.nb_queue_pairs);
508 test_queue_pair_descriptor_setup(void)
510 struct crypto_testsuite_params *ts_params = &testsuite_params;
511 struct rte_cryptodev_info dev_info;
512 struct rte_cryptodev_qp_conf qp_conf = {
513 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
518 /* Stop the device in case it's started so it can be configured */
519 rte_cryptodev_stop(ts_params->valid_devs[0]);
522 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
524 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
526 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
527 &ts_params->conf), "Failed to configure cryptodev %u",
528 ts_params->valid_devs[0]);
532 * Test various ring sizes on this device. memzones can't be
533 * freed so are re-used if ring is released and re-created.
535 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
537 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
538 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
539 ts_params->valid_devs[0], qp_id, &qp_conf,
540 rte_cryptodev_socket_id(
541 ts_params->valid_devs[0])),
543 "rte_cryptodev_queue_pair_setup: num_inflights "
544 "%u on qp %u on cryptodev %u",
545 qp_conf.nb_descriptors, qp_id,
546 ts_params->valid_devs[0]);
549 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
551 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
552 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
553 ts_params->valid_devs[0], qp_id, &qp_conf,
554 rte_cryptodev_socket_id(
555 ts_params->valid_devs[0])),
557 " rte_cryptodev_queue_pair_setup: num_inflights"
558 " %u on qp %u on cryptodev %u",
559 qp_conf.nb_descriptors, qp_id,
560 ts_params->valid_devs[0]);
563 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
565 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
566 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
567 ts_params->valid_devs[0], qp_id, &qp_conf,
568 rte_cryptodev_socket_id(
569 ts_params->valid_devs[0])),
571 "rte_cryptodev_queue_pair_setup: num_inflights"
572 " %u on qp %u on cryptodev %u",
573 qp_conf.nb_descriptors, qp_id,
574 ts_params->valid_devs[0]);
577 /* invalid number of descriptors - max supported + 2 */
578 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
580 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
581 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
582 ts_params->valid_devs[0], qp_id, &qp_conf,
583 rte_cryptodev_socket_id(
584 ts_params->valid_devs[0])),
585 "Unexpectedly passed test for "
586 "rte_cryptodev_queue_pair_setup:"
587 "num_inflights %u on qp %u on cryptodev %u",
588 qp_conf.nb_descriptors, qp_id,
589 ts_params->valid_devs[0]);
592 /* invalid number of descriptors - max value of parameter */
593 qp_conf.nb_descriptors = UINT32_MAX-1;
595 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
596 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
597 ts_params->valid_devs[0], qp_id, &qp_conf,
598 rte_cryptodev_socket_id(
599 ts_params->valid_devs[0])),
600 "Unexpectedly passed test for "
601 "rte_cryptodev_queue_pair_setup:"
602 "num_inflights %u on qp %u on cryptodev %u",
603 qp_conf.nb_descriptors, qp_id,
604 ts_params->valid_devs[0]);
607 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
609 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
610 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
611 ts_params->valid_devs[0], qp_id, &qp_conf,
612 rte_cryptodev_socket_id(
613 ts_params->valid_devs[0])),
615 " rte_cryptodev_queue_pair_setup:"
616 "num_inflights %u on qp %u on cryptodev %u",
617 qp_conf.nb_descriptors, qp_id,
618 ts_params->valid_devs[0]);
621 /* invalid number of descriptors - max supported + 1 */
622 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
624 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
625 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
626 ts_params->valid_devs[0], qp_id, &qp_conf,
627 rte_cryptodev_socket_id(
628 ts_params->valid_devs[0])),
629 "Unexpectedly passed test for "
630 "rte_cryptodev_queue_pair_setup:"
631 "num_inflights %u on qp %u on cryptodev %u",
632 qp_conf.nb_descriptors, qp_id,
633 ts_params->valid_devs[0]);
636 /* test invalid queue pair id */
637 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
639 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
641 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
642 ts_params->valid_devs[0],
644 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
645 "Failed test for rte_cryptodev_queue_pair_setup:"
646 "invalid qp %u on cryptodev %u",
647 qp_id, ts_params->valid_devs[0]);
649 qp_id = 0xffff; /*invalid*/
651 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
652 ts_params->valid_devs[0],
654 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
655 "Failed test for rte_cryptodev_queue_pair_setup:"
656 "invalid qp %u on cryptodev %u",
657 qp_id, ts_params->valid_devs[0]);
662 /* ***** Plaintext data for tests ***** */
664 const char catch_22_quote_1[] =
665 "There was only one catch and that was Catch-22, which "
666 "specified that a concern for one's safety in the face of "
667 "dangers that were real and immediate was the process of a "
668 "rational mind. Orr was crazy and could be grounded. All he "
669 "had to do was ask; and as soon as he did, he would no longer "
670 "be crazy and would have to fly more missions. Orr would be "
671 "crazy to fly more missions and sane if he didn't, but if he "
672 "was sane he had to fly them. If he flew them he was crazy "
673 "and didn't have to; but if he didn't want to he was sane and "
674 "had to. Yossarian was moved very deeply by the absolute "
675 "simplicity of this clause of Catch-22 and let out a "
676 "respectful whistle. \"That's some catch, that Catch-22\", he "
677 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
679 const char catch_22_quote[] =
680 "What a lousy earth! He wondered how many people were "
681 "destitute that same night even in his own prosperous country, "
682 "how many homes were shanties, how many husbands were drunk "
683 "and wives socked, and how many children were bullied, abused, "
684 "or abandoned. How many families hungered for food they could "
685 "not afford to buy? How many hearts were broken? How many "
686 "suicides would take place that same night, how many people "
687 "would go insane? How many cockroaches and landlords would "
688 "triumph? How many winners were losers, successes failures, "
689 "and rich men poor men? How many wise guys were stupid? How "
690 "many happy endings were unhappy endings? How many honest men "
691 "were liars, brave men cowards, loyal men traitors, how many "
692 "sainted men were corrupt, how many people in positions of "
693 "trust had sold their souls to bodyguards, how many had never "
694 "had souls? How many straight-and-narrow paths were crooked "
695 "paths? How many best families were worst families and how "
696 "many good people were bad people? When you added them all up "
697 "and then subtracted, you might be left with only the children, "
698 "and perhaps with Albert Einstein and an old violinist or "
699 "sculptor somewhere.";
701 #define QUOTE_480_BYTES (480)
702 #define QUOTE_512_BYTES (512)
703 #define QUOTE_768_BYTES (768)
704 #define QUOTE_1024_BYTES (1024)
708 /* ***** SHA1 Hash Tests ***** */
710 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
712 static uint8_t hmac_sha1_key[] = {
713 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
714 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
715 0xDE, 0xF4, 0xDE, 0xAD };
717 /* ***** SHA224 Hash Tests ***** */
719 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
722 /* ***** AES-CBC Cipher Tests ***** */
724 #define CIPHER_KEY_LENGTH_AES_CBC (16)
725 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
727 static uint8_t aes_cbc_key[] = {
728 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
729 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
731 static uint8_t aes_cbc_iv[] = {
732 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
733 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
736 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
738 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
739 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
740 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
741 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
742 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
743 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
744 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
745 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
746 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
747 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
748 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
749 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
750 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
751 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
752 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
753 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
754 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
755 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
756 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
757 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
758 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
759 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
760 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
761 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
762 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
763 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
764 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
765 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
766 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
767 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
768 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
769 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
770 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
771 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
772 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
773 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
774 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
775 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
776 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
777 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
778 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
779 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
780 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
781 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
782 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
783 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
784 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
785 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
786 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
787 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
788 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
789 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
790 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
791 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
792 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
793 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
794 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
795 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
796 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
797 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
798 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
799 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
800 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
801 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
802 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
805 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
806 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
807 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
808 0x18, 0x8c, 0x1d, 0x32
813 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
815 struct crypto_testsuite_params *ts_params = &testsuite_params;
816 struct crypto_unittest_params *ut_params = &unittest_params;
818 /* Generate test mbuf data and space for digest */
819 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
820 catch_22_quote, QUOTE_512_BYTES, 0);
822 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
823 DIGEST_BYTE_LENGTH_SHA1);
824 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
826 /* Setup Cipher Parameters */
827 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
828 ut_params->cipher_xform.next = &ut_params->auth_xform;
830 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
831 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
832 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
833 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
835 /* Setup HMAC Parameters */
836 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
838 ut_params->auth_xform.next = NULL;
840 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
841 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
842 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
843 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
844 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
846 /* Create crypto session*/
847 ut_params->sess = rte_cryptodev_sym_session_create(
848 ts_params->valid_devs[0],
849 &ut_params->cipher_xform);
850 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
852 /* Generate crypto op data structure */
853 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
854 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
855 TEST_ASSERT_NOT_NULL(ut_params->op,
856 "Failed to allocate symmetric crypto operation struct");
858 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
860 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
862 /* set crypto operation source mbuf */
863 sym_op->m_src = ut_params->ibuf;
865 /* Set crypto operation authentication parameters */
866 sym_op->auth.digest.data = ut_params->digest;
867 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
868 ut_params->ibuf, QUOTE_512_BYTES);
869 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
871 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
872 sym_op->auth.data.length = QUOTE_512_BYTES;
874 /* Set crypto operation cipher parameters */
875 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
876 CIPHER_IV_LENGTH_AES_CBC);
877 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
878 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
880 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
881 CIPHER_IV_LENGTH_AES_CBC);
883 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
884 sym_op->cipher.data.length = QUOTE_512_BYTES;
886 /* Process crypto operation */
887 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
888 ut_params->op), "failed to process sym crypto op");
890 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
891 "crypto op processing failed");
894 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
895 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
897 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
898 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
900 "ciphertext data not as expected");
902 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
904 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
905 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
906 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
907 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
908 DIGEST_BYTE_LENGTH_SHA1,
909 "Generated digest data not as expected");
914 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
916 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
918 static uint8_t hmac_sha512_key[] = {
919 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
920 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
921 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
922 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
923 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
924 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
925 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
926 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
928 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
929 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
930 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
931 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
932 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
933 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
934 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
935 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
936 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
941 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
942 struct crypto_unittest_params *ut_params);
945 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
946 struct crypto_unittest_params *ut_params,
947 struct crypto_testsuite_params *ts_params);
951 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
952 struct crypto_unittest_params *ut_params)
955 /* Setup Cipher Parameters */
956 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
957 ut_params->cipher_xform.next = NULL;
959 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
960 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
961 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
962 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
964 /* Setup HMAC Parameters */
965 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
966 ut_params->auth_xform.next = &ut_params->cipher_xform;
968 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
969 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
970 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
971 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
972 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
979 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
980 struct crypto_unittest_params *ut_params,
981 struct crypto_testsuite_params *ts_params)
983 /* Generate test mbuf data and digest */
984 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
986 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
989 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
990 DIGEST_BYTE_LENGTH_SHA512);
991 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
993 rte_memcpy(ut_params->digest,
994 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
995 DIGEST_BYTE_LENGTH_SHA512);
997 /* Generate Crypto op data structure */
998 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
999 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1000 TEST_ASSERT_NOT_NULL(ut_params->op,
1001 "Failed to allocate symmetric crypto operation struct");
1003 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1005 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1007 /* set crypto operation source mbuf */
1008 sym_op->m_src = ut_params->ibuf;
1010 sym_op->auth.digest.data = ut_params->digest;
1011 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1012 ut_params->ibuf, QUOTE_512_BYTES);
1013 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1015 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1016 sym_op->auth.data.length = QUOTE_512_BYTES;
1018 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1019 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1020 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1021 ut_params->ibuf, 0);
1022 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1024 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1025 CIPHER_IV_LENGTH_AES_CBC);
1027 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1028 sym_op->cipher.data.length = QUOTE_512_BYTES;
1030 /* Process crypto operation */
1031 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1032 ut_params->op), "failed to process sym crypto op");
1034 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1035 "crypto op processing failed");
1037 ut_params->obuf = ut_params->op->sym->m_src;
1040 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1041 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1042 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1044 "Plaintext data not as expected");
1047 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1048 "Digest verification failed");
1050 return TEST_SUCCESS;
1054 test_AES_mb_all(void)
1056 struct crypto_testsuite_params *ts_params = &testsuite_params;
1059 status = test_AES_all_tests(ts_params->mbuf_pool,
1060 ts_params->op_mpool, ts_params->valid_devs[0],
1061 RTE_CRYPTODEV_AESNI_MB_PMD);
1063 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1065 return TEST_SUCCESS;
1069 test_AES_qat_all(void)
1071 struct crypto_testsuite_params *ts_params = &testsuite_params;
1074 status = test_AES_all_tests(ts_params->mbuf_pool,
1075 ts_params->op_mpool, ts_params->valid_devs[0],
1076 RTE_CRYPTODEV_QAT_SYM_PMD);
1078 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1080 return TEST_SUCCESS;
1083 /* ***** Snow3G Tests ***** */
1085 create_snow3g_hash_session(uint8_t dev_id,
1086 const uint8_t *key, const uint8_t key_len,
1087 const uint8_t aad_len, const uint8_t auth_len,
1088 enum rte_crypto_auth_operation op)
1090 uint8_t hash_key[key_len];
1092 struct crypto_unittest_params *ut_params = &unittest_params;
1094 memcpy(hash_key, key, key_len);
1095 #ifdef RTE_APP_TEST_DEBUG
1096 rte_hexdump(stdout, "key:", key, key_len);
1098 /* Setup Authentication Parameters */
1099 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1100 ut_params->auth_xform.next = NULL;
1102 ut_params->auth_xform.auth.op = op;
1103 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1104 ut_params->auth_xform.auth.key.length = key_len;
1105 ut_params->auth_xform.auth.key.data = hash_key;
1106 ut_params->auth_xform.auth.digest_length = auth_len;
1107 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1108 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1109 &ut_params->auth_xform);
1110 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1114 create_snow3g_cipher_session(uint8_t dev_id,
1115 enum rte_crypto_cipher_operation op,
1116 const uint8_t *key, const uint8_t key_len)
1118 uint8_t cipher_key[key_len];
1120 struct crypto_unittest_params *ut_params = &unittest_params;
1122 memcpy(cipher_key, key, key_len);
1124 /* Setup Cipher Parameters */
1125 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1126 ut_params->cipher_xform.next = NULL;
1128 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1129 ut_params->cipher_xform.cipher.op = op;
1130 ut_params->cipher_xform.cipher.key.data = cipher_key;
1131 ut_params->cipher_xform.cipher.key.length = key_len;
1133 #ifdef RTE_APP_TEST_DEBUG
1134 rte_hexdump(stdout, "key:", key, key_len);
1136 /* Create Crypto session */
1137 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1140 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1145 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1146 const unsigned cipher_len,
1147 const unsigned cipher_offset)
1149 struct crypto_testsuite_params *ts_params = &testsuite_params;
1150 struct crypto_unittest_params *ut_params = &unittest_params;
1151 unsigned iv_pad_len = 0;
1153 /* Generate Crypto op data structure */
1154 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1155 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1156 TEST_ASSERT_NOT_NULL(ut_params->op,
1157 "Failed to allocate pktmbuf offload");
1159 /* Set crypto operation data parameters */
1160 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1162 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1164 /* set crypto operation source mbuf */
1165 sym_op->m_src = ut_params->ibuf;
1168 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1169 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1172 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1174 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1175 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1176 sym_op->cipher.iv.length = iv_pad_len;
1178 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1179 sym_op->cipher.data.length = cipher_len;
1180 sym_op->cipher.data.offset = cipher_offset;
1185 create_snow3g_cipher_operation_oop(const uint8_t *iv, const uint8_t iv_len,
1186 const unsigned cipher_len,
1187 const unsigned cipher_offset)
1189 struct crypto_testsuite_params *ts_params = &testsuite_params;
1190 struct crypto_unittest_params *ut_params = &unittest_params;
1191 unsigned iv_pad_len = 0;
1193 /* Generate Crypto op data structure */
1194 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1195 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1196 TEST_ASSERT_NOT_NULL(ut_params->op,
1197 "Failed to allocate pktmbuf offload");
1199 /* Set crypto operation data parameters */
1200 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1202 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1204 /* set crypto operation source mbuf */
1205 sym_op->m_src = ut_params->ibuf;
1206 sym_op->m_dst = ut_params->obuf;
1209 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1210 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1213 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1215 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1216 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1217 sym_op->cipher.iv.length = iv_pad_len;
1219 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1220 sym_op->cipher.data.length = cipher_len;
1221 sym_op->cipher.data.offset = cipher_offset;
1226 create_snow3g_cipher_auth_session(uint8_t dev_id,
1227 enum rte_crypto_cipher_operation cipher_op,
1228 enum rte_crypto_auth_operation auth_op,
1229 const uint8_t *key, const uint8_t key_len,
1230 const uint8_t aad_len, const uint8_t auth_len)
1232 uint8_t cipher_auth_key[key_len];
1234 struct crypto_unittest_params *ut_params = &unittest_params;
1236 memcpy(cipher_auth_key, key, key_len);
1238 /* Setup Authentication Parameters */
1239 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1240 ut_params->auth_xform.next = NULL;
1242 ut_params->auth_xform.auth.op = auth_op;
1243 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1244 ut_params->auth_xform.auth.key.length = key_len;
1245 /* Hash key = cipher key */
1246 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1247 ut_params->auth_xform.auth.digest_length = auth_len;
1248 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1250 /* Setup Cipher Parameters */
1251 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1252 ut_params->cipher_xform.next = &ut_params->auth_xform;
1254 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1255 ut_params->cipher_xform.cipher.op = cipher_op;
1256 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1257 ut_params->cipher_xform.cipher.key.length = key_len;
1259 #ifdef RTE_APP_TEST_DEBUG
1260 rte_hexdump(stdout, "key:", key, key_len);
1262 /* Create Crypto session*/
1263 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1264 &ut_params->cipher_xform);
1266 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1271 create_snow3g_auth_cipher_session(uint8_t dev_id,
1272 enum rte_crypto_cipher_operation cipher_op,
1273 enum rte_crypto_auth_operation auth_op,
1274 const uint8_t *key, const uint8_t key_len,
1275 const uint8_t aad_len, const uint8_t auth_len)
1277 uint8_t auth_cipher_key[key_len];
1279 struct crypto_unittest_params *ut_params = &unittest_params;
1281 memcpy(auth_cipher_key, key, key_len);
1283 /* Setup Authentication Parameters */
1284 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1285 ut_params->auth_xform.auth.op = auth_op;
1286 ut_params->auth_xform.next = &ut_params->cipher_xform;
1287 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1288 ut_params->auth_xform.auth.key.length = key_len;
1289 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1290 ut_params->auth_xform.auth.digest_length = auth_len;
1291 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1293 /* Setup Cipher Parameters */
1294 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1295 ut_params->cipher_xform.next = NULL;
1296 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1297 ut_params->cipher_xform.cipher.op = cipher_op;
1298 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1299 ut_params->cipher_xform.cipher.key.length = key_len;
1301 #ifdef RTE_APP_TEST_DEBUG
1302 rte_hexdump(stdout, "key:", key, key_len);
1304 /* Create Crypto session*/
1305 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1306 &ut_params->auth_xform);
1308 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1314 create_snow3g_hash_operation(const uint8_t *auth_tag,
1315 const unsigned auth_tag_len,
1316 const uint8_t *aad, const unsigned aad_len,
1317 unsigned data_pad_len,
1318 enum rte_crypto_auth_operation op,
1319 const unsigned auth_len, const unsigned auth_offset)
1321 struct crypto_testsuite_params *ts_params = &testsuite_params;
1323 struct crypto_unittest_params *ut_params = &unittest_params;
1325 unsigned aad_buffer_len;
1327 /* Generate Crypto op data structure */
1328 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1329 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1330 TEST_ASSERT_NOT_NULL(ut_params->op,
1331 "Failed to allocate pktmbuf offload");
1333 /* Set crypto operation data parameters */
1334 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1336 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1338 /* set crypto operation source mbuf */
1339 sym_op->m_src = ut_params->ibuf;
1343 * Always allocate the aad up to the block size.
1344 * The cryptodev API calls out -
1345 * - the array must be big enough to hold the AAD, plus any
1346 * space to round this up to the nearest multiple of the
1347 * block size (16 bytes).
1349 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1350 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1351 ut_params->ibuf, aad_buffer_len);
1352 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1353 "no room to prepend aad");
1354 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1356 sym_op->auth.aad.length = aad_len;
1358 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1359 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1361 #ifdef RTE_APP_TEST_DEBUG
1362 rte_hexdump(stdout, "aad:",
1363 sym_op->auth.aad.data, aad_len);
1367 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1368 ut_params->ibuf, auth_tag_len);
1370 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1371 "no room to append auth tag");
1372 ut_params->digest = sym_op->auth.digest.data;
1373 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1374 ut_params->ibuf, data_pad_len + aad_len);
1375 sym_op->auth.digest.length = auth_tag_len;
1376 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1377 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1379 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1381 #ifdef RTE_APP_TEST_DEBUG
1382 rte_hexdump(stdout, "digest:",
1383 sym_op->auth.digest.data,
1384 sym_op->auth.digest.length);
1387 sym_op->auth.data.length = auth_len;
1388 sym_op->auth.data.offset = auth_offset;
1394 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
1395 const unsigned auth_tag_len,
1396 const uint8_t *aad, const uint8_t aad_len,
1397 unsigned data_pad_len,
1398 enum rte_crypto_auth_operation op,
1399 const uint8_t *iv, const uint8_t iv_len,
1400 const unsigned cipher_len, const unsigned cipher_offset,
1401 const unsigned auth_len, const unsigned auth_offset)
1403 struct crypto_testsuite_params *ts_params = &testsuite_params;
1404 struct crypto_unittest_params *ut_params = &unittest_params;
1406 unsigned iv_pad_len = 0;
1407 unsigned aad_buffer_len;
1409 /* Generate Crypto op data structure */
1410 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1411 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1412 TEST_ASSERT_NOT_NULL(ut_params->op,
1413 "Failed to allocate pktmbuf offload");
1414 /* Set crypto operation data parameters */
1415 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1417 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1419 /* set crypto operation source mbuf */
1420 sym_op->m_src = ut_params->ibuf;
1424 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1426 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1427 ut_params->ibuf, iv_pad_len);
1428 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1430 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1431 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1432 sym_op->cipher.iv.length = iv_pad_len;
1434 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1436 sym_op->cipher.data.length = cipher_len;
1437 sym_op->cipher.data.offset = cipher_offset;
1441 * Always allocate the aad up to the block size.
1442 * The cryptodev API calls out -
1443 * - the array must be big enough to hold the AAD, plus any
1444 * space to round this up to the nearest multiple of the
1445 * block size (16 bytes).
1447 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1449 sym_op->auth.aad.data =
1450 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
1451 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1452 "no room to prepend aad");
1453 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1455 sym_op->auth.aad.length = aad_len;
1457 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1458 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1460 #ifdef RTE_APP_TEST_DEBUG
1461 rte_hexdump(stdout, "aad:",
1462 sym_op->auth.aad.data, aad_len);
1466 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1467 ut_params->ibuf, auth_tag_len);
1469 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1470 "no room to append auth tag");
1471 ut_params->digest = sym_op->auth.digest.data;
1472 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1473 ut_params->ibuf, data_pad_len + aad_len);
1474 sym_op->auth.digest.length = auth_tag_len;
1475 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
1476 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1478 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
1480 #ifdef RTE_APP_TEST_DEBUG
1481 rte_hexdump(stdout, "digest:",
1482 sym_op->auth.digest.data,
1483 sym_op->auth.digest.length);
1486 sym_op->auth.data.length = auth_len;
1487 sym_op->auth.data.offset = auth_offset;
1493 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
1494 const uint8_t *iv, const uint8_t iv_len,
1495 const uint8_t *aad, const uint8_t aad_len,
1496 unsigned data_pad_len,
1497 const unsigned cipher_len, const unsigned cipher_offset,
1498 const unsigned auth_len, const unsigned auth_offset)
1500 struct crypto_testsuite_params *ts_params = &testsuite_params;
1501 struct crypto_unittest_params *ut_params = &unittest_params;
1503 unsigned iv_pad_len = 0;
1504 unsigned aad_buffer_len = 0;
1506 /* Generate Crypto op data structure */
1507 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1508 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1509 TEST_ASSERT_NOT_NULL(ut_params->op,
1510 "Failed to allocate pktmbuf offload");
1512 /* Set crypto operation data parameters */
1513 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1515 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1517 /* set crypto operation source mbuf */
1518 sym_op->m_src = ut_params->ibuf;
1521 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1522 ut_params->ibuf, auth_tag_len);
1524 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1525 "no room to append auth tag");
1527 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1528 ut_params->ibuf, data_pad_len);
1529 sym_op->auth.digest.length = auth_tag_len;
1531 memset(sym_op->auth.digest.data, 0, auth_tag_len);
1533 #ifdef RTE_APP_TEST_DEBUG
1534 rte_hexdump(stdout, "digest:",
1535 sym_op->auth.digest.data,
1536 sym_op->auth.digest.length);
1539 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1541 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1542 ut_params->ibuf, iv_pad_len);
1543 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1545 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1546 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1547 sym_op->cipher.iv.length = iv_pad_len;
1549 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1553 * Always allocate the aad up to the block size.
1554 * The cryptodev API calls out -
1555 * - the array must be big enough to hold the AAD, plus any
1556 * space to round this up to the nearest multiple of the
1557 * block size (16 bytes).
1559 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1561 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1562 ut_params->ibuf, aad_buffer_len);
1563 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1564 "no room to prepend aad");
1565 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1567 sym_op->auth.aad.length = aad_len;
1569 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1570 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1572 #ifdef RTE_APP_TEST_DEBUG
1573 rte_hexdump(stdout, "aad:",
1574 sym_op->auth.aad.data, aad_len);
1577 sym_op->cipher.data.length = cipher_len;
1578 sym_op->cipher.data.offset = auth_offset + cipher_offset;
1580 sym_op->auth.data.length = auth_len;
1581 sym_op->auth.data.offset = auth_offset + cipher_offset;
1587 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
1589 struct crypto_testsuite_params *ts_params = &testsuite_params;
1590 struct crypto_unittest_params *ut_params = &unittest_params;
1593 unsigned plaintext_pad_len;
1596 /* Create SNOW3G session */
1597 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1598 tdata->key.data, tdata->key.len,
1599 tdata->aad.len, tdata->digest.len,
1600 RTE_CRYPTO_AUTH_OP_GENERATE);
1604 /* alloc mbuf and set payload */
1605 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1607 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1608 rte_pktmbuf_tailroom(ut_params->ibuf));
1610 /* Append data which is padded to a multiple of */
1611 /* the algorithms block size */
1612 plaintext_pad_len = tdata->plaintext.len >> 3;
1613 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1615 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1617 /* Create SNOW3G opertaion */
1618 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
1619 tdata->aad.data, tdata->aad.len,
1620 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
1621 tdata->validAuthLenInBits.len,
1622 tdata->validAuthOffsetLenInBits.len);
1626 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1628 ut_params->obuf = ut_params->op->sym->m_src;
1629 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1630 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1631 + plaintext_pad_len + tdata->aad.len;
1634 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1637 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
1638 "Snow3G Generated auth tag not as expected");
1644 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
1646 struct crypto_testsuite_params *ts_params = &testsuite_params;
1647 struct crypto_unittest_params *ut_params = &unittest_params;
1650 unsigned plaintext_pad_len;
1653 /* Create SNOW3G session */
1654 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
1655 tdata->key.data, tdata->key.len,
1656 tdata->aad.len, tdata->digest.len,
1657 RTE_CRYPTO_AUTH_OP_VERIFY);
1660 /* alloc mbuf and set payload */
1661 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1663 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1664 rte_pktmbuf_tailroom(ut_params->ibuf));
1666 /* Append data which is padded to a multiple */
1667 /* of the algorithms block size */
1668 plaintext_pad_len = tdata->plaintext.len >> 3;
1669 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1671 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
1673 /* Create SNOW3G operation */
1674 retval = create_snow3g_hash_operation(tdata->digest.data,
1676 tdata->aad.data, tdata->aad.len,
1678 RTE_CRYPTO_AUTH_OP_VERIFY,
1679 tdata->validAuthLenInBits.len,
1680 tdata->validAuthOffsetLenInBits.len);
1684 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1686 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1687 ut_params->obuf = ut_params->op->sym->m_src;
1688 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1689 + plaintext_pad_len + tdata->aad.len;
1692 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
1702 test_snow3g_hash_generate_test_case_1(void)
1704 return test_snow3g_authentication(&snow3g_hash_test_case_1);
1708 test_snow3g_hash_generate_test_case_2(void)
1710 return test_snow3g_authentication(&snow3g_hash_test_case_2);
1714 test_snow3g_hash_generate_test_case_3(void)
1716 return test_snow3g_authentication(&snow3g_hash_test_case_3);
1720 test_snow3g_hash_verify_test_case_1(void)
1722 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
1727 test_snow3g_hash_verify_test_case_2(void)
1729 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
1733 test_snow3g_hash_verify_test_case_3(void)
1735 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
1739 test_snow3g_encryption(const struct snow3g_test_data *tdata)
1741 struct crypto_testsuite_params *ts_params = &testsuite_params;
1742 struct crypto_unittest_params *ut_params = &unittest_params;
1745 uint8_t *plaintext, *ciphertext;
1746 uint8_t plaintext_pad_len;
1747 uint8_t lastByteValidBits = 8;
1748 uint8_t lastByteMask = 0xFF;
1750 /* Create SNOW3G session */
1751 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1752 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1753 tdata->key.data, tdata->key.len);
1757 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1759 /* Clear mbuf payload */
1760 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1761 rte_pktmbuf_tailroom(ut_params->ibuf));
1764 * Append data which is padded to a
1765 * multiple of the algorithms block size
1767 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1768 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1770 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1772 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1774 #ifdef RTE_APP_TEST_DEBUG
1775 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1777 /* Create SNOW3G operation */
1778 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1779 tdata->validCipherLenInBits.len,
1780 tdata->validCipherOffsetLenInBits.len);
1784 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1786 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1788 ut_params->obuf = ut_params->op->sym->m_dst;
1789 if (ut_params->obuf)
1790 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1793 ciphertext = plaintext;
1795 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1796 if (lastByteValidBits == 0)
1797 lastByteValidBits = 8;
1798 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1799 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1801 #ifdef RTE_APP_TEST_DEBUG
1802 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1805 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1807 tdata->ciphertext.data,
1808 tdata->ciphertext.len >> 3,
1809 "Snow3G Ciphertext data not as expected");
1815 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
1817 struct crypto_testsuite_params *ts_params = &testsuite_params;
1818 struct crypto_unittest_params *ut_params = &unittest_params;
1819 uint8_t *plaintext, *ciphertext;
1822 uint8_t plaintext_pad_len;
1823 uint8_t lastByteValidBits = 8;
1824 uint8_t lastByteMask = 0xFF;
1826 /* Create SNOW3G session */
1827 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1828 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
1829 tdata->key.data, tdata->key.len);
1833 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1834 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1836 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1837 "Failed to allocate input buffer in mempool");
1838 TEST_ASSERT_NOT_NULL(ut_params->obuf,
1839 "Failed to allocate output buffer in mempool");
1841 /* Clear mbuf payload */
1842 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1843 rte_pktmbuf_tailroom(ut_params->ibuf));
1846 * Append data which is padded to a
1847 * multiple of the algorithms block size
1849 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
1850 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
1852 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1855 rte_pktmbuf_append(ut_params->obuf,
1858 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
1860 #ifdef RTE_APP_TEST_DEBUG
1861 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1863 /* Create SNOW3G operation */
1864 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
1866 tdata->validCipherLenInBits.len,
1867 tdata->validCipherOffsetLenInBits.len);
1871 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1873 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1875 ut_params->obuf = ut_params->op->sym->m_dst;
1876 if (ut_params->obuf)
1877 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1880 ciphertext = plaintext;
1882 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1883 if (lastByteValidBits == 0)
1884 lastByteValidBits = 8;
1885 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1886 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1888 #ifdef RTE_APP_TEST_DEBUG
1889 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1892 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1894 tdata->ciphertext.data,
1895 tdata->ciphertext.len >> 3,
1896 "Snow3G Ciphertext data not as expected");
1901 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
1903 struct crypto_testsuite_params *ts_params = &testsuite_params;
1904 struct crypto_unittest_params *ut_params = &unittest_params;
1908 uint8_t *plaintext, *ciphertext;
1909 uint8_t ciphertext_pad_len;
1910 uint8_t lastByteValidBits = 8;
1911 uint8_t lastByteMask = 0xFF;
1913 /* Create SNOW3G session */
1914 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1915 RTE_CRYPTO_CIPHER_OP_DECRYPT,
1916 tdata->key.data, tdata->key.len);
1920 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1922 /* Clear mbuf payload */
1923 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
1924 rte_pktmbuf_tailroom(ut_params->ibuf));
1927 * Append data which is padded to a
1928 * multiple of the algorithms block size
1930 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
1932 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
1933 ciphertext_pad_len);
1934 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
1936 #ifdef RTE_APP_TEST_DEBUG
1937 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
1939 /* Create SNOW3G operation */
1940 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
1941 tdata->validCipherLenInBits.len,
1942 tdata->validCipherOffsetLenInBits.len);
1946 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1948 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
1949 ut_params->obuf = ut_params->op->sym->m_src;
1950 if (ut_params->obuf)
1951 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
1954 plaintext = ciphertext;
1955 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
1956 if (lastByteValidBits == 0)
1957 lastByteValidBits = 8;
1958 lastByteMask = lastByteMask << (8 - lastByteValidBits);
1959 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
1961 #ifdef RTE_APP_TEST_DEBUG
1962 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
1965 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1966 tdata->plaintext.data,
1967 tdata->plaintext.len >> 3,
1968 "Snow3G Plaintext data not as expected");
1972 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
1974 struct crypto_testsuite_params *ts_params = &testsuite_params;
1975 struct crypto_unittest_params *ut_params = &unittest_params;
1979 uint8_t *plaintext, *ciphertext;
1980 uint8_t ciphertext_pad_len;
1981 uint8_t lastByteValidBits = 8;
1982 uint8_t lastByteMask = 0xFF;
1984 /* Create SNOW3G session */
1985 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
1986 RTE_CRYPTO_CIPHER_OP_DECRYPT,
1987 tdata->key.data, tdata->key.len);
1991 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1992 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1994 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
1995 "Failed to allocate input buffer");
1996 TEST_ASSERT_NOT_NULL(ut_params->obuf,
1997 "Failed to allocate output buffer");
1999 /* Clear mbuf payload */
2000 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2001 rte_pktmbuf_tailroom(ut_params->ibuf));
2003 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
2004 rte_pktmbuf_tailroom(ut_params->obuf));
2007 * Append data which is padded to a
2008 * multiple of the algorithms block size
2010 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2012 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2013 ciphertext_pad_len);
2015 rte_pktmbuf_append(ut_params->obuf,
2016 ciphertext_pad_len);
2018 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2020 #ifdef RTE_APP_TEST_DEBUG
2021 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2023 /* Create SNOW3G operation */
2024 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
2026 tdata->validCipherLenInBits.len,
2027 tdata->validCipherOffsetLenInBits.len);
2031 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2033 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2034 ut_params->obuf = ut_params->op->sym->m_dst;
2035 if (ut_params->obuf)
2036 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2039 plaintext = ciphertext;
2040 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2041 if (lastByteValidBits == 0)
2042 lastByteValidBits = 8;
2043 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2044 (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2046 #ifdef RTE_APP_TEST_DEBUG
2047 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2050 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2051 tdata->plaintext.data,
2052 tdata->plaintext.len >> 3,
2053 "Snow3G Plaintext data not as expected");
2058 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2060 struct crypto_testsuite_params *ts_params = &testsuite_params;
2061 struct crypto_unittest_params *ut_params = &unittest_params;
2065 uint8_t *plaintext, *ciphertext;
2066 uint8_t plaintext_pad_len;
2067 uint8_t lastByteValidBits = 8;
2068 uint8_t lastByteMask = 0xFF;
2070 /* Create SNOW3G session */
2071 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2072 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2073 RTE_CRYPTO_AUTH_OP_GENERATE,
2074 tdata->key.data, tdata->key.len,
2075 tdata->aad.len, tdata->digest.len);
2078 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2080 /* clear mbuf payload */
2081 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2082 rte_pktmbuf_tailroom(ut_params->ibuf));
2084 /* Append data which is padded to a multiple */
2085 /* of the algorithms block size */
2086 plaintext_pad_len = tdata->plaintext.len >> 3;
2088 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2090 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2092 #ifdef RTE_APP_TEST_DEBUG
2093 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2096 /* Create SNOW3G operation */
2097 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2098 tdata->digest.len, tdata->aad.data,
2099 tdata->aad.len, /*tdata->plaintext.len,*/
2100 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2101 tdata->iv.data, tdata->iv.len,
2102 tdata->validCipherLenInBits.len,
2103 tdata->validCipherOffsetLenInBits.len,
2104 tdata->validAuthLenInBits.len,
2105 tdata->validAuthOffsetLenInBits.len);
2109 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2111 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2112 ut_params->obuf = ut_params->op->sym->m_src;
2113 if (ut_params->obuf)
2114 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2117 ciphertext = plaintext;
2118 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2119 if (lastByteValidBits == 0)
2120 lastByteValidBits = 8;
2121 lastByteMask = lastByteMask << (8-lastByteValidBits);
2122 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2124 #ifdef RTE_APP_TEST_DEBUG
2125 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2128 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2130 tdata->ciphertext.data,
2131 tdata->ciphertext.len >> 3,
2132 "Snow3G Ciphertext data not as expected");
2134 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2135 + plaintext_pad_len + tdata->aad.len;
2138 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2141 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2142 "Snow3G Generated auth tag not as expected");
2146 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2148 struct crypto_testsuite_params *ts_params = &testsuite_params;
2149 struct crypto_unittest_params *ut_params = &unittest_params;
2153 uint8_t *plaintext, *ciphertext;
2154 uint8_t plaintext_pad_len;
2155 uint8_t lastByteValidBits = 8;
2156 uint8_t lastByteMask = 0xFF;
2158 /* Create SNOW3G session */
2159 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2160 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2161 RTE_CRYPTO_AUTH_OP_GENERATE,
2162 tdata->key.data, tdata->key.len,
2163 tdata->aad.len, tdata->digest.len);
2167 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2169 /* clear mbuf payload */
2170 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2171 rte_pktmbuf_tailroom(ut_params->ibuf));
2173 /* Append data which is padded to a multiple */
2174 /* of the algorithms block size */
2175 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2177 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2179 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2181 #ifdef RTE_APP_TEST_DEBUG
2182 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2185 /* Create SNOW3G operation */
2186 retval = create_snow3g_auth_cipher_operation(
2188 tdata->iv.data, tdata->iv.len,
2189 tdata->aad.data, tdata->aad.len,
2191 tdata->validCipherLenInBits.len,
2192 tdata->validCipherOffsetLenInBits.len,
2193 tdata->validAuthLenInBits.len,
2194 tdata->validAuthOffsetLenInBits.len
2200 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2202 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2203 ut_params->obuf = ut_params->op->sym->m_src;
2204 if (ut_params->obuf)
2205 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2206 + tdata->aad.len + tdata->iv.len;
2208 ciphertext = plaintext;
2210 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2211 if (lastByteValidBits == 0)
2212 lastByteValidBits = 8;
2213 lastByteMask = lastByteMask << (8-lastByteValidBits);
2214 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2215 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2216 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2217 #ifdef RTE_APP_TEST_DEBUG
2218 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2221 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2223 tdata->ciphertext.data,
2224 tdata->ciphertext.len >> 3,
2225 "Snow3G Ciphertext data not as expected");
2228 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2231 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2232 "Snow3G Generated auth tag not as expected");
2237 test_snow3g_encryption_test_case_1(void)
2239 return test_snow3g_encryption(&snow3g_test_case_1);
2243 test_snow3g_encryption_test_case_1_oop(void)
2245 return test_snow3g_encryption_oop(&snow3g_test_case_1);
2249 test_snow3g_encryption_test_case_2(void)
2251 return test_snow3g_encryption(&snow3g_test_case_2);
2255 test_snow3g_encryption_test_case_3(void)
2257 return test_snow3g_encryption(&snow3g_test_case_3);
2261 test_snow3g_encryption_test_case_4(void)
2263 return test_snow3g_encryption(&snow3g_test_case_4);
2267 test_snow3g_encryption_test_case_5(void)
2269 return test_snow3g_encryption(&snow3g_test_case_5);
2273 test_snow3g_decryption_test_case_1(void)
2275 return test_snow3g_decryption(&snow3g_test_case_1);
2279 test_snow3g_decryption_test_case_1_oop(void)
2281 return test_snow3g_decryption_oop(&snow3g_test_case_1);
2285 test_snow3g_decryption_test_case_2(void)
2287 return test_snow3g_decryption(&snow3g_test_case_2);
2291 test_snow3g_decryption_test_case_3(void)
2293 return test_snow3g_decryption(&snow3g_test_case_3);
2297 test_snow3g_decryption_test_case_4(void)
2299 return test_snow3g_decryption(&snow3g_test_case_4);
2303 test_snow3g_decryption_test_case_5(void)
2305 return test_snow3g_decryption(&snow3g_test_case_5);
2308 test_snow3g_authenticated_encryption_test_case_1(void)
2310 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2314 test_snow3g_encrypted_authentication_test_case_1(void)
2316 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2319 /* ***** AES-GCM Tests ***** */
2322 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2323 const uint8_t *key, const uint8_t key_len,
2324 const uint8_t aad_len, const uint8_t auth_len)
2326 uint8_t cipher_key[key_len];
2328 struct crypto_unittest_params *ut_params = &unittest_params;
2331 memcpy(cipher_key, key, key_len);
2333 /* Setup Cipher Parameters */
2334 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2335 ut_params->cipher_xform.next = NULL;
2337 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2338 ut_params->cipher_xform.cipher.op = op;
2339 ut_params->cipher_xform.cipher.key.data = cipher_key;
2340 ut_params->cipher_xform.cipher.key.length = key_len;
2342 #ifdef RTE_APP_TEST_DEBUG
2343 rte_hexdump(stdout, "key:", key, key_len);
2345 /* Setup Authentication Parameters */
2346 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2347 ut_params->auth_xform.next = NULL;
2349 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2351 ut_params->auth_xform.auth.digest_length = auth_len;
2352 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2353 ut_params->auth_xform.auth.key.length = 0;
2354 ut_params->auth_xform.auth.key.data = NULL;
2356 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2357 ut_params->cipher_xform.next = &ut_params->auth_xform;
2359 /* Create Crypto session*/
2360 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2361 &ut_params->cipher_xform);
2362 } else {/* Create Crypto session*/
2363 ut_params->auth_xform.next = &ut_params->cipher_xform;
2364 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2365 &ut_params->auth_xform);
2368 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2374 create_gcm_operation(enum rte_crypto_cipher_operation op,
2375 const uint8_t *auth_tag, const unsigned auth_tag_len,
2376 const uint8_t *iv, const unsigned iv_len,
2377 const uint8_t *aad, const unsigned aad_len,
2378 const unsigned data_len, unsigned data_pad_len)
2380 struct crypto_testsuite_params *ts_params = &testsuite_params;
2381 struct crypto_unittest_params *ut_params = &unittest_params;
2383 unsigned iv_pad_len = 0, aad_buffer_len;
2385 /* Generate Crypto op data structure */
2386 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2387 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2388 TEST_ASSERT_NOT_NULL(ut_params->op,
2389 "Failed to allocate symmetric crypto operation struct");
2391 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2395 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2396 ut_params->ibuf, auth_tag_len);
2397 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2398 "no room to append digest");
2399 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2400 ut_params->ibuf, data_pad_len);
2401 sym_op->auth.digest.length = auth_tag_len;
2403 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2404 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2405 #ifdef RTE_APP_TEST_DEBUG
2406 rte_hexdump(stdout, "digest:",
2407 sym_op->auth.digest.data,
2408 sym_op->auth.digest.length);
2413 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2415 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2416 ut_params->ibuf, iv_pad_len);
2417 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2419 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2420 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2421 sym_op->cipher.iv.length = iv_pad_len;
2423 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2427 sym_op->cipher.iv.data[15] = 1;
2430 * Always allocate the aad up to the block size.
2431 * The cryptodev API calls out -
2432 * - the array must be big enough to hold the AAD, plus any
2433 * space to round this up to the nearest multiple of the
2434 * block size (16 bytes).
2436 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2438 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2439 ut_params->ibuf, aad_buffer_len);
2440 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2441 "no room to prepend aad");
2442 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2444 sym_op->auth.aad.length = aad_len;
2446 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2447 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2449 #ifdef RTE_APP_TEST_DEBUG
2450 rte_hexdump(stdout, "iv:", sym_op->cipher.iv.data, iv_pad_len);
2451 rte_hexdump(stdout, "aad:",
2452 sym_op->auth.aad.data, aad_len);
2454 sym_op->cipher.data.length = data_len;
2455 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2457 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2458 sym_op->auth.data.length = data_len;
2464 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2466 struct crypto_testsuite_params *ts_params = &testsuite_params;
2467 struct crypto_unittest_params *ut_params = &unittest_params;
2471 uint8_t *plaintext, *ciphertext, *auth_tag;
2472 uint16_t plaintext_pad_len;
2474 /* Create GCM session */
2475 retval = create_gcm_session(ts_params->valid_devs[0],
2476 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2477 tdata->key.data, tdata->key.len,
2478 tdata->aad.len, tdata->auth_tag.len);
2483 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2485 /* clear mbuf payload */
2486 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2487 rte_pktmbuf_tailroom(ut_params->ibuf));
2490 * Append data which is padded to a multiple
2491 * of the algorithms block size
2493 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2495 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2497 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2499 #ifdef RTE_APP_TEST_DEBUG
2500 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2502 /* Create GCM opertaion */
2503 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2504 tdata->auth_tag.data, tdata->auth_tag.len,
2505 tdata->iv.data, tdata->iv.len,
2506 tdata->aad.data, tdata->aad.len,
2507 tdata->plaintext.len, plaintext_pad_len);
2511 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2513 ut_params->op->sym->m_src = ut_params->ibuf;
2515 /* Process crypto operation */
2516 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2517 ut_params->op), "failed to process sym crypto op");
2519 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2520 "crypto op processing failed");
2522 if (ut_params->op->sym->m_dst) {
2523 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2525 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
2526 uint8_t *, plaintext_pad_len);
2528 ciphertext = plaintext;
2529 auth_tag = plaintext + plaintext_pad_len;
2532 #ifdef RTE_APP_TEST_DEBUG
2533 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2534 rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
2537 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2539 tdata->ciphertext.data,
2540 tdata->ciphertext.len,
2541 "GCM Ciphertext data not as expected");
2543 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2545 tdata->auth_tag.data,
2546 tdata->auth_tag.len,
2547 "GCM Generated auth tag not as expected");
2554 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
2556 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
2560 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
2562 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
2566 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
2568 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
2572 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
2574 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
2578 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
2580 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
2584 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
2586 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
2590 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
2592 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
2596 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
2598 struct crypto_testsuite_params *ts_params = &testsuite_params;
2599 struct crypto_unittest_params *ut_params = &unittest_params;
2603 uint8_t *plaintext, *ciphertext;
2604 uint16_t ciphertext_pad_len;
2606 /* Create GCM session */
2607 retval = create_gcm_session(ts_params->valid_devs[0],
2608 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2609 tdata->key.data, tdata->key.len,
2610 tdata->aad.len, tdata->auth_tag.len);
2615 /* alloc mbuf and set payload */
2616 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2618 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2619 rte_pktmbuf_tailroom(ut_params->ibuf));
2621 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2623 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2624 ciphertext_pad_len);
2625 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2627 #ifdef RTE_APP_TEST_DEBUG
2628 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2630 /* Create GCM opertaion */
2631 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
2632 tdata->auth_tag.data, tdata->auth_tag.len,
2633 tdata->iv.data, tdata->iv.len,
2634 tdata->aad.data, tdata->aad.len,
2635 tdata->ciphertext.len, ciphertext_pad_len);
2640 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2642 ut_params->op->sym->m_src = ut_params->ibuf;
2644 /* Process crypto operation */
2645 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2646 ut_params->op), "failed to process sym crypto op");
2648 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2649 "crypto op processing failed");
2651 if (ut_params->op->sym->m_dst)
2652 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
2655 plaintext = ciphertext;
2657 #ifdef RTE_APP_TEST_DEBUG
2658 rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
2661 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2663 tdata->plaintext.data,
2664 tdata->plaintext.len,
2665 "GCM plaintext data not as expected");
2667 TEST_ASSERT_EQUAL(ut_params->op->status,
2668 RTE_CRYPTO_OP_STATUS_SUCCESS,
2669 "GCM authentication failed");
2674 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
2676 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
2680 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
2682 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
2686 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
2688 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
2692 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
2694 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
2698 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
2700 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
2704 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
2706 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
2710 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
2712 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
2718 struct crypto_testsuite_params *ts_params = &testsuite_params;
2719 struct rte_cryptodev_stats stats;
2720 struct rte_cryptodev *dev;
2721 cryptodev_stats_get_t temp_pfn;
2723 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2724 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2725 &stats) == -ENODEV),
2726 "rte_cryptodev_stats_get invalid dev failed");
2727 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2728 "rte_cryptodev_stats_get invalid Param failed");
2729 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2730 temp_pfn = dev->dev_ops->stats_get;
2731 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2732 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2734 "rte_cryptodev_stats_get invalid Param failed");
2735 dev->dev_ops->stats_get = temp_pfn;
2737 /* Test expected values */
2739 test_AES_CBC_HMAC_SHA1_encrypt_digest();
2741 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2743 "rte_cryptodev_stats_get failed");
2744 TEST_ASSERT((stats.enqueued_count == 1),
2745 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2746 TEST_ASSERT((stats.dequeued_count == 1),
2747 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2748 TEST_ASSERT((stats.enqueue_err_count == 0),
2749 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2750 TEST_ASSERT((stats.dequeue_err_count == 0),
2751 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2753 /* invalid device but should ignore and not reset device stats*/
2754 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2755 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2757 "rte_cryptodev_stats_get failed");
2758 TEST_ASSERT((stats.enqueued_count == 1),
2759 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2761 /* check that a valid reset clears stats */
2762 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2763 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2765 "rte_cryptodev_stats_get failed");
2766 TEST_ASSERT((stats.enqueued_count == 0),
2767 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2768 TEST_ASSERT((stats.dequeued_count == 0),
2769 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2771 return TEST_SUCCESS;
2776 test_multi_session(void)
2778 struct crypto_testsuite_params *ts_params = &testsuite_params;
2779 struct crypto_unittest_params *ut_params = &unittest_params;
2781 struct rte_cryptodev_info dev_info;
2782 struct rte_cryptodev_sym_session **sessions;
2786 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2789 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2791 sessions = rte_malloc(NULL,
2792 (sizeof(struct rte_cryptodev_sym_session *) *
2793 dev_info.sym.max_nb_sessions) + 1, 0);
2795 /* Create multiple crypto sessions*/
2796 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2797 sessions[i] = rte_cryptodev_sym_session_create(
2798 ts_params->valid_devs[0],
2799 &ut_params->auth_xform);
2800 TEST_ASSERT_NOT_NULL(sessions[i],
2801 "Session creation failed at session number %u",
2804 /* Attempt to send a request on each session */
2805 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2806 sessions[i], ut_params, ts_params),
2807 "Failed to perform decrypt on request "
2809 /* free crypto operation structure */
2811 rte_crypto_op_free(ut_params->op);
2814 * free mbuf - both obuf and ibuf are usually the same,
2815 * but rte copes even if we call free twice
2817 if (ut_params->obuf) {
2818 rte_pktmbuf_free(ut_params->obuf);
2819 ut_params->obuf = 0;
2823 /* Next session create should fail */
2824 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2825 &ut_params->auth_xform);
2826 TEST_ASSERT_NULL(sessions[i],
2827 "Session creation succeeded unexpectedly!");
2829 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2830 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2835 return TEST_SUCCESS;
2839 test_null_cipher_only_operation(void)
2841 struct crypto_testsuite_params *ts_params = &testsuite_params;
2842 struct crypto_unittest_params *ut_params = &unittest_params;
2844 /* Generate test mbuf data and space for digest */
2845 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2846 catch_22_quote, QUOTE_512_BYTES, 0);
2848 /* Setup Cipher Parameters */
2849 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2850 ut_params->cipher_xform.next = NULL;
2852 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2853 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2855 /* Create Crypto session*/
2856 ut_params->sess = rte_cryptodev_sym_session_create(
2857 ts_params->valid_devs[0], &ut_params->cipher_xform);
2858 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2860 /* Generate Crypto op data structure */
2861 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2862 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2863 TEST_ASSERT_NOT_NULL(ut_params->op,
2864 "Failed to allocate symmetric crypto operation struct");
2866 /* Set crypto operation data parameters */
2867 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2869 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2871 /* set crypto operation source mbuf */
2872 sym_op->m_src = ut_params->ibuf;
2874 sym_op->cipher.data.offset = 0;
2875 sym_op->cipher.data.length = QUOTE_512_BYTES;
2877 /* Process crypto operation */
2878 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2880 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2882 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2883 "crypto operation processing failed");
2886 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2887 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
2890 "Ciphertext data not as expected");
2892 return TEST_SUCCESS;
2896 test_null_auth_only_operation(void)
2898 struct crypto_testsuite_params *ts_params = &testsuite_params;
2899 struct crypto_unittest_params *ut_params = &unittest_params;
2901 /* Generate test mbuf data and space for digest */
2902 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2903 catch_22_quote, QUOTE_512_BYTES, 0);
2905 /* Setup HMAC Parameters */
2906 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2907 ut_params->auth_xform.next = NULL;
2909 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2910 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2912 /* Create Crypto session*/
2913 ut_params->sess = rte_cryptodev_sym_session_create(
2914 ts_params->valid_devs[0], &ut_params->auth_xform);
2915 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2917 /* Generate Crypto op data structure */
2918 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2919 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2920 TEST_ASSERT_NOT_NULL(ut_params->op,
2921 "Failed to allocate symmetric crypto operation struct");
2923 /* Set crypto operation data parameters */
2924 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2926 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2928 sym_op->m_src = ut_params->ibuf;
2930 sym_op->auth.data.offset = 0;
2931 sym_op->auth.data.length = QUOTE_512_BYTES;
2933 /* Process crypto operation */
2934 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2936 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2938 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2939 "crypto operation processing failed");
2941 return TEST_SUCCESS;
2945 test_null_cipher_auth_operation(void)
2947 struct crypto_testsuite_params *ts_params = &testsuite_params;
2948 struct crypto_unittest_params *ut_params = &unittest_params;
2950 /* Generate test mbuf data and space for digest */
2951 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2952 catch_22_quote, QUOTE_512_BYTES, 0);
2954 /* Setup Cipher Parameters */
2955 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2956 ut_params->cipher_xform.next = &ut_params->auth_xform;
2958 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
2959 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2961 /* Setup HMAC Parameters */
2962 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2963 ut_params->auth_xform.next = NULL;
2965 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
2966 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2968 /* Create Crypto session*/
2969 ut_params->sess = rte_cryptodev_sym_session_create(
2970 ts_params->valid_devs[0], &ut_params->cipher_xform);
2971 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2973 /* Generate Crypto op data structure */
2974 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2975 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2976 TEST_ASSERT_NOT_NULL(ut_params->op,
2977 "Failed to allocate symmetric crypto operation struct");
2979 /* Set crypto operation data parameters */
2980 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2982 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2984 sym_op->m_src = ut_params->ibuf;
2986 sym_op->cipher.data.offset = 0;
2987 sym_op->cipher.data.length = QUOTE_512_BYTES;
2989 sym_op->auth.data.offset = 0;
2990 sym_op->auth.data.length = QUOTE_512_BYTES;
2992 /* Process crypto operation */
2993 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2995 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2997 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2998 "crypto operation processing failed");
3001 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3002 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3005 "Ciphertext data not as expected");
3007 return TEST_SUCCESS;
3011 test_null_auth_cipher_operation(void)
3013 struct crypto_testsuite_params *ts_params = &testsuite_params;
3014 struct crypto_unittest_params *ut_params = &unittest_params;
3016 /* Generate test mbuf data and space for digest */
3017 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3018 catch_22_quote, QUOTE_512_BYTES, 0);
3020 /* Setup Cipher Parameters */
3021 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3022 ut_params->cipher_xform.next = NULL;
3024 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3025 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3027 /* Setup HMAC Parameters */
3028 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3029 ut_params->auth_xform.next = &ut_params->cipher_xform;
3031 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3032 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3034 /* Create Crypto session*/
3035 ut_params->sess = rte_cryptodev_sym_session_create(
3036 ts_params->valid_devs[0], &ut_params->cipher_xform);
3037 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3039 /* Generate Crypto op data structure */
3040 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3041 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3042 TEST_ASSERT_NOT_NULL(ut_params->op,
3043 "Failed to allocate symmetric crypto operation struct");
3045 /* Set crypto operation data parameters */
3046 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3048 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3050 sym_op->m_src = ut_params->ibuf;
3052 sym_op->cipher.data.offset = 0;
3053 sym_op->cipher.data.length = QUOTE_512_BYTES;
3055 sym_op->auth.data.offset = 0;
3056 sym_op->auth.data.length = QUOTE_512_BYTES;
3058 /* Process crypto operation */
3059 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3061 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3063 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3064 "crypto operation processing failed");
3067 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3068 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
3071 "Ciphertext data not as expected");
3073 return TEST_SUCCESS;
3078 test_null_invalid_operation(void)
3080 struct crypto_testsuite_params *ts_params = &testsuite_params;
3081 struct crypto_unittest_params *ut_params = &unittest_params;
3083 /* Setup Cipher Parameters */
3084 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3085 ut_params->cipher_xform.next = NULL;
3087 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
3088 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3090 /* Create Crypto session*/
3091 ut_params->sess = rte_cryptodev_sym_session_create(
3092 ts_params->valid_devs[0], &ut_params->cipher_xform);
3093 TEST_ASSERT_NULL(ut_params->sess,
3094 "Session creation succeeded unexpectedly");
3097 /* Setup HMAC Parameters */
3098 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3099 ut_params->auth_xform.next = NULL;
3101 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
3102 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3104 /* Create Crypto session*/
3105 ut_params->sess = rte_cryptodev_sym_session_create(
3106 ts_params->valid_devs[0], &ut_params->auth_xform);
3107 TEST_ASSERT_NULL(ut_params->sess,
3108 "Session creation succeeded unexpectedly");
3110 return TEST_SUCCESS;
3114 #define NULL_BURST_LENGTH (32)
3117 test_null_burst_operation(void)
3119 struct crypto_testsuite_params *ts_params = &testsuite_params;
3120 struct crypto_unittest_params *ut_params = &unittest_params;
3122 unsigned i, burst_len = NULL_BURST_LENGTH;
3124 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
3125 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
3127 /* Setup Cipher Parameters */
3128 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3129 ut_params->cipher_xform.next = &ut_params->auth_xform;
3131 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
3132 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
3134 /* Setup HMAC Parameters */
3135 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3136 ut_params->auth_xform.next = NULL;
3138 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
3139 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
3141 /* Create Crypto session*/
3142 ut_params->sess = rte_cryptodev_sym_session_create(
3143 ts_params->valid_devs[0], &ut_params->cipher_xform);
3144 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3146 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
3147 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
3148 burst_len, "failed to generate burst of crypto ops");
3150 /* Generate an operation for each mbuf in burst */
3151 for (i = 0; i < burst_len; i++) {
3152 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3154 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
3156 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
3160 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
3162 burst[i]->sym->m_src = m;
3165 /* Process crypto operation */
3166 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
3167 0, burst, burst_len),
3169 "Error enqueuing burst");
3171 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
3172 0, burst_dequeued, burst_len),
3174 "Error dequeuing burst");
3177 for (i = 0; i < burst_len; i++) {
3179 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
3180 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
3182 "data not as expected");
3184 rte_pktmbuf_free(burst[i]->sym->m_src);
3185 rte_crypto_op_free(burst[i]);
3188 return TEST_SUCCESS;
3194 static struct unit_test_suite cryptodev_qat_testsuite = {
3195 .suite_name = "Crypto QAT Unit Test Suite",
3196 .setup = testsuite_setup,
3197 .teardown = testsuite_teardown,
3198 .unit_test_cases = {
3199 TEST_CASE_ST(ut_setup, ut_teardown,
3200 test_device_configure_invalid_dev_id),
3201 TEST_CASE_ST(ut_setup, ut_teardown,
3202 test_device_configure_invalid_queue_pair_ids),
3203 TEST_CASE_ST(ut_setup, ut_teardown,
3204 test_queue_pair_descriptor_setup),
3205 TEST_CASE_ST(ut_setup, ut_teardown,
3206 test_multi_session),
3208 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_qat_all),
3209 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3211 /** AES GCM Authenticated Encryption */
3212 TEST_CASE_ST(ut_setup, ut_teardown,
3213 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3214 TEST_CASE_ST(ut_setup, ut_teardown,
3215 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3216 TEST_CASE_ST(ut_setup, ut_teardown,
3217 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3218 TEST_CASE_ST(ut_setup, ut_teardown,
3219 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3220 TEST_CASE_ST(ut_setup, ut_teardown,
3221 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3222 TEST_CASE_ST(ut_setup, ut_teardown,
3223 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3224 TEST_CASE_ST(ut_setup, ut_teardown,
3225 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3227 /** AES GCM Authenticated Decryption */
3228 TEST_CASE_ST(ut_setup, ut_teardown,
3229 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3230 TEST_CASE_ST(ut_setup, ut_teardown,
3231 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3232 TEST_CASE_ST(ut_setup, ut_teardown,
3233 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3234 TEST_CASE_ST(ut_setup, ut_teardown,
3235 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3236 TEST_CASE_ST(ut_setup, ut_teardown,
3237 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3238 TEST_CASE_ST(ut_setup, ut_teardown,
3239 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3240 TEST_CASE_ST(ut_setup, ut_teardown,
3241 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3243 /** Snow3G encrypt only (UEA2) */
3244 TEST_CASE_ST(ut_setup, ut_teardown,
3245 test_snow3g_encryption_test_case_1),
3246 TEST_CASE_ST(ut_setup, ut_teardown,
3247 test_snow3g_encryption_test_case_2),
3248 TEST_CASE_ST(ut_setup, ut_teardown,
3249 test_snow3g_encryption_test_case_3),
3250 TEST_CASE_ST(ut_setup, ut_teardown,
3251 test_snow3g_encryption_test_case_4),
3252 TEST_CASE_ST(ut_setup, ut_teardown,
3253 test_snow3g_encryption_test_case_5),
3255 TEST_CASE_ST(ut_setup, ut_teardown,
3256 test_snow3g_encryption_test_case_1_oop),
3257 TEST_CASE_ST(ut_setup, ut_teardown,
3258 test_snow3g_decryption_test_case_1_oop),
3260 /** Snow3G decrypt only (UEA2) */
3261 TEST_CASE_ST(ut_setup, ut_teardown,
3262 test_snow3g_decryption_test_case_1),
3263 TEST_CASE_ST(ut_setup, ut_teardown,
3264 test_snow3g_decryption_test_case_2),
3265 TEST_CASE_ST(ut_setup, ut_teardown,
3266 test_snow3g_decryption_test_case_3),
3267 TEST_CASE_ST(ut_setup, ut_teardown,
3268 test_snow3g_decryption_test_case_4),
3269 TEST_CASE_ST(ut_setup, ut_teardown,
3270 test_snow3g_decryption_test_case_5),
3271 TEST_CASE_ST(ut_setup, ut_teardown,
3272 test_snow3g_hash_generate_test_case_1),
3273 TEST_CASE_ST(ut_setup, ut_teardown,
3274 test_snow3g_hash_generate_test_case_2),
3275 TEST_CASE_ST(ut_setup, ut_teardown,
3276 test_snow3g_hash_generate_test_case_3),
3277 TEST_CASE_ST(ut_setup, ut_teardown,
3278 test_snow3g_hash_verify_test_case_1),
3279 TEST_CASE_ST(ut_setup, ut_teardown,
3280 test_snow3g_hash_verify_test_case_2),
3281 TEST_CASE_ST(ut_setup, ut_teardown,
3282 test_snow3g_hash_verify_test_case_3),
3283 TEST_CASE_ST(ut_setup, ut_teardown,
3284 test_snow3g_authenticated_encryption_test_case_1),
3285 TEST_CASE_ST(ut_setup, ut_teardown,
3286 test_snow3g_encrypted_authentication_test_case_1),
3287 TEST_CASES_END() /**< NULL terminate unit test array */
3291 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3292 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3293 .setup = testsuite_setup,
3294 .teardown = testsuite_teardown,
3295 .unit_test_cases = {
3296 TEST_CASE_ST(ut_setup, ut_teardown, test_AES_mb_all),
3298 TEST_CASES_END() /**< NULL terminate unit test array */
3302 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
3303 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3304 .setup = testsuite_setup,
3305 .teardown = testsuite_teardown,
3306 .unit_test_cases = {
3307 /** AES GCM Authenticated Encryption */
3308 TEST_CASE_ST(ut_setup, ut_teardown,
3309 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3310 TEST_CASE_ST(ut_setup, ut_teardown,
3311 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3312 TEST_CASE_ST(ut_setup, ut_teardown,
3313 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3314 TEST_CASE_ST(ut_setup, ut_teardown,
3315 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3316 TEST_CASE_ST(ut_setup, ut_teardown,
3317 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3318 TEST_CASE_ST(ut_setup, ut_teardown,
3319 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3320 TEST_CASE_ST(ut_setup, ut_teardown,
3321 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3323 /** AES GCM Authenticated Decryption */
3324 TEST_CASE_ST(ut_setup, ut_teardown,
3325 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3326 TEST_CASE_ST(ut_setup, ut_teardown,
3327 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3328 TEST_CASE_ST(ut_setup, ut_teardown,
3329 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3330 TEST_CASE_ST(ut_setup, ut_teardown,
3331 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3332 TEST_CASE_ST(ut_setup, ut_teardown,
3333 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3334 TEST_CASE_ST(ut_setup, ut_teardown,
3335 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3336 TEST_CASE_ST(ut_setup, ut_teardown,
3337 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3339 TEST_CASES_END() /**< NULL terminate unit test array */
3343 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
3344 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3345 .setup = testsuite_setup,
3346 .teardown = testsuite_teardown,
3347 .unit_test_cases = {
3348 /** Snow3G encrypt only (UEA2) */
3349 TEST_CASE_ST(ut_setup, ut_teardown,
3350 test_snow3g_encryption_test_case_1),
3351 TEST_CASE_ST(ut_setup, ut_teardown,
3352 test_snow3g_encryption_test_case_2),
3353 TEST_CASE_ST(ut_setup, ut_teardown,
3354 test_snow3g_encryption_test_case_3),
3355 TEST_CASE_ST(ut_setup, ut_teardown,
3356 test_snow3g_encryption_test_case_4),
3357 TEST_CASE_ST(ut_setup, ut_teardown,
3358 test_snow3g_encryption_test_case_5),
3361 /** Snow3G decrypt only (UEA2) */
3362 TEST_CASE_ST(ut_setup, ut_teardown,
3363 test_snow3g_decryption_test_case_1),
3364 TEST_CASE_ST(ut_setup, ut_teardown,
3365 test_snow3g_decryption_test_case_2),
3366 TEST_CASE_ST(ut_setup, ut_teardown,
3367 test_snow3g_decryption_test_case_3),
3368 TEST_CASE_ST(ut_setup, ut_teardown,
3369 test_snow3g_decryption_test_case_4),
3370 TEST_CASE_ST(ut_setup, ut_teardown,
3371 test_snow3g_decryption_test_case_5),
3372 TEST_CASE_ST(ut_setup, ut_teardown,
3373 test_snow3g_hash_generate_test_case_1),
3374 TEST_CASE_ST(ut_setup, ut_teardown,
3375 test_snow3g_hash_generate_test_case_2),
3376 TEST_CASE_ST(ut_setup, ut_teardown,
3377 test_snow3g_hash_generate_test_case_3),
3378 TEST_CASE_ST(ut_setup, ut_teardown,
3379 test_snow3g_hash_verify_test_case_1),
3380 TEST_CASE_ST(ut_setup, ut_teardown,
3381 test_snow3g_hash_verify_test_case_2),
3382 TEST_CASE_ST(ut_setup, ut_teardown,
3383 test_snow3g_hash_verify_test_case_3),
3384 TEST_CASE_ST(ut_setup, ut_teardown,
3385 test_snow3g_authenticated_encryption_test_case_1),
3386 TEST_CASE_ST(ut_setup, ut_teardown,
3387 test_snow3g_encrypted_authentication_test_case_1),
3389 TEST_CASES_END() /**< NULL terminate unit test array */
3393 static struct unit_test_suite cryptodev_null_testsuite = {
3394 .suite_name = "Crypto Device NULL Unit Test Suite",
3395 .setup = testsuite_setup,
3396 .teardown = testsuite_teardown,
3397 .unit_test_cases = {
3398 TEST_CASE_ST(ut_setup, ut_teardown,
3399 test_null_auth_only_operation),
3400 TEST_CASE_ST(ut_setup, ut_teardown,
3401 test_null_cipher_only_operation),
3402 TEST_CASE_ST(ut_setup, ut_teardown,
3403 test_null_cipher_auth_operation),
3404 TEST_CASE_ST(ut_setup, ut_teardown,
3405 test_null_auth_cipher_operation),
3406 TEST_CASE_ST(ut_setup, ut_teardown,
3407 test_null_invalid_operation),
3408 TEST_CASE_ST(ut_setup, ut_teardown,
3409 test_null_burst_operation),
3411 TEST_CASES_END() /**< NULL terminate unit test array */
3416 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3418 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3419 return unit_test_suite_runner(&cryptodev_qat_testsuite);
3421 static struct test_command cryptodev_qat_cmd = {
3422 .command = "cryptodev_qat_autotest",
3423 .callback = test_cryptodev_qat,
3427 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3429 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3431 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3434 static struct test_command cryptodev_aesni_mb_cmd = {
3435 .command = "cryptodev_aesni_mb_autotest",
3436 .callback = test_cryptodev_aesni_mb,
3440 test_cryptodev_aesni_gcm(void)
3442 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
3444 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
3447 static struct test_command cryptodev_aesni_gcm_cmd = {
3448 .command = "cryptodev_aesni_gcm_autotest",
3449 .callback = test_cryptodev_aesni_gcm,
3453 test_cryptodev_null(void)
3455 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
3457 return unit_test_suite_runner(&cryptodev_null_testsuite);
3460 static struct test_command cryptodev_null_cmd = {
3461 .command = "cryptodev_null_autotest",
3462 .callback = test_cryptodev_null,
3466 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3468 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3470 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3473 static struct test_command cryptodev_sw_snow3g_cmd = {
3474 .command = "cryptodev_sw_snow3g_autotest",
3475 .callback = test_cryptodev_sw_snow3g,
3478 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3479 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3480 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
3481 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
3482 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);