Created
February 18, 2022 05:28
-
-
Save emmansun/a3feef970cdf3ffe5db623f324550950 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/bits" | |
) | |
//SM4E <Vd>.4S, <Vn>.4S | |
func sm4e(Vd, Vn byte) uint32 { | |
inst := uint32(0xcec08400) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | |
return bits.ReverseBytes32(inst) | |
} | |
//SM4EKEY <Vd>.4S, <Vn>.4S, <Vm>.4S | |
func sm4ekey(Vd, Vn, Vm byte) uint32 { | |
inst := uint32(0xce60c800) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | (uint32(Vm&0x1f) << 16) | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3PARTW1 <Vd>.4S, <Vn>.4S, <Vm>.4S | |
func sm3partw1(Vd, Vn, Vm byte) uint32 { | |
inst := uint32(0xce60c000) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | (uint32(Vm&0x1f) << 16) | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3PARTW2 <Vd>.4S, <Vn>.4S, <Vm>.4S | |
func sm3partw2(Vd, Vn, Vm byte) uint32 { | |
inst := uint32(0xce60c400) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | (uint32(Vm&0x1f) << 16) | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3SS1 <Vd>.4S, <Vn>.4S, <Vm>.4S, <Va>.4S | |
func sm3ss1(Vd, Vn, Vm, Va byte) uint32 { | |
inst := uint32(0xce400000) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | uint32(Va&0x1f)<<10 | uint32(Vm&0x1f)<<16 | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3TT1A <Vd>.4S, <Vn>.4S, <Vm>.S[<imm2>] | |
func sm3tt1a(Vd, Vn, Vm, imm2 byte) uint32 { | |
inst := uint32(0xce408000) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | uint32(imm2&0x3)<<12 | uint32(Vm&0x1f)<<16 | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3TT1B <Vd>.4S, <Vn>.4S, <Vm>.S[<imm2>] | |
func sm3tt1b(Vd, Vn, Vm, imm2 byte) uint32 { | |
inst := uint32(0xce408400) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | uint32(imm2&0x3)<<12 | uint32(Vm&0x1f)<<16 | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3TT2A <Vd>.4S, <Vn>.4S, <Vm>.S[<imm2>] | |
func sm3tt2a(Vd, Vn, Vm, imm2 byte) uint32 { | |
inst := uint32(0xce408800) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | uint32(imm2&0x3)<<12 | uint32(Vm&0x1f)<<16 | |
return bits.ReverseBytes32(inst) | |
} | |
//SM3TT2B <Vd>.4S, <Vn>.4S, <Vm>.S[<imm2>] | |
func sm3tt2b(Vd, Vn, Vm, imm2 byte) uint32 { | |
inst := uint32(0xce408c00) | uint32(Vd&0x1f) | uint32(Vn&0x1f)<<5 | uint32(imm2&0x3)<<12 | uint32(Vm&0x1f)<<16 | |
return bits.ReverseBytes32(inst) | |
} | |
func main() { | |
fmt.Printf("0x%08x\n", sm4e(8, 0)) | |
fmt.Printf("0x%08x\n", sm4e(8, 1)) | |
fmt.Printf("0x%08x\n", sm4e(8, 2)) | |
fmt.Printf("0x%08x\n", sm4e(8, 3)) | |
fmt.Printf("0x%08x\n", sm4e(8, 4)) | |
fmt.Printf("0x%08x\n", sm4e(8, 5)) | |
fmt.Printf("0x%08x\n", sm4e(8, 6)) | |
fmt.Printf("0x%08x\n", sm4e(8, 7)) | |
fmt.Printf("0x%08x\n", sm4ekey(9, 8, 0)) | |
fmt.Printf("0x%08x\n", sm4ekey(9, 8, 1)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment