lkml.org 
[lkml]   [2023]   [May]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v6 10/12] crypto: x86/aes - Prepare for a new AES implementation
On Mon, Apr 10, 2023 at 03:59:34PM -0700, Chang S. Bae wrote:
> Refactor the common C code to avoid code duplication. The AES-NI code uses
> it with a function pointer argument to call back the AES-NI assembly code.
> So will the AES-KL code.

Actually, the AES-NI XTS glue code currently makes direct calls to the assembly
code. This patch changes it to make indirect calls. Indirect calls are very
expensive these days, partly due to all the speculative execution mitigations.
So this patch likely causes a performance regression. How about making
xts_crypt_common() and xts_setkey_common() be inline functions?

Another issue with having the above be exported symbols is that their names are
too generic, so they could easily collide with another symbols in the kernel.
To be exported symbols, they would need something x86-specific in their names.

> arch/x86/crypto/Makefile | 2 +-
> arch/x86/crypto/aes-intel_asm.S | 26 ++++
> arch/x86/crypto/aes-intel_glue.c | 127 ++++++++++++++++
> arch/x86/crypto/aes-intel_glue.h | 44 ++++++
> arch/x86/crypto/aesni-intel_asm.S | 58 +++----
> arch/x86/crypto/aesni-intel_glue.c | 235 +++++++++--------------------
> arch/x86/crypto/aesni-intel_glue.h | 17 +++

It's confusing having aes-intel, aesni-intel, *and* aeskl-intel. Maybe call the
first one "aes-helpers" or "aes-common" instead?

> +struct aes_xts_ctx {
> + u8 raw_tweak_ctx[sizeof(struct crypto_aes_ctx)] AES_ALIGN_ATTR;
> + u8 raw_crypt_ctx[sizeof(struct crypto_aes_ctx)] AES_ALIGN_ATTR;
> +};

This struct does not make sense. It should look like:

struct aes_xts_ctx {
struct crypto_aes_ctx tweak_ctx AES_ALIGN_ATTR;
struct crypto_aes_ctx crypt_ctx AES_ALIGN_ATTR;
};

The runtime alignment to a 16-byte boundary should happen when translating the
raw crypto_skcipher_ctx() into the pointer to the aes_xts_ctx. It should not
happen when accessing each individual field in the aes_xts_ctx.

> /*
> - * int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
> - * unsigned int key_len)
> + * int _aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
> + * unsigned int key_len)
> */

It's conventional to use two leading underscores, not one.

- Eric

\
 
 \ /
  Last update: 2023-05-06 01:28    [W:1.942 / U:0.616 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site