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 D87BBA0505; Thu, 7 Apr 2022 16:38:08 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 74D484068B; Thu, 7 Apr 2022 16:38:08 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id 2DEB740689 for ; Thu, 7 Apr 2022 16:38:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649342286; x=1680878286; h=from:to:cc:subject:date:message-id; bh=a3Oxd+IwNite7nYoxrnAXHTCUskcIa6oRdL2O38MkPQ=; b=QxbEZ7GFgW/7Dll/5SKtFguyfnM88u5cC/DjdaG0xtwvC29hVMJ0rB+E JafXKMWEf/X5m/EJmDI360ZmrrxxkYt/EJuUqgiWfL8juv5OcwYAJknsR GeYEYtqQNhwozLWrcKOeUwgUwEfmdupyeLnmFQps6KTaOivmWQOwoRbv9 RI0Ze3qzyIUrdU0gVC7dqqtpp4n5tDbHAgFbI4O73ltkCdA43jPPxFa1k 4LOCnie36SXkp2z8Af27eB7Xbx6OE0+fcxWDBXAw++pNwHpgOjRRXxOFV 7Ve1TC9L7uWTelg3G0oK1cFZWFSONWx9Romqv6W0y/dTg2tK+UnlsW2RD g==; X-IronPort-AV: E=McAfee;i="6400,9594,10309"; a="286321334" X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="286321334" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 07:37:57 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="524945996" Received: from silpixa00400308.ir.intel.com ([10.237.214.95]) by orsmga006.jf.intel.com with ESMTP; 07 Apr 2022 07:37:54 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: gakhil@marvell.com, roy.fan.zhang@intel.com, Arek Kusztal Subject: [PATCH] crypto/qat: add ecdh key exchange algorithm Date: Thu, 7 Apr 2022 15:37:52 +0100 Message-Id: <20220407143752.20456-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 Diffie-Hellman algorithm to Intel QuickAssist Technology PMD. Signed-off-by: Arek Kusztal --- Depends-on: patch-109409 ("cryptodev: add elliptic curve diffie hellman") drivers/crypto/qat/qat_asym.c | 95 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c index c2a985b355..5dccd26201 100644 --- a/drivers/crypto/qat/qat_asym.c +++ b/drivers/crypto/qat/qat_asym.c @@ -831,6 +831,63 @@ dh_mod_set_input(struct rte_crypto_asym_op *asym_op, } 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) +{ + 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->dh.op_type == RTE_CRYPTO_ASYM_OP_PUBLIC_KEY_GENERATE) { + SET_PKE_LN(asym_op->dh.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->dh.priv_key, qat_func_alignsize, 0); + SET_PKE_LN(asym_op->dh.pub_point.x, qat_func_alignsize, 1); + SET_PKE_LN(asym_op->dh.pub_point.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 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, @@ -839,6 +896,8 @@ dh_set_input(struct rte_crypto_asym_op *asym_op, switch (xform->xform_type) { case RTE_CRYPTO_ASYM_XFORM_DH: return dh_mod_set_input(asym_op, qat_req, cookie, xform); + case RTE_CRYPTO_ASYM_XFORM_ECDH: + return ecdh_set_input(asym_op, qat_req, cookie, xform); default: QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform type"); @@ -866,6 +925,38 @@ dh_collect(struct rte_crypto_asym_op *asym_op, return RTE_CRYPTO_OP_STATUS_SUCCESS; } +static uint8_t +ecdh_collect(struct rte_crypto_asym_op *asym_op, + struct qat_asym_op_cookie *cookie, + 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->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; + x = asym_op->dh.pub_point.x.data; + y = asym_op->dh.pub_point.y.data; + } else { + asym_op->dh.shared_point.x.length = alg_bytesize; + asym_op->dh.shared_point.y.length = alg_bytesize; + x = asym_op->dh.shared_point.x.data; + y = asym_op->dh.shared_point.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 rte_crypto_asym_op *asym_op, struct icp_qat_fw_pke_request *qat_req, @@ -880,6 +971,7 @@ asym_set_input(struct rte_crypto_asym_op *asym_op, return modinv_set_input(asym_op, qat_req, cookie, xform); case RTE_CRYPTO_ASYM_XFORM_DH: + case RTE_CRYPTO_ASYM_XFORM_ECDH: return dh_set_input(asym_op, qat_req, cookie, xform); case RTE_CRYPTO_ASYM_XFORM_RSA: @@ -973,6 +1065,8 @@ qat_asym_collect_response(struct rte_crypto_op *op, return modinv_collect(asym_op, cookie, xform); case RTE_CRYPTO_ASYM_XFORM_DH: return dh_collect(asym_op, cookie, xform); + case RTE_CRYPTO_ASYM_XFORM_ECDH: + return ecdh_collect(asym_op, cookie, xform); case RTE_CRYPTO_ASYM_XFORM_RSA: return rsa_collect(asym_op, cookie); case RTE_CRYPTO_ASYM_XFORM_ECDSA: @@ -1276,6 +1370,7 @@ qat_asym_session_configure(struct rte_cryptodev *dev __rte_unused, break; case RTE_CRYPTO_ASYM_XFORM_ECDSA: case RTE_CRYPTO_ASYM_XFORM_ECPM: + case RTE_CRYPTO_ASYM_XFORM_ECDH: session_set_ecdsa(qat_session, xform); break; default: -- 2.13.6