public inbox for linux-crypto@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/2] crypto: Fix sha1 compile error
@ 2025-06-14  0:08 Yuzhuo Jing
  2025-06-14  0:08 ` [PATCH v1 1/2] crypto: Fix sha1 signed integer comparison " Yuzhuo Jing
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yuzhuo Jing @ 2025-06-14  0:08 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Ian Rogers, linux-crypto,
	linux-kernel
  Cc: Yuzhuo Jing

This is a followup patch series for an ongoing patch series to reuse
kernel tree sha1 utils in perf tools and remove libcrypto dependency.
This mirrors the fixes made in perf back to the kernel tree so we can
use tools/perf/check-headers.sh to monitor future changes.
Link: https://lore.kernel.org/lkml/aC9lXhPFcs5fkHWH@x1/t/#u

This series contains two patches: one fixing signed and unsigned integer
comparisons and another fixing function type mismatches.

Yuzhuo Jing (2):
  crypto: Fix sha1 signed integer comparison compile error
  crypto: Fix sha1 signed pointer comparison compile error

 crypto/sha1_generic.c      | 2 +-
 include/crypto/sha1_base.h | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

-- 
2.50.0.rc1.591.g9c95f17f64-goog


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

* [PATCH v1 1/2] crypto: Fix sha1 signed integer comparison compile error
  2025-06-14  0:08 [PATCH v1 0/2] crypto: Fix sha1 compile error Yuzhuo Jing
@ 2025-06-14  0:08 ` Yuzhuo Jing
  2025-06-14  0:08 ` [PATCH v1 2/2] crypto: Fix sha1 signed pointer " Yuzhuo Jing
  2025-06-14  4:53 ` [PATCH v1 0/2] crypto: Fix sha1 " Eric Biggers
  2 siblings, 0 replies; 4+ messages in thread
From: Yuzhuo Jing @ 2025-06-14  0:08 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Ian Rogers, linux-crypto,
	linux-kernel
  Cc: Yuzhuo Jing

On platforms where -Werror=sign-compare compiler flag is enabled, sha1
code gives errors when for signed to unsigned integer comparisons.
This patch fixes the issue.

Signed-off-by: Yuzhuo Jing <yuzhuo@google.com>
---
 include/crypto/sha1_base.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/crypto/sha1_base.h b/include/crypto/sha1_base.h
index 0c342ed0d038..3460759d31db 100644
--- a/include/crypto/sha1_base.h
+++ b/include/crypto/sha1_base.h
@@ -73,7 +73,7 @@ static inline int sha1_base_do_update(struct shash_desc *desc,
 static inline int sha1_base_do_finalize(struct shash_desc *desc,
 					sha1_block_fn *block_fn)
 {
-	const int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64);
+	const unsigned int bit_offset = SHA1_BLOCK_SIZE - sizeof(__be64);
 	struct sha1_state *sctx = shash_desc_ctx(desc);
 	__be64 *bits = (__be64 *)(sctx->buffer + bit_offset);
 	unsigned int partial = sctx->count % SHA1_BLOCK_SIZE;
@@ -99,7 +99,7 @@ static inline int sha1_base_finish(struct shash_desc *desc, u8 *out)
 	__be32 *digest = (__be32 *)out;
 	int i;
 
-	for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(__be32); i++)
+	for (i = 0; i < SHA1_DIGEST_SIZE / (int)sizeof(__be32); i++)
 		put_unaligned_be32(sctx->state[i], digest++);
 
 	memzero_explicit(sctx, sizeof(*sctx));
-- 
2.50.0.rc1.591.g9c95f17f64-goog


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

* [PATCH v1 2/2] crypto: Fix sha1 signed pointer comparison compile error
  2025-06-14  0:08 [PATCH v1 0/2] crypto: Fix sha1 compile error Yuzhuo Jing
  2025-06-14  0:08 ` [PATCH v1 1/2] crypto: Fix sha1 signed integer comparison " Yuzhuo Jing
@ 2025-06-14  0:08 ` Yuzhuo Jing
  2025-06-14  4:53 ` [PATCH v1 0/2] crypto: Fix sha1 " Eric Biggers
  2 siblings, 0 replies; 4+ messages in thread
From: Yuzhuo Jing @ 2025-06-14  0:08 UTC (permalink / raw)
  To: Herbert Xu, David S . Miller, Ian Rogers, linux-crypto,
	linux-kernel
  Cc: Yuzhuo Jing

In include/crypto/sha1_base.h, sha1_block_fn type is defined as
void(sha1_block_fn)(struct sha1_state *sst, u8 const *src, int blocks);

In lib/crypto/sha1.c, the second argument on sha1_transform is defined
as "const char *", which causes type mismatch when calling
sha1_transform from sha1_generic_block_fn in crypto/sha1_generic.c.

We don't break the widely used sha1_block_fn or sha1_transform function
signatures, so this patch converts the pointer sign at usage to fix the
compile error for environments that enable -Werror=pointer-sign.

Signed-off-by: Yuzhuo Jing <yuzhuo@google.com>
---
 crypto/sha1_generic.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
index 325b57fe28dc..3a3f9608b989 100644
--- a/crypto/sha1_generic.c
+++ b/crypto/sha1_generic.c
@@ -33,7 +33,7 @@ static void sha1_generic_block_fn(struct sha1_state *sst, u8 const *src,
 	u32 temp[SHA1_WORKSPACE_WORDS];
 
 	while (blocks--) {
-		sha1_transform(sst->state, src, temp);
+		sha1_transform(sst->state, (const char *)src, temp);
 		src += SHA1_BLOCK_SIZE;
 	}
 	memzero_explicit(temp, sizeof(temp));
-- 
2.50.0.rc1.591.g9c95f17f64-goog


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

* Re: [PATCH v1 0/2] crypto: Fix sha1 compile error
  2025-06-14  0:08 [PATCH v1 0/2] crypto: Fix sha1 compile error Yuzhuo Jing
  2025-06-14  0:08 ` [PATCH v1 1/2] crypto: Fix sha1 signed integer comparison " Yuzhuo Jing
  2025-06-14  0:08 ` [PATCH v1 2/2] crypto: Fix sha1 signed pointer " Yuzhuo Jing
@ 2025-06-14  4:53 ` Eric Biggers
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Biggers @ 2025-06-14  4:53 UTC (permalink / raw)
  To: Yuzhuo Jing
  Cc: Herbert Xu, David S . Miller, Ian Rogers, linux-crypto,
	linux-kernel

On Fri, Jun 13, 2025 at 05:08:26PM -0700, Yuzhuo Jing wrote:
> This is a followup patch series for an ongoing patch series to reuse
> kernel tree sha1 utils in perf tools and remove libcrypto dependency.
> This mirrors the fixes made in perf back to the kernel tree so we can
> use tools/perf/check-headers.sh to monitor future changes.
> Link: https://lore.kernel.org/lkml/aC9lXhPFcs5fkHWH@x1/t/#u
> 
> This series contains two patches: one fixing signed and unsigned integer
> comparisons and another fixing function type mismatches.
> 
> Yuzhuo Jing (2):
>   crypto: Fix sha1 signed integer comparison compile error
>   crypto: Fix sha1 signed pointer comparison compile error
> 
>  crypto/sha1_generic.c      | 2 +-
>  include/crypto/sha1_base.h | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)

I don't like these signedness inconsistencies in the code either, and I'll be
fixing these (among many other issues) when I refactor SHA-1 to have a proper
lib/crypto/ API similar to what I'm currently doing with SHA-2.  That being
said, the kernel doesn't have these warnings enabled, and especially in its
current state this code isn't really designed to be copied into a userspace
program.

So I feel that the premise of this patchset, and more importantly also the one
you linked to above for tools/perf/, is a bit misguided.

I've sent an alternative patchset for you to consider:
https://lore.kernel.org/all/20250614044133.660848-1-ebiggers@kernel.org/.  It
adds a minimal SHA-1 implementation, including a test, to tools/perf/util/.  The
SHA-1 implementation is less than 100 lines anyway.

The effort it would take to "share" the kernel's code here is just not worth it,
IMO.  Especially when I have some significant refactoring planned on the kernel
side which would make the tools/perf copy diverge anyway.

- Eric

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

end of thread, other threads:[~2025-06-14  4:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-14  0:08 [PATCH v1 0/2] crypto: Fix sha1 compile error Yuzhuo Jing
2025-06-14  0:08 ` [PATCH v1 1/2] crypto: Fix sha1 signed integer comparison " Yuzhuo Jing
2025-06-14  0:08 ` [PATCH v1 2/2] crypto: Fix sha1 signed pointer " Yuzhuo Jing
2025-06-14  4:53 ` [PATCH v1 0/2] crypto: Fix sha1 " Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox