config

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2025 License: Apache-2.0 Imports: 8 Imported by: 4

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 Assembly added in v0.15.0

type Assembly struct {
	BuildDir   string
	IncludeDir string
}

type Element

type Element []big.Int

type Extension

type Extension struct {
	Base   *Field  //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 *Field, 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 FFT added in v0.15.0

type FFT struct {
	// TODO this should be in the finite field package API
	GeneratorFullMultiplicativeGroup uint64 // generator of \mathbb{F}_r^{*}

	// TODO should be generated by goff
	GeneratorMaxTwoAdicSubgroup string // generator of the maximum subgroup of size 2^<something>

	// TODO should be generated by goff
	LogTwoOrderMaxTwoAdicSubgroup string // log_2 of the max order of the max two adic subgroup

}

func NewConfig added in v0.15.0

func NewConfig(
	genFullMultiplicativeGroup uint64,
	generatorMaxTwoAdicSubgroup,
	logTwoOrderMaxTwoAdicSubgroup string) FFT

NewConfig returns a data structure with needed information to generate apis for the FFT

type Field added in v0.15.0

type Field 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
	Mu                        uint64   // mu = 2^288 / q for 4.5 word barrett reduction
	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

	Word Word // 32 iff Q < 2^32, else 64
	F31  bool // 31 bits field

	// asm code generation
	GenerateOpsAMD64       bool
	GenerateOpsARM64       bool
	GenerateVectorOpsAMD64 bool
	GenerateVectorOpsARM64 bool

	ASMPackagePath string
}

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

func NewFieldConfig

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

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

See field/generator package

func (*Field) Add added in v0.15.0

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

func (*Field) Exp added in v0.15.0

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

func (*Field) FromMont added in v0.15.0

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

func (*Field) Mul added in v0.15.0

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

func (*Field) StringToMont added in v0.15.0

func (f *Field) 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 (*Field) ToMont added in v0.15.0

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

func (*Field) ToMontSlice added in v0.15.0

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

func (*Field) WriteElement added in v0.15.0

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

type Word added in v0.15.0

type Word struct {
	BitSize   int    // 32 or 64
	ByteSize  int    // 4 or 8
	TypeLower string // uint32 or uint64
	TypeUpper string // Uint32 or Uint64
	Add       string // Add64 or Add32
	Sub       string // Sub64 or Sub32
	Len       string // Len64 or Len32
}

Jump to

Keyboard shortcuts

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