fptower

package
v0.0.0-...-783462d Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const SizeOfGT = 48 * 12

SizeOfGT represents the size in bytes that a GT element need in binary form

Variables

This section is empty.

Functions

This section is empty.

Types

type E12

type E12 struct {
	C0, C1 E6
}

E12 is a degree two finite field extension of fp6

func BatchDecompressKarabina

func BatchDecompressKarabina(x []E12) []E12

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

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

BatchDecompressTorus GT/E12 compressed elements using a batch inversion

func BatchInvertE12

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

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

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

func (*E12) Bytes

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

Bytes returns the regular (non montgomery) value of z as a big-endian byte array. z.C1.B2.A1 | z.C1.B2.A0 | z.C1.B1.A1 | ...

func (*E12) CompressTorus

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

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

func (*E12) Conjugate

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

Conjugate set z to x conjugated and return z

func (*E12) CyclotomicExp

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

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 (*E12) CyclotomicSquare

func (z *E12) CyclotomicSquare(x *E12) *E12

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

func (*E12) CyclotomicSquareCompressed

func (z *E12) CyclotomicSquareCompressed(x *E12) *E12

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

func (*E12) DecompressKarabina

func (z *E12) DecompressKarabina(x *E12) *E12

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 (*E12) Div

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

func (*E12) Double

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

Double sets z=2*x and returns z

func (*E12) Equal

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

Equal returns true if z equals x, fasle otherwise

func (*E12) Exp

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

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

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 (*E12) Expt

func (z *E12) Expt(x *E12) *E12

Expt set z to xᵗ in E12 and return z const t uint64 = 15132376222941642752 // negative

func (*E12) ExptHalf

func (z *E12) ExptHalf(x *E12) *E12

ExptHalf set z to x^(t/2) in E12 and return z const t/2 uint64 = 7566188111470821376 // negative

func (*E12) Frobenius

func (z *E12) Frobenius(x *E12) *E12

Frobenius set z to Frobenius(x), return z

func (*E12) FrobeniusSquare

func (z *E12) FrobeniusSquare(x *E12) *E12

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

func (*E12) FromMont

func (z *E12) FromMont() *E12

FromMont converts from Mont form

func (*E12) Inverse

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

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

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

func (*E12) InverseUnitary

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

InverseUnitary inverse a unitary element

func (*E12) IsInSubGroup

func (z *E12) IsInSubGroup() bool

IsInSubGroup ensures GT/E12 is in correct sugroup

func (*E12) IsZero

func (z *E12) IsZero() bool

IsZero returns true if the two elements are equal, fasle otherwise

func (*E12) Marshal

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

Marshal converts z to a byte slice

func (*E12) Mul

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

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

func (*E12) Mul014By014

func (z *E12) Mul014By014(d0, d1, d4, c0, c1, c4 *E2) *E12

Mul014By014 multiplication of sparse element (c0,c1,0,0,c4,0) by sparse element (d0,d1,0,0,d4,0)

func (*E12) MulBy014

func (z *E12) MulBy014(c0, c1, c4 *E2) *E12

MulBy014 multiplication by sparse element (c0, c1, 0, 0, c4)

func (*E12) Select

func (z *E12) Select(cond int, caseZ *E12, caseNz *E12) *E12

func (*E12) Set

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

Set copies x into z and returns z

func (*E12) SetBytes

func (z *E12) 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. size(e) == 48 * 12 z.C1.B2.A1 | z.C1.B2.A0 | z.C1.B1.A1 | ...

func (*E12) SetOne

func (z *E12) SetOne() *E12

SetOne sets z to 1 in Montgomery form and returns z

func (*E12) SetRandom

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

SetRandom used only in tests

func (*E12) SetString

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

SetString sets a E12 from string

func (*E12) Square

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

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

func (*E12) String

func (z *E12) String() string

String puts E12 in string form

func (*E12) Sub

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

Sub sets z to x sub y and return z

func (*E12) ToMont

func (z *E12) ToMont() *E12

ToMont converts to Mont form

func (*E12) Unmarshal

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

Unmarshal is an allias to SetBytes()

type E2

type E2 struct {
	A0, A1 fp.Element
}

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

func BatchInvertE2

func BatchInvertE2(a []E2) []E2

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

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

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

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

func (z *E2) FromMont() *E2

FromMont converts from mont form

func (*E2) Halve

func (z *E2) Halve()

Halve sets z = z / 2

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

func (z *E2) IsZero() bool

IsZero returns true if the two elements are equal, 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 (1,1)

func (*E2) MulByNonResidue1Power1

func (z *E2) MulByNonResidue1Power1(x *E2) *E2

MulByNonResidue1Power1 set z=x*(1,1)^(1*(p^1-1)/6) and return z

func (*E2) MulByNonResidue1Power2

func (z *E2) MulByNonResidue1Power2(x *E2) *E2

MulByNonResidue1Power2 set z=x*(1,1)^(2*(p^1-1)/6) and return z

func (*E2) MulByNonResidue1Power3

func (z *E2) MulByNonResidue1Power3(x *E2) *E2

MulByNonResidue1Power3 set z=x*(1,1)^(3*(p^1-1)/6) and return z

func (*E2) MulByNonResidue1Power4

func (z *E2) MulByNonResidue1Power4(x *E2) *E2

MulByNonResidue1Power4 set z=x*(1,1)^(4*(p^1-1)/6) and return z

func (*E2) MulByNonResidue1Power5

func (z *E2) MulByNonResidue1Power5(x *E2) *E2

MulByNonResidue1Power5 set z=x*(1,1)^(5*(p^1-1)/6) and return z

func (*E2) MulByNonResidue2Power1

func (z *E2) MulByNonResidue2Power1(x *E2) *E2

MulByNonResidue2Power1 set z=x*(1,1)^(1*(p^2-1)/6) and return z

func (*E2) MulByNonResidue2Power2

func (z *E2) MulByNonResidue2Power2(x *E2) *E2

MulByNonResidue2Power2 set z=x*(1,1)^(2*(p^2-1)/6) and return z

func (*E2) MulByNonResidue2Power3

func (z *E2) MulByNonResidue2Power3(x *E2) *E2

MulByNonResidue2Power3 set z=x*(1,1)^(3*(p^2-1)/6) and return z

func (*E2) MulByNonResidue2Power4

func (z *E2) MulByNonResidue2Power4(x *E2) *E2

MulByNonResidue2Power4 set z=x*(1,1)^(4*(p^2-1)/6) and return z

func (*E2) MulByNonResidue2Power5

func (z *E2) MulByNonResidue2Power5(x *E2) *E2

MulByNonResidue2Power5 set z=x*(1,1)^(5*(p^2-1)/6) and return z

func (*E2) MulByNonResidueInv

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

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

func (*E2) MulBybTwistCurveCoeff

func (z *E2) MulBybTwistCurveCoeff(x *E2) *E2

MulBybTwistCurveCoeff multiplies by 4(1,1)

func (*E2) Neg

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

Neg negates an E2 element

func (*E2) Select

func (z *E2) Select(cond int, caseZ *E2, caseNz *E2) *E2

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 wether 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 9)

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

func (*E2) ToMont

func (z *E2) ToMont() *E2

ToMont converts to mont form

type E6

type E6 struct {
	B0, B1, B2 E2
}

E6 is a degree three finite field extension of fp2

func BatchCompressTorus

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

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

if len(x) == 0 or if any of the x[i].C1 coordinate is 0, this function returns an error.

func BatchInvertE6

func BatchInvertE6(a []E6) []E6

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

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

func (*E6) Add

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

Add adds two elements of E6

func (*E6) DecompressTorus

func (z *E6) DecompressTorus() E12

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

func (*E6) Div

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

func (*E6) Double

func (z *E6) Double(x *E6) *E6

Double doubles an element in E6

func (*E6) Equal

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

Equal returns true if z equals x, fasle otherwise

func (*E6) FromMont

func (z *E6) FromMont() *E6

FromMont converts from Mont form

func (*E6) Inverse

func (z *E6) Inverse(x *E6) *E6

Inverse an element in E6

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

func (*E6) IsZero

func (z *E6) IsZero() bool

IsZero returns true if the two elements are equal, fasle otherwise

func (*E6) Mul

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

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

func (*E6) MulBy01

func (z *E6) MulBy01(c0, c1 *E2) *E6

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

func (*E6) MulBy1

func (z *E6) MulBy1(c1 *E2) *E6

MulBy1 multiplication of E6 by sparse element (0, c1, 0)

func (*E6) MulByE2

func (z *E6) MulByE2(x *E6, y *E2) *E6

MulByE2 multiplies an element in E6 by an element in E2

func (*E6) MulByNonResidue

func (z *E6) MulByNonResidue(x *E6) *E6

MulByNonResidue mul x by (0,1,0)

func (*E6) Neg

func (z *E6) Neg(x *E6) *E6

Neg negates the E6 number

func (*E6) Select

func (z *E6) Select(cond int, caseZ *E6, caseNz *E6) *E6

func (*E6) Set

func (z *E6) Set(x *E6) *E6

Set Sets a E6 elmt form another E6 elmt

func (*E6) SetOne

func (z *E6) SetOne() *E6

SetOne sets z to 1 in Montgomery form and returns z

func (*E6) SetRandom

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

SetRandom set z to a random elmt

func (*E6) SetString

func (z *E6) SetString(s1, s2, s3, s4, s5, s6 string) *E6

SetString sets a E6 elmt from stringf

func (*E6) Square

func (z *E6) Square(x *E6) *E6

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

func (*E6) String

func (z *E6) String() string

String puts E6 elmt in string form

func (*E6) Sub

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

Sub two elements of E6

func (*E6) ToMont

func (z *E6) ToMont() *E6

ToMont converts to Mont form

Jump to

Keyboard shortcuts

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