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"
46 #include "test_cryptodev_aes_ctr_test_vectors.h"
47 #include "test_cryptodev_snow3g_test_vectors.h"
48 #include "test_cryptodev_snow3g_hash_test_vectors.h"
49 #include "test_cryptodev_gcm_test_vectors.h"
51 static enum rte_cryptodev_type gbl_cryptodev_type;
53 struct crypto_testsuite_params {
54 struct rte_mempool *mbuf_pool;
55 struct rte_mempool *op_mpool;
56 struct rte_cryptodev_config conf;
57 struct rte_cryptodev_qp_conf qp_conf;
59 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
60 uint8_t valid_dev_count;
63 struct crypto_unittest_params {
64 struct rte_crypto_sym_xform cipher_xform;
65 struct rte_crypto_sym_xform auth_xform;
67 struct rte_cryptodev_sym_session *sess;
69 struct rte_crypto_op *op;
71 struct rte_mbuf *obuf, *ibuf;
76 #define ALIGN_POW2_ROUNDUP(num, align) \
77 (((num) + (align) - 1) & ~((align) - 1))
80 * Forward declarations.
83 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
84 struct crypto_unittest_params *ut_params);
87 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
88 struct crypto_unittest_params *ut_params,
89 struct crypto_testsuite_params *ts_param);
91 static struct rte_mbuf *
92 setup_test_string(struct rte_mempool *mpool,
93 const char *string, size_t len, uint8_t blocksize)
95 struct rte_mbuf *m = rte_pktmbuf_alloc(mpool);
96 size_t t_len = len - (blocksize ? (len % blocksize) : 0);
98 memset(m->buf_addr, 0, m->buf_len);
100 char *dst = rte_pktmbuf_append(m, t_len);
107 rte_memcpy(dst, string, t_len);
109 memset(dst, 0, t_len);
115 setup_oop_test_mbufs(struct rte_mbuf **ibuf, struct rte_mbuf **obuf,
116 struct rte_mempool *mpool, const char *string, size_t len,
118 *ibuf = setup_test_string(mpool, string, len, blocksize);
121 *obuf = setup_test_string(mpool, NULL, len, blocksize);
130 hexdump_mbuf_data(FILE *f, const char *title, struct rte_mbuf *m)
132 rte_hexdump(f, title, rte_pktmbuf_mtod(m, const void *), m->data_len);
136 static struct rte_crypto_op *
137 process_crypto_request(uint8_t dev_id, struct rte_crypto_op *op)
140 hexdump_mbuf_data(stdout, "Enqueued Packet", ibuf);
143 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
144 printf("Error sending packet for encryption");
150 while (rte_cryptodev_dequeue_burst(dev_id, 0, &op, 1) == 0)
155 hexdump_mbuf_data(stdout, "Dequeued Packet", obuf);
161 static struct crypto_testsuite_params testsuite_params = { NULL };
162 static struct crypto_unittest_params unittest_params;
165 testsuite_setup(void)
167 struct crypto_testsuite_params *ts_params = &testsuite_params;
168 struct rte_cryptodev_info info;
169 unsigned i, nb_devs, dev_id;
173 memset(ts_params, 0, sizeof(*ts_params));
175 ts_params->mbuf_pool = rte_mempool_lookup("CRYPTO_MBUFPOOL");
176 if (ts_params->mbuf_pool == NULL) {
177 /* Not already created so create */
178 ts_params->mbuf_pool = rte_pktmbuf_pool_create(
180 NUM_MBUFS, MBUF_CACHE_SIZE, 0, MBUF_SIZE,
182 if (ts_params->mbuf_pool == NULL) {
183 RTE_LOG(ERR, USER1, "Can't create CRYPTO_MBUFPOOL\n");
188 ts_params->op_mpool = rte_crypto_op_pool_create(
189 "MBUF_CRYPTO_SYM_OP_POOL",
190 RTE_CRYPTO_OP_TYPE_SYMMETRIC,
191 NUM_MBUFS, MBUF_CACHE_SIZE,
193 sizeof(struct rte_crypto_sym_xform),
195 if (ts_params->op_mpool == NULL) {
196 RTE_LOG(ERR, USER1, "Can't create CRYPTO_OP_POOL\n");
200 /* Create 2 AESNI MB devices if required */
201 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD) {
202 nb_devs = rte_cryptodev_count_devtype(
203 RTE_CRYPTODEV_AESNI_MB_PMD);
205 for (i = nb_devs; i < 2; i++) {
206 ret = rte_eal_vdev_init(
207 CRYPTODEV_NAME_AESNI_MB_PMD, NULL);
209 TEST_ASSERT(ret == 0,
210 "Failed to create instance %u of"
212 i, CRYPTODEV_NAME_AESNI_MB_PMD);
217 /* Create 2 AESNI GCM devices if required */
218 if (gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_GCM_PMD) {
219 nb_devs = rte_cryptodev_count_devtype(
220 RTE_CRYPTODEV_AESNI_GCM_PMD);
222 for (i = nb_devs; i < 2; i++) {
223 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
224 CRYPTODEV_NAME_AESNI_GCM_PMD, NULL),
225 "Failed to create instance %u of"
227 i, CRYPTODEV_NAME_AESNI_GCM_PMD);
232 /* Create 2 Snow3G devices if required */
233 if (gbl_cryptodev_type == RTE_CRYPTODEV_SNOW3G_PMD) {
234 nb_devs = rte_cryptodev_count_devtype(RTE_CRYPTODEV_SNOW3G_PMD);
236 for (i = nb_devs; i < 2; i++) {
237 TEST_ASSERT_SUCCESS(rte_eal_vdev_init(
238 CRYPTODEV_NAME_SNOW3G_PMD, NULL),
239 "Failed to create instance %u of"
241 i, CRYPTODEV_NAME_SNOW3G_PMD);
246 /* Create 2 NULL devices if required */
247 if (gbl_cryptodev_type == RTE_CRYPTODEV_NULL_PMD) {
248 nb_devs = rte_cryptodev_count_devtype(
249 RTE_CRYPTODEV_NULL_PMD);
251 for (i = nb_devs; i < 2; i++) {
252 int dev_id = rte_eal_vdev_init(
253 CRYPTODEV_NAME_NULL_PMD, NULL);
255 TEST_ASSERT(dev_id >= 0,
256 "Failed to create instance %u of"
258 i, CRYPTODEV_NAME_NULL_PMD);
263 nb_devs = rte_cryptodev_count();
265 RTE_LOG(ERR, USER1, "No crypto devices found?");
269 /* Create list of valid crypto devs */
270 for (i = 0; i < nb_devs; i++) {
271 rte_cryptodev_info_get(i, &info);
272 if (info.dev_type == gbl_cryptodev_type)
273 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
276 if (ts_params->valid_dev_count < 1)
279 /* Set up all the qps on the first of the valid devices found */
280 for (i = 0; i < 1; i++) {
281 dev_id = ts_params->valid_devs[i];
283 rte_cryptodev_info_get(dev_id, &info);
286 * Since we can't free and re-allocate queue memory always set
287 * the queues on this device up to max size first so enough
288 * memory is allocated for any later re-configures needed by
292 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
293 ts_params->conf.socket_id = SOCKET_ID_ANY;
294 ts_params->conf.session_mp.nb_objs = info.sym.max_nb_sessions;
296 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
298 "Failed to configure cryptodev %u with %u qps",
299 dev_id, ts_params->conf.nb_queue_pairs);
301 ts_params->qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT;
303 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
304 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
305 dev_id, qp_id, &ts_params->qp_conf,
306 rte_cryptodev_socket_id(dev_id)),
307 "Failed to setup queue pair %u on "
317 testsuite_teardown(void)
319 struct crypto_testsuite_params *ts_params = &testsuite_params;
321 if (ts_params->mbuf_pool != NULL) {
322 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
323 rte_mempool_count(ts_params->mbuf_pool));
326 if (ts_params->op_mpool != NULL) {
327 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
328 rte_mempool_count(ts_params->op_mpool));
336 struct crypto_testsuite_params *ts_params = &testsuite_params;
337 struct crypto_unittest_params *ut_params = &unittest_params;
341 /* Clear unit test parameters before running test */
342 memset(ut_params, 0, sizeof(*ut_params));
344 /* Reconfigure device to default parameters */
345 ts_params->conf.nb_queue_pairs = DEFAULT_NUM_QPS_PER_QAT_DEVICE;
346 ts_params->conf.socket_id = SOCKET_ID_ANY;
347 ts_params->conf.session_mp.nb_objs =
348 (gbl_cryptodev_type == RTE_CRYPTODEV_QAT_SYM_PMD) ?
349 DEFAULT_NUM_OPS_INFLIGHT :
350 DEFAULT_NUM_OPS_INFLIGHT;
352 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
354 "Failed to configure cryptodev %u",
355 ts_params->valid_devs[0]);
358 * Now reconfigure queues to size we actually want to use in this
361 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
363 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
364 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
365 ts_params->valid_devs[0], qp_id,
367 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
368 "Failed to setup queue pair %u on cryptodev %u",
369 qp_id, ts_params->valid_devs[0]);
373 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
375 /* Start the device */
376 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
377 "Failed to start cryptodev %u",
378 ts_params->valid_devs[0]);
386 struct crypto_testsuite_params *ts_params = &testsuite_params;
387 struct crypto_unittest_params *ut_params = &unittest_params;
388 struct rte_cryptodev_stats stats;
390 /* free crypto session structure */
391 if (ut_params->sess) {
392 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
394 ut_params->sess = NULL;
397 /* free crypto operation structure */
399 rte_crypto_op_free(ut_params->op);
402 * free mbuf - both obuf and ibuf are usually the same,
403 * but rte copes even if we call free twice
405 if (ut_params->obuf) {
406 rte_pktmbuf_free(ut_params->obuf);
409 if (ut_params->ibuf) {
410 rte_pktmbuf_free(ut_params->ibuf);
414 if (ts_params->mbuf_pool != NULL)
415 RTE_LOG(DEBUG, USER1, "CRYPTO_MBUFPOOL count %u\n",
416 rte_mempool_count(ts_params->mbuf_pool));
418 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
420 /* Stop the device */
421 rte_cryptodev_stop(ts_params->valid_devs[0]);
425 test_device_configure_invalid_dev_id(void)
427 struct crypto_testsuite_params *ts_params = &testsuite_params;
428 uint16_t dev_id, num_devs = 0;
430 TEST_ASSERT((num_devs = rte_cryptodev_count()) >= 1,
431 "Need at least %d devices for test", 1);
433 /* valid dev_id values */
434 dev_id = ts_params->valid_devs[ts_params->valid_dev_count - 1];
436 /* Stop the device in case it's started so it can be configured */
437 rte_cryptodev_stop(ts_params->valid_devs[dev_id]);
439 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id, &ts_params->conf),
440 "Failed test for rte_cryptodev_configure: "
441 "invalid dev_num %u", dev_id);
443 /* invalid dev_id values */
446 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
447 "Failed test for rte_cryptodev_configure: "
448 "invalid dev_num %u", dev_id);
452 TEST_ASSERT_FAIL(rte_cryptodev_configure(dev_id, &ts_params->conf),
453 "Failed test for rte_cryptodev_configure:"
454 "invalid dev_num %u", dev_id);
460 test_device_configure_invalid_queue_pair_ids(void)
462 struct crypto_testsuite_params *ts_params = &testsuite_params;
464 /* Stop the device in case it's started so it can be configured */
465 rte_cryptodev_stop(ts_params->valid_devs[0]);
467 /* valid - one queue pairs */
468 ts_params->conf.nb_queue_pairs = 1;
470 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
472 "Failed to configure cryptodev: dev_id %u, qp_id %u",
473 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
476 /* valid - max value queue pairs */
477 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE;
479 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
481 "Failed to configure cryptodev: dev_id %u, qp_id %u",
482 ts_params->valid_devs[0], ts_params->conf.nb_queue_pairs);
485 /* invalid - zero queue pairs */
486 ts_params->conf.nb_queue_pairs = 0;
488 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
490 "Failed test for rte_cryptodev_configure, dev_id %u,"
492 ts_params->valid_devs[0],
493 ts_params->conf.nb_queue_pairs);
496 /* invalid - max value supported by field queue pairs */
497 ts_params->conf.nb_queue_pairs = UINT16_MAX;
499 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
501 "Failed test for rte_cryptodev_configure, dev_id %u,"
503 ts_params->valid_devs[0],
504 ts_params->conf.nb_queue_pairs);
507 /* invalid - max value + 1 queue pairs */
508 ts_params->conf.nb_queue_pairs = MAX_NUM_QPS_PER_QAT_DEVICE + 1;
510 TEST_ASSERT_FAIL(rte_cryptodev_configure(ts_params->valid_devs[0],
512 "Failed test for rte_cryptodev_configure, dev_id %u,"
514 ts_params->valid_devs[0],
515 ts_params->conf.nb_queue_pairs);
521 test_queue_pair_descriptor_setup(void)
523 struct crypto_testsuite_params *ts_params = &testsuite_params;
524 struct rte_cryptodev_info dev_info;
525 struct rte_cryptodev_qp_conf qp_conf = {
526 .nb_descriptors = MAX_NUM_OPS_INFLIGHT
531 /* Stop the device in case it's started so it can be configured */
532 rte_cryptodev_stop(ts_params->valid_devs[0]);
535 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
537 ts_params->conf.session_mp.nb_objs = dev_info.sym.max_nb_sessions;
539 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
540 &ts_params->conf), "Failed to configure cryptodev %u",
541 ts_params->valid_devs[0]);
545 * Test various ring sizes on this device. memzones can't be
546 * freed so are re-used if ring is released and re-created.
548 qp_conf.nb_descriptors = MIN_NUM_OPS_INFLIGHT; /* min size*/
550 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
551 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
552 ts_params->valid_devs[0], qp_id, &qp_conf,
553 rte_cryptodev_socket_id(
554 ts_params->valid_devs[0])),
556 "rte_cryptodev_queue_pair_setup: num_inflights "
557 "%u on qp %u on cryptodev %u",
558 qp_conf.nb_descriptors, qp_id,
559 ts_params->valid_devs[0]);
562 qp_conf.nb_descriptors = (uint32_t)(MAX_NUM_OPS_INFLIGHT / 2);
564 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
565 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
566 ts_params->valid_devs[0], qp_id, &qp_conf,
567 rte_cryptodev_socket_id(
568 ts_params->valid_devs[0])),
570 " rte_cryptodev_queue_pair_setup: num_inflights"
571 " %u on qp %u on cryptodev %u",
572 qp_conf.nb_descriptors, qp_id,
573 ts_params->valid_devs[0]);
576 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT; /* valid */
578 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
579 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
580 ts_params->valid_devs[0], qp_id, &qp_conf,
581 rte_cryptodev_socket_id(
582 ts_params->valid_devs[0])),
584 "rte_cryptodev_queue_pair_setup: num_inflights"
585 " %u on qp %u on cryptodev %u",
586 qp_conf.nb_descriptors, qp_id,
587 ts_params->valid_devs[0]);
590 /* invalid number of descriptors - max supported + 2 */
591 qp_conf.nb_descriptors = MAX_NUM_OPS_INFLIGHT + 2;
593 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
594 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
595 ts_params->valid_devs[0], qp_id, &qp_conf,
596 rte_cryptodev_socket_id(
597 ts_params->valid_devs[0])),
598 "Unexpectedly passed test for "
599 "rte_cryptodev_queue_pair_setup:"
600 "num_inflights %u on qp %u on cryptodev %u",
601 qp_conf.nb_descriptors, qp_id,
602 ts_params->valid_devs[0]);
605 /* invalid number of descriptors - max value of parameter */
606 qp_conf.nb_descriptors = UINT32_MAX-1;
608 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
609 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
610 ts_params->valid_devs[0], qp_id, &qp_conf,
611 rte_cryptodev_socket_id(
612 ts_params->valid_devs[0])),
613 "Unexpectedly passed test for "
614 "rte_cryptodev_queue_pair_setup:"
615 "num_inflights %u on qp %u on cryptodev %u",
616 qp_conf.nb_descriptors, qp_id,
617 ts_params->valid_devs[0]);
620 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
622 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
623 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
624 ts_params->valid_devs[0], qp_id, &qp_conf,
625 rte_cryptodev_socket_id(
626 ts_params->valid_devs[0])),
628 " rte_cryptodev_queue_pair_setup:"
629 "num_inflights %u on qp %u on cryptodev %u",
630 qp_conf.nb_descriptors, qp_id,
631 ts_params->valid_devs[0]);
634 /* invalid number of descriptors - max supported + 1 */
635 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT + 1;
637 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs; qp_id++) {
638 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
639 ts_params->valid_devs[0], qp_id, &qp_conf,
640 rte_cryptodev_socket_id(
641 ts_params->valid_devs[0])),
642 "Unexpectedly passed test for "
643 "rte_cryptodev_queue_pair_setup:"
644 "num_inflights %u on qp %u on cryptodev %u",
645 qp_conf.nb_descriptors, qp_id,
646 ts_params->valid_devs[0]);
649 /* test invalid queue pair id */
650 qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT; /*valid */
652 qp_id = DEFAULT_NUM_QPS_PER_QAT_DEVICE; /*invalid */
654 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
655 ts_params->valid_devs[0],
657 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
658 "Failed test for rte_cryptodev_queue_pair_setup:"
659 "invalid qp %u on cryptodev %u",
660 qp_id, ts_params->valid_devs[0]);
662 qp_id = 0xffff; /*invalid*/
664 TEST_ASSERT_FAIL(rte_cryptodev_queue_pair_setup(
665 ts_params->valid_devs[0],
667 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
668 "Failed test for rte_cryptodev_queue_pair_setup:"
669 "invalid qp %u on cryptodev %u",
670 qp_id, ts_params->valid_devs[0]);
675 /* ***** Plaintext data for tests ***** */
677 const char catch_22_quote_1[] =
678 "There was only one catch and that was Catch-22, which "
679 "specified that a concern for one's safety in the face of "
680 "dangers that were real and immediate was the process of a "
681 "rational mind. Orr was crazy and could be grounded. All he "
682 "had to do was ask; and as soon as he did, he would no longer "
683 "be crazy and would have to fly more missions. Orr would be "
684 "crazy to fly more missions and sane if he didn't, but if he "
685 "was sane he had to fly them. If he flew them he was crazy "
686 "and didn't have to; but if he didn't want to he was sane and "
687 "had to. Yossarian was moved very deeply by the absolute "
688 "simplicity of this clause of Catch-22 and let out a "
689 "respectful whistle. \"That's some catch, that Catch-22\", he "
690 "observed. \"It's the best there is,\" Doc Daneeka agreed.";
692 const char catch_22_quote[] =
693 "What a lousy earth! He wondered how many people were "
694 "destitute that same night even in his own prosperous country, "
695 "how many homes were shanties, how many husbands were drunk "
696 "and wives socked, and how many children were bullied, abused, "
697 "or abandoned. How many families hungered for food they could "
698 "not afford to buy? How many hearts were broken? How many "
699 "suicides would take place that same night, how many people "
700 "would go insane? How many cockroaches and landlords would "
701 "triumph? How many winners were losers, successes failures, "
702 "and rich men poor men? How many wise guys were stupid? How "
703 "many happy endings were unhappy endings? How many honest men "
704 "were liars, brave men cowards, loyal men traitors, how many "
705 "sainted men were corrupt, how many people in positions of "
706 "trust had sold their souls to bodyguards, how many had never "
707 "had souls? How many straight-and-narrow paths were crooked "
708 "paths? How many best families were worst families and how "
709 "many good people were bad people? When you added them all up "
710 "and then subtracted, you might be left with only the children, "
711 "and perhaps with Albert Einstein and an old violinist or "
712 "sculptor somewhere.";
714 #define QUOTE_480_BYTES (480)
715 #define QUOTE_512_BYTES (512)
716 #define QUOTE_768_BYTES (768)
717 #define QUOTE_1024_BYTES (1024)
721 /* ***** SHA1 Hash Tests ***** */
723 #define HMAC_KEY_LENGTH_SHA1 (DIGEST_BYTE_LENGTH_SHA1)
725 static uint8_t hmac_sha1_key[] = {
726 0xF8, 0x2A, 0xC7, 0x54, 0xDB, 0x96, 0x18, 0xAA,
727 0xC3, 0xA1, 0x53, 0xF6, 0x1F, 0x17, 0x60, 0xBD,
728 0xDE, 0xF4, 0xDE, 0xAD };
730 /* ***** SHA224 Hash Tests ***** */
732 #define HMAC_KEY_LENGTH_SHA224 (DIGEST_BYTE_LENGTH_SHA224)
735 /* ***** AES-CBC Cipher Tests ***** */
737 #define CIPHER_KEY_LENGTH_AES_CBC (16)
738 #define CIPHER_IV_LENGTH_AES_CBC (CIPHER_KEY_LENGTH_AES_CBC)
740 static uint8_t aes_cbc_key[] = {
741 0xE4, 0x23, 0x33, 0x8A, 0x35, 0x64, 0x61, 0xE2,
742 0x49, 0x03, 0xDD, 0xC6, 0xB8, 0xCA, 0x55, 0x7A };
744 static uint8_t aes_cbc_iv[] = {
745 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
746 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
749 /* ***** AES-CBC / HMAC-SHA1 Hash Tests ***** */
751 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_ciphertext[] = {
752 0x8B, 0x4D, 0xDA, 0x1B, 0xCF, 0x04, 0xA0, 0x31,
753 0xB4, 0xBF, 0xBD, 0x68, 0x43, 0x20, 0x7E, 0x76,
754 0xB1, 0x96, 0x8B, 0xA2, 0x7C, 0xA2, 0x83, 0x9E,
755 0x39, 0x5A, 0x2F, 0x7E, 0x92, 0xB4, 0x48, 0x1A,
756 0x3F, 0x6B, 0x5D, 0xDF, 0x52, 0x85, 0x5F, 0x8E,
757 0x42, 0x3C, 0xFB, 0xE9, 0x1A, 0x24, 0xD6, 0x08,
758 0xDD, 0xFD, 0x16, 0xFB, 0xE9, 0x55, 0xEF, 0xF0,
759 0xA0, 0x8D, 0x13, 0xAB, 0x81, 0xC6, 0x90, 0x01,
760 0xB5, 0x18, 0x84, 0xB3, 0xF6, 0xE6, 0x11, 0x57,
761 0xD6, 0x71, 0xC6, 0x3C, 0x3F, 0x2F, 0x33, 0xEE,
762 0x24, 0x42, 0x6E, 0xAC, 0x0B, 0xCA, 0xEC, 0xF9,
763 0x84, 0xF8, 0x22, 0xAA, 0x60, 0xF0, 0x32, 0xA9,
764 0x75, 0x75, 0x3B, 0xCB, 0x70, 0x21, 0x0A, 0x8D,
765 0x0F, 0xE0, 0xC4, 0x78, 0x2B, 0xF8, 0x97, 0xE3,
766 0xE4, 0x26, 0x4B, 0x29, 0xDA, 0x88, 0xCD, 0x46,
767 0xEC, 0xAA, 0xF9, 0x7F, 0xF1, 0x15, 0xEA, 0xC3,
768 0x87, 0xE6, 0x31, 0xF2, 0xCF, 0xDE, 0x4D, 0x80,
769 0x70, 0x91, 0x7E, 0x0C, 0xF7, 0x26, 0x3A, 0x92,
770 0x4F, 0x18, 0x83, 0xC0, 0x8F, 0x59, 0x01, 0xA5,
771 0x88, 0xD1, 0xDB, 0x26, 0x71, 0x27, 0x16, 0xF5,
772 0xEE, 0x10, 0x82, 0xAC, 0x68, 0x26, 0x9B, 0xE2,
773 0x6D, 0xD8, 0x9A, 0x80, 0xDF, 0x04, 0x31, 0xD5,
774 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
775 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
776 0x73, 0x02, 0x42, 0xC9, 0x23, 0x18, 0x8E, 0xB4,
777 0x6F, 0xB4, 0xA3, 0x54, 0x6E, 0x88, 0x3B, 0x62,
778 0x7C, 0x02, 0x8D, 0x4C, 0x9F, 0xC8, 0x45, 0xF4,
779 0xC9, 0xDE, 0x4F, 0xEB, 0x22, 0x83, 0x1B, 0xE4,
780 0x49, 0x37, 0xE4, 0xAD, 0xE7, 0xCD, 0x21, 0x54,
781 0xBC, 0x1C, 0xC2, 0x04, 0x97, 0xB4, 0x10, 0x61,
782 0xF0, 0xE4, 0xEF, 0x27, 0x63, 0x3A, 0xDA, 0x91,
783 0x41, 0x25, 0x62, 0x1C, 0x5C, 0xB6, 0x38, 0x4A,
784 0x88, 0x71, 0x59, 0x5A, 0x8D, 0xA0, 0x09, 0xAF,
785 0x72, 0x94, 0xD7, 0x79, 0x5C, 0x60, 0x7C, 0x8F,
786 0x4C, 0xF5, 0xD9, 0xA1, 0x39, 0x6D, 0x81, 0x28,
787 0xEF, 0x13, 0x28, 0xDF, 0xF5, 0x3E, 0xF7, 0x8E,
788 0x09, 0x9C, 0x78, 0x18, 0x79, 0xB8, 0x68, 0xD7,
789 0xA8, 0x29, 0x62, 0xAD, 0xDE, 0xE1, 0x61, 0x76,
790 0x1B, 0x05, 0x16, 0xCD, 0xBF, 0x02, 0x8E, 0xA6,
791 0x43, 0x6E, 0x92, 0x55, 0x4F, 0x60, 0x9C, 0x03,
792 0xB8, 0x4F, 0xA3, 0x02, 0xAC, 0xA8, 0xA7, 0x0C,
793 0x1E, 0xB5, 0x6B, 0xF8, 0xC8, 0x4D, 0xDE, 0xD2,
794 0xB0, 0x29, 0x6E, 0x40, 0xE6, 0xD6, 0xC9, 0xE6,
795 0xB9, 0x0F, 0xB6, 0x63, 0xF5, 0xAA, 0x2B, 0x96,
796 0xA7, 0x16, 0xAC, 0x4E, 0x0A, 0x33, 0x1C, 0xA6,
797 0xE6, 0xBD, 0x8A, 0xCF, 0x40, 0xA9, 0xB2, 0xFA,
798 0x63, 0x27, 0xFD, 0x9B, 0xD9, 0xFC, 0xD5, 0x87,
799 0x8D, 0x4C, 0xB6, 0xA4, 0xCB, 0xE7, 0x74, 0x55,
800 0xF4, 0xFB, 0x41, 0x25, 0xB5, 0x4B, 0x0A, 0x1B,
801 0xB1, 0xD6, 0xB7, 0xD9, 0x47, 0x2A, 0xC3, 0x98,
802 0x6A, 0xC4, 0x03, 0x73, 0x1F, 0x93, 0x6E, 0x53,
803 0x19, 0x25, 0x64, 0x15, 0x83, 0xF9, 0x73, 0x2A,
804 0x74, 0xB4, 0x93, 0x69, 0xC4, 0x72, 0xFC, 0x26,
805 0xA2, 0x9F, 0x43, 0x45, 0xDD, 0xB9, 0xEF, 0x36,
806 0xC8, 0x3A, 0xCD, 0x99, 0x9B, 0x54, 0x1A, 0x36,
807 0xC1, 0x59, 0xF8, 0x98, 0xA8, 0xCC, 0x28, 0x0D,
808 0x73, 0x4C, 0xEE, 0x98, 0xCB, 0x7C, 0x58, 0x7E,
809 0x20, 0x75, 0x1E, 0xB7, 0xC9, 0xF8, 0xF2, 0x0E,
810 0x63, 0x9E, 0x05, 0x78, 0x1A, 0xB6, 0xA8, 0x7A,
811 0xF9, 0x98, 0x6A, 0xA6, 0x46, 0x84, 0x2E, 0xF6,
812 0x4B, 0xDC, 0x9B, 0x8F, 0x9B, 0x8F, 0xEE, 0xB4,
813 0xAA, 0x3F, 0xEE, 0xC0, 0x37, 0x27, 0x76, 0xC7,
814 0x95, 0xBB, 0x26, 0x74, 0x69, 0x12, 0x7F, 0xF1,
815 0xBB, 0xFF, 0xAE, 0xB5, 0x99, 0x6E, 0xCB, 0x0C
818 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest[] = {
819 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60,
820 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
821 0x18, 0x8c, 0x1d, 0x32
826 test_AES_CBC_HMAC_SHA1_encrypt_digest(void)
828 struct crypto_testsuite_params *ts_params = &testsuite_params;
829 struct crypto_unittest_params *ut_params = &unittest_params;
831 /* Generate test mbuf data and space for digest */
832 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
833 catch_22_quote, QUOTE_512_BYTES, 0);
835 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
836 DIGEST_BYTE_LENGTH_SHA1);
837 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
839 /* Setup Cipher Parameters */
840 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
841 ut_params->cipher_xform.next = &ut_params->auth_xform;
843 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
844 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
845 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
846 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
848 /* Setup HMAC Parameters */
849 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
851 ut_params->auth_xform.next = NULL;
853 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
854 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
855 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
856 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
857 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
859 /* Create crypto session*/
860 ut_params->sess = rte_cryptodev_sym_session_create(
861 ts_params->valid_devs[0],
862 &ut_params->cipher_xform);
863 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
865 /* Generate crypto op data structure */
866 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
867 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
868 TEST_ASSERT_NOT_NULL(ut_params->op,
869 "Failed to allocate symmetric crypto operation struct");
871 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
873 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
875 /* set crypto operation source mbuf */
876 sym_op->m_src = ut_params->ibuf;
878 /* Set crypto operation authentication parameters */
879 sym_op->auth.digest.data = ut_params->digest;
880 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
881 ut_params->ibuf, QUOTE_512_BYTES);
882 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
884 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
885 sym_op->auth.data.length = QUOTE_512_BYTES;
887 /* Set crypto operation cipher parameters */
888 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
889 CIPHER_IV_LENGTH_AES_CBC);
890 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
891 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
893 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
894 CIPHER_IV_LENGTH_AES_CBC);
896 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
897 sym_op->cipher.data.length = QUOTE_512_BYTES;
899 /* Process crypto operation */
900 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
901 ut_params->op), "failed to process sym crypto op");
903 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
904 "crypto op processing failed");
907 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
908 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
910 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
911 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
913 "ciphertext data not as expected");
915 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
917 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
918 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
919 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
920 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
921 DIGEST_BYTE_LENGTH_SHA1,
922 "Generated digest data not as expected");
929 test_AES_CBC_HMAC_SHA1_encrypt_digest_oop(void)
931 struct crypto_testsuite_params *ts_params = &testsuite_params;
932 struct crypto_unittest_params *ut_params = &unittest_params;
934 /* Generate test mbuf data and space for digest */
936 TEST_ASSERT_EQUAL(setup_oop_test_mbufs(&ut_params->ibuf,
937 &ut_params->obuf, ts_params->mbuf_pool, catch_22_quote,
938 QUOTE_512_BYTES, 0), 0,
939 "Allocation of rte_mbuf failed");
941 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->obuf,
942 DIGEST_BYTE_LENGTH_SHA1);
944 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
946 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
947 ut_params->cipher_xform.next = &ut_params->auth_xform;
949 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
950 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
951 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
952 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
954 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
955 ut_params->auth_xform.next = NULL;
957 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
958 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
959 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
960 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
961 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
963 ut_params->sess = rte_cryptodev_sym_session_create(
964 ts_params->valid_devs[0],
965 &ut_params->cipher_xform);
967 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
969 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
970 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
973 TEST_ASSERT_NOT_NULL(ut_params->op,
974 "Failed to allocate symmetric crypto operation struct");
976 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
978 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
980 /* set crypto operation source mbuf */
981 sym_op->m_src = ut_params->ibuf;
982 sym_op->m_dst = ut_params->obuf;
984 sym_op->auth.digest.data = ut_params->digest;
986 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
987 ut_params->obuf, QUOTE_512_BYTES);
989 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
990 sym_op->auth.data.length = QUOTE_512_BYTES;
992 /* Set crypto operation cipher parameters */
993 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
994 CIPHER_IV_LENGTH_AES_CBC);
996 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
997 "Failed to prepend place for iv input");
999 TEST_ASSERT_NOT_NULL(rte_pktmbuf_prepend(ut_params->obuf,
1000 CIPHER_IV_LENGTH_AES_CBC),
1001 "Failed to prepend place for iv output");
1003 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1005 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1006 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1008 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1009 CIPHER_IV_LENGTH_AES_CBC);
1011 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1012 sym_op->cipher.data.length = QUOTE_512_BYTES;
1015 /* Process crypto operation */
1016 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1017 ut_params->op), "failed to process sym crypto op");
1019 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1020 "crypto op processing failed");
1023 uint8_t *ciphertext;
1025 ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
1026 uint8_t *, CIPHER_IV_LENGTH_AES_CBC);
1028 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1029 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1031 "ciphertext data not as expected");
1033 uint8_t *digest = ciphertext + QUOTE_512_BYTES;
1035 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1036 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1037 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1038 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1039 DIGEST_BYTE_LENGTH_SHA1,
1040 "Generated digest data not as expected");
1043 return TEST_SUCCESS;
1048 test_AES_CBC_HMAC_SHA1_decrypt_digest_oop_ver(void)
1050 struct crypto_testsuite_params *ts_params = &testsuite_params;
1051 struct crypto_unittest_params *ut_params = &unittest_params;
1053 /* Generate test mbuf data and digest */
1055 TEST_ASSERT_EQUAL(setup_oop_test_mbufs(&ut_params->ibuf,
1056 &ut_params->obuf, ts_params->mbuf_pool,
1058 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1059 QUOTE_512_BYTES, 0), 0,
1060 "Allocation of rte_mbuf failed");
1062 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1063 DIGEST_BYTE_LENGTH_SHA1);
1065 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1067 rte_memcpy(ut_params->digest,
1068 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1069 DIGEST_BYTE_LENGTH_SHA1);
1071 /* Setup Cipher Parameters */
1072 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1073 ut_params->cipher_xform.next = NULL;
1075 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1076 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1077 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1078 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1080 /* Setup HMAC Parameters */
1081 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1082 ut_params->auth_xform.next = &ut_params->cipher_xform;
1084 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1085 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1086 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1087 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1088 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1090 /* Create Crypto session*/
1092 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1093 &ut_params->auth_xform);
1094 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1096 /* Generate Crypto op data structure */
1097 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1098 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1099 TEST_ASSERT_NOT_NULL(ut_params->op,
1100 "Failed to allocate symmetric crypto operation struct");
1102 /* attach symmetric crypto session to crypto operations */
1103 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1105 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1107 /* set crypto operation source mbuf */
1108 sym_op->m_src = ut_params->ibuf;
1109 sym_op->m_dst = ut_params->obuf;
1111 sym_op->auth.digest.data = ut_params->digest;
1112 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1113 ut_params->ibuf, QUOTE_512_BYTES);
1114 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1116 sym_op->auth.data.length = QUOTE_512_BYTES;
1118 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1119 CIPHER_IV_LENGTH_AES_CBC);
1121 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data,
1122 "Failed to prepend place for iv input");
1124 TEST_ASSERT_NOT_NULL(rte_pktmbuf_prepend(ut_params->obuf,
1125 CIPHER_IV_LENGTH_AES_CBC),
1126 "Failed to prepend place for iv output");
1128 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1130 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1131 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1133 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1134 CIPHER_IV_LENGTH_AES_CBC);
1136 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1137 sym_op->cipher.data.length = QUOTE_512_BYTES;
1140 /* Process crypto operation */
1141 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1142 ut_params->op), "failed to process sym crypto op");
1144 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1145 "Digest verification failed");
1147 ut_params->obuf = ut_params->op->sym->m_dst;
1150 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1151 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1152 CIPHER_IV_LENGTH_AES_CBC,
1155 "Ciphertext data not as expected");
1158 return TEST_SUCCESS;
1163 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless(void)
1165 struct crypto_testsuite_params *ts_params = &testsuite_params;
1166 struct crypto_unittest_params *ut_params = &unittest_params;
1168 /* Generate test mbuf data and space for digest */
1169 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1170 catch_22_quote, QUOTE_512_BYTES, 0);
1172 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1173 DIGEST_BYTE_LENGTH_SHA1);
1174 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1176 /* Generate Crypto op data structure */
1177 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1178 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1179 TEST_ASSERT_NOT_NULL(ut_params->op,
1180 "Failed to allocate symmetric crypto operation struct");
1182 TEST_ASSERT_NOT_NULL(rte_crypto_op_sym_xforms_alloc(ut_params->op, 2),
1183 "failed to allocate space for crypto transforms");
1185 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1187 /* set crypto operation source mbuf */
1188 sym_op->m_src = ut_params->ibuf;
1190 /* Set crypto operation data parameters */
1191 sym_op->xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1193 /* cipher parameters */
1194 sym_op->xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1195 sym_op->xform->cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1196 sym_op->xform->cipher.key.data = aes_cbc_key;
1197 sym_op->xform->cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1199 /* hash parameters */
1200 sym_op->xform->next->type = RTE_CRYPTO_SYM_XFORM_AUTH;
1202 sym_op->xform->next->auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1203 sym_op->xform->next->auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1204 sym_op->xform->next->auth.key.length = HMAC_KEY_LENGTH_SHA1;
1205 sym_op->xform->next->auth.key.data = hmac_sha1_key;
1206 sym_op->xform->next->auth.digest_length =
1207 DIGEST_BYTE_LENGTH_SHA1;
1209 sym_op->auth.digest.data = ut_params->digest;
1210 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1211 ut_params->ibuf, QUOTE_512_BYTES);
1212 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1215 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1216 sym_op->auth.data.length = QUOTE_512_BYTES;
1218 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1219 CIPHER_IV_LENGTH_AES_CBC);
1220 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1221 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1223 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1224 CIPHER_IV_LENGTH_AES_CBC);
1226 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1227 sym_op->cipher.data.length = QUOTE_512_BYTES;
1229 /* Process crypto operation */
1230 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1231 ut_params->op), "failed to process sym crypto op");
1233 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1234 "crypto op processing failed");
1236 ut_params->obuf = ut_params->op->sym->m_src;
1239 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1240 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1241 CIPHER_IV_LENGTH_AES_CBC,
1242 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1244 "Ciphertext data not as expected");
1246 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1247 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1248 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1249 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1250 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1251 TRUNCATED_DIGEST_BYTE_LENGTH_SHA1 :
1252 DIGEST_BYTE_LENGTH_SHA1,
1253 "Generated digest data not as expected");
1256 return TEST_SUCCESS;
1260 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify(void)
1262 struct crypto_testsuite_params *ts_params = &testsuite_params;
1263 struct crypto_unittest_params *ut_params = &unittest_params;
1265 /* Generate test mbuf data and digest */
1266 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1268 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1269 QUOTE_512_BYTES, 0);
1271 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1272 DIGEST_BYTE_LENGTH_SHA1);
1273 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1275 rte_memcpy(ut_params->digest,
1276 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA1_digest,
1277 DIGEST_BYTE_LENGTH_SHA1);
1279 /* Setup Cipher Parameters */
1280 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1281 ut_params->cipher_xform.next = NULL;
1283 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1284 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1285 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1286 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1288 /* Setup HMAC Parameters */
1289 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1290 ut_params->auth_xform.next = &ut_params->cipher_xform;
1292 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1293 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
1294 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA1;
1295 ut_params->auth_xform.auth.key.data = hmac_sha1_key;
1296 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA1;
1298 /* Create Crypto session*/
1300 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1301 &ut_params->auth_xform);
1302 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1304 /* Generate Crypto op data structure */
1305 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1306 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1307 TEST_ASSERT_NOT_NULL(ut_params->op,
1308 "Failed to allocate symmetric crypto operation struct");
1310 /* attach symmetric crypto session to crypto operations */
1311 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1313 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1315 /* set crypto operation source mbuf */
1316 sym_op->m_src = ut_params->ibuf;
1318 sym_op->auth.digest.data = ut_params->digest;
1319 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1320 ut_params->ibuf, QUOTE_512_BYTES);
1321 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA1;
1323 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1324 sym_op->auth.data.length = QUOTE_512_BYTES;
1326 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1327 CIPHER_IV_LENGTH_AES_CBC);
1328 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1329 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1331 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1332 CIPHER_IV_LENGTH_AES_CBC);
1334 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1335 sym_op->cipher.data.length = QUOTE_512_BYTES;
1338 /* Process crypto operation */
1339 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1340 ut_params->op), "failed to process sym crypto op");
1342 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1343 "crypto op processing failed");
1345 ut_params->obuf = ut_params->op->sym->m_src;
1349 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1350 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1351 CIPHER_IV_LENGTH_AES_CBC,
1354 "Ciphertext data not as expected");
1356 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1357 "Digest verification failed");
1360 return TEST_SUCCESS;
1363 /* **** AES counter mode tests **** */
1366 test_AES_CTR_encrypt_digest(const struct aes_ctr_test_data *tdata)
1368 struct crypto_testsuite_params *ts_params = &testsuite_params;
1369 struct crypto_unittest_params *ut_params = &unittest_params;
1370 struct rte_crypto_sym_op *sym_op;
1372 uint8_t hash_key[tdata->auth_key.len];
1373 uint8_t cipher_key[tdata->key.len];
1375 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1376 (const char *)tdata->plaintext.data,
1377 tdata->plaintext.len, 0);
1379 /* Setup Cipher Parameters */
1380 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1381 ut_params->cipher_xform.next = &ut_params->auth_xform;
1383 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CTR;
1384 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1386 rte_memcpy(cipher_key, tdata->key.data, tdata->key.len);
1387 ut_params->cipher_xform.cipher.key.data = cipher_key;
1388 ut_params->cipher_xform.cipher.key.length =
1391 /* Setup HMAC Parameters */
1392 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1393 ut_params->auth_xform.next = NULL;
1395 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1396 ut_params->auth_xform.auth.algo = tdata->auth_key.algo;
1397 ut_params->auth_xform.auth.key.length =
1398 tdata->auth_key.len;
1399 rte_memcpy(hash_key, tdata->auth_key.data, tdata->auth_key.len);
1400 ut_params->auth_xform.auth.key.data = hash_key;
1401 ut_params->auth_xform.auth.digest_length = tdata->digest.len;
1403 /* Create Crypto session*/
1404 ut_params->sess = rte_cryptodev_sym_session_create(
1405 ts_params->valid_devs[0],
1406 &ut_params->cipher_xform);
1407 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1409 /* Generate Crypto op data structure */
1410 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1411 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1412 TEST_ASSERT_NOT_NULL(ut_params->op,
1413 "Failed to allocate symmetric crypto operation struct");
1415 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1417 sym_op = ut_params->op->sym;
1419 /* set crypto operation source mbuf */
1420 sym_op->m_src = ut_params->ibuf;
1422 /* Set operation cipher parameters */
1423 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1424 sym_op->m_src, tdata->iv.len);
1425 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1426 sym_op->cipher.iv.length = tdata->iv.len;
1428 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data,
1431 sym_op->cipher.data.offset = tdata->iv.len;
1432 sym_op->cipher.data.length = tdata->plaintext.len;
1434 /* Set operation authentication parameters */
1435 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
1436 sym_op->m_src, tdata->digest.len);
1437 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1439 tdata->iv.len + tdata->ciphertext.len);
1440 sym_op->auth.digest.length = tdata->digest.len;
1442 memset(sym_op->auth.digest.data, 0, tdata->digest.len);
1444 sym_op->auth.data.offset = tdata->iv.len;
1445 sym_op->auth.data.length = tdata->plaintext.len;
1447 /* Process crypto operation */
1448 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1451 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1452 "crypto op processing failed");
1454 uint8_t *ciphertext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1455 uint8_t *, tdata->iv.len);
1457 TEST_ASSERT_BUFFERS_ARE_EQUAL(ciphertext,
1458 tdata->ciphertext.data,
1459 tdata->ciphertext.len,
1460 "ciphertext data not as expected");
1462 uint8_t *digest = ciphertext + tdata->ciphertext.len;
1464 TEST_ASSERT_BUFFERS_ARE_EQUAL(digest,
1465 tdata->digest.data, tdata->digest.len,
1466 "Generated digest data not as expected");
1468 return TEST_SUCCESS;
1472 test_AES_CTR_encrypt_digest_case_1(void)
1474 return test_AES_CTR_encrypt_digest(&aes_ctr_test_case_1);
1477 test_AES_CTR_encrypt_digest_case_2(void)
1479 return test_AES_CTR_encrypt_digest(&aes_ctr_test_case_2);
1482 test_AES_CTR_encrypt_digest_case_3(void)
1484 return test_AES_CTR_encrypt_digest(&aes_ctr_test_case_3);
1488 test_AES_CTR_digest_verify_decrypt(const struct aes_ctr_test_data *tdata)
1490 struct crypto_testsuite_params *ts_params = &testsuite_params;
1491 struct crypto_unittest_params *ut_params = &unittest_params;
1492 struct rte_crypto_sym_op *sym_op;
1494 uint8_t hash_key[tdata->auth_key.len];
1495 uint8_t cipher_key[tdata->key.len];
1497 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1498 (const char *)tdata->ciphertext.data,
1499 tdata->ciphertext.len, 0);
1501 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1504 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1506 rte_memcpy(ut_params->digest,
1510 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1511 ut_params->auth_xform.next = &ut_params->cipher_xform;
1513 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1514 ut_params->auth_xform.auth.algo = tdata->auth_key.algo;
1515 ut_params->auth_xform.auth.key.length = tdata->auth_key.len;
1516 rte_memcpy(hash_key, tdata->auth_key.data, tdata->auth_key.len);
1517 ut_params->auth_xform.auth.key.data =
1519 ut_params->auth_xform.auth.digest_length = tdata->digest.len;
1521 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1522 ut_params->cipher_xform.next = NULL;
1524 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CTR;
1525 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1527 rte_memcpy(cipher_key, tdata->key.data, tdata->key.len);
1528 ut_params->cipher_xform.cipher.key.data =
1530 ut_params->cipher_xform.cipher.key.length = tdata->key.len;
1532 ut_params->sess = rte_cryptodev_sym_session_create(
1533 ts_params->valid_devs[0],
1534 &ut_params->auth_xform);
1535 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1537 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1538 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1539 TEST_ASSERT_NOT_NULL(ut_params->op,
1540 "Failed to allocate symmetric crypto operation struct");
1542 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1544 sym_op = ut_params->op->sym;
1546 sym_op->m_src = ut_params->ibuf;
1548 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1549 sym_op->m_src, tdata->iv.len);
1550 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
1551 sym_op->cipher.iv.length = tdata->iv.len;
1553 rte_memcpy(sym_op->cipher.iv.data, tdata->iv.data,
1556 sym_op->cipher.data.offset = tdata->iv.len;
1557 sym_op->cipher.data.length = tdata->ciphertext.len;
1559 sym_op->auth.digest.data = ut_params->digest;
1560 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1562 tdata->iv.len + tdata->ciphertext.len);
1563 sym_op->auth.digest.length = tdata->digest.len;
1565 sym_op->auth.data.offset = tdata->iv.len;
1566 sym_op->auth.data.length = tdata->ciphertext.len;
1568 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
1571 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1572 "crypto op processing failed");
1574 uint8_t *plaintext = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
1575 uint8_t *, tdata->iv.len);
1577 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
1578 tdata->plaintext.data,
1579 tdata->plaintext.len,
1580 "plaintext data not as expected");
1583 return TEST_SUCCESS;
1587 test_AES_CTR_digest_verify_decrypt_case_1(void)
1589 return test_AES_CTR_digest_verify_decrypt(&aes_ctr_test_case_1);
1592 test_AES_CTR_digest_verify_decrypt_case_2(void)
1594 return test_AES_CTR_digest_verify_decrypt(&aes_ctr_test_case_2);
1597 test_AES_CTR_digest_verify_decrypt_case_3(void)
1599 return test_AES_CTR_digest_verify_decrypt(&aes_ctr_test_case_3);
1603 /* ***** AES-CBC / HMAC-SHA256 Hash Tests ***** */
1605 #define HMAC_KEY_LENGTH_SHA256 (DIGEST_BYTE_LENGTH_SHA256)
1607 static uint8_t hmac_sha256_key[] = {
1608 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1609 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1610 0x58, 0x34, 0x85, 0x61, 0x1C, 0x42, 0x10, 0x76,
1611 0x9a, 0x4f, 0x88, 0x1b, 0xb6, 0x8f, 0xd8, 0x60 };
1613 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest[] = {
1614 0xc8, 0x57, 0x57, 0x31, 0x03, 0xe0, 0x03, 0x55,
1615 0x07, 0xc8, 0x9e, 0x7f, 0x48, 0x9a, 0x61, 0x9a,
1616 0x68, 0xee, 0x03, 0x0e, 0x71, 0x75, 0xc7, 0xf4,
1617 0x2e, 0x45, 0x26, 0x32, 0x7c, 0x12, 0x15, 0x15 };
1620 test_AES_CBC_HMAC_SHA256_encrypt_digest(void)
1622 struct crypto_testsuite_params *ts_params = &testsuite_params;
1623 struct crypto_unittest_params *ut_params = &unittest_params;
1625 /* Generate test mbuf data and space for digest */
1626 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1627 catch_22_quote, QUOTE_512_BYTES, 0);
1629 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1630 DIGEST_BYTE_LENGTH_SHA256);
1631 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1633 /* Setup Cipher Parameters */
1634 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1635 ut_params->cipher_xform.next = &ut_params->auth_xform;
1637 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1638 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1639 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1640 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1642 /* Setup HMAC Parameters */
1643 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1644 ut_params->auth_xform.next = NULL;
1646 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
1647 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1648 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1649 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1650 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1652 /* Create Crypto session*/
1653 ut_params->sess = rte_cryptodev_sym_session_create(
1654 ts_params->valid_devs[0],
1655 &ut_params->cipher_xform);
1656 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1658 /* Generate Crypto op data structure */
1659 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1660 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1661 TEST_ASSERT_NOT_NULL(ut_params->op,
1662 "Failed to allocate symmetric crypto operation struct");
1664 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1666 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1668 /* set crypto operation source mbuf */
1669 sym_op->m_src = ut_params->ibuf;
1671 sym_op->auth.digest.data = ut_params->digest;
1672 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1673 ut_params->ibuf, QUOTE_512_BYTES);
1674 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1676 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1677 sym_op->auth.data.length = QUOTE_512_BYTES;
1679 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1680 CIPHER_IV_LENGTH_AES_CBC);
1681 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1682 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1684 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1685 CIPHER_IV_LENGTH_AES_CBC);
1687 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1688 sym_op->cipher.data.length = QUOTE_512_BYTES;
1690 /* Process crypto operation */
1691 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1692 ut_params->op), "failed to process sym crypto op");
1694 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1695 "crypto op processing failed");
1697 ut_params->obuf = ut_params->op->sym->m_src;
1700 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1701 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1702 CIPHER_IV_LENGTH_AES_CBC,
1703 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1705 "Ciphertext data not as expected");
1707 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1708 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1709 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1710 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1711 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1712 TRUNCATED_DIGEST_BYTE_LENGTH_SHA256 :
1713 DIGEST_BYTE_LENGTH_SHA256,
1714 "Generated digest data not as expected");
1717 return TEST_SUCCESS;
1721 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify(void)
1723 struct crypto_testsuite_params *ts_params = &testsuite_params;
1724 struct crypto_unittest_params *ut_params = &unittest_params;
1726 /* Generate test mbuf data and digest */
1727 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1729 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1730 QUOTE_512_BYTES, 0);
1732 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1733 DIGEST_BYTE_LENGTH_SHA256);
1734 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1736 rte_memcpy(ut_params->digest,
1737 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA256_digest,
1738 DIGEST_BYTE_LENGTH_SHA256);
1740 /* Setup Cipher Parameters */
1741 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1742 ut_params->cipher_xform.next = NULL;
1744 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1745 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1746 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1747 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1749 /* Setup HMAC Parameters */
1750 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1751 ut_params->auth_xform.next = &ut_params->cipher_xform;
1753 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1754 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA256_HMAC;
1755 ut_params->auth_xform.auth.key.data = hmac_sha256_key;
1756 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA256;
1757 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA256;
1759 /* Create Crypto session*/
1761 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1762 &ut_params->auth_xform);
1763 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1765 /* Generate Crypto op data structure */
1766 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1767 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1768 TEST_ASSERT_NOT_NULL(ut_params->op,
1769 "Failed to allocate symmetric crypto operation struct");
1772 /* Set crypto operation data parameters */
1773 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1775 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1777 /* set crypto operation source mbuf */
1778 sym_op->m_src = ut_params->ibuf;
1780 sym_op->auth.digest.data = ut_params->digest;
1781 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1782 ut_params->ibuf, QUOTE_512_BYTES);
1783 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA256;
1785 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1786 sym_op->auth.data.length = QUOTE_512_BYTES;
1788 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
1789 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
1790 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1791 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1793 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1794 CIPHER_IV_LENGTH_AES_CBC);
1796 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1797 sym_op->cipher.data.length = QUOTE_512_BYTES;
1799 /* Process crypto operation */
1800 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1801 ut_params->op), "failed to process sym crypto op");
1803 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1804 "crypto op processing failed");
1806 ut_params->obuf = ut_params->op->sym->m_src;
1809 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1810 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1811 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
1813 "Plaintext data not as expected");
1815 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1816 "Digest verification failed");
1818 return TEST_SUCCESS;
1821 /* ***** AES-CBC / HMAC-SHA512 Hash Tests ***** */
1823 #define HMAC_KEY_LENGTH_SHA512 (DIGEST_BYTE_LENGTH_SHA512)
1825 static uint8_t hmac_sha512_key[] = {
1826 0x42, 0x1a, 0x7d, 0x3d, 0xf5, 0x82, 0x80, 0xf1,
1827 0xF1, 0x35, 0x5C, 0x3B, 0xDD, 0x9A, 0x65, 0xBA,
1828 0x58, 0x34, 0x85, 0x65, 0x1C, 0x42, 0x50, 0x76,
1829 0x9a, 0xaf, 0x88, 0x1b, 0xb6, 0x8f, 0xf8, 0x60,
1830 0xa2, 0x5a, 0x7f, 0x3f, 0xf4, 0x72, 0x70, 0xf1,
1831 0xF5, 0x35, 0x4C, 0x3B, 0xDD, 0x90, 0x65, 0xB0,
1832 0x47, 0x3a, 0x75, 0x61, 0x5C, 0xa2, 0x10, 0x76,
1833 0x9a, 0xaf, 0x77, 0x5b, 0xb6, 0x7f, 0xf7, 0x60 };
1835 static const uint8_t catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest[] = {
1836 0x5D, 0x54, 0x66, 0xC1, 0x6E, 0xBC, 0x04, 0xB8,
1837 0x46, 0xB8, 0x08, 0x6E, 0xE0, 0xF0, 0x43, 0x48,
1838 0x37, 0x96, 0x9C, 0xC6, 0x9C, 0xC2, 0x1E, 0xE8,
1839 0xF2, 0x0C, 0x0B, 0xEF, 0x86, 0xA2, 0xE3, 0x70,
1840 0x95, 0xC8, 0xB3, 0x06, 0x47, 0xA9, 0x90, 0xE8,
1841 0xA0, 0xC6, 0x72, 0x69, 0x05, 0xC0, 0x0D, 0x0E,
1842 0x21, 0x96, 0x65, 0x93, 0x74, 0x43, 0x2A, 0x1D,
1843 0x2E, 0xBF, 0xC2, 0xC2, 0xEE, 0xCC, 0x2F, 0x0A };
1846 test_AES_CBC_HMAC_SHA512_encrypt_digest(void)
1848 struct crypto_testsuite_params *ts_params = &testsuite_params;
1849 struct crypto_unittest_params *ut_params = &unittest_params;
1851 /* Generate test mbuf data and space for digest */
1852 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
1853 catch_22_quote, QUOTE_512_BYTES, 0);
1855 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
1856 DIGEST_BYTE_LENGTH_SHA512);
1857 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
1859 /* Setup Cipher Parameters */
1860 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1861 ut_params->cipher_xform.next = &ut_params->auth_xform;
1863 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1864 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
1865 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1866 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1868 /* Setup HMAC 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 = RTE_CRYPTO_AUTH_OP_GENERATE;
1873 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1874 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1875 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1876 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
1878 /* Create Crypto session*/
1880 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1881 &ut_params->cipher_xform);
1883 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1885 /* Generate Crypto op data structure */
1886 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
1887 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
1888 TEST_ASSERT_NOT_NULL(ut_params->op,
1889 "Failed to allocate symmetric crypto operation struct");
1891 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
1893 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
1895 /* set crypto operation source mbuf */
1896 sym_op->m_src = ut_params->ibuf;
1898 sym_op->auth.digest.data = ut_params->digest;
1899 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
1900 ut_params->ibuf, QUOTE_512_BYTES);
1901 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
1903 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1904 sym_op->auth.data.length = QUOTE_512_BYTES;
1906 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf,
1907 CIPHER_IV_LENGTH_AES_CBC);
1908 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
1909 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
1911 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
1912 CIPHER_IV_LENGTH_AES_CBC);
1914 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
1915 sym_op->cipher.data.length = QUOTE_512_BYTES;
1917 /* Process crypto operation */
1918 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
1919 ut_params->op), "failed to process sym crypto op");
1921 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
1922 "crypto op processing failed");
1924 ut_params->obuf = ut_params->op->sym->m_src;
1927 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1928 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1929 CIPHER_IV_LENGTH_AES_CBC,
1930 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
1932 "Ciphertext data not as expected");
1934 TEST_ASSERT_BUFFERS_ARE_EQUAL(
1935 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
1936 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES,
1937 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
1938 gbl_cryptodev_type == RTE_CRYPTODEV_AESNI_MB_PMD ?
1939 TRUNCATED_DIGEST_BYTE_LENGTH_SHA512 :
1940 DIGEST_BYTE_LENGTH_SHA512,
1941 "Generated digest data not as expected");
1943 return TEST_SUCCESS;
1948 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1949 struct crypto_unittest_params *ut_params);
1952 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
1953 struct crypto_unittest_params *ut_params,
1954 struct crypto_testsuite_params *ts_params);
1957 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify(void)
1959 struct crypto_unittest_params *ut_params = &unittest_params;
1960 struct crypto_testsuite_params *ts_params = &testsuite_params;
1962 TEST_ASSERT(test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1963 ut_params) == TEST_SUCCESS,
1964 "Failed to create session params");
1966 /* Create Crypto session*/
1968 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
1969 &ut_params->auth_xform);
1970 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
1972 return test_AES_CBC_HMAC_SHA512_decrypt_perform(ut_params->sess,
1973 ut_params, ts_params);
1977 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(
1978 struct crypto_unittest_params *ut_params)
1981 /* Setup Cipher Parameters */
1982 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
1983 ut_params->cipher_xform.next = NULL;
1985 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
1986 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
1987 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
1988 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
1990 /* Setup HMAC Parameters */
1991 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
1992 ut_params->auth_xform.next = &ut_params->cipher_xform;
1994 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
1995 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA512_HMAC;
1996 ut_params->auth_xform.auth.key.data = hmac_sha512_key;
1997 ut_params->auth_xform.auth.key.length = HMAC_KEY_LENGTH_SHA512;
1998 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_SHA512;
2000 return TEST_SUCCESS;
2005 test_AES_CBC_HMAC_SHA512_decrypt_perform(struct rte_cryptodev_sym_session *sess,
2006 struct crypto_unittest_params *ut_params,
2007 struct crypto_testsuite_params *ts_params)
2009 /* Generate test mbuf data and digest */
2010 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2012 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2013 QUOTE_512_BYTES, 0);
2015 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2016 DIGEST_BYTE_LENGTH_SHA512);
2017 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
2019 rte_memcpy(ut_params->digest,
2020 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
2021 DIGEST_BYTE_LENGTH_SHA512);
2023 /* Generate Crypto op data structure */
2024 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2025 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2026 TEST_ASSERT_NOT_NULL(ut_params->op,
2027 "Failed to allocate symmetric crypto operation struct");
2029 rte_crypto_op_attach_sym_session(ut_params->op, sess);
2031 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2033 /* set crypto operation source mbuf */
2034 sym_op->m_src = ut_params->ibuf;
2036 sym_op->auth.digest.data = ut_params->digest;
2037 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2038 ut_params->ibuf, QUOTE_512_BYTES);
2039 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
2041 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2042 sym_op->auth.data.length = QUOTE_512_BYTES;
2044 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2045 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2046 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
2047 ut_params->ibuf, 0);
2048 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2050 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2051 CIPHER_IV_LENGTH_AES_CBC);
2053 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2054 sym_op->cipher.data.length = QUOTE_512_BYTES;
2056 /* Process crypto operation */
2057 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2058 ut_params->op), "failed to process sym crypto op");
2060 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2061 "crypto op processing failed");
2063 ut_params->obuf = ut_params->op->sym->m_src;
2066 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2067 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
2068 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
2070 "Plaintext data not as expected");
2073 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2074 "Digest verification failed");
2076 return TEST_SUCCESS;
2079 /* ***** AES-CBC / HMAC-AES_XCBC Chain Tests ***** */
2081 static uint8_t aes_cbc_hmac_aes_xcbc_key[] = {
2082 0x87, 0x61, 0x54, 0x53, 0xC4, 0x6D, 0xDD, 0x51,
2083 0xE1, 0x9F, 0x86, 0x64, 0x39, 0x0A, 0xE6, 0x59
2086 static const uint8_t catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest[] = {
2087 0xE0, 0xAC, 0x9A, 0xC4, 0x22, 0x64, 0x35, 0x89,
2088 0x77, 0x1D, 0x8B, 0x75
2092 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest(void)
2094 struct crypto_testsuite_params *ts_params = &testsuite_params;
2095 struct crypto_unittest_params *ut_params = &unittest_params;
2097 /* Generate test mbuf data and space for digest */
2098 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2099 catch_22_quote, QUOTE_512_BYTES, 0);
2101 /* Setup Cipher Parameters */
2102 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2103 ut_params->cipher_xform.next = &ut_params->auth_xform;
2105 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2106 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
2107 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2108 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2110 /* Setup HMAC Parameters */
2111 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2112 ut_params->auth_xform.next = NULL;
2114 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
2115 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2116 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
2117 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
2118 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
2120 /* Create Crypto session*/
2121 ut_params->sess = rte_cryptodev_sym_session_create(
2122 ts_params->valid_devs[0],
2123 &ut_params->cipher_xform);
2124 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2126 /* Generate Crypto op data structure */
2127 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2128 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2129 TEST_ASSERT_NOT_NULL(ut_params->op,
2130 "Failed to allocate symmetric crypto operation struct");
2132 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2134 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2136 /* set crypto operation source mbuf */
2137 sym_op->m_src = ut_params->ibuf;
2139 /* Set operation cipher parameters */
2140 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2141 sym_op->m_src, CIPHER_IV_LENGTH_AES_CBC);
2142 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(sym_op->m_src);
2143 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2145 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2146 CIPHER_IV_LENGTH_AES_CBC);
2148 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2149 sym_op->cipher.data.length = QUOTE_512_BYTES;
2151 /* Set operation authentication parameters */
2152 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2153 sym_op->m_src, DIGEST_BYTE_LENGTH_AES_XCBC);
2154 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2156 CIPHER_IV_LENGTH_AES_CBC + QUOTE_512_BYTES);
2157 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
2159 memset(sym_op->auth.digest.data, 0, DIGEST_BYTE_LENGTH_AES_XCBC);
2161 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2162 sym_op->auth.data.length = QUOTE_512_BYTES;
2165 /* Process crypto operation */
2166 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2168 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to process sym crypto op");
2170 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2171 "crypto op processing failed");
2174 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2175 rte_pktmbuf_mtod_offset(ut_params->op->sym->m_src,
2176 uint8_t *, CIPHER_IV_LENGTH_AES_CBC),
2177 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2179 "Ciphertext data not as expected");
2181 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2182 rte_pktmbuf_mtod_offset(
2183 ut_params->op->sym->m_src, uint8_t *,
2184 CIPHER_IV_LENGTH_AES_CBC +
2186 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
2187 DIGEST_BYTE_LENGTH_AES_XCBC,
2188 "Generated digest data not as expected");
2190 return TEST_SUCCESS;
2194 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify(void)
2196 struct crypto_testsuite_params *ts_params = &testsuite_params;
2197 struct crypto_unittest_params *ut_params = &unittest_params;
2199 /* Generate test mbuf data and space for digest */
2200 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
2201 (const char *)catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
2202 QUOTE_512_BYTES, 0);
2204 /* Setup Cipher Parameters */
2205 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2206 ut_params->cipher_xform.next = NULL;
2208 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
2209 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT;
2210 ut_params->cipher_xform.cipher.key.data = aes_cbc_key;
2211 ut_params->cipher_xform.cipher.key.length = CIPHER_KEY_LENGTH_AES_CBC;
2213 /* Setup HMAC Parameters */
2214 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2215 ut_params->auth_xform.next = &ut_params->cipher_xform;
2217 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_VERIFY;
2218 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC;
2219 ut_params->auth_xform.auth.key.length = AES_XCBC_MAC_KEY_SZ;
2220 ut_params->auth_xform.auth.key.data = aes_cbc_hmac_aes_xcbc_key;
2221 ut_params->auth_xform.auth.digest_length = DIGEST_BYTE_LENGTH_AES_XCBC;
2223 /* Create Crypto session*/
2225 rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
2226 &ut_params->auth_xform);
2227 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2229 /* Generate Crypto op data structure */
2230 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2231 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2232 TEST_ASSERT_NOT_NULL(ut_params->op,
2233 "Failed to allocate symmetric crypto operation struct");
2235 /* Set crypto operation data parameters */
2236 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2238 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2240 /* set crypto operation source mbuf */
2241 sym_op->m_src = ut_params->ibuf;
2244 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2245 ut_params->ibuf, DIGEST_BYTE_LENGTH_AES_XCBC);
2246 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2247 "no room to append digest");
2249 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2250 ut_params->ibuf, QUOTE_512_BYTES);
2251 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_AES_XCBC;
2253 rte_memcpy(sym_op->auth.digest.data,
2254 catch_22_quote_2_512_bytes_HMAC_AES_XCBC_digest,
2255 DIGEST_BYTE_LENGTH_AES_XCBC);
2257 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2258 sym_op->auth.data.length = QUOTE_512_BYTES;
2260 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2261 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
2262 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2263 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
2265 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
2266 CIPHER_IV_LENGTH_AES_CBC);
2268 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
2269 sym_op->cipher.data.length = QUOTE_512_BYTES;
2271 /* Process crypto operation */
2272 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
2273 ut_params->op), "failed to process sym crypto op");
2275 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2276 "crypto op processing failed");
2278 ut_params->obuf = ut_params->op->sym->m_src;
2281 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2282 rte_pktmbuf_mtod(ut_params->obuf, uint8_t *) +
2283 CIPHER_IV_LENGTH_AES_CBC, catch_22_quote,
2285 "Ciphertext data not as expected");
2287 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
2288 "Digest verification failed");
2290 return TEST_SUCCESS;
2293 /* ***** Snow3G Tests ***** */
2295 create_snow3g_hash_session(uint8_t dev_id,
2296 const uint8_t *key, const uint8_t key_len,
2297 const uint8_t aad_len, const uint8_t auth_len,
2298 enum rte_crypto_auth_operation op)
2300 uint8_t hash_key[key_len];
2302 struct crypto_unittest_params *ut_params = &unittest_params;
2304 memcpy(hash_key, key, key_len);
2305 #ifdef RTE_APP_TEST_DEBUG
2306 rte_hexdump(stdout, "key:", key, key_len);
2308 /* Setup Authentication Parameters */
2309 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2310 ut_params->auth_xform.next = NULL;
2312 ut_params->auth_xform.auth.op = op;
2313 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2314 ut_params->auth_xform.auth.key.length = key_len;
2315 ut_params->auth_xform.auth.key.data = hash_key;
2316 ut_params->auth_xform.auth.digest_length = auth_len;
2317 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2318 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2319 &ut_params->auth_xform);
2320 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2324 create_snow3g_cipher_session(uint8_t dev_id,
2325 enum rte_crypto_cipher_operation op,
2326 const uint8_t *key, const uint8_t key_len)
2328 uint8_t cipher_key[key_len];
2330 struct crypto_unittest_params *ut_params = &unittest_params;
2332 memcpy(cipher_key, key, key_len);
2334 /* Setup Cipher Parameters */
2335 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2336 ut_params->cipher_xform.next = NULL;
2338 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2339 ut_params->cipher_xform.cipher.op = op;
2340 ut_params->cipher_xform.cipher.key.data = cipher_key;
2341 ut_params->cipher_xform.cipher.key.length = key_len;
2343 #ifdef RTE_APP_TEST_DEBUG
2344 rte_hexdump(stdout, "key:", key, key_len);
2346 /* Create Crypto session */
2347 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2350 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2355 create_snow3g_cipher_operation(const uint8_t *iv, const unsigned iv_len,
2356 const unsigned cipher_len,
2357 const unsigned cipher_offset)
2359 struct crypto_testsuite_params *ts_params = &testsuite_params;
2360 struct crypto_unittest_params *ut_params = &unittest_params;
2361 unsigned iv_pad_len = 0;
2363 /* Generate Crypto op data structure */
2364 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2365 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2366 TEST_ASSERT_NOT_NULL(ut_params->op,
2367 "Failed to allocate pktmbuf offload");
2369 /* Set crypto operation data parameters */
2370 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2372 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2374 /* set crypto operation source mbuf */
2375 sym_op->m_src = ut_params->ibuf;
2378 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2379 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
2382 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2384 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2385 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2386 sym_op->cipher.iv.length = iv_pad_len;
2388 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2389 sym_op->cipher.data.length = cipher_len;
2390 sym_op->cipher.data.offset = cipher_offset;
2395 create_snow3g_cipher_operation_oop(const uint8_t *iv, const unsigned iv_len,
2396 const unsigned cipher_len,
2397 const unsigned cipher_offset)
2399 struct crypto_testsuite_params *ts_params = &testsuite_params;
2400 struct crypto_unittest_params *ut_params = &unittest_params;
2401 unsigned iv_pad_len = 0;
2403 /* Generate Crypto op data structure */
2404 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2405 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2406 TEST_ASSERT_NOT_NULL(ut_params->op,
2407 "Failed to allocate pktmbuf offload");
2409 /* Set crypto operation data parameters */
2410 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2412 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2414 /* set crypto operation source mbuf */
2415 sym_op->m_src = ut_params->ibuf;
2416 sym_op->m_dst = ut_params->obuf;
2419 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2420 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(ut_params->ibuf
2423 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2425 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2426 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2427 sym_op->cipher.iv.length = iv_pad_len;
2429 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2430 sym_op->cipher.data.length = cipher_len;
2431 sym_op->cipher.data.offset = cipher_offset;
2436 create_snow3g_cipher_auth_session(uint8_t dev_id,
2437 enum rte_crypto_cipher_operation cipher_op,
2438 enum rte_crypto_auth_operation auth_op,
2439 const uint8_t *key, const uint8_t key_len,
2440 const uint8_t aad_len, const uint8_t auth_len)
2442 uint8_t cipher_auth_key[key_len];
2444 struct crypto_unittest_params *ut_params = &unittest_params;
2446 memcpy(cipher_auth_key, key, key_len);
2448 /* Setup Authentication Parameters */
2449 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2450 ut_params->auth_xform.next = NULL;
2452 ut_params->auth_xform.auth.op = auth_op;
2453 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2454 ut_params->auth_xform.auth.key.length = key_len;
2455 /* Hash key = cipher key */
2456 ut_params->auth_xform.auth.key.data = cipher_auth_key;
2457 ut_params->auth_xform.auth.digest_length = auth_len;
2458 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2460 /* Setup Cipher Parameters */
2461 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2462 ut_params->cipher_xform.next = &ut_params->auth_xform;
2464 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2465 ut_params->cipher_xform.cipher.op = cipher_op;
2466 ut_params->cipher_xform.cipher.key.data = cipher_auth_key;
2467 ut_params->cipher_xform.cipher.key.length = key_len;
2469 #ifdef RTE_APP_TEST_DEBUG
2470 rte_hexdump(stdout, "key:", key, key_len);
2472 /* Create Crypto session*/
2473 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2474 &ut_params->cipher_xform);
2476 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2481 create_snow3g_auth_cipher_session(uint8_t dev_id,
2482 enum rte_crypto_cipher_operation cipher_op,
2483 enum rte_crypto_auth_operation auth_op,
2484 const uint8_t *key, const uint8_t key_len,
2485 const uint8_t aad_len, const uint8_t auth_len)
2487 uint8_t auth_cipher_key[key_len];
2489 struct crypto_unittest_params *ut_params = &unittest_params;
2491 memcpy(auth_cipher_key, key, key_len);
2493 /* Setup Authentication Parameters */
2494 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
2495 ut_params->auth_xform.auth.op = auth_op;
2496 ut_params->auth_xform.next = &ut_params->cipher_xform;
2497 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SNOW3G_UIA2;
2498 ut_params->auth_xform.auth.key.length = key_len;
2499 ut_params->auth_xform.auth.key.data = auth_cipher_key;
2500 ut_params->auth_xform.auth.digest_length = auth_len;
2501 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
2503 /* Setup Cipher Parameters */
2504 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
2505 ut_params->cipher_xform.next = NULL;
2506 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_SNOW3G_UEA2;
2507 ut_params->cipher_xform.cipher.op = cipher_op;
2508 ut_params->cipher_xform.cipher.key.data = auth_cipher_key;
2509 ut_params->cipher_xform.cipher.key.length = key_len;
2511 #ifdef RTE_APP_TEST_DEBUG
2512 rte_hexdump(stdout, "key:", key, key_len);
2514 /* Create Crypto session*/
2515 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
2516 &ut_params->auth_xform);
2518 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
2524 create_snow3g_hash_operation(const uint8_t *auth_tag,
2525 const unsigned auth_tag_len,
2526 const uint8_t *aad, const unsigned aad_len,
2527 unsigned data_pad_len,
2528 enum rte_crypto_auth_operation op,
2529 const unsigned auth_len, const unsigned auth_offset)
2531 struct crypto_testsuite_params *ts_params = &testsuite_params;
2533 struct crypto_unittest_params *ut_params = &unittest_params;
2535 unsigned aad_buffer_len;
2537 /* Generate Crypto op data structure */
2538 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2539 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2540 TEST_ASSERT_NOT_NULL(ut_params->op,
2541 "Failed to allocate pktmbuf offload");
2543 /* Set crypto operation data parameters */
2544 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2546 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2548 /* set crypto operation source mbuf */
2549 sym_op->m_src = ut_params->ibuf;
2553 * Always allocate the aad up to the block size.
2554 * The cryptodev API calls out -
2555 * - the array must be big enough to hold the AAD, plus any
2556 * space to round this up to the nearest multiple of the
2557 * block size (16 bytes).
2559 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2560 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2561 ut_params->ibuf, aad_buffer_len);
2562 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2563 "no room to prepend aad");
2564 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2566 sym_op->auth.aad.length = aad_len;
2568 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2569 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2571 #ifdef RTE_APP_TEST_DEBUG
2572 rte_hexdump(stdout, "aad:",
2573 sym_op->auth.aad.data, aad_len);
2577 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2578 ut_params->ibuf, auth_tag_len);
2580 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2581 "no room to append auth tag");
2582 ut_params->digest = sym_op->auth.digest.data;
2583 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2584 ut_params->ibuf, data_pad_len + aad_len);
2585 sym_op->auth.digest.length = auth_tag_len;
2586 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2587 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2589 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2591 #ifdef RTE_APP_TEST_DEBUG
2592 rte_hexdump(stdout, "digest:",
2593 sym_op->auth.digest.data,
2594 sym_op->auth.digest.length);
2597 sym_op->auth.data.length = auth_len;
2598 sym_op->auth.data.offset = auth_offset;
2604 create_snow3g_cipher_hash_operation(const uint8_t *auth_tag,
2605 const unsigned auth_tag_len,
2606 const uint8_t *aad, const uint8_t aad_len,
2607 unsigned data_pad_len,
2608 enum rte_crypto_auth_operation op,
2609 const uint8_t *iv, const uint8_t iv_len,
2610 const unsigned cipher_len, const unsigned cipher_offset,
2611 const unsigned auth_len, const unsigned auth_offset)
2613 struct crypto_testsuite_params *ts_params = &testsuite_params;
2614 struct crypto_unittest_params *ut_params = &unittest_params;
2616 unsigned iv_pad_len = 0;
2617 unsigned aad_buffer_len;
2619 /* Generate Crypto op data structure */
2620 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2621 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2622 TEST_ASSERT_NOT_NULL(ut_params->op,
2623 "Failed to allocate pktmbuf offload");
2624 /* Set crypto operation data parameters */
2625 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2627 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2629 /* set crypto operation source mbuf */
2630 sym_op->m_src = ut_params->ibuf;
2634 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2636 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2637 ut_params->ibuf, iv_pad_len);
2638 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2640 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2641 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2642 sym_op->cipher.iv.length = iv_pad_len;
2644 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2646 sym_op->cipher.data.length = cipher_len;
2647 sym_op->cipher.data.offset = cipher_offset;
2651 * Always allocate the aad up to the block size.
2652 * The cryptodev API calls out -
2653 * - the array must be big enough to hold the AAD, plus any
2654 * space to round this up to the nearest multiple of the
2655 * block size (16 bytes).
2657 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2659 sym_op->auth.aad.data =
2660 (uint8_t *)rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *);
2661 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2662 "no room to prepend aad");
2663 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2665 sym_op->auth.aad.length = aad_len;
2667 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2668 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2670 #ifdef RTE_APP_TEST_DEBUG
2671 rte_hexdump(stdout, "aad:",
2672 sym_op->auth.aad.data, aad_len);
2676 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2677 ut_params->ibuf, auth_tag_len);
2679 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2680 "no room to append auth tag");
2681 ut_params->digest = sym_op->auth.digest.data;
2682 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2683 ut_params->ibuf, data_pad_len + aad_len);
2684 sym_op->auth.digest.length = auth_tag_len;
2685 if (op == RTE_CRYPTO_AUTH_OP_GENERATE)
2686 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2688 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
2690 #ifdef RTE_APP_TEST_DEBUG
2691 rte_hexdump(stdout, "digest:",
2692 sym_op->auth.digest.data,
2693 sym_op->auth.digest.length);
2696 sym_op->auth.data.length = auth_len;
2697 sym_op->auth.data.offset = auth_offset;
2703 create_snow3g_auth_cipher_operation(const unsigned auth_tag_len,
2704 const uint8_t *iv, const uint8_t iv_len,
2705 const uint8_t *aad, const uint8_t aad_len,
2706 unsigned data_pad_len,
2707 const unsigned cipher_len, const unsigned cipher_offset,
2708 const unsigned auth_len, const unsigned auth_offset)
2710 struct crypto_testsuite_params *ts_params = &testsuite_params;
2711 struct crypto_unittest_params *ut_params = &unittest_params;
2713 unsigned iv_pad_len = 0;
2714 unsigned aad_buffer_len = 0;
2716 /* Generate Crypto op data structure */
2717 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
2718 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
2719 TEST_ASSERT_NOT_NULL(ut_params->op,
2720 "Failed to allocate pktmbuf offload");
2722 /* Set crypto operation data parameters */
2723 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
2725 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
2727 /* set crypto operation source mbuf */
2728 sym_op->m_src = ut_params->ibuf;
2731 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
2732 ut_params->ibuf, auth_tag_len);
2734 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
2735 "no room to append auth tag");
2737 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
2738 ut_params->ibuf, data_pad_len);
2739 sym_op->auth.digest.length = auth_tag_len;
2741 memset(sym_op->auth.digest.data, 0, auth_tag_len);
2743 #ifdef RTE_APP_TEST_DEBUG
2744 rte_hexdump(stdout, "digest:",
2745 sym_op->auth.digest.data,
2746 sym_op->auth.digest.length);
2749 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
2751 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
2752 ut_params->ibuf, iv_pad_len);
2753 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
2755 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
2756 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
2757 sym_op->cipher.iv.length = iv_pad_len;
2759 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
2763 * Always allocate the aad up to the block size.
2764 * The cryptodev API calls out -
2765 * - the array must be big enough to hold the AAD, plus any
2766 * space to round this up to the nearest multiple of the
2767 * block size (16 bytes).
2769 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
2771 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
2772 ut_params->ibuf, aad_buffer_len);
2773 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
2774 "no room to prepend aad");
2775 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
2777 sym_op->auth.aad.length = aad_len;
2779 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
2780 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
2782 #ifdef RTE_APP_TEST_DEBUG
2783 rte_hexdump(stdout, "aad:",
2784 sym_op->auth.aad.data, aad_len);
2787 sym_op->cipher.data.length = cipher_len;
2788 sym_op->cipher.data.offset = auth_offset + cipher_offset;
2790 sym_op->auth.data.length = auth_len;
2791 sym_op->auth.data.offset = auth_offset + cipher_offset;
2797 test_snow3g_authentication(const struct snow3g_hash_test_data *tdata)
2799 struct crypto_testsuite_params *ts_params = &testsuite_params;
2800 struct crypto_unittest_params *ut_params = &unittest_params;
2803 unsigned plaintext_pad_len;
2806 /* Create SNOW3G session */
2807 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2808 tdata->key.data, tdata->key.len,
2809 tdata->aad.len, tdata->digest.len,
2810 RTE_CRYPTO_AUTH_OP_GENERATE);
2814 /* alloc mbuf and set payload */
2815 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2817 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2818 rte_pktmbuf_tailroom(ut_params->ibuf));
2820 /* Append data which is padded to a multiple of */
2821 /* the algorithms block size */
2822 plaintext_pad_len = tdata->plaintext.len >> 3;
2823 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2825 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2827 /* Create SNOW3G opertaion */
2828 retval = create_snow3g_hash_operation(NULL, tdata->digest.len,
2829 tdata->aad.data, tdata->aad.len,
2830 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
2831 tdata->validAuthLenInBits.len,
2832 tdata->validAuthOffsetLenInBits.len);
2836 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2838 ut_params->obuf = ut_params->op->sym->m_src;
2839 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2840 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2841 + plaintext_pad_len + tdata->aad.len;
2844 TEST_ASSERT_BUFFERS_ARE_EQUAL(
2847 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
2848 "Snow3G Generated auth tag not as expected");
2854 test_snow3g_authentication_verify(const struct snow3g_hash_test_data *tdata)
2856 struct crypto_testsuite_params *ts_params = &testsuite_params;
2857 struct crypto_unittest_params *ut_params = &unittest_params;
2860 unsigned plaintext_pad_len;
2863 /* Create SNOW3G session */
2864 retval = create_snow3g_hash_session(ts_params->valid_devs[0],
2865 tdata->key.data, tdata->key.len,
2866 tdata->aad.len, tdata->digest.len,
2867 RTE_CRYPTO_AUTH_OP_VERIFY);
2870 /* alloc mbuf and set payload */
2871 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2873 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2874 rte_pktmbuf_tailroom(ut_params->ibuf));
2876 /* Append data which is padded to a multiple */
2877 /* of the algorithms block size */
2878 plaintext_pad_len = tdata->plaintext.len >> 3;
2879 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
2881 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
2883 /* Create SNOW3G operation */
2884 retval = create_snow3g_hash_operation(tdata->digest.data,
2886 tdata->aad.data, tdata->aad.len,
2888 RTE_CRYPTO_AUTH_OP_VERIFY,
2889 tdata->validAuthLenInBits.len,
2890 tdata->validAuthOffsetLenInBits.len);
2894 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2896 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2897 ut_params->obuf = ut_params->op->sym->m_src;
2898 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
2899 + plaintext_pad_len + tdata->aad.len;
2902 if (ut_params->op->status == RTE_CRYPTO_OP_STATUS_SUCCESS)
2912 test_snow3g_hash_generate_test_case_1(void)
2914 return test_snow3g_authentication(&snow3g_hash_test_case_1);
2918 test_snow3g_hash_generate_test_case_2(void)
2920 return test_snow3g_authentication(&snow3g_hash_test_case_2);
2924 test_snow3g_hash_generate_test_case_3(void)
2926 return test_snow3g_authentication(&snow3g_hash_test_case_3);
2930 test_snow3g_hash_verify_test_case_1(void)
2932 return test_snow3g_authentication_verify(&snow3g_hash_test_case_1);
2937 test_snow3g_hash_verify_test_case_2(void)
2939 return test_snow3g_authentication_verify(&snow3g_hash_test_case_2);
2943 test_snow3g_hash_verify_test_case_3(void)
2945 return test_snow3g_authentication_verify(&snow3g_hash_test_case_3);
2949 test_snow3g_encryption(const struct snow3g_test_data *tdata)
2951 struct crypto_testsuite_params *ts_params = &testsuite_params;
2952 struct crypto_unittest_params *ut_params = &unittest_params;
2955 uint8_t *plaintext, *ciphertext;
2956 uint8_t plaintext_pad_len;
2957 uint8_t lastByteValidBits = 8;
2958 uint8_t lastByteMask = 0xFF;
2960 /* Create SNOW3G session */
2961 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
2962 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
2963 tdata->key.data, tdata->key.len);
2967 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
2969 /* Clear mbuf payload */
2970 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
2971 rte_pktmbuf_tailroom(ut_params->ibuf));
2974 * Append data which is padded to a
2975 * multiple of the algorithms block size
2977 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
2978 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
2980 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
2982 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
2984 #ifdef RTE_APP_TEST_DEBUG
2985 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
2987 /* Create SNOW3G operation */
2988 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
2989 tdata->validCipherLenInBits.len,
2990 tdata->validCipherOffsetLenInBits.len);
2994 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
2996 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
2998 ut_params->obuf = ut_params->op->sym->m_dst;
2999 if (ut_params->obuf)
3000 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3003 ciphertext = plaintext;
3005 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3006 if (lastByteValidBits == 0)
3007 lastByteValidBits = 8;
3008 lastByteMask = lastByteMask << (8 - lastByteValidBits);
3009 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3011 #ifdef RTE_APP_TEST_DEBUG
3012 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3015 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3017 tdata->ciphertext.data,
3018 tdata->ciphertext.len >> 3,
3019 "Snow3G Ciphertext data not as expected");
3025 test_snow3g_encryption_oop(const struct snow3g_test_data *tdata)
3027 struct crypto_testsuite_params *ts_params = &testsuite_params;
3028 struct crypto_unittest_params *ut_params = &unittest_params;
3029 uint8_t *plaintext, *ciphertext;
3032 uint8_t plaintext_pad_len;
3033 uint8_t lastByteValidBits = 8;
3034 uint8_t lastByteMask = 0xFF;
3036 /* Create SNOW3G session */
3037 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
3038 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3039 tdata->key.data, tdata->key.len);
3043 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3044 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3046 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3047 "Failed to allocate input buffer in mempool");
3048 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3049 "Failed to allocate output buffer in mempool");
3051 /* Clear mbuf payload */
3052 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3053 rte_pktmbuf_tailroom(ut_params->ibuf));
3056 * Append data which is padded to a
3057 * multiple of the algorithms block size
3059 /*tdata->plaintext.len = tdata->plaintext.len >> 3;*/
3060 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 16);
3062 plaintext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3065 rte_pktmbuf_append(ut_params->obuf,
3068 memcpy(plaintext, tdata->plaintext.data, (tdata->plaintext.len >> 3));
3070 #ifdef RTE_APP_TEST_DEBUG
3071 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3073 /* Create SNOW3G operation */
3074 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
3076 tdata->validCipherLenInBits.len,
3077 tdata->validCipherOffsetLenInBits.len);
3081 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3083 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3085 ut_params->obuf = ut_params->op->sym->m_dst;
3086 if (ut_params->obuf)
3087 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3090 ciphertext = plaintext;
3092 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3093 if (lastByteValidBits == 0)
3094 lastByteValidBits = 8;
3095 lastByteMask = lastByteMask << (8 - lastByteValidBits);
3096 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3098 #ifdef RTE_APP_TEST_DEBUG
3099 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3102 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3104 tdata->ciphertext.data,
3105 tdata->ciphertext.len >> 3,
3106 "Snow3G Ciphertext data not as expected");
3111 static int test_snow3g_decryption(const struct snow3g_test_data *tdata)
3113 struct crypto_testsuite_params *ts_params = &testsuite_params;
3114 struct crypto_unittest_params *ut_params = &unittest_params;
3118 uint8_t *plaintext, *ciphertext;
3119 uint8_t ciphertext_pad_len;
3120 uint8_t lastByteValidBits = 8;
3121 uint8_t lastByteMask = 0xFF;
3123 /* Create SNOW3G session */
3124 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
3125 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3126 tdata->key.data, tdata->key.len);
3130 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3132 /* Clear mbuf payload */
3133 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3134 rte_pktmbuf_tailroom(ut_params->ibuf));
3137 * Append data which is padded to a
3138 * multiple of the algorithms block size
3140 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
3142 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3143 ciphertext_pad_len);
3144 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
3146 #ifdef RTE_APP_TEST_DEBUG
3147 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3149 /* Create SNOW3G operation */
3150 retval = create_snow3g_cipher_operation(tdata->iv.data, tdata->iv.len,
3151 tdata->validCipherLenInBits.len,
3152 tdata->validCipherOffsetLenInBits.len);
3156 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3158 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3159 ut_params->obuf = ut_params->op->sym->m_src;
3160 if (ut_params->obuf)
3161 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3164 plaintext = ciphertext;
3165 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3166 if (lastByteValidBits == 0)
3167 lastByteValidBits = 8;
3168 lastByteMask = lastByteMask << (8 - lastByteValidBits);
3169 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3171 #ifdef RTE_APP_TEST_DEBUG
3172 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3175 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
3176 tdata->plaintext.data,
3177 tdata->plaintext.len >> 3,
3178 "Snow3G Plaintext data not as expected");
3182 static int test_snow3g_decryption_oop(const struct snow3g_test_data *tdata)
3184 struct crypto_testsuite_params *ts_params = &testsuite_params;
3185 struct crypto_unittest_params *ut_params = &unittest_params;
3189 uint8_t *plaintext, *ciphertext;
3190 uint8_t ciphertext_pad_len;
3191 uint8_t lastByteValidBits = 8;
3192 uint8_t lastByteMask = 0xFF;
3194 /* Create SNOW3G session */
3195 retval = create_snow3g_cipher_session(ts_params->valid_devs[0],
3196 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3197 tdata->key.data, tdata->key.len);
3201 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3202 ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3204 TEST_ASSERT_NOT_NULL(ut_params->ibuf,
3205 "Failed to allocate input buffer");
3206 TEST_ASSERT_NOT_NULL(ut_params->obuf,
3207 "Failed to allocate output buffer");
3209 /* Clear mbuf payload */
3210 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3211 rte_pktmbuf_tailroom(ut_params->ibuf));
3213 memset(rte_pktmbuf_mtod(ut_params->obuf, uint8_t *), 0,
3214 rte_pktmbuf_tailroom(ut_params->obuf));
3217 * Append data which is padded to a
3218 * multiple of the algorithms block size
3220 ciphertext_pad_len = RTE_ALIGN_CEIL((tdata->ciphertext.len >> 3), 16);
3222 ciphertext = (uint8_t *) rte_pktmbuf_append(ut_params->ibuf,
3223 ciphertext_pad_len);
3225 rte_pktmbuf_append(ut_params->obuf,
3226 ciphertext_pad_len);
3228 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len >> 3);
3230 #ifdef RTE_APP_TEST_DEBUG
3231 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3233 /* Create SNOW3G operation */
3234 retval = create_snow3g_cipher_operation_oop(tdata->iv.data,
3236 tdata->validCipherLenInBits.len,
3237 tdata->validCipherOffsetLenInBits.len);
3241 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3243 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3244 ut_params->obuf = ut_params->op->sym->m_dst;
3245 if (ut_params->obuf)
3246 plaintext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3249 plaintext = ciphertext;
3250 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3251 if (lastByteValidBits == 0)
3252 lastByteValidBits = 8;
3253 lastByteMask = lastByteMask << (8 - lastByteValidBits);
3254 (*(plaintext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3256 #ifdef RTE_APP_TEST_DEBUG
3257 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3260 TEST_ASSERT_BUFFERS_ARE_EQUAL(plaintext,
3261 tdata->plaintext.data,
3262 tdata->plaintext.len >> 3,
3263 "Snow3G Plaintext data not as expected");
3268 test_snow3g_authenticated_encryption(const struct snow3g_test_data *tdata)
3270 struct crypto_testsuite_params *ts_params = &testsuite_params;
3271 struct crypto_unittest_params *ut_params = &unittest_params;
3275 uint8_t *plaintext, *ciphertext;
3276 uint8_t plaintext_pad_len;
3277 uint8_t lastByteValidBits = 8;
3278 uint8_t lastByteMask = 0xFF;
3280 /* Create SNOW3G session */
3281 retval = create_snow3g_cipher_auth_session(ts_params->valid_devs[0],
3282 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3283 RTE_CRYPTO_AUTH_OP_GENERATE,
3284 tdata->key.data, tdata->key.len,
3285 tdata->aad.len, tdata->digest.len);
3288 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3290 /* clear mbuf payload */
3291 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3292 rte_pktmbuf_tailroom(ut_params->ibuf));
3294 /* Append data which is padded to a multiple */
3295 /* of the algorithms block size */
3296 plaintext_pad_len = tdata->plaintext.len >> 3;
3298 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3300 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
3302 #ifdef RTE_APP_TEST_DEBUG
3303 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3306 /* Create SNOW3G operation */
3307 retval = create_snow3g_cipher_hash_operation(tdata->digest.data,
3308 tdata->digest.len, tdata->aad.data,
3309 tdata->aad.len, /*tdata->plaintext.len,*/
3310 plaintext_pad_len, RTE_CRYPTO_AUTH_OP_GENERATE,
3311 tdata->iv.data, tdata->iv.len,
3312 tdata->validCipherLenInBits.len,
3313 tdata->validCipherOffsetLenInBits.len,
3314 tdata->validAuthLenInBits.len,
3315 tdata->validAuthOffsetLenInBits.len);
3319 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3321 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3322 ut_params->obuf = ut_params->op->sym->m_src;
3323 if (ut_params->obuf)
3324 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3327 ciphertext = plaintext;
3328 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3329 if (lastByteValidBits == 0)
3330 lastByteValidBits = 8;
3331 lastByteMask = lastByteMask << (8-lastByteValidBits);
3332 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3334 #ifdef RTE_APP_TEST_DEBUG
3335 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3338 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3340 tdata->ciphertext.data,
3341 tdata->ciphertext.len >> 3,
3342 "Snow3G Ciphertext data not as expected");
3344 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3345 + plaintext_pad_len + tdata->aad.len;
3348 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3351 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3352 "Snow3G Generated auth tag not as expected");
3356 test_snow3g_encrypted_authentication(const struct snow3g_test_data *tdata)
3358 struct crypto_testsuite_params *ts_params = &testsuite_params;
3359 struct crypto_unittest_params *ut_params = &unittest_params;
3363 uint8_t *plaintext, *ciphertext;
3364 uint8_t plaintext_pad_len;
3365 uint8_t lastByteValidBits = 8;
3366 uint8_t lastByteMask = 0xFF;
3368 /* Create SNOW3G session */
3369 retval = create_snow3g_auth_cipher_session(ts_params->valid_devs[0],
3370 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3371 RTE_CRYPTO_AUTH_OP_GENERATE,
3372 tdata->key.data, tdata->key.len,
3373 tdata->aad.len, tdata->digest.len);
3377 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3379 /* clear mbuf payload */
3380 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3381 rte_pktmbuf_tailroom(ut_params->ibuf));
3383 /* Append data which is padded to a multiple */
3384 /* of the algorithms block size */
3385 plaintext_pad_len = RTE_ALIGN_CEIL((tdata->plaintext.len >> 3), 8);
3387 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3389 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len >> 3);
3391 #ifdef RTE_APP_TEST_DEBUG
3392 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3395 /* Create SNOW3G operation */
3396 retval = create_snow3g_auth_cipher_operation(
3398 tdata->iv.data, tdata->iv.len,
3399 tdata->aad.data, tdata->aad.len,
3401 tdata->validCipherLenInBits.len,
3402 tdata->validCipherOffsetLenInBits.len,
3403 tdata->validAuthLenInBits.len,
3404 tdata->validAuthOffsetLenInBits.len
3410 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
3412 TEST_ASSERT_NOT_NULL(ut_params->op, "failed to retrieve obuf");
3413 ut_params->obuf = ut_params->op->sym->m_src;
3414 if (ut_params->obuf)
3415 ciphertext = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3416 + tdata->aad.len + tdata->iv.len;
3418 ciphertext = plaintext;
3420 lastByteValidBits = (tdata->validDataLenInBits.len % 8);
3421 if (lastByteValidBits == 0)
3422 lastByteValidBits = 8;
3423 lastByteMask = lastByteMask << (8-lastByteValidBits);
3424 (*(ciphertext + (tdata->ciphertext.len >> 3) - 1)) &= lastByteMask;
3425 ut_params->digest = rte_pktmbuf_mtod(ut_params->obuf, uint8_t *)
3426 + plaintext_pad_len + tdata->aad.len + tdata->iv.len;
3427 #ifdef RTE_APP_TEST_DEBUG
3428 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3431 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3433 tdata->ciphertext.data,
3434 tdata->ciphertext.len >> 3,
3435 "Snow3G Ciphertext data not as expected");
3438 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3441 DIGEST_BYTE_LENGTH_SNOW3G_UIA2,
3442 "Snow3G Generated auth tag not as expected");
3447 test_snow3g_encryption_test_case_1(void)
3449 return test_snow3g_encryption(&snow3g_test_case_1);
3453 test_snow3g_encryption_test_case_1_oop(void)
3455 return test_snow3g_encryption_oop(&snow3g_test_case_1);
3459 test_snow3g_encryption_test_case_2(void)
3461 return test_snow3g_encryption(&snow3g_test_case_2);
3465 test_snow3g_encryption_test_case_3(void)
3467 return test_snow3g_encryption(&snow3g_test_case_3);
3471 test_snow3g_encryption_test_case_4(void)
3473 return test_snow3g_encryption(&snow3g_test_case_4);
3477 test_snow3g_encryption_test_case_5(void)
3479 return test_snow3g_encryption(&snow3g_test_case_5);
3483 test_snow3g_decryption_test_case_1(void)
3485 return test_snow3g_decryption(&snow3g_test_case_1);
3489 test_snow3g_decryption_test_case_1_oop(void)
3491 return test_snow3g_decryption_oop(&snow3g_test_case_1);
3495 test_snow3g_decryption_test_case_2(void)
3497 return test_snow3g_decryption(&snow3g_test_case_2);
3501 test_snow3g_decryption_test_case_3(void)
3503 return test_snow3g_decryption(&snow3g_test_case_3);
3507 test_snow3g_decryption_test_case_4(void)
3509 return test_snow3g_decryption(&snow3g_test_case_4);
3513 test_snow3g_decryption_test_case_5(void)
3515 return test_snow3g_decryption(&snow3g_test_case_5);
3518 test_snow3g_authenticated_encryption_test_case_1(void)
3520 return test_snow3g_authenticated_encryption(&snow3g_test_case_3);
3524 test_snow3g_encrypted_authentication_test_case_1(void)
3526 return test_snow3g_encrypted_authentication(&snow3g_test_case_6);
3529 /* ***** AES-GCM Tests ***** */
3532 create_gcm_session(uint8_t dev_id, enum rte_crypto_cipher_operation op,
3533 const uint8_t *key, const uint8_t key_len,
3534 const uint8_t aad_len, const uint8_t auth_len)
3536 uint8_t cipher_key[key_len];
3538 struct crypto_unittest_params *ut_params = &unittest_params;
3541 memcpy(cipher_key, key, key_len);
3543 /* Setup Cipher Parameters */
3544 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3545 ut_params->cipher_xform.next = NULL;
3547 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_GCM;
3548 ut_params->cipher_xform.cipher.op = op;
3549 ut_params->cipher_xform.cipher.key.data = cipher_key;
3550 ut_params->cipher_xform.cipher.key.length = key_len;
3552 #ifdef RTE_APP_TEST_DEBUG
3553 rte_hexdump(stdout, "key:", key, key_len);
3555 /* Setup Authentication Parameters */
3556 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
3557 ut_params->auth_xform.next = NULL;
3559 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_AES_GCM;
3561 ut_params->auth_xform.auth.digest_length = auth_len;
3562 ut_params->auth_xform.auth.add_auth_data_length = aad_len;
3563 ut_params->auth_xform.auth.key.length = 0;
3564 ut_params->auth_xform.auth.key.data = NULL;
3566 if (op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
3567 ut_params->cipher_xform.next = &ut_params->auth_xform;
3569 /* Create Crypto session*/
3570 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3571 &ut_params->cipher_xform);
3572 } else {/* Create Crypto session*/
3573 ut_params->auth_xform.next = &ut_params->cipher_xform;
3574 ut_params->sess = rte_cryptodev_sym_session_create(dev_id,
3575 &ut_params->auth_xform);
3578 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
3584 create_gcm_operation(enum rte_crypto_cipher_operation op,
3585 const uint8_t *auth_tag, const unsigned auth_tag_len,
3586 const uint8_t *iv, const unsigned iv_len,
3587 const uint8_t *aad, const unsigned aad_len,
3588 const unsigned data_len, unsigned data_pad_len)
3590 struct crypto_testsuite_params *ts_params = &testsuite_params;
3591 struct crypto_unittest_params *ut_params = &unittest_params;
3593 unsigned iv_pad_len = 0, aad_buffer_len;
3595 /* Generate Crypto op data structure */
3596 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
3597 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
3598 TEST_ASSERT_NOT_NULL(ut_params->op,
3599 "Failed to allocate symmetric crypto operation struct");
3601 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
3605 sym_op->auth.digest.data = (uint8_t *)rte_pktmbuf_append(
3606 ut_params->ibuf, auth_tag_len);
3607 TEST_ASSERT_NOT_NULL(sym_op->auth.digest.data,
3608 "no room to append digest");
3609 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
3610 ut_params->ibuf, data_pad_len);
3611 sym_op->auth.digest.length = auth_tag_len;
3613 if (op == RTE_CRYPTO_CIPHER_OP_DECRYPT) {
3614 rte_memcpy(sym_op->auth.digest.data, auth_tag, auth_tag_len);
3615 #ifdef RTE_APP_TEST_DEBUG
3616 rte_hexdump(stdout, "digest:",
3617 ut_params->op->digest.data,
3618 ut_params->op->digest.length);
3623 iv_pad_len = RTE_ALIGN_CEIL(iv_len, 16);
3625 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
3626 ut_params->ibuf, iv_pad_len);
3627 TEST_ASSERT_NOT_NULL(sym_op->cipher.iv.data, "no room to prepend iv");
3629 memset(sym_op->cipher.iv.data, 0, iv_pad_len);
3630 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys(ut_params->ibuf);
3631 sym_op->cipher.iv.length = iv_pad_len;
3633 rte_memcpy(sym_op->cipher.iv.data, iv, iv_len);
3637 sym_op->cipher.iv.data[15] = 1;
3640 * Always allocate the aad up to the block size.
3641 * The cryptodev API calls out -
3642 * - the array must be big enough to hold the AAD, plus any
3643 * space to round this up to the nearest multiple of the
3644 * block size (16 bytes).
3646 aad_buffer_len = ALIGN_POW2_ROUNDUP(aad_len, 16);
3648 sym_op->auth.aad.data = (uint8_t *)rte_pktmbuf_prepend(
3649 ut_params->ibuf, aad_buffer_len);
3650 TEST_ASSERT_NOT_NULL(sym_op->auth.aad.data,
3651 "no room to prepend aad");
3652 sym_op->auth.aad.phys_addr = rte_pktmbuf_mtophys(
3654 sym_op->auth.aad.length = aad_len;
3656 memset(sym_op->auth.aad.data, 0, aad_buffer_len);
3657 rte_memcpy(sym_op->auth.aad.data, aad, aad_len);
3659 #ifdef RTE_APP_TEST_DEBUG
3660 rte_hexdump(stdout, "iv:", ut_params->op->iv.data, iv_pad_len);
3661 rte_hexdump(stdout, "aad:",
3662 ut_params->op->additional_auth.data, aad_len);
3664 sym_op->cipher.data.length = data_len;
3665 sym_op->cipher.data.offset = aad_buffer_len + iv_pad_len;
3667 sym_op->auth.data.offset = aad_buffer_len + iv_pad_len;
3668 sym_op->auth.data.length = data_len;
3674 test_mb_AES_GCM_authenticated_encryption(const struct gcm_test_data *tdata)
3676 struct crypto_testsuite_params *ts_params = &testsuite_params;
3677 struct crypto_unittest_params *ut_params = &unittest_params;
3681 uint8_t *plaintext, *ciphertext, *auth_tag;
3682 uint16_t plaintext_pad_len;
3684 /* Create GCM session */
3685 retval = create_gcm_session(ts_params->valid_devs[0],
3686 RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3687 tdata->key.data, tdata->key.len,
3688 tdata->aad.len, tdata->auth_tag.len);
3693 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3695 /* clear mbuf payload */
3696 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3697 rte_pktmbuf_tailroom(ut_params->ibuf));
3700 * Append data which is padded to a multiple
3701 * of the algorithms block size
3703 plaintext_pad_len = RTE_ALIGN_CEIL(tdata->plaintext.len, 16);
3705 plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3707 memcpy(plaintext, tdata->plaintext.data, tdata->plaintext.len);
3709 #ifdef RTE_APP_TEST_DEBUG
3710 rte_hexdump(stdout, "plaintext:", plaintext, tdata->plaintext.len);
3712 /* Create GCM opertaion */
3713 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_ENCRYPT,
3714 tdata->auth_tag.data, tdata->auth_tag.len,
3715 tdata->iv.data, tdata->iv.len,
3716 tdata->aad.data, tdata->aad.len,
3717 tdata->plaintext.len, plaintext_pad_len);
3721 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3723 ut_params->op->sym->m_src = ut_params->ibuf;
3725 /* Process crypto operation */
3726 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3727 ut_params->op), "failed to process sym crypto op");
3729 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3730 "crypto op processing failed");
3732 if (ut_params->op->sym->m_dst) {
3733 ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3735 auth_tag = rte_pktmbuf_mtod_offset(ut_params->op->sym->m_dst,
3736 uint8_t *, plaintext_pad_len);
3738 ciphertext = plaintext;
3739 auth_tag = plaintext + plaintext_pad_len;
3742 #ifdef RTE_APP_TEST_DEBUG
3743 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3744 rte_hexdump(stdout, "auth tag:", auth_tag, tdata->auth_tag.len);
3747 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3749 tdata->ciphertext.data,
3750 tdata->ciphertext.len,
3751 "GCM Ciphertext data not as expected");
3753 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3755 tdata->auth_tag.data,
3756 tdata->auth_tag.len,
3757 "GCM Generated auth tag not as expected");
3764 test_mb_AES_GCM_authenticated_encryption_test_case_1(void)
3766 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_1);
3770 test_mb_AES_GCM_authenticated_encryption_test_case_2(void)
3772 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_2);
3776 test_mb_AES_GCM_authenticated_encryption_test_case_3(void)
3778 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_3);
3782 test_mb_AES_GCM_authenticated_encryption_test_case_4(void)
3784 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_4);
3788 test_mb_AES_GCM_authenticated_encryption_test_case_5(void)
3790 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_5);
3794 test_mb_AES_GCM_authenticated_encryption_test_case_6(void)
3796 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_6);
3800 test_mb_AES_GCM_authenticated_encryption_test_case_7(void)
3802 return test_mb_AES_GCM_authenticated_encryption(&gcm_test_case_7);
3806 test_mb_AES_GCM_authenticated_decryption(const struct gcm_test_data *tdata)
3808 struct crypto_testsuite_params *ts_params = &testsuite_params;
3809 struct crypto_unittest_params *ut_params = &unittest_params;
3813 uint8_t *plaintext, *ciphertext;
3814 uint16_t ciphertext_pad_len;
3816 /* Create GCM session */
3817 retval = create_gcm_session(ts_params->valid_devs[0],
3818 RTE_CRYPTO_CIPHER_OP_DECRYPT,
3819 tdata->key.data, tdata->key.len,
3820 tdata->aad.len, tdata->auth_tag.len);
3825 /* alloc mbuf and set payload */
3826 ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool);
3828 memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0,
3829 rte_pktmbuf_tailroom(ut_params->ibuf));
3831 ciphertext_pad_len = RTE_ALIGN_CEIL(tdata->ciphertext.len, 16);
3833 ciphertext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
3834 ciphertext_pad_len);
3835 memcpy(ciphertext, tdata->ciphertext.data, tdata->ciphertext.len);
3837 #ifdef RTE_APP_TEST_DEBUG
3838 rte_hexdump(stdout, "ciphertext:", ciphertext, tdata->ciphertext.len);
3840 /* Create GCM opertaion */
3841 retval = create_gcm_operation(RTE_CRYPTO_CIPHER_OP_DECRYPT,
3842 tdata->auth_tag.data, tdata->auth_tag.len,
3843 tdata->iv.data, tdata->iv.len,
3844 tdata->aad.data, tdata->aad.len,
3845 tdata->ciphertext.len, ciphertext_pad_len);
3850 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
3852 ut_params->op->sym->m_src = ut_params->ibuf;
3854 /* Process crypto operation */
3855 TEST_ASSERT_NOT_NULL(process_crypto_request(ts_params->valid_devs[0],
3856 ut_params->op), "failed to process sym crypto op");
3858 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
3859 "crypto op processing failed");
3861 if (ut_params->op->sym->m_dst)
3862 plaintext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst,
3865 plaintext = ciphertext;
3867 #ifdef RTE_APP_TEST_DEBUG
3868 rte_hexdump(stdout, "plaintext:", plaintext, tdata->ciphertext.len);
3871 TEST_ASSERT_BUFFERS_ARE_EQUAL(
3873 tdata->plaintext.data,
3874 tdata->plaintext.len,
3875 "GCM plaintext data not as expected");
3877 TEST_ASSERT_EQUAL(ut_params->op->status,
3878 RTE_CRYPTO_OP_STATUS_SUCCESS,
3879 "GCM authentication failed");
3884 test_mb_AES_GCM_authenticated_decryption_test_case_1(void)
3886 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_1);
3890 test_mb_AES_GCM_authenticated_decryption_test_case_2(void)
3892 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_2);
3896 test_mb_AES_GCM_authenticated_decryption_test_case_3(void)
3898 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_3);
3902 test_mb_AES_GCM_authenticated_decryption_test_case_4(void)
3904 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_4);
3908 test_mb_AES_GCM_authenticated_decryption_test_case_5(void)
3910 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_5);
3914 test_mb_AES_GCM_authenticated_decryption_test_case_6(void)
3916 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_6);
3920 test_mb_AES_GCM_authenticated_decryption_test_case_7(void)
3922 return test_mb_AES_GCM_authenticated_decryption(&gcm_test_case_7);
3928 struct crypto_testsuite_params *ts_params = &testsuite_params;
3929 struct rte_cryptodev_stats stats;
3930 struct rte_cryptodev *dev;
3931 cryptodev_stats_get_t temp_pfn;
3933 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3934 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0] + 600,
3935 &stats) == -ENODEV),
3936 "rte_cryptodev_stats_get invalid dev failed");
3937 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], 0) != 0),
3938 "rte_cryptodev_stats_get invalid Param failed");
3939 dev = &rte_cryptodevs[ts_params->valid_devs[0]];
3940 temp_pfn = dev->dev_ops->stats_get;
3941 dev->dev_ops->stats_get = (cryptodev_stats_get_t)0;
3942 TEST_ASSERT((rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats)
3944 "rte_cryptodev_stats_get invalid Param failed");
3945 dev->dev_ops->stats_get = temp_pfn;
3947 /* Test expected values */
3949 test_AES_CBC_HMAC_SHA1_encrypt_digest();
3951 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3953 "rte_cryptodev_stats_get failed");
3954 TEST_ASSERT((stats.enqueued_count == 1),
3955 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3956 TEST_ASSERT((stats.dequeued_count == 1),
3957 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3958 TEST_ASSERT((stats.enqueue_err_count == 0),
3959 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3960 TEST_ASSERT((stats.dequeue_err_count == 0),
3961 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3963 /* invalid device but should ignore and not reset device stats*/
3964 rte_cryptodev_stats_reset(ts_params->valid_devs[0] + 300);
3965 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3967 "rte_cryptodev_stats_get failed");
3968 TEST_ASSERT((stats.enqueued_count == 1),
3969 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3971 /* check that a valid reset clears stats */
3972 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
3973 TEST_ASSERT_SUCCESS(rte_cryptodev_stats_get(ts_params->valid_devs[0],
3975 "rte_cryptodev_stats_get failed");
3976 TEST_ASSERT((stats.enqueued_count == 0),
3977 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3978 TEST_ASSERT((stats.dequeued_count == 0),
3979 "rte_cryptodev_stats_get returned unexpected enqueued stat");
3981 return TEST_SUCCESS;
3986 test_multi_session(void)
3988 struct crypto_testsuite_params *ts_params = &testsuite_params;
3989 struct crypto_unittest_params *ut_params = &unittest_params;
3991 struct rte_cryptodev_info dev_info;
3992 struct rte_cryptodev_sym_session **sessions;
3996 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
3999 rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info);
4001 sessions = rte_malloc(NULL,
4002 (sizeof(struct rte_cryptodev_sym_session *) *
4003 dev_info.sym.max_nb_sessions) + 1, 0);
4005 /* Create multiple crypto sessions*/
4006 for (i = 0; i < dev_info.sym.max_nb_sessions; i++) {
4007 sessions[i] = rte_cryptodev_sym_session_create(
4008 ts_params->valid_devs[0],
4009 &ut_params->auth_xform);
4010 TEST_ASSERT_NOT_NULL(sessions[i],
4011 "Session creation failed at session number %u",
4014 /* Attempt to send a request on each session */
4015 TEST_ASSERT_SUCCESS(test_AES_CBC_HMAC_SHA512_decrypt_perform(
4016 sessions[i], ut_params, ts_params),
4017 "Failed to perform decrypt on request "
4019 /* free crypto operation structure */
4021 rte_crypto_op_free(ut_params->op);
4024 * free mbuf - both obuf and ibuf are usually the same,
4025 * but rte copes even if we call free twice
4027 if (ut_params->obuf) {
4028 rte_pktmbuf_free(ut_params->obuf);
4029 ut_params->obuf = 0;
4033 /* Next session create should fail */
4034 sessions[i] = rte_cryptodev_sym_session_create(ts_params->valid_devs[0],
4035 &ut_params->auth_xform);
4036 TEST_ASSERT_NULL(sessions[i],
4037 "Session creation succeeded unexpectedly!");
4039 for (i = 0; i < dev_info.sym.max_nb_sessions; i++)
4040 rte_cryptodev_sym_session_free(ts_params->valid_devs[0],
4045 return TEST_SUCCESS;
4049 test_not_in_place_crypto(void)
4051 struct crypto_testsuite_params *ts_params = &testsuite_params;
4052 struct crypto_unittest_params *ut_params = &unittest_params;
4053 struct rte_mbuf *dst_m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4055 test_AES_CBC_HMAC_SHA512_decrypt_create_session_params(ut_params);
4057 /* Create multiple crypto sessions*/
4059 ut_params->sess = rte_cryptodev_sym_session_create(
4060 ts_params->valid_devs[0], &ut_params->auth_xform);
4062 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4065 /* Generate test mbuf data and digest */
4066 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4068 catch_22_quote_2_512_bytes_AES_CBC_ciphertext,
4069 QUOTE_512_BYTES, 0);
4071 ut_params->digest = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf,
4072 DIGEST_BYTE_LENGTH_SHA512);
4073 TEST_ASSERT_NOT_NULL(ut_params->digest, "no room to append digest");
4075 rte_memcpy(ut_params->digest,
4076 catch_22_quote_2_512_bytes_AES_CBC_HMAC_SHA512_digest,
4077 DIGEST_BYTE_LENGTH_SHA512);
4079 /* Generate Crypto op data structure */
4080 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4081 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4082 TEST_ASSERT_NOT_NULL(ut_params->op,
4083 "Failed to allocate symmetric crypto operation struct");
4086 /* Set crypto operation data parameters */
4087 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4089 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4091 /* set crypto operation source mbuf */
4092 sym_op->m_src = ut_params->ibuf;
4093 sym_op->m_dst = dst_m;
4095 sym_op->auth.digest.data = ut_params->digest;
4096 sym_op->auth.digest.phys_addr = rte_pktmbuf_mtophys_offset(
4097 ut_params->ibuf, QUOTE_512_BYTES);
4098 sym_op->auth.digest.length = DIGEST_BYTE_LENGTH_SHA512;
4100 sym_op->auth.data.offset = CIPHER_IV_LENGTH_AES_CBC;
4101 sym_op->auth.data.length = QUOTE_512_BYTES;
4104 sym_op->cipher.iv.data = (uint8_t *)rte_pktmbuf_prepend(
4105 ut_params->ibuf, CIPHER_IV_LENGTH_AES_CBC);
4106 sym_op->cipher.iv.phys_addr = rte_pktmbuf_mtophys_offset(
4107 ut_params->ibuf, 0);
4108 sym_op->cipher.iv.length = CIPHER_IV_LENGTH_AES_CBC;
4110 rte_memcpy(sym_op->cipher.iv.data, aes_cbc_iv,
4111 CIPHER_IV_LENGTH_AES_CBC);
4113 sym_op->cipher.data.offset = CIPHER_IV_LENGTH_AES_CBC;
4114 sym_op->cipher.data.length = QUOTE_512_BYTES;
4116 /* Process crypto operation */
4117 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4119 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4121 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4122 "crypto operation processing failed");
4125 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4126 rte_pktmbuf_mtod(ut_params->op->sym->m_dst, char *),
4129 "Plaintext data not as expected");
4131 return TEST_SUCCESS;
4135 test_null_cipher_only_operation(void)
4137 struct crypto_testsuite_params *ts_params = &testsuite_params;
4138 struct crypto_unittest_params *ut_params = &unittest_params;
4140 /* Generate test mbuf data and space for digest */
4141 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4142 catch_22_quote, QUOTE_512_BYTES, 0);
4144 /* Setup Cipher Parameters */
4145 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4146 ut_params->cipher_xform.next = NULL;
4148 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4149 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4151 /* Create Crypto session*/
4152 ut_params->sess = rte_cryptodev_sym_session_create(
4153 ts_params->valid_devs[0], &ut_params->cipher_xform);
4154 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4156 /* Generate Crypto op data structure */
4157 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4158 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4159 TEST_ASSERT_NOT_NULL(ut_params->op,
4160 "Failed to allocate symmetric crypto operation struct");
4162 /* Set crypto operation data parameters */
4163 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4165 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4167 /* set crypto operation source mbuf */
4168 sym_op->m_src = ut_params->ibuf;
4170 sym_op->cipher.data.offset = 0;
4171 sym_op->cipher.data.length = QUOTE_512_BYTES;
4173 /* Process crypto operation */
4174 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4176 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4178 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4179 "crypto operation processing failed");
4182 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4183 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4186 "Ciphertext data not as expected");
4188 return TEST_SUCCESS;
4192 test_null_auth_only_operation(void)
4194 struct crypto_testsuite_params *ts_params = &testsuite_params;
4195 struct crypto_unittest_params *ut_params = &unittest_params;
4197 /* Generate test mbuf data and space for digest */
4198 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4199 catch_22_quote, QUOTE_512_BYTES, 0);
4201 /* Setup HMAC Parameters */
4202 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4203 ut_params->auth_xform.next = NULL;
4205 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4206 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4208 /* Create Crypto session*/
4209 ut_params->sess = rte_cryptodev_sym_session_create(
4210 ts_params->valid_devs[0], &ut_params->auth_xform);
4211 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4213 /* Generate Crypto op data structure */
4214 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4215 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4216 TEST_ASSERT_NOT_NULL(ut_params->op,
4217 "Failed to allocate symmetric crypto operation struct");
4219 /* Set crypto operation data parameters */
4220 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4222 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4224 sym_op->m_src = ut_params->ibuf;
4226 sym_op->auth.data.offset = 0;
4227 sym_op->auth.data.length = QUOTE_512_BYTES;
4229 /* Process crypto operation */
4230 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4232 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4234 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4235 "crypto operation processing failed");
4237 return TEST_SUCCESS;
4241 test_null_cipher_auth_operation(void)
4243 struct crypto_testsuite_params *ts_params = &testsuite_params;
4244 struct crypto_unittest_params *ut_params = &unittest_params;
4246 /* Generate test mbuf data and space for digest */
4247 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4248 catch_22_quote, QUOTE_512_BYTES, 0);
4250 /* Setup Cipher Parameters */
4251 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4252 ut_params->cipher_xform.next = &ut_params->auth_xform;
4254 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4255 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4257 /* Setup HMAC Parameters */
4258 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4259 ut_params->auth_xform.next = NULL;
4261 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4262 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4264 /* Create Crypto session*/
4265 ut_params->sess = rte_cryptodev_sym_session_create(
4266 ts_params->valid_devs[0], &ut_params->cipher_xform);
4267 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4269 /* Generate Crypto op data structure */
4270 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4271 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4272 TEST_ASSERT_NOT_NULL(ut_params->op,
4273 "Failed to allocate symmetric crypto operation struct");
4275 /* Set crypto operation data parameters */
4276 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4278 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4280 sym_op->m_src = ut_params->ibuf;
4282 sym_op->cipher.data.offset = 0;
4283 sym_op->cipher.data.length = QUOTE_512_BYTES;
4285 sym_op->auth.data.offset = 0;
4286 sym_op->auth.data.length = QUOTE_512_BYTES;
4288 /* Process crypto operation */
4289 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4291 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4293 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4294 "crypto operation processing failed");
4297 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4298 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4301 "Ciphertext data not as expected");
4303 return TEST_SUCCESS;
4307 test_null_auth_cipher_operation(void)
4309 struct crypto_testsuite_params *ts_params = &testsuite_params;
4310 struct crypto_unittest_params *ut_params = &unittest_params;
4312 /* Generate test mbuf data and space for digest */
4313 ut_params->ibuf = setup_test_string(ts_params->mbuf_pool,
4314 catch_22_quote, QUOTE_512_BYTES, 0);
4316 /* Setup Cipher Parameters */
4317 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4318 ut_params->cipher_xform.next = NULL;
4320 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4321 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4323 /* Setup HMAC Parameters */
4324 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4325 ut_params->auth_xform.next = &ut_params->cipher_xform;
4327 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4328 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4330 /* Create Crypto session*/
4331 ut_params->sess = rte_cryptodev_sym_session_create(
4332 ts_params->valid_devs[0], &ut_params->cipher_xform);
4333 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4335 /* Generate Crypto op data structure */
4336 ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool,
4337 RTE_CRYPTO_OP_TYPE_SYMMETRIC);
4338 TEST_ASSERT_NOT_NULL(ut_params->op,
4339 "Failed to allocate symmetric crypto operation struct");
4341 /* Set crypto operation data parameters */
4342 rte_crypto_op_attach_sym_session(ut_params->op, ut_params->sess);
4344 struct rte_crypto_sym_op *sym_op = ut_params->op->sym;
4346 sym_op->m_src = ut_params->ibuf;
4348 sym_op->cipher.data.offset = 0;
4349 sym_op->cipher.data.length = QUOTE_512_BYTES;
4351 sym_op->auth.data.offset = 0;
4352 sym_op->auth.data.length = QUOTE_512_BYTES;
4354 /* Process crypto operation */
4355 ut_params->op = process_crypto_request(ts_params->valid_devs[0],
4357 TEST_ASSERT_NOT_NULL(ut_params->op, "no crypto operation returned");
4359 TEST_ASSERT_EQUAL(ut_params->op->status, RTE_CRYPTO_OP_STATUS_SUCCESS,
4360 "crypto operation processing failed");
4363 TEST_ASSERT_BUFFERS_ARE_EQUAL(
4364 rte_pktmbuf_mtod(ut_params->op->sym->m_src, uint8_t *),
4367 "Ciphertext data not as expected");
4369 return TEST_SUCCESS;
4374 test_null_invalid_operation(void)
4376 struct crypto_testsuite_params *ts_params = &testsuite_params;
4377 struct crypto_unittest_params *ut_params = &unittest_params;
4379 /* Setup Cipher Parameters */
4380 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4381 ut_params->cipher_xform.next = NULL;
4383 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_AES_CBC;
4384 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4386 /* Create Crypto session*/
4387 ut_params->sess = rte_cryptodev_sym_session_create(
4388 ts_params->valid_devs[0], &ut_params->cipher_xform);
4389 TEST_ASSERT_NULL(ut_params->sess,
4390 "Session creation succeeded unexpectedly");
4393 /* Setup HMAC Parameters */
4394 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4395 ut_params->auth_xform.next = NULL;
4397 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_SHA1_HMAC;
4398 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4400 /* Create Crypto session*/
4401 ut_params->sess = rte_cryptodev_sym_session_create(
4402 ts_params->valid_devs[0], &ut_params->auth_xform);
4403 TEST_ASSERT_NULL(ut_params->sess,
4404 "Session creation succeeded unexpectedly");
4406 return TEST_SUCCESS;
4410 #define NULL_BURST_LENGTH (32)
4413 test_null_burst_operation(void)
4415 struct crypto_testsuite_params *ts_params = &testsuite_params;
4416 struct crypto_unittest_params *ut_params = &unittest_params;
4418 unsigned i, burst_len = NULL_BURST_LENGTH;
4420 struct rte_crypto_op *burst[NULL_BURST_LENGTH] = { NULL };
4421 struct rte_crypto_op *burst_dequeued[NULL_BURST_LENGTH] = { NULL };
4423 /* Setup Cipher Parameters */
4424 ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
4425 ut_params->cipher_xform.next = &ut_params->auth_xform;
4427 ut_params->cipher_xform.cipher.algo = RTE_CRYPTO_CIPHER_NULL;
4428 ut_params->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT;
4430 /* Setup HMAC Parameters */
4431 ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
4432 ut_params->auth_xform.next = NULL;
4434 ut_params->auth_xform.auth.algo = RTE_CRYPTO_AUTH_NULL;
4435 ut_params->auth_xform.auth.op = RTE_CRYPTO_AUTH_OP_GENERATE;
4437 /* Create Crypto session*/
4438 ut_params->sess = rte_cryptodev_sym_session_create(
4439 ts_params->valid_devs[0], &ut_params->cipher_xform);
4440 TEST_ASSERT_NOT_NULL(ut_params->sess, "Session creation failed");
4442 TEST_ASSERT_EQUAL(rte_crypto_op_bulk_alloc(ts_params->op_mpool,
4443 RTE_CRYPTO_OP_TYPE_SYMMETRIC, burst, burst_len),
4444 burst_len, "failed to generate burst of crypto ops");
4446 /* Generate an operation for each mbuf in burst */
4447 for (i = 0; i < burst_len; i++) {
4448 struct rte_mbuf *m = rte_pktmbuf_alloc(ts_params->mbuf_pool);
4450 TEST_ASSERT_NOT_NULL(m, "Failed to allocate mbuf");
4452 unsigned *data = (unsigned *)rte_pktmbuf_append(m,
4456 rte_crypto_op_attach_sym_session(burst[i], ut_params->sess);
4458 burst[i]->sym->m_src = m;
4461 /* Process crypto operation */
4462 TEST_ASSERT_EQUAL(rte_cryptodev_enqueue_burst(ts_params->valid_devs[0],
4463 0, burst, burst_len),
4465 "Error enqueuing burst");
4467 TEST_ASSERT_EQUAL(rte_cryptodev_dequeue_burst(ts_params->valid_devs[0],
4468 0, burst_dequeued, burst_len),
4470 "Error dequeuing burst");
4473 for (i = 0; i < burst_len; i++) {
4475 *rte_pktmbuf_mtod(burst[i]->sym->m_src, uint32_t *),
4476 *rte_pktmbuf_mtod(burst_dequeued[i]->sym->m_src,
4478 "data not as expected");
4480 rte_pktmbuf_free(burst[i]->sym->m_src);
4481 rte_crypto_op_free(burst[i]);
4484 return TEST_SUCCESS;
4490 static struct unit_test_suite cryptodev_qat_testsuite = {
4491 .suite_name = "Crypto QAT Unit Test Suite",
4492 .setup = testsuite_setup,
4493 .teardown = testsuite_teardown,
4494 .unit_test_cases = {
4495 TEST_CASE_ST(ut_setup, ut_teardown,
4496 test_device_configure_invalid_dev_id),
4497 TEST_CASE_ST(ut_setup, ut_teardown,
4498 test_device_configure_invalid_queue_pair_ids),
4499 TEST_CASE_ST(ut_setup, ut_teardown,
4500 test_queue_pair_descriptor_setup),
4501 TEST_CASE_ST(ut_setup, ut_teardown,
4502 test_multi_session),
4504 TEST_CASE_ST(ut_setup, ut_teardown,
4505 test_AES_CBC_HMAC_SHA1_encrypt_digest_oop),
4506 TEST_CASE_ST(ut_setup, ut_teardown,
4507 test_AES_CBC_HMAC_SHA1_decrypt_digest_oop_ver),
4509 TEST_CASE_ST(ut_setup, ut_teardown,
4510 test_AES_CBC_HMAC_SHA1_encrypt_digest),
4511 TEST_CASE_ST(ut_setup, ut_teardown,
4512 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
4514 TEST_CASE_ST(ut_setup, ut_teardown,
4515 test_AES_CBC_HMAC_SHA256_encrypt_digest),
4516 TEST_CASE_ST(ut_setup, ut_teardown,
4517 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
4519 TEST_CASE_ST(ut_setup, ut_teardown,
4520 test_AES_CBC_HMAC_SHA512_encrypt_digest),
4521 TEST_CASE_ST(ut_setup, ut_teardown,
4522 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
4524 TEST_CASE_ST(ut_setup, ut_teardown,
4525 test_AES_CTR_encrypt_digest_case_1),
4526 TEST_CASE_ST(ut_setup, ut_teardown,
4527 test_AES_CTR_encrypt_digest_case_2),
4528 TEST_CASE_ST(ut_setup, ut_teardown,
4529 test_AES_CTR_encrypt_digest_case_3),
4530 TEST_CASE_ST(ut_setup, ut_teardown,
4531 test_AES_CTR_digest_verify_decrypt_case_1),
4532 TEST_CASE_ST(ut_setup, ut_teardown,
4533 test_AES_CTR_digest_verify_decrypt_case_2),
4534 TEST_CASE_ST(ut_setup, ut_teardown,
4535 test_AES_CTR_digest_verify_decrypt_case_3),
4537 TEST_CASE_ST(ut_setup, ut_teardown,
4538 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
4539 TEST_CASE_ST(ut_setup, ut_teardown,
4540 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
4541 TEST_CASE_ST(ut_setup, ut_teardown, test_stats),
4543 /** AES GCM Authenticated Encryption */
4544 TEST_CASE_ST(ut_setup, ut_teardown,
4545 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4546 TEST_CASE_ST(ut_setup, ut_teardown,
4547 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4548 TEST_CASE_ST(ut_setup, ut_teardown,
4549 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4550 TEST_CASE_ST(ut_setup, ut_teardown,
4551 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4552 TEST_CASE_ST(ut_setup, ut_teardown,
4553 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4554 TEST_CASE_ST(ut_setup, ut_teardown,
4555 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4556 TEST_CASE_ST(ut_setup, ut_teardown,
4557 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4559 /** AES GCM Authenticated Decryption */
4560 TEST_CASE_ST(ut_setup, ut_teardown,
4561 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4562 TEST_CASE_ST(ut_setup, ut_teardown,
4563 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4564 TEST_CASE_ST(ut_setup, ut_teardown,
4565 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4566 TEST_CASE_ST(ut_setup, ut_teardown,
4567 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4568 TEST_CASE_ST(ut_setup, ut_teardown,
4569 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4570 TEST_CASE_ST(ut_setup, ut_teardown,
4571 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4572 TEST_CASE_ST(ut_setup, ut_teardown,
4573 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4575 /** Snow3G encrypt only (UEA2) */
4576 TEST_CASE_ST(ut_setup, ut_teardown,
4577 test_snow3g_encryption_test_case_1),
4578 TEST_CASE_ST(ut_setup, ut_teardown,
4579 test_snow3g_encryption_test_case_2),
4580 TEST_CASE_ST(ut_setup, ut_teardown,
4581 test_snow3g_encryption_test_case_3),
4582 TEST_CASE_ST(ut_setup, ut_teardown,
4583 test_snow3g_encryption_test_case_4),
4584 TEST_CASE_ST(ut_setup, ut_teardown,
4585 test_snow3g_encryption_test_case_5),
4587 TEST_CASE_ST(ut_setup, ut_teardown,
4588 test_snow3g_encryption_test_case_1_oop),
4589 TEST_CASE_ST(ut_setup, ut_teardown,
4590 test_snow3g_decryption_test_case_1_oop),
4592 /** Snow3G decrypt only (UEA2) */
4593 TEST_CASE_ST(ut_setup, ut_teardown,
4594 test_snow3g_decryption_test_case_1),
4595 TEST_CASE_ST(ut_setup, ut_teardown,
4596 test_snow3g_decryption_test_case_2),
4597 TEST_CASE_ST(ut_setup, ut_teardown,
4598 test_snow3g_decryption_test_case_3),
4599 TEST_CASE_ST(ut_setup, ut_teardown,
4600 test_snow3g_decryption_test_case_4),
4601 TEST_CASE_ST(ut_setup, ut_teardown,
4602 test_snow3g_decryption_test_case_5),
4603 TEST_CASE_ST(ut_setup, ut_teardown,
4604 test_snow3g_hash_generate_test_case_1),
4605 TEST_CASE_ST(ut_setup, ut_teardown,
4606 test_snow3g_hash_generate_test_case_2),
4607 TEST_CASE_ST(ut_setup, ut_teardown,
4608 test_snow3g_hash_generate_test_case_3),
4609 TEST_CASE_ST(ut_setup, ut_teardown,
4610 test_snow3g_hash_verify_test_case_1),
4611 TEST_CASE_ST(ut_setup, ut_teardown,
4612 test_snow3g_hash_verify_test_case_2),
4613 TEST_CASE_ST(ut_setup, ut_teardown,
4614 test_snow3g_hash_verify_test_case_3),
4615 TEST_CASE_ST(ut_setup, ut_teardown,
4616 test_snow3g_authenticated_encryption_test_case_1),
4617 TEST_CASE_ST(ut_setup, ut_teardown,
4618 test_snow3g_encrypted_authentication_test_case_1),
4619 TEST_CASES_END() /**< NULL terminate unit test array */
4623 static struct unit_test_suite cryptodev_aesni_mb_testsuite = {
4624 .suite_name = "Crypto Device AESNI MB Unit Test Suite",
4625 .setup = testsuite_setup,
4626 .teardown = testsuite_teardown,
4627 .unit_test_cases = {
4628 TEST_CASE_ST(ut_setup, ut_teardown,
4629 test_AES_CBC_HMAC_SHA1_encrypt_digest),
4630 TEST_CASE_ST(ut_setup, ut_teardown,
4631 test_AES_CBC_HMAC_SHA1_decrypt_digest_verify),
4633 TEST_CASE_ST(ut_setup, ut_teardown,
4634 test_AES_CBC_HMAC_SHA256_encrypt_digest),
4635 TEST_CASE_ST(ut_setup, ut_teardown,
4636 test_AES_CBC_HMAC_SHA256_decrypt_digest_verify),
4638 TEST_CASE_ST(ut_setup, ut_teardown,
4639 test_AES_CBC_HMAC_SHA512_encrypt_digest),
4640 TEST_CASE_ST(ut_setup, ut_teardown,
4641 test_AES_CBC_HMAC_SHA512_decrypt_digest_verify),
4643 TEST_CASE_ST(ut_setup, ut_teardown,
4644 test_AES_CBC_HMAC_AES_XCBC_encrypt_digest),
4645 TEST_CASE_ST(ut_setup, ut_teardown,
4646 test_AES_CBC_HMAC_AES_XCBC_decrypt_digest_verify),
4648 TEST_CASE_ST(ut_setup, ut_teardown,
4649 test_AES_CBC_HMAC_SHA1_encrypt_digest_sessionless),
4651 TEST_CASE_ST(ut_setup, ut_teardown,
4652 test_AES_CTR_encrypt_digest_case_1),
4653 TEST_CASE_ST(ut_setup, ut_teardown,
4654 test_AES_CTR_encrypt_digest_case_2),
4655 TEST_CASE_ST(ut_setup, ut_teardown,
4656 test_AES_CTR_encrypt_digest_case_3),
4657 TEST_CASE_ST(ut_setup, ut_teardown,
4658 test_AES_CTR_digest_verify_decrypt_case_1),
4659 TEST_CASE_ST(ut_setup, ut_teardown,
4660 test_AES_CTR_digest_verify_decrypt_case_2),
4661 TEST_CASE_ST(ut_setup, ut_teardown,
4662 test_AES_CTR_digest_verify_decrypt_case_3),
4664 TEST_CASE_ST(ut_setup, ut_teardown,
4665 test_not_in_place_crypto),
4667 TEST_CASES_END() /**< NULL terminate unit test array */
4671 static struct unit_test_suite cryptodev_aesni_gcm_testsuite = {
4672 .suite_name = "Crypto Device AESNI GCM Unit Test Suite",
4673 .setup = testsuite_setup,
4674 .teardown = testsuite_teardown,
4675 .unit_test_cases = {
4676 /** AES GCM Authenticated Encryption */
4677 TEST_CASE_ST(ut_setup, ut_teardown,
4678 test_mb_AES_GCM_authenticated_encryption_test_case_1),
4679 TEST_CASE_ST(ut_setup, ut_teardown,
4680 test_mb_AES_GCM_authenticated_encryption_test_case_2),
4681 TEST_CASE_ST(ut_setup, ut_teardown,
4682 test_mb_AES_GCM_authenticated_encryption_test_case_3),
4683 TEST_CASE_ST(ut_setup, ut_teardown,
4684 test_mb_AES_GCM_authenticated_encryption_test_case_4),
4685 TEST_CASE_ST(ut_setup, ut_teardown,
4686 test_mb_AES_GCM_authenticated_encryption_test_case_5),
4687 TEST_CASE_ST(ut_setup, ut_teardown,
4688 test_mb_AES_GCM_authenticated_encryption_test_case_6),
4689 TEST_CASE_ST(ut_setup, ut_teardown,
4690 test_mb_AES_GCM_authenticated_encryption_test_case_7),
4692 /** AES GCM Authenticated Decryption */
4693 TEST_CASE_ST(ut_setup, ut_teardown,
4694 test_mb_AES_GCM_authenticated_decryption_test_case_1),
4695 TEST_CASE_ST(ut_setup, ut_teardown,
4696 test_mb_AES_GCM_authenticated_decryption_test_case_2),
4697 TEST_CASE_ST(ut_setup, ut_teardown,
4698 test_mb_AES_GCM_authenticated_decryption_test_case_3),
4699 TEST_CASE_ST(ut_setup, ut_teardown,
4700 test_mb_AES_GCM_authenticated_decryption_test_case_4),
4701 TEST_CASE_ST(ut_setup, ut_teardown,
4702 test_mb_AES_GCM_authenticated_decryption_test_case_5),
4703 TEST_CASE_ST(ut_setup, ut_teardown,
4704 test_mb_AES_GCM_authenticated_decryption_test_case_6),
4705 TEST_CASE_ST(ut_setup, ut_teardown,
4706 test_mb_AES_GCM_authenticated_decryption_test_case_7),
4708 TEST_CASES_END() /**< NULL terminate unit test array */
4712 static struct unit_test_suite cryptodev_sw_snow3g_testsuite = {
4713 .suite_name = "Crypto Device SW Snow3G Unit Test Suite",
4714 .setup = testsuite_setup,
4715 .teardown = testsuite_teardown,
4716 .unit_test_cases = {
4717 /** Snow3G encrypt only (UEA2) */
4718 TEST_CASE_ST(ut_setup, ut_teardown,
4719 test_snow3g_encryption_test_case_1),
4720 TEST_CASE_ST(ut_setup, ut_teardown,
4721 test_snow3g_encryption_test_case_2),
4722 TEST_CASE_ST(ut_setup, ut_teardown,
4723 test_snow3g_encryption_test_case_3),
4724 TEST_CASE_ST(ut_setup, ut_teardown,
4725 test_snow3g_encryption_test_case_4),
4726 TEST_CASE_ST(ut_setup, ut_teardown,
4727 test_snow3g_encryption_test_case_5),
4730 /** Snow3G decrypt only (UEA2) */
4731 TEST_CASE_ST(ut_setup, ut_teardown,
4732 test_snow3g_decryption_test_case_1),
4733 TEST_CASE_ST(ut_setup, ut_teardown,
4734 test_snow3g_decryption_test_case_2),
4735 TEST_CASE_ST(ut_setup, ut_teardown,
4736 test_snow3g_decryption_test_case_3),
4737 TEST_CASE_ST(ut_setup, ut_teardown,
4738 test_snow3g_decryption_test_case_4),
4739 TEST_CASE_ST(ut_setup, ut_teardown,
4740 test_snow3g_decryption_test_case_5),
4741 TEST_CASE_ST(ut_setup, ut_teardown,
4742 test_snow3g_hash_generate_test_case_1),
4743 TEST_CASE_ST(ut_setup, ut_teardown,
4744 test_snow3g_hash_generate_test_case_2),
4745 TEST_CASE_ST(ut_setup, ut_teardown,
4746 test_snow3g_hash_generate_test_case_3),
4747 TEST_CASE_ST(ut_setup, ut_teardown,
4748 test_snow3g_hash_verify_test_case_1),
4749 TEST_CASE_ST(ut_setup, ut_teardown,
4750 test_snow3g_hash_verify_test_case_2),
4751 TEST_CASE_ST(ut_setup, ut_teardown,
4752 test_snow3g_hash_verify_test_case_3),
4753 TEST_CASE_ST(ut_setup, ut_teardown,
4754 test_snow3g_authenticated_encryption_test_case_1),
4755 TEST_CASE_ST(ut_setup, ut_teardown,
4756 test_snow3g_encrypted_authentication_test_case_1),
4758 TEST_CASES_END() /**< NULL terminate unit test array */
4762 static struct unit_test_suite cryptodev_null_testsuite = {
4763 .suite_name = "Crypto Device NULL Unit Test Suite",
4764 .setup = testsuite_setup,
4765 .teardown = testsuite_teardown,
4766 .unit_test_cases = {
4767 TEST_CASE_ST(ut_setup, ut_teardown,
4768 test_null_auth_only_operation),
4769 TEST_CASE_ST(ut_setup, ut_teardown,
4770 test_null_cipher_only_operation),
4771 TEST_CASE_ST(ut_setup, ut_teardown,
4772 test_null_cipher_auth_operation),
4773 TEST_CASE_ST(ut_setup, ut_teardown,
4774 test_null_auth_cipher_operation),
4775 TEST_CASE_ST(ut_setup, ut_teardown,
4776 test_null_invalid_operation),
4777 TEST_CASE_ST(ut_setup, ut_teardown,
4778 test_null_burst_operation),
4780 TEST_CASES_END() /**< NULL terminate unit test array */
4785 test_cryptodev_qat(void /*argv __rte_unused, int argc __rte_unused*/)
4787 gbl_cryptodev_type = RTE_CRYPTODEV_QAT_SYM_PMD;
4788 return unit_test_suite_runner(&cryptodev_qat_testsuite);
4790 static struct test_command cryptodev_qat_cmd = {
4791 .command = "cryptodev_qat_autotest",
4792 .callback = test_cryptodev_qat,
4796 test_cryptodev_aesni_mb(void /*argv __rte_unused, int argc __rte_unused*/)
4798 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_MB_PMD;
4800 return unit_test_suite_runner(&cryptodev_aesni_mb_testsuite);
4803 static struct test_command cryptodev_aesni_mb_cmd = {
4804 .command = "cryptodev_aesni_mb_autotest",
4805 .callback = test_cryptodev_aesni_mb,
4809 test_cryptodev_aesni_gcm(void)
4811 gbl_cryptodev_type = RTE_CRYPTODEV_AESNI_GCM_PMD;
4813 return unit_test_suite_runner(&cryptodev_aesni_gcm_testsuite);
4816 static struct test_command cryptodev_aesni_gcm_cmd = {
4817 .command = "cryptodev_aesni_gcm_autotest",
4818 .callback = test_cryptodev_aesni_gcm,
4822 test_cryptodev_null(void)
4824 gbl_cryptodev_type = RTE_CRYPTODEV_NULL_PMD;
4826 return unit_test_suite_runner(&cryptodev_null_testsuite);
4829 static struct test_command cryptodev_null_cmd = {
4830 .command = "cryptodev_null_autotest",
4831 .callback = test_cryptodev_null,
4835 test_cryptodev_sw_snow3g(void /*argv __rte_unused, int argc __rte_unused*/)
4837 gbl_cryptodev_type = RTE_CRYPTODEV_SNOW3G_PMD;
4839 return unit_test_suite_runner(&cryptodev_sw_snow3g_testsuite);
4842 static struct test_command cryptodev_sw_snow3g_cmd = {
4843 .command = "cryptodev_sw_snow3g_autotest",
4844 .callback = test_cryptodev_sw_snow3g,
4847 REGISTER_TEST_COMMAND(cryptodev_qat_cmd);
4848 REGISTER_TEST_COMMAND(cryptodev_aesni_mb_cmd);
4849 REGISTER_TEST_COMMAND(cryptodev_aesni_gcm_cmd);
4850 REGISTER_TEST_COMMAND(cryptodev_null_cmd);
4851 REGISTER_TEST_COMMAND(cryptodev_sw_snow3g_cmd);