android_kernel_samsung_a7y1.../crypto
Eric Biggers 302bca0e6f 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: b1ccc8f4b631 ("crypto: poly1305 - Add a four block AVX2 variant for x86_64")
Fixes: c70f4abef07a ("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>
2020-04-06 15:51:38 +02:00
..
asymmetric_keys A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
async_tx A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
842.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ablk_helper.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ablkcipher.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
aead.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
aes_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
af_alg.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ahash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
akcipher.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
algapi.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
algboss.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
algif_aead.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
algif_hash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
algif_rng.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
algif_skcipher.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ansi_cprng.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
anubis.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
api.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
arc4.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
authenc.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
authencesn.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
blkcipher.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
blowfish_common.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
blowfish_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
camellia_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cast_common.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cast5_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cast6_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cbc.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ccm.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
chacha20_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
chacha20poly1305.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
chainiv.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cipher.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cmac.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
compress.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crc32.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crc32c_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crct10dif_common.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crct10dif_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cryptd.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crypto_null.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crypto_user.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
crypto_wq.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ctr.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
cts.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
deflate.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
des_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
drbg.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ecb.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
echainiv.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
eseqiv.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
fcrypt.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
fips.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
gcm.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
gf128mul.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ghash-generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
hash_info.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
heh.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
hmac.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
internal.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
jitterentropy-kcapi.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
jitterentropy.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Kconfig A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
keywrap.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
khazad.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
lrw.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
lz4.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
lz4hc.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
lzo.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
Makefile A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
mcryptd.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
md4.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
md5.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
memneq.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
michael_mic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
pcbc.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
pcompress.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
pcrypt.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
poly1305_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
proc.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
ripemd.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rmd128.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rmd160.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rmd256.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rmd320.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rng.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rsa_helper.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rsa.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rsaprivkey.asn1 A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
rsapubkey.asn1 A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
salsa20_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
scatterwalk.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
seed.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
seqiv.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
serpent_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
sha1_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
sha256_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
sha512_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
shash.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
skcipher.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tcrypt.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tcrypt.h A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
tea.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
testmgr.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
testmgr.h crypto: x86/poly1305 - fix overflow during partial reduction 2020-04-06 15:51:38 +02:00
tgr192.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
twofish_common.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
twofish_generic.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
vmac.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
wp512.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
xcbc.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
xor.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
xts.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
zlib.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30
zstd.c A750FXXU4CTBC 2020-03-27 21:51:54 +05:30