diff mbox series

[v3,2/6] crypto: arm64/sm3-ce - make dependent on sm3 library

Message ID 20211223043547.32297-3-tianjia.zhang@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series Introduce x86 assembly accelerated implementation for SM3 algorithm | expand

Commit Message

tianjia.zhang Dec. 23, 2021, 4:35 a.m. UTC
SM3 generic library is stand-alone implementation, sm3-ce can depend
on the SM3 library instead of sm3-generic.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
---
 arch/arm64/crypto/Kconfig       |  2 +-
 arch/arm64/crypto/sm3-ce-glue.c | 20 ++++++++++++++------
 2 files changed, 15 insertions(+), 7 deletions(-)

Comments

Herbert Xu Jan. 7, 2022, 3:28 a.m. UTC | #1
On Thu, Dec 23, 2021 at 12:35:43PM +0800, Tianjia Zhang wrote:
> SM3 generic library is stand-alone implementation, sm3-ce can depend
> on the SM3 library instead of sm3-generic.
> 
> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> ---
>  arch/arm64/crypto/Kconfig       |  2 +-
>  arch/arm64/crypto/sm3-ce-glue.c | 20 ++++++++++++++------
>  2 files changed, 15 insertions(+), 7 deletions(-)

This doesn't compile cleanly with C=1 W=1:

  CC [M]  arch/arm64/crypto/sm3-ce-glue.o
  AS [M]  arch/arm64/crypto/sm3-ce-core.o
  CC [M]  arch/arm64/crypto/sm4-ce-glue.o
  CHECK   ../arch/arm64/crypto/sha3-ce-glue.c
../arch/arm64/crypto/sm3-ce-glue.c: In function ‘sm3_ce_update’:
../arch/arm64/crypto/sm3-ce-glue.c:30:10: error: void value not ignored as it ought to be
   30 |   return sm3_update(shash_desc_ctx(desc), data, len);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../arch/arm64/crypto/sm3-ce-glue.c: In function ‘sm3_ce_final’:
../arch/arm64/crypto/sm3-ce-glue.c:42:10: error: void value not ignored as it ought to be
   42 |   return sm3_final(shash_desc_ctx(desc), out);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
make[3]: *** [../scripts/Makefile.build:287: arch/arm64/crypto/sm3-ce-glue.o] Error 1
make[3]: *** Waiting for unfinished jobs....

Please make sure everything builds cleanly with C=1 W=1 *before*
you submit.

Thanks,
tianjia.zhang Jan. 7, 2022, 8:57 a.m. UTC | #2
Hi Herbert,

On 1/7/22 11:28 AM, Herbert Xu wrote:
> On Thu, Dec 23, 2021 at 12:35:43PM +0800, Tianjia Zhang wrote:
>> SM3 generic library is stand-alone implementation, sm3-ce can depend
>> on the SM3 library instead of sm3-generic.
>>
>> Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
>> ---
>>   arch/arm64/crypto/Kconfig       |  2 +-
>>   arch/arm64/crypto/sm3-ce-glue.c | 20 ++++++++++++++------
>>   2 files changed, 15 insertions(+), 7 deletions(-)
> 
> This doesn't compile cleanly with C=1 W=1:
> 
>    CC [M]  arch/arm64/crypto/sm3-ce-glue.o
>    AS [M]  arch/arm64/crypto/sm3-ce-core.o
>    CC [M]  arch/arm64/crypto/sm4-ce-glue.o
>    CHECK   ../arch/arm64/crypto/sha3-ce-glue.c
> ../arch/arm64/crypto/sm3-ce-glue.c: In function ‘sm3_ce_update’:
> ../arch/arm64/crypto/sm3-ce-glue.c:30:10: error: void value not ignored as it ought to be
>     30 |   return sm3_update(shash_desc_ctx(desc), data, len);
>        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> ../arch/arm64/crypto/sm3-ce-glue.c: In function ‘sm3_ce_final’:
> ../arch/arm64/crypto/sm3-ce-glue.c:42:10: error: void value not ignored as it ought to be
>     42 |   return sm3_final(shash_desc_ctx(desc), out);
>        |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> make[3]: *** [../scripts/Makefile.build:287: arch/arm64/crypto/sm3-ce-glue.o] Error 1
> make[3]: *** Waiting for unfinished jobs....
> 
> Please make sure everything builds cleanly with C=1 W=1 *before*
> you submit.
> 
> Thanks,

Thanks for pointing it out, will fix it in next patch. There will never 
be such a low-level error in the future

Kind Regards,
Tianjia
diff mbox series

Patch

diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig
index addfa413650b..2a965aa0188d 100644
--- a/arch/arm64/crypto/Kconfig
+++ b/arch/arm64/crypto/Kconfig
@@ -45,7 +45,7 @@  config CRYPTO_SM3_ARM64_CE
 	tristate "SM3 digest algorithm (ARMv8.2 Crypto Extensions)"
 	depends on KERNEL_MODE_NEON
 	select CRYPTO_HASH
-	select CRYPTO_SM3
+	select CRYPTO_LIB_SM3
 
 config CRYPTO_SM4_ARM64_CE
 	tristate "SM4 symmetric cipher (ARMv8.2 Crypto Extensions)"
diff --git a/arch/arm64/crypto/sm3-ce-glue.c b/arch/arm64/crypto/sm3-ce-glue.c
index d71faca322f2..3198f31c9446 100644
--- a/arch/arm64/crypto/sm3-ce-glue.c
+++ b/arch/arm64/crypto/sm3-ce-glue.c
@@ -27,7 +27,7 @@  static int sm3_ce_update(struct shash_desc *desc, const u8 *data,
 			 unsigned int len)
 {
 	if (!crypto_simd_usable())
-		return crypto_sm3_update(desc, data, len);
+		return sm3_update(shash_desc_ctx(desc), data, len);
 
 	kernel_neon_begin();
 	sm3_base_do_update(desc, data, len, sm3_ce_transform);
@@ -39,7 +39,7 @@  static int sm3_ce_update(struct shash_desc *desc, const u8 *data,
 static int sm3_ce_final(struct shash_desc *desc, u8 *out)
 {
 	if (!crypto_simd_usable())
-		return crypto_sm3_finup(desc, NULL, 0, out);
+		return sm3_final(shash_desc_ctx(desc), out);
 
 	kernel_neon_begin();
 	sm3_base_do_finalize(desc, sm3_ce_transform);
@@ -51,14 +51,22 @@  static int sm3_ce_final(struct shash_desc *desc, u8 *out)
 static int sm3_ce_finup(struct shash_desc *desc, const u8 *data,
 			unsigned int len, u8 *out)
 {
-	if (!crypto_simd_usable())
-		return crypto_sm3_finup(desc, data, len, out);
+	if (!crypto_simd_usable()) {
+		struct sm3_state *sctx = shash_desc_ctx(desc);
+
+		if (len)
+			sm3_update(sctx, data, len);
+		sm3_final(sctx, out);
+		return 0;
+	}
 
 	kernel_neon_begin();
-	sm3_base_do_update(desc, data, len, sm3_ce_transform);
+	if (len)
+		sm3_base_do_update(desc, data, len, sm3_ce_transform);
+	sm3_base_do_finalize(desc, sm3_ce_transform);
 	kernel_neon_end();
 
-	return sm3_ce_final(desc, out);
+	return sm3_base_finish(desc, out);
 }
 
 static struct shash_alg sm3_alg = {