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