kernel: 5.4: import wireguard backport
[openwrt/openwrt.git] / target / linux / generic / backport-5.4 / 080-wireguard-0036-crypto-lib-chacha20poly1305-use-chacha20_crypt.patch
1 From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2 From: Eric Biggers <ebiggers@google.com>
3 Date: Sun, 17 Nov 2019 23:22:16 -0800
4 Subject: [PATCH] crypto: lib/chacha20poly1305 - use chacha20_crypt()
5
6 commit 413808b71e6204b0cc1eeaa77960f7c3cd381d33 upstream.
7
8 Use chacha20_crypt() instead of chacha_crypt(), since it's not really
9 appropriate for users of the ChaCha library API to be passing the number
10 of rounds as an argument.
11
12 Signed-off-by: Eric Biggers <ebiggers@google.com>
13 Acked-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 lib/crypto/chacha20poly1305.c | 16 ++++++++--------
18 1 file changed, 8 insertions(+), 8 deletions(-)
19
20 --- a/lib/crypto/chacha20poly1305.c
21 +++ b/lib/crypto/chacha20poly1305.c
22 @@ -66,14 +66,14 @@ __chacha20poly1305_encrypt(u8 *dst, cons
23 __le64 lens[2];
24 } b;
25
26 - chacha_crypt(chacha_state, b.block0, pad0, sizeof(b.block0), 20);
27 + chacha20_crypt(chacha_state, b.block0, pad0, sizeof(b.block0));
28 poly1305_init(&poly1305_state, b.block0);
29
30 poly1305_update(&poly1305_state, ad, ad_len);
31 if (ad_len & 0xf)
32 poly1305_update(&poly1305_state, pad0, 0x10 - (ad_len & 0xf));
33
34 - chacha_crypt(chacha_state, dst, src, src_len, 20);
35 + chacha20_crypt(chacha_state, dst, src, src_len);
36
37 poly1305_update(&poly1305_state, dst, src_len);
38 if (src_len & 0xf)
39 @@ -140,7 +140,7 @@ __chacha20poly1305_decrypt(u8 *dst, cons
40 if (unlikely(src_len < POLY1305_DIGEST_SIZE))
41 return false;
42
43 - chacha_crypt(chacha_state, b.block0, pad0, sizeof(b.block0), 20);
44 + chacha20_crypt(chacha_state, b.block0, pad0, sizeof(b.block0));
45 poly1305_init(&poly1305_state, b.block0);
46
47 poly1305_update(&poly1305_state, ad, ad_len);
48 @@ -160,7 +160,7 @@ __chacha20poly1305_decrypt(u8 *dst, cons
49
50 ret = crypto_memneq(b.mac, src + dst_len, POLY1305_DIGEST_SIZE);
51 if (likely(!ret))
52 - chacha_crypt(chacha_state, dst, src, dst_len, 20);
53 + chacha20_crypt(chacha_state, dst, src, dst_len);
54
55 memzero_explicit(&b, sizeof(b));
56
57 @@ -241,7 +241,7 @@ bool chacha20poly1305_crypt_sg_inplace(s
58 b.iv[1] = cpu_to_le64(nonce);
59
60 chacha_init(chacha_state, b.k, (u8 *)b.iv);
61 - chacha_crypt(chacha_state, b.block0, pad0, sizeof(b.block0), 20);
62 + chacha20_crypt(chacha_state, b.block0, pad0, sizeof(b.block0));
63 poly1305_init(&poly1305_state, b.block0);
64
65 if (unlikely(ad_len)) {
66 @@ -278,14 +278,14 @@ bool chacha20poly1305_crypt_sg_inplace(s
67
68 if (unlikely(length < sl))
69 l &= ~(CHACHA_BLOCK_SIZE - 1);
70 - chacha_crypt(chacha_state, addr, addr, l, 20);
71 + chacha20_crypt(chacha_state, addr, addr, l);
72 addr += l;
73 length -= l;
74 }
75
76 if (unlikely(length > 0)) {
77 - chacha_crypt(chacha_state, b.chacha_stream, pad0,
78 - CHACHA_BLOCK_SIZE, 20);
79 + chacha20_crypt(chacha_state, b.chacha_stream, pad0,
80 + CHACHA_BLOCK_SIZE);
81 crypto_xor(addr, b.chacha_stream, length);
82 partial = length;
83 }