1
0
mirror of https://github.com/fumiama/gofastTEA.git synced 2026-07-01 23:40:24 +08:00
This commit is contained in:
fumiama
2021-11-21 22:15:35 +08:00
parent d94b730a4e
commit 396bb12a7f
13 changed files with 1571 additions and 1 deletions

25
tea_1.16_asm.go Normal file
View File

@@ -0,0 +1,25 @@
//go:build !go1.17 && amd64
// +build !go1.17,amd64
package tea
import (
"math/rand"
"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)
_, _ = rand.Read(dst[0:fill])
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
}