fptower

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const SizeOfGT = sizeOfFp * 24

Variables

This section is empty.

Functions

This section is empty.

Types

type E12 added in v0.6.0

type E12 struct {
	C0, C1, C2 E4
}

E12 is a degree three finite field extension of fp4

func BatchCompressTorus added in v0.8.0

func BatchCompressTorus(x []E24) ([]E12, error)

BatchCompressTorus GT/E24 elements to half their size using a batch inversion

func BatchInvertE12 added in v0.8.0

func BatchInvertE12(a []E12) []E12

BatchInvertE12 returns a new slice with every element inverted. Uses Montgomery batch inversion trick

if a[i] == 0, returns result[i] = a[i]

func (*E12) Add added in v0.6.0

func (z *E12) Add(x, y *E12) *E12

Add adds two elements of E12

func (*E12) Conjugate added in v0.6.0

func (z *E12) Conjugate(x *E12) *E12

Conjugate set z to x conjugated and return z

func (*E12) DecompressTorus added in v0.8.0

func (z *E12) DecompressTorus() E24

DecompressTorus GT/E24 a compressed element element must be in the cyclotomic subgroup "COMPRESSION IN FINITE FIELDS AND TORUS-BASED CRYPTOGRAPHY", K. RUBIN AND A. SILVERBERG

func (*E12) Double added in v0.6.0

func (z *E12) Double(x *E12) *E12

Double doubles an element in E12

func (*E12) Equal added in v0.6.0

func (z *E12) Equal(x *E12) bool

Equal returns true if z equals x, false otherwise

func (*E12) Exp added in v0.6.0

func (z *E12) Exp(x E12, k *big.Int) *E12

Exp sets z=xᵏ (mod q¹²) and returns it uses 2-bits windowed method

func (*E12) Inverse added in v0.6.0

func (z *E12) Inverse(x *E12) *E12

Inverse an element in E12

if x == 0, sets and returns z = x

func (*E12) InverseUnitary added in v0.6.0

func (z *E12) InverseUnitary(x *E12) *E12

InverseUnitary inverse a unitary element

func (*E12) IsOne added in v0.9.0

func (z *E12) IsOne() bool

IsOne returns true if z is one, false otherwise

func (*E12) IsZero added in v0.8.0

func (z *E12) IsZero() bool

IsZero returns true if z is zero, false otherwise

func (*E12) Mul added in v0.6.0

func (z *E12) Mul(x, y *E12) *E12

Mul sets z to the E12 product of x,y, returns z

func (*E12) MulBy01 added in v0.6.0

func (z *E12) MulBy01(c0, c1 *E4) *E12

MulBy01 multiplication by sparse element (c0,c1,0)

func (*E12) MulByE2 added in v0.6.0

func (z *E12) MulByE2(x *E12, y *E4) *E12

MulByE2 multiplies an element in E12 by an element in E2

func (*E12) MulByNonResidue added in v0.6.0

func (z *E12) MulByNonResidue(x *E12) *E12

MulByNonResidue mul x by (0,1,0)

func (*E12) Neg added in v0.6.0

func (z *E12) Neg(x *E12) *E12

Neg negates the E12 number

func (*E12) Set added in v0.6.0

func (z *E12) Set(x *E12) *E12

Set Sets a E12 elmt form another E12 elmt

func (*E12) SetOne added in v0.6.0

func (z *E12) SetOne() *E12

SetOne sets z to 1 in Montgomery form and returns z

func (*E12) SetRandom added in v0.6.0

func (z *E12) SetRandom() (*E12, error)

SetRandom set z to a random elmt

func (*E12) SetString added in v0.6.0

func (z *E12) SetString(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11 string) *E12

SetString sets a E12 elmt from stringf

func (*E12) Square added in v0.6.0

func (z *E12) Square(x *E12) *E12

Square sets z to the E12 product of x,x, returns z

func (*E12) String added in v0.6.0

func (z *E12) String() string

String puts E12 elmt in string form

func (*E12) Sub added in v0.6.0

func (z *E12) Sub(x, y *E12) *E12

Sub two elements of E12

type E2

type E2 struct {
	A0, A1 fp.Element
}

E2 is a degree two finite field extension of fp.Element

func (*E2) Add

func (z *E2) Add(x, y *E2) *E2

Add adds two elements of E2

func (*E2) Cmp

func (z *E2) Cmp(x *E2) int

Cmp compares (lexicographic order) z and x and returns:

-1 if z <  x
 0 if z == x
+1 if z >  x

func (*E2) Conjugate

func (z *E2) Conjugate(x *E2) *E2

Conjugate conjugates an element in E2

func (*E2) Div added in v0.8.0

func (z *E2) Div(x *E2, y *E2) *E2

func (*E2) Double

func (z *E2) Double(x *E2) *E2

Double doubles an E2 element

func (*E2) Equal

func (z *E2) Equal(x *E2) bool

Equal returns true if z equals x, false otherwise

func (*E2) Exp

func (z *E2) Exp(x E2, k *big.Int) *E2

Exp sets z=xᵏ (mod q²) and returns it

func (*E2) Inverse

func (z *E2) Inverse(x *E2) *E2

Inverse sets z to the E2-inverse of x, returns z

if x == 0, sets and returns z = x

func (*E2) IsOne added in v0.9.0

func (z *E2) IsOne() bool

IsOne returns true if z is one, false otherwise

func (*E2) IsZero

func (z *E2) IsZero() bool

IsZero returns true if z is zero, false otherwise

func (*E2) Legendre

func (z *E2) Legendre() int

Legendre returns the Legendre symbol of z

func (*E2) LexicographicallyLargest

func (z *E2) LexicographicallyLargest() bool

LexicographicallyLargest returns true if this element is strictly lexicographically larger than its negation, false otherwise

func (*E2) Mul

func (z *E2) Mul(x, y *E2) *E2

Mul sets z to the E2-product of x,y, returns z

func (*E2) MulByElement

func (z *E2) MulByElement(x *E2, y *fp.Element) *E2

MulByElement multiplies an element in E2 by an element in fp

func (*E2) MulByNonResidue

func (z *E2) MulByNonResidue(x *E2) *E2

MulByNonResidue multiplies a E2 by (0,1)

func (*E2) MulByNonResidueInv

func (z *E2) MulByNonResidueInv(x *E2) *E2

MulByNonResidueInv multiplies a E2 by (0,1)^{-1}

func (*E2) Neg

func (z *E2) Neg(x *E2) *E2

Neg negates an E2 element

func (*E2) Set

func (z *E2) Set(x *E2) *E2

Set sets an E2 from x

func (*E2) SetOne

func (z *E2) SetOne() *E2

SetOne sets z to 1 in Montgomery form and returns z

func (*E2) SetRandom

func (z *E2) SetRandom() (*E2, error)

SetRandom sets a0 and a1 to random values

func (*E2) SetString

func (z *E2) SetString(s1, s2 string) *E2

SetString sets a E2 element from strings

func (*E2) SetZero

func (z *E2) SetZero() *E2

SetZero sets an E2 elmt to zero

func (*E2) Sqrt

func (z *E2) Sqrt(x *E2) *E2

Sqrt sets z to the square root of and returns z The function does not test whether the square root exists or not, it's up to the caller to call Legendre beforehand. cf https://eprint.iacr.org/2012/685.pdf (algo 10)

func (*E2) Square

func (z *E2) Square(x *E2) *E2

Square sets z to the E2-product of x,x returns z

func (*E2) String

func (z *E2) String() string

String implements Stringer interface for fancy printing

func (*E2) Sub

func (z *E2) Sub(x, y *E2) *E2

Sub two elements of E2

type E24

type E24 struct {
	D0, D1 E12
}

E24 is a degree two finite field extension of fp6

func BatchDecompressKarabina added in v0.8.0

func BatchDecompressKarabina(x []E24) []E24

BatchDecompressKarabina multiple Karabina's cyclotomic square results if g3 != 0

g4 = (E * g5^2 + 3 * g1^2 - 2 * g2)/4g3

if g3 == 0

g4 = 2g1g5/g2

if g3=g2=0 then g4=g5=g1=0 and g0=1 (x=1) Theorem 3.1 is well-defined for all x in Gϕₙ\{1}

Divisions by 4g3 or g2 is batched using Montgomery batch inverse

func BatchDecompressTorus added in v0.8.0

func BatchDecompressTorus(x []E12) ([]E24, error)

BatchDecompressTorus GT/E24 compressed elements using a batch inversion

func BatchInvertE24 added in v0.8.0

func BatchInvertE24(a []E24) []E24

BatchInvertE24 returns a new slice with every element inverted. Uses Montgomery batch inversion trick

if a[i] == 0, returns result[i] = a[i]

func (*E24) Add

func (z *E24) Add(x, y *E24) *E24

Add set z=x+y in E24 and return z

func (*E24) Bytes

func (z *E24) Bytes() (r [SizeOfGT]byte)

func (*E24) CompressTorus added in v0.8.0

func (z *E24) CompressTorus() (E12, error)

CompressTorus GT/E24 element to half its size z must be in the cyclotomic subgroup i.e. z^(p⁴-p²+1)=1 e.g. GT "COMPRESSION IN FINITE FIELDS AND TORUS-BASED CRYPTOGRAPHY", K. RUBIN AND A. SILVERBERG z.C1 == 0 only when z ∈ {-1,1}

func (*E24) Conjugate

func (z *E24) Conjugate(x *E24) *E24

Conjugate set z to x conjugated and return z

func (*E24) CyclotomicExp added in v0.8.0

func (z *E24) CyclotomicExp(x E24, k *big.Int) *E24

CyclotomicExp sets z=xᵏ (mod q²⁴) and returns it uses 2-NAF decomposition x must be in the cyclotomic subgroup TODO: use a windowed method

func (*E24) CyclotomicSquare

func (z *E24) CyclotomicSquare(x *E24) *E24

Granger-Scott's cyclotomic square https://eprint.iacr.org/2009/565.pdf, 3.2

func (*E24) CyclotomicSquareCompressed added in v0.5.1

func (z *E24) CyclotomicSquareCompressed(x *E24) *E24

Karabina's compressed cyclotomic square https://eprint.iacr.org/2010/542.pdf Th. 3.2 with minor modifications to fit our tower

func (*E24) DecompressKarabina added in v0.8.0

func (z *E24) DecompressKarabina(x *E24) *E24

DecompressKarabina Karabina's cyclotomic square result if g3 != 0

g4 = (E * g5^2 + 3 * g1^2 - 2 * g2)/4g3

if g3 == 0

g4 = 2g1g5/g2

if g3=g2=0 then g4=g5=g1=0 and g0=1 (x=1) Theorem 3.1 is well-defined for all x in Gϕₙ\{1}

func (*E24) Double

func (z *E24) Double(x *E24) *E24

Double sets z=2*x and returns z

func (*E24) Equal

func (z *E24) Equal(x *E24) bool

Equal returns true if z equals x, false otherwise

func (*E24) Exp

func (z *E24) Exp(x E24, k *big.Int) *E24

Exp sets z=xᵏ (mod q²⁴) and returns it uses 2-bits windowed method

func (*E24) ExpGLV added in v0.8.0

func (z *E24) ExpGLV(x E24, k *big.Int) *E24

ExpGLV sets z=xᵏ (q²⁴) and returns it uses 2-dimensional GLV with 2-bits windowed method x must be in GT TODO: use 2-NAF TODO: use higher dimensional decomposition

func (*E24) Expt

func (z *E24) Expt(x *E24) *E24

Expt set z to x^t in E24 and return z (t is the seed of the curve) -2**32+2**30+2**22-2**20+1

func (*E24) Frobenius

func (z *E24) Frobenius(x *E24) *E24

Frobenius set z to Frobenius(x), return z

func (*E24) FrobeniusQuad

func (z *E24) FrobeniusQuad(x *E24) *E24

FrobeniusQuad set z to Frobenius^4(x), return z

func (*E24) FrobeniusSquare

func (z *E24) FrobeniusSquare(x *E24) *E24

FrobeniusSquare set z to Frobenius^2(x), return z

func (*E24) Inverse

func (z *E24) Inverse(x *E24) *E24

Inverse set z to the inverse of x in E24 and return z

if x == 0, sets and returns z = x

func (*E24) InverseUnitary

func (z *E24) InverseUnitary(x *E24) *E24

InverseUnitary inverse a unitary element

func (*E24) IsInSubGroup

func (z *E24) IsInSubGroup() bool

IsInSubGroup ensures GT/E24 is in correct subgroup

func (*E24) IsOne added in v0.9.0

func (z *E24) IsOne() bool

IsOne returns true if z is one, false otherwise

func (*E24) IsZero added in v0.8.0

func (z *E24) IsZero() bool

IsZero returns true if z is zero, false otherwise

func (*E24) Marshal

func (z *E24) Marshal() []byte

Marshal converts z to a byte slice

func (*E24) Mul

func (z *E24) Mul(x, y *E24) *E24

Mul set z=x*y in E24 and return z

func (*E24) MulBy01234 added in v0.10.0

func (z *E24) MulBy01234(x *[5]E4) *E24

MulBy01234 multiplies z by an E12 sparse element of the form (x0, x1, x2, x3, x4, 0)

func (*E24) MulBy034 added in v0.6.0

func (z *E24) MulBy034(c0, c3, c4 *E4) *E24

MulBy034 multiplication by sparse element (c0,0,0,c3,c4,0)

func (*E24) MulBy34 added in v0.13.0

func (z *E24) MulBy34(c3, c4 *E4) *E24

MulBy34 multiplication by sparse element (1,0,0,c3,c4,0)

func (*E24) Set

func (z *E24) Set(x *E24) *E24

Set copies x into z and returns z

func (*E24) SetBytes

func (z *E24) SetBytes(e []byte) error

SetBytes interprets e as the bytes of a big-endian GT sets z to that value (in Montgomery form), and returns z.

func (*E24) SetOne

func (z *E24) SetOne() *E24

SetOne sets z to 1 in Montgomery form and returns z

func (*E24) SetRandom

func (z *E24) SetRandom() (*E24, error)

SetRandom used only in tests

func (*E24) SetString

func (z *E24) SetString(s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14, s15, s16, s17, s18, s19, s20, s21, s22, s23 string) *E24

SetString sets a E24 from string

func (*E24) Square

func (z *E24) Square(x *E24) *E24

Square set z=x*x in E24 and return z

func (*E24) String

func (z *E24) String() string

String puts E24 in string form

func (*E24) Sub

func (z *E24) Sub(x, y *E24) *E24

Sub sets z to x sub y and return z

func (*E24) Unmarshal

func (z *E24) Unmarshal(buf []byte) error

Unmarshal is an alias to SetBytes()

type E4

type E4 struct {
	B0, B1 E2
}

E4 is a degree two finite field extension of fp2

func BatchInvertE4 added in v0.8.0

func BatchInvertE4(a []E4) []E4

BatchInvertE4 returns a new slice with every element inverted. Uses Montgomery batch inversion trick

if a[i] == 0, returns result[i] = a[i]

func Mul034By034 added in v0.10.0

func Mul034By034(d0, d3, d4, c0, c3, c4 *E4) [5]E4

Mul034By034 multiplication of sparse element (c0,0,0,c3,c4,0) by sparse element (d0,0,0,d3,d4,0)

func Mul34By34 added in v0.13.0

func Mul34By34(d3, d4, c3, c4 *E4) [5]E4

Mul34By34 multiplication of sparse element (1,0,0,c3,c4,0) by sparse element (1,0,0,d3,d4,0)

func (*E4) Add

func (z *E4) Add(x, y *E4) *E4

Add set z=x+y in E4 and return z

func (*E4) Cmp

func (z *E4) Cmp(x *E4) int

Cmp compares (lexicographic order) z and x and returns:

-1 if z <  x
 0 if z == x
+1 if z >  x

func (*E4) Conjugate

func (z *E4) Conjugate(x *E4) *E4

Conjugate set z to x conjugated and return z

func (*E4) Div added in v0.8.0

func (z *E4) Div(x *E4, y *E4) *E4

func (*E4) Double

func (z *E4) Double(x *E4) *E4

Double sets z=2*x and returns z

func (*E4) Equal

func (z *E4) Equal(x *E4) bool

Equal returns true if z equals x, false otherwise

func (*E4) Exp

func (z *E4) Exp(x E4, k *big.Int) *E4

Exp sets z=xᵏ (mod q⁴) and returns it

func (*E4) Frobenius

func (z *E4) Frobenius(x *E4) *E4

Frobenius sets z in E4 to x^q, returns z

func (*E4) Halve added in v0.5.2

func (z *E4) Halve()

func (*E4) Inverse

func (z *E4) Inverse(x *E4) *E4

Inverse set z to the inverse of x in E4 and return z

if x == 0, sets and returns z = x

func (*E4) IsOne added in v0.9.0

func (z *E4) IsOne() bool

IsOne returns true if z is one, false otherwise

func (*E4) IsZero

func (z *E4) IsZero() bool

IsZero returns true if z is zero, false otherwise

func (*E4) Legendre

func (z *E4) Legendre() int

Legendre returns the Legendre symbol of z

func (*E4) LexicographicallyLargest

func (z *E4) LexicographicallyLargest() bool

LexicographicallyLargest returns true if this element is strictly lexicographically larger than its negation, false otherwise

func (*E4) Mul

func (z *E4) Mul(x, y *E4) *E4

Mul set z=x*y in E4 and return z

func (*E4) MulByElement

func (z *E4) MulByElement(x *E4, y *fp.Element) *E4

MulByElement multiplies an element in E4 by an element in fp

func (*E4) MulByNonResidue

func (z *E4) MulByNonResidue(x *E4) *E4

MulByNonResidue mul x by (0,1)

func (*E4) MulByNonResidueInv

func (z *E4) MulByNonResidueInv(x *E4) *E4

MulByNonResidueInv mul x by (0,1)^{-1}

func (*E4) MulBybTwistCurveCoeff added in v0.6.0

func (z *E4) MulBybTwistCurveCoeff(x *E4) *E4

MulBybTwistCurveCoeff multiplies by 1/(0,1)

func (*E4) Neg

func (z *E4) Neg(x *E4) *E4

Neg negates an E4 element

func (*E4) Set

func (z *E4) Set(x *E4) *E4

Set copies x into z and returns z

func (*E4) SetOne

func (z *E4) SetOne() *E4

SetOne sets z to 1 in Montgomery form and returns z

func (*E4) SetRandom

func (z *E4) SetRandom() (*E4, error)

SetRandom used only in tests

func (*E4) SetString

func (z *E4) SetString(s0, s1, s2, s3 string) *E4

SetString sets a E4 from string

func (*E4) SetZero

func (z *E4) SetZero() *E4

SetZero sets an E4 elmt to zero

func (*E4) Sqrt

func (z *E4) Sqrt(x *E4) *E4

Sqrt sets z to the square root of and returns z The function does not test whether the square root exists or not, it's up to the caller to call Legendre beforehand. cf https://eprint.iacr.org/2012/685.pdf (algo 10)

func (*E4) Square

func (z *E4) Square(x *E4) *E4

Square set z=x*x in E4 and return z

func (*E4) String

func (z *E4) String() string

String puts E4 in string form

func (*E4) Sub

func (z *E4) Sub(x, y *E4) *E4

Sub sets z to x sub y and return z

Jump to

Keyboard shortcuts

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