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

Generated by: LCOV version 1.14