1
0
mirror of https://github.com/fumiama/gofastTEA.git synced 2026-06-10 19:40:33 +08:00
Files
gofastTEA/tea_1.16_asm.go
2021-11-22 20:04:01 +08:00

28 lines
757 B
Go

//go:build !go1.17 && amd64
// +build !go1.17,amd64
package tea
import (
"encoding/binary"
"unsafe"
)
// implemented in tea_$GOARCH.s
func encrypt(dstlen uintptr, tlen uintptr)
func decrypt(datalen uintptr, dstlen uintptr, t *TEA)
//go:nosplit
func (t TEA) Encrypt(src []byte) (dst []byte) {
lens := len(src)
fill := 10 - (lens+1)&7
dst = make([]byte, fill+lens+7)
binary.LittleEndian.PutUint32(dst, Uint32())
binary.LittleEndian.PutUint32(dst[4:], Uint32())
binary.LittleEndian.PutUint32(dst[8:], Uint32())
dst[0] = byte(fill-3) | 0xF8 // 存储pad长度
copy(dst[fill:], src)
encrypt(uintptr(*(*unsafe.Pointer)(unsafe.Pointer(&dst)))|uintptr(len(dst)<<40), uintptr(unsafe.Pointer(&t))|(uintptr(len(dst))&0xffffff00_00000000))
return dst
}