xref: /dpdk/app/test/test_cryptodev_asym.c (revision 742bde12)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Cavium Networks
3  */
4 
5 #include <rte_bus_vdev.h>
6 #include <rte_common.h>
7 #include <rte_hexdump.h>
8 #include <rte_mbuf.h>
9 #include <rte_malloc.h>
10 #include <rte_memcpy.h>
11 #include <rte_pause.h>
12 
13 #include <rte_cryptodev.h>
14 #include <rte_cryptodev_pmd.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_mod_test_vectors.h"
21 #include "test_cryptodev_rsa_test_vectors.h"
22 #include "test_cryptodev_asym_util.h"
23 #include "test.h"
24 
25 #define TEST_NUM_BUFS 10
26 #define TEST_NUM_SESSIONS 4
27 
28 static int gbl_driver_id;
29 struct crypto_testsuite_params {
30 	struct rte_mempool *op_mpool;
31 	struct rte_mempool *session_mpool;
32 	struct rte_cryptodev_config conf;
33 	struct rte_cryptodev_qp_conf qp_conf;
34 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
35 	uint8_t valid_dev_count;
36 };
37 
38 struct crypto_unittest_params {
39 	struct rte_cryptodev_asym_session *sess;
40 	struct rte_crypto_op *op;
41 };
42 
43 static struct crypto_testsuite_params testsuite_params = { NULL };
44 
45 static int
46 test_rsa_sign_verify(void)
47 {
48 	struct crypto_testsuite_params *ts_params = &testsuite_params;
49 	struct rte_mempool *op_mpool = ts_params->op_mpool;
50 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
51 	uint8_t dev_id = ts_params->valid_devs[0];
52 	struct rte_crypto_asym_op *asym_op = NULL;
53 	struct rte_crypto_op *op = NULL, *result_op = NULL;
54 	struct rte_cryptodev_asym_session *sess = NULL;
55 	int status = TEST_SUCCESS;
56 	uint8_t output_buf[TEST_DATA_SIZE] = {0};
57 	uint8_t input_buf[TEST_DATA_SIZE] = {0};
58 
59 	sess = rte_cryptodev_asym_session_create(sess_mpool);
60 
61 	if (!sess) {
62 		RTE_LOG(ERR, USER1, "line %u "
63 				"FAILED: %s", __LINE__,
64 				"Session creation failed");
65 		status = TEST_FAILED;
66 		goto error_exit;
67 	}
68 
69 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
70 				sess_mpool) < 0) {
71 		RTE_LOG(ERR, USER1,
72 				"line %u FAILED: %s",
73 				__LINE__, "unabled to config sym session");
74 		status = TEST_FAILED;
75 		goto error_exit;
76 	}
77 
78 	/* set up crypto op data structure */
79 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
80 	if (!op) {
81 		RTE_LOG(ERR, USER1,
82 				"line %u FAILED: %s",
83 				__LINE__,
84 				"Failed to allocate asymmetric crypto "
85 				"operation struct");
86 		status = TEST_FAILED;
87 		goto error_exit;
88 	}
89 
90 	asym_op = op->asym;
91 	/* Compute sign on the test vector */
92 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
93 
94 	memcpy(input_buf, &rsaplaintext.data,
95 			rsaplaintext.len);
96 	asym_op->rsa.message.data = input_buf;
97 	asym_op->rsa.message.length = rsaplaintext.len;
98 	asym_op->rsa.sign.data = output_buf;
99 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
100 
101 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
102 			asym_op->rsa.message.length);
103 
104 	/* attach asymmetric crypto session to crypto operations */
105 	rte_crypto_op_attach_asym_session(op, sess);
106 
107 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
108 
109 	/* Process crypto operation */
110 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
111 		RTE_LOG(ERR, USER1,
112 				"line %u FAILED: %s",
113 				__LINE__, "Error sending packet for operation");
114 		status = TEST_FAILED;
115 		goto error_exit;
116 	}
117 
118 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
119 		rte_pause();
120 
121 	if (result_op == NULL) {
122 		RTE_LOG(ERR, USER1,
123 				"line %u FAILED: %s",
124 				__LINE__, "Failed to process asym crypto op");
125 		status = TEST_FAILED;
126 		goto error_exit;
127 	}
128 	debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
129 			asym_op->rsa.sign.length);
130 	asym_op = result_op->asym;
131 
132 	/* Verify sign */
133 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
134 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
135 
136 	/* Process crypto operation */
137 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
138 		RTE_LOG(ERR, USER1,
139 				"line %u FAILED: %s",
140 				__LINE__, "Error sending packet for operation");
141 		status = TEST_FAILED;
142 		goto error_exit;
143 	}
144 
145 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
146 		rte_pause();
147 
148 	if (result_op == NULL) {
149 		RTE_LOG(ERR, USER1,
150 				"line %u FAILED: %s",
151 				__LINE__, "Failed to process asym crypto op");
152 		status = TEST_FAILED;
153 		goto error_exit;
154 	}
155 	status = TEST_SUCCESS;
156 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
157 		RTE_LOG(ERR, USER1,
158 				"line %u FAILED: %s",
159 				__LINE__, "Failed to process asym crypto op");
160 		status = TEST_FAILED;
161 		goto error_exit;
162 	}
163 
164 error_exit:
165 
166 	if (sess) {
167 		rte_cryptodev_asym_session_clear(dev_id, sess);
168 		rte_cryptodev_asym_session_free(sess);
169 	}
170 
171 	if (op)
172 		rte_crypto_op_free(op);
173 
174 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
175 
176 	return status;
177 }
178 
179 static int
180 test_rsa_enc_dec(void)
181 {
182 	struct crypto_testsuite_params *ts_params = &testsuite_params;
183 	struct rte_mempool *op_mpool = ts_params->op_mpool;
184 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
185 	uint8_t dev_id = ts_params->valid_devs[0];
186 	struct rte_crypto_asym_op *asym_op = NULL;
187 	struct rte_crypto_op *op = NULL, *result_op = NULL;
188 	struct rte_cryptodev_asym_session *sess = NULL;
189 	int status = TEST_SUCCESS;
190 	uint8_t input_buf[TEST_DATA_SIZE] = {0};
191 
192 	sess = rte_cryptodev_asym_session_create(sess_mpool);
193 
194 	if (!sess) {
195 		RTE_LOG(ERR, USER1, "line %u "
196 				"FAILED: %s", __LINE__,
197 				"Session creation failed");
198 		status = TEST_FAILED;
199 		goto error_exit;
200 	}
201 
202 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
203 				sess_mpool) < 0) {
204 		RTE_LOG(ERR, USER1,
205 				"line %u FAILED: %s",
206 				__LINE__, "unabled to config sym session");
207 		status = TEST_FAILED;
208 		goto error_exit;
209 	}
210 
211 	/* set up crypto op data structure */
212 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
213 	if (!op) {
214 		RTE_LOG(ERR, USER1,
215 				"line %u FAILED: %s",
216 				__LINE__,
217 				"Failed to allocate asymmetric crypto "
218 				"operation struct");
219 		status = TEST_FAILED;
220 		goto error_exit;
221 	}
222 
223 	asym_op = op->asym;
224 	/*Compute encryption on the test vector */
225 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
226 
227 	memcpy(input_buf, rsaplaintext.data,
228 			rsaplaintext.len);
229 	asym_op->rsa.message.data = input_buf;
230 	asym_op->rsa.message.length = rsaplaintext.len;
231 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT2;
232 
233 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
234 			asym_op->rsa.message.length);
235 
236 	/* attach asymmetric crypto session to crypto operations */
237 	rte_crypto_op_attach_asym_session(op, sess);
238 
239 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
240 
241 	/* Process crypto operation */
242 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
243 		RTE_LOG(ERR, USER1,
244 				"line %u FAILED: %s",
245 				__LINE__, "Error sending packet for operation");
246 		status = TEST_FAILED;
247 		goto error_exit;
248 	}
249 
250 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
251 		rte_pause();
252 
253 	if (result_op == NULL) {
254 		RTE_LOG(ERR, USER1,
255 				"line %u FAILED: %s",
256 				__LINE__, "Failed to process asym crypto op");
257 		status = TEST_FAILED;
258 		goto error_exit;
259 	}
260 	debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
261 			asym_op->rsa.message.length);
262 	/* Use the resulted output as decryption Input vector*/
263 	asym_op = result_op->asym;
264 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
265 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PKCS1_V1_5_BT1;
266 
267 	/* Process crypto operation */
268 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
269 		RTE_LOG(ERR, USER1,
270 				"line %u FAILED: %s",
271 				__LINE__, "Error sending packet for operation");
272 		status = TEST_FAILED;
273 		goto error_exit;
274 	}
275 
276 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
277 		rte_pause();
278 
279 	if (result_op == NULL) {
280 		RTE_LOG(ERR, USER1,
281 				"line %u FAILED: %s",
282 				__LINE__, "Failed to process asym crypto op");
283 		status = TEST_FAILED;
284 		goto error_exit;
285 	}
286 	status = TEST_SUCCESS;
287 	int ret = 0;
288 	ret = rsa_verify(&rsaplaintext, result_op);
289 	if (ret)
290 		status = TEST_FAILED;
291 
292 error_exit:
293 
294 	if (sess) {
295 		rte_cryptodev_asym_session_clear(dev_id, sess);
296 		rte_cryptodev_asym_session_free(sess);
297 	}
298 
299 	if (op)
300 		rte_crypto_op_free(op);
301 
302 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
303 
304 	return status;
305 }
306 
307 static int
308 testsuite_setup(void)
309 {
310 	struct crypto_testsuite_params *ts_params = &testsuite_params;
311 	struct rte_cryptodev_info info;
312 	uint32_t i = 0, nb_devs, dev_id;
313 	int ret;
314 	uint16_t qp_id;
315 
316 	memset(ts_params, 0, sizeof(*ts_params));
317 
318 	ts_params->op_mpool = rte_crypto_op_pool_create(
319 			"CRYPTO_ASYM_OP_POOL",
320 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
321 			TEST_NUM_BUFS, 0,
322 			0,
323 			rte_socket_id());
324 	if (ts_params->op_mpool == NULL) {
325 		RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
326 		return TEST_FAILED;
327 	}
328 
329 	/* Create an OPENSSL device if required */
330 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
331 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
332 		nb_devs = rte_cryptodev_device_count_by_driver(
333 				rte_cryptodev_driver_id_get(
334 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
335 		if (nb_devs < 1) {
336 			ret = rte_vdev_init(
337 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
338 				NULL);
339 
340 			TEST_ASSERT(ret == 0, "Failed to create "
341 				"instance of pmd : %s",
342 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
343 		}
344 	}
345 
346 	nb_devs = rte_cryptodev_count();
347 	if (nb_devs < 1) {
348 		RTE_LOG(ERR, USER1, "No crypto devices found?\n");
349 		return TEST_FAILED;
350 	}
351 
352 	/* Create list of valid crypto devs */
353 	for (i = 0; i < nb_devs; i++) {
354 		rte_cryptodev_info_get(i, &info);
355 		if (info.driver_id == gbl_driver_id)
356 			ts_params->valid_devs[ts_params->valid_dev_count++] = i;
357 	}
358 
359 	if (ts_params->valid_dev_count < 1)
360 		return TEST_FAILED;
361 
362 	/* Set up all the qps on the first of the valid devices found */
363 
364 	dev_id = ts_params->valid_devs[0];
365 
366 	rte_cryptodev_info_get(dev_id, &info);
367 
368 	/* check if device support asymmetric, skip if not */
369 	if (!(info.feature_flags &
370 				RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
371 		RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
372 				"Test Skipped.\n");
373 		return TEST_FAILED;
374 	}
375 
376 	/* configure device with num qp */
377 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
378 	ts_params->conf.socket_id = SOCKET_ID_ANY;
379 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
380 			&ts_params->conf),
381 			"Failed to configure cryptodev %u with %u qps",
382 			dev_id, ts_params->conf.nb_queue_pairs);
383 
384 	/* configure qp */
385 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
386 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
387 	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
388 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
389 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
390 			dev_id, qp_id, &ts_params->qp_conf,
391 			rte_cryptodev_socket_id(dev_id)),
392 			"Failed to setup queue pair %u on cryptodev %u ASYM",
393 			qp_id, dev_id);
394 	}
395 
396 	/* setup asym session pool */
397 	unsigned int session_size =
398 		rte_cryptodev_asym_get_private_session_size(dev_id);
399 	/*
400 	 * Create mempool with TEST_NUM_SESSIONS * 2,
401 	 * to include the session headers
402 	 */
403 	ts_params->session_mpool = rte_mempool_create(
404 				"test_asym_sess_mp",
405 				TEST_NUM_SESSIONS * 2,
406 				session_size,
407 				0, 0, NULL, NULL, NULL,
408 				NULL, SOCKET_ID_ANY,
409 				0);
410 
411 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
412 			"session mempool allocation failed");
413 
414 	return TEST_SUCCESS;
415 }
416 
417 static void
418 testsuite_teardown(void)
419 {
420 	struct crypto_testsuite_params *ts_params = &testsuite_params;
421 
422 	if (ts_params->op_mpool != NULL) {
423 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
424 		rte_mempool_avail_count(ts_params->op_mpool));
425 	}
426 
427 	/* Free session mempools */
428 	if (ts_params->session_mpool != NULL) {
429 		rte_mempool_free(ts_params->session_mpool);
430 		ts_params->session_mpool = NULL;
431 	}
432 }
433 
434 static int
435 ut_setup(void)
436 {
437 	struct crypto_testsuite_params *ts_params = &testsuite_params;
438 
439 	uint16_t qp_id;
440 
441 	/* Reconfigure device to default parameters */
442 	ts_params->conf.socket_id = SOCKET_ID_ANY;
443 
444 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
445 			&ts_params->conf),
446 			"Failed to configure cryptodev %u",
447 			ts_params->valid_devs[0]);
448 
449 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
450 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
451 			ts_params->valid_devs[0], qp_id,
452 			&ts_params->qp_conf,
453 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
454 			"Failed to setup queue pair %u on cryptodev %u",
455 			qp_id, ts_params->valid_devs[0]);
456 	}
457 
458 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
459 
460 	/* Start the device */
461 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
462 						"Failed to start cryptodev %u",
463 						ts_params->valid_devs[0]);
464 
465 	return TEST_SUCCESS;
466 }
467 
468 static void
469 ut_teardown(void)
470 {
471 	struct crypto_testsuite_params *ts_params = &testsuite_params;
472 	struct rte_cryptodev_stats stats;
473 
474 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
475 
476 	/* Stop the device */
477 	rte_cryptodev_stop(ts_params->valid_devs[0]);
478 }
479 
480 static inline void print_asym_capa(
481 		const struct rte_cryptodev_asymmetric_xform_capability *capa)
482 {
483 	int i = 0;
484 
485 	printf("\nxform type: %s\n===================\n",
486 			rte_crypto_asym_xform_strings[capa->xform_type]);
487 	printf("operation supported -");
488 
489 	for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
490 		/* check supported operations */
491 		if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
492 			printf(" %s",
493 					rte_crypto_asym_op_strings[i]);
494 		}
495 		switch (capa->xform_type) {
496 		case RTE_CRYPTO_ASYM_XFORM_RSA:
497 		case RTE_CRYPTO_ASYM_XFORM_MODINV:
498 		case RTE_CRYPTO_ASYM_XFORM_MODEX:
499 		case RTE_CRYPTO_ASYM_XFORM_DH:
500 		case RTE_CRYPTO_ASYM_XFORM_DSA:
501 			printf(" modlen: min %d max %d increment %d\n",
502 					capa->modlen.min,
503 					capa->modlen.max,
504 					capa->modlen.increment);
505 		break;
506 		default:
507 			break;
508 		}
509 }
510 
511 static int
512 test_capability(void)
513 {
514 	struct crypto_testsuite_params *ts_params = &testsuite_params;
515 	uint8_t dev_id = ts_params->valid_devs[0];
516 	struct rte_cryptodev_info dev_info;
517 	const struct rte_cryptodev_capabilities *dev_capa;
518 	int i = 0;
519 	struct rte_cryptodev_asym_capability_idx idx;
520 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
521 
522 	rte_cryptodev_info_get(dev_id, &dev_info);
523 	if (!(dev_info.feature_flags &
524 				RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
525 		RTE_LOG(INFO, USER1,
526 				"Device doesn't support asymmetric. Test Skipped\n");
527 		return TEST_SUCCESS;
528 	}
529 
530 	/* print xform capability */
531 	for (i = 0;
532 		dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
533 		i++) {
534 		dev_capa = &(dev_info.capabilities[i]);
535 		if (dev_info.capabilities[i].op ==
536 				RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
537 			idx.type = dev_capa->asym.xform_capa.xform_type;
538 
539 			capa = rte_cryptodev_asym_capability_get(dev_id,
540 				(const struct
541 				rte_cryptodev_asym_capability_idx *) &idx);
542 			print_asym_capa(capa);
543 			}
544 	}
545 	return TEST_SUCCESS;
546 }
547 
548 static int
549 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
550 {
551 	struct crypto_testsuite_params *ts_params = &testsuite_params;
552 	struct rte_mempool *op_mpool = ts_params->op_mpool;
553 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
554 	uint8_t dev_id = ts_params->valid_devs[0];
555 	struct rte_crypto_asym_op *asym_op = NULL;
556 	struct rte_crypto_op *op = NULL, *result_op = NULL;
557 	struct rte_cryptodev_asym_session *sess = NULL;
558 	int status = TEST_SUCCESS;
559 	uint8_t output[TEST_DH_MOD_LEN];
560 	struct rte_crypto_asym_xform xform = *xfrm;
561 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
562 
563 	sess = rte_cryptodev_asym_session_create(sess_mpool);
564 	if (sess == NULL) {
565 		RTE_LOG(ERR, USER1,
566 				"line %u FAILED: %s", __LINE__,
567 				"Session creation failed");
568 		status = TEST_FAILED;
569 		goto error_exit;
570 	}
571 	/* set up crypto op data structure */
572 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
573 	if (!op) {
574 		RTE_LOG(ERR, USER1,
575 			"line %u FAILED: %s",
576 			__LINE__, "Failed to allocate asymmetric crypto "
577 			"operation struct");
578 		status = TEST_FAILED;
579 		goto error_exit;
580 	}
581 	asym_op = op->asym;
582 
583 	/* Setup a xform and op to generate private key only */
584 	xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
585 	xform.next = NULL;
586 	asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
587 	asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
588 	asym_op->dh.pub_key.data = (uint8_t *)peer;
589 	asym_op->dh.pub_key.length = sizeof(peer);
590 	asym_op->dh.shared_secret.data = output;
591 	asym_op->dh.shared_secret.length = sizeof(output);
592 
593 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
594 			sess_mpool) < 0) {
595 		RTE_LOG(ERR, USER1,
596 				"line %u FAILED: %s",
597 				__LINE__, "unabled to config sym session");
598 		status = TEST_FAILED;
599 		goto error_exit;
600 	}
601 
602 	/* attach asymmetric crypto session to crypto operations */
603 	rte_crypto_op_attach_asym_session(op, sess);
604 
605 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
606 
607 	/* Process crypto operation */
608 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
609 		RTE_LOG(ERR, USER1,
610 			"line %u FAILED: %s",
611 			__LINE__, "Error sending packet for operation");
612 		status = TEST_FAILED;
613 		goto error_exit;
614 	}
615 
616 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
617 		rte_pause();
618 
619 	if (result_op == NULL) {
620 		RTE_LOG(ERR, USER1,
621 			"line %u FAILED: %s",
622 			__LINE__, "Failed to process asym crypto op");
623 		status = TEST_FAILED;
624 		goto error_exit;
625 	}
626 
627 	debug_hexdump(stdout, "shared secret:",
628 			asym_op->dh.shared_secret.data,
629 			asym_op->dh.shared_secret.length);
630 
631 error_exit:
632 	if (sess != NULL) {
633 		rte_cryptodev_asym_session_clear(dev_id, sess);
634 		rte_cryptodev_asym_session_free(sess);
635 	}
636 	if (op != NULL)
637 		rte_crypto_op_free(op);
638 	return status;
639 }
640 
641 static int
642 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
643 {
644 	struct crypto_testsuite_params *ts_params = &testsuite_params;
645 	struct rte_mempool *op_mpool = ts_params->op_mpool;
646 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
647 	uint8_t dev_id = ts_params->valid_devs[0];
648 	struct rte_crypto_asym_op *asym_op = NULL;
649 	struct rte_crypto_op *op = NULL, *result_op = NULL;
650 	struct rte_cryptodev_asym_session *sess = NULL;
651 	int status = TEST_SUCCESS;
652 	uint8_t output[TEST_DH_MOD_LEN];
653 	struct rte_crypto_asym_xform xform = *xfrm;
654 
655 	sess = rte_cryptodev_asym_session_create(sess_mpool);
656 	if (sess == NULL) {
657 		RTE_LOG(ERR, USER1,
658 				 "line %u FAILED: %s", __LINE__,
659 				"Session creation failed");
660 		status = TEST_FAILED;
661 		goto error_exit;
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.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
677 	xform.next = NULL;
678 	asym_op->dh.priv_key.data = output;
679 	asym_op->dh.priv_key.length = sizeof(output);
680 
681 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
682 			sess_mpool) < 0) {
683 		RTE_LOG(ERR, USER1,
684 				"line %u FAILED: %s",
685 				__LINE__, "unabled to config sym session");
686 		status = TEST_FAILED;
687 		goto error_exit;
688 	}
689 
690 	/* attach asymmetric crypto session to crypto operations */
691 	rte_crypto_op_attach_asym_session(op, sess);
692 
693 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
694 
695 	/* Process crypto operation */
696 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
697 		RTE_LOG(ERR, USER1,
698 			"line %u FAILED: %s",
699 			__LINE__, "Error sending packet for operation");
700 		status = TEST_FAILED;
701 		goto error_exit;
702 	}
703 
704 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
705 		rte_pause();
706 
707 	if (result_op == NULL) {
708 		RTE_LOG(ERR, USER1,
709 			"line %u FAILED: %s",
710 			__LINE__, "Failed to process asym crypto op");
711 		status = TEST_FAILED;
712 		goto error_exit;
713 	}
714 
715 	debug_hexdump(stdout, "private key:",
716 			asym_op->dh.priv_key.data,
717 			asym_op->dh.priv_key.length);
718 
719 
720 error_exit:
721 	if (sess != NULL) {
722 		rte_cryptodev_asym_session_clear(dev_id, sess);
723 		rte_cryptodev_asym_session_free(sess);
724 	}
725 	if (op != NULL)
726 		rte_crypto_op_free(op);
727 
728 	return status;
729 }
730 
731 
732 static int
733 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
734 {
735 	struct crypto_testsuite_params *ts_params = &testsuite_params;
736 	struct rte_mempool *op_mpool = ts_params->op_mpool;
737 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
738 	uint8_t dev_id = ts_params->valid_devs[0];
739 	struct rte_crypto_asym_op *asym_op = NULL;
740 	struct rte_crypto_op *op = NULL, *result_op = NULL;
741 	struct rte_cryptodev_asym_session *sess = NULL;
742 	int status = TEST_SUCCESS;
743 	uint8_t output[TEST_DH_MOD_LEN];
744 	struct rte_crypto_asym_xform xform = *xfrm;
745 
746 	sess = rte_cryptodev_asym_session_create(sess_mpool);
747 	if (sess == NULL) {
748 		RTE_LOG(ERR, USER1,
749 				 "line %u FAILED: %s", __LINE__,
750 				"Session creation failed");
751 		status = TEST_FAILED;
752 		goto error_exit;
753 	}
754 	/* set up crypto op data structure */
755 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
756 	if (!op) {
757 		RTE_LOG(ERR, USER1,
758 			"line %u FAILED: %s",
759 			__LINE__, "Failed to allocate asymmetric crypto "
760 			"operation struct");
761 		status = TEST_FAILED;
762 		goto error_exit;
763 	}
764 	asym_op = op->asym;
765 	/* Setup a xform chain to generate public key
766 	 * using test private key
767 	 *
768 	 */
769 	xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
770 	xform.next = NULL;
771 
772 	asym_op->dh.pub_key.data = output;
773 	asym_op->dh.pub_key.length = sizeof(output);
774 	/* load pre-defined private key */
775 	asym_op->dh.priv_key.data = rte_malloc(NULL,
776 					dh_test_params.priv_key.length,
777 					0);
778 	asym_op->dh.priv_key = dh_test_params.priv_key;
779 
780 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
781 			sess_mpool) < 0) {
782 		RTE_LOG(ERR, USER1,
783 				"line %u FAILED: %s",
784 				__LINE__, "unabled to config sym session");
785 		status = TEST_FAILED;
786 		goto error_exit;
787 	}
788 
789 	/* attach asymmetric crypto session to crypto operations */
790 	rte_crypto_op_attach_asym_session(op, sess);
791 
792 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
793 
794 	/* Process crypto operation */
795 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
796 		RTE_LOG(ERR, USER1,
797 			"line %u FAILED: %s",
798 			__LINE__, "Error sending packet for operation");
799 		status = TEST_FAILED;
800 		goto error_exit;
801 	}
802 
803 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
804 		rte_pause();
805 
806 	if (result_op == NULL) {
807 		RTE_LOG(ERR, USER1,
808 			"line %u FAILED: %s",
809 			__LINE__, "Failed to process asym crypto op");
810 		status = TEST_FAILED;
811 		goto error_exit;
812 	}
813 
814 	debug_hexdump(stdout, "pub key:",
815 			asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
816 
817 	debug_hexdump(stdout, "priv key:",
818 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
819 
820 error_exit:
821 	if (sess != NULL) {
822 		rte_cryptodev_asym_session_clear(dev_id, sess);
823 		rte_cryptodev_asym_session_free(sess);
824 	}
825 	if (op != NULL)
826 		rte_crypto_op_free(op);
827 
828 	return status;
829 }
830 
831 static int
832 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
833 {
834 	struct crypto_testsuite_params *ts_params = &testsuite_params;
835 	struct rte_mempool *op_mpool = ts_params->op_mpool;
836 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
837 	uint8_t dev_id = ts_params->valid_devs[0];
838 	struct rte_crypto_asym_op *asym_op = NULL;
839 	struct rte_crypto_op *op = NULL, *result_op = NULL;
840 	struct rte_cryptodev_asym_session *sess = NULL;
841 	int status = TEST_SUCCESS;
842 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
843 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
844 	struct rte_crypto_asym_xform pub_key_xform;
845 	struct rte_crypto_asym_xform xform = *xfrm;
846 
847 	sess = rte_cryptodev_asym_session_create(sess_mpool);
848 	if (sess == NULL) {
849 		RTE_LOG(ERR, USER1,
850 				 "line %u FAILED: %s", __LINE__,
851 				"Session creation failed");
852 		status = TEST_FAILED;
853 		goto error_exit;
854 	}
855 
856 	/* set up crypto op data structure */
857 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
858 	if (!op) {
859 		RTE_LOG(ERR, USER1,
860 			"line %u FAILED: %s",
861 			__LINE__, "Failed to allocate asymmetric crypto "
862 			"operation struct");
863 		status = TEST_FAILED;
864 		goto error_exit;
865 	}
866 	asym_op = op->asym;
867 	/* Setup a xform chain to generate
868 	 * private key first followed by
869 	 * public key
870 	 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
871 	pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
872 	pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
873 	xform.next = &pub_key_xform;
874 
875 	asym_op->dh.pub_key.data = out_pub_key;
876 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
877 	asym_op->dh.priv_key.data = out_prv_key;
878 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
879 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
880 			sess_mpool) < 0) {
881 		RTE_LOG(ERR, USER1,
882 				"line %u FAILED: %s",
883 				__LINE__, "unabled to config sym session");
884 		status = TEST_FAILED;
885 		goto error_exit;
886 	}
887 
888 	/* attach asymmetric crypto session to crypto operations */
889 	rte_crypto_op_attach_asym_session(op, sess);
890 
891 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
892 
893 	/* Process crypto operation */
894 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
895 		RTE_LOG(ERR, USER1,
896 			"line %u FAILED: %s",
897 			__LINE__, "Error sending packet for operation");
898 		status = TEST_FAILED;
899 		goto error_exit;
900 	}
901 
902 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
903 		rte_pause();
904 
905 	if (result_op == NULL) {
906 		RTE_LOG(ERR, USER1,
907 			"line %u FAILED: %s",
908 			__LINE__, "Failed to process asym crypto op");
909 		status = TEST_FAILED;
910 		goto error_exit;
911 	}
912 	debug_hexdump(stdout, "priv key:",
913 			out_prv_key, asym_op->dh.priv_key.length);
914 	debug_hexdump(stdout, "pub key:",
915 			out_pub_key, asym_op->dh.pub_key.length);
916 
917 error_exit:
918 	if (sess != NULL) {
919 		rte_cryptodev_asym_session_clear(dev_id, sess);
920 		rte_cryptodev_asym_session_free(sess);
921 	}
922 	if (op != NULL)
923 		rte_crypto_op_free(op);
924 
925 	return status;
926 }
927 
928 static int
929 test_mod_inv(void)
930 {
931 	struct crypto_testsuite_params *ts_params = &testsuite_params;
932 	struct rte_mempool *op_mpool = ts_params->op_mpool;
933 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
934 	uint8_t dev_id = ts_params->valid_devs[0];
935 	struct rte_crypto_asym_op *asym_op = NULL;
936 	struct rte_crypto_op *op = NULL, *result_op = NULL;
937 	struct rte_cryptodev_asym_session *sess = NULL;
938 	int status = TEST_SUCCESS;
939 	struct rte_cryptodev_asym_capability_idx cap_idx;
940 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
941 	uint8_t input[TEST_DATA_SIZE] = {0};
942 	int ret = 0;
943 
944 	if (rte_cryptodev_asym_get_xform_enum(
945 		&modinv_xform.xform_type, "modinv") < 0) {
946 		RTE_LOG(ERR, USER1,
947 				 "Invalid ASYNC algorithm specified\n");
948 		return -1;
949 	}
950 
951 	cap_idx.type = modinv_xform.xform_type;
952 	capability = rte_cryptodev_asym_capability_get(dev_id,
953 					&cap_idx);
954 
955 	if (rte_cryptodev_asym_xform_capability_check_modlen(
956 		capability,
957 		modinv_xform.modinv.modulus.length)) {
958 		RTE_LOG(ERR, USER1,
959 				 "Invalid MODULOUS length specified\n");
960 				return -1;
961 		}
962 
963 	sess = rte_cryptodev_asym_session_create(sess_mpool);
964 	if (!sess) {
965 		RTE_LOG(ERR, USER1, "line %u "
966 				"FAILED: %s", __LINE__,
967 				"Session creation failed");
968 		status = TEST_FAILED;
969 		goto error_exit;
970 	}
971 
972 	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
973 			sess_mpool) < 0) {
974 		RTE_LOG(ERR, USER1,
975 				"line %u FAILED: %s",
976 				__LINE__, "unabled to config sym session");
977 		status = TEST_FAILED;
978 		goto error_exit;
979 	}
980 
981 	/* generate crypto op data structure */
982 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
983 	if (!op) {
984 		RTE_LOG(ERR, USER1,
985 			"line %u FAILED: %s",
986 			__LINE__, "Failed to allocate asymmetric crypto "
987 			"operation struct");
988 		status = TEST_FAILED;
989 		goto error_exit;
990 	}
991 
992 	asym_op = op->asym;
993 	memcpy(input, base, sizeof(base));
994 	asym_op->modinv.base.data = input;
995 	asym_op->modinv.base.length = sizeof(base);
996 
997 	/* attach asymmetric crypto session to crypto operations */
998 	rte_crypto_op_attach_asym_session(op, sess);
999 
1000 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1001 
1002 	/* Process crypto operation */
1003 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1004 		RTE_LOG(ERR, USER1,
1005 			"line %u FAILED: %s",
1006 			__LINE__, "Error sending packet for operation");
1007 		status = TEST_FAILED;
1008 		goto error_exit;
1009 	}
1010 
1011 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1012 		rte_pause();
1013 
1014 	if (result_op == NULL) {
1015 		RTE_LOG(ERR, USER1,
1016 				"line %u FAILED: %s",
1017 				__LINE__, "Failed to process asym crypto op");
1018 		status = TEST_FAILED;
1019 		goto error_exit;
1020 	}
1021 
1022 	ret = verify_modinv(mod_inv, result_op);
1023 	if (ret) {
1024 		RTE_LOG(ERR, USER1,
1025 			 "operation verification failed\n");
1026 		status = TEST_FAILED;
1027 	}
1028 
1029 error_exit:
1030 	if (sess) {
1031 		rte_cryptodev_asym_session_clear(dev_id, sess);
1032 		rte_cryptodev_asym_session_free(sess);
1033 	}
1034 
1035 	if (op)
1036 		rte_crypto_op_free(op);
1037 
1038 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1039 
1040 	return status;
1041 }
1042 
1043 static int
1044 test_mod_exp(void)
1045 {
1046 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1047 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1048 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1049 	uint8_t dev_id = ts_params->valid_devs[0];
1050 	struct rte_crypto_asym_op *asym_op = NULL;
1051 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1052 	struct rte_cryptodev_asym_session *sess = NULL;
1053 	int status = TEST_SUCCESS;
1054 	struct rte_cryptodev_asym_capability_idx cap_idx;
1055 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
1056 	uint8_t input[TEST_DATA_SIZE] = {0};
1057 	int ret = 0;
1058 
1059 	if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1060 		"modexp")
1061 		< 0) {
1062 		RTE_LOG(ERR, USER1,
1063 				"Invalid ASYNC algorithm specified\n");
1064 		return -1;
1065 	}
1066 
1067 	/* check for modlen capability */
1068 	cap_idx.type = modex_xform.xform_type;
1069 	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1070 
1071 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1072 			capability, modex_xform.modex.modulus.length)) {
1073 		RTE_LOG(ERR, USER1,
1074 				"Invalid MODULOUS length specified\n");
1075 				return -1;
1076 		}
1077 
1078 	/* generate crypto op data structure */
1079 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1080 	if (!op) {
1081 		RTE_LOG(ERR, USER1,
1082 			"line %u FAILED: %s",
1083 			__LINE__, "Failed to allocate asymmetric crypto "
1084 			"operation struct");
1085 		status = TEST_FAILED;
1086 		goto error_exit;
1087 	}
1088 
1089 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1090 	if (!sess) {
1091 		RTE_LOG(ERR, USER1,
1092 				 "line %u "
1093 				"FAILED: %s", __LINE__,
1094 				"Session creation failed");
1095 		status = TEST_FAILED;
1096 		goto error_exit;
1097 	}
1098 
1099 	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1100 			sess_mpool) < 0) {
1101 		RTE_LOG(ERR, USER1,
1102 				"line %u FAILED: %s",
1103 				__LINE__, "unabled to config sym session");
1104 		status = TEST_FAILED;
1105 		goto error_exit;
1106 	}
1107 
1108 	asym_op = op->asym;
1109 	memcpy(input, base, sizeof(base));
1110 	asym_op->modex.base.data = input;
1111 	asym_op->modex.base.length = sizeof(base);
1112 	/* attach asymmetric crypto session to crypto operations */
1113 	rte_crypto_op_attach_asym_session(op, sess);
1114 
1115 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1116 	/* Process crypto operation */
1117 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1118 		RTE_LOG(ERR, USER1,
1119 				"line %u FAILED: %s",
1120 				__LINE__, "Error sending packet for operation");
1121 		status = TEST_FAILED;
1122 		goto error_exit;
1123 	}
1124 
1125 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1126 		rte_pause();
1127 
1128 	if (result_op == NULL) {
1129 		RTE_LOG(ERR, USER1,
1130 				"line %u FAILED: %s",
1131 				__LINE__, "Failed to process asym crypto op");
1132 		status = TEST_FAILED;
1133 		goto error_exit;
1134 	}
1135 
1136 	ret = verify_modexp(mod_exp, result_op);
1137 	if (ret) {
1138 		RTE_LOG(ERR, USER1,
1139 			 "operation verification failed\n");
1140 		status = TEST_FAILED;
1141 	}
1142 
1143 error_exit:
1144 	if (sess != NULL) {
1145 		rte_cryptodev_asym_session_clear(dev_id, sess);
1146 		rte_cryptodev_asym_session_free(sess);
1147 	}
1148 
1149 	if (op != NULL)
1150 		rte_crypto_op_free(op);
1151 
1152 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1153 
1154 	return status;
1155 }
1156 
1157 static int
1158 test_dh_keygenration(void)
1159 {
1160 	int status;
1161 
1162 	debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1163 	debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1164 	debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1165 			dh_test_params.priv_key.length);
1166 
1167 	RTE_LOG(INFO, USER1,
1168 		"Test Public and Private key pair generation\n");
1169 
1170 	status = test_dh_gen_kp(&dh_xform);
1171 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1172 
1173 	RTE_LOG(INFO, USER1,
1174 		"Test Public Key Generation using pre-defined priv key\n");
1175 
1176 	status = test_dh_gen_pub_key(&dh_xform);
1177 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1178 
1179 	RTE_LOG(INFO, USER1,
1180 		"Test Private Key Generation only\n");
1181 
1182 	status = test_dh_gen_priv_key(&dh_xform);
1183 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1184 
1185 	RTE_LOG(INFO, USER1,
1186 		"Test shared secret compute\n");
1187 
1188 	status = test_dh_gen_shared_sec(&dh_xform);
1189 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1190 
1191 	return status;
1192 }
1193 
1194 static int
1195 test_dsa_sign(void)
1196 {
1197 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1198 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1199 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1200 	uint8_t dev_id = ts_params->valid_devs[0];
1201 	struct rte_crypto_asym_op *asym_op = NULL;
1202 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1203 	struct rte_cryptodev_asym_session *sess = NULL;
1204 	int status = TEST_SUCCESS;
1205 	uint8_t r[TEST_DH_MOD_LEN];
1206 	uint8_t s[TEST_DH_MOD_LEN];
1207 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1208 
1209 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1210 	if (sess == NULL) {
1211 		RTE_LOG(ERR, USER1,
1212 				 "line %u FAILED: %s", __LINE__,
1213 				"Session creation failed");
1214 		status = TEST_FAILED;
1215 		goto error_exit;
1216 	}
1217 	/* set up crypto op data structure */
1218 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1219 	if (!op) {
1220 		RTE_LOG(ERR, USER1,
1221 			"line %u FAILED: %s",
1222 			__LINE__, "Failed to allocate asymmetric crypto "
1223 			"operation struct");
1224 		status = TEST_FAILED;
1225 		goto error_exit;
1226 	}
1227 	asym_op = op->asym;
1228 
1229 	debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1230 			dsa_xform.dsa.p.length);
1231 	debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1232 			dsa_xform.dsa.q.length);
1233 	debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1234 			dsa_xform.dsa.g.length);
1235 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1236 			dsa_xform.dsa.x.length);
1237 
1238 	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1239 				sess_mpool) < 0) {
1240 		RTE_LOG(ERR, USER1,
1241 				"line %u FAILED: %s",
1242 				__LINE__, "unabled to config sym session");
1243 		status = TEST_FAILED;
1244 		goto error_exit;
1245 	}
1246 
1247 	/* attach asymmetric crypto session to crypto operations */
1248 	rte_crypto_op_attach_asym_session(op, sess);
1249 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1250 	asym_op->dsa.message.data = dgst;
1251 	asym_op->dsa.message.length = sizeof(dgst);
1252 	asym_op->dsa.r.length = sizeof(r);
1253 	asym_op->dsa.r.data = r;
1254 	asym_op->dsa.s.length = sizeof(s);
1255 	asym_op->dsa.s.data = s;
1256 
1257 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1258 
1259 	/* Process crypto operation */
1260 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1261 		RTE_LOG(ERR, USER1,
1262 			"line %u FAILED: %s",
1263 			__LINE__, "Error sending packet for operation");
1264 		status = TEST_FAILED;
1265 		goto error_exit;
1266 	}
1267 
1268 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1269 		rte_pause();
1270 
1271 	if (result_op == NULL) {
1272 		RTE_LOG(ERR, USER1,
1273 			"line %u FAILED: %s",
1274 			__LINE__, "Failed to process asym crypto op");
1275 		status = TEST_FAILED;
1276 		goto error_exit;
1277 	}
1278 
1279 	asym_op = result_op->asym;
1280 
1281 	debug_hexdump(stdout, "r:",
1282 			asym_op->dsa.r.data, asym_op->dsa.r.length);
1283 	debug_hexdump(stdout, "s:",
1284 			asym_op->dsa.s.data, asym_op->dsa.s.length);
1285 
1286 	/* Test PMD DSA sign verification using signer public key */
1287 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1288 
1289 	/* copy signer public key */
1290 	asym_op->dsa.y.data = dsa_test_params.y.data;
1291 	asym_op->dsa.y.length = dsa_test_params.y.length;
1292 
1293 	/* Process crypto operation */
1294 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1295 		RTE_LOG(ERR, USER1,
1296 			"line %u FAILED: %s",
1297 			__LINE__, "Error sending packet for operation");
1298 		status = TEST_FAILED;
1299 		goto error_exit;
1300 	}
1301 
1302 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1303 		rte_pause();
1304 
1305 	if (result_op == NULL) {
1306 		RTE_LOG(ERR, USER1,
1307 			"line %u FAILED: %s",
1308 			__LINE__, "Failed to process asym crypto op");
1309 		status = TEST_FAILED;
1310 		goto error_exit;
1311 	}
1312 
1313 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1314 		RTE_LOG(ERR, USER1,
1315 				"line %u FAILED: %s",
1316 				__LINE__, "Failed to process asym crypto op");
1317 		status = TEST_FAILED;
1318 	}
1319 error_exit:
1320 	if (sess != NULL) {
1321 		rte_cryptodev_asym_session_clear(dev_id, sess);
1322 		rte_cryptodev_asym_session_free(sess);
1323 	}
1324 	if (op != NULL)
1325 		rte_crypto_op_free(op);
1326 	return status;
1327 }
1328 
1329 static int
1330 test_dsa(void)
1331 {
1332 	int status;
1333 	status = test_dsa_sign();
1334 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1335 	return status;
1336 }
1337 
1338 
1339 static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
1340 	.suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1341 	.setup = testsuite_setup,
1342 	.teardown = testsuite_teardown,
1343 	.unit_test_cases = {
1344 		TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1345 		TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1346 		TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1347 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1348 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1349 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1350 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1351 		TEST_CASES_END() /**< NULL terminate unit test array */
1352 	}
1353 };
1354 
1355 static int
1356 test_cryptodev_openssl_asym(void)
1357 {
1358 	gbl_driver_id = rte_cryptodev_driver_id_get(
1359 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1360 
1361 	if (gbl_driver_id == -1) {
1362 		RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1363 				"CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1364 				"in config file to run this testsuite.\n");
1365 		return TEST_FAILED;
1366 	}
1367 
1368 	return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1369 }
1370 
1371 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1372 					  test_cryptodev_openssl_asym);
1373