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_cryptodev_info dev_info;
339 struct rte_crypto_asym_op *asym_op = NULL;
340 struct rte_crypto_op *op = NULL, *result_op = NULL;
341 struct rte_cryptodev_asym_session *sess = NULL;
342 int status = TEST_SUCCESS;
343 uint8_t output_buf[TEST_DATA_SIZE] = {0};
344 uint8_t input_buf[TEST_DATA_SIZE] = {0};
346 /* test case supports op with exponent key only,
347 * Check in PMD feature flag for RSA exponent key type support.
349 rte_cryptodev_info_get(dev_id, &dev_info);
350 if (!(dev_info.feature_flags &
351 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
353 "Device doesn't support sign op with "
354 "exponent key type. Test Skipped\n");
358 sess = rte_cryptodev_asym_session_create(sess_mpool);
361 RTE_LOG(ERR, USER1, "line %u "
362 "FAILED: %s", __LINE__,
363 "Session creation failed");
364 status = TEST_FAILED;
368 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
371 "line %u FAILED: %s",
372 __LINE__, "unabled to config sym session");
373 status = TEST_FAILED;
377 /* set up crypto op data structure */
378 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
381 "line %u FAILED: %s",
383 "Failed to allocate asymmetric crypto "
385 status = TEST_FAILED;
390 /* Compute sign on the test vector */
391 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
393 memcpy(input_buf, &rsaplaintext.data,
395 asym_op->rsa.message.data = input_buf;
396 asym_op->rsa.message.length = rsaplaintext.len;
397 asym_op->rsa.sign.data = output_buf;
398 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
400 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
401 asym_op->rsa.message.length);
403 /* attach asymmetric crypto session to crypto operations */
404 rte_crypto_op_attach_asym_session(op, sess);
406 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
408 /* Process crypto operation */
409 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
411 "line %u FAILED: %s",
412 __LINE__, "Error sending packet for operation");
413 status = TEST_FAILED;
417 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
420 if (result_op == NULL) {
422 "line %u FAILED: %s",
423 __LINE__, "Failed to process asym crypto op");
424 status = TEST_FAILED;
427 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
428 asym_op->rsa.sign.length);
429 asym_op = result_op->asym;
432 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
433 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
435 /* Process crypto operation */
436 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
438 "line %u FAILED: %s",
439 __LINE__, "Error sending packet for operation");
440 status = TEST_FAILED;
444 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
447 if (result_op == NULL) {
449 "line %u FAILED: %s",
450 __LINE__, "Failed to process asym crypto op");
451 status = TEST_FAILED;
454 status = TEST_SUCCESS;
455 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
457 "line %u FAILED: %s",
458 __LINE__, "Failed to process asym crypto op");
459 status = TEST_FAILED;
466 rte_cryptodev_asym_session_clear(dev_id, sess);
467 rte_cryptodev_asym_session_free(sess);
471 rte_crypto_op_free(op);
473 TEST_ASSERT_EQUAL(status, 0, "Test failed");
479 test_rsa_enc_dec(void)
481 struct crypto_testsuite_params *ts_params = &testsuite_params;
482 struct rte_mempool *op_mpool = ts_params->op_mpool;
483 struct rte_mempool *sess_mpool = ts_params->session_mpool;
484 uint8_t dev_id = ts_params->valid_devs[0];
485 struct rte_cryptodev_info dev_info;
486 struct rte_crypto_asym_op *asym_op = NULL;
487 struct rte_crypto_op *op = NULL, *result_op = NULL;
488 struct rte_cryptodev_asym_session *sess = NULL;
489 int status = TEST_SUCCESS;
490 uint8_t input_buf[TEST_DATA_SIZE] = {0};
492 /* test case supports op with exponent key only,
493 * Check in PMD feature flag for RSA exponent key type support.
495 rte_cryptodev_info_get(dev_id, &dev_info);
496 if (!(dev_info.feature_flags &
497 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
499 "Device doesn't support sign op with "
500 "exponent key type. Test Skipped\n");
504 sess = rte_cryptodev_asym_session_create(sess_mpool);
507 RTE_LOG(ERR, USER1, "line %u "
508 "FAILED: %s", __LINE__,
509 "Session creation failed");
510 status = TEST_FAILED;
514 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
517 "line %u FAILED: %s",
518 __LINE__, "unabled to config sym session");
519 status = TEST_FAILED;
523 /* set up crypto op data structure */
524 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
527 "line %u FAILED: %s",
529 "Failed to allocate asymmetric crypto "
531 status = TEST_FAILED;
536 /*Compute encryption on the test vector */
537 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
539 memcpy(input_buf, rsaplaintext.data,
541 asym_op->rsa.message.data = input_buf;
542 asym_op->rsa.message.length = rsaplaintext.len;
543 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
545 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
546 asym_op->rsa.message.length);
548 /* attach asymmetric crypto session to crypto operations */
549 rte_crypto_op_attach_asym_session(op, sess);
551 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
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 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
573 asym_op->rsa.message.length);
574 /* Use the resulted output as decryption Input vector*/
575 asym_op = result_op->asym;
576 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
577 asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
579 /* Process crypto operation */
580 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
582 "line %u FAILED: %s",
583 __LINE__, "Error sending packet for operation");
584 status = TEST_FAILED;
588 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
591 if (result_op == NULL) {
593 "line %u FAILED: %s",
594 __LINE__, "Failed to process asym crypto op");
595 status = TEST_FAILED;
598 status = TEST_SUCCESS;
600 ret = rsa_verify(&rsaplaintext, result_op);
602 status = TEST_FAILED;
607 rte_cryptodev_asym_session_clear(dev_id, sess);
608 rte_cryptodev_asym_session_free(sess);
612 rte_crypto_op_free(op);
614 TEST_ASSERT_EQUAL(status, 0, "Test failed");
620 testsuite_setup(void)
622 struct crypto_testsuite_params *ts_params = &testsuite_params;
623 struct rte_cryptodev_info info;
624 uint32_t i = 0, nb_devs, dev_id;
628 memset(ts_params, 0, sizeof(*ts_params));
630 test_vector.size = 0;
633 ts_params->op_mpool = rte_crypto_op_pool_create(
634 "CRYPTO_ASYM_OP_POOL",
635 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
639 if (ts_params->op_mpool == NULL) {
640 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
644 /* Create an OPENSSL device if required */
645 if (gbl_driver_id == rte_cryptodev_driver_id_get(
646 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
647 nb_devs = rte_cryptodev_device_count_by_driver(
648 rte_cryptodev_driver_id_get(
649 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
652 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
655 TEST_ASSERT(ret == 0, "Failed to create "
656 "instance of pmd : %s",
657 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
661 nb_devs = rte_cryptodev_count();
663 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
667 /* Create list of valid crypto devs */
668 for (i = 0; i < nb_devs; i++) {
669 rte_cryptodev_info_get(i, &info);
670 if (info.driver_id == gbl_driver_id)
671 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
674 if (ts_params->valid_dev_count < 1)
677 /* Set up all the qps on the first of the valid devices found */
679 dev_id = ts_params->valid_devs[0];
681 rte_cryptodev_info_get(dev_id, &info);
683 /* check if device support asymmetric, skip if not */
684 if (!(info.feature_flags &
685 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
686 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
691 /* configure device with num qp */
692 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
693 ts_params->conf.socket_id = SOCKET_ID_ANY;
694 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
696 "Failed to configure cryptodev %u with %u qps",
697 dev_id, ts_params->conf.nb_queue_pairs);
700 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
701 ts_params->qp_conf.mp_session = ts_params->session_mpool;
702 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
703 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
704 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
705 dev_id, qp_id, &ts_params->qp_conf,
706 rte_cryptodev_socket_id(dev_id)),
707 "Failed to setup queue pair %u on cryptodev %u ASYM",
711 /* setup asym session pool */
712 unsigned int session_size =
713 rte_cryptodev_asym_get_private_session_size(dev_id);
715 * Create mempool with TEST_NUM_SESSIONS * 2,
716 * to include the session headers
718 ts_params->session_mpool = rte_mempool_create(
720 TEST_NUM_SESSIONS * 2,
722 0, 0, NULL, NULL, NULL,
726 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
727 "session mempool allocation failed");
733 testsuite_teardown(void)
735 struct crypto_testsuite_params *ts_params = &testsuite_params;
737 if (ts_params->op_mpool != NULL) {
738 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
739 rte_mempool_avail_count(ts_params->op_mpool));
742 /* Free session mempools */
743 if (ts_params->session_mpool != NULL) {
744 rte_mempool_free(ts_params->session_mpool);
745 ts_params->session_mpool = NULL;
752 struct crypto_testsuite_params *ts_params = &testsuite_params;
756 /* Reconfigure device to default parameters */
757 ts_params->conf.socket_id = SOCKET_ID_ANY;
759 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
761 "Failed to configure cryptodev %u",
762 ts_params->valid_devs[0]);
764 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
765 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
766 ts_params->valid_devs[0], qp_id,
768 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
769 "Failed to setup queue pair %u on cryptodev %u",
770 qp_id, ts_params->valid_devs[0]);
773 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
775 /* Start the device */
776 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
777 "Failed to start cryptodev %u",
778 ts_params->valid_devs[0]);
786 struct crypto_testsuite_params *ts_params = &testsuite_params;
787 struct rte_cryptodev_stats stats;
789 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
791 /* Stop the device */
792 rte_cryptodev_stop(ts_params->valid_devs[0]);
795 static inline void print_asym_capa(
796 const struct rte_cryptodev_asymmetric_xform_capability *capa)
800 printf("\nxform type: %s\n===================\n",
801 rte_crypto_asym_xform_strings[capa->xform_type]);
802 printf("operation supported -");
804 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
805 /* check supported operations */
806 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
808 rte_crypto_asym_op_strings[i]);
810 switch (capa->xform_type) {
811 case RTE_CRYPTO_ASYM_XFORM_RSA:
812 case RTE_CRYPTO_ASYM_XFORM_MODINV:
813 case RTE_CRYPTO_ASYM_XFORM_MODEX:
814 case RTE_CRYPTO_ASYM_XFORM_DH:
815 case RTE_CRYPTO_ASYM_XFORM_DSA:
816 printf(" modlen: min %d max %d increment %d\n",
819 capa->modlen.increment);
827 test_capability(void)
829 struct crypto_testsuite_params *ts_params = &testsuite_params;
830 uint8_t dev_id = ts_params->valid_devs[0];
831 struct rte_cryptodev_info dev_info;
832 const struct rte_cryptodev_capabilities *dev_capa;
834 struct rte_cryptodev_asym_capability_idx idx;
835 const struct rte_cryptodev_asymmetric_xform_capability *capa;
837 rte_cryptodev_info_get(dev_id, &dev_info);
838 if (!(dev_info.feature_flags &
839 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
841 "Device doesn't support asymmetric. Test Skipped\n");
845 /* print xform capability */
847 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
849 dev_capa = &(dev_info.capabilities[i]);
850 if (dev_info.capabilities[i].op ==
851 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
852 idx.type = dev_capa->asym.xform_capa.xform_type;
854 capa = rte_cryptodev_asym_capability_get(dev_id,
856 rte_cryptodev_asym_capability_idx *) &idx);
857 print_asym_capa(capa);
864 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
866 struct crypto_testsuite_params *ts_params = &testsuite_params;
867 struct rte_mempool *op_mpool = ts_params->op_mpool;
868 struct rte_mempool *sess_mpool = ts_params->session_mpool;
869 uint8_t dev_id = ts_params->valid_devs[0];
870 struct rte_crypto_asym_op *asym_op = NULL;
871 struct rte_crypto_op *op = NULL, *result_op = NULL;
872 struct rte_cryptodev_asym_session *sess = NULL;
873 int status = TEST_SUCCESS;
874 uint8_t output[TEST_DH_MOD_LEN];
875 struct rte_crypto_asym_xform xform = *xfrm;
876 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
878 sess = rte_cryptodev_asym_session_create(sess_mpool);
881 "line %u FAILED: %s", __LINE__,
882 "Session creation failed");
883 status = TEST_FAILED;
886 /* set up crypto op data structure */
887 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
890 "line %u FAILED: %s",
891 __LINE__, "Failed to allocate asymmetric crypto "
893 status = TEST_FAILED;
898 /* Setup a xform and op to generate private key only */
899 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
901 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
902 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
903 asym_op->dh.pub_key.data = (uint8_t *)peer;
904 asym_op->dh.pub_key.length = sizeof(peer);
905 asym_op->dh.shared_secret.data = output;
906 asym_op->dh.shared_secret.length = sizeof(output);
908 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
911 "line %u FAILED: %s",
912 __LINE__, "unabled to config sym session");
913 status = TEST_FAILED;
917 /* attach asymmetric crypto session to crypto operations */
918 rte_crypto_op_attach_asym_session(op, sess);
920 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
922 /* Process crypto operation */
923 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
925 "line %u FAILED: %s",
926 __LINE__, "Error sending packet for operation");
927 status = TEST_FAILED;
931 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
934 if (result_op == NULL) {
936 "line %u FAILED: %s",
937 __LINE__, "Failed to process asym crypto op");
938 status = TEST_FAILED;
942 debug_hexdump(stdout, "shared secret:",
943 asym_op->dh.shared_secret.data,
944 asym_op->dh.shared_secret.length);
948 rte_cryptodev_asym_session_clear(dev_id, sess);
949 rte_cryptodev_asym_session_free(sess);
952 rte_crypto_op_free(op);
957 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
959 struct crypto_testsuite_params *ts_params = &testsuite_params;
960 struct rte_mempool *op_mpool = ts_params->op_mpool;
961 struct rte_mempool *sess_mpool = ts_params->session_mpool;
962 uint8_t dev_id = ts_params->valid_devs[0];
963 struct rte_crypto_asym_op *asym_op = NULL;
964 struct rte_crypto_op *op = NULL, *result_op = NULL;
965 struct rte_cryptodev_asym_session *sess = NULL;
966 int status = TEST_SUCCESS;
967 uint8_t output[TEST_DH_MOD_LEN];
968 struct rte_crypto_asym_xform xform = *xfrm;
970 sess = rte_cryptodev_asym_session_create(sess_mpool);
973 "line %u FAILED: %s", __LINE__,
974 "Session creation failed");
975 status = TEST_FAILED;
978 /* set up crypto op data structure */
979 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
982 "line %u FAILED: %s",
983 __LINE__, "Failed to allocate asymmetric crypto "
985 status = TEST_FAILED;
990 /* Setup a xform and op to generate private key only */
991 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
993 asym_op->dh.priv_key.data = output;
994 asym_op->dh.priv_key.length = sizeof(output);
996 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
999 "line %u FAILED: %s",
1000 __LINE__, "unabled to config sym session");
1001 status = TEST_FAILED;
1005 /* attach asymmetric crypto session to crypto operations */
1006 rte_crypto_op_attach_asym_session(op, sess);
1008 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1010 /* Process crypto operation */
1011 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1013 "line %u FAILED: %s",
1014 __LINE__, "Error sending packet for operation");
1015 status = TEST_FAILED;
1019 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1022 if (result_op == NULL) {
1024 "line %u FAILED: %s",
1025 __LINE__, "Failed to process asym crypto op");
1026 status = TEST_FAILED;
1030 debug_hexdump(stdout, "private key:",
1031 asym_op->dh.priv_key.data,
1032 asym_op->dh.priv_key.length);
1037 rte_cryptodev_asym_session_clear(dev_id, sess);
1038 rte_cryptodev_asym_session_free(sess);
1041 rte_crypto_op_free(op);
1048 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1050 struct crypto_testsuite_params *ts_params = &testsuite_params;
1051 struct rte_mempool *op_mpool = ts_params->op_mpool;
1052 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1053 uint8_t dev_id = ts_params->valid_devs[0];
1054 struct rte_crypto_asym_op *asym_op = NULL;
1055 struct rte_crypto_op *op = NULL, *result_op = NULL;
1056 struct rte_cryptodev_asym_session *sess = NULL;
1057 int status = TEST_SUCCESS;
1058 uint8_t output[TEST_DH_MOD_LEN];
1059 struct rte_crypto_asym_xform xform = *xfrm;
1061 sess = rte_cryptodev_asym_session_create(sess_mpool);
1064 "line %u FAILED: %s", __LINE__,
1065 "Session creation failed");
1066 status = TEST_FAILED;
1069 /* set up crypto op data structure */
1070 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1073 "line %u FAILED: %s",
1074 __LINE__, "Failed to allocate asymmetric crypto "
1075 "operation struct");
1076 status = TEST_FAILED;
1080 /* Setup a xform chain to generate public key
1081 * using test private key
1084 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1087 asym_op->dh.pub_key.data = output;
1088 asym_op->dh.pub_key.length = sizeof(output);
1089 /* load pre-defined private key */
1090 asym_op->dh.priv_key.data = rte_malloc(NULL,
1091 dh_test_params.priv_key.length,
1093 asym_op->dh.priv_key = dh_test_params.priv_key;
1095 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1098 "line %u FAILED: %s",
1099 __LINE__, "unabled to config sym session");
1100 status = TEST_FAILED;
1104 /* attach asymmetric crypto session to crypto operations */
1105 rte_crypto_op_attach_asym_session(op, sess);
1107 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1109 /* Process crypto operation */
1110 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1112 "line %u FAILED: %s",
1113 __LINE__, "Error sending packet for operation");
1114 status = TEST_FAILED;
1118 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1121 if (result_op == NULL) {
1123 "line %u FAILED: %s",
1124 __LINE__, "Failed to process asym crypto op");
1125 status = TEST_FAILED;
1129 debug_hexdump(stdout, "pub key:",
1130 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1132 debug_hexdump(stdout, "priv key:",
1133 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1137 rte_cryptodev_asym_session_clear(dev_id, sess);
1138 rte_cryptodev_asym_session_free(sess);
1141 rte_crypto_op_free(op);
1147 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1149 struct crypto_testsuite_params *ts_params = &testsuite_params;
1150 struct rte_mempool *op_mpool = ts_params->op_mpool;
1151 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1152 uint8_t dev_id = ts_params->valid_devs[0];
1153 struct rte_crypto_asym_op *asym_op = NULL;
1154 struct rte_crypto_op *op = NULL, *result_op = NULL;
1155 struct rte_cryptodev_asym_session *sess = NULL;
1156 int status = TEST_SUCCESS;
1157 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1158 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1159 struct rte_crypto_asym_xform pub_key_xform;
1160 struct rte_crypto_asym_xform xform = *xfrm;
1162 sess = rte_cryptodev_asym_session_create(sess_mpool);
1165 "line %u FAILED: %s", __LINE__,
1166 "Session creation failed");
1167 status = TEST_FAILED;
1171 /* set up crypto op data structure */
1172 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1175 "line %u FAILED: %s",
1176 __LINE__, "Failed to allocate asymmetric crypto "
1177 "operation struct");
1178 status = TEST_FAILED;
1182 /* Setup a xform chain to generate
1183 * private key first followed by
1185 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1186 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1187 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1188 xform.next = &pub_key_xform;
1190 asym_op->dh.pub_key.data = out_pub_key;
1191 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1192 asym_op->dh.priv_key.data = out_prv_key;
1193 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1194 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1197 "line %u FAILED: %s",
1198 __LINE__, "unabled to config sym session");
1199 status = TEST_FAILED;
1203 /* attach asymmetric crypto session to crypto operations */
1204 rte_crypto_op_attach_asym_session(op, sess);
1206 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1208 /* Process crypto operation */
1209 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1211 "line %u FAILED: %s",
1212 __LINE__, "Error sending packet for operation");
1213 status = TEST_FAILED;
1217 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1220 if (result_op == NULL) {
1222 "line %u FAILED: %s",
1223 __LINE__, "Failed to process asym crypto op");
1224 status = TEST_FAILED;
1227 debug_hexdump(stdout, "priv key:",
1228 out_prv_key, asym_op->dh.priv_key.length);
1229 debug_hexdump(stdout, "pub key:",
1230 out_pub_key, asym_op->dh.pub_key.length);
1234 rte_cryptodev_asym_session_clear(dev_id, sess);
1235 rte_cryptodev_asym_session_free(sess);
1238 rte_crypto_op_free(op);
1246 struct crypto_testsuite_params *ts_params = &testsuite_params;
1247 struct rte_mempool *op_mpool = ts_params->op_mpool;
1248 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1249 uint8_t dev_id = ts_params->valid_devs[0];
1250 struct rte_crypto_asym_op *asym_op = NULL;
1251 struct rte_crypto_op *op = NULL, *result_op = NULL;
1252 struct rte_cryptodev_asym_session *sess = NULL;
1253 int status = TEST_SUCCESS;
1254 struct rte_cryptodev_asym_capability_idx cap_idx;
1255 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1256 uint8_t input[TEST_DATA_SIZE] = {0};
1258 uint8_t result[sizeof(mod_p)] = { 0 };
1260 if (rte_cryptodev_asym_get_xform_enum(
1261 &modinv_xform.xform_type, "modinv") < 0) {
1263 "Invalid ASYNC algorithm specified\n");
1267 cap_idx.type = modinv_xform.xform_type;
1268 capability = rte_cryptodev_asym_capability_get(dev_id,
1271 if (rte_cryptodev_asym_xform_capability_check_modlen(
1273 modinv_xform.modinv.modulus.length)) {
1275 "Invalid MODULOUS length specified\n");
1279 sess = rte_cryptodev_asym_session_create(sess_mpool);
1281 RTE_LOG(ERR, USER1, "line %u "
1282 "FAILED: %s", __LINE__,
1283 "Session creation failed");
1284 status = TEST_FAILED;
1288 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1291 "line %u FAILED: %s",
1292 __LINE__, "unabled to config sym session");
1293 status = TEST_FAILED;
1297 /* generate crypto op data structure */
1298 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1301 "line %u FAILED: %s",
1302 __LINE__, "Failed to allocate asymmetric crypto "
1303 "operation struct");
1304 status = TEST_FAILED;
1309 memcpy(input, base, sizeof(base));
1310 asym_op->modinv.base.data = input;
1311 asym_op->modinv.base.length = sizeof(base);
1312 asym_op->modinv.result.data = result;
1313 asym_op->modinv.result.length = sizeof(result);
1315 /* attach asymmetric crypto session to crypto operations */
1316 rte_crypto_op_attach_asym_session(op, sess);
1318 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1320 /* Process crypto operation */
1321 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1323 "line %u FAILED: %s",
1324 __LINE__, "Error sending packet for operation");
1325 status = TEST_FAILED;
1329 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1332 if (result_op == NULL) {
1334 "line %u FAILED: %s",
1335 __LINE__, "Failed to process asym crypto op");
1336 status = TEST_FAILED;
1340 ret = verify_modinv(mod_inv, result_op);
1343 "operation verification failed\n");
1344 status = TEST_FAILED;
1349 rte_cryptodev_asym_session_clear(dev_id, sess);
1350 rte_cryptodev_asym_session_free(sess);
1354 rte_crypto_op_free(op);
1356 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1364 struct crypto_testsuite_params *ts_params = &testsuite_params;
1365 struct rte_mempool *op_mpool = ts_params->op_mpool;
1366 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1367 uint8_t dev_id = ts_params->valid_devs[0];
1368 struct rte_crypto_asym_op *asym_op = NULL;
1369 struct rte_crypto_op *op = NULL, *result_op = NULL;
1370 struct rte_cryptodev_asym_session *sess = NULL;
1371 int status = TEST_SUCCESS;
1372 struct rte_cryptodev_asym_capability_idx cap_idx;
1373 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1374 uint8_t input[TEST_DATA_SIZE] = {0};
1376 uint8_t result[sizeof(mod_p)] = { 0 };
1378 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1382 "Invalid ASYNC algorithm specified\n");
1386 /* check for modlen capability */
1387 cap_idx.type = modex_xform.xform_type;
1388 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1390 if (rte_cryptodev_asym_xform_capability_check_modlen(
1391 capability, modex_xform.modex.modulus.length)) {
1393 "Invalid MODULOUS length specified\n");
1397 /* generate crypto op data structure */
1398 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1401 "line %u FAILED: %s",
1402 __LINE__, "Failed to allocate asymmetric crypto "
1403 "operation struct");
1404 status = TEST_FAILED;
1408 sess = rte_cryptodev_asym_session_create(sess_mpool);
1412 "FAILED: %s", __LINE__,
1413 "Session creation failed");
1414 status = TEST_FAILED;
1418 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1421 "line %u FAILED: %s",
1422 __LINE__, "unabled to config sym session");
1423 status = TEST_FAILED;
1428 memcpy(input, base, sizeof(base));
1429 asym_op->modex.base.data = input;
1430 asym_op->modex.base.length = sizeof(base);
1431 asym_op->modex.result.data = result;
1432 asym_op->modex.result.length = sizeof(result);
1433 /* attach asymmetric crypto session to crypto operations */
1434 rte_crypto_op_attach_asym_session(op, sess);
1436 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1437 /* Process crypto operation */
1438 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1440 "line %u FAILED: %s",
1441 __LINE__, "Error sending packet for operation");
1442 status = TEST_FAILED;
1446 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1449 if (result_op == NULL) {
1451 "line %u FAILED: %s",
1452 __LINE__, "Failed to process asym crypto op");
1453 status = TEST_FAILED;
1457 ret = verify_modexp(mod_exp, result_op);
1460 "operation verification failed\n");
1461 status = TEST_FAILED;
1466 rte_cryptodev_asym_session_clear(dev_id, sess);
1467 rte_cryptodev_asym_session_free(sess);
1471 rte_crypto_op_free(op);
1473 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1479 test_dh_keygenration(void)
1483 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1484 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1485 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1486 dh_test_params.priv_key.length);
1488 RTE_LOG(INFO, USER1,
1489 "Test Public and Private key pair generation\n");
1491 status = test_dh_gen_kp(&dh_xform);
1492 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1494 RTE_LOG(INFO, USER1,
1495 "Test Public Key Generation using pre-defined priv key\n");
1497 status = test_dh_gen_pub_key(&dh_xform);
1498 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1500 RTE_LOG(INFO, USER1,
1501 "Test Private Key Generation only\n");
1503 status = test_dh_gen_priv_key(&dh_xform);
1504 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1506 RTE_LOG(INFO, USER1,
1507 "Test shared secret compute\n");
1509 status = test_dh_gen_shared_sec(&dh_xform);
1510 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1518 struct crypto_testsuite_params *ts_params = &testsuite_params;
1519 struct rte_mempool *op_mpool = ts_params->op_mpool;
1520 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1521 uint8_t dev_id = ts_params->valid_devs[0];
1522 struct rte_crypto_asym_op *asym_op = NULL;
1523 struct rte_crypto_op *op = NULL, *result_op = NULL;
1524 struct rte_cryptodev_asym_session *sess = NULL;
1525 int status = TEST_SUCCESS;
1526 uint8_t r[TEST_DH_MOD_LEN];
1527 uint8_t s[TEST_DH_MOD_LEN];
1528 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1530 sess = rte_cryptodev_asym_session_create(sess_mpool);
1533 "line %u FAILED: %s", __LINE__,
1534 "Session creation failed");
1535 status = TEST_FAILED;
1538 /* set up crypto op data structure */
1539 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1542 "line %u FAILED: %s",
1543 __LINE__, "Failed to allocate asymmetric crypto "
1544 "operation struct");
1545 status = TEST_FAILED;
1550 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1551 dsa_xform.dsa.p.length);
1552 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1553 dsa_xform.dsa.q.length);
1554 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1555 dsa_xform.dsa.g.length);
1556 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1557 dsa_xform.dsa.x.length);
1559 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1562 "line %u FAILED: %s",
1563 __LINE__, "unabled to config sym session");
1564 status = TEST_FAILED;
1568 /* attach asymmetric crypto session to crypto operations */
1569 rte_crypto_op_attach_asym_session(op, sess);
1570 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1571 asym_op->dsa.message.data = dgst;
1572 asym_op->dsa.message.length = sizeof(dgst);
1573 asym_op->dsa.r.length = sizeof(r);
1574 asym_op->dsa.r.data = r;
1575 asym_op->dsa.s.length = sizeof(s);
1576 asym_op->dsa.s.data = s;
1578 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1580 /* Process crypto operation */
1581 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1583 "line %u FAILED: %s",
1584 __LINE__, "Error sending packet for operation");
1585 status = TEST_FAILED;
1589 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1592 if (result_op == NULL) {
1594 "line %u FAILED: %s",
1595 __LINE__, "Failed to process asym crypto op");
1596 status = TEST_FAILED;
1600 asym_op = result_op->asym;
1602 debug_hexdump(stdout, "r:",
1603 asym_op->dsa.r.data, asym_op->dsa.r.length);
1604 debug_hexdump(stdout, "s:",
1605 asym_op->dsa.s.data, asym_op->dsa.s.length);
1607 /* Test PMD DSA sign verification using signer public key */
1608 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1610 /* copy signer public key */
1611 asym_op->dsa.y.data = dsa_test_params.y.data;
1612 asym_op->dsa.y.length = dsa_test_params.y.length;
1614 /* Process crypto operation */
1615 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1617 "line %u FAILED: %s",
1618 __LINE__, "Error sending packet for operation");
1619 status = TEST_FAILED;
1623 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1626 if (result_op == NULL) {
1628 "line %u FAILED: %s",
1629 __LINE__, "Failed to process asym crypto op");
1630 status = TEST_FAILED;
1634 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1636 "line %u FAILED: %s",
1637 __LINE__, "Failed to process asym crypto op");
1638 status = TEST_FAILED;
1642 rte_cryptodev_asym_session_clear(dev_id, sess);
1643 rte_cryptodev_asym_session_free(sess);
1646 rte_crypto_op_free(op);
1654 status = test_dsa_sign();
1655 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1660 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1661 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1662 .setup = testsuite_setup,
1663 .teardown = testsuite_teardown,
1664 .unit_test_cases = {
1665 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1666 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1667 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1668 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1669 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1670 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1671 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1672 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1673 TEST_CASES_END() /**< NULL terminate unit test array */
1677 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1678 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1679 .setup = testsuite_setup,
1680 .teardown = testsuite_teardown,
1681 .unit_test_cases = {
1682 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1683 TEST_CASES_END() /**< NULL terminate unit test array */
1688 test_cryptodev_openssl_asym(void)
1690 gbl_driver_id = rte_cryptodev_driver_id_get(
1691 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1693 if (gbl_driver_id == -1) {
1694 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1695 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1696 "in config file to run this testsuite.\n");
1700 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1704 test_cryptodev_qat_asym(void)
1706 gbl_driver_id = rte_cryptodev_driver_id_get(
1707 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1709 if (gbl_driver_id == -1) {
1710 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1711 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1712 "in config file to run this testsuite.\n");
1716 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1719 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1720 test_cryptodev_openssl_asym);
1722 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);