crypto: rename

This commit is contained in:
Felix Lange 2024-03-18 16:40:39 +01:00
parent 8f03199f36
commit 1b5993e690
5 changed files with 14 additions and 13 deletions

View file

@ -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)
}

View file

@ -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

View file

@ -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()
}

View file

@ -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

View file

@ -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{}