android_kernel_oneplus_msm8998/crypto
Eric Biggers 7977328f42 crypto: x86/poly1305 - fix overflow during partial reduction
commit 678cce4019d746da6c680c48ba9e6d417803e127 upstream.

The x86_64 implementation of Poly1305 produces the wrong result on some
inputs because poly1305_4block_avx2() incorrectly assumes that when
partially reducing the accumulator, the bits carried from limb 'd4' to
limb 'h0' fit in a 32-bit integer.  This is true for poly1305-generic
which processes only one block at a time.  However, it's not true for
the AVX2 implementation, which processes 4 blocks at a time and
therefore can produce intermediate limbs about 4x larger.

Fix it by making the relevant calculations use 64-bit arithmetic rather
than 32-bit.  Note that most of the carries already used 64-bit
arithmetic, but the d4 -> h0 carry was different for some reason.

To be safe I also made the same change to the corresponding SSE2 code,
though that only operates on 1 or 2 blocks at a time.  I don't think
it's really needed for poly1305_block_sse2(), but it doesn't hurt
because it's already x86_64 code.  It *might* be needed for
poly1305_2block_sse2(), but overflows aren't easy to reproduce there.

This bug was originally detected by my patches that improve testmgr to
fuzz algorithms against their generic implementation.  But also add a
test vector which reproduces it directly (in the AVX2 case).

Fixes: b1ccc8f4b6 ("crypto: poly1305 - Add a four block AVX2 variant for x86_64")
Fixes: c70f4abef0 ("crypto: poly1305 - Add a SSE2 SIMD variant for x86_64")
Cc: <stable@vger.kernel.org> # v4.3+
Cc: Martin Willi <martin@strongswan.org>
Cc: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Martin Willi <martin@strongswan.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2019-04-27 09:34:01 +02:00
..
asymmetric_keys
async_tx
.gitignore
842.c
ablk_helper.c
ablkcipher.c crypto: skcipher - Fix -Wstringop-truncation warnings 2018-10-10 08:52:03 +02:00
aead.c
aes_generic.c
af_alg.c
ahash.c crypto: ahash - fix another early termination in hash walk 2019-03-23 08:44:32 +01:00
akcipher.c
algapi.c
algboss.c
algif_aead.c
algif_hash.c
algif_rng.c
algif_skcipher.c
ansi_cprng.c
anubis.c
api.c
arc4.c
authenc.c crypto: authenc - fix parsing key with misaligned rta_len 2019-01-26 09:42:50 +01:00
authencesn.c crypto: authencesn - Avoid twice completion call in decrypt path 2019-01-26 09:42:49 +01:00
blkcipher.c crypto: skcipher - Fix -Wstringop-truncation warnings 2018-10-10 08:52:03 +02:00
blowfish_common.c
blowfish_generic.c
camellia_generic.c
cast5_generic.c
cast6_generic.c
cast_common.c
cbc.c
ccm.c
chacha20_generic.c
chacha20poly1305.c
chainiv.c
cipher.c
cmac.c
compress.c
crc32.c
crc32c_generic.c
crct10dif_common.c
crct10dif_generic.c
cryptd.c
crypto_null.c
crypto_user.c
crypto_wq.c
ctr.c
cts.c crypto: cts - fix crash on short inputs 2019-01-16 22:16:12 +01:00
deflate.c
des_generic.c
drbg.c
ecb.c
echainiv.c
eseqiv.c
fcrypt.c
fips.c
gcm.c
gf128mul.c
ghash-generic.c
hash_info.c
hmac.c
internal.h
jitterentropy-kcapi.c
jitterentropy.c
Kconfig
keywrap.c
khazad.c
lrw.c crypto: lrw - Fix out-of bounds access on counter overflow 2018-11-21 09:27:34 +01:00
lz4.c
lz4hc.c
lzo.c
Makefile
mcryptd.c
md4.c
md5.c
memneq.c
michael_mic.c
pcbc.c crypto: pcbc - remove bogus memcpy()s with src == dest 2019-03-23 08:44:36 +01:00
pcompress.c
pcrypt.c
poly1305_generic.c
proc.c
ripemd.h
rmd128.c
rmd160.c
rmd256.c
rmd320.c
rng.c
rsa.c
rsa_helper.c
rsaprivkey.asn1
rsapubkey.asn1
salsa20_generic.c
scatterwalk.c
seed.c
seqiv.c
serpent_generic.c
sha1_generic.c
sha256_generic.c
sha512_generic.c
shash.c crypto: shash - Fix a sleep-in-atomic bug in shash_setkey_unaligned 2018-11-10 07:41:42 -08:00
skcipher.c
tcrypt.c
tcrypt.h
tea.c
testmgr.c
testmgr.h crypto: x86/poly1305 - fix overflow during partial reduction 2019-04-27 09:34:01 +02:00
tgr192.c
twofish_common.c
twofish_generic.c
vmac.c crypto: vmac - separate tfm and request context 2018-08-17 20:56:45 +02:00
wp512.c
xcbc.c
xor.c
xts.c
zlib.c