patches for DPDK stable branches
 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>,
	stable@dpdk.org
Subject: [dpdk-stable] [PATCH] crypto/qat: fix uncleared cookies after operation
Date: Thu, 21 Oct 2021 11:06:01 +0100	[thread overview]
Message-ID: <20211021100601.16190-1-arkadiuszx.kusztal@intel.com> (raw)

This commit fixes uncleared cookies issue when using
RSA algorithm.

Fixes: e2c5f4ea994c ("crypto/qat: support RSA in asym")
Cc: stable@dpdk.org

Signed-off-by: Arek Kusztal <arkadiuszx.kusztal@intel.com>
---
 drivers/crypto/qat/qat_asym.c | 41 +++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 12 deletions(-)

diff --git a/drivers/crypto/qat/qat_asym.c b/drivers/crypto/qat/qat_asym.c
index 983c639d68..f893508030 100644
--- a/drivers/crypto/qat/qat_asym.c
+++ b/drivers/crypto/qat/qat_asym.c
@@ -65,27 +65,45 @@ static size_t max_of(int n, ...)
 }
 
 static void qat_clear_arrays(struct qat_asym_op_cookie *cookie,
-		int in_count, int out_count, int in_size, int out_size)
+		int in_count, int out_count, int alg_size)
 {
 	int i;
 
 	for (i = 0; i < in_count; i++)
-		memset(cookie->input_array[i], 0x0, in_size);
+		memset(cookie->input_array[i], 0x0, alg_size);
 	for (i = 0; i < out_count; i++)
-		memset(cookie->output_array[i], 0x0, out_size);
+		memset(cookie->output_array[i], 0x0, alg_size);
+}
+
+static void qat_clear_arrays_crt(struct qat_asym_op_cookie *cookie,
+		int alg_size)
+{
+	int i;
+
+	memset(cookie->input_array[0], 0x0, alg_size);
+	for (i = 1; i < QAT_ASYM_RSA_QT_NUM_IN_PARAMS; i++)
+		memset(cookie->input_array[i], 0x0, alg_size / 2);
+	for (i = 0; i < QAT_ASYM_RSA_NUM_OUT_PARAMS; i++)
+		memset(cookie->output_array[i], 0x0, alg_size);
 }
 
 static void qat_clear_arrays_by_alg(struct qat_asym_op_cookie *cookie,
-		enum rte_crypto_asym_xform_type alg, int in_size, int out_size)
+		struct rte_crypto_asym_xform *xform, int alg_size)
 {
-	if (alg == RTE_CRYPTO_ASYM_XFORM_MODEX)
+	if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODEX)
 		qat_clear_arrays(cookie, QAT_ASYM_MODEXP_NUM_IN_PARAMS,
-				QAT_ASYM_MODEXP_NUM_OUT_PARAMS, in_size,
-				out_size);
-	else if (alg == RTE_CRYPTO_ASYM_XFORM_MODINV)
+				QAT_ASYM_MODEXP_NUM_OUT_PARAMS, alg_size);
+	else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_MODINV)
 		qat_clear_arrays(cookie, QAT_ASYM_MODINV_NUM_IN_PARAMS,
-				QAT_ASYM_MODINV_NUM_OUT_PARAMS, in_size,
-				out_size);
+				QAT_ASYM_MODINV_NUM_OUT_PARAMS, alg_size);
+	else if (xform->xform_type == RTE_CRYPTO_ASYM_XFORM_RSA) {
+		if (xform->rsa.key_type == RTE_RSA_KET_TYPE_QT)
+			qat_clear_arrays_crt(cookie, alg_size);
+		else {
+			qat_clear_arrays(cookie, QAT_ASYM_RSA_NUM_IN_PARAMS,
+				QAT_ASYM_RSA_NUM_OUT_PARAMS, alg_size);
+		}
+	}
 }
 
 static int qat_asym_check_nonzero(rte_crypto_param n)
@@ -657,8 +675,7 @@ static void qat_asym_collect_response(struct rte_crypto_op *rx_op,
 			}
 		}
 	}
-	qat_clear_arrays_by_alg(cookie, xform->xform_type, alg_size_in_bytes,
-			alg_size_in_bytes);
+	qat_clear_arrays_by_alg(cookie, xform, alg_size_in_bytes);
 }
 
 void
-- 
2.21.3


             reply	other threads:[~2021-10-21 10:06 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-21 10:06 Arek Kusztal [this message]
2021-10-21 13:14 ` Zhang, Roy Fan
2021-10-31 19:33   ` 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=20211021100601.16190-1-arkadiuszx.kusztal@intel.com \
    --to=arkadiuszx.kusztal@intel.com \
    --cc=dev@dpdk.org \
    --cc=gakhil@marvell.com \
    --cc=roy.fan.zhang@intel.com \
    --cc=stable@dpdk.org \
    /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).