Documentation ¶
Overview ¶
GF(2^255-19) field arithmetic in radix 2^51 representation. This code is a port of the public domain amd64-51-30k version of ed25519 from SUPERCOP.
The interface works similarly to math/big.Int, and all arguments and receivers are allowed to alias.
Index ¶
- Variables
- func CondSwap(a, b *FieldElement, cond int)
- type FieldElement
- func (v *FieldElement) Abs(u *FieldElement) *FieldElement
- func (v *FieldElement) Add(a, b *FieldElement) *FieldElement
- func (v *FieldElement) Bytes(b []byte) []byte
- func (v *FieldElement) CondNeg(u *FieldElement, cond int) *FieldElement
- func (v *FieldElement) Equal(u *FieldElement) int
- func (v *FieldElement) FromBig(n *big.Int) *FieldElement
- func (v *FieldElement) FromBytes(x []byte) *FieldElement
- func (v *FieldElement) Invert(z *FieldElement) *FieldElement
- func (v *FieldElement) IsNegative() int
- func (v *FieldElement) Mul(x, y *FieldElement) *FieldElement
- func (v *FieldElement) Neg(a *FieldElement) *FieldElement
- func (v *FieldElement) One() *FieldElement
- func (v *FieldElement) Select(a, b *FieldElement, cond int) *FieldElement
- func (v *FieldElement) Set(a *FieldElement) *FieldElement
- func (v *FieldElement) Square(x *FieldElement) *FieldElement
- func (v *FieldElement) Sub(a, b *FieldElement) *FieldElement
- func (v *FieldElement) ToBig() *big.Int
- func (v *FieldElement) Zero() *FieldElement
Constants ¶
This section is empty.
Variables ¶
var ( Zero = &FieldElement{0, 0, 0, 0, 0} One = &FieldElement{1, 0, 0, 0, 0} Two = &FieldElement{2, 0, 0, 0, 0} MinusOne = new(FieldElement).Neg(One) )
Functions ¶
func CondSwap ¶
func CondSwap(a, b *FieldElement, cond int)
CondSwap swaps a and b if cond == 1 or leaves them unchanged if cond == 0.
Types ¶
type FieldElement ¶
type FieldElement [5]uint64
FieldElement represents an element of the field GF(2^255-19). An element t represents the integer t[0] + t[1]*2^51 + t[2]*2^102 + t[3]*2^153 + t[4]*2^204.
Between operations, all limbs are expected to be lower than 2^51, except the first one, which can be up to 2^255 + 2^13 * 19 due to carry propagation.
The zero value is a valid zero element.
func (*FieldElement) Abs ¶
func (v *FieldElement) Abs(u *FieldElement) *FieldElement
Abs sets v to |u| and returns v.
func (*FieldElement) Add ¶
func (v *FieldElement) Add(a, b *FieldElement) *FieldElement
Add sets v = a + b and returns v.
func (*FieldElement) Bytes ¶
func (v *FieldElement) Bytes(b []byte) []byte
Bytes appends a 32 bytes little-endian encoding of v to b.
func (*FieldElement) CondNeg ¶
func (v *FieldElement) CondNeg(u *FieldElement, cond int) *FieldElement
CondNeg sets v to -u if cond == 1, and to u if cond == 0.
func (*FieldElement) Equal ¶
func (v *FieldElement) Equal(u *FieldElement) int
Equal returns 1 if v and u are equal, and 0 otherwise.
func (*FieldElement) FromBig ¶
func (v *FieldElement) FromBig(n *big.Int) *FieldElement
FromBig sets v = n and returns v. The bit length of n must not exceed 256.
func (*FieldElement) FromBytes ¶
func (v *FieldElement) FromBytes(x []byte) *FieldElement
FromBytes sets v to x, which must be a 32 bytes little-endian encoding.
Consistently with RFC 7748, the most significant bit (the high bit of the last byte) is ignored, and non-canonical values (2^255-19 through 2^255-1) are accepted.
func (*FieldElement) Invert ¶
func (v *FieldElement) Invert(z *FieldElement) *FieldElement
Invert sets v = 1/z mod p and returns v.
func (*FieldElement) IsNegative ¶
func (v *FieldElement) IsNegative() int
IsNegative returns 1 if v is negative, and 0 otherwise.
func (*FieldElement) Mul ¶
func (v *FieldElement) Mul(x, y *FieldElement) *FieldElement
Mul sets v = x * y and returns v.
func (*FieldElement) Neg ¶
func (v *FieldElement) Neg(a *FieldElement) *FieldElement
Neg sets v = -a and returns v.
func (*FieldElement) Select ¶
func (v *FieldElement) Select(a, b *FieldElement, cond int) *FieldElement
Select sets v to a if cond == 1, and to b if cond == 0.
func (*FieldElement) Set ¶
func (v *FieldElement) Set(a *FieldElement) *FieldElement
Set sets v = a and returns v.
func (*FieldElement) Square ¶
func (v *FieldElement) Square(x *FieldElement) *FieldElement
Square sets v = x * x and returns v.
func (*FieldElement) Sub ¶
func (v *FieldElement) Sub(a, b *FieldElement) *FieldElement
Sub sets v = a - b and returns v.
func (*FieldElement) Zero ¶
func (v *FieldElement) Zero() *FieldElement
Zero sets v = 0 and returns v.