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,
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;
385 sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
387 snprintf(test_msg, ASYM_TEST_MSG_LEN,
389 "FAILED: %s", __LINE__,
390 "Session creation failed");
391 status = TEST_FAILED;
395 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
396 ts_params->session_mpool) < 0) {
397 snprintf(test_msg, ASYM_TEST_MSG_LEN,
398 "line %u FAILED: %s",
399 __LINE__, "unabled to config sym session");
400 status = TEST_FAILED;
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) {
410 snprintf(test_msg, ASYM_TEST_MSG_LEN,
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) {
421 snprintf(test_msg, ASYM_TEST_MSG_LEN,
422 "line %u FAILED: %s",
423 __LINE__, "Failed to process asym crypto op");
424 status = TEST_FAILED;
428 if (test_cryptodev_asym_ver(data_tc, result_op) != TEST_SUCCESS) {
429 snprintf(test_msg, ASYM_TEST_MSG_LEN,
430 "line %u FAILED: %s",
431 __LINE__, "Verification failed ");
432 status = TEST_FAILED;
436 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
440 rte_cryptodev_asym_session_clear(dev_id, sess);
441 rte_cryptodev_asym_session_free(sess);
445 rte_crypto_op_free(op);
454 test_one_case(const void *test_case)
456 int status = TEST_SUCCESS;
457 char test_msg[ASYM_TEST_MSG_LEN + 1];
459 /* Map the case to union */
460 union test_case_structure tc;
461 memcpy(&tc, test_case, sizeof(tc));
463 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg);
465 printf(" %u) TestCase %s %s\n", test_index++,
466 tc.modex.description, test_msg);
472 load_test_vectors(void)
474 uint32_t i = 0, v_size = 0;
475 /* Load MODEX vector*/
476 v_size = ARRAY_SIZE(modex_test_case);
477 for (i = 0; i < v_size; i++) {
478 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
479 RTE_LOG(DEBUG, USER1,
480 "TEST_VECTOR_SIZE too small\n");
483 test_vector.address[test_vector.size] = &modex_test_case[i];
486 /* Load MODINV vector*/
487 v_size = ARRAY_SIZE(modinv_test_case);
488 for (i = 0; i < v_size; i++) {
489 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
490 RTE_LOG(DEBUG, USER1,
491 "TEST_VECTOR_SIZE too small\n");
494 test_vector.address[test_vector.size] = &modinv_test_case[i];
501 test_one_by_one(void)
503 int status = TEST_SUCCESS;
506 /* Go through all test cases */
508 for (i = 0; i < test_vector.size; i++) {
509 if (test_one_case(test_vector.address[i]) != TEST_SUCCESS)
510 status = TEST_FAILED;
513 TEST_ASSERT_EQUAL(status, 0, "Test failed");
518 test_rsa_sign_verify(void)
520 struct crypto_testsuite_params *ts_params = &testsuite_params;
521 struct rte_mempool *sess_mpool = ts_params->session_mpool;
522 uint8_t dev_id = ts_params->valid_devs[0];
523 struct rte_cryptodev_asym_session *sess;
524 struct rte_cryptodev_info dev_info;
525 int status = TEST_SUCCESS;
527 /* Test case supports op with exponent key only,
528 * Check in PMD feature flag for RSA exponent key type support.
530 rte_cryptodev_info_get(dev_id, &dev_info);
531 if (!(dev_info.feature_flags &
532 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
533 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
534 "exponent key type. Test Skipped\n");
538 sess = rte_cryptodev_asym_session_create(sess_mpool);
541 RTE_LOG(ERR, USER1, "Session creation failed for "
546 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
548 RTE_LOG(ERR, USER1, "Unable to config asym session for "
550 status = TEST_FAILED;
554 status = queue_ops_rsa_sign_verify(sess);
558 rte_cryptodev_asym_session_clear(dev_id, sess);
559 rte_cryptodev_asym_session_free(sess);
561 TEST_ASSERT_EQUAL(status, 0, "Test failed");
567 test_rsa_enc_dec(void)
569 struct crypto_testsuite_params *ts_params = &testsuite_params;
570 struct rte_mempool *sess_mpool = ts_params->session_mpool;
571 uint8_t dev_id = ts_params->valid_devs[0];
572 struct rte_cryptodev_asym_session *sess;
573 struct rte_cryptodev_info dev_info;
574 int status = TEST_SUCCESS;
576 /* Test case supports op with exponent key only,
577 * Check in PMD feature flag for RSA exponent key type support.
579 rte_cryptodev_info_get(dev_id, &dev_info);
580 if (!(dev_info.feature_flags &
581 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
582 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
583 "exponent key type. Test skipped\n");
587 sess = rte_cryptodev_asym_session_create(sess_mpool);
590 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
594 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
596 RTE_LOG(ERR, USER1, "Unable to config asym session for "
598 status = TEST_FAILED;
602 status = queue_ops_rsa_enc_dec(sess);
606 rte_cryptodev_asym_session_clear(dev_id, sess);
607 rte_cryptodev_asym_session_free(sess);
609 TEST_ASSERT_EQUAL(status, 0, "Test failed");
615 test_rsa_sign_verify_crt(void)
617 struct crypto_testsuite_params *ts_params = &testsuite_params;
618 struct rte_mempool *sess_mpool = ts_params->session_mpool;
619 uint8_t dev_id = ts_params->valid_devs[0];
620 struct rte_cryptodev_asym_session *sess;
621 struct rte_cryptodev_info dev_info;
622 int status = TEST_SUCCESS;
624 /* Test case supports op with quintuple format key only,
625 * Check im PMD feature flag for RSA quintuple key type support.
627 rte_cryptodev_info_get(dev_id, &dev_info);
628 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
629 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
630 "quintuple key type. Test skipped\n");
634 sess = rte_cryptodev_asym_session_create(sess_mpool);
637 RTE_LOG(ERR, USER1, "Session creation failed for "
638 "sign_verify_crt\n");
639 status = TEST_FAILED;
643 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
645 RTE_LOG(ERR, USER1, "Unable to config asym session for "
646 "sign_verify_crt\n");
647 status = TEST_FAILED;
650 status = queue_ops_rsa_sign_verify(sess);
654 rte_cryptodev_asym_session_clear(dev_id, sess);
655 rte_cryptodev_asym_session_free(sess);
657 TEST_ASSERT_EQUAL(status, 0, "Test failed");
663 test_rsa_enc_dec_crt(void)
665 struct crypto_testsuite_params *ts_params = &testsuite_params;
666 struct rte_mempool *sess_mpool = ts_params->session_mpool;
667 uint8_t dev_id = ts_params->valid_devs[0];
668 struct rte_cryptodev_asym_session *sess;
669 struct rte_cryptodev_info dev_info;
670 int status = TEST_SUCCESS;
672 /* Test case supports op with quintuple format key only,
673 * Check in PMD feature flag for RSA quintuple key type support.
675 rte_cryptodev_info_get(dev_id, &dev_info);
676 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
677 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
678 "quintuple key type. Test skipped\n");
682 sess = rte_cryptodev_asym_session_create(sess_mpool);
685 RTE_LOG(ERR, USER1, "Session creation failed for "
690 if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
692 RTE_LOG(ERR, USER1, "Unable to config asym session for "
694 status = TEST_FAILED;
697 status = queue_ops_rsa_enc_dec(sess);
701 rte_cryptodev_asym_session_clear(dev_id, sess);
702 rte_cryptodev_asym_session_free(sess);
704 TEST_ASSERT_EQUAL(status, 0, "Test failed");
710 testsuite_setup(void)
712 struct crypto_testsuite_params *ts_params = &testsuite_params;
713 struct rte_cryptodev_info info;
714 uint32_t i = 0, nb_devs, dev_id;
718 memset(ts_params, 0, sizeof(*ts_params));
720 test_vector.size = 0;
723 ts_params->op_mpool = rte_crypto_op_pool_create(
724 "CRYPTO_ASYM_OP_POOL",
725 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
729 if (ts_params->op_mpool == NULL) {
730 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
734 /* Create an OPENSSL device if required */
735 if (gbl_driver_id == rte_cryptodev_driver_id_get(
736 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
737 nb_devs = rte_cryptodev_device_count_by_driver(
738 rte_cryptodev_driver_id_get(
739 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
742 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
745 TEST_ASSERT(ret == 0, "Failed to create "
746 "instance of pmd : %s",
747 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
751 nb_devs = rte_cryptodev_count();
753 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
757 /* Create list of valid crypto devs */
758 for (i = 0; i < nb_devs; i++) {
759 rte_cryptodev_info_get(i, &info);
760 if (info.driver_id == gbl_driver_id)
761 ts_params->valid_devs[ts_params->valid_dev_count++] = i;
764 if (ts_params->valid_dev_count < 1)
767 /* Set up all the qps on the first of the valid devices found */
769 dev_id = ts_params->valid_devs[0];
771 rte_cryptodev_info_get(dev_id, &info);
773 /* check if device support asymmetric, skip if not */
774 if (!(info.feature_flags &
775 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
776 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
781 /* configure device with num qp */
782 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
783 ts_params->conf.socket_id = SOCKET_ID_ANY;
784 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
785 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
786 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
788 "Failed to configure cryptodev %u with %u qps",
789 dev_id, ts_params->conf.nb_queue_pairs);
792 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
793 ts_params->qp_conf.mp_session = ts_params->session_mpool;
794 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
795 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
796 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
797 dev_id, qp_id, &ts_params->qp_conf,
798 rte_cryptodev_socket_id(dev_id)),
799 "Failed to setup queue pair %u on cryptodev %u ASYM",
803 /* setup asym session pool */
804 unsigned int session_size =
805 rte_cryptodev_asym_get_private_session_size(dev_id);
807 * Create mempool with TEST_NUM_SESSIONS * 2,
808 * to include the session headers
810 ts_params->session_mpool = rte_mempool_create(
812 TEST_NUM_SESSIONS * 2,
814 0, 0, NULL, NULL, NULL,
818 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
819 "session mempool allocation failed");
825 testsuite_teardown(void)
827 struct crypto_testsuite_params *ts_params = &testsuite_params;
829 if (ts_params->op_mpool != NULL) {
830 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
831 rte_mempool_avail_count(ts_params->op_mpool));
834 /* Free session mempools */
835 if (ts_params->session_mpool != NULL) {
836 rte_mempool_free(ts_params->session_mpool);
837 ts_params->session_mpool = NULL;
844 struct crypto_testsuite_params *ts_params = &testsuite_params;
848 /* Reconfigure device to default parameters */
849 ts_params->conf.socket_id = SOCKET_ID_ANY;
851 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
853 "Failed to configure cryptodev %u",
854 ts_params->valid_devs[0]);
856 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
857 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
858 ts_params->valid_devs[0], qp_id,
860 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
861 "Failed to setup queue pair %u on cryptodev %u",
862 qp_id, ts_params->valid_devs[0]);
865 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
867 /* Start the device */
868 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
869 "Failed to start cryptodev %u",
870 ts_params->valid_devs[0]);
878 struct crypto_testsuite_params *ts_params = &testsuite_params;
879 struct rte_cryptodev_stats stats;
881 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
883 /* Stop the device */
884 rte_cryptodev_stop(ts_params->valid_devs[0]);
887 static inline void print_asym_capa(
888 const struct rte_cryptodev_asymmetric_xform_capability *capa)
892 printf("\nxform type: %s\n===================\n",
893 rte_crypto_asym_xform_strings[capa->xform_type]);
894 printf("operation supported -");
896 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
897 /* check supported operations */
898 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
900 rte_crypto_asym_op_strings[i]);
902 switch (capa->xform_type) {
903 case RTE_CRYPTO_ASYM_XFORM_RSA:
904 case RTE_CRYPTO_ASYM_XFORM_MODINV:
905 case RTE_CRYPTO_ASYM_XFORM_MODEX:
906 case RTE_CRYPTO_ASYM_XFORM_DH:
907 case RTE_CRYPTO_ASYM_XFORM_DSA:
908 printf(" modlen: min %d max %d increment %d\n",
911 capa->modlen.increment);
919 test_capability(void)
921 struct crypto_testsuite_params *ts_params = &testsuite_params;
922 uint8_t dev_id = ts_params->valid_devs[0];
923 struct rte_cryptodev_info dev_info;
924 const struct rte_cryptodev_capabilities *dev_capa;
926 struct rte_cryptodev_asym_capability_idx idx;
927 const struct rte_cryptodev_asymmetric_xform_capability *capa;
929 rte_cryptodev_info_get(dev_id, &dev_info);
930 if (!(dev_info.feature_flags &
931 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
933 "Device doesn't support asymmetric. Test Skipped\n");
937 /* print xform capability */
939 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
941 dev_capa = &(dev_info.capabilities[i]);
942 if (dev_info.capabilities[i].op ==
943 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
944 idx.type = dev_capa->asym.xform_capa.xform_type;
946 capa = rte_cryptodev_asym_capability_get(dev_id,
948 rte_cryptodev_asym_capability_idx *) &idx);
949 print_asym_capa(capa);
956 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
958 struct crypto_testsuite_params *ts_params = &testsuite_params;
959 struct rte_mempool *op_mpool = ts_params->op_mpool;
960 struct rte_mempool *sess_mpool = ts_params->session_mpool;
961 uint8_t dev_id = ts_params->valid_devs[0];
962 struct rte_crypto_asym_op *asym_op = NULL;
963 struct rte_crypto_op *op = NULL, *result_op = NULL;
964 struct rte_cryptodev_asym_session *sess = NULL;
965 int status = TEST_SUCCESS;
966 uint8_t output[TEST_DH_MOD_LEN];
967 struct rte_crypto_asym_xform xform = *xfrm;
968 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
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_SHARED_SECRET_COMPUTE;
993 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
994 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
995 asym_op->dh.pub_key.data = (uint8_t *)peer;
996 asym_op->dh.pub_key.length = sizeof(peer);
997 asym_op->dh.shared_secret.data = output;
998 asym_op->dh.shared_secret.length = sizeof(output);
1000 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1003 "line %u FAILED: %s",
1004 __LINE__, "unabled to config sym session");
1005 status = TEST_FAILED;
1009 /* attach asymmetric crypto session to crypto operations */
1010 rte_crypto_op_attach_asym_session(op, sess);
1012 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1014 /* Process crypto operation */
1015 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1017 "line %u FAILED: %s",
1018 __LINE__, "Error sending packet for operation");
1019 status = TEST_FAILED;
1023 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1026 if (result_op == NULL) {
1028 "line %u FAILED: %s",
1029 __LINE__, "Failed to process asym crypto op");
1030 status = TEST_FAILED;
1034 debug_hexdump(stdout, "shared secret:",
1035 asym_op->dh.shared_secret.data,
1036 asym_op->dh.shared_secret.length);
1040 rte_cryptodev_asym_session_clear(dev_id, sess);
1041 rte_cryptodev_asym_session_free(sess);
1044 rte_crypto_op_free(op);
1049 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1051 struct crypto_testsuite_params *ts_params = &testsuite_params;
1052 struct rte_mempool *op_mpool = ts_params->op_mpool;
1053 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1054 uint8_t dev_id = ts_params->valid_devs[0];
1055 struct rte_crypto_asym_op *asym_op = NULL;
1056 struct rte_crypto_op *op = NULL, *result_op = NULL;
1057 struct rte_cryptodev_asym_session *sess = NULL;
1058 int status = TEST_SUCCESS;
1059 uint8_t output[TEST_DH_MOD_LEN];
1060 struct rte_crypto_asym_xform xform = *xfrm;
1062 sess = rte_cryptodev_asym_session_create(sess_mpool);
1065 "line %u FAILED: %s", __LINE__,
1066 "Session creation failed");
1067 status = TEST_FAILED;
1070 /* set up crypto op data structure */
1071 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1074 "line %u FAILED: %s",
1075 __LINE__, "Failed to allocate asymmetric crypto "
1076 "operation struct");
1077 status = TEST_FAILED;
1082 /* Setup a xform and op to generate private key only */
1083 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1085 asym_op->dh.priv_key.data = output;
1086 asym_op->dh.priv_key.length = sizeof(output);
1088 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1091 "line %u FAILED: %s",
1092 __LINE__, "unabled to config sym session");
1093 status = TEST_FAILED;
1097 /* attach asymmetric crypto session to crypto operations */
1098 rte_crypto_op_attach_asym_session(op, sess);
1100 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1102 /* Process crypto operation */
1103 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1105 "line %u FAILED: %s",
1106 __LINE__, "Error sending packet for operation");
1107 status = TEST_FAILED;
1111 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1114 if (result_op == NULL) {
1116 "line %u FAILED: %s",
1117 __LINE__, "Failed to process asym crypto op");
1118 status = TEST_FAILED;
1122 debug_hexdump(stdout, "private key:",
1123 asym_op->dh.priv_key.data,
1124 asym_op->dh.priv_key.length);
1129 rte_cryptodev_asym_session_clear(dev_id, sess);
1130 rte_cryptodev_asym_session_free(sess);
1133 rte_crypto_op_free(op);
1140 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1142 struct crypto_testsuite_params *ts_params = &testsuite_params;
1143 struct rte_mempool *op_mpool = ts_params->op_mpool;
1144 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1145 uint8_t dev_id = ts_params->valid_devs[0];
1146 struct rte_crypto_asym_op *asym_op = NULL;
1147 struct rte_crypto_op *op = NULL, *result_op = NULL;
1148 struct rte_cryptodev_asym_session *sess = NULL;
1149 int status = TEST_SUCCESS;
1150 uint8_t output[TEST_DH_MOD_LEN];
1151 struct rte_crypto_asym_xform xform = *xfrm;
1153 sess = rte_cryptodev_asym_session_create(sess_mpool);
1156 "line %u FAILED: %s", __LINE__,
1157 "Session creation failed");
1158 status = TEST_FAILED;
1161 /* set up crypto op data structure */
1162 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1165 "line %u FAILED: %s",
1166 __LINE__, "Failed to allocate asymmetric crypto "
1167 "operation struct");
1168 status = TEST_FAILED;
1172 /* Setup a xform chain to generate public key
1173 * using test private key
1176 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1179 asym_op->dh.pub_key.data = output;
1180 asym_op->dh.pub_key.length = sizeof(output);
1181 /* load pre-defined private key */
1182 asym_op->dh.priv_key.data = rte_malloc(NULL,
1183 dh_test_params.priv_key.length,
1185 asym_op->dh.priv_key = dh_test_params.priv_key;
1187 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1190 "line %u FAILED: %s",
1191 __LINE__, "unabled to config sym session");
1192 status = TEST_FAILED;
1196 /* attach asymmetric crypto session to crypto operations */
1197 rte_crypto_op_attach_asym_session(op, sess);
1199 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1201 /* Process crypto operation */
1202 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1204 "line %u FAILED: %s",
1205 __LINE__, "Error sending packet for operation");
1206 status = TEST_FAILED;
1210 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1213 if (result_op == NULL) {
1215 "line %u FAILED: %s",
1216 __LINE__, "Failed to process asym crypto op");
1217 status = TEST_FAILED;
1221 debug_hexdump(stdout, "pub key:",
1222 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1224 debug_hexdump(stdout, "priv key:",
1225 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1229 rte_cryptodev_asym_session_clear(dev_id, sess);
1230 rte_cryptodev_asym_session_free(sess);
1233 rte_crypto_op_free(op);
1239 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1241 struct crypto_testsuite_params *ts_params = &testsuite_params;
1242 struct rte_mempool *op_mpool = ts_params->op_mpool;
1243 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1244 uint8_t dev_id = ts_params->valid_devs[0];
1245 struct rte_crypto_asym_op *asym_op = NULL;
1246 struct rte_crypto_op *op = NULL, *result_op = NULL;
1247 struct rte_cryptodev_asym_session *sess = NULL;
1248 int status = TEST_SUCCESS;
1249 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1250 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1251 struct rte_crypto_asym_xform pub_key_xform;
1252 struct rte_crypto_asym_xform xform = *xfrm;
1254 sess = rte_cryptodev_asym_session_create(sess_mpool);
1257 "line %u FAILED: %s", __LINE__,
1258 "Session creation failed");
1259 status = TEST_FAILED;
1263 /* set up crypto op data structure */
1264 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1267 "line %u FAILED: %s",
1268 __LINE__, "Failed to allocate asymmetric crypto "
1269 "operation struct");
1270 status = TEST_FAILED;
1274 /* Setup a xform chain to generate
1275 * private key first followed by
1277 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1278 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1279 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1280 xform.next = &pub_key_xform;
1282 asym_op->dh.pub_key.data = out_pub_key;
1283 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1284 asym_op->dh.priv_key.data = out_prv_key;
1285 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1286 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1289 "line %u FAILED: %s",
1290 __LINE__, "unabled to config sym session");
1291 status = TEST_FAILED;
1295 /* attach asymmetric crypto session to crypto operations */
1296 rte_crypto_op_attach_asym_session(op, sess);
1298 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1300 /* Process crypto operation */
1301 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1303 "line %u FAILED: %s",
1304 __LINE__, "Error sending packet for operation");
1305 status = TEST_FAILED;
1309 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1312 if (result_op == NULL) {
1314 "line %u FAILED: %s",
1315 __LINE__, "Failed to process asym crypto op");
1316 status = TEST_FAILED;
1319 debug_hexdump(stdout, "priv key:",
1320 out_prv_key, asym_op->dh.priv_key.length);
1321 debug_hexdump(stdout, "pub key:",
1322 out_pub_key, asym_op->dh.pub_key.length);
1326 rte_cryptodev_asym_session_clear(dev_id, sess);
1327 rte_cryptodev_asym_session_free(sess);
1330 rte_crypto_op_free(op);
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(
1353 &modinv_xform.xform_type, "modinv") < 0) {
1355 "Invalid ASYM algorithm specified\n");
1359 cap_idx.type = modinv_xform.xform_type;
1360 capability = rte_cryptodev_asym_capability_get(dev_id,
1363 if (capability == NULL) {
1364 RTE_LOG(INFO, USER1,
1365 "Device doesn't support MOD INV. Test Skipped\n");
1369 if (rte_cryptodev_asym_xform_capability_check_modlen(
1371 modinv_xform.modinv.modulus.length)) {
1373 "Invalid MODULUS length specified\n");
1377 sess = rte_cryptodev_asym_session_create(sess_mpool);
1379 RTE_LOG(ERR, USER1, "line %u "
1380 "FAILED: %s", __LINE__,
1381 "Session creation failed");
1382 status = TEST_FAILED;
1386 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1389 "line %u FAILED: %s",
1390 __LINE__, "unabled to config sym session");
1391 status = TEST_FAILED;
1395 /* generate crypto op data structure */
1396 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1399 "line %u FAILED: %s",
1400 __LINE__, "Failed to allocate asymmetric crypto "
1401 "operation struct");
1402 status = TEST_FAILED;
1407 memcpy(input, base, sizeof(base));
1408 asym_op->modinv.base.data = input;
1409 asym_op->modinv.base.length = sizeof(base);
1410 asym_op->modinv.result.data = result;
1411 asym_op->modinv.result.length = sizeof(result);
1413 /* attach asymmetric crypto session to crypto operations */
1414 rte_crypto_op_attach_asym_session(op, sess);
1416 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1418 /* Process crypto operation */
1419 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1421 "line %u FAILED: %s",
1422 __LINE__, "Error sending packet for operation");
1423 status = TEST_FAILED;
1427 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1430 if (result_op == NULL) {
1432 "line %u FAILED: %s",
1433 __LINE__, "Failed to process asym crypto op");
1434 status = TEST_FAILED;
1438 ret = verify_modinv(mod_inv, result_op);
1441 "operation verification failed\n");
1442 status = TEST_FAILED;
1447 rte_cryptodev_asym_session_clear(dev_id, sess);
1448 rte_cryptodev_asym_session_free(sess);
1452 rte_crypto_op_free(op);
1454 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1462 struct crypto_testsuite_params *ts_params = &testsuite_params;
1463 struct rte_mempool *op_mpool = ts_params->op_mpool;
1464 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1465 uint8_t dev_id = ts_params->valid_devs[0];
1466 struct rte_crypto_asym_op *asym_op = NULL;
1467 struct rte_crypto_op *op = NULL, *result_op = NULL;
1468 struct rte_cryptodev_asym_session *sess = NULL;
1469 int status = TEST_SUCCESS;
1470 struct rte_cryptodev_asym_capability_idx cap_idx;
1471 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1472 uint8_t input[TEST_DATA_SIZE] = {0};
1474 uint8_t result[sizeof(mod_p)] = { 0 };
1476 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1480 "Invalid ASYM algorithm specified\n");
1484 /* check for modlen capability */
1485 cap_idx.type = modex_xform.xform_type;
1486 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1488 if (capability == NULL) {
1489 RTE_LOG(INFO, USER1,
1490 "Device doesn't support MOD EXP. Test Skipped\n");
1494 if (rte_cryptodev_asym_xform_capability_check_modlen(
1495 capability, modex_xform.modex.modulus.length)) {
1497 "Invalid MODULUS length specified\n");
1501 /* generate crypto op data structure */
1502 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1505 "line %u FAILED: %s",
1506 __LINE__, "Failed to allocate asymmetric crypto "
1507 "operation struct");
1508 status = TEST_FAILED;
1512 sess = rte_cryptodev_asym_session_create(sess_mpool);
1516 "FAILED: %s", __LINE__,
1517 "Session creation failed");
1518 status = TEST_FAILED;
1522 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1525 "line %u FAILED: %s",
1526 __LINE__, "unabled to config sym session");
1527 status = TEST_FAILED;
1532 memcpy(input, base, sizeof(base));
1533 asym_op->modex.base.data = input;
1534 asym_op->modex.base.length = sizeof(base);
1535 asym_op->modex.result.data = result;
1536 asym_op->modex.result.length = sizeof(result);
1537 /* attach asymmetric crypto session to crypto operations */
1538 rte_crypto_op_attach_asym_session(op, sess);
1540 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1541 /* Process crypto operation */
1542 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1544 "line %u FAILED: %s",
1545 __LINE__, "Error sending packet for operation");
1546 status = TEST_FAILED;
1550 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1553 if (result_op == NULL) {
1555 "line %u FAILED: %s",
1556 __LINE__, "Failed to process asym crypto op");
1557 status = TEST_FAILED;
1561 ret = verify_modexp(mod_exp, result_op);
1564 "operation verification failed\n");
1565 status = TEST_FAILED;
1570 rte_cryptodev_asym_session_clear(dev_id, sess);
1571 rte_cryptodev_asym_session_free(sess);
1575 rte_crypto_op_free(op);
1577 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1583 test_dh_keygenration(void)
1587 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1588 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1589 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1590 dh_test_params.priv_key.length);
1592 RTE_LOG(INFO, USER1,
1593 "Test Public and Private key pair generation\n");
1595 status = test_dh_gen_kp(&dh_xform);
1596 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1598 RTE_LOG(INFO, USER1,
1599 "Test Public Key Generation using pre-defined priv key\n");
1601 status = test_dh_gen_pub_key(&dh_xform);
1602 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1604 RTE_LOG(INFO, USER1,
1605 "Test Private Key Generation only\n");
1607 status = test_dh_gen_priv_key(&dh_xform);
1608 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1610 RTE_LOG(INFO, USER1,
1611 "Test shared secret compute\n");
1613 status = test_dh_gen_shared_sec(&dh_xform);
1614 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1622 struct crypto_testsuite_params *ts_params = &testsuite_params;
1623 struct rte_mempool *op_mpool = ts_params->op_mpool;
1624 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1625 uint8_t dev_id = ts_params->valid_devs[0];
1626 struct rte_crypto_asym_op *asym_op = NULL;
1627 struct rte_crypto_op *op = NULL, *result_op = NULL;
1628 struct rte_cryptodev_asym_session *sess = NULL;
1629 int status = TEST_SUCCESS;
1630 uint8_t r[TEST_DH_MOD_LEN];
1631 uint8_t s[TEST_DH_MOD_LEN];
1632 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1634 sess = rte_cryptodev_asym_session_create(sess_mpool);
1637 "line %u FAILED: %s", __LINE__,
1638 "Session creation failed");
1639 status = TEST_FAILED;
1642 /* set up crypto op data structure */
1643 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1646 "line %u FAILED: %s",
1647 __LINE__, "Failed to allocate asymmetric crypto "
1648 "operation struct");
1649 status = TEST_FAILED;
1654 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1655 dsa_xform.dsa.p.length);
1656 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1657 dsa_xform.dsa.q.length);
1658 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1659 dsa_xform.dsa.g.length);
1660 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1661 dsa_xform.dsa.x.length);
1663 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1666 "line %u FAILED: %s",
1667 __LINE__, "unabled to config sym session");
1668 status = TEST_FAILED;
1672 /* attach asymmetric crypto session to crypto operations */
1673 rte_crypto_op_attach_asym_session(op, sess);
1674 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1675 asym_op->dsa.message.data = dgst;
1676 asym_op->dsa.message.length = sizeof(dgst);
1677 asym_op->dsa.r.length = sizeof(r);
1678 asym_op->dsa.r.data = r;
1679 asym_op->dsa.s.length = sizeof(s);
1680 asym_op->dsa.s.data = s;
1682 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1684 /* Process crypto operation */
1685 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1687 "line %u FAILED: %s",
1688 __LINE__, "Error sending packet for operation");
1689 status = TEST_FAILED;
1693 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1696 if (result_op == NULL) {
1698 "line %u FAILED: %s",
1699 __LINE__, "Failed to process asym crypto op");
1700 status = TEST_FAILED;
1704 asym_op = result_op->asym;
1706 debug_hexdump(stdout, "r:",
1707 asym_op->dsa.r.data, asym_op->dsa.r.length);
1708 debug_hexdump(stdout, "s:",
1709 asym_op->dsa.s.data, asym_op->dsa.s.length);
1711 /* Test PMD DSA sign verification using signer public key */
1712 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1714 /* copy signer public key */
1715 asym_op->dsa.y.data = dsa_test_params.y.data;
1716 asym_op->dsa.y.length = dsa_test_params.y.length;
1718 /* Process crypto operation */
1719 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1721 "line %u FAILED: %s",
1722 __LINE__, "Error sending packet for operation");
1723 status = TEST_FAILED;
1727 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1730 if (result_op == NULL) {
1732 "line %u FAILED: %s",
1733 __LINE__, "Failed to process asym crypto op");
1734 status = TEST_FAILED;
1738 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1740 "line %u FAILED: %s",
1741 __LINE__, "Failed to process asym crypto op");
1742 status = TEST_FAILED;
1746 rte_cryptodev_asym_session_clear(dev_id, sess);
1747 rte_cryptodev_asym_session_free(sess);
1750 rte_crypto_op_free(op);
1758 status = test_dsa_sign();
1759 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1764 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1765 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1766 .setup = testsuite_setup,
1767 .teardown = testsuite_teardown,
1768 .unit_test_cases = {
1769 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1770 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1771 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1772 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1773 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1774 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1775 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1776 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1777 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1778 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1779 TEST_CASES_END() /**< NULL terminate unit test array */
1783 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1784 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1785 .setup = testsuite_setup,
1786 .teardown = testsuite_teardown,
1787 .unit_test_cases = {
1788 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1789 TEST_CASES_END() /**< NULL terminate unit test array */
1794 test_cryptodev_openssl_asym(void)
1796 gbl_driver_id = rte_cryptodev_driver_id_get(
1797 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1799 if (gbl_driver_id == -1) {
1800 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1801 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1802 "in config file to run this testsuite.\n");
1806 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1810 test_cryptodev_qat_asym(void)
1812 gbl_driver_id = rte_cryptodev_driver_id_get(
1813 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1815 if (gbl_driver_id == -1) {
1816 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1817 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1818 "in config file to run this testsuite.\n");
1822 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1825 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1826 test_cryptodev_openssl_asym);
1828 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);