mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-11-05 20:35:44 +00:00
target/arm: Demultiplex AESE and AESMC
Split these helpers so that we are not passing 'decrypt' within the simd descriptor. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
This commit is contained in:
parent
44a0c4a8cc
commit
0f23908c5c
6 changed files with 41 additions and 27 deletions
|
@ -552,7 +552,9 @@ DEF_HELPER_FLAGS_2(neon_qzip16, TCG_CALL_NO_RWG, void, ptr, ptr)
|
|||
DEF_HELPER_FLAGS_2(neon_qzip32, TCG_CALL_NO_RWG, void, ptr, ptr)
|
||||
|
||||
DEF_HELPER_FLAGS_4(crypto_aese, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
|
||||
DEF_HELPER_FLAGS_4(crypto_aesd, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
|
||||
DEF_HELPER_FLAGS_3(crypto_aesmc, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
|
||||
DEF_HELPER_FLAGS_3(crypto_aesimc, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
|
||||
|
||||
DEF_HELPER_FLAGS_4(crypto_sha1su0, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
|
||||
DEF_HELPER_FLAGS_4(crypto_sha1c, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
|
||||
|
|
|
@ -45,11 +45,9 @@ static void clear_tail_16(void *vd, uint32_t desc)
|
|||
clear_tail(vd, opr_sz, max_sz);
|
||||
}
|
||||
|
||||
static void do_crypto_aese(uint64_t *rd, uint64_t *rn,
|
||||
uint64_t *rm, bool decrypt)
|
||||
static void do_crypto_aese(uint64_t *rd, uint64_t *rn, uint64_t *rm,
|
||||
const uint8_t *sbox, const uint8_t *shift)
|
||||
{
|
||||
static uint8_t const * const sbox[2] = { AES_sbox, AES_isbox };
|
||||
static uint8_t const * const shift[2] = { AES_shifts, AES_ishifts };
|
||||
union CRYPTO_STATE rk = { .l = { rm[0], rm[1] } };
|
||||
union CRYPTO_STATE st = { .l = { rn[0], rn[1] } };
|
||||
int i;
|
||||
|
@ -60,7 +58,7 @@ static void do_crypto_aese(uint64_t *rd, uint64_t *rn,
|
|||
|
||||
/* combine ShiftRows operation and sbox substitution */
|
||||
for (i = 0; i < 16; i++) {
|
||||
CR_ST_BYTE(st, i) = sbox[decrypt][CR_ST_BYTE(rk, shift[decrypt][i])];
|
||||
CR_ST_BYTE(st, i) = sbox[CR_ST_BYTE(rk, shift[i])];
|
||||
}
|
||||
|
||||
rd[0] = st.l[0];
|
||||
|
@ -70,18 +68,26 @@ static void do_crypto_aese(uint64_t *rd, uint64_t *rn,
|
|||
void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc)
|
||||
{
|
||||
intptr_t i, opr_sz = simd_oprsz(desc);
|
||||
bool decrypt = simd_data(desc);
|
||||
|
||||
for (i = 0; i < opr_sz; i += 16) {
|
||||
do_crypto_aese(vd + i, vn + i, vm + i, decrypt);
|
||||
do_crypto_aese(vd + i, vn + i, vm + i, AES_sbox, AES_shifts);
|
||||
}
|
||||
clear_tail(vd, opr_sz, simd_maxsz(desc));
|
||||
}
|
||||
|
||||
static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, bool decrypt)
|
||||
void HELPER(crypto_aesd)(void *vd, void *vn, void *vm, uint32_t desc)
|
||||
{
|
||||
intptr_t i, opr_sz = simd_oprsz(desc);
|
||||
|
||||
for (i = 0; i < opr_sz; i += 16) {
|
||||
do_crypto_aese(vd + i, vn + i, vm + i, AES_isbox, AES_ishifts);
|
||||
}
|
||||
clear_tail(vd, opr_sz, simd_maxsz(desc));
|
||||
}
|
||||
|
||||
static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, const uint32_t *mc)
|
||||
{
|
||||
union CRYPTO_STATE st = { .l = { rm[0], rm[1] } };
|
||||
const uint32_t *mc = decrypt ? AES_imc_rot : AES_mc_rot;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 16; i += 4) {
|
||||
|
@ -99,10 +105,19 @@ static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, bool decrypt)
|
|||
void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t desc)
|
||||
{
|
||||
intptr_t i, opr_sz = simd_oprsz(desc);
|
||||
bool decrypt = simd_data(desc);
|
||||
|
||||
for (i = 0; i < opr_sz; i += 16) {
|
||||
do_crypto_aesmc(vd + i, vm + i, decrypt);
|
||||
do_crypto_aesmc(vd + i, vm + i, AES_mc_rot);
|
||||
}
|
||||
clear_tail(vd, opr_sz, simd_maxsz(desc));
|
||||
}
|
||||
|
||||
void HELPER(crypto_aesimc)(void *vd, void *vm, uint32_t desc)
|
||||
{
|
||||
intptr_t i, opr_sz = simd_oprsz(desc);
|
||||
|
||||
for (i = 0; i < opr_sz; i += 16) {
|
||||
do_crypto_aesmc(vd + i, vm + i, AES_imc_rot);
|
||||
}
|
||||
clear_tail(vd, opr_sz, simd_maxsz(desc));
|
||||
}
|
||||
|
|
|
@ -1629,8 +1629,8 @@ STNT1_zprz 1110010 .. 10 ..... 001 ... ..... ..... \
|
|||
### SVE2 Crypto Extensions
|
||||
|
||||
# SVE2 crypto unary operations
|
||||
# AESMC and AESIMC
|
||||
AESMC 01000101 00 10000011100 decrypt:1 00000 rd:5
|
||||
AESMC 01000101 00 10000011100 0 00000 rd:5
|
||||
AESIMC 01000101 00 10000011100 1 00000 rd:5
|
||||
|
||||
# SVE2 crypto destructive binary operations
|
||||
AESE 01000101 00 10001 0 11100 0 ..... ..... @rdn_rm_e0
|
||||
|
|
|
@ -13210,7 +13210,6 @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn)
|
|||
int opcode = extract32(insn, 12, 5);
|
||||
int rn = extract32(insn, 5, 5);
|
||||
int rd = extract32(insn, 0, 5);
|
||||
int decrypt;
|
||||
gen_helper_gvec_2 *genfn2 = NULL;
|
||||
gen_helper_gvec_3 *genfn3 = NULL;
|
||||
|
||||
|
@ -13221,20 +13220,16 @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn)
|
|||
|
||||
switch (opcode) {
|
||||
case 0x4: /* AESE */
|
||||
decrypt = 0;
|
||||
genfn3 = gen_helper_crypto_aese;
|
||||
break;
|
||||
case 0x6: /* AESMC */
|
||||
decrypt = 0;
|
||||
genfn2 = gen_helper_crypto_aesmc;
|
||||
break;
|
||||
case 0x5: /* AESD */
|
||||
decrypt = 1;
|
||||
genfn3 = gen_helper_crypto_aese;
|
||||
genfn3 = gen_helper_crypto_aesd;
|
||||
break;
|
||||
case 0x7: /* AESIMC */
|
||||
decrypt = 1;
|
||||
genfn2 = gen_helper_crypto_aesmc;
|
||||
genfn2 = gen_helper_crypto_aesimc;
|
||||
break;
|
||||
default:
|
||||
unallocated_encoding(s);
|
||||
|
@ -13245,9 +13240,9 @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn)
|
|||
return;
|
||||
}
|
||||
if (genfn2) {
|
||||
gen_gvec_op2_ool(s, true, rd, rn, decrypt, genfn2);
|
||||
gen_gvec_op2_ool(s, true, rd, rn, 0, genfn2);
|
||||
} else {
|
||||
gen_gvec_op3_ool(s, true, rd, rd, rn, decrypt, genfn3);
|
||||
gen_gvec_op3_ool(s, true, rd, rd, rn, 0, genfn3);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3451,9 +3451,9 @@ static bool trans_VMVN(DisasContext *s, arg_2misc *a)
|
|||
}
|
||||
|
||||
WRAP_2M_3_OOL_FN(gen_AESE, gen_helper_crypto_aese, 0)
|
||||
WRAP_2M_3_OOL_FN(gen_AESD, gen_helper_crypto_aese, 1)
|
||||
WRAP_2M_3_OOL_FN(gen_AESD, gen_helper_crypto_aesd, 0)
|
||||
WRAP_2M_2_OOL_FN(gen_AESMC, gen_helper_crypto_aesmc, 0)
|
||||
WRAP_2M_2_OOL_FN(gen_AESIMC, gen_helper_crypto_aesmc, 1)
|
||||
WRAP_2M_2_OOL_FN(gen_AESIMC, gen_helper_crypto_aesimc, 0)
|
||||
WRAP_2M_2_OOL_FN(gen_SHA1H, gen_helper_crypto_sha1h, 0)
|
||||
WRAP_2M_2_OOL_FN(gen_SHA1SU1, gen_helper_crypto_sha1su1, 0)
|
||||
WRAP_2M_2_OOL_FN(gen_SHA256SU0, gen_helper_crypto_sha256su0, 0)
|
||||
|
|
|
@ -7151,12 +7151,14 @@ TRANS_FEAT(USDOT_zzzz, aa64_sve_i8mm, gen_gvec_ool_arg_zzzz,
|
|||
a->esz == 2 ? gen_helper_gvec_usdot_b : NULL, a, 0)
|
||||
|
||||
TRANS_FEAT_NONSTREAMING(AESMC, aa64_sve2_aes, gen_gvec_ool_zz,
|
||||
gen_helper_crypto_aesmc, a->rd, a->rd, a->decrypt)
|
||||
gen_helper_crypto_aesmc, a->rd, a->rd, 0)
|
||||
TRANS_FEAT_NONSTREAMING(AESIMC, aa64_sve2_aes, gen_gvec_ool_zz,
|
||||
gen_helper_crypto_aesimc, a->rd, a->rd, 0)
|
||||
|
||||
TRANS_FEAT_NONSTREAMING(AESE, aa64_sve2_aes, gen_gvec_ool_arg_zzz,
|
||||
gen_helper_crypto_aese, a, false)
|
||||
gen_helper_crypto_aese, a, 0)
|
||||
TRANS_FEAT_NONSTREAMING(AESD, aa64_sve2_aes, gen_gvec_ool_arg_zzz,
|
||||
gen_helper_crypto_aese, a, true)
|
||||
gen_helper_crypto_aesd, a, 0)
|
||||
|
||||
TRANS_FEAT_NONSTREAMING(SM4E, aa64_sve2_sm4, gen_gvec_ool_arg_zzz,
|
||||
gen_helper_crypto_sm4e, a, 0)
|
||||
|
|
Loading…
Reference in a new issue