1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium Networks
3 * Copyright (c) 2019 Intel Corporation
6 #ifndef RTE_EXEC_ENV_WINDOWS
8 #include <rte_bus_vdev.h>
9 #include <rte_common.h>
10 #include <rte_hexdump.h>
12 #include <rte_malloc.h>
13 #include <rte_memcpy.h>
14 #include <rte_pause.h>
16 #include <rte_cryptodev.h>
17 #include <rte_crypto.h>
19 #include "test_cryptodev.h"
20 #include "test_cryptodev_dh_test_vectors.h"
21 #include "test_cryptodev_dsa_test_vectors.h"
22 #include "test_cryptodev_ecdsa_test_vectors.h"
23 #include "test_cryptodev_ecpm_test_vectors.h"
24 #include "test_cryptodev_mod_test_vectors.h"
25 #include "test_cryptodev_rsa_test_vectors.h"
26 #include "test_cryptodev_asym_util.h"
29 #define TEST_NUM_BUFS 10
30 #define TEST_NUM_SESSIONS 4
32 #ifndef TEST_DATA_SIZE
33 #define TEST_DATA_SIZE 4096
35 #define ASYM_TEST_MSG_LEN 256
36 #define TEST_VECTOR_SIZE 256
38 static int gbl_driver_id;
39 struct crypto_testsuite_params_asym {
40 struct rte_mempool *op_mpool;
41 struct rte_mempool *session_mpool;
42 struct rte_cryptodev_config conf;
43 struct rte_cryptodev_qp_conf qp_conf;
44 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
45 uint8_t valid_dev_count;
48 struct crypto_unittest_params {
50 struct rte_crypto_op *op;
53 union test_case_structure {
54 struct modex_test_data modex;
55 struct modinv_test_data modinv;
56 struct rsa_test_data_2 rsa_data;
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_asym testsuite_params = { NULL };
70 queue_ops_rsa_sign_verify(void *sess)
72 struct crypto_testsuite_params_asym *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.padding.type = 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.padding.type = 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(void *sess)
163 struct crypto_testsuite_params_asym *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.padding.type = 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.padding.type = 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(struct rte_crypto_op *op,
250 struct rte_crypto_asym_xform *xform_tc,
251 union test_case_structure *data_tc,
252 struct rte_crypto_op *result_op)
254 int status = TEST_FAILED;
256 uint8_t *data_expected = NULL, *data_received = NULL;
257 size_t data_size = 0;
259 switch (data_tc->modex.xform_type) {
260 case RTE_CRYPTO_ASYM_XFORM_MODEX:
261 data_expected = data_tc->modex.reminder.data;
262 data_received = result_op->asym->modex.result.data;
263 data_size = result_op->asym->modex.result.length;
265 case RTE_CRYPTO_ASYM_XFORM_MODINV:
266 data_expected = data_tc->modinv.inverse.data;
267 data_received = result_op->asym->modinv.result.data;
268 data_size = result_op->asym->modinv.result.length;
270 case RTE_CRYPTO_ASYM_XFORM_RSA:
271 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
272 data_size = xform_tc->rsa.n.length;
273 data_received = result_op->asym->rsa.cipher.data;
274 data_expected = data_tc->rsa_data.ct.data;
275 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
276 data_size = xform_tc->rsa.n.length;
277 data_expected = data_tc->rsa_data.pt.data;
278 data_received = result_op->asym->rsa.message.data;
279 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
280 data_size = xform_tc->rsa.n.length;
281 data_expected = data_tc->rsa_data.sign.data;
282 data_received = result_op->asym->rsa.sign.data;
283 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
284 data_size = xform_tc->rsa.n.length;
285 data_expected = data_tc->rsa_data.pt.data;
286 data_received = result_op->asym->rsa.cipher.data;
289 case RTE_CRYPTO_ASYM_XFORM_DH:
290 case RTE_CRYPTO_ASYM_XFORM_DSA:
291 case RTE_CRYPTO_ASYM_XFORM_NONE:
292 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
296 ret = memcmp(data_expected, data_received, data_size);
297 if (!ret && data_size)
298 status = TEST_SUCCESS;
304 test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
305 union test_case_structure *data_tc,
306 char *test_msg, int sessionless, enum rte_crypto_asym_op_type type,
307 enum rte_crypto_rsa_priv_key_type key_type)
309 struct rte_crypto_asym_op *asym_op = NULL;
310 struct rte_crypto_op *op = NULL;
311 struct rte_crypto_op *result_op = NULL;
312 struct rte_crypto_asym_xform xform_tc;
314 struct rte_cryptodev_asym_capability_idx cap_idx;
315 const struct rte_cryptodev_asymmetric_xform_capability *capability;
316 uint8_t dev_id = ts_params->valid_devs[0];
317 uint8_t input[TEST_DATA_SIZE] = {0};
318 uint8_t *result = NULL;
320 int ret, status = TEST_SUCCESS;
322 xform_tc.next = NULL;
323 xform_tc.xform_type = data_tc->modex.xform_type;
325 cap_idx.type = xform_tc.xform_type;
326 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
328 if (capability == NULL) {
330 "Device doesn't support MODEX. Test Skipped\n");
334 /* Generate crypto op data structure */
335 op = rte_crypto_op_alloc(ts_params->op_mpool,
336 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
339 snprintf(test_msg, ASYM_TEST_MSG_LEN,
340 "line %u FAILED: %s",
341 __LINE__, "Failed to allocate asymmetric crypto "
343 status = TEST_FAILED;
349 switch (xform_tc.xform_type) {
350 case RTE_CRYPTO_ASYM_XFORM_MODEX:
351 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
352 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
353 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
354 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
355 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
356 memcpy(input, data_tc->modex.base.data,
357 data_tc->modex.base.len);
358 asym_op->modex.base.data = input;
359 asym_op->modex.base.length = data_tc->modex.base.len;
360 asym_op->modex.result.data = result;
361 asym_op->modex.result.length = data_tc->modex.result_len;
362 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
363 xform_tc.modex.modulus.length)) {
364 snprintf(test_msg, ASYM_TEST_MSG_LEN,
366 "FAILED: %s", __LINE__,
367 "Invalid MODULUS length specified");
368 status = TEST_FAILED;
372 case RTE_CRYPTO_ASYM_XFORM_MODINV:
373 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
374 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
375 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
376 memcpy(input, data_tc->modinv.base.data,
377 data_tc->modinv.base.len);
378 asym_op->modinv.base.data = input;
379 asym_op->modinv.base.length = data_tc->modinv.base.len;
380 asym_op->modinv.result.data = result;
381 asym_op->modinv.result.length = data_tc->modinv.result_len;
382 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
383 xform_tc.modinv.modulus.length)) {
384 snprintf(test_msg, ASYM_TEST_MSG_LEN,
386 "FAILED: %s", __LINE__,
387 "Invalid MODULUS length specified");
388 status = TEST_FAILED;
392 case RTE_CRYPTO_ASYM_XFORM_RSA:
393 result = rte_zmalloc(NULL, data_tc->rsa_data.n.len, 0);
394 op->asym->rsa.op_type = type;
395 xform_tc.rsa.e.data = data_tc->rsa_data.e.data;
396 xform_tc.rsa.e.length = data_tc->rsa_data.e.len;
397 xform_tc.rsa.n.data = data_tc->rsa_data.n.data;
398 xform_tc.rsa.n.length = data_tc->rsa_data.n.len;
400 if (key_type == RTE_RSA_KEY_TYPE_EXP) {
401 xform_tc.rsa.d.data = data_tc->rsa_data.d.data;
402 xform_tc.rsa.d.length = data_tc->rsa_data.d.len;
404 xform_tc.rsa.qt.p.data = data_tc->rsa_data.p.data;
405 xform_tc.rsa.qt.p.length = data_tc->rsa_data.p.len;
406 xform_tc.rsa.qt.q.data = data_tc->rsa_data.q.data;
407 xform_tc.rsa.qt.q.length = data_tc->rsa_data.q.len;
408 xform_tc.rsa.qt.dP.data = data_tc->rsa_data.dP.data;
409 xform_tc.rsa.qt.dP.length = data_tc->rsa_data.dP.len;
410 xform_tc.rsa.qt.dQ.data = data_tc->rsa_data.dQ.data;
411 xform_tc.rsa.qt.dQ.length = data_tc->rsa_data.dQ.len;
412 xform_tc.rsa.qt.qInv.data = data_tc->rsa_data.qInv.data;
413 xform_tc.rsa.qt.qInv.length = data_tc->rsa_data.qInv.len;
416 xform_tc.rsa.key_type = key_type;
417 op->asym->rsa.padding.type = data_tc->rsa_data.padding;
419 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
420 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
421 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
422 asym_op->rsa.cipher.data = result;
423 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
424 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
425 asym_op->rsa.message.data = result;
426 asym_op->rsa.message.length = data_tc->rsa_data.n.len;
427 asym_op->rsa.cipher.data = data_tc->rsa_data.ct.data;
428 asym_op->rsa.cipher.length = data_tc->rsa_data.ct.len;
429 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
430 asym_op->rsa.sign.data = result;
431 asym_op->rsa.sign.length = data_tc->rsa_data.n.len;
432 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
433 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
434 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
435 asym_op->rsa.cipher.data = result;
436 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
437 asym_op->rsa.sign.data = data_tc->rsa_data.sign.data;
438 asym_op->rsa.sign.length = data_tc->rsa_data.sign.len;
441 case RTE_CRYPTO_ASYM_XFORM_DH:
442 case RTE_CRYPTO_ASYM_XFORM_DSA:
443 case RTE_CRYPTO_ASYM_XFORM_NONE:
444 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
446 snprintf(test_msg, ASYM_TEST_MSG_LEN,
448 "FAILED: %s", __LINE__,
449 "Invalid ASYM algorithm specified");
450 status = TEST_FAILED;
455 ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
456 ts_params->session_mpool, &sess);
458 snprintf(test_msg, ASYM_TEST_MSG_LEN,
460 "FAILED: %s", __LINE__,
461 "Session creation failed");
462 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
466 rte_crypto_op_attach_asym_session(op, sess);
468 asym_op->xform = &xform_tc;
469 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
471 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
473 /* Process crypto operation */
474 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
475 snprintf(test_msg, ASYM_TEST_MSG_LEN,
476 "line %u FAILED: %s",
477 __LINE__, "Error sending packet for operation");
478 status = TEST_FAILED;
482 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
485 if (result_op == NULL) {
486 snprintf(test_msg, ASYM_TEST_MSG_LEN,
487 "line %u FAILED: %s",
488 __LINE__, "Failed to process asym crypto op");
489 status = TEST_FAILED;
493 if (test_cryptodev_asym_ver(op, &xform_tc, data_tc, result_op) != TEST_SUCCESS) {
494 snprintf(test_msg, ASYM_TEST_MSG_LEN,
495 "line %u FAILED: %s",
496 __LINE__, "Verification failed ");
497 status = TEST_FAILED;
502 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
504 snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
508 rte_cryptodev_asym_session_free(dev_id, sess);
511 rte_crypto_op_free(op);
519 test_one_case(const void *test_case, int sessionless)
521 int status = TEST_SUCCESS, i = 0;
522 char test_msg[ASYM_TEST_MSG_LEN + 1];
524 /* Map the case to union */
525 union test_case_structure tc;
526 memcpy(&tc, test_case, sizeof(tc));
528 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX
529 || tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
530 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
532 printf(" %u) TestCase %s %s\n", test_index++,
533 tc.modex.description, test_msg);
535 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
536 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
537 if (tc.rsa_data.op_type_flags & (1 << i)) {
538 if (tc.rsa_data.key_exp) {
539 status = test_cryptodev_asym_op(
540 &testsuite_params, &tc,
541 test_msg, sessionless, i,
542 RTE_RSA_KEY_TYPE_EXP);
546 if (tc.rsa_data.key_qt && (i ==
547 RTE_CRYPTO_ASYM_OP_DECRYPT ||
548 i == RTE_CRYPTO_ASYM_OP_SIGN)) {
549 status = test_cryptodev_asym_op(
551 &tc, test_msg, sessionless, i,
552 RTE_RSA_KEY_TYPE_QT);
559 printf(" %u) TestCase %s %s\n", test_index++,
560 tc.modex.description, test_msg);
567 load_test_vectors(void)
569 uint32_t i = 0, v_size = 0;
570 /* Load MODEX vector*/
571 v_size = RTE_DIM(modex_test_case);
572 for (i = 0; i < v_size; i++) {
573 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
574 RTE_LOG(DEBUG, USER1,
575 "TEST_VECTOR_SIZE too small\n");
578 test_vector.address[test_vector.size] = &modex_test_case[i];
581 /* Load MODINV vector*/
582 v_size = RTE_DIM(modinv_test_case);
583 for (i = 0; i < v_size; i++) {
584 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
585 RTE_LOG(DEBUG, USER1,
586 "TEST_VECTOR_SIZE too small\n");
589 test_vector.address[test_vector.size] = &modinv_test_case[i];
593 v_size = RTE_DIM(rsa_test_case_list);
594 for (i = 0; i < v_size; i++) {
595 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
596 RTE_LOG(DEBUG, USER1,
597 "TEST_VECTOR_SIZE too small\n");
600 test_vector.address[test_vector.size] = &rsa_test_case_list[i];
607 test_one_by_one(void)
609 int status = TEST_SUCCESS;
610 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
612 uint8_t dev_id = ts_params->valid_devs[0];
613 struct rte_cryptodev_info dev_info;
616 rte_cryptodev_info_get(dev_id, &dev_info);
617 if ((dev_info.feature_flags &
618 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
622 /* Go through all test cases */
624 for (i = 0; i < test_vector.size; i++) {
625 if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
626 status = TEST_FAILED;
629 for (i = 0; i < test_vector.size; i++) {
630 if (test_one_case(test_vector.address[i], 1)
632 status = TEST_FAILED;
636 TEST_ASSERT_EQUAL(status, 0, "Test failed");
641 test_rsa_sign_verify(void)
643 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
644 struct rte_mempool *sess_mpool = ts_params->session_mpool;
645 uint8_t dev_id = ts_params->valid_devs[0];
647 struct rte_cryptodev_info dev_info;
648 int ret, status = TEST_SUCCESS;
650 /* Test case supports op with exponent key only,
651 * Check in PMD feature flag for RSA exponent key type support.
653 rte_cryptodev_info_get(dev_id, &dev_info);
654 if (!(dev_info.feature_flags &
655 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
656 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
657 "exponent key type. Test Skipped\n");
661 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
664 RTE_LOG(ERR, USER1, "Session creation failed for "
666 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
670 status = queue_ops_rsa_sign_verify(sess);
673 rte_cryptodev_asym_session_free(dev_id, sess);
675 TEST_ASSERT_EQUAL(status, 0, "Test failed");
681 test_rsa_enc_dec(void)
683 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
684 struct rte_mempool *sess_mpool = ts_params->session_mpool;
685 uint8_t dev_id = ts_params->valid_devs[0];
687 struct rte_cryptodev_info dev_info;
688 int ret, status = TEST_SUCCESS;
690 /* Test case supports op with exponent key only,
691 * Check in PMD feature flag for RSA exponent key type support.
693 rte_cryptodev_info_get(dev_id, &dev_info);
694 if (!(dev_info.feature_flags &
695 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
696 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
697 "exponent key type. Test skipped\n");
701 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
704 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
705 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
709 status = queue_ops_rsa_enc_dec(sess);
713 rte_cryptodev_asym_session_free(dev_id, sess);
715 TEST_ASSERT_EQUAL(status, 0, "Test failed");
721 test_rsa_sign_verify_crt(void)
723 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
724 struct rte_mempool *sess_mpool = ts_params->session_mpool;
725 uint8_t dev_id = ts_params->valid_devs[0];
727 struct rte_cryptodev_info dev_info;
728 int ret, status = TEST_SUCCESS;
730 /* Test case supports op with quintuple format key only,
731 * Check im PMD feature flag for RSA quintuple key type support.
733 rte_cryptodev_info_get(dev_id, &dev_info);
734 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
735 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
736 "quintuple key type. Test skipped\n");
740 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
743 RTE_LOG(ERR, USER1, "Session creation failed for "
744 "sign_verify_crt\n");
745 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
749 status = queue_ops_rsa_sign_verify(sess);
753 rte_cryptodev_asym_session_free(dev_id, sess);
755 TEST_ASSERT_EQUAL(status, 0, "Test failed");
761 test_rsa_enc_dec_crt(void)
763 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
764 struct rte_mempool *sess_mpool = ts_params->session_mpool;
765 uint8_t dev_id = ts_params->valid_devs[0];
767 struct rte_cryptodev_info dev_info;
768 int ret, status = TEST_SUCCESS;
770 /* Test case supports op with quintuple format key only,
771 * Check in PMD feature flag for RSA quintuple key type support.
773 rte_cryptodev_info_get(dev_id, &dev_info);
774 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
775 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
776 "quintuple key type. Test skipped\n");
780 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
783 RTE_LOG(ERR, USER1, "Session creation failed for "
785 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
789 status = queue_ops_rsa_enc_dec(sess);
793 rte_cryptodev_asym_session_free(dev_id, sess);
795 TEST_ASSERT_EQUAL(status, 0, "Test failed");
801 testsuite_setup(void)
803 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
804 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
805 struct rte_cryptodev_info info;
806 int ret, dev_id = -1;
810 memset(ts_params, 0, sizeof(*ts_params));
812 test_vector.size = 0;
815 /* Device, op pool and session configuration for asymmetric crypto. 8< */
816 ts_params->op_mpool = rte_crypto_op_pool_create(
817 "CRYPTO_ASYM_OP_POOL",
818 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
822 if (ts_params->op_mpool == NULL) {
823 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
827 /* Create an OPENSSL device if required */
828 if (gbl_driver_id == rte_cryptodev_driver_id_get(
829 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
830 nb_devs = rte_cryptodev_device_count_by_driver(
831 rte_cryptodev_driver_id_get(
832 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
835 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
838 TEST_ASSERT(ret == 0, "Failed to create "
839 "instance of pmd : %s",
840 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
844 /* Get list of valid crypto devs */
845 nb_devs = rte_cryptodev_devices_get(
846 rte_cryptodev_driver_name_get(gbl_driver_id),
847 valid_devs, RTE_CRYPTO_MAX_DEVS);
849 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
854 * Get first valid asymmetric device found in test suite param and
857 for (i = 0; i < nb_devs ; i++) {
858 rte_cryptodev_info_get(valid_devs[i], &info);
859 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
860 dev_id = ts_params->valid_devs[0] = valid_devs[i];
866 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
871 /* Set valid device count */
872 ts_params->valid_dev_count = nb_devs;
874 /* configure device with num qp */
875 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
876 ts_params->conf.socket_id = SOCKET_ID_ANY;
877 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
878 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
879 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
881 "Failed to configure cryptodev %u with %u qps",
882 dev_id, ts_params->conf.nb_queue_pairs);
885 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
886 ts_params->qp_conf.mp_session = ts_params->session_mpool;
887 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
888 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
889 dev_id, qp_id, &ts_params->qp_conf,
890 rte_cryptodev_socket_id(dev_id)),
891 "Failed to setup queue pair %u on cryptodev %u ASYM",
895 ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
896 "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
899 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
900 "session mempool allocation failed");
901 /* >8 End of device, op pool and session configuration for asymmetric crypto section. */
906 testsuite_teardown(void)
908 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
910 if (ts_params->op_mpool != NULL) {
911 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
912 rte_mempool_avail_count(ts_params->op_mpool));
915 /* Free session mempools */
916 if (ts_params->session_mpool != NULL) {
917 rte_mempool_free(ts_params->session_mpool);
918 ts_params->session_mpool = NULL;
925 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
929 /* Reconfigure device to default parameters */
930 ts_params->conf.socket_id = SOCKET_ID_ANY;
932 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
934 "Failed to configure cryptodev %u",
935 ts_params->valid_devs[0]);
937 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
938 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
939 ts_params->valid_devs[0], qp_id,
941 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
942 "Failed to setup queue pair %u on cryptodev %u",
943 qp_id, ts_params->valid_devs[0]);
946 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
948 /* Start the device */
949 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
950 "Failed to start cryptodev %u",
951 ts_params->valid_devs[0]);
957 ut_teardown_asym(void)
959 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
960 struct rte_cryptodev_stats stats;
962 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
964 /* Stop the device */
965 rte_cryptodev_stop(ts_params->valid_devs[0]);
968 static inline void print_asym_capa(
969 const struct rte_cryptodev_asymmetric_xform_capability *capa)
973 printf("\nxform type: %s\n===================\n",
974 rte_crypto_asym_xform_strings[capa->xform_type]);
975 printf("operation supported -");
977 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
978 /* check supported operations */
979 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) {
980 if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH)
981 printf(" %s", rte_crypto_asym_ke_strings[i]);
983 printf(" %s", rte_crypto_asym_op_strings[i]);
986 switch (capa->xform_type) {
987 case RTE_CRYPTO_ASYM_XFORM_RSA:
988 case RTE_CRYPTO_ASYM_XFORM_MODINV:
989 case RTE_CRYPTO_ASYM_XFORM_MODEX:
990 case RTE_CRYPTO_ASYM_XFORM_DH:
991 case RTE_CRYPTO_ASYM_XFORM_DSA:
992 printf(" modlen: min %d max %d increment %d",
995 capa->modlen.increment);
997 case RTE_CRYPTO_ASYM_XFORM_ECDSA:
998 case RTE_CRYPTO_ASYM_XFORM_ECPM:
1006 test_capability(void)
1008 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1009 uint8_t dev_id = ts_params->valid_devs[0];
1010 struct rte_cryptodev_info dev_info;
1011 const struct rte_cryptodev_capabilities *dev_capa;
1013 struct rte_cryptodev_asym_capability_idx idx;
1014 const struct rte_cryptodev_asymmetric_xform_capability *capa;
1016 rte_cryptodev_info_get(dev_id, &dev_info);
1017 if (!(dev_info.feature_flags &
1018 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1019 RTE_LOG(INFO, USER1,
1020 "Device doesn't support asymmetric. Test Skipped\n");
1021 return TEST_SUCCESS;
1024 /* print xform capability */
1026 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1028 dev_capa = &(dev_info.capabilities[i]);
1029 if (dev_info.capabilities[i].op ==
1030 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1031 idx.type = dev_capa->asym.xform_capa.xform_type;
1033 capa = rte_cryptodev_asym_capability_get(dev_id,
1035 rte_cryptodev_asym_capability_idx *) &idx);
1036 print_asym_capa(capa);
1039 return TEST_SUCCESS;
1043 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1045 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1046 struct rte_mempool *op_mpool = ts_params->op_mpool;
1047 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1048 uint8_t dev_id = ts_params->valid_devs[0];
1049 struct rte_crypto_asym_op *asym_op = NULL;
1050 struct rte_crypto_op *op = NULL, *result_op = NULL;
1052 int ret, status = TEST_SUCCESS;
1053 uint8_t output[TEST_DH_MOD_LEN];
1054 struct rte_crypto_asym_xform xform = *xfrm;
1055 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1057 /* set up crypto op data structure */
1058 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1061 "line %u FAILED: %s",
1062 __LINE__, "Failed to allocate asymmetric crypto "
1063 "operation struct");
1064 status = TEST_FAILED;
1069 /* Setup a xform and op to generate private key only */
1071 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
1072 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1073 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1074 asym_op->dh.pub_key.data = (uint8_t *)peer;
1075 asym_op->dh.pub_key.length = sizeof(peer);
1076 asym_op->dh.shared_secret.data = output;
1077 asym_op->dh.shared_secret.length = sizeof(output);
1079 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1082 "line %u FAILED: %s", __LINE__,
1083 "Session creation failed");
1084 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1088 /* attach asymmetric crypto session to crypto operations */
1089 rte_crypto_op_attach_asym_session(op, sess);
1091 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1093 /* Process crypto operation */
1094 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1096 "line %u FAILED: %s",
1097 __LINE__, "Error sending packet for operation");
1098 status = TEST_FAILED;
1102 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1105 if (result_op == NULL) {
1107 "line %u FAILED: %s",
1108 __LINE__, "Failed to process asym crypto op");
1109 status = TEST_FAILED;
1113 debug_hexdump(stdout, "shared secret:",
1114 asym_op->dh.shared_secret.data,
1115 asym_op->dh.shared_secret.length);
1119 rte_cryptodev_asym_session_free(dev_id, sess);
1121 rte_crypto_op_free(op);
1126 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1128 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1129 struct rte_mempool *op_mpool = ts_params->op_mpool;
1130 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1131 uint8_t dev_id = ts_params->valid_devs[0];
1132 struct rte_crypto_asym_op *asym_op = NULL;
1133 struct rte_crypto_op *op = NULL, *result_op = NULL;
1135 int ret, status = TEST_SUCCESS;
1136 uint8_t output[TEST_DH_MOD_LEN];
1137 struct rte_crypto_asym_xform xform = *xfrm;
1139 /* set up crypto op data structure */
1140 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1143 "line %u FAILED: %s",
1144 __LINE__, "Failed to allocate asymmetric crypto "
1145 "operation struct");
1146 status = TEST_FAILED;
1151 /* Setup a xform and op to generate private key only */
1153 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
1154 asym_op->dh.priv_key.data = output;
1155 asym_op->dh.priv_key.length = sizeof(output);
1157 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1160 "line %u FAILED: %s", __LINE__,
1161 "Session creation failed");
1162 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1166 /* attach asymmetric crypto session to crypto operations */
1167 rte_crypto_op_attach_asym_session(op, sess);
1169 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1171 /* Process crypto operation */
1172 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1174 "line %u FAILED: %s",
1175 __LINE__, "Error sending packet for operation");
1176 status = TEST_FAILED;
1180 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1183 if (result_op == NULL) {
1185 "line %u FAILED: %s",
1186 __LINE__, "Failed to process asym crypto op");
1187 status = TEST_FAILED;
1191 debug_hexdump(stdout, "private key:",
1192 asym_op->dh.priv_key.data,
1193 asym_op->dh.priv_key.length);
1198 rte_cryptodev_asym_session_free(dev_id, sess);
1200 rte_crypto_op_free(op);
1207 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1209 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1210 struct rte_mempool *op_mpool = ts_params->op_mpool;
1211 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1212 uint8_t dev_id = ts_params->valid_devs[0];
1213 struct rte_crypto_asym_op *asym_op = NULL;
1214 struct rte_crypto_op *op = NULL, *result_op = NULL;
1216 int ret, status = TEST_SUCCESS;
1217 uint8_t output[TEST_DH_MOD_LEN];
1218 struct rte_crypto_asym_xform xform = *xfrm;
1220 /* set up crypto op data structure */
1221 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1224 "line %u FAILED: %s",
1225 __LINE__, "Failed to allocate asymmetric crypto "
1226 "operation struct");
1227 status = TEST_FAILED;
1231 /* Setup a xform chain to generate public key
1232 * using test private key
1237 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
1238 asym_op->dh.pub_key.data = output;
1239 asym_op->dh.pub_key.length = sizeof(output);
1240 /* load pre-defined private key */
1241 asym_op->dh.priv_key.data = rte_malloc(NULL,
1242 dh_test_params.priv_key.length,
1244 asym_op->dh.priv_key = dh_test_params.priv_key;
1246 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1249 "line %u FAILED: %s", __LINE__,
1250 "Session creation failed");
1251 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1255 /* attach asymmetric crypto session to crypto operations */
1256 rte_crypto_op_attach_asym_session(op, sess);
1258 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1260 /* Process crypto operation */
1261 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1263 "line %u FAILED: %s",
1264 __LINE__, "Error sending packet for operation");
1265 status = TEST_FAILED;
1269 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1272 if (result_op == NULL) {
1274 "line %u FAILED: %s",
1275 __LINE__, "Failed to process asym crypto op");
1276 status = TEST_FAILED;
1280 debug_hexdump(stdout, "pub key:",
1281 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1283 debug_hexdump(stdout, "priv key:",
1284 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1288 rte_cryptodev_asym_session_free(dev_id, sess);
1290 rte_crypto_op_free(op);
1296 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1298 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1299 struct rte_mempool *op_mpool = ts_params->op_mpool;
1300 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1301 uint8_t dev_id = ts_params->valid_devs[0];
1302 struct rte_crypto_asym_op *asym_op = NULL;
1303 struct rte_crypto_op *op = NULL, *result_op = NULL;
1305 int ret, status = TEST_SUCCESS;
1306 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1307 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1308 struct rte_crypto_asym_xform pub_key_xform;
1309 struct rte_crypto_asym_xform xform = *xfrm;
1311 /* set up crypto op data structure */
1312 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1315 "line %u FAILED: %s",
1316 __LINE__, "Failed to allocate asymmetric crypto "
1317 "operation struct");
1318 status = TEST_FAILED;
1322 /* Setup a xform chain to generate
1323 * private key first followed by
1326 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1327 xform.next = &pub_key_xform;
1329 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
1330 asym_op->dh.pub_key.data = out_pub_key;
1331 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1332 asym_op->dh.priv_key.data = out_prv_key;
1333 asym_op->dh.priv_key.length = 0;
1335 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1338 "line %u FAILED: %s", __LINE__,
1339 "Session creation failed");
1340 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1344 /* attach asymmetric crypto session to crypto operations */
1345 rte_crypto_op_attach_asym_session(op, sess);
1347 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1349 /* Process crypto operation */
1350 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1352 "line %u FAILED: %s",
1353 __LINE__, "Error sending packet for operation");
1354 status = TEST_FAILED;
1358 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1361 if (result_op == NULL) {
1363 "line %u FAILED: %s",
1364 __LINE__, "Failed to process asym crypto op");
1365 status = TEST_FAILED;
1368 debug_hexdump(stdout, "priv key:",
1369 out_prv_key, asym_op->dh.priv_key.length);
1370 debug_hexdump(stdout, "pub key:",
1371 out_pub_key, asym_op->dh.pub_key.length);
1375 rte_cryptodev_asym_session_free(dev_id, sess);
1377 rte_crypto_op_free(op);
1385 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1386 struct rte_mempool *op_mpool = ts_params->op_mpool;
1387 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1388 uint8_t dev_id = ts_params->valid_devs[0];
1389 struct rte_crypto_asym_op *asym_op = NULL;
1390 struct rte_crypto_op *op = NULL, *result_op = NULL;
1392 int status = TEST_SUCCESS;
1393 struct rte_cryptodev_asym_capability_idx cap_idx;
1394 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1395 uint8_t input[TEST_DATA_SIZE] = {0};
1397 uint8_t result[sizeof(mod_p)] = { 0 };
1399 if (rte_cryptodev_asym_get_xform_enum(
1400 &modinv_xform.xform_type, "modinv") < 0) {
1402 "Invalid ASYM algorithm specified\n");
1406 cap_idx.type = modinv_xform.xform_type;
1407 capability = rte_cryptodev_asym_capability_get(dev_id,
1410 if (capability == NULL) {
1411 RTE_LOG(INFO, USER1,
1412 "Device doesn't support MOD INV. Test Skipped\n");
1413 return TEST_SKIPPED;
1416 if (rte_cryptodev_asym_xform_capability_check_modlen(
1418 modinv_xform.modinv.modulus.length)) {
1420 "Invalid MODULUS length specified\n");
1421 return TEST_SKIPPED;
1424 ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
1426 RTE_LOG(ERR, USER1, "line %u "
1427 "FAILED: %s", __LINE__,
1428 "Session creation failed");
1429 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1433 /* generate crypto op data structure */
1434 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1437 "line %u FAILED: %s",
1438 __LINE__, "Failed to allocate asymmetric crypto "
1439 "operation struct");
1440 status = TEST_FAILED;
1445 memcpy(input, base, sizeof(base));
1446 asym_op->modinv.base.data = input;
1447 asym_op->modinv.base.length = sizeof(base);
1448 asym_op->modinv.result.data = result;
1449 asym_op->modinv.result.length = sizeof(result);
1451 /* attach asymmetric crypto session to crypto operations */
1452 rte_crypto_op_attach_asym_session(op, sess);
1454 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1456 /* Process crypto operation */
1457 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1459 "line %u FAILED: %s",
1460 __LINE__, "Error sending packet for operation");
1461 status = TEST_FAILED;
1465 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1468 if (result_op == NULL) {
1470 "line %u FAILED: %s",
1471 __LINE__, "Failed to process asym crypto op");
1472 status = TEST_FAILED;
1476 ret = verify_modinv(mod_inv, result_op);
1479 "operation verification failed\n");
1480 status = TEST_FAILED;
1485 rte_cryptodev_asym_session_free(dev_id, sess);
1488 rte_crypto_op_free(op);
1490 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1498 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1499 struct rte_mempool *op_mpool = ts_params->op_mpool;
1500 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1501 uint8_t dev_id = ts_params->valid_devs[0];
1502 struct rte_crypto_asym_op *asym_op = NULL;
1503 struct rte_crypto_op *op = NULL, *result_op = NULL;
1505 int status = TEST_SUCCESS;
1506 struct rte_cryptodev_asym_capability_idx cap_idx;
1507 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1508 uint8_t input[TEST_DATA_SIZE] = {0};
1510 uint8_t result[sizeof(mod_p)] = { 0 };
1512 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1516 "Invalid ASYM algorithm specified\n");
1520 /* check for modlen capability */
1521 cap_idx.type = modex_xform.xform_type;
1522 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1524 if (capability == NULL) {
1525 RTE_LOG(INFO, USER1,
1526 "Device doesn't support MOD EXP. Test Skipped\n");
1527 return TEST_SKIPPED;
1530 if (rte_cryptodev_asym_xform_capability_check_modlen(
1531 capability, modex_xform.modex.modulus.length)) {
1533 "Invalid MODULUS length specified\n");
1534 return TEST_SKIPPED;
1537 /* Create op, create session, and process packets. 8< */
1538 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1541 "line %u FAILED: %s",
1542 __LINE__, "Failed to allocate asymmetric crypto "
1543 "operation struct");
1544 status = TEST_FAILED;
1548 ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
1552 "FAILED: %s", __LINE__,
1553 "Session creation failed");
1554 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1559 memcpy(input, base, sizeof(base));
1560 asym_op->modex.base.data = input;
1561 asym_op->modex.base.length = sizeof(base);
1562 asym_op->modex.result.data = result;
1563 asym_op->modex.result.length = sizeof(result);
1564 /* attach asymmetric crypto session to crypto operations */
1565 rte_crypto_op_attach_asym_session(op, sess);
1567 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1568 /* Process crypto operation */
1569 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1571 "line %u FAILED: %s",
1572 __LINE__, "Error sending packet for operation");
1573 status = TEST_FAILED;
1577 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1580 if (result_op == NULL) {
1582 "line %u FAILED: %s",
1583 __LINE__, "Failed to process asym crypto op");
1584 status = TEST_FAILED;
1587 /* >8 End of create op, create session, and process packets section. */
1588 ret = verify_modexp(mod_exp, result_op);
1591 "operation verification failed\n");
1592 status = TEST_FAILED;
1597 rte_cryptodev_asym_session_free(dev_id, sess);
1600 rte_crypto_op_free(op);
1602 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1608 test_dh_keygenration(void)
1612 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1613 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1614 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1615 dh_test_params.priv_key.length);
1617 RTE_LOG(INFO, USER1,
1618 "Test Public and Private key pair generation\n");
1620 status = test_dh_gen_kp(&dh_xform);
1621 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1623 RTE_LOG(INFO, USER1,
1624 "Test Public Key Generation using pre-defined priv key\n");
1626 status = test_dh_gen_pub_key(&dh_xform);
1627 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1629 RTE_LOG(INFO, USER1,
1630 "Test Private Key Generation only\n");
1632 status = test_dh_gen_priv_key(&dh_xform);
1633 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1635 RTE_LOG(INFO, USER1,
1636 "Test shared secret compute\n");
1638 status = test_dh_gen_shared_sec(&dh_xform);
1639 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1647 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1648 struct rte_mempool *op_mpool = ts_params->op_mpool;
1649 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1650 uint8_t dev_id = ts_params->valid_devs[0];
1651 struct rte_crypto_asym_op *asym_op = NULL;
1652 struct rte_crypto_op *op = NULL, *result_op = NULL;
1654 int status = TEST_SUCCESS;
1655 uint8_t r[TEST_DH_MOD_LEN];
1656 uint8_t s[TEST_DH_MOD_LEN];
1657 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1660 ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1663 "line %u FAILED: %s", __LINE__,
1664 "Session creation failed");
1665 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1668 /* set up crypto op data structure */
1669 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1672 "line %u FAILED: %s",
1673 __LINE__, "Failed to allocate asymmetric crypto "
1674 "operation struct");
1675 status = TEST_FAILED;
1680 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1681 dsa_xform.dsa.p.length);
1682 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1683 dsa_xform.dsa.q.length);
1684 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1685 dsa_xform.dsa.g.length);
1686 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1687 dsa_xform.dsa.x.length);
1689 /* attach asymmetric crypto session to crypto operations */
1690 rte_crypto_op_attach_asym_session(op, sess);
1691 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1692 asym_op->dsa.message.data = dgst;
1693 asym_op->dsa.message.length = sizeof(dgst);
1694 asym_op->dsa.r.length = sizeof(r);
1695 asym_op->dsa.r.data = r;
1696 asym_op->dsa.s.length = sizeof(s);
1697 asym_op->dsa.s.data = s;
1699 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1701 /* Process crypto operation */
1702 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1704 "line %u FAILED: %s",
1705 __LINE__, "Error sending packet for operation");
1706 status = TEST_FAILED;
1710 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1713 if (result_op == NULL) {
1715 "line %u FAILED: %s",
1716 __LINE__, "Failed to process asym crypto op");
1717 status = TEST_FAILED;
1721 asym_op = result_op->asym;
1723 debug_hexdump(stdout, "r:",
1724 asym_op->dsa.r.data, asym_op->dsa.r.length);
1725 debug_hexdump(stdout, "s:",
1726 asym_op->dsa.s.data, asym_op->dsa.s.length);
1728 /* Test PMD DSA sign verification using signer public key */
1729 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1731 /* copy signer public key */
1732 asym_op->dsa.y.data = dsa_test_params.y.data;
1733 asym_op->dsa.y.length = dsa_test_params.y.length;
1735 /* Process crypto operation */
1736 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1738 "line %u FAILED: %s",
1739 __LINE__, "Error sending packet for operation");
1740 status = TEST_FAILED;
1744 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1747 if (result_op == NULL) {
1749 "line %u FAILED: %s",
1750 __LINE__, "Failed to process asym crypto op");
1751 status = TEST_FAILED;
1755 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1757 "line %u FAILED: %s",
1758 __LINE__, "Failed to process asym crypto op");
1759 status = TEST_FAILED;
1763 rte_cryptodev_asym_session_free(dev_id, sess);
1765 rte_crypto_op_free(op);
1773 status = test_dsa_sign();
1774 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1779 test_ecdsa_sign_verify(enum curve curve_id)
1781 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1782 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1783 struct rte_mempool *op_mpool = ts_params->op_mpool;
1784 struct crypto_testsuite_ecdsa_params input_params;
1786 uint8_t dev_id = ts_params->valid_devs[0];
1787 struct rte_crypto_op *result_op = NULL;
1788 uint8_t output_buf_r[TEST_DATA_SIZE];
1789 uint8_t output_buf_s[TEST_DATA_SIZE];
1790 struct rte_crypto_asym_xform xform;
1791 struct rte_crypto_asym_op *asym_op;
1792 struct rte_cryptodev_info dev_info;
1793 struct rte_crypto_op *op = NULL;
1794 int ret, status = TEST_SUCCESS;
1798 input_params = ecdsa_param_secp192r1;
1801 input_params = ecdsa_param_secp224r1;
1804 input_params = ecdsa_param_secp256r1;
1807 input_params = ecdsa_param_secp384r1;
1810 input_params = ecdsa_param_secp521r1;
1814 "line %u FAILED: %s", __LINE__,
1815 "Unsupported curve id\n");
1816 status = TEST_FAILED;
1820 rte_cryptodev_info_get(dev_id, &dev_info);
1822 /* Setup crypto op data structure */
1823 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1826 "line %u FAILED: %s", __LINE__,
1827 "Failed to allocate asymmetric crypto "
1828 "operation struct\n");
1829 status = TEST_FAILED;
1834 /* Setup asym xform */
1836 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1837 xform.ec.curve_id = input_params.curve;
1839 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1842 "line %u FAILED: %s", __LINE__,
1843 "Session creation failed\n");
1844 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1848 /* Attach asymmetric crypto session to crypto operations */
1849 rte_crypto_op_attach_asym_session(op, sess);
1853 /* Populate op with operational details */
1854 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1855 op->asym->ecdsa.message.data = input_params.digest.data;
1856 op->asym->ecdsa.message.length = input_params.digest.length;
1857 op->asym->ecdsa.k.data = input_params.scalar.data;
1858 op->asym->ecdsa.k.length = input_params.scalar.length;
1859 op->asym->ecdsa.pkey.data = input_params.pkey.data;
1860 op->asym->ecdsa.pkey.length = input_params.pkey.length;
1863 op->asym->ecdsa.r.data = output_buf_r;
1864 op->asym->ecdsa.s.data = output_buf_s;
1866 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1868 /* Process crypto operation */
1869 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1871 "line %u FAILED: %s", __LINE__,
1872 "Error sending packet for operation\n");
1873 status = TEST_FAILED;
1877 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1880 if (result_op == NULL) {
1882 "line %u FAILED: %s", __LINE__,
1883 "Failed to process asym crypto op\n");
1884 status = TEST_FAILED;
1888 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1890 "line %u FAILED: %s", __LINE__,
1891 "Failed to process asym crypto op\n");
1892 status = TEST_FAILED;
1896 asym_op = result_op->asym;
1898 debug_hexdump(stdout, "r:",
1899 asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
1900 debug_hexdump(stdout, "s:",
1901 asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
1903 ret = verify_ecdsa_sign(input_params.sign_r.data,
1904 input_params.sign_s.data, result_op);
1906 status = TEST_FAILED;
1908 "line %u FAILED: %s", __LINE__,
1909 "ECDSA sign failed.\n");
1915 /* Populate op with operational details */
1916 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1917 op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
1918 op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
1919 op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
1920 op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
1921 op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
1922 op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
1923 op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
1924 op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
1926 /* Enqueue sign result for verify */
1927 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1928 status = TEST_FAILED;
1930 "line %u FAILED: %s", __LINE__,
1931 "Error sending packet for operation\n");
1935 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1938 if (result_op == NULL) {
1939 status = TEST_FAILED;
1942 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1943 status = TEST_FAILED;
1945 "line %u FAILED: %s", __LINE__,
1946 "ECDSA verify failed.\n");
1952 rte_cryptodev_asym_session_free(dev_id, sess);
1954 rte_crypto_op_free(op);
1959 test_ecdsa_sign_verify_all_curve(void)
1961 int status, overall_status = TEST_SUCCESS;
1962 enum curve curve_id;
1966 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1967 status = test_ecdsa_sign_verify(curve_id);
1968 if (status == TEST_SUCCESS) {
1972 overall_status = status;
1974 printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
1975 test_index ++, curve[curve_id], msg);
1977 return overall_status;
1981 test_ecpm(enum curve curve_id)
1983 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1984 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1985 struct rte_mempool *op_mpool = ts_params->op_mpool;
1986 struct crypto_testsuite_ecpm_params input_params;
1988 uint8_t dev_id = ts_params->valid_devs[0];
1989 struct rte_crypto_op *result_op = NULL;
1990 uint8_t output_buf_x[TEST_DATA_SIZE];
1991 uint8_t output_buf_y[TEST_DATA_SIZE];
1992 struct rte_crypto_asym_xform xform;
1993 struct rte_crypto_asym_op *asym_op;
1994 struct rte_cryptodev_info dev_info;
1995 struct rte_crypto_op *op = NULL;
1996 int ret, status = TEST_SUCCESS;
2000 input_params = ecpm_param_secp192r1;
2003 input_params = ecpm_param_secp224r1;
2006 input_params = ecpm_param_secp256r1;
2009 input_params = ecpm_param_secp384r1;
2012 input_params = ecpm_param_secp521r1;
2016 "line %u FAILED: %s", __LINE__,
2017 "Unsupported curve id\n");
2018 status = TEST_FAILED;
2022 rte_cryptodev_info_get(dev_id, &dev_info);
2024 /* Setup crypto op data structure */
2025 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2028 "line %u FAILED: %s", __LINE__,
2029 "Failed to allocate asymmetric crypto "
2030 "operation struct\n");
2031 status = TEST_FAILED;
2036 /* Setup asym xform */
2038 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
2039 xform.ec.curve_id = input_params.curve;
2041 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2044 "line %u FAILED: %s", __LINE__,
2045 "Session creation failed\n");
2046 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2050 /* Attach asymmetric crypto session to crypto operations */
2051 rte_crypto_op_attach_asym_session(op, sess);
2053 /* Populate op with operational details */
2054 op->asym->ecpm.p.x.data = input_params.gen_x.data;
2055 op->asym->ecpm.p.x.length = input_params.gen_x.length;
2056 op->asym->ecpm.p.y.data = input_params.gen_y.data;
2057 op->asym->ecpm.p.y.length = input_params.gen_y.length;
2058 op->asym->ecpm.scalar.data = input_params.privkey.data;
2059 op->asym->ecpm.scalar.length = input_params.privkey.length;
2062 op->asym->ecpm.r.x.data = output_buf_x;
2063 op->asym->ecpm.r.y.data = output_buf_y;
2065 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2067 /* Process crypto operation */
2068 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2070 "line %u FAILED: %s", __LINE__,
2071 "Error sending packet for operation\n");
2072 status = TEST_FAILED;
2076 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2079 if (result_op == NULL) {
2081 "line %u FAILED: %s", __LINE__,
2082 "Failed to process asym crypto op\n");
2083 status = TEST_FAILED;
2087 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2089 "line %u FAILED: %s", __LINE__,
2090 "Failed to process asym crypto op\n");
2091 status = TEST_FAILED;
2095 asym_op = result_op->asym;
2097 debug_hexdump(stdout, "r x:",
2098 asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
2099 debug_hexdump(stdout, "r y:",
2100 asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
2102 ret = verify_ecpm(input_params.pubkey_x.data,
2103 input_params.pubkey_y.data, result_op);
2105 status = TEST_FAILED;
2107 "line %u FAILED: %s", __LINE__,
2108 "EC Point Multiplication failed.\n");
2114 rte_cryptodev_asym_session_free(dev_id, sess);
2116 rte_crypto_op_free(op);
2121 test_ecpm_all_curve(void)
2123 int status, overall_status = TEST_SUCCESS;
2124 enum curve curve_id;
2128 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2129 status = test_ecpm(curve_id);
2130 if (status == TEST_SUCCESS) {
2134 overall_status = status;
2136 printf(" %u) TestCase EC Point Mul Curve %s %s\n",
2137 test_index ++, curve[curve_id], msg);
2139 return overall_status;
2142 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
2143 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
2144 .setup = testsuite_setup,
2145 .teardown = testsuite_teardown,
2146 .unit_test_cases = {
2147 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2148 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
2149 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2150 test_dh_keygenration),
2151 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
2152 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2153 test_rsa_sign_verify),
2154 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2155 test_rsa_enc_dec_crt),
2156 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2157 test_rsa_sign_verify_crt),
2158 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
2159 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2160 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2161 TEST_CASES_END() /**< NULL terminate unit test array */
2165 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
2166 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
2167 .setup = testsuite_setup,
2168 .teardown = testsuite_teardown,
2169 .unit_test_cases = {
2170 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2171 TEST_CASES_END() /**< NULL terminate unit test array */
2175 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
2176 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
2177 .setup = testsuite_setup,
2178 .teardown = testsuite_teardown,
2179 .unit_test_cases = {
2180 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2181 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2182 test_rsa_enc_dec_crt),
2183 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2184 test_rsa_sign_verify_crt),
2185 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2186 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2187 test_ecdsa_sign_verify_all_curve),
2188 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2189 test_ecpm_all_curve),
2190 TEST_CASES_END() /**< NULL terminate unit test array */
2195 test_cryptodev_openssl_asym(void)
2197 gbl_driver_id = rte_cryptodev_driver_id_get(
2198 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
2200 if (gbl_driver_id == -1) {
2201 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
2205 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
2209 test_cryptodev_qat_asym(void)
2211 gbl_driver_id = rte_cryptodev_driver_id_get(
2212 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
2214 if (gbl_driver_id == -1) {
2215 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
2219 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
2223 test_cryptodev_octeontx_asym(void)
2225 gbl_driver_id = rte_cryptodev_driver_id_get(
2226 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
2227 if (gbl_driver_id == -1) {
2228 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
2231 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2235 test_cryptodev_cn9k_asym(void)
2237 gbl_driver_id = rte_cryptodev_driver_id_get(
2238 RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
2239 if (gbl_driver_id == -1) {
2240 RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
2244 /* Use test suite registered for crypto_octeontx PMD */
2245 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2249 test_cryptodev_cn10k_asym(void)
2251 gbl_driver_id = rte_cryptodev_driver_id_get(
2252 RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
2253 if (gbl_driver_id == -1) {
2254 RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
2258 /* Use test suite registered for crypto_octeontx PMD */
2259 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2262 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2263 test_cryptodev_openssl_asym);
2265 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2267 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2268 test_cryptodev_octeontx_asym);
2269 REGISTER_TEST_COMMAND(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
2270 REGISTER_TEST_COMMAND(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
2272 #endif /* !RTE_EXEC_ENV_WINDOWS */