1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 19:17:38 +08:00
MiraiGo/internal/crypto/ecdh_119.go

20 lines
408 B
Go

//go:build !go1.20
package crypto
import (
"crypto/elliptic"
"crypto/md5"
"crypto/rand"
)
func (e *ECDH) init(svrPubKey []byte) {
p256 := elliptic.P256()
key, sx, sy, _ := elliptic.GenerateKey(p256, rand.Reader)
tx, ty := elliptic.Unmarshal(p256, svrPubKey)
x, _ := p256.ScalarMult(tx, ty, key)
hash := md5.Sum(x.Bytes()[:16])
e.ShareKey = hash[:]
e.PublicKey = elliptic.Marshal(p256, sx, sy)
}