1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Cavium Networks
3 * Copyright (c) 2019 Intel Corporation
6 #include <rte_bus_vdev.h>
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
14 #include <rte_cryptodev.h>
15 #include <rte_crypto.h>
17 #include "test_cryptodev.h"
18 #include "test_cryptodev_dh_test_vectors.h"
19 #include "test_cryptodev_dsa_test_vectors.h"
20 #include "test_cryptodev_ecdsa_test_vectors.h"
21 #include "test_cryptodev_ecpm_test_vectors.h"
22 #include "test_cryptodev_mod_test_vectors.h"
23 #include "test_cryptodev_rsa_test_vectors.h"
24 #include "test_cryptodev_asym_util.h"
27 #define TEST_NUM_BUFS 10
28 #define TEST_NUM_SESSIONS 4
30 #ifndef TEST_DATA_SIZE
31 #define TEST_DATA_SIZE 4096
33 #define ASYM_TEST_MSG_LEN 256
34 #define TEST_VECTOR_SIZE 256
36 static int gbl_driver_id;
37 struct crypto_testsuite_params_asym {
38 struct rte_mempool *op_mpool;
39 struct rte_mempool *session_mpool;
40 struct rte_cryptodev_config conf;
41 struct rte_cryptodev_qp_conf qp_conf;
42 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
43 uint8_t valid_dev_count;
46 struct crypto_unittest_params {
48 struct rte_crypto_op *op;
51 union test_case_structure {
52 struct modex_test_data modex;
53 struct modinv_test_data modinv;
54 struct rsa_test_data_2 rsa_data;
57 struct test_cases_array {
59 const void *address[TEST_VECTOR_SIZE];
61 static struct test_cases_array test_vector = {0, { NULL } };
63 static uint32_t test_index;
65 static struct crypto_testsuite_params_asym testsuite_params = { NULL };
68 queue_ops_rsa_sign_verify(void *sess)
70 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
71 struct rte_mempool *op_mpool = ts_params->op_mpool;
72 uint8_t dev_id = ts_params->valid_devs[0];
73 struct rte_crypto_op *op, *result_op;
74 struct rte_crypto_asym_op *asym_op;
75 uint8_t output_buf[TEST_DATA_SIZE];
76 int status = TEST_SUCCESS;
78 /* Set up crypto op data structure */
79 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
81 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
82 "operation struct\n");
88 /* Compute sign on the test vector */
89 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
91 asym_op->rsa.message.data = rsaplaintext.data;
92 asym_op->rsa.message.length = rsaplaintext.len;
93 asym_op->rsa.sign.length = 0;
94 asym_op->rsa.sign.data = output_buf;
95 asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
97 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
98 asym_op->rsa.message.length);
100 /* Attach asymmetric crypto session to crypto operations */
101 rte_crypto_op_attach_asym_session(op, sess);
103 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
105 /* Process crypto operation */
106 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
107 RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
108 status = TEST_FAILED;
112 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
115 if (result_op == NULL) {
116 RTE_LOG(ERR, USER1, "Failed to process sign op\n");
117 status = TEST_FAILED;
121 debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
122 asym_op->rsa.sign.length);
123 asym_op = result_op->asym;
126 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
127 asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
129 /* Process crypto operation */
130 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
131 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
132 status = TEST_FAILED;
136 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
139 if (result_op == NULL) {
140 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
141 status = TEST_FAILED;
145 status = TEST_SUCCESS;
146 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
147 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
148 status = TEST_FAILED;
153 rte_crypto_op_free(op);
159 queue_ops_rsa_enc_dec(void *sess)
161 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
162 struct rte_mempool *op_mpool = ts_params->op_mpool;
163 uint8_t dev_id = ts_params->valid_devs[0];
164 struct rte_crypto_op *op, *result_op;
165 struct rte_crypto_asym_op *asym_op;
166 uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
167 int ret, status = TEST_SUCCESS;
169 /* Set up crypto op data structure */
170 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
172 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
173 "operation struct\n");
179 /* Compute encryption on the test vector */
180 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
182 asym_op->rsa.message.data = rsaplaintext.data;
183 asym_op->rsa.cipher.data = cipher_buf;
184 asym_op->rsa.cipher.length = 0;
185 asym_op->rsa.message.length = rsaplaintext.len;
186 asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
188 debug_hexdump(stdout, "message", asym_op->rsa.message.data,
189 asym_op->rsa.message.length);
191 /* Attach asymmetric crypto session to crypto operations */
192 rte_crypto_op_attach_asym_session(op, sess);
194 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
196 /* Process crypto operation */
197 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
198 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
199 status = TEST_FAILED;
203 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
206 if (result_op == NULL) {
207 RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
208 status = TEST_FAILED;
211 debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
212 asym_op->rsa.message.length);
214 /* Use the resulted output as decryption Input vector*/
215 asym_op = result_op->asym;
216 asym_op->rsa.message.length = 0;
217 asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
218 asym_op->rsa.padding.type = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
220 /* Process crypto operation */
221 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
222 RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
223 status = TEST_FAILED;
227 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
230 if (result_op == NULL) {
231 RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
232 status = TEST_FAILED;
235 status = TEST_SUCCESS;
236 ret = rsa_verify(&rsaplaintext, result_op);
238 status = TEST_FAILED;
242 rte_crypto_op_free(op);
247 test_cryptodev_asym_ver(struct rte_crypto_op *op,
248 struct rte_crypto_asym_xform *xform_tc,
249 union test_case_structure *data_tc,
250 struct rte_crypto_op *result_op)
252 int status = TEST_FAILED;
254 uint8_t *data_expected = NULL, *data_received = NULL;
255 size_t data_size = 0;
257 switch (data_tc->modex.xform_type) {
258 case RTE_CRYPTO_ASYM_XFORM_MODEX:
259 data_expected = data_tc->modex.reminder.data;
260 data_received = result_op->asym->modex.result.data;
261 data_size = result_op->asym->modex.result.length;
263 case RTE_CRYPTO_ASYM_XFORM_MODINV:
264 data_expected = data_tc->modinv.inverse.data;
265 data_received = result_op->asym->modinv.result.data;
266 data_size = result_op->asym->modinv.result.length;
268 case RTE_CRYPTO_ASYM_XFORM_RSA:
269 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
270 data_size = xform_tc->rsa.n.length;
271 data_received = result_op->asym->rsa.cipher.data;
272 data_expected = data_tc->rsa_data.ct.data;
273 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
274 data_size = xform_tc->rsa.n.length;
275 data_expected = data_tc->rsa_data.pt.data;
276 data_received = result_op->asym->rsa.message.data;
277 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
278 data_size = xform_tc->rsa.n.length;
279 data_expected = data_tc->rsa_data.sign.data;
280 data_received = result_op->asym->rsa.sign.data;
281 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
282 data_size = xform_tc->rsa.n.length;
283 data_expected = data_tc->rsa_data.pt.data;
284 data_received = result_op->asym->rsa.cipher.data;
287 case RTE_CRYPTO_ASYM_XFORM_DH:
288 case RTE_CRYPTO_ASYM_XFORM_DSA:
289 case RTE_CRYPTO_ASYM_XFORM_NONE:
290 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
294 ret = memcmp(data_expected, data_received, data_size);
295 if (!ret && data_size)
296 status = TEST_SUCCESS;
302 test_cryptodev_asym_op(struct crypto_testsuite_params_asym *ts_params,
303 union test_case_structure *data_tc,
304 char *test_msg, int sessionless, enum rte_crypto_asym_op_type type,
305 enum rte_crypto_rsa_priv_key_type key_type)
307 struct rte_crypto_asym_op *asym_op = NULL;
308 struct rte_crypto_op *op = NULL;
309 struct rte_crypto_op *result_op = NULL;
310 struct rte_crypto_asym_xform xform_tc;
312 struct rte_cryptodev_asym_capability_idx cap_idx;
313 const struct rte_cryptodev_asymmetric_xform_capability *capability;
314 uint8_t dev_id = ts_params->valid_devs[0];
315 uint8_t input[TEST_DATA_SIZE] = {0};
316 uint8_t *result = NULL;
318 int ret, status = TEST_SUCCESS;
320 xform_tc.next = NULL;
321 xform_tc.xform_type = data_tc->modex.xform_type;
323 cap_idx.type = xform_tc.xform_type;
324 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
326 if (capability == NULL) {
328 "Device doesn't support MODEX. Test Skipped\n");
332 /* Generate crypto op data structure */
333 op = rte_crypto_op_alloc(ts_params->op_mpool,
334 RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
337 snprintf(test_msg, ASYM_TEST_MSG_LEN,
338 "line %u FAILED: %s",
339 __LINE__, "Failed to allocate asymmetric crypto "
341 status = TEST_FAILED;
347 switch (xform_tc.xform_type) {
348 case RTE_CRYPTO_ASYM_XFORM_MODEX:
349 result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
350 xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
351 xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
352 xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
353 xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
354 memcpy(input, data_tc->modex.base.data,
355 data_tc->modex.base.len);
356 asym_op->modex.base.data = input;
357 asym_op->modex.base.length = data_tc->modex.base.len;
358 asym_op->modex.result.data = result;
359 asym_op->modex.result.length = data_tc->modex.result_len;
360 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
361 xform_tc.modex.modulus.length)) {
362 snprintf(test_msg, ASYM_TEST_MSG_LEN,
364 "FAILED: %s", __LINE__,
365 "Invalid MODULUS length specified");
366 status = TEST_FAILED;
370 case RTE_CRYPTO_ASYM_XFORM_MODINV:
371 result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
372 xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
373 xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
374 memcpy(input, data_tc->modinv.base.data,
375 data_tc->modinv.base.len);
376 asym_op->modinv.base.data = input;
377 asym_op->modinv.base.length = data_tc->modinv.base.len;
378 asym_op->modinv.result.data = result;
379 asym_op->modinv.result.length = data_tc->modinv.result_len;
380 if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
381 xform_tc.modinv.modulus.length)) {
382 snprintf(test_msg, ASYM_TEST_MSG_LEN,
384 "FAILED: %s", __LINE__,
385 "Invalid MODULUS length specified");
386 status = TEST_FAILED;
390 case RTE_CRYPTO_ASYM_XFORM_RSA:
391 result = rte_zmalloc(NULL, data_tc->rsa_data.n.len, 0);
392 op->asym->rsa.op_type = type;
393 xform_tc.rsa.e.data = data_tc->rsa_data.e.data;
394 xform_tc.rsa.e.length = data_tc->rsa_data.e.len;
395 xform_tc.rsa.n.data = data_tc->rsa_data.n.data;
396 xform_tc.rsa.n.length = data_tc->rsa_data.n.len;
398 if (key_type == RTE_RSA_KEY_TYPE_EXP) {
399 xform_tc.rsa.d.data = data_tc->rsa_data.d.data;
400 xform_tc.rsa.d.length = data_tc->rsa_data.d.len;
402 xform_tc.rsa.qt.p.data = data_tc->rsa_data.p.data;
403 xform_tc.rsa.qt.p.length = data_tc->rsa_data.p.len;
404 xform_tc.rsa.qt.q.data = data_tc->rsa_data.q.data;
405 xform_tc.rsa.qt.q.length = data_tc->rsa_data.q.len;
406 xform_tc.rsa.qt.dP.data = data_tc->rsa_data.dP.data;
407 xform_tc.rsa.qt.dP.length = data_tc->rsa_data.dP.len;
408 xform_tc.rsa.qt.dQ.data = data_tc->rsa_data.dQ.data;
409 xform_tc.rsa.qt.dQ.length = data_tc->rsa_data.dQ.len;
410 xform_tc.rsa.qt.qInv.data = data_tc->rsa_data.qInv.data;
411 xform_tc.rsa.qt.qInv.length = data_tc->rsa_data.qInv.len;
414 xform_tc.rsa.key_type = key_type;
415 op->asym->rsa.padding.type = data_tc->rsa_data.padding;
417 if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
418 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
419 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
420 asym_op->rsa.cipher.data = result;
421 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
422 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
423 asym_op->rsa.message.data = result;
424 asym_op->rsa.message.length = data_tc->rsa_data.n.len;
425 asym_op->rsa.cipher.data = data_tc->rsa_data.ct.data;
426 asym_op->rsa.cipher.length = data_tc->rsa_data.ct.len;
427 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
428 asym_op->rsa.sign.data = result;
429 asym_op->rsa.sign.length = data_tc->rsa_data.n.len;
430 asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
431 asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
432 } else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
433 asym_op->rsa.cipher.data = result;
434 asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
435 asym_op->rsa.sign.data = data_tc->rsa_data.sign.data;
436 asym_op->rsa.sign.length = data_tc->rsa_data.sign.len;
439 case RTE_CRYPTO_ASYM_XFORM_DH:
440 case RTE_CRYPTO_ASYM_XFORM_DSA:
441 case RTE_CRYPTO_ASYM_XFORM_NONE:
442 case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
444 snprintf(test_msg, ASYM_TEST_MSG_LEN,
446 "FAILED: %s", __LINE__,
447 "Invalid ASYM algorithm specified");
448 status = TEST_FAILED;
453 ret = rte_cryptodev_asym_session_create(dev_id, &xform_tc,
454 ts_params->session_mpool, &sess);
456 snprintf(test_msg, ASYM_TEST_MSG_LEN,
458 "FAILED: %s", __LINE__,
459 "Session creation failed");
460 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
464 rte_crypto_op_attach_asym_session(op, sess);
466 asym_op->xform = &xform_tc;
467 op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
469 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
471 /* Process crypto operation */
472 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
473 snprintf(test_msg, ASYM_TEST_MSG_LEN,
474 "line %u FAILED: %s",
475 __LINE__, "Error sending packet for operation");
476 status = TEST_FAILED;
480 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
483 if (result_op == NULL) {
484 snprintf(test_msg, ASYM_TEST_MSG_LEN,
485 "line %u FAILED: %s",
486 __LINE__, "Failed to process asym crypto op");
487 status = TEST_FAILED;
491 if (test_cryptodev_asym_ver(op, &xform_tc, data_tc, result_op) != TEST_SUCCESS) {
492 snprintf(test_msg, ASYM_TEST_MSG_LEN,
493 "line %u FAILED: %s",
494 __LINE__, "Verification failed ");
495 status = TEST_FAILED;
500 snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
502 snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
506 rte_cryptodev_asym_session_free(dev_id, sess);
509 rte_crypto_op_free(op);
517 test_one_case(const void *test_case, int sessionless)
519 int status = TEST_SUCCESS, i = 0;
520 char test_msg[ASYM_TEST_MSG_LEN + 1];
522 /* Map the case to union */
523 union test_case_structure tc;
524 memcpy(&tc, test_case, sizeof(tc));
526 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX
527 || tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
528 status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
530 printf(" %u) TestCase %s %s\n", test_index++,
531 tc.modex.description, test_msg);
533 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
534 if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
535 if (tc.rsa_data.op_type_flags & (1 << i)) {
536 if (tc.rsa_data.key_exp) {
537 status = test_cryptodev_asym_op(
538 &testsuite_params, &tc,
539 test_msg, sessionless, i,
540 RTE_RSA_KEY_TYPE_EXP);
544 if (tc.rsa_data.key_qt && (i ==
545 RTE_CRYPTO_ASYM_OP_DECRYPT ||
546 i == RTE_CRYPTO_ASYM_OP_SIGN)) {
547 status = test_cryptodev_asym_op(
549 &tc, test_msg, sessionless, i,
550 RTE_RSA_KEY_TYPE_QT);
557 printf(" %u) TestCase %s %s\n", test_index++,
558 tc.modex.description, test_msg);
565 load_test_vectors(void)
567 uint32_t i = 0, v_size = 0;
568 /* Load MODEX vector*/
569 v_size = RTE_DIM(modex_test_case);
570 for (i = 0; i < v_size; i++) {
571 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
572 RTE_LOG(DEBUG, USER1,
573 "TEST_VECTOR_SIZE too small\n");
576 test_vector.address[test_vector.size] = &modex_test_case[i];
579 /* Load MODINV vector*/
580 v_size = RTE_DIM(modinv_test_case);
581 for (i = 0; i < v_size; i++) {
582 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
583 RTE_LOG(DEBUG, USER1,
584 "TEST_VECTOR_SIZE too small\n");
587 test_vector.address[test_vector.size] = &modinv_test_case[i];
591 v_size = RTE_DIM(rsa_test_case_list);
592 for (i = 0; i < v_size; i++) {
593 if (test_vector.size >= (TEST_VECTOR_SIZE)) {
594 RTE_LOG(DEBUG, USER1,
595 "TEST_VECTOR_SIZE too small\n");
598 test_vector.address[test_vector.size] = &rsa_test_case_list[i];
605 test_one_by_one(void)
607 int status = TEST_SUCCESS;
608 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
610 uint8_t dev_id = ts_params->valid_devs[0];
611 struct rte_cryptodev_info dev_info;
614 rte_cryptodev_info_get(dev_id, &dev_info);
615 if ((dev_info.feature_flags &
616 RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
620 /* Go through all test cases */
622 for (i = 0; i < test_vector.size; i++) {
623 if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
624 status = TEST_FAILED;
627 for (i = 0; i < test_vector.size; i++) {
628 if (test_one_case(test_vector.address[i], 1)
630 status = TEST_FAILED;
634 TEST_ASSERT_EQUAL(status, 0, "Test failed");
639 test_rsa_sign_verify(void)
641 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
642 struct rte_mempool *sess_mpool = ts_params->session_mpool;
643 uint8_t dev_id = ts_params->valid_devs[0];
645 struct rte_cryptodev_info dev_info;
646 int ret, status = TEST_SUCCESS;
648 /* Test case supports op with exponent key only,
649 * Check in PMD feature flag for RSA exponent key type support.
651 rte_cryptodev_info_get(dev_id, &dev_info);
652 if (!(dev_info.feature_flags &
653 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
654 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
655 "exponent key type. Test Skipped\n");
659 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
662 RTE_LOG(ERR, USER1, "Session creation failed for "
664 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
668 status = queue_ops_rsa_sign_verify(sess);
671 rte_cryptodev_asym_session_free(dev_id, sess);
673 TEST_ASSERT_EQUAL(status, 0, "Test failed");
679 test_rsa_enc_dec(void)
681 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
682 struct rte_mempool *sess_mpool = ts_params->session_mpool;
683 uint8_t dev_id = ts_params->valid_devs[0];
685 struct rte_cryptodev_info dev_info;
686 int ret, status = TEST_SUCCESS;
688 /* Test case supports op with exponent key only,
689 * Check in PMD feature flag for RSA exponent key type support.
691 rte_cryptodev_info_get(dev_id, &dev_info);
692 if (!(dev_info.feature_flags &
693 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
694 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
695 "exponent key type. Test skipped\n");
699 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
702 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
703 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
707 status = queue_ops_rsa_enc_dec(sess);
711 rte_cryptodev_asym_session_free(dev_id, sess);
713 TEST_ASSERT_EQUAL(status, 0, "Test failed");
719 test_rsa_sign_verify_crt(void)
721 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
722 struct rte_mempool *sess_mpool = ts_params->session_mpool;
723 uint8_t dev_id = ts_params->valid_devs[0];
725 struct rte_cryptodev_info dev_info;
726 int ret, status = TEST_SUCCESS;
728 /* Test case supports op with quintuple format key only,
729 * Check im PMD feature flag for RSA quintuple key type support.
731 rte_cryptodev_info_get(dev_id, &dev_info);
732 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
733 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
734 "quintuple key type. Test skipped\n");
738 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
741 RTE_LOG(ERR, USER1, "Session creation failed for "
742 "sign_verify_crt\n");
743 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
747 status = queue_ops_rsa_sign_verify(sess);
751 rte_cryptodev_asym_session_free(dev_id, sess);
753 TEST_ASSERT_EQUAL(status, 0, "Test failed");
759 test_rsa_enc_dec_crt(void)
761 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
762 struct rte_mempool *sess_mpool = ts_params->session_mpool;
763 uint8_t dev_id = ts_params->valid_devs[0];
765 struct rte_cryptodev_info dev_info;
766 int ret, status = TEST_SUCCESS;
768 /* Test case supports op with quintuple format key only,
769 * Check in PMD feature flag for RSA quintuple key type support.
771 rte_cryptodev_info_get(dev_id, &dev_info);
772 if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
773 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
774 "quintuple key type. Test skipped\n");
778 ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
781 RTE_LOG(ERR, USER1, "Session creation failed for "
783 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
787 status = queue_ops_rsa_enc_dec(sess);
791 rte_cryptodev_asym_session_free(dev_id, sess);
793 TEST_ASSERT_EQUAL(status, 0, "Test failed");
799 testsuite_setup(void)
801 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
802 uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
803 struct rte_cryptodev_info info;
804 int ret, dev_id = -1;
808 memset(ts_params, 0, sizeof(*ts_params));
810 test_vector.size = 0;
813 /* Device, op pool and session configuration for asymmetric crypto. 8< */
814 ts_params->op_mpool = rte_crypto_op_pool_create(
815 "CRYPTO_ASYM_OP_POOL",
816 RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
820 if (ts_params->op_mpool == NULL) {
821 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
825 /* Create an OPENSSL device if required */
826 if (gbl_driver_id == rte_cryptodev_driver_id_get(
827 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
828 nb_devs = rte_cryptodev_device_count_by_driver(
829 rte_cryptodev_driver_id_get(
830 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
833 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
836 TEST_ASSERT(ret == 0, "Failed to create "
837 "instance of pmd : %s",
838 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
842 /* Get list of valid crypto devs */
843 nb_devs = rte_cryptodev_devices_get(
844 rte_cryptodev_driver_name_get(gbl_driver_id),
845 valid_devs, RTE_CRYPTO_MAX_DEVS);
847 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
852 * Get first valid asymmetric device found in test suite param and
855 for (i = 0; i < nb_devs ; i++) {
856 rte_cryptodev_info_get(valid_devs[i], &info);
857 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
858 dev_id = ts_params->valid_devs[0] = valid_devs[i];
864 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
869 /* Set valid device count */
870 ts_params->valid_dev_count = nb_devs;
872 /* configure device with num qp */
873 ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
874 ts_params->conf.socket_id = SOCKET_ID_ANY;
875 ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
876 RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
877 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
879 "Failed to configure cryptodev %u with %u qps",
880 dev_id, ts_params->conf.nb_queue_pairs);
883 ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
884 ts_params->qp_conf.mp_session = ts_params->session_mpool;
885 for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
886 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
887 dev_id, qp_id, &ts_params->qp_conf,
888 rte_cryptodev_socket_id(dev_id)),
889 "Failed to setup queue pair %u on cryptodev %u ASYM",
893 ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
894 "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
897 TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
898 "session mempool allocation failed");
899 /* >8 End of device, op pool and session configuration for asymmetric crypto section. */
904 testsuite_teardown(void)
906 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
908 if (ts_params->op_mpool != NULL) {
909 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
910 rte_mempool_avail_count(ts_params->op_mpool));
913 /* Free session mempools */
914 if (ts_params->session_mpool != NULL) {
915 rte_mempool_free(ts_params->session_mpool);
916 ts_params->session_mpool = NULL;
923 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
927 /* Reconfigure device to default parameters */
928 ts_params->conf.socket_id = SOCKET_ID_ANY;
930 TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
932 "Failed to configure cryptodev %u",
933 ts_params->valid_devs[0]);
935 for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
936 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
937 ts_params->valid_devs[0], qp_id,
939 rte_cryptodev_socket_id(ts_params->valid_devs[0])),
940 "Failed to setup queue pair %u on cryptodev %u",
941 qp_id, ts_params->valid_devs[0]);
944 rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
946 /* Start the device */
947 TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
948 "Failed to start cryptodev %u",
949 ts_params->valid_devs[0]);
955 ut_teardown_asym(void)
957 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
958 struct rte_cryptodev_stats stats;
960 rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
962 /* Stop the device */
963 rte_cryptodev_stop(ts_params->valid_devs[0]);
966 static inline void print_asym_capa(
967 const struct rte_cryptodev_asymmetric_xform_capability *capa)
971 printf("\nxform type: %s\n===================\n",
972 rte_crypto_asym_xform_strings[capa->xform_type]);
973 printf("operation supported -");
975 for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
976 /* check supported operations */
977 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) {
978 if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH)
979 printf(" %s", rte_crypto_asym_ke_strings[i]);
981 printf(" %s", rte_crypto_asym_op_strings[i]);
984 switch (capa->xform_type) {
985 case RTE_CRYPTO_ASYM_XFORM_RSA:
986 case RTE_CRYPTO_ASYM_XFORM_MODINV:
987 case RTE_CRYPTO_ASYM_XFORM_MODEX:
988 case RTE_CRYPTO_ASYM_XFORM_DH:
989 case RTE_CRYPTO_ASYM_XFORM_DSA:
990 printf(" modlen: min %d max %d increment %d",
993 capa->modlen.increment);
995 case RTE_CRYPTO_ASYM_XFORM_ECDSA:
996 case RTE_CRYPTO_ASYM_XFORM_ECPM:
1004 test_capability(void)
1006 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1007 uint8_t dev_id = ts_params->valid_devs[0];
1008 struct rte_cryptodev_info dev_info;
1009 const struct rte_cryptodev_capabilities *dev_capa;
1011 struct rte_cryptodev_asym_capability_idx idx;
1012 const struct rte_cryptodev_asymmetric_xform_capability *capa;
1014 rte_cryptodev_info_get(dev_id, &dev_info);
1015 if (!(dev_info.feature_flags &
1016 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1017 RTE_LOG(INFO, USER1,
1018 "Device doesn't support asymmetric. Test Skipped\n");
1019 return TEST_SUCCESS;
1022 /* print xform capability */
1024 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1026 dev_capa = &(dev_info.capabilities[i]);
1027 if (dev_info.capabilities[i].op ==
1028 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1029 idx.type = dev_capa->asym.xform_capa.xform_type;
1031 capa = rte_cryptodev_asym_capability_get(dev_id,
1033 rte_cryptodev_asym_capability_idx *) &idx);
1034 print_asym_capa(capa);
1037 return TEST_SUCCESS;
1041 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1043 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1044 struct rte_mempool *op_mpool = ts_params->op_mpool;
1045 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1046 uint8_t dev_id = ts_params->valid_devs[0];
1047 struct rte_crypto_asym_op *asym_op = NULL;
1048 struct rte_crypto_op *op = NULL, *result_op = NULL;
1050 int ret, status = TEST_SUCCESS;
1051 uint8_t output[TEST_DH_MOD_LEN];
1052 struct rte_crypto_asym_xform xform = *xfrm;
1053 uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1055 /* set up crypto op data structure */
1056 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1059 "line %u FAILED: %s",
1060 __LINE__, "Failed to allocate asymmetric crypto "
1061 "operation struct");
1062 status = TEST_FAILED;
1067 /* Setup a xform and op to generate private key only */
1069 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
1070 asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1071 asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1072 asym_op->dh.pub_key.data = (uint8_t *)peer;
1073 asym_op->dh.pub_key.length = sizeof(peer);
1074 asym_op->dh.shared_secret.data = output;
1075 asym_op->dh.shared_secret.length = sizeof(output);
1077 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1080 "line %u FAILED: %s", __LINE__,
1081 "Session creation failed");
1082 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1086 /* attach asymmetric crypto session to crypto operations */
1087 rte_crypto_op_attach_asym_session(op, sess);
1089 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1091 /* Process crypto operation */
1092 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1094 "line %u FAILED: %s",
1095 __LINE__, "Error sending packet for operation");
1096 status = TEST_FAILED;
1100 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1103 if (result_op == NULL) {
1105 "line %u FAILED: %s",
1106 __LINE__, "Failed to process asym crypto op");
1107 status = TEST_FAILED;
1111 debug_hexdump(stdout, "shared secret:",
1112 asym_op->dh.shared_secret.data,
1113 asym_op->dh.shared_secret.length);
1117 rte_cryptodev_asym_session_free(dev_id, sess);
1119 rte_crypto_op_free(op);
1124 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1126 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1127 struct rte_mempool *op_mpool = ts_params->op_mpool;
1128 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1129 uint8_t dev_id = ts_params->valid_devs[0];
1130 struct rte_crypto_asym_op *asym_op = NULL;
1131 struct rte_crypto_op *op = NULL, *result_op = NULL;
1133 int ret, status = TEST_SUCCESS;
1134 uint8_t output[TEST_DH_MOD_LEN];
1135 struct rte_crypto_asym_xform xform = *xfrm;
1137 /* set up crypto op data structure */
1138 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1141 "line %u FAILED: %s",
1142 __LINE__, "Failed to allocate asymmetric crypto "
1143 "operation struct");
1144 status = TEST_FAILED;
1149 /* Setup a xform and op to generate private key only */
1151 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
1152 asym_op->dh.priv_key.data = output;
1153 asym_op->dh.priv_key.length = sizeof(output);
1155 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1158 "line %u FAILED: %s", __LINE__,
1159 "Session creation failed");
1160 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1164 /* attach asymmetric crypto session to crypto operations */
1165 rte_crypto_op_attach_asym_session(op, sess);
1167 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1169 /* Process crypto operation */
1170 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1172 "line %u FAILED: %s",
1173 __LINE__, "Error sending packet for operation");
1174 status = TEST_FAILED;
1178 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1181 if (result_op == NULL) {
1183 "line %u FAILED: %s",
1184 __LINE__, "Failed to process asym crypto op");
1185 status = TEST_FAILED;
1189 debug_hexdump(stdout, "private key:",
1190 asym_op->dh.priv_key.data,
1191 asym_op->dh.priv_key.length);
1196 rte_cryptodev_asym_session_free(dev_id, sess);
1198 rte_crypto_op_free(op);
1205 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1207 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1208 struct rte_mempool *op_mpool = ts_params->op_mpool;
1209 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1210 uint8_t dev_id = ts_params->valid_devs[0];
1211 struct rte_crypto_asym_op *asym_op = NULL;
1212 struct rte_crypto_op *op = NULL, *result_op = NULL;
1214 int ret, status = TEST_SUCCESS;
1215 uint8_t output[TEST_DH_MOD_LEN];
1216 struct rte_crypto_asym_xform xform = *xfrm;
1218 /* set up crypto op data structure */
1219 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1222 "line %u FAILED: %s",
1223 __LINE__, "Failed to allocate asymmetric crypto "
1224 "operation struct");
1225 status = TEST_FAILED;
1229 /* Setup a xform chain to generate public key
1230 * using test private key
1235 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
1236 asym_op->dh.pub_key.data = output;
1237 asym_op->dh.pub_key.length = sizeof(output);
1238 /* load pre-defined private key */
1239 asym_op->dh.priv_key.data = rte_malloc(NULL,
1240 dh_test_params.priv_key.length,
1242 asym_op->dh.priv_key = dh_test_params.priv_key;
1244 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1247 "line %u FAILED: %s", __LINE__,
1248 "Session creation failed");
1249 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1253 /* attach asymmetric crypto session to crypto operations */
1254 rte_crypto_op_attach_asym_session(op, sess);
1256 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1258 /* Process crypto operation */
1259 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1261 "line %u FAILED: %s",
1262 __LINE__, "Error sending packet for operation");
1263 status = TEST_FAILED;
1267 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1270 if (result_op == NULL) {
1272 "line %u FAILED: %s",
1273 __LINE__, "Failed to process asym crypto op");
1274 status = TEST_FAILED;
1278 debug_hexdump(stdout, "pub key:",
1279 asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1281 debug_hexdump(stdout, "priv key:",
1282 asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1286 rte_cryptodev_asym_session_free(dev_id, sess);
1288 rte_crypto_op_free(op);
1294 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1296 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1297 struct rte_mempool *op_mpool = ts_params->op_mpool;
1298 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1299 uint8_t dev_id = ts_params->valid_devs[0];
1300 struct rte_crypto_asym_op *asym_op = NULL;
1301 struct rte_crypto_op *op = NULL, *result_op = NULL;
1303 int ret, status = TEST_SUCCESS;
1304 uint8_t out_pub_key[TEST_DH_MOD_LEN];
1305 uint8_t out_prv_key[TEST_DH_MOD_LEN];
1306 struct rte_crypto_asym_xform pub_key_xform;
1307 struct rte_crypto_asym_xform xform = *xfrm;
1309 /* set up crypto op data structure */
1310 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1313 "line %u FAILED: %s",
1314 __LINE__, "Failed to allocate asymmetric crypto "
1315 "operation struct");
1316 status = TEST_FAILED;
1320 /* Setup a xform chain to generate
1321 * private key first followed by
1324 pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1325 xform.next = &pub_key_xform;
1327 asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
1328 asym_op->dh.pub_key.data = out_pub_key;
1329 asym_op->dh.pub_key.length = sizeof(out_pub_key);
1330 asym_op->dh.priv_key.data = out_prv_key;
1331 asym_op->dh.priv_key.length = 0;
1333 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1336 "line %u FAILED: %s", __LINE__,
1337 "Session creation failed");
1338 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1342 /* attach asymmetric crypto session to crypto operations */
1343 rte_crypto_op_attach_asym_session(op, sess);
1345 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1347 /* Process crypto operation */
1348 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1350 "line %u FAILED: %s",
1351 __LINE__, "Error sending packet for operation");
1352 status = TEST_FAILED;
1356 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1359 if (result_op == NULL) {
1361 "line %u FAILED: %s",
1362 __LINE__, "Failed to process asym crypto op");
1363 status = TEST_FAILED;
1366 debug_hexdump(stdout, "priv key:",
1367 out_prv_key, asym_op->dh.priv_key.length);
1368 debug_hexdump(stdout, "pub key:",
1369 out_pub_key, asym_op->dh.pub_key.length);
1373 rte_cryptodev_asym_session_free(dev_id, sess);
1375 rte_crypto_op_free(op);
1383 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1384 struct rte_mempool *op_mpool = ts_params->op_mpool;
1385 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1386 uint8_t dev_id = ts_params->valid_devs[0];
1387 struct rte_crypto_asym_op *asym_op = NULL;
1388 struct rte_crypto_op *op = NULL, *result_op = NULL;
1390 int status = TEST_SUCCESS;
1391 struct rte_cryptodev_asym_capability_idx cap_idx;
1392 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1393 uint8_t input[TEST_DATA_SIZE] = {0};
1395 uint8_t result[sizeof(mod_p)] = { 0 };
1397 if (rte_cryptodev_asym_get_xform_enum(
1398 &modinv_xform.xform_type, "modinv") < 0) {
1400 "Invalid ASYM algorithm specified\n");
1404 cap_idx.type = modinv_xform.xform_type;
1405 capability = rte_cryptodev_asym_capability_get(dev_id,
1408 if (capability == NULL) {
1409 RTE_LOG(INFO, USER1,
1410 "Device doesn't support MOD INV. Test Skipped\n");
1411 return TEST_SKIPPED;
1414 if (rte_cryptodev_asym_xform_capability_check_modlen(
1416 modinv_xform.modinv.modulus.length)) {
1418 "Invalid MODULUS length specified\n");
1419 return TEST_SKIPPED;
1422 ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
1424 RTE_LOG(ERR, USER1, "line %u "
1425 "FAILED: %s", __LINE__,
1426 "Session creation failed");
1427 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1431 /* generate crypto op data structure */
1432 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1435 "line %u FAILED: %s",
1436 __LINE__, "Failed to allocate asymmetric crypto "
1437 "operation struct");
1438 status = TEST_FAILED;
1443 memcpy(input, base, sizeof(base));
1444 asym_op->modinv.base.data = input;
1445 asym_op->modinv.base.length = sizeof(base);
1446 asym_op->modinv.result.data = result;
1447 asym_op->modinv.result.length = sizeof(result);
1449 /* attach asymmetric crypto session to crypto operations */
1450 rte_crypto_op_attach_asym_session(op, sess);
1452 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1454 /* Process crypto operation */
1455 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1457 "line %u FAILED: %s",
1458 __LINE__, "Error sending packet for operation");
1459 status = TEST_FAILED;
1463 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1466 if (result_op == NULL) {
1468 "line %u FAILED: %s",
1469 __LINE__, "Failed to process asym crypto op");
1470 status = TEST_FAILED;
1474 ret = verify_modinv(mod_inv, result_op);
1477 "operation verification failed\n");
1478 status = TEST_FAILED;
1483 rte_cryptodev_asym_session_free(dev_id, sess);
1486 rte_crypto_op_free(op);
1488 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1496 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1497 struct rte_mempool *op_mpool = ts_params->op_mpool;
1498 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1499 uint8_t dev_id = ts_params->valid_devs[0];
1500 struct rte_crypto_asym_op *asym_op = NULL;
1501 struct rte_crypto_op *op = NULL, *result_op = NULL;
1503 int status = TEST_SUCCESS;
1504 struct rte_cryptodev_asym_capability_idx cap_idx;
1505 const struct rte_cryptodev_asymmetric_xform_capability *capability;
1506 uint8_t input[TEST_DATA_SIZE] = {0};
1508 uint8_t result[sizeof(mod_p)] = { 0 };
1510 if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1514 "Invalid ASYM algorithm specified\n");
1518 /* check for modlen capability */
1519 cap_idx.type = modex_xform.xform_type;
1520 capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1522 if (capability == NULL) {
1523 RTE_LOG(INFO, USER1,
1524 "Device doesn't support MOD EXP. Test Skipped\n");
1525 return TEST_SKIPPED;
1528 if (rte_cryptodev_asym_xform_capability_check_modlen(
1529 capability, modex_xform.modex.modulus.length)) {
1531 "Invalid MODULUS length specified\n");
1532 return TEST_SKIPPED;
1535 /* Create op, create session, and process packets. 8< */
1536 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1539 "line %u FAILED: %s",
1540 __LINE__, "Failed to allocate asymmetric crypto "
1541 "operation struct");
1542 status = TEST_FAILED;
1546 ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
1550 "FAILED: %s", __LINE__,
1551 "Session creation failed");
1552 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1557 memcpy(input, base, sizeof(base));
1558 asym_op->modex.base.data = input;
1559 asym_op->modex.base.length = sizeof(base);
1560 asym_op->modex.result.data = result;
1561 asym_op->modex.result.length = sizeof(result);
1562 /* attach asymmetric crypto session to crypto operations */
1563 rte_crypto_op_attach_asym_session(op, sess);
1565 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1566 /* Process crypto operation */
1567 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1569 "line %u FAILED: %s",
1570 __LINE__, "Error sending packet for operation");
1571 status = TEST_FAILED;
1575 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1578 if (result_op == NULL) {
1580 "line %u FAILED: %s",
1581 __LINE__, "Failed to process asym crypto op");
1582 status = TEST_FAILED;
1585 /* >8 End of create op, create session, and process packets section. */
1586 ret = verify_modexp(mod_exp, result_op);
1589 "operation verification failed\n");
1590 status = TEST_FAILED;
1595 rte_cryptodev_asym_session_free(dev_id, sess);
1598 rte_crypto_op_free(op);
1600 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1606 test_dh_keygenration(void)
1610 debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1611 debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1612 debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1613 dh_test_params.priv_key.length);
1615 RTE_LOG(INFO, USER1,
1616 "Test Public and Private key pair generation\n");
1618 status = test_dh_gen_kp(&dh_xform);
1619 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1621 RTE_LOG(INFO, USER1,
1622 "Test Public Key Generation using pre-defined priv key\n");
1624 status = test_dh_gen_pub_key(&dh_xform);
1625 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1627 RTE_LOG(INFO, USER1,
1628 "Test Private Key Generation only\n");
1630 status = test_dh_gen_priv_key(&dh_xform);
1631 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1633 RTE_LOG(INFO, USER1,
1634 "Test shared secret compute\n");
1636 status = test_dh_gen_shared_sec(&dh_xform);
1637 TEST_ASSERT_EQUAL(status, 0, "Test failed");
1643 test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op)
1645 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1646 struct rte_mempool *op_mpool = ts_params->op_mpool;
1647 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1648 uint8_t dev_id = ts_params->valid_devs[0];
1649 struct rte_crypto_asym_op *asym_op = NULL;
1650 struct rte_crypto_op *op = NULL, *result_op = NULL;
1652 int status = TEST_SUCCESS;
1655 ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1658 "line %u FAILED: %s", __LINE__,
1659 "Session creation failed");
1660 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1663 /* set up crypto op data structure */
1664 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1667 "line %u FAILED: %s",
1668 __LINE__, "Failed to allocate asymmetric crypto "
1669 "operation struct");
1670 status = TEST_FAILED;
1674 asym_op->dsa = *dsa_op;
1676 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1677 dsa_xform.dsa.p.length);
1678 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1679 dsa_xform.dsa.q.length);
1680 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1681 dsa_xform.dsa.g.length);
1682 debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1683 dsa_xform.dsa.x.length);
1685 /* attach asymmetric crypto session to crypto operations */
1686 rte_crypto_op_attach_asym_session(op, sess);
1687 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1688 RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1690 /* Process crypto operation */
1691 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1693 "line %u FAILED: %s",
1694 __LINE__, "Error sending packet for operation");
1695 status = TEST_FAILED;
1699 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1702 if (result_op == NULL) {
1704 "line %u FAILED: %s",
1705 __LINE__, "Failed to process asym crypto op");
1706 status = TEST_FAILED;
1710 asym_op = result_op->asym;
1711 dsa_op->r.length = asym_op->dsa.r.length;
1712 dsa_op->s.length = asym_op->dsa.s.length;
1714 debug_hexdump(stdout, "r:",
1715 asym_op->dsa.r.data, asym_op->dsa.r.length);
1716 debug_hexdump(stdout, "s:",
1717 asym_op->dsa.s.data, asym_op->dsa.s.length);
1720 rte_cryptodev_asym_session_free(dev_id, sess);
1722 rte_crypto_op_free(op);
1727 test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op)
1729 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1730 struct rte_mempool *op_mpool = ts_params->op_mpool;
1731 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1732 uint8_t dev_id = ts_params->valid_devs[0];
1733 struct rte_crypto_asym_op *asym_op = NULL;
1734 struct rte_crypto_op *op = NULL, *result_op = NULL;
1736 int status = TEST_SUCCESS;
1739 ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1742 "line %u FAILED: %s", __LINE__,
1743 "Session creation failed");
1744 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1747 /* set up crypto op data structure */
1748 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1751 "line %u FAILED: %s",
1752 __LINE__, "Failed to allocate asymmetric crypto "
1753 "operation struct");
1754 status = TEST_FAILED;
1758 asym_op->dsa = *dsa_op;
1760 debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1761 dsa_xform.dsa.p.length);
1762 debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1763 dsa_xform.dsa.q.length);
1764 debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1765 dsa_xform.dsa.g.length);
1767 /* attach asymmetric crypto session to crypto operations */
1768 rte_crypto_op_attach_asym_session(op, sess);
1770 debug_hexdump(stdout, "r:",
1771 asym_op->dsa.r.data, asym_op->dsa.r.length);
1772 debug_hexdump(stdout, "s:",
1773 asym_op->dsa.s.data, asym_op->dsa.s.length);
1775 RTE_LOG(DEBUG, USER1, "Process ASYM verify operation");
1776 /* Test PMD DSA sign verification using signer public key */
1777 asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1779 /* copy signer public key */
1780 asym_op->dsa.y.data = dsa_test_params.y.data;
1781 asym_op->dsa.y.length = dsa_test_params.y.length;
1783 /* Process crypto operation */
1784 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1786 "line %u FAILED: %s",
1787 __LINE__, "Error sending packet for operation");
1788 status = TEST_FAILED;
1792 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1795 if (result_op == NULL) {
1797 "line %u FAILED: %s",
1798 __LINE__, "Failed to process asym crypto op");
1799 status = TEST_FAILED;
1803 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1805 "line %u FAILED: %s",
1806 __LINE__, "Failed to process asym crypto op");
1807 status = TEST_FAILED;
1811 rte_cryptodev_asym_session_free(dev_id, sess);
1813 rte_crypto_op_free(op);
1821 uint8_t r[TEST_DH_MOD_LEN];
1822 uint8_t s[TEST_DH_MOD_LEN];
1823 struct rte_crypto_dsa_op_param dsa_op;
1824 uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1826 dsa_op.message.data = dgst;
1827 dsa_op.message.length = sizeof(dgst);
1830 dsa_op.r.length = sizeof(r);
1831 dsa_op.s.length = sizeof(s);
1833 status = test_dsa_sign(&dsa_op);
1834 TEST_ASSERT_EQUAL(status, 0, "DSA sign test failed");
1835 status = test_dsa_verify(&dsa_op);
1836 TEST_ASSERT_EQUAL(status, 0, "DSA verify test failed");
1841 test_ecdsa_sign_verify(enum curve curve_id)
1843 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1844 struct rte_mempool *sess_mpool = ts_params->session_mpool;
1845 struct rte_mempool *op_mpool = ts_params->op_mpool;
1846 struct crypto_testsuite_ecdsa_params input_params;
1848 uint8_t dev_id = ts_params->valid_devs[0];
1849 struct rte_crypto_op *result_op = NULL;
1850 uint8_t output_buf_r[TEST_DATA_SIZE];
1851 uint8_t output_buf_s[TEST_DATA_SIZE];
1852 struct rte_crypto_asym_xform xform;
1853 struct rte_crypto_asym_op *asym_op;
1854 struct rte_cryptodev_info dev_info;
1855 struct rte_crypto_op *op = NULL;
1856 int ret, status = TEST_SUCCESS;
1860 input_params = ecdsa_param_secp192r1;
1863 input_params = ecdsa_param_secp224r1;
1866 input_params = ecdsa_param_secp256r1;
1869 input_params = ecdsa_param_secp384r1;
1872 input_params = ecdsa_param_secp521r1;
1876 "line %u FAILED: %s", __LINE__,
1877 "Unsupported curve id\n");
1878 status = TEST_FAILED;
1882 rte_cryptodev_info_get(dev_id, &dev_info);
1884 /* Setup crypto op data structure */
1885 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1888 "line %u FAILED: %s", __LINE__,
1889 "Failed to allocate asymmetric crypto "
1890 "operation struct\n");
1891 status = TEST_FAILED;
1896 /* Setup asym xform */
1898 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1899 xform.ec.curve_id = input_params.curve;
1901 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1904 "line %u FAILED: %s", __LINE__,
1905 "Session creation failed\n");
1906 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1910 /* Attach asymmetric crypto session to crypto operations */
1911 rte_crypto_op_attach_asym_session(op, sess);
1915 /* Populate op with operational details */
1916 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1917 op->asym->ecdsa.message.data = input_params.digest.data;
1918 op->asym->ecdsa.message.length = input_params.digest.length;
1919 op->asym->ecdsa.k.data = input_params.scalar.data;
1920 op->asym->ecdsa.k.length = input_params.scalar.length;
1921 op->asym->ecdsa.pkey.data = input_params.pkey.data;
1922 op->asym->ecdsa.pkey.length = input_params.pkey.length;
1925 op->asym->ecdsa.r.data = output_buf_r;
1926 op->asym->ecdsa.s.data = output_buf_s;
1928 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1930 /* Process crypto operation */
1931 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1933 "line %u FAILED: %s", __LINE__,
1934 "Error sending packet for operation\n");
1935 status = TEST_FAILED;
1939 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1942 if (result_op == NULL) {
1944 "line %u FAILED: %s", __LINE__,
1945 "Failed to process asym crypto op\n");
1946 status = TEST_FAILED;
1950 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1952 "line %u FAILED: %s", __LINE__,
1953 "Failed to process asym crypto op\n");
1954 status = TEST_FAILED;
1958 asym_op = result_op->asym;
1960 debug_hexdump(stdout, "r:",
1961 asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
1962 debug_hexdump(stdout, "s:",
1963 asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
1965 ret = verify_ecdsa_sign(input_params.sign_r.data,
1966 input_params.sign_s.data, result_op);
1968 status = TEST_FAILED;
1970 "line %u FAILED: %s", __LINE__,
1971 "ECDSA sign failed.\n");
1977 /* Populate op with operational details */
1978 op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1979 op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
1980 op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
1981 op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
1982 op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
1983 op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
1984 op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
1985 op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
1986 op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
1988 /* Enqueue sign result for verify */
1989 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1990 status = TEST_FAILED;
1992 "line %u FAILED: %s", __LINE__,
1993 "Error sending packet for operation\n");
1997 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2000 if (result_op == NULL) {
2001 status = TEST_FAILED;
2004 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2005 status = TEST_FAILED;
2007 "line %u FAILED: %s", __LINE__,
2008 "ECDSA verify failed.\n");
2014 rte_cryptodev_asym_session_free(dev_id, sess);
2016 rte_crypto_op_free(op);
2021 test_ecdsa_sign_verify_all_curve(void)
2023 int status, overall_status = TEST_SUCCESS;
2024 enum curve curve_id;
2028 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2029 status = test_ecdsa_sign_verify(curve_id);
2030 if (status == TEST_SUCCESS) {
2034 overall_status = status;
2036 printf(" %u) TestCase Sign/Veriy Curve %s %s\n",
2037 test_index ++, curve[curve_id], msg);
2039 return overall_status;
2043 test_ecpm(enum curve curve_id)
2045 struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2046 struct rte_mempool *sess_mpool = ts_params->session_mpool;
2047 struct rte_mempool *op_mpool = ts_params->op_mpool;
2048 struct crypto_testsuite_ecpm_params input_params;
2050 uint8_t dev_id = ts_params->valid_devs[0];
2051 struct rte_crypto_op *result_op = NULL;
2052 uint8_t output_buf_x[TEST_DATA_SIZE];
2053 uint8_t output_buf_y[TEST_DATA_SIZE];
2054 struct rte_crypto_asym_xform xform;
2055 struct rte_crypto_asym_op *asym_op;
2056 struct rte_cryptodev_info dev_info;
2057 struct rte_crypto_op *op = NULL;
2058 int ret, status = TEST_SUCCESS;
2062 input_params = ecpm_param_secp192r1;
2065 input_params = ecpm_param_secp224r1;
2068 input_params = ecpm_param_secp256r1;
2071 input_params = ecpm_param_secp384r1;
2074 input_params = ecpm_param_secp521r1;
2078 "line %u FAILED: %s", __LINE__,
2079 "Unsupported curve id\n");
2080 status = TEST_FAILED;
2084 rte_cryptodev_info_get(dev_id, &dev_info);
2086 /* Setup crypto op data structure */
2087 op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2090 "line %u FAILED: %s", __LINE__,
2091 "Failed to allocate asymmetric crypto "
2092 "operation struct\n");
2093 status = TEST_FAILED;
2098 /* Setup asym xform */
2100 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
2101 xform.ec.curve_id = input_params.curve;
2103 ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2106 "line %u FAILED: %s", __LINE__,
2107 "Session creation failed\n");
2108 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2112 /* Attach asymmetric crypto session to crypto operations */
2113 rte_crypto_op_attach_asym_session(op, sess);
2115 /* Populate op with operational details */
2116 op->asym->ecpm.p.x.data = input_params.gen_x.data;
2117 op->asym->ecpm.p.x.length = input_params.gen_x.length;
2118 op->asym->ecpm.p.y.data = input_params.gen_y.data;
2119 op->asym->ecpm.p.y.length = input_params.gen_y.length;
2120 op->asym->ecpm.scalar.data = input_params.privkey.data;
2121 op->asym->ecpm.scalar.length = input_params.privkey.length;
2124 op->asym->ecpm.r.x.data = output_buf_x;
2125 op->asym->ecpm.r.y.data = output_buf_y;
2127 RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2129 /* Process crypto operation */
2130 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2132 "line %u FAILED: %s", __LINE__,
2133 "Error sending packet for operation\n");
2134 status = TEST_FAILED;
2138 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2141 if (result_op == NULL) {
2143 "line %u FAILED: %s", __LINE__,
2144 "Failed to process asym crypto op\n");
2145 status = TEST_FAILED;
2149 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2151 "line %u FAILED: %s", __LINE__,
2152 "Failed to process asym crypto op\n");
2153 status = TEST_FAILED;
2157 asym_op = result_op->asym;
2159 debug_hexdump(stdout, "r x:",
2160 asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
2161 debug_hexdump(stdout, "r y:",
2162 asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
2164 ret = verify_ecpm(input_params.pubkey_x.data,
2165 input_params.pubkey_y.data, result_op);
2167 status = TEST_FAILED;
2169 "line %u FAILED: %s", __LINE__,
2170 "EC Point Multiplication failed.\n");
2176 rte_cryptodev_asym_session_free(dev_id, sess);
2178 rte_crypto_op_free(op);
2183 test_ecpm_all_curve(void)
2185 int status, overall_status = TEST_SUCCESS;
2186 enum curve curve_id;
2190 for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2191 status = test_ecpm(curve_id);
2192 if (status == TEST_SUCCESS) {
2196 overall_status = status;
2198 printf(" %u) TestCase EC Point Mul Curve %s %s\n",
2199 test_index ++, curve[curve_id], msg);
2201 return overall_status;
2204 static struct unit_test_suite cryptodev_openssl_asym_testsuite = {
2205 .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
2206 .setup = testsuite_setup,
2207 .teardown = testsuite_teardown,
2208 .unit_test_cases = {
2209 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2210 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
2211 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2212 test_dh_keygenration),
2213 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
2214 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2215 test_rsa_sign_verify),
2216 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2217 test_rsa_enc_dec_crt),
2218 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2219 test_rsa_sign_verify_crt),
2220 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
2221 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2222 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2223 TEST_CASES_END() /**< NULL terminate unit test array */
2227 static struct unit_test_suite cryptodev_qat_asym_testsuite = {
2228 .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
2229 .setup = testsuite_setup,
2230 .teardown = testsuite_teardown,
2231 .unit_test_cases = {
2232 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_one_by_one),
2233 TEST_CASES_END() /**< NULL terminate unit test array */
2237 static struct unit_test_suite cryptodev_octeontx_asym_testsuite = {
2238 .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
2239 .setup = testsuite_setup,
2240 .teardown = testsuite_teardown,
2241 .unit_test_cases = {
2242 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
2243 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2244 test_rsa_enc_dec_crt),
2245 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2246 test_rsa_sign_verify_crt),
2247 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
2248 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2249 test_ecdsa_sign_verify_all_curve),
2250 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
2251 test_ecpm_all_curve),
2252 TEST_CASES_END() /**< NULL terminate unit test array */
2257 test_cryptodev_openssl_asym(void)
2259 gbl_driver_id = rte_cryptodev_driver_id_get(
2260 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
2262 if (gbl_driver_id == -1) {
2263 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
2267 return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
2271 test_cryptodev_qat_asym(void)
2273 gbl_driver_id = rte_cryptodev_driver_id_get(
2274 RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
2276 if (gbl_driver_id == -1) {
2277 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
2281 return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
2285 test_cryptodev_octeontx_asym(void)
2287 gbl_driver_id = rte_cryptodev_driver_id_get(
2288 RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
2289 if (gbl_driver_id == -1) {
2290 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
2293 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2297 test_cryptodev_cn9k_asym(void)
2299 gbl_driver_id = rte_cryptodev_driver_id_get(
2300 RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
2301 if (gbl_driver_id == -1) {
2302 RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
2306 /* Use test suite registered for crypto_octeontx PMD */
2307 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2311 test_cryptodev_cn10k_asym(void)
2313 gbl_driver_id = rte_cryptodev_driver_id_get(
2314 RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
2315 if (gbl_driver_id == -1) {
2316 RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
2320 /* Use test suite registered for crypto_octeontx PMD */
2321 return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2324 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2325 test_cryptodev_openssl_asym);
2327 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2329 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2330 test_cryptodev_octeontx_asym);
2331 REGISTER_TEST_COMMAND(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
2332 REGISTER_TEST_COMMAND(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);