Skip to content

Remove per-architecture ChaCha skcipher glue code

Eric Biggers linux-arm-kernel linux-crypto linux-mips linux-riscv linux-s390 linuxppc-dev lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest9 patches 4 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/9crypto: riscv/chacha - implement library instead of skcipherarch/riscv/crypto/Kconfig arch/riscv/crypto/chacha-riscv64-glue.c arch/riscv/crypto/chacha-riscv64-zvkb.S+75 -1130 replies
2/9crypto: chacha - centralize the skcipher wrappers for arch codearch/arm/crypto/chacha-glue.c arch/arm64/crypto/chacha-neon-glue.c arch/mips/crypto/chacha-glue.c +8 more+288 -1470 replies
3/9crypto: arm/chacha - remove the redundant skcipher algorithmsarch/arm/crypto/Kconfig arch/arm/crypto/chacha-glue.c arch/arm/crypto/chacha-neon-core.S+7 -2440 replies
4/9crypto: arm64/chacha - remove the skcipher algorithmsarch/arm64/crypto/Kconfig arch/arm64/crypto/chacha-neon-core.S arch/arm64/crypto/chacha-neon-glue.c+7 -1460 replies
5/9crypto: mips/chacha - remove the skcipher algorithmsarch/mips/crypto/Kconfig arch/mips/crypto/chacha-glue.c+3 -1340 replies
6/9crypto: powerpc/chacha - remove the skcipher algorithmsarch/powerpc/crypto/Kconfig arch/powerpc/crypto/chacha-p10-glue.c+6 -1470 replies
7/9crypto: s390/chacha - remove the skcipher algorithmsarch/s390/crypto/Kconfig arch/s390/crypto/chacha-glue.c+13 -950 replies
8/9crypto: x86/chacha - remove the skcipher algorithmsarch/x86/crypto/Kconfig arch/x86/crypto/chacha_glue.c+4 -1473 replies
9/9crypto: chacha - remove <crypto/internal/chacha.h>crypto/chacha.c include/crypto/internal/chacha.h+34 -440 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/9] Remove per-architecture ChaCha skcipher glue code

Currently each architecture exposes ChaCha not only through the library API, but also through the crypto_skcipher API. That requires each architecture to implement essentially the same skcipher glue code.

Following the example of what's been done for crc32 and crc32c, eliminate this redundancy by making crypto/chacha.c register both the generic and architecture-optimized skcipher algorithms, implemented on top of the appropriate library functions. This removes almost 800 lines of code and disentangles the library code from the skcipher API.

From what I remember, the following are the reasons why it wasn't just done this way originally. But none of these really hold water:

- The skcipher code was there first, so it may have seemed more natural to add onto it rather than replace it.

- Architectures could register multiple skcipher algorithms using different CPU features and have them all be tested in a single boot. This was convenient in theory, but it never really worked properly. It didn't apply to the library code, the x86 ChaCha code wasn't actually doing this (it used static keys instead), and this cannot catch bugs like accidentally using an AVX instruction in SSE code. Instead, a correct solution, which also doesn't require any special kernel support, is to just boot the kernel in QEMU using different -cpu arguments as needed to test all the code.

- There was a concern about changing cra_driver_names potentially breaking users. But in practice users rely on cra_name, not cra_driver_name. We already change, add, and remove cra_driver_names occasionally for various reasons. And even if someone was relying on a specific cra_driver_name, there are some more lightweight compatibility tricks that could be used.

- There was a desire for users to be able to override the kernel's choice of ChaCha implementation by blacklisting the arch-optimized ChaCha module. But that already became mostly impossible when the library functions were added to the same module. And in practice users don't do this anyway. Even if, hypothetically, someone really needed to do this and for some reason the kernel couldn't be fixed to make the right choice in their case automatically, there are other ways this could be implemented such as a module parameter.

Eric Biggers (9):
crypto: riscv/chacha - implement library instead of skcipher
crypto: chacha - centralize the skcipher wrappers for arch code
crypto: arm/chacha - remove the redundant skcipher algorithms
crypto: arm64/chacha - remove the skcipher algorithms
crypto: mips/chacha - remove the skcipher algorithms
crypto: powerpc/chacha - remove the skcipher algorithms
crypto: s390/chacha - remove the skcipher algorithms
crypto: x86/chacha - remove the skcipher algorithms
crypto: chacha - remove <crypto/internal/chacha.h>

 arch/arm/crypto/Kconfig                 |   7 -
 arch/arm/crypto/chacha-glue.c           | 243 +---------------------
 arch/arm/crypto/chacha-neon-core.S      |   2 +-
 arch/arm64/crypto/Kconfig               |   7 -
 arch/arm64/crypto/chacha-neon-core.S    |   2 +-
 arch/arm64/crypto/chacha-neon-glue.c    | 146 +------------
 arch/mips/crypto/Kconfig                |   6 -
 arch/mips/crypto/chacha-glue.c          | 131 +-----------
 arch/powerpc/crypto/Kconfig             |   8 -
 arch/powerpc/crypto/chacha-p10-glue.c   | 147 +-------------
 arch/riscv/crypto/Kconfig               |  11 +-
 arch/riscv/crypto/chacha-riscv64-glue.c | 112 ++++------
 arch/riscv/crypto/chacha-riscv64-zvkb.S |  71 +++----
 arch/s390/crypto/Kconfig                |   7 -
 arch/s390/crypto/chacha-glue.c          |  99 ++-------
 arch/x86/crypto/Kconfig                 |   9 -
 arch/x86/crypto/chacha_glue.c           | 144 +------------
 crypto/Makefile                         |   3 +-
 crypto/chacha.c                         | 260 ++++++++++++++++++++++++
 crypto/chacha_generic.c                 | 139 -------------
 include/crypto/chacha.h                 |   9 +
 include/crypto/internal/chacha.h        |  43 ----
 22 files changed, 413 insertions(+), 1193 deletions(-)
 create mode 100644 crypto/chacha.c
 delete mode 100644 crypto/chacha_generic.c
 delete mode 100644 include/crypto/internal/chacha.h

base-commit: 56f944529ec2292cbe63377a76df3759d702dd39

Signature · 1 line
2.49.0