evmmax_arith

package module
v0.0.0-...-68a0cb6 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

evmmax-arith

Library for performing modular addition, subtraction and Montgomery multiplication

Usage

Build the code generator and generate the arithmetic code:

(cd generator && go build)
make build

Run benchmarks:

go test -bench=.

Run tests:

go test -run=.

Documentation

Index

Constants

View Source
const MaxInputSize = 16

TODO increase this once we figure out what the cap will be

Variables

This section is empty.

Functions

func AddMod384_asm

func AddMod384_asm(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModGeneric

func AddModGeneric(f *Field, zBytes, xBytes, yBytes []byte) error

func AddModNonUnrolled1024

func AddModNonUnrolled1024(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled128

func AddModNonUnrolled128(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled192

func AddModNonUnrolled192(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled256

func AddModNonUnrolled256(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled320

func AddModNonUnrolled320(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled384

func AddModNonUnrolled384(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled448

func AddModNonUnrolled448(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled512

func AddModNonUnrolled512(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled576

func AddModNonUnrolled576(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled64

func AddModNonUnrolled64(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled640

func AddModNonUnrolled640(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled704

func AddModNonUnrolled704(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled768

func AddModNonUnrolled768(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled832

func AddModNonUnrolled832(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled896

func AddModNonUnrolled896(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func AddModNonUnrolled960

func AddModNonUnrolled960(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func BytesToLimbs

func BytesToLimbs(val []byte) []uint64

func BytesToNumString

func BytesToNumString(val []byte) string

func Eq

func Eq(n, other []uint64) bool

func GTE

func GTE(x, y []uint64) bool

TODO: compute y-m,x-m and compute GTE from that (like the template version)

func GenTestModulus

func GenTestModulus(limbCount uint) []byte

utility for unit testing. returns (1 << (((limbCount - 1) * limbBits) + limbBits / 2)) - 1

func IntToLimbs

func IntToLimbs(val *big.Int, num_limbs uint) []uint64

convert big.Int (big-endian) to big-endian limbs

func LEBytesToInt

func LEBytesToInt(v []byte) *big.Int

Methods for converting between Go big-int (64bit little-endian limbs, big-endian limb ordering) and the bigint representation expected here: 64bit little-endian limbs, little-endian ordered

func LimbsEq

func LimbsEq(x, y []uint64) bool

func LimbsToInt

func LimbsToInt(limbs []uint64) *big.Int

convert little-endian limbs to big.Int

func LimbsToLEBytes

func LimbsToLEBytes(val []uint64) []byte

func MaxModulus

func MaxModulus(limbCount uint) []byte

func MidModulus

func MidModulus(limbCount uint) []uint64

func MontConstant_Interleaved

func MontConstant_Interleaved(modulus []uint64) uint64

does the Python equivalent of pow(-modulus, -1, 1<<64)

func MulMont384_asm

func MulMont384_asm(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func MulMontNonInterleaved

func MulMontNonInterleaved(m *Field, zBytes, xBytes, yBytes []byte) error

func MulMontNonUnrolled1024

func MulMontNonUnrolled1024(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled128

func MulMontNonUnrolled128(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled192

func MulMontNonUnrolled192(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled256

func MulMontNonUnrolled256(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled320

func MulMontNonUnrolled320(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled384

func MulMontNonUnrolled384(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled448

func MulMontNonUnrolled448(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled512

func MulMontNonUnrolled512(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled576

func MulMontNonUnrolled576(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled64

func MulMontNonUnrolled64(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled640

func MulMontNonUnrolled640(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled704

func MulMontNonUnrolled704(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled768

func MulMontNonUnrolled768(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled832

func MulMontNonUnrolled832(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled896

func MulMontNonUnrolled896(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func MulMontNonUnrolled960

func MulMontNonUnrolled960(ctx *Field, z_bytes, x_bytes, y_bytes []byte) error

func One

func One(limbCount uint) []uint64

func PadBytes

func PadBytes(val []byte, size uint64) []byte

func PadBytes8

func PadBytes8(val []byte) []byte

pad big-endian bytes to the nearest 8-bytes

func RSquared

func RSquared(modulus []uint64) []uint64

func SmolModulus

func SmolModulus(limbCount uint) []byte

func SubMod384_asm

func SubMod384_asm(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModGeneric

func SubModGeneric(f *Field, zBytes, xBytes, yBytes []byte) error

func SubModNonUnrolled1024

func SubModNonUnrolled1024(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled128

func SubModNonUnrolled128(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled192

func SubModNonUnrolled192(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled256

func SubModNonUnrolled256(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled320

func SubModNonUnrolled320(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled384

func SubModNonUnrolled384(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled448

func SubModNonUnrolled448(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled512

func SubModNonUnrolled512(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled576

func SubModNonUnrolled576(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled64

func SubModNonUnrolled64(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled640

func SubModNonUnrolled640(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled704

func SubModNonUnrolled704(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled768

func SubModNonUnrolled768(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled832

func SubModNonUnrolled832(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled896

func SubModNonUnrolled896(f *Field, out_bytes, x_bytes, y_bytes []byte) error

func SubModNonUnrolled960

func SubModNonUnrolled960(f *Field, out_bytes, x_bytes, y_bytes []byte) error

Types

type ArithPreset

type ArithPreset struct {
	AddModImpls  []arithFunc
	SubModImpls  []arithFunc
	MulMontImpls []arithFunc
	// contains filtered or unexported fields
}

func AllPresets

func AllPresets() []ArithPreset

func Asm384Preset

func Asm384Preset() ArithPreset

Preset same as default except it uses blst's go-asm impl of the arithmetic at 384bit widths

func DefaultPreset

func DefaultPreset() ArithPreset

func GenericMulMontPreset

func GenericMulMontPreset() ArithPreset

func NonUnrolledPreset

func NonUnrolledPreset() ArithPreset

func (*ArithPreset) MaxLimbCount

func (a *ArithPreset) MaxLimbCount() uint

type Field

type Field struct {
	// TODO make most of these private and the arith operations methods of this struct
	Modulus               []byte
	ModulusNonInterleaved *big.Int // just here for convenience XXX better naming
	ModulusLimbs          []uint64

	MontParamInterleaved    uint64
	MontParamNonInterleaved *big.Int

	NumLimbs uint

	MulMont     arithFunc
	AddMod      arithFunc
	SubMod      arithFunc
	MulMontCost uint64
	AddModCost  uint64
	SubModCost  uint64
	SetModCost  uint64

	ElementSize uint64
	// contains filtered or unexported fields
}

TODO rename to Context

func NewField

func NewField(preset ArithPreset) *Field

func (*Field) ModInv

func (m *Field) ModInv() *big.Int

func (*Field) ModIsSet

func (m *Field) ModIsSet() bool

func (*Field) RInv

func (m *Field) RInv() *big.Int

func (*Field) RSquared

func (m *Field) RSquared() []byte

func (*Field) RVal

func (m *Field) RVal() *big.Int

func (*Field) SetMod

func (m *Field) SetMod(mod []byte) error

compute montgomery parameters given big-endian modulus bytes. don't pad the input bytes

func (*Field) ToMont

func (m *Field) ToMont(val []byte) ([]byte, error)

TODO this should not do allocation/copying. should be just as fast as mulmont

func (*Field) ToNorm

func (m *Field) ToNorm(val []byte) ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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