fq

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BiModulus = new(big.Int).SetBytes([]byte{
	0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	0x22, 0x46, 0x98, 0xfc, 0x09, 0x94, 0xa8, 0xdd,
	0x8c, 0x46, 0xeb, 0x21, 0x00, 0x00, 0x00, 0x01,
})

Functions

This section is empty.

Types

type Fq

type Fq fiat_pasta_fq_montgomery_domain_field_element

func (*Fq) Add

func (fq *Fq) Add(lhs, rhs *Fq) *Fq

Add returns the result from adding rhs to this element

func (*Fq) BigInt

func (fq *Fq) BigInt() *big.Int

BigInt converts this element into the big.Int struct

func (*Fq) Bytes

func (fq *Fq) Bytes() [32]byte

Bytes converts this element into a byte representation in little endian byte order

func (*Fq) CMove

func (fq *Fq) CMove(lhs, rhs *Fq, choice int) *Fq

CMove selects lhs if choice == 0 and rhs if choice == 1

func (*Fq) Cmp

func (fq *Fq) Cmp(rhs *Fq) int

Cmp returns -1 if fp < rhs 0 if fp == rhs 1 if fp > rhs

func (*Fq) Double

func (fq *Fq) Double(elem *Fq) *Fq

Double this element

func (*Fq) Equal

func (fq *Fq) Equal(rhs *Fq) bool

Equal returns true if fp == rhs

func (*Fq) Exp

func (fq *Fq) Exp(base, exp *Fq) *Fq

Exp exponentiates this element by exp

func (*Fq) Invert

func (fq *Fq) Invert(elem *Fq) (*Fq, bool)

Invert this element i.e. compute the multiplicative inverse return false, zero if this element is zero

func (*Fq) IsOne

func (fq *Fq) IsOne() bool

IsOne returns true if fp == r

func (*Fq) IsZero

func (fq *Fq) IsZero() bool

IsZero returns true if fp == 0

func (*Fq) Mul

func (fq *Fq) Mul(lhs, rhs *Fq) *Fq

Mul returns the result from multiplying this element by rhs

func (*Fq) Neg

func (fq *Fq) Neg(elem *Fq) *Fq

Neg returns negation of this element

func (*Fq) Set

func (fq *Fq) Set(rhs *Fq) *Fq

Set fp == rhs

func (*Fq) SetBigInt

func (fq *Fq) SetBigInt(bi *big.Int) *Fq

SetBigInt initializes an element from big.Int The value is reduced by the modulus

func (*Fq) SetBool

func (fq *Fq) SetBool(rhs bool) *Fq

func (*Fq) SetBytes

func (fq *Fq) SetBytes(input *[32]byte) (*Fq, error)

SetBytes attempts to convert a little endian byte representation of a scalar into a `Fq`, failing if input is not canonical

func (*Fq) SetBytesWide

func (fq *Fq) SetBytesWide(input *[64]byte) *Fq

SetBytesWide takes 64 bytes as input and treats them as a 512-bit number. Attributed to https://github.com/zcash/pasta_curves/blob/main/src/fields/fq.rs#L255 We reduce an arbitrary 512-bit number by decomposing it into two 256-bit digits with the higher bits multiplied by 2^256. Thus, we perform two reductions

1. the lower bits are multiplied by r^2, as normal 2. the upper bits are multiplied by r^2 * 2^256 = r^3

and computing their sum in the field. It remains to see that arbitrary 256-bit numbers can be placed into Montgomery form safely using the reduction. The reduction works so long as the product is less than r=2^256 multiplied by the modulus. This holds because for any `c` smaller than the modulus, we have that (2^256 - 1)*c is an acceptable product for the reduction. Therefore, the reduction always works so long as `c` is in the field; in this case it is either the constant `r2` or `r3`.

func (*Fq) SetOne

func (fq *Fq) SetOne() *Fq

SetOne fp == r

func (*Fq) SetRaw

func (fq *Fq) SetRaw(array *[4]uint64) *Fq

SetRaw converts a raw array into a field element

func (*Fq) SetUint64

func (fq *Fq) SetUint64(rhs uint64) *Fq

SetUint64 sets fp == rhs

func (*Fq) SetZero

func (fq *Fq) SetZero() *Fq

SetZero fp == 0

func (*Fq) Sqrt

func (fq *Fq) Sqrt(elem *Fq) (*Fq, bool)

Sqrt this element, if it exists. If true, then value is a square root. If false, value is a QNR

func (*Fq) Square

func (fq *Fq) Square(elem *Fq) *Fq

Square this element

func (*Fq) Sub

func (fq *Fq) Sub(lhs, rhs *Fq) *Fq

Sub returns the result from subtracting rhs from this element

func (*Fq) ToRaw

func (fq *Fq) ToRaw() [4]uint64

ToRaw converts this element into the a [4]uint64

Jump to

Keyboard shortcuts

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