* [PATCH] crypto: move sm3 and sm4 into crypto directory
@ 2022-03-14 3:11 Jason A. Donenfeld
2022-03-16 17:16 ` Eric Biggers
2022-04-08 8:30 ` Herbert Xu
0 siblings, 2 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-14 3:11 UTC (permalink / raw)
To: linux-crypto, herbert, tianjia.zhang, ebiggers; +Cc: Jason A. Donenfeld
The lib/crypto libraries live in lib because they are used by various
drivers of the kernel. In contrast, the various helper functions in
crypto are there because they're used exclusively by the crypto API. The
SM3 and SM4 helper functions were erroniously moved into lib/crypto/
instead of crypto/, even though there are no in-kernel users outside of
the crypto API of those functions. This commit moves them into crypto/.
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Cc: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
arch/arm64/crypto/Kconfig | 4 ++--
crypto/Kconfig | 18 ++++++++++++------
crypto/Makefile | 6 ++++--
{lib/crypto => crypto}/sm3.c | 0
{lib/crypto => crypto}/sm4.c | 0
lib/crypto/Kconfig | 6 ------
lib/crypto/Makefile | 6 ------
7 files changed, 18 insertions(+), 22 deletions(-)
rename {lib/crypto => crypto}/sm3.c (100%)
rename {lib/crypto => crypto}/sm4.c (100%)
diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig
index 2a965aa0188d..454621a20eaa 100644
--- a/arch/arm64/crypto/Kconfig
+++ b/arch/arm64/crypto/Kconfig
@@ -45,13 +45,13 @@ config CRYPTO_SM3_ARM64_CE
tristate "SM3 digest algorithm (ARMv8.2 Crypto Extensions)"
depends on KERNEL_MODE_NEON
select CRYPTO_HASH
- select CRYPTO_LIB_SM3
+ select CRYPTO_SM3
config CRYPTO_SM4_ARM64_CE
tristate "SM4 symmetric cipher (ARMv8.2 Crypto Extensions)"
depends on KERNEL_MODE_NEON
select CRYPTO_ALGAPI
- select CRYPTO_LIB_SM4
+ select CRYPTO_SM4
config CRYPTO_GHASH_ARM64_CE
tristate "GHASH/AES-GCM using ARMv8 Crypto Extensions"
diff --git a/crypto/Kconfig b/crypto/Kconfig
index d6d7e84bb7f8..517525d7d12e 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -274,7 +274,7 @@ config CRYPTO_ECRDSA
config CRYPTO_SM2
tristate "SM2 algorithm"
- select CRYPTO_LIB_SM3
+ select CRYPTO_SM3
select CRYPTO_AKCIPHER
select CRYPTO_MANAGER
select MPILIB
@@ -1005,9 +1005,12 @@ config CRYPTO_SHA3
http://keccak.noekeon.org/
config CRYPTO_SM3
+ tristate
+
+config CRYPTO_SM3_GENERIC
tristate "SM3 digest algorithm"
select CRYPTO_HASH
- select CRYPTO_LIB_SM3
+ select CRYPTO_SM3
help
SM3 secure hash function as defined by OSCCA GM/T 0004-2012 SM3).
It is part of the Chinese Commercial Cryptography suite.
@@ -1020,7 +1023,7 @@ config CRYPTO_SM3_AVX_X86_64
tristate "SM3 digest algorithm (x86_64/AVX)"
depends on X86 && 64BIT
select CRYPTO_HASH
- select CRYPTO_LIB_SM3
+ select CRYPTO_SM3
help
SM3 secure hash function as defined by OSCCA GM/T 0004-2012 SM3).
It is part of the Chinese Commercial Cryptography suite. This is
@@ -1567,9 +1570,12 @@ config CRYPTO_SERPENT_AVX2_X86_64
<https://www.cl.cam.ac.uk/~rja14/serpent.html>
config CRYPTO_SM4
+ tristate
+
+config CRYPTO_SM4_GENERIC
tristate "SM4 cipher algorithm"
select CRYPTO_ALGAPI
- select CRYPTO_LIB_SM4
+ select CRYPTO_SM4
help
SM4 cipher algorithms (OSCCA GB/T 32907-2016).
@@ -1598,7 +1604,7 @@ config CRYPTO_SM4_AESNI_AVX_X86_64
select CRYPTO_SKCIPHER
select CRYPTO_SIMD
select CRYPTO_ALGAPI
- select CRYPTO_LIB_SM4
+ select CRYPTO_SM4
help
SM4 cipher algorithms (OSCCA GB/T 32907-2016) (x86_64/AES-NI/AVX).
@@ -1619,7 +1625,7 @@ config CRYPTO_SM4_AESNI_AVX2_X86_64
select CRYPTO_SKCIPHER
select CRYPTO_SIMD
select CRYPTO_ALGAPI
- select CRYPTO_LIB_SM4
+ select CRYPTO_SM4
select CRYPTO_SM4_AESNI_AVX_X86_64
help
SM4 cipher algorithms (OSCCA GB/T 32907-2016) (x86_64/AES-NI/AVX2).
diff --git a/crypto/Makefile b/crypto/Makefile
index d76bff8d0ffd..1a4fa7d51b2f 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -78,7 +78,8 @@ obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o
obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o
obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o
obj-$(CONFIG_CRYPTO_SHA3) += sha3_generic.o
-obj-$(CONFIG_CRYPTO_SM3) += sm3_generic.o
+obj-$(CONFIG_CRYPTO_SM3) += sm3.o
+obj-$(CONFIG_CRYPTO_SM3_GENERIC) += sm3_generic.o
obj-$(CONFIG_CRYPTO_STREEBOG) += streebog_generic.o
obj-$(CONFIG_CRYPTO_WP512) += wp512.o
CFLAGS_wp512.o := $(call cc-option,-fno-schedule-insns) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149
@@ -134,7 +135,8 @@ obj-$(CONFIG_CRYPTO_SERPENT) += serpent_generic.o
CFLAGS_serpent_generic.o := $(call cc-option,-fsched-pressure) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79149
obj-$(CONFIG_CRYPTO_AES) += aes_generic.o
CFLAGS_aes_generic.o := $(call cc-option,-fno-code-hoisting) # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83356
-obj-$(CONFIG_CRYPTO_SM4) += sm4_generic.o
+obj-$(CONFIG_CRYPTO_SM4) += sm4.o
+obj-$(CONFIG_CRYPTO_SM4_GENERIC) += sm4_generic.o
obj-$(CONFIG_CRYPTO_AES_TI) += aes_ti.o
obj-$(CONFIG_CRYPTO_CAMELLIA) += camellia_generic.o
obj-$(CONFIG_CRYPTO_CAST_COMMON) += cast_common.o
diff --git a/lib/crypto/sm3.c b/crypto/sm3.c
similarity index 100%
rename from lib/crypto/sm3.c
rename to crypto/sm3.c
diff --git a/lib/crypto/sm4.c b/crypto/sm4.c
similarity index 100%
rename from lib/crypto/sm4.c
rename to crypto/sm4.c
diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig
index 379a66d7f504..9856e291f414 100644
--- a/lib/crypto/Kconfig
+++ b/lib/crypto/Kconfig
@@ -123,10 +123,4 @@ config CRYPTO_LIB_CHACHA20POLY1305
config CRYPTO_LIB_SHA256
tristate
-config CRYPTO_LIB_SM3
- tristate
-
-config CRYPTO_LIB_SM4
- tristate
-
endmenu
diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile
index 6c872d05d1e6..26be2bbe09c5 100644
--- a/lib/crypto/Makefile
+++ b/lib/crypto/Makefile
@@ -37,12 +37,6 @@ libpoly1305-y += poly1305.o
obj-$(CONFIG_CRYPTO_LIB_SHA256) += libsha256.o
libsha256-y := sha256.o
-obj-$(CONFIG_CRYPTO_LIB_SM3) += libsm3.o
-libsm3-y := sm3.o
-
-obj-$(CONFIG_CRYPTO_LIB_SM4) += libsm4.o
-libsm4-y := sm4.o
-
ifneq ($(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS),y)
libblake2s-y += blake2s-selftest.o
libchacha20poly1305-y += chacha20poly1305-selftest.o
--
2.35.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: move sm3 and sm4 into crypto directory
2022-03-14 3:11 [PATCH] crypto: move sm3 and sm4 into crypto directory Jason A. Donenfeld
@ 2022-03-16 17:16 ` Eric Biggers
2022-03-16 22:18 ` Jason A. Donenfeld
2022-04-08 8:30 ` Herbert Xu
1 sibling, 1 reply; 5+ messages in thread
From: Eric Biggers @ 2022-03-16 17:16 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: linux-crypto, herbert, tianjia.zhang
On Sun, Mar 13, 2022 at 09:11:01PM -0600, Jason A. Donenfeld wrote:
> The lib/crypto libraries live in lib because they are used by various
> drivers of the kernel. In contrast, the various helper functions in
> crypto are there because they're used exclusively by the crypto API. The
> SM3 and SM4 helper functions were erroniously moved into lib/crypto/
> instead of crypto/, even though there are no in-kernel users outside of
> the crypto API of those functions. This commit moves them into crypto/.
>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> Cc: Eric Biggers <ebiggers@kernel.org>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> arch/arm64/crypto/Kconfig | 4 ++--
> crypto/Kconfig | 18 ++++++++++++------
> crypto/Makefile | 6 ++++--
> {lib/crypto => crypto}/sm3.c | 0
> {lib/crypto => crypto}/sm4.c | 0
> lib/crypto/Kconfig | 6 ------
> lib/crypto/Makefile | 6 ------
> 7 files changed, 18 insertions(+), 22 deletions(-)
> rename {lib/crypto => crypto}/sm3.c (100%)
> rename {lib/crypto => crypto}/sm4.c (100%)
>
> diff --git a/arch/arm64/crypto/Kconfig b/arch/arm64/crypto/Kconfig
> index 2a965aa0188d..454621a20eaa 100644
> --- a/arch/arm64/crypto/Kconfig
> +++ b/arch/arm64/crypto/Kconfig
> @@ -45,13 +45,13 @@ config CRYPTO_SM3_ARM64_CE
> tristate "SM3 digest algorithm (ARMv8.2 Crypto Extensions)"
> depends on KERNEL_MODE_NEON
> select CRYPTO_HASH
> - select CRYPTO_LIB_SM3
> + select CRYPTO_SM3
>
> config CRYPTO_SM4_ARM64_CE
> tristate "SM4 symmetric cipher (ARMv8.2 Crypto Extensions)"
> depends on KERNEL_MODE_NEON
> select CRYPTO_ALGAPI
> - select CRYPTO_LIB_SM4
> + select CRYPTO_SM4
>
> config CRYPTO_GHASH_ARM64_CE
> tristate "GHASH/AES-GCM using ARMv8 Crypto Extensions"
> diff --git a/crypto/Kconfig b/crypto/Kconfig
> index d6d7e84bb7f8..517525d7d12e 100644
> --- a/crypto/Kconfig
> +++ b/crypto/Kconfig
> @@ -274,7 +274,7 @@ config CRYPTO_ECRDSA
>
> config CRYPTO_SM2
> tristate "SM2 algorithm"
> - select CRYPTO_LIB_SM3
> + select CRYPTO_SM3
> select CRYPTO_AKCIPHER
> select CRYPTO_MANAGER
> select MPILIB
> @@ -1005,9 +1005,12 @@ config CRYPTO_SHA3
> http://keccak.noekeon.org/
>
> config CRYPTO_SM3
> + tristate
> +
> +config CRYPTO_SM3_GENERIC
> tristate "SM3 digest algorithm"
> select CRYPTO_HASH
> - select CRYPTO_LIB_SM3
> + select CRYPTO_SM3
> help
> SM3 secure hash function as defined by OSCCA GM/T 0004-2012 SM3).
> It is part of the Chinese Commercial Cryptography suite.
This patch generally looks good, but perhaps CRYPTO_SM3 and CRYPTO_SM3_GENERIC
should be merged? Having separate options provides the ability to enable the
architecture implementation without the generic implementation, so arguably it's
the right thing to do; however, that's not what the other algorithms in crypto/
do. For example, if you enable CONFIG_CRYPTO_SHA3, you get the generic SHA-3
algorithms as well as the SHA-3 library functions. I.e., there's no
CONFIG_CRYPTO_SHA3_GENERIC.
IMO, being consistent is more important than providing the ability to omit the
generic implementation.
- Eric
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: move sm3 and sm4 into crypto directory
2022-03-16 17:16 ` Eric Biggers
@ 2022-03-16 22:18 ` Jason A. Donenfeld
0 siblings, 0 replies; 5+ messages in thread
From: Jason A. Donenfeld @ 2022-03-16 22:18 UTC (permalink / raw)
To: Eric Biggers; +Cc: Linux Crypto Mailing List, Herbert Xu, Tianjia Zhang
Hi Eric,
I guess I could do that, but I think that might partially weaken the
argument for moving this out of lib/. Can we do that in a subsequent
patch, so that this one stays hermetic to its purpose?
Jason
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: move sm3 and sm4 into crypto directory
2022-03-14 3:11 [PATCH] crypto: move sm3 and sm4 into crypto directory Jason A. Donenfeld
2022-03-16 17:16 ` Eric Biggers
@ 2022-04-08 8:30 ` Herbert Xu
1 sibling, 0 replies; 5+ messages in thread
From: Herbert Xu @ 2022-04-08 8:30 UTC (permalink / raw)
To: Jason A. Donenfeld; +Cc: linux-crypto, tianjia.zhang, ebiggers
On Sun, Mar 13, 2022 at 09:11:01PM -0600, Jason A. Donenfeld wrote:
> The lib/crypto libraries live in lib because they are used by various
> drivers of the kernel. In contrast, the various helper functions in
> crypto are there because they're used exclusively by the crypto API. The
> SM3 and SM4 helper functions were erroniously moved into lib/crypto/
> instead of crypto/, even though there are no in-kernel users outside of
> the crypto API of those functions. This commit moves them into crypto/.
>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Cc: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
> Cc: Eric Biggers <ebiggers@kernel.org>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
> arch/arm64/crypto/Kconfig | 4 ++--
> crypto/Kconfig | 18 ++++++++++++------
> crypto/Makefile | 6 ++++--
> {lib/crypto => crypto}/sm3.c | 0
> {lib/crypto => crypto}/sm4.c | 0
> lib/crypto/Kconfig | 6 ------
> lib/crypto/Makefile | 6 ------
> 7 files changed, 18 insertions(+), 22 deletions(-)
> rename {lib/crypto => crypto}/sm3.c (100%)
> rename {lib/crypto => crypto}/sm4.c (100%)
Patch applied. Thanks.
--
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] crypto: move sm3 and sm4 into crypto directory
@ 2022-03-14 9:07 kernel test robot
0 siblings, 0 replies; 5+ messages in thread
From: kernel test robot @ 2022-03-14 9:07 UTC (permalink / raw)
To: kbuild
[-- Attachment #1: Type: text/plain, Size: 4476 bytes --]
CC: kbuild-all(a)lists.01.org
BCC: lkp(a)intel.com
In-Reply-To: <20220314031101.663883-1-Jason@zx2c4.com>
References: <20220314031101.663883-1-Jason@zx2c4.com>
TO: "Jason A. Donenfeld" <Jason@zx2c4.com>
TO: linux-crypto(a)vger.kernel.org
TO: herbert(a)gondor.apana.org.au
TO: tianjia.zhang(a)linux.alibaba.com
TO: ebiggers(a)kernel.org
CC: "Jason A. Donenfeld" <Jason@zx2c4.com>
Hi "Jason,
I love your patch! Perhaps something to improve:
[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on next-20220310]
[cannot apply to herbert-crypto-2.6/master crng-random/master v5.17-rc8]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jason-A-Donenfeld/crypto-move-sm3-and-sm4-into-crypto-directory/20220314-111353
base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master
:::::: branch date: 6 hours ago
:::::: commit date: 6 hours ago
compiler: sparc-linux-gcc (GCC) 11.2.0
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
cppcheck possible warnings: (new ones prefixed by >>, may not real problems)
>> crypto/sm4.c:171:25: warning: Same expression on both sides of '-'. [duplicateExpression]
put_unaligned_be32(x[3 - 3], out + 3 * 4);
^
vim +171 crypto/sm4.c
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 145
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 146 /**
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 147 * sm4_crypt_block - Encrypt or decrypt a single SM4 block
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 148 * @rk: The rkey_enc for encrypt or rkey_dec for decrypt
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 149 * @out: Buffer to store output data
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 150 * @in: Buffer containing the input data
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 151 */
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 152 void sm4_crypt_block(const u32 *rk, u8 *out, const u8 *in)
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 153 {
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 154 u32 x[4], i;
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 155
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 156 x[0] = get_unaligned_be32(in + 0 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 157 x[1] = get_unaligned_be32(in + 1 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 158 x[2] = get_unaligned_be32(in + 2 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 159 x[3] = get_unaligned_be32(in + 3 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 160
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 161 for (i = 0; i < 32; i += 4) {
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 162 x[0] = sm4_round(x[0], x[1], x[2], x[3], rk[i + 0]);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 163 x[1] = sm4_round(x[1], x[2], x[3], x[0], rk[i + 1]);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 164 x[2] = sm4_round(x[2], x[3], x[0], x[1], rk[i + 2]);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 165 x[3] = sm4_round(x[3], x[0], x[1], x[2], rk[i + 3]);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 166 }
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 167
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 168 put_unaligned_be32(x[3 - 0], out + 0 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 169 put_unaligned_be32(x[3 - 1], out + 1 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 170 put_unaligned_be32(x[3 - 2], out + 2 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 @171 put_unaligned_be32(x[3 - 3], out + 3 * 4);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 172 }
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 173 EXPORT_SYMBOL_GPL(sm4_crypt_block);
2b31277af577b1 lib/crypto/sm4.c Tianjia Zhang 2021-07-20 174
---
0-DAY CI Kernel Test Service
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-04-08 8:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-14 3:11 [PATCH] crypto: move sm3 and sm4 into crypto directory Jason A. Donenfeld
2022-03-16 17:16 ` Eric Biggers
2022-03-16 22:18 ` Jason A. Donenfeld
2022-04-08 8:30 ` Herbert Xu
2022-03-14 9:07 kernel test robot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.