elliptic

package
v0.0.0-...-942cd0b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package elliptic implements several standard elliptic curves over prime finite fields of the form: y^2 = x^3 + a*x + b (mod p)

Index

Constants

This section is empty.

Variables

View Source
var Secp256k1 = new(CurveParams)

Bitcoin's secp256k1 elliptic curve Reference: https://en.bitcoin.it/wiki/Secp256k1

Functions

func Marshal

func Marshal(curve Curve, x, y *big.Int) []byte

Marshal serializes a point (x,y) in a uncompressed format.

func MarshalCompressed

func MarshalCompressed(curve Curve, x, y *big.Int) []byte

MarshalCompressed serializes a point (x,y) in a compressed SEC format.

func Unmarshal

func Unmarshal(curve Curve, buf []byte) (x, y *big.Int, err error)

Unmarshal deserializes a point (x,y)

Types

type Curve

type Curve interface {
	// Params returns the parameters for the curve.
	Params() *CurveParams
	// IsOnCurve reports whether the given (x,y) lies on the curve.
	IsOnCurve(x, y *big.Int) bool
	// Add returns the sum of (x1,y1) and (x2,y2)
	Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)
	// ScalarMult returns k*(x1, y1)
	ScalarMult(x1, y1, k *big.Int) (x, y *big.Int)
	// ScalarBaseMult returns k*G, where G is the base point of the group
	ScalarBaseMult(k *big.Int) (x, y *big.Int)
}

type CurveParams

type CurveParams struct {
	P       *big.Int // the order of the underlying finite field
	N       *big.Int // the order of the base (generator) point
	A       *big.Int // the constant of the curve equation
	B       *big.Int // the constant of the curve equation
	Gx, Gy  *big.Int // (x,y) of the base point
	BitSize int      // the size of the underlying field
	Name    string   // the canonical name of the curve
}

CurveParams contains the parameters of an elliptic curve and also provides a generic implementation of Curve.

func (*CurveParams) Add

func (curve *CurveParams) Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)

func (*CurveParams) IsOnCurve

func (curve *CurveParams) IsOnCurve(x, y *big.Int) bool

func (*CurveParams) Params

func (curve *CurveParams) Params() *CurveParams

func (*CurveParams) ScalarBaseMult

func (curve *CurveParams) ScalarBaseMult(k *big.Int) (x, y *big.Int)

func (*CurveParams) ScalarMult

func (curve *CurveParams) ScalarMult(x1, y1, k *big.Int) (x, y *big.Int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL