mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
lib/crypto: riscv/aes: Pass key struct to assembly code
Make the assembly code take the AES key struct directly, rather than the round keys pointer and key length separately. Make the aes_begin macro assume this convention, and remove support for the legacy 'struct crypto_aes_ctx' from it since that isn't used here. This aligns with the convention that is being used (and will continue to be used) for the AES modes, it makes the C glue code slightly simpler, and it avoids the unnecessary shuffling around of arguments. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://patch.msgid.link/20260927224418.109759-17-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
This commit is contained in:
parent
fd5ddddd00
commit
f50ca2d2be
|
|
@ -44,17 +44,20 @@
|
|||
// - RISC-V Vector ('V') with VLEN >= 128
|
||||
// - RISC-V Vector AES block cipher extension ('Zvkned')
|
||||
|
||||
// Loads the AES round keys from \keyp into vector registers and jumps to code
|
||||
// specific to the length of the key. Specifically:
|
||||
// Offsets in struct aes_enckey
|
||||
#define OFFSETOF_KEYLEN 0
|
||||
#define OFFSETOF_RNDKEYS 16
|
||||
|
||||
// Loads the AES round keys from the struct aes_enckey \keyp into vector
|
||||
// registers and jumps to code specific to the length of the key. Specifically:
|
||||
// - If AES-128, loads round keys into v1-v11 and jumps to \label128.
|
||||
// - If AES-192, loads round keys into v1-v13 and jumps to \label192.
|
||||
// - If AES-256, loads round keys into v1-v15 and continues onwards.
|
||||
//
|
||||
// Also sets vl=4 and vtype=e32,m1,ta,ma. Clobbers t0 and t1.
|
||||
.macro aes_begin keyp, label128, label192, key_len
|
||||
.ifb \key_len
|
||||
lwu t0, 480(\keyp) // t0 = key length in bytes
|
||||
.endif
|
||||
// Also sets vl=4 and vtype=e32,m1,ta,ma. Clobbers \keyp, t0, and t1.
|
||||
.macro aes_begin keyp, label128, label192
|
||||
lwu t0, OFFSETOF_KEYLEN(\keyp) // t0 = key length in bytes
|
||||
addi \keyp, \keyp, OFFSETOF_RNDKEYS
|
||||
li t1, 24 // t1 = key length for AES-192
|
||||
vsetivli zero, 4, e32, m1, ta, ma
|
||||
vle32.v v1, (\keyp)
|
||||
|
|
@ -78,20 +81,12 @@
|
|||
vle32.v v10, (\keyp)
|
||||
addi \keyp, \keyp, 16
|
||||
vle32.v v11, (\keyp)
|
||||
.ifb \key_len
|
||||
blt t0, t1, \label128 // If AES-128, goto label128.
|
||||
.else
|
||||
blt \key_len, t1, \label128 // If AES-128, goto label128.
|
||||
.endif
|
||||
addi \keyp, \keyp, 16
|
||||
vle32.v v12, (\keyp)
|
||||
addi \keyp, \keyp, 16
|
||||
vle32.v v13, (\keyp)
|
||||
.ifb \key_len
|
||||
beq t0, t1, \label192 // If AES-192, goto label192.
|
||||
.else
|
||||
beq \key_len, t1, \label192 // If AES-192, goto label192.
|
||||
.endif
|
||||
// Else, it's AES-256.
|
||||
addi \keyp, \keyp, 16
|
||||
vle32.v v14, (\keyp)
|
||||
|
|
|
|||
|
|
@ -50,10 +50,9 @@
|
|||
|
||||
#include "aes-macros.S"
|
||||
|
||||
#define RNDKEYS a0
|
||||
#define KEY_LEN a1
|
||||
#define OUTP a2
|
||||
#define INP a3
|
||||
#define KEYP a0
|
||||
#define OUTP a1
|
||||
#define INP a2
|
||||
|
||||
.macro __aes_crypt_zvkned enc, keybits
|
||||
vle32.v v16, (INP)
|
||||
|
|
@ -63,7 +62,7 @@
|
|||
.endm
|
||||
|
||||
.macro aes_crypt_zvkned enc
|
||||
aes_begin RNDKEYS, 128f, 192f, KEY_LEN
|
||||
aes_begin KEYP, 128f, 192f
|
||||
__aes_crypt_zvkned \enc, 256
|
||||
128:
|
||||
__aes_crypt_zvkned \enc, 128
|
||||
|
|
@ -71,14 +70,14 @@
|
|||
__aes_crypt_zvkned \enc, 192
|
||||
.endm
|
||||
|
||||
// void aes_encrypt_zvkned(const u32 rndkeys[], int key_len,
|
||||
// u8 out[AES_BLOCK_SIZE], const u8 in[AES_BLOCK_SIZE]);
|
||||
// void aes_encrypt_zvkned(const struct aes_enckey *key, u8 out[AES_BLOCK_SIZE],
|
||||
// const u8 in[AES_BLOCK_SIZE]);
|
||||
SYM_FUNC_START(aes_encrypt_zvkned)
|
||||
aes_crypt_zvkned 1
|
||||
SYM_FUNC_END(aes_encrypt_zvkned)
|
||||
|
||||
// void aes_decrypt_zvkned(const u32 rndkeys[], int key_len,
|
||||
// u8 out[AES_BLOCK_SIZE], const u8 in[AES_BLOCK_SIZE]);
|
||||
// void aes_decrypt_zvkned(const struct aes_key *key, u8 out[AES_BLOCK_SIZE],
|
||||
// const u8 in[AES_BLOCK_SIZE]);
|
||||
SYM_FUNC_START(aes_decrypt_zvkned)
|
||||
aes_crypt_zvkned 0
|
||||
SYM_FUNC_END(aes_decrypt_zvkned)
|
||||
|
|
|
|||
|
|
@ -10,10 +10,16 @@
|
|||
|
||||
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_zvkned);
|
||||
|
||||
void aes_encrypt_zvkned(const u32 rndkeys[], int key_len,
|
||||
u8 out[AES_BLOCK_SIZE], const u8 in[AES_BLOCK_SIZE]);
|
||||
void aes_decrypt_zvkned(const u32 rndkeys[], int key_len,
|
||||
u8 out[AES_BLOCK_SIZE], const u8 in[AES_BLOCK_SIZE]);
|
||||
/* The assembly code assumes the following offsets. */
|
||||
static_assert(offsetof(struct aes_enckey, len) == 0);
|
||||
static_assert(offsetof(struct aes_enckey, k.rndkeys) == 16);
|
||||
static_assert(offsetof(struct aes_key, len) == 0);
|
||||
static_assert(offsetof(struct aes_key, k.rndkeys) == 16);
|
||||
|
||||
void aes_encrypt_zvkned(const struct aes_enckey *key, u8 out[AES_BLOCK_SIZE],
|
||||
const u8 in[AES_BLOCK_SIZE]);
|
||||
void aes_decrypt_zvkned(const struct aes_key *key, u8 out[AES_BLOCK_SIZE],
|
||||
const u8 in[AES_BLOCK_SIZE]);
|
||||
|
||||
static void aes_preparekey_arch(union aes_enckey_arch *k,
|
||||
union aes_invkey_arch *inv_k,
|
||||
|
|
@ -29,7 +35,7 @@ static void aes_encrypt_arch(const struct aes_enckey *key,
|
|||
{
|
||||
if (static_branch_likely(&have_zvkned) && likely(may_use_simd())) {
|
||||
kernel_vector_begin();
|
||||
aes_encrypt_zvkned(key->k.rndkeys, key->len, out, in);
|
||||
aes_encrypt_zvkned(key, out, in);
|
||||
kernel_vector_end();
|
||||
} else {
|
||||
aes_encrypt_generic(key->k.rndkeys, key->nrounds, out, in);
|
||||
|
|
@ -46,7 +52,7 @@ static void aes_decrypt_arch(const struct aes_key *key,
|
|||
*/
|
||||
if (static_branch_likely(&have_zvkned) && likely(may_use_simd())) {
|
||||
kernel_vector_begin();
|
||||
aes_decrypt_zvkned(key->k.rndkeys, key->len, out, in);
|
||||
aes_decrypt_zvkned(key, out, in);
|
||||
kernel_vector_end();
|
||||
} else {
|
||||
aes_decrypt_generic(key->inv_k.inv_rndkeys, key->nrounds,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user