[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230604153434.GA1212@quark.localdomain>
Date: Sun, 4 Jun 2023 08:34:34 -0700
From: Eric Biggers <ebiggers@...nel.org>
To: "Chang S. Bae" <chang.seok.bae@...el.com>
Cc: linux-kernel@...r.kernel.org, linux-crypto@...r.kernel.org,
dm-devel@...hat.com, elliott@....com, gmazyland@...il.com,
luto@...nel.org, dave.hansen@...ux.intel.com, tglx@...utronix.de,
bp@...en8.de, mingo@...nel.org, x86@...nel.org,
herbert@...dor.apana.org.au, ardb@...nel.org,
dan.j.williams@...el.com, bernie.keany@...el.com,
charishma1.gairuboyina@...el.com,
lalithambika.krishnakumar@...el.com, nhuck@...gle.com,
"David S. Miller" <davem@...emloft.net>,
Ingo Molnar <mingo@...hat.com>,
"H. Peter Anvin" <hpa@...or.com>
Subject: Re: [PATCH v8 10/12] crypto: x86/aesni - Use the proper data type in
struct aesni_xts_ctx
On Sat, Jun 03, 2023 at 08:22:25AM -0700, Chang S. Bae wrote:
> Every field in struct aesni_xts_ctx is a pointer to a byte array.
A byte array. Not a pointer to a byte array.
> Then, the field can be redefined as that struct type instead of the obscure
> pointer.
There's no pointer.
> static inline struct
> aesni_rfc4106_gcm_ctx *aesni_rfc4106_gcm_ctx_get(struct crypto_aead *tfm)
> {
> - unsigned long align = AESNI_ALIGN;
> -
> - if (align <= crypto_tfm_ctx_alignment())
> - align = 1;
> - return PTR_ALIGN(crypto_aead_ctx(tfm), align);
> + return (struct aesni_rfc4106_gcm_ctx *)aes_align_addr(crypto_aead_ctx(tfm));
> }
Explicit casts from 'void *' are unnecessary.
> static int xts_aesni_setkey(struct crypto_skcipher *tfm, const u8 *key,
> unsigned int keylen)
> {
> - struct aesni_xts_ctx *ctx = crypto_skcipher_ctx(tfm);
> + struct aesni_xts_ctx *ctx = aes_xts_ctx(tfm);
> int err;
>
> err = xts_verify_key(tfm, key, keylen);
> @@ -893,20 +892,20 @@ static int xts_aesni_setkey(struct crypto_skcipher *tfm, const u8 *key,
> keylen /= 2;
>
> /* first half of xts-key is for crypt */
> - err = aes_set_key_common(crypto_skcipher_tfm(tfm), ctx->raw_crypt_ctx,
> + err = aes_set_key_common(crypto_skcipher_tfm(tfm), &ctx->crypt_ctx,
> key, keylen);
> if (err)
> return err;
>
> /* second half of xts-key is for tweak */
> - return aes_set_key_common(crypto_skcipher_tfm(tfm), ctx->raw_tweak_ctx,
> + return aes_set_key_common(crypto_skcipher_tfm(tfm), &ctx->tweak_ctx,
> key + keylen, keylen);
> }
To re-iterate what I said on v6, 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.
Yet, this code is still doing runtime alignment when accessing each individual
field, as the second argument to aes_set_key_common() is 'void *raw_ctx' which
aes_set_key_common() runtime-aligns to crypto_aes_ctx.
We should keep everything consistent, which means making aes_set_key_common()
take a pointer to crypto_aes_ctx and not do the runtime alignment.
- Eric
Powered by blists - more mailing lists