mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
22 lines
385 B
Go
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()
|
|
}
|