# package elliptic

`import "crypto/elliptic"`

elliptic包实现了几条覆盖素数有限域的标准椭圆曲线。

## type Curve

``````type Curve interface {
// Params返回椭圆曲线的参数
Params() *CurveParams
// IsOnCurve判断一个点是否在椭圆曲线上
IsOnCurve(x, y *big.Int) bool
// 返回点(x1,y1)和点(x2,y2)相加的结果
Add(x1, y1, x2, y2 *big.Int) (x, y *big.Int)
// 返回2*(x,y)，即(x,y)+(x,y)
Double(x1, y1 *big.Int) (x, y *big.Int)
// k是一个大端在前格式的数字，返回k*(Bx,By)
ScalarMult(x1, y1 *big.Int, k []byte) (x, y *big.Int)
// k是一个大端在前格式的数字，返回k*G，G是本椭圆曲线的基点
ScalarBaseMult(k []byte) (x, y *big.Int)
}
``````

Curve代表一个短格式的Weierstrass椭圆曲线，其中a=-3。

Weierstrass椭圆曲线的格式：y**2 = x**3 + a*x + b

### func P224

``````func P224() Curve
``````

### func P256

``````func P256() Curve
``````

### func P384

``````func P384() Curve
``````

### func P521

``````func P521() Curve
``````

## type CurveParams

``````type CurveParams struct {
P       *big.Int // 决定有限域的p的值（必须是素数）
N       *big.Int // 基点的阶（必须是素数）
B       *big.Int // 曲线公式的常量（B!=2）
Gx, Gy  *big.Int // 基点的坐标
BitSize int      // 决定有限域的p的字位数
}
``````

CurveParams包含一个椭圆曲线的所有参数，也可提供一般的、非常数时间实现的椭圆曲线。

### func (*CurveParams) Params

``````func (curve *CurveParams) Params() *CurveParams
``````

### func (*CurveParams) IsOnCurve

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

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

### func (*CurveParams) Double

``````func (curve *CurveParams) Double(x1, y1 *big.Int) (*big.Int, *big.Int)
``````

### func (*CurveParams) ScalarMult

``````func (curve *CurveParams) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)
``````

### func (*CurveParams) ScalarBaseMult

``````func (curve *CurveParams) ScalarBaseMult(k []byte) (*big.Int, *big.Int)
``````

## func GenerateKey

``````func GenerateKey(curve Curve, rand io.Reader) (priv []byte, x, y *big.Int, err error)
``````

## func Marshal

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

Marshal将一个点编码为ANSI X9.62指定的格式。

## func Unmarshal

``````func Unmarshal(curve Curve, data []byte) (x, y *big.Int)
``````