1174a1631SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 2174a1631SBruce Richardson * Copyright(c) 2016-2017 Intel Corporation 3f8be1786SSlawomir Mrozowicz */ 4f8be1786SSlawomir Mrozowicz 5f8be1786SSlawomir Mrozowicz #include <rte_cryptodev.h> 6d4a131a9SDavid Coyle #include <rte_ether.h> 728dde5daSAkhil Goyal #include <rte_ip.h> 8f8be1786SSlawomir Mrozowicz 9f8be1786SSlawomir Mrozowicz #include "cperf_ops.h" 10f8be1786SSlawomir Mrozowicz #include "cperf_test_vectors.h" 11f8be1786SSlawomir Mrozowicz 12e7bd6977SAnoob Joseph static void 13b82742f9SAkhil Goyal cperf_set_ops_asym_modex(struct rte_crypto_op **ops, 14ba588ce3SKiran Kumar K uint32_t src_buf_offset __rte_unused, 15ba588ce3SKiran Kumar K uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops, 162a440d6aSAkhil Goyal void *sess, 17a538d1d2SKiran Kumar K const struct cperf_options *options, 18ba588ce3SKiran Kumar K const struct cperf_test_vector *test_vector __rte_unused, 19ba588ce3SKiran Kumar K uint16_t iv_offset __rte_unused, 2028dde5daSAkhil Goyal uint32_t *imix_idx __rte_unused, 2128dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 22ba588ce3SKiran Kumar K { 23ba588ce3SKiran Kumar K uint16_t i; 24ba588ce3SKiran Kumar K 25ba588ce3SKiran Kumar K for (i = 0; i < nb_ops; i++) { 26ba588ce3SKiran Kumar K struct rte_crypto_asym_op *asym_op = ops[i]->asym; 27ba588ce3SKiran Kumar K 28ba588ce3SKiran Kumar K ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 29a538d1d2SKiran Kumar K asym_op->modex.base.data = options->modex_data->base.data; 30a538d1d2SKiran Kumar K asym_op->modex.base.length = options->modex_data->base.len; 31a538d1d2SKiran Kumar K asym_op->modex.result.data = options->modex_data->result.data; 32a538d1d2SKiran Kumar K asym_op->modex.result.length = options->modex_data->result.len; 33766cac60SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(ops[i], sess); 34ba588ce3SKiran Kumar K } 35ba588ce3SKiran Kumar K } 36ba588ce3SKiran Kumar K 37b82742f9SAkhil Goyal static void 38195a271eSGowrishankar Muthukrishnan cperf_set_ops_asym_ecdsa(struct rte_crypto_op **ops, 39195a271eSGowrishankar Muthukrishnan uint32_t src_buf_offset __rte_unused, 40195a271eSGowrishankar Muthukrishnan uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops, 41195a271eSGowrishankar Muthukrishnan void *sess, 42195a271eSGowrishankar Muthukrishnan const struct cperf_options *options, 43195a271eSGowrishankar Muthukrishnan const struct cperf_test_vector *test_vector __rte_unused, 44195a271eSGowrishankar Muthukrishnan uint16_t iv_offset __rte_unused, 45195a271eSGowrishankar Muthukrishnan uint32_t *imix_idx __rte_unused, 46195a271eSGowrishankar Muthukrishnan uint64_t *tsc_start __rte_unused) 47195a271eSGowrishankar Muthukrishnan { 48195a271eSGowrishankar Muthukrishnan uint16_t i; 49195a271eSGowrishankar Muthukrishnan 50195a271eSGowrishankar Muthukrishnan for (i = 0; i < nb_ops; i++) { 51195a271eSGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op = ops[i]->asym; 52195a271eSGowrishankar Muthukrishnan 53195a271eSGowrishankar Muthukrishnan ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 54195a271eSGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(ops[i], sess); 55195a271eSGowrishankar Muthukrishnan 56195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.op_type = options->asym_op_type; 57195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.message.data = options->secp256r1_data->message.data; 58195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.message.length = options->secp256r1_data->message.length; 59195a271eSGowrishankar Muthukrishnan 60195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.k.data = options->secp256r1_data->k.data; 61195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.k.length = options->secp256r1_data->k.length; 62195a271eSGowrishankar Muthukrishnan 63195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.r.data = options->secp256r1_data->sign_r.data; 64195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.r.length = options->secp256r1_data->sign_r.length; 65195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.s.data = options->secp256r1_data->sign_s.data; 66195a271eSGowrishankar Muthukrishnan asym_op->ecdsa.s.length = options->secp256r1_data->sign_s.length; 67195a271eSGowrishankar Muthukrishnan } 68195a271eSGowrishankar Muthukrishnan } 69195a271eSGowrishankar Muthukrishnan 70195a271eSGowrishankar Muthukrishnan static void 71*981a1ed3SGowrishankar Muthukrishnan cperf_set_ops_asym_eddsa(struct rte_crypto_op **ops, 72*981a1ed3SGowrishankar Muthukrishnan uint32_t src_buf_offset __rte_unused, 73*981a1ed3SGowrishankar Muthukrishnan uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops, 74*981a1ed3SGowrishankar Muthukrishnan void *sess, 75*981a1ed3SGowrishankar Muthukrishnan const struct cperf_options *options, 76*981a1ed3SGowrishankar Muthukrishnan const struct cperf_test_vector *test_vector __rte_unused, 77*981a1ed3SGowrishankar Muthukrishnan uint16_t iv_offset __rte_unused, 78*981a1ed3SGowrishankar Muthukrishnan uint32_t *imix_idx __rte_unused, 79*981a1ed3SGowrishankar Muthukrishnan uint64_t *tsc_start __rte_unused) 80*981a1ed3SGowrishankar Muthukrishnan { 81*981a1ed3SGowrishankar Muthukrishnan uint16_t i; 82*981a1ed3SGowrishankar Muthukrishnan 83*981a1ed3SGowrishankar Muthukrishnan for (i = 0; i < nb_ops; i++) { 84*981a1ed3SGowrishankar Muthukrishnan struct rte_crypto_asym_op *asym_op = ops[i]->asym; 85*981a1ed3SGowrishankar Muthukrishnan 86*981a1ed3SGowrishankar Muthukrishnan ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 87*981a1ed3SGowrishankar Muthukrishnan rte_crypto_op_attach_asym_session(ops[i], sess); 88*981a1ed3SGowrishankar Muthukrishnan 89*981a1ed3SGowrishankar Muthukrishnan asym_op->eddsa.op_type = options->asym_op_type; 90*981a1ed3SGowrishankar Muthukrishnan asym_op->eddsa.message.data = options->eddsa_data->message.data; 91*981a1ed3SGowrishankar Muthukrishnan asym_op->eddsa.message.length = options->eddsa_data->message.length; 92*981a1ed3SGowrishankar Muthukrishnan 93*981a1ed3SGowrishankar Muthukrishnan asym_op->eddsa.instance = options->eddsa_data->instance; 94*981a1ed3SGowrishankar Muthukrishnan 95*981a1ed3SGowrishankar Muthukrishnan asym_op->eddsa.sign.data = options->eddsa_data->sign.data; 96*981a1ed3SGowrishankar Muthukrishnan asym_op->eddsa.sign.length = options->eddsa_data->sign.length; 97*981a1ed3SGowrishankar Muthukrishnan } 98*981a1ed3SGowrishankar Muthukrishnan } 99*981a1ed3SGowrishankar Muthukrishnan 100*981a1ed3SGowrishankar Muthukrishnan static void 101b82742f9SAkhil Goyal cperf_set_ops_asym_sm2(struct rte_crypto_op **ops, 102b82742f9SAkhil Goyal uint32_t src_buf_offset __rte_unused, 103b82742f9SAkhil Goyal uint32_t dst_buf_offset __rte_unused, uint16_t nb_ops, 104b82742f9SAkhil Goyal void *sess, 105b82742f9SAkhil Goyal const struct cperf_options *options, 106b82742f9SAkhil Goyal const struct cperf_test_vector *test_vector __rte_unused, 107b82742f9SAkhil Goyal uint16_t iv_offset __rte_unused, 108b82742f9SAkhil Goyal uint32_t *imix_idx __rte_unused, 109b82742f9SAkhil Goyal uint64_t *tsc_start __rte_unused) 110b82742f9SAkhil Goyal { 111b82742f9SAkhil Goyal uint16_t i; 112b82742f9SAkhil Goyal 113b82742f9SAkhil Goyal for (i = 0; i < nb_ops; i++) { 114b82742f9SAkhil Goyal struct rte_crypto_asym_op *asym_op = ops[i]->asym; 115b82742f9SAkhil Goyal 116b82742f9SAkhil Goyal ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 117b82742f9SAkhil Goyal rte_crypto_op_attach_asym_session(ops[i], sess); 118b82742f9SAkhil Goyal 119b82742f9SAkhil Goyal /* Populate op with operational details */ 120b82742f9SAkhil Goyal asym_op->sm2.hash = options->asym_hash_alg; 121b82742f9SAkhil Goyal 122b82742f9SAkhil Goyal asym_op->sm2.op_type = options->asym_op_type; 123b82742f9SAkhil Goyal asym_op->sm2.message.data = options->sm2_data->message.data; 124b82742f9SAkhil Goyal asym_op->sm2.message.length = options->sm2_data->message.length; 125b82742f9SAkhil Goyal asym_op->sm2.cipher.data = options->sm2_data->cipher.data; 126b82742f9SAkhil Goyal asym_op->sm2.cipher.length = options->sm2_data->cipher.length; 127b82742f9SAkhil Goyal asym_op->sm2.id.data = options->sm2_data->id.data; 128b82742f9SAkhil Goyal asym_op->sm2.id.length = options->sm2_data->id.length; 129b82742f9SAkhil Goyal 130b82742f9SAkhil Goyal asym_op->sm2.k.data = options->sm2_data->k.data; 131b82742f9SAkhil Goyal asym_op->sm2.k.length = options->sm2_data->k.length; 132b82742f9SAkhil Goyal 133b82742f9SAkhil Goyal asym_op->sm2.r.data = options->sm2_data->sign_r.data; 134b82742f9SAkhil Goyal asym_op->sm2.r.length = options->sm2_data->sign_r.length; 135b82742f9SAkhil Goyal asym_op->sm2.s.data = options->sm2_data->sign_s.data; 136b82742f9SAkhil Goyal asym_op->sm2.s.length = options->sm2_data->sign_s.length; 137b82742f9SAkhil Goyal } 138b82742f9SAkhil Goyal } 139b82742f9SAkhil Goyal 140b82742f9SAkhil Goyal 141a8d0d473SBruce Richardson #ifdef RTE_LIB_SECURITY 14228dde5daSAkhil Goyal static void 14328dde5daSAkhil Goyal test_ipsec_vec_populate(struct rte_mbuf *m, const struct cperf_options *options, 14428dde5daSAkhil Goyal const struct cperf_test_vector *test_vector) 14528dde5daSAkhil Goyal { 14628dde5daSAkhil Goyal struct rte_ipv4_hdr *ip = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *); 14728dde5daSAkhil Goyal 14821230400SAnoob Joseph if (options->is_outbound) { 149bcfeb919SAkhil Goyal memcpy(ip, test_vector->plaintext.data, sizeof(struct rte_ipv4_hdr)); 150bcfeb919SAkhil Goyal ip->total_length = rte_cpu_to_be_16(m->pkt_len); 15128dde5daSAkhil Goyal } 15228dde5daSAkhil Goyal } 15328dde5daSAkhil Goyal 154e7bd6977SAnoob Joseph static void 1558fd2b5a6SAkhil Goyal cperf_set_ops_security(struct rte_crypto_op **ops, 1568fd2b5a6SAkhil Goyal uint32_t src_buf_offset __rte_unused, 1578fd2b5a6SAkhil Goyal uint32_t dst_buf_offset __rte_unused, 1582a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 15928dde5daSAkhil Goyal const struct cperf_options *options, 16028dde5daSAkhil Goyal const struct cperf_test_vector *test_vector, 16128dde5daSAkhil Goyal uint16_t iv_offset __rte_unused, uint32_t *imix_idx, 16228dde5daSAkhil Goyal uint64_t *tsc_start) 1638fd2b5a6SAkhil Goyal { 1648fd2b5a6SAkhil Goyal uint16_t i; 1658fd2b5a6SAkhil Goyal 1668fd2b5a6SAkhil Goyal for (i = 0; i < nb_ops; i++) { 1678fd2b5a6SAkhil Goyal struct rte_crypto_sym_op *sym_op = ops[i]->sym; 168d4a131a9SDavid Coyle uint32_t buf_sz; 1698fd2b5a6SAkhil Goyal 1705a61bdb9SAkhil Goyal uint32_t *per_pkt_hfn = rte_crypto_op_ctod_offset(ops[i], 1715a61bdb9SAkhil Goyal uint32_t *, iv_offset); 1725a61bdb9SAkhil Goyal *per_pkt_hfn = options->pdcp_ses_hfn_en ? 0 : PDCP_DEFAULT_HFN; 1735a61bdb9SAkhil Goyal 1748fd2b5a6SAkhil Goyal ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 175766cac60SGowrishankar Muthukrishnan rte_security_attach_session(ops[i], sess); 1768fd2b5a6SAkhil Goyal sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 1778fd2b5a6SAkhil Goyal src_buf_offset); 178d4a131a9SDavid Coyle 179fa609d94SAnoob Joseph if (options->op_type == CPERF_PDCP) { 1808fd2b5a6SAkhil Goyal sym_op->m_src->buf_len = options->segment_sz; 1818fd2b5a6SAkhil Goyal sym_op->m_src->data_len = options->test_buffer_size; 1828fd2b5a6SAkhil Goyal sym_op->m_src->pkt_len = sym_op->m_src->data_len; 183d4a131a9SDavid Coyle } 184d4a131a9SDavid Coyle 185d4a131a9SDavid Coyle if (options->op_type == CPERF_DOCSIS) { 186d4a131a9SDavid Coyle if (options->imix_distribution_count) { 187d4a131a9SDavid Coyle buf_sz = options->imix_buffer_sizes[*imix_idx]; 188d4a131a9SDavid Coyle *imix_idx = (*imix_idx + 1) % options->pool_sz; 189d4a131a9SDavid Coyle } else 190d4a131a9SDavid Coyle buf_sz = options->test_buffer_size; 191d4a131a9SDavid Coyle 192f7d2c696SDavid Coyle sym_op->m_src->buf_len = options->segment_sz; 193f7d2c696SDavid Coyle sym_op->m_src->data_len = buf_sz; 194f7d2c696SDavid Coyle sym_op->m_src->pkt_len = buf_sz; 195f7d2c696SDavid Coyle 196d4a131a9SDavid Coyle /* DOCSIS header is not CRC'ed */ 197d4a131a9SDavid Coyle sym_op->auth.data.offset = options->docsis_hdr_sz; 198d4a131a9SDavid Coyle sym_op->auth.data.length = buf_sz - 199d4a131a9SDavid Coyle sym_op->auth.data.offset - RTE_ETHER_CRC_LEN; 200d4a131a9SDavid Coyle /* 201d4a131a9SDavid Coyle * DOCSIS header and SRC and DST MAC addresses are not 202d4a131a9SDavid Coyle * ciphered 203d4a131a9SDavid Coyle */ 204d4a131a9SDavid Coyle sym_op->cipher.data.offset = sym_op->auth.data.offset + 205d4a131a9SDavid Coyle RTE_ETHER_HDR_LEN - RTE_ETHER_TYPE_LEN; 206d4a131a9SDavid Coyle sym_op->cipher.data.length = buf_sz - 207d4a131a9SDavid Coyle sym_op->cipher.data.offset; 208d4a131a9SDavid Coyle } 2098fd2b5a6SAkhil Goyal 2108fd2b5a6SAkhil Goyal /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 2118fd2b5a6SAkhil Goyal if (dst_buf_offset == 0) 2128fd2b5a6SAkhil Goyal sym_op->m_dst = NULL; 2138fd2b5a6SAkhil Goyal else 2148fd2b5a6SAkhil Goyal sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 2158fd2b5a6SAkhil Goyal dst_buf_offset); 2168fd2b5a6SAkhil Goyal } 2178fd2b5a6SAkhil Goyal 218fa609d94SAnoob Joseph RTE_SET_USED(tsc_start); 219fa609d94SAnoob Joseph RTE_SET_USED(test_vector); 2208fd2b5a6SAkhil Goyal } 221fa609d94SAnoob Joseph 222e7bd6977SAnoob Joseph static void 223fa609d94SAnoob Joseph cperf_set_ops_security_ipsec(struct rte_crypto_op **ops, 224fa609d94SAnoob Joseph uint32_t src_buf_offset __rte_unused, 225fa609d94SAnoob Joseph uint32_t dst_buf_offset __rte_unused, 2262a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 227fa609d94SAnoob Joseph const struct cperf_options *options, 228fa609d94SAnoob Joseph const struct cperf_test_vector *test_vector, 229fa609d94SAnoob Joseph uint16_t iv_offset __rte_unused, uint32_t *imix_idx, 230fa609d94SAnoob Joseph uint64_t *tsc_start) 231fa609d94SAnoob Joseph { 232fa609d94SAnoob Joseph const uint32_t test_buffer_size = options->test_buffer_size; 233fa609d94SAnoob Joseph uint64_t tsc_start_temp, tsc_end_temp; 234fa609d94SAnoob Joseph uint16_t i = 0; 235fa609d94SAnoob Joseph 236fa609d94SAnoob Joseph RTE_SET_USED(imix_idx); 237fa609d94SAnoob Joseph 238fa609d94SAnoob Joseph for (i = 0; i < nb_ops; i++) { 239fa609d94SAnoob Joseph struct rte_crypto_sym_op *sym_op = ops[i]->sym; 240fa609d94SAnoob Joseph struct rte_mbuf *m = sym_op->m_src; 241bcfeb919SAkhil Goyal uint32_t offset = test_buffer_size; 242fa609d94SAnoob Joseph 243fa609d94SAnoob Joseph ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 244766cac60SGowrishankar Muthukrishnan rte_security_attach_session(ops[i], sess); 245bcfeb919SAkhil Goyal sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + src_buf_offset); 246bcfeb919SAkhil Goyal sym_op->m_src->pkt_len = test_buffer_size; 247fa609d94SAnoob Joseph 248bcfeb919SAkhil Goyal while ((m->next != NULL) && (offset >= m->data_len)) { 249bcfeb919SAkhil Goyal offset -= m->data_len; 250bcfeb919SAkhil Goyal m = m->next; 251bcfeb919SAkhil Goyal } 252bcfeb919SAkhil Goyal m->data_len = offset; 253bcfeb919SAkhil Goyal /* 254bcfeb919SAkhil Goyal * If there is not enough room in segment, 255bcfeb919SAkhil Goyal * place the digest in the next segment 256fa609d94SAnoob Joseph */ 257bcfeb919SAkhil Goyal if (rte_pktmbuf_tailroom(m) < options->digest_sz) { 258bcfeb919SAkhil Goyal m = m->next; 259bcfeb919SAkhil Goyal offset = 0; 260bcfeb919SAkhil Goyal } 261bcfeb919SAkhil Goyal m->next = NULL; 262fa609d94SAnoob Joseph 263fa609d94SAnoob Joseph sym_op->m_dst = NULL; 264fa609d94SAnoob Joseph } 265fa609d94SAnoob Joseph 266fa609d94SAnoob Joseph if (options->test_file != NULL) 267e7bd6977SAnoob Joseph return; 268fa609d94SAnoob Joseph 269fa609d94SAnoob Joseph tsc_start_temp = rte_rdtsc_precise(); 270fa609d94SAnoob Joseph 271fa609d94SAnoob Joseph for (i = 0; i < nb_ops; i++) { 272fa609d94SAnoob Joseph struct rte_crypto_sym_op *sym_op = ops[i]->sym; 273fa609d94SAnoob Joseph struct rte_mbuf *m = sym_op->m_src; 274fa609d94SAnoob Joseph 275fa609d94SAnoob Joseph test_ipsec_vec_populate(m, options, test_vector); 276fa609d94SAnoob Joseph } 277fa609d94SAnoob Joseph 278fa609d94SAnoob Joseph tsc_end_temp = rte_rdtsc_precise(); 279fa609d94SAnoob Joseph *tsc_start += tsc_end_temp - tsc_start_temp; 280fa609d94SAnoob Joseph } 281fa609d94SAnoob Joseph 2829afa7a46SAkhil Goyal static void 2839afa7a46SAkhil Goyal cperf_set_ops_security_tls(struct rte_crypto_op **ops, 2849afa7a46SAkhil Goyal uint32_t src_buf_offset __rte_unused, 2859afa7a46SAkhil Goyal uint32_t dst_buf_offset __rte_unused, 2869afa7a46SAkhil Goyal uint16_t nb_ops, void *sess, 2879afa7a46SAkhil Goyal const struct cperf_options *options, 2889afa7a46SAkhil Goyal const struct cperf_test_vector *test_vector, 2899afa7a46SAkhil Goyal uint16_t iv_offset __rte_unused, uint32_t *imix_idx, 2909afa7a46SAkhil Goyal uint64_t *tsc_start) 2919afa7a46SAkhil Goyal { 2929afa7a46SAkhil Goyal const uint32_t test_buffer_size = options->test_buffer_size; 2939afa7a46SAkhil Goyal uint16_t i = 0; 2949afa7a46SAkhil Goyal 2959afa7a46SAkhil Goyal RTE_SET_USED(imix_idx); 2969afa7a46SAkhil Goyal RTE_SET_USED(tsc_start); 2979afa7a46SAkhil Goyal RTE_SET_USED(test_vector); 2989afa7a46SAkhil Goyal 2999afa7a46SAkhil Goyal for (i = 0; i < nb_ops; i++) { 3009afa7a46SAkhil Goyal struct rte_crypto_sym_op *sym_op = ops[i]->sym; 3019afa7a46SAkhil Goyal struct rte_mbuf *m = sym_op->m_src; 302bcfeb919SAkhil Goyal uint32_t offset = test_buffer_size; 3039afa7a46SAkhil Goyal 3049afa7a46SAkhil Goyal ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 3059afa7a46SAkhil Goyal ops[i]->param1.tls_record.content_type = 0x17; 3069afa7a46SAkhil Goyal rte_security_attach_session(ops[i], sess); 3079afa7a46SAkhil Goyal sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + src_buf_offset); 308bcfeb919SAkhil Goyal sym_op->m_src->pkt_len = test_buffer_size; 3099afa7a46SAkhil Goyal 310bcfeb919SAkhil Goyal while ((m->next != NULL) && (offset >= m->data_len)) { 311bcfeb919SAkhil Goyal offset -= m->data_len; 312bcfeb919SAkhil Goyal m = m->next; 313bcfeb919SAkhil Goyal } 314bcfeb919SAkhil Goyal m->data_len = offset; 315bcfeb919SAkhil Goyal /* 316bcfeb919SAkhil Goyal * If there is not enough room in segment, 317bcfeb919SAkhil Goyal * place the digest in the next segment 318bcfeb919SAkhil Goyal */ 319bcfeb919SAkhil Goyal if ((rte_pktmbuf_tailroom(m)) < options->digest_sz) { 320bcfeb919SAkhil Goyal m = m->next; 321bcfeb919SAkhil Goyal m->data_len = 0; 322bcfeb919SAkhil Goyal } 323bcfeb919SAkhil Goyal m->next = NULL; 3249afa7a46SAkhil Goyal 3259afa7a46SAkhil Goyal sym_op->m_dst = NULL; 3269afa7a46SAkhil Goyal } 3279afa7a46SAkhil Goyal } 3288fd2b5a6SAkhil Goyal #endif 3298fd2b5a6SAkhil Goyal 330e7bd6977SAnoob Joseph static void 331f8be1786SSlawomir Mrozowicz cperf_set_ops_null_cipher(struct rte_crypto_op **ops, 332bf9d6702SPablo de Lara uint32_t src_buf_offset, uint32_t dst_buf_offset, 3332a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 334f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 335f8b7fdd3SPablo de Lara const struct cperf_test_vector *test_vector __rte_unused, 33628dde5daSAkhil Goyal uint16_t iv_offset __rte_unused, uint32_t *imix_idx, 33728dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 338f8be1786SSlawomir Mrozowicz { 339f8be1786SSlawomir Mrozowicz uint16_t i; 340f8be1786SSlawomir Mrozowicz 341f8be1786SSlawomir Mrozowicz for (i = 0; i < nb_ops; i++) { 342f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_op *sym_op = ops[i]->sym; 343f8be1786SSlawomir Mrozowicz 344bf9d6702SPablo de Lara ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 345f8be1786SSlawomir Mrozowicz rte_crypto_op_attach_sym_session(ops[i], sess); 346f8be1786SSlawomir Mrozowicz 347bf9d6702SPablo de Lara sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 348bf9d6702SPablo de Lara src_buf_offset); 349bf9d6702SPablo de Lara 350bf9d6702SPablo de Lara /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 351bf9d6702SPablo de Lara if (dst_buf_offset == 0) 352bf9d6702SPablo de Lara sym_op->m_dst = NULL; 353bf9d6702SPablo de Lara else 354bf9d6702SPablo de Lara sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 355bf9d6702SPablo de Lara dst_buf_offset); 356f8be1786SSlawomir Mrozowicz 357f8be1786SSlawomir Mrozowicz /* cipher parameters */ 35827c2e747SPablo de Lara if (options->imix_distribution_count) { 35927c2e747SPablo de Lara sym_op->cipher.data.length = 36027c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 36127c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 36227c2e747SPablo de Lara } else 363f6cefe25SPablo de Lara sym_op->cipher.data.length = options->test_buffer_size; 364f8be1786SSlawomir Mrozowicz sym_op->cipher.data.offset = 0; 365f8be1786SSlawomir Mrozowicz } 366f8be1786SSlawomir Mrozowicz } 367f8be1786SSlawomir Mrozowicz 368e7bd6977SAnoob Joseph static void 369f8be1786SSlawomir Mrozowicz cperf_set_ops_null_auth(struct rte_crypto_op **ops, 370bf9d6702SPablo de Lara uint32_t src_buf_offset, uint32_t dst_buf_offset, 3712a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 372f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 373f8b7fdd3SPablo de Lara const struct cperf_test_vector *test_vector __rte_unused, 37428dde5daSAkhil Goyal uint16_t iv_offset __rte_unused, uint32_t *imix_idx, 37528dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 376f8be1786SSlawomir Mrozowicz { 377f8be1786SSlawomir Mrozowicz uint16_t i; 378f8be1786SSlawomir Mrozowicz 379f8be1786SSlawomir Mrozowicz for (i = 0; i < nb_ops; i++) { 380f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_op *sym_op = ops[i]->sym; 381f8be1786SSlawomir Mrozowicz 382bf9d6702SPablo de Lara ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 383f8be1786SSlawomir Mrozowicz rte_crypto_op_attach_sym_session(ops[i], sess); 384f8be1786SSlawomir Mrozowicz 385bf9d6702SPablo de Lara sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 386bf9d6702SPablo de Lara src_buf_offset); 387bf9d6702SPablo de Lara 388bf9d6702SPablo de Lara /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 389bf9d6702SPablo de Lara if (dst_buf_offset == 0) 390bf9d6702SPablo de Lara sym_op->m_dst = NULL; 391bf9d6702SPablo de Lara else 392bf9d6702SPablo de Lara sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 393bf9d6702SPablo de Lara dst_buf_offset); 394f8be1786SSlawomir Mrozowicz 395f8be1786SSlawomir Mrozowicz /* auth parameters */ 39627c2e747SPablo de Lara if (options->imix_distribution_count) { 39727c2e747SPablo de Lara sym_op->auth.data.length = 39827c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 39927c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 40027c2e747SPablo de Lara } else 401f6cefe25SPablo de Lara sym_op->auth.data.length = options->test_buffer_size; 402f8be1786SSlawomir Mrozowicz sym_op->auth.data.offset = 0; 403f8be1786SSlawomir Mrozowicz } 404f8be1786SSlawomir Mrozowicz } 405f8be1786SSlawomir Mrozowicz 406e7bd6977SAnoob Joseph static void 407f8be1786SSlawomir Mrozowicz cperf_set_ops_cipher(struct rte_crypto_op **ops, 408bf9d6702SPablo de Lara uint32_t src_buf_offset, uint32_t dst_buf_offset, 4092a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 410f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 411f8b7fdd3SPablo de Lara const struct cperf_test_vector *test_vector, 41228dde5daSAkhil Goyal uint16_t iv_offset, uint32_t *imix_idx, 41328dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 414f8be1786SSlawomir Mrozowicz { 415f8be1786SSlawomir Mrozowicz uint16_t i; 416f8be1786SSlawomir Mrozowicz 417f8be1786SSlawomir Mrozowicz for (i = 0; i < nb_ops; i++) { 418f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_op *sym_op = ops[i]->sym; 419f8be1786SSlawomir Mrozowicz 420bf9d6702SPablo de Lara ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 421f8be1786SSlawomir Mrozowicz rte_crypto_op_attach_sym_session(ops[i], sess); 422f8be1786SSlawomir Mrozowicz 423bf9d6702SPablo de Lara sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 424bf9d6702SPablo de Lara src_buf_offset); 425bf9d6702SPablo de Lara 426bf9d6702SPablo de Lara /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 427bf9d6702SPablo de Lara if (dst_buf_offset == 0) 428bf9d6702SPablo de Lara sym_op->m_dst = NULL; 429bf9d6702SPablo de Lara else 430bf9d6702SPablo de Lara sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 431bf9d6702SPablo de Lara dst_buf_offset); 432f8be1786SSlawomir Mrozowicz 433f8be1786SSlawomir Mrozowicz /* cipher parameters */ 43427c2e747SPablo de Lara if (options->imix_distribution_count) { 43527c2e747SPablo de Lara sym_op->cipher.data.length = 43627c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 43727c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 43827c2e747SPablo de Lara } else 43927c2e747SPablo de Lara sym_op->cipher.data.length = options->test_buffer_size; 44027c2e747SPablo de Lara 44100915761SPablo de Lara if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 44200915761SPablo de Lara options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 44300915761SPablo de Lara options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) 44427c2e747SPablo de Lara sym_op->cipher.data.length <<= 3; 44500915761SPablo de Lara 446f8be1786SSlawomir Mrozowicz sym_op->cipher.data.offset = 0; 447f8be1786SSlawomir Mrozowicz } 448f8be1786SSlawomir Mrozowicz 449f8b7fdd3SPablo de Lara if (options->test == CPERF_TEST_TYPE_VERIFY) { 4505082f991SPablo de Lara for (i = 0; i < nb_ops; i++) { 4515082f991SPablo de Lara uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], 4525082f991SPablo de Lara uint8_t *, iv_offset); 4535082f991SPablo de Lara 454acf86169SPablo de Lara memcpy(iv_ptr, test_vector->cipher_iv.data, 455acf86169SPablo de Lara test_vector->cipher_iv.length); 456acf86169SPablo de Lara 457acf86169SPablo de Lara } 458acf86169SPablo de Lara } 459f8be1786SSlawomir Mrozowicz } 460f8be1786SSlawomir Mrozowicz 461e7bd6977SAnoob Joseph static void 462f8be1786SSlawomir Mrozowicz cperf_set_ops_auth(struct rte_crypto_op **ops, 463bf9d6702SPablo de Lara uint32_t src_buf_offset, uint32_t dst_buf_offset, 4642a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 465f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 466f8b7fdd3SPablo de Lara const struct cperf_test_vector *test_vector, 46728dde5daSAkhil Goyal uint16_t iv_offset, uint32_t *imix_idx, 46828dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 469f8be1786SSlawomir Mrozowicz { 470f8be1786SSlawomir Mrozowicz uint16_t i; 471f8be1786SSlawomir Mrozowicz 472f8be1786SSlawomir Mrozowicz for (i = 0; i < nb_ops; i++) { 473f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_op *sym_op = ops[i]->sym; 474f8be1786SSlawomir Mrozowicz 475bf9d6702SPablo de Lara ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 476f8be1786SSlawomir Mrozowicz rte_crypto_op_attach_sym_session(ops[i], sess); 477f8be1786SSlawomir Mrozowicz 478bf9d6702SPablo de Lara sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 479bf9d6702SPablo de Lara src_buf_offset); 480bf9d6702SPablo de Lara 481bf9d6702SPablo de Lara /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 482bf9d6702SPablo de Lara if (dst_buf_offset == 0) 483bf9d6702SPablo de Lara sym_op->m_dst = NULL; 484bf9d6702SPablo de Lara else 485bf9d6702SPablo de Lara sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 486bf9d6702SPablo de Lara dst_buf_offset); 487f8be1786SSlawomir Mrozowicz 488acf86169SPablo de Lara if (test_vector->auth_iv.length) { 489acf86169SPablo de Lara uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], 490acf86169SPablo de Lara uint8_t *, 491acf86169SPablo de Lara iv_offset); 492acf86169SPablo de Lara memcpy(iv_ptr, test_vector->auth_iv.data, 493acf86169SPablo de Lara test_vector->auth_iv.length); 494acf86169SPablo de Lara } 495acf86169SPablo de Lara 496f8be1786SSlawomir Mrozowicz /* authentication parameters */ 497f8be1786SSlawomir Mrozowicz if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) { 498f8be1786SSlawomir Mrozowicz sym_op->auth.digest.data = test_vector->digest.data; 499f8be1786SSlawomir Mrozowicz sym_op->auth.digest.phys_addr = 500f8be1786SSlawomir Mrozowicz test_vector->digest.phys_addr; 501f8be1786SSlawomir Mrozowicz } else { 502f8be1786SSlawomir Mrozowicz 503f6cefe25SPablo de Lara uint32_t offset = options->test_buffer_size; 504f8be1786SSlawomir Mrozowicz struct rte_mbuf *buf, *tbuf; 505f8be1786SSlawomir Mrozowicz 506f8be1786SSlawomir Mrozowicz if (options->out_of_place) { 507bf9d6702SPablo de Lara buf = sym_op->m_dst; 508f8be1786SSlawomir Mrozowicz } else { 509bf9d6702SPablo de Lara tbuf = sym_op->m_src; 510f8be1786SSlawomir Mrozowicz while ((tbuf->next != NULL) && 511f8be1786SSlawomir Mrozowicz (offset >= tbuf->data_len)) { 512f8be1786SSlawomir Mrozowicz offset -= tbuf->data_len; 513f8be1786SSlawomir Mrozowicz tbuf = tbuf->next; 514f8be1786SSlawomir Mrozowicz } 515083de3ebSPablo de Lara /* 516083de3ebSPablo de Lara * If there is not enough room in segment, 517083de3ebSPablo de Lara * place the digest in the next segment 518083de3ebSPablo de Lara */ 519083de3ebSPablo de Lara if ((tbuf->data_len - offset) < options->digest_sz) { 520083de3ebSPablo de Lara tbuf = tbuf->next; 521083de3ebSPablo de Lara offset = 0; 522083de3ebSPablo de Lara } 523b9bdd593SSergio Gonzalez Monroy buf = tbuf; 524f8be1786SSlawomir Mrozowicz } 525f8be1786SSlawomir Mrozowicz 526f8be1786SSlawomir Mrozowicz sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf, 527f8be1786SSlawomir Mrozowicz uint8_t *, offset); 528f8be1786SSlawomir Mrozowicz sym_op->auth.digest.phys_addr = 529bfa9a8a4SThomas Monjalon rte_pktmbuf_iova_offset(buf, offset); 530f8be1786SSlawomir Mrozowicz 531f8be1786SSlawomir Mrozowicz } 532f8be1786SSlawomir Mrozowicz 53327c2e747SPablo de Lara if (options->imix_distribution_count) { 53427c2e747SPablo de Lara sym_op->auth.data.length = 53527c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 53627c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 53727c2e747SPablo de Lara } else 53827c2e747SPablo de Lara sym_op->auth.data.length = options->test_buffer_size; 53927c2e747SPablo de Lara 54000915761SPablo de Lara if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 54100915761SPablo de Lara options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 54200915761SPablo de Lara options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) 54327c2e747SPablo de Lara sym_op->auth.data.length <<= 3; 54400915761SPablo de Lara 545f8be1786SSlawomir Mrozowicz sym_op->auth.data.offset = 0; 546f8be1786SSlawomir Mrozowicz } 547f8be1786SSlawomir Mrozowicz 548acf86169SPablo de Lara if (options->test == CPERF_TEST_TYPE_VERIFY) { 549acf86169SPablo de Lara if (test_vector->auth_iv.length) { 550acf86169SPablo de Lara for (i = 0; i < nb_ops; i++) { 551acf86169SPablo de Lara uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], 552acf86169SPablo de Lara uint8_t *, iv_offset); 553acf86169SPablo de Lara 554acf86169SPablo de Lara memcpy(iv_ptr, test_vector->auth_iv.data, 555acf86169SPablo de Lara test_vector->auth_iv.length); 556acf86169SPablo de Lara } 557acf86169SPablo de Lara } 558acf86169SPablo de Lara } 559f8be1786SSlawomir Mrozowicz } 560f8be1786SSlawomir Mrozowicz 561e7bd6977SAnoob Joseph static void 562f8be1786SSlawomir Mrozowicz cperf_set_ops_cipher_auth(struct rte_crypto_op **ops, 563bf9d6702SPablo de Lara uint32_t src_buf_offset, uint32_t dst_buf_offset, 5642a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 565f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 566f8b7fdd3SPablo de Lara const struct cperf_test_vector *test_vector, 56728dde5daSAkhil Goyal uint16_t iv_offset, uint32_t *imix_idx, 56828dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 569f8be1786SSlawomir Mrozowicz { 570f8be1786SSlawomir Mrozowicz uint16_t i; 571f8be1786SSlawomir Mrozowicz 572f8be1786SSlawomir Mrozowicz for (i = 0; i < nb_ops; i++) { 573f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_op *sym_op = ops[i]->sym; 574f8be1786SSlawomir Mrozowicz 575bf9d6702SPablo de Lara ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 576f8be1786SSlawomir Mrozowicz rte_crypto_op_attach_sym_session(ops[i], sess); 577f8be1786SSlawomir Mrozowicz 578bf9d6702SPablo de Lara sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 579bf9d6702SPablo de Lara src_buf_offset); 580bf9d6702SPablo de Lara 581bf9d6702SPablo de Lara /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 582bf9d6702SPablo de Lara if (dst_buf_offset == 0) 583bf9d6702SPablo de Lara sym_op->m_dst = NULL; 584bf9d6702SPablo de Lara else 585bf9d6702SPablo de Lara sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 586bf9d6702SPablo de Lara dst_buf_offset); 587f8be1786SSlawomir Mrozowicz 588f8be1786SSlawomir Mrozowicz /* cipher parameters */ 58927c2e747SPablo de Lara if (options->imix_distribution_count) { 59027c2e747SPablo de Lara sym_op->cipher.data.length = 59127c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 59227c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 59327c2e747SPablo de Lara } else 59427c2e747SPablo de Lara sym_op->cipher.data.length = options->test_buffer_size; 59527c2e747SPablo de Lara 5969f3677d6STejasree Kondoj if ((options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) && 5979f3677d6STejasree Kondoj (options->op_type == CPERF_AUTH_THEN_CIPHER)) 5989f3677d6STejasree Kondoj sym_op->cipher.data.length += options->digest_sz; 5999f3677d6STejasree Kondoj 60000915761SPablo de Lara if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || 60100915761SPablo de Lara options->cipher_algo == RTE_CRYPTO_CIPHER_KASUMI_F8 || 60200915761SPablo de Lara options->cipher_algo == RTE_CRYPTO_CIPHER_ZUC_EEA3) 60327c2e747SPablo de Lara sym_op->cipher.data.length <<= 3; 60400915761SPablo de Lara 605f8be1786SSlawomir Mrozowicz sym_op->cipher.data.offset = 0; 606f8be1786SSlawomir Mrozowicz 607f8be1786SSlawomir Mrozowicz /* authentication parameters */ 608f8be1786SSlawomir Mrozowicz if (options->auth_op == RTE_CRYPTO_AUTH_OP_VERIFY) { 609f8be1786SSlawomir Mrozowicz sym_op->auth.digest.data = test_vector->digest.data; 610f8be1786SSlawomir Mrozowicz sym_op->auth.digest.phys_addr = 611f8be1786SSlawomir Mrozowicz test_vector->digest.phys_addr; 612f8be1786SSlawomir Mrozowicz } else { 613f8be1786SSlawomir Mrozowicz 614f6cefe25SPablo de Lara uint32_t offset = options->test_buffer_size; 615f8be1786SSlawomir Mrozowicz struct rte_mbuf *buf, *tbuf; 616f8be1786SSlawomir Mrozowicz 617f8be1786SSlawomir Mrozowicz if (options->out_of_place) { 618bf9d6702SPablo de Lara buf = sym_op->m_dst; 619f8be1786SSlawomir Mrozowicz } else { 620bf9d6702SPablo de Lara tbuf = sym_op->m_src; 621f8be1786SSlawomir Mrozowicz while ((tbuf->next != NULL) && 622f8be1786SSlawomir Mrozowicz (offset >= tbuf->data_len)) { 623f8be1786SSlawomir Mrozowicz offset -= tbuf->data_len; 624f8be1786SSlawomir Mrozowicz tbuf = tbuf->next; 625f8be1786SSlawomir Mrozowicz } 626083de3ebSPablo de Lara /* 627083de3ebSPablo de Lara * If there is not enough room in segment, 628083de3ebSPablo de Lara * place the digest in the next segment 629083de3ebSPablo de Lara */ 630083de3ebSPablo de Lara if ((tbuf->data_len - offset) < options->digest_sz) { 631083de3ebSPablo de Lara tbuf = tbuf->next; 632083de3ebSPablo de Lara offset = 0; 633083de3ebSPablo de Lara } 634b9bdd593SSergio Gonzalez Monroy buf = tbuf; 635f8be1786SSlawomir Mrozowicz } 636f8be1786SSlawomir Mrozowicz 637f8be1786SSlawomir Mrozowicz sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf, 638f8be1786SSlawomir Mrozowicz uint8_t *, offset); 639f8be1786SSlawomir Mrozowicz sym_op->auth.digest.phys_addr = 640bfa9a8a4SThomas Monjalon rte_pktmbuf_iova_offset(buf, offset); 641f8be1786SSlawomir Mrozowicz } 642f8be1786SSlawomir Mrozowicz 64327c2e747SPablo de Lara if (options->imix_distribution_count) { 64427c2e747SPablo de Lara sym_op->auth.data.length = 64527c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 64627c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 64727c2e747SPablo de Lara } else 64827c2e747SPablo de Lara sym_op->auth.data.length = options->test_buffer_size; 64927c2e747SPablo de Lara 65000915761SPablo de Lara if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || 65100915761SPablo de Lara options->auth_algo == RTE_CRYPTO_AUTH_KASUMI_F9 || 65200915761SPablo de Lara options->auth_algo == RTE_CRYPTO_AUTH_ZUC_EIA3) 65327c2e747SPablo de Lara sym_op->auth.data.length <<= 3; 65400915761SPablo de Lara 655f8be1786SSlawomir Mrozowicz sym_op->auth.data.offset = 0; 656f8be1786SSlawomir Mrozowicz } 657f8be1786SSlawomir Mrozowicz 658f8b7fdd3SPablo de Lara if (options->test == CPERF_TEST_TYPE_VERIFY) { 6595082f991SPablo de Lara for (i = 0; i < nb_ops; i++) { 6605082f991SPablo de Lara uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], 6615082f991SPablo de Lara uint8_t *, iv_offset); 6625082f991SPablo de Lara 663acf86169SPablo de Lara memcpy(iv_ptr, test_vector->cipher_iv.data, 664acf86169SPablo de Lara test_vector->cipher_iv.length); 665acf86169SPablo de Lara if (test_vector->auth_iv.length) { 666acf86169SPablo de Lara /* 667acf86169SPablo de Lara * Copy IV after the crypto operation and 668acf86169SPablo de Lara * the cipher IV 669acf86169SPablo de Lara */ 670acf86169SPablo de Lara iv_ptr += test_vector->cipher_iv.length; 671acf86169SPablo de Lara memcpy(iv_ptr, test_vector->auth_iv.data, 672acf86169SPablo de Lara test_vector->auth_iv.length); 673f8b7fdd3SPablo de Lara } 6745082f991SPablo de Lara } 675f8b7fdd3SPablo de Lara 676acf86169SPablo de Lara } 677f8be1786SSlawomir Mrozowicz } 678f8be1786SSlawomir Mrozowicz 679e7bd6977SAnoob Joseph static void 680f8be1786SSlawomir Mrozowicz cperf_set_ops_aead(struct rte_crypto_op **ops, 681bf9d6702SPablo de Lara uint32_t src_buf_offset, uint32_t dst_buf_offset, 6822a440d6aSAkhil Goyal uint16_t nb_ops, void *sess, 683f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 684f8b7fdd3SPablo de Lara const struct cperf_test_vector *test_vector, 68528dde5daSAkhil Goyal uint16_t iv_offset, uint32_t *imix_idx, 68628dde5daSAkhil Goyal uint64_t *tsc_start __rte_unused) 687f8be1786SSlawomir Mrozowicz { 688f8be1786SSlawomir Mrozowicz uint16_t i; 6897df07433SPablo de Lara /* AAD is placed after the IV */ 6900b242422SPablo de Lara uint16_t aad_offset = iv_offset + 6910b242422SPablo de Lara RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16); 692f8be1786SSlawomir Mrozowicz 693f8be1786SSlawomir Mrozowicz for (i = 0; i < nb_ops; i++) { 694f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_op *sym_op = ops[i]->sym; 695f8be1786SSlawomir Mrozowicz 696bf9d6702SPablo de Lara ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; 697f8be1786SSlawomir Mrozowicz rte_crypto_op_attach_sym_session(ops[i], sess); 698f8be1786SSlawomir Mrozowicz 699bf9d6702SPablo de Lara sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + 700bf9d6702SPablo de Lara src_buf_offset); 701bf9d6702SPablo de Lara 702bf9d6702SPablo de Lara /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ 703bf9d6702SPablo de Lara if (dst_buf_offset == 0) 704bf9d6702SPablo de Lara sym_op->m_dst = NULL; 705bf9d6702SPablo de Lara else 706bf9d6702SPablo de Lara sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + 707bf9d6702SPablo de Lara dst_buf_offset); 708f8be1786SSlawomir Mrozowicz 7098a5b494aSPablo de Lara /* AEAD parameters */ 71027c2e747SPablo de Lara if (options->imix_distribution_count) { 71127c2e747SPablo de Lara sym_op->aead.data.length = 71227c2e747SPablo de Lara options->imix_buffer_sizes[*imix_idx]; 71327c2e747SPablo de Lara *imix_idx = (*imix_idx + 1) % options->pool_sz; 71427c2e747SPablo de Lara } else 7158a5b494aSPablo de Lara sym_op->aead.data.length = options->test_buffer_size; 7160b242422SPablo de Lara sym_op->aead.data.offset = 0; 717f8be1786SSlawomir Mrozowicz 7180b242422SPablo de Lara sym_op->aead.aad.data = rte_crypto_op_ctod_offset(ops[i], 7190b242422SPablo de Lara uint8_t *, aad_offset); 7200b242422SPablo de Lara sym_op->aead.aad.phys_addr = rte_crypto_op_ctophys_offset(ops[i], 7210b242422SPablo de Lara aad_offset); 722f8be1786SSlawomir Mrozowicz 7238a5b494aSPablo de Lara if (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT) { 7248a5b494aSPablo de Lara sym_op->aead.digest.data = test_vector->digest.data; 7258a5b494aSPablo de Lara sym_op->aead.digest.phys_addr = 726f8be1786SSlawomir Mrozowicz test_vector->digest.phys_addr; 727f8be1786SSlawomir Mrozowicz } else { 728f8be1786SSlawomir Mrozowicz 7298a5b494aSPablo de Lara uint32_t offset = sym_op->aead.data.length + 7308a5b494aSPablo de Lara sym_op->aead.data.offset; 731f8be1786SSlawomir Mrozowicz struct rte_mbuf *buf, *tbuf; 732f8be1786SSlawomir Mrozowicz 733f8be1786SSlawomir Mrozowicz if (options->out_of_place) { 734bf9d6702SPablo de Lara buf = sym_op->m_dst; 735f8be1786SSlawomir Mrozowicz } else { 736bf9d6702SPablo de Lara tbuf = sym_op->m_src; 737f8be1786SSlawomir Mrozowicz while ((tbuf->next != NULL) && 738f8be1786SSlawomir Mrozowicz (offset >= tbuf->data_len)) { 739f8be1786SSlawomir Mrozowicz offset -= tbuf->data_len; 740f8be1786SSlawomir Mrozowicz tbuf = tbuf->next; 741f8be1786SSlawomir Mrozowicz } 742083de3ebSPablo de Lara /* 743083de3ebSPablo de Lara * If there is not enough room in segment, 744083de3ebSPablo de Lara * place the digest in the next segment 745083de3ebSPablo de Lara */ 746083de3ebSPablo de Lara if ((tbuf->data_len - offset) < options->digest_sz) { 747083de3ebSPablo de Lara tbuf = tbuf->next; 748083de3ebSPablo de Lara offset = 0; 749083de3ebSPablo de Lara } 750b9bdd593SSergio Gonzalez Monroy buf = tbuf; 751f8be1786SSlawomir Mrozowicz } 752f8be1786SSlawomir Mrozowicz 7538a5b494aSPablo de Lara sym_op->aead.digest.data = rte_pktmbuf_mtod_offset(buf, 754f8be1786SSlawomir Mrozowicz uint8_t *, offset); 7558a5b494aSPablo de Lara sym_op->aead.digest.phys_addr = 756bfa9a8a4SThomas Monjalon rte_pktmbuf_iova_offset(buf, offset); 757f8be1786SSlawomir Mrozowicz } 758f8be1786SSlawomir Mrozowicz } 759f8be1786SSlawomir Mrozowicz 76014864c42SArchana Muniganti if ((options->test == CPERF_TEST_TYPE_VERIFY) || 76179daa287SSuanming Mou (options->test == CPERF_TEST_TYPE_LATENCY) || 76279daa287SSuanming Mou (options->test == CPERF_TEST_TYPE_THROUGHPUT && 76379daa287SSuanming Mou (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT || 76479daa287SSuanming Mou options->cipher_op == RTE_CRYPTO_CIPHER_OP_DECRYPT))) { 7655082f991SPablo de Lara for (i = 0; i < nb_ops; i++) { 7665082f991SPablo de Lara uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], 7675082f991SPablo de Lara uint8_t *, iv_offset); 7685082f991SPablo de Lara 7697df07433SPablo de Lara /* 7707df07433SPablo de Lara * If doing AES-CCM, nonce is copied one byte 7717df07433SPablo de Lara * after the start of IV field, and AAD is copied 7727df07433SPablo de Lara * 18 bytes after the start of the AAD field. 7737df07433SPablo de Lara */ 7747df07433SPablo de Lara if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) { 7757df07433SPablo de Lara memcpy(iv_ptr + 1, test_vector->aead_iv.data, 7767df07433SPablo de Lara test_vector->aead_iv.length); 7777df07433SPablo de Lara 7787df07433SPablo de Lara memcpy(ops[i]->sym->aead.aad.data + 18, 7797df07433SPablo de Lara test_vector->aad.data, 7807df07433SPablo de Lara test_vector->aad.length); 7817df07433SPablo de Lara } else { 7828a5b494aSPablo de Lara memcpy(iv_ptr, test_vector->aead_iv.data, 7838a5b494aSPablo de Lara test_vector->aead_iv.length); 7840b242422SPablo de Lara 7850b242422SPablo de Lara memcpy(ops[i]->sym->aead.aad.data, 7860b242422SPablo de Lara test_vector->aad.data, 7870b242422SPablo de Lara test_vector->aad.length); 788f8b7fdd3SPablo de Lara } 7895082f991SPablo de Lara } 7907df07433SPablo de Lara } 791f8be1786SSlawomir Mrozowicz } 792f8be1786SSlawomir Mrozowicz 7932a440d6aSAkhil Goyal static void * 79428dde5daSAkhil Goyal create_ipsec_session(struct rte_mempool *sess_mp, 79528dde5daSAkhil Goyal uint8_t dev_id, 79628dde5daSAkhil Goyal const struct cperf_options *options, 79728dde5daSAkhil Goyal const struct cperf_test_vector *test_vector, 79828dde5daSAkhil Goyal uint16_t iv_offset) 79928dde5daSAkhil Goyal { 80028dde5daSAkhil Goyal struct rte_crypto_sym_xform auth_xform = {0}; 80121230400SAnoob Joseph struct rte_crypto_sym_xform *crypto_xform; 80221230400SAnoob Joseph struct rte_crypto_sym_xform xform = {0}; 80328dde5daSAkhil Goyal 80428dde5daSAkhil Goyal if (options->aead_algo != 0) { 80528dde5daSAkhil Goyal /* Setup AEAD Parameters */ 80628dde5daSAkhil Goyal xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 80728dde5daSAkhil Goyal xform.next = NULL; 80828dde5daSAkhil Goyal xform.aead.algo = options->aead_algo; 80928dde5daSAkhil Goyal xform.aead.op = options->aead_op; 81028dde5daSAkhil Goyal xform.aead.iv.offset = iv_offset; 81128dde5daSAkhil Goyal xform.aead.key.data = test_vector->aead_key.data; 81228dde5daSAkhil Goyal xform.aead.key.length = test_vector->aead_key.length; 81328dde5daSAkhil Goyal xform.aead.iv.length = test_vector->aead_iv.length; 81428dde5daSAkhil Goyal xform.aead.digest_length = options->digest_sz; 81528dde5daSAkhil Goyal xform.aead.aad_length = options->aead_aad_sz; 81621230400SAnoob Joseph crypto_xform = &xform; 81728dde5daSAkhil Goyal } else if (options->cipher_algo != 0 && options->auth_algo != 0) { 81828dde5daSAkhil Goyal /* Setup Cipher Parameters */ 81928dde5daSAkhil Goyal xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 82028dde5daSAkhil Goyal xform.cipher.algo = options->cipher_algo; 82128dde5daSAkhil Goyal xform.cipher.op = options->cipher_op; 82228dde5daSAkhil Goyal xform.cipher.iv.offset = iv_offset; 82328dde5daSAkhil Goyal xform.cipher.iv.length = test_vector->cipher_iv.length; 82428dde5daSAkhil Goyal /* cipher different than null */ 82528dde5daSAkhil Goyal if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 82628dde5daSAkhil Goyal xform.cipher.key.data = test_vector->cipher_key.data; 82728dde5daSAkhil Goyal xform.cipher.key.length = 82828dde5daSAkhil Goyal test_vector->cipher_key.length; 82928dde5daSAkhil Goyal } else { 83028dde5daSAkhil Goyal xform.cipher.key.data = NULL; 83128dde5daSAkhil Goyal xform.cipher.key.length = 0; 83228dde5daSAkhil Goyal } 83328dde5daSAkhil Goyal 83428dde5daSAkhil Goyal /* Setup Auth Parameters */ 83528dde5daSAkhil Goyal auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 83628dde5daSAkhil Goyal auth_xform.auth.algo = options->auth_algo; 83728dde5daSAkhil Goyal auth_xform.auth.op = options->auth_op; 83828dde5daSAkhil Goyal auth_xform.auth.iv.offset = iv_offset + 83928dde5daSAkhil Goyal xform.cipher.iv.length; 84028dde5daSAkhil Goyal /* auth different than null */ 84128dde5daSAkhil Goyal if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) { 84228dde5daSAkhil Goyal auth_xform.auth.digest_length = options->digest_sz; 84328dde5daSAkhil Goyal auth_xform.auth.key.length = 84428dde5daSAkhil Goyal test_vector->auth_key.length; 84528dde5daSAkhil Goyal auth_xform.auth.key.data = test_vector->auth_key.data; 84628dde5daSAkhil Goyal auth_xform.auth.iv.length = test_vector->auth_iv.length; 84728dde5daSAkhil Goyal } else { 84828dde5daSAkhil Goyal auth_xform.auth.digest_length = 0; 84928dde5daSAkhil Goyal auth_xform.auth.key.length = 0; 85028dde5daSAkhil Goyal auth_xform.auth.key.data = NULL; 85128dde5daSAkhil Goyal auth_xform.auth.iv.length = 0; 85228dde5daSAkhil Goyal } 85328dde5daSAkhil Goyal 85421230400SAnoob Joseph if (options->is_outbound) { 85521230400SAnoob Joseph crypto_xform = &xform; 85628dde5daSAkhil Goyal xform.next = &auth_xform; 85721230400SAnoob Joseph auth_xform.next = NULL; 85821230400SAnoob Joseph } else { 85921230400SAnoob Joseph crypto_xform = &auth_xform; 86021230400SAnoob Joseph auth_xform.next = &xform; 86121230400SAnoob Joseph xform.next = NULL; 86221230400SAnoob Joseph } 86328dde5daSAkhil Goyal } else { 86428dde5daSAkhil Goyal return NULL; 86528dde5daSAkhil Goyal } 86628dde5daSAkhil Goyal 86728dde5daSAkhil Goyal #define CPERF_IPSEC_SRC_IP 0x01010101 86828dde5daSAkhil Goyal #define CPERF_IPSEC_DST_IP 0x02020202 86928dde5daSAkhil Goyal #define CPERF_IPSEC_SALT 0x0 87028dde5daSAkhil Goyal #define CPERF_IPSEC_DEFTTL 64 87128dde5daSAkhil Goyal struct rte_security_ipsec_tunnel_param tunnel = { 87228dde5daSAkhil Goyal .type = RTE_SECURITY_IPSEC_TUNNEL_IPV4, 87328dde5daSAkhil Goyal {.ipv4 = { 87428dde5daSAkhil Goyal .src_ip = { .s_addr = CPERF_IPSEC_SRC_IP}, 87528dde5daSAkhil Goyal .dst_ip = { .s_addr = CPERF_IPSEC_DST_IP}, 87628dde5daSAkhil Goyal .dscp = 0, 87728dde5daSAkhil Goyal .df = 0, 87828dde5daSAkhil Goyal .ttl = CPERF_IPSEC_DEFTTL, 87928dde5daSAkhil Goyal } }, 88028dde5daSAkhil Goyal }; 88128dde5daSAkhil Goyal struct rte_security_session_conf sess_conf = { 88228dde5daSAkhil Goyal .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 88328dde5daSAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_IPSEC, 88428dde5daSAkhil Goyal {.ipsec = { 8852218e078SAnoob Joseph .spi = rte_lcore_id() + 1, 88628dde5daSAkhil Goyal /**< For testing sake, lcore_id is taken as SPI so that 88728dde5daSAkhil Goyal * for every core a different session is created. 88828dde5daSAkhil Goyal */ 88928dde5daSAkhil Goyal .salt = CPERF_IPSEC_SALT, 89028dde5daSAkhil Goyal .options = { 0 }, 89128dde5daSAkhil Goyal .replay_win_sz = 0, 89228dde5daSAkhil Goyal .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP, 89328dde5daSAkhil Goyal .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL, 89428dde5daSAkhil Goyal .tunnel = tunnel, 89528dde5daSAkhil Goyal } }, 89628dde5daSAkhil Goyal .userdata = NULL, 89721230400SAnoob Joseph .crypto_xform = crypto_xform, 89828dde5daSAkhil Goyal }; 89928dde5daSAkhil Goyal 90021230400SAnoob Joseph if (options->is_outbound) 90121230400SAnoob Joseph sess_conf.ipsec.direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS; 90221230400SAnoob Joseph else 90321230400SAnoob Joseph sess_conf.ipsec.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS; 90421230400SAnoob Joseph 90579bdb787SAkhil Goyal void *ctx = rte_cryptodev_get_sec_ctx(dev_id); 90628dde5daSAkhil Goyal 90728dde5daSAkhil Goyal /* Create security session */ 9083f3fc330SAkhil Goyal return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp); 90928dde5daSAkhil Goyal } 91028dde5daSAkhil Goyal 9112a440d6aSAkhil Goyal static void * 9129afa7a46SAkhil Goyal create_tls_session(struct rte_mempool *sess_mp, 9139afa7a46SAkhil Goyal uint8_t dev_id, 9149afa7a46SAkhil Goyal const struct cperf_options *options, 9159afa7a46SAkhil Goyal const struct cperf_test_vector *test_vector, 9169afa7a46SAkhil Goyal uint16_t iv_offset) 9179afa7a46SAkhil Goyal { 9189afa7a46SAkhil Goyal struct rte_crypto_sym_xform auth_xform = {0}; 9199afa7a46SAkhil Goyal struct rte_crypto_sym_xform *crypto_xform; 9209afa7a46SAkhil Goyal struct rte_crypto_sym_xform xform = {0}; 9219afa7a46SAkhil Goyal 9229afa7a46SAkhil Goyal if (options->aead_algo != 0) { 9239afa7a46SAkhil Goyal /* Setup AEAD Parameters */ 9249afa7a46SAkhil Goyal xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 9259afa7a46SAkhil Goyal xform.next = NULL; 9269afa7a46SAkhil Goyal xform.aead.algo = options->aead_algo; 9279afa7a46SAkhil Goyal xform.aead.op = options->aead_op; 9289afa7a46SAkhil Goyal xform.aead.iv.offset = iv_offset; 9299afa7a46SAkhil Goyal xform.aead.key.data = test_vector->aead_key.data; 9309afa7a46SAkhil Goyal xform.aead.key.length = test_vector->aead_key.length; 9319afa7a46SAkhil Goyal xform.aead.iv.length = test_vector->aead_iv.length; 9329afa7a46SAkhil Goyal xform.aead.digest_length = options->digest_sz; 9339afa7a46SAkhil Goyal xform.aead.aad_length = options->aead_aad_sz; 9349afa7a46SAkhil Goyal crypto_xform = &xform; 9359afa7a46SAkhil Goyal } else if (options->cipher_algo != 0 && options->auth_algo != 0) { 9369afa7a46SAkhil Goyal /* Setup Cipher Parameters */ 9379afa7a46SAkhil Goyal xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 9389afa7a46SAkhil Goyal xform.cipher.algo = options->cipher_algo; 9399afa7a46SAkhil Goyal xform.cipher.op = options->cipher_op; 9409afa7a46SAkhil Goyal xform.cipher.iv.offset = iv_offset; 9419afa7a46SAkhil Goyal xform.cipher.iv.length = test_vector->cipher_iv.length; 9429afa7a46SAkhil Goyal /* cipher different than null */ 9439afa7a46SAkhil Goyal if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 9449afa7a46SAkhil Goyal xform.cipher.key.data = test_vector->cipher_key.data; 9459afa7a46SAkhil Goyal xform.cipher.key.length = test_vector->cipher_key.length; 9469afa7a46SAkhil Goyal } else { 9479afa7a46SAkhil Goyal xform.cipher.key.data = NULL; 9489afa7a46SAkhil Goyal xform.cipher.key.length = 0; 9499afa7a46SAkhil Goyal } 9509afa7a46SAkhil Goyal 9519afa7a46SAkhil Goyal /* Setup Auth Parameters */ 9529afa7a46SAkhil Goyal auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 9539afa7a46SAkhil Goyal auth_xform.auth.algo = options->auth_algo; 9549afa7a46SAkhil Goyal auth_xform.auth.op = options->auth_op; 9559afa7a46SAkhil Goyal auth_xform.auth.iv.offset = iv_offset + xform.cipher.iv.length; 9569afa7a46SAkhil Goyal /* auth different than null */ 9579afa7a46SAkhil Goyal if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) { 9589afa7a46SAkhil Goyal auth_xform.auth.digest_length = options->digest_sz; 9599afa7a46SAkhil Goyal auth_xform.auth.key.length = test_vector->auth_key.length; 9609afa7a46SAkhil Goyal auth_xform.auth.key.data = test_vector->auth_key.data; 9619afa7a46SAkhil Goyal auth_xform.auth.iv.length = test_vector->auth_iv.length; 9629afa7a46SAkhil Goyal } else { 9639afa7a46SAkhil Goyal auth_xform.auth.digest_length = 0; 9649afa7a46SAkhil Goyal auth_xform.auth.key.length = 0; 9659afa7a46SAkhil Goyal auth_xform.auth.key.data = NULL; 9669afa7a46SAkhil Goyal auth_xform.auth.iv.length = 0; 9679afa7a46SAkhil Goyal } 9689afa7a46SAkhil Goyal 9699afa7a46SAkhil Goyal if (options->is_outbound) { 9709afa7a46SAkhil Goyal /* Currently supporting AUTH then Encrypt mode only for TLS. */ 9719afa7a46SAkhil Goyal crypto_xform = &auth_xform; 9729afa7a46SAkhil Goyal auth_xform.next = &xform; 9739afa7a46SAkhil Goyal xform.next = NULL; 9749afa7a46SAkhil Goyal } else { 9759afa7a46SAkhil Goyal crypto_xform = &xform; 9769afa7a46SAkhil Goyal xform.next = &auth_xform; 9779afa7a46SAkhil Goyal auth_xform.next = NULL; 9789afa7a46SAkhil Goyal } 9799afa7a46SAkhil Goyal } else { 9809afa7a46SAkhil Goyal return NULL; 9819afa7a46SAkhil Goyal } 9829afa7a46SAkhil Goyal 9839afa7a46SAkhil Goyal struct rte_security_tls_record_sess_options opts = { 9849afa7a46SAkhil Goyal .iv_gen_disable = 0, 9859afa7a46SAkhil Goyal .extra_padding_enable = 0, 9869afa7a46SAkhil Goyal }; 9879afa7a46SAkhil Goyal struct rte_security_session_conf sess_conf = { 9889afa7a46SAkhil Goyal .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 9899afa7a46SAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_TLS_RECORD, 9909afa7a46SAkhil Goyal {.tls_record = { 9919afa7a46SAkhil Goyal .ver = RTE_SECURITY_VERSION_TLS_1_2, 9929afa7a46SAkhil Goyal .options = opts, 9939afa7a46SAkhil Goyal } }, 9949afa7a46SAkhil Goyal .userdata = NULL, 9959afa7a46SAkhil Goyal .crypto_xform = crypto_xform, 9969afa7a46SAkhil Goyal }; 9979afa7a46SAkhil Goyal if (options->tls_version) 9989afa7a46SAkhil Goyal sess_conf.tls_record.ver = options->tls_version; 9999afa7a46SAkhil Goyal 10009afa7a46SAkhil Goyal if (options->is_outbound) 10019afa7a46SAkhil Goyal sess_conf.tls_record.type = RTE_SECURITY_TLS_SESS_TYPE_WRITE; 10029afa7a46SAkhil Goyal else 10039afa7a46SAkhil Goyal sess_conf.tls_record.type = RTE_SECURITY_TLS_SESS_TYPE_READ; 10049afa7a46SAkhil Goyal 10059afa7a46SAkhil Goyal void *ctx = rte_cryptodev_get_sec_ctx(dev_id); 10069afa7a46SAkhil Goyal 10079afa7a46SAkhil Goyal /* Create security session */ 10089afa7a46SAkhil Goyal return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp); 10099afa7a46SAkhil Goyal } 10109afa7a46SAkhil Goyal 10119afa7a46SAkhil Goyal static void * 1012b3bbd9e5SSlawomir Mrozowicz cperf_create_session(struct rte_mempool *sess_mp, 1013b3bbd9e5SSlawomir Mrozowicz uint8_t dev_id, 1014f8be1786SSlawomir Mrozowicz const struct cperf_options *options, 10150fbd75a9SPablo de Lara const struct cperf_test_vector *test_vector, 10160fbd75a9SPablo de Lara uint16_t iv_offset) 1017f8be1786SSlawomir Mrozowicz { 1018f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_xform cipher_xform; 1019f8be1786SSlawomir Mrozowicz struct rte_crypto_sym_xform auth_xform; 10208a5b494aSPablo de Lara struct rte_crypto_sym_xform aead_xform; 10212a440d6aSAkhil Goyal void *sess = NULL; 1022757f40e2SCiara Power void *asym_sess = NULL; 1023ba588ce3SKiran Kumar K struct rte_crypto_asym_xform xform = {0}; 1024757f40e2SCiara Power int ret; 1025f8be1786SSlawomir Mrozowicz 1026ba588ce3SKiran Kumar K if (options->op_type == CPERF_ASYM_MODEX) { 1027ba588ce3SKiran Kumar K xform.next = NULL; 1028ba588ce3SKiran Kumar K xform.xform_type = RTE_CRYPTO_ASYM_XFORM_MODEX; 1029a538d1d2SKiran Kumar K xform.modex.modulus.data = options->modex_data->modulus.data; 1030a538d1d2SKiran Kumar K xform.modex.modulus.length = options->modex_data->modulus.len; 1031a538d1d2SKiran Kumar K xform.modex.exponent.data = options->modex_data->exponent.data; 1032a538d1d2SKiran Kumar K xform.modex.exponent.length = options->modex_data->exponent.len; 1033ba588ce3SKiran Kumar K 1034757f40e2SCiara Power ret = rte_cryptodev_asym_session_create(dev_id, &xform, 1035757f40e2SCiara Power sess_mp, &asym_sess); 1036757f40e2SCiara Power if (ret < 0) { 1037757f40e2SCiara Power RTE_LOG(ERR, USER1, "Asym session create failed\n"); 1038ba588ce3SKiran Kumar K return NULL; 1039757f40e2SCiara Power } 1040757f40e2SCiara Power return asym_sess; 1041ba588ce3SKiran Kumar K } 1042b82742f9SAkhil Goyal 1043195a271eSGowrishankar Muthukrishnan if (options->op_type == CPERF_ASYM_SECP256R1) { 1044195a271eSGowrishankar Muthukrishnan xform.next = NULL; 1045195a271eSGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_ECDSA; 1046195a271eSGowrishankar Muthukrishnan xform.ec.curve_id = options->secp256r1_data->curve; 1047195a271eSGowrishankar Muthukrishnan xform.ec.pkey.data = options->secp256r1_data->pkey.data; 1048195a271eSGowrishankar Muthukrishnan xform.ec.pkey.length = options->secp256r1_data->pkey.length; 1049195a271eSGowrishankar Muthukrishnan xform.ec.q.x.data = options->secp256r1_data->pubkey_qx.data; 1050195a271eSGowrishankar Muthukrishnan xform.ec.q.x.length = options->secp256r1_data->pubkey_qx.length; 1051195a271eSGowrishankar Muthukrishnan xform.ec.q.y.data = options->secp256r1_data->pubkey_qy.data; 1052195a271eSGowrishankar Muthukrishnan xform.ec.q.y.length = options->secp256r1_data->pubkey_qy.length; 1053195a271eSGowrishankar Muthukrishnan 1054195a271eSGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, 1055195a271eSGowrishankar Muthukrishnan sess_mp, &asym_sess); 1056195a271eSGowrishankar Muthukrishnan if (ret < 0) { 1057195a271eSGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, "ECDSA Asym session create failed\n"); 1058195a271eSGowrishankar Muthukrishnan return NULL; 1059195a271eSGowrishankar Muthukrishnan } 1060195a271eSGowrishankar Muthukrishnan 1061195a271eSGowrishankar Muthukrishnan return asym_sess; 1062195a271eSGowrishankar Muthukrishnan } 1063195a271eSGowrishankar Muthukrishnan 1064*981a1ed3SGowrishankar Muthukrishnan if (options->op_type == CPERF_ASYM_ED25519) { 1065*981a1ed3SGowrishankar Muthukrishnan xform.next = NULL; 1066*981a1ed3SGowrishankar Muthukrishnan xform.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA; 1067*981a1ed3SGowrishankar Muthukrishnan xform.ec.curve_id = options->eddsa_data->curve; 1068*981a1ed3SGowrishankar Muthukrishnan xform.ec.pkey.data = options->eddsa_data->pkey.data; 1069*981a1ed3SGowrishankar Muthukrishnan xform.ec.pkey.length = options->eddsa_data->pkey.length; 1070*981a1ed3SGowrishankar Muthukrishnan xform.ec.q.x.data = options->eddsa_data->pubkey.data; 1071*981a1ed3SGowrishankar Muthukrishnan xform.ec.q.x.length = options->eddsa_data->pubkey.length; 1072*981a1ed3SGowrishankar Muthukrishnan 1073*981a1ed3SGowrishankar Muthukrishnan ret = rte_cryptodev_asym_session_create(dev_id, &xform, 1074*981a1ed3SGowrishankar Muthukrishnan sess_mp, &asym_sess); 1075*981a1ed3SGowrishankar Muthukrishnan if (ret < 0) { 1076*981a1ed3SGowrishankar Muthukrishnan RTE_LOG(ERR, USER1, "EdDSA Asym session create failed\n"); 1077*981a1ed3SGowrishankar Muthukrishnan return NULL; 1078*981a1ed3SGowrishankar Muthukrishnan } 1079*981a1ed3SGowrishankar Muthukrishnan 1080*981a1ed3SGowrishankar Muthukrishnan return asym_sess; 1081*981a1ed3SGowrishankar Muthukrishnan } 1082*981a1ed3SGowrishankar Muthukrishnan 1083b82742f9SAkhil Goyal if (options->op_type == CPERF_ASYM_SM2) { 1084b82742f9SAkhil Goyal xform.next = NULL; 1085b82742f9SAkhil Goyal xform.xform_type = RTE_CRYPTO_ASYM_XFORM_SM2; 1086b82742f9SAkhil Goyal xform.ec.curve_id = options->sm2_data->curve; 1087b82742f9SAkhil Goyal xform.ec.pkey.data = options->sm2_data->pkey.data; 1088b82742f9SAkhil Goyal xform.ec.pkey.length = options->sm2_data->pkey.length; 1089b82742f9SAkhil Goyal xform.ec.q.x.data = options->sm2_data->pubkey_qx.data; 1090b82742f9SAkhil Goyal xform.ec.q.x.length = options->sm2_data->pubkey_qx.length; 1091b82742f9SAkhil Goyal xform.ec.q.y.data = options->sm2_data->pubkey_qy.data; 1092b82742f9SAkhil Goyal xform.ec.q.y.length = options->sm2_data->pubkey_qy.length; 1093b82742f9SAkhil Goyal 1094b82742f9SAkhil Goyal ret = rte_cryptodev_asym_session_create(dev_id, &xform, 1095b82742f9SAkhil Goyal sess_mp, &asym_sess); 1096b82742f9SAkhil Goyal if (ret < 0) { 1097b82742f9SAkhil Goyal RTE_LOG(ERR, USER1, "SM2 Asym session create failed\n"); 1098b82742f9SAkhil Goyal return NULL; 1099b82742f9SAkhil Goyal } 1100b82742f9SAkhil Goyal 1101b82742f9SAkhil Goyal return asym_sess; 1102b82742f9SAkhil Goyal } 1103a8d0d473SBruce Richardson #ifdef RTE_LIB_SECURITY 11048fd2b5a6SAkhil Goyal /* 11058fd2b5a6SAkhil Goyal * security only 11068fd2b5a6SAkhil Goyal */ 11078fd2b5a6SAkhil Goyal if (options->op_type == CPERF_PDCP) { 11088fd2b5a6SAkhil Goyal /* Setup Cipher Parameters */ 11098fd2b5a6SAkhil Goyal cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 11108fd2b5a6SAkhil Goyal cipher_xform.next = NULL; 11118fd2b5a6SAkhil Goyal cipher_xform.cipher.algo = options->cipher_algo; 11128fd2b5a6SAkhil Goyal cipher_xform.cipher.op = options->cipher_op; 11138fd2b5a6SAkhil Goyal cipher_xform.cipher.iv.offset = iv_offset; 11145a61bdb9SAkhil Goyal cipher_xform.cipher.iv.length = 4; 11158fd2b5a6SAkhil Goyal 11168fd2b5a6SAkhil Goyal /* cipher different than null */ 11178fd2b5a6SAkhil Goyal if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 11188fd2b5a6SAkhil Goyal cipher_xform.cipher.key.data = test_vector->cipher_key.data; 11198fd2b5a6SAkhil Goyal cipher_xform.cipher.key.length = test_vector->cipher_key.length; 11208fd2b5a6SAkhil Goyal } else { 11218fd2b5a6SAkhil Goyal cipher_xform.cipher.key.data = NULL; 11228fd2b5a6SAkhil Goyal cipher_xform.cipher.key.length = 0; 11238fd2b5a6SAkhil Goyal } 11248fd2b5a6SAkhil Goyal 11258fd2b5a6SAkhil Goyal /* Setup Auth Parameters */ 11268fd2b5a6SAkhil Goyal if (options->auth_algo != 0) { 11278fd2b5a6SAkhil Goyal auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 11288fd2b5a6SAkhil Goyal auth_xform.next = NULL; 11298fd2b5a6SAkhil Goyal auth_xform.auth.algo = options->auth_algo; 11308fd2b5a6SAkhil Goyal auth_xform.auth.op = options->auth_op; 11318fd2b5a6SAkhil Goyal auth_xform.auth.iv.offset = iv_offset + 11328fd2b5a6SAkhil Goyal cipher_xform.cipher.iv.length; 11338fd2b5a6SAkhil Goyal 11348fd2b5a6SAkhil Goyal /* auth different than null */ 11358fd2b5a6SAkhil Goyal if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) { 11368fd2b5a6SAkhil Goyal auth_xform.auth.digest_length = options->digest_sz; 11378fd2b5a6SAkhil Goyal auth_xform.auth.key.length = test_vector->auth_key.length; 11388fd2b5a6SAkhil Goyal auth_xform.auth.key.data = test_vector->auth_key.data; 11398fd2b5a6SAkhil Goyal auth_xform.auth.iv.length = test_vector->auth_iv.length; 11408fd2b5a6SAkhil Goyal } else { 11418fd2b5a6SAkhil Goyal auth_xform.auth.digest_length = 0; 11428fd2b5a6SAkhil Goyal auth_xform.auth.key.length = 0; 11438fd2b5a6SAkhil Goyal auth_xform.auth.key.data = NULL; 11448fd2b5a6SAkhil Goyal auth_xform.auth.iv.length = 0; 11458fd2b5a6SAkhil Goyal } 11468fd2b5a6SAkhil Goyal 11478fd2b5a6SAkhil Goyal cipher_xform.next = &auth_xform; 11488fd2b5a6SAkhil Goyal } else { 11498fd2b5a6SAkhil Goyal cipher_xform.next = NULL; 11508fd2b5a6SAkhil Goyal } 11518fd2b5a6SAkhil Goyal 11528fd2b5a6SAkhil Goyal struct rte_security_session_conf sess_conf = { 11538fd2b5a6SAkhil Goyal .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 11548fd2b5a6SAkhil Goyal .protocol = RTE_SECURITY_PROTOCOL_PDCP, 11558fd2b5a6SAkhil Goyal {.pdcp = { 11568fd2b5a6SAkhil Goyal .bearer = 0x16, 11578fd2b5a6SAkhil Goyal .domain = options->pdcp_domain, 11588fd2b5a6SAkhil Goyal .pkt_dir = 0, 11598fd2b5a6SAkhil Goyal .sn_size = options->pdcp_sn_sz, 11605a61bdb9SAkhil Goyal .hfn = options->pdcp_ses_hfn_en ? 11615a61bdb9SAkhil Goyal PDCP_DEFAULT_HFN : 0, 11628fd2b5a6SAkhil Goyal .hfn_threshold = 0x70C0A, 116323a95dfeSGagandeep Singh .sdap_enabled = options->pdcp_sdap, 11645a61bdb9SAkhil Goyal .hfn_ovrd = !(options->pdcp_ses_hfn_en), 11658fd2b5a6SAkhil Goyal } }, 11668fd2b5a6SAkhil Goyal .crypto_xform = &cipher_xform 11678fd2b5a6SAkhil Goyal }; 11688fd2b5a6SAkhil Goyal 116979bdb787SAkhil Goyal void *ctx = rte_cryptodev_get_sec_ctx(dev_id); 11708fd2b5a6SAkhil Goyal 11718fd2b5a6SAkhil Goyal /* Create security session */ 11723f3fc330SAkhil Goyal return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp); 11738fd2b5a6SAkhil Goyal } 117428dde5daSAkhil Goyal 117528dde5daSAkhil Goyal if (options->op_type == CPERF_IPSEC) { 11763f3fc330SAkhil Goyal return create_ipsec_session(sess_mp, dev_id, 117728dde5daSAkhil Goyal options, test_vector, iv_offset); 117828dde5daSAkhil Goyal } 117928dde5daSAkhil Goyal 11809afa7a46SAkhil Goyal if (options->op_type == CPERF_TLS) { 11819afa7a46SAkhil Goyal return create_tls_session(sess_mp, dev_id, 11829afa7a46SAkhil Goyal options, test_vector, iv_offset); 11839afa7a46SAkhil Goyal } 11849afa7a46SAkhil Goyal 1185d4a131a9SDavid Coyle if (options->op_type == CPERF_DOCSIS) { 1186d4a131a9SDavid Coyle enum rte_security_docsis_direction direction; 1187d4a131a9SDavid Coyle 1188d4a131a9SDavid Coyle cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1189d4a131a9SDavid Coyle cipher_xform.next = NULL; 1190d4a131a9SDavid Coyle cipher_xform.cipher.algo = options->cipher_algo; 1191d4a131a9SDavid Coyle cipher_xform.cipher.op = options->cipher_op; 1192d4a131a9SDavid Coyle cipher_xform.cipher.iv.offset = iv_offset; 1193d4a131a9SDavid Coyle if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 1194d4a131a9SDavid Coyle cipher_xform.cipher.key.data = 1195d4a131a9SDavid Coyle test_vector->cipher_key.data; 1196d4a131a9SDavid Coyle cipher_xform.cipher.key.length = 1197d4a131a9SDavid Coyle test_vector->cipher_key.length; 1198d4a131a9SDavid Coyle cipher_xform.cipher.iv.length = 1199d4a131a9SDavid Coyle test_vector->cipher_iv.length; 1200d4a131a9SDavid Coyle } else { 1201d4a131a9SDavid Coyle cipher_xform.cipher.key.data = NULL; 1202d4a131a9SDavid Coyle cipher_xform.cipher.key.length = 0; 1203d4a131a9SDavid Coyle cipher_xform.cipher.iv.length = 0; 1204d4a131a9SDavid Coyle } 1205d4a131a9SDavid Coyle cipher_xform.next = NULL; 1206d4a131a9SDavid Coyle 1207d4a131a9SDavid Coyle if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) 1208d4a131a9SDavid Coyle direction = RTE_SECURITY_DOCSIS_DOWNLINK; 1209d4a131a9SDavid Coyle else 1210d4a131a9SDavid Coyle direction = RTE_SECURITY_DOCSIS_UPLINK; 1211d4a131a9SDavid Coyle 1212d4a131a9SDavid Coyle struct rte_security_session_conf sess_conf = { 1213d4a131a9SDavid Coyle .action_type = 1214d4a131a9SDavid Coyle RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, 1215d4a131a9SDavid Coyle .protocol = RTE_SECURITY_PROTOCOL_DOCSIS, 1216d4a131a9SDavid Coyle {.docsis = { 1217d4a131a9SDavid Coyle .direction = direction, 1218d4a131a9SDavid Coyle } }, 1219d4a131a9SDavid Coyle .crypto_xform = &cipher_xform 1220d4a131a9SDavid Coyle }; 122179bdb787SAkhil Goyal void *ctx = rte_cryptodev_get_sec_ctx(dev_id); 1222d4a131a9SDavid Coyle 1223d4a131a9SDavid Coyle /* Create security session */ 12243f3fc330SAkhil Goyal return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp); 1225d4a131a9SDavid Coyle } 12268fd2b5a6SAkhil Goyal #endif 1227f8be1786SSlawomir Mrozowicz /* 1228f8be1786SSlawomir Mrozowicz * cipher only 1229f8be1786SSlawomir Mrozowicz */ 1230f8be1786SSlawomir Mrozowicz if (options->op_type == CPERF_CIPHER_ONLY) { 1231f8be1786SSlawomir Mrozowicz cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1232f8be1786SSlawomir Mrozowicz cipher_xform.next = NULL; 1233f8be1786SSlawomir Mrozowicz cipher_xform.cipher.algo = options->cipher_algo; 1234f8be1786SSlawomir Mrozowicz cipher_xform.cipher.op = options->cipher_op; 12350fbd75a9SPablo de Lara cipher_xform.cipher.iv.offset = iv_offset; 1236f8be1786SSlawomir Mrozowicz 1237f8be1786SSlawomir Mrozowicz /* cipher different than null */ 1238f8be1786SSlawomir Mrozowicz if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 1239f8be1786SSlawomir Mrozowicz cipher_xform.cipher.key.data = 1240f8be1786SSlawomir Mrozowicz test_vector->cipher_key.data; 1241f8be1786SSlawomir Mrozowicz cipher_xform.cipher.key.length = 1242f8be1786SSlawomir Mrozowicz test_vector->cipher_key.length; 1243acf86169SPablo de Lara cipher_xform.cipher.iv.length = 1244acf86169SPablo de Lara test_vector->cipher_iv.length; 1245884ed3ffSTomasz Kulasek } else { 1246884ed3ffSTomasz Kulasek cipher_xform.cipher.key.data = NULL; 1247884ed3ffSTomasz Kulasek cipher_xform.cipher.key.length = 0; 12480fbd75a9SPablo de Lara cipher_xform.cipher.iv.length = 0; 1249f8be1786SSlawomir Mrozowicz } 1250f8be1786SSlawomir Mrozowicz /* create crypto session */ 1251bdce2564SAkhil Goyal sess = rte_cryptodev_sym_session_create(dev_id, &cipher_xform, 1252bdce2564SAkhil Goyal sess_mp); 1253f8be1786SSlawomir Mrozowicz /* 1254f8be1786SSlawomir Mrozowicz * auth only 1255f8be1786SSlawomir Mrozowicz */ 1256f8be1786SSlawomir Mrozowicz } else if (options->op_type == CPERF_AUTH_ONLY) { 1257f8be1786SSlawomir Mrozowicz auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1258f8be1786SSlawomir Mrozowicz auth_xform.next = NULL; 1259f8be1786SSlawomir Mrozowicz auth_xform.auth.algo = options->auth_algo; 1260f8be1786SSlawomir Mrozowicz auth_xform.auth.op = options->auth_op; 12617925c6beSPablo de Lara auth_xform.auth.iv.offset = iv_offset; 1262f8be1786SSlawomir Mrozowicz 1263f8be1786SSlawomir Mrozowicz /* auth different than null */ 1264f8be1786SSlawomir Mrozowicz if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) { 1265f8be1786SSlawomir Mrozowicz auth_xform.auth.digest_length = 12668a5b494aSPablo de Lara options->digest_sz; 1267f8be1786SSlawomir Mrozowicz auth_xform.auth.key.length = 1268f8be1786SSlawomir Mrozowicz test_vector->auth_key.length; 1269f8be1786SSlawomir Mrozowicz auth_xform.auth.key.data = test_vector->auth_key.data; 1270acf86169SPablo de Lara auth_xform.auth.iv.length = 1271acf86169SPablo de Lara test_vector->auth_iv.length; 1272884ed3ffSTomasz Kulasek } else { 1273884ed3ffSTomasz Kulasek auth_xform.auth.digest_length = 0; 1274884ed3ffSTomasz Kulasek auth_xform.auth.key.length = 0; 1275884ed3ffSTomasz Kulasek auth_xform.auth.key.data = NULL; 1276acf86169SPablo de Lara auth_xform.auth.iv.length = 0; 1277f8be1786SSlawomir Mrozowicz } 1278f8be1786SSlawomir Mrozowicz /* create crypto session */ 1279bdce2564SAkhil Goyal sess = rte_cryptodev_sym_session_create(dev_id, &auth_xform, 1280bdce2564SAkhil Goyal sess_mp); 1281f8be1786SSlawomir Mrozowicz /* 1282f8be1786SSlawomir Mrozowicz * cipher and auth 1283f8be1786SSlawomir Mrozowicz */ 1284f8be1786SSlawomir Mrozowicz } else if (options->op_type == CPERF_CIPHER_THEN_AUTH 12858a5b494aSPablo de Lara || options->op_type == CPERF_AUTH_THEN_CIPHER) { 1286f8be1786SSlawomir Mrozowicz /* 1287f8be1786SSlawomir Mrozowicz * cipher 1288f8be1786SSlawomir Mrozowicz */ 1289f8be1786SSlawomir Mrozowicz cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; 1290f8be1786SSlawomir Mrozowicz cipher_xform.next = NULL; 1291f8be1786SSlawomir Mrozowicz cipher_xform.cipher.algo = options->cipher_algo; 1292f8be1786SSlawomir Mrozowicz cipher_xform.cipher.op = options->cipher_op; 12930fbd75a9SPablo de Lara cipher_xform.cipher.iv.offset = iv_offset; 1294f8be1786SSlawomir Mrozowicz 1295f8be1786SSlawomir Mrozowicz /* cipher different than null */ 1296f8be1786SSlawomir Mrozowicz if (options->cipher_algo != RTE_CRYPTO_CIPHER_NULL) { 1297f8be1786SSlawomir Mrozowicz cipher_xform.cipher.key.data = 1298f8be1786SSlawomir Mrozowicz test_vector->cipher_key.data; 1299f8be1786SSlawomir Mrozowicz cipher_xform.cipher.key.length = 1300f8be1786SSlawomir Mrozowicz test_vector->cipher_key.length; 1301acf86169SPablo de Lara cipher_xform.cipher.iv.length = 1302acf86169SPablo de Lara test_vector->cipher_iv.length; 1303884ed3ffSTomasz Kulasek } else { 1304884ed3ffSTomasz Kulasek cipher_xform.cipher.key.data = NULL; 1305884ed3ffSTomasz Kulasek cipher_xform.cipher.key.length = 0; 13060fbd75a9SPablo de Lara cipher_xform.cipher.iv.length = 0; 1307f8be1786SSlawomir Mrozowicz } 1308f8be1786SSlawomir Mrozowicz 1309f8be1786SSlawomir Mrozowicz /* 1310f8be1786SSlawomir Mrozowicz * auth 1311f8be1786SSlawomir Mrozowicz */ 1312f8be1786SSlawomir Mrozowicz auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; 1313f8be1786SSlawomir Mrozowicz auth_xform.next = NULL; 1314f8be1786SSlawomir Mrozowicz auth_xform.auth.algo = options->auth_algo; 1315f8be1786SSlawomir Mrozowicz auth_xform.auth.op = options->auth_op; 13167925c6beSPablo de Lara auth_xform.auth.iv.offset = iv_offset + 13177925c6beSPablo de Lara cipher_xform.cipher.iv.length; 1318f8be1786SSlawomir Mrozowicz 1319f8be1786SSlawomir Mrozowicz /* auth different than null */ 1320f8be1786SSlawomir Mrozowicz if (options->auth_algo != RTE_CRYPTO_AUTH_NULL) { 13218a5b494aSPablo de Lara auth_xform.auth.digest_length = options->digest_sz; 13228a5b494aSPablo de Lara auth_xform.auth.iv.length = test_vector->auth_iv.length; 1323f8be1786SSlawomir Mrozowicz auth_xform.auth.key.length = 1324f8be1786SSlawomir Mrozowicz test_vector->auth_key.length; 1325f8be1786SSlawomir Mrozowicz auth_xform.auth.key.data = 1326f8be1786SSlawomir Mrozowicz test_vector->auth_key.data; 1327884ed3ffSTomasz Kulasek } else { 1328884ed3ffSTomasz Kulasek auth_xform.auth.digest_length = 0; 1329884ed3ffSTomasz Kulasek auth_xform.auth.key.length = 0; 1330884ed3ffSTomasz Kulasek auth_xform.auth.key.data = NULL; 1331acf86169SPablo de Lara auth_xform.auth.iv.length = 0; 1332f8be1786SSlawomir Mrozowicz } 1333f8be1786SSlawomir Mrozowicz 1334f8be1786SSlawomir Mrozowicz /* cipher then auth */ 1335f8be1786SSlawomir Mrozowicz if (options->op_type == CPERF_CIPHER_THEN_AUTH) { 1336f8be1786SSlawomir Mrozowicz cipher_xform.next = &auth_xform; 1337f8be1786SSlawomir Mrozowicz /* create crypto session */ 1338bdce2564SAkhil Goyal sess = rte_cryptodev_sym_session_create(dev_id, 1339bdce2564SAkhil Goyal &cipher_xform, sess_mp); 1340f8be1786SSlawomir Mrozowicz } else { /* auth then cipher */ 1341f8be1786SSlawomir Mrozowicz auth_xform.next = &cipher_xform; 1342f8be1786SSlawomir Mrozowicz /* create crypto session */ 1343bdce2564SAkhil Goyal sess = rte_cryptodev_sym_session_create(dev_id, 1344bdce2564SAkhil Goyal &auth_xform, sess_mp); 1345f8be1786SSlawomir Mrozowicz } 13468a5b494aSPablo de Lara } else { /* options->op_type == CPERF_AEAD */ 13478a5b494aSPablo de Lara aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; 13488a5b494aSPablo de Lara aead_xform.next = NULL; 13498a5b494aSPablo de Lara aead_xform.aead.algo = options->aead_algo; 13508a5b494aSPablo de Lara aead_xform.aead.op = options->aead_op; 13518a5b494aSPablo de Lara aead_xform.aead.iv.offset = iv_offset; 13528a5b494aSPablo de Lara 13538a5b494aSPablo de Lara aead_xform.aead.key.data = 13548a5b494aSPablo de Lara test_vector->aead_key.data; 13558a5b494aSPablo de Lara aead_xform.aead.key.length = 13568a5b494aSPablo de Lara test_vector->aead_key.length; 13578a5b494aSPablo de Lara aead_xform.aead.iv.length = test_vector->aead_iv.length; 13588a5b494aSPablo de Lara 13598a5b494aSPablo de Lara aead_xform.aead.digest_length = options->digest_sz; 136046a0547fSPablo de Lara aead_xform.aead.aad_length = 13618a5b494aSPablo de Lara options->aead_aad_sz; 13628a5b494aSPablo de Lara 13638a5b494aSPablo de Lara /* Create crypto session */ 1364bdce2564SAkhil Goyal sess = rte_cryptodev_sym_session_create(dev_id, &aead_xform, 1365bdce2564SAkhil Goyal sess_mp); 1366f8be1786SSlawomir Mrozowicz } 13678a5b494aSPablo de Lara 1368f8be1786SSlawomir Mrozowicz return sess; 1369f8be1786SSlawomir Mrozowicz } 1370f8be1786SSlawomir Mrozowicz 1371f8be1786SSlawomir Mrozowicz int 1372f8be1786SSlawomir Mrozowicz cperf_get_op_functions(const struct cperf_options *options, 1373f8be1786SSlawomir Mrozowicz struct cperf_op_fns *op_fns) 1374f8be1786SSlawomir Mrozowicz { 1375f8be1786SSlawomir Mrozowicz memset(op_fns, 0, sizeof(struct cperf_op_fns)); 1376f8be1786SSlawomir Mrozowicz 1377f8be1786SSlawomir Mrozowicz op_fns->sess_create = cperf_create_session; 1378f8be1786SSlawomir Mrozowicz 137928dde5daSAkhil Goyal switch (options->op_type) { 138028dde5daSAkhil Goyal case CPERF_AEAD: 1381f8be1786SSlawomir Mrozowicz op_fns->populate_ops = cperf_set_ops_aead; 138228dde5daSAkhil Goyal break; 13838a5b494aSPablo de Lara 138428dde5daSAkhil Goyal case CPERF_AUTH_THEN_CIPHER: 138528dde5daSAkhil Goyal case CPERF_CIPHER_THEN_AUTH: 1386f8be1786SSlawomir Mrozowicz op_fns->populate_ops = cperf_set_ops_cipher_auth; 138728dde5daSAkhil Goyal break; 138828dde5daSAkhil Goyal case CPERF_AUTH_ONLY: 1389f8be1786SSlawomir Mrozowicz if (options->auth_algo == RTE_CRYPTO_AUTH_NULL) 1390f8be1786SSlawomir Mrozowicz op_fns->populate_ops = cperf_set_ops_null_auth; 1391f8be1786SSlawomir Mrozowicz else 1392f8be1786SSlawomir Mrozowicz op_fns->populate_ops = cperf_set_ops_auth; 139328dde5daSAkhil Goyal break; 139428dde5daSAkhil Goyal case CPERF_CIPHER_ONLY: 1395f8be1786SSlawomir Mrozowicz if (options->cipher_algo == RTE_CRYPTO_CIPHER_NULL) 1396f8be1786SSlawomir Mrozowicz op_fns->populate_ops = cperf_set_ops_null_cipher; 1397f8be1786SSlawomir Mrozowicz else 1398f8be1786SSlawomir Mrozowicz op_fns->populate_ops = cperf_set_ops_cipher; 139928dde5daSAkhil Goyal break; 140028dde5daSAkhil Goyal case CPERF_ASYM_MODEX: 1401b82742f9SAkhil Goyal op_fns->populate_ops = cperf_set_ops_asym_modex; 1402b82742f9SAkhil Goyal break; 1403195a271eSGowrishankar Muthukrishnan case CPERF_ASYM_SECP256R1: 1404195a271eSGowrishankar Muthukrishnan op_fns->populate_ops = cperf_set_ops_asym_ecdsa; 1405195a271eSGowrishankar Muthukrishnan break; 1406*981a1ed3SGowrishankar Muthukrishnan case CPERF_ASYM_ED25519: 1407*981a1ed3SGowrishankar Muthukrishnan op_fns->populate_ops = cperf_set_ops_asym_eddsa; 1408*981a1ed3SGowrishankar Muthukrishnan break; 1409b82742f9SAkhil Goyal case CPERF_ASYM_SM2: 1410b82742f9SAkhil Goyal op_fns->populate_ops = cperf_set_ops_asym_sm2; 141128dde5daSAkhil Goyal break; 1412a8d0d473SBruce Richardson #ifdef RTE_LIB_SECURITY 141328dde5daSAkhil Goyal case CPERF_PDCP: 141428dde5daSAkhil Goyal case CPERF_DOCSIS: 14158fd2b5a6SAkhil Goyal op_fns->populate_ops = cperf_set_ops_security; 141628dde5daSAkhil Goyal break; 1417fa609d94SAnoob Joseph case CPERF_IPSEC: 1418fa609d94SAnoob Joseph op_fns->populate_ops = cperf_set_ops_security_ipsec; 1419fa609d94SAnoob Joseph break; 14209afa7a46SAkhil Goyal case CPERF_TLS: 14219afa7a46SAkhil Goyal op_fns->populate_ops = cperf_set_ops_security_tls; 14229afa7a46SAkhil Goyal break; 14238fd2b5a6SAkhil Goyal #endif 142428dde5daSAkhil Goyal default: 1425f8be1786SSlawomir Mrozowicz return -1; 1426f8be1786SSlawomir Mrozowicz } 142728dde5daSAkhil Goyal 142828dde5daSAkhil Goyal return 0; 142928dde5daSAkhil Goyal } 1430