From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 83B48A04F2; Thu, 5 Dec 2019 16:39:47 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0B6D01BF97; Thu, 5 Dec 2019 16:39:34 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 730871BF92 for ; Thu, 5 Dec 2019 16:39:32 +0100 (CET) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xB5FaBmC028491; Thu, 5 Dec 2019 07:39:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0818; bh=8L+i69wSfsb86NAv3c/UzrQqcLGZP8WfQZfpDZTtUYI=; b=m7hJ+IoZlDuCFLbt9yhZoJdfSaZzJRJiVef9ccptYoR7tejZGY3qGq1MyDlfe/DwzXaa zmRL/hl1RFR9Gk2s1dTsLT9q1UsQ2dfOU4vBoRkmLuxyKAuFcjAM68lQhGhXkAcVBQSz aX6xkovYoD4BT8UCaENBlmVon2wTNg6W3tjOwy0AcWY8bJ/7saY2huRjMwG54PLGcJhQ jAsUELSsoc+C0/rhXP7p2GZTZ2dCOEqwqwsrXYmy0fumiEu9vOWAcEfV+ASsZF0/Hzz+ r3m0WpIUYJjwfGsE5ZU2N7nL//vTI+7+xlwcgf3pyQHK0gIf437LWMgMCMh2YUnl8IZj WA== Received: from sc-exch01.marvell.com ([199.233.58.181]) by mx0a-0016f401.pphosted.com with ESMTP id 2wpywp140t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Thu, 05 Dec 2019 07:39:31 -0800 Received: from SC-EXCH01.marvell.com (10.93.176.81) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Thu, 5 Dec 2019 07:39:30 -0800 Received: from maili.marvell.com (10.93.176.43) by SC-EXCH01.marvell.com (10.93.176.81) with Microsoft SMTP Server id 15.0.1367.3 via Frontend Transport; Thu, 5 Dec 2019 07:39:30 -0800 Received: from ajoseph83.caveonetworks.com.com (unknown [10.29.45.60]) by maili.marvell.com (Postfix) with ESMTP id 3A0EA3F7041; Thu, 5 Dec 2019 07:39:25 -0800 (PST) From: Anoob Joseph To: Akhil Goyal , Declan Doherty , Pablo de Lara CC: Sunila Sahu , Fiona Trahe , "Arek Kusztal" , Jerin Jacob , Narayana Prasad , Shally Verma , Ankur Dwivedi , , Anoob Joseph , Balakrishna Bhamidipati Date: Thu, 5 Dec 2019 21:07:58 +0530 Message-ID: <1575560280-3261-3-git-send-email-anoobj@marvell.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1575560280-3261-1-git-send-email-anoobj@marvell.com> References: <1575560280-3261-1-git-send-email-anoobj@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95,18.0.572 definitions=2019-12-05_03:2019-12-04,2019-12-05 signatures=0 Subject: [dpdk-dev] [PATCH 2/4] crypto/octeontx: add EC Point Mul support X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Sunila Sahu Adding support for EC Point Multiplication operation in crypto_octeontx PMD. Signed-off-by: Anoob Joseph Signed-off-by: Balakrishna Bhamidipati Signed-off-by: Sunila Sahu --- doc/guides/cryptodevs/features/octeontx.ini | 1 + drivers/common/cpt/cpt_mcode_defines.h | 2 + drivers/common/cpt/cpt_ucode_asym.h | 85 ++++++++++++++++++++++ .../crypto/octeontx/otx_cryptodev_capabilities.c | 11 +++ drivers/crypto/octeontx/otx_cryptodev_ops.c | 23 ++++++ 5 files changed, 122 insertions(+) diff --git a/doc/guides/cryptodevs/features/octeontx.ini b/doc/guides/cryptodevs/features/octeontx.ini index 544bb46..3cc807a 100644 --- a/doc/guides/cryptodevs/features/octeontx.ini +++ b/doc/guides/cryptodevs/features/octeontx.ini @@ -73,3 +73,4 @@ Modular Exponentiation = Y Modular Inversion = Diffie-hellman = ECDSA = Y +EC Point Multiplication = Y diff --git a/drivers/common/cpt/cpt_mcode_defines.h b/drivers/common/cpt/cpt_mcode_defines.h index 64d3e8c..d830bef 100644 --- a/drivers/common/cpt/cpt_mcode_defines.h +++ b/drivers/common/cpt/cpt_mcode_defines.h @@ -24,6 +24,7 @@ /* AE opcodes */ #define CPT_MAJOR_OP_MODEX 0x03 #define CPT_MAJOR_OP_ECDSA 0x04 +#define CPT_MAJOR_OP_ECC 0x05 #define CPT_MINOR_OP_MODEX 0x01 #define CPT_MINOR_OP_PKCS_ENC 0x02 #define CPT_MINOR_OP_PKCS_ENC_CRT 0x03 @@ -32,6 +33,7 @@ #define CPT_MINOR_OP_MODEX_CRT 0x06 #define CPT_MINOR_OP_ECDSA_SIGN 0x01 #define CPT_MINOR_OP_ECDSA_VERIFY 0x02 +#define CPT_MINOR_OP_ECC_UMP 0x03 #define CPT_BLOCK_TYPE1 0 #define CPT_BLOCK_TYPE2 1 diff --git a/drivers/common/cpt/cpt_ucode_asym.h b/drivers/common/cpt/cpt_ucode_asym.h index 1f76bd1..9a54d34 100644 --- a/drivers/common/cpt/cpt_ucode_asym.h +++ b/drivers/common/cpt/cpt_ucode_asym.h @@ -172,6 +172,8 @@ cpt_fill_asym_session_parameters(struct cpt_asym_sess_misc *sess, ret = cpt_fill_modex_params(sess, xform); break; case RTE_CRYPTO_ASYM_XFORM_ECDSA: + /* Fall through */ + case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL: ret = cpt_fill_ec_params(sess, xform); break; default: @@ -199,6 +201,8 @@ cpt_free_asym_session_parameters(struct cpt_asym_sess_misc *sess) rte_free(mod->modulus.data); break; case RTE_CRYPTO_ASYM_XFORM_ECDSA: + /* Fall through */ + case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL: break; default: CPT_LOG_DP_ERR("Invalid transform type"); @@ -828,4 +832,85 @@ cpt_enqueue_ecdsa_op(struct rte_crypto_op *op, return 0; } +static __rte_always_inline int +cpt_ecpm_prep(struct rte_crypto_ec_point_mul_param *ecpm, + struct asym_op_params *asym_params, + uint8_t curveid) +{ + struct cpt_request_info *req = asym_params->req; + phys_addr_t mphys = asym_params->meta_buf; + uint16_t x1_len = ecpm->p.x.length; + uint16_t y1_len = ecpm->p.y.length; + uint16_t scalar_align, p_align; + uint16_t dlen, rlen, prime_len; + uint16_t x1_offset, y1_offset; + vq_cmd_word0_t vq_cmd_w0; + opcode_info_t opcode; + buf_ptr_t caddr; + uint8_t *dptr; + + prime_len = ec_grp[curveid].prime.length; + + /* Input buffer */ + dptr = RTE_PTR_ADD(req, sizeof(struct cpt_request_info)); + + p_align = ROUNDUP8(prime_len); + scalar_align = ROUNDUP8(ecpm->scalar.length); + + /* + * Set dlen = sum(ROUNDUP8(input point(x and y coordinates), prime, + * scalar length), + * Please note point length is equivalent to prime of the curve + */ + dlen = 3 * p_align + scalar_align; + + x1_offset = prime_len - x1_len; + y1_offset = prime_len - y1_len; + + memset(dptr, 0, dlen); + + /* Copy input point, scalar, prime */ + memcpy(dptr + x1_offset, ecpm->p.x.data, x1_len); + dptr += p_align; + memcpy(dptr + y1_offset, ecpm->p.y.data, y1_len); + dptr += p_align; + memcpy(dptr, ecpm->scalar.data, ecpm->scalar.length); + dptr += scalar_align; + memcpy(dptr, ec_grp[curveid].prime.data, ec_grp[curveid].prime.length); + dptr += p_align; + + /* Setup opcodes */ + opcode.s.major = CPT_MAJOR_OP_ECC; + opcode.s.minor = CPT_MINOR_OP_ECC_UMP; + + /* GP op header */ + vq_cmd_w0.s.opcode = opcode.flags; + vq_cmd_w0.s.param1 = curveid; + vq_cmd_w0.s.param2 = ecpm->scalar.length; + vq_cmd_w0.s.dlen = dlen; + vq_cmd_w0.u64 = vq_cmd_w0.u64; + + /* Filling cpt_request_info structure */ + req->ist.ei0 = vq_cmd_w0.u64; + req->ist.ei1 = mphys; + req->ist.ei2 = mphys + dlen; + + /* Result buffer will store output point where length of + * each coordinate will be of prime length, thus set + * rlen to twice of prime length. + */ + rlen = p_align << 1; + req->rptr = dptr; + + /* alternate_caddr to write completion status by the microcode */ + req->alternate_caddr = (uint64_t *)(dptr + rlen); + *req->alternate_caddr = ~((uint64_t)COMPLETION_CODE_INIT); + + /* Preparing completion addr, +1 for completion code */ + caddr.vaddr = dptr + rlen + 1; + caddr.dma_addr = mphys + dlen + rlen + 1; + + cpt_fill_req_comp_addr(req, caddr); + return 0; +} #endif /* _CPT_UCODE_ASYM_H_ */ diff --git a/drivers/crypto/octeontx/otx_cryptodev_capabilities.c b/drivers/crypto/octeontx/otx_cryptodev_capabilities.c index 6418ad2..22f34ad 100644 --- a/drivers/crypto/octeontx/otx_cryptodev_capabilities.c +++ b/drivers/crypto/octeontx/otx_cryptodev_capabilities.c @@ -641,6 +641,17 @@ static const struct rte_cryptodev_capabilities otx_asym_capabilities[] = { }, } }, + { /* EC POINT MUL */ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, + {.asym = { + .xform_capa = { + .xform_type = + RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL, + .op_types = 0 + } + }, + } + }, /* End of asymmetric capabilities */ RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST() }; diff --git a/drivers/crypto/octeontx/otx_cryptodev_ops.c b/drivers/crypto/octeontx/otx_cryptodev_ops.c index f97ce3a..e7520d5 100644 --- a/drivers/crypto/octeontx/otx_cryptodev_ops.c +++ b/drivers/crypto/octeontx/otx_cryptodev_ops.c @@ -443,6 +443,13 @@ otx_cpt_enq_single_asym(struct cpt_instance *instance, if (unlikely(ret)) goto req_fail; break; + case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL: + ret = cpt_ecpm_prep(&asym_op->ecpm, ¶ms, + sess->ec_ctx.curveid); + if (unlikely(ret)) + goto req_fail; + break; + default: op->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; ret = -EINVAL; @@ -704,6 +711,19 @@ otx_cpt_asym_dequeue_ecdsa_op(struct rte_crypto_ecdsa_op_param *ecdsa, ecdsa->s.length = prime_len; } +static __rte_always_inline void +otx_cpt_asym_dequeue_ecpm_op(struct rte_crypto_ec_point_mul_param *ecpm, + struct cpt_request_info *req, + struct cpt_asym_ec_ctx *ec) +{ + int prime_len = ec_grp[ec->curveid].prime.length; + + memcpy(ecpm->r.x.data, req->rptr, prime_len); + memcpy(ecpm->r.y.data, req->rptr + ROUNDUP8(prime_len), prime_len); + ecpm->r.x.length = prime_len; + ecpm->r.y.length = prime_len; +} + static __rte_always_inline void __hot otx_cpt_asym_post_process(struct rte_crypto_op *cop, struct cpt_request_info *req) @@ -726,6 +746,9 @@ otx_cpt_asym_post_process(struct rte_crypto_op *cop, case RTE_CRYPTO_ASYM_XFORM_ECDSA: otx_cpt_asym_dequeue_ecdsa_op(&op->ecdsa, req, &sess->ec_ctx); break; + case RTE_CRYPTO_ASYM_XFORM_EC_POINT_MUL: + otx_cpt_asym_dequeue_ecpm_op(&op->ecpm, req, &sess->ec_ctx); + break; default: CPT_LOG_DP_DEBUG("Invalid crypto xform type"); cop->status = RTE_CRYPTO_OP_STATUS_INVALID_ARGS; -- 2.7.4