patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
To: <dev@dpdk.org>, Akhil Goyal <gakhil@marvell.com>,
	Fan Zhang <fanzhang.oss@gmail.com>,
	Arkadiusz Kusztal <arkadiuszx.kusztal@intel.com>,
	Ciara Power <ciara.power@intel.com>,
	Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
Cc: Anoob Joseph <anoobj@marvell.com>, <stable@dpdk.org>
Subject: [PATCH v3 1/3] test/crypto: validate modex result from first nonzero value
Date: Wed, 26 Jun 2024 15:33:40 +0530	[thread overview]
Message-ID: <20240626100345.1758-2-gmuthukrishn@marvell.com> (raw)
In-Reply-To: <20240626100345.1758-1-gmuthukrishn@marvell.com>

At present, there is no specification of whether modex op output
can carry leading zeroes without changing the value. OpenSSL strips
leading zeroes, but other hardware need not be. Hence, when output
is compared against expected result, validation could start from
first non-zero.

Fixes: 1ffefe00f1 ("test/crypto: add modexp and modinv functions")
Cc: stable@dpdk.org

Signed-off-by: Gowrishankar Muthukrishnan <gmuthukrishn@marvell.com>
---
 app/test/test_cryptodev_asym.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/app/test/test_cryptodev_asym.c b/app/test/test_cryptodev_asym.c
index 2c745a7f7c..fec53f87db 100644
--- a/app/test/test_cryptodev_asym.c
+++ b/app/test/test_cryptodev_asym.c
@@ -3200,6 +3200,27 @@ static int send_one(void)
 	return TEST_SUCCESS;
 }
 
+static int
+modular_cmpeq(const uint8_t *a, const uint8_t *b, size_t len)
+{
+	const uint8_t *new_a = a, *new_b = b;
+	size_t i, j;
+
+	/* Strip leading NUL bytes */
+	for (i = 0; i < len; i++)
+		if (a[i] != 0)
+			new_a = &a[i];
+
+	for (j = 0; j < len; j++)
+		if (b[j] != 0)
+			new_b = &b[i];
+
+	if (i != j || memcmp(new_a, new_b, len - i))
+		return 1;
+
+	return 0;
+}
+
 static int
 modular_exponentiation(const void *test_data)
 {
@@ -3234,9 +3255,9 @@ modular_exponentiation(const void *test_data)
 
 	TEST_ASSERT_SUCCESS(send_one(),
 		"Failed to process crypto op");
-	TEST_ASSERT_BUFFERS_ARE_EQUAL(vector->reminder.data,
+	TEST_ASSERT_SUCCESS(modular_cmpeq(vector->reminder.data,
 			self->result_op->asym->modex.result.data,
-			self->result_op->asym->modex.result.length,
+			self->result_op->asym->modex.result.length),
 			"operation verification failed\n");
 
 	return TEST_SUCCESS;
-- 
2.25.1


      parent reply	other threads:[~2024-06-26 10:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20240616044223.2841-1-gmuthukrishn@marvell.com>
2024-06-16  4:42 ` [PATCH v1 1/4] " Gowrishankar Muthukrishnan
     [not found] ` <20240621023832.1707-1-gmuthukrishn@marvell.com>
2024-06-21  2:38   ` [PATCH v2 " Gowrishankar Muthukrishnan
     [not found]   ` <20240626100345.1758-1-gmuthukrishn@marvell.com>
2024-06-26 10:03     ` Gowrishankar Muthukrishnan [this message]

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=20240626100345.1758-2-gmuthukrishn@marvell.com \
    --to=gmuthukrishn@marvell.com \
    --cc=anoobj@marvell.com \
    --cc=arkadiuszx.kusztal@intel.com \
    --cc=ciara.power@intel.com \
    --cc=dev@dpdk.org \
    --cc=fanzhang.oss@gmail.com \
    --cc=gakhil@marvell.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).