From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 52470A0032; Wed, 17 Aug 2022 10:04:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 58C32427F4; Wed, 17 Aug 2022 10:04:33 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id D7DD141147 for ; Wed, 17 Aug 2022 10:04:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1660723471; x=1692259471; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=kXyAsGJVAWAjAcioPPGtGAvWsVOjpUUKuunwvUFfOeE=; b=fy8aOI1GwsCJ7FmGbzC1NnqynPCa8Cv7rFAGJNQGmUHNCEjRm4fdPx1Q aa3ihq4V1duB4+KCj2lpAJsFAEzbLyf2+fgpOOQnGugNqRVCfQAx2U4l6 8l5y4ikAXGqzXGCi26DSycv7487hEHfqRUr2fmA4E7/7eg518oACEoUSy ZW+/guesbSKeSYGHi4f+abju2KmnvsQ1dzfA7FPHTUWNeWFM9VWMTIlZE JwonqTR9WsZwHHZKZp9Y7xeDqw5LiwSYibhCHQcfNhjatpnApNAaaM4f+ 1C9T09gUu9E9qbJ6OAHZAkqEDFoRGa9pcpXKzZqcOHtj0YESaVSJcVe/t w==; X-IronPort-AV: E=McAfee;i="6400,9594,10441"; a="354176555" X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="354176555" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Aug 2022 01:04:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,242,1654585200"; d="scan'208";a="733595835" Received: from silpixa00399302.ir.intel.com ([10.237.214.136]) by orsmga004.jf.intel.com with ESMTP; 17 Aug 2022 01:04:29 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: gakhil@marvell.com, kai.ji@intel.com, Arek Kusztal Subject: [PATCH 2/3] crypto/qat: add ecdh key exchange algorithm Date: Wed, 17 Aug 2022 07:55:35 +0100 Message-Id: <20220817065536.79716-3-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20220817065536.79716-1-arkadiuszx.kusztal@intel.com> References: <20220817065536.79716-1-arkadiuszx.kusztal@intel.com> 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 ECDH algorithm to Intel QuickAssist Technology driver. Signed-off-by: Arek Kusztal --- drivers/crypto/qat/qat_asym.c | 94 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c index 374452020a..34fb3f5a45 100644 --- a/drivers/crypto/qat/qat_asym.c +++ b/drivers/crypto/qat/qat_asym.c @@ -760,6 +760,95 @@ ecpm_collect(struct rte_crypto_asym_op *asym_op, } static int +ecdh_set_input(struct icp_qat_fw_pke_request *qat_req, + struct qat_asym_op_cookie *cookie, + const struct rte_crypto_asym_op *asym_op, + const 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_ecpm_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); + + if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) { + SET_PKE_LN(asym_op->ecdh.priv_key, qat_func_alignsize, 0); + SET_PKE_LN_EC(curve[curve_id], x, 1); + SET_PKE_LN_EC(curve[curve_id], y, 2); + } else { + SET_PKE_LN(asym_op->ecdh.priv_key, qat_func_alignsize, 0); + SET_PKE_LN(asym_op->ecdh.pub_key.x, qat_func_alignsize, 1); + SET_PKE_LN(asym_op->ecdh.pub_key.y, qat_func_alignsize, 2); + } + SET_PKE_LN_EC(curve[curve_id], a, 3); + SET_PKE_LN_EC(curve[curve_id], b, 4); + SET_PKE_LN_EC(curve[curve_id], p, 5); + SET_PKE_LN_EC(curve[curve_id], h, 6); + + 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 = + QAT_ASYM_ECPM_IN_PARAMS; + qat_req->output_param_count = + QAT_ASYM_ECPM_OUT_PARAMS; + + HEXDUMP("k", cookie->input_array[0], qat_func_alignsize); + HEXDUMP("xG", cookie->input_array[1], qat_func_alignsize); + HEXDUMP("yG", 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); + HEXDUMP("q", cookie->input_array[5], qat_func_alignsize); + HEXDUMP("h", cookie->input_array[6], qat_func_alignsize); + + return 0; +} + +static uint8_t +ecdh_collect(struct rte_crypto_asym_op *asym_op, + const struct qat_asym_op_cookie *cookie, + const struct rte_crypto_asym_xform *xform) +{ + uint8_t *x, *y; + uint32_t alg_bytesize = cookie->alg_bytesize; + uint32_t qat_func_alignsize = cookie->qat_func_alignsize; + uint32_t ltrim = qat_func_alignsize - alg_bytesize; + + if (asym_op->ecdh.ke_type == RTE_CRYPTO_ASYM_KE_PUB_KEY_GENERATE) { + asym_op->ecdh.pub_key.x.length = alg_bytesize; + asym_op->ecdh.pub_key.y.length = alg_bytesize; + x = asym_op->ecdh.pub_key.x.data; + y = asym_op->ecdh.pub_key.y.data; + } else { + asym_op->ecdh.shared_secret.x.length = alg_bytesize; + asym_op->ecdh.shared_secret.y.length = alg_bytesize; + x = asym_op->ecdh.shared_secret.x.data; + y = asym_op->ecdh.shared_secret.y.data; + } + + rte_memcpy(x, &cookie->output_array[0][ltrim], alg_bytesize); + rte_memcpy(y, &cookie->output_array[1][ltrim], alg_bytesize); + + HEXDUMP("X", cookie->output_array[0], + qat_func_alignsize); + HEXDUMP("Y", cookie->output_array[1], + qat_func_alignsize); + return RTE_CRYPTO_OP_STATUS_SUCCESS; +} + +static int asym_set_input(struct icp_qat_fw_pke_request *qat_req, struct qat_asym_op_cookie *cookie, const struct rte_crypto_asym_op *asym_op, @@ -781,6 +870,9 @@ asym_set_input(struct icp_qat_fw_pke_request *qat_req, case RTE_CRYPTO_ASYM_XFORM_ECPM: return ecpm_set_input(qat_req, cookie, asym_op, xform); + case RTE_CRYPTO_ASYM_XFORM_ECDH: + return ecdh_set_input(qat_req, cookie, + asym_op, xform); default: QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform"); return -EINVAL; @@ -867,6 +959,8 @@ qat_asym_collect_response(struct rte_crypto_op *op, return ecdsa_collect(asym_op, cookie); case RTE_CRYPTO_ASYM_XFORM_ECPM: return ecpm_collect(asym_op, cookie); + case RTE_CRYPTO_ASYM_XFORM_ECDH: + return ecdh_collect(asym_op, cookie, xform); default: QAT_LOG(ERR, "Not supported xform type"); return RTE_CRYPTO_OP_STATUS_ERROR; -- 2.13.6