bls12381

package
v0.10.3 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Limbs                = 6
	FieldBytes           = 48
	WideFieldBytes       = 96
	DoubleWideFieldBytes = 192
)
View Source
const GtFieldBytes = 576

GtFieldBytes is the number of bytes needed to represent this field

Variables

This section is empty.

Functions

func Bls12381FqNew

func Bls12381FqNew() *native.Field

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

func (*Engine) AddPair

func (e *Engine) AddPair(g1 *G1, g2 *G2) *Engine

AddPair adds a pair of points to be paired

func (*Engine) AddPairInvG1

func (e *Engine) AddPairInvG1(g1 *G1, g2 *G2) *Engine

AddPairInvG1 adds a pair of points to be paired. G1 point is negated

func (*Engine) AddPairInvG2

func (e *Engine) AddPairInvG2(g1 *G1, g2 *G2) *Engine

AddPairInvG2 adds a pair of points to be paired. G2 point is negated

func (*Engine) Check

func (e *Engine) Check() bool

func (*Engine) Reset

func (e *Engine) Reset() *Engine

func (*Engine) Result

func (e *Engine) Result() *Gt

type Fq

type G1

type G1 struct {
	// contains filtered or unexported fields
}

G1 is a point in g1

func (*G1) Add

func (g1 *G1) Add(arg1, arg2 *G1) *G1

Add adds this point to another point.

func (*G1) BigInt

func (g1 *G1) BigInt() (x, y *big.Int)

BigInt returns the x and y as big.Ints in affine

func (*G1) CMove

func (g1 *G1) CMove(arg1, arg2 *G1, choice int) *G1

CMove sets g1 = arg1 if choice == 0 and g1 = arg2 if choice == 1

func (*G1) ClearCofactor

func (g1 *G1) ClearCofactor(a *G1) *G1

ClearCofactor multiplies by (1 - z), where z is the parameter of BLS12-381, which [suffices to clear](https://ia.cr/2019/403) the cofactor and map elliptic curve points to elements of G1.

func (*G1) Double

func (g1 *G1) Double(a *G1) *G1

Double this point

func (*G1) Equal

func (g1 *G1) Equal(rhs *G1) int

Equal returns 1 if the two points are equal 0 otherwise.

func (*G1) FromCompressed

func (g1 *G1) FromCompressed(input *[FieldBytes]byte) (*G1, error)

FromCompressed deserializes this element from compressed form.

func (*G1) FromUncompressed

func (g1 *G1) FromUncompressed(input *[WideFieldBytes]byte) (*G1, error)

FromUncompressed deserializes this element from uncompressed form.

func (*G1) Generator

func (g1 *G1) Generator() *G1

Generator returns the base point

func (*G1) GetX

func (g1 *G1) GetX() *fp

GetX returns the affine X coordinate

func (*G1) GetY

func (g1 *G1) GetY() *fp

GetY returns the affine Y coordinate

func (*G1) Hash

func (g1 *G1) Hash(hash *native.EllipticPointHasher, msg, dst []byte) *G1

Hash uses the hasher to map bytes to a valid point

func (*G1) Identity

func (g1 *G1) Identity() *G1

Identity returns the identity point

func (*G1) InCorrectSubgroup

func (g1 *G1) InCorrectSubgroup() int

InCorrectSubgroup returns 1 if the point is torsion free, 0 otherwise

func (*G1) IsIdentity

func (g1 *G1) IsIdentity() int

IsIdentity returns true if this point is at infinity

func (*G1) IsOnCurve

func (g1 *G1) IsOnCurve() int

IsOnCurve determines if this point represents a valid curve point

func (*G1) Mul

func (g1 *G1) Mul(a *G1, s *native.Field) *G1

Mul multiplies this point by the input scalar

func (*G1) MulByX

func (g1 *G1) MulByX(a *G1) *G1

MulByX multiplies by BLS X using double and add

func (*G1) Neg

func (g1 *G1) Neg(a *G1) *G1

Neg negates this point

func (*G1) Random

func (g1 *G1) Random(reader io.Reader) (*G1, error)

Random creates a random point on the curve from the specified reader

func (*G1) Set

func (g1 *G1) Set(a *G1) *G1

Set copies a into g1

func (*G1) SetBigInt

func (g1 *G1) SetBigInt(x, y *big.Int) (*G1, error)

SetBigInt creates a point from affine x, y and returns the point if it is on the curve

func (*G1) Sub

func (g1 *G1) Sub(arg1, arg2 *G1) *G1

Sub subtracts the two points

func (*G1) SumOfProducts

func (g1 *G1) SumOfProducts(points []*G1, scalars []*native.Field) (*G1, error)

SumOfProducts computes the multi-exponentiation for the specified points and scalars and stores the result in `g1`. Returns an error if the lengths of the arguments is not equal.

func (*G1) ToAffine

func (g1 *G1) ToAffine(a *G1) *G1

ToAffine converts the point into affine coordinates

func (*G1) ToCompressed

func (g1 *G1) ToCompressed() [FieldBytes]byte

ToCompressed serializes this element into compressed form.

func (*G1) ToUncompressed

func (g1 *G1) ToUncompressed() [WideFieldBytes]byte

ToUncompressed serializes this element into uncompressed form.

type G2

type G2 struct {
	// contains filtered or unexported fields
}

G2 is a point in g2

func (*G2) Add

func (g2 *G2) Add(arg1, arg2 *G2) *G2

Add adds this point to another point.

func (*G2) BigInt

func (g2 *G2) BigInt() (x, y *big.Int)

BigInt returns the x and y as big.Ints in affine

func (*G2) CMove

func (g2 *G2) CMove(arg1, arg2 *G2, choice int) *G2

CMove sets g2 = arg1 if choice == 0 and g2 = arg2 if choice == 1

func (*G2) ClearCofactor

func (g2 *G2) ClearCofactor(a *G2) *G2

ClearCofactor using [Budroni-Pintore](https://ia.cr/2017/419). This is equivalent to multiplying by h_{eff} = 3(z^2 - 1) * h_2 where h_2 is the cofactor of G_2 and z is the parameter of BLS12-381.

func (*G2) Double

func (g2 *G2) Double(a *G2) *G2

Double this point

func (*G2) Equal

func (g2 *G2) Equal(rhs *G2) int

Equal returns 1 if the two points are equal 0 otherwise.

func (*G2) FromCompressed

func (g2 *G2) FromCompressed(input *[WideFieldBytes]byte) (*G2, error)

FromCompressed deserializes this element from compressed form.

func (*G2) FromUncompressed

func (g2 *G2) FromUncompressed(input *[DoubleWideFieldBytes]byte) (*G2, error)

FromUncompressed deserializes this element from uncompressed form.

func (*G2) Generator

func (g2 *G2) Generator() *G2

Generator returns the base point

func (*G2) GetX

func (g2 *G2) GetX() *fp2

GetX returns the affine X coordinate

func (*G2) GetY

func (g2 *G2) GetY() *fp2

GetY returns the affine Y coordinate

func (*G2) Hash

func (g2 *G2) Hash(hash *native.EllipticPointHasher, msg, dst []byte) *G2

Hash uses the hasher to map bytes to a valid point

func (*G2) Identity

func (g2 *G2) Identity() *G2

Identity returns the identity point

func (*G2) InCorrectSubgroup

func (g2 *G2) InCorrectSubgroup() int

InCorrectSubgroup returns 1 if the point is torsion free, 0 otherwise

func (*G2) IsIdentity

func (g2 *G2) IsIdentity() int

IsIdentity returns true if this point is at infinity

func (*G2) IsOnCurve

func (g2 *G2) IsOnCurve() int

IsOnCurve determines if this point represents a valid curve point

func (*G2) Mul

func (g2 *G2) Mul(a *G2, s *native.Field) *G2

Mul multiplies this point by the input scalar

func (*G2) MulByX

func (g2 *G2) MulByX(a *G2) *G2

MulByX multiplies by BLS X using double and add

func (*G2) Neg

func (g2 *G2) Neg(a *G2) *G2

Neg negates this point

func (*G2) Random

func (g2 *G2) Random(reader io.Reader) (*G2, error)

Random creates a random point on the curve from the specified reader

func (*G2) Set

func (g2 *G2) Set(a *G2) *G2

Set copies a into g2

func (*G2) SetBigInt

func (g2 *G2) SetBigInt(x, y *big.Int) (*G2, error)

SetBigInt creates a point from affine x, y and returns the point if it is on the curve

func (*G2) Sub

func (g2 *G2) Sub(arg1, arg2 *G2) *G2

Sub subtracts the two points

func (*G2) SumOfProducts

func (g2 *G2) SumOfProducts(points []*G2, scalars []*native.Field) (*G2, error)

SumOfProducts computes the multi-exponentiation for the specified points and scalars and stores the result in `g2`. Returns an error if the lengths of the arguments is not equal.

func (*G2) ToAffine

func (g2 *G2) ToAffine(a *G2) *G2

ToAffine converts the point into affine coordinates

func (*G2) ToCompressed

func (g2 *G2) ToCompressed() [WideFieldBytes]byte

ToCompressed serializes this element into compressed form.

func (*G2) ToUncompressed

func (g2 *G2) ToUncompressed() [DoubleWideFieldBytes]byte

ToUncompressed serializes this element into uncompressed form.

type Gt

type Gt fp12

Gt is the target group

func (*Gt) Add

func (gt *Gt) Add(arg1, arg2 *Gt) *Gt

Add adds this value to another value.

func (*Gt) Bytes

func (gt *Gt) Bytes() [GtFieldBytes]byte

Bytes returns the Gt field byte representation

func (*Gt) Double

func (gt *Gt) Double(a *Gt) *Gt

Double this value

func (*Gt) Equal

func (gt *Gt) Equal(rhs *Gt) int

Equal returns 1 if gt == rhs, 0 otherwise

func (*Gt) FinalExponentiation

func (gt *Gt) FinalExponentiation(a *Gt) *Gt

FinalExponentiation performs a "final exponentiation" routine to convert the result of a Miller loop into an element of `Gt` with help of efficient squaring operation in the so-called `cyclotomic subgroup` of `Fq6` so that it can be compared with other elements of `Gt`.

func (*Gt) Generator

func (gt *Gt) Generator() *Gt

Generator returns the base point

func (*Gt) Invert

func (gt *Gt) Invert(a *Gt) (*Gt, int)

Invert this value

func (*Gt) IsOne

func (gt *Gt) IsOne() int

IsOne returns 1 if gt == 1, 0 otherwise

func (*Gt) IsZero

func (gt *Gt) IsZero() int

IsZero returns 1 if gt == 0, 0 otherwise

func (*Gt) Mul

func (gt *Gt) Mul(a *Gt, s *native.Field) *Gt

Mul multiplies this value by the input scalar

func (*Gt) Neg

func (gt *Gt) Neg(a *Gt) *Gt

Neg negates this value

func (*Gt) Random

func (gt *Gt) Random(reader io.Reader) (*Gt, error)

Random generates a random field element

func (*Gt) Set

func (gt *Gt) Set(a *Gt) *Gt

Set copies a into gt

func (*Gt) SetBytes

func (gt *Gt) SetBytes(input *[GtFieldBytes]byte) (*Gt, int)

SetBytes attempts to convert a big-endian byte representation of a scalar into a `Gt`, failing if the input is not canonical.

func (*Gt) SetOne

func (gt *Gt) SetOne() *Gt

SetOne gt = one

func (*Gt) Square

func (gt *Gt) Square(a *Gt) *Gt

Square this value

func (*Gt) Sub

func (gt *Gt) Sub(arg1, arg2 *Gt) *Gt

Sub subtracts the two values

Jump to

Keyboard shortcuts

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