Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: lib/chachapoly - Drop dependency on CRYPTO_ALGAPI

The ChaCha20-Poly1305 library code uses the sg_miter API to process
input presented via scatterlists, except for the special case where the
digest buffer is not covered entirely by the same scatterlist entry as
the last byte of input. In that case, it uses scatterwalk_map_and_copy()
to access the memory in the input scatterlist where the digest is stored.

This results in a dependency on crypto/scatterwalk.c and therefore on
CONFIG_CRYPTO_ALGAPI, which is unnecessary, as the sg_miter API already
provides this functionality via sg_copy_to_buffer(). So use that
instead, and drop the dependencies on CONFIG_CRYPTO_ALGAPI and
CONFIG_CRYPTO.

Reported-by: Arnd Bergmann <arnd@arndb.de>
Acked-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Ard Biesheuvel and committed by
Herbert Xu
ba89b4ea 06f0e09f

+3 -6
-2
lib/crypto/Kconfig
··· 142 142 143 143 config CRYPTO_LIB_CHACHA20POLY1305 144 144 tristate "ChaCha20-Poly1305 AEAD support (8-byte nonce library version)" 145 - select CRYPTO 146 145 select CRYPTO_LIB_CHACHA 147 146 select CRYPTO_LIB_POLY1305 148 147 select CRYPTO_LIB_UTILS 149 - select CRYPTO_ALGAPI 150 148 151 149 config CRYPTO_LIB_SHA1 152 150 tristate
+3 -4
lib/crypto/chacha20poly1305.c
··· 7 7 * Information: https://tools.ietf.org/html/rfc8439 8 8 */ 9 9 10 - #include <crypto/algapi.h> 11 10 #include <crypto/chacha20poly1305.h> 12 11 #include <crypto/chacha.h> 13 12 #include <crypto/poly1305.h> 14 - #include <crypto/scatterwalk.h> 13 + #include <crypto/utils.h> 15 14 16 15 #include <linux/unaligned.h> 17 16 #include <linux/kernel.h> ··· 317 318 318 319 if (unlikely(sl > -POLY1305_DIGEST_SIZE)) { 319 320 poly1305_final(&poly1305_state, b.mac[1]); 320 - scatterwalk_map_and_copy(b.mac[encrypt], src, src_len, 321 - sizeof(b.mac[1]), encrypt); 321 + sg_copy_buffer(src, sg_nents(src), b.mac[encrypt], 322 + sizeof(b.mac[1]), src_len, !encrypt); 322 323 ret = encrypt || 323 324 !crypto_memneq(b.mac[0], b.mac[1], POLY1305_DIGEST_SIZE); 324 325 }