xref: /dpdk/app/test/test_cryptodev_asym.c (revision 68a03efeed657e6e05f281479b33b51102797e15)
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_ecdsa_test_vectors.h"
22 #include "test_cryptodev_ecpm_test_vectors.h"
23 #include "test_cryptodev_mod_test_vectors.h"
24 #include "test_cryptodev_rsa_test_vectors.h"
25 #include "test_cryptodev_asym_util.h"
26 #include "test.h"
27 
28 #define TEST_NUM_BUFS 10
29 #define TEST_NUM_SESSIONS 4
30 
31 #ifndef TEST_DATA_SIZE
32 	#define TEST_DATA_SIZE 4096
33 #endif
34 #define ASYM_TEST_MSG_LEN 256
35 #define TEST_VECTOR_SIZE 256
36 
37 static int gbl_driver_id;
38 struct crypto_testsuite_params {
39 	struct rte_mempool *op_mpool;
40 	struct rte_mempool *session_mpool;
41 	struct rte_cryptodev_config conf;
42 	struct rte_cryptodev_qp_conf qp_conf;
43 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
44 	uint8_t valid_dev_count;
45 };
46 
47 struct crypto_unittest_params {
48 	struct rte_cryptodev_asym_session *sess;
49 	struct rte_crypto_op *op;
50 };
51 
52 union test_case_structure {
53 	struct modex_test_data modex;
54 	struct modinv_test_data modinv;
55 	struct rsa_test_data_2 rsa_data;
56 };
57 
58 struct test_cases_array {
59 	uint32_t size;
60 	const void *address[TEST_VECTOR_SIZE];
61 };
62 static struct test_cases_array test_vector = {0, { NULL } };
63 
64 static uint32_t test_index;
65 
66 static struct crypto_testsuite_params testsuite_params = { NULL };
67 
68 static int
69 queue_ops_rsa_sign_verify(struct rte_cryptodev_asym_session *sess)
70 {
71 	struct crypto_testsuite_params *ts_params = &testsuite_params;
72 	struct rte_mempool *op_mpool = ts_params->op_mpool;
73 	uint8_t dev_id = ts_params->valid_devs[0];
74 	struct rte_crypto_op *op, *result_op;
75 	struct rte_crypto_asym_op *asym_op;
76 	uint8_t output_buf[TEST_DATA_SIZE];
77 	int status = TEST_SUCCESS;
78 
79 	/* Set up crypto op data structure */
80 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
81 	if (!op) {
82 		RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
83 			"operation struct\n");
84 		return TEST_FAILED;
85 	}
86 
87 	asym_op = op->asym;
88 
89 	/* Compute sign on the test vector */
90 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
91 
92 	asym_op->rsa.message.data = rsaplaintext.data;
93 	asym_op->rsa.message.length = rsaplaintext.len;
94 	asym_op->rsa.sign.length = 0;
95 	asym_op->rsa.sign.data = output_buf;
96 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
97 
98 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
99 		      asym_op->rsa.message.length);
100 
101 	/* Attach asymmetric crypto session to crypto operations */
102 	rte_crypto_op_attach_asym_session(op, sess);
103 
104 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
105 
106 	/* Process crypto operation */
107 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
108 		RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
109 		status = TEST_FAILED;
110 		goto error_exit;
111 	}
112 
113 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
114 		rte_pause();
115 
116 	if (result_op == NULL) {
117 		RTE_LOG(ERR, USER1, "Failed to process sign op\n");
118 		status = TEST_FAILED;
119 		goto error_exit;
120 	}
121 
122 	debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
123 		      asym_op->rsa.sign.length);
124 	asym_op = result_op->asym;
125 
126 	/* Verify sign */
127 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
128 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
129 
130 	/* Process crypto operation */
131 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
132 		RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
133 		status = TEST_FAILED;
134 		goto error_exit;
135 	}
136 
137 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
138 		rte_pause();
139 
140 	if (result_op == NULL) {
141 		RTE_LOG(ERR, USER1, "Failed to process verify op\n");
142 		status = TEST_FAILED;
143 		goto error_exit;
144 	}
145 
146 	status = TEST_SUCCESS;
147 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
148 		RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
149 		status = TEST_FAILED;
150 	}
151 
152 error_exit:
153 
154 	rte_crypto_op_free(op);
155 
156 	return status;
157 }
158 
159 static int
160 queue_ops_rsa_enc_dec(struct rte_cryptodev_asym_session *sess)
161 {
162 	struct crypto_testsuite_params *ts_params = &testsuite_params;
163 	struct rte_mempool *op_mpool = ts_params->op_mpool;
164 	uint8_t dev_id = ts_params->valid_devs[0];
165 	struct rte_crypto_op *op, *result_op;
166 	struct rte_crypto_asym_op *asym_op;
167 	uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
168 	int ret, status = TEST_SUCCESS;
169 
170 	/* Set up crypto op data structure */
171 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
172 	if (!op) {
173 		RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
174 			"operation struct\n");
175 		return TEST_FAILED;
176 	}
177 
178 	asym_op = op->asym;
179 
180 	/* Compute encryption on the test vector */
181 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
182 
183 	asym_op->rsa.message.data = rsaplaintext.data;
184 	asym_op->rsa.cipher.data = cipher_buf;
185 	asym_op->rsa.cipher.length = 0;
186 	asym_op->rsa.message.length = rsaplaintext.len;
187 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
188 
189 	debug_hexdump(stdout, "message", asym_op->rsa.message.data,
190 		      asym_op->rsa.message.length);
191 
192 	/* Attach asymmetric crypto session to crypto operations */
193 	rte_crypto_op_attach_asym_session(op, sess);
194 
195 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
196 
197 	/* Process crypto operation */
198 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
199 		RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
200 		status = TEST_FAILED;
201 		goto error_exit;
202 	}
203 
204 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
205 		rte_pause();
206 
207 	if (result_op == NULL) {
208 		RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
209 		status = TEST_FAILED;
210 		goto error_exit;
211 	}
212 	debug_hexdump(stdout, "encrypted message", asym_op->rsa.message.data,
213 		      asym_op->rsa.message.length);
214 
215 	/* Use the resulted output as decryption Input vector*/
216 	asym_op = result_op->asym;
217 	asym_op->rsa.message.length = 0;
218 	asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
219 	asym_op->rsa.pad = RTE_CRYPTO_RSA_PADDING_PKCS1_5;
220 
221 	/* Process crypto operation */
222 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
223 		RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
224 		status = TEST_FAILED;
225 		goto error_exit;
226 	}
227 
228 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
229 		rte_pause();
230 
231 	if (result_op == NULL) {
232 		RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
233 		status = TEST_FAILED;
234 		goto error_exit;
235 	}
236 	status = TEST_SUCCESS;
237 	ret = rsa_verify(&rsaplaintext, result_op);
238 	if (ret)
239 		status = TEST_FAILED;
240 
241 error_exit:
242 
243 	rte_crypto_op_free(op);
244 
245 	return status;
246 }
247 static int
248 test_cryptodev_asym_ver(struct rte_crypto_op *op,
249 				struct rte_crypto_asym_xform *xform_tc,
250 				union test_case_structure *data_tc,
251 				struct rte_crypto_op *result_op)
252 {
253 	int status = TEST_FAILED;
254 	int ret = 0;
255 	uint8_t *data_expected = NULL, *data_received = NULL;
256 	size_t data_size = 0;
257 
258 	switch (data_tc->modex.xform_type) {
259 	case RTE_CRYPTO_ASYM_XFORM_MODEX:
260 		data_expected = data_tc->modex.reminder.data;
261 		data_received = result_op->asym->modex.result.data;
262 		data_size = result_op->asym->modex.result.length;
263 		break;
264 	case RTE_CRYPTO_ASYM_XFORM_MODINV:
265 		data_expected = data_tc->modinv.inverse.data;
266 		data_received = result_op->asym->modinv.result.data;
267 		data_size = result_op->asym->modinv.result.length;
268 		break;
269 	case RTE_CRYPTO_ASYM_XFORM_RSA:
270 		if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
271 			data_size = xform_tc->rsa.n.length;
272 			data_received = result_op->asym->rsa.cipher.data;
273 			data_expected = data_tc->rsa_data.ct.data;
274 		} else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
275 			data_size = xform_tc->rsa.n.length;
276 			data_expected = data_tc->rsa_data.pt.data;
277 			data_received = result_op->asym->rsa.message.data;
278 		} else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
279 			data_size = xform_tc->rsa.n.length;
280 			data_expected = data_tc->rsa_data.sign.data;
281 			data_received = result_op->asym->rsa.sign.data;
282 		} else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
283 			data_size = xform_tc->rsa.n.length;
284 			data_expected = data_tc->rsa_data.pt.data;
285 			data_received = result_op->asym->rsa.cipher.data;
286 		}
287 		break;
288 	case RTE_CRYPTO_ASYM_XFORM_DH:
289 	case RTE_CRYPTO_ASYM_XFORM_DSA:
290 	case RTE_CRYPTO_ASYM_XFORM_NONE:
291 	case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
292 	default:
293 		break;
294 	}
295 	ret = memcmp(data_expected, data_received, data_size);
296 	if (!ret && data_size)
297 		status = TEST_SUCCESS;
298 
299 	return status;
300 }
301 
302 static int
303 test_cryptodev_asym_op(struct crypto_testsuite_params *ts_params,
304 	union test_case_structure *data_tc,
305 	char *test_msg, int sessionless, enum rte_crypto_asym_op_type type,
306 	enum rte_crypto_rsa_priv_key_type key_type)
307 {
308 	struct rte_crypto_asym_op *asym_op = NULL;
309 	struct rte_crypto_op *op = NULL;
310 	struct rte_crypto_op *result_op = NULL;
311 	struct rte_crypto_asym_xform xform_tc;
312 	struct rte_cryptodev_asym_session *sess = NULL;
313 	struct rte_cryptodev_asym_capability_idx cap_idx;
314 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
315 	uint8_t dev_id = ts_params->valid_devs[0];
316 	uint8_t input[TEST_DATA_SIZE] = {0};
317 	uint8_t *result = NULL;
318 
319 	int status = TEST_SUCCESS;
320 
321 	xform_tc.next = NULL;
322 	xform_tc.xform_type = data_tc->modex.xform_type;
323 
324 	cap_idx.type = xform_tc.xform_type;
325 	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
326 
327 	if (capability == NULL) {
328 		RTE_LOG(INFO, USER1,
329 			"Device doesn't support MODEX. Test Skipped\n");
330 		return -ENOTSUP;
331 	}
332 
333 	/* Generate crypto op data structure */
334 	op = rte_crypto_op_alloc(ts_params->op_mpool,
335 		RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
336 
337 	if (!op) {
338 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
339 			"line %u FAILED: %s",
340 			__LINE__, "Failed to allocate asymmetric crypto "
341 			"operation struct");
342 		status = TEST_FAILED;
343 		goto error_exit;
344 	}
345 
346 	asym_op = op->asym;
347 
348 	switch (xform_tc.xform_type) {
349 	case RTE_CRYPTO_ASYM_XFORM_MODEX:
350 		result = rte_zmalloc(NULL, data_tc->modex.result_len, 0);
351 		xform_tc.modex.modulus.data = data_tc->modex.modulus.data;
352 		xform_tc.modex.modulus.length = data_tc->modex.modulus.len;
353 		xform_tc.modex.exponent.data = data_tc->modex.exponent.data;
354 		xform_tc.modex.exponent.length = data_tc->modex.exponent.len;
355 		memcpy(input, data_tc->modex.base.data,
356 			data_tc->modex.base.len);
357 		asym_op->modex.base.data = input;
358 		asym_op->modex.base.length = data_tc->modex.base.len;
359 		asym_op->modex.result.data = result;
360 		asym_op->modex.result.length = data_tc->modex.result_len;
361 		if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
362 				xform_tc.modex.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_MODINV:
372 		result = rte_zmalloc(NULL, data_tc->modinv.result_len, 0);
373 		xform_tc.modinv.modulus.data = data_tc->modinv.modulus.data;
374 		xform_tc.modinv.modulus.length = data_tc->modinv.modulus.len;
375 		memcpy(input, data_tc->modinv.base.data,
376 			data_tc->modinv.base.len);
377 		asym_op->modinv.base.data = input;
378 		asym_op->modinv.base.length = data_tc->modinv.base.len;
379 		asym_op->modinv.result.data = result;
380 		asym_op->modinv.result.length = data_tc->modinv.result_len;
381 		if (rte_cryptodev_asym_xform_capability_check_modlen(capability,
382 				xform_tc.modinv.modulus.length)) {
383 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
384 				"line %u "
385 				"FAILED: %s", __LINE__,
386 				"Invalid MODULUS length specified");
387 			status = TEST_FAILED;
388 			goto error_exit;
389 		}
390 		break;
391 	case RTE_CRYPTO_ASYM_XFORM_RSA:
392 		result = rte_zmalloc(NULL, data_tc->rsa_data.n.len, 0);
393 		op->asym->rsa.op_type = type;
394 		xform_tc.rsa.e.data = data_tc->rsa_data.e.data;
395 		xform_tc.rsa.e.length = data_tc->rsa_data.e.len;
396 		xform_tc.rsa.n.data = data_tc->rsa_data.n.data;
397 		xform_tc.rsa.n.length = data_tc->rsa_data.n.len;
398 
399 		if (key_type == RTE_RSA_KEY_TYPE_EXP) {
400 			xform_tc.rsa.d.data = data_tc->rsa_data.d.data;
401 			xform_tc.rsa.d.length = data_tc->rsa_data.d.len;
402 		} else {
403 			xform_tc.rsa.qt.p.data = data_tc->rsa_data.p.data;
404 			xform_tc.rsa.qt.p.length = data_tc->rsa_data.p.len;
405 			xform_tc.rsa.qt.q.data = data_tc->rsa_data.q.data;
406 			xform_tc.rsa.qt.q.length = data_tc->rsa_data.q.len;
407 			xform_tc.rsa.qt.dP.data = data_tc->rsa_data.dP.data;
408 			xform_tc.rsa.qt.dP.length = data_tc->rsa_data.dP.len;
409 			xform_tc.rsa.qt.dQ.data = data_tc->rsa_data.dQ.data;
410 			xform_tc.rsa.qt.dQ.length = data_tc->rsa_data.dQ.len;
411 			xform_tc.rsa.qt.qInv.data = data_tc->rsa_data.qInv.data;
412 			xform_tc.rsa.qt.qInv.length = data_tc->rsa_data.qInv.len;
413 		}
414 
415 		xform_tc.rsa.key_type = key_type;
416 		op->asym->rsa.pad = data_tc->rsa_data.padding;
417 
418 		if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
419 			asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
420 			asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
421 			asym_op->rsa.cipher.data = result;
422 			asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
423 		} else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
424 			asym_op->rsa.message.data = result;
425 			asym_op->rsa.message.length = data_tc->rsa_data.n.len;
426 			asym_op->rsa.cipher.data = data_tc->rsa_data.ct.data;
427 			asym_op->rsa.cipher.length = data_tc->rsa_data.ct.len;
428 		} else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
429 			asym_op->rsa.sign.data = result;
430 			asym_op->rsa.sign.length = data_tc->rsa_data.n.len;
431 			asym_op->rsa.message.data = data_tc->rsa_data.pt.data;
432 			asym_op->rsa.message.length = data_tc->rsa_data.pt.len;
433 		} else if (op->asym->rsa.op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
434 			asym_op->rsa.cipher.data = result;
435 			asym_op->rsa.cipher.length = data_tc->rsa_data.n.len;
436 			asym_op->rsa.sign.data = data_tc->rsa_data.sign.data;
437 			asym_op->rsa.sign.length = data_tc->rsa_data.sign.len;
438 		}
439 		break;
440 	case RTE_CRYPTO_ASYM_XFORM_DH:
441 	case RTE_CRYPTO_ASYM_XFORM_DSA:
442 	case RTE_CRYPTO_ASYM_XFORM_NONE:
443 	case RTE_CRYPTO_ASYM_XFORM_UNSPECIFIED:
444 	default:
445 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
446 				"line %u "
447 				"FAILED: %s", __LINE__,
448 				"Invalid ASYM algorithm specified");
449 		status = TEST_FAILED;
450 		goto error_exit;
451 	}
452 
453 	if (!sessionless) {
454 		sess = rte_cryptodev_asym_session_create(ts_params->session_mpool);
455 		if (!sess) {
456 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
457 					"line %u "
458 					"FAILED: %s", __LINE__,
459 					"Session creation failed");
460 			status = TEST_FAILED;
461 			goto error_exit;
462 		}
463 
464 		if (rte_cryptodev_asym_session_init(dev_id, sess, &xform_tc,
465 				ts_params->session_mpool) < 0) {
466 			snprintf(test_msg, ASYM_TEST_MSG_LEN,
467 					"line %u FAILED: %s",
468 					__LINE__, "unabled to config sym session");
469 			status = TEST_FAILED;
470 			goto error_exit;
471 		}
472 
473 		rte_crypto_op_attach_asym_session(op, sess);
474 	} else {
475 		asym_op->xform = &xform_tc;
476 		op->sess_type = RTE_CRYPTO_OP_SESSIONLESS;
477 	}
478 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
479 
480 	/* Process crypto operation */
481 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
482 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
483 				"line %u FAILED: %s",
484 				__LINE__, "Error sending packet for operation");
485 		status = TEST_FAILED;
486 		goto error_exit;
487 	}
488 
489 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
490 		rte_pause();
491 
492 	if (result_op == NULL) {
493 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
494 				"line %u FAILED: %s",
495 				__LINE__, "Failed to process asym crypto op");
496 		status = TEST_FAILED;
497 		goto error_exit;
498 	}
499 
500 	if (test_cryptodev_asym_ver(op, &xform_tc, data_tc, result_op) != TEST_SUCCESS) {
501 		snprintf(test_msg, ASYM_TEST_MSG_LEN,
502 			"line %u FAILED: %s",
503 			__LINE__, "Verification failed ");
504 		status = TEST_FAILED;
505 		goto error_exit;
506 	}
507 
508 	if (!sessionless)
509 		snprintf(test_msg, ASYM_TEST_MSG_LEN, "PASS");
510 	else
511 		snprintf(test_msg, ASYM_TEST_MSG_LEN, "SESSIONLESS PASS");
512 
513 error_exit:
514 		if (sess != NULL) {
515 			rte_cryptodev_asym_session_clear(dev_id, sess);
516 			rte_cryptodev_asym_session_free(sess);
517 		}
518 
519 		if (op != NULL)
520 			rte_crypto_op_free(op);
521 
522 		if (result != NULL)
523 			rte_free(result);
524 
525 	return status;
526 }
527 
528 static int
529 test_one_case(const void *test_case, int sessionless)
530 {
531 	int status = TEST_SUCCESS, i = 0;
532 	char test_msg[ASYM_TEST_MSG_LEN + 1];
533 
534 	/* Map the case to union */
535 	union test_case_structure tc;
536 	memcpy(&tc, test_case, sizeof(tc));
537 
538 	if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX
539 			|| tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
540 		status = test_cryptodev_asym_op(&testsuite_params, &tc, test_msg,
541 				sessionless, 0, 0);
542 		printf("  %u) TestCase %s %s\n", test_index++,
543 			tc.modex.description, test_msg);
544 	} else {
545 		for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
546 			if (tc.modex.xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
547 				if (tc.rsa_data.op_type_flags & (1 << i)) {
548 					if (tc.rsa_data.key_exp) {
549 						status = test_cryptodev_asym_op(
550 							&testsuite_params, &tc,
551 							test_msg, sessionless, i,
552 							RTE_RSA_KEY_TYPE_EXP);
553 					}
554 					if (status)
555 						break;
556 					if (tc.rsa_data.key_qt && (i ==
557 							RTE_CRYPTO_ASYM_OP_DECRYPT ||
558 							i == RTE_CRYPTO_ASYM_OP_SIGN)) {
559 						status = test_cryptodev_asym_op(
560 							&testsuite_params,
561 							&tc, test_msg, sessionless, i,
562 							RTE_RSA_KET_TYPE_QT);
563 					}
564 					if (status)
565 						break;
566 				}
567 			}
568 		}
569 		printf("  %u) TestCase %s %s\n", test_index++,
570 			tc.modex.description, test_msg);
571 	}
572 
573 	return status;
574 }
575 
576 static int
577 load_test_vectors(void)
578 {
579 	uint32_t i = 0, v_size = 0;
580 	/* Load MODEX vector*/
581 	v_size = RTE_DIM(modex_test_case);
582 	for (i = 0; i < v_size; i++) {
583 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
584 			RTE_LOG(DEBUG, USER1,
585 				"TEST_VECTOR_SIZE too small\n");
586 			return -1;
587 		}
588 		test_vector.address[test_vector.size] = &modex_test_case[i];
589 		test_vector.size++;
590 	}
591 	/* Load MODINV vector*/
592 	v_size = RTE_DIM(modinv_test_case);
593 	for (i = 0; i < v_size; i++) {
594 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
595 			RTE_LOG(DEBUG, USER1,
596 				"TEST_VECTOR_SIZE too small\n");
597 			return -1;
598 		}
599 		test_vector.address[test_vector.size] = &modinv_test_case[i];
600 		test_vector.size++;
601 	}
602 	/* Load RSA vector*/
603 	v_size = RTE_DIM(rsa_test_case_list);
604 	for (i = 0; i < v_size; i++) {
605 		if (test_vector.size >= (TEST_VECTOR_SIZE)) {
606 			RTE_LOG(DEBUG, USER1,
607 				"TEST_VECTOR_SIZE too small\n");
608 			return -1;
609 		}
610 		test_vector.address[test_vector.size] = &rsa_test_case_list[i];
611 		test_vector.size++;
612 	}
613 	return 0;
614 }
615 
616 static int
617 test_one_by_one(void)
618 {
619 	int status = TEST_SUCCESS;
620 	struct crypto_testsuite_params *ts_params = &testsuite_params;
621 	uint32_t i = 0;
622 	uint8_t dev_id = ts_params->valid_devs[0];
623 	struct rte_cryptodev_info dev_info;
624 	int sessionless = 0;
625 
626 	rte_cryptodev_info_get(dev_id, &dev_info);
627 	if ((dev_info.feature_flags &
628 			RTE_CRYPTODEV_FF_ASYM_SESSIONLESS)) {
629 		sessionless = 1;
630 	}
631 
632 	/* Go through all test cases */
633 	test_index = 0;
634 	for (i = 0; i < test_vector.size; i++) {
635 		if (test_one_case(test_vector.address[i], 0) != TEST_SUCCESS)
636 			status = TEST_FAILED;
637 	}
638 	if (sessionless) {
639 		for (i = 0; i < test_vector.size; i++) {
640 			if (test_one_case(test_vector.address[i], 1)
641 					!= TEST_SUCCESS)
642 				status = TEST_FAILED;
643 		}
644 	}
645 
646 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
647 	return status;
648 }
649 
650 static int
651 test_rsa_sign_verify(void)
652 {
653 	struct crypto_testsuite_params *ts_params = &testsuite_params;
654 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
655 	uint8_t dev_id = ts_params->valid_devs[0];
656 	struct rte_cryptodev_asym_session *sess;
657 	struct rte_cryptodev_info dev_info;
658 	int status = TEST_SUCCESS;
659 
660 	/* Test case supports op with exponent key only,
661 	 * Check in PMD feature flag for RSA exponent key type support.
662 	 */
663 	rte_cryptodev_info_get(dev_id, &dev_info);
664 	if (!(dev_info.feature_flags &
665 				RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
666 		RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
667 			"exponent key type. Test Skipped\n");
668 		return -ENOTSUP;
669 	}
670 
671 	sess = rte_cryptodev_asym_session_create(sess_mpool);
672 
673 	if (!sess) {
674 		RTE_LOG(ERR, USER1, "Session creation failed for "
675 			"sign_verify\n");
676 		return TEST_FAILED;
677 	}
678 
679 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
680 				sess_mpool) < 0) {
681 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
682 			"sign_verify\n");
683 		status = TEST_FAILED;
684 		goto error_exit;
685 	}
686 
687 	status = queue_ops_rsa_sign_verify(sess);
688 
689 error_exit:
690 
691 	rte_cryptodev_asym_session_clear(dev_id, sess);
692 	rte_cryptodev_asym_session_free(sess);
693 
694 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
695 
696 	return status;
697 }
698 
699 static int
700 test_rsa_enc_dec(void)
701 {
702 	struct crypto_testsuite_params *ts_params = &testsuite_params;
703 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
704 	uint8_t dev_id = ts_params->valid_devs[0];
705 	struct rte_cryptodev_asym_session *sess;
706 	struct rte_cryptodev_info dev_info;
707 	int status = TEST_SUCCESS;
708 
709 	/* Test case supports op with exponent key only,
710 	 * Check in PMD feature flag for RSA exponent key type support.
711 	 */
712 	rte_cryptodev_info_get(dev_id, &dev_info);
713 	if (!(dev_info.feature_flags &
714 				RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
715 		RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
716 			"exponent key type. Test skipped\n");
717 		return -ENOTSUP;
718 	}
719 
720 	sess = rte_cryptodev_asym_session_create(sess_mpool);
721 
722 	if (!sess) {
723 		RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
724 		return TEST_FAILED;
725 	}
726 
727 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform,
728 				sess_mpool) < 0) {
729 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
730 			"enc_dec\n");
731 		status = TEST_FAILED;
732 		goto error_exit;
733 	}
734 
735 	status = queue_ops_rsa_enc_dec(sess);
736 
737 error_exit:
738 
739 	rte_cryptodev_asym_session_clear(dev_id, sess);
740 	rte_cryptodev_asym_session_free(sess);
741 
742 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
743 
744 	return status;
745 }
746 
747 static int
748 test_rsa_sign_verify_crt(void)
749 {
750 	struct crypto_testsuite_params *ts_params = &testsuite_params;
751 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
752 	uint8_t dev_id = ts_params->valid_devs[0];
753 	struct rte_cryptodev_asym_session *sess;
754 	struct rte_cryptodev_info dev_info;
755 	int status = TEST_SUCCESS;
756 
757 	/* Test case supports op with quintuple format key only,
758 	 * Check im PMD feature flag for RSA quintuple key type support.
759 	 */
760 	rte_cryptodev_info_get(dev_id, &dev_info);
761 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
762 		RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
763 			"quintuple key type. Test skipped\n");
764 		return -ENOTSUP;
765 	}
766 
767 	sess = rte_cryptodev_asym_session_create(sess_mpool);
768 
769 	if (!sess) {
770 		RTE_LOG(ERR, USER1, "Session creation failed for "
771 			"sign_verify_crt\n");
772 		status = TEST_FAILED;
773 		return status;
774 	}
775 
776 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
777 				sess_mpool) < 0) {
778 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
779 			"sign_verify_crt\n");
780 		status = TEST_FAILED;
781 		goto error_exit;
782 	}
783 	status = queue_ops_rsa_sign_verify(sess);
784 
785 error_exit:
786 
787 	rte_cryptodev_asym_session_clear(dev_id, sess);
788 	rte_cryptodev_asym_session_free(sess);
789 
790 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
791 
792 	return status;
793 }
794 
795 static int
796 test_rsa_enc_dec_crt(void)
797 {
798 	struct crypto_testsuite_params *ts_params = &testsuite_params;
799 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
800 	uint8_t dev_id = ts_params->valid_devs[0];
801 	struct rte_cryptodev_asym_session *sess;
802 	struct rte_cryptodev_info dev_info;
803 	int status = TEST_SUCCESS;
804 
805 	/* Test case supports op with quintuple format key only,
806 	 * Check in PMD feature flag for RSA quintuple key type support.
807 	 */
808 	rte_cryptodev_info_get(dev_id, &dev_info);
809 	if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
810 		RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
811 			"quintuple key type. Test skipped\n");
812 		return -ENOTSUP;
813 	}
814 
815 	sess = rte_cryptodev_asym_session_create(sess_mpool);
816 
817 	if (!sess) {
818 		RTE_LOG(ERR, USER1, "Session creation failed for "
819 			"enc_dec_crt\n");
820 		return TEST_FAILED;
821 	}
822 
823 	if (rte_cryptodev_asym_session_init(dev_id, sess, &rsa_xform_crt,
824 				sess_mpool) < 0) {
825 		RTE_LOG(ERR, USER1, "Unable to config asym session for "
826 			"enc_dec_crt\n");
827 		status = TEST_FAILED;
828 		goto error_exit;
829 	}
830 	status = queue_ops_rsa_enc_dec(sess);
831 
832 error_exit:
833 
834 	rte_cryptodev_asym_session_clear(dev_id, sess);
835 	rte_cryptodev_asym_session_free(sess);
836 
837 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
838 
839 	return status;
840 }
841 
842 static int
843 testsuite_setup(void)
844 {
845 	struct crypto_testsuite_params *ts_params = &testsuite_params;
846 	uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
847 	struct rte_cryptodev_info info;
848 	int ret, dev_id = -1;
849 	uint32_t i, nb_devs;
850 	uint16_t qp_id;
851 
852 	memset(ts_params, 0, sizeof(*ts_params));
853 
854 	test_vector.size = 0;
855 	load_test_vectors();
856 
857 	ts_params->op_mpool = rte_crypto_op_pool_create(
858 			"CRYPTO_ASYM_OP_POOL",
859 			RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
860 			TEST_NUM_BUFS, 0,
861 			0,
862 			rte_socket_id());
863 	if (ts_params->op_mpool == NULL) {
864 		RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
865 		return TEST_FAILED;
866 	}
867 
868 	/* Create an OPENSSL device if required */
869 	if (gbl_driver_id == rte_cryptodev_driver_id_get(
870 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
871 		nb_devs = rte_cryptodev_device_count_by_driver(
872 				rte_cryptodev_driver_id_get(
873 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
874 		if (nb_devs < 1) {
875 			ret = rte_vdev_init(
876 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
877 				NULL);
878 
879 			TEST_ASSERT(ret == 0, "Failed to create "
880 				"instance of pmd : %s",
881 				RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
882 		}
883 	}
884 
885 	/* Get list of valid crypto devs */
886 	nb_devs = rte_cryptodev_devices_get(
887 				rte_cryptodev_driver_name_get(gbl_driver_id),
888 				valid_devs, RTE_CRYPTO_MAX_DEVS);
889 	if (nb_devs < 1) {
890 		RTE_LOG(ERR, USER1, "No crypto devices found?\n");
891 		return TEST_FAILED;
892 	}
893 
894 	/*
895 	 * Get first valid asymmetric device found in test suite param and
896 	 * break
897 	 */
898 	for (i = 0; i < nb_devs ; i++) {
899 		rte_cryptodev_info_get(valid_devs[i], &info);
900 		if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
901 			dev_id = ts_params->valid_devs[0] = valid_devs[i];
902 			break;
903 		}
904 	}
905 
906 	if (dev_id == -1) {
907 		RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
908 			"Test skipped.\n");
909 		return TEST_FAILED;
910 	}
911 
912 	/* Set valid device count */
913 	ts_params->valid_dev_count = nb_devs;
914 
915 	/* configure device with num qp */
916 	ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
917 	ts_params->conf.socket_id = SOCKET_ID_ANY;
918 	ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
919 			RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
920 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
921 			&ts_params->conf),
922 			"Failed to configure cryptodev %u with %u qps",
923 			dev_id, ts_params->conf.nb_queue_pairs);
924 
925 	/* configure qp */
926 	ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
927 	ts_params->qp_conf.mp_session = ts_params->session_mpool;
928 	ts_params->qp_conf.mp_session_private = ts_params->session_mpool;
929 	for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
930 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
931 			dev_id, qp_id, &ts_params->qp_conf,
932 			rte_cryptodev_socket_id(dev_id)),
933 			"Failed to setup queue pair %u on cryptodev %u ASYM",
934 			qp_id, dev_id);
935 	}
936 
937 	/* setup asym session pool */
938 	unsigned int session_size = RTE_MAX(
939 		rte_cryptodev_asym_get_private_session_size(dev_id),
940 		rte_cryptodev_asym_get_header_session_size());
941 	/*
942 	 * Create mempool with TEST_NUM_SESSIONS * 2,
943 	 * to include the session headers
944 	 */
945 	ts_params->session_mpool = rte_mempool_create(
946 				"test_asym_sess_mp",
947 				TEST_NUM_SESSIONS * 2,
948 				session_size,
949 				0, 0, NULL, NULL, NULL,
950 				NULL, SOCKET_ID_ANY,
951 				0);
952 
953 	TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
954 			"session mempool allocation failed");
955 
956 	return TEST_SUCCESS;
957 }
958 
959 static void
960 testsuite_teardown(void)
961 {
962 	struct crypto_testsuite_params *ts_params = &testsuite_params;
963 
964 	if (ts_params->op_mpool != NULL) {
965 		RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
966 		rte_mempool_avail_count(ts_params->op_mpool));
967 	}
968 
969 	/* Free session mempools */
970 	if (ts_params->session_mpool != NULL) {
971 		rte_mempool_free(ts_params->session_mpool);
972 		ts_params->session_mpool = NULL;
973 	}
974 }
975 
976 static int
977 ut_setup(void)
978 {
979 	struct crypto_testsuite_params *ts_params = &testsuite_params;
980 
981 	uint16_t qp_id;
982 
983 	/* Reconfigure device to default parameters */
984 	ts_params->conf.socket_id = SOCKET_ID_ANY;
985 
986 	TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
987 			&ts_params->conf),
988 			"Failed to configure cryptodev %u",
989 			ts_params->valid_devs[0]);
990 
991 	for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
992 		TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
993 			ts_params->valid_devs[0], qp_id,
994 			&ts_params->qp_conf,
995 			rte_cryptodev_socket_id(ts_params->valid_devs[0])),
996 			"Failed to setup queue pair %u on cryptodev %u",
997 			qp_id, ts_params->valid_devs[0]);
998 	}
999 
1000 	rte_cryptodev_stats_reset(ts_params->valid_devs[0]);
1001 
1002 	/* Start the device */
1003 	TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
1004 						"Failed to start cryptodev %u",
1005 						ts_params->valid_devs[0]);
1006 
1007 	return TEST_SUCCESS;
1008 }
1009 
1010 static void
1011 ut_teardown(void)
1012 {
1013 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1014 	struct rte_cryptodev_stats stats;
1015 
1016 	rte_cryptodev_stats_get(ts_params->valid_devs[0], &stats);
1017 
1018 	/* Stop the device */
1019 	rte_cryptodev_stop(ts_params->valid_devs[0]);
1020 }
1021 
1022 static inline void print_asym_capa(
1023 		const struct rte_cryptodev_asymmetric_xform_capability *capa)
1024 {
1025 	int i = 0;
1026 
1027 	printf("\nxform type: %s\n===================\n",
1028 			rte_crypto_asym_xform_strings[capa->xform_type]);
1029 	printf("operation supported -");
1030 
1031 	for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
1032 		/* check supported operations */
1033 		if (rte_cryptodev_asym_xform_capability_check_optype(capa, i))
1034 			printf(" %s",
1035 					rte_crypto_asym_op_strings[i]);
1036 		}
1037 		switch (capa->xform_type) {
1038 		case RTE_CRYPTO_ASYM_XFORM_RSA:
1039 		case RTE_CRYPTO_ASYM_XFORM_MODINV:
1040 		case RTE_CRYPTO_ASYM_XFORM_MODEX:
1041 		case RTE_CRYPTO_ASYM_XFORM_DH:
1042 		case RTE_CRYPTO_ASYM_XFORM_DSA:
1043 			printf(" modlen: min %d max %d increment %d",
1044 					capa->modlen.min,
1045 					capa->modlen.max,
1046 					capa->modlen.increment);
1047 		break;
1048 		case RTE_CRYPTO_ASYM_XFORM_ECDSA:
1049 		case RTE_CRYPTO_ASYM_XFORM_ECPM:
1050 		default:
1051 			break;
1052 		}
1053 		printf("\n");
1054 }
1055 
1056 static int
1057 test_capability(void)
1058 {
1059 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1060 	uint8_t dev_id = ts_params->valid_devs[0];
1061 	struct rte_cryptodev_info dev_info;
1062 	const struct rte_cryptodev_capabilities *dev_capa;
1063 	int i = 0;
1064 	struct rte_cryptodev_asym_capability_idx idx;
1065 	const struct rte_cryptodev_asymmetric_xform_capability *capa;
1066 
1067 	rte_cryptodev_info_get(dev_id, &dev_info);
1068 	if (!(dev_info.feature_flags &
1069 				RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
1070 		RTE_LOG(INFO, USER1,
1071 				"Device doesn't support asymmetric. Test Skipped\n");
1072 		return TEST_SUCCESS;
1073 	}
1074 
1075 	/* print xform capability */
1076 	for (i = 0;
1077 		dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
1078 		i++) {
1079 		dev_capa = &(dev_info.capabilities[i]);
1080 		if (dev_info.capabilities[i].op ==
1081 				RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
1082 			idx.type = dev_capa->asym.xform_capa.xform_type;
1083 
1084 			capa = rte_cryptodev_asym_capability_get(dev_id,
1085 				(const struct
1086 				rte_cryptodev_asym_capability_idx *) &idx);
1087 			print_asym_capa(capa);
1088 			}
1089 	}
1090 	return TEST_SUCCESS;
1091 }
1092 
1093 static int
1094 test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
1095 {
1096 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1097 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1098 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1099 	uint8_t dev_id = ts_params->valid_devs[0];
1100 	struct rte_crypto_asym_op *asym_op = NULL;
1101 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1102 	struct rte_cryptodev_asym_session *sess = NULL;
1103 	int status = TEST_SUCCESS;
1104 	uint8_t output[TEST_DH_MOD_LEN];
1105 	struct rte_crypto_asym_xform xform = *xfrm;
1106 	uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
1107 
1108 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1109 	if (sess == NULL) {
1110 		RTE_LOG(ERR, USER1,
1111 				"line %u FAILED: %s", __LINE__,
1112 				"Session creation failed");
1113 		status = TEST_FAILED;
1114 		goto error_exit;
1115 	}
1116 	/* set up crypto op data structure */
1117 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1118 	if (!op) {
1119 		RTE_LOG(ERR, USER1,
1120 			"line %u FAILED: %s",
1121 			__LINE__, "Failed to allocate asymmetric crypto "
1122 			"operation struct");
1123 		status = TEST_FAILED;
1124 		goto error_exit;
1125 	}
1126 	asym_op = op->asym;
1127 
1128 	/* Setup a xform and op to generate private key only */
1129 	xform.dh.type = RTE_CRYPTO_ASYM_OP_SHARED_SECRET_COMPUTE;
1130 	xform.next = NULL;
1131 	asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
1132 	asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
1133 	asym_op->dh.pub_key.data = (uint8_t *)peer;
1134 	asym_op->dh.pub_key.length = sizeof(peer);
1135 	asym_op->dh.shared_secret.data = output;
1136 	asym_op->dh.shared_secret.length = sizeof(output);
1137 
1138 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1139 			sess_mpool) < 0) {
1140 		RTE_LOG(ERR, USER1,
1141 				"line %u FAILED: %s",
1142 				__LINE__, "unabled to config sym session");
1143 		status = TEST_FAILED;
1144 		goto error_exit;
1145 	}
1146 
1147 	/* attach asymmetric crypto session to crypto operations */
1148 	rte_crypto_op_attach_asym_session(op, sess);
1149 
1150 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1151 
1152 	/* Process crypto operation */
1153 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1154 		RTE_LOG(ERR, USER1,
1155 			"line %u FAILED: %s",
1156 			__LINE__, "Error sending packet for operation");
1157 		status = TEST_FAILED;
1158 		goto error_exit;
1159 	}
1160 
1161 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1162 		rte_pause();
1163 
1164 	if (result_op == NULL) {
1165 		RTE_LOG(ERR, USER1,
1166 			"line %u FAILED: %s",
1167 			__LINE__, "Failed to process asym crypto op");
1168 		status = TEST_FAILED;
1169 		goto error_exit;
1170 	}
1171 
1172 	debug_hexdump(stdout, "shared secret:",
1173 			asym_op->dh.shared_secret.data,
1174 			asym_op->dh.shared_secret.length);
1175 
1176 error_exit:
1177 	if (sess != NULL) {
1178 		rte_cryptodev_asym_session_clear(dev_id, sess);
1179 		rte_cryptodev_asym_session_free(sess);
1180 	}
1181 	if (op != NULL)
1182 		rte_crypto_op_free(op);
1183 	return status;
1184 }
1185 
1186 static int
1187 test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
1188 {
1189 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1190 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1191 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1192 	uint8_t dev_id = ts_params->valid_devs[0];
1193 	struct rte_crypto_asym_op *asym_op = NULL;
1194 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1195 	struct rte_cryptodev_asym_session *sess = NULL;
1196 	int status = TEST_SUCCESS;
1197 	uint8_t output[TEST_DH_MOD_LEN];
1198 	struct rte_crypto_asym_xform xform = *xfrm;
1199 
1200 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1201 	if (sess == NULL) {
1202 		RTE_LOG(ERR, USER1,
1203 				 "line %u FAILED: %s", __LINE__,
1204 				"Session creation failed");
1205 		status = TEST_FAILED;
1206 		goto error_exit;
1207 	}
1208 	/* set up crypto op data structure */
1209 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1210 	if (!op) {
1211 		RTE_LOG(ERR, USER1,
1212 			"line %u FAILED: %s",
1213 			__LINE__, "Failed to allocate asymmetric crypto "
1214 			"operation struct");
1215 		status = TEST_FAILED;
1216 		goto error_exit;
1217 	}
1218 	asym_op = op->asym;
1219 
1220 	/* Setup a xform and op to generate private key only */
1221 	xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1222 	xform.next = NULL;
1223 	asym_op->dh.priv_key.data = output;
1224 	asym_op->dh.priv_key.length = sizeof(output);
1225 
1226 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1227 			sess_mpool) < 0) {
1228 		RTE_LOG(ERR, USER1,
1229 				"line %u FAILED: %s",
1230 				__LINE__, "unabled to config sym session");
1231 		status = TEST_FAILED;
1232 		goto error_exit;
1233 	}
1234 
1235 	/* attach asymmetric crypto session to crypto operations */
1236 	rte_crypto_op_attach_asym_session(op, sess);
1237 
1238 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1239 
1240 	/* Process crypto operation */
1241 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1242 		RTE_LOG(ERR, USER1,
1243 			"line %u FAILED: %s",
1244 			__LINE__, "Error sending packet for operation");
1245 		status = TEST_FAILED;
1246 		goto error_exit;
1247 	}
1248 
1249 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1250 		rte_pause();
1251 
1252 	if (result_op == NULL) {
1253 		RTE_LOG(ERR, USER1,
1254 			"line %u FAILED: %s",
1255 			__LINE__, "Failed to process asym crypto op");
1256 		status = TEST_FAILED;
1257 		goto error_exit;
1258 	}
1259 
1260 	debug_hexdump(stdout, "private key:",
1261 			asym_op->dh.priv_key.data,
1262 			asym_op->dh.priv_key.length);
1263 
1264 
1265 error_exit:
1266 	if (sess != NULL) {
1267 		rte_cryptodev_asym_session_clear(dev_id, sess);
1268 		rte_cryptodev_asym_session_free(sess);
1269 	}
1270 	if (op != NULL)
1271 		rte_crypto_op_free(op);
1272 
1273 	return status;
1274 }
1275 
1276 
1277 static int
1278 test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
1279 {
1280 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1281 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1282 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1283 	uint8_t dev_id = ts_params->valid_devs[0];
1284 	struct rte_crypto_asym_op *asym_op = NULL;
1285 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1286 	struct rte_cryptodev_asym_session *sess = NULL;
1287 	int status = TEST_SUCCESS;
1288 	uint8_t output[TEST_DH_MOD_LEN];
1289 	struct rte_crypto_asym_xform xform = *xfrm;
1290 
1291 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1292 	if (sess == NULL) {
1293 		RTE_LOG(ERR, USER1,
1294 				 "line %u FAILED: %s", __LINE__,
1295 				"Session creation failed");
1296 		status = TEST_FAILED;
1297 		goto error_exit;
1298 	}
1299 	/* set up crypto op data structure */
1300 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1301 	if (!op) {
1302 		RTE_LOG(ERR, USER1,
1303 			"line %u FAILED: %s",
1304 			__LINE__, "Failed to allocate asymmetric crypto "
1305 			"operation struct");
1306 		status = TEST_FAILED;
1307 		goto error_exit;
1308 	}
1309 	asym_op = op->asym;
1310 	/* Setup a xform chain to generate public key
1311 	 * using test private key
1312 	 *
1313 	 */
1314 	xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1315 	xform.next = NULL;
1316 
1317 	asym_op->dh.pub_key.data = output;
1318 	asym_op->dh.pub_key.length = sizeof(output);
1319 	/* load pre-defined private key */
1320 	asym_op->dh.priv_key.data = rte_malloc(NULL,
1321 					dh_test_params.priv_key.length,
1322 					0);
1323 	asym_op->dh.priv_key = dh_test_params.priv_key;
1324 
1325 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1326 			sess_mpool) < 0) {
1327 		RTE_LOG(ERR, USER1,
1328 				"line %u FAILED: %s",
1329 				__LINE__, "unabled to config sym session");
1330 		status = TEST_FAILED;
1331 		goto error_exit;
1332 	}
1333 
1334 	/* attach asymmetric crypto session to crypto operations */
1335 	rte_crypto_op_attach_asym_session(op, sess);
1336 
1337 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1338 
1339 	/* Process crypto operation */
1340 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1341 		RTE_LOG(ERR, USER1,
1342 			"line %u FAILED: %s",
1343 			__LINE__, "Error sending packet for operation");
1344 		status = TEST_FAILED;
1345 		goto error_exit;
1346 	}
1347 
1348 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1349 		rte_pause();
1350 
1351 	if (result_op == NULL) {
1352 		RTE_LOG(ERR, USER1,
1353 			"line %u FAILED: %s",
1354 			__LINE__, "Failed to process asym crypto op");
1355 		status = TEST_FAILED;
1356 		goto error_exit;
1357 	}
1358 
1359 	debug_hexdump(stdout, "pub key:",
1360 			asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
1361 
1362 	debug_hexdump(stdout, "priv key:",
1363 			asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
1364 
1365 error_exit:
1366 	if (sess != NULL) {
1367 		rte_cryptodev_asym_session_clear(dev_id, sess);
1368 		rte_cryptodev_asym_session_free(sess);
1369 	}
1370 	if (op != NULL)
1371 		rte_crypto_op_free(op);
1372 
1373 	return status;
1374 }
1375 
1376 static int
1377 test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
1378 {
1379 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1380 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1381 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1382 	uint8_t dev_id = ts_params->valid_devs[0];
1383 	struct rte_crypto_asym_op *asym_op = NULL;
1384 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1385 	struct rte_cryptodev_asym_session *sess = NULL;
1386 	int status = TEST_SUCCESS;
1387 	uint8_t out_pub_key[TEST_DH_MOD_LEN];
1388 	uint8_t out_prv_key[TEST_DH_MOD_LEN];
1389 	struct rte_crypto_asym_xform pub_key_xform;
1390 	struct rte_crypto_asym_xform xform = *xfrm;
1391 
1392 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1393 	if (sess == NULL) {
1394 		RTE_LOG(ERR, USER1,
1395 				 "line %u FAILED: %s", __LINE__,
1396 				"Session creation failed");
1397 		status = TEST_FAILED;
1398 		goto error_exit;
1399 	}
1400 
1401 	/* set up crypto op data structure */
1402 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1403 	if (!op) {
1404 		RTE_LOG(ERR, USER1,
1405 			"line %u FAILED: %s",
1406 			__LINE__, "Failed to allocate asymmetric crypto "
1407 			"operation struct");
1408 		status = TEST_FAILED;
1409 		goto error_exit;
1410 	}
1411 	asym_op = op->asym;
1412 	/* Setup a xform chain to generate
1413 	 * private key first followed by
1414 	 * public key
1415 	 */xform.dh.type = RTE_CRYPTO_ASYM_OP_PRIVATE_KEY_GENERATE;
1416 	pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
1417 	pub_key_xform.dh.type = RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE;
1418 	xform.next = &pub_key_xform;
1419 
1420 	asym_op->dh.pub_key.data = out_pub_key;
1421 	asym_op->dh.pub_key.length = sizeof(out_pub_key);
1422 	asym_op->dh.priv_key.data = out_prv_key;
1423 	asym_op->dh.priv_key.length = sizeof(out_prv_key);
1424 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1425 			sess_mpool) < 0) {
1426 		RTE_LOG(ERR, USER1,
1427 				"line %u FAILED: %s",
1428 				__LINE__, "unabled to config sym session");
1429 		status = TEST_FAILED;
1430 		goto error_exit;
1431 	}
1432 
1433 	/* attach asymmetric crypto session to crypto operations */
1434 	rte_crypto_op_attach_asym_session(op, sess);
1435 
1436 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1437 
1438 	/* Process crypto operation */
1439 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1440 		RTE_LOG(ERR, USER1,
1441 			"line %u FAILED: %s",
1442 			__LINE__, "Error sending packet for operation");
1443 		status = TEST_FAILED;
1444 		goto error_exit;
1445 	}
1446 
1447 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1448 		rte_pause();
1449 
1450 	if (result_op == NULL) {
1451 		RTE_LOG(ERR, USER1,
1452 			"line %u FAILED: %s",
1453 			__LINE__, "Failed to process asym crypto op");
1454 		status = TEST_FAILED;
1455 		goto error_exit;
1456 	}
1457 	debug_hexdump(stdout, "priv key:",
1458 			out_prv_key, asym_op->dh.priv_key.length);
1459 	debug_hexdump(stdout, "pub key:",
1460 			out_pub_key, asym_op->dh.pub_key.length);
1461 
1462 error_exit:
1463 	if (sess != NULL) {
1464 		rte_cryptodev_asym_session_clear(dev_id, sess);
1465 		rte_cryptodev_asym_session_free(sess);
1466 	}
1467 	if (op != NULL)
1468 		rte_crypto_op_free(op);
1469 
1470 	return status;
1471 }
1472 
1473 static int
1474 test_mod_inv(void)
1475 {
1476 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1477 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1478 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1479 	uint8_t dev_id = ts_params->valid_devs[0];
1480 	struct rte_crypto_asym_op *asym_op = NULL;
1481 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1482 	struct rte_cryptodev_asym_session *sess = NULL;
1483 	int status = TEST_SUCCESS;
1484 	struct rte_cryptodev_asym_capability_idx cap_idx;
1485 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
1486 	uint8_t input[TEST_DATA_SIZE] = {0};
1487 	int ret = 0;
1488 	uint8_t result[sizeof(mod_p)] = { 0 };
1489 
1490 	if (rte_cryptodev_asym_get_xform_enum(
1491 		&modinv_xform.xform_type, "modinv") < 0) {
1492 		RTE_LOG(ERR, USER1,
1493 				 "Invalid ASYM algorithm specified\n");
1494 		return -1;
1495 	}
1496 
1497 	cap_idx.type = modinv_xform.xform_type;
1498 	capability = rte_cryptodev_asym_capability_get(dev_id,
1499 					&cap_idx);
1500 
1501 	if (capability == NULL) {
1502 		RTE_LOG(INFO, USER1,
1503 			"Device doesn't support MOD INV. Test Skipped\n");
1504 		return -ENOTSUP;
1505 	}
1506 
1507 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1508 		capability,
1509 		modinv_xform.modinv.modulus.length)) {
1510 		RTE_LOG(ERR, USER1,
1511 				 "Invalid MODULUS length specified\n");
1512 				return -ENOTSUP;
1513 		}
1514 
1515 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1516 	if (!sess) {
1517 		RTE_LOG(ERR, USER1, "line %u "
1518 				"FAILED: %s", __LINE__,
1519 				"Session creation failed");
1520 		status = TEST_FAILED;
1521 		goto error_exit;
1522 	}
1523 
1524 	if (rte_cryptodev_asym_session_init(dev_id, sess, &modinv_xform,
1525 			sess_mpool) < 0) {
1526 		RTE_LOG(ERR, USER1,
1527 				"line %u FAILED: %s",
1528 				__LINE__, "unabled to config sym session");
1529 		status = TEST_FAILED;
1530 		goto error_exit;
1531 	}
1532 
1533 	/* generate crypto op data structure */
1534 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1535 	if (!op) {
1536 		RTE_LOG(ERR, USER1,
1537 			"line %u FAILED: %s",
1538 			__LINE__, "Failed to allocate asymmetric crypto "
1539 			"operation struct");
1540 		status = TEST_FAILED;
1541 		goto error_exit;
1542 	}
1543 
1544 	asym_op = op->asym;
1545 	memcpy(input, base, sizeof(base));
1546 	asym_op->modinv.base.data = input;
1547 	asym_op->modinv.base.length = sizeof(base);
1548 	asym_op->modinv.result.data = result;
1549 	asym_op->modinv.result.length = sizeof(result);
1550 
1551 	/* attach asymmetric crypto session to crypto operations */
1552 	rte_crypto_op_attach_asym_session(op, sess);
1553 
1554 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1555 
1556 	/* Process crypto operation */
1557 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1558 		RTE_LOG(ERR, USER1,
1559 			"line %u FAILED: %s",
1560 			__LINE__, "Error sending packet for operation");
1561 		status = TEST_FAILED;
1562 		goto error_exit;
1563 	}
1564 
1565 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1566 		rte_pause();
1567 
1568 	if (result_op == NULL) {
1569 		RTE_LOG(ERR, USER1,
1570 				"line %u FAILED: %s",
1571 				__LINE__, "Failed to process asym crypto op");
1572 		status = TEST_FAILED;
1573 		goto error_exit;
1574 	}
1575 
1576 	ret = verify_modinv(mod_inv, result_op);
1577 	if (ret) {
1578 		RTE_LOG(ERR, USER1,
1579 			 "operation verification failed\n");
1580 		status = TEST_FAILED;
1581 	}
1582 
1583 error_exit:
1584 	if (sess) {
1585 		rte_cryptodev_asym_session_clear(dev_id, sess);
1586 		rte_cryptodev_asym_session_free(sess);
1587 	}
1588 
1589 	if (op)
1590 		rte_crypto_op_free(op);
1591 
1592 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1593 
1594 	return status;
1595 }
1596 
1597 static int
1598 test_mod_exp(void)
1599 {
1600 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1601 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1602 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1603 	uint8_t dev_id = ts_params->valid_devs[0];
1604 	struct rte_crypto_asym_op *asym_op = NULL;
1605 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1606 	struct rte_cryptodev_asym_session *sess = NULL;
1607 	int status = TEST_SUCCESS;
1608 	struct rte_cryptodev_asym_capability_idx cap_idx;
1609 	const struct rte_cryptodev_asymmetric_xform_capability *capability;
1610 	uint8_t input[TEST_DATA_SIZE] = {0};
1611 	int ret = 0;
1612 	uint8_t result[sizeof(mod_p)] = { 0 };
1613 
1614 	if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
1615 		"modexp")
1616 		< 0) {
1617 		RTE_LOG(ERR, USER1,
1618 				"Invalid ASYM algorithm specified\n");
1619 		return -1;
1620 	}
1621 
1622 	/* check for modlen capability */
1623 	cap_idx.type = modex_xform.xform_type;
1624 	capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
1625 
1626 	if (capability == NULL) {
1627 		RTE_LOG(INFO, USER1,
1628 			"Device doesn't support MOD EXP. Test Skipped\n");
1629 		return -ENOTSUP;
1630 	}
1631 
1632 	if (rte_cryptodev_asym_xform_capability_check_modlen(
1633 			capability, modex_xform.modex.modulus.length)) {
1634 		RTE_LOG(ERR, USER1,
1635 				"Invalid MODULUS length specified\n");
1636 				return -ENOTSUP;
1637 		}
1638 
1639 	/* generate crypto op data structure */
1640 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1641 	if (!op) {
1642 		RTE_LOG(ERR, USER1,
1643 			"line %u FAILED: %s",
1644 			__LINE__, "Failed to allocate asymmetric crypto "
1645 			"operation struct");
1646 		status = TEST_FAILED;
1647 		goto error_exit;
1648 	}
1649 
1650 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1651 	if (!sess) {
1652 		RTE_LOG(ERR, USER1,
1653 				 "line %u "
1654 				"FAILED: %s", __LINE__,
1655 				"Session creation failed");
1656 		status = TEST_FAILED;
1657 		goto error_exit;
1658 	}
1659 
1660 	if (rte_cryptodev_asym_session_init(dev_id, sess, &modex_xform,
1661 			sess_mpool) < 0) {
1662 		RTE_LOG(ERR, USER1,
1663 				"line %u FAILED: %s",
1664 				__LINE__, "unabled to config sym session");
1665 		status = TEST_FAILED;
1666 		goto error_exit;
1667 	}
1668 
1669 	asym_op = op->asym;
1670 	memcpy(input, base, sizeof(base));
1671 	asym_op->modex.base.data = input;
1672 	asym_op->modex.base.length = sizeof(base);
1673 	asym_op->modex.result.data = result;
1674 	asym_op->modex.result.length = sizeof(result);
1675 	/* attach asymmetric crypto session to crypto operations */
1676 	rte_crypto_op_attach_asym_session(op, sess);
1677 
1678 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1679 	/* Process crypto operation */
1680 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1681 		RTE_LOG(ERR, USER1,
1682 				"line %u FAILED: %s",
1683 				__LINE__, "Error sending packet for operation");
1684 		status = TEST_FAILED;
1685 		goto error_exit;
1686 	}
1687 
1688 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1689 		rte_pause();
1690 
1691 	if (result_op == NULL) {
1692 		RTE_LOG(ERR, USER1,
1693 				"line %u FAILED: %s",
1694 				__LINE__, "Failed to process asym crypto op");
1695 		status = TEST_FAILED;
1696 		goto error_exit;
1697 	}
1698 
1699 	ret = verify_modexp(mod_exp, result_op);
1700 	if (ret) {
1701 		RTE_LOG(ERR, USER1,
1702 			 "operation verification failed\n");
1703 		status = TEST_FAILED;
1704 	}
1705 
1706 error_exit:
1707 	if (sess != NULL) {
1708 		rte_cryptodev_asym_session_clear(dev_id, sess);
1709 		rte_cryptodev_asym_session_free(sess);
1710 	}
1711 
1712 	if (op != NULL)
1713 		rte_crypto_op_free(op);
1714 
1715 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1716 
1717 	return status;
1718 }
1719 
1720 static int
1721 test_dh_keygenration(void)
1722 {
1723 	int status;
1724 
1725 	debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
1726 	debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
1727 	debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
1728 			dh_test_params.priv_key.length);
1729 
1730 	RTE_LOG(INFO, USER1,
1731 		"Test Public and Private key pair generation\n");
1732 
1733 	status = test_dh_gen_kp(&dh_xform);
1734 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1735 
1736 	RTE_LOG(INFO, USER1,
1737 		"Test Public Key Generation using pre-defined priv key\n");
1738 
1739 	status = test_dh_gen_pub_key(&dh_xform);
1740 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1741 
1742 	RTE_LOG(INFO, USER1,
1743 		"Test Private Key Generation only\n");
1744 
1745 	status = test_dh_gen_priv_key(&dh_xform);
1746 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1747 
1748 	RTE_LOG(INFO, USER1,
1749 		"Test shared secret compute\n");
1750 
1751 	status = test_dh_gen_shared_sec(&dh_xform);
1752 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1753 
1754 	return status;
1755 }
1756 
1757 static int
1758 test_dsa_sign(void)
1759 {
1760 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1761 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1762 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1763 	uint8_t dev_id = ts_params->valid_devs[0];
1764 	struct rte_crypto_asym_op *asym_op = NULL;
1765 	struct rte_crypto_op *op = NULL, *result_op = NULL;
1766 	struct rte_cryptodev_asym_session *sess = NULL;
1767 	int status = TEST_SUCCESS;
1768 	uint8_t r[TEST_DH_MOD_LEN];
1769 	uint8_t s[TEST_DH_MOD_LEN];
1770 	uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
1771 
1772 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1773 	if (sess == NULL) {
1774 		RTE_LOG(ERR, USER1,
1775 				 "line %u FAILED: %s", __LINE__,
1776 				"Session creation failed");
1777 		status = TEST_FAILED;
1778 		goto error_exit;
1779 	}
1780 	/* set up crypto op data structure */
1781 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1782 	if (!op) {
1783 		RTE_LOG(ERR, USER1,
1784 			"line %u FAILED: %s",
1785 			__LINE__, "Failed to allocate asymmetric crypto "
1786 			"operation struct");
1787 		status = TEST_FAILED;
1788 		goto error_exit;
1789 	}
1790 	asym_op = op->asym;
1791 
1792 	debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
1793 			dsa_xform.dsa.p.length);
1794 	debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
1795 			dsa_xform.dsa.q.length);
1796 	debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
1797 			dsa_xform.dsa.g.length);
1798 	debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
1799 			dsa_xform.dsa.x.length);
1800 
1801 	if (rte_cryptodev_asym_session_init(dev_id, sess, &dsa_xform,
1802 				sess_mpool) < 0) {
1803 		RTE_LOG(ERR, USER1,
1804 				"line %u FAILED: %s",
1805 				__LINE__, "unabled to config sym session");
1806 		status = TEST_FAILED;
1807 		goto error_exit;
1808 	}
1809 
1810 	/* attach asymmetric crypto session to crypto operations */
1811 	rte_crypto_op_attach_asym_session(op, sess);
1812 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1813 	asym_op->dsa.message.data = dgst;
1814 	asym_op->dsa.message.length = sizeof(dgst);
1815 	asym_op->dsa.r.length = sizeof(r);
1816 	asym_op->dsa.r.data = r;
1817 	asym_op->dsa.s.length = sizeof(s);
1818 	asym_op->dsa.s.data = s;
1819 
1820 	RTE_LOG(DEBUG, USER1, "Process ASYM operation");
1821 
1822 	/* Process crypto operation */
1823 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1824 		RTE_LOG(ERR, USER1,
1825 			"line %u FAILED: %s",
1826 			__LINE__, "Error sending packet for operation");
1827 		status = TEST_FAILED;
1828 		goto error_exit;
1829 	}
1830 
1831 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1832 		rte_pause();
1833 
1834 	if (result_op == NULL) {
1835 		RTE_LOG(ERR, USER1,
1836 			"line %u FAILED: %s",
1837 			__LINE__, "Failed to process asym crypto op");
1838 		status = TEST_FAILED;
1839 		goto error_exit;
1840 	}
1841 
1842 	asym_op = result_op->asym;
1843 
1844 	debug_hexdump(stdout, "r:",
1845 			asym_op->dsa.r.data, asym_op->dsa.r.length);
1846 	debug_hexdump(stdout, "s:",
1847 			asym_op->dsa.s.data, asym_op->dsa.s.length);
1848 
1849 	/* Test PMD DSA sign verification using signer public key */
1850 	asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
1851 
1852 	/* copy signer public key */
1853 	asym_op->dsa.y.data = dsa_test_params.y.data;
1854 	asym_op->dsa.y.length = dsa_test_params.y.length;
1855 
1856 	/* Process crypto operation */
1857 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
1858 		RTE_LOG(ERR, USER1,
1859 			"line %u FAILED: %s",
1860 			__LINE__, "Error sending packet for operation");
1861 		status = TEST_FAILED;
1862 		goto error_exit;
1863 	}
1864 
1865 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
1866 		rte_pause();
1867 
1868 	if (result_op == NULL) {
1869 		RTE_LOG(ERR, USER1,
1870 			"line %u FAILED: %s",
1871 			__LINE__, "Failed to process asym crypto op");
1872 		status = TEST_FAILED;
1873 		goto error_exit;
1874 	}
1875 
1876 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
1877 		RTE_LOG(ERR, USER1,
1878 				"line %u FAILED: %s",
1879 				__LINE__, "Failed to process asym crypto op");
1880 		status = TEST_FAILED;
1881 	}
1882 error_exit:
1883 	if (sess != NULL) {
1884 		rte_cryptodev_asym_session_clear(dev_id, sess);
1885 		rte_cryptodev_asym_session_free(sess);
1886 	}
1887 	if (op != NULL)
1888 		rte_crypto_op_free(op);
1889 	return status;
1890 }
1891 
1892 static int
1893 test_dsa(void)
1894 {
1895 	int status;
1896 	status = test_dsa_sign();
1897 	TEST_ASSERT_EQUAL(status, 0, "Test failed");
1898 	return status;
1899 }
1900 
1901 static int
1902 test_ecdsa_sign_verify(enum curve curve_id)
1903 {
1904 	struct crypto_testsuite_params *ts_params = &testsuite_params;
1905 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
1906 	struct rte_mempool *op_mpool = ts_params->op_mpool;
1907 	struct crypto_testsuite_ecdsa_params input_params;
1908 	struct rte_cryptodev_asym_session *sess = NULL;
1909 	uint8_t dev_id = ts_params->valid_devs[0];
1910 	struct rte_crypto_op *result_op = NULL;
1911 	uint8_t output_buf_r[TEST_DATA_SIZE];
1912 	uint8_t output_buf_s[TEST_DATA_SIZE];
1913 	struct rte_crypto_asym_xform xform;
1914 	struct rte_crypto_asym_op *asym_op;
1915 	struct rte_cryptodev_info dev_info;
1916 	struct rte_crypto_op *op = NULL;
1917 	int status = TEST_SUCCESS, ret;
1918 
1919 	switch (curve_id) {
1920 	case SECP192R1:
1921 		input_params = ecdsa_param_secp192r1;
1922 		break;
1923 	case SECP224R1:
1924 		input_params = ecdsa_param_secp224r1;
1925 		break;
1926 	case SECP256R1:
1927 		input_params = ecdsa_param_secp256r1;
1928 		break;
1929 	case SECP384R1:
1930 		input_params = ecdsa_param_secp384r1;
1931 		break;
1932 	case SECP521R1:
1933 		input_params = ecdsa_param_secp521r1;
1934 		break;
1935 	default:
1936 		RTE_LOG(ERR, USER1,
1937 				"line %u FAILED: %s", __LINE__,
1938 				"Unsupported curve id\n");
1939 		status = TEST_FAILED;
1940 		goto exit;
1941 	}
1942 
1943 	rte_cryptodev_info_get(dev_id, &dev_info);
1944 
1945 	sess = rte_cryptodev_asym_session_create(sess_mpool);
1946 	if (sess == NULL) {
1947 		RTE_LOG(ERR, USER1,
1948 				"line %u FAILED: %s", __LINE__,
1949 				"Session creation failed\n");
1950 		status = TEST_FAILED;
1951 		goto exit;
1952 	}
1953 
1954 	/* Setup crypto op data structure */
1955 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
1956 	if (op == NULL) {
1957 		RTE_LOG(ERR, USER1,
1958 				"line %u FAILED: %s", __LINE__,
1959 				"Failed to allocate asymmetric crypto "
1960 				"operation struct\n");
1961 		status = TEST_FAILED;
1962 		goto exit;
1963 	}
1964 	asym_op = op->asym;
1965 
1966 	/* Setup asym xform */
1967 	xform.next = NULL;
1968 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
1969 	xform.ec.curve_id = input_params.curve;
1970 
1971 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
1972 				sess_mpool) < 0) {
1973 		RTE_LOG(ERR, USER1,
1974 				"line %u FAILED: %s", __LINE__,
1975 				"Unable to config asym session\n");
1976 		status = TEST_FAILED;
1977 		goto exit;
1978 	}
1979 
1980 	/* Attach asymmetric crypto session to crypto operations */
1981 	rte_crypto_op_attach_asym_session(op, sess);
1982 
1983 	/* Compute sign */
1984 
1985 	/* Populate op with operational details */
1986 	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
1987 	op->asym->ecdsa.message.data = input_params.digest.data;
1988 	op->asym->ecdsa.message.length = input_params.digest.length;
1989 	op->asym->ecdsa.k.data = input_params.scalar.data;
1990 	op->asym->ecdsa.k.length = input_params.scalar.length;
1991 	op->asym->ecdsa.pkey.data = input_params.pkey.data;
1992 	op->asym->ecdsa.pkey.length = input_params.pkey.length;
1993 
1994 	/* Init out buf */
1995 	op->asym->ecdsa.r.data = output_buf_r;
1996 	op->asym->ecdsa.s.data = output_buf_s;
1997 
1998 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
1999 
2000 	/* Process crypto operation */
2001 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2002 		RTE_LOG(ERR, USER1,
2003 				"line %u FAILED: %s", __LINE__,
2004 				"Error sending packet for operation\n");
2005 		status = TEST_FAILED;
2006 		goto exit;
2007 	}
2008 
2009 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2010 		rte_pause();
2011 
2012 	if (result_op == NULL) {
2013 		RTE_LOG(ERR, USER1,
2014 				"line %u FAILED: %s", __LINE__,
2015 				"Failed to process asym crypto op\n");
2016 		status = TEST_FAILED;
2017 		goto exit;
2018 	}
2019 
2020 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2021 		RTE_LOG(ERR, USER1,
2022 				"line %u FAILED: %s", __LINE__,
2023 				"Failed to process asym crypto op\n");
2024 		status = TEST_FAILED;
2025 		goto exit;
2026 	}
2027 
2028 	asym_op = result_op->asym;
2029 
2030 	debug_hexdump(stdout, "r:",
2031 			asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
2032 	debug_hexdump(stdout, "s:",
2033 			asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
2034 
2035 	ret = verify_ecdsa_sign(input_params.sign_r.data,
2036 				input_params.sign_s.data, result_op);
2037 	if (ret) {
2038 		status = TEST_FAILED;
2039 		RTE_LOG(ERR, USER1,
2040 				"line %u FAILED: %s", __LINE__,
2041 				"ECDSA sign failed.\n");
2042 		goto exit;
2043 	}
2044 
2045 	/* Verify sign */
2046 
2047 	/* Populate op with operational details */
2048 	op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
2049 	op->asym->ecdsa.q.x.data = input_params.pubkey_qx.data;
2050 	op->asym->ecdsa.q.x.length = input_params.pubkey_qx.length;
2051 	op->asym->ecdsa.q.y.data = input_params.pubkey_qy.data;
2052 	op->asym->ecdsa.q.y.length = input_params.pubkey_qx.length;
2053 	op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
2054 	op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
2055 	op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
2056 	op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
2057 
2058 	/* Enqueue sign result for verify */
2059 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2060 		status = TEST_FAILED;
2061 		RTE_LOG(ERR, USER1,
2062 				"line %u FAILED: %s", __LINE__,
2063 				"Error sending packet for operation\n");
2064 		goto exit;
2065 	}
2066 
2067 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2068 		rte_pause();
2069 
2070 	if (result_op == NULL) {
2071 		status = TEST_FAILED;
2072 		goto exit;
2073 	}
2074 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2075 		status = TEST_FAILED;
2076 		RTE_LOG(ERR, USER1,
2077 				"line %u FAILED: %s", __LINE__,
2078 				"ECDSA verify failed.\n");
2079 		goto exit;
2080 	}
2081 
2082 exit:
2083 	if (sess != NULL) {
2084 		rte_cryptodev_asym_session_clear(dev_id, sess);
2085 		rte_cryptodev_asym_session_free(sess);
2086 	}
2087 	if (op != NULL)
2088 		rte_crypto_op_free(op);
2089 	return status;
2090 };
2091 
2092 static int
2093 test_ecdsa_sign_verify_all_curve(void)
2094 {
2095 	int status, overall_status = TEST_SUCCESS;
2096 	enum curve curve_id;
2097 	int test_index = 0;
2098 	const char *msg;
2099 
2100 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2101 		status = test_ecdsa_sign_verify(curve_id);
2102 		if (status == TEST_SUCCESS) {
2103 			msg = "succeeded";
2104 		} else {
2105 			msg = "failed";
2106 			overall_status = status;
2107 		}
2108 		printf("  %u) TestCase Sign/Veriy Curve %s  %s\n",
2109 		       test_index ++, curve[curve_id], msg);
2110 	}
2111 	return overall_status;
2112 }
2113 
2114 static int
2115 test_ecpm(enum curve curve_id)
2116 {
2117 	struct crypto_testsuite_params *ts_params = &testsuite_params;
2118 	struct rte_mempool *sess_mpool = ts_params->session_mpool;
2119 	struct rte_mempool *op_mpool = ts_params->op_mpool;
2120 	struct crypto_testsuite_ecpm_params input_params;
2121 	struct rte_cryptodev_asym_session *sess = NULL;
2122 	uint8_t dev_id = ts_params->valid_devs[0];
2123 	struct rte_crypto_op *result_op = NULL;
2124 	uint8_t output_buf_x[TEST_DATA_SIZE];
2125 	uint8_t output_buf_y[TEST_DATA_SIZE];
2126 	struct rte_crypto_asym_xform xform;
2127 	struct rte_crypto_asym_op *asym_op;
2128 	struct rte_cryptodev_info dev_info;
2129 	struct rte_crypto_op *op = NULL;
2130 	int status = TEST_SUCCESS, ret;
2131 
2132 	switch (curve_id) {
2133 	case SECP192R1:
2134 		input_params = ecpm_param_secp192r1;
2135 		break;
2136 	case SECP224R1:
2137 		input_params = ecpm_param_secp224r1;
2138 		break;
2139 	case SECP256R1:
2140 		input_params = ecpm_param_secp256r1;
2141 		break;
2142 	case SECP384R1:
2143 		input_params = ecpm_param_secp384r1;
2144 		break;
2145 	case SECP521R1:
2146 		input_params = ecpm_param_secp521r1;
2147 		break;
2148 	default:
2149 		RTE_LOG(ERR, USER1,
2150 				"line %u FAILED: %s", __LINE__,
2151 				"Unsupported curve id\n");
2152 		status = TEST_FAILED;
2153 		goto exit;
2154 	}
2155 
2156 	rte_cryptodev_info_get(dev_id, &dev_info);
2157 
2158 	sess = rte_cryptodev_asym_session_create(sess_mpool);
2159 	if (sess == NULL) {
2160 		RTE_LOG(ERR, USER1,
2161 				"line %u FAILED: %s", __LINE__,
2162 				"Session creation failed\n");
2163 		status = TEST_FAILED;
2164 		goto exit;
2165 	}
2166 
2167 	/* Setup crypto op data structure */
2168 	op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
2169 	if (op == NULL) {
2170 		RTE_LOG(ERR, USER1,
2171 				"line %u FAILED: %s", __LINE__,
2172 				"Failed to allocate asymmetric crypto "
2173 				"operation struct\n");
2174 		status = TEST_FAILED;
2175 		goto exit;
2176 	}
2177 	asym_op = op->asym;
2178 
2179 	/* Setup asym xform */
2180 	xform.next = NULL;
2181 	xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
2182 	xform.ec.curve_id = input_params.curve;
2183 
2184 	if (rte_cryptodev_asym_session_init(dev_id, sess, &xform,
2185 				sess_mpool) < 0) {
2186 		RTE_LOG(ERR, USER1,
2187 				"line %u FAILED: %s", __LINE__,
2188 				"Unable to config asym session\n");
2189 		status = TEST_FAILED;
2190 		goto exit;
2191 	}
2192 
2193 	/* Attach asymmetric crypto session to crypto operations */
2194 	rte_crypto_op_attach_asym_session(op, sess);
2195 
2196 	/* Populate op with operational details */
2197 	op->asym->ecpm.p.x.data = input_params.gen_x.data;
2198 	op->asym->ecpm.p.x.length = input_params.gen_x.length;
2199 	op->asym->ecpm.p.y.data = input_params.gen_y.data;
2200 	op->asym->ecpm.p.y.length = input_params.gen_y.length;
2201 	op->asym->ecpm.scalar.data = input_params.privkey.data;
2202 	op->asym->ecpm.scalar.length = input_params.privkey.length;
2203 
2204 	/* Init out buf */
2205 	op->asym->ecpm.r.x.data = output_buf_x;
2206 	op->asym->ecpm.r.y.data = output_buf_y;
2207 
2208 	RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
2209 
2210 	/* Process crypto operation */
2211 	if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
2212 		RTE_LOG(ERR, USER1,
2213 				"line %u FAILED: %s", __LINE__,
2214 				"Error sending packet for operation\n");
2215 		status = TEST_FAILED;
2216 		goto exit;
2217 	}
2218 
2219 	while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
2220 		rte_pause();
2221 
2222 	if (result_op == NULL) {
2223 		RTE_LOG(ERR, USER1,
2224 				"line %u FAILED: %s", __LINE__,
2225 				"Failed to process asym crypto op\n");
2226 		status = TEST_FAILED;
2227 		goto exit;
2228 	}
2229 
2230 	if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
2231 		RTE_LOG(ERR, USER1,
2232 				"line %u FAILED: %s", __LINE__,
2233 				"Failed to process asym crypto op\n");
2234 		status = TEST_FAILED;
2235 		goto exit;
2236 	}
2237 
2238 	asym_op = result_op->asym;
2239 
2240 	debug_hexdump(stdout, "r x:",
2241 			asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
2242 	debug_hexdump(stdout, "r y:",
2243 			asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
2244 
2245 	ret = verify_ecpm(input_params.pubkey_x.data,
2246 				input_params.pubkey_y.data, result_op);
2247 	if (ret) {
2248 		status = TEST_FAILED;
2249 		RTE_LOG(ERR, USER1,
2250 				"line %u FAILED: %s", __LINE__,
2251 				"EC Point Multiplication failed.\n");
2252 		goto exit;
2253 	}
2254 
2255 exit:
2256 	if (sess != NULL) {
2257 		rte_cryptodev_asym_session_clear(dev_id, sess);
2258 		rte_cryptodev_asym_session_free(sess);
2259 	}
2260 	if (op != NULL)
2261 		rte_crypto_op_free(op);
2262 	return status;
2263 }
2264 
2265 static int
2266 test_ecpm_all_curve(void)
2267 {
2268 	int status, overall_status = TEST_SUCCESS;
2269 	enum curve curve_id;
2270 	int test_index = 0;
2271 	const char *msg;
2272 
2273 	for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
2274 		status = test_ecpm(curve_id);
2275 		if (status == TEST_SUCCESS) {
2276 			msg = "succeeded";
2277 		} else {
2278 			msg = "failed";
2279 			overall_status = status;
2280 		}
2281 		printf("  %u) TestCase EC Point Mul Curve %s  %s\n",
2282 		       test_index ++, curve[curve_id], msg);
2283 	}
2284 	return overall_status;
2285 }
2286 
2287 static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
2288 	.suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
2289 	.setup = testsuite_setup,
2290 	.teardown = testsuite_teardown,
2291 	.unit_test_cases = {
2292 		TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
2293 		TEST_CASE_ST(ut_setup, ut_teardown, test_dsa),
2294 		TEST_CASE_ST(ut_setup, ut_teardown, test_dh_keygenration),
2295 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec),
2296 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify),
2297 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
2298 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
2299 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_inv),
2300 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
2301 		TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
2302 		TEST_CASES_END() /**< NULL terminate unit test array */
2303 	}
2304 };
2305 
2306 static struct unit_test_suite cryptodev_qat_asym_testsuite  = {
2307 	.suite_name = "Crypto Device QAT ASYM Unit Test Suite",
2308 	.setup = testsuite_setup,
2309 	.teardown = testsuite_teardown,
2310 	.unit_test_cases = {
2311 		TEST_CASE_ST(ut_setup, ut_teardown, test_one_by_one),
2312 		TEST_CASES_END() /**< NULL terminate unit test array */
2313 	}
2314 };
2315 
2316 static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
2317 	.suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
2318 	.setup = testsuite_setup,
2319 	.teardown = testsuite_teardown,
2320 	.unit_test_cases = {
2321 		TEST_CASE_ST(ut_setup, ut_teardown, test_capability),
2322 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_enc_dec_crt),
2323 		TEST_CASE_ST(ut_setup, ut_teardown, test_rsa_sign_verify_crt),
2324 		TEST_CASE_ST(ut_setup, ut_teardown, test_mod_exp),
2325 		TEST_CASE_ST(ut_setup, ut_teardown,
2326 			     test_ecdsa_sign_verify_all_curve),
2327 		TEST_CASE_ST(ut_setup, ut_teardown, test_ecpm_all_curve),
2328 		TEST_CASES_END() /**< NULL terminate unit test array */
2329 	}
2330 };
2331 
2332 static int
2333 test_cryptodev_openssl_asym(void)
2334 {
2335 	gbl_driver_id = rte_cryptodev_driver_id_get(
2336 			RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
2337 
2338 	if (gbl_driver_id == -1) {
2339 		RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
2340 		return TEST_FAILED;
2341 	}
2342 
2343 	return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
2344 }
2345 
2346 static int
2347 test_cryptodev_qat_asym(void)
2348 {
2349 	gbl_driver_id = rte_cryptodev_driver_id_get(
2350 			RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
2351 
2352 	if (gbl_driver_id == -1) {
2353 		RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
2354 		return TEST_FAILED;
2355 	}
2356 
2357 	return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
2358 }
2359 
2360 static int
2361 test_cryptodev_octeontx_asym(void)
2362 {
2363 	gbl_driver_id = rte_cryptodev_driver_id_get(
2364 			RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
2365 	if (gbl_driver_id == -1) {
2366 		RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
2367 		return TEST_FAILED;
2368 	}
2369 	return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2370 }
2371 
2372 static int
2373 test_cryptodev_octeontx2_asym(void)
2374 {
2375 	gbl_driver_id = rte_cryptodev_driver_id_get(
2376 			RTE_STR(CRYPTODEV_NAME_OCTEONTX2_PMD));
2377 	if (gbl_driver_id == -1) {
2378 		RTE_LOG(ERR, USER1, "OCTEONTX2 PMD must be loaded.\n");
2379 		return TEST_FAILED;
2380 	}
2381 
2382 	/* Use test suite registered for crypto_octeontx PMD */
2383 	return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
2384 }
2385 
2386 REGISTER_TEST_COMMAND(cryptodev_openssl_asym_autotest,
2387 					  test_cryptodev_openssl_asym);
2388 
2389 REGISTER_TEST_COMMAND(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
2390 
2391 REGISTER_TEST_COMMAND(cryptodev_octeontx_asym_autotest,
2392 					  test_cryptodev_octeontx_asym);
2393 
2394 REGISTER_TEST_COMMAND(cryptodev_octeontx2_asym_autotest,
2395 					  test_cryptodev_octeontx2_asym);
2396