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>
38 #include <rte_mbuf_offload.h>
40 #include <rte_crypto.h>
41 #include <rte_cryptodev.h>
42 #include <rte_cryptodev_pmd.h>
45 #include "test_cryptodev.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 *mbuf_ol_pool;
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_mbuf_offload *ol;
66 struct rte_crypto_sym_op *op;
68 struct rte_mbuf *obuf, *ibuf;
74 * Forward declarations.
77 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
78 struct crypto_unittest_params *ut_params);
81 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
82 struct crypto_unittest_params *ut_params,
83 struct crypto_testsuite_params *ts_param);
85 static struct rte_mbuf *
86 setup_test_string(struct rte_mempool *mpool,
87 const char *string, size_t len, uint8_t blocksize)
89 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
90 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
92 memset(m->buf_addr, 0, m->buf_len);
94 char *dst = rte_pktmbuf_append(m, t_len);
101 rte_memcpy(dst, string, t_len);
109 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
111 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
115 static struct rte_mbuf *
116 process_crypto_request(uint8_t dev_id, struct rte_mbuf *ibuf)
118 struct rte_mbuf *obuf = NULL;
120 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
123 if (rte_cryptodev_enqueue_burst(dev_id, 0, &ibuf, 1) != 1) {
124 printf("Error sending packet for encryption");
127 while (rte_cryptodev_dequeue_burst(dev_id, 0, &obuf, 1) == 0)
132 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
138 static struct crypto_testsuite_params testsuite_params = { NULL };
139 static struct crypto_unittest_params unittest_params;
142 testsuite_setup(void)
144 struct crypto_testsuite_params *ts_params = &testsuite_params;
145 struct rte_cryptodev_info info;
146 unsigned i, nb_devs, dev_id;
150 memset(ts_params, 0, sizeof(*ts_params));
152 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
153 if (ts_params->mbuf_pool == NULL) {
154 /* Not already created so create */
155 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
157 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
159 if (ts_params->mbuf_pool == NULL) {
160 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
165 ts_params->mbuf_ol_pool = rte_pktmbuf_offload_pool_create(
167 NUM_MBUFS, MBUF_CACHE_SIZE,
169 sizeof(struct rte_crypto_sym_xform),
171 if (ts_params->mbuf_ol_pool == NULL) {
172 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
176 /* Create 2 AESNI MB devices if required */
177 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
178 nb_devs = rte_cryptodev_count_devtype(
179 RTE_CRYPTODEV_AESNI_MB_PMD);
181 for (i = nb_devs; i < 2; i++) {
182 ret = rte_eal_vdev_init(
183 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
185 TEST_ASSERT(ret == 0,
186 "Failed to create instance %u of"
188 i, CRYPTODEV_NAME_AESNI_MB_PMD);
193 nb_devs = rte_cryptodev_count();
195 RTE_LOG(ERR, USER1, "No crypto devices found?");
199 /* Create list of valid crypto devs */
200 for (i = 0; i < nb_devs; i++) {
201 rte_cryptodev_info_get(i, &info);
202 if (info.dev_type == gbl_cryptodev_type)
203 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
206 if (ts_params->valid_dev_count < 1)
209 /* Set up all the qps on the first of the valid devices found */
210 for (i = 0; i < 1; i++) {
211 dev_id = ts_params->valid_devs[i];
213 rte_cryptodev_info_get(dev_id, &info);
216 * Since we can't free and re-allocate queue memory always set
217 * the queues on this device up to max size first so enough
218 * memory is allocated for any later re-configures needed by
222 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
223 ts_params->conf.socket_id = SOCKET_ID_ANY;
224 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
226 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
228 "Failed to configure cryptodev %u with %u qps",
229 dev_id, ts_params->conf.nb_queue_pairs);
231 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
233 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
234 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
235 dev_id, qp_id, &ts_params->qp_conf,
236 rte_cryptodev_socket_id(dev_id)),
237 "Failed to setup queue pair %u on "
247 testsuite_teardown(void)
249 struct crypto_testsuite_params *ts_params = &testsuite_params;
251 if (ts_params->mbuf_pool != NULL) {
252 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
253 rte_mempool_count(ts_params->mbuf_pool));
257 if (ts_params->mbuf_ol_pool != NULL) {
258 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
259 rte_mempool_count(ts_params->mbuf_ol_pool));
267 struct crypto_testsuite_params *ts_params = &testsuite_params;
268 struct crypto_unittest_params *ut_params = &unittest_params;
272 /* Clear unit test parameters before running test */
273 memset(ut_params, 0, sizeof(*ut_params));
275 /* Reconfigure device to default parameters */
276 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
277 ts_params->conf.socket_id = SOCKET_ID_ANY;
278 ts_params->conf.session_mp.nb_objs =
279 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
280 DEFAULT_NUM_OPS_INFLIGHT :
281 DEFAULT_NUM_OPS_INFLIGHT;
283 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
285 "Failed to configure cryptodev %u",
286 ts_params->valid_devs[0]);
289 * Now reconfigure queues to size we actually want to use in this
292 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
294 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
295 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
296 ts_params->valid_devs[0], qp_id,
298 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
299 "Failed to setup queue pair %u on cryptodev %u",
300 qp_id, ts_params->valid_devs[0]);
304 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
306 /* Start the device */
307 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
308 "Failed to start cryptodev %u",
309 ts_params->valid_devs[0]);
317 struct crypto_testsuite_params *ts_params = &testsuite_params;
318 struct crypto_unittest_params *ut_params = &unittest_params;
319 struct rte_cryptodev_stats stats;
321 /* free crypto session structure */
322 if (ut_params->sess) {
323 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
325 ut_params->sess = NULL;
328 /* free crypto operation structure */
330 rte_pktmbuf_offload_free(ut_params->ol);
333 * free mbuf - both obuf and ibuf are usually the same,
334 * but rte copes even if we call free twice
336 if (ut_params->obuf) {
337 rte_pktmbuf_free(ut_params->obuf);
340 if (ut_params->ibuf) {
341 rte_pktmbuf_free(ut_params->ibuf);
345 if (ts_params->mbuf_pool != NULL)
346 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
347 rte_mempool_count(ts_params->mbuf_pool));
349 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
351 /* Stop the device */
352 rte_cryptodev_stop(ts_params->valid_devs[0]);
356 test_device_configure_invalid_dev_id(void)
358 struct crypto_testsuite_params *ts_params = &testsuite_params;
359 uint16_t dev_id, num_devs = 0;
361 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
362 "Need at least %d devices for test", 1);
364 /* valid dev_id values */
365 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
367 /* Stop the device in case it's started so it can be configured */
368 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
370 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
371 "Failed test for rte_cryptodev_configure: "
372 "invalid dev_num %u", dev_id);
374 /* invalid dev_id values */
377 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
378 "Failed test for rte_cryptodev_configure: "
379 "invalid dev_num %u", dev_id);
383 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
384 "Failed test for rte_cryptodev_configure:"
385 "invalid dev_num %u", dev_id);
391 test_device_configure_invalid_queue_pair_ids(void)
393 struct crypto_testsuite_params *ts_params = &testsuite_params;
395 /* Stop the device in case it's started so it can be configured */
396 rte_cryptodev_stop(ts_params->valid_devs[0]);
398 /* valid - one queue pairs */
399 ts_params->conf.nb_queue_pairs = 1;
401 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
403 "Failed to configure cryptodev: dev_id %u, qp_id %u",
404 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
407 /* valid - max value queue pairs */
408 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
410 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
412 "Failed to configure cryptodev: dev_id %u, qp_id %u",
413 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
416 /* invalid - zero queue pairs */
417 ts_params->conf.nb_queue_pairs = 0;
419 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
421 "Failed test for rte_cryptodev_configure, dev_id %u,"
423 ts_params->valid_devs[0],
424 ts_params->conf.nb_queue_pairs);
427 /* invalid - max value supported by field queue pairs */
428 ts_params->conf.nb_queue_pairs = UINT16_MAX;
430 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
432 "Failed test for rte_cryptodev_configure, dev_id %u,"
434 ts_params->valid_devs[0],
435 ts_params->conf.nb_queue_pairs);
438 /* invalid - max value + 1 queue pairs */
439 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
441 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
443 "Failed test for rte_cryptodev_configure, dev_id %u,"
445 ts_params->valid_devs[0],
446 ts_params->conf.nb_queue_pairs);
452 test_queue_pair_descriptor_setup(void)
454 struct crypto_testsuite_params *ts_params = &testsuite_params;
455 struct rte_cryptodev_info dev_info;
456 struct rte_cryptodev_qp_conf qp_conf = {
457 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
462 /* Stop the device in case it's started so it can be configured */
463 rte_cryptodev_stop(ts_params->valid_devs[0]);
466 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
468 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
470 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
471 &ts_params->conf), "Failed to configure cryptodev %u",
472 ts_params->valid_devs[0]);
476 * Test various ring sizes on this device. memzones can't be
477 * freed so are re-used if ring is released and re-created.
479 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
481 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
482 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
483 ts_params->valid_devs[0], qp_id, &qp_conf,
484 rte_cryptodev_socket_id(
485 ts_params->valid_devs[0])),
487 "rte_cryptodev_queue_pair_setup: num_inflights "
488 "%u on qp %u on cryptodev %u",
489 qp_conf.nb_descriptors, qp_id,
490 ts_params->valid_devs[0]);
493 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
495 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
496 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
497 ts_params->valid_devs[0], qp_id, &qp_conf,
498 rte_cryptodev_socket_id(
499 ts_params->valid_devs[0])),
501 " rte_cryptodev_queue_pair_setup: num_inflights"
502 " %u on qp %u on cryptodev %u",
503 qp_conf.nb_descriptors, qp_id,
504 ts_params->valid_devs[0]);
507 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
509 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
510 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
511 ts_params->valid_devs[0], qp_id, &qp_conf,
512 rte_cryptodev_socket_id(
513 ts_params->valid_devs[0])),
515 "rte_cryptodev_queue_pair_setup: num_inflights"
516 " %u on qp %u on cryptodev %u",
517 qp_conf.nb_descriptors, qp_id,
518 ts_params->valid_devs[0]);
521 /* invalid number of descriptors - max supported + 2 */
522 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
524 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
525 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
526 ts_params->valid_devs[0], qp_id, &qp_conf,
527 rte_cryptodev_socket_id(
528 ts_params->valid_devs[0])),
529 "Unexpectedly passed test for "
530 "rte_cryptodev_queue_pair_setup:"
531 "num_inflights %u on qp %u on cryptodev %u",
532 qp_conf.nb_descriptors, qp_id,
533 ts_params->valid_devs[0]);
536 /* invalid number of descriptors - max value of parameter */
537 qp_conf.nb_descriptors = UINT32_MAX-1;
539 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
540 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
541 ts_params->valid_devs[0], qp_id, &qp_conf,
542 rte_cryptodev_socket_id(
543 ts_params->valid_devs[0])),
544 "Unexpectedly passed test for "
545 "rte_cryptodev_queue_pair_setup:"
546 "num_inflights %u on qp %u on cryptodev %u",
547 qp_conf.nb_descriptors, qp_id,
548 ts_params->valid_devs[0]);
551 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
553 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
554 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
555 ts_params->valid_devs[0], qp_id, &qp_conf,
556 rte_cryptodev_socket_id(
557 ts_params->valid_devs[0])),
559 " rte_cryptodev_queue_pair_setup:"
560 "num_inflights %u on qp %u on cryptodev %u",
561 qp_conf.nb_descriptors, qp_id,
562 ts_params->valid_devs[0]);
565 /* invalid number of descriptors - max supported + 1 */
566 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
568 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
569 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
570 ts_params->valid_devs[0], qp_id, &qp_conf,
571 rte_cryptodev_socket_id(
572 ts_params->valid_devs[0])),
573 "Unexpectedly passed test for "
574 "rte_cryptodev_queue_pair_setup:"
575 "num_inflights %u on qp %u on cryptodev %u",
576 qp_conf.nb_descriptors, qp_id,
577 ts_params->valid_devs[0]);
580 /* test invalid queue pair id */
581 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
583 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
585 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
586 ts_params->valid_devs[0],
588 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
589 "Failed test for rte_cryptodev_queue_pair_setup:"
590 "invalid qp %u on cryptodev %u",
591 qp_id, ts_params->valid_devs[0]);
593 qp_id = 0xffff; /*invalid*/
595 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
596 ts_params->valid_devs[0],
598 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
599 "Failed test for rte_cryptodev_queue_pair_setup:"
600 "invalid qp %u on cryptodev %u",
601 qp_id, ts_params->valid_devs[0]);
606 /* ***** Plaintext data for tests ***** */
608 const char catch_22_quote_1[] =
609 "There was only one catch and that was Catch-22, which "
610 "specified that a concern for one's safety in the face of "
611 "dangers that were real and immediate was the process of a "
612 "rational mind. Orr was crazy and could be grounded. All he "
613 "had to do was ask; and as soon as he did, he would no longer "
614 "be crazy and would have to fly more missions. Orr would be "
615 "crazy to fly more missions and sane if he didn't, but if he "
616 "was sane he had to fly them. If he flew them he was crazy "
617 "and didn't have to; but if he didn't want to he was sane and "
618 "had to. Yossarian was moved very deeply by the absolute "
619 "simplicity of this clause of Catch-22 and let out a "
620 "respectful whistle. \"That's some catch, that Catch-22\", he "
621 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
623 const char catch_22_quote[] =
624 "What a lousy earth! He wondered how many people were "
625 "destitute that same night even in his own prosperous country, "
626 "how many homes were shanties, how many husbands were drunk "
627 "and wives socked, and how many children were bullied, abused, "
628 "or abandoned. How many families hungered for food they could "
629 "not afford to buy? How many hearts were broken? How many "
630 "suicides would take place that same night, how many people "
631 "would go insane? How many cockroaches and landlords would "
632 "triumph? How many winners were losers, successes failures, "
633 "and rich men poor men? How many wise guys were stupid? How "
634 "many happy endings were unhappy endings? How many honest men "
635 "were liars, brave men cowards, loyal men traitors, how many "
636 "sainted men were corrupt, how many people in positions of "
637 "trust had sold their souls to bodyguards, how many had never "
638 "had souls? How many straight-and-narrow paths were crooked "
639 "paths? How many best families were worst families and how "
640 "many good people were bad people? When you added them all up "
641 "and then subtracted, you might be left with only the children, "
642 "and perhaps with Albert Einstein and an old violinist or "
643 "sculptor somewhere.";
645 #define QUOTE_480_BYTES (480)
646 #define QUOTE_512_BYTES (512)
647 #define QUOTE_768_BYTES (768)
648 #define QUOTE_1024_BYTES (1024)
652 /* ***** SHA1 Hash Tests ***** */
654 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
656 static uint8_t hmac_sha1_key[] = {
657 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
658 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
659 0xDE, 0xF4, 0xDE, 0xAD };
661 /* ***** SHA224 Hash Tests ***** */
663 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
666 /* ***** AES-CBC Cipher Tests ***** */
668 #define CIPHER_KEY_LENGTH_AES_CBC (16)
669 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
671 static uint8_t aes_cbc_key[] = {
672 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
673 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
675 static uint8_t aes_cbc_iv[] = {
676 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
677 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
680 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
682 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
683 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
684 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
685 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
686 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
687 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
688 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
689 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
690 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
691 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
692 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
693 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
694 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
695 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
696 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
697 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
698 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
699 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
700 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
701 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
702 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
703 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
704 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
705 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
706 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
707 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
708 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
709 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
710 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
711 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
712 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
713 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
714 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
715 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
716 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
717 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
718 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
719 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
720 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
721 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
722 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
723 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
724 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
725 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
726 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
727 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
728 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
729 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
730 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
731 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
732 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
733 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
734 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
735 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
736 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
737 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
738 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
739 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
740 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
741 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
742 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
743 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
744 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
745 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
746 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
749 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
750 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
751 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
752 0x18, 0x8c, 0x1d, 0x32
757 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
759 struct crypto_testsuite_params *ts_params = &testsuite_params;
760 struct crypto_unittest_params *ut_params = &unittest_params;
762 /* Generate test mbuf data and space for digest */
763 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
764 catch_22_quote, QUOTE_512_BYTES, 0);
766 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
767 DIGEST_BYTE_LENGTH_SHA1);
768 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
770 /* Setup Cipher Parameters */
771 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
772 ut_params->cipher_xform.next = &ut_params->auth_xform;
774 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
775 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
776 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
777 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
779 /* Setup HMAC Parameters */
780 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
782 ut_params->auth_xform.next = NULL;
784 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
785 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
786 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
787 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
788 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
790 /* Create crypto session*/
791 ut_params->sess = rte_cryptodev_sym_session_create(
792 ts_params->valid_devs[0],
793 &ut_params->cipher_xform);
794 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
796 /* Generate Crypto op data structure */
797 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
798 RTE_PKTMBUF_OL_CRYPTO_SYM);
799 TEST_ASSERT_NOT_NULL(ut_params->ol,
800 "Failed to allocate pktmbuf offload");
802 ut_params->op = &ut_params->ol->op.crypto;
804 /* Set crypto operation data parameters */
805 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
807 ut_params->op->digest.data = ut_params->digest;
808 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
809 ut_params->ibuf, QUOTE_512_BYTES);
810 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
812 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
813 CIPHER_IV_LENGTH_AES_CBC);
814 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
815 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
817 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
818 CIPHER_IV_LENGTH_AES_CBC);
820 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
821 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
822 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
823 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
825 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
827 /* Process crypto operation */
828 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
830 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
833 TEST_ASSERT_BUFFERS_ARE_EQUAL(
834 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
835 CIPHER_IV_LENGTH_AES_CBC,
836 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
838 "ciphertext data not as expected");
840 TEST_ASSERT_BUFFERS_ARE_EQUAL(
841 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
842 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
843 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
844 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
845 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
846 DIGEST_BYTE_LENGTH_SHA1,
847 "Generated digest data not as expected");
853 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
855 struct crypto_testsuite_params *ts_params = &testsuite_params;
856 struct crypto_unittest_params *ut_params = &unittest_params;
858 /* Generate test mbuf data and space for digest */
859 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
860 catch_22_quote, QUOTE_512_BYTES, 0);
862 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
863 DIGEST_BYTE_LENGTH_SHA1);
864 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
866 /* Generate Crypto op data structure */
867 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
868 RTE_PKTMBUF_OL_CRYPTO_SYM);
869 TEST_ASSERT_NOT_NULL(ut_params->ol,
870 "Failed to allocate pktmbuf offload");
872 ut_params->op = &ut_params->ol->op.crypto;
874 TEST_ASSERT_NOT_NULL(rte_pktmbuf_offload_alloc_crypto_sym_xforms(
876 "failed to allocate space for crypto transforms");
878 /* Set crypto operation data parameters */
879 ut_params->op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
881 /* cipher parameters */
882 ut_params->op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
883 ut_params->op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
884 ut_params->op->xform->cipher.key.data = aes_cbc_key;
885 ut_params->op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
887 /* hash parameters */
888 ut_params->op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
890 ut_params->op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
891 ut_params->op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
892 ut_params->op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
893 ut_params->op->xform->next->auth.key.data = hmac_sha1_key;
894 ut_params->op->xform->next->auth.digest_length =
895 DIGEST_BYTE_LENGTH_SHA1;
897 ut_params->op->digest.data = ut_params->digest;
898 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
899 ut_params->ibuf, QUOTE_512_BYTES);
900 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
902 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
903 CIPHER_IV_LENGTH_AES_CBC);
904 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
905 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
907 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
908 CIPHER_IV_LENGTH_AES_CBC);
910 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
911 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
912 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
913 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
915 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
917 /* Process crypto operation */
918 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
920 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
923 TEST_ASSERT_BUFFERS_ARE_EQUAL(
924 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
925 CIPHER_IV_LENGTH_AES_CBC,
926 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
928 "Ciphertext data not as expected");
930 TEST_ASSERT_BUFFERS_ARE_EQUAL(
931 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
932 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
933 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
934 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
935 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
936 DIGEST_BYTE_LENGTH_SHA1,
937 "Generated digest data not as expected");
944 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
946 struct crypto_testsuite_params *ts_params = &testsuite_params;
947 struct crypto_unittest_params *ut_params = &unittest_params;
949 /* Generate test mbuf data and digest */
950 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
952 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
955 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
956 DIGEST_BYTE_LENGTH_SHA1);
957 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
959 rte_memcpy(ut_params->digest,
960 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
961 DIGEST_BYTE_LENGTH_SHA1);
963 /* Setup Cipher Parameters */
964 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
965 ut_params->cipher_xform.next = NULL;
967 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
968 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
969 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
970 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
972 /* Setup HMAC Parameters */
973 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
974 ut_params->auth_xform.next = &ut_params->cipher_xform;
976 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
977 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
978 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
979 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
980 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
982 /* Create Crypto session*/
984 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
985 &ut_params->auth_xform);
986 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
988 /* Generate Crypto op data structure */
989 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
990 RTE_PKTMBUF_OL_CRYPTO_SYM);
991 TEST_ASSERT_NOT_NULL(ut_params->ol,
992 "Failed to allocate pktmbuf offload");
994 ut_params->op = &ut_params->ol->op.crypto;
997 /* Set crypto operation data parameters */
998 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1000 ut_params->op->digest.data = ut_params->digest;
1001 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1002 ut_params->ibuf, QUOTE_512_BYTES);
1003 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
1005 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1006 CIPHER_IV_LENGTH_AES_CBC);
1007 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1008 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1010 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1011 CIPHER_IV_LENGTH_AES_CBC);
1013 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1014 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1016 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1017 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1019 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1021 /* Process crypto operation */
1022 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1024 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1027 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1028 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1029 CIPHER_IV_LENGTH_AES_CBC,
1032 "Ciphertext data not as expected");
1034 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1035 "Digest verification failed");
1038 return TEST_SUCCESS;
1042 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1044 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1046 static uint8_t hmac_sha256_key[] = {
1047 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1048 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1049 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1050 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1052 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1053 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1054 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1055 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1056 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1059 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1061 struct crypto_testsuite_params *ts_params = &testsuite_params;
1062 struct crypto_unittest_params *ut_params = &unittest_params;
1064 /* Generate test mbuf data and space for digest */
1065 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1066 catch_22_quote, QUOTE_512_BYTES, 0);
1068 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1069 DIGEST_BYTE_LENGTH_SHA256);
1070 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1072 /* Setup Cipher Parameters */
1073 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1074 ut_params->cipher_xform.next = &ut_params->auth_xform;
1076 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1077 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1078 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1079 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1081 /* Setup HMAC Parameters */
1082 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1083 ut_params->auth_xform.next = NULL;
1085 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1086 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1087 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1088 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1089 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1091 /* Create Crypto session*/
1093 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1094 &ut_params->cipher_xform);
1095 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1097 /* Generate Crypto op data structure */
1098 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1099 RTE_PKTMBUF_OL_CRYPTO_SYM);
1100 TEST_ASSERT_NOT_NULL(ut_params->ol,
1101 "Failed to allocate pktmbuf offload");
1103 ut_params->op = &ut_params->ol->op.crypto;
1106 /* Set crypto operation data parameters */
1107 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1109 ut_params->op->digest.data = ut_params->digest;
1110 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1111 ut_params->ibuf, QUOTE_512_BYTES);
1112 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA256;
1114 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1115 CIPHER_IV_LENGTH_AES_CBC);
1116 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1117 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1119 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1120 CIPHER_IV_LENGTH_AES_CBC);
1122 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1123 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1124 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1125 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1127 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1129 /* Process crypto operation */
1130 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1132 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1135 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1136 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1137 CIPHER_IV_LENGTH_AES_CBC,
1138 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1140 "Ciphertext data not as expected");
1142 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1143 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1144 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1145 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1146 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1147 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1148 DIGEST_BYTE_LENGTH_SHA256,
1149 "Generated digest data not as expected");
1152 return TEST_SUCCESS;
1156 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1158 struct crypto_testsuite_params *ts_params = &testsuite_params;
1159 struct crypto_unittest_params *ut_params = &unittest_params;
1161 /* Generate test mbuf data and digest */
1162 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1164 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1165 QUOTE_512_BYTES, 0);
1167 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1168 DIGEST_BYTE_LENGTH_SHA256);
1169 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1171 rte_memcpy(ut_params->digest,
1172 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1173 DIGEST_BYTE_LENGTH_SHA256);
1175 /* Setup Cipher Parameters */
1176 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1177 ut_params->cipher_xform.next = NULL;
1179 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1180 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1181 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1182 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1184 /* Setup HMAC Parameters */
1185 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1186 ut_params->auth_xform.next = &ut_params->cipher_xform;
1188 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1189 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1190 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1191 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1192 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1194 /* Create Crypto session*/
1196 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1197 &ut_params->auth_xform);
1198 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1200 /* Generate Crypto op data structure */
1201 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1202 RTE_PKTMBUF_OL_CRYPTO_SYM);
1203 TEST_ASSERT_NOT_NULL(ut_params->ol,
1204 "Failed to allocate pktmbuf offload");
1206 ut_params->op = &ut_params->ol->op.crypto;
1209 /* Set crypto operation data parameters */
1210 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1212 ut_params->op->digest.data = ut_params->digest;
1213 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1214 ut_params->ibuf, QUOTE_512_BYTES);
1215 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA256;
1217 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1218 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1219 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1220 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1222 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1223 CIPHER_IV_LENGTH_AES_CBC);
1225 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1226 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1228 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1229 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1231 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1233 /* Process crypto operation */
1234 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1236 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1239 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1240 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1241 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1243 "Plaintext data not as expected");
1245 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1246 "Digest verification failed");
1248 return TEST_SUCCESS;
1251 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1253 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1255 static uint8_t hmac_sha512_key[] = {
1256 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1257 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1258 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1259 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1260 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1261 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1262 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1263 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1265 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1266 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1267 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1268 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1269 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1270 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1271 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1272 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1273 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1276 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1278 struct crypto_testsuite_params *ts_params = &testsuite_params;
1279 struct crypto_unittest_params *ut_params = &unittest_params;
1281 /* Generate test mbuf data and space for digest */
1282 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1283 catch_22_quote, QUOTE_512_BYTES, 0);
1285 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1286 DIGEST_BYTE_LENGTH_SHA512);
1287 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1289 /* Setup Cipher Parameters */
1290 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1291 ut_params->cipher_xform.next = &ut_params->auth_xform;
1293 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1294 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1295 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1296 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1298 /* Setup HMAC Parameters */
1299 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1300 ut_params->auth_xform.next = NULL;
1302 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1303 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1304 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1305 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1306 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1308 /* Create Crypto session*/
1310 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1311 &ut_params->cipher_xform);
1313 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1316 /* Generate Crypto op data structure */
1317 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1318 RTE_PKTMBUF_OL_CRYPTO_SYM);
1319 TEST_ASSERT_NOT_NULL(ut_params->ol,
1320 "Failed to allocate pktmbuf offload");
1322 ut_params->op = &ut_params->ol->op.crypto;
1325 /* Set crypto operation data parameters */
1326 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1328 ut_params->op->digest.data = ut_params->digest;
1329 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1330 ut_params->ibuf, QUOTE_512_BYTES);
1331 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1333 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1334 CIPHER_IV_LENGTH_AES_CBC);
1335 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1336 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1338 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1339 CIPHER_IV_LENGTH_AES_CBC);
1341 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1342 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1343 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1344 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1346 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1348 /* Process crypto operation */
1349 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1351 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1354 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1355 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1356 CIPHER_IV_LENGTH_AES_CBC,
1357 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1359 "Ciphertext data not as expected");
1361 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1362 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1363 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1364 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1365 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1366 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1367 DIGEST_BYTE_LENGTH_SHA512,
1368 "Generated digest data not as expected");
1370 return TEST_SUCCESS;
1375 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1376 struct crypto_unittest_params *ut_params);
1379 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1380 struct crypto_unittest_params *ut_params,
1381 struct crypto_testsuite_params *ts_params);
1384 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1386 struct crypto_unittest_params *ut_params = &unittest_params;
1387 struct crypto_testsuite_params *ts_params = &testsuite_params;
1389 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1390 ut_params) == TEST_SUCCESS,
1391 "Failed to create session params");
1393 /* Create Crypto session*/
1395 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1396 &ut_params->auth_xform);
1397 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1399 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1400 ut_params, ts_params);
1404 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1405 struct crypto_unittest_params *ut_params)
1408 /* Setup Cipher Parameters */
1409 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1410 ut_params->cipher_xform.next = NULL;
1412 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1413 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1414 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1415 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1417 /* Setup HMAC Parameters */
1418 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1419 ut_params->auth_xform.next = &ut_params->cipher_xform;
1421 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1422 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1423 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1424 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1425 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1427 return TEST_SUCCESS;
1432 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1433 struct crypto_unittest_params *ut_params,
1434 struct crypto_testsuite_params *ts_params)
1436 /* Generate test mbuf data and digest */
1437 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1439 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1440 QUOTE_512_BYTES, 0);
1442 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1443 DIGEST_BYTE_LENGTH_SHA512);
1444 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1446 rte_memcpy(ut_params->digest,
1447 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1448 DIGEST_BYTE_LENGTH_SHA512);
1450 /* Generate Crypto op data structure */
1451 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1452 RTE_PKTMBUF_OL_CRYPTO_SYM);
1453 TEST_ASSERT_NOT_NULL(ut_params->ol,
1454 "Failed to allocate pktmbuf offload");
1456 ut_params->op = &ut_params->ol->op.crypto;
1459 /* Set crypto operation data parameters */
1460 rte_crypto_sym_op_attach_session(ut_params->op, sess);
1462 ut_params->op->digest.data = ut_params->digest;
1463 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1464 ut_params->ibuf, QUOTE_512_BYTES);
1465 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1467 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1468 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1469 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys_offset(
1470 ut_params->ibuf, 0);
1471 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1473 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1474 CIPHER_IV_LENGTH_AES_CBC);
1476 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1477 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1479 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1480 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1482 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1484 /* Process crypto operation */
1485 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1487 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1490 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1491 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1492 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1494 "Plaintext data not as expected");
1497 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1498 "Digest verification failed");
1500 return TEST_SUCCESS;
1503 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1505 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1506 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1507 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1510 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1511 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1512 0x77, 0x1D, 0x8B, 0x75
1516 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1518 struct crypto_testsuite_params *ts_params = &testsuite_params;
1519 struct crypto_unittest_params *ut_params = &unittest_params;
1521 /* Generate test mbuf data and space for digest */
1522 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1523 catch_22_quote, QUOTE_512_BYTES, 0);
1525 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1526 DIGEST_BYTE_LENGTH_AES_XCBC);
1527 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1529 /* Setup Cipher Parameters */
1530 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1531 ut_params->cipher_xform.next = &ut_params->auth_xform;
1533 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1534 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1535 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1536 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1538 /* Setup HMAC Parameters */
1539 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1540 ut_params->auth_xform.next = NULL;
1542 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1543 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1544 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1545 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1546 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1548 /* Create Crypto session*/
1550 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1551 &ut_params->cipher_xform);
1552 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1554 /* Generate Crypto op data structure */
1555 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1556 RTE_PKTMBUF_OL_CRYPTO_SYM);
1557 TEST_ASSERT_NOT_NULL(ut_params->ol,
1558 "Failed to allocate pktmbuf offload");
1560 ut_params->op = &ut_params->ol->op.crypto;
1563 /* Set crypto operation data parameters */
1564 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1566 ut_params->op->iv.data = (uint8_t *)
1567 rte_pktmbuf_prepend(ut_params->ibuf,
1568 CIPHER_IV_LENGTH_AES_CBC);
1569 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1570 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1572 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1573 CIPHER_IV_LENGTH_AES_CBC);
1575 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1576 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1577 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1578 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1580 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1582 /* Process crypto operation */
1583 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1585 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1588 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1589 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1590 CIPHER_IV_LENGTH_AES_CBC,
1591 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1593 "Ciphertext data not as expected");
1594 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1595 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1596 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1597 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1598 DIGEST_BYTE_LENGTH_AES_XCBC,
1599 "Generated digest data not as expected");
1601 return TEST_SUCCESS;
1605 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1607 struct crypto_testsuite_params *ts_params = &testsuite_params;
1608 struct crypto_unittest_params *ut_params = &unittest_params;
1610 /* Generate test mbuf data and space for digest */
1611 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1612 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1613 QUOTE_512_BYTES, 0);
1615 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1616 DIGEST_BYTE_LENGTH_AES_XCBC);
1617 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1619 rte_memcpy(ut_params->digest,
1620 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1621 DIGEST_BYTE_LENGTH_AES_XCBC);
1623 /* Setup Cipher Parameters */
1624 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1625 ut_params->cipher_xform.next = NULL;
1627 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1628 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1629 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1630 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1632 /* Setup HMAC Parameters */
1633 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1634 ut_params->auth_xform.next = &ut_params->cipher_xform;
1636 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1637 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1638 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1639 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1640 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1642 /* Create Crypto session*/
1644 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1645 &ut_params->auth_xform);
1646 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1648 /* Generate Crypto op data structure */
1649 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1650 RTE_PKTMBUF_OL_CRYPTO_SYM);
1651 TEST_ASSERT_NOT_NULL(ut_params->ol,
1652 "Failed to allocate pktmbuf offload");
1654 ut_params->op = &ut_params->ol->op.crypto;
1657 /* Set crypto operation data parameters */
1658 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1660 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1661 CIPHER_IV_LENGTH_AES_CBC);
1662 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1663 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1665 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1666 CIPHER_IV_LENGTH_AES_CBC);
1668 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1669 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1670 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1671 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1672 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1674 /* Process crypto operation */
1675 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1677 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1680 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1681 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1682 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1684 "Ciphertext data not as expected");
1686 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1687 "Digest verification failed");
1689 return TEST_SUCCESS;
1693 /* ***** AES-GCM Tests ***** */
1698 struct crypto_testsuite_params *ts_params = &testsuite_params;
1699 struct rte_cryptodev_stats stats;
1700 struct rte_cryptodev *dev;
1701 cryptodev_stats_get_t temp_pfn;
1703 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1704 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
1705 &stats) == -ENODEV),
1706 "rte_cryptodev_stats_get invalid dev failed");
1707 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
1708 "rte_cryptodev_stats_get invalid Param failed");
1709 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
1710 temp_pfn = dev->dev_ops->stats_get;
1711 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
1712 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
1714 "rte_cryptodev_stats_get invalid Param failed");
1715 dev->dev_ops->stats_get = temp_pfn;
1717 /* Test expected values */
1719 test_AES_CBC_HMAC_SHA1_encrypt_digest();
1721 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1723 "rte_cryptodev_stats_get failed");
1724 TEST_ASSERT((stats.enqueued_count == 1),
1725 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1726 TEST_ASSERT((stats.dequeued_count == 1),
1727 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1728 TEST_ASSERT((stats.enqueue_err_count == 0),
1729 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1730 TEST_ASSERT((stats.dequeue_err_count == 0),
1731 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1733 /* invalid device but should ignore and not reset device stats*/
1734 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
1735 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1737 "rte_cryptodev_stats_get failed");
1738 TEST_ASSERT((stats.enqueued_count == 1),
1739 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1741 /* check that a valid reset clears stats */
1742 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1743 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1745 "rte_cryptodev_stats_get failed");
1746 TEST_ASSERT((stats.enqueued_count == 0),
1747 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1748 TEST_ASSERT((stats.dequeued_count == 0),
1749 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1751 return TEST_SUCCESS;
1756 test_multi_session(void)
1758 struct crypto_testsuite_params *ts_params = &testsuite_params;
1759 struct crypto_unittest_params *ut_params = &unittest_params;
1761 struct rte_cryptodev_info dev_info;
1762 struct rte_cryptodev_sym_session **sessions;
1766 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1769 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
1771 sessions = rte_malloc(NULL,
1772 (sizeof(struct rte_cryptodev_sym_session *) *
1773 dev_info.sym.max_nb_sessions) + 1, 0);
1775 /* Create multiple crypto sessions*/
1776 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
1777 sessions[i] = rte_cryptodev_sym_session_create(
1778 ts_params->valid_devs[0],
1779 &ut_params->auth_xform);
1780 TEST_ASSERT_NOT_NULL(sessions[i],
1781 "Session creation failed at session number %u",
1784 /* Attempt to send a request on each session */
1785 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
1786 sessions[i], ut_params, ts_params),
1787 "Failed to perform decrypt on request "
1791 /* Next session create should fail */
1792 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1793 &ut_params->auth_xform);
1794 TEST_ASSERT_NULL(sessions[i],
1795 "Session creation succeeded unexpectedly!");
1797 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
1798 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
1803 return TEST_SUCCESS;
1807 test_not_in_place_crypto(void)
1809 struct crypto_testsuite_params *ts_params = &testsuite_params;
1810 struct crypto_unittest_params *ut_params = &unittest_params;
1811 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1813 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1815 /* Create multiple crypto sessions*/
1817 ut_params->sess = rte_cryptodev_sym_session_create(
1818 ts_params->valid_devs[0], &ut_params->auth_xform);
1820 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1823 /* Generate test mbuf data and digest */
1824 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1826 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1827 QUOTE_512_BYTES, 0);
1829 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1830 DIGEST_BYTE_LENGTH_SHA512);
1831 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1833 rte_memcpy(ut_params->digest,
1834 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1835 DIGEST_BYTE_LENGTH_SHA512);
1837 /* Generate Crypto op data structure */
1838 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1839 RTE_PKTMBUF_OL_CRYPTO_SYM);
1840 TEST_ASSERT_NOT_NULL(ut_params->ol,
1841 "Failed to allocate pktmbuf offload");
1843 ut_params->op = &ut_params->ol->op.crypto;
1846 /* Set crypto operation data parameters */
1847 rte_crypto_sym_op_attach_session(ut_params->op, ut_params->sess);
1849 ut_params->op->digest.data = ut_params->digest;
1850 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1851 ut_params->ibuf, QUOTE_512_BYTES);
1852 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1854 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1855 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1856 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys_offset(
1857 ut_params->ibuf, 0);
1858 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1860 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1861 CIPHER_IV_LENGTH_AES_CBC);
1863 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1864 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1866 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1867 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1869 ut_params->op->dst.m = dst_m;
1870 ut_params->op->dst.offset = 0;
1872 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1874 /* Process crypto operation */
1875 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1877 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1880 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1881 rte_pktmbuf_mtod(ut_params->op->dst.m, char *),
1884 "Plaintext data not as expected");
1888 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1889 "Digest verification failed");
1891 return TEST_SUCCESS;
1895 static struct unit_test_suite cryptodev_qat_testsuite = {
1896 .suite_name = "Crypto QAT Unit Test Suite",
1897 .setup = testsuite_setup,
1898 .teardown = testsuite_teardown,
1899 .unit_test_cases = {
1900 TEST_CASE_ST(ut_setup, ut_teardown,
1901 test_device_configure_invalid_dev_id),
1902 TEST_CASE_ST(ut_setup, ut_teardown,
1903 test_device_configure_invalid_queue_pair_ids),
1904 TEST_CASE_ST(ut_setup, ut_teardown,
1905 test_queue_pair_descriptor_setup),
1906 TEST_CASE_ST(ut_setup, ut_teardown,
1907 test_multi_session),
1909 TEST_CASE_ST(ut_setup, ut_teardown,
1910 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1911 TEST_CASE_ST(ut_setup, ut_teardown,
1912 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1914 TEST_CASE_ST(ut_setup, ut_teardown,
1915 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1916 TEST_CASE_ST(ut_setup, ut_teardown,
1917 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1919 TEST_CASE_ST(ut_setup, ut_teardown,
1920 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1921 TEST_CASE_ST(ut_setup, ut_teardown,
1922 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1924 TEST_CASE_ST(ut_setup, ut_teardown,
1925 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1926 TEST_CASE_ST(ut_setup, ut_teardown,
1927 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1929 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
1931 TEST_CASES_END() /**< NULL terminate unit test array */
1935 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
1936 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
1937 .setup = testsuite_setup,
1938 .teardown = testsuite_teardown,
1939 .unit_test_cases = {
1940 TEST_CASE_ST(ut_setup, ut_teardown,
1941 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1942 TEST_CASE_ST(ut_setup, ut_teardown,
1943 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1945 TEST_CASE_ST(ut_setup, ut_teardown,
1946 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1947 TEST_CASE_ST(ut_setup, ut_teardown,
1948 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1950 TEST_CASE_ST(ut_setup, ut_teardown,
1951 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1952 TEST_CASE_ST(ut_setup, ut_teardown,
1953 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1955 TEST_CASE_ST(ut_setup, ut_teardown,
1956 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1957 TEST_CASE_ST(ut_setup, ut_teardown,
1958 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1960 TEST_CASE_ST(ut_setup, ut_teardown,
1961 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
1963 TEST_CASE_ST(ut_setup, ut_teardown,
1964 test_not_in_place_crypto),
1966 TEST_CASES_END() /**< NULL terminate unit test array */
1971 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
1973 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
1974 return unit_test_suite_runner(&cryptodev_qat_testsuite);
1976 static struct test_command cryptodev_qat_cmd = {
1977 .command = "cryptodev_qat_autotest",
1978 .callback = test_cryptodev_qat,
1982 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
1984 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
1986 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
1989 static struct test_command cryptodev_aesni_mb_cmd = {
1990 .command = "cryptodev_aesni_mb_autotest",
1991 .callback = test_cryptodev_aesni_mb,
1994 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
1995 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);