LCOV - code coverage report
Current view: top level - app/test - test_cryptodev_asym.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 812 1798 45.2 %
Date: 2025-04-03 19:37:06 Functions: 40 63 63.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 237 819 28.9 %

           Branch data     Line data    Source code
       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_ecdh_test_vectors.h"
      21                 :            : #include "test_cryptodev_ecdsa_test_vectors.h"
      22                 :            : #include "test_cryptodev_ecpm_test_vectors.h"
      23                 :            : #include "test_cryptodev_eddsa_test_vectors.h"
      24                 :            : #include "test_cryptodev_mod_test_vectors.h"
      25                 :            : #include "test_cryptodev_rsa_test_vectors.h"
      26                 :            : #include "test_cryptodev_sm2_test_vectors.h"
      27                 :            : #include "test_cryptodev_asym_util.h"
      28                 :            : #include "test.h"
      29                 :            : 
      30                 :            : #define TEST_NUM_BUFS 10
      31                 :            : #define TEST_NUM_SESSIONS 4
      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                 :            : #define DEQ_TIMEOUT 50
      39                 :            : 
      40                 :            : static int gbl_driver_id;
      41                 :            : static struct crypto_testsuite_params_asym {
      42                 :            :         struct rte_mempool *op_mpool;
      43                 :            :         struct rte_mempool *session_mpool;
      44                 :            :         struct rte_cryptodev_config conf;
      45                 :            :         struct rte_cryptodev_qp_conf qp_conf;
      46                 :            :         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
      47                 :            :         uint8_t valid_dev_count;
      48                 :            : } testsuite_params, *params = &testsuite_params;
      49                 :            : 
      50                 :            : static struct ut_args {
      51                 :            :         void *sess;
      52                 :            :         struct rte_crypto_op *op;
      53                 :            :         struct rte_crypto_op *result_op;
      54                 :            : } _args, *self = &_args;
      55                 :            : 
      56                 :            : static int
      57                 :          2 : queue_ops_rsa_sign_verify(void *sess)
      58                 :            : {
      59                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
      60                 :          2 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
      61                 :          2 :         uint8_t dev_id = ts_params->valid_devs[0];
      62                 :            :         struct rte_crypto_op *op, *result_op;
      63                 :            :         struct rte_crypto_asym_op *asym_op;
      64                 :            :         uint8_t output_buf[TEST_DATA_SIZE];
      65                 :            :         int status;
      66                 :            : 
      67                 :            :         /* Set up crypto op data structure */
      68                 :          2 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
      69         [ -  + ]:          2 :         if (!op) {
      70                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
      71                 :            :                         "operation struct\n");
      72                 :          0 :                 return TEST_FAILED;
      73                 :            :         }
      74                 :            : 
      75                 :            :         asym_op = op->asym;
      76                 :            : 
      77                 :            :         /* Compute sign on the test vector */
      78                 :          2 :         asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
      79                 :            : 
      80                 :          2 :         asym_op->rsa.message.data = rsaplaintext.data;
      81                 :          2 :         asym_op->rsa.message.length = rsaplaintext.len;
      82                 :          2 :         asym_op->rsa.sign.length = RTE_DIM(rsa_n);
      83                 :          2 :         asym_op->rsa.sign.data = output_buf;
      84                 :            : 
      85                 :          2 :         debug_hexdump(stdout, "message", asym_op->rsa.message.data,
      86                 :            :                       asym_op->rsa.message.length);
      87                 :            : 
      88                 :            :         /* Attach asymmetric crypto session to crypto operations */
      89         [ +  - ]:          2 :         rte_crypto_op_attach_asym_session(op, sess);
      90                 :            : 
      91                 :          2 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
      92                 :            : 
      93                 :            :         /* Process crypto operation */
      94         [ -  + ]:          2 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
      95                 :          0 :                 RTE_LOG(ERR, USER1, "Error sending packet for sign\n");
      96                 :            :                 status = TEST_FAILED;
      97                 :          0 :                 goto error_exit;
      98                 :            :         }
      99                 :            : 
     100         [ -  + ]:          2 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     101                 :            :                 rte_pause();
     102                 :            : 
     103         [ -  + ]:          2 :         if (result_op == NULL) {
     104                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process sign op\n");
     105                 :            :                 status = TEST_FAILED;
     106                 :          0 :                 goto error_exit;
     107                 :            :         }
     108                 :            : 
     109                 :          2 :         debug_hexdump(stdout, "signed message", asym_op->rsa.sign.data,
     110                 :            :                       asym_op->rsa.sign.length);
     111                 :          2 :         asym_op = result_op->asym;
     112                 :            : 
     113                 :            :         /* Verify sign */
     114                 :          2 :         asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
     115                 :            : 
     116                 :            :         /* Process crypto operation */
     117         [ -  + ]:          2 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
     118                 :          0 :                 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
     119                 :            :                 status = TEST_FAILED;
     120                 :          0 :                 goto error_exit;
     121                 :            :         }
     122                 :            : 
     123         [ -  + ]:          2 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     124                 :            :                 rte_pause();
     125                 :            : 
     126         [ -  + ]:          2 :         if (result_op == NULL) {
     127                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
     128                 :            :                 status = TEST_FAILED;
     129                 :          0 :                 goto error_exit;
     130                 :            :         }
     131                 :            : 
     132         [ -  + ]:          2 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
     133                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
     134                 :            :                 status = TEST_FAILED;
     135                 :          0 :                 goto error_exit;
     136                 :            :         }
     137                 :            : 
     138                 :            :         /* Negative test */
     139                 :          2 :         result_op->asym->rsa.sign.data[0] ^= 0xff;
     140         [ -  + ]:          2 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &result_op, 1) != 1) {
     141                 :          0 :                 RTE_LOG(ERR, USER1, "Error sending packet for verify\n");
     142                 :            :                 status = TEST_FAILED;
     143                 :          0 :                 goto error_exit;
     144                 :            :         }
     145                 :            : 
     146         [ -  + ]:          2 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     147                 :            :                 rte_pause();
     148                 :            : 
     149         [ -  + ]:          2 :         if (result_op == NULL) {
     150                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process verify op\n");
     151                 :            :                 status = TEST_FAILED;
     152                 :          0 :                 goto error_exit;
     153                 :            :         }
     154                 :            : 
     155         [ -  + ]:          2 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_ERROR) {
     156                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process sign-verify op\n");
     157                 :            :                 status = TEST_FAILED;
     158                 :            :         }
     159                 :            : 
     160                 :            :         status = TEST_SUCCESS;
     161                 :          2 : error_exit:
     162                 :            : 
     163                 :          2 :         rte_crypto_op_free(op);
     164                 :            : 
     165                 :          2 :         return status;
     166                 :            : }
     167                 :            : 
     168                 :            : static int
     169                 :          2 : queue_ops_rsa_enc_dec(void *sess)
     170                 :            : {
     171                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     172                 :          2 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
     173                 :          2 :         uint8_t dev_id = ts_params->valid_devs[0];
     174                 :            :         struct rte_crypto_op *op, *result_op;
     175                 :            :         struct rte_crypto_asym_op *asym_op;
     176                 :          2 :         uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
     177                 :            :         int ret, status = TEST_SUCCESS;
     178                 :            : 
     179                 :            :         /* Set up crypto op data structure */
     180                 :          2 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     181         [ -  + ]:          2 :         if (!op) {
     182                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to allocate asymmetric crypto "
     183                 :            :                         "operation struct\n");
     184                 :          0 :                 return TEST_FAILED;
     185                 :            :         }
     186                 :            : 
     187                 :            :         asym_op = op->asym;
     188                 :            : 
     189                 :            :         /* Compute encryption on the test vector */
     190                 :          2 :         asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
     191                 :            : 
     192                 :          2 :         asym_op->rsa.message.data = rsaplaintext.data;
     193                 :          2 :         asym_op->rsa.cipher.data = cipher_buf;
     194                 :          2 :         asym_op->rsa.cipher.length = RTE_DIM(rsa_n);
     195                 :          2 :         asym_op->rsa.message.length = rsaplaintext.len;
     196                 :            : 
     197                 :          2 :         debug_hexdump(stdout, "message", asym_op->rsa.message.data,
     198                 :            :                       asym_op->rsa.message.length);
     199                 :            : 
     200                 :            :         /* Attach asymmetric crypto session to crypto operations */
     201         [ +  - ]:          2 :         rte_crypto_op_attach_asym_session(op, sess);
     202                 :            : 
     203                 :          2 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
     204                 :            : 
     205                 :            :         /* Process crypto operation */
     206         [ -  + ]:          2 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
     207                 :          0 :                 RTE_LOG(ERR, USER1, "Error sending packet for encryption\n");
     208                 :            :                 status = TEST_FAILED;
     209                 :          0 :                 goto error_exit;
     210                 :            :         }
     211                 :            : 
     212         [ -  + ]:          2 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     213                 :            :                 rte_pause();
     214                 :            : 
     215         [ -  + ]:          2 :         if (result_op == NULL) {
     216                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process encryption op\n");
     217                 :            :                 status = TEST_FAILED;
     218                 :          0 :                 goto error_exit;
     219                 :            :         }
     220                 :          2 :         debug_hexdump(stdout, "encrypted message", asym_op->rsa.cipher.data,
     221                 :            :                       asym_op->rsa.cipher.length);
     222                 :            : 
     223                 :            :         /* Use the resulted output as decryption Input vector*/
     224                 :          2 :         asym_op = result_op->asym;
     225                 :          2 :         asym_op->rsa.message.length = RTE_DIM(rsa_n);
     226                 :          2 :         asym_op->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
     227                 :            : 
     228                 :            :         /* Process crypto operation */
     229         [ -  + ]:          2 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
     230                 :          0 :                 RTE_LOG(ERR, USER1, "Error sending packet for decryption\n");
     231                 :            :                 status = TEST_FAILED;
     232                 :          0 :                 goto error_exit;
     233                 :            :         }
     234                 :            : 
     235         [ -  + ]:          2 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     236                 :            :                 rte_pause();
     237                 :            : 
     238         [ -  + ]:          2 :         if (result_op == NULL) {
     239                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to process decryption op\n");
     240                 :            :                 status = TEST_FAILED;
     241                 :          0 :                 goto error_exit;
     242                 :            :         }
     243                 :            :         status = TEST_SUCCESS;
     244                 :            :         ret = rsa_verify(&rsaplaintext, result_op);
     245                 :            :         if (ret)
     246                 :            :                 status = TEST_FAILED;
     247                 :            : 
     248                 :          2 : error_exit:
     249                 :            : 
     250                 :          2 :         rte_crypto_op_free(op);
     251                 :            : 
     252                 :          2 :         return status;
     253                 :            : }
     254                 :            : 
     255                 :            : static int
     256                 :          1 : test_rsa_sign_verify(void)
     257                 :            : {
     258                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     259                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     260                 :            :         struct rte_cryptodev_asym_capability_idx idx;
     261                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     262                 :          1 :         void *sess = NULL;
     263                 :            :         struct rte_cryptodev_info dev_info;
     264                 :            :         int ret, status = TEST_SUCCESS;
     265                 :            : 
     266                 :            :         /* Check RSA capability */
     267                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
     268         [ +  - ]:          1 :         if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
     269                 :            :                 return -ENOTSUP;
     270                 :            : 
     271                 :            :         /* Test case supports op with exponent key only,
     272                 :            :          * Check in PMD feature flag for RSA exponent key type support.
     273                 :            :          */
     274                 :          1 :         rte_cryptodev_info_get(dev_id, &dev_info);
     275         [ -  + ]:          1 :         if (!(dev_info.feature_flags &
     276                 :            :                                 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
     277                 :          0 :                 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
     278                 :            :                         "exponent key type. Test Skipped\n");
     279                 :          0 :                 return TEST_SKIPPED;
     280                 :            :         }
     281                 :            : 
     282                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
     283                 :            : 
     284         [ -  + ]:          1 :         if (ret < 0) {
     285                 :          0 :                 RTE_LOG(ERR, USER1, "Session creation failed for "
     286                 :            :                         "sign_verify\n");
     287         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     288                 :          0 :                 goto error_exit;
     289                 :            :         }
     290                 :            : 
     291                 :          1 :         status = queue_ops_rsa_sign_verify(sess);
     292                 :            : 
     293                 :          1 : error_exit:
     294                 :          1 :         rte_cryptodev_asym_session_free(dev_id, sess);
     295                 :            : 
     296         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
     297                 :            : 
     298                 :            :         return status;
     299                 :            : }
     300                 :            : 
     301                 :            : static int
     302                 :          1 : test_rsa_enc_dec(void)
     303                 :            : {
     304                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     305                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     306                 :            :         struct rte_cryptodev_asym_capability_idx idx;
     307                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     308                 :          1 :         void *sess = NULL;
     309                 :            :         struct rte_cryptodev_info dev_info;
     310                 :            :         int ret, status = TEST_SUCCESS;
     311                 :            : 
     312                 :            :         /* Check RSA capability */
     313                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
     314         [ +  - ]:          1 :         if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
     315                 :            :                 return -ENOTSUP;
     316                 :            : 
     317                 :            :         /* Test case supports op with exponent key only,
     318                 :            :          * Check in PMD feature flag for RSA exponent key type support.
     319                 :            :          */
     320                 :          1 :         rte_cryptodev_info_get(dev_id, &dev_info);
     321         [ -  + ]:          1 :         if (!(dev_info.feature_flags &
     322                 :            :                                 RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_EXP)) {
     323                 :          0 :                 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
     324                 :            :                         "exponent key type. Test skipped\n");
     325                 :          0 :                 return TEST_SKIPPED;
     326                 :            :         }
     327                 :            : 
     328                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform, sess_mpool, &sess);
     329                 :            : 
     330         [ -  + ]:          1 :         if (ret < 0) {
     331                 :          0 :                 RTE_LOG(ERR, USER1, "Session creation failed for enc_dec\n");
     332         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     333                 :          0 :                 goto error_exit;
     334                 :            :         }
     335                 :            : 
     336                 :          1 :         status = queue_ops_rsa_enc_dec(sess);
     337                 :            : 
     338                 :          1 : error_exit:
     339                 :            : 
     340                 :          1 :         rte_cryptodev_asym_session_free(dev_id, sess);
     341                 :            : 
     342         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
     343                 :            : 
     344                 :            :         return status;
     345                 :            : }
     346                 :            : 
     347                 :            : static int
     348                 :          1 : test_rsa_sign_verify_crt(void)
     349                 :            : {
     350                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     351                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     352                 :            :         struct rte_cryptodev_asym_capability_idx idx;
     353                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     354                 :          1 :         void *sess = NULL;
     355                 :            :         struct rte_cryptodev_info dev_info;
     356                 :            :         int ret, status = TEST_SUCCESS;
     357                 :            : 
     358                 :            :         /* Check RSA capability */
     359                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
     360         [ +  - ]:          1 :         if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
     361                 :            :                 return -ENOTSUP;
     362                 :            : 
     363                 :            :         /* Test case supports op with quintuple format key only,
     364                 :            :          * Check im PMD feature flag for RSA quintuple key type support.
     365                 :            :          */
     366                 :          1 :         rte_cryptodev_info_get(dev_id, &dev_info);
     367         [ -  + ]:          1 :         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
     368                 :          0 :                 RTE_LOG(INFO, USER1, "Device doesn't support sign op with "
     369                 :            :                         "quintuple key type. Test skipped\n");
     370                 :          0 :                 return TEST_SKIPPED;
     371                 :            :         }
     372                 :            : 
     373                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
     374                 :            : 
     375         [ -  + ]:          1 :         if (ret < 0) {
     376                 :          0 :                 RTE_LOG(ERR, USER1, "Session creation failed for "
     377                 :            :                         "sign_verify_crt\n");
     378         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     379                 :          0 :                 goto error_exit;
     380                 :            :         }
     381                 :            : 
     382                 :          1 :         status = queue_ops_rsa_sign_verify(sess);
     383                 :            : 
     384                 :          1 : error_exit:
     385                 :            : 
     386                 :          1 :         rte_cryptodev_asym_session_free(dev_id, sess);
     387                 :            : 
     388         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
     389                 :            : 
     390                 :            :         return status;
     391                 :            : }
     392                 :            : 
     393                 :            : static int
     394                 :          1 : test_rsa_enc_dec_crt(void)
     395                 :            : {
     396                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     397                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     398                 :            :         struct rte_cryptodev_asym_capability_idx idx;
     399                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     400                 :          1 :         void *sess = NULL;
     401                 :            :         struct rte_cryptodev_info dev_info;
     402                 :            :         int ret, status = TEST_SUCCESS;
     403                 :            : 
     404                 :            :         /* Check RSA capability */
     405                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_RSA;
     406         [ +  - ]:          1 :         if (rte_cryptodev_asym_capability_get(dev_id, &idx) == NULL)
     407                 :            :                 return -ENOTSUP;
     408                 :            : 
     409                 :            :         /* Test case supports op with quintuple format key only,
     410                 :            :          * Check in PMD feature flag for RSA quintuple key type support.
     411                 :            :          */
     412                 :          1 :         rte_cryptodev_info_get(dev_id, &dev_info);
     413         [ -  + ]:          1 :         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
     414                 :          0 :                 RTE_LOG(INFO, USER1, "Device doesn't support decrypt op with "
     415                 :            :                         "quintuple key type. Test skipped\n");
     416                 :          0 :                 return TEST_SKIPPED;
     417                 :            :         }
     418                 :            : 
     419                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &rsa_xform_crt, sess_mpool, &sess);
     420                 :            : 
     421         [ -  + ]:          1 :         if (ret < 0) {
     422                 :          0 :                 RTE_LOG(ERR, USER1, "Session creation failed for "
     423                 :            :                         "enc_dec_crt\n");
     424         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     425                 :          0 :                 goto error_exit;
     426                 :            :         }
     427                 :            : 
     428                 :          1 :         status = queue_ops_rsa_enc_dec(sess);
     429                 :            : 
     430                 :          1 : error_exit:
     431                 :            : 
     432                 :          1 :         rte_cryptodev_asym_session_free(dev_id, sess);
     433                 :            : 
     434         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
     435                 :            : 
     436                 :            :         return status;
     437                 :            : }
     438                 :            : 
     439                 :            : static int
     440                 :          1 : testsuite_setup(void)
     441                 :            : {
     442                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     443                 :            :         uint8_t valid_devs[RTE_CRYPTO_MAX_DEVS];
     444                 :            :         struct rte_cryptodev_info info;
     445                 :            :         int ret, dev_id = -1;
     446                 :            :         uint32_t i, nb_devs;
     447                 :            :         uint16_t qp_id;
     448                 :            : 
     449                 :            :         memset(ts_params, 0, sizeof(*ts_params));
     450                 :            : 
     451                 :            :         /* Device, op pool and session configuration for asymmetric crypto. 8< */
     452                 :          1 :         ts_params->op_mpool = rte_crypto_op_pool_create(
     453                 :            :                         "CRYPTO_ASYM_OP_POOL",
     454                 :            :                         RTE_CRYPTO_OP_TYPE_ASYMMETRIC,
     455                 :            :                         TEST_NUM_BUFS, 0,
     456                 :            :                         0,
     457                 :          1 :                         rte_socket_id());
     458         [ -  + ]:          1 :         if (ts_params->op_mpool == NULL) {
     459                 :          0 :                 RTE_LOG(ERR, USER1, "Can't create ASYM_CRYPTO_OP_POOL\n");
     460                 :          0 :                 return TEST_FAILED;
     461                 :            :         }
     462                 :            : 
     463                 :            :         /* Create an OPENSSL device if required */
     464         [ +  - ]:          1 :         if (gbl_driver_id == rte_cryptodev_driver_id_get(
     465                 :            :                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD))) {
     466                 :          1 :                 nb_devs = rte_cryptodev_device_count_by_driver(
     467                 :          1 :                                 rte_cryptodev_driver_id_get(
     468                 :            :                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD)));
     469         [ -  + ]:          1 :                 if (nb_devs < 1) {
     470                 :          0 :                         ret = rte_vdev_init(
     471                 :            :                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD),
     472                 :            :                                 NULL);
     473                 :            : 
     474         [ #  # ]:          0 :                         TEST_ASSERT(ret == 0, "Failed to create "
     475                 :            :                                 "instance of pmd : %s",
     476                 :            :                                 RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
     477                 :            :                 }
     478                 :            :         }
     479                 :            : 
     480                 :            :         /* Get list of valid crypto devs */
     481                 :          1 :         nb_devs = rte_cryptodev_devices_get(
     482                 :            :                                 rte_cryptodev_driver_name_get(gbl_driver_id),
     483                 :            :                                 valid_devs, RTE_CRYPTO_MAX_DEVS);
     484         [ -  + ]:          1 :         if (nb_devs < 1) {
     485                 :          0 :                 RTE_LOG(ERR, USER1, "No crypto devices found?\n");
     486                 :          0 :                 return TEST_SKIPPED;
     487                 :            :         }
     488                 :            : 
     489                 :            :         /*
     490                 :            :          * Get first valid asymmetric device found in test suite param and
     491                 :            :          * break
     492                 :            :          */
     493         [ +  - ]:          1 :         for (i = 0; i < nb_devs ; i++) {
     494                 :          1 :                 rte_cryptodev_info_get(valid_devs[i], &info);
     495         [ +  - ]:          1 :                 if (info.feature_flags & RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO) {
     496                 :          1 :                         dev_id = ts_params->valid_devs[0] = valid_devs[i];
     497                 :          1 :                         break;
     498                 :            :                 }
     499                 :            :         }
     500                 :            : 
     501         [ -  + ]:          1 :         if (dev_id == -1) {
     502                 :          0 :                 RTE_LOG(ERR, USER1, "Device doesn't support asymmetric. "
     503                 :            :                         "Test skipped.\n");
     504                 :          0 :                 return TEST_FAILED;
     505                 :            :         }
     506                 :            : 
     507                 :            :         /* Set valid device count */
     508                 :          1 :         ts_params->valid_dev_count = nb_devs;
     509                 :            : 
     510                 :            :         /* configure device with num qp */
     511                 :          1 :         ts_params->conf.nb_queue_pairs = info.max_nb_queue_pairs;
     512                 :          1 :         ts_params->conf.socket_id = SOCKET_ID_ANY;
     513                 :          1 :         ts_params->conf.ff_disable = RTE_CRYPTODEV_FF_SECURITY |
     514                 :            :                         RTE_CRYPTODEV_FF_SYMMETRIC_CRYPTO;
     515         [ -  + ]:          1 :         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
     516                 :            :                         &ts_params->conf),
     517                 :            :                         "Failed to configure cryptodev %u with %u qps",
     518                 :            :                         dev_id, ts_params->conf.nb_queue_pairs);
     519                 :            : 
     520                 :            :         /* configure qp */
     521                 :          1 :         ts_params->qp_conf.nb_descriptors = DEFAULT_NUM_OPS_INFLIGHT;
     522                 :          1 :         ts_params->qp_conf.mp_session = ts_params->session_mpool;
     523         [ +  + ]:          9 :         for (qp_id = 0; qp_id < info.max_nb_queue_pairs; qp_id++) {
     524         [ -  + ]:          8 :                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
     525                 :            :                         dev_id, qp_id, &ts_params->qp_conf,
     526                 :            :                         rte_cryptodev_socket_id(dev_id)),
     527                 :            :                         "Failed to setup queue pair %u on cryptodev %u ASYM",
     528                 :            :                         qp_id, dev_id);
     529                 :            :         }
     530                 :            : 
     531                 :          1 :         ts_params->session_mpool = rte_cryptodev_asym_session_pool_create(
     532                 :            :                         "test_asym_sess_mp", TEST_NUM_SESSIONS, 0, 0,
     533                 :            :                         SOCKET_ID_ANY);
     534                 :            : 
     535         [ -  + ]:          1 :         TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
     536                 :            :                         "session mempool allocation failed");
     537                 :            :         /* >8 End of device, op pool and session configuration for asymmetric crypto section. */
     538                 :            :         return TEST_SUCCESS;
     539                 :            : }
     540                 :            : 
     541                 :            : static void
     542                 :          1 : testsuite_teardown(void)
     543                 :            : {
     544                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     545                 :            : 
     546                 :            :         /* Reset device */
     547                 :          1 :         ts_params->qp_conf.mp_session = NULL;
     548                 :          1 :         ts_params->conf.ff_disable = 0;
     549         [ -  + ]:          1 :         if (rte_cryptodev_configure(ts_params->valid_devs[0], &ts_params->conf))
     550                 :          0 :                 RTE_LOG(DEBUG, USER1, "Could not reset cryptodev\n");
     551                 :            : 
     552         [ +  - ]:          1 :         if (ts_params->op_mpool != NULL) {
     553                 :          1 :                 RTE_LOG(DEBUG, USER1, "CRYPTO_OP_POOL count %u\n",
     554                 :            :                 rte_mempool_avail_count(ts_params->op_mpool));
     555                 :            :         }
     556                 :            : 
     557                 :            :         /* Free session mempools */
     558         [ +  - ]:          1 :         if (ts_params->session_mpool != NULL) {
     559                 :          1 :                 rte_mempool_free(ts_params->session_mpool);
     560                 :          1 :                 ts_params->session_mpool = NULL;
     561                 :            :         }
     562                 :          1 : }
     563                 :            : 
     564                 :            : static int
     565                 :         22 : ut_setup_asym(void)
     566                 :            : {
     567                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     568                 :            :         uint16_t qp_id;
     569                 :            : 
     570                 :         22 :         memset(self, 0, sizeof(*self));
     571                 :         22 :         self->op = rte_crypto_op_alloc(params->op_mpool,
     572                 :            :                         RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     573         [ -  + ]:         22 :         TEST_ASSERT_NOT_NULL(self->op,
     574                 :            :                 "Failed to allocate asymmetric crypto operation struct"
     575                 :            :         );
     576                 :            : 
     577                 :            :         /* Reconfigure device to default parameters */
     578                 :         22 :         ts_params->conf.socket_id = SOCKET_ID_ANY;
     579                 :            : 
     580         [ -  + ]:         22 :         TEST_ASSERT_SUCCESS(rte_cryptodev_configure(ts_params->valid_devs[0],
     581                 :            :                         &ts_params->conf),
     582                 :            :                         "Failed to configure cryptodev %u",
     583                 :            :                         ts_params->valid_devs[0]);
     584                 :            : 
     585         [ +  + ]:        198 :         for (qp_id = 0; qp_id < ts_params->conf.nb_queue_pairs ; qp_id++) {
     586         [ -  + ]:        176 :                 TEST_ASSERT_SUCCESS(rte_cryptodev_queue_pair_setup(
     587                 :            :                         ts_params->valid_devs[0], qp_id,
     588                 :            :                         &ts_params->qp_conf,
     589                 :            :                         rte_cryptodev_socket_id(ts_params->valid_devs[0])),
     590                 :            :                         "Failed to setup queue pair %u on cryptodev %u",
     591                 :            :                         qp_id, ts_params->valid_devs[0]);
     592                 :            :         }
     593                 :            : 
     594                 :            :         /* Start the device */
     595         [ -  + ]:         22 :         TEST_ASSERT_SUCCESS(rte_cryptodev_start(ts_params->valid_devs[0]),
     596                 :            :                                                 "Failed to start cryptodev %u",
     597                 :            :                                                 ts_params->valid_devs[0]);
     598                 :            : 
     599                 :            :         return TEST_SUCCESS;
     600                 :            : }
     601                 :            : 
     602                 :            : static void
     603                 :         22 : ut_teardown_asym(void)
     604                 :            : {
     605                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     606                 :         22 :         uint8_t dev_id = ts_params->valid_devs[0];
     607                 :            : 
     608         [ +  + ]:         22 :         if (self->sess != NULL)
     609                 :          8 :                 rte_cryptodev_asym_session_free(dev_id, self->sess);
     610                 :         22 :         rte_crypto_op_free(self->op);
     611                 :         22 :         self->sess = NULL;
     612                 :         22 :         self->op = NULL;
     613                 :         22 :         self->result_op = NULL;
     614                 :            : 
     615                 :            :         /* Stop the device */
     616                 :         22 :         rte_cryptodev_stop(ts_params->valid_devs[0]);
     617                 :         22 : }
     618                 :            : 
     619                 :          8 : static inline void print_asym_capa(
     620                 :            :                 const struct rte_cryptodev_asymmetric_xform_capability *capa)
     621                 :            : {
     622                 :            :         int i = 0;
     623                 :            : 
     624                 :          8 :         printf("\nxform type: %s\n===================\n",
     625                 :          8 :                         rte_cryptodev_asym_get_xform_string(capa->xform_type));
     626                 :            :         printf("operation supported -");
     627                 :            : 
     628         [ +  + ]:         40 :         for (i = 0; i < RTE_CRYPTO_ASYM_OP_LIST_END; i++) {
     629                 :            :                 /* check supported operations */
     630         [ +  + ]:         32 :                 if (rte_cryptodev_asym_xform_capability_check_optype(capa, i)) {
     631         [ +  + ]:         15 :                         if (capa->xform_type == RTE_CRYPTO_ASYM_XFORM_DH)
     632                 :          3 :                                 printf(" %s", rte_crypto_asym_ke_strings[i]);
     633                 :            :                         else
     634                 :         12 :                                 printf(" %s", rte_crypto_asym_op_strings[i]);
     635                 :            :                 }
     636                 :            :         }
     637         [ +  + ]:          8 :         switch (capa->xform_type) {
     638                 :          5 :         case RTE_CRYPTO_ASYM_XFORM_RSA:
     639                 :            :         case RTE_CRYPTO_ASYM_XFORM_MODINV:
     640                 :            :         case RTE_CRYPTO_ASYM_XFORM_MODEX:
     641                 :            :         case RTE_CRYPTO_ASYM_XFORM_DH:
     642                 :            :         case RTE_CRYPTO_ASYM_XFORM_DSA:
     643                 :          5 :                 printf(" modlen: min %d max %d increment %d",
     644                 :          5 :                                 capa->modlen.min,
     645                 :          5 :                                 capa->modlen.max,
     646                 :          5 :                                 capa->modlen.increment);
     647                 :            :         break;
     648                 :            :         case RTE_CRYPTO_ASYM_XFORM_ECDSA:
     649                 :            :         case RTE_CRYPTO_ASYM_XFORM_ECPM:
     650                 :            :         case RTE_CRYPTO_ASYM_XFORM_SM2:
     651                 :            :         default:
     652                 :            :                 break;
     653                 :            :         }
     654                 :            :         printf("\n");
     655                 :          8 : }
     656                 :            : 
     657                 :            : static int
     658                 :          1 : test_capability(void)
     659                 :            : {
     660                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     661                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     662                 :            :         struct rte_cryptodev_info dev_info;
     663                 :            :         const struct rte_cryptodev_capabilities *dev_capa;
     664                 :            :         int i = 0;
     665                 :            :         struct rte_cryptodev_asym_capability_idx idx;
     666                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
     667                 :            : 
     668                 :          1 :         rte_cryptodev_info_get(dev_id, &dev_info);
     669         [ -  + ]:          1 :         if (!(dev_info.feature_flags &
     670                 :            :                                 RTE_CRYPTODEV_FF_ASYMMETRIC_CRYPTO)) {
     671                 :          0 :                 RTE_LOG(INFO, USER1,
     672                 :            :                                 "Device doesn't support asymmetric. Test Skipped\n");
     673                 :          0 :                 return TEST_SKIPPED;
     674                 :            :         }
     675                 :            : 
     676                 :            :         /* print xform capability */
     677                 :            :         for (i = 0;
     678         [ +  + ]:         31 :                 dev_info.capabilities[i].op != RTE_CRYPTO_OP_TYPE_UNDEFINED;
     679                 :         30 :                 i++) {
     680                 :            :                 dev_capa = &(dev_info.capabilities[i]);
     681         [ +  + ]:         30 :                 if (dev_info.capabilities[i].op ==
     682                 :            :                                 RTE_CRYPTO_OP_TYPE_ASYMMETRIC) {
     683                 :          8 :                         idx.type = dev_capa->asym.xform_capa.xform_type;
     684                 :            : 
     685                 :          8 :                         capa = rte_cryptodev_asym_capability_get(dev_id,
     686                 :            :                                 (const struct
     687                 :            :                                 rte_cryptodev_asym_capability_idx *) &idx);
     688         [ -  + ]:          8 :                         TEST_ASSERT_NOT_NULL(capa, "Failed to get asymmetric capability");
     689                 :          8 :                         print_asym_capa(capa);
     690                 :            :                         }
     691                 :            :         }
     692                 :            :         return TEST_SUCCESS;
     693                 :            : }
     694                 :            : 
     695                 :            : static int
     696                 :          1 : test_dh_gen_shared_sec(struct rte_crypto_asym_xform *xfrm)
     697                 :            : {
     698                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     699                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
     700                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     701                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     702                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
     703                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
     704                 :          1 :         void *sess = NULL;
     705                 :            :         int ret, status = TEST_SUCCESS;
     706                 :            :         uint8_t output[TEST_DH_MOD_LEN];
     707                 :          1 :         struct rte_crypto_asym_xform xform = *xfrm;
     708                 :          1 :         uint8_t peer[] = "01234567890123456789012345678901234567890123456789";
     709                 :            : 
     710                 :            :         /* set up crypto op data structure */
     711                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     712         [ -  + ]:          1 :         if (!op) {
     713                 :          0 :                 RTE_LOG(ERR, USER1,
     714                 :            :                         "line %u FAILED: %s",
     715                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
     716                 :            :                         "operation struct");
     717                 :            :                 status = TEST_FAILED;
     718                 :          0 :                 goto error_exit;
     719                 :            :         }
     720                 :            :         asym_op = op->asym;
     721                 :            : 
     722                 :            :         /* Setup a xform and op to generate private key only */
     723                 :          1 :         xform.next = NULL;
     724                 :          1 :         asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
     725                 :          1 :         asym_op->dh.priv_key.data = dh_test_params.priv_key.data;
     726                 :          1 :         asym_op->dh.priv_key.length = dh_test_params.priv_key.length;
     727                 :          1 :         asym_op->dh.pub_key.data = (uint8_t *)peer;
     728                 :          1 :         asym_op->dh.pub_key.length = sizeof(peer);
     729                 :          1 :         asym_op->dh.shared_secret.data = output;
     730                 :          1 :         asym_op->dh.shared_secret.length = sizeof(output);
     731                 :            : 
     732                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
     733         [ -  + ]:          1 :         if (ret < 0) {
     734                 :          0 :                 RTE_LOG(ERR, USER1,
     735                 :            :                                 "line %u FAILED: %s", __LINE__,
     736                 :            :                                 "Session creation failed");
     737         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     738                 :          0 :                 goto error_exit;
     739                 :            :         }
     740                 :            : 
     741                 :            :         /* attach asymmetric crypto session to crypto operations */
     742         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
     743                 :            : 
     744                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
     745                 :            : 
     746                 :            :         /* Process crypto operation */
     747         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
     748                 :          0 :                 RTE_LOG(ERR, USER1,
     749                 :            :                         "line %u FAILED: %s",
     750                 :            :                         __LINE__, "Error sending packet for operation");
     751                 :            :                 status = TEST_FAILED;
     752                 :          0 :                 goto error_exit;
     753                 :            :         }
     754                 :            : 
     755         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     756                 :            :                 rte_pause();
     757                 :            : 
     758         [ -  + ]:          1 :         if (result_op == NULL) {
     759                 :          0 :                 RTE_LOG(ERR, USER1,
     760                 :            :                         "line %u FAILED: %s",
     761                 :            :                         __LINE__, "Failed to process asym crypto op");
     762                 :            :                 status = TEST_FAILED;
     763                 :          0 :                 goto error_exit;
     764                 :            :         }
     765                 :            : 
     766                 :          1 :         debug_hexdump(stdout, "shared secret:",
     767                 :          1 :                         asym_op->dh.shared_secret.data,
     768                 :            :                         asym_op->dh.shared_secret.length);
     769                 :            : 
     770                 :          1 : error_exit:
     771         [ +  - ]:          1 :         if (sess != NULL)
     772                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
     773                 :          1 :         rte_crypto_op_free(op);
     774                 :          1 :         return status;
     775                 :            : }
     776                 :            : 
     777                 :            : static int
     778                 :          1 : test_dh_gen_priv_key(struct rte_crypto_asym_xform *xfrm)
     779                 :            : {
     780                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     781                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
     782                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     783                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     784                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
     785                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
     786                 :          1 :         void *sess = NULL;
     787                 :            :         int ret, status = TEST_SUCCESS;
     788                 :            :         uint8_t output[TEST_DH_MOD_LEN];
     789                 :          1 :         struct rte_crypto_asym_xform xform = *xfrm;
     790                 :            : 
     791                 :            :         /* set up crypto op data structure */
     792                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     793         [ -  + ]:          1 :         if (!op) {
     794                 :          0 :                 RTE_LOG(ERR, USER1,
     795                 :            :                         "line %u FAILED: %s",
     796                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
     797                 :            :                         "operation struct");
     798                 :            :                 status = TEST_FAILED;
     799                 :          0 :                 goto error_exit;
     800                 :            :         }
     801                 :            :         asym_op = op->asym;
     802                 :            : 
     803                 :            :         /* Setup a xform and op to generate private key only */
     804                 :          1 :         xform.next = NULL;
     805                 :          1 :         asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
     806                 :          1 :         asym_op->dh.priv_key.data = output;
     807                 :          1 :         asym_op->dh.priv_key.length = sizeof(output);
     808                 :            : 
     809                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
     810         [ -  + ]:          1 :         if (ret < 0) {
     811                 :          0 :                 RTE_LOG(ERR, USER1,
     812                 :            :                                 "line %u FAILED: %s", __LINE__,
     813                 :            :                                 "Session creation failed");
     814         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     815                 :          0 :                 goto error_exit;
     816                 :            :         }
     817                 :            : 
     818                 :            :         /* attach asymmetric crypto session to crypto operations */
     819         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
     820                 :            : 
     821                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
     822                 :            : 
     823                 :            :         /* Process crypto operation */
     824         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
     825                 :          0 :                 RTE_LOG(ERR, USER1,
     826                 :            :                         "line %u FAILED: %s",
     827                 :            :                         __LINE__, "Error sending packet for operation");
     828                 :            :                 status = TEST_FAILED;
     829                 :          0 :                 goto error_exit;
     830                 :            :         }
     831                 :            : 
     832         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     833                 :            :                 rte_pause();
     834                 :            : 
     835         [ -  + ]:          1 :         if (result_op == NULL) {
     836                 :          0 :                 RTE_LOG(ERR, USER1,
     837                 :            :                         "line %u FAILED: %s",
     838                 :            :                         __LINE__, "Failed to process asym crypto op");
     839                 :            :                 status = TEST_FAILED;
     840                 :          0 :                 goto error_exit;
     841                 :            :         }
     842                 :            : 
     843                 :          1 :         debug_hexdump(stdout, "private key:",
     844                 :          1 :                         asym_op->dh.priv_key.data,
     845                 :            :                         asym_op->dh.priv_key.length);
     846                 :            : 
     847                 :            : 
     848                 :          1 : error_exit:
     849         [ +  - ]:          1 :         if (sess != NULL)
     850                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
     851                 :          1 :         rte_crypto_op_free(op);
     852                 :            : 
     853                 :          1 :         return status;
     854                 :            : }
     855                 :            : 
     856                 :            : 
     857                 :            : static int
     858                 :          1 : test_dh_gen_pub_key(struct rte_crypto_asym_xform *xfrm)
     859                 :            : {
     860                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     861                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
     862                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     863                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     864                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
     865                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
     866                 :          1 :         void *sess = NULL;
     867                 :            :         int ret, status = TEST_SUCCESS;
     868                 :            :         uint8_t output[TEST_DH_MOD_LEN];
     869                 :          1 :         struct rte_crypto_asym_xform xform = *xfrm;
     870                 :            : 
     871                 :            :         /* set up crypto op data structure */
     872                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     873         [ -  + ]:          1 :         if (!op) {
     874                 :          0 :                 RTE_LOG(ERR, USER1,
     875                 :            :                         "line %u FAILED: %s",
     876                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
     877                 :            :                         "operation struct");
     878                 :            :                 status = TEST_FAILED;
     879                 :          0 :                 goto error_exit;
     880                 :            :         }
     881                 :            :         asym_op = op->asym;
     882                 :            :         /* Setup a xform chain to generate public key
     883                 :            :          * using test private key
     884                 :            :          *
     885                 :            :          */
     886                 :          1 :         xform.next = NULL;
     887                 :            : 
     888                 :          1 :         asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
     889                 :          1 :         asym_op->dh.pub_key.data = output;
     890                 :          1 :         asym_op->dh.pub_key.length = sizeof(output);
     891                 :            :         /* load pre-defined private key */
     892                 :          1 :         asym_op->dh.priv_key.data = rte_malloc(NULL,
     893                 :            :                                         dh_test_params.priv_key.length,
     894                 :            :                                         0);
     895                 :          1 :         asym_op->dh.priv_key = dh_test_params.priv_key;
     896                 :            : 
     897                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
     898         [ -  + ]:          1 :         if (ret < 0) {
     899                 :          0 :                 RTE_LOG(ERR, USER1,
     900                 :            :                                 "line %u FAILED: %s", __LINE__,
     901                 :            :                                 "Session creation failed");
     902         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     903                 :          0 :                 goto error_exit;
     904                 :            :         }
     905                 :            : 
     906                 :            :         /* attach asymmetric crypto session to crypto operations */
     907         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
     908                 :            : 
     909                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
     910                 :            : 
     911                 :            :         /* Process crypto operation */
     912         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
     913                 :          0 :                 RTE_LOG(ERR, USER1,
     914                 :            :                         "line %u FAILED: %s",
     915                 :            :                         __LINE__, "Error sending packet for operation");
     916                 :            :                 status = TEST_FAILED;
     917                 :          0 :                 goto error_exit;
     918                 :            :         }
     919                 :            : 
     920         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
     921                 :            :                 rte_pause();
     922                 :            : 
     923         [ -  + ]:          1 :         if (result_op == NULL) {
     924                 :          0 :                 RTE_LOG(ERR, USER1,
     925                 :            :                         "line %u FAILED: %s",
     926                 :            :                         __LINE__, "Failed to process asym crypto op");
     927                 :            :                 status = TEST_FAILED;
     928                 :          0 :                 goto error_exit;
     929                 :            :         }
     930                 :            : 
     931                 :          1 :         debug_hexdump(stdout, "pub key:",
     932                 :          1 :                         asym_op->dh.pub_key.data, asym_op->dh.pub_key.length);
     933                 :            : 
     934                 :          1 :         debug_hexdump(stdout, "priv key:",
     935                 :          1 :                         asym_op->dh.priv_key.data, asym_op->dh.priv_key.length);
     936                 :            : 
     937                 :          1 : error_exit:
     938         [ +  - ]:          1 :         if (sess != NULL)
     939                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
     940                 :          1 :         rte_crypto_op_free(op);
     941                 :            : 
     942                 :          1 :         return status;
     943                 :            : }
     944                 :            : 
     945                 :            : static int
     946                 :          1 : test_dh_gen_kp(struct rte_crypto_asym_xform *xfrm)
     947                 :            : {
     948                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
     949                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
     950                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
     951                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
     952                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
     953                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
     954                 :          1 :         void *sess = NULL;
     955                 :            :         int ret, status = TEST_SUCCESS;
     956                 :            :         uint8_t out_pub_key[TEST_DH_MOD_LEN];
     957                 :            :         uint8_t out_prv_key[TEST_DH_MOD_LEN];
     958                 :            :         struct rte_crypto_asym_xform pub_key_xform;
     959                 :          1 :         struct rte_crypto_asym_xform xform = *xfrm;
     960                 :            : 
     961                 :            :         /* set up crypto op data structure */
     962                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
     963         [ -  + ]:          1 :         if (!op) {
     964                 :          0 :                 RTE_LOG(ERR, USER1,
     965                 :            :                         "line %u FAILED: %s",
     966                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
     967                 :            :                         "operation struct");
     968                 :            :                 status = TEST_FAILED;
     969                 :          0 :                 goto error_exit;
     970                 :            :         }
     971                 :            :         asym_op = op->asym;
     972                 :            :         /* Setup a xform chain to generate
     973                 :            :          * private key first followed by
     974                 :            :          * public key
     975                 :            :          */
     976                 :          1 :         pub_key_xform.xform_type = RTE_CRYPTO_ASYM_XFORM_DH;
     977                 :          1 :         xform.next = &pub_key_xform;
     978                 :            : 
     979                 :          1 :         asym_op->dh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
     980                 :          1 :         asym_op->dh.pub_key.data = out_pub_key;
     981                 :          1 :         asym_op->dh.pub_key.length = sizeof(out_pub_key);
     982                 :          1 :         asym_op->dh.priv_key.data = out_prv_key;
     983                 :          1 :         asym_op->dh.priv_key.length = 0;
     984                 :            : 
     985                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
     986         [ -  + ]:          1 :         if (ret < 0) {
     987                 :          0 :                 RTE_LOG(ERR, USER1,
     988                 :            :                                 "line %u FAILED: %s", __LINE__,
     989                 :            :                                 "Session creation failed");
     990         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
     991                 :          0 :                 goto error_exit;
     992                 :            :         }
     993                 :            : 
     994                 :            :         /* attach asymmetric crypto session to crypto operations */
     995         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
     996                 :            : 
     997                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
     998                 :            : 
     999                 :            :         /* Process crypto operation */
    1000         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1001                 :          0 :                 RTE_LOG(ERR, USER1,
    1002                 :            :                         "line %u FAILED: %s",
    1003                 :            :                         __LINE__, "Error sending packet for operation");
    1004                 :            :                 status = TEST_FAILED;
    1005                 :          0 :                 goto error_exit;
    1006                 :            :         }
    1007                 :            : 
    1008         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1009                 :            :                 rte_pause();
    1010                 :            : 
    1011         [ -  + ]:          1 :         if (result_op == NULL) {
    1012                 :          0 :                 RTE_LOG(ERR, USER1,
    1013                 :            :                         "line %u FAILED: %s",
    1014                 :            :                         __LINE__, "Failed to process asym crypto op");
    1015                 :            :                 status = TEST_FAILED;
    1016                 :          0 :                 goto error_exit;
    1017                 :            :         }
    1018                 :          1 :         debug_hexdump(stdout, "priv key:",
    1019                 :            :                         out_prv_key, asym_op->dh.priv_key.length);
    1020                 :          1 :         debug_hexdump(stdout, "pub key:",
    1021                 :            :                         out_pub_key, asym_op->dh.pub_key.length);
    1022                 :            : 
    1023                 :          1 : error_exit:
    1024         [ +  - ]:          1 :         if (sess != NULL)
    1025                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1026                 :          1 :         rte_crypto_op_free(op);
    1027                 :            : 
    1028                 :          1 :         return status;
    1029                 :            : }
    1030                 :            : 
    1031                 :            : static int
    1032                 :          1 : test_mod_inv(void)
    1033                 :            : {
    1034                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1035                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1036                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1037                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    1038                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
    1039                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
    1040                 :          1 :         void *sess = NULL;
    1041                 :            :         int status = TEST_SUCCESS;
    1042                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1043                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability;
    1044                 :          1 :         uint8_t input[TEST_DATA_SIZE] = {0};
    1045                 :            :         int ret = 0;
    1046                 :          1 :         uint8_t result[sizeof(mod_p)] = { 0 };
    1047                 :            : 
    1048         [ -  + ]:          1 :         if (rte_cryptodev_asym_get_xform_enum(
    1049                 :            :                 &modinv_xform.xform_type, "modinv") < 0) {
    1050                 :          0 :                 RTE_LOG(ERR, USER1,
    1051                 :            :                                  "Invalid ASYM algorithm specified\n");
    1052                 :          0 :                 return -1;
    1053                 :            :         }
    1054                 :            : 
    1055                 :          1 :         cap_idx.type = modinv_xform.xform_type;
    1056                 :          1 :         capability = rte_cryptodev_asym_capability_get(dev_id,
    1057                 :            :                                         &cap_idx);
    1058                 :            : 
    1059         [ -  + ]:          1 :         if (capability == NULL) {
    1060                 :          0 :                 RTE_LOG(INFO, USER1,
    1061                 :            :                         "Device doesn't support MOD INV. Test Skipped\n");
    1062                 :          0 :                 return TEST_SKIPPED;
    1063                 :            :         }
    1064                 :            : 
    1065         [ -  + ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_modlen(
    1066                 :            :                 capability,
    1067                 :          1 :                 modinv_xform.modinv.modulus.length)) {
    1068                 :          0 :                 RTE_LOG(ERR, USER1,
    1069                 :            :                                  "Invalid MODULUS length specified\n");
    1070                 :          0 :                                 return TEST_SKIPPED;
    1071                 :            :                 }
    1072                 :            : 
    1073                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &modinv_xform, sess_mpool, &sess);
    1074         [ -  + ]:          1 :         if (ret < 0) {
    1075                 :          0 :                 RTE_LOG(ERR, USER1, "line %u "
    1076                 :            :                                 "FAILED: %s", __LINE__,
    1077                 :            :                                 "Session creation failed");
    1078         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1079                 :          0 :                 goto error_exit;
    1080                 :            :         }
    1081                 :            : 
    1082                 :            :         /* generate crypto op data structure */
    1083                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1084         [ -  + ]:          1 :         if (!op) {
    1085                 :          0 :                 RTE_LOG(ERR, USER1,
    1086                 :            :                         "line %u FAILED: %s",
    1087                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
    1088                 :            :                         "operation struct");
    1089                 :            :                 status = TEST_FAILED;
    1090                 :          0 :                 goto error_exit;
    1091                 :            :         }
    1092                 :            : 
    1093                 :            :         asym_op = op->asym;
    1094                 :            :         memcpy(input, base, sizeof(base));
    1095                 :          1 :         asym_op->modinv.base.data = input;
    1096                 :          1 :         asym_op->modinv.base.length = sizeof(base);
    1097                 :          1 :         asym_op->modinv.result.data = result;
    1098                 :          1 :         asym_op->modinv.result.length = sizeof(result);
    1099                 :            : 
    1100                 :            :         /* attach asymmetric crypto session to crypto operations */
    1101         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    1102                 :            : 
    1103                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
    1104                 :            : 
    1105                 :            :         /* Process crypto operation */
    1106         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1107                 :          0 :                 RTE_LOG(ERR, USER1,
    1108                 :            :                         "line %u FAILED: %s",
    1109                 :            :                         __LINE__, "Error sending packet for operation");
    1110                 :            :                 status = TEST_FAILED;
    1111                 :          0 :                 goto error_exit;
    1112                 :            :         }
    1113                 :            : 
    1114         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1115                 :            :                 rte_pause();
    1116                 :            : 
    1117         [ -  + ]:          1 :         if (result_op == NULL) {
    1118                 :          0 :                 RTE_LOG(ERR, USER1,
    1119                 :            :                                 "line %u FAILED: %s",
    1120                 :            :                                 __LINE__, "Failed to process asym crypto op");
    1121                 :            :                 status = TEST_FAILED;
    1122                 :          0 :                 goto error_exit;
    1123                 :            :         }
    1124                 :            : 
    1125                 :            :         ret = verify_modinv(mod_inv, result_op);
    1126                 :            :         if (ret) {
    1127                 :          0 :                 RTE_LOG(ERR, USER1,
    1128                 :            :                          "operation verification failed\n");
    1129                 :            :                 status = TEST_FAILED;
    1130                 :            :         }
    1131                 :            : 
    1132                 :          1 : error_exit:
    1133         [ +  - ]:          1 :         if (sess)
    1134                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1135                 :            : 
    1136                 :          1 :         rte_crypto_op_free(op);
    1137                 :            : 
    1138         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
    1139                 :            : 
    1140                 :            :         return status;
    1141                 :            : }
    1142                 :            : 
    1143                 :            : static int
    1144                 :          1 : test_mod_exp(void)
    1145                 :            : {
    1146                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1147                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1148                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1149                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    1150                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
    1151                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
    1152                 :          1 :         void *sess = NULL;
    1153                 :            :         int status = TEST_SUCCESS;
    1154                 :            :         struct rte_cryptodev_asym_capability_idx cap_idx;
    1155                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capability;
    1156                 :          1 :         uint8_t input[TEST_DATA_SIZE] = {0};
    1157                 :            :         int ret = 0;
    1158                 :          1 :         uint8_t result[sizeof(mod_p)] = { 0 };
    1159                 :            : 
    1160         [ -  + ]:          1 :         if (rte_cryptodev_asym_get_xform_enum(&modex_xform.xform_type,
    1161                 :            :                 "modexp")
    1162                 :            :                 < 0) {
    1163                 :          0 :                 RTE_LOG(ERR, USER1,
    1164                 :            :                                 "Invalid ASYM algorithm specified\n");
    1165                 :          0 :                 return -1;
    1166                 :            :         }
    1167                 :            : 
    1168                 :            :         /* check for modlen capability */
    1169                 :          1 :         cap_idx.type = modex_xform.xform_type;
    1170                 :          1 :         capability = rte_cryptodev_asym_capability_get(dev_id, &cap_idx);
    1171                 :            : 
    1172         [ -  + ]:          1 :         if (capability == NULL) {
    1173                 :          0 :                 RTE_LOG(INFO, USER1,
    1174                 :            :                         "Device doesn't support MOD EXP. Test Skipped\n");
    1175                 :          0 :                 return TEST_SKIPPED;
    1176                 :            :         }
    1177                 :            : 
    1178         [ -  + ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_modlen(
    1179                 :          1 :                         capability, modex_xform.modex.modulus.length)) {
    1180                 :          0 :                 RTE_LOG(ERR, USER1,
    1181                 :            :                                 "Invalid MODULUS length specified\n");
    1182                 :          0 :                                 return TEST_SKIPPED;
    1183                 :            :                 }
    1184                 :            : 
    1185                 :            :         /* Create op, create session, and process packets. 8< */
    1186                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1187         [ -  + ]:          1 :         if (!op) {
    1188                 :          0 :                 RTE_LOG(ERR, USER1,
    1189                 :            :                         "line %u FAILED: %s",
    1190                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
    1191                 :            :                         "operation struct");
    1192                 :            :                 status = TEST_FAILED;
    1193                 :          0 :                 goto error_exit;
    1194                 :            :         }
    1195                 :            : 
    1196                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &modex_xform, sess_mpool, &sess);
    1197         [ -  + ]:          1 :         if (ret < 0) {
    1198                 :          0 :                 RTE_LOG(ERR, USER1,
    1199                 :            :                                  "line %u "
    1200                 :            :                                 "FAILED: %s", __LINE__,
    1201                 :            :                                 "Session creation failed");
    1202         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1203                 :          0 :                 goto error_exit;
    1204                 :            :         }
    1205                 :            : 
    1206                 :          1 :         asym_op = op->asym;
    1207                 :            :         memcpy(input, base, sizeof(base));
    1208                 :          1 :         asym_op->modex.base.data = input;
    1209                 :          1 :         asym_op->modex.base.length = sizeof(base);
    1210                 :          1 :         asym_op->modex.result.data = result;
    1211                 :          1 :         asym_op->modex.result.length = sizeof(result);
    1212                 :            :         /* attach asymmetric crypto session to crypto operations */
    1213         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    1214                 :            : 
    1215                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
    1216                 :            :         /* Process crypto operation */
    1217         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1218                 :          0 :                 RTE_LOG(ERR, USER1,
    1219                 :            :                                 "line %u FAILED: %s",
    1220                 :            :                                 __LINE__, "Error sending packet for operation");
    1221                 :            :                 status = TEST_FAILED;
    1222                 :          0 :                 goto error_exit;
    1223                 :            :         }
    1224                 :            : 
    1225         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1226                 :            :                 rte_pause();
    1227                 :            : 
    1228         [ -  + ]:          1 :         if (result_op == NULL) {
    1229                 :          0 :                 RTE_LOG(ERR, USER1,
    1230                 :            :                                 "line %u FAILED: %s",
    1231                 :            :                                 __LINE__, "Failed to process asym crypto op");
    1232                 :            :                 status = TEST_FAILED;
    1233                 :          0 :                 goto error_exit;
    1234                 :            :         }
    1235                 :            :         /* >8 End of create op, create session, and process packets section. */
    1236                 :            :         ret = verify_modexp(mod_exp, result_op);
    1237                 :            :         if (ret) {
    1238                 :          0 :                 RTE_LOG(ERR, USER1,
    1239                 :            :                          "operation verification failed\n");
    1240                 :            :                 status = TEST_FAILED;
    1241                 :            :         }
    1242                 :            : 
    1243                 :          1 : error_exit:
    1244         [ +  - ]:          1 :         if (sess != NULL)
    1245                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1246                 :            : 
    1247                 :          1 :         rte_crypto_op_free(op);
    1248                 :            : 
    1249         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
    1250                 :            : 
    1251                 :            :         return status;
    1252                 :            : }
    1253                 :            : 
    1254                 :            : static int
    1255                 :          1 : test_dh_key_generation(void)
    1256                 :            : {
    1257                 :            :         int status;
    1258                 :            : 
    1259                 :          1 :         debug_hexdump(stdout, "p:", dh_xform.dh.p.data, dh_xform.dh.p.length);
    1260                 :          1 :         debug_hexdump(stdout, "g:", dh_xform.dh.g.data, dh_xform.dh.g.length);
    1261                 :          1 :         debug_hexdump(stdout, "priv_key:", dh_test_params.priv_key.data,
    1262                 :            :                         dh_test_params.priv_key.length);
    1263                 :            : 
    1264                 :          1 :         RTE_LOG(INFO, USER1,
    1265                 :            :                 "Test Public and Private key pair generation\n");
    1266                 :            : 
    1267                 :          1 :         status = test_dh_gen_kp(&dh_xform);
    1268         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
    1269                 :            : 
    1270                 :          1 :         RTE_LOG(INFO, USER1,
    1271                 :            :                 "Test Public Key Generation using pre-defined priv key\n");
    1272                 :            : 
    1273                 :          1 :         status = test_dh_gen_pub_key(&dh_xform);
    1274         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
    1275                 :            : 
    1276                 :          1 :         RTE_LOG(INFO, USER1,
    1277                 :            :                 "Test Private Key Generation only\n");
    1278                 :            : 
    1279                 :          1 :         status = test_dh_gen_priv_key(&dh_xform);
    1280         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
    1281                 :            : 
    1282                 :          1 :         RTE_LOG(INFO, USER1,
    1283                 :            :                 "Test shared secret compute\n");
    1284                 :            : 
    1285                 :          1 :         status = test_dh_gen_shared_sec(&dh_xform);
    1286         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "Test failed");
    1287                 :            : 
    1288                 :            :         return status;
    1289                 :            : }
    1290                 :            : 
    1291                 :            : static int
    1292                 :          1 : test_dsa_sign(struct rte_crypto_dsa_op_param *dsa_op)
    1293                 :            : {
    1294                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1295                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1296                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1297                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    1298                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
    1299                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
    1300                 :          1 :         void *sess = NULL;
    1301                 :            :         int status = TEST_SUCCESS;
    1302                 :            :         int ret;
    1303                 :            : 
    1304                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
    1305         [ -  + ]:          1 :         if (ret < 0) {
    1306                 :          0 :                 RTE_LOG(ERR, USER1,
    1307                 :            :                                  "line %u FAILED: %s", __LINE__,
    1308                 :            :                                 "Session creation failed");
    1309         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1310                 :          0 :                 goto error_exit;
    1311                 :            :         }
    1312                 :            :         /* set up crypto op data structure */
    1313                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1314         [ -  + ]:          1 :         if (!op) {
    1315                 :          0 :                 RTE_LOG(ERR, USER1,
    1316                 :            :                         "line %u FAILED: %s",
    1317                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
    1318                 :            :                         "operation struct");
    1319                 :            :                 status = TEST_FAILED;
    1320                 :          0 :                 goto error_exit;
    1321                 :            :         }
    1322                 :            :         asym_op = op->asym;
    1323                 :          1 :         asym_op->dsa = *dsa_op;
    1324                 :            : 
    1325                 :          1 :         debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
    1326                 :            :                         dsa_xform.dsa.p.length);
    1327                 :          1 :         debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
    1328                 :            :                         dsa_xform.dsa.q.length);
    1329                 :          1 :         debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
    1330                 :            :                         dsa_xform.dsa.g.length);
    1331                 :          1 :         debug_hexdump(stdout, "priv_key: ", dsa_xform.dsa.x.data,
    1332                 :            :                         dsa_xform.dsa.x.length);
    1333                 :            : 
    1334                 :            :         /* attach asymmetric crypto session to crypto operations */
    1335         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    1336                 :          1 :         asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
    1337                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation");
    1338                 :            : 
    1339                 :            :         /* Process crypto operation */
    1340         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1341                 :          0 :                 RTE_LOG(ERR, USER1,
    1342                 :            :                         "line %u FAILED: %s",
    1343                 :            :                         __LINE__, "Error sending packet for operation");
    1344                 :            :                 status = TEST_FAILED;
    1345                 :          0 :                 goto error_exit;
    1346                 :            :         }
    1347                 :            : 
    1348         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1349                 :            :                 rte_pause();
    1350                 :            : 
    1351         [ -  + ]:          1 :         if (result_op == NULL) {
    1352                 :          0 :                 RTE_LOG(ERR, USER1,
    1353                 :            :                         "line %u FAILED: %s",
    1354                 :            :                         __LINE__, "Failed to process asym crypto op");
    1355                 :            :                 status = TEST_FAILED;
    1356                 :          0 :                 goto error_exit;
    1357                 :            :         }
    1358                 :            : 
    1359                 :            :         asym_op = result_op->asym;
    1360                 :          1 :         dsa_op->r.length = asym_op->dsa.r.length;
    1361                 :          1 :         dsa_op->s.length = asym_op->dsa.s.length;
    1362                 :            : 
    1363                 :          1 :         debug_hexdump(stdout, "r:",
    1364                 :          1 :                         asym_op->dsa.r.data, asym_op->dsa.r.length);
    1365                 :          1 :         debug_hexdump(stdout, "s:",
    1366                 :          1 :                         asym_op->dsa.s.data, asym_op->dsa.s.length);
    1367                 :          1 : error_exit:
    1368         [ +  - ]:          1 :         if (sess != NULL)
    1369                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1370                 :          1 :         rte_crypto_op_free(op);
    1371                 :          1 :         return status;
    1372                 :            : }
    1373                 :            : 
    1374                 :            : static int
    1375                 :          1 : test_dsa_verify(struct rte_crypto_dsa_op_param *dsa_op)
    1376                 :            : {
    1377                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1378                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1379                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1380                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    1381                 :            :         struct rte_crypto_asym_op *asym_op = NULL;
    1382                 :          1 :         struct rte_crypto_op *op = NULL, *result_op = NULL;
    1383                 :          1 :         void *sess = NULL;
    1384                 :            :         int status = TEST_SUCCESS;
    1385                 :            :         int ret;
    1386                 :            : 
    1387                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &dsa_xform, sess_mpool, &sess);
    1388         [ -  + ]:          1 :         if (ret < 0) {
    1389                 :          0 :                 RTE_LOG(ERR, USER1,
    1390                 :            :                                  "line %u FAILED: %s", __LINE__,
    1391                 :            :                                 "Session creation failed");
    1392         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1393                 :          0 :                 goto error_exit;
    1394                 :            :         }
    1395                 :            :         /* set up crypto op data structure */
    1396                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1397         [ -  + ]:          1 :         if (!op) {
    1398                 :          0 :                 RTE_LOG(ERR, USER1,
    1399                 :            :                         "line %u FAILED: %s",
    1400                 :            :                         __LINE__, "Failed to allocate asymmetric crypto "
    1401                 :            :                         "operation struct");
    1402                 :            :                 status = TEST_FAILED;
    1403                 :          0 :                 goto error_exit;
    1404                 :            :         }
    1405                 :            :         asym_op = op->asym;
    1406                 :          1 :         asym_op->dsa = *dsa_op;
    1407                 :            : 
    1408                 :          1 :         debug_hexdump(stdout, "p: ", dsa_xform.dsa.p.data,
    1409                 :            :                         dsa_xform.dsa.p.length);
    1410                 :          1 :         debug_hexdump(stdout, "q: ", dsa_xform.dsa.q.data,
    1411                 :            :                         dsa_xform.dsa.q.length);
    1412                 :          1 :         debug_hexdump(stdout, "g: ", dsa_xform.dsa.g.data,
    1413                 :            :                         dsa_xform.dsa.g.length);
    1414                 :            : 
    1415                 :            :         /* attach asymmetric crypto session to crypto operations */
    1416         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    1417                 :            : 
    1418                 :          1 :         debug_hexdump(stdout, "r:",
    1419                 :          1 :                         asym_op->dsa.r.data, asym_op->dsa.r.length);
    1420                 :          1 :         debug_hexdump(stdout, "s:",
    1421                 :          1 :                         asym_op->dsa.s.data, asym_op->dsa.s.length);
    1422                 :            : 
    1423                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM verify operation");
    1424                 :            :         /* Test PMD DSA sign verification using signer public key */
    1425                 :          1 :         asym_op->dsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    1426                 :            : 
    1427                 :            :         /* copy signer public key */
    1428                 :          1 :         asym_op->dsa.y.data = dsa_test_params.y.data;
    1429                 :          1 :         asym_op->dsa.y.length = dsa_test_params.y.length;
    1430                 :            : 
    1431                 :            :         /* Process crypto operation */
    1432         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1433                 :          0 :                 RTE_LOG(ERR, USER1,
    1434                 :            :                         "line %u FAILED: %s",
    1435                 :            :                         __LINE__, "Error sending packet for operation");
    1436                 :            :                 status = TEST_FAILED;
    1437                 :          0 :                 goto error_exit;
    1438                 :            :         }
    1439                 :            : 
    1440         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1441                 :            :                 rte_pause();
    1442                 :            : 
    1443         [ -  + ]:          1 :         if (result_op == NULL) {
    1444                 :          0 :                 RTE_LOG(ERR, USER1,
    1445                 :            :                         "line %u FAILED: %s",
    1446                 :            :                         __LINE__, "Failed to process asym crypto op");
    1447                 :            :                 status = TEST_FAILED;
    1448                 :          0 :                 goto error_exit;
    1449                 :            :         }
    1450                 :            : 
    1451         [ +  - ]:          1 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    1452                 :          0 :                 RTE_LOG(ERR, USER1,
    1453                 :            :                                 "line %u FAILED: %s",
    1454                 :            :                                 __LINE__, "Failed to process asym crypto op");
    1455                 :            :                 status = TEST_FAILED;
    1456                 :            :         }
    1457                 :          1 : error_exit:
    1458         [ +  - ]:          1 :         if (sess != NULL)
    1459                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1460                 :          1 :         rte_crypto_op_free(op);
    1461                 :          1 :         return status;
    1462                 :            : }
    1463                 :            : 
    1464                 :            : static int
    1465                 :          1 : test_dsa(void)
    1466                 :            : {
    1467                 :            :         int status;
    1468                 :            :         uint8_t r[TEST_DH_MOD_LEN];
    1469                 :            :         uint8_t s[TEST_DH_MOD_LEN];
    1470                 :            :         struct rte_crypto_dsa_op_param dsa_op;
    1471                 :          1 :         uint8_t dgst[] = "35d81554afaad2cf18f3a1770d5fedc4ea5be344";
    1472                 :            : 
    1473                 :          1 :         dsa_op.message.data = dgst;
    1474                 :          1 :         dsa_op.message.length = sizeof(dgst);
    1475                 :          1 :         dsa_op.r.data = r;
    1476                 :          1 :         dsa_op.s.data = s;
    1477                 :          1 :         dsa_op.r.length = sizeof(r);
    1478                 :          1 :         dsa_op.s.length = sizeof(s);
    1479                 :            : 
    1480                 :          1 :         status = test_dsa_sign(&dsa_op);
    1481         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "DSA sign test failed");
    1482                 :          1 :         status = test_dsa_verify(&dsa_op);
    1483         [ -  + ]:          1 :         TEST_ASSERT_EQUAL(status, 0, "DSA verify test failed");
    1484                 :            :         return status;
    1485                 :            : }
    1486                 :            : 
    1487                 :            : static int
    1488                 :          0 : test_ecdsa_sign_verify(enum curve curve_id)
    1489                 :            : {
    1490                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1491                 :          0 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1492                 :          0 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1493                 :            :         struct crypto_testsuite_ecdsa_params input_params;
    1494                 :          0 :         void *sess = NULL;
    1495                 :          0 :         uint8_t dev_id = ts_params->valid_devs[0];
    1496                 :          0 :         struct rte_crypto_op *result_op = NULL;
    1497                 :            :         uint8_t output_buf_r[TEST_DATA_SIZE];
    1498                 :            :         uint8_t output_buf_s[TEST_DATA_SIZE];
    1499                 :            :         struct rte_crypto_asym_xform xform;
    1500                 :            :         struct rte_crypto_asym_op *asym_op;
    1501                 :            :         struct rte_cryptodev_info dev_info;
    1502                 :          0 :         struct rte_crypto_op *op = NULL;
    1503                 :            :         int ret, status = TEST_SUCCESS;
    1504                 :            : 
    1505   [ #  #  #  #  :          0 :         switch (curve_id) {
                #  #  # ]
    1506                 :          0 :         case SECP192R1:
    1507                 :          0 :                 input_params = ecdsa_param_secp192r1;
    1508                 :          0 :                 break;
    1509                 :          0 :         case SECP224R1:
    1510                 :          0 :                 input_params = ecdsa_param_secp224r1;
    1511                 :          0 :                 break;
    1512                 :          0 :         case SECP256R1:
    1513                 :          0 :                 input_params = ecdsa_param_secp256r1;
    1514                 :          0 :                 break;
    1515                 :          0 :         case SECP384R1:
    1516                 :          0 :                 input_params = ecdsa_param_secp384r1;
    1517                 :          0 :                 break;
    1518                 :          0 :         case SECP521R1:
    1519                 :          0 :                 input_params = ecdsa_param_secp521r1;
    1520                 :          0 :                 break;
    1521                 :          0 :         case SECP521R1_UA:
    1522                 :          0 :                 input_params = ecdsa_param_secp521r1_ua;
    1523                 :          0 :                 break;
    1524                 :          0 :         default:
    1525                 :          0 :                 RTE_LOG(ERR, USER1,
    1526                 :            :                                 "line %u FAILED: %s", __LINE__,
    1527                 :            :                                 "Unsupported curve id\n");
    1528                 :            :                 status = TEST_FAILED;
    1529                 :          0 :                 goto exit;
    1530                 :            :         }
    1531                 :            : 
    1532                 :          0 :         rte_cryptodev_info_get(dev_id, &dev_info);
    1533                 :            : 
    1534                 :            :         /* Setup crypto op data structure */
    1535                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1536         [ #  # ]:          0 :         if (op == NULL) {
    1537                 :          0 :                 RTE_LOG(ERR, USER1,
    1538                 :            :                                 "line %u FAILED: %s", __LINE__,
    1539                 :            :                                 "Failed to allocate asymmetric crypto "
    1540                 :            :                                 "operation struct\n");
    1541                 :            :                 status = TEST_FAILED;
    1542                 :          0 :                 goto exit;
    1543                 :            :         }
    1544                 :            :         asym_op = op->asym;
    1545                 :            : 
    1546                 :            :         /* Setup asym xform */
    1547                 :          0 :         xform.next = NULL;
    1548                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
    1549                 :          0 :         xform.ec.curve_id = input_params.curve;
    1550                 :          0 :         xform.ec.pkey.data = input_params.pkey.data;
    1551                 :          0 :         xform.ec.pkey.length = input_params.pkey.length;
    1552                 :          0 :         xform.ec.q.x.data = input_params.pubkey_qx.data;
    1553                 :          0 :         xform.ec.q.x.length = input_params.pubkey_qx.length;
    1554                 :          0 :         xform.ec.q.y.data = input_params.pubkey_qy.data;
    1555                 :          0 :         xform.ec.q.y.length = input_params.pubkey_qy.length;
    1556                 :            : 
    1557                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    1558         [ #  # ]:          0 :         if (ret < 0) {
    1559                 :          0 :                 RTE_LOG(ERR, USER1,
    1560                 :            :                                 "line %u FAILED: %s", __LINE__,
    1561                 :            :                                 "Session creation failed\n");
    1562         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1563                 :          0 :                 goto exit;
    1564                 :            :         }
    1565                 :            : 
    1566                 :            :         /* Attach asymmetric crypto session to crypto operations */
    1567         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    1568                 :            : 
    1569                 :            :         /* Compute sign */
    1570                 :            : 
    1571                 :            :         /* Populate op with operational details */
    1572                 :          0 :         op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
    1573                 :          0 :         op->asym->ecdsa.message.data = input_params.digest.data;
    1574                 :          0 :         op->asym->ecdsa.message.length = input_params.digest.length;
    1575                 :          0 :         op->asym->ecdsa.k.data = input_params.scalar.data;
    1576                 :          0 :         op->asym->ecdsa.k.length = input_params.scalar.length;
    1577                 :            : 
    1578                 :            :         /* Init out buf */
    1579                 :          0 :         op->asym->ecdsa.r.data = output_buf_r;
    1580                 :          0 :         op->asym->ecdsa.s.data = output_buf_s;
    1581                 :            : 
    1582                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    1583                 :            : 
    1584                 :            :         /* Process crypto operation */
    1585         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1586                 :          0 :                 RTE_LOG(ERR, USER1,
    1587                 :            :                                 "line %u FAILED: %s", __LINE__,
    1588                 :            :                                 "Error sending packet for operation\n");
    1589                 :            :                 status = TEST_FAILED;
    1590                 :          0 :                 goto exit;
    1591                 :            :         }
    1592                 :            : 
    1593         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1594                 :            :                 rte_pause();
    1595                 :            : 
    1596         [ #  # ]:          0 :         if (result_op == NULL) {
    1597                 :          0 :                 RTE_LOG(ERR, USER1,
    1598                 :            :                                 "line %u FAILED: %s", __LINE__,
    1599                 :            :                                 "Failed to process asym crypto op\n");
    1600                 :            :                 status = TEST_FAILED;
    1601                 :          0 :                 goto exit;
    1602                 :            :         }
    1603                 :            : 
    1604         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    1605                 :          0 :                 RTE_LOG(ERR, USER1,
    1606                 :            :                                 "line %u FAILED: %s", __LINE__,
    1607                 :            :                                 "Failed to process asym crypto op\n");
    1608                 :            :                 status = TEST_FAILED;
    1609                 :          0 :                 goto exit;
    1610                 :            :         }
    1611                 :            : 
    1612                 :            :         asym_op = result_op->asym;
    1613                 :            : 
    1614                 :          0 :         debug_hexdump(stdout, "r:",
    1615                 :          0 :                         asym_op->ecdsa.r.data, asym_op->ecdsa.r.length);
    1616                 :          0 :         debug_hexdump(stdout, "s:",
    1617                 :          0 :                         asym_op->ecdsa.s.data, asym_op->ecdsa.s.length);
    1618                 :            : 
    1619                 :          0 :         ret = verify_ecdsa_sign(input_params.sign_r.data,
    1620                 :            :                                 input_params.sign_s.data, result_op);
    1621         [ #  # ]:          0 :         if (ret) {
    1622                 :            :                 status = TEST_FAILED;
    1623                 :          0 :                 RTE_LOG(ERR, USER1,
    1624                 :            :                                 "line %u FAILED: %s", __LINE__,
    1625                 :            :                                 "ECDSA sign failed.\n");
    1626                 :          0 :                 goto exit;
    1627                 :            :         }
    1628                 :            : 
    1629                 :            :         /* Verify sign */
    1630                 :            : 
    1631                 :            :         /* Populate op with operational details */
    1632                 :          0 :         op->asym->ecdsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    1633                 :          0 :         op->asym->ecdsa.r.data = asym_op->ecdsa.r.data;
    1634                 :          0 :         op->asym->ecdsa.r.length = asym_op->ecdsa.r.length;
    1635                 :          0 :         op->asym->ecdsa.s.data = asym_op->ecdsa.s.data;
    1636                 :          0 :         op->asym->ecdsa.s.length = asym_op->ecdsa.s.length;
    1637                 :            : 
    1638                 :            :         /* Enqueue sign result for verify */
    1639         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1640                 :            :                 status = TEST_FAILED;
    1641                 :          0 :                 RTE_LOG(ERR, USER1,
    1642                 :            :                                 "line %u FAILED: %s", __LINE__,
    1643                 :            :                                 "Error sending packet for operation\n");
    1644                 :          0 :                 goto exit;
    1645                 :            :         }
    1646                 :            : 
    1647         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1648                 :            :                 rte_pause();
    1649                 :            : 
    1650         [ #  # ]:          0 :         if (result_op == NULL) {
    1651                 :            :                 status = TEST_FAILED;
    1652                 :          0 :                 goto exit;
    1653                 :            :         }
    1654         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    1655                 :            :                 status = TEST_FAILED;
    1656                 :          0 :                 RTE_LOG(ERR, USER1,
    1657                 :            :                                 "line %u FAILED: %s", __LINE__,
    1658                 :            :                                 "ECDSA verify failed.\n");
    1659                 :          0 :                 goto exit;
    1660                 :            :         }
    1661                 :            : 
    1662                 :          0 : exit:
    1663         [ #  # ]:          0 :         if (sess != NULL)
    1664                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1665                 :          0 :         rte_crypto_op_free(op);
    1666                 :          0 :         return status;
    1667                 :            : };
    1668                 :            : 
    1669                 :            : static int
    1670                 :          0 : test_ecdsa_sign_verify_all_curve(void)
    1671                 :            : {
    1672                 :            :         int status, overall_status = TEST_SUCCESS;
    1673                 :            :         enum curve curve_id;
    1674                 :            :         int test_index = 0;
    1675                 :            :         const char *msg;
    1676                 :            : 
    1677         [ #  # ]:          0 :         for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
    1678         [ #  # ]:          0 :                 if (curve_id == ED25519 || curve_id == ED448)
    1679                 :          0 :                         continue;
    1680                 :            : 
    1681                 :          0 :                 status = test_ecdsa_sign_verify(curve_id);
    1682         [ #  # ]:          0 :                 if (status == TEST_SUCCESS) {
    1683                 :            :                         msg = "succeeded";
    1684                 :            :                 } else {
    1685                 :            :                         msg = "failed";
    1686                 :            :                         overall_status = status;
    1687                 :            :                 }
    1688                 :          0 :                 printf("  %u) TestCase Sign/Veriy Curve %s  %s\n",
    1689                 :            :                        test_index ++, curve[curve_id], msg);
    1690                 :            :         }
    1691                 :          0 :         return overall_status;
    1692                 :            : }
    1693                 :            : 
    1694                 :            : static int
    1695                 :          0 : test_ecpm(enum curve curve_id)
    1696                 :            : {
    1697                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1698                 :          0 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1699                 :          0 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1700                 :            :         struct crypto_testsuite_ecpm_params input_params;
    1701                 :          0 :         void *sess = NULL;
    1702                 :          0 :         uint8_t dev_id = ts_params->valid_devs[0];
    1703                 :          0 :         struct rte_crypto_op *result_op = NULL;
    1704                 :            :         uint8_t output_buf_x[TEST_DATA_SIZE];
    1705                 :            :         uint8_t output_buf_y[TEST_DATA_SIZE];
    1706                 :            :         struct rte_crypto_asym_xform xform;
    1707                 :            :         struct rte_crypto_asym_op *asym_op;
    1708                 :            :         struct rte_cryptodev_info dev_info;
    1709                 :          0 :         struct rte_crypto_op *op = NULL;
    1710                 :            :         int ret, status = TEST_SUCCESS;
    1711                 :            : 
    1712   [ #  #  #  #  :          0 :         switch (curve_id) {
                   #  # ]
    1713                 :          0 :         case SECP192R1:
    1714                 :          0 :                 input_params = ecpm_param_secp192r1;
    1715                 :          0 :                 break;
    1716                 :          0 :         case SECP224R1:
    1717                 :          0 :                 input_params = ecpm_param_secp224r1;
    1718                 :          0 :                 break;
    1719                 :          0 :         case SECP256R1:
    1720                 :          0 :                 input_params = ecpm_param_secp256r1;
    1721                 :          0 :                 break;
    1722                 :          0 :         case SECP384R1:
    1723                 :          0 :                 input_params = ecpm_param_secp384r1;
    1724                 :          0 :                 break;
    1725                 :          0 :         case SECP521R1:
    1726                 :          0 :                 input_params = ecpm_param_secp521r1;
    1727                 :          0 :                 break;
    1728                 :          0 :         default:
    1729                 :          0 :                 RTE_LOG(ERR, USER1,
    1730                 :            :                                 "line %u FAILED: %s", __LINE__,
    1731                 :            :                                 "Unsupported curve id\n");
    1732                 :            :                 status = TEST_FAILED;
    1733                 :          0 :                 goto exit;
    1734                 :            :         }
    1735                 :            : 
    1736                 :          0 :         rte_cryptodev_info_get(dev_id, &dev_info);
    1737                 :            : 
    1738                 :            :         /* Setup crypto op data structure */
    1739                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1740         [ #  # ]:          0 :         if (op == NULL) {
    1741                 :          0 :                 RTE_LOG(ERR, USER1,
    1742                 :            :                                 "line %u FAILED: %s", __LINE__,
    1743                 :            :                                 "Failed to allocate asymmetric crypto "
    1744                 :            :                                 "operation struct\n");
    1745                 :            :                 status = TEST_FAILED;
    1746                 :          0 :                 goto exit;
    1747                 :            :         }
    1748                 :            :         asym_op = op->asym;
    1749                 :            : 
    1750                 :            :         /* Setup asym xform */
    1751                 :          0 :         xform.next = NULL;
    1752                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECPM;
    1753                 :          0 :         xform.ec.curve_id = input_params.curve;
    1754                 :            : 
    1755                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    1756         [ #  # ]:          0 :         if (ret < 0) {
    1757                 :          0 :                 RTE_LOG(ERR, USER1,
    1758                 :            :                                 "line %u FAILED: %s", __LINE__,
    1759                 :            :                                 "Session creation failed\n");
    1760         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1761                 :          0 :                 goto exit;
    1762                 :            :         }
    1763                 :            : 
    1764                 :            :         /* Attach asymmetric crypto session to crypto operations */
    1765         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    1766                 :            : 
    1767                 :            :         /* Populate op with operational details */
    1768                 :          0 :         op->asym->ecpm.p.x.data = input_params.gen_x.data;
    1769                 :          0 :         op->asym->ecpm.p.x.length = input_params.gen_x.length;
    1770                 :          0 :         op->asym->ecpm.p.y.data = input_params.gen_y.data;
    1771                 :          0 :         op->asym->ecpm.p.y.length = input_params.gen_y.length;
    1772                 :          0 :         op->asym->ecpm.scalar.data = input_params.privkey.data;
    1773                 :          0 :         op->asym->ecpm.scalar.length = input_params.privkey.length;
    1774                 :            : 
    1775                 :            :         /* Init out buf */
    1776                 :          0 :         op->asym->ecpm.r.x.data = output_buf_x;
    1777                 :          0 :         op->asym->ecpm.r.y.data = output_buf_y;
    1778                 :            : 
    1779                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    1780                 :            : 
    1781                 :            :         /* Process crypto operation */
    1782         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1783                 :          0 :                 RTE_LOG(ERR, USER1,
    1784                 :            :                                 "line %u FAILED: %s", __LINE__,
    1785                 :            :                                 "Error sending packet for operation\n");
    1786                 :            :                 status = TEST_FAILED;
    1787                 :          0 :                 goto exit;
    1788                 :            :         }
    1789                 :            : 
    1790         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1791                 :            :                 rte_pause();
    1792                 :            : 
    1793         [ #  # ]:          0 :         if (result_op == NULL) {
    1794                 :          0 :                 RTE_LOG(ERR, USER1,
    1795                 :            :                                 "line %u FAILED: %s", __LINE__,
    1796                 :            :                                 "Failed to process asym crypto op\n");
    1797                 :            :                 status = TEST_FAILED;
    1798                 :          0 :                 goto exit;
    1799                 :            :         }
    1800                 :            : 
    1801         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    1802                 :          0 :                 RTE_LOG(ERR, USER1,
    1803                 :            :                                 "line %u FAILED: %s", __LINE__,
    1804                 :            :                                 "Failed to process asym crypto op\n");
    1805                 :            :                 status = TEST_FAILED;
    1806                 :          0 :                 goto exit;
    1807                 :            :         }
    1808                 :            : 
    1809                 :            :         asym_op = result_op->asym;
    1810                 :            : 
    1811                 :          0 :         debug_hexdump(stdout, "r x:",
    1812                 :          0 :                         asym_op->ecpm.r.x.data, asym_op->ecpm.r.x.length);
    1813                 :          0 :         debug_hexdump(stdout, "r y:",
    1814                 :          0 :                         asym_op->ecpm.r.y.data, asym_op->ecpm.r.y.length);
    1815                 :            : 
    1816                 :          0 :         ret = verify_ecpm(input_params.pubkey_x.data,
    1817                 :            :                                 input_params.pubkey_y.data, result_op);
    1818         [ #  # ]:          0 :         if (ret) {
    1819                 :            :                 status = TEST_FAILED;
    1820                 :          0 :                 RTE_LOG(ERR, USER1,
    1821                 :            :                                 "line %u FAILED: %s", __LINE__,
    1822                 :            :                                 "EC Point Multiplication failed.\n");
    1823                 :          0 :                 goto exit;
    1824                 :            :         }
    1825                 :            : 
    1826                 :          0 : exit:
    1827         [ #  # ]:          0 :         if (sess != NULL)
    1828                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1829                 :          0 :         rte_crypto_op_free(op);
    1830                 :          0 :         return status;
    1831                 :            : }
    1832                 :            : 
    1833                 :            : static int
    1834                 :          0 : test_ecpm_all_curve(void)
    1835                 :            : {
    1836                 :            :         int status, overall_status = TEST_SUCCESS;
    1837                 :            :         enum curve curve_id;
    1838                 :            :         int test_index = 0;
    1839                 :            :         const char *msg;
    1840                 :            : 
    1841         [ #  # ]:          0 :         for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
    1842         [ #  # ]:          0 :                 if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
    1843                 :          0 :                         continue;
    1844                 :            : 
    1845                 :          0 :                 status = test_ecpm(curve_id);
    1846         [ #  # ]:          0 :                 if (status == TEST_SUCCESS) {
    1847                 :            :                         msg = "succeeded";
    1848                 :            :                 } else {
    1849                 :            :                         msg = "failed";
    1850                 :            :                         overall_status = status;
    1851                 :            :                 }
    1852                 :          0 :                 printf("  %u) TestCase EC Point Mul Curve %s  %s\n",
    1853                 :            :                        test_index ++, curve[curve_id], msg);
    1854                 :            :         }
    1855                 :          0 :         return overall_status;
    1856                 :            : }
    1857                 :            : 
    1858                 :            : static int
    1859                 :          0 : test_ecdh_priv_key_generate(enum curve curve_id)
    1860                 :            : {
    1861                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1862                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    1863                 :          0 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1864                 :          0 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    1865                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    1866                 :          0 :         uint8_t dev_id = ts_params->valid_devs[0];
    1867                 :          0 :         struct rte_crypto_asym_xform xform = {0};
    1868                 :          0 :         struct rte_crypto_op *result_op = NULL;
    1869                 :            :         uint8_t output_buf[TEST_DATA_SIZE];
    1870                 :            :         struct rte_crypto_asym_op *asym_op;
    1871                 :          0 :         struct rte_crypto_op *op = NULL;
    1872                 :            :         int ret, status = TEST_SUCCESS;
    1873                 :            :         uint16_t output_buflen = 0;
    1874                 :          0 :         void *sess = NULL;
    1875                 :            :         int curve;
    1876                 :            : 
    1877                 :            :         /* Check ECDH capability */
    1878                 :          0 :         idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    1879                 :          0 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    1880         [ #  # ]:          0 :         if (capa == NULL)
    1881                 :            :                 return -ENOTSUP;
    1882                 :            : 
    1883         [ #  # ]:          0 :         if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE)))
    1884                 :            :                 return -ENOTSUP;
    1885                 :            : 
    1886                 :            :         switch (curve_id) {
    1887                 :            :         case SECP192R1:
    1888                 :            :                 curve = RTE_CRYPTO_EC_GROUP_SECP192R1;
    1889                 :            :                 output_buflen = 24;
    1890                 :            :                 break;
    1891                 :            :         case SECP224R1:
    1892                 :            :                 curve = RTE_CRYPTO_EC_GROUP_SECP224R1;
    1893                 :            :                 output_buflen = 28;
    1894                 :            :                 break;
    1895                 :            :         case SECP256R1:
    1896                 :            :                 curve = RTE_CRYPTO_EC_GROUP_SECP256R1;
    1897                 :            :                 output_buflen = 32;
    1898                 :            :                 break;
    1899                 :            :         case SECP384R1:
    1900                 :            :                 curve = RTE_CRYPTO_EC_GROUP_SECP384R1;
    1901                 :            :                 output_buflen = 48;
    1902                 :            :                 break;
    1903                 :            :         case SECP521R1:
    1904                 :            :                 curve = RTE_CRYPTO_EC_GROUP_SECP521R1;
    1905                 :            :                 output_buflen = 66;
    1906                 :            :                 break;
    1907                 :          0 :         default:
    1908                 :          0 :                 RTE_LOG(ERR, USER1,
    1909                 :            :                                 "line %u FAILED: %s", __LINE__,
    1910                 :            :                                 "Unsupported curve id\n");
    1911                 :            :                 status = TEST_FAILED;
    1912                 :          0 :                 goto exit;
    1913                 :            :         }
    1914                 :            : 
    1915                 :            :         /* Setup crypto op data structure */
    1916                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    1917         [ #  # ]:          0 :         if (op == NULL) {
    1918                 :          0 :                 RTE_LOG(ERR, USER1,
    1919                 :            :                                 "line %u FAILED: %s", __LINE__,
    1920                 :            :                                 "Failed to allocate asymmetric crypto "
    1921                 :            :                                 "operation struct\n");
    1922                 :            :                 status = TEST_FAILED;
    1923                 :          0 :                 goto exit;
    1924                 :            :         }
    1925                 :            :         asym_op = op->asym;
    1926                 :            : 
    1927                 :            :         /* Setup asym xform */
    1928                 :          0 :         xform.next = NULL;
    1929                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    1930                 :          0 :         xform.ec.curve_id = curve;
    1931                 :            : 
    1932                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    1933         [ #  # ]:          0 :         if (ret < 0) {
    1934                 :          0 :                 RTE_LOG(ERR, USER1,
    1935                 :            :                                 "line %u FAILED: %s", __LINE__,
    1936                 :            :                                 "Session creation failed\n");
    1937         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    1938                 :          0 :                 goto exit;
    1939                 :            :         }
    1940                 :            : 
    1941                 :            :         /* Attach asymmetric crypto session to crypto operations */
    1942         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    1943                 :            : 
    1944                 :            :         /* Populate op with operational details */
    1945                 :          0 :         asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PRIV_KEY_GENERATE;
    1946                 :            : 
    1947                 :            :         /* Init out buf */
    1948                 :          0 :         asym_op->ecdh.priv_key.data = output_buf;
    1949                 :          0 :         asym_op->ecdh.priv_key.length = output_buflen;
    1950                 :            : 
    1951                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    1952                 :            : 
    1953                 :            :         /* Process crypto operation */
    1954         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    1955                 :          0 :                 RTE_LOG(ERR, USER1,
    1956                 :            :                                 "line %u FAILED: %s", __LINE__,
    1957                 :            :                                 "Error sending packet for operation\n");
    1958                 :            :                 status = TEST_FAILED;
    1959                 :          0 :                 goto exit;
    1960                 :            :         }
    1961                 :            : 
    1962         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    1963                 :            :                 rte_pause();
    1964                 :            : 
    1965         [ #  # ]:          0 :         if (result_op == NULL) {
    1966                 :          0 :                 RTE_LOG(ERR, USER1,
    1967                 :            :                                 "line %u FAILED: %s", __LINE__,
    1968                 :            :                                 "Failed to process asym crypto op\n");
    1969                 :            :                 status = TEST_FAILED;
    1970                 :          0 :                 goto exit;
    1971                 :            :         }
    1972                 :            : 
    1973         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    1974                 :          0 :                 RTE_LOG(ERR, USER1,
    1975                 :            :                                 "line %u FAILED: %s", __LINE__,
    1976                 :            :                                 "Failed to process asym crypto op\n");
    1977                 :            :                 status = TEST_FAILED;
    1978                 :          0 :                 goto exit;
    1979                 :            :         }
    1980                 :            : 
    1981                 :            :         asym_op = result_op->asym;
    1982                 :            : 
    1983                 :          0 :         debug_hexdump(stdout, "priv_key:",
    1984                 :          0 :                 asym_op->ecdh.priv_key.data, asym_op->ecdh.priv_key.length);
    1985                 :            : 
    1986                 :          0 : exit:
    1987         [ #  # ]:          0 :         if (sess != NULL)
    1988                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    1989                 :          0 :         rte_crypto_op_free(op);
    1990                 :          0 :         return status;
    1991                 :            : }
    1992                 :            : 
    1993                 :            : static int
    1994                 :          0 : test_ecdh_pub_key_generate(enum curve curve_id)
    1995                 :            : {
    1996                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    1997                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    1998                 :          0 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    1999                 :          0 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    2000                 :            :         struct crypto_testsuite_ecdh_params input_params;
    2001                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    2002                 :          0 :         uint8_t dev_id = ts_params->valid_devs[0];
    2003                 :          0 :         struct rte_crypto_asym_xform xform = {0};
    2004                 :          0 :         struct rte_crypto_op *result_op = NULL;
    2005                 :            :         uint8_t output_buf_x[TEST_DATA_SIZE];
    2006                 :            :         uint8_t output_buf_y[TEST_DATA_SIZE];
    2007                 :            :         struct rte_crypto_asym_op *asym_op;
    2008                 :          0 :         struct rte_crypto_op *op = NULL;
    2009                 :            :         int ret, status = TEST_SUCCESS;
    2010                 :          0 :         void *sess = NULL;
    2011                 :            : 
    2012                 :            :         /* Check ECDH capability */
    2013                 :          0 :         idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2014                 :          0 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2015         [ #  # ]:          0 :         if (capa == NULL)
    2016                 :            :                 return TEST_SKIPPED;
    2017                 :            : 
    2018         [ #  # ]:          0 :         if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE)))
    2019                 :            :                 return TEST_SKIPPED;
    2020                 :            : 
    2021         [ #  # ]:          0 :         if (curve_id == ED25519 || curve_id == ED448) {
    2022                 :            :                 /* Check EdDSA capability */
    2023                 :          0 :                 idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    2024                 :          0 :                 capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2025         [ #  # ]:          0 :                 if (capa == NULL)
    2026                 :            :                         return TEST_SKIPPED;
    2027                 :            :         }
    2028                 :            : 
    2029   [ #  #  #  #  :          0 :         switch (curve_id) {
             #  #  #  # ]
    2030                 :          0 :         case SECP192R1:
    2031                 :          0 :                 input_params = ecdh_param_secp192r1;
    2032                 :          0 :                 break;
    2033                 :          0 :         case SECP224R1:
    2034                 :          0 :                 input_params = ecdh_param_secp224r1;
    2035                 :          0 :                 break;
    2036                 :          0 :         case SECP256R1:
    2037                 :          0 :                 input_params = ecdh_param_secp256r1;
    2038                 :          0 :                 break;
    2039                 :          0 :         case SECP384R1:
    2040                 :          0 :                 input_params = ecdh_param_secp384r1;
    2041                 :          0 :                 break;
    2042                 :          0 :         case SECP521R1:
    2043                 :          0 :                 input_params = ecdh_param_secp521r1;
    2044                 :          0 :                 break;
    2045                 :          0 :         case ED25519:
    2046                 :          0 :                 input_params = ecdh_param_ed25519;
    2047                 :          0 :                 break;
    2048                 :          0 :         case ED448:
    2049                 :          0 :                 input_params = ecdh_param_ed448;
    2050                 :          0 :                 break;
    2051                 :          0 :         default:
    2052                 :          0 :                 RTE_LOG(ERR, USER1,
    2053                 :            :                                 "line %u FAILED: %s", __LINE__,
    2054                 :            :                                 "Unsupported curve id\n");
    2055                 :            :                 status = TEST_FAILED;
    2056                 :          0 :                 goto exit;
    2057                 :            :         }
    2058                 :            : 
    2059                 :          0 :         debug_hexdump(stdout, "pkey:",
    2060                 :            :                 input_params.pkey_A.data, input_params.pkey_A.length);
    2061                 :            : 
    2062                 :            :         /* Setup crypto op data structure */
    2063                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2064         [ #  # ]:          0 :         if (op == NULL) {
    2065                 :          0 :                 RTE_LOG(ERR, USER1,
    2066                 :            :                                 "line %u FAILED: %s", __LINE__,
    2067                 :            :                                 "Failed to allocate asymmetric crypto "
    2068                 :            :                                 "operation struct\n");
    2069                 :            :                 status = TEST_FAILED;
    2070                 :          0 :                 goto exit;
    2071                 :            :         }
    2072                 :            :         asym_op = op->asym;
    2073                 :            : 
    2074                 :            :         /* Setup asym xform */
    2075                 :          0 :         xform.next = NULL;
    2076                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2077                 :          0 :         xform.ec.curve_id = input_params.curve;
    2078                 :          0 :         xform.ec.pkey.data = input_params.pkey_A.data;
    2079                 :          0 :         xform.ec.pkey.length = input_params.pkey_A.length;
    2080                 :            : 
    2081                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2082         [ #  # ]:          0 :         if (ret < 0) {
    2083                 :          0 :                 RTE_LOG(ERR, USER1,
    2084                 :            :                                 "line %u FAILED: %s", __LINE__,
    2085                 :            :                                 "Session creation failed\n");
    2086         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2087                 :          0 :                 goto exit;
    2088                 :            :         }
    2089                 :            : 
    2090                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2091         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    2092                 :            : 
    2093                 :            :         /* Populate op with operational details */
    2094                 :          0 :         asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE;
    2095         [ #  # ]:          0 :         if (curve_id == ED25519 || curve_id == ED448)
    2096                 :          0 :                 asym_op->flags |= RTE_CRYPTO_ASYM_FLAG_PUB_KEY_COMPRESSED;
    2097                 :            : 
    2098                 :            :         /* Init out buf */
    2099                 :          0 :         asym_op->ecdh.pub_key.x.data = output_buf_x;
    2100         [ #  # ]:          0 :         if (curve_id == ED25519 || curve_id == ED448)
    2101                 :          0 :                 asym_op->ecdh.pub_key.y.data = NULL;
    2102                 :            :         else
    2103                 :          0 :                 asym_op->ecdh.pub_key.y.data = output_buf_y;
    2104                 :            : 
    2105                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    2106                 :            : 
    2107                 :            :         /* Process crypto operation */
    2108         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2109                 :          0 :                 RTE_LOG(ERR, USER1,
    2110                 :            :                                 "line %u FAILED: %s", __LINE__,
    2111                 :            :                                 "Error sending packet for operation\n");
    2112                 :            :                 status = TEST_FAILED;
    2113                 :          0 :                 goto exit;
    2114                 :            :         }
    2115                 :            : 
    2116         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2117                 :            :                 rte_pause();
    2118                 :            : 
    2119         [ #  # ]:          0 :         if (result_op == NULL) {
    2120                 :          0 :                 RTE_LOG(ERR, USER1,
    2121                 :            :                                 "line %u FAILED: %s", __LINE__,
    2122                 :            :                                 "Failed to process asym crypto op\n");
    2123                 :            :                 status = TEST_FAILED;
    2124                 :          0 :                 goto exit;
    2125                 :            :         }
    2126                 :            : 
    2127         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2128                 :          0 :                 RTE_LOG(ERR, USER1,
    2129                 :            :                                 "line %u FAILED: %s", __LINE__,
    2130                 :            :                                 "Failed to process asym crypto op\n");
    2131                 :            :                 status = TEST_FAILED;
    2132                 :          0 :                 goto exit;
    2133                 :            :         }
    2134                 :            : 
    2135                 :            :         asym_op = result_op->asym;
    2136                 :            : 
    2137                 :          0 :         debug_hexdump(stdout, "qx:",
    2138                 :          0 :                 asym_op->ecdh.pub_key.x.data, asym_op->ecdh.pub_key.x.length);
    2139                 :          0 :         debug_hexdump(stdout, "qy:",
    2140                 :          0 :                 asym_op->ecdh.pub_key.y.data, asym_op->ecdh.pub_key.y.length);
    2141                 :            : 
    2142         [ #  # ]:          0 :         if (curve_id == ED25519 || curve_id == ED448)
    2143                 :          0 :                 ret = memcmp(input_params.pubkey_qA_x.data, result_op->asym->ecdh.pub_key.x.data,
    2144                 :          0 :                            result_op->asym->ecdh.pub_key.x.length);
    2145                 :            :         else
    2146                 :          0 :                 ret = verify_ecdh_secret(input_params.pubkey_qA_x.data,
    2147                 :            :                                 input_params.pubkey_qA_y.data, result_op);
    2148                 :            : 
    2149         [ #  # ]:          0 :         if (ret) {
    2150                 :            :                 status = TEST_FAILED;
    2151                 :          0 :                 RTE_LOG(ERR, USER1,
    2152                 :            :                                 "line %u FAILED: %s", __LINE__,
    2153                 :            :                                 "ECDH public key generation failed.\n");
    2154                 :          0 :                 goto exit;
    2155                 :            :         }
    2156                 :            : 
    2157                 :          0 : exit:
    2158         [ #  # ]:          0 :         if (sess != NULL)
    2159                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    2160                 :          0 :         rte_crypto_op_free(op);
    2161                 :          0 :         return status;
    2162                 :            : }
    2163                 :            : 
    2164                 :            : static int
    2165                 :          0 : test_ecdh_pub_key_verify(enum curve curve_id)
    2166                 :            : {
    2167                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    2168                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    2169                 :          0 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    2170                 :          0 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    2171                 :            :         struct crypto_testsuite_ecdh_params input_params;
    2172                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    2173                 :          0 :         uint8_t dev_id = ts_params->valid_devs[0];
    2174                 :          0 :         struct rte_crypto_asym_xform xform = {0};
    2175                 :          0 :         struct rte_crypto_op *result_op = NULL;
    2176                 :            :         struct rte_crypto_asym_op *asym_op;
    2177                 :          0 :         struct rte_crypto_op *op = NULL;
    2178                 :            :         int ret, status = TEST_SUCCESS;
    2179                 :          0 :         void *sess = NULL;
    2180                 :            : 
    2181                 :            :         /* Check ECDH capability */
    2182                 :          0 :         idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2183                 :          0 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2184         [ #  # ]:          0 :         if (capa == NULL)
    2185                 :            :                 return -ENOTSUP;
    2186                 :            : 
    2187         [ #  # ]:          0 :         if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY)))
    2188                 :            :                 return -ENOTSUP;
    2189                 :            : 
    2190   [ #  #  #  #  :          0 :         switch (curve_id) {
                   #  # ]
    2191                 :          0 :         case SECP192R1:
    2192                 :          0 :                 input_params = ecdh_param_secp192r1;
    2193                 :          0 :                 break;
    2194                 :          0 :         case SECP224R1:
    2195                 :          0 :                 input_params = ecdh_param_secp224r1;
    2196                 :          0 :                 break;
    2197                 :          0 :         case SECP256R1:
    2198                 :          0 :                 input_params = ecdh_param_secp256r1;
    2199                 :          0 :                 break;
    2200                 :          0 :         case SECP384R1:
    2201                 :          0 :                 input_params = ecdh_param_secp384r1;
    2202                 :          0 :                 break;
    2203                 :          0 :         case SECP521R1:
    2204                 :          0 :                 input_params = ecdh_param_secp521r1;
    2205                 :          0 :                 break;
    2206                 :          0 :         default:
    2207                 :          0 :                 RTE_LOG(ERR, USER1,
    2208                 :            :                                 "line %u FAILED: %s", __LINE__,
    2209                 :            :                                 "Unsupported curve id\n");
    2210                 :            :                 status = TEST_FAILED;
    2211                 :          0 :                 goto exit;
    2212                 :            :         }
    2213                 :            : 
    2214                 :          0 :         debug_hexdump(stdout, "qx:",
    2215                 :            :                 input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
    2216                 :          0 :         debug_hexdump(stdout, "qy:",
    2217                 :            :                 input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
    2218                 :            : 
    2219                 :            :         /* Setup crypto op data structure */
    2220                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2221         [ #  # ]:          0 :         if (op == NULL) {
    2222                 :          0 :                 RTE_LOG(ERR, USER1,
    2223                 :            :                                 "line %u FAILED: %s", __LINE__,
    2224                 :            :                                 "Failed to allocate asymmetric crypto "
    2225                 :            :                                 "operation struct\n");
    2226                 :            :                 status = TEST_FAILED;
    2227                 :          0 :                 goto exit;
    2228                 :            :         }
    2229                 :            :         asym_op = op->asym;
    2230                 :            : 
    2231                 :            :         /* Setup asym xform */
    2232                 :          0 :         xform.next = NULL;
    2233                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2234                 :          0 :         xform.ec.curve_id = input_params.curve;
    2235                 :            : 
    2236                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2237         [ #  # ]:          0 :         if (ret < 0) {
    2238                 :          0 :                 RTE_LOG(ERR, USER1,
    2239                 :            :                                 "line %u FAILED: %s", __LINE__,
    2240                 :            :                                 "Session creation failed\n");
    2241         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2242                 :          0 :                 goto exit;
    2243                 :            :         }
    2244                 :            : 
    2245                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2246         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    2247                 :            : 
    2248                 :            :         /* Populate op with operational details */
    2249                 :          0 :         asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_PUB_KEY_VERIFY;
    2250                 :          0 :         asym_op->ecdh.pub_key.x.data = input_params.pubkey_qA_x.data;
    2251                 :          0 :         asym_op->ecdh.pub_key.x.length = input_params.pubkey_qA_x.length;
    2252                 :          0 :         asym_op->ecdh.pub_key.y.data = input_params.pubkey_qA_y.data;
    2253                 :          0 :         asym_op->ecdh.pub_key.y.length = input_params.pubkey_qA_y.length;
    2254                 :            : 
    2255                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    2256                 :            : 
    2257                 :            :         /* Process crypto operation */
    2258         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2259                 :          0 :                 RTE_LOG(ERR, USER1,
    2260                 :            :                                 "line %u FAILED: %s", __LINE__,
    2261                 :            :                                 "Error sending packet for operation\n");
    2262                 :            :                 status = TEST_FAILED;
    2263                 :          0 :                 goto exit;
    2264                 :            :         }
    2265                 :            : 
    2266         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2267                 :            :                 rte_pause();
    2268                 :            : 
    2269         [ #  # ]:          0 :         if (result_op == NULL) {
    2270                 :          0 :                 RTE_LOG(ERR, USER1,
    2271                 :            :                                 "line %u FAILED: %s", __LINE__,
    2272                 :            :                                 "Failed to process asym crypto op\n");
    2273                 :            :                 status = TEST_FAILED;
    2274                 :          0 :                 goto exit;
    2275                 :            :         }
    2276                 :            : 
    2277         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2278                 :          0 :                 RTE_LOG(ERR, USER1,
    2279                 :            :                                 "line %u FAILED: %s", __LINE__,
    2280                 :            :                                 "Failed to process asym crypto op\n");
    2281                 :            :                 status = TEST_FAILED;
    2282                 :          0 :                 goto exit;
    2283                 :            :         }
    2284                 :            : 
    2285                 :          0 : exit:
    2286         [ #  # ]:          0 :         if (sess != NULL)
    2287                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    2288                 :          0 :         rte_crypto_op_free(op);
    2289                 :          0 :         return status;
    2290                 :            : }
    2291                 :            : 
    2292                 :            : static int
    2293                 :          0 : test_ecdh_shared_secret(enum curve curve_id)
    2294                 :            : {
    2295                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    2296                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    2297                 :          0 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    2298                 :          0 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    2299                 :            :         struct crypto_testsuite_ecdh_params input_params;
    2300                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    2301                 :          0 :         uint8_t dev_id = ts_params->valid_devs[0];
    2302                 :          0 :         struct rte_crypto_asym_xform xform = {0};
    2303                 :          0 :         struct rte_crypto_op *result_op = NULL;
    2304                 :            :         uint8_t output_buf_x[TEST_DATA_SIZE];
    2305                 :            :         uint8_t output_buf_y[TEST_DATA_SIZE];
    2306                 :            :         struct rte_crypto_asym_op *asym_op;
    2307                 :          0 :         struct rte_crypto_op *op = NULL;
    2308                 :            :         int ret, status = TEST_SUCCESS;
    2309                 :          0 :         void *sess = NULL;
    2310                 :            : 
    2311                 :            :         /* Check ECDH capability */
    2312                 :          0 :         idx.type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2313                 :          0 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2314         [ #  # ]:          0 :         if (capa == NULL)
    2315                 :            :                 return -ENOTSUP;
    2316                 :            : 
    2317         [ #  # ]:          0 :         if (!(capa->op_types & (1 <<  RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE)))
    2318                 :            :                 return -ENOTSUP;
    2319                 :            : 
    2320   [ #  #  #  #  :          0 :         switch (curve_id) {
                   #  # ]
    2321                 :          0 :         case SECP192R1:
    2322                 :          0 :                 input_params = ecdh_param_secp192r1;
    2323                 :          0 :                 break;
    2324                 :          0 :         case SECP224R1:
    2325                 :          0 :                 input_params = ecdh_param_secp224r1;
    2326                 :          0 :                 break;
    2327                 :          0 :         case SECP256R1:
    2328                 :          0 :                 input_params = ecdh_param_secp256r1;
    2329                 :          0 :                 break;
    2330                 :          0 :         case SECP384R1:
    2331                 :          0 :                 input_params = ecdh_param_secp384r1;
    2332                 :          0 :                 break;
    2333                 :          0 :         case SECP521R1:
    2334                 :          0 :                 input_params = ecdh_param_secp521r1;
    2335                 :          0 :                 break;
    2336                 :          0 :         default:
    2337                 :          0 :                 RTE_LOG(ERR, USER1,
    2338                 :            :                                 "line %u FAILED: %s", __LINE__,
    2339                 :            :                                 "Unsupported curve id\n");
    2340                 :            :                 status = TEST_FAILED;
    2341                 :          0 :                 goto exit;
    2342                 :            :         }
    2343                 :            : 
    2344                 :            :         /* zA = dA.QB */
    2345                 :          0 :         debug_hexdump(stdout, "pkey:",
    2346                 :            :                 input_params.pkey_A.data, input_params.pkey_A.length);
    2347                 :          0 :         debug_hexdump(stdout, "qx:",
    2348                 :            :                 input_params.pubkey_qB_x.data, input_params.pubkey_qB_x.length);
    2349                 :          0 :         debug_hexdump(stdout, "qy:",
    2350                 :            :                 input_params.pubkey_qB_y.data, input_params.pubkey_qB_y.length);
    2351                 :            : 
    2352                 :            :         /* Setup crypto op data structure */
    2353                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2354         [ #  # ]:          0 :         if (op == NULL) {
    2355                 :          0 :                 RTE_LOG(ERR, USER1,
    2356                 :            :                                 "line %u FAILED: %s", __LINE__,
    2357                 :            :                                 "Failed to allocate asymmetric crypto "
    2358                 :            :                                 "operation struct\n");
    2359                 :            :                 status = TEST_FAILED;
    2360                 :          0 :                 goto exit;
    2361                 :            :         }
    2362                 :            :         asym_op = op->asym;
    2363                 :            : 
    2364                 :            :         /* Setup asym xform */
    2365                 :          0 :         xform.next = NULL;
    2366                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2367                 :          0 :         xform.ec.curve_id = input_params.curve;
    2368                 :          0 :         xform.ec.pkey.data = input_params.pkey_A.data;
    2369                 :          0 :         xform.ec.pkey.length = input_params.pkey_A.length;
    2370                 :          0 :         xform.ec.q.x.data = input_params.pubkey_qB_x.data;
    2371                 :          0 :         xform.ec.q.x.length = input_params.pubkey_qB_x.length;
    2372                 :          0 :         xform.ec.q.y.data = input_params.pubkey_qB_y.data;
    2373                 :          0 :         xform.ec.q.y.length = input_params.pubkey_qB_y.length;
    2374                 :            : 
    2375                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2376         [ #  # ]:          0 :         if (ret < 0) {
    2377                 :          0 :                 RTE_LOG(ERR, USER1,
    2378                 :            :                                 "line %u FAILED: %s", __LINE__,
    2379                 :            :                                 "Session creation failed\n");
    2380         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2381                 :          0 :                 goto exit;
    2382                 :            :         }
    2383                 :            : 
    2384                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2385         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    2386                 :            : 
    2387                 :            :         /* Populate op with operational details */
    2388                 :          0 :         asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
    2389                 :            : 
    2390                 :            :         /* Init out buf */
    2391                 :          0 :         asym_op->ecdh.shared_secret.x.data = output_buf_x;
    2392                 :          0 :         asym_op->ecdh.shared_secret.y.data = output_buf_y;
    2393                 :            : 
    2394                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    2395                 :            : 
    2396                 :            :         /* Process crypto operation */
    2397         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2398                 :          0 :                 RTE_LOG(ERR, USER1,
    2399                 :            :                                 "line %u FAILED: %s", __LINE__,
    2400                 :            :                                 "Error sending packet for operation\n");
    2401                 :            :                 status = TEST_FAILED;
    2402                 :          0 :                 goto exit;
    2403                 :            :         }
    2404                 :            : 
    2405         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2406                 :            :                 rte_pause();
    2407                 :            : 
    2408         [ #  # ]:          0 :         if (result_op == NULL) {
    2409                 :          0 :                 RTE_LOG(ERR, USER1,
    2410                 :            :                                 "line %u FAILED: %s", __LINE__,
    2411                 :            :                                 "Failed to process asym crypto op\n");
    2412                 :            :                 status = TEST_FAILED;
    2413                 :          0 :                 goto exit;
    2414                 :            :         }
    2415                 :            : 
    2416         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2417                 :          0 :                 RTE_LOG(ERR, USER1,
    2418                 :            :                                 "line %u FAILED: %s", __LINE__,
    2419                 :            :                                 "Failed to process asym crypto op\n");
    2420                 :            :                 status = TEST_FAILED;
    2421                 :          0 :                 goto exit;
    2422                 :            :         }
    2423                 :            : 
    2424                 :            :         asym_op = result_op->asym;
    2425                 :            : 
    2426                 :          0 :         debug_hexdump(stdout, "secret_x:",
    2427                 :          0 :                 asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
    2428                 :          0 :         debug_hexdump(stdout, "secret_y:",
    2429                 :          0 :                 asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
    2430                 :            : 
    2431                 :          0 :         ret = verify_ecdh_secret(input_params.secret_x.data,
    2432                 :            :                                 input_params.secret_y.data, result_op);
    2433         [ #  # ]:          0 :         if (ret) {
    2434                 :            :                 status = TEST_FAILED;
    2435                 :          0 :                 RTE_LOG(ERR, USER1,
    2436                 :            :                                 "line %u FAILED: %s", __LINE__,
    2437                 :            :                                 "ECDH shared secret compute failed.\n");
    2438                 :          0 :                 goto exit;
    2439                 :            :         }
    2440                 :            : 
    2441         [ #  # ]:          0 :         if (sess != NULL)
    2442                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    2443                 :          0 :         rte_crypto_op_free(op);
    2444                 :            : 
    2445                 :            :         /* zB = dB.QA */
    2446                 :          0 :         debug_hexdump(stdout, "pkey:",
    2447                 :            :                 input_params.pkey_B.data, input_params.pkey_B.length);
    2448                 :          0 :         debug_hexdump(stdout, "qx:",
    2449                 :            :                 input_params.pubkey_qA_x.data, input_params.pubkey_qA_x.length);
    2450                 :          0 :         debug_hexdump(stdout, "qy:",
    2451                 :            :                 input_params.pubkey_qA_y.data, input_params.pubkey_qA_y.length);
    2452                 :            : 
    2453                 :            :         /* Setup crypto op data structure */
    2454                 :          0 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2455         [ #  # ]:          0 :         if (op == NULL) {
    2456                 :          0 :                 RTE_LOG(ERR, USER1,
    2457                 :            :                                 "line %u FAILED: %s", __LINE__,
    2458                 :            :                                 "Failed to allocate asymmetric crypto "
    2459                 :            :                                 "operation struct\n");
    2460                 :            :                 status = TEST_FAILED;
    2461                 :          0 :                 goto exit;
    2462                 :            :         }
    2463                 :            :         asym_op = op->asym;
    2464                 :            : 
    2465                 :            :         /* Setup asym xform */
    2466                 :          0 :         xform.next = NULL;
    2467                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDH;
    2468                 :          0 :         xform.ec.curve_id = input_params.curve;
    2469                 :          0 :         xform.ec.pkey.data = input_params.pkey_B.data;
    2470                 :          0 :         xform.ec.pkey.length = input_params.pkey_B.length;
    2471                 :          0 :         xform.ec.q.x.data = input_params.pubkey_qA_x.data;
    2472                 :          0 :         xform.ec.q.x.length = input_params.pubkey_qA_x.length;
    2473                 :          0 :         xform.ec.q.y.data = input_params.pubkey_qA_y.data;
    2474                 :          0 :         xform.ec.q.y.length = input_params.pubkey_qA_y.length;
    2475                 :            : 
    2476                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2477         [ #  # ]:          0 :         if (ret < 0) {
    2478                 :          0 :                 RTE_LOG(ERR, USER1,
    2479                 :            :                                 "line %u FAILED: %s", __LINE__,
    2480                 :            :                                 "Session creation failed\n");
    2481         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2482                 :          0 :                 goto exit;
    2483                 :            :         }
    2484                 :            : 
    2485                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2486         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    2487                 :            : 
    2488                 :            :         /* Populate op with operational details */
    2489                 :          0 :         asym_op->ecdh.ke_type = RTE_CRYPTO_ASYM_KE_SHARED_SECRET_COMPUTE;
    2490                 :            : 
    2491                 :            :         /* Init out buf */
    2492                 :          0 :         asym_op->ecdh.shared_secret.x.data = output_buf_x;
    2493                 :          0 :         asym_op->ecdh.shared_secret.y.data = output_buf_y;
    2494                 :            : 
    2495                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    2496                 :            : 
    2497                 :            :         /* Process crypto operation */
    2498         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2499                 :          0 :                 RTE_LOG(ERR, USER1,
    2500                 :            :                                 "line %u FAILED: %s", __LINE__,
    2501                 :            :                                 "Error sending packet for operation\n");
    2502                 :            :                 status = TEST_FAILED;
    2503                 :          0 :                 goto exit;
    2504                 :            :         }
    2505                 :            : 
    2506         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2507                 :            :                 rte_pause();
    2508                 :            : 
    2509         [ #  # ]:          0 :         if (result_op == NULL) {
    2510                 :          0 :                 RTE_LOG(ERR, USER1,
    2511                 :            :                                 "line %u FAILED: %s", __LINE__,
    2512                 :            :                                 "Failed to process asym crypto op\n");
    2513                 :            :                 status = TEST_FAILED;
    2514                 :          0 :                 goto exit;
    2515                 :            :         }
    2516                 :            : 
    2517         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2518                 :          0 :                 RTE_LOG(ERR, USER1,
    2519                 :            :                                 "line %u FAILED: %s", __LINE__,
    2520                 :            :                                 "Failed to process asym crypto op\n");
    2521                 :            :                 status = TEST_FAILED;
    2522                 :          0 :                 goto exit;
    2523                 :            :         }
    2524                 :            : 
    2525                 :            :         asym_op = result_op->asym;
    2526                 :            : 
    2527                 :          0 :         debug_hexdump(stdout, "secret_x:",
    2528                 :          0 :                         asym_op->ecdh.shared_secret.x.data, asym_op->ecdh.shared_secret.x.length);
    2529                 :          0 :         debug_hexdump(stdout, "secret_y:",
    2530                 :          0 :                         asym_op->ecdh.shared_secret.y.data, asym_op->ecdh.shared_secret.y.length);
    2531                 :            : 
    2532                 :          0 :         ret = verify_ecdh_secret(input_params.secret_x.data,
    2533                 :            :                                 input_params.secret_y.data, result_op);
    2534         [ #  # ]:          0 :         if (ret) {
    2535                 :            :                 status = TEST_FAILED;
    2536                 :          0 :                 RTE_LOG(ERR, USER1,
    2537                 :            :                                 "line %u FAILED: %s", __LINE__,
    2538                 :            :                                 "ECDH shared secret compute failed.\n");
    2539                 :          0 :                 goto exit;
    2540                 :            :         }
    2541                 :            : 
    2542                 :          0 : exit:
    2543         [ #  # ]:          0 :         if (sess != NULL)
    2544                 :          0 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    2545                 :          0 :         rte_crypto_op_free(op);
    2546                 :          0 :         return status;
    2547                 :            : }
    2548                 :            : 
    2549                 :            : static int
    2550                 :          0 : test_ecdh_all_curve(void)
    2551                 :            : {
    2552                 :            :         int status, overall_status = TEST_SUCCESS;
    2553                 :            :         enum curve curve_id;
    2554                 :            :         int test_index = 0;
    2555                 :            :         const char *msg;
    2556                 :            : 
    2557         [ #  # ]:          0 :         for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
    2558         [ #  # ]:          0 :                 if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
    2559                 :          0 :                         continue;
    2560                 :            : 
    2561                 :          0 :                 status = test_ecdh_priv_key_generate(curve_id);
    2562         [ #  # ]:          0 :                 if (status == TEST_SUCCESS) {
    2563                 :            :                         msg = "succeeded";
    2564                 :            :                 } else {
    2565                 :            :                         msg = "failed";
    2566                 :            :                         overall_status = status;
    2567                 :            :                 }
    2568                 :          0 :                 printf("  %u) TestCase ECDH private key generation for Curve %s %s\n",
    2569                 :            :                        test_index ++, curve[curve_id], msg);
    2570                 :            :         }
    2571                 :            : 
    2572         [ #  # ]:          0 :         for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
    2573         [ #  # ]:          0 :                 if (curve_id == SECP521R1_UA)
    2574                 :          0 :                         continue;
    2575                 :            : 
    2576                 :          0 :                 status = test_ecdh_pub_key_generate(curve_id);
    2577         [ #  # ]:          0 :                 if (status == TEST_SUCCESS) {
    2578                 :            :                         msg = "succeeded";
    2579         [ #  # ]:          0 :                 } else if (status == TEST_SKIPPED) {
    2580                 :            :                         msg = "skipped";
    2581                 :            :                 } else {
    2582                 :            :                         msg = "failed";
    2583                 :            :                         overall_status = status;
    2584                 :            :                 }
    2585                 :          0 :                 printf("  %u) TestCase ECDH public key generation for Curve %s %s\n",
    2586                 :            :                        test_index ++, curve[curve_id], msg);
    2587                 :            :         }
    2588                 :            : 
    2589         [ #  # ]:          0 :         for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
    2590         [ #  # ]:          0 :                 if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
    2591                 :          0 :                         continue;
    2592                 :            : 
    2593                 :          0 :                 status = test_ecdh_pub_key_verify(curve_id);
    2594         [ #  # ]:          0 :                 if (status == TEST_SUCCESS) {
    2595                 :            :                         msg = "succeeded";
    2596                 :            :                 } else {
    2597                 :            :                         msg = "failed";
    2598                 :            :                         overall_status = status;
    2599                 :            :                 }
    2600                 :          0 :                 printf("  %u) TestCase ECDH public key verification for Curve %s %s\n",
    2601                 :            :                        test_index ++, curve[curve_id], msg);
    2602                 :            :         }
    2603                 :            : 
    2604         [ #  # ]:          0 :         for (curve_id = SECP192R1; curve_id < END_OF_CURVE_LIST; curve_id++) {
    2605         [ #  # ]:          0 :                 if (curve_id == SECP521R1_UA || curve_id == ED25519 || curve_id == ED448)
    2606                 :          0 :                         continue;
    2607                 :            : 
    2608                 :          0 :                 status = test_ecdh_shared_secret(curve_id);
    2609         [ #  # ]:          0 :                 if (status == TEST_SUCCESS) {
    2610                 :            :                         msg = "succeeded";
    2611                 :            :                 } else {
    2612                 :            :                         msg = "failed";
    2613                 :            :                         overall_status = status;
    2614                 :            :                 }
    2615                 :          0 :                 printf("  %u) TestCase ECDH shared secret compute for Curve %s %s\n",
    2616                 :            :                        test_index ++, curve[curve_id], msg);
    2617                 :            :         }
    2618                 :            : 
    2619                 :          0 :         return overall_status;
    2620                 :            : }
    2621                 :            : 
    2622                 :            : static int
    2623                 :          1 : test_sm2_sign(void)
    2624                 :            : {
    2625                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    2626                 :          1 :         struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
    2627                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    2628                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    2629                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    2630                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    2631                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    2632                 :          1 :         struct rte_crypto_op *result_op = NULL;
    2633                 :            :         uint8_t output_buf_r[TEST_DATA_SIZE];
    2634                 :            :         uint8_t output_buf_s[TEST_DATA_SIZE];
    2635                 :            :         struct rte_crypto_asym_xform xform;
    2636                 :            :         struct rte_crypto_asym_op *asym_op;
    2637                 :          1 :         struct rte_crypto_op *op = NULL;
    2638                 :            :         int ret, status = TEST_SUCCESS;
    2639                 :          1 :         void *sess = NULL;
    2640                 :            : 
    2641                 :            :         /* Check SM2 capability */
    2642                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
    2643                 :          1 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2644         [ +  - ]:          1 :         if (capa == NULL)
    2645                 :            :                 return -ENOTSUP;
    2646                 :            : 
    2647                 :            :         /* Setup crypto op data structure */
    2648                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2649         [ -  + ]:          1 :         if (op == NULL) {
    2650                 :          0 :                 RTE_LOG(ERR, USER1,
    2651                 :            :                                 "line %u FAILED: %s", __LINE__,
    2652                 :            :                                 "Failed to allocate asymmetric crypto "
    2653                 :            :                                 "operation struct\n");
    2654                 :            :                 status = TEST_FAILED;
    2655                 :          0 :                 goto exit;
    2656                 :            :         }
    2657                 :            : 
    2658                 :            :         asym_op = op->asym;
    2659                 :            : 
    2660                 :            :         /* Setup asym xform */
    2661                 :          1 :         xform.next = NULL;
    2662                 :          1 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
    2663                 :          1 :         xform.ec.curve_id = input_params.curve;
    2664                 :          1 :         xform.ec.pkey.data = input_params.pkey.data;
    2665                 :          1 :         xform.ec.pkey.length = input_params.pkey.length;
    2666                 :          1 :         xform.ec.q.x.data = input_params.pubkey_qx.data;
    2667                 :          1 :         xform.ec.q.x.length = input_params.pubkey_qx.length;
    2668                 :          1 :         xform.ec.q.y.data = input_params.pubkey_qy.data;
    2669                 :          1 :         xform.ec.q.y.length = input_params.pubkey_qy.length;
    2670                 :            : 
    2671                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2672         [ -  + ]:          1 :         if (ret < 0) {
    2673                 :          0 :                 RTE_LOG(ERR, USER1,
    2674                 :            :                                 "line %u FAILED: %s", __LINE__,
    2675                 :            :                                 "Session creation failed\n");
    2676         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2677                 :          0 :                 goto exit;
    2678                 :            :         }
    2679                 :            : 
    2680                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2681         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    2682                 :            : 
    2683                 :            :         /* Compute sign */
    2684                 :            : 
    2685                 :            :         /* Populate op with operational details */
    2686                 :          1 :         asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
    2687         [ +  - ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
    2688                 :            :                         RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_PH))
    2689                 :          1 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
    2690                 :            :         else
    2691                 :          0 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
    2692                 :            : 
    2693         [ +  - ]:          1 :         if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
    2694                 :          1 :                 asym_op->sm2.message.data = input_params.message.data;
    2695                 :          1 :                 asym_op->sm2.message.length = input_params.message.length;
    2696                 :          1 :                 asym_op->sm2.id.data = input_params.id.data;
    2697                 :          1 :                 asym_op->sm2.id.length = input_params.id.length;
    2698                 :            :         } else {
    2699                 :          0 :                 asym_op->sm2.message.data = input_params.digest.data;
    2700                 :          0 :                 asym_op->sm2.message.length = input_params.digest.length;
    2701                 :          0 :                 asym_op->sm2.id.data = NULL;
    2702                 :          0 :                 asym_op->sm2.id.length = 0;
    2703                 :            :         }
    2704                 :            : 
    2705         [ +  - ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
    2706                 :            :                         RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
    2707                 :          1 :                 asym_op->sm2.k.data = NULL;
    2708                 :          1 :                 asym_op->sm2.k.length = 0;
    2709                 :            :         } else {
    2710                 :          0 :                 asym_op->sm2.k.data = input_params.k.data;
    2711                 :          0 :                 asym_op->sm2.k.length = input_params.k.length;
    2712                 :            :         }
    2713                 :            : 
    2714                 :            :         /* Init out buf */
    2715                 :          1 :         asym_op->sm2.r.data = output_buf_r;
    2716                 :          1 :         asym_op->sm2.s.data = output_buf_s;
    2717                 :            : 
    2718                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    2719                 :            : 
    2720                 :            :         /* Process crypto operation */
    2721         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2722                 :          0 :                 RTE_LOG(ERR, USER1,
    2723                 :            :                                 "line %u FAILED: %s", __LINE__,
    2724                 :            :                                 "Error sending packet for operation\n");
    2725                 :            :                 status = TEST_FAILED;
    2726                 :          0 :                 goto exit;
    2727                 :            :         }
    2728                 :            : 
    2729         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2730                 :            :                 rte_pause();
    2731                 :            : 
    2732         [ -  + ]:          1 :         if (result_op == NULL) {
    2733                 :          0 :                 RTE_LOG(ERR, USER1,
    2734                 :            :                                 "line %u FAILED: %s", __LINE__,
    2735                 :            :                                 "Failed to process asym crypto op\n");
    2736                 :            :                 status = TEST_FAILED;
    2737                 :          0 :                 goto exit;
    2738                 :            :         }
    2739                 :            : 
    2740         [ -  + ]:          1 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2741                 :          0 :                 RTE_LOG(ERR, USER1,
    2742                 :            :                                 "line %u FAILED: %s", __LINE__,
    2743                 :            :                                 "Failed to process asym crypto op\n");
    2744                 :            :                 status = TEST_FAILED;
    2745                 :          0 :                 goto exit;
    2746                 :            :         }
    2747                 :            : 
    2748                 :            :         asym_op = result_op->asym;
    2749                 :            : 
    2750                 :          1 :         debug_hexdump(stdout, "r:",
    2751                 :          1 :                         asym_op->sm2.r.data, asym_op->sm2.r.length);
    2752                 :          1 :         debug_hexdump(stdout, "s:",
    2753                 :          1 :                         asym_op->sm2.s.data, asym_op->sm2.s.length);
    2754                 :            : 
    2755         [ -  + ]:          1 :         if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
    2756                 :            :                         RTE_CRYPTO_ASYM_OP_SIGN, RTE_CRYPTO_SM2_RNG)) {
    2757                 :            :                 /* Verify sign (by comparison). */
    2758         [ #  # ]:          0 :                 if (memcmp(input_params.sign_r.data, asym_op->sm2.r.data,
    2759                 :            :                                    asym_op->sm2.r.length) != 0) {
    2760                 :            :                         status = TEST_FAILED;
    2761                 :          0 :                         RTE_LOG(ERR, USER1,
    2762                 :            :                                         "line %u FAILED: %s", __LINE__,
    2763                 :            :                                         "SM2 sign failed.\n");
    2764                 :          0 :                         goto exit;
    2765                 :            :                 }
    2766         [ #  # ]:          0 :                 if (memcmp(input_params.sign_s.data, asym_op->sm2.s.data,
    2767                 :            :                                    asym_op->sm2.s.length) != 0) {
    2768                 :            :                         status = TEST_FAILED;
    2769                 :          0 :                         RTE_LOG(ERR, USER1,
    2770                 :            :                                         "line %u FAILED: %s", __LINE__,
    2771                 :            :                                         "SM2 sign failed.\n");
    2772                 :          0 :                         goto exit;
    2773                 :            :                 }
    2774                 :            :         } else {
    2775                 :            :                 /* Verify sign (in roundtrip).
    2776                 :            :                  * Due to random number used per message, sign op
    2777                 :            :                  * would produce different output for same message
    2778                 :            :                  * every time. Hence, we can't have expected output
    2779                 :            :                  * to match, instead reverse op to verify.
    2780                 :            :                  */
    2781                 :            : 
    2782                 :            :                 /* Populate op with operational details */
    2783                 :          1 :                 asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    2784                 :            : 
    2785                 :            :                 /* Enqueue sign result for verify */
    2786         [ -  + ]:          1 :                 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2787                 :            :                         status = TEST_FAILED;
    2788                 :          0 :                         RTE_LOG(ERR, USER1,
    2789                 :            :                                         "line %u FAILED: %s", __LINE__,
    2790                 :            :                                         "Error sending packet for operation\n");
    2791                 :          0 :                         goto exit;
    2792                 :            :                 }
    2793                 :            : 
    2794         [ -  + ]:          1 :                 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2795                 :            :                         rte_pause();
    2796                 :            : 
    2797         [ -  + ]:          1 :                 if (result_op == NULL) {
    2798                 :            :                         status = TEST_FAILED;
    2799                 :          0 :                         goto exit;
    2800                 :            :                 }
    2801         [ +  - ]:          1 :                 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2802                 :            :                         status = TEST_FAILED;
    2803                 :          0 :                         RTE_LOG(ERR, USER1,
    2804                 :            :                                         "line %u FAILED: %s", __LINE__,
    2805                 :            :                                         "SM2 verify failed.\n");
    2806                 :          0 :                         goto exit;
    2807                 :            :                 }
    2808                 :            :         }
    2809                 :            : 
    2810                 :          1 : exit:
    2811         [ +  - ]:          1 :         if (sess != NULL)
    2812                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    2813                 :          1 :         rte_crypto_op_free(op);
    2814                 :          1 :         return status;
    2815                 :            : };
    2816                 :            : 
    2817                 :            : static int
    2818                 :          1 : test_sm2_verify(void)
    2819                 :            : {
    2820                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    2821                 :          1 :         struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
    2822                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    2823                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    2824                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    2825                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    2826                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    2827                 :          1 :         struct rte_crypto_op *result_op = NULL;
    2828                 :            :         struct rte_crypto_asym_xform xform;
    2829                 :            :         struct rte_crypto_asym_op *asym_op;
    2830                 :          1 :         struct rte_crypto_op *op = NULL;
    2831                 :            :         int ret, status = TEST_SUCCESS;
    2832                 :          1 :         void *sess = NULL;
    2833                 :            : 
    2834                 :            :         /* Check SM2 capability */
    2835                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
    2836                 :          1 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2837         [ +  - ]:          1 :         if (capa == NULL)
    2838                 :            :                 return -ENOTSUP;
    2839                 :            : 
    2840                 :            :         /* Setup crypto op data structure */
    2841                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2842         [ -  + ]:          1 :         if (op == NULL) {
    2843                 :          0 :                 RTE_LOG(ERR, USER1,
    2844                 :            :                                 "line %u FAILED: %s", __LINE__,
    2845                 :            :                                 "Failed to allocate asymmetric crypto "
    2846                 :            :                                 "operation struct\n");
    2847                 :            :                 status = TEST_FAILED;
    2848                 :          0 :                 goto exit;
    2849                 :            :         }
    2850                 :            : 
    2851                 :            :         asym_op = op->asym;
    2852                 :            : 
    2853                 :            :         /* Setup asym xform */
    2854                 :          1 :         xform.next = NULL;
    2855                 :          1 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
    2856                 :          1 :         xform.ec.curve_id = input_params.curve;
    2857                 :          1 :         xform.ec.pkey.data = input_params.pkey.data;
    2858                 :          1 :         xform.ec.pkey.length = input_params.pkey.length;
    2859                 :          1 :         xform.ec.q.x.data = input_params.pubkey_qx.data;
    2860                 :          1 :         xform.ec.q.x.length = input_params.pubkey_qx.length;
    2861                 :          1 :         xform.ec.q.y.data = input_params.pubkey_qy.data;
    2862                 :          1 :         xform.ec.q.y.length = input_params.pubkey_qy.length;
    2863                 :            : 
    2864                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2865         [ -  + ]:          1 :         if (ret < 0) {
    2866                 :          0 :                 RTE_LOG(ERR, USER1,
    2867                 :            :                                 "line %u FAILED: %s", __LINE__,
    2868                 :            :                                 "Session creation failed\n");
    2869         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2870                 :          0 :                 goto exit;
    2871                 :            :         }
    2872                 :            : 
    2873                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2874         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    2875                 :            : 
    2876                 :            :         /* Verify given sign */
    2877                 :            : 
    2878                 :            :         /* Populate op with operational details */
    2879                 :          1 :         asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    2880                 :            : 
    2881         [ +  - ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
    2882                 :            :                         RTE_CRYPTO_ASYM_OP_VERIFY, RTE_CRYPTO_SM2_PH))
    2883                 :          1 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
    2884                 :            :         else
    2885                 :          0 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
    2886                 :            : 
    2887         [ +  - ]:          1 :         if (asym_op->sm2.hash == RTE_CRYPTO_AUTH_SM3) {
    2888                 :          1 :                 asym_op->sm2.message.data = input_params.message.data;
    2889                 :          1 :                 asym_op->sm2.message.length = input_params.message.length;
    2890                 :          1 :                 asym_op->sm2.id.data = input_params.id.data;
    2891                 :          1 :                 asym_op->sm2.id.length = input_params.id.length;
    2892                 :            :         } else {
    2893                 :          0 :                 asym_op->sm2.message.data = input_params.digest.data;
    2894                 :          0 :                 asym_op->sm2.message.length = input_params.digest.length;
    2895                 :          0 :                 asym_op->sm2.id.data = NULL;
    2896                 :          0 :                 asym_op->sm2.id.length = 0;
    2897                 :            :         }
    2898                 :            : 
    2899                 :          1 :         asym_op->sm2.r.data = input_params.sign_r.data;
    2900                 :          1 :         asym_op->sm2.r.length = input_params.sign_r.length;
    2901                 :          1 :         asym_op->sm2.s.data = input_params.sign_s.data;
    2902                 :          1 :         asym_op->sm2.s.length = input_params.sign_s.length;
    2903                 :            : 
    2904                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    2905                 :            : 
    2906                 :            :         /* Process crypto operation */
    2907         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    2908                 :          0 :                 RTE_LOG(ERR, USER1,
    2909                 :            :                                 "line %u FAILED: %s", __LINE__,
    2910                 :            :                                 "Error sending packet for operation\n");
    2911                 :            :                 status = TEST_FAILED;
    2912                 :          0 :                 goto exit;
    2913                 :            :         }
    2914                 :            : 
    2915         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    2916                 :            :                 rte_pause();
    2917                 :            : 
    2918         [ -  + ]:          1 :         if (result_op == NULL) {
    2919                 :          0 :                 RTE_LOG(ERR, USER1,
    2920                 :            :                                 "line %u FAILED: %s", __LINE__,
    2921                 :            :                                 "Failed to process asym crypto op\n");
    2922                 :            :                 status = TEST_FAILED;
    2923                 :          0 :                 goto exit;
    2924                 :            :         }
    2925                 :            : 
    2926         [ +  - ]:          1 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    2927                 :          0 :                 RTE_LOG(ERR, USER1,
    2928                 :            :                                 "line %u FAILED: %s", __LINE__,
    2929                 :            :                                 "Failed to process asym crypto op\n");
    2930                 :            :                 status = TEST_FAILED;
    2931                 :          0 :                 goto exit;
    2932                 :            :         }
    2933                 :            : 
    2934                 :          1 : exit:
    2935         [ +  - ]:          1 :         if (sess != NULL)
    2936                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    2937                 :          1 :         rte_crypto_op_free(op);
    2938                 :          1 :         return status;
    2939                 :            : };
    2940                 :            : 
    2941                 :            : static int
    2942                 :          1 : test_sm2_enc(void)
    2943                 :            : {
    2944                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    2945                 :          1 :         struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
    2946                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    2947                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    2948                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    2949                 :            :         uint8_t output_buf[TEST_DATA_SIZE], *pbuf = NULL;
    2950                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    2951                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    2952                 :          1 :         struct rte_crypto_op *result_op = NULL;
    2953                 :            :         struct rte_crypto_asym_xform xform;
    2954                 :            :         struct rte_crypto_asym_op *asym_op;
    2955                 :          1 :         struct rte_crypto_op *op = NULL;
    2956                 :            :         int ret, status = TEST_SUCCESS;
    2957                 :          1 :         void *sess = NULL;
    2958                 :            : 
    2959                 :            :         /* Check SM2 capability */
    2960                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
    2961                 :          1 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    2962         [ +  - ]:          1 :         if (capa == NULL)
    2963                 :            :                 return -ENOTSUP;
    2964                 :            : 
    2965                 :            :         /* Setup crypto op data structure */
    2966                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    2967         [ -  + ]:          1 :         if (op == NULL) {
    2968                 :          0 :                 RTE_LOG(ERR, USER1,
    2969                 :            :                                 "line %u FAILED: %s", __LINE__,
    2970                 :            :                                 "Failed to allocate asymmetric crypto "
    2971                 :            :                                 "operation struct\n");
    2972                 :            :                 status = TEST_FAILED;
    2973                 :          0 :                 goto exit;
    2974                 :            :         }
    2975                 :            :         asym_op = op->asym;
    2976                 :            : 
    2977                 :            :         /* Setup asym xform */
    2978                 :          1 :         xform.next = NULL;
    2979                 :          1 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
    2980                 :          1 :         xform.ec.curve_id = input_params.curve;
    2981                 :          1 :         xform.ec.pkey.data = input_params.pkey.data;
    2982                 :          1 :         xform.ec.pkey.length = input_params.pkey.length;
    2983                 :          1 :         xform.ec.q.x.data = input_params.pubkey_qx.data;
    2984                 :          1 :         xform.ec.q.x.length = input_params.pubkey_qx.length;
    2985                 :          1 :         xform.ec.q.y.data = input_params.pubkey_qy.data;
    2986                 :          1 :         xform.ec.q.y.length = input_params.pubkey_qy.length;
    2987                 :            : 
    2988                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    2989         [ -  + ]:          1 :         if (ret < 0) {
    2990                 :          0 :                 RTE_LOG(ERR, USER1,
    2991                 :            :                                 "line %u FAILED: %s", __LINE__,
    2992                 :            :                                 "Session creation failed\n");
    2993         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    2994                 :          0 :                 goto exit;
    2995                 :            :         }
    2996                 :            : 
    2997                 :            :         /* Attach asymmetric crypto session to crypto operations */
    2998         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    2999                 :            : 
    3000                 :            :         /* Compute encrypt */
    3001                 :            : 
    3002                 :            :         /* Populate op with operational details */
    3003                 :          1 :         asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
    3004         [ -  + ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
    3005                 :            :                         RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_PH))
    3006                 :          0 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
    3007                 :            :         else
    3008                 :          1 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
    3009                 :            : 
    3010                 :          1 :         asym_op->sm2.message.data = input_params.message.data;
    3011                 :          1 :         asym_op->sm2.message.length = input_params.message.length;
    3012                 :            : 
    3013         [ +  - ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
    3014                 :            :                         RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
    3015                 :          1 :                 asym_op->sm2.k.data = NULL;
    3016                 :          1 :                 asym_op->sm2.k.length = 0;
    3017                 :            :         } else {
    3018                 :          0 :                 asym_op->sm2.k.data = input_params.k.data;
    3019                 :          0 :                 asym_op->sm2.k.length = input_params.k.length;
    3020                 :            :         }
    3021                 :            : 
    3022                 :            :         /* Init out buf */
    3023                 :          1 :         asym_op->sm2.cipher.data = output_buf;
    3024                 :            : 
    3025                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    3026                 :            : 
    3027                 :            :         /* Process crypto operation */
    3028         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    3029                 :          0 :                 RTE_LOG(ERR, USER1,
    3030                 :            :                                 "line %u FAILED: %s", __LINE__,
    3031                 :            :                                 "Error sending packet for operation\n");
    3032                 :            :                 status = TEST_FAILED;
    3033                 :          0 :                 goto exit;
    3034                 :            :         }
    3035                 :            : 
    3036         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    3037                 :            :                 rte_pause();
    3038                 :            : 
    3039         [ -  + ]:          1 :         if (result_op == NULL) {
    3040                 :          0 :                 RTE_LOG(ERR, USER1,
    3041                 :            :                                 "line %u FAILED: %s", __LINE__,
    3042                 :            :                                 "Failed to process asym crypto op\n");
    3043                 :            :                 status = TEST_FAILED;
    3044                 :          0 :                 goto exit;
    3045                 :            :         }
    3046                 :            : 
    3047         [ -  + ]:          1 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    3048                 :          0 :                 RTE_LOG(ERR, USER1,
    3049                 :            :                                 "line %u FAILED: %s", __LINE__,
    3050                 :            :                                 "Failed to process asym crypto op\n");
    3051                 :            :                 status = TEST_FAILED;
    3052                 :          0 :                 goto exit;
    3053                 :            :         }
    3054                 :            : 
    3055                 :            :         asym_op = result_op->asym;
    3056                 :            : 
    3057                 :          1 :         debug_hexdump(stdout, "cipher:",
    3058                 :          1 :                         asym_op->sm2.cipher.data, asym_op->sm2.cipher.length);
    3059                 :            : 
    3060         [ -  + ]:          1 :         if (!rte_cryptodev_asym_xform_capability_check_opcap(capa,
    3061                 :            :                         RTE_CRYPTO_ASYM_OP_ENCRYPT, RTE_CRYPTO_SM2_RNG)) {
    3062         [ #  # ]:          0 :                 if (memcmp(input_params.cipher.data, asym_op->sm2.cipher.data,
    3063                 :            :                                    asym_op->sm2.cipher.length) != 0) {
    3064                 :            :                         status = TEST_FAILED;
    3065                 :          0 :                         RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
    3066                 :            :                                         "SM2 encrypt failed.\n");
    3067                 :          0 :                         goto exit;
    3068                 :            :                 }
    3069                 :            :         } else {
    3070                 :            :                 /* Verify cipher (in roundtrip).
    3071                 :            :                  * Due to random number used per message, encrypt op
    3072                 :            :                  * would produce different output for same message
    3073                 :            :                  * every time. Hence, we can't have expected output
    3074                 :            :                  * to match, instead reverse op to decrypt.
    3075                 :            :                  */
    3076                 :            : 
    3077                 :            :                 /* Populate op with operational details */
    3078                 :          1 :                 op->asym->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
    3079                 :          1 :                 pbuf = rte_malloc(NULL, TEST_DATA_SIZE, 0);
    3080                 :          1 :                 op->asym->sm2.message.data = pbuf;
    3081                 :          1 :                 op->asym->sm2.message.length = TEST_DATA_SIZE;
    3082                 :            : 
    3083                 :            :                 /* Enqueue cipher result for decrypt */
    3084         [ -  + ]:          1 :                 if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    3085                 :            :                         status = TEST_FAILED;
    3086                 :          0 :                         RTE_LOG(ERR, USER1,
    3087                 :            :                                         "line %u FAILED: %s", __LINE__,
    3088                 :            :                                         "Error sending packet for operation\n");
    3089                 :          0 :                         goto exit;
    3090                 :            :                 }
    3091                 :            : 
    3092         [ -  + ]:          1 :                 while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    3093                 :            :                         rte_pause();
    3094                 :            : 
    3095         [ -  + ]:          1 :                 if (result_op == NULL) {
    3096                 :            :                         status = TEST_FAILED;
    3097                 :          0 :                         goto exit;
    3098                 :            :                 }
    3099         [ -  + ]:          1 :                 if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    3100                 :            :                         status = TEST_FAILED;
    3101                 :          0 :                         RTE_LOG(ERR, USER1,
    3102                 :            :                                         "line %u FAILED: %s", __LINE__,
    3103                 :            :                                         "SM2 encrypt failed.\n");
    3104                 :          0 :                         goto exit;
    3105                 :            :                 }
    3106                 :            : 
    3107                 :            :                 asym_op = result_op->asym;
    3108         [ +  - ]:          1 :                 if (memcmp(input_params.message.data, asym_op->sm2.message.data,
    3109                 :            :                                asym_op->sm2.message.length) != 0) {
    3110                 :            :                         status = TEST_FAILED;
    3111                 :          0 :                         RTE_LOG(ERR, USER1, "line %u FAILED: %s", __LINE__,
    3112                 :            :                                         "SM2 encrypt failed.\n");
    3113                 :          0 :                         goto exit;
    3114                 :            :                 }
    3115                 :            :         }
    3116                 :          1 : exit:
    3117                 :          1 :         rte_free(pbuf);
    3118                 :            : 
    3119         [ +  - ]:          1 :         if (sess != NULL)
    3120                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    3121                 :          1 :         rte_crypto_op_free(op);
    3122                 :          1 :         return status;
    3123                 :            : };
    3124                 :            : 
    3125                 :            : static int
    3126                 :          1 : test_sm2_dec(void)
    3127                 :            : {
    3128                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    3129                 :          1 :         struct crypto_testsuite_sm2_params input_params = sm2_param_fp256;
    3130                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    3131                 :          1 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    3132                 :          1 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    3133                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    3134                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    3135                 :          1 :         struct rte_crypto_op *result_op = NULL;
    3136                 :            :         uint8_t output_buf_m[TEST_DATA_SIZE];
    3137                 :            :         struct rte_crypto_asym_xform xform;
    3138                 :            :         struct rte_crypto_asym_op *asym_op;
    3139                 :          1 :         struct rte_crypto_op *op = NULL;
    3140                 :            :         int ret, status = TEST_SUCCESS;
    3141                 :          1 :         void *sess = NULL;
    3142                 :            : 
    3143                 :            :         /* Check SM2 capability */
    3144                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_SM2;
    3145                 :          1 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    3146         [ +  - ]:          1 :         if (capa == NULL)
    3147                 :            :                 return -ENOTSUP;
    3148                 :            : 
    3149                 :            :         /* Setup crypto op data structure */
    3150                 :          1 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    3151         [ -  + ]:          1 :         if (op == NULL) {
    3152                 :          0 :                 RTE_LOG(ERR, USER1,
    3153                 :            :                                 "line %u FAILED: %s", __LINE__,
    3154                 :            :                                 "Failed to allocate asymmetric crypto "
    3155                 :            :                                 "operation struct\n");
    3156                 :            :                 status = TEST_FAILED;
    3157                 :          0 :                 goto exit;
    3158                 :            :         }
    3159                 :            :         asym_op = op->asym;
    3160                 :            : 
    3161                 :            :         /* Setup asym xform */
    3162                 :          1 :         xform.next = NULL;
    3163                 :          1 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
    3164                 :          1 :         xform.ec.curve_id = input_params.curve;
    3165                 :          1 :         xform.ec.pkey.data = input_params.pkey.data;
    3166                 :          1 :         xform.ec.pkey.length = input_params.pkey.length;
    3167                 :          1 :         xform.ec.q.x.data = input_params.pubkey_qx.data;
    3168                 :          1 :         xform.ec.q.x.length = input_params.pubkey_qx.length;
    3169                 :          1 :         xform.ec.q.y.data = input_params.pubkey_qy.data;
    3170                 :          1 :         xform.ec.q.y.length = input_params.pubkey_qy.length;
    3171                 :            : 
    3172                 :          1 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    3173         [ -  + ]:          1 :         if (ret < 0) {
    3174                 :          0 :                 RTE_LOG(ERR, USER1,
    3175                 :            :                                 "line %u FAILED: %s", __LINE__,
    3176                 :            :                                 "Session creation failed\n");
    3177         [ #  # ]:          0 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    3178                 :          0 :                 goto exit;
    3179                 :            :         }
    3180                 :            : 
    3181                 :            :         /* Attach asymmetric crypto session to crypto operations */
    3182         [ +  - ]:          1 :         rte_crypto_op_attach_asym_session(op, sess);
    3183                 :            : 
    3184                 :            :         /* Compute decrypt */
    3185                 :            : 
    3186                 :            :         /* Populate op with operational details */
    3187                 :          1 :         asym_op->sm2.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
    3188         [ -  + ]:          1 :         if (rte_cryptodev_asym_xform_capability_check_opcap(capa,
    3189                 :            :                         RTE_CRYPTO_ASYM_OP_DECRYPT, RTE_CRYPTO_SM2_PH))
    3190                 :          0 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_SM3;
    3191                 :            :         else
    3192                 :          1 :                 asym_op->sm2.hash = RTE_CRYPTO_AUTH_NULL;
    3193                 :            : 
    3194                 :          1 :         asym_op->sm2.cipher.data = input_params.cipher.data;
    3195                 :          1 :         asym_op->sm2.cipher.length = input_params.cipher.length;
    3196                 :            : 
    3197                 :            :         /* Init out buf */
    3198                 :          1 :         asym_op->sm2.message.data = output_buf_m;
    3199                 :          1 :         asym_op->sm2.message.length = RTE_DIM(output_buf_m);
    3200                 :            : 
    3201                 :          1 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    3202                 :            : 
    3203                 :            :         /* Process crypto operation */
    3204         [ -  + ]:          1 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    3205                 :          0 :                 RTE_LOG(ERR, USER1,
    3206                 :            :                                 "line %u FAILED: %s", __LINE__,
    3207                 :            :                                 "Error sending packet for operation\n");
    3208                 :            :                 status = TEST_FAILED;
    3209                 :          0 :                 goto exit;
    3210                 :            :         }
    3211                 :            : 
    3212         [ -  + ]:          1 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    3213                 :            :                 rte_pause();
    3214                 :            : 
    3215         [ -  + ]:          1 :         if (result_op == NULL) {
    3216                 :          0 :                 RTE_LOG(ERR, USER1,
    3217                 :            :                                 "line %u FAILED: %s", __LINE__,
    3218                 :            :                                 "Failed to process asym crypto op\n");
    3219                 :            :                 status = TEST_FAILED;
    3220                 :          0 :                 goto exit;
    3221                 :            :         }
    3222                 :            : 
    3223         [ -  + ]:          1 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    3224                 :          0 :                 RTE_LOG(ERR, USER1,
    3225                 :            :                                 "line %u FAILED: %s", __LINE__,
    3226                 :            :                                 "Failed to process asym crypto op\n");
    3227                 :            :                 status = TEST_FAILED;
    3228                 :          0 :                 goto exit;
    3229                 :            :         }
    3230                 :            : 
    3231                 :            :         asym_op = result_op->asym;
    3232                 :            : 
    3233                 :          1 :         debug_hexdump(stdout, "message:",
    3234                 :          1 :                         asym_op->sm2.message.data, asym_op->sm2.message.length);
    3235                 :            : 
    3236                 :          1 :         if (memcmp(input_params.message.data, asym_op->sm2.message.data,
    3237         [ +  - ]:          1 :                         op->asym->sm2.message.length)) {
    3238                 :            :                 status = TEST_FAILED;
    3239                 :          0 :                 RTE_LOG(ERR, USER1,
    3240                 :            :                                 "line %u FAILED: %s", __LINE__,
    3241                 :            :                                 "SM2 decrypt failed.\n");
    3242                 :          0 :                 goto exit;
    3243                 :            :         }
    3244                 :          1 : exit:
    3245         [ +  - ]:          1 :         if (sess != NULL)
    3246                 :          1 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    3247                 :          1 :         rte_crypto_op_free(op);
    3248                 :          1 :         return status;
    3249                 :            : };
    3250                 :            : 
    3251                 :            : static int
    3252                 :          9 : test_eddsa_sign(struct crypto_testsuite_eddsa_params *input_params)
    3253                 :            : {
    3254                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    3255                 :          9 :         enum rte_crypto_edward_instance instance = input_params->instance;
    3256                 :          9 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    3257                 :          9 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    3258                 :          9 :         uint8_t dev_id = ts_params->valid_devs[0];
    3259                 :          9 :         struct rte_crypto_op *result_op = NULL;
    3260                 :            :         uint8_t output_buf_r[TEST_DATA_SIZE];
    3261                 :            :         struct rte_crypto_asym_xform xform;
    3262                 :            :         struct rte_crypto_asym_op *asym_op;
    3263                 :          9 :         struct rte_crypto_op *op = NULL;
    3264                 :            :         int ret, status = TEST_FAILED;
    3265                 :          9 :         void *sess = NULL;
    3266                 :            :         bool ctx = false;
    3267                 :            : 
    3268         [ +  + ]:          9 :         if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
    3269                 :            :                 ctx = true;
    3270                 :            : 
    3271                 :            :         /* Setup crypto op data structure */
    3272                 :          9 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    3273         [ -  + ]:          9 :         if (op == NULL) {
    3274                 :          0 :                 RTE_LOG(ERR, USER1,
    3275                 :            :                                 "line %u FAILED: %s", __LINE__,
    3276                 :            :                                 "Failed to allocate asymmetric crypto "
    3277                 :            :                                 "operation struct\n");
    3278                 :            :                 status = TEST_FAILED;
    3279                 :          0 :                 goto exit;
    3280                 :            :         }
    3281                 :            : 
    3282                 :            :         asym_op = op->asym;
    3283                 :            : 
    3284                 :            :         /* Setup asym xform */
    3285                 :          9 :         xform.next = NULL;
    3286                 :          9 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    3287                 :          9 :         xform.ec.curve_id = input_params->curve;
    3288                 :          9 :         xform.ec.pkey.data = input_params->pkey.data;
    3289                 :          9 :         xform.ec.pkey.length = input_params->pkey.length;
    3290                 :          9 :         xform.ec.q.x.data = input_params->pubkey.data;
    3291                 :          9 :         xform.ec.q.x.length = input_params->pubkey.length;
    3292                 :            : 
    3293                 :          9 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    3294         [ +  - ]:          9 :         if (ret < 0) {
    3295                 :          9 :                 RTE_LOG(ERR, USER1,
    3296                 :            :                                 "line %u FAILED: %s", __LINE__,
    3297                 :            :                                 "Session creation failed\n");
    3298         [ -  + ]:          9 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    3299                 :          9 :                 goto exit;
    3300                 :            :         }
    3301                 :            : 
    3302                 :            :         /* Attach asymmetric crypto session to crypto operations */
    3303         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    3304                 :            : 
    3305                 :            :         /* Compute sign */
    3306                 :            : 
    3307                 :            :         /* Populate op with operational details */
    3308                 :          0 :         asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_SIGN;
    3309                 :          0 :         asym_op->eddsa.instance = input_params->instance;
    3310                 :          0 :         asym_op->eddsa.message.data = input_params->message.data;
    3311                 :          0 :         asym_op->eddsa.message.length = input_params->message.length;
    3312                 :          0 :         asym_op->eddsa.context.length = 0;
    3313         [ #  # ]:          0 :         if (ctx) {
    3314                 :          0 :                 asym_op->eddsa.context.data = input_params->context.data;
    3315                 :          0 :                 asym_op->eddsa.context.length = input_params->context.length;
    3316                 :            :         }
    3317                 :            : 
    3318                 :            :         /* Init out buf */
    3319                 :          0 :         asym_op->eddsa.sign.data = output_buf_r;
    3320                 :            : 
    3321                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    3322                 :            : 
    3323                 :            :         /* Process crypto operation */
    3324         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    3325                 :          0 :                 RTE_LOG(ERR, USER1,
    3326                 :            :                                 "line %u FAILED: %s", __LINE__,
    3327                 :            :                                 "Error sending packet for operation\n");
    3328                 :          0 :                 goto exit;
    3329                 :            :         }
    3330                 :            : 
    3331         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    3332                 :            :                 rte_pause();
    3333                 :            : 
    3334         [ #  # ]:          0 :         if (result_op == NULL) {
    3335                 :          0 :                 RTE_LOG(ERR, USER1,
    3336                 :            :                                 "line %u FAILED: %s", __LINE__,
    3337                 :            :                                 "Failed to process asym crypto op\n");
    3338                 :          0 :                 goto exit;
    3339                 :            :         }
    3340                 :            : 
    3341         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    3342                 :          0 :                 RTE_LOG(ERR, USER1,
    3343                 :            :                                 "line %u FAILED: %s", __LINE__,
    3344                 :            :                                 "Failed to process asym crypto op\n");
    3345                 :          0 :                 goto exit;
    3346                 :            :         }
    3347                 :            : 
    3348                 :            :         asym_op = result_op->asym;
    3349                 :            : 
    3350                 :          0 :         debug_hexdump(stdout, "sign:",
    3351                 :          0 :                         asym_op->eddsa.sign.data, asym_op->eddsa.sign.length);
    3352                 :            : 
    3353                 :            :         /* Verify sign (by comparison). */
    3354         [ #  # ]:          0 :         if (memcmp(input_params->sign.data, asym_op->eddsa.sign.data,
    3355                 :            :                            asym_op->eddsa.sign.length) != 0) {
    3356                 :          0 :                 RTE_LOG(ERR, USER1,
    3357                 :            :                                 "line %u FAILED: %s", __LINE__,
    3358                 :            :                                 "EdDSA sign failed.\n");
    3359                 :          0 :                 goto exit;
    3360                 :            :         }
    3361                 :            : 
    3362                 :            :         status = TEST_SUCCESS;
    3363                 :          9 : exit:
    3364         [ +  - ]:          9 :         if (sess != NULL)
    3365                 :          9 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    3366                 :          9 :         rte_crypto_op_free(op);
    3367                 :          9 :         return status;
    3368                 :            : };
    3369                 :            : 
    3370                 :            : static int
    3371                 :          9 : test_eddsa_verify(struct crypto_testsuite_eddsa_params *input_params)
    3372                 :            : {
    3373                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    3374                 :          9 :         enum rte_crypto_edward_instance instance = input_params->instance;
    3375                 :          9 :         struct rte_mempool *sess_mpool = ts_params->session_mpool;
    3376                 :          9 :         struct rte_mempool *op_mpool = ts_params->op_mpool;
    3377                 :          9 :         uint8_t dev_id = ts_params->valid_devs[0];
    3378                 :          9 :         struct rte_crypto_op *result_op = NULL;
    3379                 :            :         struct rte_crypto_asym_xform xform;
    3380                 :            :         struct rte_crypto_asym_op *asym_op;
    3381                 :          9 :         struct rte_crypto_op *op = NULL;
    3382                 :            :         int ret, status = TEST_FAILED;
    3383                 :          9 :         void *sess = NULL;
    3384                 :            :         bool ctx = false;
    3385                 :            : 
    3386         [ +  + ]:          9 :         if (instance == RTE_CRYPTO_EDCURVE_25519CTX)
    3387                 :            :                 ctx = true;
    3388                 :            : 
    3389                 :            :         /* Setup crypto op data structure */
    3390                 :          9 :         op = rte_crypto_op_alloc(op_mpool, RTE_CRYPTO_OP_TYPE_ASYMMETRIC);
    3391         [ -  + ]:          9 :         if (op == NULL) {
    3392                 :          0 :                 RTE_LOG(ERR, USER1,
    3393                 :            :                                 "line %u FAILED: %s", __LINE__,
    3394                 :            :                                 "Failed to allocate asymmetric crypto "
    3395                 :            :                                 "operation struct\n");
    3396                 :          0 :                 goto exit;
    3397                 :            :         }
    3398                 :            : 
    3399                 :            :         asym_op = op->asym;
    3400                 :            : 
    3401                 :            :         /* Setup asym xform */
    3402                 :          9 :         xform.next = NULL;
    3403                 :          9 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    3404                 :          9 :         xform.ec.curve_id = input_params->curve;
    3405                 :          9 :         xform.ec.pkey.length = 0;
    3406                 :          9 :         xform.ec.q.x.data = input_params->pubkey.data;
    3407                 :          9 :         xform.ec.q.x.length = input_params->pubkey.length;
    3408                 :            : 
    3409                 :          9 :         ret = rte_cryptodev_asym_session_create(dev_id, &xform, sess_mpool, &sess);
    3410         [ +  - ]:          9 :         if (ret < 0) {
    3411                 :          9 :                 RTE_LOG(ERR, USER1,
    3412                 :            :                                 "line %u FAILED: %s", __LINE__,
    3413                 :            :                                 "Session creation failed\n");
    3414         [ -  + ]:          9 :                 status = (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    3415                 :          9 :                 goto exit;
    3416                 :            :         }
    3417                 :            : 
    3418                 :            :         /* Attach asymmetric crypto session to crypto operations */
    3419         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(op, sess);
    3420                 :            : 
    3421                 :            :         /* Compute sign */
    3422                 :            : 
    3423                 :            :         /* Populate op with operational details */
    3424                 :          0 :         asym_op->eddsa.op_type = RTE_CRYPTO_ASYM_OP_VERIFY;
    3425                 :          0 :         asym_op->eddsa.instance = input_params->instance;
    3426                 :          0 :         asym_op->eddsa.message.data = input_params->message.data;
    3427                 :          0 :         asym_op->eddsa.message.length = input_params->message.length;
    3428                 :          0 :         asym_op->eddsa.context.length = 0;
    3429         [ #  # ]:          0 :         if (ctx) {
    3430                 :          0 :                 asym_op->eddsa.context.data = input_params->context.data;
    3431                 :          0 :                 asym_op->eddsa.context.length = input_params->context.length;
    3432                 :            :         }
    3433                 :            : 
    3434                 :          0 :         asym_op->eddsa.sign.data = input_params->sign.data;
    3435                 :          0 :         asym_op->eddsa.sign.length = input_params->sign.length;
    3436                 :            : 
    3437                 :          0 :         RTE_LOG(DEBUG, USER1, "Process ASYM operation\n");
    3438                 :            : 
    3439                 :            :         /* Process crypto operation */
    3440         [ #  # ]:          0 :         if (rte_cryptodev_enqueue_burst(dev_id, 0, &op, 1) != 1) {
    3441                 :          0 :                 RTE_LOG(ERR, USER1,
    3442                 :            :                                 "line %u FAILED: %s", __LINE__,
    3443                 :            :                                 "Error sending packet for operation\n");
    3444                 :          0 :                 goto exit;
    3445                 :            :         }
    3446                 :            : 
    3447         [ #  # ]:          0 :         while (rte_cryptodev_dequeue_burst(dev_id, 0, &result_op, 1) == 0)
    3448                 :            :                 rte_pause();
    3449                 :            : 
    3450         [ #  # ]:          0 :         if (result_op == NULL) {
    3451                 :          0 :                 RTE_LOG(ERR, USER1,
    3452                 :            :                                 "line %u FAILED: %s", __LINE__,
    3453                 :            :                                 "Failed to process asym crypto op\n");
    3454                 :          0 :                 goto exit;
    3455                 :            :         }
    3456                 :            : 
    3457         [ #  # ]:          0 :         if (result_op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) {
    3458                 :          0 :                 RTE_LOG(ERR, USER1,
    3459                 :            :                                 "line %u FAILED: %s", __LINE__,
    3460                 :            :                                 "Failed to process asym crypto op\n");
    3461                 :          0 :                 goto exit;
    3462                 :            :         }
    3463                 :            : 
    3464                 :            :         status = TEST_SUCCESS;
    3465                 :          9 : exit:
    3466         [ +  - ]:          9 :         if (sess != NULL)
    3467                 :          9 :                 rte_cryptodev_asym_session_free(dev_id, sess);
    3468                 :          9 :         rte_crypto_op_free(op);
    3469                 :          9 :         return status;
    3470                 :            : };
    3471                 :            : 
    3472                 :            : static int
    3473                 :          1 : test_eddsa_sign_verify_all_curve(void)
    3474                 :            : {
    3475                 :            :         struct crypto_testsuite_params_asym *ts_params = &testsuite_params;
    3476                 :            :         const struct rte_cryptodev_asymmetric_xform_capability *capa;
    3477                 :            :         struct crypto_testsuite_eddsa_params input_params;
    3478                 :            :         struct rte_cryptodev_asym_capability_idx idx;
    3479                 :            :         int status, overall_status = TEST_SUCCESS;
    3480                 :          1 :         uint8_t dev_id = ts_params->valid_devs[0];
    3481                 :            :         uint8_t i, tc = 0;
    3482                 :            :         const char *msg;
    3483                 :            : 
    3484                 :            :         /* Check EdDSA capability */
    3485                 :          1 :         idx.type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    3486                 :          1 :         capa = rte_cryptodev_asym_capability_get(dev_id, &idx);
    3487         [ +  - ]:          1 :         if (capa == NULL)
    3488                 :            :                 return TEST_SKIPPED;
    3489                 :            : 
    3490                 :            :         /* Sign tests */
    3491         [ +  + ]:          9 :         for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
    3492                 :          8 :                 memcpy(&input_params, &eddsa_test_params[i],
    3493                 :            :                                 sizeof(input_params));
    3494                 :          8 :                 status = test_eddsa_sign(&input_params);
    3495         [ +  - ]:          8 :                 if (status == TEST_SUCCESS) {
    3496                 :            :                         msg = "succeeded";
    3497                 :            :                 } else {
    3498                 :            :                         msg = "failed";
    3499                 :            :                         overall_status = status;
    3500                 :            :                 }
    3501                 :          8 :                 printf("  %u) TestCase Sign %s  %s\n",
    3502                 :          8 :                        tc++, input_params.description, msg);
    3503                 :            :         }
    3504                 :            : 
    3505                 :            :         /* Verify tests */
    3506         [ +  + ]:          9 :         for (i = 0; i < RTE_DIM(eddsa_test_params); i++) {
    3507                 :          8 :                 memcpy(&input_params, &eddsa_test_params[i],
    3508                 :            :                                 sizeof(input_params));
    3509                 :          8 :                 status = test_eddsa_verify(&input_params);
    3510         [ +  - ]:          8 :                 if (status == TEST_SUCCESS) {
    3511                 :            :                         msg = "succeeded";
    3512                 :            :                 } else {
    3513                 :            :                         msg = "failed";
    3514                 :            :                         overall_status = status;
    3515                 :            :                 }
    3516                 :          8 :                 printf("  %u) TestCase Verify %s  %s\n",
    3517                 :          8 :                        tc++, input_params.description, msg);
    3518                 :            :         }
    3519                 :            : 
    3520                 :            :         /* Negative tests */
    3521                 :            :         memcpy(&input_params, &eddsa_test_params[1],
    3522                 :            :                         sizeof(input_params));
    3523                 :          1 :         input_params.pubkey.data[0] ^= 0x01;
    3524                 :            : 
    3525                 :          1 :         status = test_eddsa_sign(&input_params);
    3526         [ +  - ]:          1 :         if (status == TEST_FAILED) {
    3527                 :            :                 msg = "succeeded";
    3528                 :            :         } else {
    3529                 :            :                 msg = "failed";
    3530                 :            :                 overall_status = status;
    3531                 :            :         }
    3532                 :          1 :         printf("  %u) TestCase Negative Sign %s  %s\n",
    3533                 :          1 :                         tc++, input_params.description, msg);
    3534                 :            : 
    3535                 :          1 :         status = test_eddsa_verify(&input_params);
    3536         [ +  - ]:          1 :         if (status == TEST_FAILED) {
    3537                 :            :                 msg = "succeeded";
    3538                 :            :         } else {
    3539                 :            :                 msg = "failed";
    3540                 :            :                 overall_status = status;
    3541                 :            :         }
    3542                 :          1 :         printf("  %u) TestCase Negative Verify %s  %s\n",
    3543                 :            :                         tc++, input_params.description, msg);
    3544                 :            : 
    3545                 :          1 :         return overall_status;
    3546                 :            : }
    3547                 :            : 
    3548                 :          8 : static int send_one(void)
    3549                 :            : {
    3550                 :            :         int ticks = 0;
    3551                 :            : 
    3552         [ -  + ]:          8 :         if (rte_cryptodev_enqueue_burst(params->valid_devs[0], 0,
    3553                 :          8 :                         &self->op, 1) != 1) {
    3554                 :          0 :                 RTE_LOG(ERR, USER1,
    3555                 :            :                         "line %u FAILED: Error sending packet for operation on device %d",
    3556                 :            :                         __LINE__, params->valid_devs[0]);
    3557                 :          0 :                 return TEST_FAILED;
    3558                 :            :         }
    3559                 :          8 :         while (rte_cryptodev_dequeue_burst(params->valid_devs[0], 0,
    3560         [ -  + ]:          8 :                         &self->result_op, 1) == 0) {
    3561                 :            :                 rte_delay_ms(1);
    3562                 :          0 :                 ticks++;
    3563         [ #  # ]:          0 :                 if (ticks >= DEQ_TIMEOUT) {
    3564                 :          0 :                         RTE_LOG(ERR, USER1,
    3565                 :            :                                 "line %u FAILED: Cannot dequeue the crypto op on device %d",
    3566                 :            :                                 __LINE__, params->valid_devs[0]);
    3567                 :          0 :                         return TEST_FAILED;
    3568                 :            :                 }
    3569                 :            :         }
    3570         [ -  + ]:          8 :         TEST_ASSERT_NOT_NULL(self->result_op,
    3571                 :            :                 "Failed to process asym crypto op");
    3572         [ -  + ]:          8 :         TEST_ASSERT_SUCCESS(self->result_op->status,
    3573                 :            :                 "Failed to process asym crypto op, error status received");
    3574                 :            :         return TEST_SUCCESS;
    3575                 :            : }
    3576                 :            : 
    3577                 :            : static int
    3578                 :          8 : modular_cmpeq(const uint8_t *a, size_t a_len, const uint8_t *b, size_t b_len)
    3579                 :            : {
    3580                 :            :         const uint8_t *new_a, *new_b;
    3581                 :            :         size_t i, j;
    3582                 :            : 
    3583                 :            :         /* Strip leading NUL bytes */
    3584         [ +  - ]:          8 :         for (i = 0; i < a_len; i++)
    3585         [ +  - ]:          8 :                 if (a[i] != 0)
    3586                 :            :                         break;
    3587                 :            : 
    3588         [ +  - ]:          8 :         for (j = 0; j < b_len; j++)
    3589         [ -  + ]:          8 :                 if (b[j] != 0)
    3590                 :            :                         break;
    3591                 :            : 
    3592         [ +  - ]:          8 :         if (a_len - i != b_len - j)
    3593                 :            :                 return 1;
    3594                 :            : 
    3595                 :          8 :         new_a = &a[i];
    3596                 :          8 :         new_b = &b[j];
    3597         [ -  + ]:          8 :         if (memcmp(new_a, new_b, a_len - i))
    3598                 :          0 :                 return 1;
    3599                 :            : 
    3600                 :            :         return 0;
    3601                 :            : }
    3602                 :            : 
    3603                 :            : static int
    3604                 :          8 : modular_exponentiation(const void *test_data)
    3605                 :            : {
    3606                 :            :         const struct modex_test_data *vector = test_data;
    3607                 :          8 :         uint8_t input[TEST_DATA_SIZE] = { 0 };
    3608                 :          8 :         uint8_t exponent[TEST_DATA_SIZE] = { 0 };
    3609                 :          8 :         uint8_t modulus[TEST_DATA_SIZE] = { 0 };
    3610                 :          8 :         uint8_t result[TEST_DATA_SIZE] = { 0 };
    3611                 :          8 :         struct rte_crypto_asym_xform xform = { };
    3612                 :          8 :         const uint8_t dev_id = params->valid_devs[0];
    3613                 :            : 
    3614                 :          8 :         memcpy(input, vector->base.data, vector->base.len);
    3615                 :          8 :         memcpy(exponent, vector->exponent.data, vector->exponent.len);
    3616                 :          8 :         memcpy(modulus, vector->modulus.data, vector->modulus.len);
    3617                 :            : 
    3618                 :          8 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
    3619                 :          8 :         xform.modex.exponent.data = exponent;
    3620                 :          8 :         xform.modex.exponent.length = vector->exponent.len;
    3621                 :          8 :         xform.modex.modulus.data = modulus;
    3622                 :          8 :         xform.modex.modulus.length = vector->modulus.len;
    3623                 :            : 
    3624         [ -  + ]:          8 :         if (rte_cryptodev_asym_session_create(dev_id, &xform,
    3625                 :          8 :                         params->session_mpool, &self->sess) < 0) {
    3626                 :          0 :                 RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
    3627                 :            :                         __LINE__);
    3628                 :          0 :                 return TEST_FAILED;
    3629                 :            :         }
    3630         [ +  - ]:          8 :         rte_crypto_op_attach_asym_session(self->op, self->sess);
    3631                 :          8 :         self->op->asym->modex.base.data = input;
    3632                 :          8 :         self->op->asym->modex.base.length = vector->base.len;
    3633                 :          8 :         self->op->asym->modex.result.data = result;
    3634                 :            : 
    3635         [ -  + ]:          8 :         TEST_ASSERT_SUCCESS(send_one(),
    3636                 :            :                 "Failed to process crypto op");
    3637         [ -  + ]:          8 :         TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data, vector->reminder.len,
    3638                 :            :                         self->result_op->asym->modex.result.data,
    3639                 :            :                         self->result_op->asym->modex.result.length),
    3640                 :            :                         "operation verification failed\n");
    3641                 :            : 
    3642                 :            :         return TEST_SUCCESS;
    3643                 :            : }
    3644                 :            : 
    3645                 :            : static int
    3646                 :          0 : modular_multiplicative_inverse(const void *test_data)
    3647                 :            : {
    3648                 :            :         const struct modinv_test_data *vector = test_data;
    3649                 :          0 :         uint8_t input[TEST_DATA_SIZE] = { 0 };
    3650                 :          0 :         uint8_t modulus[TEST_DATA_SIZE] = { 0 };
    3651                 :          0 :         uint8_t result[TEST_DATA_SIZE] = { 0 };
    3652                 :          0 :         struct rte_crypto_asym_xform xform = { };
    3653                 :          0 :         const uint8_t dev_id = params->valid_devs[0];
    3654                 :            : 
    3655                 :          0 :         memcpy(input, vector->base.data, vector->base.len);
    3656                 :          0 :         memcpy(modulus, vector->modulus.data, vector->modulus.len);
    3657                 :          0 :         xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV;
    3658                 :          0 :         xform.modex.modulus.data = modulus;
    3659                 :          0 :         xform.modex.modulus.length = vector->modulus.len;
    3660         [ #  # ]:          0 :         if (rte_cryptodev_asym_session_create(dev_id, &xform,
    3661                 :          0 :                         params->session_mpool, &self->sess) < 0) {
    3662                 :          0 :                 RTE_LOG(ERR, USER1, "line %u FAILED: Session creation failed",
    3663                 :            :                         __LINE__);
    3664                 :          0 :                 return TEST_FAILED;
    3665                 :            :         }
    3666         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(self->op, self->sess);
    3667                 :            : 
    3668                 :          0 :         self->op->asym->modinv.base.data = input;
    3669                 :          0 :         self->op->asym->modinv.base.length = vector->base.len;
    3670                 :          0 :         self->op->asym->modinv.result.data = result;
    3671                 :          0 :         self->op->asym->modinv.result.length = vector->modulus.len;
    3672                 :            : 
    3673         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(send_one(),
    3674                 :            :                 "Failed to process crypto op");
    3675         [ #  # ]:          0 :         TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->inverse.data,
    3676                 :            :                 self->result_op->asym->modinv.result.data,
    3677                 :            :                 self->result_op->asym->modinv.result.length,
    3678                 :            :                 "Incorrect reminder\n");
    3679                 :            : 
    3680                 :            :         return TEST_SUCCESS;
    3681                 :            : }
    3682                 :            : 
    3683                 :            : #define SET_RSA_PARAM(arg, vector, coef) \
    3684                 :            :         uint8_t coef[TEST_DATA_SIZE] = { }; \
    3685                 :            :         memcpy(coef, vector->coef.data, vector->coef.len); \
    3686                 :            :         arg.coef.data = coef; \
    3687                 :            :         arg.coef.length = vector->coef.len
    3688                 :            : 
    3689                 :            : #define SET_RSA_PARAM_QT(arg, vector, coef) \
    3690                 :            :         uint8_t coef[TEST_DATA_SIZE] = { }; \
    3691                 :            :         memcpy(coef, vector->coef.data, vector->coef.len); \
    3692                 :            :         arg.qt.coef.data = coef; \
    3693                 :            :         arg.qt.coef.length = vector->coef.len
    3694                 :            : 
    3695                 :            : static int
    3696                 :          0 : rsa_encrypt(const struct rsa_test_data_2 *vector, uint8_t *cipher_buf)
    3697                 :            : {
    3698                 :          0 :         self->result_op = NULL;
    3699                 :            :         /* Compute encryption on the test vector */
    3700                 :          0 :         self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_ENCRYPT;
    3701                 :          0 :         self->op->asym->rsa.cipher.data = cipher_buf;
    3702                 :          0 :         self->op->asym->rsa.cipher.length = 0;
    3703         [ #  # ]:          0 :         SET_RSA_PARAM(self->op->asym->rsa, vector, message);
    3704                 :            : 
    3705         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(self->op, self->sess);
    3706         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(send_one(),
    3707                 :            :                 "Failed to process crypto op (Enryption)");
    3708                 :            : 
    3709                 :            :         return 0;
    3710                 :            : }
    3711                 :            : 
    3712                 :            : static int
    3713                 :          0 : rsa_decrypt(const struct rsa_test_data_2 *vector, uint8_t *plaintext,
    3714                 :            :                 const int use_op)
    3715                 :            : {
    3716                 :          0 :         uint8_t cipher[TEST_DATA_SIZE] = { 0 };
    3717                 :            : 
    3718         [ #  # ]:          0 :         if (use_op == 0) {
    3719                 :          0 :                 memcpy(cipher, vector->cipher.data, vector->cipher.len);
    3720                 :          0 :                 self->op->asym->rsa.cipher.data = cipher;
    3721                 :          0 :                 self->op->asym->rsa.cipher.length = vector->cipher.len;
    3722                 :            :         }
    3723                 :          0 :         self->result_op = NULL;
    3724                 :          0 :         self->op->asym->rsa.message.data = plaintext;
    3725                 :          0 :         self->op->asym->rsa.message.length = 0;
    3726                 :          0 :         self->op->asym->rsa.op_type = RTE_CRYPTO_ASYM_OP_DECRYPT;
    3727         [ #  # ]:          0 :         rte_crypto_op_attach_asym_session(self->op, self->sess);
    3728         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(send_one(),
    3729                 :            :                 "Failed to process crypto op (Decryption)");
    3730                 :            :         return 0;
    3731                 :            : }
    3732                 :            : 
    3733                 :            : static int
    3734                 :          0 : rsa_init_session(struct rte_crypto_asym_xform *xform)
    3735                 :            : {
    3736                 :          0 :         const uint8_t dev_id = params->valid_devs[0];
    3737                 :            :         struct rte_cryptodev_info dev_info;
    3738                 :            :         int ret = 0;
    3739                 :            : 
    3740                 :          0 :         xform->xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
    3741                 :            : 
    3742                 :          0 :         rte_cryptodev_info_get(dev_id, &dev_info);
    3743         [ #  # ]:          0 :         if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_RSA_PRIV_OP_KEY_QT)) {
    3744                 :          0 :                 RTE_LOG(INFO, USER1,
    3745                 :            :                         "Device doesn't support decrypt op with quintuple key type. Test skipped\n");
    3746                 :          0 :                 return TEST_SKIPPED;
    3747                 :            :         }
    3748                 :          0 :         ret = rte_cryptodev_asym_session_create(dev_id, xform,
    3749                 :          0 :                 params->session_mpool, &self->sess);
    3750         [ #  # ]:          0 :         if (ret < 0) {
    3751                 :          0 :                 RTE_LOG(ERR, USER1,
    3752                 :            :                         "Session creation failed for enc_dec_crt\n");
    3753         [ #  # ]:          0 :                 return (ret == -ENOTSUP) ? TEST_SKIPPED : TEST_FAILED;
    3754                 :            :         }
    3755                 :            :         return 0;
    3756                 :            : }
    3757                 :            : 
    3758                 :            : static int
    3759                 :          0 : kat_rsa_encrypt(const void *data)
    3760                 :            : {
    3761                 :          0 :         uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
    3762                 :            :         const struct rsa_test_data_2 *vector = data;
    3763                 :          0 :         struct rte_crypto_asym_xform xform = { };
    3764                 :            : 
    3765                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, n);
    3766                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, e);
    3767                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, d);
    3768                 :          0 :         xform.rsa.padding.type = vector->padding;
    3769                 :            :         xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
    3770                 :          0 :         int ret = rsa_init_session(&xform);
    3771                 :            : 
    3772         [ #  # ]:          0 :         if (ret) {
    3773                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
    3774                 :          0 :                 return ret;
    3775                 :            :         }
    3776         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
    3777                 :            :                 "RSA: Failed to encrypt");
    3778         [ #  # ]:          0 :         TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
    3779                 :            :                 self->result_op->asym->rsa.cipher.data,
    3780                 :            :                 self->result_op->asym->rsa.cipher.length,
    3781                 :            :                 "operation verification failed\n");
    3782                 :            :         return 0;
    3783                 :            : }
    3784                 :            : 
    3785                 :            : static int
    3786                 :          0 : kat_rsa_encrypt_crt(const void *data)
    3787                 :            : {
    3788                 :          0 :         uint8_t cipher_buf[TEST_DATA_SIZE] = {0};
    3789                 :            :         const struct rsa_test_data_2 *vector = data;
    3790                 :          0 :         struct rte_crypto_asym_xform xform = { };
    3791                 :            : 
    3792                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, n);
    3793                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, e);
    3794                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, p);
    3795                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, q);
    3796                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, dP);
    3797                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
    3798                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
    3799                 :          0 :         xform.rsa.padding.type = vector->padding;
    3800                 :          0 :         xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
    3801                 :          0 :         int ret = rsa_init_session(&xform);
    3802         [ #  # ]:          0 :         if (ret) {
    3803                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
    3804                 :          0 :                 return ret;
    3805                 :            :         }
    3806         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rsa_encrypt(vector, cipher_buf),
    3807                 :            :                 "RSA: Failed to encrypt");
    3808         [ #  # ]:          0 :         TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->cipher.data,
    3809                 :            :                 self->result_op->asym->rsa.cipher.data,
    3810                 :            :                 self->result_op->asym->rsa.cipher.length,
    3811                 :            :                 "operation verification failed\n");
    3812                 :            :         return 0;
    3813                 :            : }
    3814                 :            : 
    3815                 :            : static int
    3816                 :          0 : kat_rsa_decrypt(const void *data)
    3817                 :            : {
    3818                 :          0 :         uint8_t message[TEST_DATA_SIZE] = {0};
    3819                 :            :         const struct rsa_test_data_2 *vector = data;
    3820                 :          0 :         struct rte_crypto_asym_xform xform = { };
    3821                 :            : 
    3822                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, n);
    3823                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, e);
    3824                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, d);
    3825                 :          0 :         xform.rsa.padding.type = vector->padding;
    3826                 :            :         xform.rsa.key_type = RTE_RSA_KEY_TYPE_EXP;
    3827                 :          0 :         int ret = rsa_init_session(&xform);
    3828                 :            : 
    3829         [ #  # ]:          0 :         if (ret) {
    3830                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
    3831                 :          0 :                 return ret;
    3832                 :            :         }
    3833         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
    3834                 :            :                 "RSA: Failed to encrypt");
    3835         [ #  # ]:          0 :         TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
    3836                 :            :                 self->result_op->asym->rsa.message.data,
    3837                 :            :                 self->result_op->asym->rsa.message.length,
    3838                 :            :                 "operation verification failed\n");
    3839                 :            :         return 0;
    3840                 :            : }
    3841                 :            : 
    3842                 :            : static int
    3843                 :          0 : kat_rsa_decrypt_crt(const void *data)
    3844                 :            : {
    3845                 :          0 :         uint8_t message[TEST_DATA_SIZE] = {0};
    3846                 :            :         const struct rsa_test_data_2 *vector = data;
    3847                 :          0 :         struct rte_crypto_asym_xform xform = { };
    3848                 :            : 
    3849                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, n);
    3850                 :          0 :         SET_RSA_PARAM(xform.rsa, vector, e);
    3851                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, p);
    3852                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, q);
    3853                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, dP);
    3854                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, dQ);
    3855                 :          0 :         SET_RSA_PARAM_QT(xform.rsa, vector, qInv);
    3856                 :          0 :         xform.rsa.padding.type = vector->padding;
    3857                 :          0 :         xform.rsa.key_type = RTE_RSA_KEY_TYPE_QT;
    3858                 :          0 :         int ret = rsa_init_session(&xform);
    3859         [ #  # ]:          0 :         if (ret) {
    3860                 :          0 :                 RTE_LOG(ERR, USER1, "Failed to init session for RSA\n");
    3861                 :          0 :                 return ret;
    3862                 :            :         }
    3863         [ #  # ]:          0 :         TEST_ASSERT_SUCCESS(rsa_decrypt(vector, message, 0),
    3864                 :            :                 "RSA: Failed to encrypt");
    3865         [ #  # ]:          0 :         TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->message.data,
    3866                 :            :                 self->result_op->asym->rsa.message.data,
    3867                 :            :                 self->result_op->asym->rsa.message.length,
    3868                 :            :                 "operation verification failed\n");
    3869                 :            :         return 0;
    3870                 :            : }
    3871                 :            : 
    3872                 :            : static struct unit_test_suite cryptodev_openssl_asym_testsuite  = {
    3873                 :            :         .suite_name = "Crypto Device OPENSSL ASYM Unit Test Suite",
    3874                 :            :         .setup = testsuite_setup,
    3875                 :            :         .teardown = testsuite_teardown,
    3876                 :            :         .unit_test_cases = {
    3877                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
    3878                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_dsa),
    3879                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3880                 :            :                                 test_dh_key_generation),
    3881                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
    3882                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
    3883                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_enc),
    3884                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_dec),
    3885                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
    3886                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3887                 :            :                                 test_rsa_sign_verify),
    3888                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3889                 :            :                                 test_rsa_enc_dec_crt),
    3890                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3891                 :            :                                 test_rsa_sign_verify_crt),
    3892                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_inv),
    3893                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
    3894                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3895                 :            :                         "Modex test for zero padding",
    3896                 :            :                         ut_setup_asym, ut_teardown_asym,
    3897                 :            :                         modular_exponentiation, &modex_test_cases[0]),
    3898                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3899                 :            :                         "Modex test for zero padding (2)",
    3900                 :            :                         ut_setup_asym, ut_teardown_asym,
    3901                 :            :                         modular_exponentiation, &modex_test_cases[1]),
    3902                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3903                 :            :                         "Modex Group 5 test",
    3904                 :            :                         ut_setup_asym, ut_teardown_asym,
    3905                 :            :                         modular_exponentiation, &modex_group_test_cases[0]),
    3906                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3907                 :            :                         "Modex Group 14 test",
    3908                 :            :                         ut_setup_asym, ut_teardown_asym,
    3909                 :            :                         modular_exponentiation, &modex_group_test_cases[1]),
    3910                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3911                 :            :                         "Modex Group 15 test",
    3912                 :            :                         ut_setup_asym, ut_teardown_asym,
    3913                 :            :                         modular_exponentiation, &modex_group_test_cases[2]),
    3914                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3915                 :            :                         "Modex Group 16 test",
    3916                 :            :                         ut_setup_asym, ut_teardown_asym,
    3917                 :            :                         modular_exponentiation, &modex_group_test_cases[3]),
    3918                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3919                 :            :                         "Modex Group 17 test",
    3920                 :            :                         ut_setup_asym, ut_teardown_asym,
    3921                 :            :                         modular_exponentiation, &modex_group_test_cases[4]),
    3922                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3923                 :            :                         "Modex Group 18 test",
    3924                 :            :                         ut_setup_asym, ut_teardown_asym,
    3925                 :            :                         modular_exponentiation, &modex_group_test_cases[5]),
    3926                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
    3927                 :            :                 TEST_CASES_END() /**< NULL terminate unit test array */
    3928                 :            :         }
    3929                 :            : };
    3930                 :            : 
    3931                 :            : static struct unit_test_suite cryptodev_qat_asym_testsuite  = {
    3932                 :            :         .suite_name = "Crypto Device QAT ASYM Unit Test Suite",
    3933                 :            :         .setup = testsuite_setup,
    3934                 :            :         .teardown = testsuite_teardown,
    3935                 :            :         .unit_test_cases = {
    3936                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3937                 :            :                         "Modular Exponentiation (mod=128, base=20, exp=3, res=128)",
    3938                 :            :                         ut_setup_asym, ut_teardown_asym,
    3939                 :            :                         modular_exponentiation, &modex_test_case_m128_b20_e3),
    3940                 :            :                 /* Modular Multiplicative Inverse */
    3941                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3942                 :            :                         "Modular Inverse (mod=128, base=20, exp=3, inv=128)",
    3943                 :            :                         ut_setup_asym, ut_teardown_asym,
    3944                 :            :                         modular_multiplicative_inverse, &modinv_test_case),
    3945                 :            :                 /* RSA EXP */
    3946                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3947                 :            :                         "RSA Encryption (n=128, pt=20, e=3) EXP, Padding: NONE",
    3948                 :            :                         ut_setup_asym, ut_teardown_asym,
    3949                 :            :                         kat_rsa_encrypt, &rsa_vector_128_20_3_none),
    3950                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3951                 :            :                         "RSA Decryption (n=128, pt=20, e=3) EXP, Padding: NONE",
    3952                 :            :                         ut_setup_asym, ut_teardown_asym,
    3953                 :            :                         kat_rsa_decrypt, &rsa_vector_128_20_3_none),
    3954                 :            :                 /* RSA CRT */
    3955                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3956                 :            :                         "RSA Encryption (n=128, pt=20, e=3) CRT, Padding: NONE",
    3957                 :            :                         ut_setup_asym, ut_teardown_asym,
    3958                 :            :                         kat_rsa_encrypt_crt, &rsa_vector_128_20_3_none),
    3959                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3960                 :            :                         "RSA Decryption (n=128, pt=20, e=3) CRT, Padding: NONE",
    3961                 :            :                         ut_setup_asym, ut_teardown_asym,
    3962                 :            :                         kat_rsa_decrypt_crt, &rsa_vector_128_20_3_none),
    3963                 :            :                 TEST_CASES_END() /**< NULL terminate unit test array */
    3964                 :            :         }
    3965                 :            : };
    3966                 :            : 
    3967                 :            : static struct unit_test_suite cryptodev_octeontx_asym_testsuite  = {
    3968                 :            :         .suite_name = "Crypto Device OCTEONTX ASYM Unit Test Suite",
    3969                 :            :         .setup = testsuite_setup,
    3970                 :            :         .teardown = testsuite_teardown,
    3971                 :            :         .unit_test_cases = {
    3972                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
    3973                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3974                 :            :                                 test_rsa_enc_dec_crt),
    3975                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3976                 :            :                                 test_rsa_sign_verify_crt),
    3977                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec),
    3978                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    3979                 :            :                                 test_rsa_sign_verify),
    3980                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_mod_exp),
    3981                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3982                 :            :                         "Modex test for zero padding",
    3983                 :            :                         ut_setup_asym, ut_teardown_asym,
    3984                 :            :                         modular_exponentiation, &modex_test_cases[0]),
    3985                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3986                 :            :                         "Modex test for zero padding (2)",
    3987                 :            :                         ut_setup_asym, ut_teardown_asym,
    3988                 :            :                         modular_exponentiation, &modex_test_cases[1]),
    3989                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3990                 :            :                         "Modex Group 5 test",
    3991                 :            :                         ut_setup_asym, ut_teardown_asym,
    3992                 :            :                         modular_exponentiation, &modex_group_test_cases[0]),
    3993                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3994                 :            :                         "Modex Group 14 test",
    3995                 :            :                         ut_setup_asym, ut_teardown_asym,
    3996                 :            :                         modular_exponentiation, &modex_group_test_cases[1]),
    3997                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    3998                 :            :                         "Modex Group 15 test",
    3999                 :            :                         ut_setup_asym, ut_teardown_asym,
    4000                 :            :                         modular_exponentiation, &modex_group_test_cases[2]),
    4001                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    4002                 :            :                         "Modex Group 16 test",
    4003                 :            :                         ut_setup_asym, ut_teardown_asym,
    4004                 :            :                         modular_exponentiation, &modex_group_test_cases[3]),
    4005                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    4006                 :            :                         "Modex Group 17 test",
    4007                 :            :                         ut_setup_asym, ut_teardown_asym,
    4008                 :            :                         modular_exponentiation, &modex_group_test_cases[4]),
    4009                 :            :                 TEST_CASE_NAMED_WITH_DATA(
    4010                 :            :                         "Modex Group 18 test",
    4011                 :            :                         ut_setup_asym, ut_teardown_asym,
    4012                 :            :                         modular_exponentiation, &modex_group_test_cases[5]),
    4013                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    4014                 :            :                              test_ecdsa_sign_verify_all_curve),
    4015                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_sign),
    4016                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_sm2_verify),
    4017                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    4018                 :            :                                 test_ecdh_all_curve),
    4019                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    4020                 :            :                                 test_ecpm_all_curve),
    4021                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_eddsa_sign_verify_all_curve),
    4022                 :            :                 TEST_CASES_END() /**< NULL terminate unit test array */
    4023                 :            :         }
    4024                 :            : };
    4025                 :            : 
    4026                 :            : static struct unit_test_suite cryptodev_virtio_asym_testsuite  = {
    4027                 :            :         .suite_name = "Crypto Device VIRTIO ASYM Unit Test Suite",
    4028                 :            :         .setup = testsuite_setup,
    4029                 :            :         .teardown = testsuite_teardown,
    4030                 :            :         .unit_test_cases = {
    4031                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_capability),
    4032                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym,
    4033                 :            :                                 test_rsa_sign_verify_crt),
    4034                 :            :                 TEST_CASE_ST(ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt),
    4035                 :            :                 TEST_CASES_END() /**< NULL terminate unit test array */
    4036                 :            :         }
    4037                 :            : };
    4038                 :            : 
    4039                 :            : static int
    4040                 :          1 : test_cryptodev_openssl_asym(void)
    4041                 :            : {
    4042                 :          1 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4043                 :            :                         RTE_STR(CRYPTODEV_NAME_OPENSSL_PMD));
    4044                 :            : 
    4045         [ -  + ]:          1 :         if (gbl_driver_id == -1) {
    4046                 :          0 :                 RTE_LOG(ERR, USER1, "OPENSSL PMD must be loaded.\n");
    4047                 :          0 :                 return TEST_SKIPPED;
    4048                 :            :         }
    4049                 :            : 
    4050                 :          1 :         return unit_test_suite_runner(&cryptodev_openssl_asym_testsuite);
    4051                 :            : }
    4052                 :            : 
    4053                 :            : static int
    4054                 :          0 : test_cryptodev_qat_asym(void)
    4055                 :            : {
    4056                 :          0 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4057                 :            :                         RTE_STR(CRYPTODEV_NAME_QAT_ASYM_PMD));
    4058                 :            : 
    4059         [ #  # ]:          0 :         if (gbl_driver_id == -1) {
    4060                 :          0 :                 RTE_LOG(ERR, USER1, "QAT PMD must be loaded.\n");
    4061                 :          0 :                 return TEST_SKIPPED;
    4062                 :            :         }
    4063                 :            : 
    4064                 :          0 :         return unit_test_suite_runner(&cryptodev_qat_asym_testsuite);
    4065                 :            : }
    4066                 :            : 
    4067                 :            : static int
    4068                 :          0 : test_cryptodev_octeontx_asym(void)
    4069                 :            : {
    4070                 :          0 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4071                 :            :                         RTE_STR(CRYPTODEV_NAME_OCTEONTX_SYM_PMD));
    4072         [ #  # ]:          0 :         if (gbl_driver_id == -1) {
    4073                 :          0 :                 RTE_LOG(ERR, USER1, "OCTEONTX PMD must be loaded.\n");
    4074                 :          0 :                 return TEST_SKIPPED;
    4075                 :            :         }
    4076                 :          0 :         return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
    4077                 :            : }
    4078                 :            : 
    4079                 :            : static int
    4080                 :          0 : test_cryptodev_cn9k_asym(void)
    4081                 :            : {
    4082                 :          0 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4083                 :            :                         RTE_STR(CRYPTODEV_NAME_CN9K_PMD));
    4084         [ #  # ]:          0 :         if (gbl_driver_id == -1) {
    4085                 :          0 :                 RTE_LOG(ERR, USER1, "CN9K PMD must be loaded.\n");
    4086                 :          0 :                 return TEST_SKIPPED;
    4087                 :            :         }
    4088                 :            : 
    4089                 :            :         /* Use test suite registered for crypto_octeontx PMD */
    4090                 :          0 :         return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
    4091                 :            : }
    4092                 :            : 
    4093                 :            : static int
    4094                 :          0 : test_cryptodev_cn10k_asym(void)
    4095                 :            : {
    4096                 :          0 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4097                 :            :                         RTE_STR(CRYPTODEV_NAME_CN10K_PMD));
    4098         [ #  # ]:          0 :         if (gbl_driver_id == -1) {
    4099                 :          0 :                 RTE_LOG(ERR, USER1, "CN10K PMD must be loaded.\n");
    4100                 :          0 :                 return TEST_SKIPPED;
    4101                 :            :         }
    4102                 :            : 
    4103                 :            :         /* Use test suite registered for crypto_octeontx PMD */
    4104                 :          0 :         return unit_test_suite_runner(&cryptodev_octeontx_asym_testsuite);
    4105                 :            : }
    4106                 :            : 
    4107                 :            : static int
    4108                 :          0 : test_cryptodev_virtio_asym(void)
    4109                 :            : {
    4110                 :          0 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4111                 :            :                         RTE_STR(CRYPTODEV_NAME_VIRTIO_PMD));
    4112         [ #  # ]:          0 :         if (gbl_driver_id == -1) {
    4113                 :          0 :                 RTE_LOG(ERR, USER1, "virtio PMD must be loaded.\n");
    4114                 :          0 :                 return TEST_SKIPPED;
    4115                 :            :         }
    4116                 :            : 
    4117                 :            :         /* Use test suite registered for crypto_virtio PMD */
    4118                 :          0 :         return unit_test_suite_runner(&cryptodev_virtio_asym_testsuite);
    4119                 :            : }
    4120                 :            : 
    4121                 :            : static int
    4122                 :          0 : test_cryptodev_virtio_user_asym(void)
    4123                 :            : {
    4124                 :          0 :         gbl_driver_id = rte_cryptodev_driver_id_get(
    4125                 :            :                         RTE_STR(CRYPTODEV_NAME_VIRTIO_USER_PMD));
    4126         [ #  # ]:          0 :         if (gbl_driver_id == -1) {
    4127                 :          0 :                 RTE_LOG(ERR, USER1, "virtio user PMD must be loaded.\n");
    4128                 :          0 :                 return TEST_SKIPPED;
    4129                 :            :         }
    4130                 :            : 
    4131                 :            :         /* Use test suite registered for crypto_virtio_user PMD */
    4132                 :          0 :         return unit_test_suite_runner(&cryptodev_virtio_asym_testsuite);
    4133                 :            : }
    4134                 :            : 
    4135                 :        252 : REGISTER_DRIVER_TEST(cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);
    4136                 :        252 : REGISTER_DRIVER_TEST(cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
    4137                 :        252 : REGISTER_DRIVER_TEST(cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
    4138                 :        252 : REGISTER_DRIVER_TEST(cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);
    4139                 :        252 : REGISTER_DRIVER_TEST(cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);
    4140                 :        252 : REGISTER_DRIVER_TEST(cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
    4141                 :        252 : REGISTER_DRIVER_TEST(cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);

Generated by: LCOV version 1.14