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] crypto/qat: fix smaller modulus cases for mod exp
Date: Tue,  1 Mar 2022 14:16:16 +0000	[thread overview]
Message-ID: <20220301141616.31821-1-arkadiuszx.kusztal@intel.com> (raw)

This patches fixes not working cases when modulus is
smaller than other arguments.

Fixes: 109755f0a427 ("crypto/qat: refactor asymmetric crypto functions")

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/common/qat/qat_adf/qat_pke.h | 24 +++++++++++++++---------
 drivers/crypto/qat/qat_asym.c        | 12 ++++++++++--
 2 files changed, 25 insertions(+), 11 deletions(-)

diff --git a/drivers/common/qat/qat_adf/qat_pke.h b/drivers/common/qat/qat_adf/qat_pke.h
index 092fc373de..b5fb2a020c 100644
--- a/drivers/common/qat/qat_adf/qat_pke.h
+++ b/drivers/common/qat/qat_adf/qat_pke.h
@@ -17,32 +17,32 @@ struct qat_asym_function {
 };
 
 static struct qat_asym_function
-get_modexp_function(struct rte_crypto_asym_xform *xform)
+get_modexp_function2(uint32_t bytesize)
 {
 	struct qat_asym_function qat_function = { };
 
-	if (xform->modex.modulus.length <= 64) {
+	if (bytesize <= 64) {
 		qat_function.func_id = MATHS_MODEXP_L512;
 		qat_function.bytesize = 64;
-	} else if (xform->modex.modulus.length <= 128) {
+	} else if (bytesize <= 128) {
 		qat_function.func_id = MATHS_MODEXP_L1024;
 		qat_function.bytesize = 128;
-	} else if (xform->modex.modulus.length <= 192) {
+	} else if (bytesize <= 192) {
 		qat_function.func_id = MATHS_MODEXP_L1536;
 		qat_function.bytesize = 192;
-	} else if (xform->modex.modulus.length <= 256) {
+	} else if (bytesize <= 256) {
 		qat_function.func_id = MATHS_MODEXP_L2048;
 		qat_function.bytesize = 256;
-	} else if (xform->modex.modulus.length <= 320) {
+	} else if (bytesize <= 320) {
 		qat_function.func_id = MATHS_MODEXP_L2560;
 		qat_function.bytesize = 320;
-	} else if (xform->modex.modulus.length <= 384) {
+	} else if (bytesize <= 384) {
 		qat_function.func_id = MATHS_MODEXP_L3072;
 		qat_function.bytesize = 384;
-	} else if (xform->modex.modulus.length <= 448) {
+	} else if (bytesize <= 448) {
 		qat_function.func_id = MATHS_MODEXP_L3584;
 		qat_function.bytesize = 448;
-	} else if (xform->modex.modulus.length <= 512) {
+	} else if (bytesize <= 512) {
 		qat_function.func_id = MATHS_MODEXP_L4096;
 		qat_function.bytesize = 512;
 	}
@@ -50,6 +50,12 @@ get_modexp_function(struct rte_crypto_asym_xform *xform)
 }
 
 static struct qat_asym_function
+get_modexp_function(struct rte_crypto_asym_xform *xform)
+{
+	return get_modexp_function2(xform->modex.modulus.length);
+}
+
+static struct qat_asym_function
 get_modinv_function(struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function = { };
diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index badf018f13..25694e52b5 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -205,7 +205,7 @@ modexp_set_input(struct rte_crypto_asym_op *asym_op,
 		struct rte_crypto_asym_xform *xform)
 {
 	struct qat_asym_function qat_function;
-	uint32_t alg_bytesize, func_id;
+	uint32_t alg_bytesize, func_id, in_bytesize;
 	int status = 0;
 
 	CHECK_IF_NOT_EMPTY(xform->modex.modulus, "mod exp",
@@ -215,7 +215,15 @@ modexp_set_input(struct rte_crypto_asym_op *asym_op,
 	if (status)
 		return status;
 
-	qat_function = get_asym_function(xform);
+	if (asym_op->modex.base.length > xform->modex.exponent.length &&
+		asym_op->modex.base.length > xform->modex.modulus.length) {
+		in_bytesize = asym_op->modex.base.length;
+	} else if (xform->modex.exponent.length > xform->modex.modulus.length)
+		in_bytesize = xform->modex.exponent.length;
+	else
+		in_bytesize = xform->modex.modulus.length;
+
+	qat_function = get_modexp_function2(in_bytesize);
 	func_id = qat_function.func_id;
 	if (qat_function.func_id == 0) {
 		QAT_LOG(ERR, "Cannot obtain functionality id");
-- 
2.13.6


             reply	other threads:[~2022-03-01 14:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-01 14:16 Arek Kusztal [this message]
2022-03-02 10:18 ` Zhang, Roy Fan
2022-03-04 10:21   ` 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=20220301141616.31821-1-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).