mbox series

[v4,0/3] crypto: Add AES-GCM implementation to lib/crypto

Message ID 20221024063052.109148-1-ardb@kernel.org
Headers show
Series crypto: Add AES-GCM implementation to lib/crypto | expand

Message

Ard Biesheuvel Oct. 24, 2022, 6:30 a.m. UTC
Provide a generic library implementation of AES-GCM which can be used
really early during boot, e.g., to communicate with the security
coprocessor on SEV-SNP virtual machines to bring up secondary cores.
This is needed because the crypto API is not available yet this early.

We cannot rely on special instructions for AES or polynomial
multiplication, which are arch specific and rely on in-kernel SIMD
infrastructure. Instead, add a generic C implementation that combines
the existing C implementations of AES and multiplication in GF(2^128).

To reduce the risk of forgery attacks, replace data dependent table
lookups and conditional branches in the used gf128mul routine with
constant-time equivalents. The AES library has already been robustified
to some extent to prevent known-plaintext timing attacks on the key, but
we call it with interrupts disabled to make it a bit more robust. (Note
that in SEV-SNP context, the VMM is untrusted, and is able to inject
interrupts arbitrarily, and potentially maliciously.)

Changes since v3:
- rename GCM-AES to AES-GCM

Changes since v2:
- move gf128mul to lib/crypto
- add patch #2 to make gf128mul_lle constant time
- fix kerneldoc headers and drop them from the .h file

Changes since v1:
- rename gcm to gcmaes to reflect that GCM is also used in
  combination with other symmetric ciphers (Jason)
- add Nikunj's Tested-by

Ard Biesheuvel (3):
  crypto: move gf128mul library into lib/crypto
  crypto: gf128mul - make gf128mul_lle time invariant
  crypto: aesgcm - Provide minimal library implementation

 crypto/Kconfig                    |   3 -
 crypto/Makefile                   |   1 -
 include/crypto/gcm.h              |  22 +
 lib/crypto/Kconfig                |   9 +
 lib/crypto/Makefile               |   5 +
 lib/crypto/aesgcm.c               | 720 ++++++++++++++++++++
 {crypto => lib/crypto}/gf128mul.c |  58 +-
 7 files changed, 795 insertions(+), 23 deletions(-)
 create mode 100644 lib/crypto/aesgcm.c
 rename {crypto => lib/crypto}/gf128mul.c (87%)

Comments

Eric Biggers Oct. 25, 2022, 5:26 a.m. UTC | #1
On Mon, Oct 24, 2022 at 08:30:50AM +0200, Ard Biesheuvel wrote:
> +config CRYPTO_GF128MUL
> +	tristate

This should be renamed to CRYPTO_LIB_GF128MUL, to make it consistent with all
the other CRYPTO_LIB_* options.  (It could be a separate patch, though.)

- Eric