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 queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
72 struct crypto_testsuite_params *ts_params = &testsuite_params;
73 struct rte_mempool *op_mpool = ts_params->op_mpool;
74 uint8_t dev_id = ts_params->valid_devs[0];
75 struct rte_crypto_op *op, *result_op;
76 struct rte_crypto_asym_op *asym_op;
77 uint8_t output_buf[TEST_DATA_SIZE];
78 int status = TEST_SUCCESS;
80 /* Set up crypto op data structure */
81 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
83 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
84 "operation struct\n");
90 /* Compute sign on the test vector */
91 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
93 asym_op->rsa.message.data = rsaplaintext.data;
94 asym_op->rsa.message.length = rsaplaintext.len;
95 asym_op->rsa.sign.length = 0;
96 asym_op->rsa.sign.data = output_buf;
97 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
99 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
100 asym_op->rsa.message.length);
102 /* Attach asymmetric crypto session to crypto operations */
103 rte_crypto_op_attach_asym_session(op, sess);
105 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
107 /* Process crypto operation */
108 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
109 RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
110 status = TEST_FAILED;
114 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
117 if (result_op == NULL) {
118 RTE_LOG(ERR, USER1, "Failed to process sign op\n");
119 status = TEST_FAILED;
123 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
124 asym_op->rsa.sign.length);
125 asym_op = result_op->asym;
128 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
129 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
131 /* Process crypto operation */
132 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
133 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
134 status = TEST_FAILED;
138 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
141 if (result_op == NULL) {
142 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
143 status = TEST_FAILED;
147 status = TEST_SUCCESS;
148 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
149 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
150 status = TEST_FAILED;
155 rte_crypto_op_free(op);
161 queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
163 struct crypto_testsuite_params *ts_params = &testsuite_params;
164 struct rte_mempool *op_mpool = ts_params->op_mpool;
165 uint8_t dev_id = ts_params->valid_devs[0];
166 struct rte_crypto_op *op, *result_op;
167 struct rte_crypto_asym_op *asym_op;
168 uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
169 int ret, status = TEST_SUCCESS;
171 /* Set up crypto op data structure */
172 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
174 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
175 "operation struct\n");
181 /* Compute encryption on the test vector */
182 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
184 asym_op->rsa.message.data = rsaplaintext.data;
185 asym_op->rsa.cipher.data = cipher_buf;
186 asym_op->rsa.cipher.length = 0;
187 asym_op->rsa.message.length = rsaplaintext.len;
188 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
190 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
191 asym_op->rsa.message.length);
193 /* Attach asymmetric crypto session to crypto operations */
194 rte_crypto_op_attach_asym_session(op, sess);
196 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
198 /* Process crypto operation */
199 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
200 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
201 status = TEST_FAILED;
205 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
208 if (result_op == NULL) {
209 RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
210 status = TEST_FAILED;
213 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
214 asym_op->rsa.message.length);
216 /* Use the resulted output as decryption Input vector*/
217 asym_op = result_op->asym;
218 asym_op->rsa.message.length = 0;
219 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
220 asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
222 /* Process crypto operation */
223 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
224 RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
225 status = TEST_FAILED;
229 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
232 if (result_op == NULL) {
233 RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
234 status = TEST_FAILED;
237 status = TEST_SUCCESS;
238 ret = rsa_verify(&rsaplaintext, result_op);
240 status = TEST_FAILED;
244 rte_crypto_op_free(op);
249 test_cryptodev_asym_ver(union test_case_structure *data_tc,
250 struct rte_crypto_op *result_op)
252 int status = TEST_SUCCESS;
254 uint8_t *data_expected = NULL, *data_received = NULL;
255 size_t data_size = 0;
257 switch (data_tc->modex.xform_type) {
258 case RTE_CRYPTO_ASYM_XFORM_MODEX:
259 data_expected = data_tc->modex.reminder.data;
260 data_received = result_op->asym->modex.result.data;
261 data_size = result_op->asym->modex.result.length;
263 case RTE_CRYPTO_ASYM_XFORM_MODINV:
264 data_expected = data_tc->modinv.inverse.data;
265 data_received = result_op->asym->modinv.result.data;
266 data_size = result_op->asym->modinv.result.length;
268 case RTE_CRYPTO_ASYM_XFORM_DH:
269 case RTE_CRYPTO_ASYM_XFORM_DSA:
270 case RTE_CRYPTO_ASYM_XFORM_RSA:
271 case RTE_CRYPTO_ASYM_XFORM_NONE:
272 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
276 ret = memcmp(data_expected, data_received, data_size);
278 status = TEST_FAILED;
284 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
285 union test_case_structure *data_tc,
286 char *test_msg, int sessionless)
288 struct rte_crypto_asym_op *asym_op = NULL;
289 struct rte_crypto_op *op = NULL;
290 struct rte_crypto_op *result_op = NULL;
291 struct rte_crypto_asym_xform xform_tc;
292 struct rte_cryptodev_asym_session *sess = NULL;
293 struct rte_cryptodev_asym_capability_idx cap_idx;
294 const struct rte_cryptodev_asymmetric_xform_capability *capability;
295 uint8_t dev_id = ts_params->valid_devs[0];
296 uint8_t input[TEST_DATA_SIZE] = {0};
297 uint8_t *result = NULL;
299 int status = TEST_SUCCESS;
301 xform_tc.next = NULL;
302 xform_tc.xform_type = data_tc->modex.xform_type;
304 cap_idx.type = xform_tc.xform_type;
305 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
307 if (capability == NULL) {
309 "Device doesn't support MODEX. Test Skipped\n");
313 /* Generate crypto op data structure */
314 op = rte_crypto_op_alloc(ts_params->op_mpool,
315 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
318 snprintf(test_msg, ASYM_TEST_MSG_LEN,
319 "line %u FAILED: %s",
320 __LINE__, "Failed to allocate asymmetric crypto "
322 status = TEST_FAILED;
328 switch (xform_tc.xform_type) {
329 case RTE_CRYPTO_ASYM_XFORM_MODEX:
330 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
331 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
332 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
333 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
334 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
335 memcpy(input, data_tc->modex.base.data,
336 data_tc->modex.base.len);
337 asym_op->modex.base.data = input;
338 asym_op->modex.base.length = data_tc->modex.base.len;
339 asym_op->modex.result.data = result;
340 asym_op->modex.result.length = data_tc->modex.result_len;
341 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
342 xform_tc.modex.modulus.length)) {
343 snprintf(test_msg, ASYM_TEST_MSG_LEN,
345 "FAILED: %s", __LINE__,
346 "Invalid MODULUS length specified");
347 status = TEST_FAILED;
351 case RTE_CRYPTO_ASYM_XFORM_MODINV:
352 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
353 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
354 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
355 memcpy(input, data_tc->modinv.base.data,
356 data_tc->modinv.base.len);
357 asym_op->modinv.base.data = input;
358 asym_op->modinv.base.length = data_tc->modinv.base.len;
359 asym_op->modinv.result.data = result;
360 asym_op->modinv.result.length = data_tc->modinv.result_len;
361 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
362 xform_tc.modinv.modulus.length)) {
363 snprintf(test_msg, ASYM_TEST_MSG_LEN,
365 "FAILED: %s", __LINE__,
366 "Invalid MODULUS length specified");
367 status = TEST_FAILED;
371 case RTE_CRYPTO_ASYM_XFORM_DH:
372 case RTE_CRYPTO_ASYM_XFORM_DSA:
373 case RTE_CRYPTO_ASYM_XFORM_RSA:
374 case RTE_CRYPTO_ASYM_XFORM_NONE:
375 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
377 snprintf(test_msg, ASYM_TEST_MSG_LEN,
379 "FAILED: %s", __LINE__,
380 "Invalid ASYM algorithm specified");
381 status = TEST_FAILED;
386 sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
388 snprintf(test_msg, ASYM_TEST_MSG_LEN,
390 "FAILED: %s", __LINE__,
391 "Session creation failed");
392 status = TEST_FAILED;
396 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
397 ts_params->session_mpool) < 0) {
398 snprintf(test_msg, ASYM_TEST_MSG_LEN,
399 "line %u FAILED: %s",
400 __LINE__, "unabled to config sym session");
401 status = TEST_FAILED;
405 rte_crypto_op_attach_asym_session(op, sess);
407 asym_op->xform = &xform_tc;
408 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
410 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
412 /* Process crypto operation */
413 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
414 snprintf(test_msg, ASYM_TEST_MSG_LEN,
415 "line %u FAILED: %s",
416 __LINE__, "Error sending packet for operation");
417 status = TEST_FAILED;
421 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
424 if (result_op == NULL) {
425 snprintf(test_msg, ASYM_TEST_MSG_LEN,
426 "line %u FAILED: %s",
427 __LINE__, "Failed to process asym crypto op");
428 status = TEST_FAILED;
432 if (test_cryptodev_asym_ver(data_tc, result_op) != TEST_SUCCESS) {
433 snprintf(test_msg, ASYM_TEST_MSG_LEN,
434 "line %u FAILED: %s",
435 __LINE__, "Verification failed ");
436 status = TEST_FAILED;
441 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
443 snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
447 rte_cryptodev_asym_session_clear(dev_id, sess);
448 rte_cryptodev_asym_session_free(sess);
452 rte_crypto_op_free(op);
461 test_one_case(const void *test_case, int sessionless)
463 int status = TEST_SUCCESS;
464 char test_msg[ASYM_TEST_MSG_LEN + 1];
466 /* Map the case to union */
467 union test_case_structure tc;
468 memcpy(&tc, test_case, sizeof(tc));
470 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
473 printf(" %u) TestCase %s %s\n", test_index++,
474 tc.modex.description, test_msg);
480 load_test_vectors(void)
482 uint32_t i = 0, v_size = 0;
483 /* Load MODEX vector*/
484 v_size = ARRAY_SIZE(modex_test_case);
485 for (i = 0; i < v_size; i++) {
486 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
487 RTE_LOG(DEBUG, USER1,
488 "TEST_VECTOR_SIZE too small\n");
491 test_vector.address[test_vector.size] = &modex_test_case[i];
494 /* Load MODINV vector*/
495 v_size = ARRAY_SIZE(modinv_test_case);
496 for (i = 0; i < v_size; i++) {
497 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
498 RTE_LOG(DEBUG, USER1,
499 "TEST_VECTOR_SIZE too small\n");
502 test_vector.address[test_vector.size] = &modinv_test_case[i];
509 test_one_by_one(void)
511 int status = TEST_SUCCESS;
512 struct crypto_testsuite_params *ts_params = &testsuite_params;
514 uint8_t dev_id = ts_params->valid_devs[0];
515 struct rte_cryptodev_info dev_info;
518 rte_cryptodev_info_get(dev_id, &dev_info);
519 if ((dev_info.feature_flags &
520 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
524 /* Go through all test cases */
526 for (i = 0; i < test_vector.size; i++) {
527 if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
528 status = TEST_FAILED;
531 for (i = 0; i < test_vector.size; i++) {
532 if (test_one_case(test_vector.address[i], 1)
534 status = TEST_FAILED;
538 TEST_ASSERT_EQUAL(status, 0, "Test failed");
543 test_rsa_sign_verify(void)
545 struct crypto_testsuite_params *ts_params = &testsuite_params;
546 struct rte_mempool *sess_mpool = ts_params->session_mpool;
547 uint8_t dev_id = ts_params->valid_devs[0];
548 struct rte_cryptodev_asym_session *sess;
549 struct rte_cryptodev_info dev_info;
550 int status = TEST_SUCCESS;
552 /* Test case supports op with exponent key only,
553 * Check in PMD feature flag for RSA exponent key type support.
555 rte_cryptodev_info_get(dev_id, &dev_info);
556 if (!(dev_info.feature_flags &
557 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
558 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
559 "exponent key type. Test Skipped\n");
563 sess = rte_cryptodev_asym_session_create(sess_mpool);
566 RTE_LOG(ERR, USER1, "Session creation failed for "
571 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
573 RTE_LOG(ERR, USER1, "Unable to config asym session for "
575 status = TEST_FAILED;
579 status = queue_ops_rsa_sign_verify(sess);
583 rte_cryptodev_asym_session_clear(dev_id, sess);
584 rte_cryptodev_asym_session_free(sess);
586 TEST_ASSERT_EQUAL(status, 0, "Test failed");
592 test_rsa_enc_dec(void)
594 struct crypto_testsuite_params *ts_params = &testsuite_params;
595 struct rte_mempool *sess_mpool = ts_params->session_mpool;
596 uint8_t dev_id = ts_params->valid_devs[0];
597 struct rte_cryptodev_asym_session *sess;
598 struct rte_cryptodev_info dev_info;
599 int status = TEST_SUCCESS;
601 /* Test case supports op with exponent key only,
602 * Check in PMD feature flag for RSA exponent key type support.
604 rte_cryptodev_info_get(dev_id, &dev_info);
605 if (!(dev_info.feature_flags &
606 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
607 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
608 "exponent key type. Test skipped\n");
612 sess = rte_cryptodev_asym_session_create(sess_mpool);
615 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
619 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
621 RTE_LOG(ERR, USER1, "Unable to config asym session for "
623 status = TEST_FAILED;
627 status = queue_ops_rsa_enc_dec(sess);
631 rte_cryptodev_asym_session_clear(dev_id, sess);
632 rte_cryptodev_asym_session_free(sess);
634 TEST_ASSERT_EQUAL(status, 0, "Test failed");
640 test_rsa_sign_verify_crt(void)
642 struct crypto_testsuite_params *ts_params = &testsuite_params;
643 struct rte_mempool *sess_mpool = ts_params->session_mpool;
644 uint8_t dev_id = ts_params->valid_devs[0];
645 struct rte_cryptodev_asym_session *sess;
646 struct rte_cryptodev_info dev_info;
647 int status = TEST_SUCCESS;
649 /* Test case supports op with quintuple format key only,
650 * Check im PMD feature flag for RSA quintuple key type support.
652 rte_cryptodev_info_get(dev_id, &dev_info);
653 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
654 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
655 "quintuple key type. Test skipped\n");
659 sess = rte_cryptodev_asym_session_create(sess_mpool);
662 RTE_LOG(ERR, USER1, "Session creation failed for "
663 "sign_verify_crt\n");
664 status = TEST_FAILED;
668 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
670 RTE_LOG(ERR, USER1, "Unable to config asym session for "
671 "sign_verify_crt\n");
672 status = TEST_FAILED;
675 status = queue_ops_rsa_sign_verify(sess);
679 rte_cryptodev_asym_session_clear(dev_id, sess);
680 rte_cryptodev_asym_session_free(sess);
682 TEST_ASSERT_EQUAL(status, 0, "Test failed");
688 test_rsa_enc_dec_crt(void)
690 struct crypto_testsuite_params *ts_params = &testsuite_params;
691 struct rte_mempool *sess_mpool = ts_params->session_mpool;
692 uint8_t dev_id = ts_params->valid_devs[0];
693 struct rte_cryptodev_asym_session *sess;
694 struct rte_cryptodev_info dev_info;
695 int status = TEST_SUCCESS;
697 /* Test case supports op with quintuple format key only,
698 * Check in PMD feature flag for RSA quintuple key type support.
700 rte_cryptodev_info_get(dev_id, &dev_info);
701 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
702 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
703 "quintuple key type. Test skipped\n");
707 sess = rte_cryptodev_asym_session_create(sess_mpool);
710 RTE_LOG(ERR, USER1, "Session creation failed for "
715 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
717 RTE_LOG(ERR, USER1, "Unable to config asym session for "
719 status = TEST_FAILED;
722 status = queue_ops_rsa_enc_dec(sess);
726 rte_cryptodev_asym_session_clear(dev_id, sess);
727 rte_cryptodev_asym_session_free(sess);
729 TEST_ASSERT_EQUAL(status, 0, "Test failed");
735 testsuite_setup(void)
737 struct crypto_testsuite_params *ts_params = &testsuite_params;
738 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
739 struct rte_cryptodev_info info;
740 int ret, dev_id = -1;
744 memset(ts_params, 0, sizeof(*ts_params));
746 test_vector.size = 0;
749 ts_params->op_mpool = rte_crypto_op_pool_create(
750 "CRYPTO_ASYM_OP_POOL",
751 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
755 if (ts_params->op_mpool == NULL) {
756 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
760 /* Create an OPENSSL device if required */
761 if (gbl_driver_id == rte_cryptodev_driver_id_get(
762 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
763 nb_devs = rte_cryptodev_device_count_by_driver(
764 rte_cryptodev_driver_id_get(
765 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
768 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
771 TEST_ASSERT(ret == 0, "Failed to create "
772 "instance of pmd : %s",
773 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
777 /* Get list of valid crypto devs */
778 nb_devs = rte_cryptodev_devices_get(
779 rte_cryptodev_driver_name_get(gbl_driver_id),
780 valid_devs, RTE_CRYPTO_MAX_DEVS);
782 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
787 * Get first valid asymmetric device found in test suite param and
790 for (i = 0; i < nb_devs ; i++) {
791 rte_cryptodev_info_get(valid_devs[i], &info);
792 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
793 dev_id = ts_params->valid_devs[0] = valid_devs[i];
799 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
804 /* Set valid device count */
805 ts_params->valid_dev_count = nb_devs;
807 /* configure device with num qp */
808 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
809 ts_params->conf.socket_id = SOCKET_ID_ANY;
810 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
811 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
812 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
814 "Failed to configure cryptodev %u with %u qps",
815 dev_id, ts_params->conf.nb_queue_pairs);
818 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
819 ts_params->qp_conf.mp_session = ts_params->session_mpool;
820 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
821 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
822 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
823 dev_id, qp_id, &ts_params->qp_conf,
824 rte_cryptodev_socket_id(dev_id)),
825 "Failed to setup queue pair %u on cryptodev %u ASYM",
829 /* setup asym session pool */
830 unsigned int session_size =
831 rte_cryptodev_asym_get_private_session_size(dev_id);
833 * Create mempool with TEST_NUM_SESSIONS * 2,
834 * to include the session headers
836 ts_params->session_mpool = rte_mempool_create(
838 TEST_NUM_SESSIONS * 2,
840 0, 0, NULL, NULL, NULL,
844 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
845 "session mempool allocation failed");
851 testsuite_teardown(void)
853 struct crypto_testsuite_params *ts_params = &testsuite_params;
855 if (ts_params->op_mpool != NULL) {
856 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
857 rte_mempool_avail_count(ts_params->op_mpool));
860 /* Free session mempools */
861 if (ts_params->session_mpool != NULL) {
862 rte_mempool_free(ts_params->session_mpool);
863 ts_params->session_mpool = NULL;
870 struct crypto_testsuite_params *ts_params = &testsuite_params;
874 /* Reconfigure device to default parameters */
875 ts_params->conf.socket_id = SOCKET_ID_ANY;
877 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
879 "Failed to configure cryptodev %u",
880 ts_params->valid_devs[0]);
882 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
883 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
884 ts_params->valid_devs[0], qp_id,
886 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
887 "Failed to setup queue pair %u on cryptodev %u",
888 qp_id, ts_params->valid_devs[0]);
891 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
893 /* Start the device */
894 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
895 "Failed to start cryptodev %u",
896 ts_params->valid_devs[0]);
904 struct crypto_testsuite_params *ts_params = &testsuite_params;
905 struct rte_cryptodev_stats stats;
907 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
909 /* Stop the device */
910 rte_cryptodev_stop(ts_params->valid_devs[0]);
913 static inline void print_asym_capa(
914 const struct rte_cryptodev_asymmetric_xform_capability *capa)
918 printf("\nxform type: %s\n===================\n",
919 rte_crypto_asym_xform_strings[capa->xform_type]);
920 printf("operation supported -");
922 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
923 /* check supported operations */
924 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
926 rte_crypto_asym_op_strings[i]);
928 switch (capa->xform_type) {
929 case RTE_CRYPTO_ASYM_XFORM_RSA:
930 case RTE_CRYPTO_ASYM_XFORM_MODINV:
931 case RTE_CRYPTO_ASYM_XFORM_MODEX:
932 case RTE_CRYPTO_ASYM_XFORM_DH:
933 case RTE_CRYPTO_ASYM_XFORM_DSA:
934 printf(" modlen: min %d max %d increment %d\n",
937 capa->modlen.increment);
945 test_capability(void)
947 struct crypto_testsuite_params *ts_params = &testsuite_params;
948 uint8_t dev_id = ts_params->valid_devs[0];
949 struct rte_cryptodev_info dev_info;
950 const struct rte_cryptodev_capabilities *dev_capa;
952 struct rte_cryptodev_asym_capability_idx idx;
953 const struct rte_cryptodev_asymmetric_xform_capability *capa;
955 rte_cryptodev_info_get(dev_id, &dev_info);
956 if (!(dev_info.feature_flags &
957 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
959 "Device doesn't support asymmetric. Test Skipped\n");
963 /* print xform capability */
965 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
967 dev_capa = &(dev_info.capabilities[i]);
968 if (dev_info.capabilities[i].op ==
969 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
970 idx.type = dev_capa->asym.xform_capa.xform_type;
972 capa = rte_cryptodev_asym_capability_get(dev_id,
974 rte_cryptodev_asym_capability_idx *) &idx);
975 print_asym_capa(capa);
982 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
984 struct crypto_testsuite_params *ts_params = &testsuite_params;
985 struct rte_mempool *op_mpool = ts_params->op_mpool;
986 struct rte_mempool *sess_mpool = ts_params->session_mpool;
987 uint8_t dev_id = ts_params->valid_devs[0];
988 struct rte_crypto_asym_op *asym_op = NULL;
989 struct rte_crypto_op *op = NULL, *result_op = NULL;
990 struct rte_cryptodev_asym_session *sess = NULL;
991 int status = TEST_SUCCESS;
992 uint8_t output[TEST_DH_MOD_LEN];
993 struct rte_crypto_asym_xform xform = *xfrm;
994 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
996 sess = rte_cryptodev_asym_session_create(sess_mpool);
999 "line %u FAILED: %s", __LINE__,
1000 "Session creation failed");
1001 status = TEST_FAILED;
1004 /* set up crypto op data structure */
1005 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1008 "line %u FAILED: %s",
1009 __LINE__, "Failed to allocate asymmetric crypto "
1010 "operation struct");
1011 status = TEST_FAILED;
1016 /* Setup a xform and op to generate private key only */
1017 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
1019 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1020 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1021 asym_op->dh.pub_key.data = (uint8_t *)peer;
1022 asym_op->dh.pub_key.length = sizeof(peer);
1023 asym_op->dh.shared_secret.data = output;
1024 asym_op->dh.shared_secret.length = sizeof(output);
1026 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1029 "line %u FAILED: %s",
1030 __LINE__, "unabled to config sym session");
1031 status = TEST_FAILED;
1035 /* attach asymmetric crypto session to crypto operations */
1036 rte_crypto_op_attach_asym_session(op, sess);
1038 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1040 /* Process crypto operation */
1041 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1043 "line %u FAILED: %s",
1044 __LINE__, "Error sending packet for operation");
1045 status = TEST_FAILED;
1049 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1052 if (result_op == NULL) {
1054 "line %u FAILED: %s",
1055 __LINE__, "Failed to process asym crypto op");
1056 status = TEST_FAILED;
1060 debug_hexdump(stdout, "shared secret:",
1061 asym_op->dh.shared_secret.data,
1062 asym_op->dh.shared_secret.length);
1066 rte_cryptodev_asym_session_clear(dev_id, sess);
1067 rte_cryptodev_asym_session_free(sess);
1070 rte_crypto_op_free(op);
1075 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1077 struct crypto_testsuite_params *ts_params = &testsuite_params;
1078 struct rte_mempool *op_mpool = ts_params->op_mpool;
1079 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1080 uint8_t dev_id = ts_params->valid_devs[0];
1081 struct rte_crypto_asym_op *asym_op = NULL;
1082 struct rte_crypto_op *op = NULL, *result_op = NULL;
1083 struct rte_cryptodev_asym_session *sess = NULL;
1084 int status = TEST_SUCCESS;
1085 uint8_t output[TEST_DH_MOD_LEN];
1086 struct rte_crypto_asym_xform xform = *xfrm;
1088 sess = rte_cryptodev_asym_session_create(sess_mpool);
1091 "line %u FAILED: %s", __LINE__,
1092 "Session creation failed");
1093 status = TEST_FAILED;
1096 /* set up crypto op data structure */
1097 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1100 "line %u FAILED: %s",
1101 __LINE__, "Failed to allocate asymmetric crypto "
1102 "operation struct");
1103 status = TEST_FAILED;
1108 /* Setup a xform and op to generate private key only */
1109 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1111 asym_op->dh.priv_key.data = output;
1112 asym_op->dh.priv_key.length = sizeof(output);
1114 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1117 "line %u FAILED: %s",
1118 __LINE__, "unabled to config sym session");
1119 status = TEST_FAILED;
1123 /* attach asymmetric crypto session to crypto operations */
1124 rte_crypto_op_attach_asym_session(op, sess);
1126 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1128 /* Process crypto operation */
1129 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1131 "line %u FAILED: %s",
1132 __LINE__, "Error sending packet for operation");
1133 status = TEST_FAILED;
1137 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1140 if (result_op == NULL) {
1142 "line %u FAILED: %s",
1143 __LINE__, "Failed to process asym crypto op");
1144 status = TEST_FAILED;
1148 debug_hexdump(stdout, "private key:",
1149 asym_op->dh.priv_key.data,
1150 asym_op->dh.priv_key.length);
1155 rte_cryptodev_asym_session_clear(dev_id, sess);
1156 rte_cryptodev_asym_session_free(sess);
1159 rte_crypto_op_free(op);
1166 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1168 struct crypto_testsuite_params *ts_params = &testsuite_params;
1169 struct rte_mempool *op_mpool = ts_params->op_mpool;
1170 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1171 uint8_t dev_id = ts_params->valid_devs[0];
1172 struct rte_crypto_asym_op *asym_op = NULL;
1173 struct rte_crypto_op *op = NULL, *result_op = NULL;
1174 struct rte_cryptodev_asym_session *sess = NULL;
1175 int status = TEST_SUCCESS;
1176 uint8_t output[TEST_DH_MOD_LEN];
1177 struct rte_crypto_asym_xform xform = *xfrm;
1179 sess = rte_cryptodev_asym_session_create(sess_mpool);
1182 "line %u FAILED: %s", __LINE__,
1183 "Session creation failed");
1184 status = TEST_FAILED;
1187 /* set up crypto op data structure */
1188 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1191 "line %u FAILED: %s",
1192 __LINE__, "Failed to allocate asymmetric crypto "
1193 "operation struct");
1194 status = TEST_FAILED;
1198 /* Setup a xform chain to generate public key
1199 * using test private key
1202 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1205 asym_op->dh.pub_key.data = output;
1206 asym_op->dh.pub_key.length = sizeof(output);
1207 /* load pre-defined private key */
1208 asym_op->dh.priv_key.data = rte_malloc(NULL,
1209 dh_test_params.priv_key.length,
1211 asym_op->dh.priv_key = dh_test_params.priv_key;
1213 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1216 "line %u FAILED: %s",
1217 __LINE__, "unabled to config sym session");
1218 status = TEST_FAILED;
1222 /* attach asymmetric crypto session to crypto operations */
1223 rte_crypto_op_attach_asym_session(op, sess);
1225 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1227 /* Process crypto operation */
1228 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1230 "line %u FAILED: %s",
1231 __LINE__, "Error sending packet for operation");
1232 status = TEST_FAILED;
1236 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1239 if (result_op == NULL) {
1241 "line %u FAILED: %s",
1242 __LINE__, "Failed to process asym crypto op");
1243 status = TEST_FAILED;
1247 debug_hexdump(stdout, "pub key:",
1248 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1250 debug_hexdump(stdout, "priv key:",
1251 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1255 rte_cryptodev_asym_session_clear(dev_id, sess);
1256 rte_cryptodev_asym_session_free(sess);
1259 rte_crypto_op_free(op);
1265 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1267 struct crypto_testsuite_params *ts_params = &testsuite_params;
1268 struct rte_mempool *op_mpool = ts_params->op_mpool;
1269 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1270 uint8_t dev_id = ts_params->valid_devs[0];
1271 struct rte_crypto_asym_op *asym_op = NULL;
1272 struct rte_crypto_op *op = NULL, *result_op = NULL;
1273 struct rte_cryptodev_asym_session *sess = NULL;
1274 int status = TEST_SUCCESS;
1275 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1276 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1277 struct rte_crypto_asym_xform pub_key_xform;
1278 struct rte_crypto_asym_xform xform = *xfrm;
1280 sess = rte_cryptodev_asym_session_create(sess_mpool);
1283 "line %u FAILED: %s", __LINE__,
1284 "Session creation failed");
1285 status = TEST_FAILED;
1289 /* set up crypto op data structure */
1290 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1293 "line %u FAILED: %s",
1294 __LINE__, "Failed to allocate asymmetric crypto "
1295 "operation struct");
1296 status = TEST_FAILED;
1300 /* Setup a xform chain to generate
1301 * private key first followed by
1303 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1304 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1305 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1306 xform.next = &pub_key_xform;
1308 asym_op->dh.pub_key.data = out_pub_key;
1309 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1310 asym_op->dh.priv_key.data = out_prv_key;
1311 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1312 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1315 "line %u FAILED: %s",
1316 __LINE__, "unabled to config sym session");
1317 status = TEST_FAILED;
1321 /* attach asymmetric crypto session to crypto operations */
1322 rte_crypto_op_attach_asym_session(op, sess);
1324 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1326 /* Process crypto operation */
1327 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1329 "line %u FAILED: %s",
1330 __LINE__, "Error sending packet for operation");
1331 status = TEST_FAILED;
1335 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1338 if (result_op == NULL) {
1340 "line %u FAILED: %s",
1341 __LINE__, "Failed to process asym crypto op");
1342 status = TEST_FAILED;
1345 debug_hexdump(stdout, "priv key:",
1346 out_prv_key, asym_op->dh.priv_key.length);
1347 debug_hexdump(stdout, "pub key:",
1348 out_pub_key, asym_op->dh.pub_key.length);
1352 rte_cryptodev_asym_session_clear(dev_id, sess);
1353 rte_cryptodev_asym_session_free(sess);
1356 rte_crypto_op_free(op);
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(
1379 &modinv_xform.xform_type, "modinv") < 0) {
1381 "Invalid ASYM algorithm specified\n");
1385 cap_idx.type = modinv_xform.xform_type;
1386 capability = rte_cryptodev_asym_capability_get(dev_id,
1389 if (capability == NULL) {
1390 RTE_LOG(INFO, USER1,
1391 "Device doesn't support MOD INV. Test Skipped\n");
1395 if (rte_cryptodev_asym_xform_capability_check_modlen(
1397 modinv_xform.modinv.modulus.length)) {
1399 "Invalid MODULUS length specified\n");
1403 sess = rte_cryptodev_asym_session_create(sess_mpool);
1405 RTE_LOG(ERR, USER1, "line %u "
1406 "FAILED: %s", __LINE__,
1407 "Session creation failed");
1408 status = TEST_FAILED;
1412 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1415 "line %u FAILED: %s",
1416 __LINE__, "unabled to config sym session");
1417 status = TEST_FAILED;
1421 /* generate crypto op data structure */
1422 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1425 "line %u FAILED: %s",
1426 __LINE__, "Failed to allocate asymmetric crypto "
1427 "operation struct");
1428 status = TEST_FAILED;
1433 memcpy(input, base, sizeof(base));
1434 asym_op->modinv.base.data = input;
1435 asym_op->modinv.base.length = sizeof(base);
1436 asym_op->modinv.result.data = result;
1437 asym_op->modinv.result.length = sizeof(result);
1439 /* attach asymmetric crypto session to crypto operations */
1440 rte_crypto_op_attach_asym_session(op, sess);
1442 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1444 /* Process crypto operation */
1445 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1447 "line %u FAILED: %s",
1448 __LINE__, "Error sending packet for operation");
1449 status = TEST_FAILED;
1453 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1456 if (result_op == NULL) {
1458 "line %u FAILED: %s",
1459 __LINE__, "Failed to process asym crypto op");
1460 status = TEST_FAILED;
1464 ret = verify_modinv(mod_inv, result_op);
1467 "operation verification failed\n");
1468 status = TEST_FAILED;
1473 rte_cryptodev_asym_session_clear(dev_id, sess);
1474 rte_cryptodev_asym_session_free(sess);
1478 rte_crypto_op_free(op);
1480 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1488 struct crypto_testsuite_params *ts_params = &testsuite_params;
1489 struct rte_mempool *op_mpool = ts_params->op_mpool;
1490 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1491 uint8_t dev_id = ts_params->valid_devs[0];
1492 struct rte_crypto_asym_op *asym_op = NULL;
1493 struct rte_crypto_op *op = NULL, *result_op = NULL;
1494 struct rte_cryptodev_asym_session *sess = NULL;
1495 int status = TEST_SUCCESS;
1496 struct rte_cryptodev_asym_capability_idx cap_idx;
1497 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1498 uint8_t input[TEST_DATA_SIZE] = {0};
1500 uint8_t result[sizeof(mod_p)] = { 0 };
1502 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1506 "Invalid ASYM algorithm specified\n");
1510 /* check for modlen capability */
1511 cap_idx.type = modex_xform.xform_type;
1512 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1514 if (capability == NULL) {
1515 RTE_LOG(INFO, USER1,
1516 "Device doesn't support MOD EXP. Test Skipped\n");
1520 if (rte_cryptodev_asym_xform_capability_check_modlen(
1521 capability, modex_xform.modex.modulus.length)) {
1523 "Invalid MODULUS length specified\n");
1527 /* generate crypto op data structure */
1528 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1531 "line %u FAILED: %s",
1532 __LINE__, "Failed to allocate asymmetric crypto "
1533 "operation struct");
1534 status = TEST_FAILED;
1538 sess = rte_cryptodev_asym_session_create(sess_mpool);
1542 "FAILED: %s", __LINE__,
1543 "Session creation failed");
1544 status = TEST_FAILED;
1548 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1551 "line %u FAILED: %s",
1552 __LINE__, "unabled to config sym session");
1553 status = TEST_FAILED;
1558 memcpy(input, base, sizeof(base));
1559 asym_op->modex.base.data = input;
1560 asym_op->modex.base.length = sizeof(base);
1561 asym_op->modex.result.data = result;
1562 asym_op->modex.result.length = sizeof(result);
1563 /* attach asymmetric crypto session to crypto operations */
1564 rte_crypto_op_attach_asym_session(op, sess);
1566 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1567 /* Process crypto operation */
1568 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1570 "line %u FAILED: %s",
1571 __LINE__, "Error sending packet for operation");
1572 status = TEST_FAILED;
1576 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1579 if (result_op == NULL) {
1581 "line %u FAILED: %s",
1582 __LINE__, "Failed to process asym crypto op");
1583 status = TEST_FAILED;
1587 ret = verify_modexp(mod_exp, result_op);
1590 "operation verification failed\n");
1591 status = TEST_FAILED;
1596 rte_cryptodev_asym_session_clear(dev_id, sess);
1597 rte_cryptodev_asym_session_free(sess);
1601 rte_crypto_op_free(op);
1603 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1609 test_dh_keygenration(void)
1613 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1614 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1615 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1616 dh_test_params.priv_key.length);
1618 RTE_LOG(INFO, USER1,
1619 "Test Public and Private key pair generation\n");
1621 status = test_dh_gen_kp(&dh_xform);
1622 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1624 RTE_LOG(INFO, USER1,
1625 "Test Public Key Generation using pre-defined priv key\n");
1627 status = test_dh_gen_pub_key(&dh_xform);
1628 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1630 RTE_LOG(INFO, USER1,
1631 "Test Private Key Generation only\n");
1633 status = test_dh_gen_priv_key(&dh_xform);
1634 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1636 RTE_LOG(INFO, USER1,
1637 "Test shared secret compute\n");
1639 status = test_dh_gen_shared_sec(&dh_xform);
1640 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1648 struct crypto_testsuite_params *ts_params = &testsuite_params;
1649 struct rte_mempool *op_mpool = ts_params->op_mpool;
1650 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1651 uint8_t dev_id = ts_params->valid_devs[0];
1652 struct rte_crypto_asym_op *asym_op = NULL;
1653 struct rte_crypto_op *op = NULL, *result_op = NULL;
1654 struct rte_cryptodev_asym_session *sess = NULL;
1655 int status = TEST_SUCCESS;
1656 uint8_t r[TEST_DH_MOD_LEN];
1657 uint8_t s[TEST_DH_MOD_LEN];
1658 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1660 sess = rte_cryptodev_asym_session_create(sess_mpool);
1663 "line %u FAILED: %s", __LINE__,
1664 "Session creation failed");
1665 status = TEST_FAILED;
1668 /* set up crypto op data structure */
1669 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1672 "line %u FAILED: %s",
1673 __LINE__, "Failed to allocate asymmetric crypto "
1674 "operation struct");
1675 status = TEST_FAILED;
1680 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1681 dsa_xform.dsa.p.length);
1682 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1683 dsa_xform.dsa.q.length);
1684 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1685 dsa_xform.dsa.g.length);
1686 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1687 dsa_xform.dsa.x.length);
1689 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1692 "line %u FAILED: %s",
1693 __LINE__, "unabled to config sym session");
1694 status = TEST_FAILED;
1698 /* attach asymmetric crypto session to crypto operations */
1699 rte_crypto_op_attach_asym_session(op, sess);
1700 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1701 asym_op->dsa.message.data = dgst;
1702 asym_op->dsa.message.length = sizeof(dgst);
1703 asym_op->dsa.r.length = sizeof(r);
1704 asym_op->dsa.r.data = r;
1705 asym_op->dsa.s.length = sizeof(s);
1706 asym_op->dsa.s.data = s;
1708 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1710 /* Process crypto operation */
1711 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1713 "line %u FAILED: %s",
1714 __LINE__, "Error sending packet for operation");
1715 status = TEST_FAILED;
1719 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1722 if (result_op == NULL) {
1724 "line %u FAILED: %s",
1725 __LINE__, "Failed to process asym crypto op");
1726 status = TEST_FAILED;
1730 asym_op = result_op->asym;
1732 debug_hexdump(stdout, "r:",
1733 asym_op->dsa.r.data, asym_op->dsa.r.length);
1734 debug_hexdump(stdout, "s:",
1735 asym_op->dsa.s.data, asym_op->dsa.s.length);
1737 /* Test PMD DSA sign verification using signer public key */
1738 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1740 /* copy signer public key */
1741 asym_op->dsa.y.data = dsa_test_params.y.data;
1742 asym_op->dsa.y.length = dsa_test_params.y.length;
1744 /* Process crypto operation */
1745 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1747 "line %u FAILED: %s",
1748 __LINE__, "Error sending packet for operation");
1749 status = TEST_FAILED;
1753 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1756 if (result_op == NULL) {
1758 "line %u FAILED: %s",
1759 __LINE__, "Failed to process asym crypto op");
1760 status = TEST_FAILED;
1764 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1766 "line %u FAILED: %s",
1767 __LINE__, "Failed to process asym crypto op");
1768 status = TEST_FAILED;
1772 rte_cryptodev_asym_session_clear(dev_id, sess);
1773 rte_cryptodev_asym_session_free(sess);
1776 rte_crypto_op_free(op);
1784 status = test_dsa_sign();
1785 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1790 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1791 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1792 .setup = testsuite_setup,
1793 .teardown = testsuite_teardown,
1794 .unit_test_cases = {
1795 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1796 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1797 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1798 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1799 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1800 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1801 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1802 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1803 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1804 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1805 TEST_CASES_END() /**< NULL terminate unit test array */
1809 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1810 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1811 .setup = testsuite_setup,
1812 .teardown = testsuite_teardown,
1813 .unit_test_cases = {
1814 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1815 TEST_CASES_END() /**< NULL terminate unit test array */
1819 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
1820 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
1821 .setup = testsuite_setup,
1822 .teardown = testsuite_teardown,
1823 .unit_test_cases = {
1824 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1825 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1826 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1827 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1828 TEST_CASES_END() /**< NULL terminate unit test array */
1833 test_cryptodev_openssl_asym(void)
1835 gbl_driver_id = rte_cryptodev_driver_id_get(
1836 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1838 if (gbl_driver_id == -1) {
1839 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1840 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1841 "in config file to run this testsuite.\n");
1845 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1849 test_cryptodev_qat_asym(void)
1851 gbl_driver_id = rte_cryptodev_driver_id_get(
1852 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1854 if (gbl_driver_id == -1) {
1855 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1856 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1857 "in config file to run this testsuite.\n");
1861 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1865 test_cryptodev_octeontx_asym(void)
1867 gbl_driver_id = rte_cryptodev_driver_id_get(
1868 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
1869 if (gbl_driver_id == -1) {
1870 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
1871 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
1872 "enabled in config file to run this "
1876 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
1880 test_cryptodev_octeontx2_asym(void)
1882 gbl_driver_id = rte_cryptodev_driver_id_get(
1883 RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
1884 if (gbl_driver_id == -1) {
1885 RTE_LOG(ERR, USER1, "OCTEONTX2 PMD must be loaded. Check if "
1886 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX2_CRYPTO is "
1887 "enabled in config file to run this "
1892 /* Use test suite registered for crypto_octeontx PMD */
1893 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
1896 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1897 test_cryptodev_openssl_asym);
1899 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
1901 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
1902 test_cryptodev_octeontx_asym);
1904 REGISTER_TEST_COMMAND(cryptodev_octeontx2_asym_autotest,
1905 test_cryptodev_octeontx2_asym);