An error occurred while fetching folder content.
crypto: x86/poly1305 - fix overflow during partial reduction
Eric Biggers authored
commit 678cce40 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: b1ccc8f4 ("crypto: poly1305 - Add a four block AVX2 variant for x86_64")
Fixes: c70f4abe

 ("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: default avatarEric Biggers <ebiggers@google.com>
Reviewed-by: default avatarMartin Willi <martin@strongswan.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
fbe5cff9
Name Last commit Last update
..
asymmetric_keys Replace magic for trusting the secondary keyring with #define
async_tx async_pq: Remove VLA usage
842.c crypto: acomp - add support for 842 via scomp
Kconfig crypto: aes_ti - disable interrupts while accessing S-box
Makefile crypto: speck - remove Speck
ablkcipher.c crypto: ablkcipher - fix crash flushing dcache in error path
acompress.c crypto: acomp - allow registration of multiple acomps
aead.c crypto: aead - set CRYPTO_TFM_NEED_KEY if ->setkey() fails
aegis.h crypto: aegis/generic - fix for big endian systems
aegis128.c crypto: aegis - fix handling chunked inputs
aegis128l.c crypto: aegis - fix handling chunked inputs
aegis256.c crypto: aegis - fix handling chunked inputs
aes_generic.c crypto: aes-generic - drop alignment requirement
aes_ti.c crypto: aes_ti - disable interrupts while accessing S-box
af_alg.c net: crypto set sk to NULL when af_alg_release.
ahash.c crypto: hash - set CRYPTO_TFM_NEED_KEY if ->setkey() fails
akcipher.c crypto: Replaced gcc specific attributes with macros from compiler.h
algapi.c crypto: api - laying defines and checks for statically allocated buffers
algboss.c crypto: algboss - remove redundant setting of len to zero
algif_aead.c Revert changes to convert to ->poll_mask() and aio IOCB_CMD_POLL
algif_hash.c net: remove sock_no_poll
algif_rng.c net: remove sock_no_poll
algif_skcipher.c Revert changes to convert to ->poll_mask() and aio IOCB_CMD_POLL
ansi_cprng.c crypto: ansi_cprng - Convert to new rng interface
anubis.c crypto: prefix module autoloading with "crypto-"
api.c
arc4.c
authenc.c
authencesn.c
blkcipher.c
blowfish_common.c
blowfish_generic.c
camellia_generic.c
cast5_generic.c
cast6_generic.c
cast_common.c
cbc.c
ccm.c
cfb.c
chacha20_generic.c
chacha20poly1305.c
cipher.c
cmac.c
compress.c
crc32_generic.c
crc32c_generic.c
crct10dif_common.c
crct10dif_generic.c
cryptd.c
crypto_engine.c
crypto_null.c
crypto_user.c
crypto_wq.c
ctr.c
cts.c
deflate.c
des_generic.c
dh.c
dh_helper.c
drbg.c
ecb.c
ecc.c
ecc.h
ecc_curve_defs.h
ecdh.c
ecdh_helper.c
echainiv.c
fcrypt.c
fips.c
gcm.c
gf128mul.c
ghash-generic.c
hash_info.c
hmac.c
internal.h
jitterentropy-kcapi.c
jitterentropy.c
keywrap.c
khazad.c
kpp.c
lrw.c
lz4.c
lz4hc.c
lzo.c
mcryptd.c
md4.c
md5.c
memneq.c
michael_mic.c
morus1280.c
morus640.c
pcbc.c
pcrypt.c
poly1305_generic.c
proc.c
ripemd.h
rmd128.c
rmd160.c
rmd256.c
rmd320.c