From 1b5993e690f9ca6df4dee056279c9a166d257f48 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Mon, 18 Mar 2024 16:40:39 +0100 Subject: [PATCH] crypto: rename --- crypto/crypto.go | 7 ++++--- crypto/ecies/ecies.go | 4 ++-- crypto/signature_cgo.go | 2 +- crypto/signature_nocgo.go | 12 ++++++------ p2p/rlpx/rlpx.go | 2 +- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/crypto/crypto.go b/crypto/crypto.go index 769793308f..734feed5ca 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -51,10 +51,11 @@ var ( var errInvalidPubkey = errors.New("invalid secp256k1 public key") -// BetterCurve is an interface that combines both a curve -// and (un)-marshalling functions to and from that curve. -type BetterCurve interface { +// EllipticCurve contains curve operations. +type EllipticCurve interface { elliptic.Curve + + // Point marshaling/unmarshaing. Marshal(x, y *big.Int) []byte Unmarshal(data []byte) (x, y *big.Int) } diff --git a/crypto/ecies/ecies.go b/crypto/ecies/ecies.go index bd7ab1d583..1b6c9e97c1 100644 --- a/crypto/ecies/ecies.go +++ b/crypto/ecies/ecies.go @@ -257,7 +257,7 @@ func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err e d := messageTag(params.Hash, Km, em, s2) - if curve, ok := pub.Curve.(crypto.BetterCurve); ok { + if curve, ok := pub.Curve.(crypto.EllipticCurve); ok { Rb := curve.Marshal(R.PublicKey.X, R.PublicKey.Y) ct = make([]byte, len(Rb)+len(em)+len(d)) copy(ct, Rb) @@ -303,7 +303,7 @@ func (prv *PrivateKey) Decrypt(c, s1, s2 []byte) (m []byte, err error) { R := new(PublicKey) R.Curve = prv.PublicKey.Curve - if curve, ok := R.Curve.(crypto.BetterCurve); ok { + if curve, ok := R.Curve.(crypto.EllipticCurve); ok { R.X, R.Y = curve.Unmarshal(c[:rLen]) if R.X == nil { return nil, ErrInvalidPublicKey diff --git a/crypto/signature_cgo.go b/crypto/signature_cgo.go index 085cbd025f..87289253c0 100644 --- a/crypto/signature_cgo.go +++ b/crypto/signature_cgo.go @@ -81,6 +81,6 @@ func CompressPubkey(pubkey *ecdsa.PublicKey) []byte { } // S256 returns an instance of the secp256k1 curve. -func S256() BetterCurve { +func S256() EllipticCurve { return secp256k1.S256() } diff --git a/crypto/signature_nocgo.go b/crypto/signature_nocgo.go index d6d3564380..f40d928986 100644 --- a/crypto/signature_nocgo.go +++ b/crypto/signature_nocgo.go @@ -159,16 +159,16 @@ func CompressPubkey(pubkey *ecdsa.PublicKey) []byte { } // S256 returns an instance of the secp256k1 curve. -func S256() BetterCurve { - return KoblitzCurve{btcec.S256()} +func S256() EllipticCurve { + return btCurve{btcec.S256()} } -type KoblitzCurve struct { - *btcec.KoblitzCurve +type btCurve struct { + *btcec.btCurve } // Marshall converts a point given as (x, y) into a byte slice. -func (curve KoblitzCurve) Marshal(x, y *big.Int) []byte { +func (curve btCurve) Marshal(x, y *big.Int) []byte { byteLen := (curve.Params().BitSize + 7) / 8 ret := make([]byte, 1+2*byteLen) @@ -182,7 +182,7 @@ func (curve KoblitzCurve) Marshal(x, y *big.Int) []byte { // Unmarshal converts a point, serialised by Marshal, into an x, y pair. On // error, x = nil. -func (curve KoblitzCurve) Unmarshal(data []byte) (x, y *big.Int) { +func (curve btCurve) Unmarshal(data []byte) (x, y *big.Int) { byteLen := (curve.Params().BitSize + 7) / 8 if len(data) != 1+2*byteLen { return nil, nil diff --git a/p2p/rlpx/rlpx.go b/p2p/rlpx/rlpx.go index d34ef60d50..a338490e62 100644 --- a/p2p/rlpx/rlpx.go +++ b/p2p/rlpx/rlpx.go @@ -663,7 +663,7 @@ func exportPubkey(pub *ecies.PublicKey) []byte { if pub == nil { panic("nil pubkey") } - if curve, ok := pub.Curve.(crypto.BetterCurve); ok { + if curve, ok := pub.Curve.(crypto.EllipticCurve); ok { return curve.Marshal(pub.X, pub.Y)[1:] } return []byte{}