LCOV - code coverage report
Current view: top level - app/test-crypto-perf - cperf_ops.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 697 0.0 %
Date: 2025-07-01 21:32:37 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2016-2017 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_cryptodev.h>
       6                 :            : #include <rte_ether.h>
       7                 :            : #include <rte_ip.h>
       8                 :            : 
       9                 :            : #include "cperf_ops.h"
      10                 :            : #include "cperf_test_vectors.h"
      11                 :            : 
      12                 :            : static void
      13                 :          0 : cperf_set_ops_asym_modex(struct rte_crypto_op **ops,
      14                 :            :                    uint32_t src_buf_offset __rte_unused,
      15                 :            :                    uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
      16                 :            :                    void *sess,
      17                 :            :                    const struct cperf_options *options,
      18                 :            :                    const struct cperf_test_vector *test_vector __rte_unused,
      19                 :            :                    uint16_t iv_offset __rte_unused,
      20                 :            :                    uint32_t *imix_idx __rte_unused,
      21                 :            :                    uint64_t *tsc_start __rte_unused)
      22                 :            : {
      23                 :            :         uint16_t i;
      24                 :            : 
      25                 :          0 :         for (i = 0; i < nb_ops; i++) {
      26                 :          0 :                 struct rte_crypto_asym_op *asym_op = ops[i]->asym;
      27                 :            : 
      28                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
      29                 :          0 :                 asym_op->modex.base.data = options->modex_data->base.data;
      30                 :          0 :                 asym_op->modex.base.length = options->modex_data->base.len;
      31                 :          0 :                 asym_op->modex.result.data = options->modex_data->result.data;
      32                 :          0 :                 asym_op->modex.result.length = options->modex_data->result.len;
      33                 :            :                 rte_crypto_op_attach_asym_session(ops[i], sess);
      34                 :            :         }
      35                 :          0 : }
      36                 :            : 
      37                 :            : static void
      38                 :          0 : cperf_set_ops_asym_rsa(struct rte_crypto_op **ops,
      39                 :            :                    uint32_t src_buf_offset __rte_unused,
      40                 :            :                    uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
      41                 :            :                    void *sess,
      42                 :            :                    const struct cperf_options *options,
      43                 :            :                    const struct cperf_test_vector *test_vector __rte_unused,
      44                 :            :                    uint16_t iv_offset __rte_unused,
      45                 :            :                    uint32_t *imix_idx __rte_unused,
      46                 :            :                    uint64_t *tsc_start __rte_unused)
      47                 :            : {
      48                 :          0 :         uint8_t crypto_buf[CRYPTO_BUF_SIZE] = {0};
      49                 :            :         uint16_t i;
      50                 :            : 
      51                 :          0 :         for (i = 0; i < nb_ops; i++) {
      52                 :          0 :                 struct rte_crypto_asym_op *asym_op = ops[i]->asym;
      53                 :            : 
      54                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
      55                 :          0 :                 asym_op->rsa.op_type = options->asym_op_type;
      56                 :          0 :                 if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
      57                 :          0 :                         asym_op->rsa.message.data = rsa_plaintext.data;
      58                 :          0 :                         asym_op->rsa.message.length = rsa_plaintext.len;
      59                 :          0 :                         asym_op->rsa.sign.data = crypto_buf;
      60                 :          0 :                         asym_op->rsa.sign.length = options->rsa_data->n.length;
      61                 :          0 :                 } else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_ENCRYPT) {
      62                 :          0 :                         asym_op->rsa.message.data = rsa_plaintext.data;
      63                 :          0 :                         asym_op->rsa.message.length = rsa_plaintext.len;
      64                 :          0 :                         asym_op->rsa.cipher.data = crypto_buf;
      65                 :          0 :                         asym_op->rsa.cipher.length = options->rsa_data->n.length;
      66                 :          0 :                 } else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_DECRYPT) {
      67                 :          0 :                         asym_op->rsa.cipher.data = options->rsa_data->cipher.data;
      68                 :          0 :                         asym_op->rsa.cipher.length = options->rsa_data->cipher.length;
      69                 :          0 :                         asym_op->rsa.message.data = crypto_buf;
      70                 :          0 :                         asym_op->rsa.message.length = options->rsa_data->n.length;
      71                 :          0 :                 } else if (options->asym_op_type == RTE_CRYPTO_ASYM_OP_VERIFY) {
      72                 :          0 :                         memcpy(crypto_buf, options->rsa_data->sign.data,
      73                 :          0 :                                 options->rsa_data->sign.length);
      74                 :          0 :                         asym_op->rsa.sign.data = crypto_buf;
      75                 :          0 :                         asym_op->rsa.sign.length = options->rsa_data->sign.length;
      76                 :          0 :                         asym_op->rsa.message.data = rsa_plaintext.data;
      77                 :          0 :                         asym_op->rsa.message.length = rsa_plaintext.len;
      78                 :            :                 } else {
      79                 :          0 :                         rte_panic("Unsupported RSA operation type %d\n",
      80                 :            :                                   options->asym_op_type);
      81                 :            :                 }
      82                 :            :                 rte_crypto_op_attach_asym_session(ops[i], sess);
      83                 :            :         }
      84                 :          0 : }
      85                 :            : 
      86                 :            : static void
      87                 :          0 : cperf_set_ops_asym_ecdsa(struct rte_crypto_op **ops,
      88                 :            :                    uint32_t src_buf_offset __rte_unused,
      89                 :            :                    uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
      90                 :            :                    void *sess,
      91                 :            :                    const struct cperf_options *options,
      92                 :            :                    const struct cperf_test_vector *test_vector __rte_unused,
      93                 :            :                    uint16_t iv_offset __rte_unused,
      94                 :            :                    uint32_t *imix_idx __rte_unused,
      95                 :            :                    uint64_t *tsc_start __rte_unused)
      96                 :            : {
      97                 :            :         uint16_t i;
      98                 :            : 
      99                 :          0 :         for (i = 0; i < nb_ops; i++) {
     100                 :          0 :                 struct rte_crypto_asym_op *asym_op = ops[i]->asym;
     101                 :            : 
     102                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     103                 :            :                 rte_crypto_op_attach_asym_session(ops[i], sess);
     104                 :            : 
     105                 :          0 :                 asym_op->ecdsa.op_type = options->asym_op_type;
     106                 :          0 :                 asym_op->ecdsa.message.data = options->secp256r1_data->message.data;
     107                 :          0 :                 asym_op->ecdsa.message.length = options->secp256r1_data->message.length;
     108                 :            : 
     109                 :          0 :                 asym_op->ecdsa.k.data = options->secp256r1_data->k.data;
     110                 :          0 :                 asym_op->ecdsa.k.length = options->secp256r1_data->k.length;
     111                 :            : 
     112                 :          0 :                 asym_op->ecdsa.r.data = options->secp256r1_data->sign_r.data;
     113                 :          0 :                 asym_op->ecdsa.r.length = options->secp256r1_data->sign_r.length;
     114                 :          0 :                 asym_op->ecdsa.s.data = options->secp256r1_data->sign_s.data;
     115                 :          0 :                 asym_op->ecdsa.s.length = options->secp256r1_data->sign_s.length;
     116                 :            :         }
     117                 :          0 : }
     118                 :            : 
     119                 :            : static void
     120                 :          0 : cperf_set_ops_asym_eddsa(struct rte_crypto_op **ops,
     121                 :            :                    uint32_t src_buf_offset __rte_unused,
     122                 :            :                    uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
     123                 :            :                    void *sess,
     124                 :            :                    const struct cperf_options *options,
     125                 :            :                    const struct cperf_test_vector *test_vector __rte_unused,
     126                 :            :                    uint16_t iv_offset __rte_unused,
     127                 :            :                    uint32_t *imix_idx __rte_unused,
     128                 :            :                    uint64_t *tsc_start __rte_unused)
     129                 :            : {
     130                 :            :         uint16_t i;
     131                 :            : 
     132                 :          0 :         for (i = 0; i < nb_ops; i++) {
     133                 :          0 :                 struct rte_crypto_asym_op *asym_op = ops[i]->asym;
     134                 :            : 
     135                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     136                 :            :                 rte_crypto_op_attach_asym_session(ops[i], sess);
     137                 :            : 
     138                 :          0 :                 asym_op->eddsa.op_type = options->asym_op_type;
     139                 :          0 :                 asym_op->eddsa.message.data = options->eddsa_data->message.data;
     140                 :          0 :                 asym_op->eddsa.message.length = options->eddsa_data->message.length;
     141                 :            : 
     142                 :          0 :                 asym_op->eddsa.instance = options->eddsa_data->instance;
     143                 :            : 
     144                 :          0 :                 asym_op->eddsa.sign.data = options->eddsa_data->sign.data;
     145                 :          0 :                 asym_op->eddsa.sign.length = options->eddsa_data->sign.length;
     146                 :            :         }
     147                 :          0 : }
     148                 :            : 
     149                 :            : static void
     150                 :          0 : cperf_set_ops_asym_sm2(struct rte_crypto_op **ops,
     151                 :            :                    uint32_t src_buf_offset __rte_unused,
     152                 :            :                    uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops,
     153                 :            :                    void *sess,
     154                 :            :                    const struct cperf_options *options,
     155                 :            :                    const struct cperf_test_vector *test_vector __rte_unused,
     156                 :            :                    uint16_t iv_offset __rte_unused,
     157                 :            :                    uint32_t *imix_idx __rte_unused,
     158                 :            :                    uint64_t *tsc_start __rte_unused)
     159                 :            : {
     160                 :            :         uint16_t i;
     161                 :            : 
     162                 :          0 :         for (i = 0; i < nb_ops; i++) {
     163                 :          0 :                 struct rte_crypto_asym_op *asym_op = ops[i]->asym;
     164                 :            : 
     165                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     166                 :            :                 rte_crypto_op_attach_asym_session(ops[i], sess);
     167                 :            : 
     168                 :            :                 /* Populate op with operational details */
     169                 :          0 :                 asym_op->sm2.hash = options->asym_hash_alg;
     170                 :            : 
     171                 :          0 :                 asym_op->sm2.op_type = options->asym_op_type;
     172                 :          0 :                 asym_op->sm2.message.data = options->sm2_data->message.data;
     173                 :          0 :                 asym_op->sm2.message.length = options->sm2_data->message.length;
     174                 :          0 :                 asym_op->sm2.cipher.data = options->sm2_data->cipher.data;
     175                 :          0 :                 asym_op->sm2.cipher.length = options->sm2_data->cipher.length;
     176                 :          0 :                 asym_op->sm2.id.data = options->sm2_data->id.data;
     177                 :          0 :                 asym_op->sm2.id.length = options->sm2_data->id.length;
     178                 :            : 
     179                 :          0 :                 asym_op->sm2.k.data = options->sm2_data->k.data;
     180                 :          0 :                 asym_op->sm2.k.length = options->sm2_data->k.length;
     181                 :            : 
     182                 :          0 :                 asym_op->sm2.r.data = options->sm2_data->sign_r.data;
     183                 :          0 :                 asym_op->sm2.r.length = options->sm2_data->sign_r.length;
     184                 :          0 :                 asym_op->sm2.s.data = options->sm2_data->sign_s.data;
     185                 :          0 :                 asym_op->sm2.s.length = options->sm2_data->sign_s.length;
     186                 :            :         }
     187                 :          0 : }
     188                 :            : 
     189                 :            : 
     190                 :            : #ifdef RTE_LIB_SECURITY
     191                 :            : static void
     192                 :          0 : test_ipsec_vec_populate(struct rte_mbuf *m, const struct cperf_options *options,
     193                 :            :                         const struct cperf_test_vector *test_vector)
     194                 :            : {
     195                 :          0 :         struct rte_ipv4_hdr *ip = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *);
     196                 :            : 
     197                 :          0 :         if (options->is_outbound) {
     198                 :          0 :                 memcpy(ip, test_vector->plaintext.data, sizeof(struct rte_ipv4_hdr));
     199                 :          0 :                 ip->total_length = rte_cpu_to_be_16(m->pkt_len);
     200                 :            :         }
     201                 :          0 : }
     202                 :            : 
     203                 :            : static void
     204                 :          0 : cperf_set_ops_security(struct rte_crypto_op **ops,
     205                 :            :                 uint32_t src_buf_offset __rte_unused,
     206                 :            :                 uint32_t dst_buf_offset __rte_unused,
     207                 :            :                 uint16_t nb_ops, void *sess,
     208                 :            :                 const struct cperf_options *options,
     209                 :            :                 const struct cperf_test_vector *test_vector,
     210                 :            :                 uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
     211                 :            :                 uint64_t *tsc_start)
     212                 :            : {
     213                 :            :         uint16_t i;
     214                 :            : 
     215                 :          0 :         for (i = 0; i < nb_ops; i++) {
     216                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     217                 :            :                 uint32_t buf_sz;
     218                 :            : 
     219                 :          0 :                 uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ops[i],
     220                 :            :                                         uint32_t *, iv_offset);
     221                 :          0 :                 *per_pkt_hfn = options->pdcp_ses_hfn_en ? 0 : PDCP_DEFAULT_HFN;
     222                 :            : 
     223                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     224                 :            :                 rte_security_attach_session(ops[i], sess);
     225                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     226                 :            :                                                         src_buf_offset);
     227                 :            : 
     228                 :          0 :                 if (options->op_type == CPERF_PDCP) {
     229                 :          0 :                         sym_op->m_src->buf_len = options->segment_sz;
     230                 :          0 :                         sym_op->m_src->data_len = options->test_buffer_size;
     231                 :          0 :                         sym_op->m_src->pkt_len = sym_op->m_src->data_len;
     232                 :            :                 }
     233                 :            : 
     234                 :          0 :                 if (options->op_type == CPERF_DOCSIS) {
     235                 :          0 :                         if (options->imix_distribution_count) {
     236                 :          0 :                                 buf_sz = options->imix_buffer_sizes[*imix_idx];
     237                 :          0 :                                 *imix_idx = (*imix_idx + 1) % options->pool_sz;
     238                 :            :                         } else
     239                 :          0 :                                 buf_sz = options->test_buffer_size;
     240                 :            : 
     241                 :          0 :                         sym_op->m_src->buf_len = options->segment_sz;
     242                 :          0 :                         sym_op->m_src->data_len = buf_sz;
     243                 :          0 :                         sym_op->m_src->pkt_len = buf_sz;
     244                 :            : 
     245                 :            :                         /* DOCSIS header is not CRC'ed */
     246                 :          0 :                         sym_op->auth.data.offset = options->docsis_hdr_sz;
     247                 :          0 :                         sym_op->auth.data.length = buf_sz -
     248                 :          0 :                                 sym_op->auth.data.offset - RTE_ETHER_CRC_LEN;
     249                 :            :                         /*
     250                 :            :                          * DOCSIS header and SRC and DST MAC addresses are not
     251                 :            :                          * ciphered
     252                 :            :                          */
     253                 :          0 :                         sym_op->cipher.data.offset = sym_op->auth.data.offset +
     254                 :          0 :                                 RTE_ETHER_HDR_LEN - RTE_ETHER_TYPE_LEN;
     255                 :          0 :                         sym_op->cipher.data.length = buf_sz -
     256                 :            :                                 sym_op->cipher.data.offset;
     257                 :            :                 }
     258                 :            : 
     259                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     260                 :          0 :                 if (dst_buf_offset == 0)
     261                 :          0 :                         sym_op->m_dst = NULL;
     262                 :            :                 else
     263                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     264                 :            :                                                         dst_buf_offset);
     265                 :            :         }
     266                 :            : 
     267                 :            :         RTE_SET_USED(tsc_start);
     268                 :            :         RTE_SET_USED(test_vector);
     269                 :          0 : }
     270                 :            : 
     271                 :            : static void
     272                 :          0 : cperf_set_ops_security_ipsec(struct rte_crypto_op **ops,
     273                 :            :                 uint32_t src_buf_offset __rte_unused,
     274                 :            :                 uint32_t dst_buf_offset __rte_unused,
     275                 :            :                 uint16_t nb_ops, void *sess,
     276                 :            :                 const struct cperf_options *options,
     277                 :            :                 const struct cperf_test_vector *test_vector,
     278                 :            :                 uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
     279                 :            :                 uint64_t *tsc_start)
     280                 :            : {
     281                 :          0 :         const uint32_t test_buffer_size = options->test_buffer_size;
     282                 :            :         uint64_t tsc_start_temp, tsc_end_temp;
     283                 :            :         uint16_t i = 0;
     284                 :            : 
     285                 :            :         RTE_SET_USED(imix_idx);
     286                 :            : 
     287                 :          0 :         for (i = 0; i < nb_ops; i++) {
     288                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     289                 :          0 :                 struct rte_mbuf *m = sym_op->m_src;
     290                 :            :                 uint32_t offset = test_buffer_size;
     291                 :            : 
     292                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     293                 :            :                 rte_security_attach_session(ops[i], sess);
     294                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + src_buf_offset);
     295                 :          0 :                 sym_op->m_src->pkt_len = test_buffer_size;
     296                 :            : 
     297                 :          0 :                 while ((m->next != NULL) && (offset >= m->data_len)) {
     298                 :          0 :                         offset -= m->data_len;
     299                 :            :                         m = m->next;
     300                 :            :                 }
     301                 :          0 :                 m->data_len = offset;
     302                 :            :                 /*
     303                 :            :                  * If there is not enough room in segment,
     304                 :            :                  * place the digest in the next segment
     305                 :            :                  */
     306                 :          0 :                 if (rte_pktmbuf_tailroom(m) < options->digest_sz) {
     307                 :            :                         m = m->next;
     308                 :            :                         offset = 0;
     309                 :            :                 }
     310                 :          0 :                 m->next = NULL;
     311                 :            : 
     312                 :          0 :                 sym_op->m_dst = NULL;
     313                 :            :         }
     314                 :            : 
     315                 :          0 :         if (options->test_file != NULL)
     316                 :            :                 return;
     317                 :            : 
     318                 :            :         tsc_start_temp = rte_rdtsc_precise();
     319                 :            : 
     320                 :          0 :         for (i = 0; i < nb_ops; i++) {
     321                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     322                 :          0 :                 struct rte_mbuf *m = sym_op->m_src;
     323                 :            : 
     324                 :          0 :                 test_ipsec_vec_populate(m, options, test_vector);
     325                 :            :         }
     326                 :            : 
     327                 :            :         tsc_end_temp = rte_rdtsc_precise();
     328                 :          0 :         *tsc_start += tsc_end_temp - tsc_start_temp;
     329                 :            : }
     330                 :            : 
     331                 :            : static void
     332                 :          0 : cperf_set_ops_security_tls(struct rte_crypto_op **ops,
     333                 :            :                 uint32_t src_buf_offset __rte_unused,
     334                 :            :                 uint32_t dst_buf_offset __rte_unused,
     335                 :            :                 uint16_t nb_ops, void *sess,
     336                 :            :                 const struct cperf_options *options,
     337                 :            :                 const struct cperf_test_vector *test_vector,
     338                 :            :                 uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
     339                 :            :                 uint64_t *tsc_start)
     340                 :            : {
     341                 :          0 :         const uint32_t test_buffer_size = options->test_buffer_size;
     342                 :            :         uint16_t i = 0;
     343                 :            : 
     344                 :            :         RTE_SET_USED(imix_idx);
     345                 :            :         RTE_SET_USED(tsc_start);
     346                 :            :         RTE_SET_USED(test_vector);
     347                 :            : 
     348                 :          0 :         for (i = 0; i < nb_ops; i++) {
     349                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     350                 :          0 :                 struct rte_mbuf *m = sym_op->m_src;
     351                 :            :                 uint32_t offset = test_buffer_size;
     352                 :            : 
     353                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     354                 :          0 :                 ops[i]->param1.tls_record.content_type = 0x17;
     355                 :            :                 rte_security_attach_session(ops[i], sess);
     356                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + src_buf_offset);
     357                 :          0 :                 sym_op->m_src->pkt_len = test_buffer_size;
     358                 :            : 
     359                 :          0 :                 while ((m->next != NULL) && (offset >= m->data_len)) {
     360                 :          0 :                         offset -= m->data_len;
     361                 :            :                         m = m->next;
     362                 :            :                 }
     363                 :          0 :                 m->data_len = offset;
     364                 :            :                 /*
     365                 :            :                  * If there is not enough room in segment,
     366                 :            :                  * place the digest in the next segment
     367                 :            :                  */
     368                 :          0 :                 if ((rte_pktmbuf_tailroom(m)) < options->digest_sz) {
     369                 :            :                         m = m->next;
     370                 :          0 :                         m->data_len = 0;
     371                 :            :                 }
     372                 :          0 :                 m->next = NULL;
     373                 :            : 
     374                 :          0 :                 sym_op->m_dst = NULL;
     375                 :            :         }
     376                 :          0 : }
     377                 :            : #endif
     378                 :            : 
     379                 :            : static void
     380                 :          0 : cperf_set_ops_null_cipher(struct rte_crypto_op **ops,
     381                 :            :                 uint32_t src_buf_offset, uint32_t dst_buf_offset,
     382                 :            :                 uint16_t nb_ops, void *sess,
     383                 :            :                 const struct cperf_options *options,
     384                 :            :                 const struct cperf_test_vector *test_vector __rte_unused,
     385                 :            :                 uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
     386                 :            :                 uint64_t *tsc_start __rte_unused)
     387                 :            : {
     388                 :            :         uint16_t i;
     389                 :            : 
     390                 :          0 :         for (i = 0; i < nb_ops; i++) {
     391                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     392                 :            : 
     393                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     394                 :            :                 rte_crypto_op_attach_sym_session(ops[i], sess);
     395                 :            : 
     396                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     397                 :            :                                                         src_buf_offset);
     398                 :            : 
     399                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     400                 :          0 :                 if (dst_buf_offset == 0)
     401                 :          0 :                         sym_op->m_dst = NULL;
     402                 :            :                 else
     403                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     404                 :            :                                                         dst_buf_offset);
     405                 :            : 
     406                 :            :                 /* cipher parameters */
     407                 :          0 :                 if (options->imix_distribution_count) {
     408                 :          0 :                         sym_op->cipher.data.length =
     409                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     410                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     411                 :            :                 } else
     412                 :          0 :                         sym_op->cipher.data.length = options->test_buffer_size;
     413                 :          0 :                 sym_op->cipher.data.offset = 0;
     414                 :            :         }
     415                 :          0 : }
     416                 :            : 
     417                 :            : static void
     418                 :          0 : cperf_set_ops_null_auth(struct rte_crypto_op **ops,
     419                 :            :                 uint32_t src_buf_offset, uint32_t dst_buf_offset,
     420                 :            :                 uint16_t nb_ops, void *sess,
     421                 :            :                 const struct cperf_options *options,
     422                 :            :                 const struct cperf_test_vector *test_vector __rte_unused,
     423                 :            :                 uint16_t iv_offset __rte_unused, uint32_t *imix_idx,
     424                 :            :                 uint64_t *tsc_start __rte_unused)
     425                 :            : {
     426                 :            :         uint16_t i;
     427                 :            : 
     428                 :          0 :         for (i = 0; i < nb_ops; i++) {
     429                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     430                 :            : 
     431                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     432                 :            :                 rte_crypto_op_attach_sym_session(ops[i], sess);
     433                 :            : 
     434                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     435                 :            :                                                         src_buf_offset);
     436                 :            : 
     437                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     438                 :          0 :                 if (dst_buf_offset == 0)
     439                 :          0 :                         sym_op->m_dst = NULL;
     440                 :            :                 else
     441                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     442                 :            :                                                         dst_buf_offset);
     443                 :            : 
     444                 :            :                 /* auth parameters */
     445                 :          0 :                 if (options->imix_distribution_count) {
     446                 :          0 :                         sym_op->auth.data.length =
     447                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     448                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     449                 :            :                 } else
     450                 :          0 :                         sym_op->auth.data.length = options->test_buffer_size;
     451                 :          0 :                 sym_op->auth.data.offset = 0;
     452                 :            :         }
     453                 :          0 : }
     454                 :            : 
     455                 :            : static void
     456                 :          0 : cperf_set_ops_cipher(struct rte_crypto_op **ops,
     457                 :            :                 uint32_t src_buf_offset, uint32_t dst_buf_offset,
     458                 :            :                 uint16_t nb_ops, void *sess,
     459                 :            :                 const struct cperf_options *options,
     460                 :            :                 const struct cperf_test_vector *test_vector,
     461                 :            :                 uint16_t iv_offset, uint32_t *imix_idx,
     462                 :            :                 uint64_t *tsc_start __rte_unused)
     463                 :            : {
     464                 :            :         uint16_t i;
     465                 :            : 
     466                 :          0 :         for (i = 0; i < nb_ops; i++) {
     467                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     468                 :            : 
     469                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     470                 :            :                 rte_crypto_op_attach_sym_session(ops[i], sess);
     471                 :            : 
     472                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     473                 :            :                                                         src_buf_offset);
     474                 :            : 
     475                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     476                 :          0 :                 if (dst_buf_offset == 0)
     477                 :          0 :                         sym_op->m_dst = NULL;
     478                 :            :                 else
     479                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     480                 :            :                                                         dst_buf_offset);
     481                 :            : 
     482                 :            :                 /* cipher parameters */
     483                 :          0 :                 if (options->imix_distribution_count) {
     484                 :          0 :                         sym_op->cipher.data.length =
     485                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     486                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     487                 :            :                 } else
     488                 :          0 :                         sym_op->cipher.data.length = options->test_buffer_size;
     489                 :            : 
     490                 :          0 :                 if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
     491                 :          0 :                                 options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
     492                 :            :                                 options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)
     493                 :          0 :                         sym_op->cipher.data.length <<= 3;
     494                 :            : 
     495                 :          0 :                 sym_op->cipher.data.offset = 0;
     496                 :            :         }
     497                 :            : 
     498                 :          0 :         if (options->test == CPERF_TEST_TYPE_VERIFY) {
     499                 :          0 :                 for (i = 0; i < nb_ops; i++) {
     500                 :          0 :                         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
     501                 :            :                                         uint8_t *, iv_offset);
     502                 :            : 
     503                 :          0 :                         memcpy(iv_ptr, test_vector->cipher_iv.data,
     504                 :          0 :                                         test_vector->cipher_iv.length);
     505                 :            : 
     506                 :            :                 }
     507                 :            :         }
     508                 :          0 : }
     509                 :            : 
     510                 :            : static void
     511                 :          0 : cperf_set_ops_auth(struct rte_crypto_op **ops,
     512                 :            :                 uint32_t src_buf_offset, uint32_t dst_buf_offset,
     513                 :            :                 uint16_t nb_ops, void *sess,
     514                 :            :                 const struct cperf_options *options,
     515                 :            :                 const struct cperf_test_vector *test_vector,
     516                 :            :                 uint16_t iv_offset, uint32_t *imix_idx,
     517                 :            :                 uint64_t *tsc_start __rte_unused)
     518                 :            : {
     519                 :            :         uint16_t i;
     520                 :            : 
     521                 :          0 :         for (i = 0; i < nb_ops; i++) {
     522                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     523                 :            : 
     524                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     525                 :            :                 rte_crypto_op_attach_sym_session(ops[i], sess);
     526                 :            : 
     527                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     528                 :            :                                                         src_buf_offset);
     529                 :            : 
     530                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     531                 :          0 :                 if (dst_buf_offset == 0)
     532                 :          0 :                         sym_op->m_dst = NULL;
     533                 :            :                 else
     534                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     535                 :            :                                                         dst_buf_offset);
     536                 :            : 
     537                 :          0 :                 if (test_vector->auth_iv.length) {
     538                 :          0 :                         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
     539                 :            :                                                                 uint8_t *,
     540                 :            :                                                                 iv_offset);
     541                 :          0 :                         memcpy(iv_ptr, test_vector->auth_iv.data,
     542                 :            :                                         test_vector->auth_iv.length);
     543                 :            :                 }
     544                 :            : 
     545                 :            :                 /* authentication parameters */
     546                 :          0 :                 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
     547                 :          0 :                         sym_op->auth.digest.data = test_vector->digest.data;
     548                 :          0 :                         sym_op->auth.digest.phys_addr =
     549                 :          0 :                                         test_vector->digest.phys_addr;
     550                 :            :                 } else {
     551                 :            : 
     552                 :          0 :                         uint32_t offset = options->test_buffer_size;
     553                 :            :                         struct rte_mbuf *buf, *tbuf;
     554                 :            : 
     555                 :          0 :                         if (options->out_of_place) {
     556                 :          0 :                                 buf = sym_op->m_dst;
     557                 :            :                         } else {
     558                 :          0 :                                 tbuf = sym_op->m_src;
     559                 :          0 :                                 while ((tbuf->next != NULL) &&
     560                 :          0 :                                                 (offset >= tbuf->data_len)) {
     561                 :          0 :                                         offset -= tbuf->data_len;
     562                 :            :                                         tbuf = tbuf->next;
     563                 :            :                                 }
     564                 :            :                                 /*
     565                 :            :                                  * If there is not enough room in segment,
     566                 :            :                                  * place the digest in the next segment
     567                 :            :                                  */
     568                 :          0 :                                 if ((tbuf->data_len - offset) < options->digest_sz) {
     569                 :            :                                         tbuf = tbuf->next;
     570                 :            :                                         offset = 0;
     571                 :            :                                 }
     572                 :            :                                 buf = tbuf;
     573                 :            :                         }
     574                 :            : 
     575                 :          0 :                         sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
     576                 :            :                                         uint8_t *, offset);
     577                 :          0 :                         sym_op->auth.digest.phys_addr =
     578                 :          0 :                                         rte_pktmbuf_iova_offset(buf, offset);
     579                 :            : 
     580                 :            :                 }
     581                 :            : 
     582                 :          0 :                 if (options->imix_distribution_count) {
     583                 :          0 :                         sym_op->auth.data.length =
     584                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     585                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     586                 :            :                 } else
     587                 :          0 :                         sym_op->auth.data.length = options->test_buffer_size;
     588                 :            : 
     589                 :          0 :                 if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
     590                 :          0 :                                 options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
     591                 :            :                                 options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3)
     592                 :          0 :                         sym_op->auth.data.length <<= 3;
     593                 :            : 
     594                 :          0 :                 sym_op->auth.data.offset = 0;
     595                 :            :         }
     596                 :            : 
     597                 :          0 :         if (options->test == CPERF_TEST_TYPE_VERIFY) {
     598                 :          0 :                 if (test_vector->auth_iv.length) {
     599                 :          0 :                         for (i = 0; i < nb_ops; i++) {
     600                 :          0 :                                 uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
     601                 :            :                                                 uint8_t *, iv_offset);
     602                 :            : 
     603                 :          0 :                                 memcpy(iv_ptr, test_vector->auth_iv.data,
     604                 :          0 :                                                 test_vector->auth_iv.length);
     605                 :            :                         }
     606                 :            :                 }
     607                 :            :         }
     608                 :          0 : }
     609                 :            : 
     610                 :            : static void
     611                 :          0 : cperf_set_ops_cipher_auth(struct rte_crypto_op **ops,
     612                 :            :                 uint32_t src_buf_offset, uint32_t dst_buf_offset,
     613                 :            :                 uint16_t nb_ops, void *sess,
     614                 :            :                 const struct cperf_options *options,
     615                 :            :                 const struct cperf_test_vector *test_vector,
     616                 :            :                 uint16_t iv_offset, uint32_t *imix_idx,
     617                 :            :                 uint64_t *tsc_start __rte_unused)
     618                 :            : {
     619                 :            :         uint16_t i;
     620                 :            : 
     621                 :          0 :         for (i = 0; i < nb_ops; i++) {
     622                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     623                 :            : 
     624                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     625                 :            :                 rte_crypto_op_attach_sym_session(ops[i], sess);
     626                 :            : 
     627                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     628                 :            :                                                         src_buf_offset);
     629                 :            : 
     630                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     631                 :          0 :                 if (dst_buf_offset == 0)
     632                 :          0 :                         sym_op->m_dst = NULL;
     633                 :            :                 else
     634                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     635                 :            :                                                         dst_buf_offset);
     636                 :            : 
     637                 :            :                 /* cipher parameters */
     638                 :          0 :                 if (options->imix_distribution_count) {
     639                 :          0 :                         sym_op->cipher.data.length =
     640                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     641                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     642                 :            :                 } else
     643                 :          0 :                         sym_op->cipher.data.length = options->test_buffer_size;
     644                 :            : 
     645                 :          0 :                 if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) &&
     646                 :          0 :                                 (options->op_type == CPERF_AUTH_THEN_CIPHER))
     647                 :          0 :                         sym_op->cipher.data.length += options->digest_sz;
     648                 :            : 
     649                 :          0 :                 if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 ||
     650                 :          0 :                                 options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 ||
     651                 :            :                                 options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3)
     652                 :          0 :                         sym_op->cipher.data.length <<= 3;
     653                 :            : 
     654                 :          0 :                 sym_op->cipher.data.offset = 0;
     655                 :            : 
     656                 :            :                 /* authentication parameters */
     657                 :          0 :                 if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) {
     658                 :          0 :                         sym_op->auth.digest.data = test_vector->digest.data;
     659                 :          0 :                         sym_op->auth.digest.phys_addr =
     660                 :          0 :                                         test_vector->digest.phys_addr;
     661                 :            :                 } else {
     662                 :            : 
     663                 :          0 :                         uint32_t offset = options->test_buffer_size;
     664                 :            :                         struct rte_mbuf *buf, *tbuf;
     665                 :            : 
     666                 :          0 :                         if (options->out_of_place) {
     667                 :          0 :                                 buf = sym_op->m_dst;
     668                 :            :                         } else {
     669                 :            :                                 tbuf = sym_op->m_src;
     670                 :          0 :                                 while ((tbuf->next != NULL) &&
     671                 :          0 :                                                 (offset >= tbuf->data_len)) {
     672                 :          0 :                                         offset -= tbuf->data_len;
     673                 :            :                                         tbuf = tbuf->next;
     674                 :            :                                 }
     675                 :            :                                 /*
     676                 :            :                                  * If there is not enough room in segment,
     677                 :            :                                  * place the digest in the next segment
     678                 :            :                                  */
     679                 :          0 :                                 if ((tbuf->data_len - offset) < options->digest_sz) {
     680                 :            :                                         tbuf = tbuf->next;
     681                 :            :                                         offset = 0;
     682                 :            :                                 }
     683                 :            :                                 buf = tbuf;
     684                 :            :                         }
     685                 :            : 
     686                 :          0 :                         sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf,
     687                 :            :                                         uint8_t *, offset);
     688                 :          0 :                         sym_op->auth.digest.phys_addr =
     689                 :          0 :                                         rte_pktmbuf_iova_offset(buf, offset);
     690                 :            :                 }
     691                 :            : 
     692                 :          0 :                 if (options->imix_distribution_count) {
     693                 :          0 :                         sym_op->auth.data.length =
     694                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     695                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     696                 :            :                 } else
     697                 :          0 :                         sym_op->auth.data.length = options->test_buffer_size;
     698                 :            : 
     699                 :          0 :                 if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 ||
     700                 :          0 :                                 options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 ||
     701                 :            :                                 options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3)
     702                 :          0 :                         sym_op->auth.data.length <<= 3;
     703                 :            : 
     704                 :          0 :                 sym_op->auth.data.offset = 0;
     705                 :            :         }
     706                 :            : 
     707                 :          0 :         if (options->test == CPERF_TEST_TYPE_VERIFY) {
     708                 :          0 :                 for (i = 0; i < nb_ops; i++) {
     709                 :          0 :                         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
     710                 :            :                                         uint8_t *, iv_offset);
     711                 :            : 
     712                 :          0 :                         memcpy(iv_ptr, test_vector->cipher_iv.data,
     713                 :          0 :                                         test_vector->cipher_iv.length);
     714                 :          0 :                         if (test_vector->auth_iv.length) {
     715                 :            :                                 /*
     716                 :            :                                  * Copy IV after the crypto operation and
     717                 :            :                                  * the cipher IV
     718                 :            :                                  */
     719                 :          0 :                                 iv_ptr += test_vector->cipher_iv.length;
     720                 :          0 :                                 memcpy(iv_ptr, test_vector->auth_iv.data,
     721                 :            :                                                 test_vector->auth_iv.length);
     722                 :            :                         }
     723                 :            :                 }
     724                 :            : 
     725                 :            :         }
     726                 :          0 : }
     727                 :            : 
     728                 :            : static void
     729                 :          0 : cperf_set_ops_aead(struct rte_crypto_op **ops,
     730                 :            :                 uint32_t src_buf_offset, uint32_t dst_buf_offset,
     731                 :            :                 uint16_t nb_ops, void *sess,
     732                 :            :                 const struct cperf_options *options,
     733                 :            :                 const struct cperf_test_vector *test_vector,
     734                 :            :                 uint16_t iv_offset, uint32_t *imix_idx,
     735                 :            :                 uint64_t *tsc_start __rte_unused)
     736                 :            : {
     737                 :            :         uint16_t i;
     738                 :            :         /* AAD is placed after the IV */
     739                 :          0 :         uint16_t aad_offset = iv_offset +
     740                 :          0 :                         ((options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) ?
     741                 :          0 :                         RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16) :
     742                 :            :                         test_vector->aead_iv.length);
     743                 :            : 
     744                 :          0 :         for (i = 0; i < nb_ops; i++) {
     745                 :          0 :                 struct rte_crypto_sym_op *sym_op = ops[i]->sym;
     746                 :            : 
     747                 :          0 :                 ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED;
     748                 :            :                 rte_crypto_op_attach_sym_session(ops[i], sess);
     749                 :            : 
     750                 :          0 :                 sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] +
     751                 :            :                                                         src_buf_offset);
     752                 :            : 
     753                 :            :                 /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */
     754                 :          0 :                 if (dst_buf_offset == 0)
     755                 :          0 :                         sym_op->m_dst = NULL;
     756                 :            :                 else
     757                 :          0 :                         sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] +
     758                 :            :                                                         dst_buf_offset);
     759                 :            : 
     760                 :            :                 /* AEAD parameters */
     761                 :          0 :                 if (options->imix_distribution_count) {
     762                 :          0 :                         sym_op->aead.data.length =
     763                 :          0 :                                 options->imix_buffer_sizes[*imix_idx];
     764                 :          0 :                         *imix_idx = (*imix_idx + 1) % options->pool_sz;
     765                 :            :                 } else
     766                 :          0 :                         sym_op->aead.data.length = options->test_buffer_size;
     767                 :          0 :                 sym_op->aead.data.offset = 0;
     768                 :            : 
     769                 :          0 :                 sym_op->aead.aad.data = rte_crypto_op_ctod_offset(ops[i],
     770                 :            :                                         uint8_t *, aad_offset);
     771                 :          0 :                 sym_op->aead.aad.phys_addr = rte_crypto_op_ctophys_offset(ops[i],
     772                 :            :                                         aad_offset);
     773                 :            : 
     774                 :          0 :                 if (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT) {
     775                 :          0 :                         sym_op->aead.digest.data = test_vector->digest.data;
     776                 :          0 :                         sym_op->aead.digest.phys_addr =
     777                 :          0 :                                         test_vector->digest.phys_addr;
     778                 :            :                 } else {
     779                 :            : 
     780                 :          0 :                         uint32_t offset = sym_op->aead.data.length +
     781                 :            :                                                 sym_op->aead.data.offset;
     782                 :            :                         struct rte_mbuf *buf, *tbuf;
     783                 :            : 
     784                 :          0 :                         if (options->out_of_place) {
     785                 :          0 :                                 buf = sym_op->m_dst;
     786                 :            :                         } else {
     787                 :            :                                 tbuf = sym_op->m_src;
     788                 :          0 :                                 while ((tbuf->next != NULL) &&
     789                 :          0 :                                                 (offset >= tbuf->data_len)) {
     790                 :          0 :                                         offset -= tbuf->data_len;
     791                 :            :                                         tbuf = tbuf->next;
     792                 :            :                                 }
     793                 :            :                                 /*
     794                 :            :                                  * If there is not enough room in segment,
     795                 :            :                                  * place the digest in the next segment
     796                 :            :                                  */
     797                 :          0 :                                 if ((tbuf->data_len - offset) < options->digest_sz) {
     798                 :            :                                         tbuf = tbuf->next;
     799                 :            :                                         offset = 0;
     800                 :            :                                 }
     801                 :            :                                 buf = tbuf;
     802                 :            :                         }
     803                 :            : 
     804                 :          0 :                         sym_op->aead.digest.data = rte_pktmbuf_mtod_offset(buf,
     805                 :            :                                         uint8_t *, offset);
     806                 :          0 :                         sym_op->aead.digest.phys_addr =
     807                 :          0 :                                         rte_pktmbuf_iova_offset(buf, offset);
     808                 :            :                 }
     809                 :            :         }
     810                 :            : 
     811                 :          0 :         if ((options->test == CPERF_TEST_TYPE_VERIFY) ||
     812                 :          0 :             (options->test == CPERF_TEST_TYPE_LATENCY) ||
     813                 :          0 :             (options->test == CPERF_TEST_TYPE_THROUGHPUT &&
     814                 :          0 :              (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT ||
     815                 :          0 :               options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT))) {
     816                 :          0 :                 for (i = 0; i < nb_ops; i++) {
     817                 :          0 :                         uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i],
     818                 :            :                                         uint8_t *, iv_offset);
     819                 :            : 
     820                 :            :                         /*
     821                 :            :                          * If doing AES-CCM, nonce is copied one byte
     822                 :            :                          * after the start of IV field, and AAD is copied
     823                 :            :                          * 18 bytes after the start of the AAD field.
     824                 :            :                          */
     825                 :          0 :                         if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) {
     826                 :          0 :                                 memcpy(iv_ptr + 1, test_vector->aead_iv.data,
     827                 :          0 :                                         test_vector->aead_iv.length);
     828                 :            : 
     829                 :          0 :                                 memcpy(ops[i]->sym->aead.aad.data + 18,
     830                 :          0 :                                         test_vector->aad.data,
     831                 :          0 :                                         test_vector->aad.length);
     832                 :            :                         } else {
     833                 :          0 :                                 memcpy(iv_ptr, test_vector->aead_iv.data,
     834                 :          0 :                                         test_vector->aead_iv.length);
     835                 :            : 
     836                 :          0 :                                 memcpy(ops[i]->sym->aead.aad.data,
     837                 :          0 :                                         test_vector->aad.data,
     838                 :          0 :                                         test_vector->aad.length);
     839                 :            :                         }
     840                 :            :                 }
     841                 :            :         }
     842                 :          0 : }
     843                 :            : 
     844                 :            : static void *
     845                 :          0 : create_ipsec_session(struct rte_mempool *sess_mp,
     846                 :            :                 uint8_t dev_id,
     847                 :            :                 const struct cperf_options *options,
     848                 :            :                 const struct cperf_test_vector *test_vector,
     849                 :            :                 uint16_t iv_offset)
     850                 :            : {
     851                 :          0 :         struct rte_crypto_sym_xform auth_xform = {0};
     852                 :            :         struct rte_crypto_sym_xform *crypto_xform;
     853                 :          0 :         struct rte_crypto_sym_xform xform = {0};
     854                 :            : 
     855                 :          0 :         if (options->aead_algo != 0) {
     856                 :            :                 /* Setup AEAD Parameters */
     857                 :          0 :                 xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
     858                 :            :                 xform.next = NULL;
     859                 :          0 :                 xform.aead.algo = options->aead_algo;
     860                 :          0 :                 xform.aead.op = options->aead_op;
     861                 :          0 :                 xform.aead.iv.offset = iv_offset;
     862                 :          0 :                 xform.aead.key.data = test_vector->aead_key.data;
     863                 :          0 :                 xform.aead.key.length = test_vector->aead_key.length;
     864                 :          0 :                 xform.aead.iv.length = test_vector->aead_iv.length;
     865                 :          0 :                 xform.aead.digest_length = options->digest_sz;
     866                 :          0 :                 xform.aead.aad_length = options->aead_aad_sz;
     867                 :            :                 crypto_xform = &xform;
     868                 :          0 :         } else if (options->cipher_algo != 0 && options->auth_algo != 0) {
     869                 :            :                 /* Setup Cipher Parameters */
     870                 :          0 :                 xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
     871                 :          0 :                 xform.cipher.algo = options->cipher_algo;
     872                 :          0 :                 xform.cipher.op = options->cipher_op;
     873                 :          0 :                 xform.cipher.iv.offset = iv_offset;
     874                 :          0 :                 xform.cipher.iv.length = test_vector->cipher_iv.length;
     875                 :            :                 /* cipher different than null */
     876                 :          0 :                 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
     877                 :          0 :                         xform.cipher.key.data = test_vector->cipher_key.data;
     878                 :          0 :                         xform.cipher.key.length =
     879                 :          0 :                                 test_vector->cipher_key.length;
     880                 :            :                 } else {
     881                 :            :                         xform.cipher.key.data = NULL;
     882                 :            :                         xform.cipher.key.length = 0;
     883                 :            :                 }
     884                 :            : 
     885                 :            :                 /* Setup Auth Parameters */
     886                 :          0 :                 auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
     887                 :          0 :                 auth_xform.auth.algo = options->auth_algo;
     888                 :          0 :                 auth_xform.auth.op = options->auth_op;
     889                 :          0 :                 auth_xform.auth.iv.offset = iv_offset +
     890                 :            :                                 xform.cipher.iv.length;
     891                 :            :                 /* auth different than null */
     892                 :          0 :                 if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
     893                 :          0 :                         auth_xform.auth.digest_length = options->digest_sz;
     894                 :          0 :                         auth_xform.auth.key.length =
     895                 :          0 :                                                 test_vector->auth_key.length;
     896                 :          0 :                         auth_xform.auth.key.data = test_vector->auth_key.data;
     897                 :          0 :                         auth_xform.auth.iv.length = test_vector->auth_iv.length;
     898                 :            :                 } else {
     899                 :            :                         auth_xform.auth.digest_length = 0;
     900                 :            :                         auth_xform.auth.key.length = 0;
     901                 :            :                         auth_xform.auth.key.data = NULL;
     902                 :            :                         auth_xform.auth.iv.length = 0;
     903                 :            :                 }
     904                 :            : 
     905                 :          0 :                 if (options->is_outbound) {
     906                 :            :                         crypto_xform = &xform;
     907                 :          0 :                         xform.next = &auth_xform;
     908                 :            :                         auth_xform.next = NULL;
     909                 :            :                 } else {
     910                 :            :                         crypto_xform = &auth_xform;
     911                 :          0 :                         auth_xform.next = &xform;
     912                 :            :                         xform.next = NULL;
     913                 :            :                 }
     914                 :            :         } else {
     915                 :            :                 return NULL;
     916                 :            :         }
     917                 :            : 
     918                 :            : #define CPERF_IPSEC_SRC_IP      0x01010101
     919                 :            : #define CPERF_IPSEC_DST_IP      0x02020202
     920                 :            : #define CPERF_IPSEC_SALT        0x0
     921                 :            : #define CPERF_IPSEC_DEFTTL      64
     922                 :          0 :         struct rte_security_ipsec_tunnel_param tunnel = {
     923                 :            :                 .type = RTE_SECURITY_IPSEC_TUNNEL_IPV4,
     924                 :            :                 {.ipv4 = {
     925                 :            :                         .src_ip = { .s_addr = CPERF_IPSEC_SRC_IP},
     926                 :            :                         .dst_ip = { .s_addr = CPERF_IPSEC_DST_IP},
     927                 :            :                         .dscp = 0,
     928                 :            :                         .df = 0,
     929                 :            :                         .ttl = CPERF_IPSEC_DEFTTL,
     930                 :            :                 } },
     931                 :            :         };
     932                 :          0 :         struct rte_security_session_conf sess_conf = {
     933                 :            :                 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
     934                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     935                 :            :                 {.ipsec = {
     936                 :          0 :                         .spi = rte_lcore_id() + 1,
     937                 :            :                         /**< For testing sake, lcore_id is taken as SPI so that
     938                 :            :                          * for every core a different session is created.
     939                 :            :                          */
     940                 :            :                         .salt = CPERF_IPSEC_SALT,
     941                 :            :                         .options = { 0 },
     942                 :            :                         .replay_win_sz = 0,
     943                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     944                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
     945                 :            :                         .tunnel = tunnel,
     946                 :            :                 } },
     947                 :            :                 .userdata = NULL,
     948                 :            :                 .crypto_xform = crypto_xform,
     949                 :            :         };
     950                 :            : 
     951                 :          0 :         if (options->is_outbound)
     952                 :            :                 sess_conf.ipsec.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS;
     953                 :            :         else
     954                 :          0 :                 sess_conf.ipsec.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS;
     955                 :            : 
     956                 :          0 :         void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
     957                 :            : 
     958                 :            :         /* Create security session */
     959                 :          0 :         return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
     960                 :            : }
     961                 :            : 
     962                 :            : static void *
     963                 :          0 : create_tls_session(struct rte_mempool *sess_mp,
     964                 :            :                 uint8_t dev_id,
     965                 :            :                 const struct cperf_options *options,
     966                 :            :                 const struct cperf_test_vector *test_vector,
     967                 :            :                 uint16_t iv_offset)
     968                 :            : {
     969                 :          0 :         struct rte_crypto_sym_xform auth_xform = {0};
     970                 :            :         struct rte_crypto_sym_xform *crypto_xform;
     971                 :          0 :         struct rte_crypto_sym_xform xform = {0};
     972                 :            : 
     973                 :          0 :         if (options->aead_algo != 0) {
     974                 :            :                 /* Setup AEAD Parameters */
     975                 :          0 :                 xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
     976                 :            :                 xform.next = NULL;
     977                 :          0 :                 xform.aead.algo = options->aead_algo;
     978                 :          0 :                 xform.aead.op = options->aead_op;
     979                 :          0 :                 xform.aead.iv.offset = iv_offset;
     980                 :          0 :                 xform.aead.key.data = test_vector->aead_key.data;
     981                 :          0 :                 xform.aead.key.length = test_vector->aead_key.length;
     982                 :          0 :                 xform.aead.iv.length = test_vector->aead_iv.length;
     983                 :          0 :                 xform.aead.digest_length = options->digest_sz;
     984                 :          0 :                 xform.aead.aad_length = options->aead_aad_sz;
     985                 :            :                 crypto_xform = &xform;
     986                 :          0 :         } else if (options->cipher_algo != 0 && options->auth_algo != 0) {
     987                 :            :                 /* Setup Cipher Parameters */
     988                 :          0 :                 xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
     989                 :          0 :                 xform.cipher.algo = options->cipher_algo;
     990                 :          0 :                 xform.cipher.op = options->cipher_op;
     991                 :          0 :                 xform.cipher.iv.offset = iv_offset;
     992                 :          0 :                 xform.cipher.iv.length = test_vector->cipher_iv.length;
     993                 :            :                 /* cipher different than null */
     994                 :          0 :                 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
     995                 :          0 :                         xform.cipher.key.data = test_vector->cipher_key.data;
     996                 :          0 :                         xform.cipher.key.length = test_vector->cipher_key.length;
     997                 :            :                 } else {
     998                 :            :                         xform.cipher.key.data = NULL;
     999                 :            :                         xform.cipher.key.length = 0;
    1000                 :            :                 }
    1001                 :            : 
    1002                 :            :                 /* Setup Auth Parameters */
    1003                 :          0 :                 auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1004                 :          0 :                 auth_xform.auth.algo = options->auth_algo;
    1005                 :          0 :                 auth_xform.auth.op = options->auth_op;
    1006                 :          0 :                 auth_xform.auth.iv.offset = iv_offset + xform.cipher.iv.length;
    1007                 :            :                 /* auth different than null */
    1008                 :          0 :                 if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
    1009                 :          0 :                         auth_xform.auth.digest_length = options->digest_sz;
    1010                 :          0 :                         auth_xform.auth.key.length = test_vector->auth_key.length;
    1011                 :          0 :                         auth_xform.auth.key.data = test_vector->auth_key.data;
    1012                 :          0 :                         auth_xform.auth.iv.length = test_vector->auth_iv.length;
    1013                 :            :                 } else {
    1014                 :            :                         auth_xform.auth.digest_length = 0;
    1015                 :            :                         auth_xform.auth.key.length = 0;
    1016                 :            :                         auth_xform.auth.key.data = NULL;
    1017                 :            :                         auth_xform.auth.iv.length = 0;
    1018                 :            :                 }
    1019                 :            : 
    1020                 :          0 :                 if (options->is_outbound) {
    1021                 :            :                         /* Currently supporting AUTH then Encrypt mode only for TLS. */
    1022                 :            :                         crypto_xform = &auth_xform;
    1023                 :          0 :                         auth_xform.next = &xform;
    1024                 :            :                         xform.next = NULL;
    1025                 :            :                 } else {
    1026                 :            :                         crypto_xform = &xform;
    1027                 :          0 :                         xform.next = &auth_xform;
    1028                 :            :                         auth_xform.next = NULL;
    1029                 :            :                 }
    1030                 :            :         } else {
    1031                 :            :                 return NULL;
    1032                 :            :         }
    1033                 :            : 
    1034                 :            :         struct rte_security_tls_record_sess_options opts = {
    1035                 :            :                 .iv_gen_disable = 0,
    1036                 :            :                 .extra_padding_enable = 0,
    1037                 :            :         };
    1038                 :          0 :         struct rte_security_session_conf sess_conf = {
    1039                 :            :                 .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
    1040                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD,
    1041                 :            :                 {.tls_record = {
    1042                 :            :                         .ver = RTE_SECURITY_VERSION_TLS_1_2,
    1043                 :            :                         .options = opts,
    1044                 :            :                 } },
    1045                 :            :                 .userdata = NULL,
    1046                 :            :                 .crypto_xform = crypto_xform,
    1047                 :            :         };
    1048                 :          0 :         if (options->tls_version)
    1049                 :          0 :                 sess_conf.tls_record.ver = options->tls_version;
    1050                 :            : 
    1051                 :          0 :         if (options->is_outbound)
    1052                 :          0 :                 sess_conf.tls_record.type = RTE_SECURITY_TLS_SESS_TYPE_WRITE;
    1053                 :            :         else
    1054                 :            :                 sess_conf.tls_record.type = RTE_SECURITY_TLS_SESS_TYPE_READ;
    1055                 :            : 
    1056                 :          0 :         void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
    1057                 :            : 
    1058                 :            :         /* Create security session */
    1059                 :          0 :         return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
    1060                 :            : }
    1061                 :            : 
    1062                 :            : static void *
    1063                 :          0 : cperf_create_session(struct rte_mempool *sess_mp,
    1064                 :            :         uint8_t dev_id,
    1065                 :            :         const struct cperf_options *options,
    1066                 :            :         const struct cperf_test_vector *test_vector,
    1067                 :            :         uint16_t iv_offset)
    1068                 :            : {
    1069                 :            :         struct rte_crypto_sym_xform cipher_xform;
    1070                 :            :         struct rte_crypto_sym_xform auth_xform;
    1071                 :            :         struct rte_crypto_sym_xform aead_xform;
    1072                 :            :         void *sess = NULL;
    1073                 :          0 :         void *asym_sess = NULL;
    1074                 :          0 :         struct rte_crypto_asym_xform xform = {0};
    1075                 :            :         int ret;
    1076                 :            : 
    1077                 :          0 :         if (options->op_type == CPERF_ASYM_MODEX) {
    1078                 :            :                 xform.next = NULL;
    1079                 :          0 :                 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX;
    1080                 :          0 :                 xform.modex.modulus.data = options->modex_data->modulus.data;
    1081                 :          0 :                 xform.modex.modulus.length = options->modex_data->modulus.len;
    1082                 :          0 :                 xform.modex.exponent.data = options->modex_data->exponent.data;
    1083                 :          0 :                 xform.modex.exponent.length = options->modex_data->exponent.len;
    1084                 :            : 
    1085                 :          0 :                 ret = rte_cryptodev_asym_session_create(dev_id, &xform,
    1086                 :            :                                 sess_mp, &asym_sess);
    1087                 :          0 :                 if (ret < 0) {
    1088                 :          0 :                         RTE_LOG(ERR, USER1, "Asym session create failed\n");
    1089                 :          0 :                         return NULL;
    1090                 :            :                 }
    1091                 :          0 :                 return asym_sess;
    1092                 :            :         }
    1093                 :            : 
    1094                 :            :         if (options->op_type == CPERF_ASYM_RSA) {
    1095                 :            :                 xform.next = NULL;
    1096                 :          0 :                 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_RSA;
    1097                 :          0 :                 xform.rsa.padding.type = options->rsa_data->padding;
    1098                 :          0 :                 xform.rsa.n.data = options->rsa_data->n.data;
    1099                 :          0 :                 xform.rsa.n.length = options->rsa_data->n.length;
    1100                 :          0 :                 xform.rsa.e.data = options->rsa_data->e.data;
    1101                 :          0 :                 xform.rsa.e.length = options->rsa_data->e.length;
    1102                 :          0 :                 xform.rsa.d.data = options->rsa_data->d.data;
    1103                 :          0 :                 xform.rsa.d.length = options->rsa_data->d.length;
    1104                 :          0 :                 xform.rsa.key_type = options->rsa_data->key_type;
    1105                 :          0 :                 if (xform.rsa.key_type == RTE_RSA_KEY_TYPE_QT) {
    1106                 :          0 :                         xform.rsa.qt.p.data = options->rsa_data->p.data;
    1107                 :          0 :                         xform.rsa.qt.p.length = options->rsa_data->p.length;
    1108                 :          0 :                         xform.rsa.qt.q.data = options->rsa_data->q.data;
    1109                 :          0 :                         xform.rsa.qt.q.length = options->rsa_data->q.length;
    1110                 :          0 :                         xform.rsa.qt.dP.data = options->rsa_data->dp.data;
    1111                 :          0 :                         xform.rsa.qt.dP.length = options->rsa_data->dp.length;
    1112                 :          0 :                         xform.rsa.qt.dQ.data = options->rsa_data->dq.data;
    1113                 :          0 :                         xform.rsa.qt.dQ.length = options->rsa_data->dq.length;
    1114                 :          0 :                         xform.rsa.qt.qInv.data = options->rsa_data->qinv.data;
    1115                 :          0 :                         xform.rsa.qt.qInv.length = options->rsa_data->qinv.length;
    1116                 :            :                 }
    1117                 :          0 :                 ret = rte_cryptodev_asym_session_create(dev_id, &xform,
    1118                 :            :                                 sess_mp, &asym_sess);
    1119                 :          0 :                 if (ret < 0) {
    1120                 :          0 :                         RTE_LOG(ERR, USER1, "Asym session create failed\n");
    1121                 :          0 :                         return NULL;
    1122                 :            :                 }
    1123                 :          0 :                 return asym_sess;
    1124                 :            :         }
    1125                 :            : 
    1126                 :            :         if (options->op_type == CPERF_ASYM_SECP256R1) {
    1127                 :            :                 xform.next = NULL;
    1128                 :          0 :                 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA;
    1129                 :          0 :                 xform.ec.curve_id = options->secp256r1_data->curve;
    1130                 :          0 :                 xform.ec.pkey.data = options->secp256r1_data->pkey.data;
    1131                 :          0 :                 xform.ec.pkey.length = options->secp256r1_data->pkey.length;
    1132                 :          0 :                 xform.ec.q.x.data = options->secp256r1_data->pubkey_qx.data;
    1133                 :          0 :                 xform.ec.q.x.length = options->secp256r1_data->pubkey_qx.length;
    1134                 :          0 :                 xform.ec.q.y.data = options->secp256r1_data->pubkey_qy.data;
    1135                 :          0 :                 xform.ec.q.y.length = options->secp256r1_data->pubkey_qy.length;
    1136                 :            : 
    1137                 :          0 :                 ret = rte_cryptodev_asym_session_create(dev_id, &xform,
    1138                 :            :                                 sess_mp, &asym_sess);
    1139                 :          0 :                 if (ret < 0) {
    1140                 :          0 :                         RTE_LOG(ERR, USER1, "ECDSA Asym session create failed\n");
    1141                 :          0 :                         return NULL;
    1142                 :            :                 }
    1143                 :            : 
    1144                 :          0 :                 return asym_sess;
    1145                 :            :         }
    1146                 :            : 
    1147                 :            :         if (options->op_type == CPERF_ASYM_ED25519) {
    1148                 :            :                 xform.next = NULL;
    1149                 :          0 :                 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA;
    1150                 :          0 :                 xform.ec.curve_id = options->eddsa_data->curve;
    1151                 :          0 :                 xform.ec.pkey.data = options->eddsa_data->pkey.data;
    1152                 :          0 :                 xform.ec.pkey.length = options->eddsa_data->pkey.length;
    1153                 :          0 :                 xform.ec.q.x.data = options->eddsa_data->pubkey.data;
    1154                 :          0 :                 xform.ec.q.x.length = options->eddsa_data->pubkey.length;
    1155                 :            : 
    1156                 :          0 :                 ret = rte_cryptodev_asym_session_create(dev_id, &xform,
    1157                 :            :                                 sess_mp, &asym_sess);
    1158                 :          0 :                 if (ret < 0) {
    1159                 :          0 :                         RTE_LOG(ERR, USER1, "EdDSA Asym session create failed\n");
    1160                 :          0 :                         return NULL;
    1161                 :            :                 }
    1162                 :            : 
    1163                 :          0 :                 return asym_sess;
    1164                 :            :         }
    1165                 :            : 
    1166                 :            :         if (options->op_type == CPERF_ASYM_SM2) {
    1167                 :            :                 xform.next = NULL;
    1168                 :          0 :                 xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2;
    1169                 :          0 :                 xform.ec.curve_id = options->sm2_data->curve;
    1170                 :          0 :                 xform.ec.pkey.data = options->sm2_data->pkey.data;
    1171                 :          0 :                 xform.ec.pkey.length = options->sm2_data->pkey.length;
    1172                 :          0 :                 xform.ec.q.x.data = options->sm2_data->pubkey_qx.data;
    1173                 :          0 :                 xform.ec.q.x.length = options->sm2_data->pubkey_qx.length;
    1174                 :          0 :                 xform.ec.q.y.data = options->sm2_data->pubkey_qy.data;
    1175                 :          0 :                 xform.ec.q.y.length = options->sm2_data->pubkey_qy.length;
    1176                 :            : 
    1177                 :          0 :                 ret = rte_cryptodev_asym_session_create(dev_id, &xform,
    1178                 :            :                                 sess_mp, &asym_sess);
    1179                 :          0 :                 if (ret < 0) {
    1180                 :          0 :                         RTE_LOG(ERR, USER1, "SM2 Asym session create failed\n");
    1181                 :          0 :                         return NULL;
    1182                 :            :                 }
    1183                 :            : 
    1184                 :          0 :                 return asym_sess;
    1185                 :            :         }
    1186                 :            : #ifdef RTE_LIB_SECURITY
    1187                 :            :         /*
    1188                 :            :          * security only
    1189                 :            :          */
    1190                 :            :         if (options->op_type == CPERF_PDCP) {
    1191                 :            :                 /* Setup Cipher Parameters */
    1192                 :          0 :                 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1193                 :          0 :                 cipher_xform.next = NULL;
    1194                 :          0 :                 cipher_xform.cipher.algo = options->cipher_algo;
    1195                 :          0 :                 cipher_xform.cipher.op = options->cipher_op;
    1196                 :          0 :                 cipher_xform.cipher.iv.offset = iv_offset;
    1197                 :          0 :                 cipher_xform.cipher.iv.length = 4;
    1198                 :            : 
    1199                 :            :                 /* cipher different than null */
    1200                 :          0 :                 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
    1201                 :          0 :                         cipher_xform.cipher.key.data = test_vector->cipher_key.data;
    1202                 :          0 :                         cipher_xform.cipher.key.length = test_vector->cipher_key.length;
    1203                 :            :                 } else {
    1204                 :          0 :                         cipher_xform.cipher.key.data = NULL;
    1205                 :          0 :                         cipher_xform.cipher.key.length = 0;
    1206                 :            :                 }
    1207                 :            : 
    1208                 :            :                 /* Setup Auth Parameters */
    1209                 :          0 :                 if (options->auth_algo != 0) {
    1210                 :          0 :                         auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1211                 :          0 :                         auth_xform.next = NULL;
    1212                 :          0 :                         auth_xform.auth.algo = options->auth_algo;
    1213                 :          0 :                         auth_xform.auth.op = options->auth_op;
    1214                 :          0 :                         auth_xform.auth.iv.offset = iv_offset +
    1215                 :            :                                 cipher_xform.cipher.iv.length;
    1216                 :            : 
    1217                 :            :                         /* auth different than null */
    1218                 :          0 :                         if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
    1219                 :          0 :                                 auth_xform.auth.digest_length = options->digest_sz;
    1220                 :          0 :                                 auth_xform.auth.key.length = test_vector->auth_key.length;
    1221                 :          0 :                                 auth_xform.auth.key.data = test_vector->auth_key.data;
    1222                 :          0 :                                 auth_xform.auth.iv.length = test_vector->auth_iv.length;
    1223                 :            :                         } else {
    1224                 :          0 :                                 auth_xform.auth.digest_length = 0;
    1225                 :          0 :                                 auth_xform.auth.key.length = 0;
    1226                 :          0 :                                 auth_xform.auth.key.data = NULL;
    1227                 :          0 :                                 auth_xform.auth.iv.length = 0;
    1228                 :            :                         }
    1229                 :            : 
    1230                 :          0 :                         cipher_xform.next = &auth_xform;
    1231                 :            :                 } else {
    1232                 :            :                         cipher_xform.next = NULL;
    1233                 :            :                 }
    1234                 :            : 
    1235                 :          0 :                 struct rte_security_session_conf sess_conf = {
    1236                 :            :                         .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
    1237                 :            :                         .protocol = RTE_SECURITY_PROTOCOL_PDCP,
    1238                 :            :                         {.pdcp = {
    1239                 :            :                                 .bearer = 0x16,
    1240                 :          0 :                                 .domain = options->pdcp_domain,
    1241                 :            :                                 .pkt_dir = 0,
    1242                 :          0 :                                 .sn_size = options->pdcp_sn_sz,
    1243                 :          0 :                                 .hfn = options->pdcp_ses_hfn_en ?
    1244                 :          0 :                                         PDCP_DEFAULT_HFN : 0,
    1245                 :            :                                 .hfn_threshold = 0x70C0A,
    1246                 :          0 :                                 .sdap_enabled = options->pdcp_sdap,
    1247                 :          0 :                                 .hfn_ovrd = !(options->pdcp_ses_hfn_en),
    1248                 :            :                         } },
    1249                 :            :                         .crypto_xform = &cipher_xform
    1250                 :            :                 };
    1251                 :            : 
    1252                 :          0 :                 void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
    1253                 :            : 
    1254                 :            :                 /* Create security session */
    1255                 :          0 :                 return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
    1256                 :            :         }
    1257                 :            : 
    1258                 :            :         if (options->op_type == CPERF_IPSEC) {
    1259                 :          0 :                 return create_ipsec_session(sess_mp, dev_id,
    1260                 :            :                                 options, test_vector, iv_offset);
    1261                 :            :         }
    1262                 :            : 
    1263                 :            :         if (options->op_type == CPERF_TLS) {
    1264                 :          0 :                 return create_tls_session(sess_mp, dev_id,
    1265                 :            :                                 options, test_vector, iv_offset);
    1266                 :            :         }
    1267                 :            : 
    1268                 :            :         if (options->op_type == CPERF_DOCSIS) {
    1269                 :            :                 enum rte_security_docsis_direction direction;
    1270                 :            : 
    1271                 :          0 :                 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1272                 :          0 :                 cipher_xform.next = NULL;
    1273                 :          0 :                 cipher_xform.cipher.algo = options->cipher_algo;
    1274                 :          0 :                 cipher_xform.cipher.op = options->cipher_op;
    1275                 :          0 :                 cipher_xform.cipher.iv.offset = iv_offset;
    1276                 :          0 :                 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
    1277                 :          0 :                         cipher_xform.cipher.key.data =
    1278                 :          0 :                                 test_vector->cipher_key.data;
    1279                 :          0 :                         cipher_xform.cipher.key.length =
    1280                 :          0 :                                 test_vector->cipher_key.length;
    1281                 :          0 :                         cipher_xform.cipher.iv.length =
    1282                 :          0 :                                 test_vector->cipher_iv.length;
    1283                 :            :                 } else {
    1284                 :          0 :                         cipher_xform.cipher.key.data = NULL;
    1285                 :          0 :                         cipher_xform.cipher.key.length = 0;
    1286                 :          0 :                         cipher_xform.cipher.iv.length = 0;
    1287                 :            :                 }
    1288                 :            :                 cipher_xform.next = NULL;
    1289                 :            : 
    1290                 :          0 :                 if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
    1291                 :            :                         direction = RTE_SECURITY_DOCSIS_DOWNLINK;
    1292                 :            :                 else
    1293                 :            :                         direction = RTE_SECURITY_DOCSIS_UPLINK;
    1294                 :            : 
    1295                 :          0 :                 struct rte_security_session_conf sess_conf = {
    1296                 :            :                         .action_type =
    1297                 :            :                                 RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL,
    1298                 :            :                         .protocol = RTE_SECURITY_PROTOCOL_DOCSIS,
    1299                 :            :                         {.docsis = {
    1300                 :            :                                 .direction = direction,
    1301                 :            :                         } },
    1302                 :            :                         .crypto_xform = &cipher_xform
    1303                 :            :                 };
    1304                 :          0 :                 void *ctx = rte_cryptodev_get_sec_ctx(dev_id);
    1305                 :            : 
    1306                 :            :                 /* Create security session */
    1307                 :          0 :                 return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
    1308                 :            :         }
    1309                 :            : #endif
    1310                 :            :         /*
    1311                 :            :          * cipher only
    1312                 :            :          */
    1313                 :            :         if (options->op_type == CPERF_CIPHER_ONLY) {
    1314                 :          0 :                 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1315                 :          0 :                 cipher_xform.next = NULL;
    1316                 :          0 :                 cipher_xform.cipher.algo = options->cipher_algo;
    1317                 :          0 :                 cipher_xform.cipher.op = options->cipher_op;
    1318                 :          0 :                 cipher_xform.cipher.iv.offset = iv_offset;
    1319                 :            : 
    1320                 :            :                 /* cipher different than null */
    1321                 :          0 :                 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
    1322                 :          0 :                         cipher_xform.cipher.key.data =
    1323                 :          0 :                                         test_vector->cipher_key.data;
    1324                 :          0 :                         cipher_xform.cipher.key.length =
    1325                 :          0 :                                         test_vector->cipher_key.length;
    1326                 :          0 :                         cipher_xform.cipher.iv.length =
    1327                 :          0 :                                         test_vector->cipher_iv.length;
    1328                 :            :                 } else {
    1329                 :          0 :                         cipher_xform.cipher.key.data = NULL;
    1330                 :          0 :                         cipher_xform.cipher.key.length = 0;
    1331                 :          0 :                         cipher_xform.cipher.iv.length = 0;
    1332                 :            :                 }
    1333                 :            :                 /* create crypto session */
    1334                 :          0 :                 sess = rte_cryptodev_sym_session_create(dev_id, &cipher_xform,
    1335                 :            :                                 sess_mp);
    1336                 :            :         /*
    1337                 :            :          *  auth only
    1338                 :            :          */
    1339                 :            :         } else if (options->op_type == CPERF_AUTH_ONLY) {
    1340                 :          0 :                 auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1341                 :          0 :                 auth_xform.next = NULL;
    1342                 :          0 :                 auth_xform.auth.algo = options->auth_algo;
    1343                 :          0 :                 auth_xform.auth.op = options->auth_op;
    1344                 :          0 :                 auth_xform.auth.iv.offset = iv_offset;
    1345                 :            : 
    1346                 :            :                 /* auth different than null */
    1347                 :          0 :                 if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
    1348                 :          0 :                         auth_xform.auth.digest_length =
    1349                 :          0 :                                         options->digest_sz;
    1350                 :          0 :                         auth_xform.auth.key.length =
    1351                 :          0 :                                         test_vector->auth_key.length;
    1352                 :          0 :                         auth_xform.auth.key.data = test_vector->auth_key.data;
    1353                 :          0 :                         auth_xform.auth.iv.length =
    1354                 :          0 :                                         test_vector->auth_iv.length;
    1355                 :            :                 } else {
    1356                 :          0 :                         auth_xform.auth.digest_length = 0;
    1357                 :          0 :                         auth_xform.auth.key.length = 0;
    1358                 :          0 :                         auth_xform.auth.key.data = NULL;
    1359                 :          0 :                         auth_xform.auth.iv.length = 0;
    1360                 :            :                 }
    1361                 :            :                 /* create crypto session */
    1362                 :          0 :                 sess = rte_cryptodev_sym_session_create(dev_id, &auth_xform,
    1363                 :            :                                 sess_mp);
    1364                 :            :         /*
    1365                 :            :          * cipher and auth
    1366                 :            :          */
    1367                 :            :         } else if (options->op_type == CPERF_CIPHER_THEN_AUTH
    1368                 :            :                         || options->op_type == CPERF_AUTH_THEN_CIPHER) {
    1369                 :            :                 /*
    1370                 :            :                  * cipher
    1371                 :            :                  */
    1372                 :          0 :                 cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER;
    1373                 :          0 :                 cipher_xform.next = NULL;
    1374                 :          0 :                 cipher_xform.cipher.algo = options->cipher_algo;
    1375                 :          0 :                 cipher_xform.cipher.op = options->cipher_op;
    1376                 :          0 :                 cipher_xform.cipher.iv.offset = iv_offset;
    1377                 :            : 
    1378                 :            :                 /* cipher different than null */
    1379                 :          0 :                 if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) {
    1380                 :          0 :                         cipher_xform.cipher.key.data =
    1381                 :          0 :                                         test_vector->cipher_key.data;
    1382                 :          0 :                         cipher_xform.cipher.key.length =
    1383                 :          0 :                                         test_vector->cipher_key.length;
    1384                 :          0 :                         cipher_xform.cipher.iv.length =
    1385                 :          0 :                                         test_vector->cipher_iv.length;
    1386                 :            :                 } else {
    1387                 :          0 :                         cipher_xform.cipher.key.data = NULL;
    1388                 :          0 :                         cipher_xform.cipher.key.length = 0;
    1389                 :          0 :                         cipher_xform.cipher.iv.length = 0;
    1390                 :            :                 }
    1391                 :            : 
    1392                 :            :                 /*
    1393                 :            :                  * auth
    1394                 :            :                  */
    1395                 :          0 :                 auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH;
    1396                 :          0 :                 auth_xform.next = NULL;
    1397                 :          0 :                 auth_xform.auth.algo = options->auth_algo;
    1398                 :          0 :                 auth_xform.auth.op = options->auth_op;
    1399                 :          0 :                 auth_xform.auth.iv.offset = iv_offset +
    1400                 :          0 :                         cipher_xform.cipher.iv.length;
    1401                 :            : 
    1402                 :            :                 /* auth different than null */
    1403                 :          0 :                 if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) {
    1404                 :          0 :                         auth_xform.auth.digest_length = options->digest_sz;
    1405                 :          0 :                         auth_xform.auth.iv.length = test_vector->auth_iv.length;
    1406                 :          0 :                         auth_xform.auth.key.length =
    1407                 :          0 :                                         test_vector->auth_key.length;
    1408                 :          0 :                         auth_xform.auth.key.data =
    1409                 :          0 :                                         test_vector->auth_key.data;
    1410                 :            :                 } else {
    1411                 :          0 :                         auth_xform.auth.digest_length = 0;
    1412                 :          0 :                         auth_xform.auth.key.length = 0;
    1413                 :          0 :                         auth_xform.auth.key.data = NULL;
    1414                 :          0 :                         auth_xform.auth.iv.length = 0;
    1415                 :            :                 }
    1416                 :            : 
    1417                 :            :                 /* cipher then auth */
    1418                 :          0 :                 if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
    1419                 :          0 :                         cipher_xform.next = &auth_xform;
    1420                 :            :                         /* create crypto session */
    1421                 :          0 :                         sess = rte_cryptodev_sym_session_create(dev_id,
    1422                 :            :                                         &cipher_xform, sess_mp);
    1423                 :            :                 } else { /* auth then cipher */
    1424                 :          0 :                         auth_xform.next = &cipher_xform;
    1425                 :            :                         /* create crypto session */
    1426                 :          0 :                         sess = rte_cryptodev_sym_session_create(dev_id,
    1427                 :            :                                         &auth_xform, sess_mp);
    1428                 :            :                 }
    1429                 :            :         } else { /* options->op_type == CPERF_AEAD */
    1430                 :          0 :                 aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
    1431                 :          0 :                 aead_xform.next = NULL;
    1432                 :          0 :                 aead_xform.aead.algo = options->aead_algo;
    1433                 :          0 :                 aead_xform.aead.op = options->aead_op;
    1434                 :          0 :                 aead_xform.aead.iv.offset = iv_offset;
    1435                 :            : 
    1436                 :          0 :                 aead_xform.aead.key.data =
    1437                 :          0 :                                         test_vector->aead_key.data;
    1438                 :          0 :                 aead_xform.aead.key.length =
    1439                 :          0 :                                         test_vector->aead_key.length;
    1440                 :          0 :                 aead_xform.aead.iv.length = test_vector->aead_iv.length;
    1441                 :            : 
    1442                 :          0 :                 aead_xform.aead.digest_length = options->digest_sz;
    1443                 :          0 :                 aead_xform.aead.aad_length =
    1444                 :          0 :                                         options->aead_aad_sz;
    1445                 :            : 
    1446                 :            :                 /* Create crypto session */
    1447                 :          0 :                 sess = rte_cryptodev_sym_session_create(dev_id, &aead_xform,
    1448                 :            :                                 sess_mp);
    1449                 :            :         }
    1450                 :            : 
    1451                 :            :         return sess;
    1452                 :            : }
    1453                 :            : 
    1454                 :            : int
    1455                 :          0 : cperf_get_op_functions(const struct cperf_options *options,
    1456                 :            :                 struct cperf_op_fns *op_fns)
    1457                 :            : {
    1458                 :            :         memset(op_fns, 0, sizeof(struct cperf_op_fns));
    1459                 :            : 
    1460                 :          0 :         op_fns->sess_create = cperf_create_session;
    1461                 :            : 
    1462                 :          0 :         switch (options->op_type) {
    1463                 :          0 :         case CPERF_AEAD:
    1464                 :          0 :                 op_fns->populate_ops = cperf_set_ops_aead;
    1465                 :          0 :                 break;
    1466                 :            : 
    1467                 :          0 :         case CPERF_AUTH_THEN_CIPHER:
    1468                 :            :         case CPERF_CIPHER_THEN_AUTH:
    1469                 :          0 :                 op_fns->populate_ops = cperf_set_ops_cipher_auth;
    1470                 :          0 :                 break;
    1471                 :          0 :         case CPERF_AUTH_ONLY:
    1472                 :          0 :                 if (options->auth_algo == RTE_CRYPTO_AUTH_NULL)
    1473                 :          0 :                         op_fns->populate_ops = cperf_set_ops_null_auth;
    1474                 :            :                 else
    1475                 :          0 :                         op_fns->populate_ops = cperf_set_ops_auth;
    1476                 :            :                 break;
    1477                 :          0 :         case CPERF_CIPHER_ONLY:
    1478                 :          0 :                 if (options->cipher_algo == RTE_CRYPTO_CIPHER_NULL)
    1479                 :          0 :                         op_fns->populate_ops = cperf_set_ops_null_cipher;
    1480                 :            :                 else
    1481                 :          0 :                         op_fns->populate_ops = cperf_set_ops_cipher;
    1482                 :            :                 break;
    1483                 :          0 :         case CPERF_ASYM_MODEX:
    1484                 :          0 :                 op_fns->populate_ops = cperf_set_ops_asym_modex;
    1485                 :          0 :                 break;
    1486                 :          0 :         case CPERF_ASYM_RSA:
    1487                 :          0 :                 op_fns->populate_ops = cperf_set_ops_asym_rsa;
    1488                 :          0 :                 break;
    1489                 :          0 :         case CPERF_ASYM_SECP256R1:
    1490                 :          0 :                 op_fns->populate_ops = cperf_set_ops_asym_ecdsa;
    1491                 :          0 :                 break;
    1492                 :          0 :         case CPERF_ASYM_ED25519:
    1493                 :          0 :                 op_fns->populate_ops = cperf_set_ops_asym_eddsa;
    1494                 :          0 :                 break;
    1495                 :          0 :         case CPERF_ASYM_SM2:
    1496                 :          0 :                 op_fns->populate_ops = cperf_set_ops_asym_sm2;
    1497                 :          0 :                 break;
    1498                 :            : #ifdef RTE_LIB_SECURITY
    1499                 :          0 :         case CPERF_PDCP:
    1500                 :            :         case CPERF_DOCSIS:
    1501                 :          0 :                 op_fns->populate_ops = cperf_set_ops_security;
    1502                 :          0 :                 break;
    1503                 :          0 :         case CPERF_IPSEC:
    1504                 :          0 :                 op_fns->populate_ops = cperf_set_ops_security_ipsec;
    1505                 :          0 :                 break;
    1506                 :          0 :         case CPERF_TLS:
    1507                 :          0 :                 op_fns->populate_ops = cperf_set_ops_security_tls;
    1508                 :          0 :                 break;
    1509                 :            : #endif
    1510                 :            :         default:
    1511                 :            :                 return -1;
    1512                 :            :         }
    1513                 :            : 
    1514                 :            :         return 0;
    1515                 :            : }

Generated by: LCOV version 1.14