Skip to contentSkip to conversation

lib/cryptodev: avoid implicit conversion to 64 bit number

PATCH Superseded Andre Muezerie 6 participants 20 messages Nov 28, 2024 – Feb 6, 2025 Crypto API

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 lib/cryptodev: avoid implicit conversion to 64 bit number

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

---
 lib/cryptodev/rte_cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_cryptodev.c +1 -1
index 85a4b46ac9..a49b0662f3 100644
@@ -620,7 +620,7 @@ rte_cryptodev_asym_xform_capability_check_hash(
 {
 	bool ret = false;
 
-	if (capability->hash_algos & (1 << hash))
+	if (capability->hash_algos & RTE_BIT64(hash))
 		ret = true;
 
 	rte_cryptodev_trace_asym_xform_capability_check_hash(
Signature · 1 line
2.47.0.vfs.0.3
#1 lore raw

PATCH 2/2 lib/hash: avoid implicit conversion to 64 bit number

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

1ULL should be used as the result of the bit shift gets multiplied by sizeof(uint32_t).

---
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
lib/hash/rte_thash.c +1 -1
index fa78787143..f076311b57 100644
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
 		offset;
 
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper) +
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		sizeof(uint32_t) * (1ULL << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);
 	if (ent == NULL)
 		return -ENOMEM;
lib/hash/rte_thash_gf2_poly_math.c +3 -3
index 825da4382f..858884b4d4 100644
@@ -119,16 +119,16 @@ static uint32_t
 gf2_mul(uint32_t a, uint32_t b, uint32_t r, int degree)
 {
 	uint64_t product = 0;
-	uint64_t r_poly = r|(1ULL << degree);
+	uint64_t r_poly = r | RTE_BIT64(degree);
 
 	for (; b; b &= (b - 1))
 		product ^= (uint64_t)a << (rte_bsf32(b));
 
 	for (int i = degree * 2 - 1; i >= degree; i--)
-		if (product & (1 << i))
+		if (product & RTE_BIT64(i))
 			product ^= r_poly << (i - degree);
 
-	return product;
+	return (uint32_t)product;
 }
 
 static uint32_t
Signature · 1 line
2.47.0.vfs.0.3
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] lib/hash: avoid implicit conversion to 64 bit number

Quoted 13 lines · Andre Muezerie

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Quoted 5 lines

1ULL should be used as the result of the bit shift gets multiplied by sizeof(uint32_t).

---

Quoted 9 lines
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
lib/hash/rte_thash.c +0 -0
index fa78787143..f076311b57 100644

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len, · line 569

Quoted 6 lines
lib/hash/rte_thash.c +1 -1
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
 		offset;
 
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper) +
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		sizeof(uint32_t) * (1ULL << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);

Is there a reason not to use RTE_BIT64 here too?

#3 lore raw

Re: [PATCH 2/2] lib/hash: avoid implicit conversion to 64 bit number

Quoted 33 lines · Bruce Richardson
Quoted 13 lines · Andre Muezerie

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Quoted 5 lines

1ULL should be used as the result of the bit shift gets multiplied by sizeof(uint32_t).

---

Quoted 11 lines
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
lib/hash/rte_thash.c +0 -0
index fa78787143..f076311b57 100644
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
 		offset;
 
Quoted 6 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len, · line 569

Quoted 4 lines
lib/hash/rte_thash.c +1 -1
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper) +
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		sizeof(uint32_t) * (1ULL << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);

Is there a reason not to use RTE_BIT64 here too?

Here we are calculating the size to be passed to the second argument of rte_zmalloc, which is of type size_t. size_t is implementation dependent, typically 4 bytes on 32-bit systems and 8 bytes on 64-bit systems, so using 1ULL seems more appropriate.

#4 lore raw

RE: [PATCH 2/2] lib/hash: avoid implicit conversion to 64 bit number

Quoted 46 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Wednesday, 22 January 2025 22.37

Quoted 26 lines · Bruce Richardson
Quoted 13 lines · Andre Muezerie

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Quoted 5 lines

1ULL should be used as the result of the bit shift gets multiplied by sizeof(uint32_t).

---

Quoted 4 lines
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 5 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx,

Quoted 5 lines
lib/hash/rte_thash.c +0 -0
index fa78787143..f076311b57 100644
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx,

const char *name, uint32_t len,

Quoted 3 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx, · line 567

Quoted 3 lines
lib/hash/rte_thash.c +0 -0
 		offset;
 
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper)

+

Quoted 5 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len, · line 569

Quoted 3 lines
lib/hash/rte_thash.c +1 -1
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		sizeof(uint32_t) * (1ULL << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);

Is there a reason not to use RTE_BIT64 here too?

Quoted 4 lines

Here we are calculating the size to be passed to the second argument of rte_zmalloc, which is of type size_t. size_t is implementation dependent, typically 4 bytes on 32-bit systems and 8 bytes on 64-bit systems, so using 1ULL seems more appropriate.

1ULL makes it 8 byte on 32-bit systems too. Did you mean 1UL?

How about reducing the formula to directly shift the sizeof() instead, i.e.:
sizeof(uint32_t) << ctx->reta_sz_log,

#5 lore raw

Re: [PATCH 2/2] lib/hash: avoid implicit conversion to 64 bit number

Quoted 51 lines · Morten Brørup
Quoted 46 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Wednesday, 22 January 2025 22.37

Quoted 26 lines · Bruce Richardson
Quoted 13 lines · Andre Muezerie

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Quoted 5 lines

1ULL should be used as the result of the bit shift gets multiplied by sizeof(uint32_t).

---

Quoted 4 lines
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
Quoted 5 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx,

Quoted 5 lines
lib/hash/rte_thash.c +0 -0
index fa78787143..f076311b57 100644
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx,

const char *name, uint32_t len,

Quoted 3 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx, · line 567

Quoted 3 lines
lib/hash/rte_thash.c +0 -0
 		offset;
 
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper)

+

Quoted 5 lines

lib/hash/rte_thash.c rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len, · line 569

Quoted 3 lines
lib/hash/rte_thash.c +1 -1
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		sizeof(uint32_t) * (1ULL << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);

Is there a reason not to use RTE_BIT64 here too?

Quoted 4 lines

Here we are calculating the size to be passed to the second argument of rte_zmalloc, which is of type size_t. size_t is implementation dependent, typically 4 bytes on 32-bit systems and 8 bytes on 64-bit systems, so using 1ULL seems more appropriate.

Quoted 4 lines

1ULL makes it 8 byte on 32-bit systems too. Did you mean 1UL?

How about reducing the formula to directly shift the sizeof() instead, i.e.:
sizeof(uint32_t) << ctx->reta_sz_log,

Shifting the sizeof() directly is better indeed. Let me know how we should proceed. Do you want me to send out a new series incorporating this suggestion?

#6 lore raw

RE: [PATCH 2/2] lib/hash: avoid implicit conversion to 64 bit number

Quoted 8 lines
Quoted 1 line

How about reducing the formula to directly shift the sizeof()

instead, i.e.:

Quoted 1 line

sizeof(uint32_t) << ctx->reta_sz_log,

Shifting the sizeof() directly is better indeed. Let me know how we should
proceed. Do you want me to send out a new series incorporating this suggestion?

Yes, please.

Acked-by on v1 2/2
#7 lore raw

Re: [PATCH 2/2] lib/hash: avoid implicit conversion to 64 bit number

In reply to Andre Muezerie
Quoted 22 lines · Andre Muezerie

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

1ULL should be used as the result of the bit shift gets multiplied by sizeof(uint32_t).

---
  lib/hash/rte_thash.c               | 2 +-
  lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
  2 files changed, 4 insertions(+), 4 deletions(-)

<snip>

Signature · 2 lines
Regards,
Vladimir
Acked-by on v1 1/2
#8 lore raw
In reply to Andre Muezerie
Quoted 10 lines

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

1/2 patch Applied to dpdk-next-crypto
2/2 patch will be taken via main tree.

Thanks.

#9 lore raw

PATCH v2 1/2 lib/cryptodev: avoid implicit conversion to 64 bit number

In reply to Andre Muezerie

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

---
 lib/cryptodev/rte_cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_cryptodev.c +1 -1
index 85a4b46ac9..a49b0662f3 100644
@@ -620,7 +620,7 @@ rte_cryptodev_asym_xform_capability_check_hash(
 {
 	bool ret = false;
 
-	if (capability->hash_algos & (1 << hash))
+	if (capability->hash_algos & RTE_BIT64(hash))
 		ret = true;
 
 	rte_cryptodev_trace_asym_xform_capability_check_hash(
Signature · 1 line
2.47.2.vfs.0.1
#10 lore raw

PATCH v2 2/2 lib/hash: avoid implicit conversion to 64 bit number

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Instead of multiplying sizeof(uint32_t) by the result of shifting "1", sizeof(uint32_t) can be shifted directly.

---
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
lib/hash/rte_thash.c +1 -1
index 336c228e64..429b895d6c 100644
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
 		offset;
 
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper) +
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		(sizeof(uint32_t) << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);
 	if (ent == NULL)
 		return -ENOMEM;
lib/hash/rte_thash_gf2_poly_math.c +3 -3
index 1c62974e71..a28f2495a5 100644
@@ -118,16 +118,16 @@ static uint32_t
 gf2_mul(uint32_t a, uint32_t b, uint32_t r, int degree)
 {
 	uint64_t product = 0;
-	uint64_t r_poly = r|(1ULL << degree);
+	uint64_t r_poly = r | RTE_BIT64(degree);
 
 	for (; b; b &= (b - 1))
 		product ^= (uint64_t)a << (rte_bsf32(b));
 
 	for (int i = degree * 2 - 1; i >= degree; i--)
-		if (product & (1 << i))
+		if (product & RTE_BIT64(i))
 			product ^= r_poly << (i - degree);
 
-	return product;
+	return (uint32_t)product;
 }
 
 static uint32_t
Signature · 1 line
2.47.2.vfs.0.1
Reviewed-by on v2 2/2
#11 lore raw

RE: [PATCH v2 2/2] lib/hash: avoid implicit conversion to 64 bit number

Quoted 16 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Monday, 27 January 2025 17.04

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Quoted 7 lines

Instead of multiplying sizeof(uint32_t) by the result of shifting "1", sizeof(uint32_t) can be shifted directly.

---

Reviewed-by on v2 1/2
#12 lore raw
In reply to Andre Muezerie
Quoted 24 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Monday, 27 January 2025 17.04

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

---
 lib/cryptodev/rte_cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_cryptodev.c +0 -0
index 85a4b46ac9..a49b0662f3 100644

lib/cryptodev/rte_cryptodev.c rte_cryptodev_asym_xform_capability_check_hash( · line 624

Quoted 6 lines
lib/cryptodev/rte_cryptodev.c +1 -1
@@ -620,7 +620,7 @@ rte_cryptodev_asym_xform_capability_check_hash(
 {
 	bool ret = false;
 
-	if (capability->hash_algos & (1 << hash))
+	if (capability->hash_algos & RTE_BIT64(hash))
 		ret = true;

If I'm not mistaken, the last of the hash enums RTE_CRYPTO_AUTH_SM3_HMAC has the value 32, so this patch actually fixes a bug.
If you agree with my analysis, a Fixes tag should be added, so the patch can be backported. (RTE_CRYPTO_AUTH_SM3_HMAC also exists in previous DPDK versions.)

Furthermore, driver initializations of hash_algos should also use RTE_BIT64():
https://elixir.bootlin.com/dpdk/v24.11.1/C/ident/hash_algos
Specifically, OpenSSL and CNXK crypto drivers have the same bug, and need to be fixed too:
https://elixir.bootlin.com/dpdk/v24.11.1/source/drivers/crypto/openssl/rte_openssl_pmd_ops.c#L633
https://elixir.bootlin.com/dpdk/v24.11.1/source/drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c#L1210

With Fixes tag added,

#13 lore raw
Quoted 34 lines · Morten Brørup
Quoted 24 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Monday, 27 January 2025 17.04

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

---
 lib/cryptodev/rte_cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_cryptodev.c +0 -0
index 85a4b46ac9..a49b0662f3 100644

lib/cryptodev/rte_cryptodev.c rte_cryptodev_asym_xform_capability_check_hash( · line 624

Quoted 6 lines
lib/cryptodev/rte_cryptodev.c +1 -1
@@ -620,7 +620,7 @@ rte_cryptodev_asym_xform_capability_check_hash(
 {
 	bool ret = false;
 
-	if (capability->hash_algos & (1 << hash))
+	if (capability->hash_algos & RTE_BIT64(hash))
 		ret = true;

If I'm not mistaken, the last of the hash enums RTE_CRYPTO_AUTH_SM3_HMAC has the value 32, so this patch actually fixes a bug.
If you agree with my analysis, a Fixes tag should be added, so the patch can be backported. (RTE_CRYPTO_AUTH_SM3_HMAC also exists in previous DPDK versions.)

Quoted 8 lines

Furthermore, driver initializations of hash_algos should also use RTE_BIT64():
https://elixir.bootlin.com/dpdk/v24.11.1/C/ident/hash_algos
Specifically, OpenSSL and CNXK crypto drivers have the same bug, and need to be fixed too:
https://elixir.bootlin.com/dpdk/v24.11.1/source/drivers/crypto/openssl/rte_openssl_pmd_ops.c#L633
https://elixir.bootlin.com/dpdk/v24.11.1/source/drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c#L1210

With Fixes tag added,

Great observation. I agree that this is indeed fixing a bug. I also fixed the two drivers as suggested and sent out v3 of this series.

#14 lore raw

PATCH v3 1/3 lib/cryptodev: avoid implicit conversion to 64 bit number

In reply to Andre Muezerie

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

This patch actually fixes a bug present in previous DPDK versions because the last of the hash enums RTE_CRYPTO_AUTH_SM3_HMAC in rte_crypto_auth_algorithm has value 32.

Fixes 6f8ef8b68edb ("cryptodev: add hash algorithms in asymmetric capability")
---
 lib/cryptodev/rte_cryptodev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/cryptodev/rte_cryptodev.c +1 -1
index 85a4b46ac9..a49b0662f3 100644
@@ -620,7 +620,7 @@ rte_cryptodev_asym_xform_capability_check_hash(
 {
 	bool ret = false;
 
-	if (capability->hash_algos & (1 << hash))
+	if (capability->hash_algos & RTE_BIT64(hash))
 		ret = true;
 
 	rte_cryptodev_trace_asym_xform_capability_check_hash(
Signature · 1 line
2.47.2.vfs.0.1
#15 lore raw

PATCH v3 2/3 lib/hash: avoid implicit conversion to 64 bit number

MSVC issues the warnings below:

1) ../lib/hash/rte_thash_gf2_poly_math.c(128): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

2) ../lib/hash/rte_thash.c(568): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

Instead of multiplying sizeof(uint32_t) by the result of shifting "1", sizeof(uint32_t) can be shifted directly.

---
 lib/hash/rte_thash.c               | 2 +-
 lib/hash/rte_thash_gf2_poly_math.c | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)
lib/hash/rte_thash.c +1 -1
index 336c228e64..429b895d6c 100644
@@ -565,7 +565,7 @@ rte_thash_add_helper(struct rte_thash_ctx *ctx, const char *name, uint32_t len,
 		offset;
 
 	ent = rte_zmalloc(NULL, sizeof(struct rte_thash_subtuple_helper) +
-		sizeof(uint32_t) * (1 << ctx->reta_sz_log),
+		(sizeof(uint32_t) << ctx->reta_sz_log),
 		RTE_CACHE_LINE_SIZE);
 	if (ent == NULL)
 		return -ENOMEM;
lib/hash/rte_thash_gf2_poly_math.c +3 -3
index 1c62974e71..a28f2495a5 100644
@@ -118,16 +118,16 @@ static uint32_t
 gf2_mul(uint32_t a, uint32_t b, uint32_t r, int degree)
 {
 	uint64_t product = 0;
-	uint64_t r_poly = r|(1ULL << degree);
+	uint64_t r_poly = r | RTE_BIT64(degree);
 
 	for (; b; b &= (b - 1))
 		product ^= (uint64_t)a << (rte_bsf32(b));
 
 	for (int i = degree * 2 - 1; i >= degree; i--)
-		if (product & (1 << i))
+		if (product & RTE_BIT64(i))
 			product ^= r_poly << (i - degree);
 
-	return product;
+	return (uint32_t)product;
 }
 
 static uint32_t
Signature · 1 line
2.47.2.vfs.0.1
#16 lore raw

PATCH v3 3/3 drivers/crypto: use RTE_BIT64 in initializations of hash_algos

In reply to Andre Muezerie

This was found during code review of similar issues.

---
 drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c | 4 ++--
 drivers/crypto/openssl/rte_openssl_pmd_ops.c      | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c +2 -2
index 4394513002..e78bc37c37 100644
@@ -1207,8 +1207,8 @@ static const struct rte_cryptodev_capabilities caps_eddsa[] = {
 		{.asym = {
 			.xform_capa = {
 				.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA,
-				.hash_algos = (1 << RTE_CRYPTO_AUTH_SHA512 |
-					       1 << RTE_CRYPTO_AUTH_SHAKE_256),
+				.hash_algos = (RTE_BIT64(RTE_CRYPTO_AUTH_SHA512) |
+					       RTE_BIT64(RTE_CRYPTO_AUTH_SHAKE_256)),
 				.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
 					     (1 << RTE_CRYPTO_ASYM_OP_VERIFY))
 			}
drivers/crypto/openssl/rte_openssl_pmd_ops.c +2 -2
index 18f096abfd..04e018f3df 100644
@@ -630,8 +630,8 @@ static const struct rte_cryptodev_capabilities openssl_pmd_capabilities[] = {
 		{.asym = {
 			.xform_capa = {
 				.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA,
-				.hash_algos = (1 << RTE_CRYPTO_AUTH_SHA512 |
-					       1 << RTE_CRYPTO_AUTH_SHAKE_256),
+				.hash_algos = (RTE_BIT64(RTE_CRYPTO_AUTH_SHA512) |
+					       RTE_BIT64(RTE_CRYPTO_AUTH_SHAKE_256)),
 				.op_types =
 				((1<<RTE_CRYPTO_ASYM_OP_SIGN) |
 				 (1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
Signature · 1 line
2.47.2.vfs.0.1
Reviewed-by on v3 3/3
#17 lore raw

RE: [PATCH v3 3/3] drivers/crypto: use RTE_BIT64 in initializations of hash_algos

Quoted 7 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Monday, 27 January 2025 20.33

This was found during code review of similar issues.

---

CNXK crypto & OpenSSL crypto driver maintainers, please review/ack.

Quoted 44 lines
 drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c | 4 ++--
 drivers/crypto/openssl/rte_openssl_pmd_ops.c      | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c +1 -2
index 4394513002..e78bc37c37 100644
@@ -1207,8 +1207,8 @@ static const struct rte_cryptodev_capabilities
 caps_eddsa[] = {
 		{.asym = {
 			.xform_capa = {
 				.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA,
-				.hash_algos = (1 << RTE_CRYPTO_AUTH_SHA512 |
-					       1 << RTE_CRYPTO_AUTH_SHAKE_256),
+				.hash_algos =

(RTE_BIT64(RTE_CRYPTO_AUTH_SHA512) |
+
RTE_BIT64(RTE_CRYPTO_AUTH_SHAKE_256)),

drivers/crypto/cnxk/cnxk_cryptodev_capabilities.c +0 -0
 				.op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) |
 					     (1 << RTE_CRYPTO_ASYM_OP_VERIFY))
 			}
drivers/crypto/openssl/rte_openssl_pmd_ops.c +1 -2
index 18f096abfd..04e018f3df 100644
@@ -630,8 +630,8 @@ static const struct rte_cryptodev_capabilities
 openssl_pmd_capabilities[] = {
 		{.asym = {
 			.xform_capa = {
 				.xform_type = RTE_CRYPTO_ASYM_XFORM_EDDSA,
-				.hash_algos = (1 << RTE_CRYPTO_AUTH_SHA512 |
-					       1 << RTE_CRYPTO_AUTH_SHAKE_256),
+				.hash_algos =

(RTE_BIT64(RTE_CRYPTO_AUTH_SHA512) |
+
RTE_BIT64(RTE_CRYPTO_AUTH_SHAKE_256)),

drivers/crypto/openssl/rte_openssl_pmd_ops.c +0 -1
 				.op_types =
 				((1<<RTE_CRYPTO_ASYM_OP_SIGN) |
 				 (1 << RTE_CRYPTO_ASYM_OP_VERIFY)),
--

2.47.2.vfs.0.1

Acked-by
#18 lore raw

RE: [PATCH v3 3/3] drivers/crypto: use RTE_BIT64 in initializations of hash_algos

Quoted 11 lines
Quoted 7 lines

From: Andre Muezerie [mailto:[email protected]]
Sent: Monday, 27 January 2025 20.33

This was found during code review of similar issues.

---

CNXK crypto & OpenSSL crypto driver maintainers, please review/ack.

#19 lore raw
In reply to Andre Muezerie
Quoted 13 lines

MSVC issues the warning below:

../lib/cryptodev/rte_cryptodev.c(623): warning C4334: '<<':
result of 32-bit shift implicitly converted to 64 bits (was 64-bit shift intended?)

The code would be better off by using 64 bit numbers to begin with. That eliminates the need for a conversion to 64 bits later.

This patch actually fixes a bug present in previous DPDK versions because the last of the hash enums RTE_CRYPTO_AUTH_SM3_HMAC in rte_crypto_auth_algorithm has value 32.

Quoted 6 lines
Fixes 6f8ef8b68edb ("cryptodev: add hash algorithms in asymmetric capability")

V2 of this patch was already applied to dpdk-next-crypto.

Now the other patches of the series are also applied. Thanks.