Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/crypto: aescfb: 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-33-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+22 -22
+5 -5
drivers/char/tpm/tpm2-sessions.c
··· 126 126 u8 session_key[SHA256_DIGEST_SIZE]; 127 127 u8 passphrase[SHA256_DIGEST_SIZE]; 128 128 int passphrase_len; 129 - struct crypto_aes_ctx aes_ctx; 129 + struct aes_enckey aes_key; 130 130 /* saved session attributes: */ 131 131 u8 attrs; 132 132 __be32 ordinal; ··· 677 677 auth->scratch); 678 678 679 679 len = tpm_buf_read_u16(buf, &offset_p); 680 - aes_expandkey(&auth->aes_ctx, auth->scratch, AES_KEY_BYTES); 681 - aescfb_encrypt(&auth->aes_ctx, &buf->data[offset_p], 680 + aes_prepareenckey(&auth->aes_key, auth->scratch, AES_KEY_BYTES); 681 + aescfb_encrypt(&auth->aes_key, &buf->data[offset_p], 682 682 &buf->data[offset_p], len, 683 683 auth->scratch + AES_KEY_BYTES); 684 684 /* reset p to beginning of parameters for HMAC */ ··· 858 858 auth->scratch); 859 859 860 860 len = tpm_buf_read_u16(buf, &offset_p); 861 - aes_expandkey(&auth->aes_ctx, auth->scratch, AES_KEY_BYTES); 862 - aescfb_decrypt(&auth->aes_ctx, &buf->data[offset_p], 861 + aes_prepareenckey(&auth->aes_key, auth->scratch, AES_KEY_BYTES); 862 + aescfb_decrypt(&auth->aes_key, &buf->data[offset_p], 863 863 &buf->data[offset_p], len, 864 864 auth->scratch + AES_KEY_BYTES); 865 865 }
+2 -2
include/crypto/aes.h
··· 343 343 extern const u32 aes_enc_tab[256]; 344 344 extern const u32 aes_dec_tab[256]; 345 345 346 - void aescfb_encrypt(const struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src, 346 + void aescfb_encrypt(const struct aes_enckey *key, u8 *dst, const u8 *src, 347 347 int len, const u8 iv[AES_BLOCK_SIZE]); 348 - void aescfb_decrypt(const struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src, 348 + void aescfb_decrypt(const struct aes_enckey *key, u8 *dst, const u8 *src, 349 349 int len, const u8 iv[AES_BLOCK_SIZE]); 350 350 351 351 #endif
+15 -15
lib/crypto/aescfb.c
··· 11 11 #include <linux/module.h> 12 12 #include <asm/irqflags.h> 13 13 14 - static void aescfb_encrypt_block(const struct crypto_aes_ctx *ctx, void *dst, 14 + static void aescfb_encrypt_block(const struct aes_enckey *key, void *dst, 15 15 const void *src) 16 16 { 17 17 unsigned long flags; ··· 25 25 * interrupts disabled. 26 26 */ 27 27 local_irq_save(flags); 28 - aes_encrypt(ctx, dst, src); 28 + aes_encrypt(key, dst, src); 29 29 local_irq_restore(flags); 30 30 } 31 31 32 32 /** 33 33 * aescfb_encrypt - Perform AES-CFB encryption on a block of data 34 34 * 35 - * @ctx: The AES-CFB key schedule 35 + * @key: The AES-CFB key schedule 36 36 * @dst: Pointer to the ciphertext output buffer 37 37 * @src: Pointer the plaintext (may equal @dst for encryption in place) 38 38 * @len: The size in bytes of the plaintext and ciphertext. 39 39 * @iv: The initialization vector (IV) to use for this block of data 40 40 */ 41 - void aescfb_encrypt(const struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src, 41 + void aescfb_encrypt(const struct aes_enckey *key, u8 *dst, const u8 *src, 42 42 int len, const u8 iv[AES_BLOCK_SIZE]) 43 43 { 44 44 u8 ks[AES_BLOCK_SIZE]; 45 45 const u8 *v = iv; 46 46 47 47 while (len > 0) { 48 - aescfb_encrypt_block(ctx, ks, v); 48 + aescfb_encrypt_block(key, ks, v); 49 49 crypto_xor_cpy(dst, src, ks, min(len, AES_BLOCK_SIZE)); 50 50 v = dst; 51 51 ··· 61 61 /** 62 62 * aescfb_decrypt - Perform AES-CFB decryption on a block of data 63 63 * 64 - * @ctx: The AES-CFB key schedule 64 + * @key: The AES-CFB key schedule 65 65 * @dst: Pointer to the plaintext output buffer 66 66 * @src: Pointer the ciphertext (may equal @dst for decryption in place) 67 67 * @len: The size in bytes of the plaintext and ciphertext. 68 68 * @iv: The initialization vector (IV) to use for this block of data 69 69 */ 70 - void aescfb_decrypt(const struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src, 70 + void aescfb_decrypt(const struct aes_enckey *key, u8 *dst, const u8 *src, 71 71 int len, const u8 iv[AES_BLOCK_SIZE]) 72 72 { 73 73 u8 ks[2][AES_BLOCK_SIZE]; 74 74 75 - aescfb_encrypt_block(ctx, ks[0], iv); 75 + aescfb_encrypt_block(key, ks[0], iv); 76 76 77 77 for (int i = 0; len > 0; i ^= 1) { 78 78 if (len > AES_BLOCK_SIZE) ··· 81 81 * performing the XOR, as that may update in place and 82 82 * overwrite the ciphertext. 83 83 */ 84 - aescfb_encrypt_block(ctx, ks[!i], src); 84 + aescfb_encrypt_block(key, ks[!i], src); 85 85 86 86 crypto_xor_cpy(dst, src, ks[i], min(len, AES_BLOCK_SIZE)); 87 87 ··· 214 214 static int __init libaescfb_init(void) 215 215 { 216 216 for (int i = 0; i < ARRAY_SIZE(aescfb_tv); i++) { 217 - struct crypto_aes_ctx ctx; 217 + struct aes_enckey key; 218 218 u8 buf[64]; 219 219 220 - if (aes_expandkey(&ctx, aescfb_tv[i].key, aescfb_tv[i].klen)) { 221 - pr_err("aes_expandkey() failed on vector %d\n", i); 220 + if (aes_prepareenckey(&key, aescfb_tv[i].key, aescfb_tv[i].klen)) { 221 + pr_err("aes_prepareenckey() failed on vector %d\n", i); 222 222 return -ENODEV; 223 223 } 224 224 225 - aescfb_encrypt(&ctx, buf, aescfb_tv[i].ptext, aescfb_tv[i].len, 225 + aescfb_encrypt(&key, buf, aescfb_tv[i].ptext, aescfb_tv[i].len, 226 226 aescfb_tv[i].iv); 227 227 if (memcmp(buf, aescfb_tv[i].ctext, aescfb_tv[i].len)) { 228 228 pr_err("aescfb_encrypt() #1 failed on vector %d\n", i); ··· 230 230 } 231 231 232 232 /* decrypt in place */ 233 - aescfb_decrypt(&ctx, buf, buf, aescfb_tv[i].len, aescfb_tv[i].iv); 233 + aescfb_decrypt(&key, buf, buf, aescfb_tv[i].len, aescfb_tv[i].iv); 234 234 if (memcmp(buf, aescfb_tv[i].ptext, aescfb_tv[i].len)) { 235 235 pr_err("aescfb_decrypt() failed on vector %d\n", i); 236 236 return -ENODEV; 237 237 } 238 238 239 239 /* encrypt in place */ 240 - aescfb_encrypt(&ctx, buf, buf, aescfb_tv[i].len, aescfb_tv[i].iv); 240 + aescfb_encrypt(&key, buf, buf, aescfb_tv[i].len, aescfb_tv[i].iv); 241 241 if (memcmp(buf, aescfb_tv[i].ctext, aescfb_tv[i].len)) { 242 242 pr_err("aescfb_encrypt() #2 failed on vector %d\n", i); 243 243