kelliptic

package
v0.0.0-...-28d9278 Latest Latest
Warning

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

Go to latest
Published: May 8, 2014 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package bitelliptic implements several Koblitz elliptic curves over prime fields.

This package operates, internally, on Jacobian coordinates. For a given (x, y) position on the curve, the Jacobian coordinates are (x1, y1, z1) where x = x1/z1² and y = y1/z1³. The greatest speedups come when the whole calculation can be performed within the transform (as in ScalarMult and ScalarBaseMult). But even for Add and Double, it's faster to apply and reverse the transform than to operate in affine coordinates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressPoint

func CompressPoint(curve *Curve, X, Y *big.Int) (cp []byte)

func LegendreSymbol

func LegendreSymbol(a, p *big.Int) int

Types

type Curve

type Curve struct {
	P       *big.Int // the order of the underlying field
	N       *big.Int // the order of the base point
	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
}

A Curve represents a Koblitz Curve with a=0. See http://www.hyperellipticurve.org/EFD/g1p/auto-shortw.html

func S160

func S160() *Curve

S160 returns a Curve which implements secp160k1 (see SEC 2 section 2.4.1)

func S192

func S192() *Curve

S192 returns a Curve which implements secp192k1 (see SEC 2 section 2.5.1)

func S224

func S224() *Curve

S224 returns a Curve which implements secp224k1 (see SEC 2 section 2.6.1)

func S256

func S256() *Curve

S256 returns a Curve which implements secp256k1 (see SEC 2 section 2.7.1)

func (*Curve) Add

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

Add returns the sum of (x1,y1) and (x2,y2)

func (*Curve) CompressPoint

func (curve *Curve) CompressPoint(X, Y *big.Int) (cp []byte)

Point Compression Routines. These could use a lot of testing.

func (*Curve) DecompressPoint

func (curve *Curve) DecompressPoint(cp []byte) (X, Y *big.Int, err error)

func (*Curve) Double

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

Double returns 2*(x,y)

func (*Curve) IsOnCurve

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

IsOnCurve returns true if the given (x,y) lies on the curve.

func (*Curve) Params

func (curve *Curve) Params() *elliptic.CurveParams

func (*Curve) ScalarBaseMult

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

ScalarBaseMult returns k*G, where G is the base point of the group and k is an integer in big-endian form.

func (*Curve) ScalarMult

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

ScalarMult returns k*(Bx,By) where k is a number in big-endian form.

TODO(x): double check if it is okay

func (*Curve) Sqrt

func (curve *Curve) Sqrt(a *big.Int) *big.Int

Sqrt returns the module square root.

Modulus must be prime. Some non-prime values will loop indefinately. Modulo Square root involves deep magic. You have been warned! Uses the Shanks-Tonelli algorithem:

http://en.wikipedia.org/wiki/Shanks-Tonelli_algorithm

Translated from a python implementation found here:

http://eli.thegreenplace.net/2009/03/07/computing-modular-square-roots-in-python/

Jump to

Keyboard shortcuts

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