Re: [PATCH] crypto: lib/chachapoly - Drop dependency on CRYPTO_ALGAPI

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Feb 27, 2025 at 01:33:38PM +0100, Ard Biesheuvel wrote:
> From: Ard Biesheuvel <ardb@xxxxxxxxxx>
> 
> 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 CRYPTO_ALGAPI dependency.
> 
> Reported-by: Arnd Bergmann <arnd@xxxxxxxx>
> Signed-off-by: Ard Biesheuvel <ardb@xxxxxxxxxx>

Acked-by: Eric Biggers <ebiggers@xxxxxxxxxx>

There's indeed redundancy between crypto/scatterwalk.c and lib/scatterlist.c,
and switching to lib/scatterlist.c makes sense here.  I do think that the
implementation in crypto/scatterwalk.c is slightly better (including being
slightly more efficient), especially if my patchset
https://lore.kernel.org/linux-crypto/20250219182341.43961-1-ebiggers@xxxxxxxxxx/
gets applied.  It would be a good future project to unify them into a single
version, which of course would not depend on CRYPTO.  But for now, just using
the one that already does not depend on CRYPTO here is the right choice.

> diff --git a/lib/crypto/Kconfig b/lib/crypto/Kconfig
> index b01253cac70a..a759e6f6a939 100644
> --- a/lib/crypto/Kconfig
> +++ b/lib/crypto/Kconfig
> @@ -135,7 +135,6 @@ config CRYPTO_LIB_CHACHA20POLY1305
>  	depends on CRYPTO
>  	select CRYPTO_LIB_CHACHA
>  	select CRYPTO_LIB_POLY1305
> -	select CRYPTO_ALGAPI

As Arnd mentioned, 'depends on CRYPTO' should be dropped.

> diff --git a/lib/crypto/chacha20poly1305.c b/lib/crypto/chacha20poly1305.c
> index a839c0ac60b2..280a4925dd17 100644
> --- a/lib/crypto/chacha20poly1305.c
> +++ b/lib/crypto/chacha20poly1305.c
> @@ -11,7 +11,6 @@
>  #include <crypto/algapi.h>
>  #include <crypto/chacha20poly1305.h>
>  #include <crypto/chacha.h>
>  #include <crypto/poly1305.h>
> -#include <crypto/scatterwalk.h>

Also replace the include of <crypto/algapi.h> with <crypto/utils.h>, for
consistency with the removal of the selection of CRYPTO_ALGAPI.

- Eric




[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux