github.com/fumiama/gofastTEA@v0.0.10/tea.go (about) 1 // Package tea 2 // from https://github.com/Mrs4s/MiraiGo/blob/master/binary/tea.go 3 package tea 4 5 import ( 6 "encoding/binary" 7 _ "unsafe" // required by go:linkname 8 ) 9 10 type TEA [4]uint32 11 12 // randuint32 returns a lock free uint32 value. 13 //go:linkname randuint32 runtime.fastrand 14 func randuint32() uint32 15 16 //go:nosplit 17 func NewTeaCipher(key []byte) (t TEA) { 18 if len(key) == 16 { 19 t[3] = binary.BigEndian.Uint32(key[12:]) 20 t[2] = binary.BigEndian.Uint32(key[8:]) 21 t[1] = binary.BigEndian.Uint32(key[4:]) 22 t[0] = binary.BigEndian.Uint32(key[0:]) 23 } 24 return 25 } 26 27 //go:nosplit 28 func NewTeaCipherLittleEndian(key []byte) (t TEA) { 29 if len(key) == 16 { 30 t[3] = binary.LittleEndian.Uint32(key[12:]) 31 t[2] = binary.LittleEndian.Uint32(key[8:]) 32 t[1] = binary.LittleEndian.Uint32(key[4:]) 33 t[0] = binary.LittleEndian.Uint32(key[0:]) 34 } 35 return 36 }