Skip to content

Commit 1aa82df

Browse files
author
Eric Biggers
committed
lib/crypto: aescfb: Don't disable IRQs during AES block encryption
aes_encrypt() now uses AES instructions when available instead of always using table-based code. AES instructions are constant-time and don't benefit from disabling IRQs as a constant-time hardening measure. In fact, on two architectures (arm and riscv) disabling IRQs is counterproductive because it prevents the AES instructions from being used. (See the may_use_simd() implementation on those architectures.) Therefore, let's remove the IRQ disabling/enabling and leave the choice of constant-time hardening measures to the AES library code. Note that currently the arm table-based AES code (which runs on arm kernels that don't have ARMv8 CE) disables IRQs, while the generic table-based AES code does not. So this does technically regress in constant-time hardening when that generic code is used. But as discussed in commit a22fd0e ("lib/crypto: aes: Introduce improved AES library") I think just leaving IRQs enabled is the right choice. Disabling them is slow and can cause problems, and AES instructions (which modern CPUs have) solve the problem in a much better way anyway. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20260331024414.51545-1-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent d2a68ab commit 1aa82df

1 file changed

Lines changed: 3 additions & 22 deletions

File tree

lib/crypto/aescfb.c

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,6 @@
99
#include <crypto/algapi.h>
1010
#include <linux/export.h>
1111
#include <linux/module.h>
12-
#include <asm/irqflags.h>
13-
14-
static void aescfb_encrypt_block(const struct aes_enckey *key, void *dst,
15-
const void *src)
16-
{
17-
unsigned long flags;
18-
19-
/*
20-
* In AES-CFB, the AES encryption operates on known 'plaintext' (the IV
21-
* and ciphertext), making it susceptible to timing attacks on the
22-
* encryption key. The AES library already mitigates this risk to some
23-
* extent by pulling the entire S-box into the caches before doing any
24-
* substitutions, but this strategy is more effective when running with
25-
* interrupts disabled.
26-
*/
27-
local_irq_save(flags);
28-
aes_encrypt(key, dst, src);
29-
local_irq_restore(flags);
30-
}
3112

3213
/**
3314
* aescfb_encrypt - Perform AES-CFB encryption on a block of data
@@ -45,7 +26,7 @@ void aescfb_encrypt(const struct aes_enckey *key, u8 *dst, const u8 *src,
4526
const u8 *v = iv;
4627

4728
while (len > 0) {
48-
aescfb_encrypt_block(key, ks, v);
29+
aes_encrypt(key, ks, v);
4930
crypto_xor_cpy(dst, src, ks, min(len, AES_BLOCK_SIZE));
5031
v = dst;
5132

@@ -72,7 +53,7 @@ void aescfb_decrypt(const struct aes_enckey *key, u8 *dst, const u8 *src,
7253
{
7354
u8 ks[2][AES_BLOCK_SIZE];
7455

75-
aescfb_encrypt_block(key, ks[0], iv);
56+
aes_encrypt(key, ks[0], iv);
7657

7758
for (int i = 0; len > 0; i ^= 1) {
7859
if (len > AES_BLOCK_SIZE)
@@ -81,7 +62,7 @@ void aescfb_decrypt(const struct aes_enckey *key, u8 *dst, const u8 *src,
8162
* performing the XOR, as that may update in place and
8263
* overwrite the ciphertext.
8364
*/
84-
aescfb_encrypt_block(key, ks[!i], src);
65+
aes_encrypt(key, ks[!i], src);
8566

8667
crypto_xor_cpy(dst, src, ks[i], min(len, AES_BLOCK_SIZE));
8768

0 commit comments

Comments
 (0)