diff --git a/src/backend_x64/emit_x64_aes.cpp b/src/backend_x64/emit_x64_aes.cpp index 4b52946b..74980199 100644 --- a/src/backend_x64/emit_x64_aes.cpp +++ b/src/backend_x64/emit_x64_aes.cpp @@ -15,19 +15,19 @@ namespace Dynarmic::BackendX64 { using namespace Xbyak::util; - -using AESFn = void(Common::AESState&, const Common::AESState&); + +using AESFn = void(Common::AES::State&, const Common::AES::State&); static void EmitAESFunction(std::array args, EmitContext& ctx, BlockOfCode& code, IR::Inst* inst, AESFn fn) { - constexpr u32 stack_space = static_cast(sizeof(Common::AESState)) * 2; + constexpr u32 stack_space = static_cast(sizeof(Common::AES::State)) * 2; const Xbyak::Xmm input = ctx.reg_alloc.UseXmm(args[0]); ctx.reg_alloc.EndOfAllocScope(); ctx.reg_alloc.HostCall(nullptr); code.sub(rsp, stack_space + ABI_SHADOW_SPACE); code.lea(code.ABI_PARAM1, ptr[rsp + ABI_SHADOW_SPACE]); - code.lea(code.ABI_PARAM2, ptr[rsp + ABI_SHADOW_SPACE + sizeof(Common::AESState)]); + code.lea(code.ABI_PARAM2, ptr[rsp + ABI_SHADOW_SPACE + sizeof(Common::AES::State)]); code.movaps(xword[code.ABI_PARAM2], input); @@ -44,13 +44,13 @@ static void EmitAESFunction(std::array args, EmitContext& ctx, Bloc void EmitX64::EmitAESDecryptSingleRound(EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - EmitAESFunction(args, ctx, code, inst, Common::DecryptSingleRound); + EmitAESFunction(args, ctx, code, inst, Common::AES::DecryptSingleRound); } void EmitX64::EmitAESEncryptSingleRound(EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - EmitAESFunction(args, ctx, code, inst, Common::EncryptSingleRound); + EmitAESFunction(args, ctx, code, inst, Common::AES::EncryptSingleRound); } void EmitX64::EmitAESInverseMixColumns(EmitContext& ctx, IR::Inst* inst) { @@ -64,13 +64,13 @@ void EmitX64::EmitAESInverseMixColumns(EmitContext& ctx, IR::Inst* inst) { ctx.reg_alloc.DefineValue(inst, result); } else { - EmitAESFunction(args, ctx, code, inst, Common::InverseMixColumns); + EmitAESFunction(args, ctx, code, inst, Common::AES::InverseMixColumns); } } void EmitX64::EmitAESMixColumns(EmitContext& ctx, IR::Inst* inst) { auto args = ctx.reg_alloc.GetArgumentInfo(inst); - EmitAESFunction(args, ctx, code, inst, Common::MixColumns); + EmitAESFunction(args, ctx, code, inst, Common::AES::MixColumns); } } // namespace Dynarmic::BackendX64 diff --git a/src/common/aes.cpp b/src/common/aes.cpp index f9822486..d6a8f5ab 100644 --- a/src/common/aes.cpp +++ b/src/common/aes.cpp @@ -9,7 +9,7 @@ #include "common/aes.h" #include "common/common_types.h" -namespace Dynarmic::Common { +namespace Dynarmic::Common::AES { using SubstitutionTable = std::array; @@ -69,7 +69,7 @@ static constexpr u8 Multiply(u8 x, u8 y) { ((y >> 4 & 1) * xtime(xtime(xtime(xtime(x)))))); } -static void ShiftRows(AESState& out_state, const AESState& state) { +static void ShiftRows(State& out_state, const State& state) { // Move zeroth row over out_state[0] = state[0]; out_state[4] = state[4]; @@ -100,7 +100,7 @@ static void ShiftRows(AESState& out_state, const AESState& state) { out_state[7] = temp; } -static void InverseShiftRows(AESState& out_state, const AESState& state) { +static void InverseShiftRows(State& out_state, const State& state) { // Move zeroth row over out_state[0] = state[0]; out_state[4] = state[4]; @@ -131,7 +131,7 @@ static void InverseShiftRows(AESState& out_state, const AESState& state) { out_state[15] = temp; } -static void SubBytes(AESState& state, const SubstitutionTable& table) { +static void SubBytes(State& state, const SubstitutionTable& table) { for (size_t i = 0; i < 4; i++) { for (size_t j = 0; j < 4; j++) { state[4 * i + j] = table[state[4 * i + j]]; @@ -139,17 +139,17 @@ static void SubBytes(AESState& state, const SubstitutionTable& table) { } } -void DecryptSingleRound(AESState& out_state, const AESState& state) { +void DecryptSingleRound(State& out_state, const State& state) { InverseShiftRows(out_state, state); SubBytes(out_state, inverse_substitution_box); } -void EncryptSingleRound(AESState& out_state, const AESState& state) { +void EncryptSingleRound(State& out_state, const State& state) { ShiftRows(out_state, state); SubBytes(out_state, substitution_box); } -void MixColumns(AESState& out_state, const AESState& state) { +void MixColumns(State& out_state, const State& state) { for (size_t i = 0; i < out_state.size(); i += 4) { const u8 a = state[i]; const u8 b = state[i + 1]; @@ -165,7 +165,7 @@ void MixColumns(AESState& out_state, const AESState& state) { } } -void InverseMixColumns(AESState& out_state, const AESState& state) { +void InverseMixColumns(State& out_state, const State& state) { for (size_t i = 0; i < out_state.size(); i += 4) { const u8 a = state[i]; const u8 b = state[i + 1]; @@ -179,4 +179,4 @@ void InverseMixColumns(AESState& out_state, const AESState& state) { } } -} // namespace Dynarmic::Common +} // namespace Dynarmic::Common::AES diff --git a/src/common/aes.h b/src/common/aes.h index 2d0cc240..1f58d4b4 100644 --- a/src/common/aes.h +++ b/src/common/aes.h @@ -9,15 +9,15 @@ #include #include "common/common_types.h" -namespace Dynarmic::Common { +namespace Dynarmic::Common::AES { -using AESState = std::array; +using State = std::array; // Assumes the state has already been XORed by the round key. -void DecryptSingleRound(AESState& out_state, const AESState& state); -void EncryptSingleRound(AESState& out_state, const AESState& state); +void DecryptSingleRound(State& out_state, const State& state); +void EncryptSingleRound(State& out_state, const State& state); -void MixColumns(AESState& out_state, const AESState& state); -void InverseMixColumns(AESState& out_state, const AESState& state); +void MixColumns(State& out_state, const State& state); +void InverseMixColumns(State& out_state, const State& state); -} // namespace Dynarmic::Common +} // namespace Dynarmic::Common::AES