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