field

package
v0.0.0-...-3227541 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2022 License: Unlicense Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GF255e_EIGHT = GF255e{8, 0, 0, 0}

Field element of value 8.

View Source
var GF255e_HUNDREDSEVENTYSIX = GF255e{176, 0, 0, 0}

Field element of value 176.

View Source
var GF255e_INVT508 = GF255e{
	0xD40D5B5D2BE1CF5D, 0x3B3573987282DD51,
	0x3ECCB22800EED6AE, 0x44F35C558E8FAC0B}

Field element of value 1/2^508 (used internally for inversions).

View Source
var GF255e_ONE = GF255e{1, 0, 0, 0}

Field element of value 1.

View Source
var GF255e_SEVEN = GF255e{7, 0, 0, 0}

Field element of value 7.

View Source
var GF255e_THREE = GF255e{3, 0, 0, 0}

Field element of value 3.

View Source
var GF255e_THREEHUNDREDEIGHT = GF255e{308, 0, 0, 0}

Field element of value 308.

View Source
var GF255e_THREEHUNDREDFORTYTHREE = GF255e{343, 0, 0, 0}

Field element of value 343.

View Source
var GF255e_TWENTYSEVEN = GF255e{27, 0, 0, 0}

Field element of value 27.

View Source
var GF255e_ZERO = GF255e{0, 0, 0, 0}

Field element of value 0.

View Source
var GF255s_INVT508 = GF255s{
	0xC7E0DEC400D7BDB6, 0xCCABD4771F6FB10F,
	0x940F23A06B74BE6E, 0x1C45852F33548365}

Field element of value 1/2^508 (used internally for inversions).

View Source
var GF255s_ONE = GF255s{1, 0, 0, 0}

Field element of value 1.

View Source
var GF255s_TWO = GF255s{2, 0, 0, 0}

Field element of value 2.

View Source
var GF255s_ZERO = GF255s{0, 0, 0, 0}

Field element of value 0.

Functions

This section is empty.

Types

type GF255e

type GF255e [4]uint64

======================================================================= Field GF255e: integers modulo p = 2^255 - 18651

func (*GF255e) Add

func (d *GF255e) Add(a, b *GF255e) *GF255e

d <- a + b

func (*GF255e) CondNeg

func (d *GF255e) CondNeg(a *GF255e, ctl uint64) *GF255e

If ctl == 1: d <- -a If ctl == 0: d <- a ctl MUST be 0 or 1

func (*GF255e) CondOrFrom

func (d *GF255e) CondOrFrom(a *GF255e, mask uint64) *GF255e

d <- d OR (a AND mask) mask value should be 0 or 0xFFFFFFFFFFFFFFFF

func (*GF255e) Decode

func (d *GF255e) Decode(src []byte) uint64

Decode element from 32 bytes. If the source is invalid (out of range), then the decoded value is zero, and 0 is returned; otherwise, 1 is returned.

func (*GF255e) DecodeReduce

func (d *GF255e) DecodeReduce(src []byte) *GF255e

Decode element from bytes. The input bytes are interpreted as an integer (unsigned little-endian convention) which is reduced modulo the field modulus. By definition, this process cannot fail.

func (*GF255e) Encode

func (d *GF255e) Encode(dst []byte) []byte

Encode element into exactly 32 bytes. The encoding is appended to the provided slice, and the resulting slice is returned. The extension is done in place if the provided slice has enough capacity.

func (*GF255e) Eq

func (d *GF255e) Eq(a *GF255e) uint64

Returns 1 if d == a, or 0 otherwise.

func (*GF255e) Half

func (d *GF255e) Half(a *GF255e) *GF255e

d <- a/2

func (*GF255e) Inv

func (d *GF255e) Inv(a *GF255e) *GF255e

d <- 1/a (if a == 0, this sets d to 0)

func (*GF255e) IsNegative

func (d *GF255e) IsNegative() uint64

Returns 1 if d is "negative" (i.e. least significant bit of the canonical encoding is 1), 0 otherwise.

func (*GF255e) IsZero

func (d *GF255e) IsZero() uint64

Returns 1 if d == 0, or 0 otherwise.

func (*GF255e) Legendre

func (d *GF255e) Legendre() uint64

Legendre symbol computation; return value:

 0  if d == 0
 1  if d != 0 and is a quadratic residue
-1  if d != 0 and is a not a quadratic residue

Value is returned as uint64, i.e. 0xFFFFFFFFFFFFFFFF for non-squares.

func (*GF255e) Lsh

func (d *GF255e) Lsh(a *GF255e, n uint) *GF255e

d <- a*2^n n must be between 1 and 15 (inclusive)

func (*GF255e) Mul

func (d *GF255e) Mul(a, b *GF255e) *GF255e

d <- a*b

func (*GF255e) Neg

func (d *GF255e) Neg(a *GF255e) *GF255e

d <- -a

func (*GF255e) Select

func (d *GF255e) Select(a, b *GF255e, ctl uint64) *GF255e

If ctl == 1: d <- a If ctl == 0: d <- b ctl MUST be 0 or 1

func (*GF255e) Set

func (d *GF255e) Set(a *GF255e) *GF255e

d <- a

func (*GF255e) Sqr

func (d *GF255e) Sqr(a *GF255e) *GF255e

d <- a^2

func (*GF255e) SqrX

func (d *GF255e) SqrX(a *GF255e, n uint) *GF255e

d <- a^(2^n) for any n >= 0 This is constant-time with regard to a and d, but not to n.

func (*GF255e) Sqrt

func (d *GF255e) Sqrt(a *GF255e) uint64

Square root computation. If the source value (a) is a quadratic residue, then this function sets this object (d) to a square root of a, and returns 1; otherwise, it sets d to zero and returns 0. When the input is a square, this function returns the square root whose least significant bit (as an integer in the 0..p-1 range) is zero.

func (*GF255e) Sub

func (d *GF255e) Sub(a, b *GF255e) *GF255e

d <- a - b

type GF255s

type GF255s [4]uint64

======================================================================= Field GF255s: integers modulo p = 2^255 - 3957

func (*GF255s) Add

func (d *GF255s) Add(a, b *GF255s) *GF255s

d <- a + b

func (*GF255s) CondNeg

func (d *GF255s) CondNeg(a *GF255s, ctl uint64) *GF255s

If ctl == 1: d <- -a If ctl == 0: d <- a ctl MUST be 0 or 1

func (*GF255s) CondOrFrom

func (d *GF255s) CondOrFrom(a *GF255s, mask uint64) *GF255s

d <- d OR (a AND mask) mask value should be 0 or 0xFFFFFFFFFFFFFFFF

func (*GF255s) Decode

func (d *GF255s) Decode(src []byte) uint64

Decode element from 32 bytes. If the source is invalid (out of range), then the decoded value is zero, and 0 is returned; otherwise, 1 is returned.

func (*GF255s) DecodeReduce

func (d *GF255s) DecodeReduce(src []byte) *GF255s

Decode element from bytes. The input bytes are interpreted as an integer (unsigned little-endian convention) which is reduced modulo the field modulus. By definition, this process cannot fail.

func (*GF255s) Encode

func (d *GF255s) Encode(dst []byte) []byte

Encode element into exactly 32 bytes. The encoding is appended to the provided slice, and the resulting slice is returned. The extension is done in place if the provided slice has enough capacity.

func (*GF255s) Eq

func (d *GF255s) Eq(a *GF255s) uint64

Returns 1 if d == a, or 0 otherwise.

func (*GF255s) Half

func (d *GF255s) Half(a *GF255s) *GF255s

d <- a/2

func (*GF255s) Inv

func (d *GF255s) Inv(a *GF255s) *GF255s

d <- 1/a (if a == 0, this sets d to 0)

func (*GF255s) IsNegative

func (d *GF255s) IsNegative() uint64

Returns 1 if d is "negative" (i.e. least significant bit of the canonical encoding is 1), 0 otherwise.

func (*GF255s) IsZero

func (d *GF255s) IsZero() uint64

Returns 1 if d == 0, or 0 otherwise.

func (*GF255s) Legendre

func (d *GF255s) Legendre() uint64

Legendre symbol computation; return value:

 0  if d == 0
 1  if d != 0 and is a quadratic residue
-1  if d != 0 and is a not a quadratic residue

Value is returned as uint64, i.e. 0xFFFFFFFFFFFFFFFF for non-squares.

func (*GF255s) Lsh

func (d *GF255s) Lsh(a *GF255s, n uint) *GF255s

d <- a*2^n n must be between 1 and 15 (inclusive)

func (*GF255s) Mul

func (d *GF255s) Mul(a, b *GF255s) *GF255s

d <- a*b

func (*GF255s) Neg

func (d *GF255s) Neg(a *GF255s) *GF255s

d <- -a

func (*GF255s) Select

func (d *GF255s) Select(a, b *GF255s, ctl uint64) *GF255s

If ctl == 1: d <- a If ctl == 0: d <- b ctl MUST be 0 or 1

func (*GF255s) Set

func (d *GF255s) Set(a *GF255s) *GF255s

d <- a

func (*GF255s) Sqr

func (d *GF255s) Sqr(a *GF255s) *GF255s

d <- a^2

func (*GF255s) SqrX

func (d *GF255s) SqrX(a *GF255s, n uint) *GF255s

d <- a^(2^n) for any n >= 0 This is constant-time with regard to a and d, but not to n.

func (*GF255s) Sqrt

func (d *GF255s) Sqrt(a *GF255s) uint64

Square root computation. If the source value (a) is a quadratic residue, then this function sets this object (d) to a square root of a, and returns 1; otherwise, it sets d to zero and returns 0. When the input is a square, this function returns the square root whose least significant bit (as an integer in the 0..p-1 range) is zero.

func (*GF255s) Sub

func (d *GF255s) Sub(a, b *GF255s) *GF255s

d <- a - b

Jump to

Keyboard shortcuts

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