bls12381

package
v0.0.0-...-c4bf151 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: BSD-3-Clause Imports: 5 Imported by: 4

Documentation

Overview

Package bls12381 provides a Go interface to the implementation of the BLS12-381 bilinear pairing. See https://z.cash/blog/new-snark-curve/ for more information about BLS12-381.

Index

Constants

This section is empty.

Variables

Sizes of group elements when marshalled

G1GeneratorAffine is a generator of group G1, in affine representation.

G1Zero is the zero (identity) element of group G1, in projective representation.

G1ZeroAffine is the zero (identity) element of group G1, in affine representation.

G2GeneratorAffine is a generator of group G2, in affine representation.

G2Zero is the zero (identity) element of group G2, in projective representation.

G2ZeroAffine is the zero (identity) element of group G2, in affine representation.

GTGenerator is the generator of group GT.

GTZero is the zero (identity) element of group GT.

GroupOrder is a 255-bit prime number that is the order of G1, G2, and GT.

Functions

func G1AffineEqual

func G1AffineEqual(a *G1Affine, b *G1Affine) bool

G1AffineEqual tests whether two elements of G1 are equal.

func G1Equal

func G1Equal(a *G1, b *G1) bool

G1Equal tests whether two elements of G1 are equal.

func G2AffineEqual

func G2AffineEqual(a *G2Affine, b *G2Affine) bool

G2AffineEqual tests whether two elements of G2 are equal.

func G2Equal

func G2Equal(a *G2, b *G2) bool

G2Equal tests whether two elements of G2 are equal.

func GTEqual

func GTEqual(a *GT, b *GT) bool

GTEqual test whether two elements of GT are equal.

Types

type G1

type G1 struct {
	Data C.embedded_pairing_bls12_381_g1_t
}

G1 is an element of G1, the smaller and faster source group of the BLS12-381 pairing, in projective representation.

func (*G1) Add

func (result *G1) Add(a *G1, b *G1) *G1

Add computes result := a + b.

func (*G1) AddMixed

func (result *G1) AddMixed(a *G1, b *G1Affine) *G1

AddMixed computes result := a + b.

func (*G1) Copy

func (result *G1) Copy(a *G1) *G1

Copy computes result := a.

func (*G1) Double

func (result *G1) Double(a *G1) *G1

Double computes result := 2 * a.

func (*G1) FromAffine

func (result *G1) FromAffine(a *G1Affine) *G1

FromAffine computes result := a.

func (*G1) Multiply

func (result *G1) Multiply(a *G1, scalar *big.Int) *G1

Multiply computes result := scalar * a.

func (*G1) MultiplyAffine

func (result *G1) MultiplyAffine(a *G1Affine, scalar *big.Int) *G1

MultiplyAffine computes result := scalar * a.

func (*G1) Negate

func (result *G1) Negate(a *G1) *G1

Negate computes result := -a.

func (*G1) Random

func (result *G1) Random() *G1

Random samples an element of G1 uniformly at random and stores it in result.

type G1Affine

type G1Affine struct {
	Data C.embedded_pairing_bls12_381_g1affine_t
}

G1Affine is an element of G1, the smaller and faster source group of the BLS12-381 pairing, in affine representation.

func (*G1Affine) Copy

func (result *G1Affine) Copy(a *G1Affine) *G1Affine

Copy computes result := a.

func (*G1Affine) FromProjective

func (result *G1Affine) FromProjective(a *G1) *G1Affine

FromProjective computes result := a.

func (*G1Affine) Hash

func (result *G1Affine) Hash(buffer []byte) *G1Affine

Hash hashes the contents of the provided buffer to an element of G1, and stores it in result.

func (*G1Affine) Marshal

func (g *G1Affine) Marshal(into []byte, compressed bool) []byte

Marshal encodes an element of G1 into the provided byte slice, in either compressed or uncompressed form depending on the argument, and then returns the byte slice.

func (*G1Affine) Negate

func (result *G1Affine) Negate(a *G1Affine) *G1Affine

Negate computes result := -a.

func (*G1Affine) Unmarshal

func (g *G1Affine) Unmarshal(marshalled []byte, compressed bool, checked bool) *G1Affine

Unmarshal recovers an element of G1 from a byte slice, which must encode either its compressed or uncompressed form, depending on the argument. If CHECKED is set to false, then unmarshalling is faster (some checks on the result are skipped), but the function will not detect if the resulting group element is invalid.

type G2

type G2 struct {
	Data C.embedded_pairing_bls12_381_g2_t
}

G2 is an element of G2, the larger and slower source group of the BLS12-381 pairing, in projective representation.

func (*G2) Add

func (result *G2) Add(a *G2, b *G2) *G2

Add computes result := a + b.

func (*G2) AddMixed

func (result *G2) AddMixed(a *G2, b *G2Affine) *G2

AddMixed computes result := a + b.

func (*G2) Copy

func (result *G2) Copy(a *G2) *G2

Copy computes result := a.

func (*G2) Double

func (result *G2) Double(a *G2) *G2

Double computes result := 2 * a.

func (*G2) FromAffine

func (result *G2) FromAffine(a *G2Affine) *G2

FromAffine computes result := a.

func (*G2) Multiply

func (result *G2) Multiply(a *G2, scalar *big.Int) *G2

Multiply computes result := scalar * a.

func (*G2) MultiplyAffine

func (result *G2) MultiplyAffine(a *G2Affine, scalar *big.Int) *G2

MultiplyAffine computes result := scalar * a.

func (*G2) Negate

func (result *G2) Negate(a *G2) *G2

Negate computes result := -a.

func (*G2) Random

func (result *G2) Random() *G2

Random samples an element of G2 uniformly at random and stores it in result.

type G2Affine

type G2Affine struct {
	Data C.embedded_pairing_bls12_381_g2affine_t
}

G2Affine is an element of G2, the larger and slower source group of the BLS12-381 pairing, in affine representation.

func (*G2Affine) Copy

func (result *G2Affine) Copy(a *G2Affine) *G2Affine

Copy computes result := a.

func (*G2Affine) FromProjective

func (result *G2Affine) FromProjective(a *G2) *G2Affine

FromProjective computes result := a.

func (*G2Affine) Hash

func (result *G2Affine) Hash(buffer []byte) *G2Affine

Hash hashes the contents of the provided buffer to an element of G2, and stores it in result.

func (*G2Affine) Marshal

func (g *G2Affine) Marshal(into []byte, compressed bool) []byte

Marshal encodes an element of G2 into the provided byte slice, in either compressed or uncompressed form depending on the argument, and then returns the byte slice.

func (*G2Affine) Negate

func (result *G2Affine) Negate(a *G2Affine) *G2Affine

Negate computes result := -a.

func (*G2Affine) Unmarshal

func (g *G2Affine) Unmarshal(marshalled []byte, compressed bool, checked bool) *G2Affine

Unmarshal recovers an element of G2 from a byte slice, which must encode either its compressed or uncompressed form, depending on the argument. If CHECKED is set to false, then unmarshalling is faster (some checks on the result are skipped), but the function will not detect if the resulting group element is invalid.

type G2Prepared

type G2Prepared struct {
	Data C.embedded_pairing_bls12_381_g2prepared_t
}

G2Prepared represents a precomputed value derived from an element of G2 that accelerates pairing computations involving that element. Note that this is large (~20 KB) compared to other structures in this library.

func (*G2Prepared) Prepare

func (result *G2Prepared) Prepare(a *G2Affine) *G2Prepared

Prepare precomputes a value that can be used to accelerate future pairing computations using a (see PreparedPairing), and store it in result.

type GT

type GT struct {
	Data C.embedded_pairing_bls12_381_fq12_t
}

GT represents an element of GT, the target group of the BLS12-381 pairing.

func (*GT) Add

func (result *GT) Add(a *GT, b *GT) *GT

Add computes result := a + b.

func (*GT) Copy

func (result *GT) Copy(a *GT) *GT

Copy computes result := a.

func (*GT) Double

func (result *GT) Double(a *GT) *GT

Double computes result := 2 * a.

func (*GT) Marshal

func (g *GT) Marshal(into []byte) []byte

Marshal encodes an element of GT into the provided byte slice, and then returns the byte slice.

func (*GT) Multiply

func (result *GT) Multiply(a *GT, scalar *big.Int) *GT

Multiply computes result := scalar * a.

func (*GT) Negate

func (result *GT) Negate(a *GT) *GT

Negate computes result := -a.

func (*GT) Pairing

func (result *GT) Pairing(a *G1Affine, b *G2Affine) *GT

Pairing computes result := e(a, b).

func (*GT) PairingSum

func (result *GT) PairingSum(a []*G1Affine, b []*G2Affine, c []*G1Affine, d []*G2Prepared) *GT

PairingSum computes the sum of e(a[i], b[i]) for i = 0 ... len(a) - 1 and e(c[j], d[j]) for j = 0 ... len(c) - 1 (so the sum of len(a) + len(c) terms total), and stores the in result. It is significantly faster than computing each term separately using Pairing() or PreparedPairing and then computing the sum using Add.

func (*GT) PreparedPairing

func (result *GT) PreparedPairing(a *G1Affine, b *G2Prepared) *GT

PreparedPairing computes result := e(a, b).

func (*GT) Random

func (result *GT) Random(a *GT) (*GT, *big.Int)

Random computes result := scalar * a, where scalar is a random element of Zp, and then returns the chosen scalar. This is significantly faster than sampling a random scalar in Zp and then calling Multiply().

func (*GT) Unmarshal

func (g *GT) Unmarshal(marshalled []byte) *GT

Unmarshal recovers an element of GT from a byte slice.

Jump to

Keyboard shortcuts

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