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 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
714 struct rte_cryptodev_info info;
715 int ret, dev_id = -1;
719 memset(ts_params, 0, sizeof(*ts_params));
721 test_vector.size = 0;
724 ts_params->op_mpool = rte_crypto_op_pool_create(
725 "CRYPTO_ASYM_OP_POOL",
726 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
730 if (ts_params->op_mpool == NULL) {
731 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
735 /* Create an OPENSSL device if required */
736 if (gbl_driver_id == rte_cryptodev_driver_id_get(
737 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
738 nb_devs = rte_cryptodev_device_count_by_driver(
739 rte_cryptodev_driver_id_get(
740 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
743 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
746 TEST_ASSERT(ret == 0, "Failed to create "
747 "instance of pmd : %s",
748 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
752 /* Get list of valid crypto devs */
753 nb_devs = rte_cryptodev_devices_get(
754 rte_cryptodev_driver_name_get(gbl_driver_id),
755 valid_devs, RTE_CRYPTO_MAX_DEVS);
757 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
762 * Get first valid asymmetric device found in test suite param and
765 for (i = 0; i < nb_devs ; i++) {
766 rte_cryptodev_info_get(valid_devs[i], &info);
767 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
768 dev_id = ts_params->valid_devs[0] = valid_devs[i];
774 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
779 /* Set valid device count */
780 ts_params->valid_dev_count = nb_devs;
782 /* configure device with num qp */
783 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
784 ts_params->conf.socket_id = SOCKET_ID_ANY;
785 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
786 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
787 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
789 "Failed to configure cryptodev %u with %u qps",
790 dev_id, ts_params->conf.nb_queue_pairs);
793 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
794 ts_params->qp_conf.mp_session = ts_params->session_mpool;
795 ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
796 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
797 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
798 dev_id, qp_id, &ts_params->qp_conf,
799 rte_cryptodev_socket_id(dev_id)),
800 "Failed to setup queue pair %u on cryptodev %u ASYM",
804 /* setup asym session pool */
805 unsigned int session_size =
806 rte_cryptodev_asym_get_private_session_size(dev_id);
808 * Create mempool with TEST_NUM_SESSIONS * 2,
809 * to include the session headers
811 ts_params->session_mpool = rte_mempool_create(
813 TEST_NUM_SESSIONS * 2,
815 0, 0, NULL, NULL, NULL,
819 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
820 "session mempool allocation failed");
826 testsuite_teardown(void)
828 struct crypto_testsuite_params *ts_params = &testsuite_params;
830 if (ts_params->op_mpool != NULL) {
831 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
832 rte_mempool_avail_count(ts_params->op_mpool));
835 /* Free session mempools */
836 if (ts_params->session_mpool != NULL) {
837 rte_mempool_free(ts_params->session_mpool);
838 ts_params->session_mpool = NULL;
845 struct crypto_testsuite_params *ts_params = &testsuite_params;
849 /* Reconfigure device to default parameters */
850 ts_params->conf.socket_id = SOCKET_ID_ANY;
852 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
854 "Failed to configure cryptodev %u",
855 ts_params->valid_devs[0]);
857 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
858 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
859 ts_params->valid_devs[0], qp_id,
861 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
862 "Failed to setup queue pair %u on cryptodev %u",
863 qp_id, ts_params->valid_devs[0]);
866 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
868 /* Start the device */
869 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
870 "Failed to start cryptodev %u",
871 ts_params->valid_devs[0]);
879 struct crypto_testsuite_params *ts_params = &testsuite_params;
880 struct rte_cryptodev_stats stats;
882 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
884 /* Stop the device */
885 rte_cryptodev_stop(ts_params->valid_devs[0]);
888 static inline void print_asym_capa(
889 const struct rte_cryptodev_asymmetric_xform_capability *capa)
893 printf("\nxform type: %s\n===================\n",
894 rte_crypto_asym_xform_strings[capa->xform_type]);
895 printf("operation supported -");
897 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
898 /* check supported operations */
899 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
901 rte_crypto_asym_op_strings[i]);
903 switch (capa->xform_type) {
904 case RTE_CRYPTO_ASYM_XFORM_RSA:
905 case RTE_CRYPTO_ASYM_XFORM_MODINV:
906 case RTE_CRYPTO_ASYM_XFORM_MODEX:
907 case RTE_CRYPTO_ASYM_XFORM_DH:
908 case RTE_CRYPTO_ASYM_XFORM_DSA:
909 printf(" modlen: min %d max %d increment %d\n",
912 capa->modlen.increment);
920 test_capability(void)
922 struct crypto_testsuite_params *ts_params = &testsuite_params;
923 uint8_t dev_id = ts_params->valid_devs[0];
924 struct rte_cryptodev_info dev_info;
925 const struct rte_cryptodev_capabilities *dev_capa;
927 struct rte_cryptodev_asym_capability_idx idx;
928 const struct rte_cryptodev_asymmetric_xform_capability *capa;
930 rte_cryptodev_info_get(dev_id, &dev_info);
931 if (!(dev_info.feature_flags &
932 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
934 "Device doesn't support asymmetric. Test Skipped\n");
938 /* print xform capability */
940 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
942 dev_capa = &(dev_info.capabilities[i]);
943 if (dev_info.capabilities[i].op ==
944 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
945 idx.type = dev_capa->asym.xform_capa.xform_type;
947 capa = rte_cryptodev_asym_capability_get(dev_id,
949 rte_cryptodev_asym_capability_idx *) &idx);
950 print_asym_capa(capa);
957 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
959 struct crypto_testsuite_params *ts_params = &testsuite_params;
960 struct rte_mempool *op_mpool = ts_params->op_mpool;
961 struct rte_mempool *sess_mpool = ts_params->session_mpool;
962 uint8_t dev_id = ts_params->valid_devs[0];
963 struct rte_crypto_asym_op *asym_op = NULL;
964 struct rte_crypto_op *op = NULL, *result_op = NULL;
965 struct rte_cryptodev_asym_session *sess = NULL;
966 int status = TEST_SUCCESS;
967 uint8_t output[TEST_DH_MOD_LEN];
968 struct rte_crypto_asym_xform xform = *xfrm;
969 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
971 sess = rte_cryptodev_asym_session_create(sess_mpool);
974 "line %u FAILED: %s", __LINE__,
975 "Session creation failed");
976 status = TEST_FAILED;
979 /* set up crypto op data structure */
980 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
983 "line %u FAILED: %s",
984 __LINE__, "Failed to allocate asymmetric crypto "
986 status = TEST_FAILED;
991 /* Setup a xform and op to generate private key only */
992 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
994 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
995 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
996 asym_op->dh.pub_key.data = (uint8_t *)peer;
997 asym_op->dh.pub_key.length = sizeof(peer);
998 asym_op->dh.shared_secret.data = output;
999 asym_op->dh.shared_secret.length = sizeof(output);
1001 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1004 "line %u FAILED: %s",
1005 __LINE__, "unabled to config sym session");
1006 status = TEST_FAILED;
1010 /* attach asymmetric crypto session to crypto operations */
1011 rte_crypto_op_attach_asym_session(op, sess);
1013 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1015 /* Process crypto operation */
1016 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1018 "line %u FAILED: %s",
1019 __LINE__, "Error sending packet for operation");
1020 status = TEST_FAILED;
1024 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1027 if (result_op == NULL) {
1029 "line %u FAILED: %s",
1030 __LINE__, "Failed to process asym crypto op");
1031 status = TEST_FAILED;
1035 debug_hexdump(stdout, "shared secret:",
1036 asym_op->dh.shared_secret.data,
1037 asym_op->dh.shared_secret.length);
1041 rte_cryptodev_asym_session_clear(dev_id, sess);
1042 rte_cryptodev_asym_session_free(sess);
1045 rte_crypto_op_free(op);
1050 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1052 struct crypto_testsuite_params *ts_params = &testsuite_params;
1053 struct rte_mempool *op_mpool = ts_params->op_mpool;
1054 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1055 uint8_t dev_id = ts_params->valid_devs[0];
1056 struct rte_crypto_asym_op *asym_op = NULL;
1057 struct rte_crypto_op *op = NULL, *result_op = NULL;
1058 struct rte_cryptodev_asym_session *sess = NULL;
1059 int status = TEST_SUCCESS;
1060 uint8_t output[TEST_DH_MOD_LEN];
1061 struct rte_crypto_asym_xform xform = *xfrm;
1063 sess = rte_cryptodev_asym_session_create(sess_mpool);
1066 "line %u FAILED: %s", __LINE__,
1067 "Session creation failed");
1068 status = TEST_FAILED;
1071 /* set up crypto op data structure */
1072 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1075 "line %u FAILED: %s",
1076 __LINE__, "Failed to allocate asymmetric crypto "
1077 "operation struct");
1078 status = TEST_FAILED;
1083 /* Setup a xform and op to generate private key only */
1084 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1086 asym_op->dh.priv_key.data = output;
1087 asym_op->dh.priv_key.length = sizeof(output);
1089 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1092 "line %u FAILED: %s",
1093 __LINE__, "unabled to config sym session");
1094 status = TEST_FAILED;
1098 /* attach asymmetric crypto session to crypto operations */
1099 rte_crypto_op_attach_asym_session(op, sess);
1101 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1103 /* Process crypto operation */
1104 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1106 "line %u FAILED: %s",
1107 __LINE__, "Error sending packet for operation");
1108 status = TEST_FAILED;
1112 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1115 if (result_op == NULL) {
1117 "line %u FAILED: %s",
1118 __LINE__, "Failed to process asym crypto op");
1119 status = TEST_FAILED;
1123 debug_hexdump(stdout, "private key:",
1124 asym_op->dh.priv_key.data,
1125 asym_op->dh.priv_key.length);
1130 rte_cryptodev_asym_session_clear(dev_id, sess);
1131 rte_cryptodev_asym_session_free(sess);
1134 rte_crypto_op_free(op);
1141 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1143 struct crypto_testsuite_params *ts_params = &testsuite_params;
1144 struct rte_mempool *op_mpool = ts_params->op_mpool;
1145 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1146 uint8_t dev_id = ts_params->valid_devs[0];
1147 struct rte_crypto_asym_op *asym_op = NULL;
1148 struct rte_crypto_op *op = NULL, *result_op = NULL;
1149 struct rte_cryptodev_asym_session *sess = NULL;
1150 int status = TEST_SUCCESS;
1151 uint8_t output[TEST_DH_MOD_LEN];
1152 struct rte_crypto_asym_xform xform = *xfrm;
1154 sess = rte_cryptodev_asym_session_create(sess_mpool);
1157 "line %u FAILED: %s", __LINE__,
1158 "Session creation failed");
1159 status = TEST_FAILED;
1162 /* set up crypto op data structure */
1163 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1166 "line %u FAILED: %s",
1167 __LINE__, "Failed to allocate asymmetric crypto "
1168 "operation struct");
1169 status = TEST_FAILED;
1173 /* Setup a xform chain to generate public key
1174 * using test private key
1177 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1180 asym_op->dh.pub_key.data = output;
1181 asym_op->dh.pub_key.length = sizeof(output);
1182 /* load pre-defined private key */
1183 asym_op->dh.priv_key.data = rte_malloc(NULL,
1184 dh_test_params.priv_key.length,
1186 asym_op->dh.priv_key = dh_test_params.priv_key;
1188 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1191 "line %u FAILED: %s",
1192 __LINE__, "unabled to config sym session");
1193 status = TEST_FAILED;
1197 /* attach asymmetric crypto session to crypto operations */
1198 rte_crypto_op_attach_asym_session(op, sess);
1200 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1202 /* Process crypto operation */
1203 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1205 "line %u FAILED: %s",
1206 __LINE__, "Error sending packet for operation");
1207 status = TEST_FAILED;
1211 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1214 if (result_op == NULL) {
1216 "line %u FAILED: %s",
1217 __LINE__, "Failed to process asym crypto op");
1218 status = TEST_FAILED;
1222 debug_hexdump(stdout, "pub key:",
1223 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1225 debug_hexdump(stdout, "priv key:",
1226 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1230 rte_cryptodev_asym_session_clear(dev_id, sess);
1231 rte_cryptodev_asym_session_free(sess);
1234 rte_crypto_op_free(op);
1240 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1242 struct crypto_testsuite_params *ts_params = &testsuite_params;
1243 struct rte_mempool *op_mpool = ts_params->op_mpool;
1244 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1245 uint8_t dev_id = ts_params->valid_devs[0];
1246 struct rte_crypto_asym_op *asym_op = NULL;
1247 struct rte_crypto_op *op = NULL, *result_op = NULL;
1248 struct rte_cryptodev_asym_session *sess = NULL;
1249 int status = TEST_SUCCESS;
1250 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1251 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1252 struct rte_crypto_asym_xform pub_key_xform;
1253 struct rte_crypto_asym_xform xform = *xfrm;
1255 sess = rte_cryptodev_asym_session_create(sess_mpool);
1258 "line %u FAILED: %s", __LINE__,
1259 "Session creation failed");
1260 status = TEST_FAILED;
1264 /* set up crypto op data structure */
1265 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1268 "line %u FAILED: %s",
1269 __LINE__, "Failed to allocate asymmetric crypto "
1270 "operation struct");
1271 status = TEST_FAILED;
1275 /* Setup a xform chain to generate
1276 * private key first followed by
1278 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1279 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1280 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1281 xform.next = &pub_key_xform;
1283 asym_op->dh.pub_key.data = out_pub_key;
1284 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1285 asym_op->dh.priv_key.data = out_prv_key;
1286 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1287 if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1290 "line %u FAILED: %s",
1291 __LINE__, "unabled to config sym session");
1292 status = TEST_FAILED;
1296 /* attach asymmetric crypto session to crypto operations */
1297 rte_crypto_op_attach_asym_session(op, sess);
1299 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1301 /* Process crypto operation */
1302 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1304 "line %u FAILED: %s",
1305 __LINE__, "Error sending packet for operation");
1306 status = TEST_FAILED;
1310 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1313 if (result_op == NULL) {
1315 "line %u FAILED: %s",
1316 __LINE__, "Failed to process asym crypto op");
1317 status = TEST_FAILED;
1320 debug_hexdump(stdout, "priv key:",
1321 out_prv_key, asym_op->dh.priv_key.length);
1322 debug_hexdump(stdout, "pub key:",
1323 out_pub_key, asym_op->dh.pub_key.length);
1327 rte_cryptodev_asym_session_clear(dev_id, sess);
1328 rte_cryptodev_asym_session_free(sess);
1331 rte_crypto_op_free(op);
1339 struct crypto_testsuite_params *ts_params = &testsuite_params;
1340 struct rte_mempool *op_mpool = ts_params->op_mpool;
1341 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1342 uint8_t dev_id = ts_params->valid_devs[0];
1343 struct rte_crypto_asym_op *asym_op = NULL;
1344 struct rte_crypto_op *op = NULL, *result_op = NULL;
1345 struct rte_cryptodev_asym_session *sess = NULL;
1346 int status = TEST_SUCCESS;
1347 struct rte_cryptodev_asym_capability_idx cap_idx;
1348 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1349 uint8_t input[TEST_DATA_SIZE] = {0};
1351 uint8_t result[sizeof(mod_p)] = { 0 };
1353 if (rte_cryptodev_asym_get_xform_enum(
1354 &modinv_xform.xform_type, "modinv") < 0) {
1356 "Invalid ASYM algorithm specified\n");
1360 cap_idx.type = modinv_xform.xform_type;
1361 capability = rte_cryptodev_asym_capability_get(dev_id,
1364 if (capability == NULL) {
1365 RTE_LOG(INFO, USER1,
1366 "Device doesn't support MOD INV. Test Skipped\n");
1370 if (rte_cryptodev_asym_xform_capability_check_modlen(
1372 modinv_xform.modinv.modulus.length)) {
1374 "Invalid MODULUS length specified\n");
1378 sess = rte_cryptodev_asym_session_create(sess_mpool);
1380 RTE_LOG(ERR, USER1, "line %u "
1381 "FAILED: %s", __LINE__,
1382 "Session creation failed");
1383 status = TEST_FAILED;
1387 if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1390 "line %u FAILED: %s",
1391 __LINE__, "unabled to config sym session");
1392 status = TEST_FAILED;
1396 /* generate crypto op data structure */
1397 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1400 "line %u FAILED: %s",
1401 __LINE__, "Failed to allocate asymmetric crypto "
1402 "operation struct");
1403 status = TEST_FAILED;
1408 memcpy(input, base, sizeof(base));
1409 asym_op->modinv.base.data = input;
1410 asym_op->modinv.base.length = sizeof(base);
1411 asym_op->modinv.result.data = result;
1412 asym_op->modinv.result.length = sizeof(result);
1414 /* attach asymmetric crypto session to crypto operations */
1415 rte_crypto_op_attach_asym_session(op, sess);
1417 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1419 /* Process crypto operation */
1420 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1422 "line %u FAILED: %s",
1423 __LINE__, "Error sending packet for operation");
1424 status = TEST_FAILED;
1428 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1431 if (result_op == NULL) {
1433 "line %u FAILED: %s",
1434 __LINE__, "Failed to process asym crypto op");
1435 status = TEST_FAILED;
1439 ret = verify_modinv(mod_inv, result_op);
1442 "operation verification failed\n");
1443 status = TEST_FAILED;
1448 rte_cryptodev_asym_session_clear(dev_id, sess);
1449 rte_cryptodev_asym_session_free(sess);
1453 rte_crypto_op_free(op);
1455 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1463 struct crypto_testsuite_params *ts_params = &testsuite_params;
1464 struct rte_mempool *op_mpool = ts_params->op_mpool;
1465 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1466 uint8_t dev_id = ts_params->valid_devs[0];
1467 struct rte_crypto_asym_op *asym_op = NULL;
1468 struct rte_crypto_op *op = NULL, *result_op = NULL;
1469 struct rte_cryptodev_asym_session *sess = NULL;
1470 int status = TEST_SUCCESS;
1471 struct rte_cryptodev_asym_capability_idx cap_idx;
1472 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1473 uint8_t input[TEST_DATA_SIZE] = {0};
1475 uint8_t result[sizeof(mod_p)] = { 0 };
1477 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1481 "Invalid ASYM algorithm specified\n");
1485 /* check for modlen capability */
1486 cap_idx.type = modex_xform.xform_type;
1487 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1489 if (capability == NULL) {
1490 RTE_LOG(INFO, USER1,
1491 "Device doesn't support MOD EXP. Test Skipped\n");
1495 if (rte_cryptodev_asym_xform_capability_check_modlen(
1496 capability, modex_xform.modex.modulus.length)) {
1498 "Invalid MODULUS length specified\n");
1502 /* generate crypto op data structure */
1503 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1506 "line %u FAILED: %s",
1507 __LINE__, "Failed to allocate asymmetric crypto "
1508 "operation struct");
1509 status = TEST_FAILED;
1513 sess = rte_cryptodev_asym_session_create(sess_mpool);
1517 "FAILED: %s", __LINE__,
1518 "Session creation failed");
1519 status = TEST_FAILED;
1523 if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1526 "line %u FAILED: %s",
1527 __LINE__, "unabled to config sym session");
1528 status = TEST_FAILED;
1533 memcpy(input, base, sizeof(base));
1534 asym_op->modex.base.data = input;
1535 asym_op->modex.base.length = sizeof(base);
1536 asym_op->modex.result.data = result;
1537 asym_op->modex.result.length = sizeof(result);
1538 /* attach asymmetric crypto session to crypto operations */
1539 rte_crypto_op_attach_asym_session(op, sess);
1541 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1542 /* Process crypto operation */
1543 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1545 "line %u FAILED: %s",
1546 __LINE__, "Error sending packet for operation");
1547 status = TEST_FAILED;
1551 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1554 if (result_op == NULL) {
1556 "line %u FAILED: %s",
1557 __LINE__, "Failed to process asym crypto op");
1558 status = TEST_FAILED;
1562 ret = verify_modexp(mod_exp, result_op);
1565 "operation verification failed\n");
1566 status = TEST_FAILED;
1571 rte_cryptodev_asym_session_clear(dev_id, sess);
1572 rte_cryptodev_asym_session_free(sess);
1576 rte_crypto_op_free(op);
1578 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1584 test_dh_keygenration(void)
1588 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1589 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1590 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1591 dh_test_params.priv_key.length);
1593 RTE_LOG(INFO, USER1,
1594 "Test Public and Private key pair generation\n");
1596 status = test_dh_gen_kp(&dh_xform);
1597 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1599 RTE_LOG(INFO, USER1,
1600 "Test Public Key Generation using pre-defined priv key\n");
1602 status = test_dh_gen_pub_key(&dh_xform);
1603 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1605 RTE_LOG(INFO, USER1,
1606 "Test Private Key Generation only\n");
1608 status = test_dh_gen_priv_key(&dh_xform);
1609 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1611 RTE_LOG(INFO, USER1,
1612 "Test shared secret compute\n");
1614 status = test_dh_gen_shared_sec(&dh_xform);
1615 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1623 struct crypto_testsuite_params *ts_params = &testsuite_params;
1624 struct rte_mempool *op_mpool = ts_params->op_mpool;
1625 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1626 uint8_t dev_id = ts_params->valid_devs[0];
1627 struct rte_crypto_asym_op *asym_op = NULL;
1628 struct rte_crypto_op *op = NULL, *result_op = NULL;
1629 struct rte_cryptodev_asym_session *sess = NULL;
1630 int status = TEST_SUCCESS;
1631 uint8_t r[TEST_DH_MOD_LEN];
1632 uint8_t s[TEST_DH_MOD_LEN];
1633 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1635 sess = rte_cryptodev_asym_session_create(sess_mpool);
1638 "line %u FAILED: %s", __LINE__,
1639 "Session creation failed");
1640 status = TEST_FAILED;
1643 /* set up crypto op data structure */
1644 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1647 "line %u FAILED: %s",
1648 __LINE__, "Failed to allocate asymmetric crypto "
1649 "operation struct");
1650 status = TEST_FAILED;
1655 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1656 dsa_xform.dsa.p.length);
1657 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1658 dsa_xform.dsa.q.length);
1659 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1660 dsa_xform.dsa.g.length);
1661 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1662 dsa_xform.dsa.x.length);
1664 if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1667 "line %u FAILED: %s",
1668 __LINE__, "unabled to config sym session");
1669 status = TEST_FAILED;
1673 /* attach asymmetric crypto session to crypto operations */
1674 rte_crypto_op_attach_asym_session(op, sess);
1675 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1676 asym_op->dsa.message.data = dgst;
1677 asym_op->dsa.message.length = sizeof(dgst);
1678 asym_op->dsa.r.length = sizeof(r);
1679 asym_op->dsa.r.data = r;
1680 asym_op->dsa.s.length = sizeof(s);
1681 asym_op->dsa.s.data = s;
1683 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1685 /* Process crypto operation */
1686 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1688 "line %u FAILED: %s",
1689 __LINE__, "Error sending packet for operation");
1690 status = TEST_FAILED;
1694 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1697 if (result_op == NULL) {
1699 "line %u FAILED: %s",
1700 __LINE__, "Failed to process asym crypto op");
1701 status = TEST_FAILED;
1705 asym_op = result_op->asym;
1707 debug_hexdump(stdout, "r:",
1708 asym_op->dsa.r.data, asym_op->dsa.r.length);
1709 debug_hexdump(stdout, "s:",
1710 asym_op->dsa.s.data, asym_op->dsa.s.length);
1712 /* Test PMD DSA sign verification using signer public key */
1713 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1715 /* copy signer public key */
1716 asym_op->dsa.y.data = dsa_test_params.y.data;
1717 asym_op->dsa.y.length = dsa_test_params.y.length;
1719 /* Process crypto operation */
1720 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1722 "line %u FAILED: %s",
1723 __LINE__, "Error sending packet for operation");
1724 status = TEST_FAILED;
1728 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1731 if (result_op == NULL) {
1733 "line %u FAILED: %s",
1734 __LINE__, "Failed to process asym crypto op");
1735 status = TEST_FAILED;
1739 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1741 "line %u FAILED: %s",
1742 __LINE__, "Failed to process asym crypto op");
1743 status = TEST_FAILED;
1747 rte_cryptodev_asym_session_clear(dev_id, sess);
1748 rte_cryptodev_asym_session_free(sess);
1751 rte_crypto_op_free(op);
1759 status = test_dsa_sign();
1760 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1765 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
1766 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1767 .setup = testsuite_setup,
1768 .teardown = testsuite_teardown,
1769 .unit_test_cases = {
1770 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1771 TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1772 TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1773 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1774 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1775 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1776 TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1777 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1778 TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1779 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1780 TEST_CASES_END() /**< NULL terminate unit test array */
1784 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
1785 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1786 .setup = testsuite_setup,
1787 .teardown = testsuite_teardown,
1788 .unit_test_cases = {
1789 TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1790 TEST_CASES_END() /**< NULL terminate unit test array */
1794 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
1795 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
1796 .setup = testsuite_setup,
1797 .teardown = testsuite_teardown,
1798 .unit_test_cases = {
1799 TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
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_exp),
1803 TEST_CASES_END() /**< NULL terminate unit test array */
1808 test_cryptodev_openssl_asym(void)
1810 gbl_driver_id = rte_cryptodev_driver_id_get(
1811 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1813 if (gbl_driver_id == -1) {
1814 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1815 "CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1816 "in config file to run this testsuite.\n");
1820 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1824 test_cryptodev_qat_asym(void)
1826 gbl_driver_id = rte_cryptodev_driver_id_get(
1827 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1829 if (gbl_driver_id == -1) {
1830 RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1831 "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1832 "in config file to run this testsuite.\n");
1836 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1840 test_cryptodev_octeontx_asym(void)
1842 gbl_driver_id = rte_cryptodev_driver_id_get(
1843 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
1844 if (gbl_driver_id == -1) {
1845 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded. Check if "
1846 "CONFIG_RTE_LIBRTE_PMD_OCTEONTX_CRYPTO is "
1847 "enabled in config file to run this "
1851 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
1854 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1855 test_cryptodev_openssl_asym);
1857 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
1859 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
1860 test_cryptodev_octeontx_asym);