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"
45 #include "test_cryptodev_snow3g_test_vectors.h"
46 #include "test_cryptodev_snow3g_hash_test_vectors.h"
47 #include "test_cryptodev_gcm_test_vectors.h"
49 static enum rte_cryptodev_type gbl_cryptodev_type;
51 struct crypto_testsuite_params {
52 struct rte_mempool *mbuf_pool;
53 struct rte_mempool *op_mpool;
54 struct rte_cryptodev_config conf;
55 struct rte_cryptodev_qp_conf qp_conf;
57 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
58 uint8_t valid_dev_count;
61 struct crypto_unittest_params {
62 struct rte_crypto_sym_xform cipher_xform;
63 struct rte_crypto_sym_xform auth_xform;
65 struct rte_cryptodev_sym_session *sess;
67 struct rte_crypto_op *op;
69 struct rte_mbuf *obuf, *ibuf;
74 #define ALIGN_POW2_ROUNDUP(num, align) \
75 (((num) + (align) - 1) & ~((align) - 1))
78 * Forward declarations.
81 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
82 struct crypto_unittest_params *ut_params);
85 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
86 struct crypto_unittest_params *ut_params,
87 struct crypto_testsuite_params *ts_param);
89 static struct rte_mbuf *
90 setup_test_string(struct rte_mempool *mpool,
91 const char *string, size_t len, uint8_t blocksize)
93 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
94 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
96 memset(m->buf_addr, 0, m->buf_len);
98 char *dst = rte_pktmbuf_append(m, t_len);
105 rte_memcpy(dst, string, t_len);
113 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
115 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
119 static struct rte_crypto_op *
120 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
123 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
126 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
127 printf("Error sending packet for encryption");
133 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
138 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
144 static struct crypto_testsuite_params testsuite_params = { NULL };
145 static struct crypto_unittest_params unittest_params;
148 testsuite_setup(void)
150 struct crypto_testsuite_params *ts_params = &testsuite_params;
151 struct rte_cryptodev_info info;
152 unsigned i, nb_devs, dev_id;
156 memset(ts_params, 0, sizeof(*ts_params));
158 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
159 if (ts_params->mbuf_pool == NULL) {
160 /* Not already created so create */
161 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
163 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
165 if (ts_params->mbuf_pool == NULL) {
166 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
171 ts_params->op_mpool = rte_crypto_op_pool_create(
172 "MBUF_CRYPTO_SYM_OP_POOL",
173 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
174 NUM_MBUFS, MBUF_CACHE_SIZE,
176 sizeof(struct rte_crypto_sym_xform),
178 if (ts_params->op_mpool == NULL) {
179 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
183 /* Create 2 AESNI MB devices if required */
184 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
185 nb_devs = rte_cryptodev_count_devtype(
186 RTE_CRYPTODEV_AESNI_MB_PMD);
188 for (i = nb_devs; i < 2; i++) {
189 ret = rte_eal_vdev_init(
190 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
192 TEST_ASSERT(ret == 0,
193 "Failed to create instance %u of"
195 i, CRYPTODEV_NAME_AESNI_MB_PMD);
200 /* Create 2 AESNI GCM devices if required */
201 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
202 nb_devs = rte_cryptodev_count_devtype(
203 RTE_CRYPTODEV_AESNI_GCM_PMD);
205 for (i = nb_devs; i < 2; i++) {
206 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
207 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
208 "Failed to create instance %u of"
210 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
215 /* Create 2 Snow3G devices if required */
216 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
217 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
219 for (i = nb_devs; i < 2; i++) {
220 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
221 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
222 "Failed to create instance %u of"
224 i, CRYPTODEV_NAME_SNOW3G_PMD);
229 nb_devs = rte_cryptodev_count();
231 RTE_LOG(ERR, USER1, "No crypto devices found?");
235 /* Create list of valid crypto devs */
236 for (i = 0; i < nb_devs; i++) {
237 rte_cryptodev_info_get(i, &info);
238 if (info.dev_type == gbl_cryptodev_type)
239 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
242 if (ts_params->valid_dev_count < 1)
245 /* Set up all the qps on the first of the valid devices found */
246 for (i = 0; i < 1; i++) {
247 dev_id = ts_params->valid_devs[i];
249 rte_cryptodev_info_get(dev_id, &info);
252 * Since we can't free and re-allocate queue memory always set
253 * the queues on this device up to max size first so enough
254 * memory is allocated for any later re-configures needed by
258 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
259 ts_params->conf.socket_id = SOCKET_ID_ANY;
260 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
262 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
264 "Failed to configure cryptodev %u with %u qps",
265 dev_id, ts_params->conf.nb_queue_pairs);
267 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
269 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
270 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
271 dev_id, qp_id, &ts_params->qp_conf,
272 rte_cryptodev_socket_id(dev_id)),
273 "Failed to setup queue pair %u on "
283 testsuite_teardown(void)
285 struct crypto_testsuite_params *ts_params = &testsuite_params;
287 if (ts_params->mbuf_pool != NULL) {
288 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
289 rte_mempool_count(ts_params->mbuf_pool));
292 if (ts_params->op_mpool != NULL) {
293 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
294 rte_mempool_count(ts_params->op_mpool));
302 struct crypto_testsuite_params *ts_params = &testsuite_params;
303 struct crypto_unittest_params *ut_params = &unittest_params;
307 /* Clear unit test parameters before running test */
308 memset(ut_params, 0, sizeof(*ut_params));
310 /* Reconfigure device to default parameters */
311 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
312 ts_params->conf.socket_id = SOCKET_ID_ANY;
313 ts_params->conf.session_mp.nb_objs =
314 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
315 DEFAULT_NUM_OPS_INFLIGHT :
316 DEFAULT_NUM_OPS_INFLIGHT;
318 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
320 "Failed to configure cryptodev %u",
321 ts_params->valid_devs[0]);
324 * Now reconfigure queues to size we actually want to use in this
327 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
329 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
330 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
331 ts_params->valid_devs[0], qp_id,
333 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
334 "Failed to setup queue pair %u on cryptodev %u",
335 qp_id, ts_params->valid_devs[0]);
339 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
341 /* Start the device */
342 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
343 "Failed to start cryptodev %u",
344 ts_params->valid_devs[0]);
352 struct crypto_testsuite_params *ts_params = &testsuite_params;
353 struct crypto_unittest_params *ut_params = &unittest_params;
354 struct rte_cryptodev_stats stats;
356 /* free crypto session structure */
357 if (ut_params->sess) {
358 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
360 ut_params->sess = NULL;
363 /* free crypto operation structure */
365 rte_crypto_op_free(ut_params->op);
368 * free mbuf - both obuf and ibuf are usually the same,
369 * but rte copes even if we call free twice
371 if (ut_params->obuf) {
372 rte_pktmbuf_free(ut_params->obuf);
375 if (ut_params->ibuf) {
376 rte_pktmbuf_free(ut_params->ibuf);
380 if (ts_params->mbuf_pool != NULL)
381 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
382 rte_mempool_count(ts_params->mbuf_pool));
384 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
386 /* Stop the device */
387 rte_cryptodev_stop(ts_params->valid_devs[0]);
391 test_device_configure_invalid_dev_id(void)
393 struct crypto_testsuite_params *ts_params = &testsuite_params;
394 uint16_t dev_id, num_devs = 0;
396 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
397 "Need at least %d devices for test", 1);
399 /* valid dev_id values */
400 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
402 /* Stop the device in case it's started so it can be configured */
403 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
405 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
406 "Failed test for rte_cryptodev_configure: "
407 "invalid dev_num %u", dev_id);
409 /* invalid dev_id values */
412 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
413 "Failed test for rte_cryptodev_configure: "
414 "invalid dev_num %u", dev_id);
418 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
419 "Failed test for rte_cryptodev_configure:"
420 "invalid dev_num %u", dev_id);
426 test_device_configure_invalid_queue_pair_ids(void)
428 struct crypto_testsuite_params *ts_params = &testsuite_params;
430 /* Stop the device in case it's started so it can be configured */
431 rte_cryptodev_stop(ts_params->valid_devs[0]);
433 /* valid - one queue pairs */
434 ts_params->conf.nb_queue_pairs = 1;
436 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
438 "Failed to configure cryptodev: dev_id %u, qp_id %u",
439 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
442 /* valid - max value queue pairs */
443 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
445 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
447 "Failed to configure cryptodev: dev_id %u, qp_id %u",
448 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
451 /* invalid - zero queue pairs */
452 ts_params->conf.nb_queue_pairs = 0;
454 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
456 "Failed test for rte_cryptodev_configure, dev_id %u,"
458 ts_params->valid_devs[0],
459 ts_params->conf.nb_queue_pairs);
462 /* invalid - max value supported by field queue pairs */
463 ts_params->conf.nb_queue_pairs = UINT16_MAX;
465 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
467 "Failed test for rte_cryptodev_configure, dev_id %u,"
469 ts_params->valid_devs[0],
470 ts_params->conf.nb_queue_pairs);
473 /* invalid - max value + 1 queue pairs */
474 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
476 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
478 "Failed test for rte_cryptodev_configure, dev_id %u,"
480 ts_params->valid_devs[0],
481 ts_params->conf.nb_queue_pairs);
487 test_queue_pair_descriptor_setup(void)
489 struct crypto_testsuite_params *ts_params = &testsuite_params;
490 struct rte_cryptodev_info dev_info;
491 struct rte_cryptodev_qp_conf qp_conf = {
492 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
497 /* Stop the device in case it's started so it can be configured */
498 rte_cryptodev_stop(ts_params->valid_devs[0]);
501 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
503 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
505 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
506 &ts_params->conf), "Failed to configure cryptodev %u",
507 ts_params->valid_devs[0]);
511 * Test various ring sizes on this device. memzones can't be
512 * freed so are re-used if ring is released and re-created.
514 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
516 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
517 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
518 ts_params->valid_devs[0], qp_id, &qp_conf,
519 rte_cryptodev_socket_id(
520 ts_params->valid_devs[0])),
522 "rte_cryptodev_queue_pair_setup: num_inflights "
523 "%u on qp %u on cryptodev %u",
524 qp_conf.nb_descriptors, qp_id,
525 ts_params->valid_devs[0]);
528 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
530 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
531 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
532 ts_params->valid_devs[0], qp_id, &qp_conf,
533 rte_cryptodev_socket_id(
534 ts_params->valid_devs[0])),
536 " rte_cryptodev_queue_pair_setup: num_inflights"
537 " %u on qp %u on cryptodev %u",
538 qp_conf.nb_descriptors, qp_id,
539 ts_params->valid_devs[0]);
542 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
544 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
545 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
546 ts_params->valid_devs[0], qp_id, &qp_conf,
547 rte_cryptodev_socket_id(
548 ts_params->valid_devs[0])),
550 "rte_cryptodev_queue_pair_setup: num_inflights"
551 " %u on qp %u on cryptodev %u",
552 qp_conf.nb_descriptors, qp_id,
553 ts_params->valid_devs[0]);
556 /* invalid number of descriptors - max supported + 2 */
557 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
559 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
560 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
561 ts_params->valid_devs[0], qp_id, &qp_conf,
562 rte_cryptodev_socket_id(
563 ts_params->valid_devs[0])),
564 "Unexpectedly passed test for "
565 "rte_cryptodev_queue_pair_setup:"
566 "num_inflights %u on qp %u on cryptodev %u",
567 qp_conf.nb_descriptors, qp_id,
568 ts_params->valid_devs[0]);
571 /* invalid number of descriptors - max value of parameter */
572 qp_conf.nb_descriptors = UINT32_MAX-1;
574 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
575 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
576 ts_params->valid_devs[0], qp_id, &qp_conf,
577 rte_cryptodev_socket_id(
578 ts_params->valid_devs[0])),
579 "Unexpectedly passed test for "
580 "rte_cryptodev_queue_pair_setup:"
581 "num_inflights %u on qp %u on cryptodev %u",
582 qp_conf.nb_descriptors, qp_id,
583 ts_params->valid_devs[0]);
586 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
588 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
589 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
590 ts_params->valid_devs[0], qp_id, &qp_conf,
591 rte_cryptodev_socket_id(
592 ts_params->valid_devs[0])),
594 " rte_cryptodev_queue_pair_setup:"
595 "num_inflights %u on qp %u on cryptodev %u",
596 qp_conf.nb_descriptors, qp_id,
597 ts_params->valid_devs[0]);
600 /* invalid number of descriptors - max supported + 1 */
601 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
603 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
604 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
605 ts_params->valid_devs[0], qp_id, &qp_conf,
606 rte_cryptodev_socket_id(
607 ts_params->valid_devs[0])),
608 "Unexpectedly passed test for "
609 "rte_cryptodev_queue_pair_setup:"
610 "num_inflights %u on qp %u on cryptodev %u",
611 qp_conf.nb_descriptors, qp_id,
612 ts_params->valid_devs[0]);
615 /* test invalid queue pair id */
616 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
618 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
620 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
621 ts_params->valid_devs[0],
623 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
624 "Failed test for rte_cryptodev_queue_pair_setup:"
625 "invalid qp %u on cryptodev %u",
626 qp_id, ts_params->valid_devs[0]);
628 qp_id = 0xffff; /*invalid*/
630 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
631 ts_params->valid_devs[0],
633 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
634 "Failed test for rte_cryptodev_queue_pair_setup:"
635 "invalid qp %u on cryptodev %u",
636 qp_id, ts_params->valid_devs[0]);
641 /* ***** Plaintext data for tests ***** */
643 const char catch_22_quote_1[] =
644 "There was only one catch and that was Catch-22, which "
645 "specified that a concern for one's safety in the face of "
646 "dangers that were real and immediate was the process of a "
647 "rational mind. Orr was crazy and could be grounded. All he "
648 "had to do was ask; and as soon as he did, he would no longer "
649 "be crazy and would have to fly more missions. Orr would be "
650 "crazy to fly more missions and sane if he didn't, but if he "
651 "was sane he had to fly them. If he flew them he was crazy "
652 "and didn't have to; but if he didn't want to he was sane and "
653 "had to. Yossarian was moved very deeply by the absolute "
654 "simplicity of this clause of Catch-22 and let out a "
655 "respectful whistle. \"That's some catch, that Catch-22\", he "
656 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
658 const char catch_22_quote[] =
659 "What a lousy earth! He wondered how many people were "
660 "destitute that same night even in his own prosperous country, "
661 "how many homes were shanties, how many husbands were drunk "
662 "and wives socked, and how many children were bullied, abused, "
663 "or abandoned. How many families hungered for food they could "
664 "not afford to buy? How many hearts were broken? How many "
665 "suicides would take place that same night, how many people "
666 "would go insane? How many cockroaches and landlords would "
667 "triumph? How many winners were losers, successes failures, "
668 "and rich men poor men? How many wise guys were stupid? How "
669 "many happy endings were unhappy endings? How many honest men "
670 "were liars, brave men cowards, loyal men traitors, how many "
671 "sainted men were corrupt, how many people in positions of "
672 "trust had sold their souls to bodyguards, how many had never "
673 "had souls? How many straight-and-narrow paths were crooked "
674 "paths? How many best families were worst families and how "
675 "many good people were bad people? When you added them all up "
676 "and then subtracted, you might be left with only the children, "
677 "and perhaps with Albert Einstein and an old violinist or "
678 "sculptor somewhere.";
680 #define QUOTE_480_BYTES (480)
681 #define QUOTE_512_BYTES (512)
682 #define QUOTE_768_BYTES (768)
683 #define QUOTE_1024_BYTES (1024)
687 /* ***** SHA1 Hash Tests ***** */
689 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
691 static uint8_t hmac_sha1_key[] = {
692 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
693 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
694 0xDE, 0xF4, 0xDE, 0xAD };
696 /* ***** SHA224 Hash Tests ***** */
698 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
701 /* ***** AES-CBC Cipher Tests ***** */
703 #define CIPHER_KEY_LENGTH_AES_CBC (16)
704 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
706 static uint8_t aes_cbc_key[] = {
707 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
708 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
710 static uint8_t aes_cbc_iv[] = {
711 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
712 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
715 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
717 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
718 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
719 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
720 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
721 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
722 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
723 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
724 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
725 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
726 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
727 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
728 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
729 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
730 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
731 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
732 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
733 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
734 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
735 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
736 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
737 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
738 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
739 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
740 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
741 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
742 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
743 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
744 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
745 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
746 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
747 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
748 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
749 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
750 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
751 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
752 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
753 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
754 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
755 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
756 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
757 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
758 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
759 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
760 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
761 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
762 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
763 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
764 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
765 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
766 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
767 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
768 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
769 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
770 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
771 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
772 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
773 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
774 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
775 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
776 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
777 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
778 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
779 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
780 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
781 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
784 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
785 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
786 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
787 0x18, 0x8c, 0x1d, 0x32
792 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
794 struct crypto_testsuite_params *ts_params = &testsuite_params;
795 struct crypto_unittest_params *ut_params = &unittest_params;
797 /* Generate test mbuf data and space for digest */
798 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
799 catch_22_quote, QUOTE_512_BYTES, 0);
801 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
802 DIGEST_BYTE_LENGTH_SHA1);
803 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
805 /* Setup Cipher Parameters */
806 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
807 ut_params->cipher_xform.next = &ut_params->auth_xform;
809 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
810 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
811 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
812 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
814 /* Setup HMAC Parameters */
815 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
817 ut_params->auth_xform.next = NULL;
819 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
820 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
821 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
822 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
823 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
825 /* Create crypto session*/
826 ut_params->sess = rte_cryptodev_sym_session_create(
827 ts_params->valid_devs[0],
828 &ut_params->cipher_xform);
829 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
831 /* Generate crypto op data structure */
832 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
833 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
834 TEST_ASSERT_NOT_NULL(ut_params->op,
835 "Failed to allocate symmetric crypto operation struct");
837 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
839 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
841 /* set crypto operation source mbuf */
842 sym_op->m_src = ut_params->ibuf;
844 /* Set crypto operation authentication parameters */
845 sym_op->auth.digest.data = ut_params->digest;
846 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
847 ut_params->ibuf, QUOTE_512_BYTES);
848 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
850 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
851 sym_op->auth.data.length = QUOTE_512_BYTES;
853 /* Set crypto operation cipher parameters */
854 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
855 CIPHER_IV_LENGTH_AES_CBC);
856 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
857 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
859 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
860 CIPHER_IV_LENGTH_AES_CBC);
862 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
863 sym_op->cipher.data.length = QUOTE_512_BYTES;
865 /* Process crypto operation */
866 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
867 ut_params->op), "failed to process sym crypto op");
869 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
870 "crypto op processing failed");
873 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
874 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
876 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
877 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
879 "ciphertext data not as expected");
881 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
883 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
884 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
885 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
886 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
887 DIGEST_BYTE_LENGTH_SHA1,
888 "Generated digest data not as expected");
894 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
896 struct crypto_testsuite_params *ts_params = &testsuite_params;
897 struct crypto_unittest_params *ut_params = &unittest_params;
899 /* Generate test mbuf data and space for digest */
900 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
901 catch_22_quote, QUOTE_512_BYTES, 0);
903 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
904 DIGEST_BYTE_LENGTH_SHA1);
905 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
907 /* Generate Crypto op data structure */
908 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
909 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
910 TEST_ASSERT_NOT_NULL(ut_params->op,
911 "Failed to allocate symmetric crypto operation struct");
913 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
914 "failed to allocate space for crypto transforms");
916 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
918 /* set crypto operation source mbuf */
919 sym_op->m_src = ut_params->ibuf;
921 /* Set crypto operation data parameters */
922 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
924 /* cipher parameters */
925 sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
926 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
927 sym_op->xform->cipher.key.data = aes_cbc_key;
928 sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
930 /* hash parameters */
931 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
933 sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
934 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
935 sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
936 sym_op->xform->next->auth.key.data = hmac_sha1_key;
937 sym_op->xform->next->auth.digest_length =
938 DIGEST_BYTE_LENGTH_SHA1;
940 sym_op->auth.digest.data = ut_params->digest;
941 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
942 ut_params->ibuf, QUOTE_512_BYTES);
943 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
946 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
947 sym_op->auth.data.length = QUOTE_512_BYTES;
949 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
950 CIPHER_IV_LENGTH_AES_CBC);
951 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
952 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
954 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
955 CIPHER_IV_LENGTH_AES_CBC);
957 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
958 sym_op->cipher.data.length = QUOTE_512_BYTES;
960 /* Process crypto operation */
961 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
962 ut_params->op), "failed to process sym crypto op");
964 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
965 "crypto op processing failed");
967 ut_params->obuf = ut_params->op->sym->m_src;
970 TEST_ASSERT_BUFFERS_ARE_EQUAL(
971 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
972 CIPHER_IV_LENGTH_AES_CBC,
973 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
975 "Ciphertext data not as expected");
977 TEST_ASSERT_BUFFERS_ARE_EQUAL(
978 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
979 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
980 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
981 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
982 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
983 DIGEST_BYTE_LENGTH_SHA1,
984 "Generated digest data not as expected");
991 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
993 struct crypto_testsuite_params *ts_params = &testsuite_params;
994 struct crypto_unittest_params *ut_params = &unittest_params;
996 /* Generate test mbuf data and digest */
997 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
999 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1000 QUOTE_512_BYTES, 0);
1002 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1003 DIGEST_BYTE_LENGTH_SHA1);
1004 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1006 rte_memcpy(ut_params->digest,
1007 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1008 DIGEST_BYTE_LENGTH_SHA1);
1010 /* Setup Cipher Parameters */
1011 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1012 ut_params->cipher_xform.next = NULL;
1014 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1015 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1016 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1017 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1019 /* Setup HMAC Parameters */
1020 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1021 ut_params->auth_xform.next = &ut_params->cipher_xform;
1023 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1024 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1025 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1026 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1027 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1029 /* Create Crypto session*/
1031 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1032 &ut_params->auth_xform);
1033 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1035 /* Generate Crypto op data structure */
1036 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1037 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1038 TEST_ASSERT_NOT_NULL(ut_params->op,
1039 "Failed to allocate symmetric crypto operation struct");
1041 /* attach symmetric crypto session to crypto operations */
1042 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1044 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1046 /* set crypto operation source mbuf */
1047 sym_op->m_src = ut_params->ibuf;
1049 sym_op->auth.digest.data = ut_params->digest;
1050 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1051 ut_params->ibuf, QUOTE_512_BYTES);
1052 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1054 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1055 sym_op->auth.data.length = QUOTE_512_BYTES;
1057 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1058 CIPHER_IV_LENGTH_AES_CBC);
1059 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1060 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1062 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1063 CIPHER_IV_LENGTH_AES_CBC);
1065 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1066 sym_op->cipher.data.length = QUOTE_512_BYTES;
1069 /* Process crypto operation */
1070 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1071 ut_params->op), "failed to process sym crypto op");
1073 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1074 "crypto op processing failed");
1076 ut_params->obuf = ut_params->op->sym->m_src;
1080 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1081 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1082 CIPHER_IV_LENGTH_AES_CBC,
1085 "Ciphertext data not as expected");
1087 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1088 "Digest verification failed");
1091 return TEST_SUCCESS;
1095 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1097 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1099 static uint8_t hmac_sha256_key[] = {
1100 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1101 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1102 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1103 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1105 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1106 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1107 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1108 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1109 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1112 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1114 struct crypto_testsuite_params *ts_params = &testsuite_params;
1115 struct crypto_unittest_params *ut_params = &unittest_params;
1117 /* Generate test mbuf data and space for digest */
1118 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1119 catch_22_quote, QUOTE_512_BYTES, 0);
1121 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1122 DIGEST_BYTE_LENGTH_SHA256);
1123 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1125 /* Setup Cipher Parameters */
1126 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1127 ut_params->cipher_xform.next = &ut_params->auth_xform;
1129 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1130 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1131 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1132 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1134 /* Setup HMAC Parameters */
1135 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1136 ut_params->auth_xform.next = NULL;
1138 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1139 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1140 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1141 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1142 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1144 /* Create Crypto session*/
1145 ut_params->sess = rte_cryptodev_sym_session_create(
1146 ts_params->valid_devs[0],
1147 &ut_params->cipher_xform);
1148 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1150 /* Generate Crypto op data structure */
1151 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1152 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1153 TEST_ASSERT_NOT_NULL(ut_params->op,
1154 "Failed to allocate symmetric crypto operation struct");
1156 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1158 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1160 /* set crypto operation source mbuf */
1161 sym_op->m_src = ut_params->ibuf;
1163 sym_op->auth.digest.data = ut_params->digest;
1164 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1165 ut_params->ibuf, QUOTE_512_BYTES);
1166 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1168 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1169 sym_op->auth.data.length = QUOTE_512_BYTES;
1171 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1172 CIPHER_IV_LENGTH_AES_CBC);
1173 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1174 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1176 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1177 CIPHER_IV_LENGTH_AES_CBC);
1179 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1180 sym_op->cipher.data.length = QUOTE_512_BYTES;
1182 /* Process crypto operation */
1183 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1184 ut_params->op), "failed to process sym crypto op");
1186 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1187 "crypto op processing failed");
1189 ut_params->obuf = ut_params->op->sym->m_src;
1192 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1193 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1194 CIPHER_IV_LENGTH_AES_CBC,
1195 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1197 "Ciphertext data not as expected");
1199 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1200 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1201 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1202 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1203 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1204 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1205 DIGEST_BYTE_LENGTH_SHA256,
1206 "Generated digest data not as expected");
1209 return TEST_SUCCESS;
1213 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1215 struct crypto_testsuite_params *ts_params = &testsuite_params;
1216 struct crypto_unittest_params *ut_params = &unittest_params;
1218 /* Generate test mbuf data and digest */
1219 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1221 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1222 QUOTE_512_BYTES, 0);
1224 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1225 DIGEST_BYTE_LENGTH_SHA256);
1226 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1228 rte_memcpy(ut_params->digest,
1229 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1230 DIGEST_BYTE_LENGTH_SHA256);
1232 /* Setup Cipher Parameters */
1233 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1234 ut_params->cipher_xform.next = NULL;
1236 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1237 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1238 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1239 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1241 /* Setup HMAC Parameters */
1242 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1243 ut_params->auth_xform.next = &ut_params->cipher_xform;
1245 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1246 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1247 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1248 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1249 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1251 /* Create Crypto session*/
1253 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1254 &ut_params->auth_xform);
1255 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1257 /* Generate Crypto op data structure */
1258 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1259 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1260 TEST_ASSERT_NOT_NULL(ut_params->op,
1261 "Failed to allocate symmetric crypto operation struct");
1264 /* Set crypto operation data parameters */
1265 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1267 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1269 /* set crypto operation source mbuf */
1270 sym_op->m_src = ut_params->ibuf;
1272 sym_op->auth.digest.data = ut_params->digest;
1273 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1274 ut_params->ibuf, QUOTE_512_BYTES);
1275 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1277 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1278 sym_op->auth.data.length = QUOTE_512_BYTES;
1280 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1281 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1282 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1283 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1285 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1286 CIPHER_IV_LENGTH_AES_CBC);
1288 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1289 sym_op->cipher.data.length = QUOTE_512_BYTES;
1291 /* Process crypto operation */
1292 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1293 ut_params->op), "failed to process sym crypto op");
1295 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1296 "crypto op processing failed");
1298 ut_params->obuf = ut_params->op->sym->m_src;
1301 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1302 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1303 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1305 "Plaintext data not as expected");
1307 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1308 "Digest verification failed");
1310 return TEST_SUCCESS;
1313 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1315 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1317 static uint8_t hmac_sha512_key[] = {
1318 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1319 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1320 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1321 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1322 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1323 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1324 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1325 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1327 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1328 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1329 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1330 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1331 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1332 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1333 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1334 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1335 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1338 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1340 struct crypto_testsuite_params *ts_params = &testsuite_params;
1341 struct crypto_unittest_params *ut_params = &unittest_params;
1343 /* Generate test mbuf data and space for digest */
1344 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1345 catch_22_quote, QUOTE_512_BYTES, 0);
1347 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1348 DIGEST_BYTE_LENGTH_SHA512);
1349 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1351 /* Setup Cipher Parameters */
1352 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1353 ut_params->cipher_xform.next = &ut_params->auth_xform;
1355 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1356 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1357 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1358 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1360 /* Setup HMAC Parameters */
1361 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1362 ut_params->auth_xform.next = NULL;
1364 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1365 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1366 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1367 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1368 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1370 /* Create Crypto session*/
1372 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1373 &ut_params->cipher_xform);
1375 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1377 /* Generate Crypto op data structure */
1378 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1379 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1380 TEST_ASSERT_NOT_NULL(ut_params->op,
1381 "Failed to allocate symmetric crypto operation struct");
1383 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1385 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1387 /* set crypto operation source mbuf */
1388 sym_op->m_src = ut_params->ibuf;
1390 sym_op->auth.digest.data = ut_params->digest;
1391 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1392 ut_params->ibuf, QUOTE_512_BYTES);
1393 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1395 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1396 sym_op->auth.data.length = QUOTE_512_BYTES;
1398 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1399 CIPHER_IV_LENGTH_AES_CBC);
1400 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1401 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1403 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1404 CIPHER_IV_LENGTH_AES_CBC);
1406 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1407 sym_op->cipher.data.length = QUOTE_512_BYTES;
1409 /* Process crypto operation */
1410 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1411 ut_params->op), "failed to process sym crypto op");
1413 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1414 "crypto op processing failed");
1416 ut_params->obuf = ut_params->op->sym->m_src;
1419 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1420 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1421 CIPHER_IV_LENGTH_AES_CBC,
1422 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1424 "Ciphertext data not as expected");
1426 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1427 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1428 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1429 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1430 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1431 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1432 DIGEST_BYTE_LENGTH_SHA512,
1433 "Generated digest data not as expected");
1435 return TEST_SUCCESS;
1440 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1441 struct crypto_unittest_params *ut_params);
1444 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1445 struct crypto_unittest_params *ut_params,
1446 struct crypto_testsuite_params *ts_params);
1449 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1451 struct crypto_unittest_params *ut_params = &unittest_params;
1452 struct crypto_testsuite_params *ts_params = &testsuite_params;
1454 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1455 ut_params) == TEST_SUCCESS,
1456 "Failed to create session params");
1458 /* Create Crypto session*/
1460 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1461 &ut_params->auth_xform);
1462 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1464 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1465 ut_params, ts_params);
1469 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1470 struct crypto_unittest_params *ut_params)
1473 /* Setup Cipher Parameters */
1474 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1475 ut_params->cipher_xform.next = NULL;
1477 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1478 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1479 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1480 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1482 /* Setup HMAC Parameters */
1483 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1484 ut_params->auth_xform.next = &ut_params->cipher_xform;
1486 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1487 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1488 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1489 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1490 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1492 return TEST_SUCCESS;
1497 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1498 struct crypto_unittest_params *ut_params,
1499 struct crypto_testsuite_params *ts_params)
1501 /* Generate test mbuf data and digest */
1502 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1504 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1505 QUOTE_512_BYTES, 0);
1507 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1508 DIGEST_BYTE_LENGTH_SHA512);
1509 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1511 rte_memcpy(ut_params->digest,
1512 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1513 DIGEST_BYTE_LENGTH_SHA512);
1515 /* Generate Crypto op data structure */
1516 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1517 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1518 TEST_ASSERT_NOT_NULL(ut_params->op,
1519 "Failed to allocate symmetric crypto operation struct");
1521 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1523 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1525 /* set crypto operation source mbuf */
1526 sym_op->m_src = ut_params->ibuf;
1528 sym_op->auth.digest.data = ut_params->digest;
1529 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1530 ut_params->ibuf, QUOTE_512_BYTES);
1531 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1533 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1534 sym_op->auth.data.length = QUOTE_512_BYTES;
1536 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1537 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1538 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1539 ut_params->ibuf, 0);
1540 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1542 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1543 CIPHER_IV_LENGTH_AES_CBC);
1545 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1546 sym_op->cipher.data.length = QUOTE_512_BYTES;
1548 /* Process crypto operation */
1549 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1550 ut_params->op), "failed to process sym crypto op");
1552 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1553 "crypto op processing failed");
1555 ut_params->obuf = ut_params->op->sym->m_src;
1558 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1559 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1560 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1562 "Plaintext data not as expected");
1565 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1566 "Digest verification failed");
1568 return TEST_SUCCESS;
1571 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1573 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1574 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1575 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1578 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1579 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1580 0x77, 0x1D, 0x8B, 0x75
1584 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1586 struct crypto_testsuite_params *ts_params = &testsuite_params;
1587 struct crypto_unittest_params *ut_params = &unittest_params;
1589 /* Generate test mbuf data and space for digest */
1590 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1591 catch_22_quote, QUOTE_512_BYTES, 0);
1593 /* Setup Cipher Parameters */
1594 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1595 ut_params->cipher_xform.next = &ut_params->auth_xform;
1597 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1598 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1599 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1600 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1602 /* Setup HMAC Parameters */
1603 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1604 ut_params->auth_xform.next = NULL;
1606 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1607 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1608 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1609 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1610 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1612 /* Create Crypto session*/
1613 ut_params->sess = rte_cryptodev_sym_session_create(
1614 ts_params->valid_devs[0],
1615 &ut_params->cipher_xform);
1616 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1618 /* Generate Crypto op data structure */
1619 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1620 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1621 TEST_ASSERT_NOT_NULL(ut_params->op,
1622 "Failed to allocate symmetric crypto operation struct");
1624 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1626 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1628 /* set crypto operation source mbuf */
1629 sym_op->m_src = ut_params->ibuf;
1631 /* Set operation cipher parameters */
1632 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1633 sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
1634 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1635 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1637 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1638 CIPHER_IV_LENGTH_AES_CBC);
1640 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1641 sym_op->cipher.data.length = QUOTE_512_BYTES;
1643 /* Set operation authentication parameters */
1644 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1645 sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
1646 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1648 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
1649 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1651 memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
1653 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1654 sym_op->auth.data.length = QUOTE_512_BYTES;
1657 /* Process crypto operation */
1658 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1660 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
1662 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1663 "crypto op processing failed");
1666 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1667 rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1668 uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
1669 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1671 "Ciphertext data not as expected");
1673 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1674 rte_pktmbuf_mtod_offset(
1675 ut_params->op->sym->m_src, uint8_t *,
1676 CIPHER_IV_LENGTH_AES_CBC +
1678 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1679 DIGEST_BYTE_LENGTH_AES_XCBC,
1680 "Generated digest data not as expected");
1682 return TEST_SUCCESS;
1686 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1688 struct crypto_testsuite_params *ts_params = &testsuite_params;
1689 struct crypto_unittest_params *ut_params = &unittest_params;
1691 /* Generate test mbuf data and space for digest */
1692 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1693 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1694 QUOTE_512_BYTES, 0);
1696 /* Setup Cipher Parameters */
1697 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1698 ut_params->cipher_xform.next = NULL;
1700 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1701 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1702 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1703 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1705 /* Setup HMAC Parameters */
1706 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1707 ut_params->auth_xform.next = &ut_params->cipher_xform;
1709 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1710 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1711 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1712 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1713 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1715 /* Create Crypto session*/
1717 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1718 &ut_params->auth_xform);
1719 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1721 /* Generate Crypto op data structure */
1722 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1723 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1724 TEST_ASSERT_NOT_NULL(ut_params->op,
1725 "Failed to allocate symmetric crypto operation struct");
1727 /* Set crypto operation data parameters */
1728 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1730 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1732 /* set crypto operation source mbuf */
1733 sym_op->m_src = ut_params->ibuf;
1736 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1737 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
1738 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1739 "no room to append digest");
1741 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1742 ut_params->ibuf, QUOTE_512_BYTES);
1743 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1745 rte_memcpy(sym_op->auth.digest.data,
1746 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1747 DIGEST_BYTE_LENGTH_AES_XCBC);
1749 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1750 sym_op->auth.data.length = QUOTE_512_BYTES;
1752 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1753 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1754 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1755 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1757 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1758 CIPHER_IV_LENGTH_AES_CBC);
1760 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1761 sym_op->cipher.data.length = QUOTE_512_BYTES;
1763 /* Process crypto operation */
1764 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1765 ut_params->op), "failed to process sym crypto op");
1767 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1768 "crypto op processing failed");
1770 ut_params->obuf = ut_params->op->sym->m_src;
1773 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1774 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1775 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1777 "Ciphertext data not as expected");
1779 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1780 "Digest verification failed");
1782 return TEST_SUCCESS;
1785 /* ***** Snow3G Tests ***** */
1787 create_snow3g_hash_session(uint8_t dev_id,
1788 const uint8_t *key, const uint8_t key_len,
1789 const uint8_t aad_len, const uint8_t auth_len,
1790 enum rte_crypto_auth_operation op)
1792 uint8_t hash_key[key_len];
1794 struct crypto_unittest_params *ut_params = &unittest_params;
1796 memcpy(hash_key, key, key_len);
1797 #ifdef RTE_APP_TEST_DEBUG
1798 rte_hexdump(stdout, "key:", key, key_len);
1800 /* Setup Authentication Parameters */
1801 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1802 ut_params->auth_xform.next = NULL;
1804 ut_params->auth_xform.auth.op = op;
1805 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1806 ut_params->auth_xform.auth.key.length = key_len;
1807 ut_params->auth_xform.auth.key.data = hash_key;
1808 ut_params->auth_xform.auth.digest_length = auth_len;
1809 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1810 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1811 &ut_params->auth_xform);
1812 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1816 create_snow3g_cipher_session(uint8_t dev_id,
1817 enum rte_crypto_cipher_operation op,
1818 const uint8_t *key, const uint8_t key_len)
1820 uint8_t cipher_key[key_len];
1822 struct crypto_unittest_params *ut_params = &unittest_params;
1824 memcpy(cipher_key, key, key_len);
1826 /* Setup Cipher Parameters */
1827 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1828 ut_params->cipher_xform.next = NULL;
1830 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1831 ut_params->cipher_xform.cipher.op = op;
1832 ut_params->cipher_xform.cipher.key.data = cipher_key;
1833 ut_params->cipher_xform.cipher.key.length = key_len;
1835 #ifdef RTE_APP_TEST_DEBUG
1836 rte_hexdump(stdout, "key:", key, key_len);
1838 /* Create Crypto session */
1839 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1842 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1847 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1848 const unsigned cipher_len,
1849 const unsigned cipher_offset)
1851 struct crypto_testsuite_params *ts_params = &testsuite_params;
1852 struct crypto_unittest_params *ut_params = &unittest_params;
1853 unsigned iv_pad_len = 0;
1855 /* Generate Crypto op data structure */
1856 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1857 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1858 TEST_ASSERT_NOT_NULL(ut_params->op,
1859 "Failed to allocate pktmbuf offload");
1861 /* Set crypto operation data parameters */
1862 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1864 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1866 /* set crypto operation source mbuf */
1867 sym_op->m_src = ut_params->ibuf;
1870 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1871 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1874 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1876 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1877 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1878 sym_op->cipher.iv.length = iv_pad_len;
1880 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1881 sym_op->cipher.data.length = cipher_len;
1882 sym_op->cipher.data.offset = cipher_offset;
1888 create_snow3g_cipher_auth_session(uint8_t dev_id,
1889 enum rte_crypto_cipher_operation cipher_op,
1890 enum rte_crypto_auth_operation auth_op,
1891 const uint8_t *key, const uint8_t key_len,
1892 const uint8_t aad_len, const uint8_t auth_len)
1894 uint8_t cipher_auth_key[key_len];
1896 struct crypto_unittest_params *ut_params = &unittest_params;
1898 memcpy(cipher_auth_key, key, key_len);
1900 /* Setup Authentication Parameters */
1901 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1902 ut_params->auth_xform.next = NULL;
1904 ut_params->auth_xform.auth.op = auth_op;
1905 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1906 ut_params->auth_xform.auth.key.length = key_len;
1907 /* Hash key = cipher key */
1908 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1909 ut_params->auth_xform.auth.digest_length = auth_len;
1910 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1912 /* Setup Cipher Parameters */
1913 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1914 ut_params->cipher_xform.next = &ut_params->auth_xform;
1916 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1917 ut_params->cipher_xform.cipher.op = cipher_op;
1918 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1919 ut_params->cipher_xform.cipher.key.length = key_len;
1921 #ifdef RTE_APP_TEST_DEBUG
1922 rte_hexdump(stdout, "key:", key, key_len);
1924 /* Create Crypto session*/
1925 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1926 &ut_params->cipher_xform);
1928 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1933 create_snow3g_auth_cipher_session(uint8_t dev_id,
1934 enum rte_crypto_cipher_operation cipher_op,
1935 enum rte_crypto_auth_operation auth_op,
1936 const uint8_t *key, const uint8_t key_len,
1937 const uint8_t aad_len, const uint8_t auth_len)
1939 uint8_t auth_cipher_key[key_len];
1941 struct crypto_unittest_params *ut_params = &unittest_params;
1943 memcpy(auth_cipher_key, key, key_len);
1945 /* Setup Authentication Parameters */
1946 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1947 ut_params->auth_xform.auth.op = auth_op;
1948 ut_params->auth_xform.next = &ut_params->cipher_xform;
1949 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1950 ut_params->auth_xform.auth.key.length = key_len;
1951 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1952 ut_params->auth_xform.auth.digest_length = auth_len;
1953 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1955 /* Setup Cipher Parameters */
1956 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1957 ut_params->cipher_xform.next = NULL;
1958 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1959 ut_params->cipher_xform.cipher.op = cipher_op;
1960 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1961 ut_params->cipher_xform.cipher.key.length = key_len;
1963 #ifdef RTE_APP_TEST_DEBUG
1964 rte_hexdump(stdout, "key:", key, key_len);
1966 /* Create Crypto session*/
1967 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1968 &ut_params->auth_xform);
1970 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1976 create_snow3g_hash_operation(const uint8_t *auth_tag,
1977 const unsigned auth_tag_len,
1978 const uint8_t *aad, const unsigned aad_len,
1979 unsigned data_pad_len,
1980 enum rte_crypto_auth_operation op,
1981 const unsigned auth_len, const unsigned auth_offset)
1983 struct crypto_testsuite_params *ts_params = &testsuite_params;
1985 struct crypto_unittest_params *ut_params = &unittest_params;
1987 unsigned aad_buffer_len;
1989 /* Generate Crypto op data structure */
1990 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1991 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1992 TEST_ASSERT_NOT_NULL(ut_params->op,
1993 "Failed to allocate pktmbuf offload");
1995 /* Set crypto operation data parameters */
1996 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1998 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2000 /* set crypto operation source mbuf */
2001 sym_op->m_src = ut_params->ibuf;
2005 * Always allocate the aad up to the block size.
2006 * The cryptodev API calls out -
2007 * - the array must be big enough to hold the AAD, plus any
2008 * space to round this up to the nearest multiple of the
2009 * block size (16 bytes).
2011 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2012 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2013 ut_params->ibuf, aad_buffer_len);
2014 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2015 "no room to prepend aad");
2016 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2018 sym_op->auth.aad.length = aad_len;
2020 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2021 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2023 #ifdef RTE_APP_TEST_DEBUG
2024 rte_hexdump(stdout, "aad:",
2025 sym_op->auth.aad.data, aad_len);
2029 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2030 ut_params->ibuf, auth_tag_len);
2032 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2033 "no room to append auth tag");
2034 ut_params->digest = sym_op->auth.digest.data;
2035 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2036 ut_params->ibuf, data_pad_len + aad_len);
2037 sym_op->auth.digest.length = auth_tag_len;
2038 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2039 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2041 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2043 #ifdef RTE_APP_TEST_DEBUG
2044 rte_hexdump(stdout, "digest:",
2045 sym_op->auth.digest.data,
2046 sym_op->auth.digest.length);
2049 sym_op->auth.data.length = auth_len;
2050 sym_op->auth.data.offset = auth_offset;
2056 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2057 const unsigned auth_tag_len,
2058 const uint8_t *aad, const unsigned aad_len,
2059 unsigned data_pad_len,
2060 enum rte_crypto_auth_operation op,
2061 const uint8_t *iv, const unsigned iv_len,
2062 const unsigned cipher_len, const unsigned cipher_offset,
2063 const unsigned auth_len, const unsigned auth_offset)
2065 struct crypto_testsuite_params *ts_params = &testsuite_params;
2066 struct crypto_unittest_params *ut_params = &unittest_params;
2068 unsigned iv_pad_len = 0;
2069 unsigned aad_buffer_len;
2071 /* Generate Crypto op data structure */
2072 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2073 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2074 TEST_ASSERT_NOT_NULL(ut_params->op,
2075 "Failed to allocate pktmbuf offload");
2076 /* Set crypto operation data parameters */
2077 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2079 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2081 /* set crypto operation source mbuf */
2082 sym_op->m_src = ut_params->ibuf;
2086 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2088 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2089 ut_params->ibuf, iv_pad_len);
2090 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2092 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2093 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2094 sym_op->cipher.iv.length = iv_pad_len;
2096 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2098 sym_op->cipher.data.length = cipher_len;
2099 sym_op->cipher.data.offset = cipher_offset;
2103 * Always allocate the aad up to the block size.
2104 * The cryptodev API calls out -
2105 * - the array must be big enough to hold the AAD, plus any
2106 * space to round this up to the nearest multiple of the
2107 * block size (16 bytes).
2109 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2111 sym_op->auth.aad.data =
2112 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2113 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2114 "no room to prepend aad");
2115 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2117 sym_op->auth.aad.length = aad_len;
2119 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2120 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2122 #ifdef RTE_APP_TEST_DEBUG
2123 rte_hexdump(stdout, "aad:",
2124 sym_op->auth.aad.data, aad_len);
2128 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2129 ut_params->ibuf, auth_tag_len);
2131 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2132 "no room to append auth tag");
2133 ut_params->digest = sym_op->auth.digest.data;
2134 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2135 ut_params->ibuf, data_pad_len + aad_len);
2136 sym_op->auth.digest.length = auth_tag_len;
2137 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2138 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2140 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2142 #ifdef RTE_APP_TEST_DEBUG
2143 rte_hexdump(stdout, "digest:",
2144 sym_op->auth.digest.data,
2145 sym_op->auth.digest.length);
2148 sym_op->auth.data.length = auth_len;
2149 sym_op->auth.data.offset = auth_offset;
2155 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2156 const uint8_t *iv, const unsigned iv_len,
2157 const uint8_t *aad, const unsigned aad_len,
2158 unsigned data_pad_len,
2159 const unsigned cipher_len, const unsigned cipher_offset,
2160 const unsigned auth_len, const unsigned auth_offset)
2162 struct crypto_testsuite_params *ts_params = &testsuite_params;
2163 struct crypto_unittest_params *ut_params = &unittest_params;
2165 unsigned iv_pad_len = 0;
2166 unsigned aad_buffer_len = 0;
2168 /* Generate Crypto op data structure */
2169 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2170 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2171 TEST_ASSERT_NOT_NULL(ut_params->op,
2172 "Failed to allocate pktmbuf offload");
2174 /* Set crypto operation data parameters */
2175 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2177 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2179 /* set crypto operation source mbuf */
2180 sym_op->m_src = ut_params->ibuf;
2183 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2184 ut_params->ibuf, auth_tag_len);
2186 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2187 "no room to append auth tag");
2189 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2190 ut_params->ibuf, data_pad_len);
2191 sym_op->auth.digest.length = auth_tag_len;
2193 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2195 #ifdef RTE_APP_TEST_DEBUG
2196 rte_hexdump(stdout, "digest:",
2197 sym_op->auth.digest.data,
2198 sym_op->auth.digest.length);
2201 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2203 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2204 ut_params->ibuf, iv_pad_len);
2205 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2207 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2208 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2209 sym_op->cipher.iv.length = iv_pad_len;
2211 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2215 * Always allocate the aad up to the block size.
2216 * The cryptodev API calls out -
2217 * - the array must be big enough to hold the AAD, plus any
2218 * space to round this up to the nearest multiple of the
2219 * block size (16 bytes).
2221 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2223 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2224 ut_params->ibuf, aad_buffer_len);
2225 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2226 "no room to prepend aad");
2227 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2229 sym_op->auth.aad.length = aad_len;
2231 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2232 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2234 #ifdef RTE_APP_TEST_DEBUG
2235 rte_hexdump(stdout, "aad:",
2236 sym_op->auth.aad.data, aad_len);
2239 sym_op->cipher.data.length = cipher_len;
2240 sym_op->cipher.data.offset = auth_offset + cipher_offset;
2242 sym_op->auth.data.length = auth_len;
2243 sym_op->auth.data.offset = auth_offset + cipher_offset;
2249 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2251 struct crypto_testsuite_params *ts_params = &testsuite_params;
2252 struct crypto_unittest_params *ut_params = &unittest_params;
2255 unsigned plaintext_pad_len;
2258 /* Create SNOW3G session */
2259 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2260 tdata->key.data, tdata->key.len,
2261 tdata->aad.len, tdata->digest.len,
2262 RTE_CRYPTO_AUTH_OP_GENERATE);
2266 /* alloc mbuf and set payload */
2267 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2269 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2270 rte_pktmbuf_tailroom(ut_params->ibuf));
2272 /* Append data which is padded to a multiple of */
2273 /* the algorithms block size */
2274 plaintext_pad_len = tdata->plaintext.len >> 3;
2275 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2277 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2279 /* Create SNOW3G opertaion */
2280 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2281 tdata->aad.data, tdata->aad.len,
2282 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2283 tdata->validAuthLenInBits.len,
2284 tdata->validAuthOffsetLenInBits.len);
2288 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2290 ut_params->obuf = ut_params->op->sym->m_src;
2291 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2292 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2293 + plaintext_pad_len + tdata->aad.len;
2296 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2299 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2300 "Snow3G Generated auth tag not as expected");
2306 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2308 struct crypto_testsuite_params *ts_params = &testsuite_params;
2309 struct crypto_unittest_params *ut_params = &unittest_params;
2312 unsigned plaintext_pad_len;
2315 /* Create SNOW3G session */
2316 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2317 tdata->key.data, tdata->key.len,
2318 tdata->aad.len, tdata->digest.len,
2319 RTE_CRYPTO_AUTH_OP_VERIFY);
2322 /* alloc mbuf and set payload */
2323 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2325 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2326 rte_pktmbuf_tailroom(ut_params->ibuf));
2328 /* Append data which is padded to a multiple */
2329 /* of the algorithms block size */
2330 plaintext_pad_len = tdata->plaintext.len >> 3;
2331 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2333 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2335 /* Create SNOW3G operation */
2336 retval = create_snow3g_hash_operation(tdata->digest.data,
2338 tdata->aad.data, tdata->aad.len,
2340 RTE_CRYPTO_AUTH_OP_VERIFY,
2341 tdata->validAuthLenInBits.len,
2342 tdata->validAuthOffsetLenInBits.len);
2346 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2348 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2349 ut_params->obuf = ut_params->op->sym->m_src;
2350 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2351 + plaintext_pad_len + tdata->aad.len;
2354 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2364 test_snow3g_hash_generate_test_case_1(void)
2366 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2370 test_snow3g_hash_generate_test_case_2(void)
2372 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2376 test_snow3g_hash_generate_test_case_3(void)
2378 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2382 test_snow3g_hash_verify_test_case_1(void)
2384 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2389 test_snow3g_hash_verify_test_case_2(void)
2391 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2395 test_snow3g_hash_verify_test_case_3(void)
2397 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2401 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2403 struct crypto_testsuite_params *ts_params = &testsuite_params;
2404 struct crypto_unittest_params *ut_params = &unittest_params;
2408 uint8_t *plaintext, *ciphertext;
2409 uint8_t plaintext_pad_len;
2410 uint8_t lastByteValidBits = 8;
2411 uint8_t lastByteMask = 0xFF;
2413 /* Create SNOW3G session */
2414 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2415 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2416 tdata->key.data, tdata->key.len);
2420 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2422 /* Clear mbuf payload */
2423 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2424 rte_pktmbuf_tailroom(ut_params->ibuf));
2427 * Append data which is padded to a
2428 * multiple of the algorithms block size
2430 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2431 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2433 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2435 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2437 #ifdef RTE_APP_TEST_DEBUG
2438 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2440 /* Create SNOW3G operation */
2441 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2442 tdata->validCipherLenInBits.len,
2443 tdata->validCipherOffsetLenInBits.len);
2447 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2449 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2451 ut_params->obuf = ut_params->op->sym->m_src;
2452 if (ut_params->obuf)
2453 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2456 ciphertext = plaintext;
2458 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2459 if (lastByteValidBits == 0)
2460 lastByteValidBits = 8;
2461 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2462 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2464 #ifdef RTE_APP_TEST_DEBUG
2465 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2468 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2470 tdata->ciphertext.data,
2471 tdata->ciphertext.len >> 3,
2472 "Snow3G Ciphertext data not as expected");
2476 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2478 struct crypto_testsuite_params *ts_params = &testsuite_params;
2479 struct crypto_unittest_params *ut_params = &unittest_params;
2483 uint8_t *plaintext, *ciphertext;
2484 uint8_t ciphertext_pad_len;
2485 uint8_t lastByteValidBits = 8;
2486 uint8_t lastByteMask = 0xFF;
2488 /* Create SNOW3G session */
2489 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2490 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2491 tdata->key.data, tdata->key.len);
2495 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2497 /* Clear mbuf payload */
2498 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2499 rte_pktmbuf_tailroom(ut_params->ibuf));
2502 * Append data which is padded to a
2503 * multiple of the algorithms block size
2505 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
2507 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2508 ciphertext_pad_len);
2509 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
2511 #ifdef RTE_APP_TEST_DEBUG
2512 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2514 /* Create SNOW3G operation */
2515 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2516 tdata->validCipherLenInBits.len,
2517 tdata->validCipherOffsetLenInBits.len);
2521 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2523 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2524 ut_params->obuf = ut_params->op->sym->m_src;
2525 if (ut_params->obuf)
2526 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2529 plaintext = ciphertext;
2530 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2531 if (lastByteValidBits == 0)
2532 lastByteValidBits = 8;
2533 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2534 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2536 #ifdef RTE_APP_TEST_DEBUG
2537 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2540 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2541 tdata->plaintext.data,
2542 tdata->plaintext.len >> 3,
2543 "Snow3G Plaintext data not as expected");
2548 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2550 struct crypto_testsuite_params *ts_params = &testsuite_params;
2551 struct crypto_unittest_params *ut_params = &unittest_params;
2555 uint8_t *plaintext, *ciphertext;
2556 uint8_t plaintext_pad_len;
2557 uint8_t lastByteValidBits = 8;
2558 uint8_t lastByteMask = 0xFF;
2560 /* Create SNOW3G session */
2561 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2562 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2563 RTE_CRYPTO_AUTH_OP_GENERATE,
2564 tdata->key.data, tdata->key.len,
2565 tdata->aad.len, tdata->digest.len);
2568 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2570 /* clear mbuf payload */
2571 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2572 rte_pktmbuf_tailroom(ut_params->ibuf));
2574 /* Append data which is padded to a multiple */
2575 /* of the algorithms block size */
2576 plaintext_pad_len = tdata->plaintext.len >> 3;
2578 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2580 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2582 #ifdef RTE_APP_TEST_DEBUG
2583 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2586 /* Create SNOW3G operation */
2587 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2588 tdata->digest.len, tdata->aad.data,
2589 tdata->aad.len, /*tdata->plaintext.len,*/
2590 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2591 tdata->iv.data, tdata->iv.len,
2592 tdata->validCipherLenInBits.len,
2593 tdata->validCipherOffsetLenInBits.len,
2594 tdata->validAuthLenInBits.len,
2595 tdata->validAuthOffsetLenInBits.len);
2599 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2601 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2602 ut_params->obuf = ut_params->op->sym->m_src;
2603 if (ut_params->obuf)
2604 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2607 ciphertext = plaintext;
2608 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2609 if (lastByteValidBits == 0)
2610 lastByteValidBits = 8;
2611 lastByteMask = lastByteMask << (8-lastByteValidBits);
2612 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2614 #ifdef RTE_APP_TEST_DEBUG
2615 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2618 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2620 tdata->ciphertext.data,
2621 tdata->ciphertext.len >> 3,
2622 "Snow3G Ciphertext data not as expected");
2624 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2625 + plaintext_pad_len + tdata->aad.len;
2628 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2631 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2632 "Snow3G Generated auth tag not as expected");
2636 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2638 struct crypto_testsuite_params *ts_params = &testsuite_params;
2639 struct crypto_unittest_params *ut_params = &unittest_params;
2643 uint8_t *plaintext, *ciphertext;
2644 uint8_t plaintext_pad_len;
2645 uint8_t lastByteValidBits = 8;
2646 uint8_t lastByteMask = 0xFF;
2648 /* Create SNOW3G session */
2649 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2650 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2651 RTE_CRYPTO_AUTH_OP_GENERATE,
2652 tdata->key.data, tdata->key.len,
2653 tdata->aad.len, tdata->digest.len);
2657 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2659 /* clear mbuf payload */
2660 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2661 rte_pktmbuf_tailroom(ut_params->ibuf));
2663 /* Append data which is padded to a multiple */
2664 /* of the algorithms block size */
2665 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
2667 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2669 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2671 #ifdef RTE_APP_TEST_DEBUG
2672 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2675 /* Create SNOW3G operation */
2676 retval = create_snow3g_auth_cipher_operation(
2678 tdata->iv.data, tdata->iv.len,
2679 tdata->aad.data, tdata->aad.len,
2681 tdata->validCipherLenInBits.len,
2682 tdata->validCipherOffsetLenInBits.len,
2683 tdata->validAuthLenInBits.len,
2684 tdata->validAuthOffsetLenInBits.len
2690 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2692 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2693 ut_params->obuf = ut_params->op->sym->m_src;
2694 if (ut_params->obuf)
2695 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2696 + tdata->aad.len + tdata->iv.len;
2698 ciphertext = plaintext;
2700 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2701 if (lastByteValidBits == 0)
2702 lastByteValidBits = 8;
2703 lastByteMask = lastByteMask << (8-lastByteValidBits);
2704 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
2705 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2706 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2707 #ifdef RTE_APP_TEST_DEBUG
2708 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2711 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2713 tdata->ciphertext.data,
2714 tdata->ciphertext.len >> 3,
2715 "Snow3G Ciphertext data not as expected");
2718 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2721 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2722 "Snow3G Generated auth tag not as expected");
2727 test_snow3g_encryption_test_case_1(void)
2729 return test_snow3g_encryption(&snow3g_test_case_1);
2733 test_snow3g_encryption_test_case_2(void)
2735 return test_snow3g_encryption(&snow3g_test_case_2);
2739 test_snow3g_encryption_test_case_3(void)
2741 return test_snow3g_encryption(&snow3g_test_case_3);
2745 test_snow3g_encryption_test_case_4(void)
2747 return test_snow3g_encryption(&snow3g_test_case_4);
2751 test_snow3g_encryption_test_case_5(void)
2753 return test_snow3g_encryption(&snow3g_test_case_5);
2757 test_snow3g_decryption_test_case_1(void)
2759 return test_snow3g_decryption(&snow3g_test_case_1);
2763 test_snow3g_decryption_test_case_2(void)
2765 return test_snow3g_decryption(&snow3g_test_case_2);
2769 test_snow3g_decryption_test_case_3(void)
2771 return test_snow3g_decryption(&snow3g_test_case_3);
2775 test_snow3g_decryption_test_case_4(void)
2777 return test_snow3g_decryption(&snow3g_test_case_4);
2781 test_snow3g_decryption_test_case_5(void)
2783 return test_snow3g_decryption(&snow3g_test_case_5);
2786 test_snow3g_authenticated_encryption_test_case_1(void)
2788 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2792 test_snow3g_encrypted_authentication_test_case_1(void)
2794 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2797 /* ***** AES-GCM Tests ***** */
2800 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
2801 const uint8_t *key, const uint8_t key_len,
2802 const uint8_t aad_len, const uint8_t auth_len)
2804 uint8_t cipher_key[key_len];
2806 struct crypto_unittest_params *ut_params = &unittest_params;
2809 memcpy(cipher_key, key, key_len);
2811 /* Setup Cipher Parameters */
2812 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2813 ut_params->cipher_xform.next = NULL;
2815 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
2816 ut_params->cipher_xform.cipher.op = op;
2817 ut_params->cipher_xform.cipher.key.data = cipher_key;
2818 ut_params->cipher_xform.cipher.key.length = key_len;
2820 #ifdef RTE_APP_TEST_DEBUG
2821 rte_hexdump(stdout, "key:", key, key_len);
2823 /* Setup Authentication Parameters */
2824 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2825 ut_params->auth_xform.next = NULL;
2827 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
2829 ut_params->auth_xform.auth.digest_length = auth_len;
2830 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2831 ut_params->auth_xform.auth.key.length = 0;
2832 ut_params->auth_xform.auth.key.data = NULL;
2834 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
2835 ut_params->cipher_xform.next = &ut_params->auth_xform;
2837 /* Create Crypto session*/
2838 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2839 &ut_params->cipher_xform);
2840 } else {/* Create Crypto session*/
2841 ut_params->auth_xform.next = &ut_params->cipher_xform;
2842 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2843 &ut_params->auth_xform);
2846 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2852 create_gcm_operation(enum rte_crypto_cipher_operation op,
2853 const uint8_t *auth_tag, const unsigned auth_tag_len,
2854 const uint8_t *iv, const unsigned iv_len,
2855 const uint8_t *aad, const unsigned aad_len,
2856 const unsigned data_len, unsigned data_pad_len)
2858 struct crypto_testsuite_params *ts_params = &testsuite_params;
2859 struct crypto_unittest_params *ut_params = &unittest_params;
2861 unsigned iv_pad_len = 0, aad_buffer_len;
2863 /* Generate Crypto op data structure */
2864 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2865 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2866 TEST_ASSERT_NOT_NULL(ut_params->op,
2867 "Failed to allocate symmetric crypto operation struct");
2869 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2873 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2874 ut_params->ibuf, auth_tag_len);
2875 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2876 "no room to append digest");
2877 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2878 ut_params->ibuf, data_pad_len);
2879 sym_op->auth.digest.length = auth_tag_len;
2881 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
2882 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2883 #ifdef RTE_APP_TEST_DEBUG
2884 rte_hexdump(stdout, "digest:",
2885 ut_params->op->digest.data,
2886 ut_params->op->digest.length);
2891 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2893 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2894 ut_params->ibuf, iv_pad_len);
2895 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2897 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2898 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2899 sym_op->cipher.iv.length = iv_pad_len;
2901 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2905 sym_op->cipher.iv.data[15] = 1;
2908 * Always allocate the aad up to the block size.
2909 * The cryptodev API calls out -
2910 * - the array must be big enough to hold the AAD, plus any
2911 * space to round this up to the nearest multiple of the
2912 * block size (16 bytes).
2914 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2916 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2917 ut_params->ibuf, aad_buffer_len);
2918 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2919 "no room to prepend aad");
2920 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2922 sym_op->auth.aad.length = aad_len;
2924 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2925 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2927 #ifdef RTE_APP_TEST_DEBUG
2928 rte_hexdump(stdout, "iv:", ut_params->op->iv.data, iv_pad_len);
2929 rte_hexdump(stdout, "aad:",
2930 ut_params->op->additional_auth.data, aad_len);
2932 sym_op->cipher.data.length = data_len;
2933 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2935 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2936 sym_op->auth.data.length = data_len;
2942 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
2944 struct crypto_testsuite_params *ts_params = &testsuite_params;
2945 struct crypto_unittest_params *ut_params = &unittest_params;
2949 uint8_t *plaintext, *ciphertext, *auth_tag;
2950 uint16_t plaintext_pad_len;
2952 /* Create GCM session */
2953 retval = create_gcm_session(ts_params->valid_devs[0],
2954 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2955 tdata->key.data, tdata->key.len,
2956 tdata->aad.len, tdata->auth_tag.len);
2961 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2963 /* clear mbuf payload */
2964 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2965 rte_pktmbuf_tailroom(ut_params->ibuf));
2968 * Append data which is padded to a multiple
2969 * of the algorithms block size
2971 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2973 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2975 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2977 #ifdef RTE_APP_TEST_DEBUG
2978 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2980 /* Create GCM opertaion */
2981 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2982 tdata->auth_tag.data, tdata->auth_tag.len,
2983 tdata->iv.data, tdata->iv.len,
2984 tdata->aad.data, tdata->aad.len,
2985 tdata->plaintext.len, plaintext_pad_len);
2989 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2991 ut_params->op->sym->m_src = ut_params->ibuf;
2993 /* Process crypto operation */
2994 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2995 ut_params->op), "failed to process sym crypto op");
2997 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2998 "crypto op processing failed");
3000 if (ut_params->op->sym->m_dst) {
3001 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3003 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3004 uint8_t *, plaintext_pad_len);
3006 ciphertext = plaintext;
3007 auth_tag = plaintext + plaintext_pad_len;
3010 #ifdef RTE_APP_TEST_DEBUG
3011 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3012 rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3015 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3017 tdata->ciphertext.data,
3018 tdata->ciphertext.len,
3019 "GCM Ciphertext data not as expected");
3021 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3023 tdata->auth_tag.data,
3024 tdata->auth_tag.len,
3025 "GCM Generated auth tag not as expected");
3032 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3034 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3038 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3040 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3044 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3046 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3050 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3052 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3056 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3058 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3062 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3064 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3068 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3070 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3074 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3076 struct crypto_testsuite_params *ts_params = &testsuite_params;
3077 struct crypto_unittest_params *ut_params = &unittest_params;
3081 uint8_t *plaintext, *ciphertext;
3082 uint16_t ciphertext_pad_len;
3084 /* Create GCM session */
3085 retval = create_gcm_session(ts_params->valid_devs[0],
3086 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3087 tdata->key.data, tdata->key.len,
3088 tdata->aad.len, tdata->auth_tag.len);
3093 /* alloc mbuf and set payload */
3094 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3096 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3097 rte_pktmbuf_tailroom(ut_params->ibuf));
3099 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3101 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3102 ciphertext_pad_len);
3103 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3105 #ifdef RTE_APP_TEST_DEBUG
3106 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3108 /* Create GCM opertaion */
3109 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3110 tdata->auth_tag.data, tdata->auth_tag.len,
3111 tdata->iv.data, tdata->iv.len,
3112 tdata->aad.data, tdata->aad.len,
3113 tdata->ciphertext.len, ciphertext_pad_len);
3118 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3120 ut_params->op->sym->m_src = ut_params->ibuf;
3122 /* Process crypto operation */
3123 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3124 ut_params->op), "failed to process sym crypto op");
3126 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3127 "crypto op processing failed");
3129 if (ut_params->op->sym->m_dst)
3130 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3133 plaintext = ciphertext;
3135 #ifdef RTE_APP_TEST_DEBUG
3136 rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3139 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3141 tdata->plaintext.data,
3142 tdata->plaintext.len,
3143 "GCM plaintext data not as expected");
3145 TEST_ASSERT_EQUAL(ut_params->op->status,
3146 RTE_CRYPTO_OP_STATUS_SUCCESS,
3147 "GCM authentication failed");
3152 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3154 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3158 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3160 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3164 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3166 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3170 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3172 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3176 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3178 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3182 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3184 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3188 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3190 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3196 struct crypto_testsuite_params *ts_params = &testsuite_params;
3197 struct rte_cryptodev_stats stats;
3198 struct rte_cryptodev *dev;
3199 cryptodev_stats_get_t temp_pfn;
3201 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3202 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3203 &stats) == -ENODEV),
3204 "rte_cryptodev_stats_get invalid dev failed");
3205 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3206 "rte_cryptodev_stats_get invalid Param failed");
3207 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3208 temp_pfn = dev->dev_ops->stats_get;
3209 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3210 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3212 "rte_cryptodev_stats_get invalid Param failed");
3213 dev->dev_ops->stats_get = temp_pfn;
3215 /* Test expected values */
3217 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3219 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3221 "rte_cryptodev_stats_get failed");
3222 TEST_ASSERT((stats.enqueued_count == 1),
3223 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3224 TEST_ASSERT((stats.dequeued_count == 1),
3225 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3226 TEST_ASSERT((stats.enqueue_err_count == 0),
3227 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3228 TEST_ASSERT((stats.dequeue_err_count == 0),
3229 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3231 /* invalid device but should ignore and not reset device stats*/
3232 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3233 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3235 "rte_cryptodev_stats_get failed");
3236 TEST_ASSERT((stats.enqueued_count == 1),
3237 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3239 /* check that a valid reset clears stats */
3240 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3241 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3243 "rte_cryptodev_stats_get failed");
3244 TEST_ASSERT((stats.enqueued_count == 0),
3245 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3246 TEST_ASSERT((stats.dequeued_count == 0),
3247 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3249 return TEST_SUCCESS;
3254 test_multi_session(void)
3256 struct crypto_testsuite_params *ts_params = &testsuite_params;
3257 struct crypto_unittest_params *ut_params = &unittest_params;
3259 struct rte_cryptodev_info dev_info;
3260 struct rte_cryptodev_sym_session **sessions;
3264 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3267 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
3269 sessions = rte_malloc(NULL,
3270 (sizeof(struct rte_cryptodev_sym_session *) *
3271 dev_info.sym.max_nb_sessions) + 1, 0);
3273 /* Create multiple crypto sessions*/
3274 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
3275 sessions[i] = rte_cryptodev_sym_session_create(
3276 ts_params->valid_devs[0],
3277 &ut_params->auth_xform);
3278 TEST_ASSERT_NOT_NULL(sessions[i],
3279 "Session creation failed at session number %u",
3282 /* Attempt to send a request on each session */
3283 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
3284 sessions[i], ut_params, ts_params),
3285 "Failed to perform decrypt on request "
3287 /* free crypto operation structure */
3289 rte_crypto_op_free(ut_params->op);
3292 * free mbuf - both obuf and ibuf are usually the same,
3293 * but rte copes even if we call free twice
3295 if (ut_params->obuf) {
3296 rte_pktmbuf_free(ut_params->obuf);
3297 ut_params->obuf = 0;
3301 /* Next session create should fail */
3302 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
3303 &ut_params->auth_xform);
3304 TEST_ASSERT_NULL(sessions[i],
3305 "Session creation succeeded unexpectedly!");
3307 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
3308 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
3313 return TEST_SUCCESS;
3317 test_not_in_place_crypto(void)
3319 struct crypto_testsuite_params *ts_params = &testsuite_params;
3320 struct crypto_unittest_params *ut_params = &unittest_params;
3321 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3323 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3325 /* Create multiple crypto sessions*/
3327 ut_params->sess = rte_cryptodev_sym_session_create(
3328 ts_params->valid_devs[0], &ut_params->auth_xform);
3330 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3333 /* Generate test mbuf data and digest */
3334 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
3336 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
3337 QUOTE_512_BYTES, 0);
3339 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3340 DIGEST_BYTE_LENGTH_SHA512);
3341 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
3343 rte_memcpy(ut_params->digest,
3344 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
3345 DIGEST_BYTE_LENGTH_SHA512);
3347 /* Generate Crypto op data structure */
3348 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3349 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3350 TEST_ASSERT_NOT_NULL(ut_params->op,
3351 "Failed to allocate symmetric crypto operation struct");
3354 /* Set crypto operation data parameters */
3355 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3357 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3359 /* set crypto operation source mbuf */
3360 sym_op->m_src = ut_params->ibuf;
3361 sym_op->m_dst = dst_m;
3363 sym_op->auth.digest.data = ut_params->digest;
3364 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3365 ut_params->ibuf, QUOTE_512_BYTES);
3366 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
3368 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
3369 sym_op->auth.data.length = QUOTE_512_BYTES;
3372 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3373 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
3374 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
3375 ut_params->ibuf, 0);
3376 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
3378 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
3379 CIPHER_IV_LENGTH_AES_CBC);
3381 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
3382 sym_op->cipher.data.length = QUOTE_512_BYTES;
3384 /* Process crypto operation */
3385 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3387 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
3389 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3390 "crypto operation processing failed");
3393 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3394 rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
3397 "Plaintext data not as expected");
3401 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3402 "Digest verification failed");
3404 return TEST_SUCCESS;
3408 static struct unit_test_suite cryptodev_qat_testsuite = {
3409 .suite_name = "Crypto QAT Unit Test Suite",
3410 .setup = testsuite_setup,
3411 .teardown = testsuite_teardown,
3412 .unit_test_cases = {
3413 TEST_CASE_ST(ut_setup, ut_teardown,
3414 test_device_configure_invalid_dev_id),
3415 TEST_CASE_ST(ut_setup, ut_teardown,
3416 test_device_configure_invalid_queue_pair_ids),
3417 TEST_CASE_ST(ut_setup, ut_teardown,
3418 test_queue_pair_descriptor_setup),
3419 TEST_CASE_ST(ut_setup, ut_teardown,
3420 test_multi_session),
3422 TEST_CASE_ST(ut_setup, ut_teardown,
3423 test_AES_CBC_HMAC_SHA1_encrypt_digest),
3424 TEST_CASE_ST(ut_setup, ut_teardown,
3425 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
3427 TEST_CASE_ST(ut_setup, ut_teardown,
3428 test_AES_CBC_HMAC_SHA256_encrypt_digest),
3429 TEST_CASE_ST(ut_setup, ut_teardown,
3430 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3432 TEST_CASE_ST(ut_setup, ut_teardown,
3433 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3434 TEST_CASE_ST(ut_setup, ut_teardown,
3435 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3437 TEST_CASE_ST(ut_setup, ut_teardown,
3438 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3439 TEST_CASE_ST(ut_setup, ut_teardown,
3440 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3441 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3442 /** Snow3G encrypt only (UEA2) */
3443 TEST_CASE_ST(ut_setup, ut_teardown,
3444 test_snow3g_encryption_test_case_1),
3445 TEST_CASE_ST(ut_setup, ut_teardown,
3446 test_snow3g_encryption_test_case_2),
3447 TEST_CASE_ST(ut_setup, ut_teardown,
3448 test_snow3g_encryption_test_case_3),
3449 TEST_CASE_ST(ut_setup, ut_teardown,
3450 test_snow3g_encryption_test_case_4),
3451 TEST_CASE_ST(ut_setup, ut_teardown,
3452 test_snow3g_encryption_test_case_5),
3455 /** Snow3G decrypt only (UEA2) */
3456 TEST_CASE_ST(ut_setup, ut_teardown,
3457 test_snow3g_decryption_test_case_1),
3458 TEST_CASE_ST(ut_setup, ut_teardown,
3459 test_snow3g_decryption_test_case_2),
3460 TEST_CASE_ST(ut_setup, ut_teardown,
3461 test_snow3g_decryption_test_case_3),
3462 TEST_CASE_ST(ut_setup, ut_teardown,
3463 test_snow3g_decryption_test_case_4),
3464 TEST_CASE_ST(ut_setup, ut_teardown,
3465 test_snow3g_decryption_test_case_5),
3466 TEST_CASE_ST(ut_setup, ut_teardown,
3467 test_snow3g_hash_generate_test_case_1),
3468 TEST_CASE_ST(ut_setup, ut_teardown,
3469 test_snow3g_hash_generate_test_case_2),
3470 TEST_CASE_ST(ut_setup, ut_teardown,
3471 test_snow3g_hash_generate_test_case_3),
3472 TEST_CASE_ST(ut_setup, ut_teardown,
3473 test_snow3g_hash_verify_test_case_1),
3474 TEST_CASE_ST(ut_setup, ut_teardown,
3475 test_snow3g_hash_verify_test_case_2),
3476 TEST_CASE_ST(ut_setup, ut_teardown,
3477 test_snow3g_hash_verify_test_case_3),
3478 TEST_CASE_ST(ut_setup, ut_teardown,
3479 test_snow3g_authenticated_encryption_test_case_1),
3480 TEST_CASE_ST(ut_setup, ut_teardown,
3481 test_snow3g_encrypted_authentication_test_case_1),
3482 TEST_CASES_END() /**< NULL terminate unit test array */
3486 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3487 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3488 .setup = testsuite_setup,
3489 .teardown = testsuite_teardown,
3490 .unit_test_cases = {
3491 TEST_CASE_ST(ut_setup, ut_teardown,
3492 test_AES_CBC_HMAC_SHA1_encrypt_digest),
3493 TEST_CASE_ST(ut_setup, ut_teardown,
3494 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
3496 TEST_CASE_ST(ut_setup, ut_teardown,
3497 test_AES_CBC_HMAC_SHA256_encrypt_digest),
3498 TEST_CASE_ST(ut_setup, ut_teardown,
3499 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3501 TEST_CASE_ST(ut_setup, ut_teardown,
3502 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3503 TEST_CASE_ST(ut_setup, ut_teardown,
3504 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3506 TEST_CASE_ST(ut_setup, ut_teardown,
3507 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3508 TEST_CASE_ST(ut_setup, ut_teardown,
3509 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3511 TEST_CASE_ST(ut_setup, ut_teardown,
3512 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
3514 TEST_CASE_ST(ut_setup, ut_teardown,
3515 test_not_in_place_crypto),
3517 TEST_CASES_END() /**< NULL terminate unit test array */
3521 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
3522 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
3523 .setup = testsuite_setup,
3524 .teardown = testsuite_teardown,
3525 .unit_test_cases = {
3526 /** AES GCM Authenticated Encryption */
3527 TEST_CASE_ST(ut_setup, ut_teardown,
3528 test_mb_AES_GCM_authenticated_encryption_test_case_1),
3529 TEST_CASE_ST(ut_setup, ut_teardown,
3530 test_mb_AES_GCM_authenticated_encryption_test_case_2),
3531 TEST_CASE_ST(ut_setup, ut_teardown,
3532 test_mb_AES_GCM_authenticated_encryption_test_case_3),
3533 TEST_CASE_ST(ut_setup, ut_teardown,
3534 test_mb_AES_GCM_authenticated_encryption_test_case_4),
3535 TEST_CASE_ST(ut_setup, ut_teardown,
3536 test_mb_AES_GCM_authenticated_encryption_test_case_5),
3537 TEST_CASE_ST(ut_setup, ut_teardown,
3538 test_mb_AES_GCM_authenticated_encryption_test_case_6),
3539 TEST_CASE_ST(ut_setup, ut_teardown,
3540 test_mb_AES_GCM_authenticated_encryption_test_case_7),
3542 /** AES GCM Authenticated Decryption */
3543 TEST_CASE_ST(ut_setup, ut_teardown,
3544 test_mb_AES_GCM_authenticated_decryption_test_case_1),
3545 TEST_CASE_ST(ut_setup, ut_teardown,
3546 test_mb_AES_GCM_authenticated_decryption_test_case_2),
3547 TEST_CASE_ST(ut_setup, ut_teardown,
3548 test_mb_AES_GCM_authenticated_decryption_test_case_3),
3549 TEST_CASE_ST(ut_setup, ut_teardown,
3550 test_mb_AES_GCM_authenticated_decryption_test_case_4),
3551 TEST_CASE_ST(ut_setup, ut_teardown,
3552 test_mb_AES_GCM_authenticated_decryption_test_case_5),
3553 TEST_CASE_ST(ut_setup, ut_teardown,
3554 test_mb_AES_GCM_authenticated_decryption_test_case_6),
3555 TEST_CASE_ST(ut_setup, ut_teardown,
3556 test_mb_AES_GCM_authenticated_decryption_test_case_7),
3558 TEST_CASES_END() /**< NULL terminate unit test array */
3562 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
3563 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3564 .setup = testsuite_setup,
3565 .teardown = testsuite_teardown,
3566 .unit_test_cases = {
3567 /** Snow3G encrypt only (UEA2) */
3568 TEST_CASE_ST(ut_setup, ut_teardown,
3569 test_snow3g_encryption_test_case_1),
3570 TEST_CASE_ST(ut_setup, ut_teardown,
3571 test_snow3g_encryption_test_case_2),
3572 TEST_CASE_ST(ut_setup, ut_teardown,
3573 test_snow3g_encryption_test_case_3),
3574 TEST_CASE_ST(ut_setup, ut_teardown,
3575 test_snow3g_encryption_test_case_4),
3576 TEST_CASE_ST(ut_setup, ut_teardown,
3577 test_snow3g_encryption_test_case_5),
3580 /** Snow3G decrypt only (UEA2) */
3581 TEST_CASE_ST(ut_setup, ut_teardown,
3582 test_snow3g_decryption_test_case_1),
3583 TEST_CASE_ST(ut_setup, ut_teardown,
3584 test_snow3g_decryption_test_case_2),
3585 TEST_CASE_ST(ut_setup, ut_teardown,
3586 test_snow3g_decryption_test_case_3),
3587 TEST_CASE_ST(ut_setup, ut_teardown,
3588 test_snow3g_decryption_test_case_4),
3589 TEST_CASE_ST(ut_setup, ut_teardown,
3590 test_snow3g_decryption_test_case_5),
3591 TEST_CASE_ST(ut_setup, ut_teardown,
3592 test_snow3g_hash_generate_test_case_1),
3593 TEST_CASE_ST(ut_setup, ut_teardown,
3594 test_snow3g_hash_generate_test_case_2),
3595 TEST_CASE_ST(ut_setup, ut_teardown,
3596 test_snow3g_hash_generate_test_case_3),
3597 TEST_CASE_ST(ut_setup, ut_teardown,
3598 test_snow3g_hash_verify_test_case_1),
3599 TEST_CASE_ST(ut_setup, ut_teardown,
3600 test_snow3g_hash_verify_test_case_2),
3601 TEST_CASE_ST(ut_setup, ut_teardown,
3602 test_snow3g_hash_verify_test_case_3),
3603 TEST_CASE_ST(ut_setup, ut_teardown,
3604 test_snow3g_authenticated_encryption_test_case_1),
3605 TEST_CASE_ST(ut_setup, ut_teardown,
3606 test_snow3g_encrypted_authentication_test_case_1),
3608 TEST_CASES_END() /**< NULL terminate unit test array */
3613 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3615 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3616 return unit_test_suite_runner(&cryptodev_qat_testsuite);
3618 static struct test_command cryptodev_qat_cmd = {
3619 .command = "cryptodev_qat_autotest",
3620 .callback = test_cryptodev_qat,
3624 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3626 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3628 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3631 static struct test_command cryptodev_aesni_mb_cmd = {
3632 .command = "cryptodev_aesni_mb_autotest",
3633 .callback = test_cryptodev_aesni_mb,
3637 test_cryptodev_aesni_gcm(void)
3639 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
3641 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
3644 static struct test_command cryptodev_aesni_gcm_cmd = {
3645 .command = "cryptodev_aesni_gcm_autotest",
3646 .callback = test_cryptodev_aesni_gcm,
3650 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3652 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3654 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3657 static struct test_command cryptodev_sw_snow3g_cmd = {
3658 .command = "cryptodev_sw_snow3g_autotest",
3659 .callback = test_cryptodev_sw_snow3g,
3662 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3663 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3664 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
3665 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);