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;
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,
168 DEFAULT_NUM_XFORMS * sizeof(struct rte_crypto_xform),
170 if (ts_params->mbuf_ol_pool == NULL) {
171 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
175 /* Create 2 AESNI MB devices if required */
176 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
177 nb_devs = rte_cryptodev_count_devtype(
178 RTE_CRYPTODEV_AESNI_MB_PMD);
180 for (i = nb_devs; i < 2; i++) {
181 ret = rte_eal_vdev_init(
182 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
184 TEST_ASSERT(ret == 0,
185 "Failed to create instance %u of"
187 i, CRYPTODEV_NAME_AESNI_MB_PMD);
192 nb_devs = rte_cryptodev_count();
194 RTE_LOG(ERR, USER1, "No crypto devices found?");
198 /* Create list of valid crypto devs */
199 for (i = 0; i < nb_devs; i++) {
200 rte_cryptodev_info_get(i, &info);
201 if (info.dev_type == gbl_cryptodev_type)
202 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
205 if (ts_params->valid_dev_count < 1)
208 /* Set up all the qps on the first of the valid devices found */
209 for (i = 0; i < 1; i++) {
210 dev_id = ts_params->valid_devs[i];
212 rte_cryptodev_info_get(dev_id, &info);
215 * Since we can't free and re-allocate queue memory always set
216 * the queues on this device up to max size first so enough
217 * memory is allocated for any later re-configures needed by
221 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
222 ts_params->conf.socket_id = SOCKET_ID_ANY;
223 ts_params->conf.session_mp.nb_objs = info.max_nb_sessions;
225 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
227 "Failed to configure cryptodev %u with %u qps",
228 dev_id, ts_params->conf.nb_queue_pairs);
230 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
232 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
233 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
234 dev_id, qp_id, &ts_params->qp_conf,
235 rte_cryptodev_socket_id(dev_id)),
236 "Failed to setup queue pair %u on "
246 testsuite_teardown(void)
248 struct crypto_testsuite_params *ts_params = &testsuite_params;
250 if (ts_params->mbuf_pool != NULL) {
251 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
252 rte_mempool_count(ts_params->mbuf_pool));
256 if (ts_params->mbuf_ol_pool != NULL) {
257 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
258 rte_mempool_count(ts_params->mbuf_ol_pool));
266 struct crypto_testsuite_params *ts_params = &testsuite_params;
267 struct crypto_unittest_params *ut_params = &unittest_params;
271 /* Clear unit test parameters before running test */
272 memset(ut_params, 0, sizeof(*ut_params));
274 /* Reconfigure device to default parameters */
275 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
276 ts_params->conf.socket_id = SOCKET_ID_ANY;
277 ts_params->conf.session_mp.nb_objs =
278 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_PMD) ?
279 DEFAULT_NUM_OPS_INFLIGHT :
280 DEFAULT_NUM_OPS_INFLIGHT;
282 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
284 "Failed to configure cryptodev %u",
285 ts_params->valid_devs[0]);
288 * Now reconfigure queues to size we actually want to use in this
291 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
293 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
294 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
295 ts_params->valid_devs[0], qp_id,
297 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
298 "Failed to setup queue pair %u on cryptodev %u",
299 qp_id, ts_params->valid_devs[0]);
303 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
305 /* Start the device */
306 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
307 "Failed to start cryptodev %u",
308 ts_params->valid_devs[0]);
316 struct crypto_testsuite_params *ts_params = &testsuite_params;
317 struct crypto_unittest_params *ut_params = &unittest_params;
318 struct rte_cryptodev_stats stats;
320 /* free crypto session structure */
321 if (ut_params->sess) {
322 rte_cryptodev_session_free(ts_params->valid_devs[0],
324 ut_params->sess = NULL;
327 /* free crypto operation structure */
329 rte_pktmbuf_offload_free(ut_params->ol);
332 * free mbuf - both obuf and ibuf are usually the same,
333 * but rte copes even if we call free twice
335 if (ut_params->obuf) {
336 rte_pktmbuf_free(ut_params->obuf);
339 if (ut_params->ibuf) {
340 rte_pktmbuf_free(ut_params->ibuf);
344 if (ts_params->mbuf_pool != NULL)
345 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
346 rte_mempool_count(ts_params->mbuf_pool));
348 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
350 /* Stop the device */
351 rte_cryptodev_stop(ts_params->valid_devs[0]);
355 test_device_configure_invalid_dev_id(void)
357 struct crypto_testsuite_params *ts_params = &testsuite_params;
358 uint16_t dev_id, num_devs = 0;
360 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
361 "Need at least %d devices for test", 1);
363 /* valid dev_id values */
364 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
366 /* Stop the device in case it's started so it can be configured */
367 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
369 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
370 "Failed test for rte_cryptodev_configure: "
371 "invalid dev_num %u", dev_id);
373 /* invalid dev_id values */
376 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
377 "Failed test for rte_cryptodev_configure: "
378 "invalid dev_num %u", dev_id);
382 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
383 "Failed test for rte_cryptodev_configure:"
384 "invalid dev_num %u", dev_id);
390 test_device_configure_invalid_queue_pair_ids(void)
392 struct crypto_testsuite_params *ts_params = &testsuite_params;
394 /* Stop the device in case it's started so it can be configured */
395 rte_cryptodev_stop(ts_params->valid_devs[0]);
397 /* valid - one queue pairs */
398 ts_params->conf.nb_queue_pairs = 1;
400 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
402 "Failed to configure cryptodev: dev_id %u, qp_id %u",
403 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
406 /* valid - max value queue pairs */
407 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
409 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
411 "Failed to configure cryptodev: dev_id %u, qp_id %u",
412 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
415 /* invalid - zero queue pairs */
416 ts_params->conf.nb_queue_pairs = 0;
418 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
420 "Failed test for rte_cryptodev_configure, dev_id %u,"
422 ts_params->valid_devs[0],
423 ts_params->conf.nb_queue_pairs);
426 /* invalid - max value supported by field queue pairs */
427 ts_params->conf.nb_queue_pairs = UINT16_MAX;
429 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
431 "Failed test for rte_cryptodev_configure, dev_id %u,"
433 ts_params->valid_devs[0],
434 ts_params->conf.nb_queue_pairs);
437 /* invalid - max value + 1 queue pairs */
438 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
440 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
442 "Failed test for rte_cryptodev_configure, dev_id %u,"
444 ts_params->valid_devs[0],
445 ts_params->conf.nb_queue_pairs);
451 test_queue_pair_descriptor_setup(void)
453 struct crypto_testsuite_params *ts_params = &testsuite_params;
454 struct rte_cryptodev_info dev_info;
455 struct rte_cryptodev_qp_conf qp_conf = {
456 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
461 /* Stop the device in case it's started so it can be configured */
462 rte_cryptodev_stop(ts_params->valid_devs[0]);
465 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
467 ts_params->conf.session_mp.nb_objs = dev_info.max_nb_sessions;
469 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
470 &ts_params->conf), "Failed to configure cryptodev %u",
471 ts_params->valid_devs[0]);
475 * Test various ring sizes on this device. memzones can't be
476 * freed so are re-used if ring is released and re-created.
478 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
480 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
481 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
482 ts_params->valid_devs[0], qp_id, &qp_conf,
483 rte_cryptodev_socket_id(
484 ts_params->valid_devs[0])),
486 "rte_cryptodev_queue_pair_setup: num_inflights "
487 "%u on qp %u on cryptodev %u",
488 qp_conf.nb_descriptors, qp_id,
489 ts_params->valid_devs[0]);
492 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
494 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
495 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
496 ts_params->valid_devs[0], qp_id, &qp_conf,
497 rte_cryptodev_socket_id(
498 ts_params->valid_devs[0])),
500 " rte_cryptodev_queue_pair_setup: num_inflights"
501 " %u on qp %u on cryptodev %u",
502 qp_conf.nb_descriptors, qp_id,
503 ts_params->valid_devs[0]);
506 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
508 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
509 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
510 ts_params->valid_devs[0], qp_id, &qp_conf,
511 rte_cryptodev_socket_id(
512 ts_params->valid_devs[0])),
514 "rte_cryptodev_queue_pair_setup: num_inflights"
515 " %u on qp %u on cryptodev %u",
516 qp_conf.nb_descriptors, qp_id,
517 ts_params->valid_devs[0]);
520 /* invalid number of descriptors - max supported + 2 */
521 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
523 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
524 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
525 ts_params->valid_devs[0], qp_id, &qp_conf,
526 rte_cryptodev_socket_id(
527 ts_params->valid_devs[0])),
528 "Unexpectedly passed test for "
529 "rte_cryptodev_queue_pair_setup:"
530 "num_inflights %u on qp %u on cryptodev %u",
531 qp_conf.nb_descriptors, qp_id,
532 ts_params->valid_devs[0]);
535 /* invalid number of descriptors - max value of parameter */
536 qp_conf.nb_descriptors = UINT32_MAX-1;
538 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
539 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
540 ts_params->valid_devs[0], qp_id, &qp_conf,
541 rte_cryptodev_socket_id(
542 ts_params->valid_devs[0])),
543 "Unexpectedly passed test for "
544 "rte_cryptodev_queue_pair_setup:"
545 "num_inflights %u on qp %u on cryptodev %u",
546 qp_conf.nb_descriptors, qp_id,
547 ts_params->valid_devs[0]);
550 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
552 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
553 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
554 ts_params->valid_devs[0], qp_id, &qp_conf,
555 rte_cryptodev_socket_id(
556 ts_params->valid_devs[0])),
558 " rte_cryptodev_queue_pair_setup:"
559 "num_inflights %u on qp %u on cryptodev %u",
560 qp_conf.nb_descriptors, qp_id,
561 ts_params->valid_devs[0]);
564 /* invalid number of descriptors - max supported + 1 */
565 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
567 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
568 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
569 ts_params->valid_devs[0], qp_id, &qp_conf,
570 rte_cryptodev_socket_id(
571 ts_params->valid_devs[0])),
572 "Unexpectedly passed test for "
573 "rte_cryptodev_queue_pair_setup:"
574 "num_inflights %u on qp %u on cryptodev %u",
575 qp_conf.nb_descriptors, qp_id,
576 ts_params->valid_devs[0]);
579 /* test invalid queue pair id */
580 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
582 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
584 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
585 ts_params->valid_devs[0],
587 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
588 "Failed test for rte_cryptodev_queue_pair_setup:"
589 "invalid qp %u on cryptodev %u",
590 qp_id, ts_params->valid_devs[0]);
592 qp_id = 0xffff; /*invalid*/
594 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
595 ts_params->valid_devs[0],
597 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
598 "Failed test for rte_cryptodev_queue_pair_setup:"
599 "invalid qp %u on cryptodev %u",
600 qp_id, ts_params->valid_devs[0]);
605 /* ***** Plaintext data for tests ***** */
607 const char catch_22_quote_1[] =
608 "There was only one catch and that was Catch-22, which "
609 "specified that a concern for one's safety in the face of "
610 "dangers that were real and immediate was the process of a "
611 "rational mind. Orr was crazy and could be grounded. All he "
612 "had to do was ask; and as soon as he did, he would no longer "
613 "be crazy and would have to fly more missions. Orr would be "
614 "crazy to fly more missions and sane if he didn't, but if he "
615 "was sane he had to fly them. If he flew them he was crazy "
616 "and didn't have to; but if he didn't want to he was sane and "
617 "had to. Yossarian was moved very deeply by the absolute "
618 "simplicity of this clause of Catch-22 and let out a "
619 "respectful whistle. \"That's some catch, that Catch-22\", he "
620 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
622 const char catch_22_quote[] =
623 "What a lousy earth! He wondered how many people were "
624 "destitute that same night even in his own prosperous country, "
625 "how many homes were shanties, how many husbands were drunk "
626 "and wives socked, and how many children were bullied, abused, "
627 "or abandoned. How many families hungered for food they could "
628 "not afford to buy? How many hearts were broken? How many "
629 "suicides would take place that same night, how many people "
630 "would go insane? How many cockroaches and landlords would "
631 "triumph? How many winners were losers, successes failures, "
632 "and rich men poor men? How many wise guys were stupid? How "
633 "many happy endings were unhappy endings? How many honest men "
634 "were liars, brave men cowards, loyal men traitors, how many "
635 "sainted men were corrupt, how many people in positions of "
636 "trust had sold their souls to bodyguards, how many had never "
637 "had souls? How many straight-and-narrow paths were crooked "
638 "paths? How many best families were worst families and how "
639 "many good people were bad people? When you added them all up "
640 "and then subtracted, you might be left with only the children, "
641 "and perhaps with Albert Einstein and an old violinist or "
642 "sculptor somewhere.";
644 #define QUOTE_480_BYTES (480)
645 #define QUOTE_512_BYTES (512)
646 #define QUOTE_768_BYTES (768)
647 #define QUOTE_1024_BYTES (1024)
651 /* ***** SHA1 Hash Tests ***** */
653 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
655 static uint8_t hmac_sha1_key[] = {
656 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
657 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
658 0xDE, 0xF4, 0xDE, 0xAD };
660 /* ***** SHA224 Hash Tests ***** */
662 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
665 /* ***** AES-CBC Cipher Tests ***** */
667 #define CIPHER_KEY_LENGTH_AES_CBC (16)
668 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
670 static uint8_t aes_cbc_key[] = {
671 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
672 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
674 static uint8_t aes_cbc_iv[] = {
675 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
676 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
679 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
681 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
682 0x8B, 0X4D, 0XDA, 0X1B, 0XCF, 0X04, 0XA0, 0X31,
683 0XB4, 0XBF, 0XBD, 0X68, 0X43, 0X20, 0X7E, 0X76,
684 0XB1, 0X96, 0X8B, 0XA2, 0X7C, 0XA2, 0X83, 0X9E,
685 0X39, 0X5A, 0X2F, 0X7E, 0X92, 0XB4, 0X48, 0X1A,
686 0X3F, 0X6B, 0X5D, 0XDF, 0X52, 0X85, 0X5F, 0X8E,
687 0X42, 0X3C, 0XFB, 0XE9, 0X1A, 0X24, 0XD6, 0X08,
688 0XDD, 0XFD, 0X16, 0XFB, 0XE9, 0X55, 0XEF, 0XF0,
689 0XA0, 0X8D, 0X13, 0XAB, 0X81, 0XC6, 0X90, 0X01,
690 0XB5, 0X18, 0X84, 0XB3, 0XF6, 0XE6, 0X11, 0X57,
691 0XD6, 0X71, 0XC6, 0X3C, 0X3F, 0X2F, 0X33, 0XEE,
692 0X24, 0X42, 0X6E, 0XAC, 0X0B, 0XCA, 0XEC, 0XF9,
693 0X84, 0XF8, 0X22, 0XAA, 0X60, 0XF0, 0X32, 0XA9,
694 0X75, 0X75, 0X3B, 0XCB, 0X70, 0X21, 0X0A, 0X8D,
695 0X0F, 0XE0, 0XC4, 0X78, 0X2B, 0XF8, 0X97, 0XE3,
696 0XE4, 0X26, 0X4B, 0X29, 0XDA, 0X88, 0XCD, 0X46,
697 0XEC, 0XAA, 0XF9, 0X7F, 0XF1, 0X15, 0XEA, 0XC3,
698 0X87, 0XE6, 0X31, 0XF2, 0XCF, 0XDE, 0X4D, 0X80,
699 0X70, 0X91, 0X7E, 0X0C, 0XF7, 0X26, 0X3A, 0X92,
700 0X4F, 0X18, 0X83, 0XC0, 0X8F, 0X59, 0X01, 0XA5,
701 0X88, 0XD1, 0XDB, 0X26, 0X71, 0X27, 0X16, 0XF5,
702 0XEE, 0X10, 0X82, 0XAC, 0X68, 0X26, 0X9B, 0XE2,
703 0X6D, 0XD8, 0X9A, 0X80, 0XDF, 0X04, 0X31, 0XD5,
704 0XF1, 0X35, 0X5C, 0X3B, 0XDD, 0X9A, 0X65, 0XBA,
705 0X58, 0X34, 0X85, 0X61, 0X1C, 0X42, 0X10, 0X76,
706 0X73, 0X02, 0X42, 0XC9, 0X23, 0X18, 0X8E, 0XB4,
707 0X6F, 0XB4, 0XA3, 0X54, 0X6E, 0X88, 0X3B, 0X62,
708 0X7C, 0X02, 0X8D, 0X4C, 0X9F, 0XC8, 0X45, 0XF4,
709 0XC9, 0XDE, 0X4F, 0XEB, 0X22, 0X83, 0X1B, 0XE4,
710 0X49, 0X37, 0XE4, 0XAD, 0XE7, 0XCD, 0X21, 0X54,
711 0XBC, 0X1C, 0XC2, 0X04, 0X97, 0XB4, 0X10, 0X61,
712 0XF0, 0XE4, 0XEF, 0X27, 0X63, 0X3A, 0XDA, 0X91,
713 0X41, 0X25, 0X62, 0X1C, 0X5C, 0XB6, 0X38, 0X4A,
714 0X88, 0X71, 0X59, 0X5A, 0X8D, 0XA0, 0X09, 0XAF,
715 0X72, 0X94, 0XD7, 0X79, 0X5C, 0X60, 0X7C, 0X8F,
716 0X4C, 0XF5, 0XD9, 0XA1, 0X39, 0X6D, 0X81, 0X28,
717 0XEF, 0X13, 0X28, 0XDF, 0XF5, 0X3E, 0XF7, 0X8E,
718 0X09, 0X9C, 0X78, 0X18, 0X79, 0XB8, 0X68, 0XD7,
719 0XA8, 0X29, 0X62, 0XAD, 0XDE, 0XE1, 0X61, 0X76,
720 0X1B, 0X05, 0X16, 0XCD, 0XBF, 0X02, 0X8E, 0XA6,
721 0X43, 0X6E, 0X92, 0X55, 0X4F, 0X60, 0X9C, 0X03,
722 0XB8, 0X4F, 0XA3, 0X02, 0XAC, 0XA8, 0XA7, 0X0C,
723 0X1E, 0XB5, 0X6B, 0XF8, 0XC8, 0X4D, 0XDE, 0XD2,
724 0XB0, 0X29, 0X6E, 0X40, 0XE6, 0XD6, 0XC9, 0XE6,
725 0XB9, 0X0F, 0XB6, 0X63, 0XF5, 0XAA, 0X2B, 0X96,
726 0XA7, 0X16, 0XAC, 0X4E, 0X0A, 0X33, 0X1C, 0XA6,
727 0XE6, 0XBD, 0X8A, 0XCF, 0X40, 0XA9, 0XB2, 0XFA,
728 0X63, 0X27, 0XFD, 0X9B, 0XD9, 0XFC, 0XD5, 0X87,
729 0X8D, 0X4C, 0XB6, 0XA4, 0XCB, 0XE7, 0X74, 0X55,
730 0XF4, 0XFB, 0X41, 0X25, 0XB5, 0X4B, 0X0A, 0X1B,
731 0XB1, 0XD6, 0XB7, 0XD9, 0X47, 0X2A, 0XC3, 0X98,
732 0X6A, 0XC4, 0X03, 0X73, 0X1F, 0X93, 0X6E, 0X53,
733 0X19, 0X25, 0X64, 0X15, 0X83, 0XF9, 0X73, 0X2A,
734 0X74, 0XB4, 0X93, 0X69, 0XC4, 0X72, 0XFC, 0X26,
735 0XA2, 0X9F, 0X43, 0X45, 0XDD, 0XB9, 0XEF, 0X36,
736 0XC8, 0X3A, 0XCD, 0X99, 0X9B, 0X54, 0X1A, 0X36,
737 0XC1, 0X59, 0XF8, 0X98, 0XA8, 0XCC, 0X28, 0X0D,
738 0X73, 0X4C, 0XEE, 0X98, 0XCB, 0X7C, 0X58, 0X7E,
739 0X20, 0X75, 0X1E, 0XB7, 0XC9, 0XF8, 0XF2, 0X0E,
740 0X63, 0X9E, 0X05, 0X78, 0X1A, 0XB6, 0XA8, 0X7A,
741 0XF9, 0X98, 0X6A, 0XA6, 0X46, 0X84, 0X2E, 0XF6,
742 0X4B, 0XDC, 0X9B, 0X8F, 0X9B, 0X8F, 0XEE, 0XB4,
743 0XAA, 0X3F, 0XEE, 0XC0, 0X37, 0X27, 0X76, 0XC7,
744 0X95, 0XBB, 0X26, 0X74, 0X69, 0X12, 0X7F, 0XF1,
745 0XBB, 0XFF, 0XAE, 0XB5, 0X99, 0X6E, 0XCB, 0X0C
748 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
749 0x9a, 0X4f, 0X88, 0X1b, 0Xb6, 0X8f, 0Xd8, 0X60,
750 0X42, 0X1a, 0X7d, 0X3d, 0Xf5, 0X82, 0X80, 0Xf1,
751 0X18, 0X8c, 0X1d, 0X32 };
755 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
757 struct crypto_testsuite_params *ts_params = &testsuite_params;
758 struct crypto_unittest_params *ut_params = &unittest_params;
760 /* Generate test mbuf data and space for digest */
761 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
762 catch_22_quote, QUOTE_512_BYTES, 0);
764 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
765 DIGEST_BYTE_LENGTH_SHA1);
766 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
768 /* Setup Cipher Parameters */
769 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
770 ut_params->cipher_xform.next = &ut_params->auth_xform;
772 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
773 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
774 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
775 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
777 /* Setup HMAC Parameters */
779 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
780 ut_params->auth_xform.next = NULL;
782 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
783 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
784 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
785 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
786 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
788 /* Create Crypto session*/
789 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
790 &ut_params->cipher_xform);
791 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
793 /* Generate Crypto op data structure */
794 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
795 RTE_PKTMBUF_OL_CRYPTO);
796 TEST_ASSERT_NOT_NULL(ut_params->ol,
797 "Failed to allocate pktmbuf offload");
799 ut_params->op = &ut_params->ol->op.crypto;
801 /* Set crypto operation data parameters */
802 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
804 ut_params->op->digest.data = ut_params->digest;
805 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
806 ut_params->ibuf, QUOTE_512_BYTES);
807 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
809 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
810 CIPHER_IV_LENGTH_AES_CBC);
811 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
812 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
814 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
815 CIPHER_IV_LENGTH_AES_CBC);
817 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
818 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
819 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
820 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
822 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
824 /* Process crypto operation */
825 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
827 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
830 TEST_ASSERT_BUFFERS_ARE_EQUAL(
831 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
832 CIPHER_IV_LENGTH_AES_CBC,
833 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
835 "Ciphertext data not as expected");
837 TEST_ASSERT_BUFFERS_ARE_EQUAL(
838 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
839 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
840 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
841 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
842 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
843 DIGEST_BYTE_LENGTH_SHA1,
844 "Generated digest data not as expected");
850 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
852 struct crypto_testsuite_params *ts_params = &testsuite_params;
853 struct crypto_unittest_params *ut_params = &unittest_params;
855 /* Generate test mbuf data and space for digest */
856 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
857 catch_22_quote, QUOTE_512_BYTES, 0);
859 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
860 DIGEST_BYTE_LENGTH_SHA1);
861 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
863 /* Generate Crypto op data structure */
864 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
865 RTE_PKTMBUF_OL_CRYPTO);
866 TEST_ASSERT_NOT_NULL(ut_params->ol,
867 "Failed to allocate pktmbuf offload");
869 ut_params->op = &ut_params->ol->op.crypto;
871 TEST_ASSERT_NOT_NULL(rte_pktmbuf_offload_alloc_crypto_xforms(
873 "failed to allocate space for crypto transforms");
875 /* Set crypto operation data parameters */
876 ut_params->op->xform->type = RTE_CRYPTO_XFORM_CIPHER;
878 /* cipher parameters */
879 ut_params->op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
880 ut_params->op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
881 ut_params->op->xform->cipher.key.data = aes_cbc_key;
882 ut_params->op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
884 /* hash parameters */
885 ut_params->op->xform->next->type = RTE_CRYPTO_XFORM_AUTH;
887 ut_params->op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
888 ut_params->op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
889 ut_params->op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
890 ut_params->op->xform->next->auth.key.data = hmac_sha1_key;
891 ut_params->op->xform->next->auth.digest_length =
892 DIGEST_BYTE_LENGTH_SHA1;
894 ut_params->op->digest.data = ut_params->digest;
895 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
896 ut_params->ibuf, QUOTE_512_BYTES);
897 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
899 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
900 CIPHER_IV_LENGTH_AES_CBC);
901 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
902 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
904 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
905 CIPHER_IV_LENGTH_AES_CBC);
907 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
908 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
909 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
910 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
912 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
914 /* Process crypto operation */
915 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
917 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
920 TEST_ASSERT_BUFFERS_ARE_EQUAL(
921 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
922 CIPHER_IV_LENGTH_AES_CBC,
923 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
925 "Ciphertext data not as expected");
927 TEST_ASSERT_BUFFERS_ARE_EQUAL(
928 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
929 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
930 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
931 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
932 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
933 DIGEST_BYTE_LENGTH_SHA1,
934 "Generated digest data not as expected");
941 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
943 struct crypto_testsuite_params *ts_params = &testsuite_params;
944 struct crypto_unittest_params *ut_params = &unittest_params;
946 /* Generate test mbuf data and digest */
947 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
949 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
952 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
953 DIGEST_BYTE_LENGTH_SHA1);
954 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
956 rte_memcpy(ut_params->digest,
957 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
958 DIGEST_BYTE_LENGTH_SHA1);
960 /* Setup Cipher Parameters */
961 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
962 ut_params->cipher_xform.next = NULL;
964 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
965 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
966 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
967 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
969 /* Setup HMAC Parameters */
970 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
971 ut_params->auth_xform.next = &ut_params->cipher_xform;
973 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
974 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
975 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
976 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
977 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
979 /* Create Crypto session*/
980 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
981 &ut_params->auth_xform);
982 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
984 /* Generate Crypto op data structure */
985 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
986 RTE_PKTMBUF_OL_CRYPTO);
987 TEST_ASSERT_NOT_NULL(ut_params->ol,
988 "Failed to allocate pktmbuf offload");
990 ut_params->op = &ut_params->ol->op.crypto;
993 /* Set crypto operation data parameters */
994 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
996 ut_params->op->digest.data = ut_params->digest;
997 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
998 ut_params->ibuf, QUOTE_512_BYTES);
999 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA1;
1001 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1002 CIPHER_IV_LENGTH_AES_CBC);
1003 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1004 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1006 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1007 CIPHER_IV_LENGTH_AES_CBC);
1009 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1010 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1012 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1013 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1015 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1017 /* Process crypto operation */
1018 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1020 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1023 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1024 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1025 CIPHER_IV_LENGTH_AES_CBC,
1028 "Ciphertext data not as expected");
1030 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1031 "Digest verification failed");
1034 return TEST_SUCCESS;
1038 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1040 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1042 static uint8_t hmac_sha256_key[] = {
1043 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1044 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1045 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1046 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1048 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1049 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1050 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1051 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1052 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1055 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1057 struct crypto_testsuite_params *ts_params = &testsuite_params;
1058 struct crypto_unittest_params *ut_params = &unittest_params;
1060 /* Generate test mbuf data and space for digest */
1061 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1062 catch_22_quote, QUOTE_512_BYTES, 0);
1064 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1065 DIGEST_BYTE_LENGTH_SHA256);
1066 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1068 /* Setup Cipher Parameters */
1069 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1070 ut_params->cipher_xform.next = &ut_params->auth_xform;
1072 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1073 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1074 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1075 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1077 /* Setup HMAC Parameters */
1078 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1079 ut_params->auth_xform.next = NULL;
1081 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1082 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1083 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1084 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1085 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1087 /* Create Crypto session*/
1088 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1089 &ut_params->cipher_xform);
1090 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1092 /* Generate Crypto op data structure */
1093 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1094 RTE_PKTMBUF_OL_CRYPTO);
1095 TEST_ASSERT_NOT_NULL(ut_params->ol,
1096 "Failed to allocate pktmbuf offload");
1098 ut_params->op = &ut_params->ol->op.crypto;
1101 /* Set crypto operation data parameters */
1102 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1104 ut_params->op->digest.data = ut_params->digest;
1105 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1106 ut_params->ibuf, QUOTE_512_BYTES);
1107 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA256;
1109 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1110 CIPHER_IV_LENGTH_AES_CBC);
1111 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1112 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1114 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1115 CIPHER_IV_LENGTH_AES_CBC);
1117 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1118 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1119 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1120 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1122 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1124 /* Process crypto operation */
1125 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1127 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1130 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1131 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1132 CIPHER_IV_LENGTH_AES_CBC,
1133 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1135 "Ciphertext data not as expected");
1137 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1138 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1139 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1140 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1141 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1142 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1143 DIGEST_BYTE_LENGTH_SHA256,
1144 "Generated digest data not as expected");
1147 return TEST_SUCCESS;
1151 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1153 struct crypto_testsuite_params *ts_params = &testsuite_params;
1154 struct crypto_unittest_params *ut_params = &unittest_params;
1156 /* Generate test mbuf data and digest */
1157 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1159 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1160 QUOTE_512_BYTES, 0);
1162 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1163 DIGEST_BYTE_LENGTH_SHA256);
1164 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1166 rte_memcpy(ut_params->digest,
1167 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1168 DIGEST_BYTE_LENGTH_SHA256);
1170 /* Setup Cipher Parameters */
1171 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1172 ut_params->cipher_xform.next = NULL;
1174 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1175 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1176 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1177 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1179 /* Setup HMAC Parameters */
1180 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1181 ut_params->auth_xform.next = &ut_params->cipher_xform;
1183 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1184 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1185 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1186 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1187 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1189 /* Create Crypto session*/
1190 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1191 &ut_params->auth_xform);
1192 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1194 /* Generate Crypto op data structure */
1195 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1196 RTE_PKTMBUF_OL_CRYPTO);
1197 TEST_ASSERT_NOT_NULL(ut_params->ol,
1198 "Failed to allocate pktmbuf offload");
1200 ut_params->op = &ut_params->ol->op.crypto;
1203 /* Set crypto operation data parameters */
1204 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1206 ut_params->op->digest.data = ut_params->digest;
1207 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1208 ut_params->ibuf, QUOTE_512_BYTES);
1209 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA256;
1211 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1212 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1213 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1214 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1216 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1217 CIPHER_IV_LENGTH_AES_CBC);
1219 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1220 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1222 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1223 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1225 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1227 /* Process crypto operation */
1228 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1230 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1233 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1234 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1235 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1237 "Plaintext data not as expected");
1239 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1240 "Digest verification failed");
1243 return TEST_SUCCESS;
1246 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1248 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1250 static uint8_t hmac_sha512_key[] = {
1251 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1252 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1253 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1254 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1255 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1256 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1257 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1258 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1260 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1261 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1262 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1263 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1264 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1265 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1266 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1267 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1268 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1271 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1273 struct crypto_testsuite_params *ts_params = &testsuite_params;
1274 struct crypto_unittest_params *ut_params = &unittest_params;
1276 /* Generate test mbuf data and space for digest */
1277 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1278 catch_22_quote, QUOTE_512_BYTES, 0);
1280 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1281 DIGEST_BYTE_LENGTH_SHA512);
1282 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1284 /* Setup Cipher Parameters */
1285 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1286 ut_params->cipher_xform.next = &ut_params->auth_xform;
1288 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1289 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1290 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1291 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1293 /* Setup HMAC Parameters */
1294 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1295 ut_params->auth_xform.next = NULL;
1297 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1298 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1299 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1300 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1301 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1303 /* Create Crypto session*/
1304 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1305 &ut_params->cipher_xform);
1307 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1310 /* Generate Crypto op data structure */
1311 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1312 RTE_PKTMBUF_OL_CRYPTO);
1313 TEST_ASSERT_NOT_NULL(ut_params->ol,
1314 "Failed to allocate pktmbuf offload");
1316 ut_params->op = &ut_params->ol->op.crypto;
1319 /* Set crypto operation data parameters */
1320 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1322 ut_params->op->digest.data = ut_params->digest;
1323 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1324 ut_params->ibuf, QUOTE_512_BYTES);
1325 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1327 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1328 CIPHER_IV_LENGTH_AES_CBC);
1329 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1330 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1332 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1333 CIPHER_IV_LENGTH_AES_CBC);
1335 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1336 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1337 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1338 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1340 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1342 /* Process crypto operation */
1343 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1345 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1348 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1349 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1350 CIPHER_IV_LENGTH_AES_CBC,
1351 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1353 "Ciphertext data not as expected");
1355 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1356 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1357 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1358 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1359 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1360 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1361 DIGEST_BYTE_LENGTH_SHA512,
1362 "Generated digest data not as expected");
1365 return TEST_SUCCESS;
1370 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1371 struct crypto_unittest_params *ut_params);
1374 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_session *sess,
1375 struct crypto_unittest_params *ut_params,
1376 struct crypto_testsuite_params *ts_params);
1379 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1381 struct crypto_unittest_params *ut_params = &unittest_params;
1382 struct crypto_testsuite_params *ts_params = &testsuite_params;
1384 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1385 ut_params) == TEST_SUCCESS,
1386 "Failed to create session params");
1388 /* Create Crypto session*/
1389 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1390 &ut_params->auth_xform);
1391 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1393 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1394 ut_params, ts_params);
1398 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1399 struct crypto_unittest_params *ut_params)
1402 /* Setup Cipher Parameters */
1403 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1404 ut_params->cipher_xform.next = NULL;
1406 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1407 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1408 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1409 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1411 /* Setup HMAC Parameters */
1412 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1413 ut_params->auth_xform.next = &ut_params->cipher_xform;
1415 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1416 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1417 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1418 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1419 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1420 return TEST_SUCCESS;
1425 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_session *sess,
1426 struct crypto_unittest_params *ut_params,
1427 struct crypto_testsuite_params *ts_params)
1429 /* Generate test mbuf data and digest */
1430 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1432 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1433 QUOTE_512_BYTES, 0);
1435 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1436 DIGEST_BYTE_LENGTH_SHA512);
1437 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1439 rte_memcpy(ut_params->digest,
1440 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1441 DIGEST_BYTE_LENGTH_SHA512);
1443 /* Generate Crypto op data structure */
1444 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1445 RTE_PKTMBUF_OL_CRYPTO);
1446 TEST_ASSERT_NOT_NULL(ut_params->ol,
1447 "Failed to allocate pktmbuf offload");
1449 ut_params->op = &ut_params->ol->op.crypto;
1452 /* Set crypto operation data parameters */
1453 rte_crypto_op_attach_session(ut_params->op, sess);
1455 ut_params->op->digest.data = ut_params->digest;
1456 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1457 ut_params->ibuf, QUOTE_512_BYTES);
1458 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1460 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1461 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1462 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys_offset(
1463 ut_params->ibuf, 0);
1464 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1466 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1467 CIPHER_IV_LENGTH_AES_CBC);
1469 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1470 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1472 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1473 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1475 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1477 /* Process crypto operation */
1478 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1480 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1483 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1484 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1485 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1487 "Plaintext data not as expected");
1490 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1491 "Digest verification failed");
1495 return TEST_SUCCESS;
1498 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1500 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1501 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1502 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1505 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1506 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1507 0x77, 0x1D, 0x8B, 0x75
1511 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1513 struct crypto_testsuite_params *ts_params = &testsuite_params;
1514 struct crypto_unittest_params *ut_params = &unittest_params;
1516 /* Generate test mbuf data and space for digest */
1517 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1518 catch_22_quote, QUOTE_512_BYTES, 0);
1520 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1521 DIGEST_BYTE_LENGTH_AES_XCBC);
1522 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1524 /* Setup Cipher Parameters */
1525 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1526 ut_params->cipher_xform.next = &ut_params->auth_xform;
1528 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1529 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1530 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1531 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1533 /* Setup HMAC Parameters */
1534 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1535 ut_params->auth_xform.next = NULL;
1537 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1538 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1539 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1540 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1541 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1543 /* Create Crypto session*/
1544 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1545 &ut_params->cipher_xform);
1546 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1548 /* Generate Crypto op data structure */
1549 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1550 RTE_PKTMBUF_OL_CRYPTO);
1551 TEST_ASSERT_NOT_NULL(ut_params->ol,
1552 "Failed to allocate pktmbuf offload");
1554 ut_params->op = &ut_params->ol->op.crypto;
1557 /* Set crypto operation data parameters */
1558 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1560 ut_params->op->iv.data = (uint8_t *)
1561 rte_pktmbuf_prepend(ut_params->ibuf,
1562 CIPHER_IV_LENGTH_AES_CBC);
1563 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1564 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1566 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1567 CIPHER_IV_LENGTH_AES_CBC);
1569 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1570 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1571 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1572 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1574 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1576 /* Process crypto operation */
1577 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1579 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1582 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1583 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1584 CIPHER_IV_LENGTH_AES_CBC,
1585 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1587 "Ciphertext data not as expected");
1588 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1589 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1590 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1591 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1592 DIGEST_BYTE_LENGTH_AES_XCBC,
1593 "Generated digest data not as expected");
1595 return TEST_SUCCESS;
1599 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1601 struct crypto_testsuite_params *ts_params = &testsuite_params;
1602 struct crypto_unittest_params *ut_params = &unittest_params;
1604 /* Generate test mbuf data and space for digest */
1605 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1606 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1607 QUOTE_512_BYTES, 0);
1609 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1610 DIGEST_BYTE_LENGTH_AES_XCBC);
1611 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1613 rte_memcpy(ut_params->digest,
1614 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1615 DIGEST_BYTE_LENGTH_AES_XCBC);
1617 /* Setup Cipher Parameters */
1618 ut_params->cipher_xform.type = RTE_CRYPTO_XFORM_CIPHER;
1619 ut_params->cipher_xform.next = NULL;
1621 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1622 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1623 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1624 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1626 /* Setup HMAC Parameters */
1627 ut_params->auth_xform.type = RTE_CRYPTO_XFORM_AUTH;
1628 ut_params->auth_xform.next = &ut_params->cipher_xform;
1630 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1631 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1632 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1633 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1634 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1636 /* Create Crypto session*/
1637 ut_params->sess = rte_cryptodev_session_create(ts_params->valid_devs[0],
1638 &ut_params->auth_xform);
1639 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1641 /* Generate Crypto op data structure */
1642 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1643 RTE_PKTMBUF_OL_CRYPTO);
1644 TEST_ASSERT_NOT_NULL(ut_params->ol,
1645 "Failed to allocate pktmbuf offload");
1647 ut_params->op = &ut_params->ol->op.crypto;
1650 /* Set crypto operation data parameters */
1651 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1653 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1654 CIPHER_IV_LENGTH_AES_CBC);
1655 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1656 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1658 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1659 CIPHER_IV_LENGTH_AES_CBC);
1661 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1662 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1663 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1664 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1665 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1667 /* Process crypto operation */
1668 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1670 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1673 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1674 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1675 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1677 "Ciphertext data not as expected");
1679 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1680 "Digest verification failed");
1682 return TEST_SUCCESS;
1686 /* ***** AES-GCM Tests ***** */
1691 struct crypto_testsuite_params *ts_params = &testsuite_params;
1692 struct rte_cryptodev_stats stats;
1693 struct rte_cryptodev *dev;
1694 cryptodev_stats_get_t temp_pfn;
1696 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1697 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
1698 &stats) == -ENODEV),
1699 "rte_cryptodev_stats_get invalid dev failed");
1700 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
1701 "rte_cryptodev_stats_get invalid Param failed");
1702 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
1703 temp_pfn = dev->dev_ops->stats_get;
1704 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
1705 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
1707 "rte_cryptodev_stats_get invalid Param failed");
1708 dev->dev_ops->stats_get = temp_pfn;
1710 /* Test expected values */
1712 test_AES_CBC_HMAC_SHA1_encrypt_digest();
1714 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1716 "rte_cryptodev_stats_get failed");
1717 TEST_ASSERT((stats.enqueued_count == 1),
1718 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1719 TEST_ASSERT((stats.dequeued_count == 1),
1720 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1721 TEST_ASSERT((stats.enqueue_err_count == 0),
1722 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1723 TEST_ASSERT((stats.dequeue_err_count == 0),
1724 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1726 /* invalid device but should ignore and not reset device stats*/
1727 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
1728 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1730 "rte_cryptodev_stats_get failed");
1731 TEST_ASSERT((stats.enqueued_count == 1),
1732 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1734 /* check that a valid reset clears stats */
1735 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1736 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
1738 "rte_cryptodev_stats_get failed");
1739 TEST_ASSERT((stats.enqueued_count == 0),
1740 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1741 TEST_ASSERT((stats.dequeued_count == 0),
1742 "rte_cryptodev_stats_get returned unexpected enqueued stat");
1744 return TEST_SUCCESS;
1749 test_multi_session(void)
1751 struct crypto_testsuite_params *ts_params = &testsuite_params;
1752 struct crypto_unittest_params *ut_params = &unittest_params;
1754 struct rte_cryptodev_info dev_info;
1755 struct rte_cryptodev_session **sessions;
1759 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1762 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
1764 sessions = rte_malloc(NULL, (sizeof(struct rte_cryptodev_session *) *
1765 dev_info.max_nb_sessions) + 1, 0);
1767 /* Create multiple crypto sessions*/
1768 for (i = 0; i < dev_info.max_nb_sessions; i++) {
1769 sessions[i] = rte_cryptodev_session_create(
1770 ts_params->valid_devs[0],
1771 &ut_params->auth_xform);
1772 TEST_ASSERT_NOT_NULL(sessions[i],
1773 "Session creation failed at session number %u",
1776 /* Attempt to send a request on each session */
1777 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
1778 sessions[i], ut_params, ts_params),
1779 "Failed to perform decrypt on request "
1783 /* Next session create should fail */
1784 sessions[i] = rte_cryptodev_session_create(ts_params->valid_devs[0],
1785 &ut_params->auth_xform);
1786 TEST_ASSERT_NULL(sessions[i],
1787 "Session creation succeeded unexpectedly!");
1789 for (i = 0; i < dev_info.max_nb_sessions; i++)
1790 rte_cryptodev_session_free(ts_params->valid_devs[0],
1795 return TEST_SUCCESS;
1799 test_not_in_place_crypto(void)
1801 struct crypto_testsuite_params *ts_params = &testsuite_params;
1802 struct crypto_unittest_params *ut_params = &unittest_params;
1803 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
1805 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
1807 /* Create multiple crypto sessions*/
1809 ut_params->sess = rte_cryptodev_session_create(
1810 ts_params->valid_devs[0], &ut_params->auth_xform);
1812 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1815 /* Generate test mbuf data and digest */
1816 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1818 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1819 QUOTE_512_BYTES, 0);
1821 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1822 DIGEST_BYTE_LENGTH_SHA512);
1823 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1825 rte_memcpy(ut_params->digest,
1826 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1827 DIGEST_BYTE_LENGTH_SHA512);
1829 /* Generate Crypto op data structure */
1830 ut_params->ol = rte_pktmbuf_offload_alloc(ts_params->mbuf_ol_pool,
1831 RTE_PKTMBUF_OL_CRYPTO);
1832 TEST_ASSERT_NOT_NULL(ut_params->ol,
1833 "Failed to allocate pktmbuf offload");
1835 ut_params->op = &ut_params->ol->op.crypto;
1838 /* Set crypto operation data parameters */
1839 rte_crypto_op_attach_session(ut_params->op, ut_params->sess);
1841 ut_params->op->digest.data = ut_params->digest;
1842 ut_params->op->digest.phys_addr = rte_pktmbuf_mtophys_offset(
1843 ut_params->ibuf, QUOTE_512_BYTES);
1844 ut_params->op->digest.length = DIGEST_BYTE_LENGTH_SHA512;
1846 ut_params->op->iv.data = (uint8_t *)rte_pktmbuf_prepend(
1847 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1848 ut_params->op->iv.phys_addr = rte_pktmbuf_mtophys_offset(
1849 ut_params->ibuf, 0);
1850 ut_params->op->iv.length = CIPHER_IV_LENGTH_AES_CBC;
1852 rte_memcpy(ut_params->op->iv.data, aes_cbc_iv,
1853 CIPHER_IV_LENGTH_AES_CBC);
1855 ut_params->op->data.to_cipher.offset = CIPHER_IV_LENGTH_AES_CBC;
1856 ut_params->op->data.to_cipher.length = QUOTE_512_BYTES;
1858 ut_params->op->data.to_hash.offset = CIPHER_IV_LENGTH_AES_CBC;
1859 ut_params->op->data.to_hash.length = QUOTE_512_BYTES;
1861 ut_params->op->dst.m = dst_m;
1862 ut_params->op->dst.offset = 0;
1864 rte_pktmbuf_offload_attach(ut_params->ibuf, ut_params->ol);
1866 /* Process crypto operation */
1867 ut_params->obuf = process_crypto_request(ts_params->valid_devs[0],
1869 TEST_ASSERT_NOT_NULL(ut_params->obuf, "failed to retrieve obuf");
1872 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1873 rte_pktmbuf_mtod(ut_params->op->dst.m, char *),
1876 "Plaintext data not as expected");
1880 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1881 "Digest verification failed");
1883 return TEST_SUCCESS;
1887 static struct unit_test_suite cryptodev_qat_testsuite = {
1888 .suite_name = "Crypto QAT Unit Test Suite",
1889 .setup = testsuite_setup,
1890 .teardown = testsuite_teardown,
1891 .unit_test_cases = {
1892 TEST_CASE_ST(ut_setup, ut_teardown,
1893 test_device_configure_invalid_dev_id),
1894 TEST_CASE_ST(ut_setup, ut_teardown,
1895 test_device_configure_invalid_queue_pair_ids),
1896 TEST_CASE_ST(ut_setup, ut_teardown,
1897 test_queue_pair_descriptor_setup),
1898 TEST_CASE_ST(ut_setup, ut_teardown,
1899 test_multi_session),
1901 TEST_CASE_ST(ut_setup, ut_teardown,
1902 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1903 TEST_CASE_ST(ut_setup, ut_teardown,
1904 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1906 TEST_CASE_ST(ut_setup, ut_teardown,
1907 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1908 TEST_CASE_ST(ut_setup, ut_teardown,
1909 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1911 TEST_CASE_ST(ut_setup, ut_teardown,
1912 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1913 TEST_CASE_ST(ut_setup, ut_teardown,
1914 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1916 TEST_CASE_ST(ut_setup, ut_teardown,
1917 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1918 TEST_CASE_ST(ut_setup, ut_teardown,
1919 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1921 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
1923 TEST_CASES_END() /**< NULL terminate unit test array */
1927 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
1928 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
1929 .setup = testsuite_setup,
1930 .teardown = testsuite_teardown,
1931 .unit_test_cases = {
1932 TEST_CASE_ST(ut_setup, ut_teardown,
1933 test_AES_CBC_HMAC_SHA1_encrypt_digest),
1934 TEST_CASE_ST(ut_setup, ut_teardown,
1935 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
1937 TEST_CASE_ST(ut_setup, ut_teardown,
1938 test_AES_CBC_HMAC_SHA256_encrypt_digest),
1939 TEST_CASE_ST(ut_setup, ut_teardown,
1940 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
1942 TEST_CASE_ST(ut_setup, ut_teardown,
1943 test_AES_CBC_HMAC_SHA512_encrypt_digest),
1944 TEST_CASE_ST(ut_setup, ut_teardown,
1945 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
1947 TEST_CASE_ST(ut_setup, ut_teardown,
1948 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
1949 TEST_CASE_ST(ut_setup, ut_teardown,
1950 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
1952 TEST_CASE_ST(ut_setup, ut_teardown,
1953 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
1955 TEST_CASE_ST(ut_setup, ut_teardown,
1956 test_not_in_place_crypto),
1958 TEST_CASES_END() /**< NULL terminate unit test array */
1963 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
1965 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_PMD;
1966 return unit_test_suite_runner(&cryptodev_qat_testsuite);
1968 static struct test_command cryptodev_qat_cmd = {
1969 .command = "cryptodev_qat_autotest",
1970 .callback = test_cryptodev_qat,
1974 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
1976 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
1978 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
1981 static struct test_command cryptodev_aesni_mb_cmd = {
1982 .command = "cryptodev_aesni_mb_autotest",
1983 .callback = test_cryptodev_aesni_mb,
1986 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
1987 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);