On Wed, Jan 07, 2026 at 11:48:33AM +0800, Qingfang Deng wrote:
> On Sun,  4 Jan 2026 21:13:03 -0800, Eric Biggers wrote:
> > --- a/drivers/crypto/inside-secure/safexcel_cipher.c
> > +++ b/drivers/crypto/inside-secure/safexcel_cipher.c
> > @@ -2505,37 +2505,35 @@ static int safexcel_aead_gcm_setkey(struct 
> > crypto_aead *ctfm, const u8 *key,
> >                                 unsigned int len)
> >  {
> >     struct crypto_tfm *tfm = crypto_aead_tfm(ctfm);
> >     struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
> >     struct safexcel_crypto_priv *priv = ctx->base.priv;
> > -   struct crypto_aes_ctx aes;
> > +   struct aes_enckey aes;
> >     u32 hashkey[AES_BLOCK_SIZE >> 2];
> >     int ret, i;
> >  
> > -   ret = aes_expandkey(&aes, key, len);
> > -   if (ret) {
> > -           memzero_explicit(&aes, sizeof(aes));
> > +   ret = aes_prepareenckey(&aes, key, len);
> > +   if (ret)
> >             return ret;
> > -   }
> >  
> >     if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
> >             for (i = 0; i < len / sizeof(u32); i++) {
> > -                   if (le32_to_cpu(ctx->key[i]) != aes.key_enc[i]) {
> > +                   if (ctx->key[i] != get_unaligned((__le32 *)key + i)) {
> 
> "key" is big-endian. Casting it to __le32 does not seem correct.
> Did you mean "get_unaligned_le32", which also convert the endianness?

No.  Previously, in this driver the 32-bit words of the AES key went
from little endian in their original byte array in 'key', to CPU endian
in 'aes.key_enc' (via the get_unaligned_le32() in aes_expandkey()), to
little endian in 'ctx->key' (via the cpu_to_le32() in this function).
Note that ctx->key is an array of __le32.

Those two conversions canceled out.  So I've simplified it to just grab
the little endian words of the key directly.

- Eric

Reply via email to