field

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MI_EIGHT = MakeModInt(8, true, MOD_ANY)
View Source
var MI_FOUR = MakeModInt(4, true, MOD_ANY)
View Source
var MI_ONE = MakeModInt(1, true, MOD_ANY)
View Source
var MI_SEVEN = MakeModInt(7, true, MOD_ANY)
View Source
var MI_THREE = MakeModInt(3, true, MOD_ANY)
View Source
var MI_TWO = MakeModInt(2, true, MOD_ANY)
View Source
var MI_ZERO = MakeModInt(0, true, MOD_ANY)
View Source
var MOD_ANY *big.Int = nil

for validation purposes this special value is assumed to match any other modulus

View Source
var ONE = big.NewInt(1)
View Source
var THREE = big.NewInt(3)
View Source
var TWO = big.NewInt(2)
View Source
var ZERO = big.NewInt(0)

Functions

func BytesPadBigEndian

func BytesPadBigEndian(i *big.Int, l int) []byte

func GetRandomBytes

func GetRandomBytes(len int) []byte

func GetRandomInt

func GetRandomInt(order *big.Int) *big.Int

func NAF

func NAF(nIn *big.Int, k int) []int8

func TimeTrack

func TimeTrack(start time.Time, name string)

func Trace

func Trace(strs ...fmt.Stringer)

Types

type BaseField

type BaseField struct {
	LengthInBytes int
	FieldOrder    *big.Int
}

type CurveElement

type CurveElement struct {
	ElemParams *CurveParams
	PointLike
}

func (*CurveElement) Add

func (elem *CurveElement) Add(elemIn *CurveElement) *CurveElement

func (*CurveElement) CopyPow

func (elem *CurveElement) CopyPow() PowElement

func (*CurveElement) Invert

func (elem *CurveElement) Invert() *CurveElement

func (*CurveElement) MakeOnePow

func (elem *CurveElement) MakeOnePow() PowElement

func (*CurveElement) MulPoint

func (elem *CurveElement) MulPoint(elemIn *CurveElement) *CurveElement

func (*CurveElement) MulPow

func (elem *CurveElement) MulPow(elemIn PowElement) PowElement

func (*CurveElement) MulScalar

func (elem *CurveElement) MulScalar(n *big.Int) *CurveElement

func (*CurveElement) NegateY

func (elem *CurveElement) NegateY() *CurveElement

func (*CurveElement) Pow

func (elem *CurveElement) Pow(in *ModInt) *CurveElement

func (*CurveElement) PowZn

func (elem *CurveElement) PowZn(in *big.Int) *CurveElement

func (*CurveElement) Square

func (elem *CurveElement) Square() *CurveElement

func (*CurveElement) Sub

func (elem *CurveElement) Sub(_ *CurveElement) *CurveElement

type CurveField

type CurveField struct {
	CurveParams
	// contains filtered or unexported fields
}

func MakeCurveField

func MakeCurveField(
	a *ZElement,
	b *ZElement,
	order *big.Int,
	genX *big.Int,
	genY *big.Int) *CurveField

func (*CurveField) GetGen

func (field *CurveField) GetGen() *CurveElement

func (*CurveField) MakeElement

func (field *CurveField) MakeElement(x *big.Int, y *big.Int) *CurveElement

func (*CurveField) MakeElementFromBytes

func (field *CurveField) MakeElementFromBytes(elemBytes []byte) *CurveElement

func (*CurveField) MakeElementFromHash

func (field *CurveField) MakeElementFromHash(h []byte) *CurveElement

this function constructs a point on the curve from the input hash-derived bytes. since the input is assumed to be random when we use it as an initial X value it is not guaranteed to lie on the curve therefore - unlike MakeElementFromX - we iterate in a stable way to find a value that does satisfy the curve equation the size of the hash must be such that we can guarantee that its value as an integer is less than our target order

func (*CurveField) MakeElementFromX

func (field *CurveField) MakeElementFromX(x *big.Int) *CurveElement

TODO: needs to account for sign

type CurveParams

type CurveParams struct {
	BaseField
	// contains filtered or unexported fields
}

func (*CurveParams) GetTargetField

func (curveParams *CurveParams) GetTargetField() *ZField

type Field

type Field interface{}

type ModInt

type ModInt struct {
	// contains filtered or unexported fields
}

ModInt is intended to represent the base level of integer modular math for field computations. What may be a bit confusing (and I need to think about) is that I don't intend this to be a replacement for big.Int everywhere. The full name here is more explicit: field.ModInt - that is, a large integer that is a component of a field, which implies/requires modular math.

func CopyFrom

func CopyFrom(bi *big.Int, frozen bool, mod *big.Int) *ModInt

func MakeModInt

func MakeModInt(x int64, frozen bool, mod *big.Int) *ModInt

func MakeModIntRandom

func MakeModIntRandom(order *big.Int) *ModInt

func MakeModIntStr

func MakeModIntStr(x string, base int, mod *big.Int) *ModInt

func MakeModIntWords

func MakeModIntWords(w []big.Word, frozen bool, mod *big.Int) *ModInt

func (*ModInt) Add

func (bi *ModInt) Add(in *ModInt) *ModInt

func (*ModInt) Copy

func (bi *ModInt) Copy() *ModInt

func (*ModInt) Freeze

func (bi *ModInt) Freeze()

func (*ModInt) GetMod

func (bi *ModInt) GetMod() *big.Int

func (*ModInt) GetValue

func (bi *ModInt) GetValue() *big.Int

func (*ModInt) Invert

func (bi *ModInt) Invert() *ModInt

func (*ModInt) IsValEqual

func (bi *ModInt) IsValEqual(in *ModInt) bool

TODO: how do we want these functions to behave WRT nil? also TODO: should we validate for modulus? right now no ...

func (*ModInt) Mul

func (bi *ModInt) Mul(in *ModInt) *ModInt

func (*ModInt) Negate

func (bi *ModInt) Negate() *ModInt

func (*ModInt) Pow

func (bi *ModInt) Pow(in *ModInt) *ModInt

func (*ModInt) Square

func (bi *ModInt) Square() *ModInt

func (*ModInt) String

func (bi *ModInt) String() string

func (*ModInt) Sub

func (bi *ModInt) Sub(in *ModInt) *ModInt

type PointLike

type PointLike struct {
	// contains filtered or unexported fields
}

func MakePointFromBytes

func MakePointFromBytes(pointBytes []byte, targetField *BaseField) *PointLike

func (*PointLike) IsInf

func (p *PointLike) IsInf() bool

func (*PointLike) IsValEqual

func (p *PointLike) IsValEqual(elemIn *PointLike) bool

func (*PointLike) String

func (p *PointLike) String() string

TODO: get at base type name ?

func (*PointLike) X

func (p *PointLike) X() *ModInt

func (*PointLike) Y

func (p *PointLike) Y() *ModInt

type PowElement

type PowElement interface {
	String() string
	CopyPow() PowElement
	MakeOnePow() PowElement
	MulPow(PowElement) PowElement
}

type ZElement

type ZElement struct {
	ElemField *ZField
	*ModInt
}

func (*ZElement) String

func (elem *ZElement) String() string

type ZField

type ZField struct {
	BaseField
	TwoInverse *ModInt
}

func MakeZField

func MakeZField(fieldOrder *big.Int) *ZField

func (*ZField) NewElement

func (zfield *ZField) NewElement(elemValue *big.Int) *ZElement

func (*ZField) NewOneElement

func (zfield *ZField) NewOneElement() *ZElement

func (*ZField) NewRandomElement

func (zfield *ZField) NewRandomElement() *ZElement

func (*ZField) NewZeroElement

func (zfield *ZField) NewZeroElement() *ZElement

Jump to

Keyboard shortcuts

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