* [PATCH] crypto: lib/chacha - remove unused arch-specific init support
@ 2025-03-16 4:57 Eric Biggers
2025-03-16 8:24 ` Ard Biesheuvel
2025-03-21 11:07 ` Herbert Xu
0 siblings, 2 replies; 3+ messages in thread
From: Eric Biggers @ 2025-03-16 4:57 UTC (permalink / raw)
To: linux-crypto
From: Eric Biggers <ebiggers@google.com>
All implementations of chacha_init_arch() just call
chacha_init_generic(), so it is pointless. Just delete it, and replace
chacha_init() with what was previously chacha_init_generic().
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
arch/arm/crypto/chacha-glue.c | 10 ++--------
arch/arm64/crypto/chacha-neon-glue.c | 10 ++--------
arch/mips/crypto/chacha-glue.c | 10 ++--------
arch/powerpc/crypto/chacha-p10-glue.c | 10 ++--------
arch/s390/crypto/chacha-glue.c | 8 +-------
arch/x86/crypto/chacha_glue.c | 10 ++--------
crypto/chacha_generic.c | 4 ++--
include/crypto/chacha.h | 11 +----------
tools/testing/crypto/chacha20-s390/test-cipher.c | 4 ++--
9 files changed, 16 insertions(+), 61 deletions(-)
diff --git a/arch/arm/crypto/chacha-glue.c b/arch/arm/crypto/chacha-glue.c
index cdde8fd01f8f9..50e635512046e 100644
--- a/arch/arm/crypto/chacha-glue.c
+++ b/arch/arm/crypto/chacha-glue.c
@@ -74,16 +74,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
kernel_neon_end();
}
}
EXPORT_SYMBOL(hchacha_block_arch);
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
-{
- chacha_init_generic(state, key, iv);
-}
-EXPORT_SYMBOL(chacha_init_arch);
-
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
int nrounds)
{
if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon_usable() ||
bytes <= CHACHA_BLOCK_SIZE) {
@@ -114,11 +108,11 @@ static int chacha_stream_xor(struct skcipher_request *req,
u32 state[16];
int err;
err = skcipher_walk_virt(&walk, req, false);
- chacha_init_generic(state, ctx->key, iv);
+ chacha_init(state, ctx->key, iv);
while (walk.nbytes > 0) {
unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total)
@@ -164,11 +158,11 @@ static int do_xchacha(struct skcipher_request *req, bool neon)
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
struct chacha_ctx subctx;
u32 state[16];
u8 real_iv[16];
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon) {
hchacha_block_arm(state, subctx.key, ctx->nrounds);
} else {
kernel_neon_begin();
diff --git a/arch/arm64/crypto/chacha-neon-glue.c b/arch/arm64/crypto/chacha-neon-glue.c
index af2bbca38e70f..229876acfc581 100644
--- a/arch/arm64/crypto/chacha-neon-glue.c
+++ b/arch/arm64/crypto/chacha-neon-glue.c
@@ -72,16 +72,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
kernel_neon_end();
}
}
EXPORT_SYMBOL(hchacha_block_arch);
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
-{
- chacha_init_generic(state, key, iv);
-}
-EXPORT_SYMBOL(chacha_init_arch);
-
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
int nrounds)
{
if (!static_branch_likely(&have_neon) || bytes <= CHACHA_BLOCK_SIZE ||
!crypto_simd_usable())
@@ -108,11 +102,11 @@ static int chacha_neon_stream_xor(struct skcipher_request *req,
u32 state[16];
int err;
err = skcipher_walk_virt(&walk, req, false);
- chacha_init_generic(state, ctx->key, iv);
+ chacha_init(state, ctx->key, iv);
while (walk.nbytes > 0) {
unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total)
@@ -149,11 +143,11 @@ static int xchacha_neon(struct skcipher_request *req)
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
struct chacha_ctx subctx;
u32 state[16];
u8 real_iv[16];
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
hchacha_block_arch(state, subctx.key, ctx->nrounds);
subctx.nrounds = ctx->nrounds;
memcpy(&real_iv[0], req->iv + 24, 8);
memcpy(&real_iv[8], req->iv + 16, 8);
diff --git a/arch/mips/crypto/chacha-glue.c b/arch/mips/crypto/chacha-glue.c
index d1fd23e6ef844..f6fc2e1079a19 100644
--- a/arch/mips/crypto/chacha-glue.c
+++ b/arch/mips/crypto/chacha-glue.c
@@ -18,26 +18,20 @@ asmlinkage void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
EXPORT_SYMBOL(chacha_crypt_arch);
asmlinkage void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds);
EXPORT_SYMBOL(hchacha_block_arch);
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
-{
- chacha_init_generic(state, key, iv);
-}
-EXPORT_SYMBOL(chacha_init_arch);
-
static int chacha_mips_stream_xor(struct skcipher_request *req,
const struct chacha_ctx *ctx, const u8 *iv)
{
struct skcipher_walk walk;
u32 state[16];
int err;
err = skcipher_walk_virt(&walk, req, false);
- chacha_init_generic(state, ctx->key, iv);
+ chacha_init(state, ctx->key, iv);
while (walk.nbytes > 0) {
unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total)
@@ -65,11 +59,11 @@ static int xchacha_mips(struct skcipher_request *req)
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
struct chacha_ctx subctx;
u32 state[16];
u8 real_iv[16];
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
hchacha_block(state, subctx.key, ctx->nrounds);
subctx.nrounds = ctx->nrounds;
memcpy(&real_iv[0], req->iv + 24, 8);
diff --git a/arch/powerpc/crypto/chacha-p10-glue.c b/arch/powerpc/crypto/chacha-p10-glue.c
index 7c728755852e1..d8796decc1fb7 100644
--- a/arch/powerpc/crypto/chacha-p10-glue.c
+++ b/arch/powerpc/crypto/chacha-p10-glue.c
@@ -55,16 +55,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
{
hchacha_block_generic(state, stream, nrounds);
}
EXPORT_SYMBOL(hchacha_block_arch);
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
-{
- chacha_init_generic(state, key, iv);
-}
-EXPORT_SYMBOL(chacha_init_arch);
-
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
int nrounds)
{
if (!static_branch_likely(&have_p10) || bytes <= CHACHA_BLOCK_SIZE ||
!crypto_simd_usable())
@@ -93,11 +87,11 @@ static int chacha_p10_stream_xor(struct skcipher_request *req,
err = skcipher_walk_virt(&walk, req, false);
if (err)
return err;
- chacha_init_generic(state, ctx->key, iv);
+ chacha_init(state, ctx->key, iv);
while (walk.nbytes > 0) {
unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total)
@@ -135,11 +129,11 @@ static int xchacha_p10(struct skcipher_request *req)
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
struct chacha_ctx subctx;
u32 state[16];
u8 real_iv[16];
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
hchacha_block_arch(state, subctx.key, ctx->nrounds);
subctx.nrounds = ctx->nrounds;
memcpy(&real_iv[0], req->iv + 24, 8);
memcpy(&real_iv[8], req->iv + 16, 8);
diff --git a/arch/s390/crypto/chacha-glue.c b/arch/s390/crypto/chacha-glue.c
index f8b0c52e77a4f..920e9f0941e75 100644
--- a/arch/s390/crypto/chacha-glue.c
+++ b/arch/s390/crypto/chacha-glue.c
@@ -39,11 +39,11 @@ static int chacha20_s390(struct skcipher_request *req)
struct skcipher_walk walk;
unsigned int nbytes;
int rc;
rc = skcipher_walk_virt(&walk, req, false);
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
while (walk.nbytes > 0) {
nbytes = walk.nbytes;
if (nbytes < walk.total)
nbytes = round_down(nbytes, walk.stride);
@@ -67,16 +67,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
/* TODO: implement hchacha_block_arch() in assembly */
hchacha_block_generic(state, stream, nrounds);
}
EXPORT_SYMBOL(hchacha_block_arch);
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
-{
- chacha_init_generic(state, key, iv);
-}
-EXPORT_SYMBOL(chacha_init_arch);
-
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
unsigned int bytes, int nrounds)
{
/* s390 chacha20 implementation has 20 rounds hard-coded,
* it cannot handle a block of data or less, but otherwise
diff --git a/arch/x86/crypto/chacha_glue.c b/arch/x86/crypto/chacha_glue.c
index 7b3a1cf0984be..8bb74a2728798 100644
--- a/arch/x86/crypto/chacha_glue.c
+++ b/arch/x86/crypto/chacha_glue.c
@@ -131,16 +131,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
kernel_fpu_end();
}
}
EXPORT_SYMBOL(hchacha_block_arch);
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
-{
- chacha_init_generic(state, key, iv);
-}
-EXPORT_SYMBOL(chacha_init_arch);
-
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
int nrounds)
{
if (!static_branch_likely(&chacha_use_simd) || !crypto_simd_usable() ||
bytes <= CHACHA_BLOCK_SIZE)
@@ -167,11 +161,11 @@ static int chacha_simd_stream_xor(struct skcipher_request *req,
struct skcipher_walk walk;
int err;
err = skcipher_walk_virt(&walk, req, false);
- chacha_init_generic(state, ctx->key, iv);
+ chacha_init(state, ctx->key, iv);
while (walk.nbytes > 0) {
unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total)
@@ -209,11 +203,11 @@ static int xchacha_simd(struct skcipher_request *req)
struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
u32 state[CHACHA_STATE_WORDS] __aligned(8);
struct chacha_ctx subctx;
u8 real_iv[16];
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
if (req->cryptlen > CHACHA_BLOCK_SIZE && crypto_simd_usable()) {
kernel_fpu_begin();
hchacha_block_ssse3(state, subctx.key, ctx->nrounds);
kernel_fpu_end();
diff --git a/crypto/chacha_generic.c b/crypto/chacha_generic.c
index ba7fcb47f9aa0..1fb9fbd302c6f 100644
--- a/crypto/chacha_generic.c
+++ b/crypto/chacha_generic.c
@@ -19,11 +19,11 @@ static int chacha_stream_xor(struct skcipher_request *req,
u32 state[16];
int err;
err = skcipher_walk_virt(&walk, req, false);
- chacha_init_generic(state, ctx->key, iv);
+ chacha_init(state, ctx->key, iv);
while (walk.nbytes > 0) {
unsigned int nbytes = walk.nbytes;
if (nbytes < walk.total)
@@ -52,11 +52,11 @@ static int crypto_xchacha_crypt(struct skcipher_request *req)
struct chacha_ctx subctx;
u32 state[16];
u8 real_iv[16];
/* Compute the subkey given the original key and first 128 nonce bits */
- chacha_init_generic(state, ctx->key, req->iv);
+ chacha_init(state, ctx->key, req->iv);
hchacha_block_generic(state, subctx.key, ctx->nrounds);
subctx.nrounds = ctx->nrounds;
/* Build the real IV */
memcpy(&real_iv[0], req->iv + 24, 8); /* stream position */
diff --git a/include/crypto/chacha.h b/include/crypto/chacha.h
index 5bae6a55b3337..f8cc073bba41b 100644
--- a/include/crypto/chacha.h
+++ b/include/crypto/chacha.h
@@ -60,12 +60,11 @@ static inline void chacha_init_consts(u32 *state)
state[1] = CHACHA_CONSTANT_ND_3;
state[2] = CHACHA_CONSTANT_2_BY;
state[3] = CHACHA_CONSTANT_TE_K;
}
-void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv);
-static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv)
+static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv)
{
chacha_init_consts(state);
state[4] = key[0];
state[5] = key[1];
state[6] = key[2];
@@ -78,18 +77,10 @@ static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv)
state[13] = get_unaligned_le32(iv + 4);
state[14] = get_unaligned_le32(iv + 8);
state[15] = get_unaligned_le32(iv + 12);
}
-static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv)
-{
- if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CHACHA))
- chacha_init_arch(state, key, iv);
- else
- chacha_init_generic(state, key, iv);
-}
-
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
unsigned int bytes, int nrounds);
void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src,
unsigned int bytes, int nrounds);
diff --git a/tools/testing/crypto/chacha20-s390/test-cipher.c b/tools/testing/crypto/chacha20-s390/test-cipher.c
index 8141d45df51aa..35ea65c54ffa5 100644
--- a/tools/testing/crypto/chacha20-s390/test-cipher.c
+++ b/tools/testing/crypto/chacha20-s390/test-cipher.c
@@ -64,11 +64,11 @@ static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain)
print_hex_dump(KERN_INFO, "iv: ", DUMP_PREFIX_OFFSET,
16, 1, iv, 16, 1);
}
/* Encrypt */
- chacha_init_arch(chacha_state, (u32*)key, iv);
+ chacha_init(chacha_state, (u32 *)key, iv);
start = ktime_get_ns();
chacha_crypt_arch(chacha_state, cipher, plain, data_size, 20);
end = ktime_get_ns();
@@ -79,11 +79,11 @@ static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain)
(data_size > 64 ? 64 : data_size), 1);
pr_info("lib encryption took: %lld nsec", end - start);
/* Decrypt */
- chacha_init_arch(chacha_state, (u32 *)key, iv);
+ chacha_init(chacha_state, (u32 *)key, iv);
start = ktime_get_ns();
chacha_crypt_arch(chacha_state, revert, cipher, data_size, 20);
end = ktime_get_ns();
base-commit: d2d072a313c1817a0d72d7b8301eaf29ce7f83fc
--
2.49.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: lib/chacha - remove unused arch-specific init support
2025-03-16 4:57 [PATCH] crypto: lib/chacha - remove unused arch-specific init support Eric Biggers
@ 2025-03-16 8:24 ` Ard Biesheuvel
2025-03-21 11:07 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Ard Biesheuvel @ 2025-03-16 8:24 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto
On Sun, 16 Mar 2025 at 05:57, Eric Biggers <ebiggers@kernel.org> wrote:
>
> From: Eric Biggers <ebiggers@google.com>
>
> All implementations of chacha_init_arch() just call
> chacha_init_generic(), so it is pointless. Just delete it, and replace
> chacha_init() with what was previously chacha_init_generic().
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
> ---
> arch/arm/crypto/chacha-glue.c | 10 ++--------
> arch/arm64/crypto/chacha-neon-glue.c | 10 ++--------
> arch/mips/crypto/chacha-glue.c | 10 ++--------
> arch/powerpc/crypto/chacha-p10-glue.c | 10 ++--------
> arch/s390/crypto/chacha-glue.c | 8 +-------
> arch/x86/crypto/chacha_glue.c | 10 ++--------
> crypto/chacha_generic.c | 4 ++--
> include/crypto/chacha.h | 11 +----------
> tools/testing/crypto/chacha20-s390/test-cipher.c | 4 ++--
> 9 files changed, 16 insertions(+), 61 deletions(-)
>
> diff --git a/arch/arm/crypto/chacha-glue.c b/arch/arm/crypto/chacha-glue.c
> index cdde8fd01f8f9..50e635512046e 100644
> --- a/arch/arm/crypto/chacha-glue.c
> +++ b/arch/arm/crypto/chacha-glue.c
> @@ -74,16 +74,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
> kernel_neon_end();
> }
> }
> EXPORT_SYMBOL(hchacha_block_arch);
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
> -{
> - chacha_init_generic(state, key, iv);
> -}
> -EXPORT_SYMBOL(chacha_init_arch);
> -
> void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
> int nrounds)
> {
> if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon_usable() ||
> bytes <= CHACHA_BLOCK_SIZE) {
> @@ -114,11 +108,11 @@ static int chacha_stream_xor(struct skcipher_request *req,
> u32 state[16];
> int err;
>
> err = skcipher_walk_virt(&walk, req, false);
>
> - chacha_init_generic(state, ctx->key, iv);
> + chacha_init(state, ctx->key, iv);
>
> while (walk.nbytes > 0) {
> unsigned int nbytes = walk.nbytes;
>
> if (nbytes < walk.total)
> @@ -164,11 +158,11 @@ static int do_xchacha(struct skcipher_request *req, bool neon)
> struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
> struct chacha_ctx subctx;
> u32 state[16];
> u8 real_iv[16];
>
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
>
> if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon) {
> hchacha_block_arm(state, subctx.key, ctx->nrounds);
> } else {
> kernel_neon_begin();
> diff --git a/arch/arm64/crypto/chacha-neon-glue.c b/arch/arm64/crypto/chacha-neon-glue.c
> index af2bbca38e70f..229876acfc581 100644
> --- a/arch/arm64/crypto/chacha-neon-glue.c
> +++ b/arch/arm64/crypto/chacha-neon-glue.c
> @@ -72,16 +72,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
> kernel_neon_end();
> }
> }
> EXPORT_SYMBOL(hchacha_block_arch);
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
> -{
> - chacha_init_generic(state, key, iv);
> -}
> -EXPORT_SYMBOL(chacha_init_arch);
> -
> void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
> int nrounds)
> {
> if (!static_branch_likely(&have_neon) || bytes <= CHACHA_BLOCK_SIZE ||
> !crypto_simd_usable())
> @@ -108,11 +102,11 @@ static int chacha_neon_stream_xor(struct skcipher_request *req,
> u32 state[16];
> int err;
>
> err = skcipher_walk_virt(&walk, req, false);
>
> - chacha_init_generic(state, ctx->key, iv);
> + chacha_init(state, ctx->key, iv);
>
> while (walk.nbytes > 0) {
> unsigned int nbytes = walk.nbytes;
>
> if (nbytes < walk.total)
> @@ -149,11 +143,11 @@ static int xchacha_neon(struct skcipher_request *req)
> struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
> struct chacha_ctx subctx;
> u32 state[16];
> u8 real_iv[16];
>
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
> hchacha_block_arch(state, subctx.key, ctx->nrounds);
> subctx.nrounds = ctx->nrounds;
>
> memcpy(&real_iv[0], req->iv + 24, 8);
> memcpy(&real_iv[8], req->iv + 16, 8);
> diff --git a/arch/mips/crypto/chacha-glue.c b/arch/mips/crypto/chacha-glue.c
> index d1fd23e6ef844..f6fc2e1079a19 100644
> --- a/arch/mips/crypto/chacha-glue.c
> +++ b/arch/mips/crypto/chacha-glue.c
> @@ -18,26 +18,20 @@ asmlinkage void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
> EXPORT_SYMBOL(chacha_crypt_arch);
>
> asmlinkage void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds);
> EXPORT_SYMBOL(hchacha_block_arch);
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
> -{
> - chacha_init_generic(state, key, iv);
> -}
> -EXPORT_SYMBOL(chacha_init_arch);
> -
> static int chacha_mips_stream_xor(struct skcipher_request *req,
> const struct chacha_ctx *ctx, const u8 *iv)
> {
> struct skcipher_walk walk;
> u32 state[16];
> int err;
>
> err = skcipher_walk_virt(&walk, req, false);
>
> - chacha_init_generic(state, ctx->key, iv);
> + chacha_init(state, ctx->key, iv);
>
> while (walk.nbytes > 0) {
> unsigned int nbytes = walk.nbytes;
>
> if (nbytes < walk.total)
> @@ -65,11 +59,11 @@ static int xchacha_mips(struct skcipher_request *req)
> struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
> struct chacha_ctx subctx;
> u32 state[16];
> u8 real_iv[16];
>
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
>
> hchacha_block(state, subctx.key, ctx->nrounds);
> subctx.nrounds = ctx->nrounds;
>
> memcpy(&real_iv[0], req->iv + 24, 8);
> diff --git a/arch/powerpc/crypto/chacha-p10-glue.c b/arch/powerpc/crypto/chacha-p10-glue.c
> index 7c728755852e1..d8796decc1fb7 100644
> --- a/arch/powerpc/crypto/chacha-p10-glue.c
> +++ b/arch/powerpc/crypto/chacha-p10-glue.c
> @@ -55,16 +55,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
> {
> hchacha_block_generic(state, stream, nrounds);
> }
> EXPORT_SYMBOL(hchacha_block_arch);
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
> -{
> - chacha_init_generic(state, key, iv);
> -}
> -EXPORT_SYMBOL(chacha_init_arch);
> -
> void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
> int nrounds)
> {
> if (!static_branch_likely(&have_p10) || bytes <= CHACHA_BLOCK_SIZE ||
> !crypto_simd_usable())
> @@ -93,11 +87,11 @@ static int chacha_p10_stream_xor(struct skcipher_request *req,
>
> err = skcipher_walk_virt(&walk, req, false);
> if (err)
> return err;
>
> - chacha_init_generic(state, ctx->key, iv);
> + chacha_init(state, ctx->key, iv);
>
> while (walk.nbytes > 0) {
> unsigned int nbytes = walk.nbytes;
>
> if (nbytes < walk.total)
> @@ -135,11 +129,11 @@ static int xchacha_p10(struct skcipher_request *req)
> struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
> struct chacha_ctx subctx;
> u32 state[16];
> u8 real_iv[16];
>
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
> hchacha_block_arch(state, subctx.key, ctx->nrounds);
> subctx.nrounds = ctx->nrounds;
>
> memcpy(&real_iv[0], req->iv + 24, 8);
> memcpy(&real_iv[8], req->iv + 16, 8);
> diff --git a/arch/s390/crypto/chacha-glue.c b/arch/s390/crypto/chacha-glue.c
> index f8b0c52e77a4f..920e9f0941e75 100644
> --- a/arch/s390/crypto/chacha-glue.c
> +++ b/arch/s390/crypto/chacha-glue.c
> @@ -39,11 +39,11 @@ static int chacha20_s390(struct skcipher_request *req)
> struct skcipher_walk walk;
> unsigned int nbytes;
> int rc;
>
> rc = skcipher_walk_virt(&walk, req, false);
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
>
> while (walk.nbytes > 0) {
> nbytes = walk.nbytes;
> if (nbytes < walk.total)
> nbytes = round_down(nbytes, walk.stride);
> @@ -67,16 +67,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
> /* TODO: implement hchacha_block_arch() in assembly */
> hchacha_block_generic(state, stream, nrounds);
> }
> EXPORT_SYMBOL(hchacha_block_arch);
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
> -{
> - chacha_init_generic(state, key, iv);
> -}
> -EXPORT_SYMBOL(chacha_init_arch);
> -
> void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
> unsigned int bytes, int nrounds)
> {
> /* s390 chacha20 implementation has 20 rounds hard-coded,
> * it cannot handle a block of data or less, but otherwise
> diff --git a/arch/x86/crypto/chacha_glue.c b/arch/x86/crypto/chacha_glue.c
> index 7b3a1cf0984be..8bb74a2728798 100644
> --- a/arch/x86/crypto/chacha_glue.c
> +++ b/arch/x86/crypto/chacha_glue.c
> @@ -131,16 +131,10 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
> kernel_fpu_end();
> }
> }
> EXPORT_SYMBOL(hchacha_block_arch);
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
> -{
> - chacha_init_generic(state, key, iv);
> -}
> -EXPORT_SYMBOL(chacha_init_arch);
> -
> void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
> int nrounds)
> {
> if (!static_branch_likely(&chacha_use_simd) || !crypto_simd_usable() ||
> bytes <= CHACHA_BLOCK_SIZE)
> @@ -167,11 +161,11 @@ static int chacha_simd_stream_xor(struct skcipher_request *req,
> struct skcipher_walk walk;
> int err;
>
> err = skcipher_walk_virt(&walk, req, false);
>
> - chacha_init_generic(state, ctx->key, iv);
> + chacha_init(state, ctx->key, iv);
>
> while (walk.nbytes > 0) {
> unsigned int nbytes = walk.nbytes;
>
> if (nbytes < walk.total)
> @@ -209,11 +203,11 @@ static int xchacha_simd(struct skcipher_request *req)
> struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
> u32 state[CHACHA_STATE_WORDS] __aligned(8);
> struct chacha_ctx subctx;
> u8 real_iv[16];
>
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
>
> if (req->cryptlen > CHACHA_BLOCK_SIZE && crypto_simd_usable()) {
> kernel_fpu_begin();
> hchacha_block_ssse3(state, subctx.key, ctx->nrounds);
> kernel_fpu_end();
> diff --git a/crypto/chacha_generic.c b/crypto/chacha_generic.c
> index ba7fcb47f9aa0..1fb9fbd302c6f 100644
> --- a/crypto/chacha_generic.c
> +++ b/crypto/chacha_generic.c
> @@ -19,11 +19,11 @@ static int chacha_stream_xor(struct skcipher_request *req,
> u32 state[16];
> int err;
>
> err = skcipher_walk_virt(&walk, req, false);
>
> - chacha_init_generic(state, ctx->key, iv);
> + chacha_init(state, ctx->key, iv);
>
> while (walk.nbytes > 0) {
> unsigned int nbytes = walk.nbytes;
>
> if (nbytes < walk.total)
> @@ -52,11 +52,11 @@ static int crypto_xchacha_crypt(struct skcipher_request *req)
> struct chacha_ctx subctx;
> u32 state[16];
> u8 real_iv[16];
>
> /* Compute the subkey given the original key and first 128 nonce bits */
> - chacha_init_generic(state, ctx->key, req->iv);
> + chacha_init(state, ctx->key, req->iv);
> hchacha_block_generic(state, subctx.key, ctx->nrounds);
> subctx.nrounds = ctx->nrounds;
>
> /* Build the real IV */
> memcpy(&real_iv[0], req->iv + 24, 8); /* stream position */
> diff --git a/include/crypto/chacha.h b/include/crypto/chacha.h
> index 5bae6a55b3337..f8cc073bba41b 100644
> --- a/include/crypto/chacha.h
> +++ b/include/crypto/chacha.h
> @@ -60,12 +60,11 @@ static inline void chacha_init_consts(u32 *state)
> state[1] = CHACHA_CONSTANT_ND_3;
> state[2] = CHACHA_CONSTANT_2_BY;
> state[3] = CHACHA_CONSTANT_TE_K;
> }
>
> -void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv);
> -static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv)
> +static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv)
> {
> chacha_init_consts(state);
> state[4] = key[0];
> state[5] = key[1];
> state[6] = key[2];
> @@ -78,18 +77,10 @@ static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv)
> state[13] = get_unaligned_le32(iv + 4);
> state[14] = get_unaligned_le32(iv + 8);
> state[15] = get_unaligned_le32(iv + 12);
> }
>
> -static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv)
> -{
> - if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CHACHA))
> - chacha_init_arch(state, key, iv);
> - else
> - chacha_init_generic(state, key, iv);
> -}
> -
> void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
> unsigned int bytes, int nrounds);
> void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src,
> unsigned int bytes, int nrounds);
>
> diff --git a/tools/testing/crypto/chacha20-s390/test-cipher.c b/tools/testing/crypto/chacha20-s390/test-cipher.c
> index 8141d45df51aa..35ea65c54ffa5 100644
> --- a/tools/testing/crypto/chacha20-s390/test-cipher.c
> +++ b/tools/testing/crypto/chacha20-s390/test-cipher.c
> @@ -64,11 +64,11 @@ static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain)
> print_hex_dump(KERN_INFO, "iv: ", DUMP_PREFIX_OFFSET,
> 16, 1, iv, 16, 1);
> }
>
> /* Encrypt */
> - chacha_init_arch(chacha_state, (u32*)key, iv);
> + chacha_init(chacha_state, (u32 *)key, iv);
>
> start = ktime_get_ns();
> chacha_crypt_arch(chacha_state, cipher, plain, data_size, 20);
> end = ktime_get_ns();
>
> @@ -79,11 +79,11 @@ static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain)
> (data_size > 64 ? 64 : data_size), 1);
>
> pr_info("lib encryption took: %lld nsec", end - start);
>
> /* Decrypt */
> - chacha_init_arch(chacha_state, (u32 *)key, iv);
> + chacha_init(chacha_state, (u32 *)key, iv);
>
> start = ktime_get_ns();
> chacha_crypt_arch(chacha_state, revert, cipher, data_size, 20);
> end = ktime_get_ns();
>
>
> base-commit: d2d072a313c1817a0d72d7b8301eaf29ce7f83fc
> --
> 2.49.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] crypto: lib/chacha - remove unused arch-specific init support
2025-03-16 4:57 [PATCH] crypto: lib/chacha - remove unused arch-specific init support Eric Biggers
2025-03-16 8:24 ` Ard Biesheuvel
@ 2025-03-21 11:07 ` Herbert Xu
1 sibling, 0 replies; 3+ messages in thread
From: Herbert Xu @ 2025-03-21 11:07 UTC (permalink / raw)
To: Eric Biggers; +Cc: linux-crypto
Eric Biggers <ebiggers@kernel.org> wrote:
> From: Eric Biggers <ebiggers@google.com>
>
> All implementations of chacha_init_arch() just call
> chacha_init_generic(), so it is pointless. Just delete it, and replace
> chacha_init() with what was previously chacha_init_generic().
>
> Signed-off-by: Eric Biggers <ebiggers@google.com>
> ---
> arch/arm/crypto/chacha-glue.c | 10 ++--------
> arch/arm64/crypto/chacha-neon-glue.c | 10 ++--------
> arch/mips/crypto/chacha-glue.c | 10 ++--------
> arch/powerpc/crypto/chacha-p10-glue.c | 10 ++--------
> arch/s390/crypto/chacha-glue.c | 8 +-------
> arch/x86/crypto/chacha_glue.c | 10 ++--------
> crypto/chacha_generic.c | 4 ++--
> include/crypto/chacha.h | 11 +----------
> tools/testing/crypto/chacha20-s390/test-cipher.c | 4 ++--
> 9 files changed, 16 insertions(+), 61 deletions(-)
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] 3+ messages in thread
end of thread, other threads:[~2025-03-21 11:07 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-16 4:57 [PATCH] crypto: lib/chacha - remove unused arch-specific init support Eric Biggers
2025-03-16 8:24 ` Ard Biesheuvel
2025-03-21 11:07 ` Herbert Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox