linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: keescook@chromium.org, ebiggers@kernel.org, jason@zx2c4.com,
	herbert@gondor.apana.org.au, nikunj@amd.com,
	Ard Biesheuvel <ardb@kernel.org>
Subject: [PATCH v3 0/3] crypto: Add GCM-AES implementation to lib/crypto
Date: Tue, 18 Oct 2022 22:04:19 +0200	[thread overview]
Message-ID: <20221018200422.179372-1-ardb@kernel.org> (raw)

Provide a generic library implementation of GCM-AES 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 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: gcmaes - Provide minimal library implementation

 arch/x86/crypto/aesni-intel_glue.c |  24 +-
 crypto/Kconfig                     |   3 -
 crypto/Makefile                    |   1 -
 include/crypto/gcm.h               |  22 +
 lib/crypto/Kconfig                 |   9 +
 lib/crypto/Makefile                |   5 +
 lib/crypto/gcmaes.c                | 720 ++++++++++++++++++++
 {crypto => lib/crypto}/gf128mul.c  |  58 +-
 8 files changed, 807 insertions(+), 35 deletions(-)
 create mode 100644 lib/crypto/gcmaes.c
 rename {crypto => lib/crypto}/gf128mul.c (87%)

-- 
2.35.1


             reply	other threads:[~2022-10-18 20:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-18 20:04 Ard Biesheuvel [this message]
2022-10-18 20:04 ` [PATCH v3 1/3] crypto: move gf128mul library into lib/crypto Ard Biesheuvel
2022-10-18 20:04 ` [PATCH v3 2/3] crypto: gf128mul - make gf128mul_lle time invariant Ard Biesheuvel
2022-10-18 20:04 ` [PATCH v3 3/3] crypto: gcmaes - Provide minimal library implementation Ard Biesheuvel
2022-10-18 20:10 ` [PATCH v3 0/3] crypto: Add GCM-AES implementation to lib/crypto Jason A. Donenfeld
2022-10-18 21:00   ` Ard Biesheuvel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221018200422.179372-1-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=ebiggers@kernel.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=jason@zx2c4.com \
    --cc=keescook@chromium.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=nikunj@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).