From patchwork Thu Apr 7 16:45:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Kusztal X-Patchwork-Id: 109437 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A037EA0505; Thu, 7 Apr 2022 18:45:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8205A4068B; Thu, 7 Apr 2022 18:45:48 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id F02BE40689 for ; Thu, 7 Apr 2022 18:45:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649349946; x=1680885946; h=from:to:cc:subject:date:message-id; bh=mNOzmSQFdunUeukvI9CYnOquv8fBAex2gHtAyH8l+nc=; b=ITjZ+aYIgSsj7YHdooo9zGfyCXM902aO3l5S1wflYDYySgE3dC7wt3lH 9Z44d2UlqYSKfF+kx8y9wlTUDavxOInUeDrZ4zUPfxEguMo+YEvAgzniy vC/Bv5J6hJN8JKVbyVj1Z7g/H4I5XHSG6sMNOexK6wBWuU+R6UjxT5dsG TukkJTBGbeIBCCaxsYpfy5oisOIiiepkU6kgfrxG536OGMebh9uwwbIy3 ZM1hCQt8MyN6STRhAqlSN2SWRquUqYwMOEsvRDTO3FwPxONzHMBI4/obd 02puQ5clr+nRRX3n47JS4EsSnRWPf8JDmyhG/p7hOSGKNbhYdz+6Q9D21 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10310"; a="324540460" X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="324540460" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 09:45:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="550141338" Received: from silpixa00400308.ir.intel.com ([10.237.214.95]) by orsmga007.jf.intel.com with ESMTP; 07 Apr 2022 09:45:22 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: gakhil@marvell.com, roy.fan.zhang@intel.com, Arek Kusztal Subject: [PATCH] crypto/qat: add ec point verify function Date: Thu, 7 Apr 2022 17:45:20 +0100 Message-Id: <20220407164520.20996-1-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.17.1 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org This commit adds elliptic curve point verification to Intel QuickAssist Technology PMD. Signed-off-by: Arek Kusztal Acked-by: Fan Zhang --- Depends-on: patch-109436 ("cryptodev: add dh verify option") drivers/common/qat/qat_adf/qat_pke.h | 24 ++++++++++++++ drivers/crypto/qat/qat_asym.c | 64 +++++++++++++++++++++++++++++++++++- 2 files changed, 87 insertions(+), 1 deletion(-) diff --git a/drivers/common/qat/qat_adf/qat_pke.h b/drivers/common/qat/qat_adf/qat_pke.h index c727e4e1af..5c6569adf5 100644 --- a/drivers/common/qat/qat_adf/qat_pke.h +++ b/drivers/common/qat/qat_adf/qat_pke.h @@ -326,4 +326,28 @@ get_ecpm_function(struct rte_crypto_asym_xform *xform) return qat_function; } +static struct qat_asym_function +get_ec_verify_function(struct rte_crypto_asym_xform *xform) +{ + struct qat_asym_function qat_function; + + switch (xform->ec.curve_id) { + case RTE_CRYPTO_EC_GROUP_SECP256R1: + qat_function.func_id = MATHS_POINT_VERIFY_GFP_L256; + qat_function.bytesize = 32; + break; + case RTE_CRYPTO_EC_GROUP_SECP384R1: + qat_function.func_id = MATHS_POINT_VERIFY_GFP_L512; + qat_function.bytesize = 64; + break; + case RTE_CRYPTO_EC_GROUP_SECP521R1: + qat_function.func_id = MATHS_POINT_VERIFY_GFP_521; + qat_function.bytesize = 66; + break; + default: + qat_function.func_id = 0; + } + return qat_function; +} + #endif diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c index 5dccd26201..8f27219583 100644 --- a/drivers/crypto/qat/qat_asym.c +++ b/drivers/crypto/qat/qat_asym.c @@ -831,7 +831,7 @@ dh_mod_set_input(struct rte_crypto_asym_op *asym_op, } static int -ecdh_set_input(struct rte_crypto_asym_op *asym_op, +ecdh_set_input_phase(struct rte_crypto_asym_op *asym_op, struct icp_qat_fw_pke_request *qat_req, struct qat_asym_op_cookie *cookie, struct rte_crypto_asym_xform *xform) @@ -888,6 +888,65 @@ ecdh_set_input(struct rte_crypto_asym_op *asym_op, } static int +ecdh_set_input_verify(struct rte_crypto_asym_op *asym_op, + struct icp_qat_fw_pke_request *qat_req, + struct qat_asym_op_cookie *cookie, + struct rte_crypto_asym_xform *xform) +{ + struct qat_asym_function qat_function; + uint32_t qat_func_alignsize, func_id; + int curve_id; + + curve_id = pick_curve(xform); + if (curve_id < 0) { + QAT_LOG(DEBUG, "Incorrect elliptic curve"); + return -EINVAL; + } + + qat_function = get_ec_verify_function(xform); + func_id = qat_function.func_id; + if (func_id == 0) { + QAT_LOG(ERR, "Cannot obtain functionality id"); + return -EINVAL; + } + qat_func_alignsize = RTE_ALIGN_CEIL(qat_function.bytesize, 8); + + SET_PKE_LN(asym_op->dh.pub_point.x, qat_func_alignsize, 0); + SET_PKE_LN(asym_op->dh.pub_point.y, qat_func_alignsize, 1); + SET_PKE_LN_EC(curve[curve_id], p, 2); + SET_PKE_LN_EC(curve[curve_id], a, 3); + SET_PKE_LN_EC(curve[curve_id], b, 4); + + cookie->alg_bytesize = curve[curve_id].bytesize; + cookie->qat_func_alignsize = qat_func_alignsize; + qat_req->pke_hdr.cd_pars.func_id = func_id; + qat_req->input_param_count = + 5; + qat_req->output_param_count = + 0; + + HEXDUMP("x", cookie->input_array[0], qat_func_alignsize); + HEXDUMP("y", cookie->input_array[1], qat_func_alignsize); + HEXDUMP("p", cookie->input_array[2], qat_func_alignsize); + HEXDUMP("a", cookie->input_array[3], qat_func_alignsize); + HEXDUMP("b", cookie->input_array[4], qat_func_alignsize); + + return 0; +} + +static int +ecdh_set_input(struct rte_crypto_asym_op *asym_op, + struct icp_qat_fw_pke_request *qat_req, + struct qat_asym_op_cookie *cookie, + struct rte_crypto_asym_xform *xform) +{ + if (asym_op->dh.op_type == RTE_CRYPTO_ASYM_OP_KEY_VERIFY) + return ecdh_set_input_verify(asym_op, qat_req, cookie, xform); + else + return ecdh_set_input_phase(asym_op, qat_req, cookie, xform); +} + +static int dh_set_input(struct rte_crypto_asym_op *asym_op, struct icp_qat_fw_pke_request *qat_req, struct qat_asym_op_cookie *cookie, @@ -935,6 +994,9 @@ ecdh_collect(struct rte_crypto_asym_op *asym_op, uint32_t qat_func_alignsize = cookie->qat_func_alignsize; uint32_t ltrim = qat_func_alignsize - alg_bytesize; + if (asym_op->dh.op_type == RTE_CRYPTO_ASYM_OP_KEY_VERIFY) + return RTE_CRYPTO_OP_STATUS_SUCCESS; + if (asym_op->dh.op_type == RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE) { asym_op->dh.pub_point.x.length = alg_bytesize; asym_op->dh.pub_point.y.length = alg_bytesize;