patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH v1 1/4] test/crypto: validate modex result from first nonzero value
       [not found] <20240616044223.2841-1-gmuthukrishn@marvell.com>
@ 2024-06-16  4:42 ` Gowrishankar Muthukrishnan
       [not found] ` <20240621023832.1707-1-gmuthukrishn@marvell.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Gowrishankar Muthukrishnan @ 2024-06-16  4:42 UTC (permalink / raw)
  To: dev, Akhil Goyal, Fan Zhang, Gowrishankar Muthukrishnan,
	Arkadiusz Kusztal, Ciara Power
  Cc: Anoob Joseph, stable

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 17daf734e8..c26be9b2bf 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/4] test/crypto: validate modex result from first nonzero value
       [not found] ` <20240621023832.1707-1-gmuthukrishn@marvell.com>
@ 2024-06-21  2:38   ` Gowrishankar Muthukrishnan
       [not found]   ` <20240626100345.1758-1-gmuthukrishn@marvell.com>
  1 sibling, 0 replies; 3+ messages in thread
From: Gowrishankar Muthukrishnan @ 2024-06-21  2:38 UTC (permalink / raw)
  To: dev, Akhil Goyal, Fan Zhang, Ciara Power,
	Gowrishankar Muthukrishnan, Arkadiusz Kusztal
  Cc: Anoob Joseph, stable

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v3 1/3] test/crypto: validate modex result from first nonzero value
       [not found]   ` <20240626100345.1758-1-gmuthukrishn@marvell.com>
@ 2024-06-26 10:03     ` Gowrishankar Muthukrishnan
  0 siblings, 0 replies; 3+ messages in thread
From: Gowrishankar Muthukrishnan @ 2024-06-26 10:03 UTC (permalink / raw)
  To: dev, Akhil Goyal, Fan Zhang, Arkadiusz Kusztal, Ciara Power,
	Gowrishankar Muthukrishnan
  Cc: Anoob Joseph, stable

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-26 10:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20240616044223.2841-1-gmuthukrishn@marvell.com>
2024-06-16  4:42 ` [PATCH v1 1/4] test/crypto: validate modex result from first nonzero value 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     ` [PATCH v3 1/3] " Gowrishankar Muthukrishnan

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).