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 static enum rte_cryptodev_type gbl_cryptodev_type;
49 struct crypto_testsuite_params {
50 struct rte_mempool *mbuf_pool;
51 struct rte_mempool *op_mpool;
52 struct rte_cryptodev_config conf;
53 struct rte_cryptodev_qp_conf qp_conf;
55 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
56 uint8_t valid_dev_count;
59 struct crypto_unittest_params {
60 struct rte_crypto_sym_xform cipher_xform;
61 struct rte_crypto_sym_xform auth_xform;
63 struct rte_cryptodev_sym_session *sess;
65 struct rte_crypto_op *op;
67 struct rte_mbuf *obuf, *ibuf;
72 #define ALIGN_POW2_ROUNDUP(num, align) \
73 (((num) + (align) - 1) & ~((align) - 1))
76 * Forward declarations.
79 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
80 struct crypto_unittest_params *ut_params);
83 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
84 struct crypto_unittest_params *ut_params,
85 struct crypto_testsuite_params *ts_param);
87 static struct rte_mbuf *
88 setup_test_string(struct rte_mempool *mpool,
89 const char *string, size_t len, uint8_t blocksize)
91 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
92 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
94 memset(m->buf_addr, 0, m->buf_len);
96 char *dst = rte_pktmbuf_append(m, t_len);
103 rte_memcpy(dst, string, t_len);
111 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
113 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
117 static struct rte_crypto_op *
118 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
121 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
124 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
125 printf("Error sending packet for encryption");
131 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
136 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
142 static struct crypto_testsuite_params testsuite_params = { NULL };
143 static struct crypto_unittest_params unittest_params;
146 testsuite_setup(void)
148 struct crypto_testsuite_params *ts_params = &testsuite_params;
149 struct rte_cryptodev_info info;
150 unsigned i, nb_devs, dev_id;
154 memset(ts_params, 0, sizeof(*ts_params));
156 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
157 if (ts_params->mbuf_pool == NULL) {
158 /* Not already created so create */
159 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
161 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
163 if (ts_params->mbuf_pool == NULL) {
164 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
169 ts_params->op_mpool = rte_crypto_op_pool_create(
170 "MBUF_CRYPTO_SYM_OP_POOL",
171 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
172 NUM_MBUFS, MBUF_CACHE_SIZE,
174 sizeof(struct rte_crypto_sym_xform),
176 if (ts_params->op_mpool == NULL) {
177 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
181 /* Create 2 AESNI MB devices if required */
182 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
183 nb_devs = rte_cryptodev_count_devtype(
184 RTE_CRYPTODEV_AESNI_MB_PMD);
186 for (i = nb_devs; i < 2; i++) {
187 ret = rte_eal_vdev_init(
188 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
190 TEST_ASSERT(ret == 0,
191 "Failed to create instance %u of"
193 i, CRYPTODEV_NAME_AESNI_MB_PMD);
198 /* Create 2 Snow3G devices if required */
199 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
200 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
202 for (i = nb_devs; i < 2; i++) {
203 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
204 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
205 "Failed to create instance %u of"
207 i, CRYPTODEV_NAME_SNOW3G_PMD);
212 nb_devs = rte_cryptodev_count();
214 RTE_LOG(ERR, USER1, "No crypto devices found?");
218 /* Create list of valid crypto devs */
219 for (i = 0; i < nb_devs; i++) {
220 rte_cryptodev_info_get(i, &info);
221 if (info.dev_type == gbl_cryptodev_type)
222 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
225 if (ts_params->valid_dev_count < 1)
228 /* Set up all the qps on the first of the valid devices found */
229 for (i = 0; i < 1; i++) {
230 dev_id = ts_params->valid_devs[i];
232 rte_cryptodev_info_get(dev_id, &info);
235 * Since we can't free and re-allocate queue memory always set
236 * the queues on this device up to max size first so enough
237 * memory is allocated for any later re-configures needed by
241 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
242 ts_params->conf.socket_id = SOCKET_ID_ANY;
243 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
245 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
247 "Failed to configure cryptodev %u with %u qps",
248 dev_id, ts_params->conf.nb_queue_pairs);
250 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
252 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
253 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
254 dev_id, qp_id, &ts_params->qp_conf,
255 rte_cryptodev_socket_id(dev_id)),
256 "Failed to setup queue pair %u on "
266 testsuite_teardown(void)
268 struct crypto_testsuite_params *ts_params = &testsuite_params;
270 if (ts_params->mbuf_pool != NULL) {
271 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
272 rte_mempool_count(ts_params->mbuf_pool));
275 if (ts_params->op_mpool != NULL) {
276 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
277 rte_mempool_count(ts_params->op_mpool));
285 struct crypto_testsuite_params *ts_params = &testsuite_params;
286 struct crypto_unittest_params *ut_params = &unittest_params;
290 /* Clear unit test parameters before running test */
291 memset(ut_params, 0, sizeof(*ut_params));
293 /* Reconfigure device to default parameters */
294 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
295 ts_params->conf.socket_id = SOCKET_ID_ANY;
296 ts_params->conf.session_mp.nb_objs =
297 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
298 DEFAULT_NUM_OPS_INFLIGHT :
299 DEFAULT_NUM_OPS_INFLIGHT;
301 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
303 "Failed to configure cryptodev %u",
304 ts_params->valid_devs[0]);
307 * Now reconfigure queues to size we actually want to use in this
310 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
312 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
313 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
314 ts_params->valid_devs[0], qp_id,
316 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
317 "Failed to setup queue pair %u on cryptodev %u",
318 qp_id, ts_params->valid_devs[0]);
322 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
324 /* Start the device */
325 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
326 "Failed to start cryptodev %u",
327 ts_params->valid_devs[0]);
335 struct crypto_testsuite_params *ts_params = &testsuite_params;
336 struct crypto_unittest_params *ut_params = &unittest_params;
337 struct rte_cryptodev_stats stats;
339 /* free crypto session structure */
340 if (ut_params->sess) {
341 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
343 ut_params->sess = NULL;
346 /* free crypto operation structure */
348 rte_crypto_op_free(ut_params->op);
351 * free mbuf - both obuf and ibuf are usually the same,
352 * but rte copes even if we call free twice
354 if (ut_params->obuf) {
355 rte_pktmbuf_free(ut_params->obuf);
358 if (ut_params->ibuf) {
359 rte_pktmbuf_free(ut_params->ibuf);
363 if (ts_params->mbuf_pool != NULL)
364 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
365 rte_mempool_count(ts_params->mbuf_pool));
367 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
369 /* Stop the device */
370 rte_cryptodev_stop(ts_params->valid_devs[0]);
374 test_device_configure_invalid_dev_id(void)
376 struct crypto_testsuite_params *ts_params = &testsuite_params;
377 uint16_t dev_id, num_devs = 0;
379 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
380 "Need at least %d devices for test", 1);
382 /* valid dev_id values */
383 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
385 /* Stop the device in case it's started so it can be configured */
386 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
388 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
389 "Failed test for rte_cryptodev_configure: "
390 "invalid dev_num %u", dev_id);
392 /* invalid dev_id values */
395 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
396 "Failed test for rte_cryptodev_configure: "
397 "invalid dev_num %u", dev_id);
401 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
402 "Failed test for rte_cryptodev_configure:"
403 "invalid dev_num %u", dev_id);
409 test_device_configure_invalid_queue_pair_ids(void)
411 struct crypto_testsuite_params *ts_params = &testsuite_params;
413 /* Stop the device in case it's started so it can be configured */
414 rte_cryptodev_stop(ts_params->valid_devs[0]);
416 /* valid - one queue pairs */
417 ts_params->conf.nb_queue_pairs = 1;
419 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
421 "Failed to configure cryptodev: dev_id %u, qp_id %u",
422 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
425 /* valid - max value queue pairs */
426 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
428 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
430 "Failed to configure cryptodev: dev_id %u, qp_id %u",
431 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
434 /* invalid - zero queue pairs */
435 ts_params->conf.nb_queue_pairs = 0;
437 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
439 "Failed test for rte_cryptodev_configure, dev_id %u,"
441 ts_params->valid_devs[0],
442 ts_params->conf.nb_queue_pairs);
445 /* invalid - max value supported by field queue pairs */
446 ts_params->conf.nb_queue_pairs = UINT16_MAX;
448 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
450 "Failed test for rte_cryptodev_configure, dev_id %u,"
452 ts_params->valid_devs[0],
453 ts_params->conf.nb_queue_pairs);
456 /* invalid - max value + 1 queue pairs */
457 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
459 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
461 "Failed test for rte_cryptodev_configure, dev_id %u,"
463 ts_params->valid_devs[0],
464 ts_params->conf.nb_queue_pairs);
470 test_queue_pair_descriptor_setup(void)
472 struct crypto_testsuite_params *ts_params = &testsuite_params;
473 struct rte_cryptodev_info dev_info;
474 struct rte_cryptodev_qp_conf qp_conf = {
475 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
480 /* Stop the device in case it's started so it can be configured */
481 rte_cryptodev_stop(ts_params->valid_devs[0]);
484 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
486 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
488 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
489 &ts_params->conf), "Failed to configure cryptodev %u",
490 ts_params->valid_devs[0]);
494 * Test various ring sizes on this device. memzones can't be
495 * freed so are re-used if ring is released and re-created.
497 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
499 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
500 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
501 ts_params->valid_devs[0], qp_id, &qp_conf,
502 rte_cryptodev_socket_id(
503 ts_params->valid_devs[0])),
505 "rte_cryptodev_queue_pair_setup: num_inflights "
506 "%u on qp %u on cryptodev %u",
507 qp_conf.nb_descriptors, qp_id,
508 ts_params->valid_devs[0]);
511 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
513 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
514 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
515 ts_params->valid_devs[0], qp_id, &qp_conf,
516 rte_cryptodev_socket_id(
517 ts_params->valid_devs[0])),
519 " rte_cryptodev_queue_pair_setup: num_inflights"
520 " %u on qp %u on cryptodev %u",
521 qp_conf.nb_descriptors, qp_id,
522 ts_params->valid_devs[0]);
525 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
527 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
528 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
529 ts_params->valid_devs[0], qp_id, &qp_conf,
530 rte_cryptodev_socket_id(
531 ts_params->valid_devs[0])),
533 "rte_cryptodev_queue_pair_setup: num_inflights"
534 " %u on qp %u on cryptodev %u",
535 qp_conf.nb_descriptors, qp_id,
536 ts_params->valid_devs[0]);
539 /* invalid number of descriptors - max supported + 2 */
540 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
542 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
543 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
544 ts_params->valid_devs[0], qp_id, &qp_conf,
545 rte_cryptodev_socket_id(
546 ts_params->valid_devs[0])),
547 "Unexpectedly passed test for "
548 "rte_cryptodev_queue_pair_setup:"
549 "num_inflights %u on qp %u on cryptodev %u",
550 qp_conf.nb_descriptors, qp_id,
551 ts_params->valid_devs[0]);
554 /* invalid number of descriptors - max value of parameter */
555 qp_conf.nb_descriptors = UINT32_MAX-1;
557 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
558 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
559 ts_params->valid_devs[0], qp_id, &qp_conf,
560 rte_cryptodev_socket_id(
561 ts_params->valid_devs[0])),
562 "Unexpectedly passed test for "
563 "rte_cryptodev_queue_pair_setup:"
564 "num_inflights %u on qp %u on cryptodev %u",
565 qp_conf.nb_descriptors, qp_id,
566 ts_params->valid_devs[0]);
569 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
571 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
572 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
573 ts_params->valid_devs[0], qp_id, &qp_conf,
574 rte_cryptodev_socket_id(
575 ts_params->valid_devs[0])),
577 " rte_cryptodev_queue_pair_setup:"
578 "num_inflights %u on qp %u on cryptodev %u",
579 qp_conf.nb_descriptors, qp_id,
580 ts_params->valid_devs[0]);
583 /* invalid number of descriptors - max supported + 1 */
584 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
586 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
587 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
588 ts_params->valid_devs[0], qp_id, &qp_conf,
589 rte_cryptodev_socket_id(
590 ts_params->valid_devs[0])),
591 "Unexpectedly passed test for "
592 "rte_cryptodev_queue_pair_setup:"
593 "num_inflights %u on qp %u on cryptodev %u",
594 qp_conf.nb_descriptors, qp_id,
595 ts_params->valid_devs[0]);
598 /* test invalid queue pair id */
599 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
601 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
603 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
604 ts_params->valid_devs[0],
606 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
607 "Failed test for rte_cryptodev_queue_pair_setup:"
608 "invalid qp %u on cryptodev %u",
609 qp_id, ts_params->valid_devs[0]);
611 qp_id = 0xffff; /*invalid*/
613 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
614 ts_params->valid_devs[0],
616 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
617 "Failed test for rte_cryptodev_queue_pair_setup:"
618 "invalid qp %u on cryptodev %u",
619 qp_id, ts_params->valid_devs[0]);
624 /* ***** Plaintext data for tests ***** */
626 const char catch_22_quote_1[] =
627 "There was only one catch and that was Catch-22, which "
628 "specified that a concern for one's safety in the face of "
629 "dangers that were real and immediate was the process of a "
630 "rational mind. Orr was crazy and could be grounded. All he "
631 "had to do was ask; and as soon as he did, he would no longer "
632 "be crazy and would have to fly more missions. Orr would be "
633 "crazy to fly more missions and sane if he didn't, but if he "
634 "was sane he had to fly them. If he flew them he was crazy "
635 "and didn't have to; but if he didn't want to he was sane and "
636 "had to. Yossarian was moved very deeply by the absolute "
637 "simplicity of this clause of Catch-22 and let out a "
638 "respectful whistle. \"That's some catch, that Catch-22\", he "
639 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
641 const char catch_22_quote[] =
642 "What a lousy earth! He wondered how many people were "
643 "destitute that same night even in his own prosperous country, "
644 "how many homes were shanties, how many husbands were drunk "
645 "and wives socked, and how many children were bullied, abused, "
646 "or abandoned. How many families hungered for food they could "
647 "not afford to buy? How many hearts were broken? How many "
648 "suicides would take place that same night, how many people "
649 "would go insane? How many cockroaches and landlords would "
650 "triumph? How many winners were losers, successes failures, "
651 "and rich men poor men? How many wise guys were stupid? How "
652 "many happy endings were unhappy endings? How many honest men "
653 "were liars, brave men cowards, loyal men traitors, how many "
654 "sainted men were corrupt, how many people in positions of "
655 "trust had sold their souls to bodyguards, how many had never "
656 "had souls? How many straight-and-narrow paths were crooked "
657 "paths? How many best families were worst families and how "
658 "many good people were bad people? When you added them all up "
659 "and then subtracted, you might be left with only the children, "
660 "and perhaps with Albert Einstein and an old violinist or "
661 "sculptor somewhere.";
663 #define QUOTE_480_BYTES (480)
664 #define QUOTE_512_BYTES (512)
665 #define QUOTE_768_BYTES (768)
666 #define QUOTE_1024_BYTES (1024)
670 /* ***** SHA1 Hash Tests ***** */
672 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
674 static uint8_t hmac_sha1_key[] = {
675 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
676 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
677 0xDE, 0xF4, 0xDE, 0xAD };
679 /* ***** SHA224 Hash Tests ***** */
681 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
684 /* ***** AES-CBC Cipher Tests ***** */
686 #define CIPHER_KEY_LENGTH_AES_CBC (16)
687 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
689 static uint8_t aes_cbc_key[] = {
690 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
691 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
693 static uint8_t aes_cbc_iv[] = {
694 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
695 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
698 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
700 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
701 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
702 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
703 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
704 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
705 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
706 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
707 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
708 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
709 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
710 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
711 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
712 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
713 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
714 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
715 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
716 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
717 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
718 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
719 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
720 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
721 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
722 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
723 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
724 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
725 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
726 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
727 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
728 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
729 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
730 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
731 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
732 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
733 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
734 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
735 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
736 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
737 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
738 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
739 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
740 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
741 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
742 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
743 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
744 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
745 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
746 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
747 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
748 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
749 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
750 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
751 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
752 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
753 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
754 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
755 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
756 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
757 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
758 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
759 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
760 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
761 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
762 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
763 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
764 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
767 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
768 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
769 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
770 0x18, 0x8c, 0x1d, 0x32
775 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
777 struct crypto_testsuite_params *ts_params = &testsuite_params;
778 struct crypto_unittest_params *ut_params = &unittest_params;
780 /* Generate test mbuf data and space for digest */
781 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
782 catch_22_quote, QUOTE_512_BYTES, 0);
784 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
785 DIGEST_BYTE_LENGTH_SHA1);
786 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
788 /* Setup Cipher Parameters */
789 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
790 ut_params->cipher_xform.next = &ut_params->auth_xform;
792 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
793 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
794 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
795 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
797 /* Setup HMAC Parameters */
798 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
800 ut_params->auth_xform.next = NULL;
802 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
803 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
804 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
805 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
806 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
808 /* Create crypto session*/
809 ut_params->sess = rte_cryptodev_sym_session_create(
810 ts_params->valid_devs[0],
811 &ut_params->cipher_xform);
812 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
814 /* Generate crypto op data structure */
815 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
816 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
817 TEST_ASSERT_NOT_NULL(ut_params->op,
818 "Failed to allocate symmetric crypto operation struct");
820 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
822 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
824 /* set crypto operation source mbuf */
825 sym_op->m_src = ut_params->ibuf;
827 /* Set crypto operation authentication parameters */
828 sym_op->auth.digest.data = ut_params->digest;
829 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
830 ut_params->ibuf, QUOTE_512_BYTES);
831 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
833 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
834 sym_op->auth.data.length = QUOTE_512_BYTES;
836 /* Set crypto operation cipher parameters */
837 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
838 CIPHER_IV_LENGTH_AES_CBC);
839 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
840 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
842 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
843 CIPHER_IV_LENGTH_AES_CBC);
845 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
846 sym_op->cipher.data.length = QUOTE_512_BYTES;
848 /* Process crypto operation */
849 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
850 ut_params->op), "failed to process sym crypto op");
852 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
853 "crypto op processing failed");
856 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
857 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
859 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
860 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
862 "ciphertext data not as expected");
864 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
866 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
867 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
868 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
869 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
870 DIGEST_BYTE_LENGTH_SHA1,
871 "Generated digest data not as expected");
877 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
879 struct crypto_testsuite_params *ts_params = &testsuite_params;
880 struct crypto_unittest_params *ut_params = &unittest_params;
882 /* Generate test mbuf data and space for digest */
883 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
884 catch_22_quote, QUOTE_512_BYTES, 0);
886 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
887 DIGEST_BYTE_LENGTH_SHA1);
888 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
890 /* Generate Crypto op data structure */
891 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
892 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
893 TEST_ASSERT_NOT_NULL(ut_params->op,
894 "Failed to allocate symmetric crypto operation struct");
896 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
897 "failed to allocate space for crypto transforms");
899 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
901 /* set crypto operation source mbuf */
902 sym_op->m_src = ut_params->ibuf;
904 /* Set crypto operation data parameters */
905 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
907 /* cipher parameters */
908 sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
909 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
910 sym_op->xform->cipher.key.data = aes_cbc_key;
911 sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
913 /* hash parameters */
914 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
916 sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
917 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
918 sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
919 sym_op->xform->next->auth.key.data = hmac_sha1_key;
920 sym_op->xform->next->auth.digest_length =
921 DIGEST_BYTE_LENGTH_SHA1;
923 sym_op->auth.digest.data = ut_params->digest;
924 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
925 ut_params->ibuf, QUOTE_512_BYTES);
926 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
929 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
930 sym_op->auth.data.length = QUOTE_512_BYTES;
932 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
933 CIPHER_IV_LENGTH_AES_CBC);
934 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
935 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
937 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
938 CIPHER_IV_LENGTH_AES_CBC);
940 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
941 sym_op->cipher.data.length = QUOTE_512_BYTES;
943 /* Process crypto operation */
944 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
945 ut_params->op), "failed to process sym crypto op");
947 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
948 "crypto op processing failed");
950 ut_params->obuf = ut_params->op->sym->m_src;
953 TEST_ASSERT_BUFFERS_ARE_EQUAL(
954 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
955 CIPHER_IV_LENGTH_AES_CBC,
956 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
958 "Ciphertext data not as expected");
960 TEST_ASSERT_BUFFERS_ARE_EQUAL(
961 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
962 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
963 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
964 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
965 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
966 DIGEST_BYTE_LENGTH_SHA1,
967 "Generated digest data not as expected");
974 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
976 struct crypto_testsuite_params *ts_params = &testsuite_params;
977 struct crypto_unittest_params *ut_params = &unittest_params;
979 /* Generate test mbuf data and digest */
980 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
982 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
985 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
986 DIGEST_BYTE_LENGTH_SHA1);
987 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
989 rte_memcpy(ut_params->digest,
990 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
991 DIGEST_BYTE_LENGTH_SHA1);
993 /* Setup Cipher Parameters */
994 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
995 ut_params->cipher_xform.next = NULL;
997 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
998 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
999 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1000 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1002 /* Setup HMAC Parameters */
1003 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1004 ut_params->auth_xform.next = &ut_params->cipher_xform;
1006 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1007 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1008 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1009 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1010 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1012 /* Create Crypto session*/
1014 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1015 &ut_params->auth_xform);
1016 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1018 /* Generate Crypto op data structure */
1019 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1020 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1021 TEST_ASSERT_NOT_NULL(ut_params->op,
1022 "Failed to allocate symmetric crypto operation struct");
1024 /* attach symmetric crypto session to crypto operations */
1025 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1027 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1029 /* set crypto operation source mbuf */
1030 sym_op->m_src = ut_params->ibuf;
1032 sym_op->auth.digest.data = ut_params->digest;
1033 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1034 ut_params->ibuf, QUOTE_512_BYTES);
1035 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1037 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1038 sym_op->auth.data.length = QUOTE_512_BYTES;
1040 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1041 CIPHER_IV_LENGTH_AES_CBC);
1042 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1043 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1045 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1046 CIPHER_IV_LENGTH_AES_CBC);
1048 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1049 sym_op->cipher.data.length = QUOTE_512_BYTES;
1052 /* Process crypto operation */
1053 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1054 ut_params->op), "failed to process sym crypto op");
1056 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1057 "crypto op processing failed");
1059 ut_params->obuf = ut_params->op->sym->m_src;
1063 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1064 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1065 CIPHER_IV_LENGTH_AES_CBC,
1068 "Ciphertext data not as expected");
1070 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1071 "Digest verification failed");
1074 return TEST_SUCCESS;
1078 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1080 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1082 static uint8_t hmac_sha256_key[] = {
1083 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1084 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1085 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1086 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1088 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1089 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1090 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1091 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1092 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1095 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1097 struct crypto_testsuite_params *ts_params = &testsuite_params;
1098 struct crypto_unittest_params *ut_params = &unittest_params;
1100 /* Generate test mbuf data and space for digest */
1101 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1102 catch_22_quote, QUOTE_512_BYTES, 0);
1104 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1105 DIGEST_BYTE_LENGTH_SHA256);
1106 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1108 /* Setup Cipher Parameters */
1109 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1110 ut_params->cipher_xform.next = &ut_params->auth_xform;
1112 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1113 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1114 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1115 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1117 /* Setup HMAC Parameters */
1118 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1119 ut_params->auth_xform.next = NULL;
1121 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1122 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1123 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1124 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1125 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1127 /* Create Crypto session*/
1128 ut_params->sess = rte_cryptodev_sym_session_create(
1129 ts_params->valid_devs[0],
1130 &ut_params->cipher_xform);
1131 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1133 /* Generate Crypto op data structure */
1134 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1135 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1136 TEST_ASSERT_NOT_NULL(ut_params->op,
1137 "Failed to allocate symmetric crypto operation struct");
1139 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1141 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1143 /* set crypto operation source mbuf */
1144 sym_op->m_src = ut_params->ibuf;
1146 sym_op->auth.digest.data = ut_params->digest;
1147 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1148 ut_params->ibuf, QUOTE_512_BYTES);
1149 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1151 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1152 sym_op->auth.data.length = QUOTE_512_BYTES;
1154 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1155 CIPHER_IV_LENGTH_AES_CBC);
1156 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1157 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1159 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1160 CIPHER_IV_LENGTH_AES_CBC);
1162 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1163 sym_op->cipher.data.length = QUOTE_512_BYTES;
1165 /* Process crypto operation */
1166 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1167 ut_params->op), "failed to process sym crypto op");
1169 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1170 "crypto op processing failed");
1172 ut_params->obuf = ut_params->op->sym->m_src;
1175 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1176 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1177 CIPHER_IV_LENGTH_AES_CBC,
1178 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1180 "Ciphertext data not as expected");
1182 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1183 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1184 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1185 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1186 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1187 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1188 DIGEST_BYTE_LENGTH_SHA256,
1189 "Generated digest data not as expected");
1192 return TEST_SUCCESS;
1196 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1198 struct crypto_testsuite_params *ts_params = &testsuite_params;
1199 struct crypto_unittest_params *ut_params = &unittest_params;
1201 /* Generate test mbuf data and digest */
1202 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1204 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1205 QUOTE_512_BYTES, 0);
1207 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1208 DIGEST_BYTE_LENGTH_SHA256);
1209 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1211 rte_memcpy(ut_params->digest,
1212 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1213 DIGEST_BYTE_LENGTH_SHA256);
1215 /* Setup Cipher Parameters */
1216 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1217 ut_params->cipher_xform.next = NULL;
1219 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1220 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1221 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1222 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1224 /* Setup HMAC Parameters */
1225 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1226 ut_params->auth_xform.next = &ut_params->cipher_xform;
1228 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1229 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1230 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1231 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1232 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1234 /* Create Crypto session*/
1236 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1237 &ut_params->auth_xform);
1238 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1240 /* Generate Crypto op data structure */
1241 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1242 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1243 TEST_ASSERT_NOT_NULL(ut_params->op,
1244 "Failed to allocate symmetric crypto operation struct");
1247 /* Set crypto operation data parameters */
1248 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1250 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1252 /* set crypto operation source mbuf */
1253 sym_op->m_src = ut_params->ibuf;
1255 sym_op->auth.digest.data = ut_params->digest;
1256 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1257 ut_params->ibuf, QUOTE_512_BYTES);
1258 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1260 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1261 sym_op->auth.data.length = QUOTE_512_BYTES;
1263 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1264 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1265 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1266 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1268 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1269 CIPHER_IV_LENGTH_AES_CBC);
1271 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1272 sym_op->cipher.data.length = QUOTE_512_BYTES;
1274 /* Process crypto operation */
1275 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1276 ut_params->op), "failed to process sym crypto op");
1278 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1279 "crypto op processing failed");
1281 ut_params->obuf = ut_params->op->sym->m_src;
1284 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1285 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1286 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1288 "Plaintext data not as expected");
1290 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1291 "Digest verification failed");
1293 return TEST_SUCCESS;
1296 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1298 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1300 static uint8_t hmac_sha512_key[] = {
1301 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1302 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1303 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1304 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1305 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1306 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1307 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1308 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1310 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1311 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1312 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1313 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1314 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1315 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1316 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1317 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1318 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1321 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1323 struct crypto_testsuite_params *ts_params = &testsuite_params;
1324 struct crypto_unittest_params *ut_params = &unittest_params;
1326 /* Generate test mbuf data and space for digest */
1327 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1328 catch_22_quote, QUOTE_512_BYTES, 0);
1330 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1331 DIGEST_BYTE_LENGTH_SHA512);
1332 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1334 /* Setup Cipher Parameters */
1335 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1336 ut_params->cipher_xform.next = &ut_params->auth_xform;
1338 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1339 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1340 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1341 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1343 /* Setup HMAC Parameters */
1344 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1345 ut_params->auth_xform.next = NULL;
1347 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1348 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1349 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1350 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1351 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1353 /* Create Crypto session*/
1355 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1356 &ut_params->cipher_xform);
1358 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1360 /* Generate Crypto op data structure */
1361 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1362 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1363 TEST_ASSERT_NOT_NULL(ut_params->op,
1364 "Failed to allocate symmetric crypto operation struct");
1366 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1368 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1370 /* set crypto operation source mbuf */
1371 sym_op->m_src = ut_params->ibuf;
1373 sym_op->auth.digest.data = ut_params->digest;
1374 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1375 ut_params->ibuf, QUOTE_512_BYTES);
1376 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1378 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1379 sym_op->auth.data.length = QUOTE_512_BYTES;
1381 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1382 CIPHER_IV_LENGTH_AES_CBC);
1383 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1384 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1386 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1387 CIPHER_IV_LENGTH_AES_CBC);
1389 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1390 sym_op->cipher.data.length = QUOTE_512_BYTES;
1392 /* Process crypto operation */
1393 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1394 ut_params->op), "failed to process sym crypto op");
1396 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1397 "crypto op processing failed");
1399 ut_params->obuf = ut_params->op->sym->m_src;
1402 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1403 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1404 CIPHER_IV_LENGTH_AES_CBC,
1405 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1407 "Ciphertext data not as expected");
1409 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1410 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1411 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1412 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1413 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1414 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1415 DIGEST_BYTE_LENGTH_SHA512,
1416 "Generated digest data not as expected");
1418 return TEST_SUCCESS;
1423 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1424 struct crypto_unittest_params *ut_params);
1427 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1428 struct crypto_unittest_params *ut_params,
1429 struct crypto_testsuite_params *ts_params);
1432 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1434 struct crypto_unittest_params *ut_params = &unittest_params;
1435 struct crypto_testsuite_params *ts_params = &testsuite_params;
1437 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1438 ut_params) == TEST_SUCCESS,
1439 "Failed to create session params");
1441 /* Create Crypto session*/
1443 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1444 &ut_params->auth_xform);
1445 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1447 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1448 ut_params, ts_params);
1452 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1453 struct crypto_unittest_params *ut_params)
1456 /* Setup Cipher Parameters */
1457 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1458 ut_params->cipher_xform.next = NULL;
1460 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1461 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1462 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1463 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1465 /* Setup HMAC Parameters */
1466 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1467 ut_params->auth_xform.next = &ut_params->cipher_xform;
1469 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1470 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1471 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1472 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1473 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1475 return TEST_SUCCESS;
1480 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1481 struct crypto_unittest_params *ut_params,
1482 struct crypto_testsuite_params *ts_params)
1484 /* Generate test mbuf data and digest */
1485 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1487 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1488 QUOTE_512_BYTES, 0);
1490 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1491 DIGEST_BYTE_LENGTH_SHA512);
1492 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1494 rte_memcpy(ut_params->digest,
1495 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1496 DIGEST_BYTE_LENGTH_SHA512);
1498 /* Generate Crypto op data structure */
1499 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1500 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1501 TEST_ASSERT_NOT_NULL(ut_params->op,
1502 "Failed to allocate symmetric crypto operation struct");
1504 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1506 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1508 /* set crypto operation source mbuf */
1509 sym_op->m_src = ut_params->ibuf;
1511 sym_op->auth.digest.data = ut_params->digest;
1512 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1513 ut_params->ibuf, QUOTE_512_BYTES);
1514 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1516 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1517 sym_op->auth.data.length = QUOTE_512_BYTES;
1519 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1520 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1521 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1522 ut_params->ibuf, 0);
1523 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1525 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1526 CIPHER_IV_LENGTH_AES_CBC);
1528 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1529 sym_op->cipher.data.length = QUOTE_512_BYTES;
1531 /* Process crypto operation */
1532 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1533 ut_params->op), "failed to process sym crypto op");
1535 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1536 "crypto op processing failed");
1538 ut_params->obuf = ut_params->op->sym->m_src;
1541 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1542 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1543 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1545 "Plaintext data not as expected");
1548 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1549 "Digest verification failed");
1551 return TEST_SUCCESS;
1554 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1556 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1557 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1558 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1561 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1562 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1563 0x77, 0x1D, 0x8B, 0x75
1567 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1569 struct crypto_testsuite_params *ts_params = &testsuite_params;
1570 struct crypto_unittest_params *ut_params = &unittest_params;
1572 /* Generate test mbuf data and space for digest */
1573 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1574 catch_22_quote, QUOTE_512_BYTES, 0);
1576 /* Setup Cipher Parameters */
1577 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1578 ut_params->cipher_xform.next = &ut_params->auth_xform;
1580 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1581 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1582 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1583 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1585 /* Setup HMAC Parameters */
1586 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1587 ut_params->auth_xform.next = NULL;
1589 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1590 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1591 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1592 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1593 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1595 /* Create Crypto session*/
1596 ut_params->sess = rte_cryptodev_sym_session_create(
1597 ts_params->valid_devs[0],
1598 &ut_params->cipher_xform);
1599 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1601 /* Generate Crypto op data structure */
1602 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1603 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1604 TEST_ASSERT_NOT_NULL(ut_params->op,
1605 "Failed to allocate symmetric crypto operation struct");
1607 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1609 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1611 /* set crypto operation source mbuf */
1612 sym_op->m_src = ut_params->ibuf;
1614 /* Set operation cipher parameters */
1615 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1616 sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
1617 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1618 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1620 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1621 CIPHER_IV_LENGTH_AES_CBC);
1623 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1624 sym_op->cipher.data.length = QUOTE_512_BYTES;
1626 /* Set operation authentication parameters */
1627 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1628 sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
1629 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1631 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
1632 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1634 memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
1636 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1637 sym_op->auth.data.length = QUOTE_512_BYTES;
1640 /* Process crypto operation */
1641 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1643 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
1645 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1646 "crypto op processing failed");
1649 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1650 rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1651 uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
1652 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1654 "Ciphertext data not as expected");
1656 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1657 rte_pktmbuf_mtod_offset(
1658 ut_params->op->sym->m_src, uint8_t *,
1659 CIPHER_IV_LENGTH_AES_CBC +
1661 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1662 DIGEST_BYTE_LENGTH_AES_XCBC,
1663 "Generated digest data not as expected");
1665 return TEST_SUCCESS;
1669 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1671 struct crypto_testsuite_params *ts_params = &testsuite_params;
1672 struct crypto_unittest_params *ut_params = &unittest_params;
1674 /* Generate test mbuf data and space for digest */
1675 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1676 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1677 QUOTE_512_BYTES, 0);
1679 /* Setup Cipher Parameters */
1680 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1681 ut_params->cipher_xform.next = NULL;
1683 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1684 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1685 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1686 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1688 /* Setup HMAC Parameters */
1689 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1690 ut_params->auth_xform.next = &ut_params->cipher_xform;
1692 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1693 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1694 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1695 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1696 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1698 /* Create Crypto session*/
1700 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1701 &ut_params->auth_xform);
1702 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1704 /* Generate Crypto op data structure */
1705 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1706 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1707 TEST_ASSERT_NOT_NULL(ut_params->op,
1708 "Failed to allocate symmetric crypto operation struct");
1710 /* Set crypto operation data parameters */
1711 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1713 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1715 /* set crypto operation source mbuf */
1716 sym_op->m_src = ut_params->ibuf;
1719 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1720 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
1721 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1722 "no room to append digest");
1724 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1725 ut_params->ibuf, QUOTE_512_BYTES);
1726 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1728 rte_memcpy(sym_op->auth.digest.data,
1729 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1730 DIGEST_BYTE_LENGTH_AES_XCBC);
1732 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1733 sym_op->auth.data.length = QUOTE_512_BYTES;
1735 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1736 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1737 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1738 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1740 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1741 CIPHER_IV_LENGTH_AES_CBC);
1743 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1744 sym_op->cipher.data.length = QUOTE_512_BYTES;
1746 /* Process crypto operation */
1747 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1748 ut_params->op), "failed to process sym crypto op");
1750 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1751 "crypto op processing failed");
1753 ut_params->obuf = ut_params->op->sym->m_src;
1756 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1757 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1758 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1760 "Ciphertext data not as expected");
1762 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1763 "Digest verification failed");
1765 return TEST_SUCCESS;
1768 /* ***** Snow3G Tests ***** */
1770 create_snow3g_hash_session(uint8_t dev_id,
1771 const uint8_t *key, const uint8_t key_len,
1772 const uint8_t aad_len, const uint8_t auth_len,
1773 enum rte_crypto_auth_operation op)
1775 uint8_t hash_key[key_len];
1777 struct crypto_unittest_params *ut_params = &unittest_params;
1779 memcpy(hash_key, key, key_len);
1780 #ifdef RTE_APP_TEST_DEBUG
1781 rte_hexdump(stdout, "key:", key, key_len);
1783 /* Setup Authentication Parameters */
1784 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1785 ut_params->auth_xform.next = NULL;
1787 ut_params->auth_xform.auth.op = op;
1788 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1789 ut_params->auth_xform.auth.key.length = key_len;
1790 ut_params->auth_xform.auth.key.data = hash_key;
1791 ut_params->auth_xform.auth.digest_length = auth_len;
1792 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1793 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1794 &ut_params->auth_xform);
1795 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1799 create_snow3g_cipher_session(uint8_t dev_id,
1800 enum rte_crypto_cipher_operation op,
1801 const uint8_t *key, const uint8_t key_len)
1803 uint8_t cipher_key[key_len];
1805 struct crypto_unittest_params *ut_params = &unittest_params;
1807 memcpy(cipher_key, key, key_len);
1809 /* Setup Cipher Parameters */
1810 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1811 ut_params->cipher_xform.next = NULL;
1813 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1814 ut_params->cipher_xform.cipher.op = op;
1815 ut_params->cipher_xform.cipher.key.data = cipher_key;
1816 ut_params->cipher_xform.cipher.key.length = key_len;
1818 #ifdef RTE_APP_TEST_DEBUG
1819 rte_hexdump(stdout, "key:", key, key_len);
1821 /* Create Crypto session */
1822 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1825 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1830 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1831 const unsigned data_len)
1833 struct crypto_testsuite_params *ts_params = &testsuite_params;
1834 struct crypto_unittest_params *ut_params = &unittest_params;
1835 unsigned iv_pad_len = 0;
1837 /* Generate Crypto op data structure */
1838 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1839 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1840 TEST_ASSERT_NOT_NULL(ut_params->op,
1841 "Failed to allocate pktmbuf offload");
1843 /* Set crypto operation data parameters */
1844 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1846 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1848 /* set crypto operation source mbuf */
1849 sym_op->m_src = ut_params->ibuf;
1852 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1853 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1856 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1858 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1859 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1860 sym_op->cipher.iv.length = iv_pad_len;
1862 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1863 sym_op->cipher.data.length = data_len;
1864 sym_op->cipher.data.offset = iv_pad_len;
1870 create_snow3g_cipher_auth_session(uint8_t dev_id,
1871 enum rte_crypto_cipher_operation cipher_op,
1872 enum rte_crypto_auth_operation auth_op,
1873 const uint8_t *key, const uint8_t key_len,
1874 const uint8_t aad_len, const uint8_t auth_len)
1876 uint8_t cipher_auth_key[key_len];
1878 struct crypto_unittest_params *ut_params = &unittest_params;
1880 memcpy(cipher_auth_key, key, key_len);
1882 /* Setup Authentication Parameters */
1883 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1884 ut_params->auth_xform.next = NULL;
1886 ut_params->auth_xform.auth.op = auth_op;
1887 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1888 ut_params->auth_xform.auth.key.length = key_len;
1889 /* Hash key = cipher key */
1890 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1891 ut_params->auth_xform.auth.digest_length = auth_len;
1892 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1894 /* Setup Cipher Parameters */
1895 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1896 ut_params->cipher_xform.next = &ut_params->auth_xform;
1898 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1899 ut_params->cipher_xform.cipher.op = cipher_op;
1900 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1901 ut_params->cipher_xform.cipher.key.length = key_len;
1903 #ifdef RTE_APP_TEST_DEBUG
1904 rte_hexdump(stdout, "key:", key, key_len);
1906 /* Create Crypto session*/
1907 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1908 &ut_params->cipher_xform);
1910 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1915 create_snow3g_auth_cipher_session(uint8_t dev_id,
1916 enum rte_crypto_cipher_operation cipher_op,
1917 enum rte_crypto_auth_operation auth_op,
1918 const uint8_t *key, const uint8_t key_len,
1919 const uint8_t aad_len, const uint8_t auth_len)
1921 uint8_t auth_cipher_key[key_len];
1923 struct crypto_unittest_params *ut_params = &unittest_params;
1925 memcpy(auth_cipher_key, key, key_len);
1927 /* Setup Authentication Parameters */
1928 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1929 ut_params->auth_xform.auth.op = auth_op;
1930 ut_params->auth_xform.next = &ut_params->cipher_xform;
1931 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1932 ut_params->auth_xform.auth.key.length = key_len;
1933 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1934 ut_params->auth_xform.auth.digest_length = auth_len;
1935 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1937 /* Setup Cipher Parameters */
1938 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1939 ut_params->cipher_xform.next = NULL;
1940 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1941 ut_params->cipher_xform.cipher.op = cipher_op;
1942 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1943 ut_params->cipher_xform.cipher.key.length = key_len;
1945 #ifdef RTE_APP_TEST_DEBUG
1946 rte_hexdump(stdout, "key:", key, key_len);
1948 /* Create Crypto session*/
1949 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1950 &ut_params->auth_xform);
1952 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1958 create_snow3g_hash_operation(const uint8_t *auth_tag,
1959 const unsigned auth_tag_len,
1960 const uint8_t *aad, const unsigned aad_len,
1961 const unsigned data_len, unsigned data_pad_len,
1962 enum rte_crypto_auth_operation op)
1964 struct crypto_testsuite_params *ts_params = &testsuite_params;
1966 struct crypto_unittest_params *ut_params = &unittest_params;
1968 unsigned aad_buffer_len;
1970 /* Generate Crypto op data structure */
1971 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1972 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1973 TEST_ASSERT_NOT_NULL(ut_params->op,
1974 "Failed to allocate pktmbuf offload");
1976 /* Set crypto operation data parameters */
1977 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1979 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1981 /* set crypto operation source mbuf */
1982 sym_op->m_src = ut_params->ibuf;
1986 * Always allocate the aad up to the block size.
1987 * The cryptodev API calls out -
1988 * - the array must be big enough to hold the AAD, plus any
1989 * space to round this up to the nearest multiple of the
1990 * block size (16 bytes).
1992 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1993 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1994 ut_params->ibuf, aad_buffer_len);
1995 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1996 "no room to prepend aad");
1997 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1999 sym_op->auth.aad.length = aad_len;
2001 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2002 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2004 #ifdef RTE_APP_TEST_DEBUG
2005 rte_hexdump(stdout, "aad:",
2006 sym_op->auth.aad.data, aad_len);
2010 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2011 ut_params->ibuf, auth_tag_len);
2013 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2014 "no room to append auth tag");
2015 ut_params->digest = sym_op->auth.digest.data;
2016 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2017 ut_params->ibuf, data_pad_len + aad_len);
2018 sym_op->auth.digest.length = auth_tag_len;
2019 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2020 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2022 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2024 #ifdef RTE_APP_TEST_DEBUG
2025 rte_hexdump(stdout, "digest:",
2026 sym_op->auth.digest.data,
2027 sym_op->auth.digest.length);
2030 sym_op->auth.data.length = data_len;
2031 sym_op->auth.data.offset = aad_buffer_len;
2037 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2038 const unsigned auth_tag_len,
2039 const uint8_t *aad, const unsigned aad_len,
2040 const unsigned data_len, unsigned data_pad_len,
2041 enum rte_crypto_auth_operation op,
2042 const uint8_t *iv, const unsigned iv_len)
2044 struct crypto_testsuite_params *ts_params = &testsuite_params;
2045 struct crypto_unittest_params *ut_params = &unittest_params;
2047 unsigned iv_pad_len = 0;
2048 unsigned aad_buffer_len;
2050 /* Generate Crypto op data structure */
2051 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2052 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2053 TEST_ASSERT_NOT_NULL(ut_params->op,
2054 "Failed to allocate pktmbuf offload");
2055 /* Set crypto operation data parameters */
2056 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2058 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2060 /* set crypto operation source mbuf */
2061 sym_op->m_src = ut_params->ibuf;
2065 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2067 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2068 ut_params->ibuf, iv_pad_len);
2069 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2071 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2072 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2073 sym_op->cipher.iv.length = iv_pad_len;
2075 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2077 sym_op->cipher.data.length = data_len;
2078 sym_op->cipher.data.offset = iv_pad_len;
2082 * Always allocate the aad up to the block size.
2083 * The cryptodev API calls out -
2084 * - the array must be big enough to hold the AAD, plus any
2085 * space to round this up to the nearest multiple of the
2086 * block size (16 bytes).
2088 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2090 sym_op->auth.aad.data =
2091 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2092 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2093 "no room to prepend aad");
2094 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2096 sym_op->auth.aad.length = aad_len;
2098 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2099 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2101 #ifdef RTE_APP_TEST_DEBUG
2102 rte_hexdump(stdout, "aad:",
2103 sym_op->auth.aad.data, aad_len);
2107 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2108 ut_params->ibuf, auth_tag_len);
2110 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2111 "no room to append auth tag");
2112 ut_params->digest = sym_op->auth.digest.data;
2113 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2114 ut_params->ibuf, data_pad_len + aad_len);
2115 sym_op->auth.digest.length = auth_tag_len;
2116 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2117 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2119 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2121 #ifdef RTE_APP_TEST_DEBUG
2122 rte_hexdump(stdout, "digest:",
2123 sym_op->auth.digest.data,
2124 sym_op->auth.digest.length);
2127 sym_op->auth.data.length = data_len;
2128 sym_op->auth.data.offset = aad_buffer_len;
2134 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2135 const uint8_t *iv, const unsigned iv_len,
2136 const uint8_t *aad, const unsigned aad_len,
2137 const unsigned data_len, unsigned data_pad_len)
2139 struct crypto_testsuite_params *ts_params = &testsuite_params;
2140 struct crypto_unittest_params *ut_params = &unittest_params;
2142 unsigned iv_pad_len = 0;
2143 unsigned aad_buffer_len = 0;
2145 /* Generate Crypto op data structure */
2146 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2147 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2148 TEST_ASSERT_NOT_NULL(ut_params->op,
2149 "Failed to allocate pktmbuf offload");
2151 /* Set crypto operation data parameters */
2152 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2154 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2156 /* set crypto operation source mbuf */
2157 sym_op->m_src = ut_params->ibuf;
2160 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2161 ut_params->ibuf, auth_tag_len);
2163 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2164 "no room to append auth tag");
2166 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2167 ut_params->ibuf, data_pad_len);
2168 sym_op->auth.digest.length = auth_tag_len;
2170 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2172 #ifdef RTE_APP_TEST_DEBUG
2173 rte_hexdump(stdout, "digest:",
2174 sym_op->auth.digest.data,
2175 sym_op->auth.digest.length);
2178 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2180 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2181 ut_params->ibuf, iv_pad_len);
2182 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2184 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2185 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2186 sym_op->cipher.iv.length = iv_pad_len;
2188 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2192 * Always allocate the aad up to the block size.
2193 * The cryptodev API calls out -
2194 * - the array must be big enough to hold the AAD, plus any
2195 * space to round this up to the nearest multiple of the
2196 * block size (16 bytes).
2198 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2200 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2201 ut_params->ibuf, aad_buffer_len);
2202 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2203 "no room to prepend aad");
2204 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2206 sym_op->auth.aad.length = aad_len;
2208 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2209 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2211 #ifdef RTE_APP_TEST_DEBUG
2212 rte_hexdump(stdout, "aad:",
2213 sym_op->auth.aad.data, aad_len);
2216 sym_op->cipher.data.length = data_len;
2217 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2219 sym_op->auth.data.length = data_len;
2220 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2226 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2228 struct crypto_testsuite_params *ts_params = &testsuite_params;
2229 struct crypto_unittest_params *ut_params = &unittest_params;
2232 unsigned plaintext_pad_len;
2235 /* Create SNOW3G session */
2236 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2237 tdata->key.data, tdata->key.len,
2238 tdata->aad.len, tdata->digest.len,
2239 RTE_CRYPTO_AUTH_OP_GENERATE);
2243 /* alloc mbuf and set payload */
2244 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2246 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2247 rte_pktmbuf_tailroom(ut_params->ibuf));
2249 /* Append data which is padded to a multiple of */
2250 /* the algorithms block size */
2251 plaintext_pad_len = tdata->plaintext.len;
2252 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2254 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2256 /* Create SNOW3G opertaion */
2257 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2258 tdata->aad.data, tdata->aad.len, tdata->plaintext.len,
2259 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE);
2263 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2265 ut_params->obuf = ut_params->op->sym->m_src;
2266 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2267 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2268 + plaintext_pad_len + tdata->aad.len;
2271 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2274 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2275 "Snow3G Generated auth tag not as expected");
2281 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2283 struct crypto_testsuite_params *ts_params = &testsuite_params;
2284 struct crypto_unittest_params *ut_params = &unittest_params;
2287 unsigned plaintext_pad_len;
2290 /* Create SNOW3G session */
2291 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2292 tdata->key.data, tdata->key.len,
2293 tdata->aad.len, tdata->digest.len,
2294 RTE_CRYPTO_AUTH_OP_VERIFY);
2297 /* alloc mbuf and set payload */
2298 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2300 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2301 rte_pktmbuf_tailroom(ut_params->ibuf));
2303 /* Append data which is padded to a multiple */
2304 /* of the algorithms block size */
2305 plaintext_pad_len = tdata->plaintext.len;
2306 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2308 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2310 /* Create SNOW3G operation */
2311 retval = create_snow3g_hash_operation(tdata->digest.data,
2313 tdata->aad.data, tdata->aad.len,
2314 tdata->plaintext.len, plaintext_pad_len,
2315 RTE_CRYPTO_AUTH_OP_VERIFY);
2319 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2321 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2322 ut_params->obuf = ut_params->op->sym->m_src;
2323 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2324 + plaintext_pad_len + tdata->aad.len;
2327 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2337 test_snow3g_hash_generate_test_case_1(void)
2339 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2343 test_snow3g_hash_generate_test_case_2(void)
2345 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2349 test_snow3g_hash_generate_test_case_3(void)
2351 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2355 test_snow3g_hash_verify_test_case_1(void)
2357 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2362 test_snow3g_hash_verify_test_case_2(void)
2364 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2368 test_snow3g_hash_verify_test_case_3(void)
2370 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2374 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2376 struct crypto_testsuite_params *ts_params = &testsuite_params;
2377 struct crypto_unittest_params *ut_params = &unittest_params;
2381 uint8_t *plaintext, *ciphertext;
2382 uint8_t plaintext_pad_len;
2383 uint8_t lastByteValidBits = 8;
2384 uint8_t lastByteMask = 0xFF;
2386 /* Create SNOW3G session */
2387 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2388 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2389 tdata->key.data, tdata->key.len);
2393 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2395 /* Clear mbuf payload */
2396 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2397 rte_pktmbuf_tailroom(ut_params->ibuf));
2400 * Append data which is padded to a
2401 * multiple of the algorithms block size
2403 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2405 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2407 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2409 #ifdef RTE_APP_TEST_DEBUG
2410 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2412 /* Create SNOW3G operation */
2413 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2414 tdata->plaintext.len);
2418 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2420 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2422 ut_params->obuf = ut_params->op->sym->m_src;
2423 if (ut_params->obuf)
2424 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2427 ciphertext = plaintext;
2429 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2430 if (lastByteValidBits == 0)
2431 lastByteValidBits = 8;
2432 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2433 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2435 #ifdef RTE_APP_TEST_DEBUG
2436 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2439 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2441 tdata->ciphertext.data,
2442 tdata->ciphertext.len,
2443 "Snow3G Ciphertext data not as expected");
2447 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2449 struct crypto_testsuite_params *ts_params = &testsuite_params;
2450 struct crypto_unittest_params *ut_params = &unittest_params;
2454 uint8_t *plaintext, *ciphertext;
2455 uint8_t ciphertext_pad_len;
2456 uint8_t lastByteValidBits = 8;
2457 uint8_t lastByteMask = 0xFF;
2459 /* Create SNOW3G session */
2460 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2461 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2462 tdata->key.data, tdata->key.len);
2466 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2468 /* Clear mbuf payload */
2469 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2470 rte_pktmbuf_tailroom(ut_params->ibuf));
2473 * Append data which is padded to a
2474 * multiple of the algorithms block size
2476 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2478 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2479 ciphertext_pad_len);
2480 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2482 #ifdef RTE_APP_TEST_DEBUG
2483 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2485 /* Create SNOW3G operation */
2486 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2487 tdata->ciphertext.len);
2491 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2493 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2494 ut_params->obuf = ut_params->op->sym->m_src;
2495 if (ut_params->obuf)
2496 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2499 plaintext = ciphertext;
2500 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2501 if (lastByteValidBits == 0)
2502 lastByteValidBits = 8;
2503 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2504 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2506 #ifdef RTE_APP_TEST_DEBUG
2507 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2510 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2511 tdata->plaintext.data,
2512 tdata->plaintext.len,
2513 "Snow3G Plaintext data not as expected");
2518 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2520 struct crypto_testsuite_params *ts_params = &testsuite_params;
2521 struct crypto_unittest_params *ut_params = &unittest_params;
2525 uint8_t *plaintext, *ciphertext;
2526 uint8_t plaintext_pad_len;
2527 uint8_t lastByteValidBits = 8;
2528 uint8_t lastByteMask = 0xFF;
2530 /* Create SNOW3G session */
2531 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2532 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2533 RTE_CRYPTO_AUTH_OP_GENERATE,
2534 tdata->key.data, tdata->key.len,
2535 tdata->aad.len, tdata->digest.len);
2538 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2540 /* clear mbuf payload */
2541 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2542 rte_pktmbuf_tailroom(ut_params->ibuf));
2544 /* Append data which is padded to a multiple */
2545 /* of the algorithms block size */
2546 plaintext_pad_len = tdata->plaintext.len;
2548 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2550 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2552 #ifdef RTE_APP_TEST_DEBUG
2553 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2556 /* Create SNOW3G operation */
2557 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2558 tdata->digest.len, tdata->aad.data,
2559 tdata->aad.len, tdata->plaintext.len,
2560 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2561 tdata->iv.data, tdata->iv.len);
2565 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2567 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2568 ut_params->obuf = ut_params->op->sym->m_src;
2569 if (ut_params->obuf)
2570 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2573 ciphertext = plaintext;
2574 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2575 if (lastByteValidBits == 0)
2576 lastByteValidBits = 8;
2577 lastByteMask = lastByteMask << (8-lastByteValidBits);
2578 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2580 #ifdef RTE_APP_TEST_DEBUG
2581 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2584 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2586 tdata->ciphertext.data,
2587 tdata->ciphertext.len,
2588 "Snow3G Ciphertext data not as expected");
2590 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2591 + plaintext_pad_len + tdata->aad.len;
2594 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2597 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2598 "Snow3G Generated auth tag not as expected");
2602 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2604 struct crypto_testsuite_params *ts_params = &testsuite_params;
2605 struct crypto_unittest_params *ut_params = &unittest_params;
2609 uint8_t *plaintext, *ciphertext;
2610 uint8_t plaintext_pad_len;
2611 uint8_t lastByteValidBits = 8;
2612 uint8_t lastByteMask = 0xFF;
2614 /* Create SNOW3G session */
2615 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2616 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2617 RTE_CRYPTO_AUTH_OP_GENERATE,
2618 tdata->key.data, tdata->key.len,
2619 tdata->aad.len, tdata->digest.len);
2623 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2625 /* clear mbuf payload */
2626 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2627 rte_pktmbuf_tailroom(ut_params->ibuf));
2629 /* Append data which is padded to a multiple */
2630 /* of the algorithms block size */
2631 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 8);
2633 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2635 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2637 #ifdef RTE_APP_TEST_DEBUG
2638 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2641 /* Create SNOW3G operation */
2642 retval = create_snow3g_auth_cipher_operation(
2644 tdata->iv.data, tdata->iv.len,
2645 tdata->aad.data, tdata->aad.len,
2646 tdata->plaintext.len, plaintext_pad_len
2652 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2654 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2655 ut_params->obuf = ut_params->op->sym->m_src;
2656 if (ut_params->obuf)
2657 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2658 + tdata->aad.len + tdata->iv.len;
2660 ciphertext = plaintext;
2662 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2663 if (lastByteValidBits == 0)
2664 lastByteValidBits = 8;
2665 lastByteMask = lastByteMask << (8-lastByteValidBits);
2666 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2667 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2668 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2670 #ifdef RTE_APP_TEST_DEBUG
2671 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2674 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2676 tdata->ciphertext.data,
2677 tdata->ciphertext.len,
2678 "Snow3G Ciphertext data not as expected");
2681 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2684 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2685 "Snow3G Generated auth tag not as expected");
2690 test_snow3g_encryption_test_case_1(void)
2692 return test_snow3g_encryption(&snow3g_test_case_1);
2696 test_snow3g_encryption_test_case_2(void)
2698 return test_snow3g_encryption(&snow3g_test_case_2);
2702 test_snow3g_encryption_test_case_3(void)
2704 return test_snow3g_encryption(&snow3g_test_case_3);
2708 test_snow3g_encryption_test_case_4(void)
2710 return test_snow3g_encryption(&snow3g_test_case_4);
2714 test_snow3g_encryption_test_case_5(void)
2716 return test_snow3g_encryption(&snow3g_test_case_5);
2720 test_snow3g_decryption_test_case_1(void)
2722 return test_snow3g_decryption(&snow3g_test_case_1);
2726 test_snow3g_decryption_test_case_2(void)
2728 return test_snow3g_decryption(&snow3g_test_case_2);
2732 test_snow3g_decryption_test_case_3(void)
2734 return test_snow3g_decryption(&snow3g_test_case_3);
2738 test_snow3g_decryption_test_case_4(void)
2740 return test_snow3g_decryption(&snow3g_test_case_4);
2744 test_snow3g_decryption_test_case_5(void)
2746 return test_snow3g_decryption(&snow3g_test_case_5);
2749 test_snow3g_authenticated_encryption_test_case_1(void)
2751 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2755 test_snow3g_encrypted_authentication_test_case_1(void)
2757 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2760 /* ***** AES-GCM Tests ***** */
2765 struct crypto_testsuite_params *ts_params = &testsuite_params;
2766 struct rte_cryptodev_stats stats;
2767 struct rte_cryptodev *dev;
2768 cryptodev_stats_get_t temp_pfn;
2770 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2771 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2772 &stats) == -ENODEV),
2773 "rte_cryptodev_stats_get invalid dev failed");
2774 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2775 "rte_cryptodev_stats_get invalid Param failed");
2776 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2777 temp_pfn = dev->dev_ops->stats_get;
2778 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2779 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2781 "rte_cryptodev_stats_get invalid Param failed");
2782 dev->dev_ops->stats_get = temp_pfn;
2784 /* Test expected values */
2786 test_AES_CBC_HMAC_SHA1_encrypt_digest();
2788 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2790 "rte_cryptodev_stats_get failed");
2791 TEST_ASSERT((stats.enqueued_count == 1),
2792 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2793 TEST_ASSERT((stats.dequeued_count == 1),
2794 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2795 TEST_ASSERT((stats.enqueue_err_count == 0),
2796 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2797 TEST_ASSERT((stats.dequeue_err_count == 0),
2798 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2800 /* invalid device but should ignore and not reset device stats*/
2801 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2802 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2804 "rte_cryptodev_stats_get failed");
2805 TEST_ASSERT((stats.enqueued_count == 1),
2806 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2808 /* check that a valid reset clears stats */
2809 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2810 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2812 "rte_cryptodev_stats_get failed");
2813 TEST_ASSERT((stats.enqueued_count == 0),
2814 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2815 TEST_ASSERT((stats.dequeued_count == 0),
2816 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2818 return TEST_SUCCESS;
2823 test_multi_session(void)
2825 struct crypto_testsuite_params *ts_params = &testsuite_params;
2826 struct crypto_unittest_params *ut_params = &unittest_params;
2828 struct rte_cryptodev_info dev_info;
2829 struct rte_cryptodev_sym_session **sessions;
2833 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2836 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2838 sessions = rte_malloc(NULL,
2839 (sizeof(struct rte_cryptodev_sym_session *) *
2840 dev_info.sym.max_nb_sessions) + 1, 0);
2842 /* Create multiple crypto sessions*/
2843 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2844 sessions[i] = rte_cryptodev_sym_session_create(
2845 ts_params->valid_devs[0],
2846 &ut_params->auth_xform);
2847 TEST_ASSERT_NOT_NULL(sessions[i],
2848 "Session creation failed at session number %u",
2851 /* Attempt to send a request on each session */
2852 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2853 sessions[i], ut_params, ts_params),
2854 "Failed to perform decrypt on request "
2856 /* free crypto operation structure */
2858 rte_crypto_op_free(ut_params->op);
2861 * free mbuf - both obuf and ibuf are usually the same,
2862 * but rte copes even if we call free twice
2864 if (ut_params->obuf) {
2865 rte_pktmbuf_free(ut_params->obuf);
2866 ut_params->obuf = 0;
2870 /* Next session create should fail */
2871 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2872 &ut_params->auth_xform);
2873 TEST_ASSERT_NULL(sessions[i],
2874 "Session creation succeeded unexpectedly!");
2876 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2877 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2882 return TEST_SUCCESS;
2886 test_not_in_place_crypto(void)
2888 struct crypto_testsuite_params *ts_params = &testsuite_params;
2889 struct crypto_unittest_params *ut_params = &unittest_params;
2890 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2892 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2894 /* Create multiple crypto sessions*/
2896 ut_params->sess = rte_cryptodev_sym_session_create(
2897 ts_params->valid_devs[0], &ut_params->auth_xform);
2899 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2902 /* Generate test mbuf data and digest */
2903 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2905 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2906 QUOTE_512_BYTES, 0);
2908 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2909 DIGEST_BYTE_LENGTH_SHA512);
2910 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2912 rte_memcpy(ut_params->digest,
2913 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
2914 DIGEST_BYTE_LENGTH_SHA512);
2916 /* Generate Crypto op data structure */
2917 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2918 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2919 TEST_ASSERT_NOT_NULL(ut_params->op,
2920 "Failed to allocate symmetric crypto operation struct");
2923 /* Set crypto operation data parameters */
2924 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2926 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2928 /* set crypto operation source mbuf */
2929 sym_op->m_src = ut_params->ibuf;
2930 sym_op->m_dst = dst_m;
2932 sym_op->auth.digest.data = ut_params->digest;
2933 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2934 ut_params->ibuf, QUOTE_512_BYTES);
2935 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
2937 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2938 sym_op->auth.data.length = QUOTE_512_BYTES;
2941 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2942 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2943 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
2944 ut_params->ibuf, 0);
2945 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2947 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2948 CIPHER_IV_LENGTH_AES_CBC);
2950 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2951 sym_op->cipher.data.length = QUOTE_512_BYTES;
2953 /* Process crypto operation */
2954 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2956 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2958 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2959 "crypto operation processing failed");
2962 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2963 rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
2966 "Plaintext data not as expected");
2970 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2971 "Digest verification failed");
2973 return TEST_SUCCESS;
2977 static struct unit_test_suite cryptodev_qat_testsuite = {
2978 .suite_name = "Crypto QAT Unit Test Suite",
2979 .setup = testsuite_setup,
2980 .teardown = testsuite_teardown,
2981 .unit_test_cases = {
2982 TEST_CASE_ST(ut_setup, ut_teardown,
2983 test_device_configure_invalid_dev_id),
2984 TEST_CASE_ST(ut_setup, ut_teardown,
2985 test_device_configure_invalid_queue_pair_ids),
2986 TEST_CASE_ST(ut_setup, ut_teardown,
2987 test_queue_pair_descriptor_setup),
2988 TEST_CASE_ST(ut_setup, ut_teardown,
2989 test_multi_session),
2991 TEST_CASE_ST(ut_setup, ut_teardown,
2992 test_AES_CBC_HMAC_SHA1_encrypt_digest),
2993 TEST_CASE_ST(ut_setup, ut_teardown,
2994 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
2996 TEST_CASE_ST(ut_setup, ut_teardown,
2997 test_AES_CBC_HMAC_SHA256_encrypt_digest),
2998 TEST_CASE_ST(ut_setup, ut_teardown,
2999 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3001 TEST_CASE_ST(ut_setup, ut_teardown,
3002 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3003 TEST_CASE_ST(ut_setup, ut_teardown,
3004 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3006 TEST_CASE_ST(ut_setup, ut_teardown,
3007 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3008 TEST_CASE_ST(ut_setup, ut_teardown,
3009 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3010 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
3011 /** Snow3G encrypt only (UEA2) */
3012 TEST_CASE_ST(ut_setup, ut_teardown,
3013 test_snow3g_encryption_test_case_1),
3014 TEST_CASE_ST(ut_setup, ut_teardown,
3015 test_snow3g_encryption_test_case_2),
3016 TEST_CASE_ST(ut_setup, ut_teardown,
3017 test_snow3g_encryption_test_case_3),
3018 TEST_CASE_ST(ut_setup, ut_teardown,
3019 test_snow3g_encryption_test_case_4),
3020 TEST_CASE_ST(ut_setup, ut_teardown,
3021 test_snow3g_encryption_test_case_5),
3024 /** Snow3G decrypt only (UEA2) */
3025 TEST_CASE_ST(ut_setup, ut_teardown,
3026 test_snow3g_decryption_test_case_1),
3027 TEST_CASE_ST(ut_setup, ut_teardown,
3028 test_snow3g_decryption_test_case_2),
3029 TEST_CASE_ST(ut_setup, ut_teardown,
3030 test_snow3g_decryption_test_case_3),
3031 TEST_CASE_ST(ut_setup, ut_teardown,
3032 test_snow3g_decryption_test_case_4),
3033 TEST_CASE_ST(ut_setup, ut_teardown,
3034 test_snow3g_decryption_test_case_5),
3035 TEST_CASE_ST(ut_setup, ut_teardown,
3036 test_snow3g_hash_generate_test_case_1),
3037 TEST_CASE_ST(ut_setup, ut_teardown,
3038 test_snow3g_hash_generate_test_case_2),
3039 TEST_CASE_ST(ut_setup, ut_teardown,
3040 test_snow3g_hash_generate_test_case_3),
3041 TEST_CASE_ST(ut_setup, ut_teardown,
3042 test_snow3g_hash_verify_test_case_1),
3043 TEST_CASE_ST(ut_setup, ut_teardown,
3044 test_snow3g_hash_verify_test_case_2),
3045 TEST_CASE_ST(ut_setup, ut_teardown,
3046 test_snow3g_hash_verify_test_case_3),
3047 TEST_CASE_ST(ut_setup, ut_teardown,
3048 test_snow3g_authenticated_encryption_test_case_1),
3049 TEST_CASE_ST(ut_setup, ut_teardown,
3050 test_snow3g_encrypted_authentication_test_case_1),
3051 TEST_CASES_END() /**< NULL terminate unit test array */
3055 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3056 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3057 .setup = testsuite_setup,
3058 .teardown = testsuite_teardown,
3059 .unit_test_cases = {
3060 TEST_CASE_ST(ut_setup, ut_teardown,
3061 test_AES_CBC_HMAC_SHA1_encrypt_digest),
3062 TEST_CASE_ST(ut_setup, ut_teardown,
3063 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
3065 TEST_CASE_ST(ut_setup, ut_teardown,
3066 test_AES_CBC_HMAC_SHA256_encrypt_digest),
3067 TEST_CASE_ST(ut_setup, ut_teardown,
3068 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3070 TEST_CASE_ST(ut_setup, ut_teardown,
3071 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3072 TEST_CASE_ST(ut_setup, ut_teardown,
3073 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3075 TEST_CASE_ST(ut_setup, ut_teardown,
3076 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3077 TEST_CASE_ST(ut_setup, ut_teardown,
3078 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3080 TEST_CASE_ST(ut_setup, ut_teardown,
3081 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
3083 TEST_CASE_ST(ut_setup, ut_teardown,
3084 test_not_in_place_crypto),
3086 TEST_CASES_END() /**< NULL terminate unit test array */
3090 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
3091 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
3092 .setup = testsuite_setup,
3093 .teardown = testsuite_teardown,
3094 .unit_test_cases = {
3095 /** Snow3G encrypt only (UEA2) */
3096 TEST_CASE_ST(ut_setup, ut_teardown,
3097 test_snow3g_encryption_test_case_1),
3098 TEST_CASE_ST(ut_setup, ut_teardown,
3099 test_snow3g_encryption_test_case_2),
3100 TEST_CASE_ST(ut_setup, ut_teardown,
3101 test_snow3g_encryption_test_case_3),
3102 TEST_CASE_ST(ut_setup, ut_teardown,
3103 test_snow3g_encryption_test_case_4),
3104 TEST_CASE_ST(ut_setup, ut_teardown,
3105 test_snow3g_encryption_test_case_5),
3108 /** Snow3G decrypt only (UEA2) */
3109 TEST_CASE_ST(ut_setup, ut_teardown,
3110 test_snow3g_decryption_test_case_1),
3111 TEST_CASE_ST(ut_setup, ut_teardown,
3112 test_snow3g_decryption_test_case_2),
3113 TEST_CASE_ST(ut_setup, ut_teardown,
3114 test_snow3g_decryption_test_case_3),
3115 TEST_CASE_ST(ut_setup, ut_teardown,
3116 test_snow3g_decryption_test_case_4),
3117 TEST_CASE_ST(ut_setup, ut_teardown,
3118 test_snow3g_decryption_test_case_5),
3119 TEST_CASE_ST(ut_setup, ut_teardown,
3120 test_snow3g_hash_generate_test_case_1),
3121 TEST_CASE_ST(ut_setup, ut_teardown,
3122 test_snow3g_hash_generate_test_case_2),
3123 TEST_CASE_ST(ut_setup, ut_teardown,
3124 test_snow3g_hash_generate_test_case_3),
3125 TEST_CASE_ST(ut_setup, ut_teardown,
3126 test_snow3g_hash_verify_test_case_1),
3127 TEST_CASE_ST(ut_setup, ut_teardown,
3128 test_snow3g_hash_verify_test_case_2),
3129 TEST_CASE_ST(ut_setup, ut_teardown,
3130 test_snow3g_hash_verify_test_case_3),
3131 TEST_CASE_ST(ut_setup, ut_teardown,
3132 test_snow3g_authenticated_encryption_test_case_1),
3133 TEST_CASE_ST(ut_setup, ut_teardown,
3134 test_snow3g_encrypted_authentication_test_case_1),
3136 TEST_CASES_END() /**< NULL terminate unit test array */
3141 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3143 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3144 return unit_test_suite_runner(&cryptodev_qat_testsuite);
3146 static struct test_command cryptodev_qat_cmd = {
3147 .command = "cryptodev_qat_autotest",
3148 .callback = test_cryptodev_qat,
3152 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3154 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3156 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3159 static struct test_command cryptodev_aesni_mb_cmd = {
3160 .command = "cryptodev_aesni_mb_autotest",
3161 .callback = test_cryptodev_aesni_mb,
3165 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
3167 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
3169 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
3172 static struct test_command cryptodev_sw_snow3g_cmd = {
3173 .command = "cryptodev_sw_snow3g_autotest",
3174 .callback = test_cryptodev_sw_snow3g,
3177 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3178 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
3179 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);