mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 09:23:48 +00:00
p2p/enr: using btcec library for signing and verifying of signature, instead of crypto
This commit is contained in:
parent
992c80eb3d
commit
893152e52b
1 changed files with 6 additions and 5 deletions
|
|
@ -222,10 +222,12 @@ func (r *Record) signAndEncode(privkey *ecdsa.PrivateKey) error {
|
||||||
|
|
||||||
digest := crypto.Keccak256Hash(sigcontent)
|
digest := crypto.Keccak256Hash(sigcontent)
|
||||||
|
|
||||||
r.signature, err = crypto.Sign(digest.Bytes(), privkey)
|
key := btcec.PrivateKey(*privkey)
|
||||||
|
signature, err := key.Sign(digest.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
r.signature = signature.Serialize()
|
||||||
|
|
||||||
blob, err := rlp.EncodeToBytes(r.signature)
|
blob, err := rlp.EncodeToBytes(r.signature)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -263,7 +265,6 @@ func (r *Record) verifySignature() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
pubkey1 := pk.SerializeUncompressed()
|
|
||||||
|
|
||||||
// get publickey from message and signature
|
// get publickey from message and signature
|
||||||
sigcontent, err := r.serialisedContent()
|
sigcontent, err := r.serialisedContent()
|
||||||
|
|
@ -273,13 +274,13 @@ func (r *Record) verifySignature() error {
|
||||||
|
|
||||||
digest := crypto.Keccak256Hash(sigcontent)
|
digest := crypto.Keccak256Hash(sigcontent)
|
||||||
|
|
||||||
pubkey2, err := crypto.Ecrecover(digest.Bytes(), r.signature)
|
sign, err := btcec.ParseSignature(r.signature, btcec.S256())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Compare(pubkey1, pubkey2) != 0 {
|
if !sign.Verify(digest.Bytes(), pk) {
|
||||||
return errors.New("public key mismatch")
|
return errors.New("signature is not valid")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue