DPDK patches and discussions
 help / color / mirror / Atom feed
From: Arek Kusztal <arkadiuszx.kusztal@intel.com>
To: dev@dpdk.org
Cc: akhil.goyal@nxp.com, fiona.trahe@intel.com,
	Arek Kusztal <arkadiuszx.kusztal@intel.com>
Subject: [dpdk-dev] [PATCH v5 4/4] crypto/qat: add modular inverse to qat asym pmd
Date: Thu, 28 Mar 2019 14:37:03 +0100	[thread overview]
Message-ID: <20190328133703.2736-5-arkadiuszx.kusztal@intel.com> (raw)
Message-ID: <20190328133703._caGNieOOswvCLlJ9PdscG9SUZBLt58ouOHA0ewwlOg@z> (raw)
In-Reply-To: <20190328133703.2736-1-arkadiuszx.kusztal@intel.com>

This commit adds modular multiplicative inverse to Intel
QuickAssist Technology driver. For capabilities or limitations
please refer to qat.rst or qat_asym_capabilities.h.

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 doc/guides/cryptodevs/qat.rst                      |  1 +
 .../qat/qat_adf/qat_pke_functionality_arrays.h     |  4 +-
 drivers/crypto/qat/qat_asym.c                      | 85 +++++++++++++++++++++-
 drivers/crypto/qat/qat_asym.h                      |  3 +
 drivers/crypto/qat/qat_asym_capabilities.h         | 16 ++++
 5 files changed, 106 insertions(+), 3 deletions(-)

diff --git a/doc/guides/cryptodevs/qat.rst b/doc/guides/cryptodevs/qat.rst
index e09ae8b..3c2467d 100644
--- a/doc/guides/cryptodevs/qat.rst
+++ b/doc/guides/cryptodevs/qat.rst
@@ -107,6 +107,7 @@ Asymmetric Crypto Service on QAT
 The QAT Asym PMD has support for:
 
 * ``Modular exponentiation``
+* ``Modular multiplicative inverse``
 
 Limitations
 ~~~~~~~~~~~
diff --git a/drivers/common/qat/qat_adf/qat_pke_functionality_arrays.h b/drivers/common/qat/qat_adf/qat_pke_functionality_arrays.h
index ffea27e..8adf209 100644
--- a/drivers/common/qat/qat_adf/qat_pke_functionality_arrays.h
+++ b/drivers/common/qat/qat_adf/qat_pke_functionality_arrays.h
@@ -21,7 +21,7 @@ static const uint32_t MOD_EXP_SIZE[][2] = {
 		{ 4096, MATHS_MODEXP_L4096 }
 };
 
-static const uint32_t __rte_unused MOD_INV_IDS_ODD[][2] = {
+static const uint32_t MOD_INV_IDS_ODD[][2] = {
 		{ 128,	MATHS_MODINV_ODD_L128 },
 		{ 192,	MATHS_MODINV_ODD_L192 },
 		{ 256,  MATHS_MODINV_ODD_L256 },
@@ -35,7 +35,7 @@ static const uint32_t __rte_unused MOD_INV_IDS_ODD[][2] = {
 		{ 4096, MATHS_MODINV_ODD_L4096 },
 };
 
-static const uint32_t __rte_unused MOD_INV_IDS_EVEN[][2] = {
+static const uint32_t MOD_INV_IDS_EVEN[][2] = {
 		{ 128,	MATHS_MODINV_EVEN_L128 },
 		{ 192,	MATHS_MODINV_EVEN_L192 },
 		{ 256,	MATHS_MODINV_EVEN_L256 },
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 6cd6435..4ddb0e5 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -54,6 +54,9 @@ static void qat_asym_build_req_tmpl(void *sess_private_data,
 	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX) {
 		qat_req->output_param_count = 1;
 		qat_req->input_param_count = 3;
+	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
+		qat_req->output_param_count = 1;
+		qat_req->input_param_count = 2;
 	}
 }
 
@@ -147,7 +150,8 @@ qat_asym_build_request(void *in_op,
 	if (ctx->alg == QAT_PKE_MODEXP) {
 		err = qat_asym_check_nonzero(ctx->sess_alg_params.mod_exp.n);
 		if (err) {
-			QAT_LOG(ERR, "Empty modulus, aborting this operation");
+			QAT_LOG(ERR, "Empty modulus in modular exponentiation,"
+					" aborting this operation");
 			goto error;
 		}
 
@@ -189,6 +193,56 @@ qat_asym_build_request(void *in_op,
 				cookie->input_array[2],
 				alg_size_in_bytes);
 #endif
+	} else if (ctx->alg == QAT_PKE_MODINV) {
+		err = qat_asym_check_nonzero(ctx->sess_alg_params.mod_inv.n);
+		if (err) {
+			QAT_LOG(ERR, "Empty modulus in modular multiplicative"
+					" inverse, aborting this operation");
+			goto error;
+		}
+
+		alg_size_in_bytes = max_of(2, asym_op->modinv.base.length,
+				ctx->sess_alg_params.mod_inv.n.length);
+		alg_size = alg_size_in_bytes << 3;
+
+		if (ctx->sess_alg_params.mod_inv.n.data[
+				ctx->sess_alg_params.mod_inv.n.length - 1] & 0x01) {
+			if (qat_asym_get_sz_and_func_id(MOD_INV_IDS_ODD,
+					sizeof(MOD_INV_IDS_ODD)/
+					sizeof(*MOD_INV_IDS_ODD),
+					&alg_size, &func_id)) {
+				err = QAT_ASYM_ERROR_INVALID_PARAM;
+				goto error;
+			}
+		} else {
+			if (qat_asym_get_sz_and_func_id(MOD_INV_IDS_EVEN,
+					sizeof(MOD_INV_IDS_EVEN)/
+					sizeof(*MOD_INV_IDS_EVEN),
+					&alg_size, &func_id)) {
+				err = QAT_ASYM_ERROR_INVALID_PARAM;
+				goto error;
+			}
+		}
+
+		alg_size_in_bytes = alg_size >> 3;
+		rte_memcpy(cookie->input_array[0] + alg_size_in_bytes -
+			asym_op->modinv.base.length
+				, asym_op->modinv.base.data,
+				asym_op->modinv.base.length);
+		rte_memcpy(cookie->input_array[1] + alg_size_in_bytes -
+				ctx->sess_alg_params.mod_inv.n.length
+				, ctx->sess_alg_params.mod_inv.n.data,
+				ctx->sess_alg_params.mod_inv.n.length);
+		cookie->alg_size = alg_size;
+		qat_req->pke_hdr.cd_pars.func_id = func_id;
+#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
+		QAT_DP_HEXDUMP_LOG(DEBUG, "base",
+				cookie->input_array[0],
+				alg_size_in_bytes);
+		QAT_DP_HEXDUMP_LOG(DEBUG, "modulus",
+				cookie->input_array[1],
+				alg_size_in_bytes);
+#endif
 	}
 
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
@@ -262,6 +316,26 @@ qat_asym_process_response(void **op, uint8_t *resp,
 		}
 		qat_clear_arrays(cookie, 3, 1, alg_size_in_bytes,
 				alg_size_in_bytes);
+	} else if (ctx->alg == QAT_PKE_MODINV) {
+		alg_size = cookie->alg_size;
+		alg_size_in_bytes = alg_size >> 3;
+		uint8_t *modinv_result = asym_op->modinv.result.data;
+
+		if (rx_op->status == RTE_CRYPTO_OP_STATUS_NOT_PROCESSED) {
+			rte_memcpy(modinv_result + (asym_op->modinv.result.length
+				- ctx->sess_alg_params.mod_inv.n.length),
+				cookie->output_array[0] + alg_size_in_bytes
+				- ctx->sess_alg_params.mod_inv.n.length,
+				ctx->sess_alg_params.mod_inv.n.length);
+			rx_op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;
+#if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
+			QAT_DP_HEXDUMP_LOG(DEBUG, "modinv_result",
+					cookie->output_array[0],
+					alg_size_in_bytes);
+#endif
+		}
+		qat_clear_arrays(cookie, 2, 1, alg_size_in_bytes,
+			alg_size_in_bytes);
 	}
 
 #if RTE_LOG_DP_LEVEL >= RTE_LOG_DEBUG
@@ -298,6 +372,15 @@ qat_asym_session_configure(struct rte_cryptodev *dev,
 			err = -EINVAL;
 			goto error;
 		}
+	} else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV) {
+		session->sess_alg_params.mod_inv.n = xform->modinv.modulus;
+		session->alg = QAT_PKE_MODINV;
+
+		if (xform->modinv.modulus.length == 0) {
+			QAT_LOG(ERR, "Invalid mod inv input parameter");
+			err = -EINVAL;
+			goto error;
+		}
 	} else {
 		QAT_LOG(ERR, "Invalid asymmetric crypto xform");
 		err = -EINVAL;
diff --git a/drivers/crypto/qat/qat_asym.h b/drivers/crypto/qat/qat_asym.h
index 228d2f7..ce4839b 100644
--- a/drivers/crypto/qat/qat_asym.h
+++ b/drivers/crypto/qat/qat_asym.h
@@ -50,6 +50,9 @@ struct qat_asym_session {
 			rte_crypto_param n;
 			rte_crypto_param e;
 		} mod_exp;
+		struct {
+			rte_crypto_param n;
+		} mod_inv;
 	} sess_alg_params;
 };
 
diff --git a/drivers/crypto/qat/qat_asym_capabilities.h b/drivers/crypto/qat/qat_asym_capabilities.h
index 1d6323f..f43c025 100644
--- a/drivers/crypto/qat/qat_asym_capabilities.h
+++ b/drivers/crypto/qat/qat_asym_capabilities.h
@@ -21,6 +21,22 @@
 			}							\
 		},								\
 		}								\
+	},									\
+	{	/* modinv */							\
+		.op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC,				\
+		{.asym = {							\
+			.xform_capa = {						\
+				.xform_type = RTE_CRYPTO_ASYM_XFORM_MODINV,	\
+				.op_types = 0,					\
+				{						\
+				.modlen = {					\
+				.min = 1,					\
+				.max = 512,					\
+				.increment = 1					\
+				}, }						\
+			}							\
+		},								\
+		}								\
 	}									\
 
 #endif /* _QAT_ASYM_CAPABILITIES_H_ */
-- 
2.1.0


  parent reply	other threads:[~2019-03-28 13:39 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-28 13:36 [dpdk-dev] [PATCH v5 0/4] Add PMD for asymmetric cryptography operations using Intel QuickAssist Technology devices Arek Kusztal
2019-03-28 13:36 ` Arek Kusztal
2019-03-28 13:37 ` [dpdk-dev] [PATCH v5 1/4] common/qat: add headers for asymmetric crypto Arek Kusztal
2019-03-28 13:37   ` Arek Kusztal
2019-03-28 13:37 ` [dpdk-dev] [PATCH v5 2/4] crypto/qat: add asymmetric cryptography PMD Arek Kusztal
2019-03-28 13:37   ` Arek Kusztal
2019-04-03  8:42   ` Akhil Goyal
2019-04-03  8:42     ` Akhil Goyal
2019-04-03  9:05     ` Kusztal, ArkadiuszX
2019-04-03  9:05       ` Kusztal, ArkadiuszX
2019-03-28 13:37 ` [dpdk-dev] [PATCH v5 3/4] crypto/qat: add modular exponentiation to qat asym pmd Arek Kusztal
2019-03-28 13:37   ` Arek Kusztal
2019-03-28 13:37 ` Arek Kusztal [this message]
2019-03-28 13:37   ` [dpdk-dev] [PATCH v5 4/4] crypto/qat: add modular inverse " Arek Kusztal
2019-03-28 13:57 ` [dpdk-dev] [PATCH v5 0/4] Add PMD for asymmetric cryptography operations using Intel QuickAssist Technology devices Trahe, Fiona
2019-03-28 13:57   ` Trahe, Fiona
2019-03-29 14:27   ` Akhil Goyal
2019-03-29 14:27     ` Akhil Goyal

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=20190328133703.2736-5-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=akhil.goyal@nxp.com \
    --cc=dev@dpdk.org \
    --cc=fiona.trahe@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).