Skip to content

Commit 11d6bc7

Browse files
author
Eric Biggers
committed
lib/crypto: arm64/aes: Remove obsolete chunking logic
Since commit aefbab8 ("arm64: fpsimd: Preserve/restore kernel mode NEON at context switch"), kernel-mode NEON sections have been preemptible on arm64. And since commit 7dadeaa ("sched: Further restrict the preemption modes"), voluntary preemption is no longer supported on arm64 either. Therefore, there's no longer any need to limit the length of kernel-mode NEON sections on arm64. Simplify the AES-CBC-MAC code accordingly. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20260401000548.133151-2-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 8aeeb52 commit 11d6bc7

4 files changed

Lines changed: 23 additions & 39 deletions

File tree

arch/arm64/crypto/aes-ce-ccm-glue.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,11 @@ static u32 ce_aes_ccm_auth_data(u8 mac[], u8 const in[], u32 abytes,
101101
u32 blocks = abytes / AES_BLOCK_SIZE;
102102

103103
if (macp == AES_BLOCK_SIZE || (!macp && blocks > 0)) {
104-
u32 rem = ce_aes_mac_update(in, rk, rounds, blocks, mac,
105-
macp, enc_after);
106-
u32 adv = (blocks - rem) * AES_BLOCK_SIZE;
107-
104+
ce_aes_mac_update(in, rk, rounds, blocks, mac, macp,
105+
enc_after);
108106
macp = enc_after ? 0 : AES_BLOCK_SIZE;
109-
in += adv;
110-
abytes -= adv;
111-
112-
if (unlikely(rem))
113-
macp = 0;
107+
in += blocks * AES_BLOCK_SIZE;
108+
abytes -= blocks * AES_BLOCK_SIZE;
114109
} else {
115110
u32 l = min(AES_BLOCK_SIZE - macp, abytes);
116111

include/crypto/aes.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ asmlinkage void ce_aes_essiv_cbc_encrypt(u8 out[], u8 const in[],
230230
asmlinkage void ce_aes_essiv_cbc_decrypt(u8 out[], u8 const in[],
231231
u32 const rk1[], int rounds,
232232
int blocks, u8 iv[], u32 const rk2[]);
233-
asmlinkage size_t ce_aes_mac_update(u8 const in[], u32 const rk[], int rounds,
234-
size_t blocks, u8 dg[], int enc_before,
235-
int enc_after);
233+
asmlinkage void ce_aes_mac_update(u8 const in[], u32 const rk[], int rounds,
234+
size_t blocks, u8 dg[], int enc_before,
235+
int enc_after);
236236
#elif defined(CONFIG_PPC)
237237
void ppc_expand_key_128(u32 *key_enc, const u8 *key);
238238
void ppc_expand_key_192(u32 *key_enc, const u8 *key);

lib/crypto/arm64/aes-modes.S

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,9 @@ AES_FUNC_END(aes_xts_decrypt)
817817

818818
#if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_CBC_MACS)
819819
/*
820-
* size_t aes_mac_update(u8 const in[], u32 const rk[], int rounds,
821-
* size_t blocks, u8 dg[], int enc_before,
822-
* int enc_after);
820+
* void aes_mac_update(u8 const in[], u32 const rk[], int rounds,
821+
* size_t blocks, u8 dg[], int enc_before,
822+
* int enc_after);
823823
*/
824824
AES_FUNC_START(aes_mac_update)
825825
ld1 {v0.16b}, [x4] /* get dg */
@@ -844,7 +844,6 @@ AES_FUNC_START(aes_mac_update)
844844
cbz w5, .Lmacout
845845
encrypt_block v0, w2, x1, x7, w8
846846
st1 {v0.16b}, [x4] /* return dg */
847-
cond_yield .Lmacout, x7, x8
848847
b .Lmacloop4x
849848
.Lmac1x:
850849
add x3, x3, #4
@@ -863,7 +862,6 @@ AES_FUNC_START(aes_mac_update)
863862

864863
.Lmacout:
865864
st1 {v0.16b}, [x4] /* return dg */
866-
mov x0, x3
867865
ret
868866
AES_FUNC_END(aes_mac_update)
869867
#endif /* CONFIG_CRYPTO_LIB_AES_CBC_MACS */

lib/crypto/arm64/aes.h

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ asmlinkage void __aes_ce_decrypt(const u32 inv_rk[], u8 out[AES_BLOCK_SIZE],
2929
asmlinkage u32 __aes_ce_sub(u32 l);
3030
asmlinkage void __aes_ce_invert(struct aes_block *out,
3131
const struct aes_block *in);
32-
asmlinkage size_t neon_aes_mac_update(u8 const in[], u32 const rk[], int rounds,
33-
size_t blocks, u8 dg[], int enc_before,
34-
int enc_after);
32+
asmlinkage void neon_aes_mac_update(u8 const in[], u32 const rk[], int rounds,
33+
size_t blocks, u8 dg[], int enc_before,
34+
int enc_after);
3535

3636
/*
3737
* Expand an AES key using the crypto extensions if supported and usable or
@@ -192,25 +192,16 @@ static bool aes_cbcmac_blocks_arch(u8 h[AES_BLOCK_SIZE],
192192
bool enc_after)
193193
{
194194
if (static_branch_likely(&have_neon) && likely(may_use_simd())) {
195-
do {
196-
size_t rem;
197-
198-
scoped_ksimd() {
199-
if (static_branch_likely(&have_aes))
200-
rem = ce_aes_mac_update(
201-
data, key->k.rndkeys,
202-
key->nrounds, nblocks, h,
203-
enc_before, enc_after);
204-
else
205-
rem = neon_aes_mac_update(
206-
data, key->k.rndkeys,
207-
key->nrounds, nblocks, h,
208-
enc_before, enc_after);
209-
}
210-
data += (nblocks - rem) * AES_BLOCK_SIZE;
211-
nblocks = rem;
212-
enc_before = false;
213-
} while (nblocks);
195+
scoped_ksimd() {
196+
if (static_branch_likely(&have_aes))
197+
ce_aes_mac_update(data, key->k.rndkeys,
198+
key->nrounds, nblocks, h,
199+
enc_before, enc_after);
200+
else
201+
neon_aes_mac_update(data, key->k.rndkeys,
202+
key->nrounds, nblocks, h,
203+
enc_before, enc_after);
204+
}
214205
return true;
215206
}
216207
return false;

0 commit comments

Comments
 (0)