# package elliptic
`import "crypto/elliptic"`
elliptic包实现了几条覆盖素数有限域的标准椭圆曲线。
## Index
* [type Curve](#Curve)
* [func P224() Curve](#P224)
* [func P256() Curve](#P256)
* [func P384() Curve](#P384)
* [func P521() Curve](#P521)
* [type CurveParams](#CurveParams)
* [func (curve \*CurveParams) Add(x1, y1, x2, y2 \*big.Int) (\*big.Int, \*big.Int)](#CurveParams.Add)
* [func (curve \*CurveParams) Double(x1, y1 \*big.Int) (\*big.Int, \*big.Int)](#CurveParams.Double)
* [func (curve \*CurveParams) IsOnCurve(x, y \*big.Int) bool](#CurveParams.IsOnCurve)
* [func (curve \*CurveParams) Params() \*CurveParams](#CurveParams.Params)
* [func (curve \*CurveParams) ScalarBaseMult(k []byte) (\*big.Int, \*big.Int)](#CurveParams.ScalarBaseMult)
* [func (curve \*CurveParams) ScalarMult(Bx, By \*big.Int, k []byte) (\*big.Int, \*big.Int)](#CurveParams.ScalarMult)
* [func GenerateKey(curve Curve, rand io.Reader) (priv []byte, x, y \*big.Int, err error)](#GenerateKey)
* [func Marshal(curve Curve, x, y \*big.Int) []byte](#Marshal)
* [func Unmarshal(curve Curve, data []byte) (x, y \*big.Int)](#Unmarshal)
## type [Curve](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L24 "View Source")
```
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
参见[http://www.hyperelliptic.org/EFD/g1p/auto-shortw.html](http://www.hyperelliptic.org/EFD/g1p/auto-shortw.html)
### func [P224](https://github.com/golang/go/blob/master/src/crypto/elliptic/p224.go#L39 "View Source")
```
func P224() Curve
```
返回一个实现了P-224的曲线。(参见FIPS 186-3, section D.2.2)
### func [P256](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L358 "View Source")
```
func P256() Curve
```
返回一个实现了P-256的曲线。(参见FIPS 186-3, section D.2.3)
### func [P384](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L364 "View Source")
```
func P384() Curve
```
返回一个实现了P-384的曲线。(参见FIPS 186-3, section D.2.4)
### func [P521](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L370 "View Source")
```
func P521() Curve
```
返回一个实现了P-512的曲线。(参见FIPS 186-3, section D.2.5)
## type [CurveParams](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L42 "View Source")
```
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](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L50 "View Source")
```
func (curve *CurveParams) Params() *CurveParams
```
### func (\*CurveParams) [IsOnCurve](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L54 "View Source")
```
func (curve *CurveParams) IsOnCurve(x, y *big.Int) bool
```
### func (\*CurveParams) [Add](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L101 "View Source")
```
func (curve *CurveParams) Add(x1, y1, x2, y2 *big.Int) (*big.Int, *big.Int)
```
### func (\*CurveParams) [Double](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L185 "View Source")
```
func (curve *CurveParams) Double(x1, y1 *big.Int) (*big.Int, *big.Int)
```
### func (\*CurveParams) [ScalarMult](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L250 "View Source")
```
func (curve *CurveParams) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)
```
### func (\*CurveParams) [ScalarBaseMult](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L267 "View Source")
```
func (curve *CurveParams) ScalarBaseMult(k []byte) (*big.Int, *big.Int)
```
## func [GenerateKey](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L275 "View Source")
```
func GenerateKey(curve Curve, rand io.Reader) (priv []byte, x, y *big.Int, err error)
```
GenerateKey返回一个公钥/私钥对。priv是私钥,而(x,y)是公钥。密钥对是通过提供的随机数读取器来生成的,该io.Reader接口必须返回随机数据。
## func [Marshal](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L297 "View Source")
```
func Marshal(curve Curve, x, y *big.Int) []byte
```
Marshal将一个点编码为ANSI X9.62指定的格式。
## func [Unmarshal](https://github.com/golang/go/blob/master/src/crypto/elliptic/elliptic.go#L311 "View Source")
```
func Unmarshal(curve Curve, data []byte) (x, y *big.Int)
```
将一个Marshal编码后的点还原;如果出错,x会被设为nil。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe