4 * Copyright(c) 2015-2016 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
16 * * Neither the name of Intel Corporation nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <rte_common.h>
34 #include <rte_hexdump.h>
36 #include <rte_malloc.h>
37 #include <rte_memcpy.h>
39 #include <rte_crypto.h>
40 #include <rte_cryptodev.h>
41 #include <rte_cryptodev_pmd.h>
44 #include "test_cryptodev.h"
45 #include "test_cryptodev_snow3g_test_vectors.h"
46 #include "test_cryptodev_snow3g_hash_test_vectors.h"
47 static enum rte_cryptodev_type gbl_cryptodev_type;
49 struct crypto_testsuite_params {
50 struct rte_mempool *mbuf_pool;
51 struct rte_mempool *op_mpool;
52 struct rte_cryptodev_config conf;
53 struct rte_cryptodev_qp_conf qp_conf;
55 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
56 uint8_t valid_dev_count;
59 struct crypto_unittest_params {
60 struct rte_crypto_sym_xform cipher_xform;
61 struct rte_crypto_sym_xform auth_xform;
63 struct rte_cryptodev_sym_session *sess;
65 struct rte_crypto_op *op;
67 struct rte_mbuf *obuf, *ibuf;
72 #define ALIGN_POW2_ROUNDUP(num, align) \
73 (((num) + (align) - 1) & ~((align) - 1))
76 * Forward declarations.
79 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
80 struct crypto_unittest_params *ut_params);
83 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
84 struct crypto_unittest_params *ut_params,
85 struct crypto_testsuite_params *ts_param);
87 static struct rte_mbuf *
88 setup_test_string(struct rte_mempool *mpool,
89 const char *string, size_t len, uint8_t blocksize)
91 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
92 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
94 memset(m->buf_addr, 0, m->buf_len);
96 char *dst = rte_pktmbuf_append(m, t_len);
103 rte_memcpy(dst, string, t_len);
111 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
113 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
117 static struct rte_crypto_op *
118 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
121 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
124 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
125 printf("Error sending packet for encryption");
131 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
136 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
142 static struct crypto_testsuite_params testsuite_params = { NULL };
143 static struct crypto_unittest_params unittest_params;
146 testsuite_setup(void)
148 struct crypto_testsuite_params *ts_params = &testsuite_params;
149 struct rte_cryptodev_info info;
150 unsigned i, nb_devs, dev_id;
154 memset(ts_params, 0, sizeof(*ts_params));
156 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
157 if (ts_params->mbuf_pool == NULL) {
158 /* Not already created so create */
159 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
161 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
163 if (ts_params->mbuf_pool == NULL) {
164 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
169 ts_params->op_mpool = rte_crypto_op_pool_create(
170 "MBUF_CRYPTO_SYM_OP_POOL",
171 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
172 NUM_MBUFS, MBUF_CACHE_SIZE,
174 sizeof(struct rte_crypto_sym_xform),
176 if (ts_params->op_mpool == NULL) {
177 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
181 /* Create 2 AESNI MB devices if required */
182 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
183 nb_devs = rte_cryptodev_count_devtype(
184 RTE_CRYPTODEV_AESNI_MB_PMD);
186 for (i = nb_devs; i < 2; i++) {
187 ret = rte_eal_vdev_init(
188 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
190 TEST_ASSERT(ret == 0,
191 "Failed to create instance %u of"
193 i, CRYPTODEV_NAME_AESNI_MB_PMD);
198 nb_devs = rte_cryptodev_count();
200 RTE_LOG(ERR, USER1, "No crypto devices found?");
204 /* Create list of valid crypto devs */
205 for (i = 0; i < nb_devs; i++) {
206 rte_cryptodev_info_get(i, &info);
207 if (info.dev_type == gbl_cryptodev_type)
208 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
211 if (ts_params->valid_dev_count < 1)
214 /* Set up all the qps on the first of the valid devices found */
215 for (i = 0; i < 1; i++) {
216 dev_id = ts_params->valid_devs[i];
218 rte_cryptodev_info_get(dev_id, &info);
221 * Since we can't free and re-allocate queue memory always set
222 * the queues on this device up to max size first so enough
223 * memory is allocated for any later re-configures needed by
227 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
228 ts_params->conf.socket_id = SOCKET_ID_ANY;
229 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
231 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
233 "Failed to configure cryptodev %u with %u qps",
234 dev_id, ts_params->conf.nb_queue_pairs);
236 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
238 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
239 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
240 dev_id, qp_id, &ts_params->qp_conf,
241 rte_cryptodev_socket_id(dev_id)),
242 "Failed to setup queue pair %u on "
252 testsuite_teardown(void)
254 struct crypto_testsuite_params *ts_params = &testsuite_params;
256 if (ts_params->mbuf_pool != NULL) {
257 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
258 rte_mempool_count(ts_params->mbuf_pool));
261 if (ts_params->op_mpool != NULL) {
262 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
263 rte_mempool_count(ts_params->op_mpool));
271 struct crypto_testsuite_params *ts_params = &testsuite_params;
272 struct crypto_unittest_params *ut_params = &unittest_params;
276 /* Clear unit test parameters before running test */
277 memset(ut_params, 0, sizeof(*ut_params));
279 /* Reconfigure device to default parameters */
280 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
281 ts_params->conf.socket_id = SOCKET_ID_ANY;
282 ts_params->conf.session_mp.nb_objs =
283 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
284 DEFAULT_NUM_OPS_INFLIGHT :
285 DEFAULT_NUM_OPS_INFLIGHT;
287 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
289 "Failed to configure cryptodev %u",
290 ts_params->valid_devs[0]);
293 * Now reconfigure queues to size we actually want to use in this
296 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
298 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
299 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
300 ts_params->valid_devs[0], qp_id,
302 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
303 "Failed to setup queue pair %u on cryptodev %u",
304 qp_id, ts_params->valid_devs[0]);
308 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
310 /* Start the device */
311 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
312 "Failed to start cryptodev %u",
313 ts_params->valid_devs[0]);
321 struct crypto_testsuite_params *ts_params = &testsuite_params;
322 struct crypto_unittest_params *ut_params = &unittest_params;
323 struct rte_cryptodev_stats stats;
325 /* free crypto session structure */
326 if (ut_params->sess) {
327 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
329 ut_params->sess = NULL;
332 /* free crypto operation structure */
334 rte_crypto_op_free(ut_params->op);
337 * free mbuf - both obuf and ibuf are usually the same,
338 * but rte copes even if we call free twice
340 if (ut_params->obuf) {
341 rte_pktmbuf_free(ut_params->obuf);
344 if (ut_params->ibuf) {
345 rte_pktmbuf_free(ut_params->ibuf);
349 if (ts_params->mbuf_pool != NULL)
350 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
351 rte_mempool_count(ts_params->mbuf_pool));
353 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
355 /* Stop the device */
356 rte_cryptodev_stop(ts_params->valid_devs[0]);
360 test_device_configure_invalid_dev_id(void)
362 struct crypto_testsuite_params *ts_params = &testsuite_params;
363 uint16_t dev_id, num_devs = 0;
365 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
366 "Need at least %d devices for test", 1);
368 /* valid dev_id values */
369 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
371 /* Stop the device in case it's started so it can be configured */
372 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
374 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
375 "Failed test for rte_cryptodev_configure: "
376 "invalid dev_num %u", dev_id);
378 /* invalid dev_id values */
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);
387 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
388 "Failed test for rte_cryptodev_configure:"
389 "invalid dev_num %u", dev_id);
395 test_device_configure_invalid_queue_pair_ids(void)
397 struct crypto_testsuite_params *ts_params = &testsuite_params;
399 /* Stop the device in case it's started so it can be configured */
400 rte_cryptodev_stop(ts_params->valid_devs[0]);
402 /* valid - one queue pairs */
403 ts_params->conf.nb_queue_pairs = 1;
405 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
407 "Failed to configure cryptodev: dev_id %u, qp_id %u",
408 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
411 /* valid - max value queue pairs */
412 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
414 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
416 "Failed to configure cryptodev: dev_id %u, qp_id %u",
417 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
420 /* invalid - zero queue pairs */
421 ts_params->conf.nb_queue_pairs = 0;
423 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
425 "Failed test for rte_cryptodev_configure, dev_id %u,"
427 ts_params->valid_devs[0],
428 ts_params->conf.nb_queue_pairs);
431 /* invalid - max value supported by field queue pairs */
432 ts_params->conf.nb_queue_pairs = UINT16_MAX;
434 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
436 "Failed test for rte_cryptodev_configure, dev_id %u,"
438 ts_params->valid_devs[0],
439 ts_params->conf.nb_queue_pairs);
442 /* invalid - max value + 1 queue pairs */
443 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
445 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
447 "Failed test for rte_cryptodev_configure, dev_id %u,"
449 ts_params->valid_devs[0],
450 ts_params->conf.nb_queue_pairs);
456 test_queue_pair_descriptor_setup(void)
458 struct crypto_testsuite_params *ts_params = &testsuite_params;
459 struct rte_cryptodev_info dev_info;
460 struct rte_cryptodev_qp_conf qp_conf = {
461 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
466 /* Stop the device in case it's started so it can be configured */
467 rte_cryptodev_stop(ts_params->valid_devs[0]);
470 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
472 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
474 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
475 &ts_params->conf), "Failed to configure cryptodev %u",
476 ts_params->valid_devs[0]);
480 * Test various ring sizes on this device. memzones can't be
481 * freed so are re-used if ring is released and re-created.
483 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
485 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
486 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
487 ts_params->valid_devs[0], qp_id, &qp_conf,
488 rte_cryptodev_socket_id(
489 ts_params->valid_devs[0])),
491 "rte_cryptodev_queue_pair_setup: num_inflights "
492 "%u on qp %u on cryptodev %u",
493 qp_conf.nb_descriptors, qp_id,
494 ts_params->valid_devs[0]);
497 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
499 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
500 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
501 ts_params->valid_devs[0], qp_id, &qp_conf,
502 rte_cryptodev_socket_id(
503 ts_params->valid_devs[0])),
505 " rte_cryptodev_queue_pair_setup: num_inflights"
506 " %u on qp %u on cryptodev %u",
507 qp_conf.nb_descriptors, qp_id,
508 ts_params->valid_devs[0]);
511 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
513 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
514 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
515 ts_params->valid_devs[0], qp_id, &qp_conf,
516 rte_cryptodev_socket_id(
517 ts_params->valid_devs[0])),
519 "rte_cryptodev_queue_pair_setup: num_inflights"
520 " %u on qp %u on cryptodev %u",
521 qp_conf.nb_descriptors, qp_id,
522 ts_params->valid_devs[0]);
525 /* invalid number of descriptors - max supported + 2 */
526 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
528 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
529 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
530 ts_params->valid_devs[0], qp_id, &qp_conf,
531 rte_cryptodev_socket_id(
532 ts_params->valid_devs[0])),
533 "Unexpectedly passed test for "
534 "rte_cryptodev_queue_pair_setup:"
535 "num_inflights %u on qp %u on cryptodev %u",
536 qp_conf.nb_descriptors, qp_id,
537 ts_params->valid_devs[0]);
540 /* invalid number of descriptors - max value of parameter */
541 qp_conf.nb_descriptors = UINT32_MAX-1;
543 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
544 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
545 ts_params->valid_devs[0], qp_id, &qp_conf,
546 rte_cryptodev_socket_id(
547 ts_params->valid_devs[0])),
548 "Unexpectedly passed test for "
549 "rte_cryptodev_queue_pair_setup:"
550 "num_inflights %u on qp %u on cryptodev %u",
551 qp_conf.nb_descriptors, qp_id,
552 ts_params->valid_devs[0]);
555 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
557 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
558 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
559 ts_params->valid_devs[0], qp_id, &qp_conf,
560 rte_cryptodev_socket_id(
561 ts_params->valid_devs[0])),
563 " rte_cryptodev_queue_pair_setup:"
564 "num_inflights %u on qp %u on cryptodev %u",
565 qp_conf.nb_descriptors, qp_id,
566 ts_params->valid_devs[0]);
569 /* invalid number of descriptors - max supported + 1 */
570 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
572 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
573 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
574 ts_params->valid_devs[0], qp_id, &qp_conf,
575 rte_cryptodev_socket_id(
576 ts_params->valid_devs[0])),
577 "Unexpectedly passed test for "
578 "rte_cryptodev_queue_pair_setup:"
579 "num_inflights %u on qp %u on cryptodev %u",
580 qp_conf.nb_descriptors, qp_id,
581 ts_params->valid_devs[0]);
584 /* test invalid queue pair id */
585 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
587 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
589 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
590 ts_params->valid_devs[0],
592 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
593 "Failed test for rte_cryptodev_queue_pair_setup:"
594 "invalid qp %u on cryptodev %u",
595 qp_id, ts_params->valid_devs[0]);
597 qp_id = 0xffff; /*invalid*/
599 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
600 ts_params->valid_devs[0],
602 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
603 "Failed test for rte_cryptodev_queue_pair_setup:"
604 "invalid qp %u on cryptodev %u",
605 qp_id, ts_params->valid_devs[0]);
610 /* ***** Plaintext data for tests ***** */
612 const char catch_22_quote_1[] =
613 "There was only one catch and that was Catch-22, which "
614 "specified that a concern for one's safety in the face of "
615 "dangers that were real and immediate was the process of a "
616 "rational mind. Orr was crazy and could be grounded. All he "
617 "had to do was ask; and as soon as he did, he would no longer "
618 "be crazy and would have to fly more missions. Orr would be "
619 "crazy to fly more missions and sane if he didn't, but if he "
620 "was sane he had to fly them. If he flew them he was crazy "
621 "and didn't have to; but if he didn't want to he was sane and "
622 "had to. Yossarian was moved very deeply by the absolute "
623 "simplicity of this clause of Catch-22 and let out a "
624 "respectful whistle. \"That's some catch, that Catch-22\", he "
625 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
627 const char catch_22_quote[] =
628 "What a lousy earth! He wondered how many people were "
629 "destitute that same night even in his own prosperous country, "
630 "how many homes were shanties, how many husbands were drunk "
631 "and wives socked, and how many children were bullied, abused, "
632 "or abandoned. How many families hungered for food they could "
633 "not afford to buy? How many hearts were broken? How many "
634 "suicides would take place that same night, how many people "
635 "would go insane? How many cockroaches and landlords would "
636 "triumph? How many winners were losers, successes failures, "
637 "and rich men poor men? How many wise guys were stupid? How "
638 "many happy endings were unhappy endings? How many honest men "
639 "were liars, brave men cowards, loyal men traitors, how many "
640 "sainted men were corrupt, how many people in positions of "
641 "trust had sold their souls to bodyguards, how many had never "
642 "had souls? How many straight-and-narrow paths were crooked "
643 "paths? How many best families were worst families and how "
644 "many good people were bad people? When you added them all up "
645 "and then subtracted, you might be left with only the children, "
646 "and perhaps with Albert Einstein and an old violinist or "
647 "sculptor somewhere.";
649 #define QUOTE_480_BYTES (480)
650 #define QUOTE_512_BYTES (512)
651 #define QUOTE_768_BYTES (768)
652 #define QUOTE_1024_BYTES (1024)
656 /* ***** SHA1 Hash Tests ***** */
658 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
660 static uint8_t hmac_sha1_key[] = {
661 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
662 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
663 0xDE, 0xF4, 0xDE, 0xAD };
665 /* ***** SHA224 Hash Tests ***** */
667 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
670 /* ***** AES-CBC Cipher Tests ***** */
672 #define CIPHER_KEY_LENGTH_AES_CBC (16)
673 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
675 static uint8_t aes_cbc_key[] = {
676 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
677 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
679 static uint8_t aes_cbc_iv[] = {
680 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
681 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
684 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
686 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
687 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
688 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
689 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
690 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
691 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
692 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
693 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
694 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
695 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
696 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
697 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
698 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
699 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
700 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
701 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
702 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
703 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
704 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
705 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
706 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
707 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
708 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
709 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
710 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
711 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
712 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
713 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
714 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
715 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
716 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
717 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
718 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
719 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
720 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
721 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
722 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
723 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
724 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
725 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
726 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
727 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
728 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
729 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
730 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
731 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
732 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
733 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
734 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
735 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
736 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
737 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
738 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
739 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
740 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
741 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
742 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
743 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
744 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
745 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
746 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
747 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
748 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
749 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
750 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
753 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
754 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
755 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
756 0x18, 0x8c, 0x1d, 0x32
761 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
763 struct crypto_testsuite_params *ts_params = &testsuite_params;
764 struct crypto_unittest_params *ut_params = &unittest_params;
766 /* Generate test mbuf data and space for digest */
767 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
768 catch_22_quote, QUOTE_512_BYTES, 0);
770 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
771 DIGEST_BYTE_LENGTH_SHA1);
772 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
774 /* Setup Cipher Parameters */
775 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
776 ut_params->cipher_xform.next = &ut_params->auth_xform;
778 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
779 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
780 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
781 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
783 /* Setup HMAC Parameters */
784 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
786 ut_params->auth_xform.next = NULL;
788 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
789 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
790 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
791 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
792 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
794 /* Create crypto session*/
795 ut_params->sess = rte_cryptodev_sym_session_create(
796 ts_params->valid_devs[0],
797 &ut_params->cipher_xform);
798 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
800 /* Generate crypto op data structure */
801 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
802 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
803 TEST_ASSERT_NOT_NULL(ut_params->op,
804 "Failed to allocate symmetric crypto operation struct");
806 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
808 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
810 /* set crypto operation source mbuf */
811 sym_op->m_src = ut_params->ibuf;
813 /* Set crypto operation authentication parameters */
814 sym_op->auth.digest.data = ut_params->digest;
815 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
816 ut_params->ibuf, QUOTE_512_BYTES);
817 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
819 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
820 sym_op->auth.data.length = QUOTE_512_BYTES;
822 /* Set crypto operation cipher parameters */
823 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
824 CIPHER_IV_LENGTH_AES_CBC);
825 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
826 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
828 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
829 CIPHER_IV_LENGTH_AES_CBC);
831 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
832 sym_op->cipher.data.length = QUOTE_512_BYTES;
834 /* Process crypto operation */
835 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
836 ut_params->op), "failed to process sym crypto op");
838 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
839 "crypto op processing failed");
842 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
843 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
845 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
846 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
848 "ciphertext data not as expected");
850 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
852 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
853 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
854 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
855 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
856 DIGEST_BYTE_LENGTH_SHA1,
857 "Generated digest data not as expected");
863 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
865 struct crypto_testsuite_params *ts_params = &testsuite_params;
866 struct crypto_unittest_params *ut_params = &unittest_params;
868 /* Generate test mbuf data and space for digest */
869 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
870 catch_22_quote, QUOTE_512_BYTES, 0);
872 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
873 DIGEST_BYTE_LENGTH_SHA1);
874 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
876 /* Generate Crypto op data structure */
877 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
878 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
879 TEST_ASSERT_NOT_NULL(ut_params->op,
880 "Failed to allocate symmetric crypto operation struct");
882 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
883 "failed to allocate space for crypto transforms");
885 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
887 /* set crypto operation source mbuf */
888 sym_op->m_src = ut_params->ibuf;
890 /* Set crypto operation data parameters */
891 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
893 /* cipher parameters */
894 sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
895 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
896 sym_op->xform->cipher.key.data = aes_cbc_key;
897 sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
899 /* hash parameters */
900 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
902 sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
903 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
904 sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
905 sym_op->xform->next->auth.key.data = hmac_sha1_key;
906 sym_op->xform->next->auth.digest_length =
907 DIGEST_BYTE_LENGTH_SHA1;
909 sym_op->auth.digest.data = ut_params->digest;
910 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
911 ut_params->ibuf, QUOTE_512_BYTES);
912 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
915 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
916 sym_op->auth.data.length = QUOTE_512_BYTES;
918 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
919 CIPHER_IV_LENGTH_AES_CBC);
920 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
921 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
923 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
924 CIPHER_IV_LENGTH_AES_CBC);
926 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
927 sym_op->cipher.data.length = QUOTE_512_BYTES;
929 /* Process crypto operation */
930 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
931 ut_params->op), "failed to process sym crypto op");
933 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
934 "crypto op processing failed");
936 ut_params->obuf = ut_params->op->sym->m_src;
939 TEST_ASSERT_BUFFERS_ARE_EQUAL(
940 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
941 CIPHER_IV_LENGTH_AES_CBC,
942 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
944 "Ciphertext data not as expected");
946 TEST_ASSERT_BUFFERS_ARE_EQUAL(
947 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
948 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
949 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
950 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
951 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
952 DIGEST_BYTE_LENGTH_SHA1,
953 "Generated digest data not as expected");
960 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
962 struct crypto_testsuite_params *ts_params = &testsuite_params;
963 struct crypto_unittest_params *ut_params = &unittest_params;
965 /* Generate test mbuf data and digest */
966 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
968 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
971 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
972 DIGEST_BYTE_LENGTH_SHA1);
973 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
975 rte_memcpy(ut_params->digest,
976 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
977 DIGEST_BYTE_LENGTH_SHA1);
979 /* Setup Cipher Parameters */
980 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
981 ut_params->cipher_xform.next = NULL;
983 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
984 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
985 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
986 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
988 /* Setup HMAC Parameters */
989 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
990 ut_params->auth_xform.next = &ut_params->cipher_xform;
992 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
993 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
994 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
995 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
996 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
998 /* Create Crypto session*/
1000 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1001 &ut_params->auth_xform);
1002 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1004 /* Generate Crypto op data structure */
1005 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1006 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1007 TEST_ASSERT_NOT_NULL(ut_params->op,
1008 "Failed to allocate symmetric crypto operation struct");
1010 /* attach symmetric crypto session to crypto operations */
1011 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1013 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1015 /* set crypto operation source mbuf */
1016 sym_op->m_src = ut_params->ibuf;
1018 sym_op->auth.digest.data = ut_params->digest;
1019 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1020 ut_params->ibuf, QUOTE_512_BYTES);
1021 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1023 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1024 sym_op->auth.data.length = QUOTE_512_BYTES;
1026 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1027 CIPHER_IV_LENGTH_AES_CBC);
1028 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1029 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1031 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1032 CIPHER_IV_LENGTH_AES_CBC);
1034 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1035 sym_op->cipher.data.length = QUOTE_512_BYTES;
1038 /* Process crypto operation */
1039 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1040 ut_params->op), "failed to process sym crypto op");
1042 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1043 "crypto op processing failed");
1045 ut_params->obuf = ut_params->op->sym->m_src;
1049 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1050 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1051 CIPHER_IV_LENGTH_AES_CBC,
1054 "Ciphertext data not as expected");
1056 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1057 "Digest verification failed");
1060 return TEST_SUCCESS;
1064 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1066 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1068 static uint8_t hmac_sha256_key[] = {
1069 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1070 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1071 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1072 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1074 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1075 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1076 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1077 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1078 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1081 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1083 struct crypto_testsuite_params *ts_params = &testsuite_params;
1084 struct crypto_unittest_params *ut_params = &unittest_params;
1086 /* Generate test mbuf data and space for digest */
1087 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1088 catch_22_quote, QUOTE_512_BYTES, 0);
1090 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1091 DIGEST_BYTE_LENGTH_SHA256);
1092 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1094 /* Setup Cipher Parameters */
1095 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1096 ut_params->cipher_xform.next = &ut_params->auth_xform;
1098 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1099 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1100 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1101 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1103 /* Setup HMAC Parameters */
1104 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1105 ut_params->auth_xform.next = NULL;
1107 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1108 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1109 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1110 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1111 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1113 /* Create Crypto session*/
1114 ut_params->sess = rte_cryptodev_sym_session_create(
1115 ts_params->valid_devs[0],
1116 &ut_params->cipher_xform);
1117 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1119 /* Generate Crypto op data structure */
1120 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1121 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1122 TEST_ASSERT_NOT_NULL(ut_params->op,
1123 "Failed to allocate symmetric crypto operation struct");
1125 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1127 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1129 /* set crypto operation source mbuf */
1130 sym_op->m_src = ut_params->ibuf;
1132 sym_op->auth.digest.data = ut_params->digest;
1133 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1134 ut_params->ibuf, QUOTE_512_BYTES);
1135 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1137 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1138 sym_op->auth.data.length = QUOTE_512_BYTES;
1140 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1141 CIPHER_IV_LENGTH_AES_CBC);
1142 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1143 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1145 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1146 CIPHER_IV_LENGTH_AES_CBC);
1148 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1149 sym_op->cipher.data.length = QUOTE_512_BYTES;
1151 /* Process crypto operation */
1152 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1153 ut_params->op), "failed to process sym crypto op");
1155 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1156 "crypto op processing failed");
1158 ut_params->obuf = ut_params->op->sym->m_src;
1161 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1162 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1163 CIPHER_IV_LENGTH_AES_CBC,
1164 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1166 "Ciphertext data not as expected");
1168 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1169 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1170 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1171 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1172 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1173 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1174 DIGEST_BYTE_LENGTH_SHA256,
1175 "Generated digest data not as expected");
1178 return TEST_SUCCESS;
1182 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1184 struct crypto_testsuite_params *ts_params = &testsuite_params;
1185 struct crypto_unittest_params *ut_params = &unittest_params;
1187 /* Generate test mbuf data and digest */
1188 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1190 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1191 QUOTE_512_BYTES, 0);
1193 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1194 DIGEST_BYTE_LENGTH_SHA256);
1195 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1197 rte_memcpy(ut_params->digest,
1198 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1199 DIGEST_BYTE_LENGTH_SHA256);
1201 /* Setup Cipher Parameters */
1202 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1203 ut_params->cipher_xform.next = NULL;
1205 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1206 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1207 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1208 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1210 /* Setup HMAC Parameters */
1211 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1212 ut_params->auth_xform.next = &ut_params->cipher_xform;
1214 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1215 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1216 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1217 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1218 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1220 /* Create Crypto session*/
1222 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1223 &ut_params->auth_xform);
1224 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1226 /* Generate Crypto op data structure */
1227 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1228 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1229 TEST_ASSERT_NOT_NULL(ut_params->op,
1230 "Failed to allocate symmetric crypto operation struct");
1233 /* Set crypto operation data parameters */
1234 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1236 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1238 /* set crypto operation source mbuf */
1239 sym_op->m_src = ut_params->ibuf;
1241 sym_op->auth.digest.data = ut_params->digest;
1242 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1243 ut_params->ibuf, QUOTE_512_BYTES);
1244 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1246 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1247 sym_op->auth.data.length = QUOTE_512_BYTES;
1249 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1250 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1251 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1252 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1254 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1255 CIPHER_IV_LENGTH_AES_CBC);
1257 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1258 sym_op->cipher.data.length = QUOTE_512_BYTES;
1260 /* Process crypto operation */
1261 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1262 ut_params->op), "failed to process sym crypto op");
1264 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1265 "crypto op processing failed");
1267 ut_params->obuf = ut_params->op->sym->m_src;
1270 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1271 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1272 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1274 "Plaintext data not as expected");
1276 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1277 "Digest verification failed");
1279 return TEST_SUCCESS;
1282 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1284 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1286 static uint8_t hmac_sha512_key[] = {
1287 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1288 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1289 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1290 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1291 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1292 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1293 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1294 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1296 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1297 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1298 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1299 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1300 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1301 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1302 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1303 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1304 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1307 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1309 struct crypto_testsuite_params *ts_params = &testsuite_params;
1310 struct crypto_unittest_params *ut_params = &unittest_params;
1312 /* Generate test mbuf data and space for digest */
1313 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1314 catch_22_quote, QUOTE_512_BYTES, 0);
1316 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1317 DIGEST_BYTE_LENGTH_SHA512);
1318 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1320 /* Setup Cipher Parameters */
1321 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1322 ut_params->cipher_xform.next = &ut_params->auth_xform;
1324 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1325 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1326 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1327 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1329 /* Setup HMAC Parameters */
1330 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1331 ut_params->auth_xform.next = NULL;
1333 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1334 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1335 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1336 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1337 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1339 /* Create Crypto session*/
1341 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1342 &ut_params->cipher_xform);
1344 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1346 /* Generate Crypto op data structure */
1347 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1348 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1349 TEST_ASSERT_NOT_NULL(ut_params->op,
1350 "Failed to allocate symmetric crypto operation struct");
1352 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1354 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1356 /* set crypto operation source mbuf */
1357 sym_op->m_src = ut_params->ibuf;
1359 sym_op->auth.digest.data = ut_params->digest;
1360 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1361 ut_params->ibuf, QUOTE_512_BYTES);
1362 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1364 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1365 sym_op->auth.data.length = QUOTE_512_BYTES;
1367 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1368 CIPHER_IV_LENGTH_AES_CBC);
1369 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1370 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1372 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1373 CIPHER_IV_LENGTH_AES_CBC);
1375 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1376 sym_op->cipher.data.length = QUOTE_512_BYTES;
1378 /* Process crypto operation */
1379 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1380 ut_params->op), "failed to process sym crypto op");
1382 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1383 "crypto op processing failed");
1385 ut_params->obuf = ut_params->op->sym->m_src;
1388 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1389 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1390 CIPHER_IV_LENGTH_AES_CBC,
1391 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1393 "Ciphertext data not as expected");
1395 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1396 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1397 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1398 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1399 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1400 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1401 DIGEST_BYTE_LENGTH_SHA512,
1402 "Generated digest data not as expected");
1404 return TEST_SUCCESS;
1409 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1410 struct crypto_unittest_params *ut_params);
1413 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1414 struct crypto_unittest_params *ut_params,
1415 struct crypto_testsuite_params *ts_params);
1418 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1420 struct crypto_unittest_params *ut_params = &unittest_params;
1421 struct crypto_testsuite_params *ts_params = &testsuite_params;
1423 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1424 ut_params) == TEST_SUCCESS,
1425 "Failed to create session params");
1427 /* Create Crypto session*/
1429 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1430 &ut_params->auth_xform);
1431 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1433 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1434 ut_params, ts_params);
1438 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1439 struct crypto_unittest_params *ut_params)
1442 /* Setup Cipher Parameters */
1443 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1444 ut_params->cipher_xform.next = NULL;
1446 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1447 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1448 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1449 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1451 /* Setup HMAC Parameters */
1452 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1453 ut_params->auth_xform.next = &ut_params->cipher_xform;
1455 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1456 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1457 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1458 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1459 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1461 return TEST_SUCCESS;
1466 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1467 struct crypto_unittest_params *ut_params,
1468 struct crypto_testsuite_params *ts_params)
1470 /* Generate test mbuf data and digest */
1471 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1473 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1474 QUOTE_512_BYTES, 0);
1476 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1477 DIGEST_BYTE_LENGTH_SHA512);
1478 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1480 rte_memcpy(ut_params->digest,
1481 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1482 DIGEST_BYTE_LENGTH_SHA512);
1484 /* Generate Crypto op data structure */
1485 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1486 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1487 TEST_ASSERT_NOT_NULL(ut_params->op,
1488 "Failed to allocate symmetric crypto operation struct");
1490 rte_crypto_op_attach_sym_session(ut_params->op, sess);
1492 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1494 /* set crypto operation source mbuf */
1495 sym_op->m_src = ut_params->ibuf;
1497 sym_op->auth.digest.data = ut_params->digest;
1498 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1499 ut_params->ibuf, QUOTE_512_BYTES);
1500 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1502 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1503 sym_op->auth.data.length = QUOTE_512_BYTES;
1505 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1506 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1507 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
1508 ut_params->ibuf, 0);
1509 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1511 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1512 CIPHER_IV_LENGTH_AES_CBC);
1514 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1515 sym_op->cipher.data.length = QUOTE_512_BYTES;
1517 /* Process crypto operation */
1518 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1519 ut_params->op), "failed to process sym crypto op");
1521 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1522 "crypto op processing failed");
1524 ut_params->obuf = ut_params->op->sym->m_src;
1527 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1528 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1529 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1531 "Plaintext data not as expected");
1534 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1535 "Digest verification failed");
1537 return TEST_SUCCESS;
1540 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
1542 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
1543 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
1544 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
1547 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
1548 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
1549 0x77, 0x1D, 0x8B, 0x75
1553 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
1555 struct crypto_testsuite_params *ts_params = &testsuite_params;
1556 struct crypto_unittest_params *ut_params = &unittest_params;
1558 /* Generate test mbuf data and space for digest */
1559 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1560 catch_22_quote, QUOTE_512_BYTES, 0);
1562 /* Setup Cipher Parameters */
1563 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1564 ut_params->cipher_xform.next = &ut_params->auth_xform;
1566 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1567 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1568 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1569 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1571 /* Setup HMAC Parameters */
1572 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1573 ut_params->auth_xform.next = NULL;
1575 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1576 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1577 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1578 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1579 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1581 /* Create Crypto session*/
1582 ut_params->sess = rte_cryptodev_sym_session_create(
1583 ts_params->valid_devs[0],
1584 &ut_params->cipher_xform);
1585 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1587 /* Generate Crypto op data structure */
1588 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1589 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1590 TEST_ASSERT_NOT_NULL(ut_params->op,
1591 "Failed to allocate symmetric crypto operation struct");
1593 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1595 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1597 /* set crypto operation source mbuf */
1598 sym_op->m_src = ut_params->ibuf;
1600 /* Set operation cipher parameters */
1601 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1602 sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
1603 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1604 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1606 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1607 CIPHER_IV_LENGTH_AES_CBC);
1609 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1610 sym_op->cipher.data.length = QUOTE_512_BYTES;
1612 /* Set operation authentication parameters */
1613 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1614 sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
1615 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1617 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
1618 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1620 memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
1622 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1623 sym_op->auth.data.length = QUOTE_512_BYTES;
1626 /* Process crypto operation */
1627 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1629 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
1631 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1632 "crypto op processing failed");
1635 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1636 rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1637 uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
1638 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1640 "Ciphertext data not as expected");
1642 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1643 rte_pktmbuf_mtod_offset(
1644 ut_params->op->sym->m_src, uint8_t *,
1645 CIPHER_IV_LENGTH_AES_CBC +
1647 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1648 DIGEST_BYTE_LENGTH_AES_XCBC,
1649 "Generated digest data not as expected");
1651 return TEST_SUCCESS;
1655 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
1657 struct crypto_testsuite_params *ts_params = &testsuite_params;
1658 struct crypto_unittest_params *ut_params = &unittest_params;
1660 /* Generate test mbuf data and space for digest */
1661 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1662 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1663 QUOTE_512_BYTES, 0);
1665 /* Setup Cipher Parameters */
1666 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1667 ut_params->cipher_xform.next = NULL;
1669 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1670 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1671 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1672 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1674 /* Setup HMAC Parameters */
1675 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1676 ut_params->auth_xform.next = &ut_params->cipher_xform;
1678 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1679 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
1680 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
1681 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
1682 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
1684 /* Create Crypto session*/
1686 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1687 &ut_params->auth_xform);
1688 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1690 /* Generate Crypto op data structure */
1691 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1692 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1693 TEST_ASSERT_NOT_NULL(ut_params->op,
1694 "Failed to allocate symmetric crypto operation struct");
1696 /* Set crypto operation data parameters */
1697 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1699 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1701 /* set crypto operation source mbuf */
1702 sym_op->m_src = ut_params->ibuf;
1705 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1706 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
1707 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
1708 "no room to append digest");
1710 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1711 ut_params->ibuf, QUOTE_512_BYTES);
1712 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
1714 rte_memcpy(sym_op->auth.digest.data,
1715 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
1716 DIGEST_BYTE_LENGTH_AES_XCBC);
1718 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1719 sym_op->auth.data.length = QUOTE_512_BYTES;
1721 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1722 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1723 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1724 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1726 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1727 CIPHER_IV_LENGTH_AES_CBC);
1729 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1730 sym_op->cipher.data.length = QUOTE_512_BYTES;
1732 /* Process crypto operation */
1733 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1734 ut_params->op), "failed to process sym crypto op");
1736 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1737 "crypto op processing failed");
1739 ut_params->obuf = ut_params->op->sym->m_src;
1742 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1743 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1744 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1746 "Ciphertext data not as expected");
1748 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1749 "Digest verification failed");
1751 return TEST_SUCCESS;
1754 /* ***** Snow3G Tests ***** */
1756 create_snow3g_hash_session(uint8_t dev_id,
1757 const uint8_t *key, const uint8_t key_len,
1758 const uint8_t aad_len, const uint8_t auth_len,
1759 enum rte_crypto_auth_operation op)
1761 uint8_t hash_key[key_len];
1763 struct crypto_unittest_params *ut_params = &unittest_params;
1765 memcpy(hash_key, key, key_len);
1766 #ifdef RTE_APP_TEST_DEBUG
1767 rte_hexdump(stdout, "key:", key, key_len);
1769 /* Setup Authentication Parameters */
1770 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1771 ut_params->auth_xform.next = NULL;
1773 ut_params->auth_xform.auth.op = op;
1774 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1775 ut_params->auth_xform.auth.key.length = key_len;
1776 ut_params->auth_xform.auth.key.data = hash_key;
1777 ut_params->auth_xform.auth.digest_length = auth_len;
1778 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1779 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1780 &ut_params->auth_xform);
1781 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1785 create_snow3g_cipher_session(uint8_t dev_id,
1786 enum rte_crypto_cipher_operation op,
1787 const uint8_t *key, const uint8_t key_len)
1789 uint8_t cipher_key[key_len];
1791 struct crypto_unittest_params *ut_params = &unittest_params;
1793 memcpy(cipher_key, key, key_len);
1795 /* Setup Cipher Parameters */
1796 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1797 ut_params->cipher_xform.next = NULL;
1799 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1800 ut_params->cipher_xform.cipher.op = op;
1801 ut_params->cipher_xform.cipher.key.data = cipher_key;
1802 ut_params->cipher_xform.cipher.key.length = key_len;
1804 #ifdef RTE_APP_TEST_DEBUG
1805 rte_hexdump(stdout, "key:", key, key_len);
1807 /* Create Crypto session */
1808 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1811 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1816 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
1817 const unsigned data_len)
1819 struct crypto_testsuite_params *ts_params = &testsuite_params;
1820 struct crypto_unittest_params *ut_params = &unittest_params;
1821 unsigned iv_pad_len = 0;
1823 /* Generate Crypto op data structure */
1824 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1825 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1826 TEST_ASSERT_NOT_NULL(ut_params->op,
1827 "Failed to allocate pktmbuf offload");
1829 /* Set crypto operation data parameters */
1830 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1832 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1834 /* set crypto operation source mbuf */
1835 sym_op->m_src = ut_params->ibuf;
1838 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
1839 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
1842 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
1844 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
1845 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1846 sym_op->cipher.iv.length = iv_pad_len;
1848 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
1849 sym_op->cipher.data.length = data_len;
1850 sym_op->cipher.data.offset = iv_pad_len;
1856 create_snow3g_cipher_auth_session(uint8_t dev_id,
1857 enum rte_crypto_cipher_operation cipher_op,
1858 enum rte_crypto_auth_operation auth_op,
1859 const uint8_t *key, const uint8_t key_len,
1860 const uint8_t aad_len, const uint8_t auth_len)
1862 uint8_t cipher_auth_key[key_len];
1864 struct crypto_unittest_params *ut_params = &unittest_params;
1866 memcpy(cipher_auth_key, key, key_len);
1868 /* Setup Authentication Parameters */
1869 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1870 ut_params->auth_xform.next = NULL;
1872 ut_params->auth_xform.auth.op = auth_op;
1873 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1874 ut_params->auth_xform.auth.key.length = key_len;
1875 /* Hash key = cipher key */
1876 ut_params->auth_xform.auth.key.data = cipher_auth_key;
1877 ut_params->auth_xform.auth.digest_length = auth_len;
1878 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1880 /* Setup Cipher Parameters */
1881 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1882 ut_params->cipher_xform.next = &ut_params->auth_xform;
1884 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1885 ut_params->cipher_xform.cipher.op = cipher_op;
1886 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
1887 ut_params->cipher_xform.cipher.key.length = key_len;
1889 #ifdef RTE_APP_TEST_DEBUG
1890 rte_hexdump(stdout, "key:", key, key_len);
1892 /* Create Crypto session*/
1893 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1894 &ut_params->cipher_xform);
1896 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1901 create_snow3g_auth_cipher_session(uint8_t dev_id,
1902 enum rte_crypto_cipher_operation cipher_op,
1903 enum rte_crypto_auth_operation auth_op,
1904 const uint8_t *key, const uint8_t key_len,
1905 const uint8_t aad_len, const uint8_t auth_len)
1907 uint8_t auth_cipher_key[key_len];
1909 struct crypto_unittest_params *ut_params = &unittest_params;
1911 memcpy(auth_cipher_key, key, key_len);
1913 /* Setup Authentication Parameters */
1914 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1915 ut_params->auth_xform.auth.op = auth_op;
1916 ut_params->auth_xform.next = &ut_params->cipher_xform;
1917 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
1918 ut_params->auth_xform.auth.key.length = key_len;
1919 ut_params->auth_xform.auth.key.data = auth_cipher_key;
1920 ut_params->auth_xform.auth.digest_length = auth_len;
1921 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
1923 /* Setup Cipher Parameters */
1924 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1925 ut_params->cipher_xform.next = NULL;
1926 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
1927 ut_params->cipher_xform.cipher.op = cipher_op;
1928 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
1929 ut_params->cipher_xform.cipher.key.length = key_len;
1931 #ifdef RTE_APP_TEST_DEBUG
1932 rte_hexdump(stdout, "key:", key, key_len);
1934 /* Create Crypto session*/
1935 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
1936 &ut_params->auth_xform);
1938 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1944 create_snow3g_hash_operation(const uint8_t *auth_tag,
1945 const unsigned auth_tag_len,
1946 const uint8_t *aad, const unsigned aad_len,
1947 const unsigned data_len, unsigned data_pad_len,
1948 enum rte_crypto_auth_operation op)
1950 struct crypto_testsuite_params *ts_params = &testsuite_params;
1952 struct crypto_unittest_params *ut_params = &unittest_params;
1954 unsigned aad_buffer_len;
1956 /* Generate Crypto op data structure */
1957 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1958 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1959 TEST_ASSERT_NOT_NULL(ut_params->op,
1960 "Failed to allocate pktmbuf offload");
1962 /* Set crypto operation data parameters */
1963 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1965 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1967 /* set crypto operation source mbuf */
1968 sym_op->m_src = ut_params->ibuf;
1972 * Always allocate the aad up to the block size.
1973 * The cryptodev API calls out -
1974 * - the array must be big enough to hold the AAD, plus any
1975 * space to round this up to the nearest multiple of the
1976 * block size (16 bytes).
1978 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
1979 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
1980 ut_params->ibuf, aad_buffer_len);
1981 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
1982 "no room to prepend aad");
1983 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
1985 sym_op->auth.aad.length = aad_len;
1987 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
1988 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
1990 #ifdef RTE_APP_TEST_DEBUG
1991 rte_hexdump(stdout, "aad:",
1992 sym_op->auth.aad.data, aad_len);
1996 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1997 ut_params->ibuf, auth_tag_len);
1999 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2000 "no room to append auth tag");
2001 ut_params->digest = sym_op->auth.digest.data;
2002 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2003 ut_params->ibuf, data_pad_len + aad_len);
2004 sym_op->auth.digest.length = auth_tag_len;
2005 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2006 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2008 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2010 #ifdef RTE_APP_TEST_DEBUG
2011 rte_hexdump(stdout, "digest:",
2012 sym_op->auth.digest.data,
2013 sym_op->auth.digest.length);
2016 sym_op->auth.data.length = data_len;
2017 sym_op->auth.data.offset = aad_buffer_len;
2023 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2024 const unsigned auth_tag_len,
2025 const uint8_t *aad, const unsigned aad_len,
2026 const unsigned data_len, unsigned data_pad_len,
2027 enum rte_crypto_auth_operation op,
2028 const uint8_t *iv, const unsigned iv_len)
2030 struct crypto_testsuite_params *ts_params = &testsuite_params;
2031 struct crypto_unittest_params *ut_params = &unittest_params;
2033 unsigned iv_pad_len = 0;
2034 unsigned aad_buffer_len;
2036 /* Generate Crypto op data structure */
2037 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2038 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2039 TEST_ASSERT_NOT_NULL(ut_params->op,
2040 "Failed to allocate pktmbuf offload");
2041 /* Set crypto operation data parameters */
2042 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2044 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2046 /* set crypto operation source mbuf */
2047 sym_op->m_src = ut_params->ibuf;
2051 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2053 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2054 ut_params->ibuf, iv_pad_len);
2055 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2057 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2058 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2059 sym_op->cipher.iv.length = iv_pad_len;
2061 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2063 sym_op->cipher.data.length = data_len;
2064 sym_op->cipher.data.offset = iv_pad_len;
2068 * Always allocate the aad up to the block size.
2069 * The cryptodev API calls out -
2070 * - the array must be big enough to hold the AAD, plus any
2071 * space to round this up to the nearest multiple of the
2072 * block size (16 bytes).
2074 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2076 sym_op->auth.aad.data =
2077 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2078 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2079 "no room to prepend aad");
2080 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2082 sym_op->auth.aad.length = aad_len;
2084 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2085 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2087 #ifdef RTE_APP_TEST_DEBUG
2088 rte_hexdump(stdout, "aad:",
2089 sym_op->auth.aad.data, aad_len);
2093 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2094 ut_params->ibuf, auth_tag_len);
2096 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2097 "no room to append auth tag");
2098 ut_params->digest = sym_op->auth.digest.data;
2099 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2100 ut_params->ibuf, data_pad_len + aad_len);
2101 sym_op->auth.digest.length = auth_tag_len;
2102 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2103 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2105 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2107 #ifdef RTE_APP_TEST_DEBUG
2108 rte_hexdump(stdout, "digest:",
2109 sym_op->auth.digest.data,
2110 sym_op->auth.digest.length);
2113 sym_op->auth.data.length = data_len;
2114 sym_op->auth.data.offset = aad_buffer_len;
2120 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2121 const uint8_t *iv, const unsigned iv_len,
2122 const uint8_t *aad, const unsigned aad_len,
2123 const unsigned data_len, unsigned data_pad_len)
2125 struct crypto_testsuite_params *ts_params = &testsuite_params;
2126 struct crypto_unittest_params *ut_params = &unittest_params;
2128 unsigned iv_pad_len = 0;
2129 unsigned aad_buffer_len = 0;
2131 /* Generate Crypto op data structure */
2132 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2133 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2134 TEST_ASSERT_NOT_NULL(ut_params->op,
2135 "Failed to allocate pktmbuf offload");
2137 /* Set crypto operation data parameters */
2138 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2140 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2142 /* set crypto operation source mbuf */
2143 sym_op->m_src = ut_params->ibuf;
2146 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2147 ut_params->ibuf, auth_tag_len);
2149 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2150 "no room to append auth tag");
2152 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2153 ut_params->ibuf, data_pad_len);
2154 sym_op->auth.digest.length = auth_tag_len;
2156 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2158 #ifdef RTE_APP_TEST_DEBUG
2159 rte_hexdump(stdout, "digest:",
2160 sym_op->auth.digest.data,
2161 sym_op->auth.digest.length);
2164 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2166 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2167 ut_params->ibuf, iv_pad_len);
2168 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2170 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2171 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2172 sym_op->cipher.iv.length = iv_pad_len;
2174 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2178 * Always allocate the aad up to the block size.
2179 * The cryptodev API calls out -
2180 * - the array must be big enough to hold the AAD, plus any
2181 * space to round this up to the nearest multiple of the
2182 * block size (16 bytes).
2184 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2186 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2187 ut_params->ibuf, aad_buffer_len);
2188 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2189 "no room to prepend aad");
2190 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2192 sym_op->auth.aad.length = aad_len;
2194 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2195 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2197 #ifdef RTE_APP_TEST_DEBUG
2198 rte_hexdump(stdout, "aad:",
2199 sym_op->auth.aad.data, aad_len);
2202 sym_op->cipher.data.length = data_len;
2203 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
2205 sym_op->auth.data.length = data_len;
2206 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
2212 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2214 struct crypto_testsuite_params *ts_params = &testsuite_params;
2215 struct crypto_unittest_params *ut_params = &unittest_params;
2218 unsigned plaintext_pad_len;
2221 /* Create SNOW3G session */
2222 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2223 tdata->key.data, tdata->key.len,
2224 tdata->aad.len, tdata->digest.len,
2225 RTE_CRYPTO_AUTH_OP_GENERATE);
2229 /* alloc mbuf and set payload */
2230 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2232 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2233 rte_pktmbuf_tailroom(ut_params->ibuf));
2235 /* Append data which is padded to a multiple of */
2236 /* the algorithms block size */
2237 plaintext_pad_len = tdata->plaintext.len;
2238 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2240 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2242 /* Create SNOW3G opertaion */
2243 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2244 tdata->aad.data, tdata->aad.len, tdata->plaintext.len,
2245 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE);
2249 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2251 ut_params->obuf = ut_params->op->sym->m_src;
2252 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2253 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2254 + plaintext_pad_len + tdata->aad.len;
2257 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2260 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2261 "Snow3G Generated auth tag not as expected");
2267 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2269 struct crypto_testsuite_params *ts_params = &testsuite_params;
2270 struct crypto_unittest_params *ut_params = &unittest_params;
2273 unsigned plaintext_pad_len;
2276 /* Create SNOW3G session */
2277 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2278 tdata->key.data, tdata->key.len,
2279 tdata->aad.len, tdata->digest.len,
2280 RTE_CRYPTO_AUTH_OP_VERIFY);
2283 /* alloc mbuf and set payload */
2284 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2286 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2287 rte_pktmbuf_tailroom(ut_params->ibuf));
2289 /* Append data which is padded to a multiple */
2290 /* of the algorithms block size */
2291 plaintext_pad_len = tdata->plaintext.len;
2292 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2294 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2296 /* Create SNOW3G operation */
2297 retval = create_snow3g_hash_operation(tdata->digest.data,
2299 tdata->aad.data, tdata->aad.len,
2300 tdata->plaintext.len, plaintext_pad_len,
2301 RTE_CRYPTO_AUTH_OP_VERIFY);
2305 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2307 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2308 ut_params->obuf = ut_params->op->sym->m_src;
2309 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2310 + plaintext_pad_len + tdata->aad.len;
2313 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2323 test_snow3g_hash_generate_test_case_1(void)
2325 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2329 test_snow3g_hash_generate_test_case_2(void)
2331 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2335 test_snow3g_hash_generate_test_case_3(void)
2337 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2341 test_snow3g_hash_verify_test_case_1(void)
2343 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2348 test_snow3g_hash_verify_test_case_2(void)
2350 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2354 test_snow3g_hash_verify_test_case_3(void)
2356 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2360 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2362 struct crypto_testsuite_params *ts_params = &testsuite_params;
2363 struct crypto_unittest_params *ut_params = &unittest_params;
2367 uint8_t *plaintext, *ciphertext;
2368 uint8_t plaintext_pad_len;
2369 uint8_t lastByteValidBits = 8;
2370 uint8_t lastByteMask = 0xFF;
2372 /* Create SNOW3G session */
2373 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2374 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2375 tdata->key.data, tdata->key.len);
2379 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2381 /* Clear mbuf payload */
2382 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2383 rte_pktmbuf_tailroom(ut_params->ibuf));
2386 * Append data which is padded to a
2387 * multiple of the algorithms block size
2389 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
2391 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2393 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2395 #ifdef RTE_APP_TEST_DEBUG
2396 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2398 /* Create SNOW3G operation */
2399 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2400 tdata->plaintext.len);
2404 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2406 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2408 ut_params->obuf = ut_params->op->sym->m_src;
2409 if (ut_params->obuf)
2410 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2413 ciphertext = plaintext;
2415 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2416 if (lastByteValidBits == 0)
2417 lastByteValidBits = 8;
2418 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2419 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2421 #ifdef RTE_APP_TEST_DEBUG
2422 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2425 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2427 tdata->ciphertext.data,
2428 tdata->ciphertext.len,
2429 "Snow3G Ciphertext data not as expected");
2433 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
2435 struct crypto_testsuite_params *ts_params = &testsuite_params;
2436 struct crypto_unittest_params *ut_params = &unittest_params;
2440 uint8_t *plaintext, *ciphertext;
2441 uint8_t ciphertext_pad_len;
2442 uint8_t lastByteValidBits = 8;
2443 uint8_t lastByteMask = 0xFF;
2445 /* Create SNOW3G session */
2446 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2447 RTE_CRYPTO_CIPHER_OP_DECRYPT,
2448 tdata->key.data, tdata->key.len);
2452 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2454 /* Clear mbuf payload */
2455 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2456 rte_pktmbuf_tailroom(ut_params->ibuf));
2459 * Append data which is padded to a
2460 * multiple of the algorithms block size
2462 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
2464 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2465 ciphertext_pad_len);
2466 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
2468 #ifdef RTE_APP_TEST_DEBUG
2469 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2471 /* Create SNOW3G operation */
2472 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2473 tdata->ciphertext.len);
2477 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2479 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2480 ut_params->obuf = ut_params->op->sym->m_src;
2481 if (ut_params->obuf)
2482 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2485 plaintext = ciphertext;
2486 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2487 if (lastByteValidBits == 0)
2488 lastByteValidBits = 8;
2489 lastByteMask = lastByteMask << (8 - lastByteValidBits);
2490 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2492 #ifdef RTE_APP_TEST_DEBUG
2493 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2496 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
2497 tdata->plaintext.data,
2498 tdata->plaintext.len,
2499 "Snow3G Plaintext data not as expected");
2504 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
2506 struct crypto_testsuite_params *ts_params = &testsuite_params;
2507 struct crypto_unittest_params *ut_params = &unittest_params;
2511 uint8_t *plaintext, *ciphertext;
2512 uint8_t plaintext_pad_len;
2513 uint8_t lastByteValidBits = 8;
2514 uint8_t lastByteMask = 0xFF;
2516 /* Create SNOW3G session */
2517 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
2518 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2519 RTE_CRYPTO_AUTH_OP_GENERATE,
2520 tdata->key.data, tdata->key.len,
2521 tdata->aad.len, tdata->digest.len);
2524 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2526 /* clear mbuf payload */
2527 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2528 rte_pktmbuf_tailroom(ut_params->ibuf));
2530 /* Append data which is padded to a multiple */
2531 /* of the algorithms block size */
2532 plaintext_pad_len = tdata->plaintext.len;
2534 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2536 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2538 #ifdef RTE_APP_TEST_DEBUG
2539 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2542 /* Create SNOW3G operation */
2543 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
2544 tdata->digest.len, tdata->aad.data,
2545 tdata->aad.len, tdata->plaintext.len,
2546 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2547 tdata->iv.data, tdata->iv.len);
2551 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2553 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2554 ut_params->obuf = ut_params->op->sym->m_src;
2555 if (ut_params->obuf)
2556 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2559 ciphertext = plaintext;
2560 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2561 if (lastByteValidBits == 0)
2562 lastByteValidBits = 8;
2563 lastByteMask = lastByteMask << (8-lastByteValidBits);
2564 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2566 #ifdef RTE_APP_TEST_DEBUG
2567 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2570 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2572 tdata->ciphertext.data,
2573 tdata->ciphertext.len,
2574 "Snow3G Ciphertext data not as expected");
2576 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2577 + plaintext_pad_len + tdata->aad.len;
2580 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2583 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2584 "Snow3G Generated auth tag not as expected");
2588 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
2590 struct crypto_testsuite_params *ts_params = &testsuite_params;
2591 struct crypto_unittest_params *ut_params = &unittest_params;
2595 uint8_t *plaintext, *ciphertext;
2596 uint8_t plaintext_pad_len;
2597 uint8_t lastByteValidBits = 8;
2598 uint8_t lastByteMask = 0xFF;
2600 /* Create SNOW3G session */
2601 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
2602 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2603 RTE_CRYPTO_AUTH_OP_GENERATE,
2604 tdata->key.data, tdata->key.len,
2605 tdata->aad.len, tdata->digest.len);
2609 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2611 /* clear mbuf payload */
2612 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2613 rte_pktmbuf_tailroom(ut_params->ibuf));
2615 /* Append data which is padded to a multiple */
2616 /* of the algorithms block size */
2617 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 8);
2619 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2621 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
2623 #ifdef RTE_APP_TEST_DEBUG
2624 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2627 /* Create SNOW3G operation */
2628 retval = create_snow3g_auth_cipher_operation(
2630 tdata->iv.data, tdata->iv.len,
2631 tdata->aad.data, tdata->aad.len,
2632 tdata->plaintext.len, plaintext_pad_len
2638 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2640 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2641 ut_params->obuf = ut_params->op->sym->m_src;
2642 if (ut_params->obuf)
2643 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2644 + tdata->aad.len + tdata->iv.len;
2646 ciphertext = plaintext;
2648 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
2649 if (lastByteValidBits == 0)
2650 lastByteValidBits = 8;
2651 lastByteMask = lastByteMask << (8-lastByteValidBits);
2652 (*(ciphertext + tdata->ciphertext.len - 1)) &= lastByteMask;
2653 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2654 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
2656 #ifdef RTE_APP_TEST_DEBUG
2657 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
2660 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2662 tdata->ciphertext.data,
2663 tdata->ciphertext.len,
2664 "Snow3G Ciphertext data not as expected");
2667 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2670 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2671 "Snow3G Generated auth tag not as expected");
2676 test_snow3g_encryption_test_case_1(void)
2678 return test_snow3g_encryption(&snow3g_test_case_1);
2682 test_snow3g_encryption_test_case_2(void)
2684 return test_snow3g_encryption(&snow3g_test_case_2);
2688 test_snow3g_encryption_test_case_3(void)
2690 return test_snow3g_encryption(&snow3g_test_case_3);
2694 test_snow3g_encryption_test_case_4(void)
2696 return test_snow3g_encryption(&snow3g_test_case_4);
2700 test_snow3g_encryption_test_case_5(void)
2702 return test_snow3g_encryption(&snow3g_test_case_5);
2706 test_snow3g_decryption_test_case_1(void)
2708 return test_snow3g_decryption(&snow3g_test_case_1);
2712 test_snow3g_decryption_test_case_2(void)
2714 return test_snow3g_decryption(&snow3g_test_case_2);
2718 test_snow3g_decryption_test_case_3(void)
2720 return test_snow3g_decryption(&snow3g_test_case_3);
2724 test_snow3g_decryption_test_case_4(void)
2726 return test_snow3g_decryption(&snow3g_test_case_4);
2730 test_snow3g_decryption_test_case_5(void)
2732 return test_snow3g_decryption(&snow3g_test_case_5);
2735 test_snow3g_authenticated_encryption_test_case_1(void)
2737 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
2741 test_snow3g_encrypted_authentication_test_case_1(void)
2743 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
2746 /* ***** AES-GCM Tests ***** */
2751 struct crypto_testsuite_params *ts_params = &testsuite_params;
2752 struct rte_cryptodev_stats stats;
2753 struct rte_cryptodev *dev;
2754 cryptodev_stats_get_t temp_pfn;
2756 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2757 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
2758 &stats) == -ENODEV),
2759 "rte_cryptodev_stats_get invalid dev failed");
2760 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
2761 "rte_cryptodev_stats_get invalid Param failed");
2762 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
2763 temp_pfn = dev->dev_ops->stats_get;
2764 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
2765 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
2767 "rte_cryptodev_stats_get invalid Param failed");
2768 dev->dev_ops->stats_get = temp_pfn;
2770 /* Test expected values */
2772 test_AES_CBC_HMAC_SHA1_encrypt_digest();
2774 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2776 "rte_cryptodev_stats_get failed");
2777 TEST_ASSERT((stats.enqueued_count == 1),
2778 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2779 TEST_ASSERT((stats.dequeued_count == 1),
2780 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2781 TEST_ASSERT((stats.enqueue_err_count == 0),
2782 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2783 TEST_ASSERT((stats.dequeue_err_count == 0),
2784 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2786 /* invalid device but should ignore and not reset device stats*/
2787 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
2788 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2790 "rte_cryptodev_stats_get failed");
2791 TEST_ASSERT((stats.enqueued_count == 1),
2792 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2794 /* check that a valid reset clears stats */
2795 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
2796 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
2798 "rte_cryptodev_stats_get failed");
2799 TEST_ASSERT((stats.enqueued_count == 0),
2800 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2801 TEST_ASSERT((stats.dequeued_count == 0),
2802 "rte_cryptodev_stats_get returned unexpected enqueued stat");
2804 return TEST_SUCCESS;
2809 test_multi_session(void)
2811 struct crypto_testsuite_params *ts_params = &testsuite_params;
2812 struct crypto_unittest_params *ut_params = &unittest_params;
2814 struct rte_cryptodev_info dev_info;
2815 struct rte_cryptodev_sym_session **sessions;
2819 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2822 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
2824 sessions = rte_malloc(NULL,
2825 (sizeof(struct rte_cryptodev_sym_session *) *
2826 dev_info.sym.max_nb_sessions) + 1, 0);
2828 /* Create multiple crypto sessions*/
2829 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
2830 sessions[i] = rte_cryptodev_sym_session_create(
2831 ts_params->valid_devs[0],
2832 &ut_params->auth_xform);
2833 TEST_ASSERT_NOT_NULL(sessions[i],
2834 "Session creation failed at session number %u",
2837 /* Attempt to send a request on each session */
2838 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
2839 sessions[i], ut_params, ts_params),
2840 "Failed to perform decrypt on request "
2842 /* free crypto operation structure */
2844 rte_crypto_op_free(ut_params->op);
2847 * free mbuf - both obuf and ibuf are usually the same,
2848 * but rte copes even if we call free twice
2850 if (ut_params->obuf) {
2851 rte_pktmbuf_free(ut_params->obuf);
2852 ut_params->obuf = 0;
2856 /* Next session create should fail */
2857 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2858 &ut_params->auth_xform);
2859 TEST_ASSERT_NULL(sessions[i],
2860 "Session creation succeeded unexpectedly!");
2862 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
2863 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
2868 return TEST_SUCCESS;
2872 test_not_in_place_crypto(void)
2874 struct crypto_testsuite_params *ts_params = &testsuite_params;
2875 struct crypto_unittest_params *ut_params = &unittest_params;
2876 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2878 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
2880 /* Create multiple crypto sessions*/
2882 ut_params->sess = rte_cryptodev_sym_session_create(
2883 ts_params->valid_devs[0], &ut_params->auth_xform);
2885 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2888 /* Generate test mbuf data and digest */
2889 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2891 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2892 QUOTE_512_BYTES, 0);
2894 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2895 DIGEST_BYTE_LENGTH_SHA512);
2896 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2898 rte_memcpy(ut_params->digest,
2899 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
2900 DIGEST_BYTE_LENGTH_SHA512);
2902 /* Generate Crypto op data structure */
2903 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2904 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2905 TEST_ASSERT_NOT_NULL(ut_params->op,
2906 "Failed to allocate symmetric crypto operation struct");
2909 /* Set crypto operation data parameters */
2910 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2912 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2914 /* set crypto operation source mbuf */
2915 sym_op->m_src = ut_params->ibuf;
2916 sym_op->m_dst = dst_m;
2918 sym_op->auth.digest.data = ut_params->digest;
2919 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2920 ut_params->ibuf, QUOTE_512_BYTES);
2921 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
2923 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2924 sym_op->auth.data.length = QUOTE_512_BYTES;
2927 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2928 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2929 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
2930 ut_params->ibuf, 0);
2931 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2933 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2934 CIPHER_IV_LENGTH_AES_CBC);
2936 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2937 sym_op->cipher.data.length = QUOTE_512_BYTES;
2939 /* Process crypto operation */
2940 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2942 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
2944 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2945 "crypto operation processing failed");
2948 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2949 rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
2952 "Plaintext data not as expected");
2956 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2957 "Digest verification failed");
2959 return TEST_SUCCESS;
2963 static struct unit_test_suite cryptodev_qat_testsuite = {
2964 .suite_name = "Crypto QAT Unit Test Suite",
2965 .setup = testsuite_setup,
2966 .teardown = testsuite_teardown,
2967 .unit_test_cases = {
2968 TEST_CASE_ST(ut_setup, ut_teardown,
2969 test_device_configure_invalid_dev_id),
2970 TEST_CASE_ST(ut_setup, ut_teardown,
2971 test_device_configure_invalid_queue_pair_ids),
2972 TEST_CASE_ST(ut_setup, ut_teardown,
2973 test_queue_pair_descriptor_setup),
2974 TEST_CASE_ST(ut_setup, ut_teardown,
2975 test_multi_session),
2977 TEST_CASE_ST(ut_setup, ut_teardown,
2978 test_AES_CBC_HMAC_SHA1_encrypt_digest),
2979 TEST_CASE_ST(ut_setup, ut_teardown,
2980 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
2982 TEST_CASE_ST(ut_setup, ut_teardown,
2983 test_AES_CBC_HMAC_SHA256_encrypt_digest),
2984 TEST_CASE_ST(ut_setup, ut_teardown,
2985 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
2987 TEST_CASE_ST(ut_setup, ut_teardown,
2988 test_AES_CBC_HMAC_SHA512_encrypt_digest),
2989 TEST_CASE_ST(ut_setup, ut_teardown,
2990 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
2992 TEST_CASE_ST(ut_setup, ut_teardown,
2993 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
2994 TEST_CASE_ST(ut_setup, ut_teardown,
2995 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
2996 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
2997 /** Snow3G encrypt only (UEA2) */
2998 TEST_CASE_ST(ut_setup, ut_teardown,
2999 test_snow3g_encryption_test_case_1),
3000 TEST_CASE_ST(ut_setup, ut_teardown,
3001 test_snow3g_encryption_test_case_2),
3002 TEST_CASE_ST(ut_setup, ut_teardown,
3003 test_snow3g_encryption_test_case_3),
3004 TEST_CASE_ST(ut_setup, ut_teardown,
3005 test_snow3g_encryption_test_case_4),
3006 TEST_CASE_ST(ut_setup, ut_teardown,
3007 test_snow3g_encryption_test_case_5),
3010 /** Snow3G decrypt only (UEA2) */
3011 TEST_CASE_ST(ut_setup, ut_teardown,
3012 test_snow3g_decryption_test_case_1),
3013 TEST_CASE_ST(ut_setup, ut_teardown,
3014 test_snow3g_decryption_test_case_2),
3015 TEST_CASE_ST(ut_setup, ut_teardown,
3016 test_snow3g_decryption_test_case_3),
3017 TEST_CASE_ST(ut_setup, ut_teardown,
3018 test_snow3g_decryption_test_case_4),
3019 TEST_CASE_ST(ut_setup, ut_teardown,
3020 test_snow3g_decryption_test_case_5),
3021 TEST_CASE_ST(ut_setup, ut_teardown,
3022 test_snow3g_hash_generate_test_case_1),
3023 TEST_CASE_ST(ut_setup, ut_teardown,
3024 test_snow3g_hash_generate_test_case_2),
3025 TEST_CASE_ST(ut_setup, ut_teardown,
3026 test_snow3g_hash_generate_test_case_3),
3027 TEST_CASE_ST(ut_setup, ut_teardown,
3028 test_snow3g_hash_verify_test_case_1),
3029 TEST_CASE_ST(ut_setup, ut_teardown,
3030 test_snow3g_hash_verify_test_case_2),
3031 TEST_CASE_ST(ut_setup, ut_teardown,
3032 test_snow3g_hash_verify_test_case_3),
3033 TEST_CASE_ST(ut_setup, ut_teardown,
3034 test_snow3g_authenticated_encryption_test_case_1),
3035 TEST_CASE_ST(ut_setup, ut_teardown,
3036 test_snow3g_encrypted_authentication_test_case_1),
3037 TEST_CASES_END() /**< NULL terminate unit test array */
3041 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
3042 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
3043 .setup = testsuite_setup,
3044 .teardown = testsuite_teardown,
3045 .unit_test_cases = {
3046 TEST_CASE_ST(ut_setup, ut_teardown,
3047 test_AES_CBC_HMAC_SHA1_encrypt_digest),
3048 TEST_CASE_ST(ut_setup, ut_teardown,
3049 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
3051 TEST_CASE_ST(ut_setup, ut_teardown,
3052 test_AES_CBC_HMAC_SHA256_encrypt_digest),
3053 TEST_CASE_ST(ut_setup, ut_teardown,
3054 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
3056 TEST_CASE_ST(ut_setup, ut_teardown,
3057 test_AES_CBC_HMAC_SHA512_encrypt_digest),
3058 TEST_CASE_ST(ut_setup, ut_teardown,
3059 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
3061 TEST_CASE_ST(ut_setup, ut_teardown,
3062 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
3063 TEST_CASE_ST(ut_setup, ut_teardown,
3064 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
3066 TEST_CASE_ST(ut_setup, ut_teardown,
3067 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
3069 TEST_CASE_ST(ut_setup, ut_teardown,
3070 test_not_in_place_crypto),
3072 TEST_CASES_END() /**< NULL terminate unit test array */
3077 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
3079 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
3080 return unit_test_suite_runner(&cryptodev_qat_testsuite);
3082 static struct test_command cryptodev_qat_cmd = {
3083 .command = "cryptodev_qat_autotest",
3084 .callback = test_cryptodev_qat,
3088 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
3090 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
3092 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
3095 static struct test_command cryptodev_aesni_mb_cmd = {
3096 .command = "cryptodev_aesni_mb_autotest",
3097 .callback = test_cryptodev_aesni_mb,
3100 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
3101 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);