DPDK patches and discussions
 help / color / mirror / Atom feed
From: Arek Kusztal <arkadiuszx.kusztal@intel.com>
To: dev@dpdk.org
Cc: gakhil@marvell.com, roy.fan.zhang@intel.com,
	Arek Kusztal <arkadiuszx.kusztal@intel.com>
Subject: [PATCH 2/2] crypto/qat: add gen4 ecpm functions
Date: Fri,  8 Apr 2022 08:58:13 +0100	[thread overview]
Message-ID: <20220408075813.23316-3-arkadiuszx.kusztal@intel.com> (raw)
In-Reply-To: <20220408075813.23316-1-arkadiuszx.kusztal@intel.com>

This commit adds functions to use ecpm named
curves. This will speed up calculation
of multiplication for curves P-256 and P-384.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 .../common/qat/qat_adf/icp_qat_fw_mmp_ids.h   | 42 ++++++++++++
 drivers/common/qat/qat_adf/qat_pke.h          | 20 ++++++
 drivers/crypto/qat/qat_asym.c                 | 67 ++++++++++++++++++-
 3 files changed, 127 insertions(+), 2 deletions(-)

diff --git a/drivers/common/qat/qat_adf/icp_qat_fw_mmp_ids.h b/drivers/common/qat/qat_adf/icp_qat_fw_mmp_ids.h
index 9276f954f1..5a92393b40 100644
--- a/drivers/common/qat/qat_adf/icp_qat_fw_mmp_ids.h
+++ b/drivers/common/qat/qat_adf/icp_qat_fw_mmp_ids.h
@@ -1524,6 +1524,48 @@ icp_qat_fw_mmp_ecdsa_verify_gfp_521_input::in in @endlink
  * icp_qat_fw_mmp_kpt_ecdsa_sign_rs_gfp_521_output::s s @endlink
  */
 
+#define PKE_EC_GENERATOR_MULTIPLICATION_P256 0x12073556
+/**< Functionality ID for ECC P256 Generator Point Multiplication [k]G(x)
+ * @li 1 input parameters : @link
+ * icp_qat_fw_mmp_ec_p256_generator_multiplication_input_s::k k @endlink
+ * @li 2 output parameters : @link
+ * icp_qat_fw_mmp_ec_p256_generator_multiplication_output_s::xr xr @endlink
+ * @link icp_qat_fw_mmp_ec_p256_generator_multiplication_output_s::yr yr
+ * @endlink
+ */
+
+#define PKE_EC_GENERATOR_MULTIPLICATION_P384 0x0b073596
+/**< Functionality ID for ECC P384 Generator Point Multiplication [k]G(x)
+ * @li 1 input parameters : @link
+ * icp_qat_fw_mmp_ec_p384_generator_multiplication_input_s::k k @endlink
+ * @li 2 output parameters : @link
+ * icp_qat_fw_mmp_ec_p384_generator_multiplication_output_s::xr xr @endlink
+ * @link icp_qat_fw_mmp_ec_p384_generator_multiplication_output_s::yr yr
+ * @endlink
+ */
+
+#define PKE_EC_POINT_MULTIPLICATION_P256 0x0a083546
+/**< Functionality ID for ECC P256 Variable Point Multiplication [k]P(x)
+ * @li 3 input parameters : @link
+ * icp_qat_fw_mmp_ec_p256_point_multiplication_input_s::xp xp @endlink @link
+ * icp_qat_fw_mmp_ec_p256_point_multiplication_input_s::yp yp @endlink @link
+ * icp_qat_fw_mmp_ec_p256_point_multiplication_input_s::k k @endlink
+ * @li 2 output parameters : @link
+ * icp_qat_fw_mmp_ec_p256_point_multiplication_output_s::xr xr @endlink @link
+ * icp_qat_fw_mmp_ec_p256_point_multiplication_output_s::yr yr @endlink
+ */
+
+#define PKE_EC_POINT_MULTIPLICATION_P384 0x0b083586
+/**< Functionality ID for ECC P384 Variable Point Multiplication [k]P(x)
+ * @li 3 input parameters : @link
+ * icp_qat_fw_mmp_ec_p384_point_multiplication_input_s::xp xp @endlink @link
+ * icp_qat_fw_mmp_ec_p384_point_multiplication_input_s::yp yp @endlink @link
+ * icp_qat_fw_mmp_ec_p384_point_multiplication_input_s::k k @endlink
+ * @li 2 output parameters : @link
+ * icp_qat_fw_mmp_ec_p384_point_multiplication_output_s::xr xr @endlink @link
+ * icp_qat_fw_mmp_ec_p384_point_multiplication_output_s::yr yr @endlink
+ */
+
 #define PKE_ECDSA_SIGN_RS_P256 0x18133566
 /**< Functionality ID for ECC P256 ECDSA Sign RS
  * @li 3 input parameters : @link icp_qat_fw_mmp_ecdsa_sign_rs_p256_input_s::k k
diff --git a/drivers/common/qat/qat_adf/qat_pke.h b/drivers/common/qat/qat_adf/qat_pke.h
index 87b6a383b3..4c3afabb05 100644
--- a/drivers/common/qat/qat_adf/qat_pke.h
+++ b/drivers/common/qat/qat_adf/qat_pke.h
@@ -310,4 +310,24 @@ get_ecpm_function(struct rte_crypto_asym_xform *xform)
 	return qat_function;
 }
 
+static struct qat_asym_function
+get_ecpm_named_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 = PKE_EC_POINT_MULTIPLICATION_P256;
+		qat_function.bytesize = 32;
+		break;
+	case RTE_CRYPTO_EC_GROUP_SECP384R1:
+		qat_function.func_id = PKE_EC_POINT_MULTIPLICATION_P384;
+		qat_function.bytesize = 48;
+		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 0ac2bf7405..860046d446 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -739,7 +739,7 @@ ecdsa_collect(struct rte_crypto_asym_op *asym_op,
 }
 
 static int
-ecpm_set_input(struct rte_crypto_asym_op *asym_op,
+ecpm_set_generic_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)
@@ -789,6 +789,69 @@ ecpm_set_input(struct rte_crypto_asym_op *asym_op,
 	return 0;
 }
 
+static int
+ecpm_set_named_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_named_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->ecpm.p.x, qat_func_alignsize, 0);
+	SET_PKE_LN(asym_op->ecpm.p.y, qat_func_alignsize, 1);
+	SET_PKE_LN(asym_op->ecpm.scalar, qat_func_alignsize, 2);
+
+	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 =
+			3;
+	qat_req->output_param_count =
+			2;
+
+	HEXDUMP("x", cookie->input_array[0], qat_func_alignsize);
+	HEXDUMP("y", cookie->input_array[1], qat_func_alignsize);
+	HEXDUMP("scalar", cookie->input_array[2], qat_func_alignsize);
+
+	return 0;
+}
+
+static int
+ecpm_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,
+		enum qat_device_gen qat_dev_gen)
+{
+	if (qat_dev_gen >= QAT_GEN4 && (xform->ec.curve_id ==
+			RTE_CRYPTO_EC_GROUP_SECP256R1
+			|| xform->ec.curve_id ==
+				RTE_CRYPTO_EC_GROUP_SECP384R1)) {
+		return ecpm_set_named_input(asym_op, qat_req,
+				cookie,	xform);
+	} else {
+		return ecpm_set_generic_input(asym_op, qat_req,
+				cookie,	xform);
+	}
+	return 0;
+}
+
 static uint8_t
 ecpm_collect(struct rte_crypto_asym_op *asym_op,
 		struct qat_asym_op_cookie *cookie)
@@ -833,7 +896,7 @@ asym_set_input(struct rte_crypto_asym_op *asym_op,
 				cookie, xform, qat_dev_gen);
 	case RTE_CRYPTO_ASYM_XFORM_ECPM:
 		return ecpm_set_input(asym_op, qat_req,
-				cookie, xform);
+				cookie, xform, qat_dev_gen);
 	default:
 		QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform");
 		return -EINVAL;
-- 
2.30.2


  parent reply	other threads:[~2022-04-08  7:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08  7:58 [PATCH 0/2] crypto/qat: add gen4 ecdsa and " Arek Kusztal
2022-04-08  7:58 ` [PATCH 1/2] crypto/qat: add gen4 ecdsa functions Arek Kusztal
2022-06-17 10:50   ` Zhang, Roy Fan
2022-04-08  7:58 ` Arek Kusztal [this message]
2022-06-17 10:50   ` [PATCH 2/2] crypto/qat: add gen4 ecpm functions Zhang, Roy Fan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220408075813.23316-3-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=roy.fan.zhang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).