Skip to contentSkip to conversation

app/test-crypto-perf: fix invalid memcmp results

PATCH Superseded Suanming Mou 4 participants 10 messages Jan 3, 2024 – Feb 1, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 app/test-crypto-perf: fix invalid memcmp results

The function memcmp() returns an integer less than, equal to, or greater than zero. In current code, if the first memcmp() returns less than zero and the second memcmp() returns greater than zero, the sum of results may still be 0 and indicates verify succussed.

This commit converts the return value to be zero or greater than zero. That will make sure the sum of results be correct.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
---
 app/test-crypto-perf/cperf_test_verify.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
app/test-crypto-perf/cperf_test_verify.c +3 -3
index a6c0ffe813..8aa714b969 100644
@@ -186,18 +186,18 @@ cperf_verify_op(struct rte_crypto_op *op,
 
 	if (cipher == 1) {
 		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
-			res += memcmp(data + cipher_offset,
+			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
 		else
-			res += memcmp(data + cipher_offset,
+			res += !!memcmp(data + cipher_offset,
 					vector->plaintext.data,
 					options->test_buffer_size);
 	}
 
 	if (auth == 1) {
 		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
-			res += memcmp(data + auth_offset,
+			res += !!memcmp(data + auth_offset,
 					vector->digest.data,
 					options->digest_sz);
 	}
Signature · 1 line
2.34.1
#1 lore raw

PATCH 2/2 app/test-crypto-perf: fix encrypt operation verify

AEAD users RTE_CRYPTO_AEAD_OP_* with aead_op and CIPHER uses RTE_CRYPTO_CIPHER_OP_* with cipher_op in current code.

This commit aligns aead_op and cipher_op operation to fix incorrect AEAD verification.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
---
 app/test-crypto-perf/cperf_test_verify.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
app/test-crypto-perf/cperf_test_verify.c +7 -2
index 8aa714b969..525a2b1373 100644
@@ -113,6 +113,7 @@ cperf_verify_op(struct rte_crypto_op *op,
 	uint8_t *data;
 	uint32_t cipher_offset, auth_offset;
 	uint8_t	cipher, auth;
+	bool is_encrypt = false;
 	int res = 0;
 
 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
@@ -154,12 +155,14 @@ cperf_verify_op(struct rte_crypto_op *op,
 		cipher_offset = 0;
 		auth = 0;
 		auth_offset = 0;
+		is_encrypt = options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT;
 		break;
 	case CPERF_CIPHER_THEN_AUTH:
 		cipher = 1;
 		cipher_offset = 0;
 		auth = 1;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT;
 		break;
 	case CPERF_AUTH_ONLY:
 		cipher = 0;
@@ -172,12 +175,14 @@ cperf_verify_op(struct rte_crypto_op *op,
 		cipher_offset = 0;
 		auth = 1;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT;
 		break;
 	case CPERF_AEAD:
 		cipher = 1;
 		cipher_offset = 0;
-		auth = 1;
+		auth = options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = !!auth;
 		break;
 	default:
 		res = 1;
@@ -185,7 +190,7 @@ cperf_verify_op(struct rte_crypto_op *op,
 	}
 
 	if (cipher == 1) {
-		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
+		if (is_encrypt)
 			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
Signature · 1 line
2.34.1
#2 lore raw

RE: [EXT] [PATCH 2/2] app/test-crypto-perf: fix encrypt operation verify

Hi Suanming,

Please see inline.

Thanks,
Anoob

Quoted 11 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Wednesday, January 3, 2024 9:26 AM
To: Ciara Power <[email protected]>
Cc: [email protected]
Subject: [EXT] [PATCH 2/2] app/test-crypto-perf: fix encrypt operation verify

External Email

----------------------------------------------------------------------
AEAD users RTE_CRYPTO_AEAD_OP_* with aead_op and CIPHER uses

[Anoob] users -> uses

Quoted 60 lines

RTE_CRYPTO_CIPHER_OP_* with cipher_op in current code.

This commit aligns aead_op and cipher_op operation to fix incorrect AEAD verification.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
---
 app/test-crypto-perf/cperf_test_verify.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
app/test-crypto- renamed from app/test-crypto-perf/cperf_test_verify.c +0 -0

perf/cperf_test_verify.c
index 8aa714b969..525a2b1373 100644

app/test-crypto-perf/cperf_test_verify.c +3 -0
@@ -113,6 +113,7 @@ cperf_verify_op(struct rte_crypto_op *op,
 	uint8_t *data;
 	uint32_t cipher_offset, auth_offset;
 	uint8_t	cipher, auth;
+	bool is_encrypt = false;
 	int res = 0;
 
 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) @@ -154,12
+155,14 @@ cperf_verify_op(struct rte_crypto_op *op,
 		cipher_offset = 0;
 		auth = 0;
 		auth_offset = 0;
+		is_encrypt = options->cipher_op ==

RTE_CRYPTO_CIPHER_OP_ENCRYPT;

app/test-crypto-perf/cperf_test_verify.c +1 -0
 		break;
 	case CPERF_CIPHER_THEN_AUTH:
 		cipher = 1;
 		cipher_offset = 0;
 		auth = 1;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op ==

RTE_CRYPTO_CIPHER_OP_ENCRYPT;

app/test-crypto-perf/cperf_test_verify.c +3 -1
 		break;
 	case CPERF_AUTH_ONLY:
 		cipher = 0;
@@ -172,12 +175,14 @@ cperf_verify_op(struct rte_crypto_op *op,
 		cipher_offset = 0;
 		auth = 1;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op ==
 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
 		break;
 	case CPERF_AEAD:
 		cipher = 1;
 		cipher_offset = 0;
-		auth = 1;
+		auth = options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = !!auth;
 		break;
 	default:
app/test-crypto-perf/cperf_test_verify.c +0 -0
 		res = 1;

app/test-crypto-perf/cperf_test_verify.c cperf_verify_op(struct rte_crypto_op *op, · line 193

Quoted 5 lines
app/test-crypto-perf/cperf_test_verify.c +1 -1
@@ -185,7 +190,7 @@ cperf_verify_op(struct rte_crypto_op *op,
 	}
 
 	if (cipher == 1) {
-		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
+		if (is_encrypt)

[Anoob] A similar check is there under 'auth == 1' check, right? Won't that also need fixing?

	if (auth == 1) {
		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)

I think some renaming of the local variables might make code better.

        bool cipher, digest_verify = false, is_encrypt = false;

	case CPERF_CIPHER_THEN_AUTH:
		cipher = true;
		cipher_offset = 0;
		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
			is_encrypt = true;
			digest_verify = true; /* Assumption - options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE is verified elsewhere */
			auth_offset = options->test_buffer_size;
		}
		break;
	<...>
	case CPERF_AEAD:
		cipher = true;
		cipher_offset = 0;
                             if (options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
                             	is_encrypt = true;
			digest_verify = true;
			auth_offset = options->test_buffer_size;
		}

What do you think?

Quoted 5 lines
app/test-crypto-perf/cperf_test_verify.c +0 -1
 			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
--

2.34.1

#3 lore raw

RE: [EXT] [PATCH 2/2] app/test-crypto-perf: fix encrypt operation verify

Hi,

Quoted 125 lines

-----Original Message-----
From: Anoob Joseph <[email protected]>
Sent: Thursday, January 4, 2024 1:13 PM
To: Suanming Mou <[email protected]>; Ciara Power <[email protected]>
Cc: [email protected]
Subject: RE: [EXT] [PATCH 2/2] app/test-crypto-perf: fix encrypt operation verify

Hi Suanming,

Please see inline.

Thanks,
Anoob

Quoted 8 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Wednesday, January 3, 2024 9:26 AM
To: Ciara Power <[email protected]>
Cc: [email protected]
Subject: [EXT] [PATCH 2/2] app/test-crypto-perf: fix encrypt operation verify

Quoted 4 lines

External Email

----------------------------------------------------------------------
AEAD users RTE_CRYPTO_AEAD_OP_* with aead_op and CIPHER uses

[Anoob] users -> uses

Quoted 61 lines

RTE_CRYPTO_CIPHER_OP_* with cipher_op in current code.

This commit aligns aead_op and cipher_op operation to fix incorrect AEAD verification.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test

type")

---
 app/test-crypto-perf/cperf_test_verify.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/app/test-crypto- perf/cperf_test_verify.c index
8aa714b969..525a2b1373 100644

app/test-crypto-perf/cperf_test_verify.c +3 -0
@@ -113,6 +113,7 @@ cperf_verify_op(struct rte_crypto_op *op,
 	uint8_t *data;
 	uint32_t cipher_offset, auth_offset;
 	uint8_t	cipher, auth;
+	bool is_encrypt = false;
 	int res = 0;
 
 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) @@ -154,12
+155,14 @@ cperf_verify_op(struct rte_crypto_op *op,
 		cipher_offset = 0;
 		auth = 0;
 		auth_offset = 0;
+		is_encrypt = options->cipher_op ==

RTE_CRYPTO_CIPHER_OP_ENCRYPT;

app/test-crypto-perf/cperf_test_verify.c +1 -0
 		break;
 	case CPERF_CIPHER_THEN_AUTH:
 		cipher = 1;
 		cipher_offset = 0;
 		auth = 1;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op ==

RTE_CRYPTO_CIPHER_OP_ENCRYPT;

app/test-crypto-perf/cperf_test_verify.c +3 -1
 		break;
 	case CPERF_AUTH_ONLY:
 		cipher = 0;
@@ -172,12 +175,14 @@ cperf_verify_op(struct rte_crypto_op *op,
 		cipher_offset = 0;
 		auth = 1;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op ==
 RTE_CRYPTO_CIPHER_OP_ENCRYPT;
 		break;
 	case CPERF_AEAD:
 		cipher = 1;
 		cipher_offset = 0;
-		auth = 1;
+		auth = options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT;
 		auth_offset = options->test_buffer_size;
+		is_encrypt = !!auth;
 		break;
 	default:
app/test-crypto-perf/cperf_test_verify.c +0 -0
 		res = 1;

app/test-crypto-perf/cperf_test_verify.c cperf_verify_op(struct rte_crypto_op *op, · line 193

Quoted 5 lines
app/test-crypto-perf/cperf_test_verify.c +1 -1
@@ -185,7 +190,7 @@ cperf_verify_op(struct rte_crypto_op *op,
 	}
 
 	if (cipher == 1) {
-		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
+		if (is_encrypt)

[Anoob] A similar check is there under 'auth == 1' check, right? Won't that also need fixing?

	if (auth == 1) {
		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)

I think some renaming of the local variables might make code better.

        bool cipher, digest_verify = false, is_encrypt = false;

	case CPERF_CIPHER_THEN_AUTH:
		cipher = true;
		cipher_offset = 0;
		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
			is_encrypt = true;
			digest_verify = true; /* Assumption - options->auth_op
== RTE_CRYPTO_AUTH_OP_GENERATE is verified elsewhere */
			auth_offset = options->test_buffer_size;
		}
		break;
	<...>
	case CPERF_AEAD:
		cipher = true;
		cipher_offset = 0;
                             if (options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
                             	is_encrypt = true;
			digest_verify = true;
			auth_offset = options->test_buffer_size;
		}
Quoted 1 line

What do you think?

Yes, so we can totally remove the auth for now. I will do that. Thanks for the suggestion.

Quoted 6 lines
Quoted 6 lines
app/test-crypto-perf/cperf_test_verify.c +0 -1
 			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
--

2.34.1

Acked-by on v1 1/2
#4 lore raw
In reply to Suanming Mou
Quoted 11 lines

The function memcmp() returns an integer less than, equal to, or greater than zero. In current code, if the first memcmp() returns less than zero and the second memcmp() returns greater than zero, the sum of results may still be 0 and indicates verify succussed.

This commit converts the return value to be zero or greater than zero. That will make sure the sum of results be correct.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
#5 lore raw

PATCH v2 1/2 app/test-crypto-perf: fix invalid memcmp results

In reply to Suanming Mou

The function memcmp() returns an integer less than, equal to, or greater than zero. In current code, if the first memcmp() returns less than zero and the second memcmp() returns greater than zero, the sum of results may still be 0 and indicates verify succussed.

This commit converts the return value to be zero or greater than zero. That will make sure the sum of results be correct.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
---
 app/test-crypto-perf/cperf_test_verify.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
app/test-crypto-perf/cperf_test_verify.c +3 -3
index a6c0ffe813..8aa714b969 100644
@@ -186,18 +186,18 @@ cperf_verify_op(struct rte_crypto_op *op,
 
 	if (cipher == 1) {
 		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
-			res += memcmp(data + cipher_offset,
+			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
 		else
-			res += memcmp(data + cipher_offset,
+			res += !!memcmp(data + cipher_offset,
 					vector->plaintext.data,
 					options->test_buffer_size);
 	}
 
 	if (auth == 1) {
 		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
-			res += memcmp(data + auth_offset,
+			res += !!memcmp(data + auth_offset,
 					vector->digest.data,
 					options->digest_sz);
 	}
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 2/2 app/test-crypto-perf: fix encrypt operation verify

AEAD uses RTE_CRYPTO_AEAD_OP_* with aead_op and CIPHER uses RTE_CRYPTO_CIPHER_OP_* with cipher_op in current code.

This commit aligns aead_op and cipher_op operation to fix incorrect AEAD verification.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")

---

v2: align auth/cipher to bool.

---
 app/test-crypto-perf/cperf_test_verify.c | 55 ++++++++++++------------
 1 file changed, 27 insertions(+), 28 deletions(-)
app/test-crypto-perf/cperf_test_verify.c +27 -28
index 8aa714b969..2b0d3f142b 100644
@@ -111,8 +111,10 @@ cperf_verify_op(struct rte_crypto_op *op,
 	uint32_t len;
 	uint16_t nb_segs;
 	uint8_t *data;
-	uint32_t cipher_offset, auth_offset;
-	uint8_t	cipher, auth;
+	uint32_t cipher_offset, auth_offset = 0;
+	bool cipher = false;
+	bool digest_verify = false;
+	bool is_encrypt = false;
 	int res = 0;
 
 	if (op->status != RTE_CRYPTO_OP_STATUS_SUCCESS)
@@ -150,42 +152,43 @@ cperf_verify_op(struct rte_crypto_op *op,
 
 	switch (options->op_type) {
 	case CPERF_CIPHER_ONLY:
-		cipher = 1;
+		cipher = true;
 		cipher_offset = 0;
-		auth = 0;
-		auth_offset = 0;
-		break;
-	case CPERF_CIPHER_THEN_AUTH:
-		cipher = 1;
-		cipher_offset = 0;
-		auth = 1;
-		auth_offset = options->test_buffer_size;
+		is_encrypt = options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT;
 		break;
 	case CPERF_AUTH_ONLY:
-		cipher = 0;
 		cipher_offset = 0;
-		auth = 1;
-		auth_offset = options->test_buffer_size;
+		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE) {
+			auth_offset = options->test_buffer_size;
+			digest_verify = true;
+		}
 		break;
+	case CPERF_CIPHER_THEN_AUTH:
 	case CPERF_AUTH_THEN_CIPHER:
-		cipher = 1;
+		cipher = true;
 		cipher_offset = 0;
-		auth = 1;
-		auth_offset = options->test_buffer_size;
+		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) {
+			auth_offset = options->test_buffer_size;
+			digest_verify = true;
+			is_encrypt = true;
+		}
 		break;
 	case CPERF_AEAD:
-		cipher = 1;
+		cipher = true;
 		cipher_offset = 0;
-		auth = 1;
-		auth_offset = options->test_buffer_size;
+		if (options->aead_op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
+			auth_offset = options->test_buffer_size;
+			digest_verify = true;
+			is_encrypt = true;
+		}
 		break;
 	default:
 		res = 1;
 		goto out;
 	}
 
-	if (cipher == 1) {
-		if (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT)
+	if (cipher) {
+		if (is_encrypt)
 			res += !!memcmp(data + cipher_offset,
 					vector->ciphertext.data,
 					options->test_buffer_size);
@@ -195,12 +198,8 @@ cperf_verify_op(struct rte_crypto_op *op,
 					options->test_buffer_size);
 	}
 
-	if (auth == 1) {
-		if (options->auth_op == RTE_CRYPTO_AUTH_OP_GENERATE)
-			res += !!memcmp(data + auth_offset,
-					vector->digest.data,
-					options->digest_sz);
-	}
+	if (digest_verify)
+		res += !!memcmp(data + auth_offset, vector->digest.data, options->digest_sz);
 
 out:
 	rte_free(data);
Signature · 1 line
2.34.1
Acked-by on v2 2/2
#7 lore raw

RE: [EXT] [PATCH v2 2/2] app/test-crypto-perf: fix encrypt operation verify

Quoted 9 lines

AEAD uses RTE_CRYPTO_AEAD_OP_* with aead_op and CIPHER uses RTE_CRYPTO_CIPHER_OP_* with cipher_op in current code.

This commit aligns aead_op and cipher_op operation to fix incorrect AEAD verification.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
Acked-by on v2 1/2
#8 lore raw
In reply to Suanming Mou
Quoted 17 lines

-----Original Message-----
From: Suanming Mou <[email protected]>
Sent: Friday, January 5, 2024 12:03 AM
To: [email protected]; Power, Ciara <[email protected]>
Cc: [email protected]
Subject: [PATCH v2 1/2] app/test-crypto-perf: fix invalid memcmp results

The function memcmp() returns an integer less than, equal to, or greater than zero. In current code, if the first memcmp() returns less than zero and the second memcmp() returns greater than zero, the sum of results may still be 0 and indicates verify succussed.

This commit converts the return value to be zero or greater than zero. That will make sure the sum of results be correct.

Quoted 6 lines
Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")
---
 app/test-crypto-perf/cperf_test_verify.c | 6 +++---
#9 lore raw
In reply to Suanming Mou
Quoted 6 lines

The function memcmp() returns an integer less than, equal to, or greater than zero. In current code, if the first memcmp() returns less than zero and the second memcmp() returns greater than zero, the sum of results may still be 0 and indicates verify succussed.

Quoted 7 lines

This commit converts the return value to be zero or greater than zero. That will make sure the sum of results be correct.

Fixes df52cb3b6e13 ("app/crypto-perf: move verify as single test type")

Cc: [email protected]
Series
Applied to dpdk-next-crypto