eccutil

package
v0.0.0-...-cc363e2 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2015 License: BSD-3-Clause Imports: 6 Imported by: 9

Documentation

Overview

Package eccutil contains various utility functions to implement protocols over ecc

Index

Constants

View Source
const MaxLoopCount = 1000

MaxLoopCount is the maximum number of tries we do for parameter search

Variables

View Source
var (
	// ErrMsgShort is returned when the message is too short
	ErrMsgShort = errors.New("singhdas: Message too short")
	// ErrBadCoordinate is returned if a coordinate is an illegal value
	ErrBadCoordinate = errors.New("singhdas: Coordinate illegal value")
	// ErrCoordinateBase is returned if a coordinate is in the base point
	ErrCoordinateBase = errors.New("singhdas: Coordinate illegal value (basepoint,reflection,inverse)")
	// ErrMaxLoop is returned if we cannot find parameters in time, should only happen during testing
	ErrMaxLoop = errors.New("singhdas: Cannot find parameters")
	// ErrNotRelPrime is returned if two numbers must be relative prime but are not
	ErrNotRelPrime = errors.New("singhdas: Not relative prime")
	// ErrParamReuse is returned if blinding parameters are used again
	ErrParamReuse = errors.New("singhdas: Do not reuse blinding parameters")
	// ErrBadBlindParam is returned if the blinding parameter is unusable
	ErrBadBlindParam = errors.New("singhdas: Blinding parameter unusable")
	// ErrHashDif is returned if the hash of the message diffs from the signature
	ErrHashDif = errors.New("singhdas: Hash does not match signature")
	// ErrSigWrong is returned if the signature does not verify for the message and public key of signer
	ErrSigWrong = errors.New("singhdas: Signature does not verify")
)
View Source
var (
	// TestZero testing shortcut variable
	TestZero = big.NewInt(0)
	// TestOne testing shortcut variable
	TestOne = big.NewInt(1)
	// TestTwo testing shortcut variable
	TestTwo = big.NewInt(2)
)

Functions

func BytesToInt

func BytesToInt(b []byte) *big.Int

BytesToInt is a helper function to convert bytes into Int the quick way

func ManyAdd

func ManyAdd(a ...*big.Int) *big.Int

ManyAdd multiplies all parameters

func ManyMult

func ManyMult(a ...*big.Int) *big.Int

ManyMult multiplies all parameters

func PointEqual

func PointEqual(a, b *Point) bool

PointEqual returns true if the points a and b are the same

func Sha1Hash

func Sha1Hash(b []byte) []byte

Sha1Hash is an example hash function doing sha1 over []byte and returning []byte

Types

type Curve

type Curve struct {
	Curve  elliptic.Curve
	Rand   io.Reader
	Params *elliptic.CurveParams
	Nminus *big.Int
	Hash   func([]byte) []byte
}

Curve encapsulates an elliptic curve

func SetCurve

func SetCurve(curve func() elliptic.Curve, rand io.Reader, hash func([]byte) []byte) *Curve

SetCurve returns a Curve encapsulating the curve given

func (Curve) AddPoints

func (curve Curve) AddPoints(a, b *Point) *Point

AddPoints adds two points and returns the result

func (Curve) ExtractR

func (curve Curve) ExtractR(p *Point) (*big.Int, error)

ExtractR extracts the x coordinate of a point and tests it for validity

func (Curve) GenHash

func (curve Curve) GenHash(msg []byte) *big.Int

GenHash returns the hash of msg as Int

func (Curve) GenNV

func (curve Curve) GenNV() (nv []byte, err error)

GenNV generates the signature blind/nonce. Copied from src/crypto/elliptic/elliptic.go GenerateKey

func (Curve) GenNVint

func (curve Curve) GenNVint() (nvi *big.Int, err error)

GenNVint returns an int from genNV

func (Curve) GenerateKey

func (curve Curve) GenerateKey() (priv []byte, pub *Point, err error)

GenerateKey returns a new keypair

func (Curve) Mod

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

Mod returns a % curve.N

func (Curve) ModInverse

func (curve Curve) ModInverse(a *big.Int) (*big.Int, error)

ModInverse calculates the modular inverse of a over P

func (Curve) RandomElement

func (curve Curve) RandomElement() (*big.Int, error)

RandomElement returns a random element within (1,N-1)

func (Curve) ScalarBaseMult

func (curve Curve) ScalarBaseMult(k []byte) *Point

ScalarBaseMult returns the result of a scalar multiplication

func (Curve) ScalarMult

func (curve Curve) ScalarMult(p *Point, k []byte) *Point

ScalarMult returns the result of a scalar multiplication

func (Curve) TestCoordinate

func (curve Curve) TestCoordinate(i *big.Int) (bool, error)

TestCoordinate verifies that a number is not the coordinate of the base point of the curve nor that it is zero or one

func (Curve) TestInverse

func (curve Curve) TestInverse(a, b *big.Int) bool

TestInverse verifies that a number is the multiplicative inverse over P of another number

func (Curve) TestParams

func (curve Curve) TestParams(a ...*big.Int) (bool, error)

TestParams runs tests on parameters to make sure they do not form a dangerous combination

func (Curve) TestPoint

func (curve Curve) TestPoint(x1, y1, x2, y2 *big.Int) (bool, error)

TestPoint verifies that a point (x1,y2) does not equal another point (x1,y2) or it's reflection on 0

func (Curve) WithinRange

func (curve Curve) WithinRange(i *big.Int) bool

WithinRange tests if a number is in the field defined by curve.N

type Point

type Point struct {
	X *big.Int
	Y *big.Int
}

Point describes a point on a curve

func NewPoint

func NewPoint(x, y *big.Int) (p *Point)

NewPoint returns a *Point with x,y coordinates

func ZeroPoint

func ZeroPoint() *Point

ZeroPoint returns a point with (0,0)

func (*Point) GetCoordinates

func (p *Point) GetCoordinates() (x, y *big.Int)

GetCoordinates returns the coordinates of a point

Jump to

Keyboard shortcuts

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