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.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(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.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(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.pad = 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))
981 rte_crypto_asym_op_strings[i]);
983 switch (capa->xform_type) {
984 case RTE_CRYPTO_ASYM_XFORM_RSA:
985 case RTE_CRYPTO_ASYM_XFORM_MODINV:
986 case RTE_CRYPTO_ASYM_XFORM_MODEX:
987 case RTE_CRYPTO_ASYM_XFORM_DH:
988 case RTE_CRYPTO_ASYM_XFORM_DSA:
989 printf(" modlen: min %d max %d increment %d",
992 capa->modlen.increment);
994 case RTE_CRYPTO_ASYM_XFORM_ECDSA:
995 case RTE_CRYPTO_ASYM_XFORM_ECPM:
1003 test_capability(void)
1005 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1006 uint8_t dev_id = ts_params->valid_devs[0];
1007 struct rte_cryptodev_info dev_info;
1008 const struct rte_cryptodev_capabilities *dev_capa;
1010 struct rte_cryptodev_asym_capability_idx idx;
1011 const struct rte_cryptodev_asymmetric_xform_capability *capa;
1013 rte_cryptodev_info_get(dev_id, &dev_info);
1014 if (!(dev_info.feature_flags &
1015 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1016 RTE_LOG(INFO, USER1,
1017 "Device doesn't support asymmetric. Test Skipped\n");
1018 return TEST_SUCCESS;
1021 /* print xform capability */
1023 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1025 dev_capa = &(dev_info.capabilities[i]);
1026 if (dev_info.capabilities[i].op ==
1027 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1028 idx.type = dev_capa->asym.xform_capa.xform_type;
1030 capa = rte_cryptodev_asym_capability_get(dev_id,
1032 rte_cryptodev_asym_capability_idx *) &idx);
1033 print_asym_capa(capa);
1036 return TEST_SUCCESS;
1040 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1042 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1043 struct rte_mempool *op_mpool = ts_params->op_mpool;
1044 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1045 uint8_t dev_id = ts_params->valid_devs[0];
1046 struct rte_crypto_asym_op *asym_op = NULL;
1047 struct rte_crypto_op *op = NULL, *result_op = NULL;
1049 int ret, status = TEST_SUCCESS;
1050 uint8_t output[TEST_DH_MOD_LEN];
1051 struct rte_crypto_asym_xform xform = *xfrm;
1052 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1054 /* set up crypto op data structure */
1055 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1058 "line %u FAILED: %s",
1059 __LINE__, "Failed to allocate asymmetric crypto "
1060 "operation struct");
1061 status = TEST_FAILED;
1066 /* Setup a xform and op to generate private key only */
1067 xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
1069 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1070 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1071 asym_op->dh.pub_key.data = (uint8_t *)peer;
1072 asym_op->dh.pub_key.length = sizeof(peer);
1073 asym_op->dh.shared_secret.data = output;
1074 asym_op->dh.shared_secret.length = sizeof(output);
1076 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1079 "line %u FAILED: %s", __LINE__,
1080 "Session creation failed");
1081 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1085 /* attach asymmetric crypto session to crypto operations */
1086 rte_crypto_op_attach_asym_session(op, sess);
1088 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1090 /* Process crypto operation */
1091 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1093 "line %u FAILED: %s",
1094 __LINE__, "Error sending packet for operation");
1095 status = TEST_FAILED;
1099 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1102 if (result_op == NULL) {
1104 "line %u FAILED: %s",
1105 __LINE__, "Failed to process asym crypto op");
1106 status = TEST_FAILED;
1110 debug_hexdump(stdout, "shared secret:",
1111 asym_op->dh.shared_secret.data,
1112 asym_op->dh.shared_secret.length);
1116 rte_cryptodev_asym_session_free(dev_id, sess);
1118 rte_crypto_op_free(op);
1123 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1125 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1126 struct rte_mempool *op_mpool = ts_params->op_mpool;
1127 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1128 uint8_t dev_id = ts_params->valid_devs[0];
1129 struct rte_crypto_asym_op *asym_op = NULL;
1130 struct rte_crypto_op *op = NULL, *result_op = NULL;
1132 int ret, status = TEST_SUCCESS;
1133 uint8_t output[TEST_DH_MOD_LEN];
1134 struct rte_crypto_asym_xform xform = *xfrm;
1136 /* set up crypto op data structure */
1137 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1140 "line %u FAILED: %s",
1141 __LINE__, "Failed to allocate asymmetric crypto "
1142 "operation struct");
1143 status = TEST_FAILED;
1148 /* Setup a xform and op to generate private key only */
1149 xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1151 asym_op->dh.priv_key.data = output;
1152 asym_op->dh.priv_key.length = sizeof(output);
1154 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1157 "line %u FAILED: %s", __LINE__,
1158 "Session creation failed");
1159 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1163 /* attach asymmetric crypto session to crypto operations */
1164 rte_crypto_op_attach_asym_session(op, sess);
1166 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1168 /* Process crypto operation */
1169 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1171 "line %u FAILED: %s",
1172 __LINE__, "Error sending packet for operation");
1173 status = TEST_FAILED;
1177 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1180 if (result_op == NULL) {
1182 "line %u FAILED: %s",
1183 __LINE__, "Failed to process asym crypto op");
1184 status = TEST_FAILED;
1188 debug_hexdump(stdout, "private key:",
1189 asym_op->dh.priv_key.data,
1190 asym_op->dh.priv_key.length);
1195 rte_cryptodev_asym_session_free(dev_id, sess);
1197 rte_crypto_op_free(op);
1204 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1206 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1207 struct rte_mempool *op_mpool = ts_params->op_mpool;
1208 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1209 uint8_t dev_id = ts_params->valid_devs[0];
1210 struct rte_crypto_asym_op *asym_op = NULL;
1211 struct rte_crypto_op *op = NULL, *result_op = NULL;
1213 int ret, status = TEST_SUCCESS;
1214 uint8_t output[TEST_DH_MOD_LEN];
1215 struct rte_crypto_asym_xform xform = *xfrm;
1217 /* set up crypto op data structure */
1218 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1221 "line %u FAILED: %s",
1222 __LINE__, "Failed to allocate asymmetric crypto "
1223 "operation struct");
1224 status = TEST_FAILED;
1228 /* Setup a xform chain to generate public key
1229 * using test private key
1232 xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1235 asym_op->dh.pub_key.data = output;
1236 asym_op->dh.pub_key.length = sizeof(output);
1237 /* load pre-defined private key */
1238 asym_op->dh.priv_key.data = rte_malloc(NULL,
1239 dh_test_params.priv_key.length,
1241 asym_op->dh.priv_key = dh_test_params.priv_key;
1243 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1246 "line %u FAILED: %s", __LINE__,
1247 "Session creation failed");
1248 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1252 /* attach asymmetric crypto session to crypto operations */
1253 rte_crypto_op_attach_asym_session(op, sess);
1255 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1257 /* Process crypto operation */
1258 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1260 "line %u FAILED: %s",
1261 __LINE__, "Error sending packet for operation");
1262 status = TEST_FAILED;
1266 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1269 if (result_op == NULL) {
1271 "line %u FAILED: %s",
1272 __LINE__, "Failed to process asym crypto op");
1273 status = TEST_FAILED;
1277 debug_hexdump(stdout, "pub key:",
1278 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1280 debug_hexdump(stdout, "priv key:",
1281 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1285 rte_cryptodev_asym_session_free(dev_id, sess);
1287 rte_crypto_op_free(op);
1293 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1295 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1296 struct rte_mempool *op_mpool = ts_params->op_mpool;
1297 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1298 uint8_t dev_id = ts_params->valid_devs[0];
1299 struct rte_crypto_asym_op *asym_op = NULL;
1300 struct rte_crypto_op *op = NULL, *result_op = NULL;
1302 int ret, status = TEST_SUCCESS;
1303 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1304 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1305 struct rte_crypto_asym_xform pub_key_xform;
1306 struct rte_crypto_asym_xform xform = *xfrm;
1308 /* set up crypto op data structure */
1309 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1312 "line %u FAILED: %s",
1313 __LINE__, "Failed to allocate asymmetric crypto "
1314 "operation struct");
1315 status = TEST_FAILED;
1319 /* Setup a xform chain to generate
1320 * private key first followed by
1322 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1323 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1324 pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1325 xform.next = &pub_key_xform;
1327 asym_op->dh.pub_key.data = out_pub_key;
1328 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1329 asym_op->dh.priv_key.data = out_prv_key;
1330 asym_op->dh.priv_key.length = sizeof(out_prv_key);
1332 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1335 "line %u FAILED: %s", __LINE__,
1336 "Session creation failed");
1337 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1341 /* attach asymmetric crypto session to crypto operations */
1342 rte_crypto_op_attach_asym_session(op, sess);
1344 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1346 /* Process crypto operation */
1347 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1349 "line %u FAILED: %s",
1350 __LINE__, "Error sending packet for operation");
1351 status = TEST_FAILED;
1355 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1358 if (result_op == NULL) {
1360 "line %u FAILED: %s",
1361 __LINE__, "Failed to process asym crypto op");
1362 status = TEST_FAILED;
1365 debug_hexdump(stdout, "priv key:",
1366 out_prv_key, asym_op->dh.priv_key.length);
1367 debug_hexdump(stdout, "pub key:",
1368 out_pub_key, asym_op->dh.pub_key.length);
1372 rte_cryptodev_asym_session_free(dev_id, sess);
1374 rte_crypto_op_free(op);
1382 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1383 struct rte_mempool *op_mpool = ts_params->op_mpool;
1384 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1385 uint8_t dev_id = ts_params->valid_devs[0];
1386 struct rte_crypto_asym_op *asym_op = NULL;
1387 struct rte_crypto_op *op = NULL, *result_op = NULL;
1389 int status = TEST_SUCCESS;
1390 struct rte_cryptodev_asym_capability_idx cap_idx;
1391 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1392 uint8_t input[TEST_DATA_SIZE] = {0};
1394 uint8_t result[sizeof(mod_p)] = { 0 };
1396 if (rte_cryptodev_asym_get_xform_enum(
1397 &modinv_xform.xform_type, "modinv") < 0) {
1399 "Invalid ASYM algorithm specified\n");
1403 cap_idx.type = modinv_xform.xform_type;
1404 capability = rte_cryptodev_asym_capability_get(dev_id,
1407 if (capability == NULL) {
1408 RTE_LOG(INFO, USER1,
1409 "Device doesn't support MOD INV. Test Skipped\n");
1410 return TEST_SKIPPED;
1413 if (rte_cryptodev_asym_xform_capability_check_modlen(
1415 modinv_xform.modinv.modulus.length)) {
1417 "Invalid MODULUS length specified\n");
1418 return TEST_SKIPPED;
1421 ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
1423 RTE_LOG(ERR, USER1, "line %u "
1424 "FAILED: %s", __LINE__,
1425 "Session creation failed");
1426 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1430 /* generate crypto op data structure */
1431 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1434 "line %u FAILED: %s",
1435 __LINE__, "Failed to allocate asymmetric crypto "
1436 "operation struct");
1437 status = TEST_FAILED;
1442 memcpy(input, base, sizeof(base));
1443 asym_op->modinv.base.data = input;
1444 asym_op->modinv.base.length = sizeof(base);
1445 asym_op->modinv.result.data = result;
1446 asym_op->modinv.result.length = sizeof(result);
1448 /* attach asymmetric crypto session to crypto operations */
1449 rte_crypto_op_attach_asym_session(op, sess);
1451 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1453 /* Process crypto operation */
1454 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1456 "line %u FAILED: %s",
1457 __LINE__, "Error sending packet for operation");
1458 status = TEST_FAILED;
1462 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1465 if (result_op == NULL) {
1467 "line %u FAILED: %s",
1468 __LINE__, "Failed to process asym crypto op");
1469 status = TEST_FAILED;
1473 ret = verify_modinv(mod_inv, result_op);
1476 "operation verification failed\n");
1477 status = TEST_FAILED;
1482 rte_cryptodev_asym_session_free(dev_id, sess);
1485 rte_crypto_op_free(op);
1487 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1495 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1496 struct rte_mempool *op_mpool = ts_params->op_mpool;
1497 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1498 uint8_t dev_id = ts_params->valid_devs[0];
1499 struct rte_crypto_asym_op *asym_op = NULL;
1500 struct rte_crypto_op *op = NULL, *result_op = NULL;
1502 int status = TEST_SUCCESS;
1503 struct rte_cryptodev_asym_capability_idx cap_idx;
1504 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1505 uint8_t input[TEST_DATA_SIZE] = {0};
1507 uint8_t result[sizeof(mod_p)] = { 0 };
1509 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1513 "Invalid ASYM algorithm specified\n");
1517 /* check for modlen capability */
1518 cap_idx.type = modex_xform.xform_type;
1519 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1521 if (capability == NULL) {
1522 RTE_LOG(INFO, USER1,
1523 "Device doesn't support MOD EXP. Test Skipped\n");
1524 return TEST_SKIPPED;
1527 if (rte_cryptodev_asym_xform_capability_check_modlen(
1528 capability, modex_xform.modex.modulus.length)) {
1530 "Invalid MODULUS length specified\n");
1531 return TEST_SKIPPED;
1534 /* Create op, create session, and process packets. 8< */
1535 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1538 "line %u FAILED: %s",
1539 __LINE__, "Failed to allocate asymmetric crypto "
1540 "operation struct");
1541 status = TEST_FAILED;
1545 ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
1549 "FAILED: %s", __LINE__,
1550 "Session creation failed");
1551 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1556 memcpy(input, base, sizeof(base));
1557 asym_op->modex.base.data = input;
1558 asym_op->modex.base.length = sizeof(base);
1559 asym_op->modex.result.data = result;
1560 asym_op->modex.result.length = sizeof(result);
1561 /* attach asymmetric crypto session to crypto operations */
1562 rte_crypto_op_attach_asym_session(op, sess);
1564 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1565 /* Process crypto operation */
1566 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1568 "line %u FAILED: %s",
1569 __LINE__, "Error sending packet for operation");
1570 status = TEST_FAILED;
1574 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1577 if (result_op == NULL) {
1579 "line %u FAILED: %s",
1580 __LINE__, "Failed to process asym crypto op");
1581 status = TEST_FAILED;
1584 /* >8 End of create op, create session, and process packets section. */
1585 ret = verify_modexp(mod_exp, result_op);
1588 "operation verification failed\n");
1589 status = TEST_FAILED;
1594 rte_cryptodev_asym_session_free(dev_id, sess);
1597 rte_crypto_op_free(op);
1599 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1605 test_dh_keygenration(void)
1609 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1610 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1611 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1612 dh_test_params.priv_key.length);
1614 RTE_LOG(INFO, USER1,
1615 "Test Public and Private key pair generation\n");
1617 status = test_dh_gen_kp(&dh_xform);
1618 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1620 RTE_LOG(INFO, USER1,
1621 "Test Public Key Generation using pre-defined priv key\n");
1623 status = test_dh_gen_pub_key(&dh_xform);
1624 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1626 RTE_LOG(INFO, USER1,
1627 "Test Private Key Generation only\n");
1629 status = test_dh_gen_priv_key(&dh_xform);
1630 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1632 RTE_LOG(INFO, USER1,
1633 "Test shared secret compute\n");
1635 status = test_dh_gen_shared_sec(&dh_xform);
1636 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1644 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1645 struct rte_mempool *op_mpool = ts_params->op_mpool;
1646 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1647 uint8_t dev_id = ts_params->valid_devs[0];
1648 struct rte_crypto_asym_op *asym_op = NULL;
1649 struct rte_crypto_op *op = NULL, *result_op = NULL;
1651 int status = TEST_SUCCESS;
1652 uint8_t r[TEST_DH_MOD_LEN];
1653 uint8_t s[TEST_DH_MOD_LEN];
1654 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1657 ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1660 "line %u FAILED: %s", __LINE__,
1661 "Session creation failed");
1662 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1665 /* set up crypto op data structure */
1666 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1669 "line %u FAILED: %s",
1670 __LINE__, "Failed to allocate asymmetric crypto "
1671 "operation struct");
1672 status = TEST_FAILED;
1677 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1678 dsa_xform.dsa.p.length);
1679 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1680 dsa_xform.dsa.q.length);
1681 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1682 dsa_xform.dsa.g.length);
1683 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1684 dsa_xform.dsa.x.length);
1686 /* attach asymmetric crypto session to crypto operations */
1687 rte_crypto_op_attach_asym_session(op, sess);
1688 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1689 asym_op->dsa.message.data = dgst;
1690 asym_op->dsa.message.length = sizeof(dgst);
1691 asym_op->dsa.r.length = sizeof(r);
1692 asym_op->dsa.r.data = r;
1693 asym_op->dsa.s.length = sizeof(s);
1694 asym_op->dsa.s.data = s;
1696 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1698 /* Process crypto operation */
1699 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1701 "line %u FAILED: %s",
1702 __LINE__, "Error sending packet for operation");
1703 status = TEST_FAILED;
1707 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1710 if (result_op == NULL) {
1712 "line %u FAILED: %s",
1713 __LINE__, "Failed to process asym crypto op");
1714 status = TEST_FAILED;
1718 asym_op = result_op->asym;
1720 debug_hexdump(stdout, "r:",
1721 asym_op->dsa.r.data, asym_op->dsa.r.length);
1722 debug_hexdump(stdout, "s:",
1723 asym_op->dsa.s.data, asym_op->dsa.s.length);
1725 /* Test PMD DSA sign verification using signer public key */
1726 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1728 /* copy signer public key */
1729 asym_op->dsa.y.data = dsa_test_params.y.data;
1730 asym_op->dsa.y.length = dsa_test_params.y.length;
1732 /* Process crypto operation */
1733 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1735 "line %u FAILED: %s",
1736 __LINE__, "Error sending packet for operation");
1737 status = TEST_FAILED;
1741 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1744 if (result_op == NULL) {
1746 "line %u FAILED: %s",
1747 __LINE__, "Failed to process asym crypto op");
1748 status = TEST_FAILED;
1752 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1754 "line %u FAILED: %s",
1755 __LINE__, "Failed to process asym crypto op");
1756 status = TEST_FAILED;
1760 rte_cryptodev_asym_session_free(dev_id, sess);
1762 rte_crypto_op_free(op);
1770 status = test_dsa_sign();
1771 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1776 test_ecdsa_sign_verify(enum curve curve_id)
1778 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1779 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1780 struct rte_mempool *op_mpool = ts_params->op_mpool;
1781 struct crypto_testsuite_ecdsa_params input_params;
1783 uint8_t dev_id = ts_params->valid_devs[0];
1784 struct rte_crypto_op *result_op = NULL;
1785 uint8_t output_buf_r[TEST_DATA_SIZE];
1786 uint8_t output_buf_s[TEST_DATA_SIZE];
1787 struct rte_crypto_asym_xform xform;
1788 struct rte_crypto_asym_op *asym_op;
1789 struct rte_cryptodev_info dev_info;
1790 struct rte_crypto_op *op = NULL;
1791 int ret, status = TEST_SUCCESS;
1795 input_params = ecdsa_param_secp192r1;
1798 input_params = ecdsa_param_secp224r1;
1801 input_params = ecdsa_param_secp256r1;
1804 input_params = ecdsa_param_secp384r1;
1807 input_params = ecdsa_param_secp521r1;
1811 "line %u FAILED: %s", __LINE__,
1812 "Unsupported curve id\n");
1813 status = TEST_FAILED;
1817 rte_cryptodev_info_get(dev_id, &dev_info);
1819 /* Setup crypto op data structure */
1820 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1823 "line %u FAILED: %s", __LINE__,
1824 "Failed to allocate asymmetric crypto "
1825 "operation struct\n");
1826 status = TEST_FAILED;
1831 /* Setup asym xform */
1833 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1834 xform.ec.curve_id = input_params.curve;
1836 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1839 "line %u FAILED: %s", __LINE__,
1840 "Session creation failed\n");
1841 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1845 /* Attach asymmetric crypto session to crypto operations */
1846 rte_crypto_op_attach_asym_session(op, sess);
1850 /* Populate op with operational details */
1851 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1852 op->asym->ecdsa.message.data = input_params.digest.data;
1853 op->asym->ecdsa.message.length = input_params.digest.length;
1854 op->asym->ecdsa.k.data = input_params.scalar.data;
1855 op->asym->ecdsa.k.length = input_params.scalar.length;
1856 op->asym->ecdsa.pkey.data = input_params.pkey.data;
1857 op->asym->ecdsa.pkey.length = input_params.pkey.length;
1860 op->asym->ecdsa.r.data = output_buf_r;
1861 op->asym->ecdsa.s.data = output_buf_s;
1863 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1865 /* Process crypto operation */
1866 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1868 "line %u FAILED: %s", __LINE__,
1869 "Error sending packet for operation\n");
1870 status = TEST_FAILED;
1874 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1877 if (result_op == NULL) {
1879 "line %u FAILED: %s", __LINE__,
1880 "Failed to process asym crypto op\n");
1881 status = TEST_FAILED;
1885 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1887 "line %u FAILED: %s", __LINE__,
1888 "Failed to process asym crypto op\n");
1889 status = TEST_FAILED;
1893 asym_op = result_op->asym;
1895 debug_hexdump(stdout, "r:",
1896 asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
1897 debug_hexdump(stdout, "s:",
1898 asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
1900 ret = verify_ecdsa_sign(input_params.sign_r.data,
1901 input_params.sign_s.data, result_op);
1903 status = TEST_FAILED;
1905 "line %u FAILED: %s", __LINE__,
1906 "ECDSA sign failed.\n");
1912 /* Populate op with operational details */
1913 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1914 op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
1915 op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
1916 op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
1917 op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
1918 op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
1919 op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
1920 op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
1921 op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
1923 /* Enqueue sign result for verify */
1924 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1925 status = TEST_FAILED;
1927 "line %u FAILED: %s", __LINE__,
1928 "Error sending packet for operation\n");
1932 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1935 if (result_op == NULL) {
1936 status = TEST_FAILED;
1939 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1940 status = TEST_FAILED;
1942 "line %u FAILED: %s", __LINE__,
1943 "ECDSA verify failed.\n");
1949 rte_cryptodev_asym_session_free(dev_id, sess);
1951 rte_crypto_op_free(op);
1956 test_ecdsa_sign_verify_all_curve(void)
1958 int status, overall_status = TEST_SUCCESS;
1959 enum curve curve_id;
1963 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1964 status = test_ecdsa_sign_verify(curve_id);
1965 if (status == TEST_SUCCESS) {
1969 overall_status = status;
1971 printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
1972 test_index ++, curve[curve_id], msg);
1974 return overall_status;
1978 test_ecpm(enum curve curve_id)
1980 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1981 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1982 struct rte_mempool *op_mpool = ts_params->op_mpool;
1983 struct crypto_testsuite_ecpm_params input_params;
1985 uint8_t dev_id = ts_params->valid_devs[0];
1986 struct rte_crypto_op *result_op = NULL;
1987 uint8_t output_buf_x[TEST_DATA_SIZE];
1988 uint8_t output_buf_y[TEST_DATA_SIZE];
1989 struct rte_crypto_asym_xform xform;
1990 struct rte_crypto_asym_op *asym_op;
1991 struct rte_cryptodev_info dev_info;
1992 struct rte_crypto_op *op = NULL;
1993 int ret, status = TEST_SUCCESS;
1997 input_params = ecpm_param_secp192r1;
2000 input_params = ecpm_param_secp224r1;
2003 input_params = ecpm_param_secp256r1;
2006 input_params = ecpm_param_secp384r1;
2009 input_params = ecpm_param_secp521r1;
2013 "line %u FAILED: %s", __LINE__,
2014 "Unsupported curve id\n");
2015 status = TEST_FAILED;
2019 rte_cryptodev_info_get(dev_id, &dev_info);
2021 /* Setup crypto op data structure */
2022 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2025 "line %u FAILED: %s", __LINE__,
2026 "Failed to allocate asymmetric crypto "
2027 "operation struct\n");
2028 status = TEST_FAILED;
2033 /* Setup asym xform */
2035 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
2036 xform.ec.curve_id = input_params.curve;
2038 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2041 "line %u FAILED: %s", __LINE__,
2042 "Session creation failed\n");
2043 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2047 /* Attach asymmetric crypto session to crypto operations */
2048 rte_crypto_op_attach_asym_session(op, sess);
2050 /* Populate op with operational details */
2051 op->asym->ecpm.p.x.data = input_params.gen_x.data;
2052 op->asym->ecpm.p.x.length = input_params.gen_x.length;
2053 op->asym->ecpm.p.y.data = input_params.gen_y.data;
2054 op->asym->ecpm.p.y.length = input_params.gen_y.length;
2055 op->asym->ecpm.scalar.data = input_params.privkey.data;
2056 op->asym->ecpm.scalar.length = input_params.privkey.length;
2059 op->asym->ecpm.r.x.data = output_buf_x;
2060 op->asym->ecpm.r.y.data = output_buf_y;
2062 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2064 /* Process crypto operation */
2065 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2067 "line %u FAILED: %s", __LINE__,
2068 "Error sending packet for operation\n");
2069 status = TEST_FAILED;
2073 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2076 if (result_op == NULL) {
2078 "line %u FAILED: %s", __LINE__,
2079 "Failed to process asym crypto op\n");
2080 status = TEST_FAILED;
2084 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2086 "line %u FAILED: %s", __LINE__,
2087 "Failed to process asym crypto op\n");
2088 status = TEST_FAILED;
2092 asym_op = result_op->asym;
2094 debug_hexdump(stdout, "r x:",
2095 asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
2096 debug_hexdump(stdout, "r y:",
2097 asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
2099 ret = verify_ecpm(input_params.pubkey_x.data,
2100 input_params.pubkey_y.data, result_op);
2102 status = TEST_FAILED;
2104 "line %u FAILED: %s", __LINE__,
2105 "EC Point Multiplication failed.\n");
2111 rte_cryptodev_asym_session_free(dev_id, sess);
2113 rte_crypto_op_free(op);
2118 test_ecpm_all_curve(void)
2120 int status, overall_status = TEST_SUCCESS;
2121 enum curve curve_id;
2125 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2126 status = test_ecpm(curve_id);
2127 if (status == TEST_SUCCESS) {
2131 overall_status = status;
2133 printf(" %u) TestCase EC Point Mul Curve %s %s\n",
2134 test_index ++, curve[curve_id], msg);
2136 return overall_status;
2139 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
2140 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
2141 .setup = testsuite_setup,
2142 .teardown = testsuite_teardown,
2143 .unit_test_cases = {
2144 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2145 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
2146 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2147 test_dh_keygenration),
2148 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
2149 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2150 test_rsa_sign_verify),
2151 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2152 test_rsa_enc_dec_crt),
2153 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2154 test_rsa_sign_verify_crt),
2155 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
2156 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2157 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2158 TEST_CASES_END() /**< NULL terminate unit test array */
2162 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
2163 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
2164 .setup = testsuite_setup,
2165 .teardown = testsuite_teardown,
2166 .unit_test_cases = {
2167 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2168 TEST_CASES_END() /**< NULL terminate unit test array */
2172 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
2173 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
2174 .setup = testsuite_setup,
2175 .teardown = testsuite_teardown,
2176 .unit_test_cases = {
2177 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2178 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2179 test_rsa_enc_dec_crt),
2180 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2181 test_rsa_sign_verify_crt),
2182 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2183 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2184 test_ecdsa_sign_verify_all_curve),
2185 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2186 test_ecpm_all_curve),
2187 TEST_CASES_END() /**< NULL terminate unit test array */
2192 test_cryptodev_openssl_asym(void)
2194 gbl_driver_id = rte_cryptodev_driver_id_get(
2195 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
2197 if (gbl_driver_id == -1) {
2198 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
2202 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
2206 test_cryptodev_qat_asym(void)
2208 gbl_driver_id = rte_cryptodev_driver_id_get(
2209 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
2211 if (gbl_driver_id == -1) {
2212 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
2216 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
2220 test_cryptodev_octeontx_asym(void)
2222 gbl_driver_id = rte_cryptodev_driver_id_get(
2223 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
2224 if (gbl_driver_id == -1) {
2225 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
2228 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2232 test_cryptodev_cn9k_asym(void)
2234 gbl_driver_id = rte_cryptodev_driver_id_get(
2235 RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
2236 if (gbl_driver_id == -1) {
2237 RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
2241 /* Use test suite registered for crypto_octeontx PMD */
2242 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2246 test_cryptodev_cn10k_asym(void)
2248 gbl_driver_id = rte_cryptodev_driver_id_get(
2249 RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
2250 if (gbl_driver_id == -1) {
2251 RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
2255 /* Use test suite registered for crypto_octeontx PMD */
2256 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2259 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2260 test_cryptodev_openssl_asym);
2262 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2264 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2265 test_cryptodev_octeontx_asym);
2266 REGISTER_TEST_COMMAND(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
2267 REGISTER_TEST_COMMAND(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
2269 #endif /* !RTE_EXEC_ENV_WINDOWS */