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