Bluetooth: SMP: Use new AES library API

Switch from the old AES library functions (which use struct
crypto_aes_ctx) to the new ones (which use struct aes_enckey).  This
eliminates the unnecessary computation and caching of the decryption
round keys.  The new AES en/decryption functions are also much faster
and use AES instructions when supported by the CPU.

Note that in addition to the change in the key preparation function and
the key struct type itself, the change in the type of the key struct
results in aes_encrypt() (which is temporarily a type-generic macro)
calling the new encryption function rather than the old one.

Acked-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20260112192035.10427-20-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
master
Eric Biggers 2026-01-12 11:20:17 -08:00
parent 9c941c94bc
commit 7f6dfeb943
1 changed files with 4 additions and 4 deletions

View File

@ -374,7 +374,7 @@ static int smp_h7(struct crypto_shash *tfm_cmac, const u8 w[16],
static int smp_e(const u8 *k, u8 *r)
{
struct crypto_aes_ctx ctx;
struct aes_enckey aes;
uint8_t tmp[16], data[16];
int err;
@ -383,7 +383,7 @@ static int smp_e(const u8 *k, u8 *r)
/* The most significant octet of key corresponds to k[0] */
swap_buf(k, tmp, 16);
err = aes_expandkey(&ctx, tmp, 16);
err = aes_prepareenckey(&aes, tmp, 16);
if (err) {
BT_ERR("cipher setkey failed: %d", err);
return err;
@ -392,14 +392,14 @@ static int smp_e(const u8 *k, u8 *r)
/* Most significant octet of plaintextData corresponds to data[0] */
swap_buf(r, data, 16);
aes_encrypt(&ctx, data, data);
aes_encrypt(&aes, data, data);
/* Most significant octet of encryptedData corresponds to data[0] */
swap_buf(data, r, 16);
SMP_DBG("r %16phN", r);
memzero_explicit(&ctx, sizeof(ctx));
memzero_explicit(&aes, sizeof(aes));
return err;
}