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:
31
tea.go
31
tea.go
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user