xref: /dpdk/app/test/test_cryptodev_asym.c (revision 089e5ed727a15da2729cfee9b63533dd120bd04c)
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_cryptodev_pmd.h>
16 #include <rte_crypto.h>
17 
18 #include "test_cryptodev.h"
19 #include "test_cryptodev_dh_test_vectors.h"
20 #include "test_cryptodev_dsa_test_vectors.h"
21 #include "test_cryptodev_mod_test_vectors.h"
22 #include "test_cryptodev_rsa_test_vectors.h"
23 #include "test_cryptodev_asym_util.h"
24 #include "test.h"
25 
26 #define TEST_NUM_BUFS 10
27 #define TEST_NUM_SESSIONS 4
28 
29 #ifndef ARRAY_SIZE
30 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31 #endif
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 
39 static int gbl_driver_id;
40 struct crypto_testsuite_params {
41 	struct rte_mempool *op_mpool;
42 	struct rte_mempool *session_mpool;
43 	struct rte_cryptodev_config conf;
44 	struct rte_cryptodev_qp_conf qp_conf;
45 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
46 	uint8_t valid_dev_count;
47 };
48 
49 struct crypto_unittest_params {
50 	struct rte_cryptodev_asym_session *sess;
51 	struct rte_crypto_op *op;
52 };
53 
54 union test_case_structure {
55 	struct modex_test_data modex;
56 	struct modinv_test_data modinv;
57 };
58 
59 struct test_cases_array {
60 	uint32_t size;
61 	const void *address[TEST_VECTOR_SIZE];
62 };
63 static struct test_cases_array test_vector = {0, { NULL } };
64 
65 static uint32_t test_index;
66 
67 static struct crypto_testsuite_params testsuite_params = { NULL };
68 
69 static int
70 queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
71 {
72 	struct crypto_testsuite_params *ts_params = &testsuite_params;
73 	struct rte_mempool *op_mpool = ts_params->op_mpool;
74 	uint8_t dev_id = ts_params->valid_devs[0];
75 	struct rte_crypto_op *op, *result_op;
76 	struct rte_crypto_asym_op *asym_op;
77 	uint8_t output_buf[TEST_DATA_SIZE];
78 	int status = TEST_SUCCESS;
79 
80 	/* Set up crypto op data structure */
81 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
82 	if (!op) {
83 		RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
84 			"operation struct\n");
85 		return TEST_FAILED;
86 	}
87 
88 	asym_op = op->asym;
89 
90 	/* Compute sign on the test vector */
91 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
92 
93 	asym_op->rsa.message.data = rsaplaintext.data;
94 	asym_op->rsa.message.length = rsaplaintext.len;
95 	asym_op->rsa.sign.length = 0;
96 	asym_op->rsa.sign.data = output_buf;
97 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
98 
99 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
100 		      asym_op->rsa.message.length);
101 
102 	/* Attach asymmetric crypto session to crypto operations */
103 	rte_crypto_op_attach_asym_session(op, sess);
104 
105 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
106 
107 	/* Process crypto operation */
108 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
109 		RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
110 		status = TEST_FAILED;
111 		goto error_exit;
112 	}
113 
114 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
115 		rte_pause();
116 
117 	if (result_op == NULL) {
118 		RTE_LOG(ERR, USER1, "Failed to process sign op\n");
119 		status = TEST_FAILED;
120 		goto error_exit;
121 	}
122 
123 	debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
124 		      asym_op->rsa.sign.length);
125 	asym_op = result_op->asym;
126 
127 	/* Verify sign */
128 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
129 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
130 
131 	/* Process crypto operation */
132 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
133 		RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
134 		status = TEST_FAILED;
135 		goto error_exit;
136 	}
137 
138 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
139 		rte_pause();
140 
141 	if (result_op == NULL) {
142 		RTE_LOG(ERR, USER1, "Failed to process verify op\n");
143 		status = TEST_FAILED;
144 		goto error_exit;
145 	}
146 
147 	status = TEST_SUCCESS;
148 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
149 		RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
150 		status = TEST_FAILED;
151 	}
152 
153 error_exit:
154 
155 	rte_crypto_op_free(op);
156 
157 	return status;
158 }
159 
160 static int
161 queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
162 {
163 	struct crypto_testsuite_params *ts_params = &testsuite_params;
164 	struct rte_mempool *op_mpool = ts_params->op_mpool;
165 	uint8_t dev_id = ts_params->valid_devs[0];
166 	struct rte_crypto_op *op, *result_op;
167 	struct rte_crypto_asym_op *asym_op;
168 	uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
169 	int ret, status = TEST_SUCCESS;
170 
171 	/* Set up crypto op data structure */
172 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
173 	if (!op) {
174 		RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
175 			"operation struct\n");
176 		return TEST_FAILED;
177 	}
178 
179 	asym_op = op->asym;
180 
181 	/* Compute encryption on the test vector */
182 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
183 
184 	asym_op->rsa.message.data = rsaplaintext.data;
185 	asym_op->rsa.cipher.data = cipher_buf;
186 	asym_op->rsa.cipher.length = 0;
187 	asym_op->rsa.message.length = rsaplaintext.len;
188 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
189 
190 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
191 		      asym_op->rsa.message.length);
192 
193 	/* Attach asymmetric crypto session to crypto operations */
194 	rte_crypto_op_attach_asym_session(op, sess);
195 
196 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
197 
198 	/* Process crypto operation */
199 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
200 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
201 		status = TEST_FAILED;
202 		goto error_exit;
203 	}
204 
205 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
206 		rte_pause();
207 
208 	if (result_op == NULL) {
209 		RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
210 		status = TEST_FAILED;
211 		goto error_exit;
212 	}
213 	debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
214 		      asym_op->rsa.message.length);
215 
216 	/* Use the resulted output as decryption Input vector*/
217 	asym_op = result_op->asym;
218 	asym_op->rsa.message.length = 0;
219 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
220 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
221 
222 	/* Process crypto operation */
223 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
224 		RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
225 		status = TEST_FAILED;
226 		goto error_exit;
227 	}
228 
229 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
230 		rte_pause();
231 
232 	if (result_op == NULL) {
233 		RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
234 		status = TEST_FAILED;
235 		goto error_exit;
236 	}
237 	status = TEST_SUCCESS;
238 	ret = rsa_verify(&rsaplaintext, result_op);
239 	if (ret)
240 		status = TEST_FAILED;
241 
242 error_exit:
243 
244 	rte_crypto_op_free(op);
245 
246 	return status;
247 }
248 static int
249 test_cryptodev_asym_ver(union test_case_structure *data_tc,
250 						struct rte_crypto_op *result_op)
251 {
252 	int status = TEST_SUCCESS;
253 	int ret = 0;
254 	uint8_t *data_expected = NULL, *data_received = NULL;
255 	size_t data_size = 0;
256 
257 	switch (data_tc->modex.xform_type) {
258 	case RTE_CRYPTO_ASYM_XFORM_MODEX:
259 		data_expected = data_tc->modex.reminder.data;
260 		data_received = result_op->asym->modex.result.data;
261 		data_size = result_op->asym->modex.result.length;
262 		break;
263 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
264 		data_expected = data_tc->modinv.inverse.data;
265 		data_received = result_op->asym->modinv.result.data;
266 		data_size = result_op->asym->modinv.result.length;
267 		break;
268 	case RTE_CRYPTO_ASYM_XFORM_DH:
269 	case RTE_CRYPTO_ASYM_XFORM_DSA:
270 	case RTE_CRYPTO_ASYM_XFORM_RSA:
271 	case RTE_CRYPTO_ASYM_XFORM_NONE:
272 	case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
273 	default:
274 		break;
275 	}
276 	ret = memcmp(data_expected, data_received, data_size);
277 	if (ret)
278 		status = TEST_FAILED;
279 
280 	return status;
281 }
282 
283 static int
284 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
285 	union test_case_structure *data_tc,
286 	char *test_msg)
287 {
288 	struct rte_crypto_asym_op *asym_op = NULL;
289 	struct rte_crypto_op *op = NULL;
290 	struct rte_crypto_op *result_op = NULL;
291 	struct rte_crypto_asym_xform xform_tc;
292 	struct rte_cryptodev_asym_session *sess = NULL;
293 	struct rte_cryptodev_asym_capability_idx cap_idx;
294 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
295 	uint8_t dev_id = ts_params->valid_devs[0];
296 	uint8_t input[TEST_DATA_SIZE] = {0};
297 	uint8_t *result = NULL;
298 
299 	int status = TEST_SUCCESS;
300 
301 	xform_tc.next = NULL;
302 	xform_tc.xform_type = data_tc->modex.xform_type;
303 
304 	cap_idx.type = xform_tc.xform_type;
305 	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
306 
307 	if (capability == NULL) {
308 		RTE_LOG(INFO, USER1,
309 			"Device doesn't support MODEX. Test Skipped\n");
310 		return -ENOTSUP;
311 	}
312 
313 	/* Generate crypto op data structure */
314 	op = rte_crypto_op_alloc(ts_params->op_mpool,
315 		RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
316 
317 	if (!op) {
318 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
319 			"line %u FAILED: %s",
320 			__LINE__, "Failed to allocate asymmetric crypto "
321 			"operation struct");
322 		status = TEST_FAILED;
323 		goto error_exit;
324 	}
325 
326 	asym_op = op->asym;
327 
328 	switch (xform_tc.xform_type) {
329 	case RTE_CRYPTO_ASYM_XFORM_MODEX:
330 		result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
331 		xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
332 		xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
333 		xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
334 		xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
335 		memcpy(input, data_tc->modex.base.data,
336 			data_tc->modex.base.len);
337 		asym_op->modex.base.data = input;
338 		asym_op->modex.base.length = data_tc->modex.base.len;
339 		asym_op->modex.result.data = result;
340 		asym_op->modex.result.length = data_tc->modex.result_len;
341 		if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
342 				xform_tc.modex.modulus.length)) {
343 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
344 				"line %u "
345 				"FAILED: %s", __LINE__,
346 				"Invalid MODULUS length specified");
347 			status = TEST_FAILED;
348 			goto error_exit;
349 		}
350 		break;
351 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
352 		result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
353 		xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
354 		xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
355 		memcpy(input, data_tc->modinv.base.data,
356 			data_tc->modinv.base.len);
357 		asym_op->modinv.base.data = input;
358 		asym_op->modinv.base.length = data_tc->modinv.base.len;
359 		asym_op->modinv.result.data = result;
360 		asym_op->modinv.result.length = data_tc->modinv.result_len;
361 		if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
362 				xform_tc.modinv.modulus.length)) {
363 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
364 				"line %u "
365 				"FAILED: %s", __LINE__,
366 				"Invalid MODULUS length specified");
367 			status = TEST_FAILED;
368 			goto error_exit;
369 		}
370 		break;
371 	case RTE_CRYPTO_ASYM_XFORM_DH:
372 	case RTE_CRYPTO_ASYM_XFORM_DSA:
373 	case RTE_CRYPTO_ASYM_XFORM_RSA:
374 	case RTE_CRYPTO_ASYM_XFORM_NONE:
375 	case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
376 	default:
377 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
378 				"line %u "
379 				"FAILED: %s", __LINE__,
380 				"Invalid ASYM algorithm specified");
381 		status = TEST_FAILED;
382 		goto error_exit;
383 	}
384 
385 	sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
386 	if (!sess) {
387 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
388 				"line %u "
389 				"FAILED: %s", __LINE__,
390 				"Session creation failed");
391 		status = TEST_FAILED;
392 		goto error_exit;
393 	}
394 
395 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
396 			ts_params->session_mpool) < 0) {
397 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
398 				"line %u FAILED: %s",
399 				__LINE__, "unabled to config sym session");
400 		status = TEST_FAILED;
401 		goto error_exit;
402 	}
403 
404 	rte_crypto_op_attach_asym_session(op, sess);
405 
406 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
407 
408 	/* Process crypto operation */
409 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
410 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
411 				"line %u FAILED: %s",
412 				__LINE__, "Error sending packet for operation");
413 		status = TEST_FAILED;
414 		goto error_exit;
415 	}
416 
417 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
418 		rte_pause();
419 
420 	if (result_op == NULL) {
421 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
422 				"line %u FAILED: %s",
423 				__LINE__, "Failed to process asym crypto op");
424 		status = TEST_FAILED;
425 		goto error_exit;
426 	}
427 
428 	if (test_cryptodev_asym_ver(data_tc, result_op) != TEST_SUCCESS) {
429 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
430 			"line %u FAILED: %s",
431 			__LINE__, "Verification failed ");
432 		status = TEST_FAILED;
433 		goto error_exit;
434 	}
435 
436 	snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
437 
438 error_exit:
439 		if (sess != NULL) {
440 			rte_cryptodev_asym_session_clear(dev_id, sess);
441 			rte_cryptodev_asym_session_free(sess);
442 		}
443 
444 		if (op != NULL)
445 			rte_crypto_op_free(op);
446 
447 		if (result != NULL)
448 			rte_free(result);
449 
450 	return status;
451 }
452 
453 static int
454 test_one_case(const void *test_case)
455 {
456 	int status = TEST_SUCCESS;
457 	char test_msg[ASYM_TEST_MSG_LEN + 1];
458 
459 	/* Map the case to union */
460 	union test_case_structure tc;
461 	memcpy(&tc, test_case, sizeof(tc));
462 
463 	status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg);
464 
465 	printf("  %u) TestCase %s %s\n", test_index++,
466 		tc.modex.description, test_msg);
467 
468 	return status;
469 }
470 
471 static int
472 load_test_vectors(void)
473 {
474 	uint32_t i = 0, v_size = 0;
475 	/* Load MODEX vector*/
476 	v_size = ARRAY_SIZE(modex_test_case);
477 	for (i = 0; i < v_size; i++) {
478 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
479 			RTE_LOG(DEBUG, USER1,
480 				"TEST_VECTOR_SIZE too small\n");
481 			return -1;
482 		}
483 		test_vector.address[test_vector.size] = &modex_test_case[i];
484 		test_vector.size++;
485 	}
486 	/* Load MODINV vector*/
487 	v_size = ARRAY_SIZE(modinv_test_case);
488 	for (i = 0; i < v_size; i++) {
489 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
490 			RTE_LOG(DEBUG, USER1,
491 				"TEST_VECTOR_SIZE too small\n");
492 			return -1;
493 		}
494 		test_vector.address[test_vector.size] = &modinv_test_case[i];
495 		test_vector.size++;
496 	}
497 	return 0;
498 }
499 
500 static int
501 test_one_by_one(void)
502 {
503 	int status = TEST_SUCCESS;
504 	uint32_t i = 0;
505 
506 	/* Go through all test cases */
507 	test_index = 0;
508 	for (i = 0; i < test_vector.size; i++) {
509 		if (test_one_case(test_vector.address[i]) != TEST_SUCCESS)
510 			status = TEST_FAILED;
511 	}
512 
513 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
514 	return status;
515 }
516 
517 static int
518 test_rsa_sign_verify(void)
519 {
520 	struct crypto_testsuite_params *ts_params = &testsuite_params;
521 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
522 	uint8_t dev_id = ts_params->valid_devs[0];
523 	struct rte_cryptodev_asym_session *sess;
524 	struct rte_cryptodev_info dev_info;
525 	int status = TEST_SUCCESS;
526 
527 	/* Test case supports op with exponent key only,
528 	 * Check in PMD feature flag for RSA exponent key type support.
529 	 */
530 	rte_cryptodev_info_get(dev_id, &dev_info);
531 	if (!(dev_info.feature_flags &
532 				RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
533 		RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
534 			"exponent key type. Test Skipped\n");
535 		return -ENOTSUP;
536 	}
537 
538 	sess = rte_cryptodev_asym_session_create(sess_mpool);
539 
540 	if (!sess) {
541 		RTE_LOG(ERR, USER1, "Session creation failed for "
542 			"sign_verify\n");
543 		return TEST_FAILED;
544 	}
545 
546 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
547 				sess_mpool) < 0) {
548 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
549 			"sign_verify\n");
550 		status = TEST_FAILED;
551 		goto error_exit;
552 	}
553 
554 	status = queue_ops_rsa_sign_verify(sess);
555 
556 error_exit:
557 
558 	rte_cryptodev_asym_session_clear(dev_id, sess);
559 	rte_cryptodev_asym_session_free(sess);
560 
561 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
562 
563 	return status;
564 }
565 
566 static int
567 test_rsa_enc_dec(void)
568 {
569 	struct crypto_testsuite_params *ts_params = &testsuite_params;
570 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
571 	uint8_t dev_id = ts_params->valid_devs[0];
572 	struct rte_cryptodev_asym_session *sess;
573 	struct rte_cryptodev_info dev_info;
574 	int status = TEST_SUCCESS;
575 
576 	/* Test case supports op with exponent key only,
577 	 * Check in PMD feature flag for RSA exponent key type support.
578 	 */
579 	rte_cryptodev_info_get(dev_id, &dev_info);
580 	if (!(dev_info.feature_flags &
581 				RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
582 		RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
583 			"exponent key type. Test skipped\n");
584 		return -ENOTSUP;
585 	}
586 
587 	sess = rte_cryptodev_asym_session_create(sess_mpool);
588 
589 	if (!sess) {
590 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
591 		return TEST_FAILED;
592 	}
593 
594 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
595 				sess_mpool) < 0) {
596 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
597 			"enc_dec\n");
598 		status = TEST_FAILED;
599 		goto error_exit;
600 	}
601 
602 	status = queue_ops_rsa_enc_dec(sess);
603 
604 error_exit:
605 
606 	rte_cryptodev_asym_session_clear(dev_id, sess);
607 	rte_cryptodev_asym_session_free(sess);
608 
609 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
610 
611 	return status;
612 }
613 
614 static int
615 test_rsa_sign_verify_crt(void)
616 {
617 	struct crypto_testsuite_params *ts_params = &testsuite_params;
618 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
619 	uint8_t dev_id = ts_params->valid_devs[0];
620 	struct rte_cryptodev_asym_session *sess;
621 	struct rte_cryptodev_info dev_info;
622 	int status = TEST_SUCCESS;
623 
624 	/* Test case supports op with quintuple format key only,
625 	 * Check im PMD feature flag for RSA quintuple key type support.
626 	 */
627 	rte_cryptodev_info_get(dev_id, &dev_info);
628 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
629 		RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
630 			"quintuple key type. Test skipped\n");
631 		return -ENOTSUP;
632 	}
633 
634 	sess = rte_cryptodev_asym_session_create(sess_mpool);
635 
636 	if (!sess) {
637 		RTE_LOG(ERR, USER1, "Session creation failed for "
638 			"sign_verify_crt\n");
639 		status = TEST_FAILED;
640 		return status;
641 	}
642 
643 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
644 				sess_mpool) < 0) {
645 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
646 			"sign_verify_crt\n");
647 		status = TEST_FAILED;
648 		goto error_exit;
649 	}
650 	status = queue_ops_rsa_sign_verify(sess);
651 
652 error_exit:
653 
654 	rte_cryptodev_asym_session_clear(dev_id, sess);
655 	rte_cryptodev_asym_session_free(sess);
656 
657 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
658 
659 	return status;
660 }
661 
662 static int
663 test_rsa_enc_dec_crt(void)
664 {
665 	struct crypto_testsuite_params *ts_params = &testsuite_params;
666 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
667 	uint8_t dev_id = ts_params->valid_devs[0];
668 	struct rte_cryptodev_asym_session *sess;
669 	struct rte_cryptodev_info dev_info;
670 	int status = TEST_SUCCESS;
671 
672 	/* Test case supports op with quintuple format key only,
673 	 * Check in PMD feature flag for RSA quintuple key type support.
674 	 */
675 	rte_cryptodev_info_get(dev_id, &dev_info);
676 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
677 		RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
678 			"quintuple key type. Test skipped\n");
679 		return -ENOTSUP;
680 	}
681 
682 	sess = rte_cryptodev_asym_session_create(sess_mpool);
683 
684 	if (!sess) {
685 		RTE_LOG(ERR, USER1, "Session creation failed for "
686 			"enc_dec_crt\n");
687 		return TEST_FAILED;
688 	}
689 
690 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
691 				sess_mpool) < 0) {
692 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
693 			"enc_dec_crt\n");
694 		status = TEST_FAILED;
695 		goto error_exit;
696 	}
697 	status = queue_ops_rsa_enc_dec(sess);
698 
699 error_exit:
700 
701 	rte_cryptodev_asym_session_clear(dev_id, sess);
702 	rte_cryptodev_asym_session_free(sess);
703 
704 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
705 
706 	return status;
707 }
708 
709 static int
710 testsuite_setup(void)
711 {
712 	struct crypto_testsuite_params *ts_params = &testsuite_params;
713 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
714 	struct rte_cryptodev_info info;
715 	int ret, dev_id = -1;
716 	uint32_t i, nb_devs;
717 	uint16_t qp_id;
718 
719 	memset(ts_params, 0, sizeof(*ts_params));
720 
721 	test_vector.size = 0;
722 	load_test_vectors();
723 
724 	ts_params->op_mpool = rte_crypto_op_pool_create(
725 			"CRYPTO_ASYM_OP_POOL",
726 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
727 			TEST_NUM_BUFS, 0,
728 			0,
729 			rte_socket_id());
730 	if (ts_params->op_mpool == NULL) {
731 		RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
732 		return TEST_FAILED;
733 	}
734 
735 	/* Create an OPENSSL device if required */
736 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
737 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
738 		nb_devs = rte_cryptodev_device_count_by_driver(
739 				rte_cryptodev_driver_id_get(
740 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
741 		if (nb_devs < 1) {
742 			ret = rte_vdev_init(
743 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
744 				NULL);
745 
746 			TEST_ASSERT(ret == 0, "Failed to create "
747 				"instance of pmd : %s",
748 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
749 		}
750 	}
751 
752 	/* Get list of valid crypto devs */
753 	nb_devs = rte_cryptodev_devices_get(
754 				rte_cryptodev_driver_name_get(gbl_driver_id),
755 				valid_devs, RTE_CRYPTO_MAX_DEVS);
756 	if (nb_devs < 1) {
757 		RTE_LOG(ERR, USER1, "No crypto devices found?\n");
758 		return TEST_FAILED;
759 	}
760 
761 	/*
762 	 * Get first valid asymmetric device found in test suite param and
763 	 * break
764 	 */
765 	for (i = 0; i < nb_devs ; i++) {
766 		rte_cryptodev_info_get(valid_devs[i], &info);
767 		if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
768 			dev_id = ts_params->valid_devs[0] = valid_devs[i];
769 			break;
770 		}
771 	}
772 
773 	if (dev_id == -1) {
774 		RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
775 			"Test skipped.\n");
776 		return TEST_FAILED;
777 	}
778 
779 	/* Set valid device count */
780 	ts_params->valid_dev_count = nb_devs;
781 
782 	/* configure device with num qp */
783 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
784 	ts_params->conf.socket_id = SOCKET_ID_ANY;
785 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
786 			RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
787 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
788 			&ts_params->conf),
789 			"Failed to configure cryptodev %u with %u qps",
790 			dev_id, ts_params->conf.nb_queue_pairs);
791 
792 	/* configure qp */
793 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
794 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
795 	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
796 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
797 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
798 			dev_id, qp_id, &ts_params->qp_conf,
799 			rte_cryptodev_socket_id(dev_id)),
800 			"Failed to setup queue pair %u on cryptodev %u ASYM",
801 			qp_id, dev_id);
802 	}
803 
804 	/* setup asym session pool */
805 	unsigned int session_size =
806 		rte_cryptodev_asym_get_private_session_size(dev_id);
807 	/*
808 	 * Create mempool with TEST_NUM_SESSIONS * 2,
809 	 * to include the session headers
810 	 */
811 	ts_params->session_mpool = rte_mempool_create(
812 				"test_asym_sess_mp",
813 				TEST_NUM_SESSIONS * 2,
814 				session_size,
815 				0, 0, NULL, NULL, NULL,
816 				NULL, SOCKET_ID_ANY,
817 				0);
818 
819 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
820 			"session mempool allocation failed");
821 
822 	return TEST_SUCCESS;
823 }
824 
825 static void
826 testsuite_teardown(void)
827 {
828 	struct crypto_testsuite_params *ts_params = &testsuite_params;
829 
830 	if (ts_params->op_mpool != NULL) {
831 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
832 		rte_mempool_avail_count(ts_params->op_mpool));
833 	}
834 
835 	/* Free session mempools */
836 	if (ts_params->session_mpool != NULL) {
837 		rte_mempool_free(ts_params->session_mpool);
838 		ts_params->session_mpool = NULL;
839 	}
840 }
841 
842 static int
843 ut_setup(void)
844 {
845 	struct crypto_testsuite_params *ts_params = &testsuite_params;
846 
847 	uint16_t qp_id;
848 
849 	/* Reconfigure device to default parameters */
850 	ts_params->conf.socket_id = SOCKET_ID_ANY;
851 
852 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
853 			&ts_params->conf),
854 			"Failed to configure cryptodev %u",
855 			ts_params->valid_devs[0]);
856 
857 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
858 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
859 			ts_params->valid_devs[0], qp_id,
860 			&ts_params->qp_conf,
861 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
862 			"Failed to setup queue pair %u on cryptodev %u",
863 			qp_id, ts_params->valid_devs[0]);
864 	}
865 
866 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
867 
868 	/* Start the device */
869 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
870 						"Failed to start cryptodev %u",
871 						ts_params->valid_devs[0]);
872 
873 	return TEST_SUCCESS;
874 }
875 
876 static void
877 ut_teardown(void)
878 {
879 	struct crypto_testsuite_params *ts_params = &testsuite_params;
880 	struct rte_cryptodev_stats stats;
881 
882 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
883 
884 	/* Stop the device */
885 	rte_cryptodev_stop(ts_params->valid_devs[0]);
886 }
887 
888 static inline void print_asym_capa(
889 		const struct rte_cryptodev_asymmetric_xform_capability *capa)
890 {
891 	int i = 0;
892 
893 	printf("\nxform type: %s\n===================\n",
894 			rte_crypto_asym_xform_strings[capa->xform_type]);
895 	printf("operation supported -");
896 
897 	for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
898 		/* check supported operations */
899 		if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
900 			printf(" %s",
901 					rte_crypto_asym_op_strings[i]);
902 		}
903 		switch (capa->xform_type) {
904 		case RTE_CRYPTO_ASYM_XFORM_RSA:
905 		case RTE_CRYPTO_ASYM_XFORM_MODINV:
906 		case RTE_CRYPTO_ASYM_XFORM_MODEX:
907 		case RTE_CRYPTO_ASYM_XFORM_DH:
908 		case RTE_CRYPTO_ASYM_XFORM_DSA:
909 			printf(" modlen: min %d max %d increment %d\n",
910 					capa->modlen.min,
911 					capa->modlen.max,
912 					capa->modlen.increment);
913 		break;
914 		default:
915 			break;
916 		}
917 }
918 
919 static int
920 test_capability(void)
921 {
922 	struct crypto_testsuite_params *ts_params = &testsuite_params;
923 	uint8_t dev_id = ts_params->valid_devs[0];
924 	struct rte_cryptodev_info dev_info;
925 	const struct rte_cryptodev_capabilities *dev_capa;
926 	int i = 0;
927 	struct rte_cryptodev_asym_capability_idx idx;
928 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
929 
930 	rte_cryptodev_info_get(dev_id, &dev_info);
931 	if (!(dev_info.feature_flags &
932 				RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
933 		RTE_LOG(INFO, USER1,
934 				"Device doesn't support asymmetric. Test Skipped\n");
935 		return TEST_SUCCESS;
936 	}
937 
938 	/* print xform capability */
939 	for (i = 0;
940 		dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
941 		i++) {
942 		dev_capa = &(dev_info.capabilities[i]);
943 		if (dev_info.capabilities[i].op ==
944 				RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
945 			idx.type = dev_capa->asym.xform_capa.xform_type;
946 
947 			capa = rte_cryptodev_asym_capability_get(dev_id,
948 				(const struct
949 				rte_cryptodev_asym_capability_idx *) &idx);
950 			print_asym_capa(capa);
951 			}
952 	}
953 	return TEST_SUCCESS;
954 }
955 
956 static int
957 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
958 {
959 	struct crypto_testsuite_params *ts_params = &testsuite_params;
960 	struct rte_mempool *op_mpool = ts_params->op_mpool;
961 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
962 	uint8_t dev_id = ts_params->valid_devs[0];
963 	struct rte_crypto_asym_op *asym_op = NULL;
964 	struct rte_crypto_op *op = NULL, *result_op = NULL;
965 	struct rte_cryptodev_asym_session *sess = NULL;
966 	int status = TEST_SUCCESS;
967 	uint8_t output[TEST_DH_MOD_LEN];
968 	struct rte_crypto_asym_xform xform = *xfrm;
969 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
970 
971 	sess = rte_cryptodev_asym_session_create(sess_mpool);
972 	if (sess == NULL) {
973 		RTE_LOG(ERR, USER1,
974 				"line %u FAILED: %s", __LINE__,
975 				"Session creation failed");
976 		status = TEST_FAILED;
977 		goto error_exit;
978 	}
979 	/* set up crypto op data structure */
980 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
981 	if (!op) {
982 		RTE_LOG(ERR, USER1,
983 			"line %u FAILED: %s",
984 			__LINE__, "Failed to allocate asymmetric crypto "
985 			"operation struct");
986 		status = TEST_FAILED;
987 		goto error_exit;
988 	}
989 	asym_op = op->asym;
990 
991 	/* Setup a xform and op to generate private key only */
992 	xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
993 	xform.next = NULL;
994 	asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
995 	asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
996 	asym_op->dh.pub_key.data = (uint8_t *)peer;
997 	asym_op->dh.pub_key.length = sizeof(peer);
998 	asym_op->dh.shared_secret.data = output;
999 	asym_op->dh.shared_secret.length = sizeof(output);
1000 
1001 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1002 			sess_mpool) < 0) {
1003 		RTE_LOG(ERR, USER1,
1004 				"line %u FAILED: %s",
1005 				__LINE__, "unabled to config sym session");
1006 		status = TEST_FAILED;
1007 		goto error_exit;
1008 	}
1009 
1010 	/* attach asymmetric crypto session to crypto operations */
1011 	rte_crypto_op_attach_asym_session(op, sess);
1012 
1013 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1014 
1015 	/* Process crypto operation */
1016 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1017 		RTE_LOG(ERR, USER1,
1018 			"line %u FAILED: %s",
1019 			__LINE__, "Error sending packet for operation");
1020 		status = TEST_FAILED;
1021 		goto error_exit;
1022 	}
1023 
1024 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1025 		rte_pause();
1026 
1027 	if (result_op == NULL) {
1028 		RTE_LOG(ERR, USER1,
1029 			"line %u FAILED: %s",
1030 			__LINE__, "Failed to process asym crypto op");
1031 		status = TEST_FAILED;
1032 		goto error_exit;
1033 	}
1034 
1035 	debug_hexdump(stdout, "shared secret:",
1036 			asym_op->dh.shared_secret.data,
1037 			asym_op->dh.shared_secret.length);
1038 
1039 error_exit:
1040 	if (sess != NULL) {
1041 		rte_cryptodev_asym_session_clear(dev_id, sess);
1042 		rte_cryptodev_asym_session_free(sess);
1043 	}
1044 	if (op != NULL)
1045 		rte_crypto_op_free(op);
1046 	return status;
1047 }
1048 
1049 static int
1050 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1051 {
1052 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1053 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1054 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1055 	uint8_t dev_id = ts_params->valid_devs[0];
1056 	struct rte_crypto_asym_op *asym_op = NULL;
1057 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1058 	struct rte_cryptodev_asym_session *sess = NULL;
1059 	int status = TEST_SUCCESS;
1060 	uint8_t output[TEST_DH_MOD_LEN];
1061 	struct rte_crypto_asym_xform xform = *xfrm;
1062 
1063 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1064 	if (sess == NULL) {
1065 		RTE_LOG(ERR, USER1,
1066 				 "line %u FAILED: %s", __LINE__,
1067 				"Session creation failed");
1068 		status = TEST_FAILED;
1069 		goto error_exit;
1070 	}
1071 	/* set up crypto op data structure */
1072 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1073 	if (!op) {
1074 		RTE_LOG(ERR, USER1,
1075 			"line %u FAILED: %s",
1076 			__LINE__, "Failed to allocate asymmetric crypto "
1077 			"operation struct");
1078 		status = TEST_FAILED;
1079 		goto error_exit;
1080 	}
1081 	asym_op = op->asym;
1082 
1083 	/* Setup a xform and op to generate private key only */
1084 	xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1085 	xform.next = NULL;
1086 	asym_op->dh.priv_key.data = output;
1087 	asym_op->dh.priv_key.length = sizeof(output);
1088 
1089 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1090 			sess_mpool) < 0) {
1091 		RTE_LOG(ERR, USER1,
1092 				"line %u FAILED: %s",
1093 				__LINE__, "unabled to config sym session");
1094 		status = TEST_FAILED;
1095 		goto error_exit;
1096 	}
1097 
1098 	/* attach asymmetric crypto session to crypto operations */
1099 	rte_crypto_op_attach_asym_session(op, sess);
1100 
1101 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1102 
1103 	/* Process crypto operation */
1104 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1105 		RTE_LOG(ERR, USER1,
1106 			"line %u FAILED: %s",
1107 			__LINE__, "Error sending packet for operation");
1108 		status = TEST_FAILED;
1109 		goto error_exit;
1110 	}
1111 
1112 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1113 		rte_pause();
1114 
1115 	if (result_op == NULL) {
1116 		RTE_LOG(ERR, USER1,
1117 			"line %u FAILED: %s",
1118 			__LINE__, "Failed to process asym crypto op");
1119 		status = TEST_FAILED;
1120 		goto error_exit;
1121 	}
1122 
1123 	debug_hexdump(stdout, "private key:",
1124 			asym_op->dh.priv_key.data,
1125 			asym_op->dh.priv_key.length);
1126 
1127 
1128 error_exit:
1129 	if (sess != NULL) {
1130 		rte_cryptodev_asym_session_clear(dev_id, sess);
1131 		rte_cryptodev_asym_session_free(sess);
1132 	}
1133 	if (op != NULL)
1134 		rte_crypto_op_free(op);
1135 
1136 	return status;
1137 }
1138 
1139 
1140 static int
1141 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1142 {
1143 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1144 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1145 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1146 	uint8_t dev_id = ts_params->valid_devs[0];
1147 	struct rte_crypto_asym_op *asym_op = NULL;
1148 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1149 	struct rte_cryptodev_asym_session *sess = NULL;
1150 	int status = TEST_SUCCESS;
1151 	uint8_t output[TEST_DH_MOD_LEN];
1152 	struct rte_crypto_asym_xform xform = *xfrm;
1153 
1154 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1155 	if (sess == NULL) {
1156 		RTE_LOG(ERR, USER1,
1157 				 "line %u FAILED: %s", __LINE__,
1158 				"Session creation failed");
1159 		status = TEST_FAILED;
1160 		goto error_exit;
1161 	}
1162 	/* set up crypto op data structure */
1163 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1164 	if (!op) {
1165 		RTE_LOG(ERR, USER1,
1166 			"line %u FAILED: %s",
1167 			__LINE__, "Failed to allocate asymmetric crypto "
1168 			"operation struct");
1169 		status = TEST_FAILED;
1170 		goto error_exit;
1171 	}
1172 	asym_op = op->asym;
1173 	/* Setup a xform chain to generate public key
1174 	 * using test private key
1175 	 *
1176 	 */
1177 	xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1178 	xform.next = NULL;
1179 
1180 	asym_op->dh.pub_key.data = output;
1181 	asym_op->dh.pub_key.length = sizeof(output);
1182 	/* load pre-defined private key */
1183 	asym_op->dh.priv_key.data = rte_malloc(NULL,
1184 					dh_test_params.priv_key.length,
1185 					0);
1186 	asym_op->dh.priv_key = dh_test_params.priv_key;
1187 
1188 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1189 			sess_mpool) < 0) {
1190 		RTE_LOG(ERR, USER1,
1191 				"line %u FAILED: %s",
1192 				__LINE__, "unabled to config sym session");
1193 		status = TEST_FAILED;
1194 		goto error_exit;
1195 	}
1196 
1197 	/* attach asymmetric crypto session to crypto operations */
1198 	rte_crypto_op_attach_asym_session(op, sess);
1199 
1200 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1201 
1202 	/* Process crypto operation */
1203 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1204 		RTE_LOG(ERR, USER1,
1205 			"line %u FAILED: %s",
1206 			__LINE__, "Error sending packet for operation");
1207 		status = TEST_FAILED;
1208 		goto error_exit;
1209 	}
1210 
1211 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1212 		rte_pause();
1213 
1214 	if (result_op == NULL) {
1215 		RTE_LOG(ERR, USER1,
1216 			"line %u FAILED: %s",
1217 			__LINE__, "Failed to process asym crypto op");
1218 		status = TEST_FAILED;
1219 		goto error_exit;
1220 	}
1221 
1222 	debug_hexdump(stdout, "pub key:",
1223 			asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1224 
1225 	debug_hexdump(stdout, "priv key:",
1226 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1227 
1228 error_exit:
1229 	if (sess != NULL) {
1230 		rte_cryptodev_asym_session_clear(dev_id, sess);
1231 		rte_cryptodev_asym_session_free(sess);
1232 	}
1233 	if (op != NULL)
1234 		rte_crypto_op_free(op);
1235 
1236 	return status;
1237 }
1238 
1239 static int
1240 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1241 {
1242 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1243 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1244 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1245 	uint8_t dev_id = ts_params->valid_devs[0];
1246 	struct rte_crypto_asym_op *asym_op = NULL;
1247 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1248 	struct rte_cryptodev_asym_session *sess = NULL;
1249 	int status = TEST_SUCCESS;
1250 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
1251 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
1252 	struct rte_crypto_asym_xform pub_key_xform;
1253 	struct rte_crypto_asym_xform xform = *xfrm;
1254 
1255 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1256 	if (sess == NULL) {
1257 		RTE_LOG(ERR, USER1,
1258 				 "line %u FAILED: %s", __LINE__,
1259 				"Session creation failed");
1260 		status = TEST_FAILED;
1261 		goto error_exit;
1262 	}
1263 
1264 	/* set up crypto op data structure */
1265 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1266 	if (!op) {
1267 		RTE_LOG(ERR, USER1,
1268 			"line %u FAILED: %s",
1269 			__LINE__, "Failed to allocate asymmetric crypto "
1270 			"operation struct");
1271 		status = TEST_FAILED;
1272 		goto error_exit;
1273 	}
1274 	asym_op = op->asym;
1275 	/* Setup a xform chain to generate
1276 	 * private key first followed by
1277 	 * public key
1278 	 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1279 	pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1280 	pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1281 	xform.next = &pub_key_xform;
1282 
1283 	asym_op->dh.pub_key.data = out_pub_key;
1284 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
1285 	asym_op->dh.priv_key.data = out_prv_key;
1286 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
1287 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1288 			sess_mpool) < 0) {
1289 		RTE_LOG(ERR, USER1,
1290 				"line %u FAILED: %s",
1291 				__LINE__, "unabled to config sym session");
1292 		status = TEST_FAILED;
1293 		goto error_exit;
1294 	}
1295 
1296 	/* attach asymmetric crypto session to crypto operations */
1297 	rte_crypto_op_attach_asym_session(op, sess);
1298 
1299 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1300 
1301 	/* Process crypto operation */
1302 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1303 		RTE_LOG(ERR, USER1,
1304 			"line %u FAILED: %s",
1305 			__LINE__, "Error sending packet for operation");
1306 		status = TEST_FAILED;
1307 		goto error_exit;
1308 	}
1309 
1310 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1311 		rte_pause();
1312 
1313 	if (result_op == NULL) {
1314 		RTE_LOG(ERR, USER1,
1315 			"line %u FAILED: %s",
1316 			__LINE__, "Failed to process asym crypto op");
1317 		status = TEST_FAILED;
1318 		goto error_exit;
1319 	}
1320 	debug_hexdump(stdout, "priv key:",
1321 			out_prv_key, asym_op->dh.priv_key.length);
1322 	debug_hexdump(stdout, "pub key:",
1323 			out_pub_key, asym_op->dh.pub_key.length);
1324 
1325 error_exit:
1326 	if (sess != NULL) {
1327 		rte_cryptodev_asym_session_clear(dev_id, sess);
1328 		rte_cryptodev_asym_session_free(sess);
1329 	}
1330 	if (op != NULL)
1331 		rte_crypto_op_free(op);
1332 
1333 	return status;
1334 }
1335 
1336 static int
1337 test_mod_inv(void)
1338 {
1339 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1340 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1341 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1342 	uint8_t dev_id = ts_params->valid_devs[0];
1343 	struct rte_crypto_asym_op *asym_op = NULL;
1344 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1345 	struct rte_cryptodev_asym_session *sess = NULL;
1346 	int status = TEST_SUCCESS;
1347 	struct rte_cryptodev_asym_capability_idx cap_idx;
1348 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
1349 	uint8_t input[TEST_DATA_SIZE] = {0};
1350 	int ret = 0;
1351 	uint8_t result[sizeof(mod_p)] = { 0 };
1352 
1353 	if (rte_cryptodev_asym_get_xform_enum(
1354 		&modinv_xform.xform_type, "modinv") < 0) {
1355 		RTE_LOG(ERR, USER1,
1356 				 "Invalid ASYM algorithm specified\n");
1357 		return -1;
1358 	}
1359 
1360 	cap_idx.type = modinv_xform.xform_type;
1361 	capability = rte_cryptodev_asym_capability_get(dev_id,
1362 					&cap_idx);
1363 
1364 	if (capability == NULL) {
1365 		RTE_LOG(INFO, USER1,
1366 			"Device doesn't support MOD INV. Test Skipped\n");
1367 		return -ENOTSUP;
1368 	}
1369 
1370 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1371 		capability,
1372 		modinv_xform.modinv.modulus.length)) {
1373 		RTE_LOG(ERR, USER1,
1374 				 "Invalid MODULUS length specified\n");
1375 				return -ENOTSUP;
1376 		}
1377 
1378 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1379 	if (!sess) {
1380 		RTE_LOG(ERR, USER1, "line %u "
1381 				"FAILED: %s", __LINE__,
1382 				"Session creation failed");
1383 		status = TEST_FAILED;
1384 		goto error_exit;
1385 	}
1386 
1387 	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1388 			sess_mpool) < 0) {
1389 		RTE_LOG(ERR, USER1,
1390 				"line %u FAILED: %s",
1391 				__LINE__, "unabled to config sym session");
1392 		status = TEST_FAILED;
1393 		goto error_exit;
1394 	}
1395 
1396 	/* generate crypto op data structure */
1397 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1398 	if (!op) {
1399 		RTE_LOG(ERR, USER1,
1400 			"line %u FAILED: %s",
1401 			__LINE__, "Failed to allocate asymmetric crypto "
1402 			"operation struct");
1403 		status = TEST_FAILED;
1404 		goto error_exit;
1405 	}
1406 
1407 	asym_op = op->asym;
1408 	memcpy(input, base, sizeof(base));
1409 	asym_op->modinv.base.data = input;
1410 	asym_op->modinv.base.length = sizeof(base);
1411 	asym_op->modinv.result.data = result;
1412 	asym_op->modinv.result.length = sizeof(result);
1413 
1414 	/* attach asymmetric crypto session to crypto operations */
1415 	rte_crypto_op_attach_asym_session(op, sess);
1416 
1417 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1418 
1419 	/* Process crypto operation */
1420 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1421 		RTE_LOG(ERR, USER1,
1422 			"line %u FAILED: %s",
1423 			__LINE__, "Error sending packet for operation");
1424 		status = TEST_FAILED;
1425 		goto error_exit;
1426 	}
1427 
1428 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1429 		rte_pause();
1430 
1431 	if (result_op == NULL) {
1432 		RTE_LOG(ERR, USER1,
1433 				"line %u FAILED: %s",
1434 				__LINE__, "Failed to process asym crypto op");
1435 		status = TEST_FAILED;
1436 		goto error_exit;
1437 	}
1438 
1439 	ret = verify_modinv(mod_inv, result_op);
1440 	if (ret) {
1441 		RTE_LOG(ERR, USER1,
1442 			 "operation verification failed\n");
1443 		status = TEST_FAILED;
1444 	}
1445 
1446 error_exit:
1447 	if (sess) {
1448 		rte_cryptodev_asym_session_clear(dev_id, sess);
1449 		rte_cryptodev_asym_session_free(sess);
1450 	}
1451 
1452 	if (op)
1453 		rte_crypto_op_free(op);
1454 
1455 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1456 
1457 	return status;
1458 }
1459 
1460 static int
1461 test_mod_exp(void)
1462 {
1463 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1464 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1465 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1466 	uint8_t dev_id = ts_params->valid_devs[0];
1467 	struct rte_crypto_asym_op *asym_op = NULL;
1468 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1469 	struct rte_cryptodev_asym_session *sess = NULL;
1470 	int status = TEST_SUCCESS;
1471 	struct rte_cryptodev_asym_capability_idx cap_idx;
1472 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
1473 	uint8_t input[TEST_DATA_SIZE] = {0};
1474 	int ret = 0;
1475 	uint8_t result[sizeof(mod_p)] = { 0 };
1476 
1477 	if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1478 		"modexp")
1479 		< 0) {
1480 		RTE_LOG(ERR, USER1,
1481 				"Invalid ASYM algorithm specified\n");
1482 		return -1;
1483 	}
1484 
1485 	/* check for modlen capability */
1486 	cap_idx.type = modex_xform.xform_type;
1487 	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1488 
1489 	if (capability == NULL) {
1490 		RTE_LOG(INFO, USER1,
1491 			"Device doesn't support MOD EXP. Test Skipped\n");
1492 		return -ENOTSUP;
1493 	}
1494 
1495 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1496 			capability, modex_xform.modex.modulus.length)) {
1497 		RTE_LOG(ERR, USER1,
1498 				"Invalid MODULUS length specified\n");
1499 				return -ENOTSUP;
1500 		}
1501 
1502 	/* generate crypto op data structure */
1503 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1504 	if (!op) {
1505 		RTE_LOG(ERR, USER1,
1506 			"line %u FAILED: %s",
1507 			__LINE__, "Failed to allocate asymmetric crypto "
1508 			"operation struct");
1509 		status = TEST_FAILED;
1510 		goto error_exit;
1511 	}
1512 
1513 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1514 	if (!sess) {
1515 		RTE_LOG(ERR, USER1,
1516 				 "line %u "
1517 				"FAILED: %s", __LINE__,
1518 				"Session creation failed");
1519 		status = TEST_FAILED;
1520 		goto error_exit;
1521 	}
1522 
1523 	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1524 			sess_mpool) < 0) {
1525 		RTE_LOG(ERR, USER1,
1526 				"line %u FAILED: %s",
1527 				__LINE__, "unabled to config sym session");
1528 		status = TEST_FAILED;
1529 		goto error_exit;
1530 	}
1531 
1532 	asym_op = op->asym;
1533 	memcpy(input, base, sizeof(base));
1534 	asym_op->modex.base.data = input;
1535 	asym_op->modex.base.length = sizeof(base);
1536 	asym_op->modex.result.data = result;
1537 	asym_op->modex.result.length = sizeof(result);
1538 	/* attach asymmetric crypto session to crypto operations */
1539 	rte_crypto_op_attach_asym_session(op, sess);
1540 
1541 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1542 	/* Process crypto operation */
1543 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1544 		RTE_LOG(ERR, USER1,
1545 				"line %u FAILED: %s",
1546 				__LINE__, "Error sending packet for operation");
1547 		status = TEST_FAILED;
1548 		goto error_exit;
1549 	}
1550 
1551 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1552 		rte_pause();
1553 
1554 	if (result_op == NULL) {
1555 		RTE_LOG(ERR, USER1,
1556 				"line %u FAILED: %s",
1557 				__LINE__, "Failed to process asym crypto op");
1558 		status = TEST_FAILED;
1559 		goto error_exit;
1560 	}
1561 
1562 	ret = verify_modexp(mod_exp, result_op);
1563 	if (ret) {
1564 		RTE_LOG(ERR, USER1,
1565 			 "operation verification failed\n");
1566 		status = TEST_FAILED;
1567 	}
1568 
1569 error_exit:
1570 	if (sess != NULL) {
1571 		rte_cryptodev_asym_session_clear(dev_id, sess);
1572 		rte_cryptodev_asym_session_free(sess);
1573 	}
1574 
1575 	if (op != NULL)
1576 		rte_crypto_op_free(op);
1577 
1578 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1579 
1580 	return status;
1581 }
1582 
1583 static int
1584 test_dh_keygenration(void)
1585 {
1586 	int status;
1587 
1588 	debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1589 	debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1590 	debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1591 			dh_test_params.priv_key.length);
1592 
1593 	RTE_LOG(INFO, USER1,
1594 		"Test Public and Private key pair generation\n");
1595 
1596 	status = test_dh_gen_kp(&dh_xform);
1597 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1598 
1599 	RTE_LOG(INFO, USER1,
1600 		"Test Public Key Generation using pre-defined priv key\n");
1601 
1602 	status = test_dh_gen_pub_key(&dh_xform);
1603 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1604 
1605 	RTE_LOG(INFO, USER1,
1606 		"Test Private Key Generation only\n");
1607 
1608 	status = test_dh_gen_priv_key(&dh_xform);
1609 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1610 
1611 	RTE_LOG(INFO, USER1,
1612 		"Test shared secret compute\n");
1613 
1614 	status = test_dh_gen_shared_sec(&dh_xform);
1615 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1616 
1617 	return status;
1618 }
1619 
1620 static int
1621 test_dsa_sign(void)
1622 {
1623 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1624 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1625 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1626 	uint8_t dev_id = ts_params->valid_devs[0];
1627 	struct rte_crypto_asym_op *asym_op = NULL;
1628 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1629 	struct rte_cryptodev_asym_session *sess = NULL;
1630 	int status = TEST_SUCCESS;
1631 	uint8_t r[TEST_DH_MOD_LEN];
1632 	uint8_t s[TEST_DH_MOD_LEN];
1633 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1634 
1635 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1636 	if (sess == NULL) {
1637 		RTE_LOG(ERR, USER1,
1638 				 "line %u FAILED: %s", __LINE__,
1639 				"Session creation failed");
1640 		status = TEST_FAILED;
1641 		goto error_exit;
1642 	}
1643 	/* set up crypto op data structure */
1644 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1645 	if (!op) {
1646 		RTE_LOG(ERR, USER1,
1647 			"line %u FAILED: %s",
1648 			__LINE__, "Failed to allocate asymmetric crypto "
1649 			"operation struct");
1650 		status = TEST_FAILED;
1651 		goto error_exit;
1652 	}
1653 	asym_op = op->asym;
1654 
1655 	debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1656 			dsa_xform.dsa.p.length);
1657 	debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1658 			dsa_xform.dsa.q.length);
1659 	debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1660 			dsa_xform.dsa.g.length);
1661 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1662 			dsa_xform.dsa.x.length);
1663 
1664 	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1665 				sess_mpool) < 0) {
1666 		RTE_LOG(ERR, USER1,
1667 				"line %u FAILED: %s",
1668 				__LINE__, "unabled to config sym session");
1669 		status = TEST_FAILED;
1670 		goto error_exit;
1671 	}
1672 
1673 	/* attach asymmetric crypto session to crypto operations */
1674 	rte_crypto_op_attach_asym_session(op, sess);
1675 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1676 	asym_op->dsa.message.data = dgst;
1677 	asym_op->dsa.message.length = sizeof(dgst);
1678 	asym_op->dsa.r.length = sizeof(r);
1679 	asym_op->dsa.r.data = r;
1680 	asym_op->dsa.s.length = sizeof(s);
1681 	asym_op->dsa.s.data = s;
1682 
1683 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1684 
1685 	/* Process crypto operation */
1686 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1687 		RTE_LOG(ERR, USER1,
1688 			"line %u FAILED: %s",
1689 			__LINE__, "Error sending packet for operation");
1690 		status = TEST_FAILED;
1691 		goto error_exit;
1692 	}
1693 
1694 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1695 		rte_pause();
1696 
1697 	if (result_op == NULL) {
1698 		RTE_LOG(ERR, USER1,
1699 			"line %u FAILED: %s",
1700 			__LINE__, "Failed to process asym crypto op");
1701 		status = TEST_FAILED;
1702 		goto error_exit;
1703 	}
1704 
1705 	asym_op = result_op->asym;
1706 
1707 	debug_hexdump(stdout, "r:",
1708 			asym_op->dsa.r.data, asym_op->dsa.r.length);
1709 	debug_hexdump(stdout, "s:",
1710 			asym_op->dsa.s.data, asym_op->dsa.s.length);
1711 
1712 	/* Test PMD DSA sign verification using signer public key */
1713 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1714 
1715 	/* copy signer public key */
1716 	asym_op->dsa.y.data = dsa_test_params.y.data;
1717 	asym_op->dsa.y.length = dsa_test_params.y.length;
1718 
1719 	/* Process crypto operation */
1720 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1721 		RTE_LOG(ERR, USER1,
1722 			"line %u FAILED: %s",
1723 			__LINE__, "Error sending packet for operation");
1724 		status = TEST_FAILED;
1725 		goto error_exit;
1726 	}
1727 
1728 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1729 		rte_pause();
1730 
1731 	if (result_op == NULL) {
1732 		RTE_LOG(ERR, USER1,
1733 			"line %u FAILED: %s",
1734 			__LINE__, "Failed to process asym crypto op");
1735 		status = TEST_FAILED;
1736 		goto error_exit;
1737 	}
1738 
1739 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1740 		RTE_LOG(ERR, USER1,
1741 				"line %u FAILED: %s",
1742 				__LINE__, "Failed to process asym crypto op");
1743 		status = TEST_FAILED;
1744 	}
1745 error_exit:
1746 	if (sess != NULL) {
1747 		rte_cryptodev_asym_session_clear(dev_id, sess);
1748 		rte_cryptodev_asym_session_free(sess);
1749 	}
1750 	if (op != NULL)
1751 		rte_crypto_op_free(op);
1752 	return status;
1753 }
1754 
1755 static int
1756 test_dsa(void)
1757 {
1758 	int status;
1759 	status = test_dsa_sign();
1760 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1761 	return status;
1762 }
1763 
1764 
1765 static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
1766 	.suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
1767 	.setup = testsuite_setup,
1768 	.teardown = testsuite_teardown,
1769 	.unit_test_cases = {
1770 		TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
1771 		TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
1772 		TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
1773 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
1774 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
1775 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
1776 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
1777 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
1778 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
1779 		TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1780 		TEST_CASES_END() /**< NULL terminate unit test array */
1781 	}
1782 };
1783 
1784 static struct unit_test_suite cryptodev_qat_asym_testsuite  = {
1785 	.suite_name = "Crypto Device QAT ASYM Unit Test Suite",
1786 	.setup = testsuite_setup,
1787 	.teardown = testsuite_teardown,
1788 	.unit_test_cases = {
1789 		TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
1790 		TEST_CASES_END() /**< NULL terminate unit test array */
1791 	}
1792 };
1793 
1794 static int
1795 test_cryptodev_openssl_asym(void)
1796 {
1797 	gbl_driver_id = rte_cryptodev_driver_id_get(
1798 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
1799 
1800 	if (gbl_driver_id == -1) {
1801 		RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded. Check if "
1802 				"CONFIG_RTE_LIBRTE_PMD_OPENSSL is enabled "
1803 				"in config file to run this testsuite.\n");
1804 		return TEST_FAILED;
1805 	}
1806 
1807 	return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
1808 }
1809 
1810 static int
1811 test_cryptodev_qat_asym(void)
1812 {
1813 	gbl_driver_id = rte_cryptodev_driver_id_get(
1814 			RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
1815 
1816 	if (gbl_driver_id == -1) {
1817 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded. Check if "
1818 				    "CONFIG_RTE_LIBRTE_PMD_QAT_ASYM is enabled "
1819 				    "in config file to run this testsuite.\n");
1820 		return TEST_FAILED;
1821 	}
1822 
1823 	return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
1824 }
1825 
1826 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
1827 					  test_cryptodev_openssl_asym);
1828 
1829 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
1830