kernel-5.4: backport latest patches for wireguard
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0126-crypto-poly1305-fix-poly1305_core_setkey-declaration.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Arnd Bergmann <arnd@arndb.de>
3 Date: Mon, 22 Mar 2021 18:05:15 +0100
4 Subject: [PATCH] crypto: poly1305 - fix poly1305_core_setkey() declaration
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 commit 8d195e7a8ada68928f2aedb2c18302a4518fe68e upstream.
10
11 gcc-11 points out a mismatch between the declaration and the definition
12 of poly1305_core_setkey():
13
14 lib/crypto/poly1305-donna32.c:13:67: error: argument 2 of type ‘const u8[16]’ {aka ‘const unsigned char[16]’} with mismatched bound [-Werror=array-parameter=]
15 13 | void poly1305_core_setkey(struct poly1305_core_key *key, const u8 raw_key[16])
16 | ~~~~~~~~~^~~~~~~~~~~
17 In file included from lib/crypto/poly1305-donna32.c:11:
18 include/crypto/internal/poly1305.h:21:68: note: previously declared as ‘const u8 *’ {aka ‘const unsigned char *’}
19 21 | void poly1305_core_setkey(struct poly1305_core_key *key, const u8 *raw_key);
20
21 This is harmless in principle, as the calling conventions are the same,
22 but the more specific prototype allows better type checking in the
23 caller.
24
25 Change the declaration to match the actual function definition.
26 The poly1305_simd_init() is a bit suspicious here, as it previously
27 had a 32-byte argument type, but looks like it needs to take the
28 16-byte POLY1305_BLOCK_SIZE array instead.
29
30 Fixes: 1c08a104360f ("crypto: poly1305 - add new 32 and 64-bit generic versions")
31 Signed-off-by: Arnd Bergmann <arnd@arndb.de>
32 Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
33 Reviewed-by: Eric Biggers <ebiggers@google.com>
34 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
35 Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
36 ---
37 arch/arm/crypto/poly1305-glue.c | 2 +-
38 arch/arm64/crypto/poly1305-glue.c | 2 +-
39 arch/mips/crypto/poly1305-glue.c | 2 +-
40 arch/x86/crypto/poly1305_glue.c | 6 +++---
41 include/crypto/internal/poly1305.h | 3 ++-
42 include/crypto/poly1305.h | 6 ++++--
43 lib/crypto/poly1305-donna32.c | 3 ++-
44 lib/crypto/poly1305-donna64.c | 3 ++-
45 lib/crypto/poly1305.c | 3 ++-
46 9 files changed, 18 insertions(+), 12 deletions(-)
47
48 --- a/arch/arm/crypto/poly1305-glue.c
49 +++ b/arch/arm/crypto/poly1305-glue.c
50 @@ -29,7 +29,7 @@ void __weak poly1305_blocks_neon(void *s
51
52 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
53
54 -void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key)
55 +void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE])
56 {
57 poly1305_init_arm(&dctx->h, key);
58 dctx->s[0] = get_unaligned_le32(key + 16);
59 --- a/arch/arm64/crypto/poly1305-glue.c
60 +++ b/arch/arm64/crypto/poly1305-glue.c
61 @@ -25,7 +25,7 @@ asmlinkage void poly1305_emit(void *stat
62
63 static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
64
65 -void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key)
66 +void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE])
67 {
68 poly1305_init_arm64(&dctx->h, key);
69 dctx->s[0] = get_unaligned_le32(key + 16);
70 --- a/arch/mips/crypto/poly1305-glue.c
71 +++ b/arch/mips/crypto/poly1305-glue.c
72 @@ -17,7 +17,7 @@ asmlinkage void poly1305_init_mips(void
73 asmlinkage void poly1305_blocks_mips(void *state, const u8 *src, u32 len, u32 hibit);
74 asmlinkage void poly1305_emit_mips(void *state, u8 *digest, const u32 *nonce);
75
76 -void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key)
77 +void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE])
78 {
79 poly1305_init_mips(&dctx->h, key);
80 dctx->s[0] = get_unaligned_le32(key + 16);
81 --- a/arch/x86/crypto/poly1305_glue.c
82 +++ b/arch/x86/crypto/poly1305_glue.c
83 @@ -15,7 +15,7 @@
84 #include <asm/simd.h>
85
86 asmlinkage void poly1305_init_x86_64(void *ctx,
87 - const u8 key[POLY1305_KEY_SIZE]);
88 + const u8 key[POLY1305_BLOCK_SIZE]);
89 asmlinkage void poly1305_blocks_x86_64(void *ctx, const u8 *inp,
90 const size_t len, const u32 padbit);
91 asmlinkage void poly1305_emit_x86_64(void *ctx, u8 mac[POLY1305_DIGEST_SIZE],
92 @@ -80,7 +80,7 @@ static void convert_to_base2_64(void *ct
93 state->is_base2_26 = 0;
94 }
95
96 -static void poly1305_simd_init(void *ctx, const u8 key[POLY1305_KEY_SIZE])
97 +static void poly1305_simd_init(void *ctx, const u8 key[POLY1305_BLOCK_SIZE])
98 {
99 poly1305_init_x86_64(ctx, key);
100 }
101 @@ -128,7 +128,7 @@ static void poly1305_simd_emit(void *ctx
102 poly1305_emit_avx(ctx, mac, nonce);
103 }
104
105 -void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 *key)
106 +void poly1305_init_arch(struct poly1305_desc_ctx *dctx, const u8 key[POLY1305_KEY_SIZE])
107 {
108 poly1305_simd_init(&dctx->h, key);
109 dctx->s[0] = get_unaligned_le32(&key[16]);
110 --- a/include/crypto/internal/poly1305.h
111 +++ b/include/crypto/internal/poly1305.h
112 @@ -18,7 +18,8 @@
113 * only the ε-almost-∆-universal hash function (not the full MAC) is computed.
114 */
115
116 -void poly1305_core_setkey(struct poly1305_core_key *key, const u8 *raw_key);
117 +void poly1305_core_setkey(struct poly1305_core_key *key,
118 + const u8 raw_key[POLY1305_BLOCK_SIZE]);
119 static inline void poly1305_core_init(struct poly1305_state *state)
120 {
121 *state = (struct poly1305_state){};
122 --- a/include/crypto/poly1305.h
123 +++ b/include/crypto/poly1305.h
124 @@ -58,8 +58,10 @@ struct poly1305_desc_ctx {
125 };
126 };
127
128 -void poly1305_init_arch(struct poly1305_desc_ctx *desc, const u8 *key);
129 -void poly1305_init_generic(struct poly1305_desc_ctx *desc, const u8 *key);
130 +void poly1305_init_arch(struct poly1305_desc_ctx *desc,
131 + const u8 key[POLY1305_KEY_SIZE]);
132 +void poly1305_init_generic(struct poly1305_desc_ctx *desc,
133 + const u8 key[POLY1305_KEY_SIZE]);
134
135 static inline void poly1305_init(struct poly1305_desc_ctx *desc, const u8 *key)
136 {
137 --- a/lib/crypto/poly1305-donna32.c
138 +++ b/lib/crypto/poly1305-donna32.c
139 @@ -10,7 +10,8 @@
140 #include <asm/unaligned.h>
141 #include <crypto/internal/poly1305.h>
142
143 -void poly1305_core_setkey(struct poly1305_core_key *key, const u8 raw_key[16])
144 +void poly1305_core_setkey(struct poly1305_core_key *key,
145 + const u8 raw_key[POLY1305_BLOCK_SIZE])
146 {
147 /* r &= 0xffffffc0ffffffc0ffffffc0fffffff */
148 key->key.r[0] = (get_unaligned_le32(&raw_key[0])) & 0x3ffffff;
149 --- a/lib/crypto/poly1305-donna64.c
150 +++ b/lib/crypto/poly1305-donna64.c
151 @@ -12,7 +12,8 @@
152
153 typedef __uint128_t u128;
154
155 -void poly1305_core_setkey(struct poly1305_core_key *key, const u8 raw_key[16])
156 +void poly1305_core_setkey(struct poly1305_core_key *key,
157 + const u8 raw_key[POLY1305_BLOCK_SIZE])
158 {
159 u64 t0, t1;
160
161 --- a/lib/crypto/poly1305.c
162 +++ b/lib/crypto/poly1305.c
163 @@ -12,7 +12,8 @@
164 #include <linux/module.h>
165 #include <asm/unaligned.h>
166
167 -void poly1305_init_generic(struct poly1305_desc_ctx *desc, const u8 *key)
168 +void poly1305_init_generic(struct poly1305_desc_ctx *desc,
169 + const u8 key[POLY1305_KEY_SIZE])
170 {
171 poly1305_core_setkey(&desc->core_r, key);
172 desc->s[0] = get_unaligned_le32(key + 16);