diff mbox series

[1/5] crypto: sha256 - remove duplicate generic hash init function

Message ID 20211220092318.5793-2-tianjia.zhang@linux.alibaba.com
State Accepted
Commit 96ede30f4b172ab6c83789f6bb420b3c3c029653
Headers show
Series Remove duplicate context init function for sha algorithm | expand

Commit Message

tianjia.zhang Dec. 20, 2021, 9:23 a.m. UTC
crypto_sha256_init() and sha256_base_init() are the same repeated
implementations, remove the crypto_sha256_init() in generic
implementation, sha224 is the same process.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
---
 crypto/sha256_generic.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

Comments

Julian Calaby Dec. 22, 2021, 10:35 p.m. UTC | #1
Hi Tianjia,

On Mon, Dec 20, 2021 at 8:25 PM Tianjia Zhang
<tianjia.zhang@linux.alibaba.com> wrote:
>
> crypto_sha256_init() and sha256_base_init() are the same repeated
> implementations, remove the crypto_sha256_init() in generic
> implementation, sha224 is the same process.
>
> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> ---
>  crypto/sha256_generic.c | 16 ++--------------
>  1 file changed, 2 insertions(+), 14 deletions(-)
>
> diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
> index 3b377197236e..bf147b01e313 100644
> --- a/crypto/sha256_generic.c
> +++ b/crypto/sha256_generic.c
> @@ -72,7 +60,7 @@ EXPORT_SYMBOL(crypto_sha256_finup);
>
>  static struct shash_alg sha256_algs[2] = { {
>         .digestsize     =       SHA256_DIGEST_SIZE,
> -       .init           =       crypto_sha256_init,
> +       .init           =       sha256_base_init,
>         .update         =       crypto_sha256_update,
>         .final          =       crypto_sha256_final,
>         .finup          =       crypto_sha256_finup,
> @@ -86,7 +74,7 @@ static struct shash_alg sha256_algs[2] = { {
>         }
>  }, {
>         .digestsize     =       SHA224_DIGEST_SIZE,
> -       .init           =       crypto_sha224_init,
> +       .init           =       sha224_base_init,
>         .update         =       crypto_sha256_update,
>         .final          =       crypto_sha256_final,
>         .finup          =       crypto_sha256_finup,

Aren't these two functions defined as static inline functions? It
appears that these crypto_ wrappers were added so there's "actual"
referenceable functions for these structs.

Did this actually compile?

Thanks,
tianjia.zhang Dec. 23, 2021, 2:59 a.m. UTC | #2
Hi Julian,

On 12/23/21 6:35 AM, Julian Calaby wrote:
> Hi Tianjia,
> 
> On Mon, Dec 20, 2021 at 8:25 PM Tianjia Zhang
> <tianjia.zhang@linux.alibaba.com> wrote:
>>
>> crypto_sha256_init() and sha256_base_init() are the same repeated
>> implementations, remove the crypto_sha256_init() in generic
>> implementation, sha224 is the same process.
>>
>> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
>> ---
>>   crypto/sha256_generic.c | 16 ++--------------
>>   1 file changed, 2 insertions(+), 14 deletions(-)
>>
>> diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
>> index 3b377197236e..bf147b01e313 100644
>> --- a/crypto/sha256_generic.c
>> +++ b/crypto/sha256_generic.c
>> @@ -72,7 +60,7 @@ EXPORT_SYMBOL(crypto_sha256_finup);
>>
>>   static struct shash_alg sha256_algs[2] = { {
>>          .digestsize     =       SHA256_DIGEST_SIZE,
>> -       .init           =       crypto_sha256_init,
>> +       .init           =       sha256_base_init,
>>          .update         =       crypto_sha256_update,
>>          .final          =       crypto_sha256_final,
>>          .finup          =       crypto_sha256_finup,
>> @@ -86,7 +74,7 @@ static struct shash_alg sha256_algs[2] = { {
>>          }
>>   }, {
>>          .digestsize     =       SHA224_DIGEST_SIZE,
>> -       .init           =       crypto_sha224_init,
>> +       .init           =       sha224_base_init,
>>          .update         =       crypto_sha256_update,
>>          .final          =       crypto_sha256_final,
>>          .finup          =       crypto_sha256_finup,
> 
> Aren't these two functions defined as static inline functions? It
> appears that these crypto_ wrappers were added so there's "actual"
> referenceable functions for these structs.
> 
> Did this actually compile?
> 
> Thanks,
> 

Judging from the compilation results, there is really no difference, but 
the modification made by this patch is still necessary, because 
crypto_sha256_init() wrapper and sha256_base_init() are two completely 
duplicate functions.

Best regards,
Tianjia
diff mbox series

Patch

diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index 3b377197236e..bf147b01e313 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -33,18 +33,6 @@  const u8 sha256_zero_message_hash[SHA256_DIGEST_SIZE] = {
 };
 EXPORT_SYMBOL_GPL(sha256_zero_message_hash);
 
-static int crypto_sha256_init(struct shash_desc *desc)
-{
-	sha256_init(shash_desc_ctx(desc));
-	return 0;
-}
-
-static int crypto_sha224_init(struct shash_desc *desc)
-{
-	sha224_init(shash_desc_ctx(desc));
-	return 0;
-}
-
 int crypto_sha256_update(struct shash_desc *desc, const u8 *data,
 			  unsigned int len)
 {
@@ -72,7 +60,7 @@  EXPORT_SYMBOL(crypto_sha256_finup);
 
 static struct shash_alg sha256_algs[2] = { {
 	.digestsize	=	SHA256_DIGEST_SIZE,
-	.init		=	crypto_sha256_init,
+	.init		=	sha256_base_init,
 	.update		=	crypto_sha256_update,
 	.final		=	crypto_sha256_final,
 	.finup		=	crypto_sha256_finup,
@@ -86,7 +74,7 @@  static struct shash_alg sha256_algs[2] = { {
 	}
 }, {
 	.digestsize	=	SHA224_DIGEST_SIZE,
-	.init		=	crypto_sha224_init,
+	.init		=	sha224_base_init,
 	.update		=	crypto_sha256_update,
 	.final		=	crypto_sha256_final,
 	.finup		=	crypto_sha256_finup,