radix51

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2019 License: BSD-3-Clause Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

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

Neg sets v = -a and returns v.

func (*FieldElement) One

func (v *FieldElement) One() *FieldElement

One sets v = 1 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

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) ToBig

func (v *FieldElement) ToBig() *big.Int

ToBig returns v as a big.Int.

func (*FieldElement) Zero

func (v *FieldElement) Zero() *FieldElement

Zero sets v = 0 and returns v.

Jump to

Keyboard shortcuts

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