linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] crypto: lib/sha256 - return void
@ 2020-05-01  7:13 Eric Biggers
  2020-05-01 12:28 ` Christophe Leroy
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Biggers @ 2020-05-01  7:13 UTC (permalink / raw)
  To: linux-crypto

From: Eric Biggers <ebiggers@google.com>

The SHA-256 / SHA-224 library functions can't fail, so remove the
useless return value.

Also long as the declarations are being changed anyway, also fix some
parameter names in the declarations to match the definitions.

Signed-off-by: Eric Biggers <ebiggers@google.com>
---
 crypto/sha256_generic.c      | 14 +++++++++-----
 include/crypto/sha.h         | 20 ++++++++------------
 include/crypto/sha256_base.h |  6 ++++--
 lib/crypto/sha256.c          | 20 ++++++++------------
 4 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index f2d7095d4f2d64..88156e3e2a33e0 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -35,27 +35,31 @@ EXPORT_SYMBOL_GPL(sha256_zero_message_hash);
 
 static int crypto_sha256_init(struct shash_desc *desc)
 {
-	return sha256_init(shash_desc_ctx(desc));
+	sha256_init(shash_desc_ctx(desc));
+	return 0;
 }
 
 static int crypto_sha224_init(struct shash_desc *desc)
 {
-	return sha224_init(shash_desc_ctx(desc));
+	sha224_init(shash_desc_ctx(desc));
+	return 0;
 }
 
 int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
 			  unsigned int len)
 {
-	return sha256_update(shash_desc_ctx(desc), data, len);
+	sha256_update(shash_desc_ctx(desc), data, len);
+	return 0;
 }
 EXPORT_SYMBOL(crypto_sha256_update);
 
 static int crypto_sha256_final(struct shash_desc *desc, u8 *out)
 {
 	if (crypto_shash_digestsize(desc->tfm) == SHA224_DIGEST_SIZE)
-		return sha224_final(shash_desc_ctx(desc), out);
+		sha224_final(shash_desc_ctx(desc), out);
 	else
-		return sha256_final(shash_desc_ctx(desc), out);
+		sha256_final(shash_desc_ctx(desc), out);
+	return 0;
 }
 
 int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
diff --git a/include/crypto/sha.h b/include/crypto/sha.h
index 5c2132c7190095..8db9e1a3eb0cf6 100644
--- a/include/crypto/sha.h
+++ b/include/crypto/sha.h
@@ -123,7 +123,7 @@ extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data,
  * For details see lib/crypto/sha256.c
  */
 
-static inline int sha256_init(struct sha256_state *sctx)
+static inline void sha256_init(struct sha256_state *sctx)
 {
 	sctx->state[0] = SHA256_H0;
 	sctx->state[1] = SHA256_H1;
@@ -134,14 +134,12 @@ static inline int sha256_init(struct sha256_state *sctx)
 	sctx->state[6] = SHA256_H6;
 	sctx->state[7] = SHA256_H7;
 	sctx->count = 0;
-
-	return 0;
 }
-extern int sha256_update(struct sha256_state *sctx, const u8 *input,
-			 unsigned int length);
-extern int sha256_final(struct sha256_state *sctx, u8 *hash);
+extern void sha256_update(struct sha256_state *sctx, const u8 *data,
+			  unsigned int len);
+extern void sha256_final(struct sha256_state *sctx, u8 *out);
 
-static inline int sha224_init(struct sha256_state *sctx)
+static inline void sha224_init(struct sha256_state *sctx)
 {
 	sctx->state[0] = SHA224_H0;
 	sctx->state[1] = SHA224_H1;
@@ -152,11 +150,9 @@ static inline int sha224_init(struct sha256_state *sctx)
 	sctx->state[6] = SHA224_H6;
 	sctx->state[7] = SHA224_H7;
 	sctx->count = 0;
-
-	return 0;
 }
-extern int sha224_update(struct sha256_state *sctx, const u8 *input,
-			 unsigned int length);
-extern int sha224_final(struct sha256_state *sctx, u8 *hash);
+extern void sha224_update(struct sha256_state *sctx, const u8 *data,
+			  unsigned int len);
+extern void sha224_final(struct sha256_state *sctx, u8 *out);
 
 #endif
diff --git a/include/crypto/sha256_base.h b/include/crypto/sha256_base.h
index cea60cff80bd87..6ded110783ae87 100644
--- a/include/crypto/sha256_base.h
+++ b/include/crypto/sha256_base.h
@@ -22,14 +22,16 @@ static inline int sha224_base_init(struct shash_desc *desc)
 {
 	struct sha256_state *sctx = shash_desc_ctx(desc);
 
-	return sha224_init(sctx);
+	sha224_init(sctx);
+	return 0;
 }
 
 static inline int sha256_base_init(struct shash_desc *desc)
 {
 	struct sha256_state *sctx = shash_desc_ctx(desc);
 
-	return sha256_init(sctx);
+	sha256_init(sctx);
+	return 0;
 }
 
 static inline int sha256_base_do_update(struct shash_desc *desc,
diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c
index 66cb04b0cf4e7e..2e621697c5c35c 100644
--- a/lib/crypto/sha256.c
+++ b/lib/crypto/sha256.c
@@ -206,7 +206,7 @@ static void sha256_transform(u32 *state, const u8 *input)
 	memzero_explicit(W, 64 * sizeof(u32));
 }
 
-int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
+void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
 {
 	unsigned int partial, done;
 	const u8 *src;
@@ -232,18 +232,16 @@ int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
 		partial = 0;
 	}
 	memcpy(sctx->buf + partial, src, len - done);
-
-	return 0;
 }
 EXPORT_SYMBOL(sha256_update);
 
-int sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
+void sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
 {
-	return sha256_update(sctx, data, len);
+	sha256_update(sctx, data, len);
 }
 EXPORT_SYMBOL(sha224_update);
 
-static int __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words)
+static void __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words)
 {
 	__be32 *dst = (__be32 *)out;
 	__be64 bits;
@@ -268,19 +266,17 @@ static int __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words)
 
 	/* Zeroize sensitive information. */
 	memset(sctx, 0, sizeof(*sctx));
-
-	return 0;
 }
 
-int sha256_final(struct sha256_state *sctx, u8 *out)
+void sha256_final(struct sha256_state *sctx, u8 *out)
 {
-	return __sha256_final(sctx, out, 8);
+	__sha256_final(sctx, out, 8);
 }
 EXPORT_SYMBOL(sha256_final);
 
-int sha224_final(struct sha256_state *sctx, u8 *out)
+void sha224_final(struct sha256_state *sctx, u8 *out)
 {
-	return __sha256_final(sctx, out, 7);
+	__sha256_final(sctx, out, 7);
 }
 EXPORT_SYMBOL(sha224_final);
 
-- 
2.26.2


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

* Re: [PATCH] crypto: lib/sha256 - return void
  2020-05-01  7:13 [PATCH] crypto: lib/sha256 - return void Eric Biggers
@ 2020-05-01 12:28 ` Christophe Leroy
  2020-05-01 16:39   ` Eric Biggers
  0 siblings, 1 reply; 3+ messages in thread
From: Christophe Leroy @ 2020-05-01 12:28 UTC (permalink / raw)
  To: Eric Biggers, linux-crypto



Le 01/05/2020 à 09:13, Eric Biggers a écrit :
> From: Eric Biggers <ebiggers@google.com>
> 
> The SHA-256 / SHA-224 library functions can't fail, so remove the
> useless return value.
> 
> Also long as the declarations are being changed anyway, also fix some
> parameter names in the declarations to match the definitions.
> 
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
>   crypto/sha256_generic.c      | 14 +++++++++-----
>   include/crypto/sha.h         | 20 ++++++++------------
>   include/crypto/sha256_base.h |  6 ++++--
>   lib/crypto/sha256.c          | 20 ++++++++------------
>   4 files changed, 29 insertions(+), 31 deletions(-)
> 
> diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
> index f2d7095d4f2d64..88156e3e2a33e0 100644
> --- a/crypto/sha256_generic.c
> +++ b/crypto/sha256_generic.c
> @@ -35,27 +35,31 @@ EXPORT_SYMBOL_GPL(sha256_zero_message_hash);
>   
>   static int crypto_sha256_init(struct shash_desc *desc)
>   {
> -	return sha256_init(shash_desc_ctx(desc));
> +	sha256_init(shash_desc_ctx(desc));
> +	return 0;
>   }
>   
>   static int crypto_sha224_init(struct shash_desc *desc)
>   {
> -	return sha224_init(shash_desc_ctx(desc));
> +	sha224_init(shash_desc_ctx(desc));
> +	return 0;
>   }
>   
>   int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
>   			  unsigned int len)
>   {
> -	return sha256_update(shash_desc_ctx(desc), data, len);
> +	sha256_update(shash_desc_ctx(desc), data, len);
> +	return 0;
>   }
>   EXPORT_SYMBOL(crypto_sha256_update);
>   
>   static int crypto_sha256_final(struct shash_desc *desc, u8 *out)
>   {
>   	if (crypto_shash_digestsize(desc->tfm) == SHA224_DIGEST_SIZE)
> -		return sha224_final(shash_desc_ctx(desc), out);
> +		sha224_final(shash_desc_ctx(desc), out);
>   	else
> -		return sha256_final(shash_desc_ctx(desc), out);
> +		sha256_final(shash_desc_ctx(desc), out);
> +	return 0;
>   }
>   
>   int crypto_sha256_finup(struct shash_desc *desc, const u8 *data,
> diff --git a/include/crypto/sha.h b/include/crypto/sha.h
> index 5c2132c7190095..8db9e1a3eb0cf6 100644
> --- a/include/crypto/sha.h
> +++ b/include/crypto/sha.h
> @@ -123,7 +123,7 @@ extern int crypto_sha512_finup(struct shash_desc *desc, const u8 *data,
>    * For details see lib/crypto/sha256.c
>    */
>   
> -static inline int sha256_init(struct sha256_state *sctx)
> +static inline void sha256_init(struct sha256_state *sctx)
>   {
>   	sctx->state[0] = SHA256_H0;
>   	sctx->state[1] = SHA256_H1;
> @@ -134,14 +134,12 @@ static inline int sha256_init(struct sha256_state *sctx)
>   	sctx->state[6] = SHA256_H6;
>   	sctx->state[7] = SHA256_H7;
>   	sctx->count = 0;
> -
> -	return 0;
>   }
> -extern int sha256_update(struct sha256_state *sctx, const u8 *input,
> -			 unsigned int length);
> -extern int sha256_final(struct sha256_state *sctx, u8 *hash);
> +extern void sha256_update(struct sha256_state *sctx, const u8 *data,
> +			  unsigned int len);
> +extern void sha256_final(struct sha256_state *sctx, u8 *out);

The 'extern' keywork is useless in a function declaration. It should be 
removed, as recommended by 'checkpatch --strict'.

>   
> -static inline int sha224_init(struct sha256_state *sctx)
> +static inline void sha224_init(struct sha256_state *sctx)
>   {
>   	sctx->state[0] = SHA224_H0;
>   	sctx->state[1] = SHA224_H1;
> @@ -152,11 +150,9 @@ static inline int sha224_init(struct sha256_state *sctx)
>   	sctx->state[6] = SHA224_H6;
>   	sctx->state[7] = SHA224_H7;
>   	sctx->count = 0;
> -
> -	return 0;
>   }
> -extern int sha224_update(struct sha256_state *sctx, const u8 *input,
> -			 unsigned int length);
> -extern int sha224_final(struct sha256_state *sctx, u8 *hash);
> +extern void sha224_update(struct sha256_state *sctx, const u8 *data,
> +			  unsigned int len);
> +extern void sha224_final(struct sha256_state *sctx, u8 *out);

The 'extern' keywork is useless in a function declaration. It should be 
removed, as recommended by 'checkpatch --strict'.

>   
>   #endif
> diff --git a/include/crypto/sha256_base.h b/include/crypto/sha256_base.h
> index cea60cff80bd87..6ded110783ae87 100644
> --- a/include/crypto/sha256_base.h
> +++ b/include/crypto/sha256_base.h
> @@ -22,14 +22,16 @@ static inline int sha224_base_init(struct shash_desc *desc)
>   {
>   	struct sha256_state *sctx = shash_desc_ctx(desc);
>   
> -	return sha224_init(sctx);
> +	sha224_init(sctx);
> +	return 0;
>   }
>   
>   static inline int sha256_base_init(struct shash_desc *desc)
>   {
>   	struct sha256_state *sctx = shash_desc_ctx(desc);
>   
> -	return sha256_init(sctx);
> +	sha256_init(sctx);
> +	return 0;
>   }
>   
>   static inline int sha256_base_do_update(struct shash_desc *desc,
> diff --git a/lib/crypto/sha256.c b/lib/crypto/sha256.c
> index 66cb04b0cf4e7e..2e621697c5c35c 100644
> --- a/lib/crypto/sha256.c
> +++ b/lib/crypto/sha256.c
> @@ -206,7 +206,7 @@ static void sha256_transform(u32 *state, const u8 *input)
>   	memzero_explicit(W, 64 * sizeof(u32));
>   }
>   
> -int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
> +void sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
>   {
>   	unsigned int partial, done;
>   	const u8 *src;
> @@ -232,18 +232,16 @@ int sha256_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
>   		partial = 0;
>   	}
>   	memcpy(sctx->buf + partial, src, len - done);
> -
> -	return 0;
>   }
>   EXPORT_SYMBOL(sha256_update);
>   
> -int sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
> +void sha224_update(struct sha256_state *sctx, const u8 *data, unsigned int len)
>   {
> -	return sha256_update(sctx, data, len);
> +	sha256_update(sctx, data, len);
>   }
>   EXPORT_SYMBOL(sha224_update);
>   
> -static int __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words)
> +static void __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words)
>   {
>   	__be32 *dst = (__be32 *)out;
>   	__be64 bits;
> @@ -268,19 +266,17 @@ static int __sha256_final(struct sha256_state *sctx, u8 *out, int digest_words)
>   
>   	/* Zeroize sensitive information. */
>   	memset(sctx, 0, sizeof(*sctx));
> -
> -	return 0;
>   }
>   
> -int sha256_final(struct sha256_state *sctx, u8 *out)
> +void sha256_final(struct sha256_state *sctx, u8 *out)
>   {
> -	return __sha256_final(sctx, out, 8);
> +	__sha256_final(sctx, out, 8);
>   }
>   EXPORT_SYMBOL(sha256_final);
>   
> -int sha224_final(struct sha256_state *sctx, u8 *out)
> +void sha224_final(struct sha256_state *sctx, u8 *out)
>   {
> -	return __sha256_final(sctx, out, 7);
> +	__sha256_final(sctx, out, 7);
>   }
>   EXPORT_SYMBOL(sha224_final);
>   
> 

Christophe

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

* Re: [PATCH] crypto: lib/sha256 - return void
  2020-05-01 12:28 ` Christophe Leroy
@ 2020-05-01 16:39   ` Eric Biggers
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Biggers @ 2020-05-01 16:39 UTC (permalink / raw)
  To: Christophe Leroy; +Cc: linux-crypto

On Fri, May 01, 2020 at 02:28:12PM +0200, Christophe Leroy wrote:
> > -extern int sha256_update(struct sha256_state *sctx, const u8 *input,
> > -			 unsigned int length);
> > -extern int sha256_final(struct sha256_state *sctx, u8 *hash);
> > +extern void sha256_update(struct sha256_state *sctx, const u8 *data,
> > +			  unsigned int len);
> > +extern void sha256_final(struct sha256_state *sctx, u8 *out);
> 
> The 'extern' keywork is useless in a function declaration. It should be
> removed, as recommended by 'checkpatch --strict'.

Sure I can do this, just keep in mind that a lot of kernel code still uses
'extern' (including the other function declarations in this file) and some
people still disagree about the preferred style.  That's why this warning hasn't
been enabled in 'checkpatch' by default.

- Eric

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

end of thread, other threads:[~2020-05-01 16:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-01  7:13 [PATCH] crypto: lib/sha256 - return void Eric Biggers
2020-05-01 12:28 ` Christophe Leroy
2020-05-01 16:39   ` Eric Biggers

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