LCOV - code coverage report
Current view: top level - app/test - test_cryptodev_asym.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 812 1799 45.1 %
Date: 2025-06-01 17:49:23 Functions: 40 63 63.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 237 819 28.9 %

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

Generated by: LCOV version 1.14