1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-08 17:40:26 +08:00
Files
WireGold/gold/link/crypto.go
2021-10-25 19:38:32 +08:00

43 lines
930 B
Go

package link
import "net"
var (
// 本机私钥
// 利用 Curve25519 生成
// https://pkg.go.dev/golang.org/x/crypto/curve25519
// https://www.zhihu.com/question/266758647
privKey [32]byte
// 本机虚拟 ip
me net.IP
// 本机 endpoint
myend *net.UDPAddr
)
// SetMyself 设置本机参数
func SetMyself(privateKey [32]byte, myIP string, myEndpoint string) {
privKey = privateKey
var err error
myend, err = net.ResolveUDPAddr("udp", myEndpoint)
if err != nil {
panic(err)
}
me = net.ParseIP(myIP)
myconn, err = listen()
if err != nil {
panic(err)
}
}
// Encode 使用 ChaCha20-Poly1305 加密
// https://pkg.go.dev/golang.org/x/crypto/chacha20poly1305
func (l *Link) Encode(b []byte) (eb []byte, err error) {
return b, nil
}
// Decode 使用 ChaCha20-Poly1305 解密
// https://pkg.go.dev/golang.org/x/crypto/chacha20poly1305
func (l *Link) Decode(b []byte) (db []byte, err error) {
return b, nil
}