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