Path: blob/master/dep/biscuit/src/assembler_crypto.cpp
4253 views
#include <biscuit/assert.hpp>1#include <biscuit/assembler.hpp>23namespace biscuit {4namespace {5void EmitAES32Instruction(CodeBuffer& buffer, uint32_t op, GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {6BISCUIT_ASSERT(bs <= 0b11);7buffer.Emit32(op | (bs << 30) | (rs2.Index() << 20) |8(rs1.Index() << 15) | (rd.Index() << 7));9}1011void EmitSM4Instruction(CodeBuffer& buffer, uint32_t op, GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {12// Same behavior, function exists for a better contextual name.13EmitAES32Instruction(buffer, op, rd, rs1, rs2, bs);14}1516void EmitAES64Instruction(CodeBuffer& buffer, uint32_t op, GPR rd, GPR rs1, GPR rs2) noexcept {17buffer.Emit32(op | (rs2.Index() << 20) | (rs1.Index() << 15) | (rd.Index() << 7));18}1920void EmitSHAInstruction(CodeBuffer& buffer, uint32_t op, GPR rd, GPR rs1, GPR rs2) noexcept {21// Same behavior, function exists for a better contextual name.22EmitAES64Instruction(buffer, op, rd, rs1, rs2);23}2425void EmitSM3Instruction(CodeBuffer& buffer, uint32_t op, GPR rd, GPR rs) noexcept {26// Same behavior, function exists for a better contextual name.27EmitAES64Instruction(buffer, op, rd, rs, x0);28}29} // Anonymous namespace3031void Assembler::AES32DSI(GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {32EmitAES32Instruction(m_buffer, 0x2A000033, rd, rs1, rs2, bs);33}3435void Assembler::AES32DSMI(GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {36EmitAES32Instruction(m_buffer, 0x2E000033, rd, rs1, rs2, bs);37}3839void Assembler::AES32ESI(GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {40EmitAES32Instruction(m_buffer, 0x22000033, rd, rs1, rs2, bs);41}4243void Assembler::AES32ESMI(GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {44EmitAES32Instruction(m_buffer, 0x26000033, rd, rs1, rs2, bs);45}4647void Assembler::AES64DS(GPR rd, GPR rs1, GPR rs2) noexcept {48EmitAES64Instruction(m_buffer, 0x3A000033, rd, rs1, rs2);49}5051void Assembler::AES64DSM(GPR rd, GPR rs1, GPR rs2) noexcept {52EmitAES64Instruction(m_buffer, 0x3E000033, rd, rs1, rs2);53}5455void Assembler::AES64ES(GPR rd, GPR rs1, GPR rs2) noexcept {56EmitAES64Instruction(m_buffer, 0x32000033, rd, rs1, rs2);57}5859void Assembler::AES64ESM(GPR rd, GPR rs1, GPR rs2) noexcept {60EmitAES64Instruction(m_buffer, 0x36000033, rd, rs1, rs2);61}6263void Assembler::AES64IM(GPR rd, GPR rs) noexcept {64EmitAES64Instruction(m_buffer, 0x30001013, rd, rs, x0);65}6667void Assembler::AES64KS1I(GPR rd, GPR rs, uint32_t rnum) noexcept {68// RVK spec states that 0xB to 0xF are reserved.69BISCUIT_ASSERT(rnum <= 0xA);70EmitAES64Instruction(m_buffer, 0x31001013, rd, rs, GPR{rnum});71}7273void Assembler::AES64KS2(GPR rd, GPR rs1, GPR rs2) noexcept {74EmitAES64Instruction(m_buffer, 0x7E000033, rd, rs1, rs2);75}7677void Assembler::SHA256SIG0(GPR rd, GPR rs) noexcept {78EmitSHAInstruction(m_buffer, 0x10201013, rd, rs, x0);79}8081void Assembler::SHA256SIG1(GPR rd, GPR rs) noexcept {82EmitSHAInstruction(m_buffer, 0x10301013, rd, rs, x0);83}8485void Assembler::SHA256SUM0(GPR rd, GPR rs) noexcept {86EmitSHAInstruction(m_buffer, 0x10001013, rd, rs, x0);87}8889void Assembler::SHA256SUM1(GPR rd, GPR rs) noexcept {90EmitSHAInstruction(m_buffer, 0x10101013, rd, rs, x0);91}9293void Assembler::SHA512SIG0(GPR rd, GPR rs) noexcept {94EmitSHAInstruction(m_buffer, 0x10601013, rd, rs, x0);95}9697void Assembler::SHA512SIG0H(GPR rd, GPR rs1, GPR rs2) noexcept {98EmitSHAInstruction(m_buffer, 0x5C000033, rd, rs1, rs2);99}100101void Assembler::SHA512SIG0L(GPR rd, GPR rs1, GPR rs2) noexcept {102EmitSHAInstruction(m_buffer, 0x54000033, rd, rs1, rs2);103}104105void Assembler::SHA512SIG1(GPR rd, GPR rs) noexcept {106EmitSHAInstruction(m_buffer, 0x10701013, rd, rs, x0);107}108109void Assembler::SHA512SIG1H(GPR rd, GPR rs1, GPR rs2) noexcept {110EmitSHAInstruction(m_buffer, 0x5E000033, rd, rs1, rs2);111}112113void Assembler::SHA512SIG1L(GPR rd, GPR rs1, GPR rs2) noexcept {114EmitSHAInstruction(m_buffer, 0x56000033, rd, rs1, rs2);115}116117void Assembler::SHA512SUM0(GPR rd, GPR rs) noexcept {118EmitSHAInstruction(m_buffer, 0x10401013, rd, rs, x0);119}120121void Assembler::SHA512SUM0R(GPR rd, GPR rs1, GPR rs2) noexcept {122EmitSHAInstruction(m_buffer, 0x50000033, rd, rs1, rs2);123}124125void Assembler::SHA512SUM1(GPR rd, GPR rs) noexcept {126EmitSHAInstruction(m_buffer, 0x10501013, rd, rs, x0);127}128129void Assembler::SHA512SUM1R(GPR rd, GPR rs1, GPR rs2) noexcept {130EmitSHAInstruction(m_buffer, 0x52000033, rd, rs1, rs2);131}132133void Assembler::SM3P0(GPR rd, GPR rs) noexcept {134EmitSM3Instruction(m_buffer, 0x10801013, rd, rs);135}136137void Assembler::SM3P1(GPR rd, GPR rs) noexcept {138EmitSM3Instruction(m_buffer, 0x10901013, rd, rs);139}140141void Assembler::SM4ED(GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {142EmitSM4Instruction(m_buffer, 0x30000033, rd, rs1, rs2, bs);143}144145void Assembler::SM4KS(GPR rd, GPR rs1, GPR rs2, uint32_t bs) noexcept {146EmitSM4Instruction(m_buffer, 0x34000033, rd, rs1, rs2, bs);147}148} // namespace biscuit149150151