kernel: 5.4: import wireguard backport
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0012-crypto-chacha-unexport-chacha_generic-routines.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Ard Biesheuvel <ardb@kernel.org>
3 Date: Fri, 8 Nov 2019 13:22:18 +0100
4 Subject: [PATCH] crypto: chacha - unexport chacha_generic routines
5
6 commit 22cf705360707ced15f9fe5423938f313c7df536 upstream.
7
8 Now that all users of generic ChaCha code have moved to the core library,
9 there is no longer a need for the generic ChaCha skcpiher driver to
10 export parts of it implementation for reuse by other drivers. So drop
11 the exports, and make the symbols static.
12
13 Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
14 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
15 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
16 ---
17 crypto/chacha_generic.c | 26 ++++++++------------------
18 include/crypto/internal/chacha.h | 10 ----------
19 2 files changed, 8 insertions(+), 28 deletions(-)
20
21 --- a/crypto/chacha_generic.c
22 +++ b/crypto/chacha_generic.c
23 @@ -21,7 +21,7 @@ static int chacha_stream_xor(struct skci
24
25 err = skcipher_walk_virt(&walk, req, false);
26
27 - crypto_chacha_init(state, ctx, iv);
28 + chacha_init_generic(state, ctx->key, iv);
29
30 while (walk.nbytes > 0) {
31 unsigned int nbytes = walk.nbytes;
32 @@ -37,36 +37,27 @@ static int chacha_stream_xor(struct skci
33 return err;
34 }
35
36 -void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv)
37 -{
38 - chacha_init_generic(state, ctx->key, iv);
39 -}
40 -EXPORT_SYMBOL_GPL(crypto_chacha_init);
41 -
42 -int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
43 - unsigned int keysize)
44 +static int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
45 + unsigned int keysize)
46 {
47 return chacha_setkey(tfm, key, keysize, 20);
48 }
49 -EXPORT_SYMBOL_GPL(crypto_chacha20_setkey);
50
51 -int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key,
52 - unsigned int keysize)
53 +static int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key,
54 + unsigned int keysize)
55 {
56 return chacha_setkey(tfm, key, keysize, 12);
57 }
58 -EXPORT_SYMBOL_GPL(crypto_chacha12_setkey);
59
60 -int crypto_chacha_crypt(struct skcipher_request *req)
61 +static int crypto_chacha_crypt(struct skcipher_request *req)
62 {
63 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
64 struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
65
66 return chacha_stream_xor(req, ctx, req->iv);
67 }
68 -EXPORT_SYMBOL_GPL(crypto_chacha_crypt);
69
70 -int crypto_xchacha_crypt(struct skcipher_request *req)
71 +static int crypto_xchacha_crypt(struct skcipher_request *req)
72 {
73 struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req);
74 struct chacha_ctx *ctx = crypto_skcipher_ctx(tfm);
75 @@ -75,7 +66,7 @@ int crypto_xchacha_crypt(struct skcipher
76 u8 real_iv[16];
77
78 /* Compute the subkey given the original key and first 128 nonce bits */
79 - crypto_chacha_init(state, ctx, req->iv);
80 + chacha_init_generic(state, ctx->key, req->iv);
81 hchacha_block_generic(state, subctx.key, ctx->nrounds);
82 subctx.nrounds = ctx->nrounds;
83
84 @@ -86,7 +77,6 @@ int crypto_xchacha_crypt(struct skcipher
85 /* Generate the stream and XOR it with the data */
86 return chacha_stream_xor(req, &subctx, real_iv);
87 }
88 -EXPORT_SYMBOL_GPL(crypto_xchacha_crypt);
89
90 static struct skcipher_alg algs[] = {
91 {
92 --- a/include/crypto/internal/chacha.h
93 +++ b/include/crypto/internal/chacha.h
94 @@ -12,8 +12,6 @@ struct chacha_ctx {
95 int nrounds;
96 };
97
98 -void crypto_chacha_init(u32 *state, const struct chacha_ctx *ctx, const u8 *iv);
99 -
100 static inline int chacha_setkey(struct crypto_skcipher *tfm, const u8 *key,
101 unsigned int keysize, int nrounds)
102 {
103 @@ -42,12 +40,4 @@ static int inline chacha12_setkey(struct
104 return chacha_setkey(tfm, key, keysize, 12);
105 }
106
107 -int crypto_chacha20_setkey(struct crypto_skcipher *tfm, const u8 *key,
108 - unsigned int keysize);
109 -int crypto_chacha12_setkey(struct crypto_skcipher *tfm, const u8 *key,
110 - unsigned int keysize);
111 -
112 -int crypto_chacha_crypt(struct skcipher_request *req);
113 -int crypto_xchacha_crypt(struct skcipher_request *req);
114 -
115 #endif /* _CRYPTO_CHACHA_H */