4 * Copyright(c) 2015 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_xform cipher_xform;
61 struct rte_crypto_xform auth_xform;
63 struct rte_cryptodev_session *sess;
65 struct rte_mbuf_offload *ol;
66 struct rte_crypto_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_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 = 0;
149 memset(ts_params, 0, sizeof(*ts_params));
151 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
152 if (ts_params->mbuf_pool == NULL) {
153 /* Not already created so create */
154 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
156 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
158 if (ts_params->mbuf_pool == NULL) {
159 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
164 ts_params->mbuf_ol_pool = rte_pktmbuf_offload_pool_create(
166 NUM_MBUFS, MBUF_CACHE_SIZE,
167 DEFAULT_NUM_XFORMS * sizeof(struct rte_crypto_xform),
169 if (ts_params->mbuf_ol_pool == NULL) {
170 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
174 /* Create 2 AESNI MB devices if required */
175 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
176 nb_devs = rte_cryptodev_count_devtype(
177 RTE_CRYPTODEV_AESNI_MB_PMD);
179 for (i = nb_devs; i < 2; i++) {
180 int dev_id = rte_eal_vdev_init(
181 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
183 TEST_ASSERT(dev_id >= 0,
184 "Failed to create instance %u of"
186 i, CRYPTODEV_NAME_AESNI_MB_PMD);
191 nb_devs = rte_cryptodev_count();
193 RTE_LOG(ERR, USER1, "No crypto devices found?");
197 /* Create list of valid crypto devs */
198 for (i = 0; i < nb_devs; i++) {
199 rte_cryptodev_info_get(i, &info);
200 if (info.dev_type == gbl_cryptodev_type)
201 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
204 if (ts_params->valid_dev_count < 1)
207 /* Set up all the qps on the first of the valid devices found */
208 for (i = 0; i < 1; i++) {
209 dev_id = ts_params->valid_devs[i];
211 rte_cryptodev_info_get(dev_id, &info);
214 * Since we can't free and re-allocate queue memory always set
215 * the queues on this device up to max size first so enough
216 * memory is allocated for any later re-configures needed by
220 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
221 ts_params->conf.socket_id = SOCKET_ID_ANY;
222 ts_params->conf.session_mp.nb_objs = info.max_nb_sessions;
224 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
226 "Failed to configure cryptodev %u with %u qps",
227 dev_id, ts_params->conf.nb_queue_pairs);
229 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
231 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
232 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
233 dev_id, qp_id, &ts_params->qp_conf,
234 rte_cryptodev_socket_id(dev_id)),
235 "Failed to setup queue pair %u on "
245 testsuite_teardown(void)
247 struct crypto_testsuite_params *ts_params = &testsuite_params;
249 if (ts_params->mbuf_pool != NULL) {
250 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
251 rte_mempool_count(ts_params->mbuf_pool));
255 if (ts_params->mbuf_ol_pool != NULL) {
256 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
257 rte_mempool_count(ts_params->mbuf_ol_pool));
265 struct crypto_testsuite_params *ts_params = &testsuite_params;
266 struct crypto_unittest_params *ut_params = &unittest_params;
270 /* Clear unit test parameters before running test */
271 memset(ut_params, 0, sizeof(*ut_params));
273 /* Reconfigure device to default parameters */
274 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
275 ts_params->conf.socket_id = SOCKET_ID_ANY;
276 ts_params->conf.session_mp.nb_objs =
277 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_PMD) ?
278 DEFAULT_NUM_OPS_INFLIGHT :
279 DEFAULT_NUM_OPS_INFLIGHT;
281 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
283 "Failed to configure cryptodev %u",
284 ts_params->valid_devs[0]);
287 * Now reconfigure queues to size we actually want to use in this
290 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
292 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
293 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
294 ts_params->valid_devs[0], qp_id,
296 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
297 "Failed to setup queue pair %u on cryptodev %u",
298 qp_id, ts_params->valid_devs[0]);
302 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
304 /* Start the device */
305 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
306 "Failed to start cryptodev %u",
307 ts_params->valid_devs[0]);
315 struct crypto_testsuite_params *ts_params = &testsuite_params;
316 struct crypto_unittest_params *ut_params = &unittest_params;
317 struct rte_cryptodev_stats stats;
319 /* free crypto session structure */
320 if (ut_params->sess) {
321 rte_cryptodev_session_free(ts_params->valid_devs[0],
323 ut_params->sess = NULL;
326 /* free crypto operation structure */
328 rte_pktmbuf_offload_free(ut_params->ol);
331 * free mbuf - both obuf and ibuf are usually the same,
332 * but rte copes even if we call free twice
334 if (ut_params->obuf) {
335 rte_pktmbuf_free(ut_params->obuf);
338 if (ut_params->ibuf) {
339 rte_pktmbuf_free(ut_params->ibuf);
343 if (ts_params->mbuf_pool != NULL)
344 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
345 rte_mempool_count(ts_params->mbuf_pool));
347 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
349 /* Stop the device */
350 rte_cryptodev_stop(ts_params->valid_devs[0]);
354 test_device_configure_invalid_dev_id(void)
356 struct crypto_testsuite_params *ts_params = &testsuite_params;
357 uint16_t dev_id, num_devs = 0;
359 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
360 "Need at least %d devices for test", 1);
362 /* valid dev_id values */
363 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
365 /* Stop the device in case it's started so it can be configured */
366 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
368 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
369 "Failed test for rte_cryptodev_configure: "
370 "invalid dev_num %u", dev_id);
372 /* invalid dev_id values */
375 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
376 "Failed test for rte_cryptodev_configure: "
377 "invalid dev_num %u", dev_id);
381 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
382 "Failed test for rte_cryptodev_configure:"
383 "invalid dev_num %u", dev_id);
389 test_device_configure_invalid_queue_pair_ids(void)
391 struct crypto_testsuite_params *ts_params = &testsuite_params;
393 /* Stop the device in case it's started so it can be configured */
394 rte_cryptodev_stop(ts_params->valid_devs[0]);
396 /* valid - one queue pairs */
397 ts_params->conf.nb_queue_pairs = 1;
399 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
401 "Failed to configure cryptodev: dev_id %u, qp_id %u",
402 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
405 /* valid - max value queue pairs */
406 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
408 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
410 "Failed to configure cryptodev: dev_id %u, qp_id %u",
411 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
414 /* invalid - zero queue pairs */
415 ts_params->conf.nb_queue_pairs = 0;
417 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
419 "Failed test for rte_cryptodev_configure, dev_id %u,"
421 ts_params->valid_devs[0],
422 ts_params->conf.nb_queue_pairs);
425 /* invalid - max value supported by field queue pairs */
426 ts_params->conf.nb_queue_pairs = UINT16_MAX;
428 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
430 "Failed test for rte_cryptodev_configure, dev_id %u,"
432 ts_params->valid_devs[0],
433 ts_params->conf.nb_queue_pairs);
436 /* invalid - max value + 1 queue pairs */
437 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
439 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
441 "Failed test for rte_cryptodev_configure, dev_id %u,"
443 ts_params->valid_devs[0],
444 ts_params->conf.nb_queue_pairs);
450 test_queue_pair_descriptor_setup(void)
452 struct crypto_testsuite_params *ts_params = &testsuite_params;
453 struct rte_cryptodev_info dev_info;
454 struct rte_cryptodev_qp_conf qp_conf = {
455 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
460 /* Stop the device in case it's started so it can be configured */
461 rte_cryptodev_stop(ts_params->valid_devs[0]);
464 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
466 ts_params->conf.session_mp.nb_objs = dev_info.max_nb_sessions;
468 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
469 &ts_params->conf), "Failed to configure cryptodev %u",
470 ts_params->valid_devs[0]);
474 * Test various ring sizes on this device. memzones can't be
475 * freed so are re-used if ring is released and re-created.
477 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
479 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
480 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
481 ts_params->valid_devs[0], qp_id, &qp_conf,
482 rte_cryptodev_socket_id(
483 ts_params->valid_devs[0])),
485 "rte_cryptodev_queue_pair_setup: num_inflights "
486 "%u on qp %u on cryptodev %u",
487 qp_conf.nb_descriptors, qp_id,
488 ts_params->valid_devs[0]);
491 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
493 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
494 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
495 ts_params->valid_devs[0], qp_id, &qp_conf,
496 rte_cryptodev_socket_id(
497 ts_params->valid_devs[0])),
499 " rte_cryptodev_queue_pair_setup: num_inflights"
500 " %u on qp %u on cryptodev %u",
501 qp_conf.nb_descriptors, qp_id,
502 ts_params->valid_devs[0]);
505 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
507 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
508 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
509 ts_params->valid_devs[0], qp_id, &qp_conf,
510 rte_cryptodev_socket_id(
511 ts_params->valid_devs[0])),
513 "rte_cryptodev_queue_pair_setup: num_inflights"
514 " %u on qp %u on cryptodev %u",
515 qp_conf.nb_descriptors, qp_id,
516 ts_params->valid_devs[0]);
519 /* invalid number of descriptors - max supported + 2 */
520 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
522 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
523 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
524 ts_params->valid_devs[0], qp_id, &qp_conf,
525 rte_cryptodev_socket_id(
526 ts_params->valid_devs[0])),
527 "Unexpectedly passed test for "
528 "rte_cryptodev_queue_pair_setup:"
529 "num_inflights %u on qp %u on cryptodev %u",
530 qp_conf.nb_descriptors, qp_id,
531 ts_params->valid_devs[0]);
534 /* invalid number of descriptors - max value of parameter */
535 qp_conf.nb_descriptors = UINT32_MAX-1;
537 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
538 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
539 ts_params->valid_devs[0], qp_id, &qp_conf,
540 rte_cryptodev_socket_id(
541 ts_params->valid_devs[0])),
542 "Unexpectedly passed test for "
543 "rte_cryptodev_queue_pair_setup:"
544 "num_inflights %u on qp %u on cryptodev %u",
545 qp_conf.nb_descriptors, qp_id,
546 ts_params->valid_devs[0]);
549 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
551 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
552 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
553 ts_params->valid_devs[0], qp_id, &qp_conf,
554 rte_cryptodev_socket_id(
555 ts_params->valid_devs[0])),
557 " rte_cryptodev_queue_pair_setup:"
558 "num_inflights %u on qp %u on cryptodev %u",
559 qp_conf.nb_descriptors, qp_id,
560 ts_params->valid_devs[0]);
563 /* invalid number of descriptors - max supported + 1 */
564 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
566 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
567 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
568 ts_params->valid_devs[0], qp_id, &qp_conf,
569 rte_cryptodev_socket_id(
570 ts_params->valid_devs[0])),
571 "Unexpectedly passed test for "
572 "rte_cryptodev_queue_pair_setup:"
573 "num_inflights %u on qp %u on cryptodev %u",
574 qp_conf.nb_descriptors, qp_id,
575 ts_params->valid_devs[0]);
578 /* test invalid queue pair id */
579 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
581 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
583 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
584 ts_params->valid_devs[0],
586 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
587 "Failed test for rte_cryptodev_queue_pair_setup:"
588 "invalid qp %u on cryptodev %u",
589 qp_id, ts_params->valid_devs[0]);
591 qp_id = 0xffff; /*invalid*/
593 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
594 ts_params->valid_devs[0],
596 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
597 "Failed test for rte_cryptodev_queue_pair_setup:"
598 "invalid qp %u on cryptodev %u",
599 qp_id, ts_params->valid_devs[0]);
604 /* ***** Plaintext data for tests ***** */
606 const char catch_22_quote_1[] =
607 "There was only one catch and that was Catch-22, which "
608 "specified that a concern for one's safety in the face of "
609 "dangers that were real and immediate was the process of a "
610 "rational mind. Orr was crazy and could be grounded. All he "
611 "had to do was ask; and as soon as he did, he would no longer "
612 "be crazy and would have to fly more missions. Orr would be "
613 "crazy to fly more missions and sane if he didn't, but if he "
614 "was sane he had to fly them. If he flew them he was crazy "
615 "and didn't have to; but if he didn't want to he was sane and "
616 "had to. Yossarian was moved very deeply by the absolute "
617 "simplicity of this clause of Catch-22 and let out a "
618 "respectful whistle. \"That's some catch, that Catch-22\", he "
619 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
621 const char catch_22_quote[] =
622 "What a lousy earth! He wondered how many people were "
623 "destitute that same night even in his own prosperous country, "
624 "how many homes were shanties, how many husbands were drunk "
625 "and wives socked, and how many children were bullied, abused, "
626 "or abandoned. How many families hungered for food they could "
627 "not afford to buy? How many hearts were broken? How many "
628 "suicides would take place that same night, how many people "
629 "would go insane? How many cockroaches and landlords would "
630 "triumph? How many winners were losers, successes failures, "
631 "and rich men poor men? How many wise guys were stupid? How "
632 "many happy endings were unhappy endings? How many honest men "
633 "were liars, brave men cowards, loyal men traitors, how many "
634 "sainted men were corrupt, how many people in positions of "
635 "trust had sold their souls to bodyguards, how many had never "
636 "had souls? How many straight-and-narrow paths were crooked "
637 "paths? How many best families were worst families and how "
638 "many good people were bad people? When you added them all up "
639 "and then subtracted, you might be left with only the children, "
640 "and perhaps with Albert Einstein and an old violinist or "
641 "sculptor somewhere.";
643 #define QUOTE_480_BYTES (480)
644 #define QUOTE_512_BYTES (512)
645 #define QUOTE_768_BYTES (768)
646 #define QUOTE_1024_BYTES (1024)
650 /* ***** SHA1 Hash Tests ***** */
652 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
654 static uint8_t hmac_sha1_key[] = {
655 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
656 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
657 0xDE, 0xF4, 0xDE, 0xAD };
659 /* ***** SHA224 Hash Tests ***** */
661 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
664 /* ***** AES-CBC Cipher Tests ***** */
666 #define CIPHER_KEY_LENGTH_AES_CBC (16)
667 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
669 static uint8_t aes_cbc_key[] = {
670 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
671 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
673 static uint8_t aes_cbc_iv[] = {
674 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
675 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
678 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
680 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
681 0x8B, 0X4D, 0XDA, 0X1B, 0XCF, 0X04, 0XA0, 0X31,
682 0XB4, 0XBF, 0XBD, 0X68, 0X43, 0X20, 0X7E, 0X76,
683 0XB1, 0X96, 0X8B, 0XA2, 0X7C, 0XA2, 0X83, 0X9E,
684 0X39, 0X5A, 0X2F, 0X7E, 0X92, 0XB4, 0X48, 0X1A,
685 0X3F, 0X6B, 0X5D, 0XDF, 0X52, 0X85, 0X5F, 0X8E,
686 0X42, 0X3C, 0XFB, 0XE9, 0X1A, 0X24, 0XD6, 0X08,
687 0XDD, 0XFD, 0X16, 0XFB, 0XE9, 0X55, 0XEF, 0XF0,
688 0XA0, 0X8D, 0X13, 0XAB, 0X81, 0XC6, 0X90, 0X01,
689 0XB5, 0X18, 0X84, 0XB3, 0XF6, 0XE6, 0X11, 0X57,
690 0XD6, 0X71, 0XC6, 0X3C, 0X3F, 0X2F, 0X33, 0XEE,
691 0X24, 0X42, 0X6E, 0XAC, 0X0B, 0XCA, 0XEC, 0XF9,
692 0X84, 0XF8, 0X22, 0XAA, 0X60, 0XF0, 0X32, 0XA9,
693 0X75, 0X75, 0X3B, 0XCB, 0X70, 0X21, 0X0A, 0X8D,
694 0X0F, 0XE0, 0XC4, 0X78, 0X2B, 0XF8, 0X97, 0XE3,
695 0XE4, 0X26, 0X4B, 0X29, 0XDA, 0X88, 0XCD, 0X46,
696 0XEC, 0XAA, 0XF9, 0X7F, 0XF1, 0X15, 0XEA, 0XC3,
697 0X87, 0XE6, 0X31, 0XF2, 0XCF, 0XDE, 0X4D, 0X80,
698 0X70, 0X91, 0X7E, 0X0C, 0XF7, 0X26, 0X3A, 0X92,
699 0X4F, 0X18, 0X83, 0XC0, 0X8F, 0X59, 0X01, 0XA5,
700 0X88, 0XD1, 0XDB, 0X26, 0X71, 0X27, 0X16, 0XF5,
701 0XEE, 0X10, 0X82, 0XAC, 0X68, 0X26, 0X9B, 0XE2,
702 0X6D, 0XD8, 0X9A, 0X80, 0XDF, 0X04, 0X31, 0XD5,
703 0XF1, 0X35, 0X5C, 0X3B, 0XDD, 0X9A, 0X65, 0XBA,
704 0X58, 0X34, 0X85, 0X61, 0X1C, 0X42, 0X10, 0X76,
705 0X73, 0X02, 0X42, 0XC9, 0X23, 0X18, 0X8E, 0XB4,
706 0X6F, 0XB4, 0XA3, 0X54, 0X6E, 0X88, 0X3B, 0X62,
707 0X7C, 0X02, 0X8D, 0X4C, 0X9F, 0XC8, 0X45, 0XF4,
708 0XC9, 0XDE, 0X4F, 0XEB, 0X22, 0X83, 0X1B, 0XE4,
709 0X49, 0X37, 0XE4, 0XAD, 0XE7, 0XCD, 0X21, 0X54,
710 0XBC, 0X1C, 0XC2, 0X04, 0X97, 0XB4, 0X10, 0X61,
711 0XF0, 0XE4, 0XEF, 0X27, 0X63, 0X3A, 0XDA, 0X91,
712 0X41, 0X25, 0X62, 0X1C, 0X5C, 0XB6, 0X38, 0X4A,
713 0X88, 0X71, 0X59, 0X5A, 0X8D, 0XA0, 0X09, 0XAF,
714 0X72, 0X94, 0XD7, 0X79, 0X5C, 0X60, 0X7C, 0X8F,
715 0X4C, 0XF5, 0XD9, 0XA1, 0X39, 0X6D, 0X81, 0X28,
716 0XEF, 0X13, 0X28, 0XDF, 0XF5, 0X3E, 0XF7, 0X8E,
717 0X09, 0X9C, 0X78, 0X18, 0X79, 0XB8, 0X68, 0XD7,
718 0XA8, 0X29, 0X62, 0XAD, 0XDE, 0XE1, 0X61, 0X76,
719 0X1B, 0X05, 0X16, 0XCD, 0XBF, 0X02, 0X8E, 0XA6,
720 0X43, 0X6E, 0X92, 0X55, 0X4F, 0X60, 0X9C, 0X03,
721 0XB8, 0X4F, 0XA3, 0X02, 0XAC, 0XA8, 0XA7, 0X0C,
722 0X1E, 0XB5, 0X6B, 0XF8, 0XC8, 0X4D, 0XDE, 0XD2,
723 0XB0, 0X29, 0X6E, 0X40, 0XE6, 0XD6, 0XC9, 0XE6,
724 0XB9, 0X0F, 0XB6, 0X63, 0XF5, 0XAA, 0X2B, 0X96,
725 0XA7, 0X16, 0XAC, 0X4E, 0X0A, 0X33, 0X1C, 0XA6,
726 0XE6, 0XBD, 0X8A, 0XCF, 0X40, 0XA9, 0XB2, 0XFA,
727 0X63, 0X27, 0XFD, 0X9B, 0XD9, 0XFC, 0XD5, 0X87,
728 0X8D, 0X4C, 0XB6, 0XA4, 0XCB, 0XE7, 0X74, 0X55,
729 0XF4, 0XFB, 0X41, 0X25, 0XB5, 0X4B, 0X0A, 0X1B,
730 0XB1, 0XD6, 0XB7, 0XD9, 0X47, 0X2A, 0XC3, 0X98,
731 0X6A, 0XC4, 0X03, 0X73, 0X1F, 0X93, 0X6E, 0X53,
732 0X19, 0X25, 0X64, 0X15, 0X83, 0XF9, 0X73, 0X2A,
733 0X74, 0XB4, 0X93, 0X69, 0XC4, 0X72, 0XFC, 0X26,
734 0XA2, 0X9F, 0X43, 0X45, 0XDD, 0XB9, 0XEF, 0X36,
735 0XC8, 0X3A, 0XCD, 0X99, 0X9B, 0X54, 0X1A, 0X36,
736 0XC1, 0X59, 0XF8, 0X98, 0XA8, 0XCC, 0X28, 0X0D,
737 0X73, 0X4C, 0XEE, 0X98, 0XCB, 0X7C, 0X58, 0X7E,
738 0X20, 0X75, 0X1E, 0XB7, 0XC9, 0XF8, 0XF2, 0X0E,
739 0X63, 0X9E, 0X05, 0X78, 0X1A, 0XB6, 0XA8, 0X7A,
740 0XF9, 0X98, 0X6A, 0XA6, 0X46, 0X84, 0X2E, 0XF6,
741 0X4B, 0XDC, 0X9B, 0X8F, 0X9B, 0X8F, 0XEE, 0XB4,
742 0XAA, 0X3F, 0XEE, 0XC0, 0X37, 0X27, 0X76, 0XC7,
743 0X95, 0XBB, 0X26, 0X74, 0X69, 0X12, 0X7F, 0XF1,
744 0XBB, 0XFF, 0XAE, 0XB5, 0X99, 0X6E, 0XCB, 0X0C
747 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
748 0x9a, 0X4f, 0X88, 0X1b, 0Xb6, 0X8f, 0Xd8, 0X60,
749 0X42, 0X1a, 0X7d, 0X3d, 0Xf5, 0X82, 0X80, 0Xf1,
750 0X18, 0X8c, 0X1d, 0X32 };
754 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
756 struct crypto_testsuite_params *ts_params = &testsuite_params;
757 struct crypto_unittest_params *ut_params = &unittest_params;
759 /* Generate test mbuf data and space for digest */
760 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
761 catch_22_quote, QUOTE_512_BYTES, 0);
763 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
764 DIGEST_BYTE_LENGTH_SHA1);
765 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
767 /* Setup Cipher Parameters */
768 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
769 ut_params->cipher_xform.next = &ut_params->auth_xform;
771 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
772 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
773 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
774 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
776 /* Setup HMAC Parameters */
778 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
779 ut_params->auth_xform.next = NULL;
781 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
782 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
783 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
784 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
785 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
787 /* Create Crypto session*/
788 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
789 &ut_params->cipher_xform);
790 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
792 /* Generate Crypto op data structure */
793 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
794 RTE_PKTMBUF_OL_CRYPTO);
795 TEST_ASSERT_NOT_NULL(ut_params->ol,
796 "Failed to allocate pktmbuf offload");
798 ut_params->op = &ut_params->ol->op.crypto;
800 /* Set crypto operation data parameters */
801 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
803 ut_params->op->digest.data = ut_params->digest;
804 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
805 ut_params->ibuf, QUOTE_512_BYTES);
806 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
808 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
809 CIPHER_IV_LENGTH_AES_CBC);
810 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
811 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
813 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
814 CIPHER_IV_LENGTH_AES_CBC);
816 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
817 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
818 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
819 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
821 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
823 /* Process crypto operation */
824 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
826 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
829 TEST_ASSERT_BUFFERS_ARE_EQUAL(
830 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
831 CIPHER_IV_LENGTH_AES_CBC,
832 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
834 "Ciphertext data not as expected");
836 TEST_ASSERT_BUFFERS_ARE_EQUAL(
837 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
838 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
839 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
840 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
841 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
842 DIGEST_BYTE_LENGTH_SHA1,
843 "Generated digest data not as expected");
849 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
851 struct crypto_testsuite_params *ts_params = &testsuite_params;
852 struct crypto_unittest_params *ut_params = &unittest_params;
854 /* Generate test mbuf data and space for digest */
855 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
856 catch_22_quote, QUOTE_512_BYTES, 0);
858 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
859 DIGEST_BYTE_LENGTH_SHA1);
860 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
862 /* Generate Crypto op data structure */
863 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
864 RTE_PKTMBUF_OL_CRYPTO);
865 TEST_ASSERT_NOT_NULL(ut_params->ol,
866 "Failed to allocate pktmbuf offload");
868 ut_params->op = &ut_params->ol->op.crypto;
870 TEST_ASSERT_NOT_NULL(rte_pktmbuf_offload_alloc_crypto_xforms(
872 "failed to allocate space for crypto transforms");
874 /* Set crypto operation data parameters */
875 ut_params->op->xform->type = RTE_CRYPTO_XFORM_CIPHER;
877 /* cipher parameters */
878 ut_params->op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
879 ut_params->op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
880 ut_params->op->xform->cipher.key.data = aes_cbc_key;
881 ut_params->op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
883 /* hash parameters */
884 ut_params->op->xform->next->type = RTE_CRYPTO_XFORM_AUTH;
886 ut_params->op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
887 ut_params->op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
888 ut_params->op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
889 ut_params->op->xform->next->auth.key.data = hmac_sha1_key;
890 ut_params->op->xform->next->auth.digest_length =
891 DIGEST_BYTE_LENGTH_SHA1;
893 ut_params->op->digest.data = ut_params->digest;
894 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
895 ut_params->ibuf, QUOTE_512_BYTES);
896 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
898 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
899 CIPHER_IV_LENGTH_AES_CBC);
900 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
901 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
903 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
904 CIPHER_IV_LENGTH_AES_CBC);
906 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
907 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
908 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
909 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
911 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
913 /* Process crypto operation */
914 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
916 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
919 TEST_ASSERT_BUFFERS_ARE_EQUAL(
920 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
921 CIPHER_IV_LENGTH_AES_CBC,
922 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
924 "Ciphertext data not as expected");
926 TEST_ASSERT_BUFFERS_ARE_EQUAL(
927 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
928 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
929 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
930 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
931 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
932 DIGEST_BYTE_LENGTH_SHA1,
933 "Generated digest data not as expected");
940 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
942 struct crypto_testsuite_params *ts_params = &testsuite_params;
943 struct crypto_unittest_params *ut_params = &unittest_params;
945 /* Generate test mbuf data and digest */
946 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
948 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
951 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
952 DIGEST_BYTE_LENGTH_SHA1);
953 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
955 rte_memcpy(ut_params->digest,
956 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
957 DIGEST_BYTE_LENGTH_SHA1);
959 /* Setup Cipher Parameters */
960 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
961 ut_params->cipher_xform.next = NULL;
963 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
964 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
965 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
966 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
968 /* Setup HMAC Parameters */
969 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
970 ut_params->auth_xform.next = &ut_params->cipher_xform;
972 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
973 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
974 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
975 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
976 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
978 /* Create Crypto session*/
979 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
980 &ut_params->auth_xform);
981 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
983 /* Generate Crypto op data structure */
984 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
985 RTE_PKTMBUF_OL_CRYPTO);
986 TEST_ASSERT_NOT_NULL(ut_params->ol,
987 "Failed to allocate pktmbuf offload");
989 ut_params->op = &ut_params->ol->op.crypto;
992 /* Set crypto operation data parameters */
993 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
995 ut_params->op->digest.data = ut_params->digest;
996 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
997 ut_params->ibuf, QUOTE_512_BYTES);
998 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
1000 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1001 CIPHER_IV_LENGTH_AES_CBC);
1002 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1003 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1005 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1006 CIPHER_IV_LENGTH_AES_CBC);
1008 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1009 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1011 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1012 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1014 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1016 /* Process crypto operation */
1017 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1019 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1022 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1023 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1024 CIPHER_IV_LENGTH_AES_CBC,
1027 "Ciphertext data not as expected");
1029 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1030 "Digest verification failed");
1033 return TEST_SUCCESS;
1037 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1039 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1041 static uint8_t hmac_sha256_key[] = {
1042 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1043 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1044 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1045 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1047 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1048 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1049 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1050 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1051 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1054 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1056 struct crypto_testsuite_params *ts_params = &testsuite_params;
1057 struct crypto_unittest_params *ut_params = &unittest_params;
1059 /* Generate test mbuf data and space for digest */
1060 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1061 catch_22_quote, QUOTE_512_BYTES, 0);
1063 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1064 DIGEST_BYTE_LENGTH_SHA256);
1065 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1067 /* Setup Cipher Parameters */
1068 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1069 ut_params->cipher_xform.next = &ut_params->auth_xform;
1071 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1072 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1073 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1074 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1076 /* Setup HMAC Parameters */
1077 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1078 ut_params->auth_xform.next = NULL;
1080 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1081 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1082 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1083 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1084 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1086 /* Create Crypto session*/
1087 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1088 &ut_params->cipher_xform);
1089 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1091 /* Generate Crypto op data structure */
1092 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1093 RTE_PKTMBUF_OL_CRYPTO);
1094 TEST_ASSERT_NOT_NULL(ut_params->ol,
1095 "Failed to allocate pktmbuf offload");
1097 ut_params->op = &ut_params->ol->op.crypto;
1100 /* Set crypto operation data parameters */
1101 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1103 ut_params->op->digest.data = ut_params->digest;
1104 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1105 ut_params->ibuf, QUOTE_512_BYTES);
1106 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA256;
1108 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1109 CIPHER_IV_LENGTH_AES_CBC);
1110 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1111 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1113 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1114 CIPHER_IV_LENGTH_AES_CBC);
1116 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1117 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1118 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1119 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1121 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1123 /* Process crypto operation */
1124 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1126 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1129 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1130 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1131 CIPHER_IV_LENGTH_AES_CBC,
1132 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1134 "Ciphertext data not as expected");
1136 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1137 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1138 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1139 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1140 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1141 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1142 DIGEST_BYTE_LENGTH_SHA256,
1143 "Generated digest data not as expected");
1146 return TEST_SUCCESS;
1150 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1152 struct crypto_testsuite_params *ts_params = &testsuite_params;
1153 struct crypto_unittest_params *ut_params = &unittest_params;
1155 /* Generate test mbuf data and digest */
1156 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1158 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1159 QUOTE_512_BYTES, 0);
1161 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1162 DIGEST_BYTE_LENGTH_SHA256);
1163 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1165 rte_memcpy(ut_params->digest,
1166 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1167 DIGEST_BYTE_LENGTH_SHA256);
1169 /* Setup Cipher Parameters */
1170 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1171 ut_params->cipher_xform.next = NULL;
1173 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1174 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1175 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1176 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1178 /* Setup HMAC Parameters */
1179 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1180 ut_params->auth_xform.next = &ut_params->cipher_xform;
1182 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1183 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1184 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1185 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1186 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1188 /* Create Crypto session*/
1189 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1190 &ut_params->auth_xform);
1191 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1193 /* Generate Crypto op data structure */
1194 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1195 RTE_PKTMBUF_OL_CRYPTO);
1196 TEST_ASSERT_NOT_NULL(ut_params->ol,
1197 "Failed to allocate pktmbuf offload");
1199 ut_params->op = &ut_params->ol->op.crypto;
1202 /* Set crypto operation data parameters */
1203 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1205 ut_params->op->digest.data = ut_params->digest;
1206 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1207 ut_params->ibuf, QUOTE_512_BYTES);
1208 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA256;
1210 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1211 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1212 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1213 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1215 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1216 CIPHER_IV_LENGTH_AES_CBC);
1218 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1219 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1221 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1222 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1224 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1226 /* Process crypto operation */
1227 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1229 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1232 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1233 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1234 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1236 "Plaintext data not as expected");
1238 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1239 "Digest verification failed");
1242 return TEST_SUCCESS;
1245 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1247 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1249 static uint8_t hmac_sha512_key[] = {
1250 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1251 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1252 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1253 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1254 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1255 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1256 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1257 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1259 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1260 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1261 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1262 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1263 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1264 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1265 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1266 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1267 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1270 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1272 struct crypto_testsuite_params *ts_params = &testsuite_params;
1273 struct crypto_unittest_params *ut_params = &unittest_params;
1275 /* Generate test mbuf data and space for digest */
1276 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1277 catch_22_quote, QUOTE_512_BYTES, 0);
1279 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1280 DIGEST_BYTE_LENGTH_SHA512);
1281 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1283 /* Setup Cipher Parameters */
1284 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1285 ut_params->cipher_xform.next = &ut_params->auth_xform;
1287 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1288 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1289 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1290 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1292 /* Setup HMAC Parameters */
1293 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1294 ut_params->auth_xform.next = NULL;
1296 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1297 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1298 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1299 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1300 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1302 /* Create Crypto session*/
1303 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1304 &ut_params->cipher_xform);
1306 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1309 /* Generate Crypto op data structure */
1310 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1311 RTE_PKTMBUF_OL_CRYPTO);
1312 TEST_ASSERT_NOT_NULL(ut_params->ol,
1313 "Failed to allocate pktmbuf offload");
1315 ut_params->op = &ut_params->ol->op.crypto;
1318 /* Set crypto operation data parameters */
1319 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1321 ut_params->op->digest.data = ut_params->digest;
1322 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1323 ut_params->ibuf, QUOTE_512_BYTES);
1324 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1326 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1327 CIPHER_IV_LENGTH_AES_CBC);
1328 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1329 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1331 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1332 CIPHER_IV_LENGTH_AES_CBC);
1334 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1335 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1336 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1337 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1339 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1341 /* Process crypto operation */
1342 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1344 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1347 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1348 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1349 CIPHER_IV_LENGTH_AES_CBC,
1350 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1352 "Ciphertext data not as expected");
1354 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1355 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1356 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1357 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1358 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1359 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1360 DIGEST_BYTE_LENGTH_SHA512,
1361 "Generated digest data not as expected");
1364 return TEST_SUCCESS;
1369 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1370 struct crypto_unittest_params *ut_params);
1373 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_session *sess,
1374 struct crypto_unittest_params *ut_params,
1375 struct crypto_testsuite_params *ts_params);
1378 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1380 struct crypto_unittest_params *ut_params = &unittest_params;
1381 struct crypto_testsuite_params *ts_params = &testsuite_params;
1383 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1384 ut_params) == TEST_SUCCESS,
1385 "Failed to create session params");
1387 /* Create Crypto session*/
1388 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1389 &ut_params->auth_xform);
1390 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1392 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1393 ut_params, ts_params);
1397 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1398 struct crypto_unittest_params *ut_params)
1401 /* Setup Cipher Parameters */
1402 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1403 ut_params->cipher_xform.next = NULL;
1405 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1406 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1407 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1408 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1410 /* Setup HMAC Parameters */
1411 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1412 ut_params->auth_xform.next = &ut_params->cipher_xform;
1414 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1415 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1416 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1417 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1418 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1419 return TEST_SUCCESS;
1424 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_session *sess,
1425 struct crypto_unittest_params *ut_params,
1426 struct crypto_testsuite_params *ts_params)
1428 /* Generate test mbuf data and digest */
1429 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1431 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1432 QUOTE_512_BYTES, 0);
1434 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1435 DIGEST_BYTE_LENGTH_SHA512);
1436 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1438 rte_memcpy(ut_params->digest,
1439 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1440 DIGEST_BYTE_LENGTH_SHA512);
1442 /* Generate Crypto op data structure */
1443 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1444 RTE_PKTMBUF_OL_CRYPTO);
1445 TEST_ASSERT_NOT_NULL(ut_params->ol,
1446 "Failed to allocate pktmbuf offload");
1448 ut_params->op = &ut_params->ol->op.crypto;
1451 /* Set crypto operation data parameters */
1452 rte_crypto_op_attach_session(ut_params->op, sess);
1454 ut_params->op->digest.data = ut_params->digest;
1455 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1456 ut_params->ibuf, QUOTE_512_BYTES);
1457 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1459 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1460 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1461 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys_offset(
1462 ut_params->ibuf, 0);
1463 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1465 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1466 CIPHER_IV_LENGTH_AES_CBC);
1468 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1469 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1471 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1472 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1474 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1476 /* Process crypto operation */
1477 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1479 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1482 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1483 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1484 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1486 "Plaintext data not as expected");
1489 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1490 "Digest verification failed");
1494 return TEST_SUCCESS;
1497 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1499 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1500 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1501 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1504 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1505 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1506 0x77, 0x1D, 0x8B, 0x75
1510 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1512 struct crypto_testsuite_params *ts_params = &testsuite_params;
1513 struct crypto_unittest_params *ut_params = &unittest_params;
1515 /* Generate test mbuf data and space for digest */
1516 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1517 catch_22_quote, QUOTE_512_BYTES, 0);
1519 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1520 DIGEST_BYTE_LENGTH_AES_XCBC);
1521 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1523 /* Setup Cipher Parameters */
1524 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1525 ut_params->cipher_xform.next = &ut_params->auth_xform;
1527 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1528 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1529 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1530 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1532 /* Setup HMAC Parameters */
1533 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1534 ut_params->auth_xform.next = NULL;
1536 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1537 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1538 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1539 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1540 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1542 /* Create Crypto session*/
1543 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1544 &ut_params->cipher_xform);
1545 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1547 /* Generate Crypto op data structure */
1548 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1549 RTE_PKTMBUF_OL_CRYPTO);
1550 TEST_ASSERT_NOT_NULL(ut_params->ol,
1551 "Failed to allocate pktmbuf offload");
1553 ut_params->op = &ut_params->ol->op.crypto;
1556 /* Set crypto operation data parameters */
1557 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1559 ut_params->op->iv.data = (uint8_t *)
1560 rte_pktmbuf_prepend(ut_params->ibuf,
1561 CIPHER_IV_LENGTH_AES_CBC);
1562 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1563 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1565 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1566 CIPHER_IV_LENGTH_AES_CBC);
1568 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1569 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1570 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1571 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1573 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1575 /* Process crypto operation */
1576 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1578 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1581 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1582 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1583 CIPHER_IV_LENGTH_AES_CBC,
1584 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1586 "Ciphertext data not as expected");
1587 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1588 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1589 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1590 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1591 DIGEST_BYTE_LENGTH_AES_XCBC,
1592 "Generated digest data not as expected");
1594 return TEST_SUCCESS;
1598 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1600 struct crypto_testsuite_params *ts_params = &testsuite_params;
1601 struct crypto_unittest_params *ut_params = &unittest_params;
1603 /* Generate test mbuf data and space for digest */
1604 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1605 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1606 QUOTE_512_BYTES, 0);
1608 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1609 DIGEST_BYTE_LENGTH_AES_XCBC);
1610 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1612 rte_memcpy(ut_params->digest,
1613 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1614 DIGEST_BYTE_LENGTH_AES_XCBC);
1616 /* Setup Cipher Parameters */
1617 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1618 ut_params->cipher_xform.next = NULL;
1620 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1621 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1622 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1623 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1625 /* Setup HMAC Parameters */
1626 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1627 ut_params->auth_xform.next = &ut_params->cipher_xform;
1629 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1630 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1631 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1632 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1633 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1635 /* Create Crypto session*/
1636 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1637 &ut_params->auth_xform);
1638 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1640 /* Generate Crypto op data structure */
1641 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1642 RTE_PKTMBUF_OL_CRYPTO);
1643 TEST_ASSERT_NOT_NULL(ut_params->ol,
1644 "Failed to allocate pktmbuf offload");
1646 ut_params->op = &ut_params->ol->op.crypto;
1649 /* Set crypto operation data parameters */
1650 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1652 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1653 CIPHER_IV_LENGTH_AES_CBC);
1654 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1655 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1657 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1658 CIPHER_IV_LENGTH_AES_CBC);
1660 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1661 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1662 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1663 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1664 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1666 /* Process crypto operation */
1667 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1669 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1672 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1673 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1674 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1676 "Ciphertext data not as expected");
1678 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1679 "Digest verification failed");
1681 return TEST_SUCCESS;
1685 /* ***** AES-GCM Tests ***** */
1690 struct crypto_testsuite_params *ts_params = &testsuite_params;
1691 struct rte_cryptodev_stats stats;
1692 struct rte_cryptodev *dev;
1693 cryptodev_stats_get_t temp_pfn;
1695 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1696 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
1697 &stats) == -ENODEV),
1698 "rte_cryptodev_stats_get invalid dev failed");
1699 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
1700 "rte_cryptodev_stats_get invalid Param failed");
1701 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
1702 temp_pfn = dev->dev_ops->stats_get;
1703 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
1704 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
1706 "rte_cryptodev_stats_get invalid Param failed");
1707 dev->dev_ops->stats_get = temp_pfn;
1709 /* Test expected values */
1711 test_AES_CBC_HMAC_SHA1_encrypt_digest();
1713 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1715 "rte_cryptodev_stats_get failed");
1716 TEST_ASSERT((stats.enqueued_count == 1),
1717 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1718 TEST_ASSERT((stats.dequeued_count == 1),
1719 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1720 TEST_ASSERT((stats.enqueue_err_count == 0),
1721 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1722 TEST_ASSERT((stats.dequeue_err_count == 0),
1723 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1725 /* invalid device but should ignore and not reset device stats*/
1726 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
1727 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1729 "rte_cryptodev_stats_get failed");
1730 TEST_ASSERT((stats.enqueued_count == 1),
1731 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1733 /* check that a valid reset clears stats */
1734 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
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 == 0),
1739 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1740 TEST_ASSERT((stats.dequeued_count == 0),
1741 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1743 return TEST_SUCCESS;
1748 test_multi_session(void)
1750 struct crypto_testsuite_params *ts_params = &testsuite_params;
1751 struct crypto_unittest_params *ut_params = &unittest_params;
1753 struct rte_cryptodev_info dev_info;
1754 struct rte_cryptodev_session **sessions;
1758 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1761 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
1763 sessions = rte_malloc(NULL, (sizeof(struct rte_cryptodev_session *) *
1764 dev_info.max_nb_sessions) + 1, 0);
1766 /* Create multiple crypto sessions*/
1767 for (i = 0; i < dev_info.max_nb_sessions; i++) {
1768 sessions[i] = rte_cryptodev_session_create(
1769 ts_params->valid_devs[0],
1770 &ut_params->auth_xform);
1771 TEST_ASSERT_NOT_NULL(sessions[i],
1772 "Session creation failed at session number %u",
1775 /* Attempt to send a request on each session */
1776 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
1777 sessions[i], ut_params, ts_params),
1778 "Failed to perform decrypt on request "
1782 /* Next session create should fail */
1783 sessions[i] = rte_cryptodev_session_create(ts_params->valid_devs[0],
1784 &ut_params->auth_xform);
1785 TEST_ASSERT_NULL(sessions[i],
1786 "Session creation succeeded unexpectedly!");
1788 for (i = 0; i < dev_info.max_nb_sessions; i++)
1789 rte_cryptodev_session_free(ts_params->valid_devs[0],
1794 return TEST_SUCCESS;
1798 test_not_in_place_crypto(void)
1800 struct crypto_testsuite_params *ts_params = &testsuite_params;
1801 struct crypto_unittest_params *ut_params = &unittest_params;
1802 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1804 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1806 /* Create multiple crypto sessions*/
1808 ut_params->sess = rte_cryptodev_session_create(
1809 ts_params->valid_devs[0], &ut_params->auth_xform);
1811 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1814 /* Generate test mbuf data and digest */
1815 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1817 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1818 QUOTE_512_BYTES, 0);
1820 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1821 DIGEST_BYTE_LENGTH_SHA512);
1822 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1824 rte_memcpy(ut_params->digest,
1825 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1826 DIGEST_BYTE_LENGTH_SHA512);
1828 /* Generate Crypto op data structure */
1829 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1830 RTE_PKTMBUF_OL_CRYPTO);
1831 TEST_ASSERT_NOT_NULL(ut_params->ol,
1832 "Failed to allocate pktmbuf offload");
1834 ut_params->op = &ut_params->ol->op.crypto;
1837 /* Set crypto operation data parameters */
1838 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1840 ut_params->op->digest.data = ut_params->digest;
1841 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1842 ut_params->ibuf, QUOTE_512_BYTES);
1843 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1845 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1846 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1847 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys_offset(
1848 ut_params->ibuf, 0);
1849 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1851 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1852 CIPHER_IV_LENGTH_AES_CBC);
1854 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1855 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1857 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1858 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1860 ut_params->op->dst.m = dst_m;
1861 ut_params->op->dst.offset = 0;
1863 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1865 /* Process crypto operation */
1866 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1868 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1871 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1872 rte_pktmbuf_mtod(ut_params->op->dst.m, char *),
1875 "Plaintext data not as expected");
1879 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1880 "Digest verification failed");
1882 return TEST_SUCCESS;
1886 static struct unit_test_suite cryptodev_qat_testsuite = {
1887 .suite_name = "Crypto QAT Unit Test Suite",
1888 .setup = testsuite_setup,
1889 .teardown = testsuite_teardown,
1890 .unit_test_cases = {
1891 TEST_CASE_ST(ut_setup, ut_teardown,
1892 test_device_configure_invalid_dev_id),
1893 TEST_CASE_ST(ut_setup, ut_teardown,
1894 test_device_configure_invalid_queue_pair_ids),
1895 TEST_CASE_ST(ut_setup, ut_teardown,
1896 test_queue_pair_descriptor_setup),
1897 TEST_CASE_ST(ut_setup, ut_teardown,
1898 test_multi_session),
1900 TEST_CASE_ST(ut_setup, ut_teardown,
1901 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1902 TEST_CASE_ST(ut_setup, ut_teardown,
1903 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1905 TEST_CASE_ST(ut_setup, ut_teardown,
1906 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1907 TEST_CASE_ST(ut_setup, ut_teardown,
1908 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1910 TEST_CASE_ST(ut_setup, ut_teardown,
1911 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1912 TEST_CASE_ST(ut_setup, ut_teardown,
1913 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1915 TEST_CASE_ST(ut_setup, ut_teardown,
1916 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1917 TEST_CASE_ST(ut_setup, ut_teardown,
1918 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1920 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
1922 TEST_CASES_END() /**< NULL terminate unit test array */
1926 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
1927 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
1928 .setup = testsuite_setup,
1929 .teardown = testsuite_teardown,
1930 .unit_test_cases = {
1931 TEST_CASE_ST(ut_setup, ut_teardown,
1932 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1933 TEST_CASE_ST(ut_setup, ut_teardown,
1934 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1936 TEST_CASE_ST(ut_setup, ut_teardown,
1937 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1938 TEST_CASE_ST(ut_setup, ut_teardown,
1939 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1941 TEST_CASE_ST(ut_setup, ut_teardown,
1942 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1943 TEST_CASE_ST(ut_setup, ut_teardown,
1944 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1946 TEST_CASE_ST(ut_setup, ut_teardown,
1947 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1948 TEST_CASE_ST(ut_setup, ut_teardown,
1949 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1951 TEST_CASE_ST(ut_setup, ut_teardown,
1952 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
1954 TEST_CASE_ST(ut_setup, ut_teardown,
1955 test_not_in_place_crypto),
1957 TEST_CASES_END() /**< NULL terminate unit test array */
1962 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
1964 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_PMD;
1965 return unit_test_suite_runner(&cryptodev_qat_testsuite);
1967 static struct test_command cryptodev_qat_cmd = {
1968 .command = "cryptodev_qat_autotest",
1969 .callback = test_cryptodev_qat,
1973 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
1975 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
1977 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
1980 static struct test_command cryptodev_aesni_mb_cmd = {
1981 .command = "cryptodev_aesni_mb_autotest",
1982 .callback = test_cryptodev_aesni_mb,
1985 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
1986 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);