xref: /dpdk/app/test/test_cryptodev_asym.c (revision 53c65a3ce2c6b56cf3fa71621a74b97c41432fc0)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium Networks
3  * Copyright (c) 2019 Intel Corporation
4  */
5 
6 #include <rte_bus_vdev.h>
7 #include <rte_common.h>
8 #include <rte_hexdump.h>
9 #include <rte_mbuf.h>
10 #include <rte_malloc.h>
11 #include <rte_memcpy.h>
12 #include <rte_pause.h>
13 
14 #include <rte_cryptodev.h>
15 #include <rte_crypto.h>
16 
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_ecdh_test_vectors.h"
21 #include "test_cryptodev_ecdsa_test_vectors.h"
22 #include "test_cryptodev_ecpm_test_vectors.h"
23 #include "test_cryptodev_eddsa_test_vectors.h"
24 #include "test_cryptodev_mod_test_vectors.h"
25 #include "test_cryptodev_rsa_test_vectors.h"
26 #include "test_cryptodev_sm2_test_vectors.h"
27 #include "test_cryptodev_asym_util.h"
28 #include "test.h"
29 
30 #define TEST_NUM_BUFS 10
31 #define TEST_NUM_SESSIONS 4
32 
33 #ifndef TEST_DATA_SIZE
34 	#define TEST_DATA_SIZE 4096
35 #endif
36 #define ASYM_TEST_MSG_LEN 256
37 #define TEST_VECTOR_SIZE 256
38 #define DEQ_TIMEOUT 50
39 
40 static int gbl_driver_id;
41 static struct crypto_testsuite_params_asym {
42 	struct rte_mempool *op_mpool;
43 	struct rte_mempool *session_mpool;
44 	struct rte_cryptodev_config conf;
45 	struct rte_cryptodev_qp_conf qp_conf;
46 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
47 	uint8_t valid_dev_count;
48 } testsuite_params, *params = &testsuite_params;
49 
50 static struct ut_args {
51 	void *sess;
52 	struct rte_crypto_op *op;
53 	struct rte_crypto_op *result_op;
54 } _args, *self = &_args;
55 
56 static int
57 queue_ops_rsa_sign_verify(void *sess)
58 {
59 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
60 	struct rte_mempool *op_mpool = ts_params->op_mpool;
61 	uint8_t dev_id = ts_params->valid_devs[0];
62 	struct rte_crypto_op *op, *result_op;
63 	struct rte_crypto_asym_op *asym_op;
64 	uint8_t output_buf[TEST_DATA_SIZE];
65 	int status = TEST_SUCCESS;
66 
67 	/* Set up crypto op data structure */
68 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
69 	if (!op) {
70 		RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
71 			"operation struct\n");
72 		return TEST_FAILED;
73 	}
74 
75 	asym_op = op->asym;
76 
77 	/* Compute sign on the test vector */
78 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
79 
80 	asym_op->rsa.message.data = rsaplaintext.data;
81 	asym_op->rsa.message.length = rsaplaintext.len;
82 	asym_op->rsa.sign.length = RTE_DIM(rsa_n);
83 	asym_op->rsa.sign.data = output_buf;
84 
85 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
86 		      asym_op->rsa.message.length);
87 
88 	/* Attach asymmetric crypto session to crypto operations */
89 	rte_crypto_op_attach_asym_session(op, sess);
90 
91 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
92 
93 	/* Process crypto operation */
94 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
95 		RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
96 		status = TEST_FAILED;
97 		goto error_exit;
98 	}
99 
100 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
101 		rte_pause();
102 
103 	if (result_op == NULL) {
104 		RTE_LOG(ERR, USER1, "Failed to process sign op\n");
105 		status = TEST_FAILED;
106 		goto error_exit;
107 	}
108 
109 	debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
110 		      asym_op->rsa.sign.length);
111 	asym_op = result_op->asym;
112 
113 	/* Verify sign */
114 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
115 
116 	/* Process crypto operation */
117 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
118 		RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
119 		status = TEST_FAILED;
120 		goto error_exit;
121 	}
122 
123 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
124 		rte_pause();
125 
126 	if (result_op == NULL) {
127 		RTE_LOG(ERR, USER1, "Failed to process verify op\n");
128 		status = TEST_FAILED;
129 		goto error_exit;
130 	}
131 
132 	status = TEST_SUCCESS;
133 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
134 		RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
135 		status = TEST_FAILED;
136 	}
137 
138 error_exit:
139 
140 	rte_crypto_op_free(op);
141 
142 	return status;
143 }
144 
145 static int
146 queue_ops_rsa_enc_dec(void *sess)
147 {
148 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
149 	struct rte_mempool *op_mpool = ts_params->op_mpool;
150 	uint8_t dev_id = ts_params->valid_devs[0];
151 	struct rte_crypto_op *op, *result_op;
152 	struct rte_crypto_asym_op *asym_op;
153 	uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
154 	int ret, status = TEST_SUCCESS;
155 
156 	/* Set up crypto op data structure */
157 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
158 	if (!op) {
159 		RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
160 			"operation struct\n");
161 		return TEST_FAILED;
162 	}
163 
164 	asym_op = op->asym;
165 
166 	/* Compute encryption on the test vector */
167 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
168 
169 	asym_op->rsa.message.data = rsaplaintext.data;
170 	asym_op->rsa.cipher.data = cipher_buf;
171 	asym_op->rsa.cipher.length = RTE_DIM(rsa_n);
172 	asym_op->rsa.message.length = rsaplaintext.len;
173 
174 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
175 		      asym_op->rsa.message.length);
176 
177 	/* Attach asymmetric crypto session to crypto operations */
178 	rte_crypto_op_attach_asym_session(op, sess);
179 
180 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
181 
182 	/* Process crypto operation */
183 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
184 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
185 		status = TEST_FAILED;
186 		goto error_exit;
187 	}
188 
189 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
190 		rte_pause();
191 
192 	if (result_op == NULL) {
193 		RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
194 		status = TEST_FAILED;
195 		goto error_exit;
196 	}
197 	debug_hexdump(stdout, "encrypted message", asym_op->rsa.cipher.data,
198 		      asym_op->rsa.cipher.length);
199 
200 	/* Use the resulted output as decryption Input vector*/
201 	asym_op = result_op->asym;
202 	asym_op->rsa.message.length = RTE_DIM(rsa_n);
203 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
204 
205 	/* Process crypto operation */
206 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
207 		RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
208 		status = TEST_FAILED;
209 		goto error_exit;
210 	}
211 
212 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
213 		rte_pause();
214 
215 	if (result_op == NULL) {
216 		RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
217 		status = TEST_FAILED;
218 		goto error_exit;
219 	}
220 	status = TEST_SUCCESS;
221 	ret = rsa_verify(&rsaplaintext, result_op);
222 	if (ret)
223 		status = TEST_FAILED;
224 
225 error_exit:
226 
227 	rte_crypto_op_free(op);
228 
229 	return status;
230 }
231 
232 static int
233 test_rsa_sign_verify(void)
234 {
235 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
236 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
237 	uint8_t dev_id = ts_params->valid_devs[0];
238 	void *sess = NULL;
239 	struct rte_cryptodev_info dev_info;
240 	int ret, status = TEST_SUCCESS;
241 
242 	/* Test case supports op with exponent key only,
243 	 * Check in PMD feature flag for RSA exponent key type support.
244 	 */
245 	rte_cryptodev_info_get(dev_id, &dev_info);
246 	if (!(dev_info.feature_flags &
247 				RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
248 		RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
249 			"exponent key type. Test Skipped\n");
250 		return TEST_SKIPPED;
251 	}
252 
253 	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
254 
255 	if (ret < 0) {
256 		RTE_LOG(ERR, USER1, "Session creation failed for "
257 			"sign_verify\n");
258 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
259 		goto error_exit;
260 	}
261 
262 	status = queue_ops_rsa_sign_verify(sess);
263 
264 error_exit:
265 	rte_cryptodev_asym_session_free(dev_id, sess);
266 
267 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
268 
269 	return status;
270 }
271 
272 static int
273 test_rsa_enc_dec(void)
274 {
275 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
276 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
277 	uint8_t dev_id = ts_params->valid_devs[0];
278 	void *sess = NULL;
279 	struct rte_cryptodev_info dev_info;
280 	int ret, status = TEST_SUCCESS;
281 
282 	/* Test case supports op with exponent key only,
283 	 * Check in PMD feature flag for RSA exponent key type support.
284 	 */
285 	rte_cryptodev_info_get(dev_id, &dev_info);
286 	if (!(dev_info.feature_flags &
287 				RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
288 		RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
289 			"exponent key type. Test skipped\n");
290 		return TEST_SKIPPED;
291 	}
292 
293 	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
294 
295 	if (ret < 0) {
296 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
297 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
298 		goto error_exit;
299 	}
300 
301 	status = queue_ops_rsa_enc_dec(sess);
302 
303 error_exit:
304 
305 	rte_cryptodev_asym_session_free(dev_id, sess);
306 
307 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
308 
309 	return status;
310 }
311 
312 static int
313 test_rsa_sign_verify_crt(void)
314 {
315 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
316 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
317 	uint8_t dev_id = ts_params->valid_devs[0];
318 	void *sess = NULL;
319 	struct rte_cryptodev_info dev_info;
320 	int ret, status = TEST_SUCCESS;
321 
322 	/* Test case supports op with quintuple format key only,
323 	 * Check im PMD feature flag for RSA quintuple key type support.
324 	 */
325 	rte_cryptodev_info_get(dev_id, &dev_info);
326 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
327 		RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
328 			"quintuple key type. Test skipped\n");
329 		return TEST_SKIPPED;
330 	}
331 
332 	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
333 
334 	if (ret < 0) {
335 		RTE_LOG(ERR, USER1, "Session creation failed for "
336 			"sign_verify_crt\n");
337 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
338 		goto error_exit;
339 	}
340 
341 	status = queue_ops_rsa_sign_verify(sess);
342 
343 error_exit:
344 
345 	rte_cryptodev_asym_session_free(dev_id, sess);
346 
347 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
348 
349 	return status;
350 }
351 
352 static int
353 test_rsa_enc_dec_crt(void)
354 {
355 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
356 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
357 	uint8_t dev_id = ts_params->valid_devs[0];
358 	void *sess = NULL;
359 	struct rte_cryptodev_info dev_info;
360 	int ret, status = TEST_SUCCESS;
361 
362 	/* Test case supports op with quintuple format key only,
363 	 * Check in PMD feature flag for RSA quintuple key type support.
364 	 */
365 	rte_cryptodev_info_get(dev_id, &dev_info);
366 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
367 		RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
368 			"quintuple key type. Test skipped\n");
369 		return TEST_SKIPPED;
370 	}
371 
372 	ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
373 
374 	if (ret < 0) {
375 		RTE_LOG(ERR, USER1, "Session creation failed for "
376 			"enc_dec_crt\n");
377 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
378 		goto error_exit;
379 	}
380 
381 	status = queue_ops_rsa_enc_dec(sess);
382 
383 error_exit:
384 
385 	rte_cryptodev_asym_session_free(dev_id, sess);
386 
387 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
388 
389 	return status;
390 }
391 
392 static int
393 testsuite_setup(void)
394 {
395 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
396 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
397 	struct rte_cryptodev_info info;
398 	int ret, dev_id = -1;
399 	uint32_t i, nb_devs;
400 	uint16_t qp_id;
401 
402 	memset(ts_params, 0, sizeof(*ts_params));
403 
404 	/* Device, op pool and session configuration for asymmetric crypto. 8< */
405 	ts_params->op_mpool = rte_crypto_op_pool_create(
406 			"CRYPTO_ASYM_OP_POOL",
407 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
408 			TEST_NUM_BUFS, 0,
409 			0,
410 			rte_socket_id());
411 	if (ts_params->op_mpool == NULL) {
412 		RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
413 		return TEST_FAILED;
414 	}
415 
416 	/* Create an OPENSSL device if required */
417 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
418 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
419 		nb_devs = rte_cryptodev_device_count_by_driver(
420 				rte_cryptodev_driver_id_get(
421 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
422 		if (nb_devs < 1) {
423 			ret = rte_vdev_init(
424 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
425 				NULL);
426 
427 			TEST_ASSERT(ret == 0, "Failed to create "
428 				"instance of pmd : %s",
429 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
430 		}
431 	}
432 
433 	/* Get list of valid crypto devs */
434 	nb_devs = rte_cryptodev_devices_get(
435 				rte_cryptodev_driver_name_get(gbl_driver_id),
436 				valid_devs, RTE_CRYPTO_MAX_DEVS);
437 	if (nb_devs < 1) {
438 		RTE_LOG(ERR, USER1, "No crypto devices found?\n");
439 		return TEST_SKIPPED;
440 	}
441 
442 	/*
443 	 * Get first valid asymmetric device found in test suite param and
444 	 * break
445 	 */
446 	for (i = 0; i < nb_devs ; i++) {
447 		rte_cryptodev_info_get(valid_devs[i], &info);
448 		if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
449 			dev_id = ts_params->valid_devs[0] = valid_devs[i];
450 			break;
451 		}
452 	}
453 
454 	if (dev_id == -1) {
455 		RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
456 			"Test skipped.\n");
457 		return TEST_FAILED;
458 	}
459 
460 	/* Set valid device count */
461 	ts_params->valid_dev_count = nb_devs;
462 
463 	/* configure device with num qp */
464 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
465 	ts_params->conf.socket_id = SOCKET_ID_ANY;
466 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
467 			RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
468 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
469 			&ts_params->conf),
470 			"Failed to configure cryptodev %u with %u qps",
471 			dev_id, ts_params->conf.nb_queue_pairs);
472 
473 	/* configure qp */
474 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
475 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
476 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
477 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
478 			dev_id, qp_id, &ts_params->qp_conf,
479 			rte_cryptodev_socket_id(dev_id)),
480 			"Failed to setup queue pair %u on cryptodev %u ASYM",
481 			qp_id, dev_id);
482 	}
483 
484 	ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
485 			"test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
486 			SOCKET_ID_ANY);
487 
488 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
489 			"session mempool allocation failed");
490 	/* >8 End of device, op pool and session configuration for asymmetric crypto section. */
491 	return TEST_SUCCESS;
492 }
493 
494 static void
495 testsuite_teardown(void)
496 {
497 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
498 
499 	/* Reset device */
500 	ts_params->qp_conf.mp_session = NULL;
501 	ts_params->conf.ff_disable = 0;
502 	if (rte_cryptodev_configure(ts_params->valid_devs[0], &ts_params->conf))
503 		RTE_LOG(DEBUG, USER1, "Could not reset cryptodev\n");
504 
505 	if (ts_params->op_mpool != NULL) {
506 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
507 		rte_mempool_avail_count(ts_params->op_mpool));
508 	}
509 
510 	/* Free session mempools */
511 	if (ts_params->session_mpool != NULL) {
512 		rte_mempool_free(ts_params->session_mpool);
513 		ts_params->session_mpool = NULL;
514 	}
515 }
516 
517 static int
518 ut_setup_asym(void)
519 {
520 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
521 	uint16_t qp_id;
522 
523 	memset(self, 0, sizeof(*self));
524 	self->op = rte_crypto_op_alloc(params->op_mpool,
525 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
526 	TEST_ASSERT_NOT_NULL(self->op,
527 		"Failed to allocate asymmetric crypto operation struct"
528 	);
529 
530 	/* Reconfigure device to default parameters */
531 	ts_params->conf.socket_id = SOCKET_ID_ANY;
532 
533 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
534 			&ts_params->conf),
535 			"Failed to configure cryptodev %u",
536 			ts_params->valid_devs[0]);
537 
538 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
539 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
540 			ts_params->valid_devs[0], qp_id,
541 			&ts_params->qp_conf,
542 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
543 			"Failed to setup queue pair %u on cryptodev %u",
544 			qp_id, ts_params->valid_devs[0]);
545 	}
546 
547 	/* Start the device */
548 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
549 						"Failed to start cryptodev %u",
550 						ts_params->valid_devs[0]);
551 
552 	return TEST_SUCCESS;
553 }
554 
555 static void
556 ut_teardown_asym(void)
557 {
558 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
559 	uint8_t dev_id = ts_params->valid_devs[0];
560 
561 	if (self->sess != NULL)
562 		rte_cryptodev_asym_session_free(dev_id, self->sess);
563 	rte_crypto_op_free(self->op);
564 	self->sess = NULL;
565 	self->op = NULL;
566 	self->result_op = NULL;
567 
568 	/* Stop the device */
569 	rte_cryptodev_stop(ts_params->valid_devs[0]);
570 }
571 
572 static inline void print_asym_capa(
573 		const struct rte_cryptodev_asymmetric_xform_capability *capa)
574 {
575 	int i = 0;
576 
577 	printf("\nxform type: %s\n===================\n",
578 			rte_cryptodev_asym_get_xform_string(capa->xform_type));
579 	printf("operation supported -");
580 
581 	for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
582 		/* check supported operations */
583 		if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) {
584 			if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH)
585 				printf(" %s", rte_crypto_asym_ke_strings[i]);
586 			else
587 				printf(" %s", rte_crypto_asym_op_strings[i]);
588 		}
589 	}
590 	switch (capa->xform_type) {
591 	case RTE_CRYPTO_ASYM_XFORM_RSA:
592 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
593 	case RTE_CRYPTO_ASYM_XFORM_MODEX:
594 	case RTE_CRYPTO_ASYM_XFORM_DH:
595 	case RTE_CRYPTO_ASYM_XFORM_DSA:
596 		printf(" modlen: min %d max %d increment %d",
597 				capa->modlen.min,
598 				capa->modlen.max,
599 				capa->modlen.increment);
600 	break;
601 	case RTE_CRYPTO_ASYM_XFORM_ECDSA:
602 	case RTE_CRYPTO_ASYM_XFORM_ECPM:
603 	case RTE_CRYPTO_ASYM_XFORM_SM2:
604 	default:
605 		break;
606 	}
607 	printf("\n");
608 }
609 
610 static int
611 test_capability(void)
612 {
613 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
614 	uint8_t dev_id = ts_params->valid_devs[0];
615 	struct rte_cryptodev_info dev_info;
616 	const struct rte_cryptodev_capabilities *dev_capa;
617 	int i = 0;
618 	struct rte_cryptodev_asym_capability_idx idx;
619 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
620 
621 	rte_cryptodev_info_get(dev_id, &dev_info);
622 	if (!(dev_info.feature_flags &
623 				RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
624 		RTE_LOG(INFO, USER1,
625 				"Device doesn't support asymmetric. Test Skipped\n");
626 		return TEST_SKIPPED;
627 	}
628 
629 	/* print xform capability */
630 	for (i = 0;
631 		dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
632 		i++) {
633 		dev_capa = &(dev_info.capabilities[i]);
634 		if (dev_info.capabilities[i].op ==
635 				RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
636 			idx.type = dev_capa->asym.xform_capa.xform_type;
637 
638 			capa = rte_cryptodev_asym_capability_get(dev_id,
639 				(const struct
640 				rte_cryptodev_asym_capability_idx *) &idx);
641 			TEST_ASSERT_NOT_NULL(capa, "Failed to get asymmetric capability");
642 			print_asym_capa(capa);
643 			}
644 	}
645 	return TEST_SUCCESS;
646 }
647 
648 static int
649 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
650 {
651 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
652 	struct rte_mempool *op_mpool = ts_params->op_mpool;
653 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
654 	uint8_t dev_id = ts_params->valid_devs[0];
655 	struct rte_crypto_asym_op *asym_op = NULL;
656 	struct rte_crypto_op *op = NULL, *result_op = NULL;
657 	void *sess = NULL;
658 	int ret, status = TEST_SUCCESS;
659 	uint8_t output[TEST_DH_MOD_LEN];
660 	struct rte_crypto_asym_xform xform = *xfrm;
661 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
662 
663 	/* set up crypto op data structure */
664 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
665 	if (!op) {
666 		RTE_LOG(ERR, USER1,
667 			"line %u FAILED: %s",
668 			__LINE__, "Failed to allocate asymmetric crypto "
669 			"operation struct");
670 		status = TEST_FAILED;
671 		goto error_exit;
672 	}
673 	asym_op = op->asym;
674 
675 	/* Setup a xform and op to generate private key only */
676 	xform.next = NULL;
677 	asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
678 	asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
679 	asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
680 	asym_op->dh.pub_key.data = (uint8_t *)peer;
681 	asym_op->dh.pub_key.length = sizeof(peer);
682 	asym_op->dh.shared_secret.data = output;
683 	asym_op->dh.shared_secret.length = sizeof(output);
684 
685 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
686 	if (ret < 0) {
687 		RTE_LOG(ERR, USER1,
688 				"line %u FAILED: %s", __LINE__,
689 				"Session creation failed");
690 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
691 		goto error_exit;
692 	}
693 
694 	/* attach asymmetric crypto session to crypto operations */
695 	rte_crypto_op_attach_asym_session(op, sess);
696 
697 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
698 
699 	/* Process crypto operation */
700 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
701 		RTE_LOG(ERR, USER1,
702 			"line %u FAILED: %s",
703 			__LINE__, "Error sending packet for operation");
704 		status = TEST_FAILED;
705 		goto error_exit;
706 	}
707 
708 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
709 		rte_pause();
710 
711 	if (result_op == NULL) {
712 		RTE_LOG(ERR, USER1,
713 			"line %u FAILED: %s",
714 			__LINE__, "Failed to process asym crypto op");
715 		status = TEST_FAILED;
716 		goto error_exit;
717 	}
718 
719 	debug_hexdump(stdout, "shared secret:",
720 			asym_op->dh.shared_secret.data,
721 			asym_op->dh.shared_secret.length);
722 
723 error_exit:
724 	if (sess != NULL)
725 		rte_cryptodev_asym_session_free(dev_id, sess);
726 	rte_crypto_op_free(op);
727 	return status;
728 }
729 
730 static int
731 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
732 {
733 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
734 	struct rte_mempool *op_mpool = ts_params->op_mpool;
735 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
736 	uint8_t dev_id = ts_params->valid_devs[0];
737 	struct rte_crypto_asym_op *asym_op = NULL;
738 	struct rte_crypto_op *op = NULL, *result_op = NULL;
739 	void *sess = NULL;
740 	int ret, status = TEST_SUCCESS;
741 	uint8_t output[TEST_DH_MOD_LEN];
742 	struct rte_crypto_asym_xform xform = *xfrm;
743 
744 	/* set up crypto op data structure */
745 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
746 	if (!op) {
747 		RTE_LOG(ERR, USER1,
748 			"line %u FAILED: %s",
749 			__LINE__, "Failed to allocate asymmetric crypto "
750 			"operation struct");
751 		status = TEST_FAILED;
752 		goto error_exit;
753 	}
754 	asym_op = op->asym;
755 
756 	/* Setup a xform and op to generate private key only */
757 	xform.next = NULL;
758 	asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
759 	asym_op->dh.priv_key.data = output;
760 	asym_op->dh.priv_key.length = sizeof(output);
761 
762 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
763 	if (ret < 0) {
764 		RTE_LOG(ERR, USER1,
765 				"line %u FAILED: %s", __LINE__,
766 				"Session creation failed");
767 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
768 		goto error_exit;
769 	}
770 
771 	/* attach asymmetric crypto session to crypto operations */
772 	rte_crypto_op_attach_asym_session(op, sess);
773 
774 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
775 
776 	/* Process crypto operation */
777 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
778 		RTE_LOG(ERR, USER1,
779 			"line %u FAILED: %s",
780 			__LINE__, "Error sending packet for operation");
781 		status = TEST_FAILED;
782 		goto error_exit;
783 	}
784 
785 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
786 		rte_pause();
787 
788 	if (result_op == NULL) {
789 		RTE_LOG(ERR, USER1,
790 			"line %u FAILED: %s",
791 			__LINE__, "Failed to process asym crypto op");
792 		status = TEST_FAILED;
793 		goto error_exit;
794 	}
795 
796 	debug_hexdump(stdout, "private key:",
797 			asym_op->dh.priv_key.data,
798 			asym_op->dh.priv_key.length);
799 
800 
801 error_exit:
802 	if (sess != NULL)
803 		rte_cryptodev_asym_session_free(dev_id, sess);
804 	rte_crypto_op_free(op);
805 
806 	return status;
807 }
808 
809 
810 static int
811 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
812 {
813 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
814 	struct rte_mempool *op_mpool = ts_params->op_mpool;
815 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
816 	uint8_t dev_id = ts_params->valid_devs[0];
817 	struct rte_crypto_asym_op *asym_op = NULL;
818 	struct rte_crypto_op *op = NULL, *result_op = NULL;
819 	void *sess = NULL;
820 	int ret, status = TEST_SUCCESS;
821 	uint8_t output[TEST_DH_MOD_LEN];
822 	struct rte_crypto_asym_xform xform = *xfrm;
823 
824 	/* set up crypto op data structure */
825 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
826 	if (!op) {
827 		RTE_LOG(ERR, USER1,
828 			"line %u FAILED: %s",
829 			__LINE__, "Failed to allocate asymmetric crypto "
830 			"operation struct");
831 		status = TEST_FAILED;
832 		goto error_exit;
833 	}
834 	asym_op = op->asym;
835 	/* Setup a xform chain to generate public key
836 	 * using test private key
837 	 *
838 	 */
839 	xform.next = NULL;
840 
841 	asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
842 	asym_op->dh.pub_key.data = output;
843 	asym_op->dh.pub_key.length = sizeof(output);
844 	/* load pre-defined private key */
845 	asym_op->dh.priv_key.data = rte_malloc(NULL,
846 					dh_test_params.priv_key.length,
847 					0);
848 	asym_op->dh.priv_key = dh_test_params.priv_key;
849 
850 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
851 	if (ret < 0) {
852 		RTE_LOG(ERR, USER1,
853 				"line %u FAILED: %s", __LINE__,
854 				"Session creation failed");
855 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
856 		goto error_exit;
857 	}
858 
859 	/* attach asymmetric crypto session to crypto operations */
860 	rte_crypto_op_attach_asym_session(op, sess);
861 
862 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
863 
864 	/* Process crypto operation */
865 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
866 		RTE_LOG(ERR, USER1,
867 			"line %u FAILED: %s",
868 			__LINE__, "Error sending packet for operation");
869 		status = TEST_FAILED;
870 		goto error_exit;
871 	}
872 
873 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
874 		rte_pause();
875 
876 	if (result_op == NULL) {
877 		RTE_LOG(ERR, USER1,
878 			"line %u FAILED: %s",
879 			__LINE__, "Failed to process asym crypto op");
880 		status = TEST_FAILED;
881 		goto error_exit;
882 	}
883 
884 	debug_hexdump(stdout, "pub key:",
885 			asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
886 
887 	debug_hexdump(stdout, "priv key:",
888 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
889 
890 error_exit:
891 	if (sess != NULL)
892 		rte_cryptodev_asym_session_free(dev_id, sess);
893 	rte_crypto_op_free(op);
894 
895 	return status;
896 }
897 
898 static int
899 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
900 {
901 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
902 	struct rte_mempool *op_mpool = ts_params->op_mpool;
903 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
904 	uint8_t dev_id = ts_params->valid_devs[0];
905 	struct rte_crypto_asym_op *asym_op = NULL;
906 	struct rte_crypto_op *op = NULL, *result_op = NULL;
907 	void *sess = NULL;
908 	int ret, status = TEST_SUCCESS;
909 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
910 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
911 	struct rte_crypto_asym_xform pub_key_xform;
912 	struct rte_crypto_asym_xform xform = *xfrm;
913 
914 	/* set up crypto op data structure */
915 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
916 	if (!op) {
917 		RTE_LOG(ERR, USER1,
918 			"line %u FAILED: %s",
919 			__LINE__, "Failed to allocate asymmetric crypto "
920 			"operation struct");
921 		status = TEST_FAILED;
922 		goto error_exit;
923 	}
924 	asym_op = op->asym;
925 	/* Setup a xform chain to generate
926 	 * private key first followed by
927 	 * public key
928 	 */
929 	pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
930 	xform.next = &pub_key_xform;
931 
932 	asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
933 	asym_op->dh.pub_key.data = out_pub_key;
934 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
935 	asym_op->dh.priv_key.data = out_prv_key;
936 	asym_op->dh.priv_key.length = 0;
937 
938 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
939 	if (ret < 0) {
940 		RTE_LOG(ERR, USER1,
941 				"line %u FAILED: %s", __LINE__,
942 				"Session creation failed");
943 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
944 		goto error_exit;
945 	}
946 
947 	/* attach asymmetric crypto session to crypto operations */
948 	rte_crypto_op_attach_asym_session(op, sess);
949 
950 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
951 
952 	/* Process crypto operation */
953 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
954 		RTE_LOG(ERR, USER1,
955 			"line %u FAILED: %s",
956 			__LINE__, "Error sending packet for operation");
957 		status = TEST_FAILED;
958 		goto error_exit;
959 	}
960 
961 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
962 		rte_pause();
963 
964 	if (result_op == NULL) {
965 		RTE_LOG(ERR, USER1,
966 			"line %u FAILED: %s",
967 			__LINE__, "Failed to process asym crypto op");
968 		status = TEST_FAILED;
969 		goto error_exit;
970 	}
971 	debug_hexdump(stdout, "priv key:",
972 			out_prv_key, asym_op->dh.priv_key.length);
973 	debug_hexdump(stdout, "pub key:",
974 			out_pub_key, asym_op->dh.pub_key.length);
975 
976 error_exit:
977 	if (sess != NULL)
978 		rte_cryptodev_asym_session_free(dev_id, sess);
979 	rte_crypto_op_free(op);
980 
981 	return status;
982 }
983 
984 static int
985 test_mod_inv(void)
986 {
987 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
988 	struct rte_mempool *op_mpool = ts_params->op_mpool;
989 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
990 	uint8_t dev_id = ts_params->valid_devs[0];
991 	struct rte_crypto_asym_op *asym_op = NULL;
992 	struct rte_crypto_op *op = NULL, *result_op = NULL;
993 	void *sess = NULL;
994 	int status = TEST_SUCCESS;
995 	struct rte_cryptodev_asym_capability_idx cap_idx;
996 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
997 	uint8_t input[TEST_DATA_SIZE] = {0};
998 	int ret = 0;
999 	uint8_t result[sizeof(mod_p)] = { 0 };
1000 
1001 	if (rte_cryptodev_asym_get_xform_enum(
1002 		&modinv_xform.xform_type, "modinv") < 0) {
1003 		RTE_LOG(ERR, USER1,
1004 				 "Invalid ASYM algorithm specified\n");
1005 		return -1;
1006 	}
1007 
1008 	cap_idx.type = modinv_xform.xform_type;
1009 	capability = rte_cryptodev_asym_capability_get(dev_id,
1010 					&cap_idx);
1011 
1012 	if (capability == NULL) {
1013 		RTE_LOG(INFO, USER1,
1014 			"Device doesn't support MOD INV. Test Skipped\n");
1015 		return TEST_SKIPPED;
1016 	}
1017 
1018 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1019 		capability,
1020 		modinv_xform.modinv.modulus.length)) {
1021 		RTE_LOG(ERR, USER1,
1022 				 "Invalid MODULUS length specified\n");
1023 				return TEST_SKIPPED;
1024 		}
1025 
1026 	ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
1027 	if (ret < 0) {
1028 		RTE_LOG(ERR, USER1, "line %u "
1029 				"FAILED: %s", __LINE__,
1030 				"Session creation failed");
1031 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1032 		goto error_exit;
1033 	}
1034 
1035 	/* generate crypto op data structure */
1036 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1037 	if (!op) {
1038 		RTE_LOG(ERR, USER1,
1039 			"line %u FAILED: %s",
1040 			__LINE__, "Failed to allocate asymmetric crypto "
1041 			"operation struct");
1042 		status = TEST_FAILED;
1043 		goto error_exit;
1044 	}
1045 
1046 	asym_op = op->asym;
1047 	memcpy(input, base, sizeof(base));
1048 	asym_op->modinv.base.data = input;
1049 	asym_op->modinv.base.length = sizeof(base);
1050 	asym_op->modinv.result.data = result;
1051 	asym_op->modinv.result.length = sizeof(result);
1052 
1053 	/* attach asymmetric crypto session to crypto operations */
1054 	rte_crypto_op_attach_asym_session(op, sess);
1055 
1056 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1057 
1058 	/* Process crypto operation */
1059 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1060 		RTE_LOG(ERR, USER1,
1061 			"line %u FAILED: %s",
1062 			__LINE__, "Error sending packet for operation");
1063 		status = TEST_FAILED;
1064 		goto error_exit;
1065 	}
1066 
1067 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1068 		rte_pause();
1069 
1070 	if (result_op == NULL) {
1071 		RTE_LOG(ERR, USER1,
1072 				"line %u FAILED: %s",
1073 				__LINE__, "Failed to process asym crypto op");
1074 		status = TEST_FAILED;
1075 		goto error_exit;
1076 	}
1077 
1078 	ret = verify_modinv(mod_inv, result_op);
1079 	if (ret) {
1080 		RTE_LOG(ERR, USER1,
1081 			 "operation verification failed\n");
1082 		status = TEST_FAILED;
1083 	}
1084 
1085 error_exit:
1086 	if (sess)
1087 		rte_cryptodev_asym_session_free(dev_id, sess);
1088 
1089 	rte_crypto_op_free(op);
1090 
1091 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1092 
1093 	return status;
1094 }
1095 
1096 static int
1097 test_mod_exp(void)
1098 {
1099 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1100 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1101 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1102 	uint8_t dev_id = ts_params->valid_devs[0];
1103 	struct rte_crypto_asym_op *asym_op = NULL;
1104 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1105 	void *sess = NULL;
1106 	int status = TEST_SUCCESS;
1107 	struct rte_cryptodev_asym_capability_idx cap_idx;
1108 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
1109 	uint8_t input[TEST_DATA_SIZE] = {0};
1110 	int ret = 0;
1111 	uint8_t result[sizeof(mod_p)] = { 0 };
1112 
1113 	if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1114 		"modexp")
1115 		< 0) {
1116 		RTE_LOG(ERR, USER1,
1117 				"Invalid ASYM algorithm specified\n");
1118 		return -1;
1119 	}
1120 
1121 	/* check for modlen capability */
1122 	cap_idx.type = modex_xform.xform_type;
1123 	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1124 
1125 	if (capability == NULL) {
1126 		RTE_LOG(INFO, USER1,
1127 			"Device doesn't support MOD EXP. Test Skipped\n");
1128 		return TEST_SKIPPED;
1129 	}
1130 
1131 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1132 			capability, modex_xform.modex.modulus.length)) {
1133 		RTE_LOG(ERR, USER1,
1134 				"Invalid MODULUS length specified\n");
1135 				return TEST_SKIPPED;
1136 		}
1137 
1138 	/* Create op, create session, and process packets. 8< */
1139 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1140 	if (!op) {
1141 		RTE_LOG(ERR, USER1,
1142 			"line %u FAILED: %s",
1143 			__LINE__, "Failed to allocate asymmetric crypto "
1144 			"operation struct");
1145 		status = TEST_FAILED;
1146 		goto error_exit;
1147 	}
1148 
1149 	ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
1150 	if (ret < 0) {
1151 		RTE_LOG(ERR, USER1,
1152 				 "line %u "
1153 				"FAILED: %s", __LINE__,
1154 				"Session creation failed");
1155 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1156 		goto error_exit;
1157 	}
1158 
1159 	asym_op = op->asym;
1160 	memcpy(input, base, sizeof(base));
1161 	asym_op->modex.base.data = input;
1162 	asym_op->modex.base.length = sizeof(base);
1163 	asym_op->modex.result.data = result;
1164 	asym_op->modex.result.length = sizeof(result);
1165 	/* attach asymmetric crypto session to crypto operations */
1166 	rte_crypto_op_attach_asym_session(op, sess);
1167 
1168 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1169 	/* Process crypto operation */
1170 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1171 		RTE_LOG(ERR, USER1,
1172 				"line %u FAILED: %s",
1173 				__LINE__, "Error sending packet for operation");
1174 		status = TEST_FAILED;
1175 		goto error_exit;
1176 	}
1177 
1178 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1179 		rte_pause();
1180 
1181 	if (result_op == NULL) {
1182 		RTE_LOG(ERR, USER1,
1183 				"line %u FAILED: %s",
1184 				__LINE__, "Failed to process asym crypto op");
1185 		status = TEST_FAILED;
1186 		goto error_exit;
1187 	}
1188 	/* >8 End of create op, create session, and process packets section. */
1189 	ret = verify_modexp(mod_exp, result_op);
1190 	if (ret) {
1191 		RTE_LOG(ERR, USER1,
1192 			 "operation verification failed\n");
1193 		status = TEST_FAILED;
1194 	}
1195 
1196 error_exit:
1197 	if (sess != NULL)
1198 		rte_cryptodev_asym_session_free(dev_id, sess);
1199 
1200 	rte_crypto_op_free(op);
1201 
1202 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1203 
1204 	return status;
1205 }
1206 
1207 static int
1208 test_dh_key_generation(void)
1209 {
1210 	int status;
1211 
1212 	debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1213 	debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1214 	debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1215 			dh_test_params.priv_key.length);
1216 
1217 	RTE_LOG(INFO, USER1,
1218 		"Test Public and Private key pair generation\n");
1219 
1220 	status = test_dh_gen_kp(&dh_xform);
1221 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1222 
1223 	RTE_LOG(INFO, USER1,
1224 		"Test Public Key Generation using pre-defined priv key\n");
1225 
1226 	status = test_dh_gen_pub_key(&dh_xform);
1227 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1228 
1229 	RTE_LOG(INFO, USER1,
1230 		"Test Private Key Generation only\n");
1231 
1232 	status = test_dh_gen_priv_key(&dh_xform);
1233 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1234 
1235 	RTE_LOG(INFO, USER1,
1236 		"Test shared secret compute\n");
1237 
1238 	status = test_dh_gen_shared_sec(&dh_xform);
1239 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1240 
1241 	return status;
1242 }
1243 
1244 static int
1245 test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op)
1246 {
1247 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1248 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1249 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1250 	uint8_t dev_id = ts_params->valid_devs[0];
1251 	struct rte_crypto_asym_op *asym_op = NULL;
1252 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1253 	void *sess = NULL;
1254 	int status = TEST_SUCCESS;
1255 	int ret;
1256 
1257 	ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1258 	if (ret < 0) {
1259 		RTE_LOG(ERR, USER1,
1260 				 "line %u FAILED: %s", __LINE__,
1261 				"Session creation failed");
1262 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1263 		goto error_exit;
1264 	}
1265 	/* set up crypto op data structure */
1266 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1267 	if (!op) {
1268 		RTE_LOG(ERR, USER1,
1269 			"line %u FAILED: %s",
1270 			__LINE__, "Failed to allocate asymmetric crypto "
1271 			"operation struct");
1272 		status = TEST_FAILED;
1273 		goto error_exit;
1274 	}
1275 	asym_op = op->asym;
1276 	asym_op->dsa = *dsa_op;
1277 
1278 	debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1279 			dsa_xform.dsa.p.length);
1280 	debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1281 			dsa_xform.dsa.q.length);
1282 	debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1283 			dsa_xform.dsa.g.length);
1284 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1285 			dsa_xform.dsa.x.length);
1286 
1287 	/* attach asymmetric crypto session to crypto operations */
1288 	rte_crypto_op_attach_asym_session(op, sess);
1289 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1290 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1291 
1292 	/* Process crypto operation */
1293 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1294 		RTE_LOG(ERR, USER1,
1295 			"line %u FAILED: %s",
1296 			__LINE__, "Error sending packet for operation");
1297 		status = TEST_FAILED;
1298 		goto error_exit;
1299 	}
1300 
1301 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1302 		rte_pause();
1303 
1304 	if (result_op == NULL) {
1305 		RTE_LOG(ERR, USER1,
1306 			"line %u FAILED: %s",
1307 			__LINE__, "Failed to process asym crypto op");
1308 		status = TEST_FAILED;
1309 		goto error_exit;
1310 	}
1311 
1312 	asym_op = result_op->asym;
1313 	dsa_op->r.length = asym_op->dsa.r.length;
1314 	dsa_op->s.length = asym_op->dsa.s.length;
1315 
1316 	debug_hexdump(stdout, "r:",
1317 			asym_op->dsa.r.data, asym_op->dsa.r.length);
1318 	debug_hexdump(stdout, "s:",
1319 			asym_op->dsa.s.data, asym_op->dsa.s.length);
1320 error_exit:
1321 	if (sess != NULL)
1322 		rte_cryptodev_asym_session_free(dev_id, sess);
1323 	rte_crypto_op_free(op);
1324 	return status;
1325 }
1326 
1327 static int
1328 test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op)
1329 {
1330 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1331 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1332 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1333 	uint8_t dev_id = ts_params->valid_devs[0];
1334 	struct rte_crypto_asym_op *asym_op = NULL;
1335 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1336 	void *sess = NULL;
1337 	int status = TEST_SUCCESS;
1338 	int ret;
1339 
1340 	ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
1341 	if (ret < 0) {
1342 		RTE_LOG(ERR, USER1,
1343 				 "line %u FAILED: %s", __LINE__,
1344 				"Session creation failed");
1345 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1346 		goto error_exit;
1347 	}
1348 	/* set up crypto op data structure */
1349 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1350 	if (!op) {
1351 		RTE_LOG(ERR, USER1,
1352 			"line %u FAILED: %s",
1353 			__LINE__, "Failed to allocate asymmetric crypto "
1354 			"operation struct");
1355 		status = TEST_FAILED;
1356 		goto error_exit;
1357 	}
1358 	asym_op = op->asym;
1359 	asym_op->dsa = *dsa_op;
1360 
1361 	debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1362 			dsa_xform.dsa.p.length);
1363 	debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1364 			dsa_xform.dsa.q.length);
1365 	debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1366 			dsa_xform.dsa.g.length);
1367 
1368 	/* attach asymmetric crypto session to crypto operations */
1369 	rte_crypto_op_attach_asym_session(op, sess);
1370 
1371 	debug_hexdump(stdout, "r:",
1372 			asym_op->dsa.r.data, asym_op->dsa.r.length);
1373 	debug_hexdump(stdout, "s:",
1374 			asym_op->dsa.s.data, asym_op->dsa.s.length);
1375 
1376 	RTE_LOG(DEBUG, USER1, "Process ASYM verify operation");
1377 	/* Test PMD DSA sign verification using signer public key */
1378 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1379 
1380 	/* copy signer public key */
1381 	asym_op->dsa.y.data = dsa_test_params.y.data;
1382 	asym_op->dsa.y.length = dsa_test_params.y.length;
1383 
1384 	/* Process crypto operation */
1385 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1386 		RTE_LOG(ERR, USER1,
1387 			"line %u FAILED: %s",
1388 			__LINE__, "Error sending packet for operation");
1389 		status = TEST_FAILED;
1390 		goto error_exit;
1391 	}
1392 
1393 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1394 		rte_pause();
1395 
1396 	if (result_op == NULL) {
1397 		RTE_LOG(ERR, USER1,
1398 			"line %u FAILED: %s",
1399 			__LINE__, "Failed to process asym crypto op");
1400 		status = TEST_FAILED;
1401 		goto error_exit;
1402 	}
1403 
1404 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1405 		RTE_LOG(ERR, USER1,
1406 				"line %u FAILED: %s",
1407 				__LINE__, "Failed to process asym crypto op");
1408 		status = TEST_FAILED;
1409 	}
1410 error_exit:
1411 	if (sess != NULL)
1412 		rte_cryptodev_asym_session_free(dev_id, sess);
1413 	rte_crypto_op_free(op);
1414 	return status;
1415 }
1416 
1417 static int
1418 test_dsa(void)
1419 {
1420 	int status;
1421 	uint8_t r[TEST_DH_MOD_LEN];
1422 	uint8_t s[TEST_DH_MOD_LEN];
1423 	struct rte_crypto_dsa_op_param dsa_op;
1424 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1425 
1426 	dsa_op.message.data = dgst;
1427 	dsa_op.message.length = sizeof(dgst);
1428 	dsa_op.r.data = r;
1429 	dsa_op.s.data = s;
1430 	dsa_op.r.length = sizeof(r);
1431 	dsa_op.s.length = sizeof(s);
1432 
1433 	status = test_dsa_sign(&dsa_op);
1434 	TEST_ASSERT_EQUAL(status, 0, "DSA sign test failed");
1435 	status = test_dsa_verify(&dsa_op);
1436 	TEST_ASSERT_EQUAL(status, 0, "DSA verify test failed");
1437 	return status;
1438 }
1439 
1440 static int
1441 test_ecdsa_sign_verify(enum curve curve_id)
1442 {
1443 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1444 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1445 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1446 	struct crypto_testsuite_ecdsa_params input_params;
1447 	void *sess = NULL;
1448 	uint8_t dev_id = ts_params->valid_devs[0];
1449 	struct rte_crypto_op *result_op = NULL;
1450 	uint8_t output_buf_r[TEST_DATA_SIZE];
1451 	uint8_t output_buf_s[TEST_DATA_SIZE];
1452 	struct rte_crypto_asym_xform xform;
1453 	struct rte_crypto_asym_op *asym_op;
1454 	struct rte_cryptodev_info dev_info;
1455 	struct rte_crypto_op *op = NULL;
1456 	int ret, status = TEST_SUCCESS;
1457 
1458 	switch (curve_id) {
1459 	case SECP192R1:
1460 		input_params = ecdsa_param_secp192r1;
1461 		break;
1462 	case SECP224R1:
1463 		input_params = ecdsa_param_secp224r1;
1464 		break;
1465 	case SECP256R1:
1466 		input_params = ecdsa_param_secp256r1;
1467 		break;
1468 	case SECP384R1:
1469 		input_params = ecdsa_param_secp384r1;
1470 		break;
1471 	case SECP521R1:
1472 		input_params = ecdsa_param_secp521r1;
1473 		break;
1474 	case SECP521R1_UA:
1475 		input_params = ecdsa_param_secp521r1_ua;
1476 		break;
1477 	default:
1478 		RTE_LOG(ERR, USER1,
1479 				"line %u FAILED: %s", __LINE__,
1480 				"Unsupported curve id\n");
1481 		status = TEST_FAILED;
1482 		goto exit;
1483 	}
1484 
1485 	rte_cryptodev_info_get(dev_id, &dev_info);
1486 
1487 	/* Setup crypto op data structure */
1488 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1489 	if (op == NULL) {
1490 		RTE_LOG(ERR, USER1,
1491 				"line %u FAILED: %s", __LINE__,
1492 				"Failed to allocate asymmetric crypto "
1493 				"operation struct\n");
1494 		status = TEST_FAILED;
1495 		goto exit;
1496 	}
1497 	asym_op = op->asym;
1498 
1499 	/* Setup asym xform */
1500 	xform.next = NULL;
1501 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1502 	xform.ec.curve_id = input_params.curve;
1503 	xform.ec.pkey.data = input_params.pkey.data;
1504 	xform.ec.pkey.length = input_params.pkey.length;
1505 	xform.ec.q.x.data = input_params.pubkey_qx.data;
1506 	xform.ec.q.x.length = input_params.pubkey_qx.length;
1507 	xform.ec.q.y.data = input_params.pubkey_qy.data;
1508 	xform.ec.q.y.length = input_params.pubkey_qy.length;
1509 
1510 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1511 	if (ret < 0) {
1512 		RTE_LOG(ERR, USER1,
1513 				"line %u FAILED: %s", __LINE__,
1514 				"Session creation failed\n");
1515 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1516 		goto exit;
1517 	}
1518 
1519 	/* Attach asymmetric crypto session to crypto operations */
1520 	rte_crypto_op_attach_asym_session(op, sess);
1521 
1522 	/* Compute sign */
1523 
1524 	/* Populate op with operational details */
1525 	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1526 	op->asym->ecdsa.message.data = input_params.digest.data;
1527 	op->asym->ecdsa.message.length = input_params.digest.length;
1528 	op->asym->ecdsa.k.data = input_params.scalar.data;
1529 	op->asym->ecdsa.k.length = input_params.scalar.length;
1530 
1531 	/* Init out buf */
1532 	op->asym->ecdsa.r.data = output_buf_r;
1533 	op->asym->ecdsa.s.data = output_buf_s;
1534 
1535 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1536 
1537 	/* Process crypto operation */
1538 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1539 		RTE_LOG(ERR, USER1,
1540 				"line %u FAILED: %s", __LINE__,
1541 				"Error sending packet for operation\n");
1542 		status = TEST_FAILED;
1543 		goto exit;
1544 	}
1545 
1546 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1547 		rte_pause();
1548 
1549 	if (result_op == NULL) {
1550 		RTE_LOG(ERR, USER1,
1551 				"line %u FAILED: %s", __LINE__,
1552 				"Failed to process asym crypto op\n");
1553 		status = TEST_FAILED;
1554 		goto exit;
1555 	}
1556 
1557 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1558 		RTE_LOG(ERR, USER1,
1559 				"line %u FAILED: %s", __LINE__,
1560 				"Failed to process asym crypto op\n");
1561 		status = TEST_FAILED;
1562 		goto exit;
1563 	}
1564 
1565 	asym_op = result_op->asym;
1566 
1567 	debug_hexdump(stdout, "r:",
1568 			asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
1569 	debug_hexdump(stdout, "s:",
1570 			asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
1571 
1572 	ret = verify_ecdsa_sign(input_params.sign_r.data,
1573 				input_params.sign_s.data, result_op);
1574 	if (ret) {
1575 		status = TEST_FAILED;
1576 		RTE_LOG(ERR, USER1,
1577 				"line %u FAILED: %s", __LINE__,
1578 				"ECDSA sign failed.\n");
1579 		goto exit;
1580 	}
1581 
1582 	/* Verify sign */
1583 
1584 	/* Populate op with operational details */
1585 	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1586 	op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
1587 	op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
1588 	op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
1589 	op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
1590 
1591 	/* Enqueue sign result for verify */
1592 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1593 		status = TEST_FAILED;
1594 		RTE_LOG(ERR, USER1,
1595 				"line %u FAILED: %s", __LINE__,
1596 				"Error sending packet for operation\n");
1597 		goto exit;
1598 	}
1599 
1600 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1601 		rte_pause();
1602 
1603 	if (result_op == NULL) {
1604 		status = TEST_FAILED;
1605 		goto exit;
1606 	}
1607 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1608 		status = TEST_FAILED;
1609 		RTE_LOG(ERR, USER1,
1610 				"line %u FAILED: %s", __LINE__,
1611 				"ECDSA verify failed.\n");
1612 		goto exit;
1613 	}
1614 
1615 exit:
1616 	if (sess != NULL)
1617 		rte_cryptodev_asym_session_free(dev_id, sess);
1618 	rte_crypto_op_free(op);
1619 	return status;
1620 };
1621 
1622 static int
1623 test_ecdsa_sign_verify_all_curve(void)
1624 {
1625 	int status, overall_status = TEST_SUCCESS;
1626 	enum curve curve_id;
1627 	int test_index = 0;
1628 	const char *msg;
1629 
1630 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1631 		if (curve_id == ED25519 || curve_id == ED448)
1632 			continue;
1633 
1634 		status = test_ecdsa_sign_verify(curve_id);
1635 		if (status == TEST_SUCCESS) {
1636 			msg = "succeeded";
1637 		} else {
1638 			msg = "failed";
1639 			overall_status = status;
1640 		}
1641 		printf("  %u) TestCase Sign/Veriy Curve %s  %s\n",
1642 		       test_index ++, curve[curve_id], msg);
1643 	}
1644 	return overall_status;
1645 }
1646 
1647 static int
1648 test_ecpm(enum curve curve_id)
1649 {
1650 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1651 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1652 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1653 	struct crypto_testsuite_ecpm_params input_params;
1654 	void *sess = NULL;
1655 	uint8_t dev_id = ts_params->valid_devs[0];
1656 	struct rte_crypto_op *result_op = NULL;
1657 	uint8_t output_buf_x[TEST_DATA_SIZE];
1658 	uint8_t output_buf_y[TEST_DATA_SIZE];
1659 	struct rte_crypto_asym_xform xform;
1660 	struct rte_crypto_asym_op *asym_op;
1661 	struct rte_cryptodev_info dev_info;
1662 	struct rte_crypto_op *op = NULL;
1663 	int ret, status = TEST_SUCCESS;
1664 
1665 	switch (curve_id) {
1666 	case SECP192R1:
1667 		input_params = ecpm_param_secp192r1;
1668 		break;
1669 	case SECP224R1:
1670 		input_params = ecpm_param_secp224r1;
1671 		break;
1672 	case SECP256R1:
1673 		input_params = ecpm_param_secp256r1;
1674 		break;
1675 	case SECP384R1:
1676 		input_params = ecpm_param_secp384r1;
1677 		break;
1678 	case SECP521R1:
1679 		input_params = ecpm_param_secp521r1;
1680 		break;
1681 	default:
1682 		RTE_LOG(ERR, USER1,
1683 				"line %u FAILED: %s", __LINE__,
1684 				"Unsupported curve id\n");
1685 		status = TEST_FAILED;
1686 		goto exit;
1687 	}
1688 
1689 	rte_cryptodev_info_get(dev_id, &dev_info);
1690 
1691 	/* Setup crypto op data structure */
1692 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1693 	if (op == NULL) {
1694 		RTE_LOG(ERR, USER1,
1695 				"line %u FAILED: %s", __LINE__,
1696 				"Failed to allocate asymmetric crypto "
1697 				"operation struct\n");
1698 		status = TEST_FAILED;
1699 		goto exit;
1700 	}
1701 	asym_op = op->asym;
1702 
1703 	/* Setup asym xform */
1704 	xform.next = NULL;
1705 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
1706 	xform.ec.curve_id = input_params.curve;
1707 
1708 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1709 	if (ret < 0) {
1710 		RTE_LOG(ERR, USER1,
1711 				"line %u FAILED: %s", __LINE__,
1712 				"Session creation failed\n");
1713 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1714 		goto exit;
1715 	}
1716 
1717 	/* Attach asymmetric crypto session to crypto operations */
1718 	rte_crypto_op_attach_asym_session(op, sess);
1719 
1720 	/* Populate op with operational details */
1721 	op->asym->ecpm.p.x.data = input_params.gen_x.data;
1722 	op->asym->ecpm.p.x.length = input_params.gen_x.length;
1723 	op->asym->ecpm.p.y.data = input_params.gen_y.data;
1724 	op->asym->ecpm.p.y.length = input_params.gen_y.length;
1725 	op->asym->ecpm.scalar.data = input_params.privkey.data;
1726 	op->asym->ecpm.scalar.length = input_params.privkey.length;
1727 
1728 	/* Init out buf */
1729 	op->asym->ecpm.r.x.data = output_buf_x;
1730 	op->asym->ecpm.r.y.data = output_buf_y;
1731 
1732 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1733 
1734 	/* Process crypto operation */
1735 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1736 		RTE_LOG(ERR, USER1,
1737 				"line %u FAILED: %s", __LINE__,
1738 				"Error sending packet for operation\n");
1739 		status = TEST_FAILED;
1740 		goto exit;
1741 	}
1742 
1743 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1744 		rte_pause();
1745 
1746 	if (result_op == NULL) {
1747 		RTE_LOG(ERR, USER1,
1748 				"line %u FAILED: %s", __LINE__,
1749 				"Failed to process asym crypto op\n");
1750 		status = TEST_FAILED;
1751 		goto exit;
1752 	}
1753 
1754 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1755 		RTE_LOG(ERR, USER1,
1756 				"line %u FAILED: %s", __LINE__,
1757 				"Failed to process asym crypto op\n");
1758 		status = TEST_FAILED;
1759 		goto exit;
1760 	}
1761 
1762 	asym_op = result_op->asym;
1763 
1764 	debug_hexdump(stdout, "r x:",
1765 			asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
1766 	debug_hexdump(stdout, "r y:",
1767 			asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
1768 
1769 	ret = verify_ecpm(input_params.pubkey_x.data,
1770 				input_params.pubkey_y.data, result_op);
1771 	if (ret) {
1772 		status = TEST_FAILED;
1773 		RTE_LOG(ERR, USER1,
1774 				"line %u FAILED: %s", __LINE__,
1775 				"EC Point Multiplication failed.\n");
1776 		goto exit;
1777 	}
1778 
1779 exit:
1780 	if (sess != NULL)
1781 		rte_cryptodev_asym_session_free(dev_id, sess);
1782 	rte_crypto_op_free(op);
1783 	return status;
1784 }
1785 
1786 static int
1787 test_ecpm_all_curve(void)
1788 {
1789 	int status, overall_status = TEST_SUCCESS;
1790 	enum curve curve_id;
1791 	int test_index = 0;
1792 	const char *msg;
1793 
1794 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
1795 		if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
1796 			continue;
1797 
1798 		status = test_ecpm(curve_id);
1799 		if (status == TEST_SUCCESS) {
1800 			msg = "succeeded";
1801 		} else {
1802 			msg = "failed";
1803 			overall_status = status;
1804 		}
1805 		printf("  %u) TestCase EC Point Mul Curve %s  %s\n",
1806 		       test_index ++, curve[curve_id], msg);
1807 	}
1808 	return overall_status;
1809 }
1810 
1811 static int
1812 test_ecdh_priv_key_generate(enum curve curve_id)
1813 {
1814 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1815 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
1816 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1817 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1818 	struct rte_cryptodev_asym_capability_idx idx;
1819 	uint8_t dev_id = ts_params->valid_devs[0];
1820 	struct rte_crypto_asym_xform xform = {0};
1821 	struct rte_crypto_op *result_op = NULL;
1822 	uint8_t output_buf[TEST_DATA_SIZE];
1823 	struct rte_crypto_asym_op *asym_op;
1824 	struct rte_crypto_op *op = NULL;
1825 	int ret, status = TEST_SUCCESS;
1826 	uint16_t output_buflen = 0;
1827 	void *sess = NULL;
1828 	int curve;
1829 
1830 	/* Check ECDH capability */
1831 	idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
1832 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
1833 	if (capa == NULL)
1834 		return -ENOTSUP;
1835 
1836 	if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE)))
1837 		return -ENOTSUP;
1838 
1839 	switch (curve_id) {
1840 	case SECP192R1:
1841 		curve = RTE_CRYPTO_EC_GROUP_SECP192R1;
1842 		output_buflen = 24;
1843 		break;
1844 	case SECP224R1:
1845 		curve = RTE_CRYPTO_EC_GROUP_SECP224R1;
1846 		output_buflen = 28;
1847 		break;
1848 	case SECP256R1:
1849 		curve = RTE_CRYPTO_EC_GROUP_SECP256R1;
1850 		output_buflen = 32;
1851 		break;
1852 	case SECP384R1:
1853 		curve = RTE_CRYPTO_EC_GROUP_SECP384R1;
1854 		output_buflen = 48;
1855 		break;
1856 	case SECP521R1:
1857 		curve = RTE_CRYPTO_EC_GROUP_SECP521R1;
1858 		output_buflen = 66;
1859 		break;
1860 	default:
1861 		RTE_LOG(ERR, USER1,
1862 				"line %u FAILED: %s", __LINE__,
1863 				"Unsupported curve id\n");
1864 		status = TEST_FAILED;
1865 		goto exit;
1866 	}
1867 
1868 	/* Setup crypto op data structure */
1869 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1870 	if (op == NULL) {
1871 		RTE_LOG(ERR, USER1,
1872 				"line %u FAILED: %s", __LINE__,
1873 				"Failed to allocate asymmetric crypto "
1874 				"operation struct\n");
1875 		status = TEST_FAILED;
1876 		goto exit;
1877 	}
1878 	asym_op = op->asym;
1879 
1880 	/* Setup asym xform */
1881 	xform.next = NULL;
1882 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
1883 	xform.ec.curve_id = curve;
1884 
1885 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
1886 	if (ret < 0) {
1887 		RTE_LOG(ERR, USER1,
1888 				"line %u FAILED: %s", __LINE__,
1889 				"Session creation failed\n");
1890 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
1891 		goto exit;
1892 	}
1893 
1894 	/* Attach asymmetric crypto session to crypto operations */
1895 	rte_crypto_op_attach_asym_session(op, sess);
1896 
1897 	/* Populate op with operational details */
1898 	asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
1899 
1900 	/* Init out buf */
1901 	asym_op->ecdh.priv_key.data = output_buf;
1902 	asym_op->ecdh.priv_key.length = output_buflen;
1903 
1904 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1905 
1906 	/* Process crypto operation */
1907 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1908 		RTE_LOG(ERR, USER1,
1909 				"line %u FAILED: %s", __LINE__,
1910 				"Error sending packet for operation\n");
1911 		status = TEST_FAILED;
1912 		goto exit;
1913 	}
1914 
1915 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1916 		rte_pause();
1917 
1918 	if (result_op == NULL) {
1919 		RTE_LOG(ERR, USER1,
1920 				"line %u FAILED: %s", __LINE__,
1921 				"Failed to process asym crypto op\n");
1922 		status = TEST_FAILED;
1923 		goto exit;
1924 	}
1925 
1926 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1927 		RTE_LOG(ERR, USER1,
1928 				"line %u FAILED: %s", __LINE__,
1929 				"Failed to process asym crypto op\n");
1930 		status = TEST_FAILED;
1931 		goto exit;
1932 	}
1933 
1934 	asym_op = result_op->asym;
1935 
1936 	debug_hexdump(stdout, "priv_key:",
1937 		asym_op->ecdh.priv_key.data, asym_op->ecdh.priv_key.length);
1938 
1939 exit:
1940 	if (sess != NULL)
1941 		rte_cryptodev_asym_session_free(dev_id, sess);
1942 	rte_crypto_op_free(op);
1943 	return status;
1944 }
1945 
1946 static int
1947 test_ecdh_pub_key_generate(enum curve curve_id)
1948 {
1949 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
1950 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
1951 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1952 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1953 	struct crypto_testsuite_ecdh_params input_params;
1954 	struct rte_cryptodev_asym_capability_idx idx;
1955 	uint8_t dev_id = ts_params->valid_devs[0];
1956 	struct rte_crypto_asym_xform xform = {0};
1957 	struct rte_crypto_op *result_op = NULL;
1958 	uint8_t output_buf_x[TEST_DATA_SIZE];
1959 	uint8_t output_buf_y[TEST_DATA_SIZE];
1960 	struct rte_crypto_asym_op *asym_op;
1961 	struct rte_crypto_op *op = NULL;
1962 	int ret, status = TEST_SUCCESS;
1963 	void *sess = NULL;
1964 
1965 	/* Check ECDH capability */
1966 	idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
1967 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
1968 	if (capa == NULL)
1969 		return TEST_SKIPPED;
1970 
1971 	if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)))
1972 		return TEST_SKIPPED;
1973 
1974 	if (curve_id == ED25519 || curve_id == ED448) {
1975 		/* Check EdDSA capability */
1976 		idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
1977 		capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
1978 		if (capa == NULL)
1979 			return TEST_SKIPPED;
1980 	}
1981 
1982 	switch (curve_id) {
1983 	case SECP192R1:
1984 		input_params = ecdh_param_secp192r1;
1985 		break;
1986 	case SECP224R1:
1987 		input_params = ecdh_param_secp224r1;
1988 		break;
1989 	case SECP256R1:
1990 		input_params = ecdh_param_secp256r1;
1991 		break;
1992 	case SECP384R1:
1993 		input_params = ecdh_param_secp384r1;
1994 		break;
1995 	case SECP521R1:
1996 		input_params = ecdh_param_secp521r1;
1997 		break;
1998 	case ED25519:
1999 		input_params = ecdh_param_ed25519;
2000 		break;
2001 	case ED448:
2002 		input_params = ecdh_param_ed448;
2003 		break;
2004 	default:
2005 		RTE_LOG(ERR, USER1,
2006 				"line %u FAILED: %s", __LINE__,
2007 				"Unsupported curve id\n");
2008 		status = TEST_FAILED;
2009 		goto exit;
2010 	}
2011 
2012 	debug_hexdump(stdout, "pkey:",
2013 		input_params.pkey_A.data, input_params.pkey_A.length);
2014 
2015 	/* Setup crypto op data structure */
2016 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2017 	if (op == NULL) {
2018 		RTE_LOG(ERR, USER1,
2019 				"line %u FAILED: %s", __LINE__,
2020 				"Failed to allocate asymmetric crypto "
2021 				"operation struct\n");
2022 		status = TEST_FAILED;
2023 		goto exit;
2024 	}
2025 	asym_op = op->asym;
2026 
2027 	/* Setup asym xform */
2028 	xform.next = NULL;
2029 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2030 	xform.ec.curve_id = input_params.curve;
2031 	xform.ec.pkey.data = input_params.pkey_A.data;
2032 	xform.ec.pkey.length = input_params.pkey_A.length;
2033 
2034 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2035 	if (ret < 0) {
2036 		RTE_LOG(ERR, USER1,
2037 				"line %u FAILED: %s", __LINE__,
2038 				"Session creation failed\n");
2039 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2040 		goto exit;
2041 	}
2042 
2043 	/* Attach asymmetric crypto session to crypto operations */
2044 	rte_crypto_op_attach_asym_session(op, sess);
2045 
2046 	/* Populate op with operational details */
2047 	asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
2048 	if (curve_id == ED25519 || curve_id == ED448)
2049 		asym_op->flags |= RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED;
2050 
2051 	/* Init out buf */
2052 	asym_op->ecdh.pub_key.x.data = output_buf_x;
2053 	if (curve_id == ED25519 || curve_id == ED448)
2054 		asym_op->ecdh.pub_key.y.data = NULL;
2055 	else
2056 		asym_op->ecdh.pub_key.y.data = output_buf_y;
2057 
2058 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2059 
2060 	/* Process crypto operation */
2061 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2062 		RTE_LOG(ERR, USER1,
2063 				"line %u FAILED: %s", __LINE__,
2064 				"Error sending packet for operation\n");
2065 		status = TEST_FAILED;
2066 		goto exit;
2067 	}
2068 
2069 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2070 		rte_pause();
2071 
2072 	if (result_op == NULL) {
2073 		RTE_LOG(ERR, USER1,
2074 				"line %u FAILED: %s", __LINE__,
2075 				"Failed to process asym crypto op\n");
2076 		status = TEST_FAILED;
2077 		goto exit;
2078 	}
2079 
2080 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2081 		RTE_LOG(ERR, USER1,
2082 				"line %u FAILED: %s", __LINE__,
2083 				"Failed to process asym crypto op\n");
2084 		status = TEST_FAILED;
2085 		goto exit;
2086 	}
2087 
2088 	asym_op = result_op->asym;
2089 
2090 	debug_hexdump(stdout, "qx:",
2091 		asym_op->ecdh.pub_key.x.data, asym_op->ecdh.pub_key.x.length);
2092 	debug_hexdump(stdout, "qy:",
2093 		asym_op->ecdh.pub_key.y.data, asym_op->ecdh.pub_key.y.length);
2094 
2095 	if (curve_id == ED25519 || curve_id == ED448)
2096 		ret = memcmp(input_params.pubkey_qA_x.data, result_op->asym->ecdh.pub_key.x.data,
2097 			   result_op->asym->ecdh.pub_key.x.length);
2098 	else
2099 		ret = verify_ecdh_secret(input_params.pubkey_qA_x.data,
2100 				input_params.pubkey_qA_y.data, result_op);
2101 
2102 	if (ret) {
2103 		status = TEST_FAILED;
2104 		RTE_LOG(ERR, USER1,
2105 				"line %u FAILED: %s", __LINE__,
2106 				"ECDH public key generation failed.\n");
2107 		goto exit;
2108 	}
2109 
2110 exit:
2111 	if (sess != NULL)
2112 		rte_cryptodev_asym_session_free(dev_id, sess);
2113 	rte_crypto_op_free(op);
2114 	return status;
2115 }
2116 
2117 static int
2118 test_ecdh_pub_key_verify(enum curve curve_id)
2119 {
2120 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2121 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
2122 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
2123 	struct rte_mempool *op_mpool = ts_params->op_mpool;
2124 	struct crypto_testsuite_ecdh_params input_params;
2125 	struct rte_cryptodev_asym_capability_idx idx;
2126 	uint8_t dev_id = ts_params->valid_devs[0];
2127 	struct rte_crypto_asym_xform xform = {0};
2128 	struct rte_crypto_op *result_op = NULL;
2129 	struct rte_crypto_asym_op *asym_op;
2130 	struct rte_crypto_op *op = NULL;
2131 	int ret, status = TEST_SUCCESS;
2132 	void *sess = NULL;
2133 
2134 	/* Check ECDH capability */
2135 	idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2136 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2137 	if (capa == NULL)
2138 		return -ENOTSUP;
2139 
2140 	if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY)))
2141 		return -ENOTSUP;
2142 
2143 	switch (curve_id) {
2144 	case SECP192R1:
2145 		input_params = ecdh_param_secp192r1;
2146 		break;
2147 	case SECP224R1:
2148 		input_params = ecdh_param_secp224r1;
2149 		break;
2150 	case SECP256R1:
2151 		input_params = ecdh_param_secp256r1;
2152 		break;
2153 	case SECP384R1:
2154 		input_params = ecdh_param_secp384r1;
2155 		break;
2156 	case SECP521R1:
2157 		input_params = ecdh_param_secp521r1;
2158 		break;
2159 	default:
2160 		RTE_LOG(ERR, USER1,
2161 				"line %u FAILED: %s", __LINE__,
2162 				"Unsupported curve id\n");
2163 		status = TEST_FAILED;
2164 		goto exit;
2165 	}
2166 
2167 	debug_hexdump(stdout, "qx:",
2168 		input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
2169 	debug_hexdump(stdout, "qy:",
2170 		input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
2171 
2172 	/* Setup crypto op data structure */
2173 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2174 	if (op == NULL) {
2175 		RTE_LOG(ERR, USER1,
2176 				"line %u FAILED: %s", __LINE__,
2177 				"Failed to allocate asymmetric crypto "
2178 				"operation struct\n");
2179 		status = TEST_FAILED;
2180 		goto exit;
2181 	}
2182 	asym_op = op->asym;
2183 
2184 	/* Setup asym xform */
2185 	xform.next = NULL;
2186 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2187 	xform.ec.curve_id = input_params.curve;
2188 
2189 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2190 	if (ret < 0) {
2191 		RTE_LOG(ERR, USER1,
2192 				"line %u FAILED: %s", __LINE__,
2193 				"Session creation failed\n");
2194 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2195 		goto exit;
2196 	}
2197 
2198 	/* Attach asymmetric crypto session to crypto operations */
2199 	rte_crypto_op_attach_asym_session(op, sess);
2200 
2201 	/* Populate op with operational details */
2202 	asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY;
2203 	asym_op->ecdh.pub_key.x.data = input_params.pubkey_qA_x.data;
2204 	asym_op->ecdh.pub_key.x.length = input_params.pubkey_qA_x.length;
2205 	asym_op->ecdh.pub_key.y.data = input_params.pubkey_qA_y.data;
2206 	asym_op->ecdh.pub_key.y.length = input_params.pubkey_qA_y.length;
2207 
2208 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2209 
2210 	/* Process crypto operation */
2211 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2212 		RTE_LOG(ERR, USER1,
2213 				"line %u FAILED: %s", __LINE__,
2214 				"Error sending packet for operation\n");
2215 		status = TEST_FAILED;
2216 		goto exit;
2217 	}
2218 
2219 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2220 		rte_pause();
2221 
2222 	if (result_op == NULL) {
2223 		RTE_LOG(ERR, USER1,
2224 				"line %u FAILED: %s", __LINE__,
2225 				"Failed to process asym crypto op\n");
2226 		status = TEST_FAILED;
2227 		goto exit;
2228 	}
2229 
2230 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2231 		RTE_LOG(ERR, USER1,
2232 				"line %u FAILED: %s", __LINE__,
2233 				"Failed to process asym crypto op\n");
2234 		status = TEST_FAILED;
2235 		goto exit;
2236 	}
2237 
2238 exit:
2239 	if (sess != NULL)
2240 		rte_cryptodev_asym_session_free(dev_id, sess);
2241 	rte_crypto_op_free(op);
2242 	return status;
2243 }
2244 
2245 static int
2246 test_ecdh_shared_secret(enum curve curve_id)
2247 {
2248 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2249 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
2250 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
2251 	struct rte_mempool *op_mpool = ts_params->op_mpool;
2252 	struct crypto_testsuite_ecdh_params input_params;
2253 	struct rte_cryptodev_asym_capability_idx idx;
2254 	uint8_t dev_id = ts_params->valid_devs[0];
2255 	struct rte_crypto_asym_xform xform = {0};
2256 	struct rte_crypto_op *result_op = NULL;
2257 	uint8_t output_buf_x[TEST_DATA_SIZE];
2258 	uint8_t output_buf_y[TEST_DATA_SIZE];
2259 	struct rte_crypto_asym_op *asym_op;
2260 	struct rte_crypto_op *op = NULL;
2261 	int ret, status = TEST_SUCCESS;
2262 	void *sess = NULL;
2263 
2264 	/* Check ECDH capability */
2265 	idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2266 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2267 	if (capa == NULL)
2268 		return -ENOTSUP;
2269 
2270 	if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE)))
2271 		return -ENOTSUP;
2272 
2273 	switch (curve_id) {
2274 	case SECP192R1:
2275 		input_params = ecdh_param_secp192r1;
2276 		break;
2277 	case SECP224R1:
2278 		input_params = ecdh_param_secp224r1;
2279 		break;
2280 	case SECP256R1:
2281 		input_params = ecdh_param_secp256r1;
2282 		break;
2283 	case SECP384R1:
2284 		input_params = ecdh_param_secp384r1;
2285 		break;
2286 	case SECP521R1:
2287 		input_params = ecdh_param_secp521r1;
2288 		break;
2289 	default:
2290 		RTE_LOG(ERR, USER1,
2291 				"line %u FAILED: %s", __LINE__,
2292 				"Unsupported curve id\n");
2293 		status = TEST_FAILED;
2294 		goto exit;
2295 	}
2296 
2297 	/* zA = dA.QB */
2298 	debug_hexdump(stdout, "pkey:",
2299 		input_params.pkey_A.data, input_params.pkey_A.length);
2300 	debug_hexdump(stdout, "qx:",
2301 		input_params.pubkey_qB_x.data, input_params.pubkey_qB_x.length);
2302 	debug_hexdump(stdout, "qy:",
2303 		input_params.pubkey_qB_y.data, input_params.pubkey_qB_y.length);
2304 
2305 	/* Setup crypto op data structure */
2306 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2307 	if (op == NULL) {
2308 		RTE_LOG(ERR, USER1,
2309 				"line %u FAILED: %s", __LINE__,
2310 				"Failed to allocate asymmetric crypto "
2311 				"operation struct\n");
2312 		status = TEST_FAILED;
2313 		goto exit;
2314 	}
2315 	asym_op = op->asym;
2316 
2317 	/* Setup asym xform */
2318 	xform.next = NULL;
2319 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2320 	xform.ec.curve_id = input_params.curve;
2321 	xform.ec.pkey.data = input_params.pkey_A.data;
2322 	xform.ec.pkey.length = input_params.pkey_A.length;
2323 	xform.ec.q.x.data = input_params.pubkey_qB_x.data;
2324 	xform.ec.q.x.length = input_params.pubkey_qB_x.length;
2325 	xform.ec.q.y.data = input_params.pubkey_qB_y.data;
2326 	xform.ec.q.y.length = input_params.pubkey_qB_y.length;
2327 
2328 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2329 	if (ret < 0) {
2330 		RTE_LOG(ERR, USER1,
2331 				"line %u FAILED: %s", __LINE__,
2332 				"Session creation failed\n");
2333 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2334 		goto exit;
2335 	}
2336 
2337 	/* Attach asymmetric crypto session to crypto operations */
2338 	rte_crypto_op_attach_asym_session(op, sess);
2339 
2340 	/* Populate op with operational details */
2341 	asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
2342 
2343 	/* Init out buf */
2344 	asym_op->ecdh.shared_secret.x.data = output_buf_x;
2345 	asym_op->ecdh.shared_secret.y.data = output_buf_y;
2346 
2347 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2348 
2349 	/* Process crypto operation */
2350 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2351 		RTE_LOG(ERR, USER1,
2352 				"line %u FAILED: %s", __LINE__,
2353 				"Error sending packet for operation\n");
2354 		status = TEST_FAILED;
2355 		goto exit;
2356 	}
2357 
2358 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2359 		rte_pause();
2360 
2361 	if (result_op == NULL) {
2362 		RTE_LOG(ERR, USER1,
2363 				"line %u FAILED: %s", __LINE__,
2364 				"Failed to process asym crypto op\n");
2365 		status = TEST_FAILED;
2366 		goto exit;
2367 	}
2368 
2369 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2370 		RTE_LOG(ERR, USER1,
2371 				"line %u FAILED: %s", __LINE__,
2372 				"Failed to process asym crypto op\n");
2373 		status = TEST_FAILED;
2374 		goto exit;
2375 	}
2376 
2377 	asym_op = result_op->asym;
2378 
2379 	debug_hexdump(stdout, "secret_x:",
2380 		asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
2381 	debug_hexdump(stdout, "secret_y:",
2382 		asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
2383 
2384 	ret = verify_ecdh_secret(input_params.secret_x.data,
2385 				input_params.secret_y.data, result_op);
2386 	if (ret) {
2387 		status = TEST_FAILED;
2388 		RTE_LOG(ERR, USER1,
2389 				"line %u FAILED: %s", __LINE__,
2390 				"ECDH shared secret compute failed.\n");
2391 		goto exit;
2392 	}
2393 
2394 	if (sess != NULL)
2395 		rte_cryptodev_asym_session_free(dev_id, sess);
2396 	rte_crypto_op_free(op);
2397 
2398 	/* zB = dB.QA */
2399 	debug_hexdump(stdout, "pkey:",
2400 		input_params.pkey_B.data, input_params.pkey_B.length);
2401 	debug_hexdump(stdout, "qx:",
2402 		input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
2403 	debug_hexdump(stdout, "qy:",
2404 		input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
2405 
2406 	/* Setup crypto op data structure */
2407 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2408 	if (op == NULL) {
2409 		RTE_LOG(ERR, USER1,
2410 				"line %u FAILED: %s", __LINE__,
2411 				"Failed to allocate asymmetric crypto "
2412 				"operation struct\n");
2413 		status = TEST_FAILED;
2414 		goto exit;
2415 	}
2416 	asym_op = op->asym;
2417 
2418 	/* Setup asym xform */
2419 	xform.next = NULL;
2420 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
2421 	xform.ec.curve_id = input_params.curve;
2422 	xform.ec.pkey.data = input_params.pkey_B.data;
2423 	xform.ec.pkey.length = input_params.pkey_B.length;
2424 	xform.ec.q.x.data = input_params.pubkey_qA_x.data;
2425 	xform.ec.q.x.length = input_params.pubkey_qA_x.length;
2426 	xform.ec.q.y.data = input_params.pubkey_qA_y.data;
2427 	xform.ec.q.y.length = input_params.pubkey_qA_y.length;
2428 
2429 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2430 	if (ret < 0) {
2431 		RTE_LOG(ERR, USER1,
2432 				"line %u FAILED: %s", __LINE__,
2433 				"Session creation failed\n");
2434 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2435 		goto exit;
2436 	}
2437 
2438 	/* Attach asymmetric crypto session to crypto operations */
2439 	rte_crypto_op_attach_asym_session(op, sess);
2440 
2441 	/* Populate op with operational details */
2442 	asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
2443 
2444 	/* Init out buf */
2445 	asym_op->ecdh.shared_secret.x.data = output_buf_x;
2446 	asym_op->ecdh.shared_secret.y.data = output_buf_y;
2447 
2448 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2449 
2450 	/* Process crypto operation */
2451 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2452 		RTE_LOG(ERR, USER1,
2453 				"line %u FAILED: %s", __LINE__,
2454 				"Error sending packet for operation\n");
2455 		status = TEST_FAILED;
2456 		goto exit;
2457 	}
2458 
2459 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2460 		rte_pause();
2461 
2462 	if (result_op == NULL) {
2463 		RTE_LOG(ERR, USER1,
2464 				"line %u FAILED: %s", __LINE__,
2465 				"Failed to process asym crypto op\n");
2466 		status = TEST_FAILED;
2467 		goto exit;
2468 	}
2469 
2470 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2471 		RTE_LOG(ERR, USER1,
2472 				"line %u FAILED: %s", __LINE__,
2473 				"Failed to process asym crypto op\n");
2474 		status = TEST_FAILED;
2475 		goto exit;
2476 	}
2477 
2478 	asym_op = result_op->asym;
2479 
2480 	debug_hexdump(stdout, "secret_x:",
2481 			asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
2482 	debug_hexdump(stdout, "secret_y:",
2483 			asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
2484 
2485 	ret = verify_ecdh_secret(input_params.secret_x.data,
2486 				input_params.secret_y.data, result_op);
2487 	if (ret) {
2488 		status = TEST_FAILED;
2489 		RTE_LOG(ERR, USER1,
2490 				"line %u FAILED: %s", __LINE__,
2491 				"ECDH shared secret compute failed.\n");
2492 		goto exit;
2493 	}
2494 
2495 exit:
2496 	if (sess != NULL)
2497 		rte_cryptodev_asym_session_free(dev_id, sess);
2498 	rte_crypto_op_free(op);
2499 	return status;
2500 }
2501 
2502 static int
2503 test_ecdh_all_curve(void)
2504 {
2505 	int status, overall_status = TEST_SUCCESS;
2506 	enum curve curve_id;
2507 	int test_index = 0;
2508 	const char *msg;
2509 
2510 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2511 		if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2512 			continue;
2513 
2514 		status = test_ecdh_priv_key_generate(curve_id);
2515 		if (status == TEST_SUCCESS) {
2516 			msg = "succeeded";
2517 		} else {
2518 			msg = "failed";
2519 			overall_status = status;
2520 		}
2521 		printf("  %u) TestCase ECDH private key generation for Curve %s %s\n",
2522 		       test_index ++, curve[curve_id], msg);
2523 	}
2524 
2525 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2526 		if (curve_id == SECP521R1_UA)
2527 			continue;
2528 
2529 		status = test_ecdh_pub_key_generate(curve_id);
2530 		if (status == TEST_SUCCESS) {
2531 			msg = "succeeded";
2532 		} else if (status == TEST_SKIPPED) {
2533 			msg = "skipped";
2534 		} else {
2535 			msg = "failed";
2536 			overall_status = status;
2537 		}
2538 		printf("  %u) TestCase ECDH public key generation for Curve %s %s\n",
2539 		       test_index ++, curve[curve_id], msg);
2540 	}
2541 
2542 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2543 		if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2544 			continue;
2545 
2546 		status = test_ecdh_pub_key_verify(curve_id);
2547 		if (status == TEST_SUCCESS) {
2548 			msg = "succeeded";
2549 		} else {
2550 			msg = "failed";
2551 			overall_status = status;
2552 		}
2553 		printf("  %u) TestCase ECDH public key verification for Curve %s %s\n",
2554 		       test_index ++, curve[curve_id], msg);
2555 	}
2556 
2557 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2558 		if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
2559 			continue;
2560 
2561 		status = test_ecdh_shared_secret(curve_id);
2562 		if (status == TEST_SUCCESS) {
2563 			msg = "succeeded";
2564 		} else {
2565 			msg = "failed";
2566 			overall_status = status;
2567 		}
2568 		printf("  %u) TestCase ECDH shared secret compute for Curve %s %s\n",
2569 		       test_index ++, curve[curve_id], msg);
2570 	}
2571 
2572 	return overall_status;
2573 }
2574 
2575 static int
2576 test_sm2_sign(void)
2577 {
2578 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2579 	struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
2580 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
2581 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
2582 	struct rte_mempool *op_mpool = ts_params->op_mpool;
2583 	struct rte_cryptodev_asym_capability_idx idx;
2584 	uint8_t dev_id = ts_params->valid_devs[0];
2585 	struct rte_crypto_op *result_op = NULL;
2586 	uint8_t output_buf_r[TEST_DATA_SIZE];
2587 	uint8_t output_buf_s[TEST_DATA_SIZE];
2588 	struct rte_crypto_asym_xform xform;
2589 	struct rte_crypto_asym_op *asym_op;
2590 	struct rte_crypto_op *op = NULL;
2591 	int ret, status = TEST_SUCCESS;
2592 	void *sess = NULL;
2593 
2594 	/* Check SM2 capability */
2595 	idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
2596 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2597 	if (capa == NULL)
2598 		return -ENOTSUP;
2599 
2600 	/* Setup crypto op data structure */
2601 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2602 	if (op == NULL) {
2603 		RTE_LOG(ERR, USER1,
2604 				"line %u FAILED: %s", __LINE__,
2605 				"Failed to allocate asymmetric crypto "
2606 				"operation struct\n");
2607 		status = TEST_FAILED;
2608 		goto exit;
2609 	}
2610 
2611 	asym_op = op->asym;
2612 
2613 	/* Setup asym xform */
2614 	xform.next = NULL;
2615 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
2616 	xform.ec.curve_id = input_params.curve;
2617 	xform.ec.pkey.data = input_params.pkey.data;
2618 	xform.ec.pkey.length = input_params.pkey.length;
2619 	xform.ec.q.x.data = input_params.pubkey_qx.data;
2620 	xform.ec.q.x.length = input_params.pubkey_qx.length;
2621 	xform.ec.q.y.data = input_params.pubkey_qy.data;
2622 	xform.ec.q.y.length = input_params.pubkey_qy.length;
2623 
2624 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2625 	if (ret < 0) {
2626 		RTE_LOG(ERR, USER1,
2627 				"line %u FAILED: %s", __LINE__,
2628 				"Session creation failed\n");
2629 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2630 		goto exit;
2631 	}
2632 
2633 	/* Attach asymmetric crypto session to crypto operations */
2634 	rte_crypto_op_attach_asym_session(op, sess);
2635 
2636 	/* Compute sign */
2637 
2638 	/* Populate op with operational details */
2639 	asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
2640 	if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2641 			RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_PH))
2642 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
2643 	else
2644 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
2645 
2646 	if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
2647 		asym_op->sm2.message.data = input_params.message.data;
2648 		asym_op->sm2.message.length = input_params.message.length;
2649 		asym_op->sm2.id.data = input_params.id.data;
2650 		asym_op->sm2.id.length = input_params.id.length;
2651 	} else {
2652 		asym_op->sm2.message.data = input_params.digest.data;
2653 		asym_op->sm2.message.length = input_params.digest.length;
2654 		asym_op->sm2.id.data = NULL;
2655 		asym_op->sm2.id.length = 0;
2656 	}
2657 
2658 	if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2659 			RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
2660 		asym_op->sm2.k.data = NULL;
2661 		asym_op->sm2.k.length = 0;
2662 	} else {
2663 		asym_op->sm2.k.data = input_params.k.data;
2664 		asym_op->sm2.k.length = input_params.k.length;
2665 	}
2666 
2667 	/* Init out buf */
2668 	asym_op->sm2.r.data = output_buf_r;
2669 	asym_op->sm2.s.data = output_buf_s;
2670 
2671 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2672 
2673 	/* Process crypto operation */
2674 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2675 		RTE_LOG(ERR, USER1,
2676 				"line %u FAILED: %s", __LINE__,
2677 				"Error sending packet for operation\n");
2678 		status = TEST_FAILED;
2679 		goto exit;
2680 	}
2681 
2682 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2683 		rte_pause();
2684 
2685 	if (result_op == NULL) {
2686 		RTE_LOG(ERR, USER1,
2687 				"line %u FAILED: %s", __LINE__,
2688 				"Failed to process asym crypto op\n");
2689 		status = TEST_FAILED;
2690 		goto exit;
2691 	}
2692 
2693 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2694 		RTE_LOG(ERR, USER1,
2695 				"line %u FAILED: %s", __LINE__,
2696 				"Failed to process asym crypto op\n");
2697 		status = TEST_FAILED;
2698 		goto exit;
2699 	}
2700 
2701 	asym_op = result_op->asym;
2702 
2703 	debug_hexdump(stdout, "r:",
2704 			asym_op->sm2.r.data, asym_op->sm2.r.length);
2705 	debug_hexdump(stdout, "s:",
2706 			asym_op->sm2.s.data, asym_op->sm2.s.length);
2707 
2708 	if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
2709 			RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_RNG)) {
2710 		/* Verify sign (by comparison). */
2711 		if (memcmp(input_params.sign_r.data, asym_op->sm2.r.data,
2712 				   asym_op->sm2.r.length) != 0) {
2713 			status = TEST_FAILED;
2714 			RTE_LOG(ERR, USER1,
2715 					"line %u FAILED: %s", __LINE__,
2716 					"SM2 sign failed.\n");
2717 			goto exit;
2718 		}
2719 		if (memcmp(input_params.sign_s.data, asym_op->sm2.s.data,
2720 				   asym_op->sm2.s.length) != 0) {
2721 			status = TEST_FAILED;
2722 			RTE_LOG(ERR, USER1,
2723 					"line %u FAILED: %s", __LINE__,
2724 					"SM2 sign failed.\n");
2725 			goto exit;
2726 		}
2727 	} else {
2728 		/* Verify sign (in roundtrip).
2729 		 * Due to random number used per message, sign op
2730 		 * would produce different output for same message
2731 		 * every time. Hence, we can't have expected output
2732 		 * to match, instead reverse op to verify.
2733 		 */
2734 
2735 		/* Populate op with operational details */
2736 		asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2737 
2738 		/* Enqueue sign result for verify */
2739 		if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2740 			status = TEST_FAILED;
2741 			RTE_LOG(ERR, USER1,
2742 					"line %u FAILED: %s", __LINE__,
2743 					"Error sending packet for operation\n");
2744 			goto exit;
2745 		}
2746 
2747 		while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2748 			rte_pause();
2749 
2750 		if (result_op == NULL) {
2751 			status = TEST_FAILED;
2752 			goto exit;
2753 		}
2754 		if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2755 			status = TEST_FAILED;
2756 			RTE_LOG(ERR, USER1,
2757 					"line %u FAILED: %s", __LINE__,
2758 					"SM2 verify failed.\n");
2759 			goto exit;
2760 		}
2761 	}
2762 
2763 exit:
2764 	if (sess != NULL)
2765 		rte_cryptodev_asym_session_free(dev_id, sess);
2766 	rte_crypto_op_free(op);
2767 	return status;
2768 };
2769 
2770 static int
2771 test_sm2_verify(void)
2772 {
2773 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2774 	struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
2775 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
2776 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
2777 	struct rte_mempool *op_mpool = ts_params->op_mpool;
2778 	struct rte_cryptodev_asym_capability_idx idx;
2779 	uint8_t dev_id = ts_params->valid_devs[0];
2780 	struct rte_crypto_op *result_op = NULL;
2781 	struct rte_crypto_asym_xform xform;
2782 	struct rte_crypto_asym_op *asym_op;
2783 	struct rte_crypto_op *op = NULL;
2784 	int ret, status = TEST_SUCCESS;
2785 	void *sess = NULL;
2786 
2787 	/* Check SM2 capability */
2788 	idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
2789 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2790 	if (capa == NULL)
2791 		return -ENOTSUP;
2792 
2793 	/* Setup crypto op data structure */
2794 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2795 	if (op == NULL) {
2796 		RTE_LOG(ERR, USER1,
2797 				"line %u FAILED: %s", __LINE__,
2798 				"Failed to allocate asymmetric crypto "
2799 				"operation struct\n");
2800 		status = TEST_FAILED;
2801 		goto exit;
2802 	}
2803 
2804 	asym_op = op->asym;
2805 
2806 	/* Setup asym xform */
2807 	xform.next = NULL;
2808 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
2809 	xform.ec.curve_id = input_params.curve;
2810 	xform.ec.pkey.data = input_params.pkey.data;
2811 	xform.ec.pkey.length = input_params.pkey.length;
2812 	xform.ec.q.x.data = input_params.pubkey_qx.data;
2813 	xform.ec.q.x.length = input_params.pubkey_qx.length;
2814 	xform.ec.q.y.data = input_params.pubkey_qy.data;
2815 	xform.ec.q.y.length = input_params.pubkey_qy.length;
2816 
2817 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2818 	if (ret < 0) {
2819 		RTE_LOG(ERR, USER1,
2820 				"line %u FAILED: %s", __LINE__,
2821 				"Session creation failed\n");
2822 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2823 		goto exit;
2824 	}
2825 
2826 	/* Attach asymmetric crypto session to crypto operations */
2827 	rte_crypto_op_attach_asym_session(op, sess);
2828 
2829 	/* Verify given sign */
2830 
2831 	/* Populate op with operational details */
2832 	asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2833 
2834 	if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2835 			RTE_CRYPTO_ASYM_OP_VERIFY, RTE_CRYPTO_SM2_PH))
2836 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
2837 	else
2838 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
2839 
2840 	if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
2841 		asym_op->sm2.message.data = input_params.message.data;
2842 		asym_op->sm2.message.length = input_params.message.length;
2843 		asym_op->sm2.id.data = input_params.id.data;
2844 		asym_op->sm2.id.length = input_params.id.length;
2845 	} else {
2846 		asym_op->sm2.message.data = input_params.digest.data;
2847 		asym_op->sm2.message.length = input_params.digest.length;
2848 		asym_op->sm2.id.data = NULL;
2849 		asym_op->sm2.id.length = 0;
2850 	}
2851 
2852 	asym_op->sm2.r.data = input_params.sign_r.data;
2853 	asym_op->sm2.r.length = input_params.sign_r.length;
2854 	asym_op->sm2.s.data = input_params.sign_s.data;
2855 	asym_op->sm2.s.length = input_params.sign_s.length;
2856 
2857 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2858 
2859 	/* Process crypto operation */
2860 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2861 		RTE_LOG(ERR, USER1,
2862 				"line %u FAILED: %s", __LINE__,
2863 				"Error sending packet for operation\n");
2864 		status = TEST_FAILED;
2865 		goto exit;
2866 	}
2867 
2868 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2869 		rte_pause();
2870 
2871 	if (result_op == NULL) {
2872 		RTE_LOG(ERR, USER1,
2873 				"line %u FAILED: %s", __LINE__,
2874 				"Failed to process asym crypto op\n");
2875 		status = TEST_FAILED;
2876 		goto exit;
2877 	}
2878 
2879 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2880 		RTE_LOG(ERR, USER1,
2881 				"line %u FAILED: %s", __LINE__,
2882 				"Failed to process asym crypto op\n");
2883 		status = TEST_FAILED;
2884 		goto exit;
2885 	}
2886 
2887 exit:
2888 	if (sess != NULL)
2889 		rte_cryptodev_asym_session_free(dev_id, sess);
2890 	rte_crypto_op_free(op);
2891 	return status;
2892 };
2893 
2894 static int
2895 test_sm2_enc(void)
2896 {
2897 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
2898 	struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
2899 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
2900 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
2901 	struct rte_mempool *op_mpool = ts_params->op_mpool;
2902 	uint8_t output_buf[TEST_DATA_SIZE], *pbuf = NULL;
2903 	struct rte_cryptodev_asym_capability_idx idx;
2904 	uint8_t dev_id = ts_params->valid_devs[0];
2905 	struct rte_crypto_op *result_op = NULL;
2906 	struct rte_crypto_asym_xform xform;
2907 	struct rte_crypto_asym_op *asym_op;
2908 	struct rte_crypto_op *op = NULL;
2909 	int ret, status = TEST_SUCCESS;
2910 	void *sess = NULL;
2911 
2912 	/* Check SM2 capability */
2913 	idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
2914 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
2915 	if (capa == NULL)
2916 		return -ENOTSUP;
2917 
2918 	/* Setup crypto op data structure */
2919 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2920 	if (op == NULL) {
2921 		RTE_LOG(ERR, USER1,
2922 				"line %u FAILED: %s", __LINE__,
2923 				"Failed to allocate asymmetric crypto "
2924 				"operation struct\n");
2925 		status = TEST_FAILED;
2926 		goto exit;
2927 	}
2928 	asym_op = op->asym;
2929 
2930 	/* Setup asym xform */
2931 	xform.next = NULL;
2932 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
2933 	xform.ec.curve_id = input_params.curve;
2934 	xform.ec.pkey.data = input_params.pkey.data;
2935 	xform.ec.pkey.length = input_params.pkey.length;
2936 	xform.ec.q.x.data = input_params.pubkey_qx.data;
2937 	xform.ec.q.x.length = input_params.pubkey_qx.length;
2938 	xform.ec.q.y.data = input_params.pubkey_qy.data;
2939 	xform.ec.q.y.length = input_params.pubkey_qy.length;
2940 
2941 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
2942 	if (ret < 0) {
2943 		RTE_LOG(ERR, USER1,
2944 				"line %u FAILED: %s", __LINE__,
2945 				"Session creation failed\n");
2946 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
2947 		goto exit;
2948 	}
2949 
2950 	/* Attach asymmetric crypto session to crypto operations */
2951 	rte_crypto_op_attach_asym_session(op, sess);
2952 
2953 	/* Compute encrypt */
2954 
2955 	/* Populate op with operational details */
2956 	asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
2957 	if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2958 			RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_PH))
2959 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
2960 	else
2961 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
2962 
2963 	asym_op->sm2.message.data = input_params.message.data;
2964 	asym_op->sm2.message.length = input_params.message.length;
2965 
2966 	if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
2967 			RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
2968 		asym_op->sm2.k.data = NULL;
2969 		asym_op->sm2.k.length = 0;
2970 	} else {
2971 		asym_op->sm2.k.data = input_params.k.data;
2972 		asym_op->sm2.k.length = input_params.k.length;
2973 	}
2974 
2975 	/* Init out buf */
2976 	asym_op->sm2.cipher.data = output_buf;
2977 
2978 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2979 
2980 	/* Process crypto operation */
2981 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2982 		RTE_LOG(ERR, USER1,
2983 				"line %u FAILED: %s", __LINE__,
2984 				"Error sending packet for operation\n");
2985 		status = TEST_FAILED;
2986 		goto exit;
2987 	}
2988 
2989 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2990 		rte_pause();
2991 
2992 	if (result_op == NULL) {
2993 		RTE_LOG(ERR, USER1,
2994 				"line %u FAILED: %s", __LINE__,
2995 				"Failed to process asym crypto op\n");
2996 		status = TEST_FAILED;
2997 		goto exit;
2998 	}
2999 
3000 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3001 		RTE_LOG(ERR, USER1,
3002 				"line %u FAILED: %s", __LINE__,
3003 				"Failed to process asym crypto op\n");
3004 		status = TEST_FAILED;
3005 		goto exit;
3006 	}
3007 
3008 	asym_op = result_op->asym;
3009 
3010 	debug_hexdump(stdout, "cipher:",
3011 			asym_op->sm2.cipher.data, asym_op->sm2.cipher.length);
3012 
3013 	if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
3014 			RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
3015 		if (memcmp(input_params.cipher.data, asym_op->sm2.cipher.data,
3016 				   asym_op->sm2.cipher.length) != 0) {
3017 			status = TEST_FAILED;
3018 			RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
3019 					"SM2 encrypt failed.\n");
3020 			goto exit;
3021 		}
3022 	} else {
3023 		/* Verify cipher (in roundtrip).
3024 		 * Due to random number used per message, encrypt op
3025 		 * would produce different output for same message
3026 		 * every time. Hence, we can't have expected output
3027 		 * to match, instead reverse op to decrypt.
3028 		 */
3029 
3030 		/* Populate op with operational details */
3031 		op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3032 		pbuf = rte_malloc(NULL, TEST_DATA_SIZE, 0);
3033 		op->asym->sm2.message.data = pbuf;
3034 		op->asym->sm2.message.length = TEST_DATA_SIZE;
3035 
3036 		/* Enqueue cipher result for decrypt */
3037 		if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3038 			status = TEST_FAILED;
3039 			RTE_LOG(ERR, USER1,
3040 					"line %u FAILED: %s", __LINE__,
3041 					"Error sending packet for operation\n");
3042 			goto exit;
3043 		}
3044 
3045 		while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3046 			rte_pause();
3047 
3048 		if (result_op == NULL) {
3049 			status = TEST_FAILED;
3050 			goto exit;
3051 		}
3052 		if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3053 			status = TEST_FAILED;
3054 			RTE_LOG(ERR, USER1,
3055 					"line %u FAILED: %s", __LINE__,
3056 					"SM2 encrypt failed.\n");
3057 			goto exit;
3058 		}
3059 
3060 		asym_op = result_op->asym;
3061 		if (memcmp(input_params.message.data, asym_op->sm2.message.data,
3062 			       asym_op->sm2.message.length) != 0) {
3063 			status = TEST_FAILED;
3064 			RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
3065 					"SM2 encrypt failed.\n");
3066 			goto exit;
3067 		}
3068 	}
3069 exit:
3070 	rte_free(pbuf);
3071 
3072 	if (sess != NULL)
3073 		rte_cryptodev_asym_session_free(dev_id, sess);
3074 	rte_crypto_op_free(op);
3075 	return status;
3076 };
3077 
3078 static int
3079 test_sm2_dec(void)
3080 {
3081 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3082 	struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
3083 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
3084 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
3085 	struct rte_mempool *op_mpool = ts_params->op_mpool;
3086 	struct rte_cryptodev_asym_capability_idx idx;
3087 	uint8_t dev_id = ts_params->valid_devs[0];
3088 	struct rte_crypto_op *result_op = NULL;
3089 	uint8_t output_buf_m[TEST_DATA_SIZE];
3090 	struct rte_crypto_asym_xform xform;
3091 	struct rte_crypto_asym_op *asym_op;
3092 	struct rte_crypto_op *op = NULL;
3093 	int ret, status = TEST_SUCCESS;
3094 	void *sess = NULL;
3095 
3096 	/* Check SM2 capability */
3097 	idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
3098 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3099 	if (capa == NULL)
3100 		return -ENOTSUP;
3101 
3102 	/* Setup crypto op data structure */
3103 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3104 	if (op == NULL) {
3105 		RTE_LOG(ERR, USER1,
3106 				"line %u FAILED: %s", __LINE__,
3107 				"Failed to allocate asymmetric crypto "
3108 				"operation struct\n");
3109 		status = TEST_FAILED;
3110 		goto exit;
3111 	}
3112 	asym_op = op->asym;
3113 
3114 	/* Setup asym xform */
3115 	xform.next = NULL;
3116 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
3117 	xform.ec.curve_id = input_params.curve;
3118 	xform.ec.pkey.data = input_params.pkey.data;
3119 	xform.ec.pkey.length = input_params.pkey.length;
3120 	xform.ec.q.x.data = input_params.pubkey_qx.data;
3121 	xform.ec.q.x.length = input_params.pubkey_qx.length;
3122 	xform.ec.q.y.data = input_params.pubkey_qy.data;
3123 	xform.ec.q.y.length = input_params.pubkey_qy.length;
3124 
3125 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3126 	if (ret < 0) {
3127 		RTE_LOG(ERR, USER1,
3128 				"line %u FAILED: %s", __LINE__,
3129 				"Session creation failed\n");
3130 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3131 		goto exit;
3132 	}
3133 
3134 	/* Attach asymmetric crypto session to crypto operations */
3135 	rte_crypto_op_attach_asym_session(op, sess);
3136 
3137 	/* Compute decrypt */
3138 
3139 	/* Populate op with operational details */
3140 	asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3141 	if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
3142 			RTE_CRYPTO_ASYM_OP_DECRYPT, RTE_CRYPTO_SM2_PH))
3143 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
3144 	else
3145 		asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
3146 
3147 	asym_op->sm2.cipher.data = input_params.cipher.data;
3148 	asym_op->sm2.cipher.length = input_params.cipher.length;
3149 
3150 	/* Init out buf */
3151 	asym_op->sm2.message.data = output_buf_m;
3152 	asym_op->sm2.message.length = RTE_DIM(output_buf_m);
3153 
3154 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3155 
3156 	/* Process crypto operation */
3157 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3158 		RTE_LOG(ERR, USER1,
3159 				"line %u FAILED: %s", __LINE__,
3160 				"Error sending packet for operation\n");
3161 		status = TEST_FAILED;
3162 		goto exit;
3163 	}
3164 
3165 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3166 		rte_pause();
3167 
3168 	if (result_op == NULL) {
3169 		RTE_LOG(ERR, USER1,
3170 				"line %u FAILED: %s", __LINE__,
3171 				"Failed to process asym crypto op\n");
3172 		status = TEST_FAILED;
3173 		goto exit;
3174 	}
3175 
3176 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3177 		RTE_LOG(ERR, USER1,
3178 				"line %u FAILED: %s", __LINE__,
3179 				"Failed to process asym crypto op\n");
3180 		status = TEST_FAILED;
3181 		goto exit;
3182 	}
3183 
3184 	asym_op = result_op->asym;
3185 
3186 	debug_hexdump(stdout, "message:",
3187 			asym_op->sm2.message.data, asym_op->sm2.message.length);
3188 
3189 	if (memcmp(input_params.message.data, asym_op->sm2.message.data,
3190 			op->asym->sm2.message.length)) {
3191 		status = TEST_FAILED;
3192 		RTE_LOG(ERR, USER1,
3193 				"line %u FAILED: %s", __LINE__,
3194 				"SM2 decrypt failed.\n");
3195 		goto exit;
3196 	}
3197 exit:
3198 	if (sess != NULL)
3199 		rte_cryptodev_asym_session_free(dev_id, sess);
3200 	rte_crypto_op_free(op);
3201 	return status;
3202 };
3203 
3204 static int
3205 test_eddsa_sign(struct crypto_testsuite_eddsa_params *input_params)
3206 {
3207 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3208 	enum rte_crypto_edward_instance instance = input_params->instance;
3209 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
3210 	struct rte_mempool *op_mpool = ts_params->op_mpool;
3211 	uint8_t dev_id = ts_params->valid_devs[0];
3212 	struct rte_crypto_op *result_op = NULL;
3213 	uint8_t output_buf_r[TEST_DATA_SIZE];
3214 	struct rte_crypto_asym_xform xform;
3215 	struct rte_crypto_asym_op *asym_op;
3216 	struct rte_crypto_op *op = NULL;
3217 	int ret, status = TEST_FAILED;
3218 	void *sess = NULL;
3219 	bool ctx = false;
3220 
3221 	if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
3222 		ctx = true;
3223 
3224 	/* Setup crypto op data structure */
3225 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3226 	if (op == NULL) {
3227 		RTE_LOG(ERR, USER1,
3228 				"line %u FAILED: %s", __LINE__,
3229 				"Failed to allocate asymmetric crypto "
3230 				"operation struct\n");
3231 		status = TEST_FAILED;
3232 		goto exit;
3233 	}
3234 
3235 	asym_op = op->asym;
3236 
3237 	/* Setup asym xform */
3238 	xform.next = NULL;
3239 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3240 	xform.ec.curve_id = input_params->curve;
3241 	xform.ec.pkey.data = input_params->pkey.data;
3242 	xform.ec.pkey.length = input_params->pkey.length;
3243 	xform.ec.q.x.data = input_params->pubkey.data;
3244 	xform.ec.q.x.length = input_params->pubkey.length;
3245 
3246 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3247 	if (ret < 0) {
3248 		RTE_LOG(ERR, USER1,
3249 				"line %u FAILED: %s", __LINE__,
3250 				"Session creation failed\n");
3251 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3252 		goto exit;
3253 	}
3254 
3255 	/* Attach asymmetric crypto session to crypto operations */
3256 	rte_crypto_op_attach_asym_session(op, sess);
3257 
3258 	/* Compute sign */
3259 
3260 	/* Populate op with operational details */
3261 	asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
3262 	asym_op->eddsa.instance = input_params->instance;
3263 	asym_op->eddsa.message.data = input_params->message.data;
3264 	asym_op->eddsa.message.length = input_params->message.length;
3265 	asym_op->eddsa.context.length = 0;
3266 	if (ctx) {
3267 		asym_op->eddsa.context.data = input_params->context.data;
3268 		asym_op->eddsa.context.length = input_params->context.length;
3269 	}
3270 
3271 	/* Init out buf */
3272 	asym_op->eddsa.sign.data = output_buf_r;
3273 
3274 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3275 
3276 	/* Process crypto operation */
3277 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3278 		RTE_LOG(ERR, USER1,
3279 				"line %u FAILED: %s", __LINE__,
3280 				"Error sending packet for operation\n");
3281 		goto exit;
3282 	}
3283 
3284 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3285 		rte_pause();
3286 
3287 	if (result_op == NULL) {
3288 		RTE_LOG(ERR, USER1,
3289 				"line %u FAILED: %s", __LINE__,
3290 				"Failed to process asym crypto op\n");
3291 		goto exit;
3292 	}
3293 
3294 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3295 		RTE_LOG(ERR, USER1,
3296 				"line %u FAILED: %s", __LINE__,
3297 				"Failed to process asym crypto op\n");
3298 		goto exit;
3299 	}
3300 
3301 	asym_op = result_op->asym;
3302 
3303 	debug_hexdump(stdout, "sign:",
3304 			asym_op->eddsa.sign.data, asym_op->eddsa.sign.length);
3305 
3306 	/* Verify sign (by comparison). */
3307 	if (memcmp(input_params->sign.data, asym_op->eddsa.sign.data,
3308 			   asym_op->eddsa.sign.length) != 0) {
3309 		RTE_LOG(ERR, USER1,
3310 				"line %u FAILED: %s", __LINE__,
3311 				"EdDSA sign failed.\n");
3312 		goto exit;
3313 	}
3314 
3315 	status = TEST_SUCCESS;
3316 exit:
3317 	if (sess != NULL)
3318 		rte_cryptodev_asym_session_free(dev_id, sess);
3319 	rte_crypto_op_free(op);
3320 	return status;
3321 };
3322 
3323 static int
3324 test_eddsa_verify(struct crypto_testsuite_eddsa_params *input_params)
3325 {
3326 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3327 	enum rte_crypto_edward_instance instance = input_params->instance;
3328 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
3329 	struct rte_mempool *op_mpool = ts_params->op_mpool;
3330 	uint8_t dev_id = ts_params->valid_devs[0];
3331 	struct rte_crypto_op *result_op = NULL;
3332 	struct rte_crypto_asym_xform xform;
3333 	struct rte_crypto_asym_op *asym_op;
3334 	struct rte_crypto_op *op = NULL;
3335 	int ret, status = TEST_FAILED;
3336 	void *sess = NULL;
3337 	bool ctx = false;
3338 
3339 	if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
3340 		ctx = true;
3341 
3342 	/* Setup crypto op data structure */
3343 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
3344 	if (op == NULL) {
3345 		RTE_LOG(ERR, USER1,
3346 				"line %u FAILED: %s", __LINE__,
3347 				"Failed to allocate asymmetric crypto "
3348 				"operation struct\n");
3349 		goto exit;
3350 	}
3351 
3352 	asym_op = op->asym;
3353 
3354 	/* Setup asym xform */
3355 	xform.next = NULL;
3356 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3357 	xform.ec.curve_id = input_params->curve;
3358 	xform.ec.pkey.length = 0;
3359 	xform.ec.q.x.data = input_params->pubkey.data;
3360 	xform.ec.q.x.length = input_params->pubkey.length;
3361 
3362 	ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
3363 	if (ret < 0) {
3364 		RTE_LOG(ERR, USER1,
3365 				"line %u FAILED: %s", __LINE__,
3366 				"Session creation failed\n");
3367 		status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3368 		goto exit;
3369 	}
3370 
3371 	/* Attach asymmetric crypto session to crypto operations */
3372 	rte_crypto_op_attach_asym_session(op, sess);
3373 
3374 	/* Compute sign */
3375 
3376 	/* Populate op with operational details */
3377 	asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
3378 	asym_op->eddsa.instance = input_params->instance;
3379 	asym_op->eddsa.message.data = input_params->message.data;
3380 	asym_op->eddsa.message.length = input_params->message.length;
3381 	asym_op->eddsa.context.length = 0;
3382 	if (ctx) {
3383 		asym_op->eddsa.context.data = input_params->context.data;
3384 		asym_op->eddsa.context.length = input_params->context.length;
3385 	}
3386 
3387 	asym_op->eddsa.sign.data = input_params->sign.data;
3388 	asym_op->eddsa.sign.length = input_params->sign.length;
3389 
3390 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
3391 
3392 	/* Process crypto operation */
3393 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
3394 		RTE_LOG(ERR, USER1,
3395 				"line %u FAILED: %s", __LINE__,
3396 				"Error sending packet for operation\n");
3397 		goto exit;
3398 	}
3399 
3400 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
3401 		rte_pause();
3402 
3403 	if (result_op == NULL) {
3404 		RTE_LOG(ERR, USER1,
3405 				"line %u FAILED: %s", __LINE__,
3406 				"Failed to process asym crypto op\n");
3407 		goto exit;
3408 	}
3409 
3410 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
3411 		RTE_LOG(ERR, USER1,
3412 				"line %u FAILED: %s", __LINE__,
3413 				"Failed to process asym crypto op\n");
3414 		goto exit;
3415 	}
3416 
3417 	status = TEST_SUCCESS;
3418 exit:
3419 	if (sess != NULL)
3420 		rte_cryptodev_asym_session_free(dev_id, sess);
3421 	rte_crypto_op_free(op);
3422 	return status;
3423 };
3424 
3425 static int
3426 test_eddsa_sign_verify_all_curve(void)
3427 {
3428 	struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
3429 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
3430 	struct crypto_testsuite_eddsa_params input_params;
3431 	struct rte_cryptodev_asym_capability_idx idx;
3432 	int status, overall_status = TEST_SUCCESS;
3433 	uint8_t dev_id = ts_params->valid_devs[0];
3434 	uint8_t i, tc = 0;
3435 	const char *msg;
3436 
3437 	/* Check EdDSA capability */
3438 	idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
3439 	capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
3440 	if (capa == NULL)
3441 		return TEST_SKIPPED;
3442 
3443 	/* Sign tests */
3444 	for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
3445 		memcpy(&input_params, &eddsa_test_params[i],
3446 				sizeof(input_params));
3447 		status = test_eddsa_sign(&input_params);
3448 		if (status == TEST_SUCCESS) {
3449 			msg = "succeeded";
3450 		} else {
3451 			msg = "failed";
3452 			overall_status = status;
3453 		}
3454 		printf("  %u) TestCase Sign %s  %s\n",
3455 		       tc++, input_params.description, msg);
3456 	}
3457 
3458 	/* Verify tests */
3459 	for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
3460 		memcpy(&input_params, &eddsa_test_params[i],
3461 				sizeof(input_params));
3462 		status = test_eddsa_verify(&input_params);
3463 		if (status == TEST_SUCCESS) {
3464 			msg = "succeeded";
3465 		} else {
3466 			msg = "failed";
3467 			overall_status = status;
3468 		}
3469 		printf("  %u) TestCase Verify %s  %s\n",
3470 		       tc++, input_params.description, msg);
3471 	}
3472 
3473 	/* Negative tests */
3474 	memcpy(&input_params, &eddsa_test_params[1],
3475 			sizeof(input_params));
3476 	input_params.pubkey.data[0] ^= 0x01;
3477 
3478 	status = test_eddsa_sign(&input_params);
3479 	if (status == TEST_FAILED) {
3480 		msg = "succeeded";
3481 	} else {
3482 		msg = "failed";
3483 		overall_status = status;
3484 	}
3485 	printf("  %u) TestCase Negative Sign %s  %s\n",
3486 			tc++, input_params.description, msg);
3487 
3488 	status = test_eddsa_verify(&input_params);
3489 	if (status == TEST_FAILED) {
3490 		msg = "succeeded";
3491 	} else {
3492 		msg = "failed";
3493 		overall_status = status;
3494 	}
3495 	printf("  %u) TestCase Negative Verify %s  %s\n",
3496 			tc++, input_params.description, msg);
3497 
3498 	return overall_status;
3499 }
3500 
3501 static int send_one(void)
3502 {
3503 	int ticks = 0;
3504 
3505 	if (rte_cryptodev_enqueue_burst(params->valid_devs[0], 0,
3506 			&self->op, 1) != 1) {
3507 		RTE_LOG(ERR, USER1,
3508 			"line %u FAILED: Error sending packet for operation on device %d",
3509 			__LINE__, params->valid_devs[0]);
3510 		return TEST_FAILED;
3511 	}
3512 	while (rte_cryptodev_dequeue_burst(params->valid_devs[0], 0,
3513 			&self->result_op, 1) == 0) {
3514 		rte_delay_ms(1);
3515 		ticks++;
3516 		if (ticks >= DEQ_TIMEOUT) {
3517 			RTE_LOG(ERR, USER1,
3518 				"line %u FAILED: Cannot dequeue the crypto op on device %d",
3519 				__LINE__, params->valid_devs[0]);
3520 			return TEST_FAILED;
3521 		}
3522 	}
3523 	TEST_ASSERT_NOT_NULL(self->result_op,
3524 		"Failed to process asym crypto op");
3525 	TEST_ASSERT_SUCCESS(self->result_op->status,
3526 		"Failed to process asym crypto op, error status received");
3527 	return TEST_SUCCESS;
3528 }
3529 
3530 static int
3531 modular_cmpeq(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len)
3532 {
3533 	const uint8_t *new_a, *new_b;
3534 	size_t i, j;
3535 
3536 	/* Strip leading NUL bytes */
3537 	for (i = 0; i < a_len; i++)
3538 		if (a[i] != 0)
3539 			break;
3540 
3541 	for (j = 0; j < b_len; j++)
3542 		if (b[j] != 0)
3543 			break;
3544 
3545 	if (a_len - i != b_len - j)
3546 		return 1;
3547 
3548 	new_a = &a[i];
3549 	new_b = &b[j];
3550 	if (memcmp(new_a, new_b, a_len - i))
3551 		return 1;
3552 
3553 	return 0;
3554 }
3555 
3556 static int
3557 modular_exponentiation(const void *test_data)
3558 {
3559 	const struct modex_test_data *vector = test_data;
3560 	uint8_t input[TEST_DATA_SIZE] = { 0 };
3561 	uint8_t exponent[TEST_DATA_SIZE] = { 0 };
3562 	uint8_t modulus[TEST_DATA_SIZE] = { 0 };
3563 	uint8_t result[TEST_DATA_SIZE] = { 0 };
3564 	struct rte_crypto_asym_xform xform = { };
3565 	const uint8_t dev_id = params->valid_devs[0];
3566 
3567 	memcpy(input, vector->base.data, vector->base.len);
3568 	memcpy(exponent, vector->exponent.data, vector->exponent.len);
3569 	memcpy(modulus, vector->modulus.data, vector->modulus.len);
3570 
3571 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
3572 	xform.modex.exponent.data = exponent;
3573 	xform.modex.exponent.length = vector->exponent.len;
3574 	xform.modex.modulus.data = modulus;
3575 	xform.modex.modulus.length = vector->modulus.len;
3576 
3577 	if (rte_cryptodev_asym_session_create(dev_id, &xform,
3578 			params->session_mpool, &self->sess) < 0) {
3579 		RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3580 			__LINE__);
3581 		return TEST_FAILED;
3582 	}
3583 	rte_crypto_op_attach_asym_session(self->op, self->sess);
3584 	self->op->asym->modex.base.data = input;
3585 	self->op->asym->modex.base.length = vector->base.len;
3586 	self->op->asym->modex.result.data = result;
3587 
3588 	TEST_ASSERT_SUCCESS(send_one(),
3589 		"Failed to process crypto op");
3590 	TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data, vector->reminder.len,
3591 			self->result_op->asym->modex.result.data,
3592 			self->result_op->asym->modex.result.length),
3593 			"operation verification failed\n");
3594 
3595 	return TEST_SUCCESS;
3596 }
3597 
3598 static int
3599 modular_multiplicative_inverse(const void *test_data)
3600 {
3601 	const struct modinv_test_data *vector = test_data;
3602 	uint8_t input[TEST_DATA_SIZE] = { 0 };
3603 	uint8_t modulus[TEST_DATA_SIZE] = { 0 };
3604 	uint8_t result[TEST_DATA_SIZE] = { 0 };
3605 	struct rte_crypto_asym_xform xform = { };
3606 	const uint8_t dev_id = params->valid_devs[0];
3607 
3608 	memcpy(input, vector->base.data, vector->base.len);
3609 	memcpy(modulus, vector->modulus.data, vector->modulus.len);
3610 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV;
3611 	xform.modex.modulus.data = modulus;
3612 	xform.modex.modulus.length = vector->modulus.len;
3613 	if (rte_cryptodev_asym_session_create(dev_id, &xform,
3614 			params->session_mpool, &self->sess) < 0) {
3615 		RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
3616 			__LINE__);
3617 		return TEST_FAILED;
3618 	}
3619 	rte_crypto_op_attach_asym_session(self->op, self->sess);
3620 
3621 	self->op->asym->modinv.base.data = input;
3622 	self->op->asym->modinv.base.length = vector->base.len;
3623 	self->op->asym->modinv.result.data = result;
3624 	self->op->asym->modinv.result.length = vector->modulus.len;
3625 
3626 	TEST_ASSERT_SUCCESS(send_one(),
3627 		"Failed to process crypto op");
3628 	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->inverse.data,
3629 		self->result_op->asym->modinv.result.data,
3630 		self->result_op->asym->modinv.result.length,
3631 		"Incorrect reminder\n");
3632 
3633 	return TEST_SUCCESS;
3634 }
3635 
3636 #define SET_RSA_PARAM(arg, vector, coef) \
3637 	uint8_t coef[TEST_DATA_SIZE] = { }; \
3638 	memcpy(coef, vector->coef.data, vector->coef.len); \
3639 	arg.coef.data = coef; \
3640 	arg.coef.length = vector->coef.len
3641 
3642 #define SET_RSA_PARAM_QT(arg, vector, coef) \
3643 	uint8_t coef[TEST_DATA_SIZE] = { }; \
3644 	memcpy(coef, vector->coef.data, vector->coef.len); \
3645 	arg.qt.coef.data = coef; \
3646 	arg.qt.coef.length = vector->coef.len
3647 
3648 static int
3649 rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf)
3650 {
3651 	self->result_op = NULL;
3652 	/* Compute encryption on the test vector */
3653 	self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
3654 	self->op->asym->rsa.cipher.data = cipher_buf;
3655 	self->op->asym->rsa.cipher.length = 0;
3656 	SET_RSA_PARAM(self->op->asym->rsa, vector, message);
3657 
3658 	rte_crypto_op_attach_asym_session(self->op, self->sess);
3659 	TEST_ASSERT_SUCCESS(send_one(),
3660 		"Failed to process crypto op (Enryption)");
3661 
3662 	return 0;
3663 }
3664 
3665 static int
3666 rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext,
3667 		const int use_op)
3668 {
3669 	uint8_t cipher[TEST_DATA_SIZE] = { 0 };
3670 
3671 	if (use_op == 0) {
3672 		memcpy(cipher, vector->cipher.data, vector->cipher.len);
3673 		self->op->asym->rsa.cipher.data = cipher;
3674 		self->op->asym->rsa.cipher.length = vector->cipher.len;
3675 	}
3676 	self->result_op = NULL;
3677 	self->op->asym->rsa.message.data = plaintext;
3678 	self->op->asym->rsa.message.length = 0;
3679 	self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
3680 	rte_crypto_op_attach_asym_session(self->op, self->sess);
3681 	TEST_ASSERT_SUCCESS(send_one(),
3682 		"Failed to process crypto op (Decryption)");
3683 	return 0;
3684 }
3685 
3686 static int
3687 rsa_init_session(struct rte_crypto_asym_xform *xform)
3688 {
3689 	const uint8_t dev_id = params->valid_devs[0];
3690 	struct rte_cryptodev_info dev_info;
3691 	int ret = 0;
3692 
3693 	xform->xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
3694 
3695 	rte_cryptodev_info_get(dev_id, &dev_info);
3696 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
3697 		RTE_LOG(INFO, USER1,
3698 			"Device doesn't support decrypt op with quintuple key type. Test skipped\n");
3699 		return TEST_SKIPPED;
3700 	}
3701 	ret = rte_cryptodev_asym_session_create(dev_id, xform,
3702 		params->session_mpool, &self->sess);
3703 	if (ret < 0) {
3704 		RTE_LOG(ERR, USER1,
3705 			"Session creation failed for enc_dec_crt\n");
3706 		return (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
3707 	}
3708 	return 0;
3709 }
3710 
3711 static int
3712 kat_rsa_encrypt(const void *data)
3713 {
3714 	uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
3715 	const struct rsa_test_data_2 *vector = data;
3716 	struct rte_crypto_asym_xform xform = { };
3717 
3718 	SET_RSA_PARAM(xform.rsa, vector, n);
3719 	SET_RSA_PARAM(xform.rsa, vector, e);
3720 	SET_RSA_PARAM(xform.rsa, vector, d);
3721 	xform.rsa.padding.type = vector->padding;
3722 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
3723 	int ret = rsa_init_session(&xform);
3724 
3725 	if (ret) {
3726 		RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3727 		return ret;
3728 	}
3729 	TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
3730 		"RSA: Failed to encrypt");
3731 	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
3732 		self->result_op->asym->rsa.cipher.data,
3733 		self->result_op->asym->rsa.cipher.length,
3734 		"operation verification failed\n");
3735 	return 0;
3736 }
3737 
3738 static int
3739 kat_rsa_encrypt_crt(const void *data)
3740 {
3741 	uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
3742 	const struct rsa_test_data_2 *vector = data;
3743 	struct rte_crypto_asym_xform xform = { };
3744 
3745 	SET_RSA_PARAM(xform.rsa, vector, n);
3746 	SET_RSA_PARAM(xform.rsa, vector, e);
3747 	SET_RSA_PARAM_QT(xform.rsa, vector, p);
3748 	SET_RSA_PARAM_QT(xform.rsa, vector, q);
3749 	SET_RSA_PARAM_QT(xform.rsa, vector, dP);
3750 	SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
3751 	SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
3752 	xform.rsa.padding.type = vector->padding;
3753 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
3754 	int ret = rsa_init_session(&xform);
3755 	if (ret) {
3756 		RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3757 		return ret;
3758 	}
3759 	TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
3760 		"RSA: Failed to encrypt");
3761 	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
3762 		self->result_op->asym->rsa.cipher.data,
3763 		self->result_op->asym->rsa.cipher.length,
3764 		"operation verification failed\n");
3765 	return 0;
3766 }
3767 
3768 static int
3769 kat_rsa_decrypt(const void *data)
3770 {
3771 	uint8_t message[TEST_DATA_SIZE] = {0};
3772 	const struct rsa_test_data_2 *vector = data;
3773 	struct rte_crypto_asym_xform xform = { };
3774 
3775 	SET_RSA_PARAM(xform.rsa, vector, n);
3776 	SET_RSA_PARAM(xform.rsa, vector, e);
3777 	SET_RSA_PARAM(xform.rsa, vector, d);
3778 	xform.rsa.padding.type = vector->padding;
3779 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
3780 	int ret = rsa_init_session(&xform);
3781 
3782 	if (ret) {
3783 		RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3784 		return ret;
3785 	}
3786 	TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
3787 		"RSA: Failed to encrypt");
3788 	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
3789 		self->result_op->asym->rsa.message.data,
3790 		self->result_op->asym->rsa.message.length,
3791 		"operation verification failed\n");
3792 	return 0;
3793 }
3794 
3795 static int
3796 kat_rsa_decrypt_crt(const void *data)
3797 {
3798 	uint8_t message[TEST_DATA_SIZE] = {0};
3799 	const struct rsa_test_data_2 *vector = data;
3800 	struct rte_crypto_asym_xform xform = { };
3801 
3802 	SET_RSA_PARAM(xform.rsa, vector, n);
3803 	SET_RSA_PARAM(xform.rsa, vector, e);
3804 	SET_RSA_PARAM_QT(xform.rsa, vector, p);
3805 	SET_RSA_PARAM_QT(xform.rsa, vector, q);
3806 	SET_RSA_PARAM_QT(xform.rsa, vector, dP);
3807 	SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
3808 	SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
3809 	xform.rsa.padding.type = vector->padding;
3810 	xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
3811 	int ret = rsa_init_session(&xform);
3812 	if (ret) {
3813 		RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
3814 		return ret;
3815 	}
3816 	TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
3817 		"RSA: Failed to encrypt");
3818 	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
3819 		self->result_op->asym->rsa.message.data,
3820 		self->result_op->asym->rsa.message.length,
3821 		"operation verification failed\n");
3822 	return 0;
3823 }
3824 
3825 static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
3826 	.suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
3827 	.setup = testsuite_setup,
3828 	.teardown = testsuite_teardown,
3829 	.unit_test_cases = {
3830 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
3831 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
3832 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3833 				test_dh_key_generation),
3834 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
3835 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
3836 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc),
3837 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_dec),
3838 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
3839 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3840 				test_rsa_sign_verify),
3841 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3842 				test_rsa_enc_dec_crt),
3843 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3844 				test_rsa_sign_verify_crt),
3845 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
3846 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
3847 		TEST_CASE_NAMED_WITH_DATA(
3848 			"Modex test for zero padding",
3849 			ut_setup_asym, ut_teardown_asym,
3850 			modular_exponentiation, &modex_test_cases[0]),
3851 		TEST_CASE_NAMED_WITH_DATA(
3852 			"Modex test for zero padding (2)",
3853 			ut_setup_asym, ut_teardown_asym,
3854 			modular_exponentiation, &modex_test_cases[1]),
3855 		TEST_CASE_NAMED_WITH_DATA(
3856 			"Modex Group 5 test",
3857 			ut_setup_asym, ut_teardown_asym,
3858 			modular_exponentiation, &modex_group_test_cases[0]),
3859 		TEST_CASE_NAMED_WITH_DATA(
3860 			"Modex Group 14 test",
3861 			ut_setup_asym, ut_teardown_asym,
3862 			modular_exponentiation, &modex_group_test_cases[1]),
3863 		TEST_CASE_NAMED_WITH_DATA(
3864 			"Modex Group 15 test",
3865 			ut_setup_asym, ut_teardown_asym,
3866 			modular_exponentiation, &modex_group_test_cases[2]),
3867 		TEST_CASE_NAMED_WITH_DATA(
3868 			"Modex Group 16 test",
3869 			ut_setup_asym, ut_teardown_asym,
3870 			modular_exponentiation, &modex_group_test_cases[3]),
3871 		TEST_CASE_NAMED_WITH_DATA(
3872 			"Modex Group 17 test",
3873 			ut_setup_asym, ut_teardown_asym,
3874 			modular_exponentiation, &modex_group_test_cases[4]),
3875 		TEST_CASE_NAMED_WITH_DATA(
3876 			"Modex Group 18 test",
3877 			ut_setup_asym, ut_teardown_asym,
3878 			modular_exponentiation, &modex_group_test_cases[5]),
3879 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
3880 		TEST_CASES_END() /**< NULL terminate unit test array */
3881 	}
3882 };
3883 
3884 static struct unit_test_suite cryptodev_qat_asym_testsuite  = {
3885 	.suite_name = "Crypto Device QAT ASYM Unit Test Suite",
3886 	.setup = testsuite_setup,
3887 	.teardown = testsuite_teardown,
3888 	.unit_test_cases = {
3889 		TEST_CASE_NAMED_WITH_DATA(
3890 			"Modular Exponentiation (mod=128, base=20, exp=3, res=128)",
3891 			ut_setup_asym, ut_teardown_asym,
3892 			modular_exponentiation, &modex_test_case_m128_b20_e3),
3893 		/* Modular Multiplicative Inverse */
3894 		TEST_CASE_NAMED_WITH_DATA(
3895 			"Modular Inverse (mod=128, base=20, exp=3, inv=128)",
3896 			ut_setup_asym, ut_teardown_asym,
3897 			modular_multiplicative_inverse, &modinv_test_case),
3898 		/* RSA EXP */
3899 		TEST_CASE_NAMED_WITH_DATA(
3900 			"RSA Encryption (n=128, pt=20, e=3) EXP, Padding: NONE",
3901 			ut_setup_asym, ut_teardown_asym,
3902 			kat_rsa_encrypt, &rsa_vector_128_20_3_none),
3903 		TEST_CASE_NAMED_WITH_DATA(
3904 			"RSA Decryption (n=128, pt=20, e=3) EXP, Padding: NONE",
3905 			ut_setup_asym, ut_teardown_asym,
3906 			kat_rsa_decrypt, &rsa_vector_128_20_3_none),
3907 		/* RSA CRT */
3908 		TEST_CASE_NAMED_WITH_DATA(
3909 			"RSA Encryption (n=128, pt=20, e=3) CRT, Padding: NONE",
3910 			ut_setup_asym, ut_teardown_asym,
3911 			kat_rsa_encrypt_crt, &rsa_vector_128_20_3_none),
3912 		TEST_CASE_NAMED_WITH_DATA(
3913 			"RSA Decryption (n=128, pt=20, e=3) CRT, Padding: NONE",
3914 			ut_setup_asym, ut_teardown_asym,
3915 			kat_rsa_decrypt_crt, &rsa_vector_128_20_3_none),
3916 		TEST_CASES_END() /**< NULL terminate unit test array */
3917 	}
3918 };
3919 
3920 static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
3921 	.suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
3922 	.setup = testsuite_setup,
3923 	.teardown = testsuite_teardown,
3924 	.unit_test_cases = {
3925 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
3926 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3927 				test_rsa_enc_dec_crt),
3928 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3929 				test_rsa_sign_verify_crt),
3930 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
3931 		TEST_CASE_NAMED_WITH_DATA(
3932 			"Modex test for zero padding",
3933 			ut_setup_asym, ut_teardown_asym,
3934 			modular_exponentiation, &modex_test_cases[0]),
3935 		TEST_CASE_NAMED_WITH_DATA(
3936 			"Modex test for zero padding (2)",
3937 			ut_setup_asym, ut_teardown_asym,
3938 			modular_exponentiation, &modex_test_cases[1]),
3939 		TEST_CASE_NAMED_WITH_DATA(
3940 			"Modex Group 5 test",
3941 			ut_setup_asym, ut_teardown_asym,
3942 			modular_exponentiation, &modex_group_test_cases[0]),
3943 		TEST_CASE_NAMED_WITH_DATA(
3944 			"Modex Group 14 test",
3945 			ut_setup_asym, ut_teardown_asym,
3946 			modular_exponentiation, &modex_group_test_cases[1]),
3947 		TEST_CASE_NAMED_WITH_DATA(
3948 			"Modex Group 15 test",
3949 			ut_setup_asym, ut_teardown_asym,
3950 			modular_exponentiation, &modex_group_test_cases[2]),
3951 		TEST_CASE_NAMED_WITH_DATA(
3952 			"Modex Group 16 test",
3953 			ut_setup_asym, ut_teardown_asym,
3954 			modular_exponentiation, &modex_group_test_cases[3]),
3955 		TEST_CASE_NAMED_WITH_DATA(
3956 			"Modex Group 17 test",
3957 			ut_setup_asym, ut_teardown_asym,
3958 			modular_exponentiation, &modex_group_test_cases[4]),
3959 		TEST_CASE_NAMED_WITH_DATA(
3960 			"Modex Group 18 test",
3961 			ut_setup_asym, ut_teardown_asym,
3962 			modular_exponentiation, &modex_group_test_cases[5]),
3963 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3964 			     test_ecdsa_sign_verify_all_curve),
3965 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
3966 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
3967 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3968 				test_ecdh_all_curve),
3969 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
3970 				test_ecpm_all_curve),
3971 		TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
3972 		TEST_CASES_END() /**< NULL terminate unit test array */
3973 	}
3974 };
3975 
3976 static int
3977 test_cryptodev_openssl_asym(void)
3978 {
3979 	gbl_driver_id = rte_cryptodev_driver_id_get(
3980 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
3981 
3982 	if (gbl_driver_id == -1) {
3983 		RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
3984 		return TEST_SKIPPED;
3985 	}
3986 
3987 	return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
3988 }
3989 
3990 static int
3991 test_cryptodev_qat_asym(void)
3992 {
3993 	gbl_driver_id = rte_cryptodev_driver_id_get(
3994 			RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
3995 
3996 	if (gbl_driver_id == -1) {
3997 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
3998 		return TEST_SKIPPED;
3999 	}
4000 
4001 	return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
4002 }
4003 
4004 static int
4005 test_cryptodev_octeontx_asym(void)
4006 {
4007 	gbl_driver_id = rte_cryptodev_driver_id_get(
4008 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
4009 	if (gbl_driver_id == -1) {
4010 		RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
4011 		return TEST_SKIPPED;
4012 	}
4013 	return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
4014 }
4015 
4016 static int
4017 test_cryptodev_cn9k_asym(void)
4018 {
4019 	gbl_driver_id = rte_cryptodev_driver_id_get(
4020 			RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
4021 	if (gbl_driver_id == -1) {
4022 		RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
4023 		return TEST_SKIPPED;
4024 	}
4025 
4026 	/* Use test suite registered for crypto_octeontx PMD */
4027 	return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
4028 }
4029 
4030 static int
4031 test_cryptodev_cn10k_asym(void)
4032 {
4033 	gbl_driver_id = rte_cryptodev_driver_id_get(
4034 			RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
4035 	if (gbl_driver_id == -1) {
4036 		RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
4037 		return TEST_SKIPPED;
4038 	}
4039 
4040 	/* Use test suite registered for crypto_octeontx PMD */
4041 	return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
4042 }
4043 
4044 REGISTER_DRIVER_TEST(cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);
4045 REGISTER_DRIVER_TEST(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
4046 REGISTER_DRIVER_TEST(cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
4047 REGISTER_DRIVER_TEST(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
4048 REGISTER_DRIVER_TEST(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
4049