1
0
mirror of https://github.com/Mrs4s/MiraiGo.git synced 2025-05-04 11:07:40 +08:00
MiraiGo/internal/crypto/ecdh_120.go
2022-12-02 14:07:17 +08:00

22 lines
385 B
Go

//go:build go1.20
package crypto
import (
"crypto/ecdh"
"crypto/md5"
"crypto/rand"
)
func (e *ECDH) init(svrPubKey []byte) {
p256 := ecdh.P256()
local, _ := p256.GenerateKey(rand.Reader)
remote, _ := p256.NewPublicKey(svrPubKey)
share, _ := local.ECDH(remote)
hash := md5.New()
hash.Write(share[:16])
e.ShareKey = hash.Sum(nil)
e.PublicKey = local.PublicKey().Bytes()
}