1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium Networks
3 * Copyright (c) 2019 Intel Corporation
6 #include <rte_bus_vdev.h>
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
14 #include <rte_cryptodev.h>
15 #include <rte_cryptodev_pmd.h>
16 #include <rte_crypto.h>
18 #include "test_cryptodev.h"
19 #include "test_cryptodev_dh_test_vectors.h"
20 #include "test_cryptodev_dsa_test_vectors.h"
21 #include "test_cryptodev_mod_test_vectors.h"
22 #include "test_cryptodev_rsa_test_vectors.h"
23 #include "test_cryptodev_asym_util.h"
26 #define TEST_NUM_BUFS 10
27 #define TEST_NUM_SESSIONS 4
30 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
33 #ifndef TEST_DATA_SIZE
34 #define TEST_DATA_SIZE 4096
36 #define ASYM_TEST_MSG_LEN 256
37 #define TEST_VECTOR_SIZE 256
39 static int gbl_driver_id;
40 struct crypto_testsuite_params {
41 struct rte_mempool *op_mpool;
42 struct rte_mempool *session_mpool;
43 struct rte_cryptodev_config conf;
44 struct rte_cryptodev_qp_conf qp_conf;
45 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
46 uint8_t valid_dev_count;
49 struct crypto_unittest_params {
50 struct rte_cryptodev_asym_session *sess;
51 struct rte_crypto_op *op;
54 union test_case_structure {
55 struct modex_test_data modex;
56 struct modinv_test_data modinv;
59 struct test_cases_array {
61 const void *address[TEST_VECTOR_SIZE];
63 static struct test_cases_array test_vector = {0, { NULL } };
65 static uint32_t test_index;
67 static struct crypto_testsuite_params testsuite_params = { NULL };
70 test_cryptodev_asym_ver(union test_case_structure *data_tc,
71 struct rte_crypto_op *result_op)
73 int status = TEST_SUCCESS;
75 uint8_t *data_expected = NULL, *data_received = NULL;
78 switch (data_tc->modex.xform_type) {
79 case RTE_CRYPTO_ASYM_XFORM_MODEX:
80 data_expected = data_tc->modex.reminder.data;
81 data_received = result_op->asym->modex.result.data;
82 data_size = result_op->asym->modex.result.length;
84 case RTE_CRYPTO_ASYM_XFORM_MODINV:
85 data_expected = data_tc->modinv.inverse.data;
86 data_received = result_op->asym->modinv.result.data;
87 data_size = result_op->asym->modinv.result.length;
89 case RTE_CRYPTO_ASYM_XFORM_DH:
90 case RTE_CRYPTO_ASYM_XFORM_DSA:
91 case RTE_CRYPTO_ASYM_XFORM_RSA:
92 case RTE_CRYPTO_ASYM_XFORM_NONE:
93 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
97 ret = memcmp(data_expected, data_received, data_size);
105 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
106 union test_case_structure *data_tc,
109 struct rte_crypto_asym_op *asym_op = NULL;
110 struct rte_crypto_op *op = NULL;
111 struct rte_crypto_op *result_op = NULL;
112 struct rte_crypto_asym_xform xform_tc;
113 struct rte_cryptodev_asym_session *sess = NULL;
114 struct rte_cryptodev_asym_capability_idx cap_idx;
115 const struct rte_cryptodev_asymmetric_xform_capability *capability;
116 uint8_t dev_id = ts_params->valid_devs[0];
117 uint8_t input[TEST_DATA_SIZE] = {0};
118 uint8_t *result = NULL;
120 int status = TEST_SUCCESS;
122 /* Generate crypto op data structure */
123 op = rte_crypto_op_alloc(ts_params->op_mpool,
124 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
127 snprintf(test_msg, ASYM_TEST_MSG_LEN,
128 "line %u FAILED: %s",
129 __LINE__, "Failed to allocate asymmetric crypto "
131 status = TEST_FAILED;
136 xform_tc.next = NULL;
137 xform_tc.xform_type = data_tc->modex.xform_type;
139 cap_idx.type = xform_tc.xform_type;
140 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
142 switch (xform_tc.xform_type) {
143 case RTE_CRYPTO_ASYM_XFORM_MODEX:
144 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
145 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
146 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
147 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
148 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
149 memcpy(input, data_tc->modex.base.data,
150 data_tc->modex.base.len);
151 asym_op->modex.base.data = input;
152 asym_op->modex.base.length = data_tc->modex.base.len;
153 asym_op->modex.result.data = result;
154 asym_op->modex.result.length = data_tc->modex.result_len;
155 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
156 xform_tc.modex.modulus.length)) {
157 snprintf(test_msg, ASYM_TEST_MSG_LEN,
159 "FAILED: %s", __LINE__,
160 "Invalid MODULUS length specified");
161 status = TEST_FAILED;
165 case RTE_CRYPTO_ASYM_XFORM_MODINV:
166 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
167 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
168 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
169 memcpy(input, data_tc->modinv.base.data,
170 data_tc->modinv.base.len);
171 asym_op->modinv.base.data = input;
172 asym_op->modinv.base.length = data_tc->modinv.base.len;
173 asym_op->modinv.result.data = result;
174 asym_op->modinv.result.length = data_tc->modinv.result_len;
175 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
176 xform_tc.modinv.modulus.length)) {
177 snprintf(test_msg, ASYM_TEST_MSG_LEN,
179 "FAILED: %s", __LINE__,
180 "Invalid MODULUS length specified");
181 status = TEST_FAILED;
185 case RTE_CRYPTO_ASYM_XFORM_DH:
186 case RTE_CRYPTO_ASYM_XFORM_DSA:
187 case RTE_CRYPTO_ASYM_XFORM_RSA:
188 case RTE_CRYPTO_ASYM_XFORM_NONE:
189 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
191 snprintf(test_msg, ASYM_TEST_MSG_LEN,
193 "FAILED: %s", __LINE__,
194 "Invalid ASYM algorithm specified");
195 status = TEST_FAILED;
199 sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
201 snprintf(test_msg, ASYM_TEST_MSG_LEN,
203 "FAILED: %s", __LINE__,
204 "Session creation failed");
205 status = TEST_FAILED;
209 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
210 ts_params->session_mpool) < 0) {
211 snprintf(test_msg, ASYM_TEST_MSG_LEN,
212 "line %u FAILED: %s",
213 __LINE__, "unabled to config sym session");
214 status = TEST_FAILED;
218 rte_crypto_op_attach_asym_session(op, sess);
220 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
222 /* Process crypto operation */
223 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
224 snprintf(test_msg, ASYM_TEST_MSG_LEN,
225 "line %u FAILED: %s",
226 __LINE__, "Error sending packet for operation");
227 status = TEST_FAILED;
231 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
234 if (result_op == NULL) {
235 snprintf(test_msg, ASYM_TEST_MSG_LEN,
236 "line %u FAILED: %s",
237 __LINE__, "Failed to process asym crypto op");
238 status = TEST_FAILED;
242 if (test_cryptodev_asym_ver(data_tc, result_op) != TEST_SUCCESS) {
243 snprintf(test_msg, ASYM_TEST_MSG_LEN,
244 "line %u FAILED: %s",
245 __LINE__, "Verification failed ");
246 status = TEST_FAILED;
250 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
254 rte_cryptodev_asym_session_clear(dev_id, sess);
255 rte_cryptodev_asym_session_free(sess);
259 rte_crypto_op_free(op);
268 test_one_case(const void *test_case)
270 int status = TEST_SUCCESS;
271 char test_msg[ASYM_TEST_MSG_LEN + 1];
273 /* Map the case to union */
274 union test_case_structure tc;
275 memcpy(&tc, test_case, sizeof(tc));
277 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg);
279 printf(" %u) TestCase %s %s\n", test_index++,
280 tc.modex.description, test_msg);
286 load_test_vectors(void)
288 uint32_t i = 0, v_size = 0;
289 /* Load MODEX vector*/
290 v_size = ARRAY_SIZE(modex_test_case);
291 for (i = 0; i < v_size; i++) {
292 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
293 RTE_LOG(DEBUG, USER1,
294 "TEST_VECTOR_SIZE too small\n");
297 test_vector.address[test_vector.size] = &modex_test_case[i];
300 /* Load MODINV vector*/
301 v_size = ARRAY_SIZE(modinv_test_case);
302 for (i = 0; i < v_size; i++) {
303 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
304 RTE_LOG(DEBUG, USER1,
305 "TEST_VECTOR_SIZE too small\n");
308 test_vector.address[test_vector.size] = &modinv_test_case[i];
315 test_one_by_one(void)
317 int status = TEST_SUCCESS;
320 /* Go through all test cases */
322 for (i = 0; i < test_vector.size; i++) {
323 if (test_one_case(test_vector.address[i]) != TEST_SUCCESS)
324 status = TEST_FAILED;
327 TEST_ASSERT_EQUAL(status, 0, "Test failed");
332 test_rsa_sign_verify(void)
334 struct crypto_testsuite_params *ts_params = &testsuite_params;
335 struct rte_mempool *op_mpool = ts_params->op_mpool;
336 struct rte_mempool *sess_mpool = ts_params->session_mpool;
337 uint8_t dev_id = ts_params->valid_devs[0];
338 struct rte_crypto_asym_op *asym_op = NULL;
339 struct rte_crypto_op *op = NULL, *result_op = NULL;
340 struct rte_cryptodev_asym_session *sess = NULL;
341 int status = TEST_SUCCESS;
342 uint8_t output_buf[TEST_DATA_SIZE] = {0};
343 uint8_t input_buf[TEST_DATA_SIZE] = {0};
345 sess = rte_cryptodev_asym_session_create(sess_mpool);
348 RTE_LOG(ERR, USER1, "line %u "
349 "FAILED: %s", __LINE__,
350 "Session creation failed");
351 status = TEST_FAILED;
355 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
358 "line %u FAILED: %s",
359 __LINE__, "unabled to config sym session");
360 status = TEST_FAILED;
364 /* set up crypto op data structure */
365 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
368 "line %u FAILED: %s",
370 "Failed to allocate asymmetric crypto "
372 status = TEST_FAILED;
377 /* Compute sign on the test vector */
378 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
380 memcpy(input_buf, &rsaplaintext.data,
382 asym_op->rsa.message.data = input_buf;
383 asym_op->rsa.message.length = rsaplaintext.len;
384 asym_op->rsa.sign.data = output_buf;
385 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
387 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
388 asym_op->rsa.message.length);
390 /* attach asymmetric crypto session to crypto operations */
391 rte_crypto_op_attach_asym_session(op, sess);
393 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
395 /* Process crypto operation */
396 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
398 "line %u FAILED: %s",
399 __LINE__, "Error sending packet for operation");
400 status = TEST_FAILED;
404 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
407 if (result_op == NULL) {
409 "line %u FAILED: %s",
410 __LINE__, "Failed to process asym crypto op");
411 status = TEST_FAILED;
414 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
415 asym_op->rsa.sign.length);
416 asym_op = result_op->asym;
419 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
420 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
422 /* Process crypto operation */
423 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
425 "line %u FAILED: %s",
426 __LINE__, "Error sending packet for operation");
427 status = TEST_FAILED;
431 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
434 if (result_op == NULL) {
436 "line %u FAILED: %s",
437 __LINE__, "Failed to process asym crypto op");
438 status = TEST_FAILED;
441 status = TEST_SUCCESS;
442 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
444 "line %u FAILED: %s",
445 __LINE__, "Failed to process asym crypto op");
446 status = TEST_FAILED;
453 rte_cryptodev_asym_session_clear(dev_id, sess);
454 rte_cryptodev_asym_session_free(sess);
458 rte_crypto_op_free(op);
460 TEST_ASSERT_EQUAL(status, 0, "Test failed");
466 test_rsa_enc_dec(void)
468 struct crypto_testsuite_params *ts_params = &testsuite_params;
469 struct rte_mempool *op_mpool = ts_params->op_mpool;
470 struct rte_mempool *sess_mpool = ts_params->session_mpool;
471 uint8_t dev_id = ts_params->valid_devs[0];
472 struct rte_crypto_asym_op *asym_op = NULL;
473 struct rte_crypto_op *op = NULL, *result_op = NULL;
474 struct rte_cryptodev_asym_session *sess = NULL;
475 int status = TEST_SUCCESS;
476 uint8_t input_buf[TEST_DATA_SIZE] = {0};
478 sess = rte_cryptodev_asym_session_create(sess_mpool);
481 RTE_LOG(ERR, USER1, "line %u "
482 "FAILED: %s", __LINE__,
483 "Session creation failed");
484 status = TEST_FAILED;
488 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
491 "line %u FAILED: %s",
492 __LINE__, "unabled to config sym session");
493 status = TEST_FAILED;
497 /* set up crypto op data structure */
498 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
501 "line %u FAILED: %s",
503 "Failed to allocate asymmetric crypto "
505 status = TEST_FAILED;
510 /*Compute encryption on the test vector */
511 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
513 memcpy(input_buf, rsaplaintext.data,
515 asym_op->rsa.message.data = input_buf;
516 asym_op->rsa.message.length = rsaplaintext.len;
517 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
519 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
520 asym_op->rsa.message.length);
522 /* attach asymmetric crypto session to crypto operations */
523 rte_crypto_op_attach_asym_session(op, sess);
525 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
527 /* Process crypto operation */
528 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
530 "line %u FAILED: %s",
531 __LINE__, "Error sending packet for operation");
532 status = TEST_FAILED;
536 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
539 if (result_op == NULL) {
541 "line %u FAILED: %s",
542 __LINE__, "Failed to process asym crypto op");
543 status = TEST_FAILED;
546 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
547 asym_op->rsa.message.length);
548 /* Use the resulted output as decryption Input vector*/
549 asym_op = result_op->asym;
550 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
551 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
553 /* Process crypto operation */
554 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
556 "line %u FAILED: %s",
557 __LINE__, "Error sending packet for operation");
558 status = TEST_FAILED;
562 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
565 if (result_op == NULL) {
567 "line %u FAILED: %s",
568 __LINE__, "Failed to process asym crypto op");
569 status = TEST_FAILED;
572 status = TEST_SUCCESS;
574 ret = rsa_verify(&rsaplaintext, result_op);
576 status = TEST_FAILED;
581 rte_cryptodev_asym_session_clear(dev_id, sess);
582 rte_cryptodev_asym_session_free(sess);
586 rte_crypto_op_free(op);
588 TEST_ASSERT_EQUAL(status, 0, "Test failed");
594 testsuite_setup(void)
596 struct crypto_testsuite_params *ts_params = &testsuite_params;
597 struct rte_cryptodev_info info;
598 uint32_t i = 0, nb_devs, dev_id;
602 memset(ts_params, 0, sizeof(*ts_params));
604 test_vector.size = 0;
607 ts_params->op_mpool = rte_crypto_op_pool_create(
608 "CRYPTO_ASYM_OP_POOL",
609 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
613 if (ts_params->op_mpool == NULL) {
614 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
618 /* Create an OPENSSL device if required */
619 if (gbl_driver_id == rte_cryptodev_driver_id_get(
620 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
621 nb_devs = rte_cryptodev_device_count_by_driver(
622 rte_cryptodev_driver_id_get(
623 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
626 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
629 TEST_ASSERT(ret == 0, "Failed to create "
630 "instance of pmd : %s",
631 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
635 nb_devs = rte_cryptodev_count();
637 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
641 /* Create list of valid crypto devs */
642 for (i = 0; i < nb_devs; i++) {
643 rte_cryptodev_info_get(i, &info);
644 if (info.driver_id == gbl_driver_id)
645 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
648 if (ts_params->valid_dev_count < 1)
651 /* Set up all the qps on the first of the valid devices found */
653 dev_id = ts_params->valid_devs[0];
655 rte_cryptodev_info_get(dev_id, &info);
657 /* check if device support asymmetric, skip if not */
658 if (!(info.feature_flags &
659 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
660 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
665 /* configure device with num qp */
666 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
667 ts_params->conf.socket_id = SOCKET_ID_ANY;
668 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
670 "Failed to configure cryptodev %u with %u qps",
671 dev_id, ts_params->conf.nb_queue_pairs);
674 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
675 ts_params->qp_conf.mp_session = ts_params->session_mpool;
676 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
677 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
678 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
679 dev_id, qp_id, &ts_params->qp_conf,
680 rte_cryptodev_socket_id(dev_id)),
681 "Failed to setup queue pair %u on cryptodev %u ASYM",
685 /* setup asym session pool */
686 unsigned int session_size =
687 rte_cryptodev_asym_get_private_session_size(dev_id);
689 * Create mempool with TEST_NUM_SESSIONS * 2,
690 * to include the session headers
692 ts_params->session_mpool = rte_mempool_create(
694 TEST_NUM_SESSIONS * 2,
696 0, 0, NULL, NULL, NULL,
700 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
701 "session mempool allocation failed");
707 testsuite_teardown(void)
709 struct crypto_testsuite_params *ts_params = &testsuite_params;
711 if (ts_params->op_mpool != NULL) {
712 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
713 rte_mempool_avail_count(ts_params->op_mpool));
716 /* Free session mempools */
717 if (ts_params->session_mpool != NULL) {
718 rte_mempool_free(ts_params->session_mpool);
719 ts_params->session_mpool = NULL;
726 struct crypto_testsuite_params *ts_params = &testsuite_params;
730 /* Reconfigure device to default parameters */
731 ts_params->conf.socket_id = SOCKET_ID_ANY;
733 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
735 "Failed to configure cryptodev %u",
736 ts_params->valid_devs[0]);
738 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
739 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
740 ts_params->valid_devs[0], qp_id,
742 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
743 "Failed to setup queue pair %u on cryptodev %u",
744 qp_id, ts_params->valid_devs[0]);
747 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
749 /* Start the device */
750 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
751 "Failed to start cryptodev %u",
752 ts_params->valid_devs[0]);
760 struct crypto_testsuite_params *ts_params = &testsuite_params;
761 struct rte_cryptodev_stats stats;
763 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
765 /* Stop the device */
766 rte_cryptodev_stop(ts_params->valid_devs[0]);
769 static inline void print_asym_capa(
770 const struct rte_cryptodev_asymmetric_xform_capability *capa)
774 printf("\nxform type: %s\n===================\n",
775 rte_crypto_asym_xform_strings[capa->xform_type]);
776 printf("operation supported -");
778 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
779 /* check supported operations */
780 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
782 rte_crypto_asym_op_strings[i]);
784 switch (capa->xform_type) {
785 case RTE_CRYPTO_ASYM_XFORM_RSA:
786 case RTE_CRYPTO_ASYM_XFORM_MODINV:
787 case RTE_CRYPTO_ASYM_XFORM_MODEX:
788 case RTE_CRYPTO_ASYM_XFORM_DH:
789 case RTE_CRYPTO_ASYM_XFORM_DSA:
790 printf(" modlen: min %d max %d increment %d\n",
793 capa->modlen.increment);
801 test_capability(void)
803 struct crypto_testsuite_params *ts_params = &testsuite_params;
804 uint8_t dev_id = ts_params->valid_devs[0];
805 struct rte_cryptodev_info dev_info;
806 const struct rte_cryptodev_capabilities *dev_capa;
808 struct rte_cryptodev_asym_capability_idx idx;
809 const struct rte_cryptodev_asymmetric_xform_capability *capa;
811 rte_cryptodev_info_get(dev_id, &dev_info);
812 if (!(dev_info.feature_flags &
813 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
815 "Device doesn't support asymmetric. Test Skipped\n");
819 /* print xform capability */
821 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
823 dev_capa = &(dev_info.capabilities[i]);
824 if (dev_info.capabilities[i].op ==
825 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
826 idx.type = dev_capa->asym.xform_capa.xform_type;
828 capa = rte_cryptodev_asym_capability_get(dev_id,
830 rte_cryptodev_asym_capability_idx *) &idx);
831 print_asym_capa(capa);
838 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
840 struct crypto_testsuite_params *ts_params = &testsuite_params;
841 struct rte_mempool *op_mpool = ts_params->op_mpool;
842 struct rte_mempool *sess_mpool = ts_params->session_mpool;
843 uint8_t dev_id = ts_params->valid_devs[0];
844 struct rte_crypto_asym_op *asym_op = NULL;
845 struct rte_crypto_op *op = NULL, *result_op = NULL;
846 struct rte_cryptodev_asym_session *sess = NULL;
847 int status = TEST_SUCCESS;
848 uint8_t output[TEST_DH_MOD_LEN];
849 struct rte_crypto_asym_xform xform = *xfrm;
850 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
852 sess = rte_cryptodev_asym_session_create(sess_mpool);
855 "line %u FAILED: %s", __LINE__,
856 "Session creation failed");
857 status = TEST_FAILED;
860 /* set up crypto op data structure */
861 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
864 "line %u FAILED: %s",
865 __LINE__, "Failed to allocate asymmetric crypto "
867 status = TEST_FAILED;
872 /* Setup a xform and op to generate private key only */
873 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
875 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
876 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
877 asym_op->dh.pub_key.data = (uint8_t *)peer;
878 asym_op->dh.pub_key.length = sizeof(peer);
879 asym_op->dh.shared_secret.data = output;
880 asym_op->dh.shared_secret.length = sizeof(output);
882 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
885 "line %u FAILED: %s",
886 __LINE__, "unabled to config sym session");
887 status = TEST_FAILED;
891 /* attach asymmetric crypto session to crypto operations */
892 rte_crypto_op_attach_asym_session(op, sess);
894 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
896 /* Process crypto operation */
897 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
899 "line %u FAILED: %s",
900 __LINE__, "Error sending packet for operation");
901 status = TEST_FAILED;
905 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
908 if (result_op == NULL) {
910 "line %u FAILED: %s",
911 __LINE__, "Failed to process asym crypto op");
912 status = TEST_FAILED;
916 debug_hexdump(stdout, "shared secret:",
917 asym_op->dh.shared_secret.data,
918 asym_op->dh.shared_secret.length);
922 rte_cryptodev_asym_session_clear(dev_id, sess);
923 rte_cryptodev_asym_session_free(sess);
926 rte_crypto_op_free(op);
931 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
933 struct crypto_testsuite_params *ts_params = &testsuite_params;
934 struct rte_mempool *op_mpool = ts_params->op_mpool;
935 struct rte_mempool *sess_mpool = ts_params->session_mpool;
936 uint8_t dev_id = ts_params->valid_devs[0];
937 struct rte_crypto_asym_op *asym_op = NULL;
938 struct rte_crypto_op *op = NULL, *result_op = NULL;
939 struct rte_cryptodev_asym_session *sess = NULL;
940 int status = TEST_SUCCESS;
941 uint8_t output[TEST_DH_MOD_LEN];
942 struct rte_crypto_asym_xform xform = *xfrm;
944 sess = rte_cryptodev_asym_session_create(sess_mpool);
947 "line %u FAILED: %s", __LINE__,
948 "Session creation failed");
949 status = TEST_FAILED;
952 /* set up crypto op data structure */
953 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
956 "line %u FAILED: %s",
957 __LINE__, "Failed to allocate asymmetric crypto "
959 status = TEST_FAILED;
964 /* Setup a xform and op to generate private key only */
965 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
967 asym_op->dh.priv_key.data = output;
968 asym_op->dh.priv_key.length = sizeof(output);
970 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
973 "line %u FAILED: %s",
974 __LINE__, "unabled to config sym session");
975 status = TEST_FAILED;
979 /* attach asymmetric crypto session to crypto operations */
980 rte_crypto_op_attach_asym_session(op, sess);
982 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
984 /* Process crypto operation */
985 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
987 "line %u FAILED: %s",
988 __LINE__, "Error sending packet for operation");
989 status = TEST_FAILED;
993 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
996 if (result_op == NULL) {
998 "line %u FAILED: %s",
999 __LINE__, "Failed to process asym crypto op");
1000 status = TEST_FAILED;
1004 debug_hexdump(stdout, "private key:",
1005 asym_op->dh.priv_key.data,
1006 asym_op->dh.priv_key.length);
1011 rte_cryptodev_asym_session_clear(dev_id, sess);
1012 rte_cryptodev_asym_session_free(sess);
1015 rte_crypto_op_free(op);
1022 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1024 struct crypto_testsuite_params *ts_params = &testsuite_params;
1025 struct rte_mempool *op_mpool = ts_params->op_mpool;
1026 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1027 uint8_t dev_id = ts_params->valid_devs[0];
1028 struct rte_crypto_asym_op *asym_op = NULL;
1029 struct rte_crypto_op *op = NULL, *result_op = NULL;
1030 struct rte_cryptodev_asym_session *sess = NULL;
1031 int status = TEST_SUCCESS;
1032 uint8_t output[TEST_DH_MOD_LEN];
1033 struct rte_crypto_asym_xform xform = *xfrm;
1035 sess = rte_cryptodev_asym_session_create(sess_mpool);
1038 "line %u FAILED: %s", __LINE__,
1039 "Session creation failed");
1040 status = TEST_FAILED;
1043 /* set up crypto op data structure */
1044 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1047 "line %u FAILED: %s",
1048 __LINE__, "Failed to allocate asymmetric crypto "
1049 "operation struct");
1050 status = TEST_FAILED;
1054 /* Setup a xform chain to generate public key
1055 * using test private key
1058 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1061 asym_op->dh.pub_key.data = output;
1062 asym_op->dh.pub_key.length = sizeof(output);
1063 /* load pre-defined private key */
1064 asym_op->dh.priv_key.data = rte_malloc(NULL,
1065 dh_test_params.priv_key.length,
1067 asym_op->dh.priv_key = dh_test_params.priv_key;
1069 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1072 "line %u FAILED: %s",
1073 __LINE__, "unabled to config sym session");
1074 status = TEST_FAILED;
1078 /* attach asymmetric crypto session to crypto operations */
1079 rte_crypto_op_attach_asym_session(op, sess);
1081 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1083 /* Process crypto operation */
1084 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1086 "line %u FAILED: %s",
1087 __LINE__, "Error sending packet for operation");
1088 status = TEST_FAILED;
1092 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1095 if (result_op == NULL) {
1097 "line %u FAILED: %s",
1098 __LINE__, "Failed to process asym crypto op");
1099 status = TEST_FAILED;
1103 debug_hexdump(stdout, "pub key:",
1104 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1106 debug_hexdump(stdout, "priv key:",
1107 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1111 rte_cryptodev_asym_session_clear(dev_id, sess);
1112 rte_cryptodev_asym_session_free(sess);
1115 rte_crypto_op_free(op);
1121 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1123 struct crypto_testsuite_params *ts_params = &testsuite_params;
1124 struct rte_mempool *op_mpool = ts_params->op_mpool;
1125 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1126 uint8_t dev_id = ts_params->valid_devs[0];
1127 struct rte_crypto_asym_op *asym_op = NULL;
1128 struct rte_crypto_op *op = NULL, *result_op = NULL;
1129 struct rte_cryptodev_asym_session *sess = NULL;
1130 int status = TEST_SUCCESS;
1131 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1132 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1133 struct rte_crypto_asym_xform pub_key_xform;
1134 struct rte_crypto_asym_xform xform = *xfrm;
1136 sess = rte_cryptodev_asym_session_create(sess_mpool);
1139 "line %u FAILED: %s", __LINE__,
1140 "Session creation failed");
1141 status = TEST_FAILED;
1145 /* set up crypto op data structure */
1146 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1149 "line %u FAILED: %s",
1150 __LINE__, "Failed to allocate asymmetric crypto "
1151 "operation struct");
1152 status = TEST_FAILED;
1156 /* Setup a xform chain to generate
1157 * private key first followed by
1159 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1160 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1161 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1162 xform.next = &pub_key_xform;
1164 asym_op->dh.pub_key.data = out_pub_key;
1165 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1166 asym_op->dh.priv_key.data = out_prv_key;
1167 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1168 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1171 "line %u FAILED: %s",
1172 __LINE__, "unabled to config sym session");
1173 status = TEST_FAILED;
1177 /* attach asymmetric crypto session to crypto operations */
1178 rte_crypto_op_attach_asym_session(op, sess);
1180 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1182 /* Process crypto operation */
1183 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1185 "line %u FAILED: %s",
1186 __LINE__, "Error sending packet for operation");
1187 status = TEST_FAILED;
1191 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1194 if (result_op == NULL) {
1196 "line %u FAILED: %s",
1197 __LINE__, "Failed to process asym crypto op");
1198 status = TEST_FAILED;
1201 debug_hexdump(stdout, "priv key:",
1202 out_prv_key, asym_op->dh.priv_key.length);
1203 debug_hexdump(stdout, "pub key:",
1204 out_pub_key, asym_op->dh.pub_key.length);
1208 rte_cryptodev_asym_session_clear(dev_id, sess);
1209 rte_cryptodev_asym_session_free(sess);
1212 rte_crypto_op_free(op);
1220 struct crypto_testsuite_params *ts_params = &testsuite_params;
1221 struct rte_mempool *op_mpool = ts_params->op_mpool;
1222 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1223 uint8_t dev_id = ts_params->valid_devs[0];
1224 struct rte_crypto_asym_op *asym_op = NULL;
1225 struct rte_crypto_op *op = NULL, *result_op = NULL;
1226 struct rte_cryptodev_asym_session *sess = NULL;
1227 int status = TEST_SUCCESS;
1228 struct rte_cryptodev_asym_capability_idx cap_idx;
1229 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1230 uint8_t input[TEST_DATA_SIZE] = {0};
1232 uint8_t result[sizeof(mod_p)] = { 0 };
1234 if (rte_cryptodev_asym_get_xform_enum(
1235 &modinv_xform.xform_type, "modinv") < 0) {
1237 "Invalid ASYNC algorithm specified\n");
1241 cap_idx.type = modinv_xform.xform_type;
1242 capability = rte_cryptodev_asym_capability_get(dev_id,
1245 if (rte_cryptodev_asym_xform_capability_check_modlen(
1247 modinv_xform.modinv.modulus.length)) {
1249 "Invalid MODULOUS length specified\n");
1253 sess = rte_cryptodev_asym_session_create(sess_mpool);
1255 RTE_LOG(ERR, USER1, "line %u "
1256 "FAILED: %s", __LINE__,
1257 "Session creation failed");
1258 status = TEST_FAILED;
1262 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1265 "line %u FAILED: %s",
1266 __LINE__, "unabled to config sym session");
1267 status = TEST_FAILED;
1271 /* generate crypto op data structure */
1272 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1275 "line %u FAILED: %s",
1276 __LINE__, "Failed to allocate asymmetric crypto "
1277 "operation struct");
1278 status = TEST_FAILED;
1283 memcpy(input, base, sizeof(base));
1284 asym_op->modinv.base.data = input;
1285 asym_op->modinv.base.length = sizeof(base);
1286 asym_op->modinv.result.data = result;
1287 asym_op->modinv.result.length = sizeof(result);
1289 /* attach asymmetric crypto session to crypto operations */
1290 rte_crypto_op_attach_asym_session(op, sess);
1292 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1294 /* Process crypto operation */
1295 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1297 "line %u FAILED: %s",
1298 __LINE__, "Error sending packet for operation");
1299 status = TEST_FAILED;
1303 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1306 if (result_op == NULL) {
1308 "line %u FAILED: %s",
1309 __LINE__, "Failed to process asym crypto op");
1310 status = TEST_FAILED;
1314 ret = verify_modinv(mod_inv, result_op);
1317 "operation verification failed\n");
1318 status = TEST_FAILED;
1323 rte_cryptodev_asym_session_clear(dev_id, sess);
1324 rte_cryptodev_asym_session_free(sess);
1328 rte_crypto_op_free(op);
1330 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1338 struct crypto_testsuite_params *ts_params = &testsuite_params;
1339 struct rte_mempool *op_mpool = ts_params->op_mpool;
1340 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1341 uint8_t dev_id = ts_params->valid_devs[0];
1342 struct rte_crypto_asym_op *asym_op = NULL;
1343 struct rte_crypto_op *op = NULL, *result_op = NULL;
1344 struct rte_cryptodev_asym_session *sess = NULL;
1345 int status = TEST_SUCCESS;
1346 struct rte_cryptodev_asym_capability_idx cap_idx;
1347 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1348 uint8_t input[TEST_DATA_SIZE] = {0};
1350 uint8_t result[sizeof(mod_p)] = { 0 };
1352 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1356 "Invalid ASYNC algorithm specified\n");
1360 /* check for modlen capability */
1361 cap_idx.type = modex_xform.xform_type;
1362 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1364 if (rte_cryptodev_asym_xform_capability_check_modlen(
1365 capability, modex_xform.modex.modulus.length)) {
1367 "Invalid MODULOUS length specified\n");
1371 /* generate crypto op data structure */
1372 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1375 "line %u FAILED: %s",
1376 __LINE__, "Failed to allocate asymmetric crypto "
1377 "operation struct");
1378 status = TEST_FAILED;
1382 sess = rte_cryptodev_asym_session_create(sess_mpool);
1386 "FAILED: %s", __LINE__,
1387 "Session creation failed");
1388 status = TEST_FAILED;
1392 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1395 "line %u FAILED: %s",
1396 __LINE__, "unabled to config sym session");
1397 status = TEST_FAILED;
1402 memcpy(input, base, sizeof(base));
1403 asym_op->modex.base.data = input;
1404 asym_op->modex.base.length = sizeof(base);
1405 asym_op->modex.result.data = result;
1406 asym_op->modex.result.length = sizeof(result);
1407 /* attach asymmetric crypto session to crypto operations */
1408 rte_crypto_op_attach_asym_session(op, sess);
1410 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1411 /* Process crypto operation */
1412 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1414 "line %u FAILED: %s",
1415 __LINE__, "Error sending packet for operation");
1416 status = TEST_FAILED;
1420 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1423 if (result_op == NULL) {
1425 "line %u FAILED: %s",
1426 __LINE__, "Failed to process asym crypto op");
1427 status = TEST_FAILED;
1431 ret = verify_modexp(mod_exp, result_op);
1434 "operation verification failed\n");
1435 status = TEST_FAILED;
1440 rte_cryptodev_asym_session_clear(dev_id, sess);
1441 rte_cryptodev_asym_session_free(sess);
1445 rte_crypto_op_free(op);
1447 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1453 test_dh_keygenration(void)
1457 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1458 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1459 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1460 dh_test_params.priv_key.length);
1462 RTE_LOG(INFO, USER1,
1463 "Test Public and Private key pair generation\n");
1465 status = test_dh_gen_kp(&dh_xform);
1466 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1468 RTE_LOG(INFO, USER1,
1469 "Test Public Key Generation using pre-defined priv key\n");
1471 status = test_dh_gen_pub_key(&dh_xform);
1472 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1474 RTE_LOG(INFO, USER1,
1475 "Test Private Key Generation only\n");
1477 status = test_dh_gen_priv_key(&dh_xform);
1478 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1480 RTE_LOG(INFO, USER1,
1481 "Test shared secret compute\n");
1483 status = test_dh_gen_shared_sec(&dh_xform);
1484 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1492 struct crypto_testsuite_params *ts_params = &testsuite_params;
1493 struct rte_mempool *op_mpool = ts_params->op_mpool;
1494 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1495 uint8_t dev_id = ts_params->valid_devs[0];
1496 struct rte_crypto_asym_op *asym_op = NULL;
1497 struct rte_crypto_op *op = NULL, *result_op = NULL;
1498 struct rte_cryptodev_asym_session *sess = NULL;
1499 int status = TEST_SUCCESS;
1500 uint8_t r[TEST_DH_MOD_LEN];
1501 uint8_t s[TEST_DH_MOD_LEN];
1502 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1504 sess = rte_cryptodev_asym_session_create(sess_mpool);
1507 "line %u FAILED: %s", __LINE__,
1508 "Session creation failed");
1509 status = TEST_FAILED;
1512 /* set up crypto op data structure */
1513 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1516 "line %u FAILED: %s",
1517 __LINE__, "Failed to allocate asymmetric crypto "
1518 "operation struct");
1519 status = TEST_FAILED;
1524 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1525 dsa_xform.dsa.p.length);
1526 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1527 dsa_xform.dsa.q.length);
1528 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1529 dsa_xform.dsa.g.length);
1530 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1531 dsa_xform.dsa.x.length);
1533 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1536 "line %u FAILED: %s",
1537 __LINE__, "unabled to config sym session");
1538 status = TEST_FAILED;
1542 /* attach asymmetric crypto session to crypto operations */
1543 rte_crypto_op_attach_asym_session(op, sess);
1544 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1545 asym_op->dsa.message.data = dgst;
1546 asym_op->dsa.message.length = sizeof(dgst);
1547 asym_op->dsa.r.length = sizeof(r);
1548 asym_op->dsa.r.data = r;
1549 asym_op->dsa.s.length = sizeof(s);
1550 asym_op->dsa.s.data = s;
1552 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1554 /* Process crypto operation */
1555 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1557 "line %u FAILED: %s",
1558 __LINE__, "Error sending packet for operation");
1559 status = TEST_FAILED;
1563 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1566 if (result_op == NULL) {
1568 "line %u FAILED: %s",
1569 __LINE__, "Failed to process asym crypto op");
1570 status = TEST_FAILED;
1574 asym_op = result_op->asym;
1576 debug_hexdump(stdout, "r:",
1577 asym_op->dsa.r.data, asym_op->dsa.r.length);
1578 debug_hexdump(stdout, "s:",
1579 asym_op->dsa.s.data, asym_op->dsa.s.length);
1581 /* Test PMD DSA sign verification using signer public key */
1582 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1584 /* copy signer public key */
1585 asym_op->dsa.y.data = dsa_test_params.y.data;
1586 asym_op->dsa.y.length = dsa_test_params.y.length;
1588 /* Process crypto operation */
1589 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1591 "line %u FAILED: %s",
1592 __LINE__, "Error sending packet for operation");
1593 status = TEST_FAILED;
1597 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1600 if (result_op == NULL) {
1602 "line %u FAILED: %s",
1603 __LINE__, "Failed to process asym crypto op");
1604 status = TEST_FAILED;
1608 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1610 "line %u FAILED: %s",
1611 __LINE__, "Failed to process asym crypto op");
1612 status = TEST_FAILED;
1616 rte_cryptodev_asym_session_clear(dev_id, sess);
1617 rte_cryptodev_asym_session_free(sess);
1620 rte_crypto_op_free(op);
1628 status = test_dsa_sign();
1629 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1634 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1635 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1636 .setup = testsuite_setup,
1637 .teardown = testsuite_teardown,
1638 .unit_test_cases = {
1639 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1640 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1641 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1642 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1643 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1644 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1645 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1646 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1647 TEST_CASES_END() /**< NULL terminate unit test array */
1651 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1652 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1653 .setup = testsuite_setup,
1654 .teardown = testsuite_teardown,
1655 .unit_test_cases = {
1656 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1657 TEST_CASES_END() /**< NULL terminate unit test array */
1662 test_cryptodev_openssl_asym(void)
1664 gbl_driver_id = rte_cryptodev_driver_id_get(
1665 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1667 if (gbl_driver_id == -1) {
1668 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1669 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1670 "in config file to run this testsuite.\n");
1674 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1678 test_cryptodev_qat_asym(void)
1680 gbl_driver_id = rte_cryptodev_driver_id_get(
1681 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1683 if (gbl_driver_id == -1) {
1684 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1685 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1686 "in config file to run this testsuite.\n");
1690 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1693 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1694 test_cryptodev_openssl_asym);
1696 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);