1
0
mirror of https://github.com/fumiama/gofastTEA.git synced 2026-06-17 23:53:17 +08:00

add To func

This commit is contained in:
fumiama
2022-02-14 23:24:06 +08:00
parent f7b10b5216
commit 71ff104fd8
5 changed files with 317 additions and 154 deletions

31
tea.go
View File

@@ -2,4 +2,35 @@
// from https://github.com/Mrs4s/MiraiGo/blob/master/binary/tea.go
package tea
import (
"encoding/binary"
_ "unsafe" // required by go:linkname
)
type TEA [4]uint32
// randuint32 returns a lock free uint32 value.
//go:linkname randuint32 runtime.fastrand
func randuint32() uint32
//go:nosplit
func NewTeaCipher(key []byte) (t TEA) {
if len(key) == 16 {
t[3] = binary.BigEndian.Uint32(key[12:])
t[2] = binary.BigEndian.Uint32(key[8:])
t[1] = binary.BigEndian.Uint32(key[4:])
t[0] = binary.BigEndian.Uint32(key[0:])
}
return
}
//go:nosplit
func NewTeaCipherLittleEndian(key []byte) (t TEA) {
if len(key) == 16 {
t[3] = binary.LittleEndian.Uint32(key[12:])
t[2] = binary.LittleEndian.Uint32(key[8:])
t[1] = binary.LittleEndian.Uint32(key[4:])
t[0] = binary.LittleEndian.Uint32(key[0:])
}
return
}