config

package
v0.0.0-...-6c19a75 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config provides Golang code generation for efficient field arithmetic operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CoordNameForExtensionDegree

func CoordNameForExtensionDegree(degree uint8) string

TODO: Spaghetti Alert: Okay to have codegen functions here?

func NewElement

func NewElement(s []string) []big.Int

Types

type Element

type Element []big.Int

type Extension

type Extension struct {
	Base   *FieldConfig //Fp
	Size   big.Int      //q
	Degree int          //n such that q = pⁿ TODO: Make uint8 so forced to be positive and small
	RootOf int64        //α
}

Extension is a simple radical extension, obtained by adjoining ⁿ√α to Fp

func NewTower

func NewTower(base *FieldConfig, degree uint8, rootOf int64) Extension

func (*Extension) Add

func (f *Extension) Add(x Element, y Element) Element

func (*Extension) Div

func (f *Extension) Div(u, v Element) Element

Div returns u/v

func (*Extension) Equal

func (f *Extension) Equal(x Element, y Element) bool

func (*Extension) Exp

func (f *Extension) Exp(x Element, exp *big.Int) Element

func (*Extension) FromInt64

func (f *Extension) FromInt64(i ...int64) Element

func (*Extension) Halve

func (f *Extension) Halve(z Element)

func (*Extension) Inverse

func (f *Extension) Inverse(x Element) Element

func (*Extension) IsZero

func (f *Extension) IsZero(u Element) bool

func (*Extension) Mul

func (f *Extension) Mul(x Element, y Element) Element

func (*Extension) MulScalar

func (f *Extension) MulScalar(c *big.Int, x Element) Element

func (*Extension) Neg

func (f *Extension) Neg(x Element) Element

func (*Extension) Sqrt

func (f *Extension) Sqrt(x Element) Element

Sqrt returning √ x, or nil if x is not qr.

func (*Extension) ToMont

func (f *Extension) ToMont(x Element) Element

type FieldConfig

type FieldConfig struct {
	PackageName               string
	ElementName               string
	ModulusBig                *big.Int
	Modulus                   string
	ModulusHex                string
	NbWords                   int
	NbBits                    int
	NbBytes                   int
	NbWordsLastIndex          int
	NbWordsIndexesNoZero      []int
	NbWordsIndexesFull        []int
	P20InversionCorrectiveFac []uint64
	P20InversionNbIterations  int
	UsingP20Inverse           bool
	IsMSWSaturated            bool // indicates if the most significant word is 0xFFFFF...FFFF
	Q                         []uint64
	QInverse                  []uint64
	QMinusOneHalvedP          []uint64 // ((q-1) / 2 ) + 1
	ASM                       bool
	RSquare                   []uint64
	One, Thirteen             []uint64
	LegendreExponent          string // big.Int to base16 string
	NoCarry                   bool
	NoCarrySquare             bool // used if NoCarry is set, but some op may overflow in square optimization
	SqrtQ3Mod4                bool
	SqrtAtkin                 bool
	SqrtTonelliShanks         bool
	SqrtE                     uint64
	SqrtS                     []uint64
	SqrtAtkinExponent         string   // big.Int to base16 string
	SqrtSMinusOneOver2        string   // big.Int to base16 string
	SqrtQ3Mod4Exponent        string   // big.Int to base16 string
	SqrtG                     []uint64 // NonResidue ^  SqrtR (montgomery form)
	NonResidue                big.Int  // (montgomery form)
	LegendreExponentData      *addchain.AddChainData
	SqrtAtkinExponentData     *addchain.AddChainData
	SqrtSMinusOneOver2Data    *addchain.AddChainData
	SqrtQ3Mod4ExponentData    *addchain.AddChainData
	UseAddChain               bool
}

FieldConfig precomputed values used in template for code generation of field element APIs

func NewFieldConfig

func NewFieldConfig(packageName, elementName, modulus string, useAddChain bool) (*FieldConfig, error)

NewFieldConfig returns a data structure with needed information to generate apis for field element

See field/generator package

func (*FieldConfig) Add

func (f *FieldConfig) Add(z *big.Int, x *big.Int, y *big.Int) *FieldConfig

func (*FieldConfig) Exp

func (f *FieldConfig) Exp(res *big.Int, x *big.Int, pow *big.Int) *FieldConfig

func (*FieldConfig) FromMont

func (f *FieldConfig) FromMont(nonMont *big.Int, mont *big.Int) *FieldConfig

func (*FieldConfig) Mul

func (f *FieldConfig) Mul(z *big.Int, x *big.Int, y *big.Int) *FieldConfig

func (*FieldConfig) StringToMont

func (f *FieldConfig) StringToMont(str string) big.Int

StringToMont takes an element written in string form, and returns it in Montgomery form Useful for hard-coding in implementation field elements from standards documents

func (*FieldConfig) ToMont

func (f *FieldConfig) ToMont(nonMont big.Int) big.Int

func (*FieldConfig) ToMontSlice

func (f *FieldConfig) ToMontSlice(x []big.Int) []big.Int

func (*FieldConfig) WriteElement

func (f *FieldConfig) WriteElement(element Element) string

Jump to

Keyboard shortcuts

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