Skip to content

Commit ca17aa6

Browse files
ebiggersherbertx
authored andcommitted
crypto: lib/chacha - remove unused arch-specific init support
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> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent fce8b8d commit ca17aa6

File tree

9 files changed

+16
-61
lines changed

9 files changed

+16
-61
lines changed

arch/arm/crypto/chacha-glue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,6 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
7676
}
7777
EXPORT_SYMBOL(hchacha_block_arch);
7878

79-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
80-
{
81-
chacha_init_generic(state, key, iv);
82-
}
83-
EXPORT_SYMBOL(chacha_init_arch);
84-
8579
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
8680
int nrounds)
8781
{
@@ -116,7 +110,7 @@ static int chacha_stream_xor(struct skcipher_request *req,
116110

117111
err = skcipher_walk_virt(&walk, req, false);
118112

119-
chacha_init_generic(state, ctx->key, iv);
113+
chacha_init(state, ctx->key, iv);
120114

121115
while (walk.nbytes > 0) {
122116
unsigned int nbytes = walk.nbytes;
@@ -166,7 +160,7 @@ static int do_xchacha(struct skcipher_request *req, bool neon)
166160
u32 state[16];
167161
u8 real_iv[16];
168162

169-
chacha_init_generic(state, ctx->key, req->iv);
163+
chacha_init(state, ctx->key, req->iv);
170164

171165
if (!IS_ENABLED(CONFIG_KERNEL_MODE_NEON) || !neon) {
172166
hchacha_block_arm(state, subctx.key, ctx->nrounds);

arch/arm64/crypto/chacha-neon-glue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
7474
}
7575
EXPORT_SYMBOL(hchacha_block_arch);
7676

77-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
78-
{
79-
chacha_init_generic(state, key, iv);
80-
}
81-
EXPORT_SYMBOL(chacha_init_arch);
82-
8377
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
8478
int nrounds)
8579
{
@@ -110,7 +104,7 @@ static int chacha_neon_stream_xor(struct skcipher_request *req,
110104

111105
err = skcipher_walk_virt(&walk, req, false);
112106

113-
chacha_init_generic(state, ctx->key, iv);
107+
chacha_init(state, ctx->key, iv);
114108

115109
while (walk.nbytes > 0) {
116110
unsigned int nbytes = walk.nbytes;
@@ -151,7 +145,7 @@ static int xchacha_neon(struct skcipher_request *req)
151145
u32 state[16];
152146
u8 real_iv[16];
153147

154-
chacha_init_generic(state, ctx->key, req->iv);
148+
chacha_init(state, ctx->key, req->iv);
155149
hchacha_block_arch(state, subctx.key, ctx->nrounds);
156150
subctx.nrounds = ctx->nrounds;
157151

arch/mips/crypto/chacha-glue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,6 @@ EXPORT_SYMBOL(chacha_crypt_arch);
2020
asmlinkage void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds);
2121
EXPORT_SYMBOL(hchacha_block_arch);
2222

23-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
24-
{
25-
chacha_init_generic(state, key, iv);
26-
}
27-
EXPORT_SYMBOL(chacha_init_arch);
28-
2923
static int chacha_mips_stream_xor(struct skcipher_request *req,
3024
const struct chacha_ctx *ctx, const u8 *iv)
3125
{
@@ -35,7 +29,7 @@ static int chacha_mips_stream_xor(struct skcipher_request *req,
3529

3630
err = skcipher_walk_virt(&walk, req, false);
3731

38-
chacha_init_generic(state, ctx->key, iv);
32+
chacha_init(state, ctx->key, iv);
3933

4034
while (walk.nbytes > 0) {
4135
unsigned int nbytes = walk.nbytes;
@@ -67,7 +61,7 @@ static int xchacha_mips(struct skcipher_request *req)
6761
u32 state[16];
6862
u8 real_iv[16];
6963

70-
chacha_init_generic(state, ctx->key, req->iv);
64+
chacha_init(state, ctx->key, req->iv);
7165

7266
hchacha_block(state, subctx.key, ctx->nrounds);
7367
subctx.nrounds = ctx->nrounds;

arch/powerpc/crypto/chacha-p10-glue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,6 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
5757
}
5858
EXPORT_SYMBOL(hchacha_block_arch);
5959

60-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
61-
{
62-
chacha_init_generic(state, key, iv);
63-
}
64-
EXPORT_SYMBOL(chacha_init_arch);
65-
6660
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
6761
int nrounds)
6862
{
@@ -95,7 +89,7 @@ static int chacha_p10_stream_xor(struct skcipher_request *req,
9589
if (err)
9690
return err;
9791

98-
chacha_init_generic(state, ctx->key, iv);
92+
chacha_init(state, ctx->key, iv);
9993

10094
while (walk.nbytes > 0) {
10195
unsigned int nbytes = walk.nbytes;
@@ -137,7 +131,7 @@ static int xchacha_p10(struct skcipher_request *req)
137131
u32 state[16];
138132
u8 real_iv[16];
139133

140-
chacha_init_generic(state, ctx->key, req->iv);
134+
chacha_init(state, ctx->key, req->iv);
141135
hchacha_block_arch(state, subctx.key, ctx->nrounds);
142136
subctx.nrounds = ctx->nrounds;
143137

arch/s390/crypto/chacha-glue.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static int chacha20_s390(struct skcipher_request *req)
4141
int rc;
4242

4343
rc = skcipher_walk_virt(&walk, req, false);
44-
chacha_init_generic(state, ctx->key, req->iv);
44+
chacha_init(state, ctx->key, req->iv);
4545

4646
while (walk.nbytes > 0) {
4747
nbytes = walk.nbytes;
@@ -69,12 +69,6 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
6969
}
7070
EXPORT_SYMBOL(hchacha_block_arch);
7171

72-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
73-
{
74-
chacha_init_generic(state, key, iv);
75-
}
76-
EXPORT_SYMBOL(chacha_init_arch);
77-
7872
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
7973
unsigned int bytes, int nrounds)
8074
{

arch/x86/crypto/chacha_glue.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,6 @@ void hchacha_block_arch(const u32 *state, u32 *stream, int nrounds)
133133
}
134134
EXPORT_SYMBOL(hchacha_block_arch);
135135

136-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv)
137-
{
138-
chacha_init_generic(state, key, iv);
139-
}
140-
EXPORT_SYMBOL(chacha_init_arch);
141-
142136
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src, unsigned int bytes,
143137
int nrounds)
144138
{
@@ -169,7 +163,7 @@ static int chacha_simd_stream_xor(struct skcipher_request *req,
169163

170164
err = skcipher_walk_virt(&walk, req, false);
171165

172-
chacha_init_generic(state, ctx->key, iv);
166+
chacha_init(state, ctx->key, iv);
173167

174168
while (walk.nbytes > 0) {
175169
unsigned int nbytes = walk.nbytes;
@@ -211,7 +205,7 @@ static int xchacha_simd(struct skcipher_request *req)
211205
struct chacha_ctx subctx;
212206
u8 real_iv[16];
213207

214-
chacha_init_generic(state, ctx->key, req->iv);
208+
chacha_init(state, ctx->key, req->iv);
215209

216210
if (req->cryptlen > CHACHA_BLOCK_SIZE && crypto_simd_usable()) {
217211
kernel_fpu_begin();

crypto/chacha_generic.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static int chacha_stream_xor(struct skcipher_request *req,
2121

2222
err = skcipher_walk_virt(&walk, req, false);
2323

24-
chacha_init_generic(state, ctx->key, iv);
24+
chacha_init(state, ctx->key, iv);
2525

2626
while (walk.nbytes > 0) {
2727
unsigned int nbytes = walk.nbytes;
@@ -54,7 +54,7 @@ static int crypto_xchacha_crypt(struct skcipher_request *req)
5454
u8 real_iv[16];
5555

5656
/* Compute the subkey given the original key and first 128 nonce bits */
57-
chacha_init_generic(state, ctx->key, req->iv);
57+
chacha_init(state, ctx->key, req->iv);
5858
hchacha_block_generic(state, subctx.key, ctx->nrounds);
5959
subctx.nrounds = ctx->nrounds;
6060

include/crypto/chacha.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ static inline void chacha_init_consts(u32 *state)
6262
state[3] = CHACHA_CONSTANT_TE_K;
6363
}
6464

65-
void chacha_init_arch(u32 *state, const u32 *key, const u8 *iv);
66-
static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv)
65+
static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv)
6766
{
6867
chacha_init_consts(state);
6968
state[4] = key[0];
@@ -80,14 +79,6 @@ static inline void chacha_init_generic(u32 *state, const u32 *key, const u8 *iv)
8079
state[15] = get_unaligned_le32(iv + 12);
8180
}
8281

83-
static inline void chacha_init(u32 *state, const u32 *key, const u8 *iv)
84-
{
85-
if (IS_ENABLED(CONFIG_CRYPTO_ARCH_HAVE_LIB_CHACHA))
86-
chacha_init_arch(state, key, iv);
87-
else
88-
chacha_init_generic(state, key, iv);
89-
}
90-
9182
void chacha_crypt_arch(u32 *state, u8 *dst, const u8 *src,
9283
unsigned int bytes, int nrounds);
9384
void chacha_crypt_generic(u32 *state, u8 *dst, const u8 *src,

tools/testing/crypto/chacha20-s390/test-cipher.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain)
6666
}
6767

6868
/* Encrypt */
69-
chacha_init_arch(chacha_state, (u32*)key, iv);
69+
chacha_init(chacha_state, (u32 *)key, iv);
7070

7171
start = ktime_get_ns();
7272
chacha_crypt_arch(chacha_state, cipher, plain, data_size, 20);
@@ -81,7 +81,7 @@ static int test_lib_chacha(u8 *revert, u8 *cipher, u8 *plain)
8181
pr_info("lib encryption took: %lld nsec", end - start);
8282

8383
/* Decrypt */
84-
chacha_init_arch(chacha_state, (u32 *)key, iv);
84+
chacha_init(chacha_state, (u32 *)key, iv);
8585

8686
start = ktime_get_ns();
8787
chacha_crypt_arch(chacha_state, revert, cipher, data_size, 20);

0 commit comments

Comments
 (0)