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 v2 3/5] crypto/qat: add ecdsa algorithm
Date: Wed, 9 Feb 2022 14:00:18 +0000 [thread overview]
Message-ID: <20220209140020.19365-4-arkadiuszx.kusztal@intel.com> (raw)
In-Reply-To: <20220209140020.19365-1-arkadiuszx.kusztal@intel.com>
This patch adds ECDSA algorithm to Intel
QuickAssist Technology PMD.
Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
doc/guides/cryptodevs/qat.rst | 1 +
doc/guides/rel_notes/release_22_03.rst | 5 ++
drivers/common/qat/qat_adf/qat_pke.h | 40 +++++++++
drivers/crypto/qat/qat_asym.c | 148 +++++++++++++++++++++++++++++++++
drivers/crypto/qat/qat_asym.h | 4 +
5 files changed, 198 insertions(+)
diff --git a/doc/guides/cryptodevs/qat.rst b/doc/guides/cryptodevs/qat.rst
index 4428b89195..0f8fecf4df 100644
--- a/doc/guides/cryptodevs/qat.rst
+++ b/doc/guides/cryptodevs/qat.rst
@@ -175,6 +175,7 @@ The QAT ASYM PMD has support for:
* ``RTE_CRYPTO_ASYM_XFORM_MODEX``
* ``RTE_CRYPTO_ASYM_XFORM_MODINV``
* ``RTE_CRYPTO_ASYM_XFORM_RSA``
+* ``RTE_CRYPTO_ASYM_XFORM_ECDSA``
Limitations
~~~~~~~~~~~
diff --git a/doc/guides/rel_notes/release_22_03.rst b/doc/guides/rel_notes/release_22_03.rst
index 746f50e84f..1d7e0c1425 100644
--- a/doc/guides/rel_notes/release_22_03.rst
+++ b/doc/guides/rel_notes/release_22_03.rst
@@ -73,6 +73,11 @@ New Features
The new API ``rte_event_eth_rx_adapter_event_port_get()`` was added.
+* **Updated Intel QuickAssist Technology asymmetric crypto PMD.**
+
+ * ECDSA algorithm is now supported by Intel QuickAssist
+ Technology asymmetric crypto PMD.
+
Removed Items
-------------
diff --git a/drivers/common/qat/qat_adf/qat_pke.h b/drivers/common/qat/qat_adf/qat_pke.h
index 82bb1ee55e..1fe5f6bd8e 100644
--- a/drivers/common/qat/qat_adf/qat_pke.h
+++ b/drivers/common/qat/qat_adf/qat_pke.h
@@ -212,4 +212,44 @@ get_rsa_crt_function(struct rte_crypto_asym_xform *xform)
return qat_function;
}
+static struct qat_asym_function
+get_ecdsa_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 = PKE_ECDSA_VERIFY_GFP_L256;
+ qat_function.bytesize = 32;
+ break;
+ case RTE_CRYPTO_EC_GROUP_SECP521R1:
+ qat_function.func_id = PKE_ECDSA_VERIFY_GFP_521;
+ qat_function.bytesize = 66;
+ break;
+ default:
+ qat_function.func_id = 0;
+ }
+ return qat_function;
+}
+
+static struct qat_asym_function
+get_ecdsa_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_ECDSA_SIGN_RS_GFP_L256;
+ qat_function.bytesize = 32;
+ break;
+ case RTE_CRYPTO_EC_GROUP_SECP521R1:
+ qat_function.func_id = PKE_ECDSA_SIGN_RS_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 fe93e263d0..59e7c5140c 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -10,14 +10,24 @@
#include "qat_pke.h"
#include "qat_ec.h"
+/*
+ * Macros with suffix _F are used with some of predefinded identifiers:
+ * - cookie->input_buffer
+ * - qat_alg_bytesize
+ */
#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
#define HEXDUMP(name, where, size) QAT_DP_HEXDUMP_LOG(DEBUG, name, \
where, size)
#define HEXDUMP_OFF(name, where, size, idx) QAT_DP_HEXDUMP_LOG(DEBUG, name, \
&where[idx * size], size)
+
+#define HEXDUMP_OFF_F(name, idx) QAT_DP_HEXDUMP_LOG(DEBUG, name, \
+ &cookie->input_buffer[idx * qat_alg_bytesize], \
+ qat_alg_bytesize)
#else
#define HEXDUMP(name, where, size)
#define HEXDUMP_OFF(name, where, size, idx)
+#define HEXDUMP_OFF_F(name, idx)
#endif
#define CHECK_IF_NOT_EMPTY(param, name, pname, status) \
@@ -58,6 +68,17 @@
what.data, \
how)
+#define SET_PKE_LN_9A_F(what, idx) \
+ rte_memcpy(&cookie->input_buffer[idx * qat_alg_bytesize] + \
+ qat_alg_bytesize - what.length, \
+ what.data, what.length)
+
+#define SET_PKE_LN_EC_F(what, how, idx) \
+ rte_memcpy(&cookie->input_buffer[idx * \
+ RTE_ALIGN_CEIL(how, 8)] + \
+ RTE_ALIGN_CEIL(how, 8) - how, \
+ what.data, how)
+
static void
request_init(struct icp_qat_fw_pke_request *qat_req)
{
@@ -523,6 +544,128 @@ rsa_collect(struct rte_crypto_asym_op *asym_op,
return RTE_CRYPTO_OP_STATUS_SUCCESS;
}
+static int
+ecdsa_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 alg_bytesize, qat_alg_bytesize, func_id;
+ int curve_id;
+
+ curve_id = pick_curve(xform);
+ if (curve_id < 0) {
+ QAT_LOG(ERR, "Incorrect elliptic curve");
+ return -EINVAL;
+ }
+
+ switch (asym_op->ecdsa.op_type) {
+ case RTE_CRYPTO_ASYM_OP_SIGN:
+ qat_function = get_ecdsa_function(xform);
+ func_id = qat_function.func_id;
+ if (func_id == 0) {
+ QAT_LOG(ERR, "Cannot obtain functionality id");
+ return -EINVAL;
+ }
+ alg_bytesize = qat_function.bytesize;
+ qat_alg_bytesize = RTE_ALIGN_CEIL(alg_bytesize, 8);
+
+ SET_PKE_LN_9A_F(asym_op->ecdsa.pkey, 0);
+ SET_PKE_LN_9A_F(asym_op->ecdsa.message, 1);
+ SET_PKE_LN_9A_F(asym_op->ecdsa.k, 2);
+ SET_PKE_LN_EC_F(curve[curve_id].b, alg_bytesize, 3);
+ SET_PKE_LN_EC_F(curve[curve_id].a, alg_bytesize, 4);
+ SET_PKE_LN_EC_F(curve[curve_id].p, alg_bytesize, 5);
+ SET_PKE_LN_EC_F(curve[curve_id].n, alg_bytesize, 6);
+ SET_PKE_LN_EC_F(curve[curve_id].y, alg_bytesize, 7);
+ SET_PKE_LN_EC_F(curve[curve_id].x, alg_bytesize, 8);
+
+ cookie->alg_bytesize = alg_bytesize;
+ qat_req->pke_hdr.cd_pars.func_id = func_id;
+ qat_req->input_param_count =
+ QAT_ASYM_ECDSA_RS_SIGN_IN_PARAMS;
+ qat_req->output_param_count =
+ QAT_ASYM_ECDSA_RS_SIGN_OUT_PARAMS;
+
+ HEXDUMP_OFF_F("ECDSA d", 0);
+ HEXDUMP_OFF_F("ECDSA e", 1);
+ HEXDUMP_OFF_F("ECDSA k", 2);
+ HEXDUMP_OFF_F("ECDSA b", 3);
+ HEXDUMP_OFF_F("ECDSA a", 4);
+ HEXDUMP_OFF_F("ECDSA n", 5);
+ HEXDUMP_OFF_F("ECDSA y", 6);
+ HEXDUMP_OFF_F("ECDSA x", 7);
+ break;
+ case RTE_CRYPTO_ASYM_OP_VERIFY:
+ qat_function = get_ecdsa_verify_function(xform);
+ func_id = qat_function.func_id;
+ if (func_id == 0) {
+ QAT_LOG(ERR, "Cannot obtain functionality id");
+ return -EINVAL;
+ }
+ alg_bytesize = qat_function.bytesize;
+ qat_alg_bytesize = RTE_ALIGN_CEIL(alg_bytesize, 8);
+
+ SET_PKE_LN_9A_F(asym_op->ecdsa.message, 10);
+ SET_PKE_LN_9A_F(asym_op->ecdsa.s, 9);
+ SET_PKE_LN_9A_F(asym_op->ecdsa.r, 8);
+ SET_PKE_LN_EC_F(curve[curve_id].n, alg_bytesize, 7);
+ SET_PKE_LN_EC_F(curve[curve_id].x, alg_bytesize, 6);
+ SET_PKE_LN_EC_F(curve[curve_id].y, alg_bytesize, 5);
+ SET_PKE_LN_9A_F(asym_op->ecdsa.q.x, 4);
+ SET_PKE_LN_9A_F(asym_op->ecdsa.q.y, 3);
+ SET_PKE_LN_EC_F(curve[curve_id].a, alg_bytesize, 2);
+ SET_PKE_LN_EC_F(curve[curve_id].b, alg_bytesize, 1);
+ SET_PKE_LN_EC_F(curve[curve_id].p, alg_bytesize, 0);
+
+ cookie->alg_bytesize = alg_bytesize;
+ qat_req->pke_hdr.cd_pars.func_id = func_id;
+ qat_req->input_param_count =
+ QAT_ASYM_ECDSA_RS_VERIFY_IN_PARAMS;
+ qat_req->output_param_count =
+ QAT_ASYM_ECDSA_RS_VERIFY_OUT_PARAMS;
+
+ HEXDUMP_OFF_F("e", 0);
+ HEXDUMP_OFF_F("s", 1);
+ HEXDUMP_OFF_F("r", 2);
+ HEXDUMP_OFF_F("n", 3);
+ HEXDUMP_OFF_F("xG", 4);
+ HEXDUMP_OFF_F("yG", 5);
+ HEXDUMP_OFF_F("xQ", 6);
+ HEXDUMP_OFF_F("yQ", 7);
+ HEXDUMP_OFF_F("a", 8);
+ HEXDUMP_OFF_F("b", 9);
+ HEXDUMP_OFF_F("q", 10);
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+static uint8_t
+ecdsa_collect(struct rte_crypto_asym_op *asym_op,
+ struct qat_asym_op_cookie *cookie)
+{
+ uint32_t alg_bytesize = RTE_ALIGN_CEIL(cookie->alg_bytesize, 8);
+
+ if (asym_op->rsa.op_type == RTE_CRYPTO_ASYM_OP_SIGN) {
+ uint8_t *r = asym_op->ecdsa.r.data;
+ uint8_t *s = asym_op->ecdsa.s.data;
+
+ asym_op->ecdsa.r.length = alg_bytesize;
+ asym_op->ecdsa.s.length = alg_bytesize;
+ rte_memcpy(r, cookie->output_array[0], alg_bytesize);
+ rte_memcpy(s, cookie->output_array[1], alg_bytesize);
+ HEXDUMP("R", cookie->output_array[0],
+ alg_bytesize);
+ HEXDUMP("S", cookie->output_array[1],
+ alg_bytesize);
+ }
+ return RTE_CRYPTO_OP_STATUS_SUCCESS;
+}
static int
asym_set_input(struct rte_crypto_asym_op *asym_op,
@@ -540,6 +683,9 @@ asym_set_input(struct rte_crypto_asym_op *asym_op,
case RTE_CRYPTO_ASYM_XFORM_RSA:
return rsa_set_input(asym_op, qat_req,
cookie, xform);
+ case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+ return ecdsa_set_input(asym_op, qat_req,
+ cookie, xform);
default:
QAT_LOG(ERR, "Invalid/unsupported asymmetric crypto xform");
return -EINVAL;
@@ -613,6 +759,8 @@ qat_asym_collect_response(struct rte_crypto_op *rx_op,
return modinv_collect(asym_op, cookie, xform);
case RTE_CRYPTO_ASYM_XFORM_RSA:
return rsa_collect(asym_op, cookie);
+ case RTE_CRYPTO_ASYM_XFORM_ECDSA:
+ return ecdsa_collect(asym_op, cookie);
default:
QAT_LOG(ERR, "Not supported xform type");
return RTE_CRYPTO_OP_STATUS_ERROR;
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index ed4367ac4d..9344e48eb4 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -25,6 +25,10 @@ typedef uint64_t large_int_ptr;
#define QAT_ASYM_RSA_NUM_IN_PARAMS 3
#define QAT_ASYM_RSA_NUM_OUT_PARAMS 1
#define QAT_ASYM_RSA_QT_NUM_IN_PARAMS 6
+#define QAT_ASYM_ECDSA_RS_SIGN_IN_PARAMS 1
+#define QAT_ASYM_ECDSA_RS_SIGN_OUT_PARAMS 2
+#define QAT_ASYM_ECDSA_RS_VERIFY_IN_PARAMS 1
+#define QAT_ASYM_ECDSA_RS_VERIFY_OUT_PARAMS 0
struct qat_asym_op_cookie {
size_t alg_bytesize;
--
2.13.6
next prev parent reply other threads:[~2022-02-09 14:01 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 14:00 [PATCH v2 0/5] crypto/qat: add asymmetric crypto algorithms Arek Kusztal
2022-02-09 14:00 ` [PATCH v2 1/5] crypto/qat: refactor asymmetric crypto functions Arek Kusztal
2022-02-09 14:00 ` [PATCH v2 2/5] crypto/qat: add named elliptic curves Arek Kusztal
2022-02-09 14:00 ` Arek Kusztal [this message]
2022-02-09 14:00 ` [PATCH v2 4/5] crypto/qat: add ecpm algorithm Arek Kusztal
2022-02-09 14:00 ` [PATCH v2 5/5] crypto/qat: refactor asymmetric session Arek Kusztal
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=20220209140020.19365-4-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).