package bn256
import "github.com/ethereum/go-ethereum/crypto/bn256/cloudflare"
Package bn256 implements a particular bilinear group at the 128-bit security level.
Bilinear groups are the basis of many of the new cryptographic protocols that have been proposed over the past decade. They consist of a triplet of groups (G₁, G₂ and GT) such that there exists a function e(g₁ˣ,g₂ʸ)=gTˣʸ (where gₓ is a generator of the respective group). That function is called a pairing function.
This package specifically implements the Optimal Ate pairing over a 256-bit Barreto-Naehrig curve as described in http://cryptojedi.org/papers/dclxvi-20100714.pdf. Its output is not compatible with the implementation described in that paper, as different parameters are chosen.
(This package previously claimed to operate at a 128-bit security level. However, recent improvements in attacks mean that is no longer true. See https://moderncrypto.org/mail-archive/curves/2016/000740.html.)
Index ¶
- Variables
- func PairingCheck(a []*G1, b []*G2) bool
- type G1
- func RandomG1(r io.Reader) (*big.Int, *G1, error)
- func (e *G1) Add(a, b *G1) *G1
- func (e *G1) Marshal() []byte
- func (e *G1) Neg(a *G1) *G1
- func (e *G1) ScalarBaseMult(k *big.Int) *G1
- func (e *G1) ScalarMult(a *G1, k *big.Int) *G1
- func (e *G1) Set(a *G1) *G1
- func (g *G1) String() string
- func (e *G1) Unmarshal(m []byte) ([]byte, error)
- type G2
- func RandomG2(r io.Reader) (*big.Int, *G2, error)
- func (e *G2) Add(a, b *G2) *G2
- func (e *G2) Marshal() []byte
- func (e *G2) Neg(a *G2) *G2
- func (e *G2) ScalarBaseMult(k *big.Int) *G2
- func (e *G2) ScalarMult(a *G2, k *big.Int) *G2
- func (e *G2) Set(a *G2) *G2
- func (e *G2) String() string
- func (e *G2) Unmarshal(m []byte) ([]byte, error)
- type GT
- func Miller(g1 *G1, g2 *G2) *GT
- func Pair(g1 *G1, g2 *G2) *GT
- func (e *GT) Add(a, b *GT) *GT
- func (e *GT) Finalize() *GT
- func (e *GT) Marshal() []byte
- func (e *GT) Neg(a *GT) *GT
- func (e *GT) ScalarMult(a *GT, k *big.Int) *GT
- func (e *GT) Set(a *GT) *GT
- func (g *GT) String() string
- func (e *GT) Unmarshal(m []byte) ([]byte, error)
Variables ¶
var Order = bigFromBase10("21888242871839275222246405745257275088548364400416034343698204186575808495617")
Order is the number of elements in both G₁ and G₂: 36u⁴+36u³+18u²+6u+1. Needs to be highly 2-adic for efficient SNARK key and proof generation. Order - 1 = 2^28 * 3^2 * 13 * 29 * 983 * 11003 * 237073 * 405928799 * 1670836401704629 * 13818364434197438864469338081. Refer to https://eprint.iacr.org/2013/879.pdf and https://eprint.iacr.org/2013/507.pdf for more information on these parameters.
var P = bigFromBase10("21888242871839275222246405745257275088696311157297823662689037894645226208583")
P is a prime over which we form a basic field: 36u⁴+36u³+24u²+6u+1.
Functions ¶
func PairingCheck ¶
PairingCheck calculates the Optimal Ate pairing for a set of points.
Types ¶
type G1 ¶
type G1 struct {
// contains filtered or unexported fields
}
G1 is an abstract cyclic group. The zero value is suitable for use as the output of an operation, but cannot be used as an input.
func RandomG1 ¶
RandomG1 returns x and g₁ˣ where x is a random, non-zero number read from r.
func (*G1) Add ¶
Add sets e to a+b and then returns e.
func (*G1) Marshal ¶
Marshal converts e to a byte slice.
func (*G1) Neg ¶
Neg sets e to -a and then returns e.
func (*G1) ScalarBaseMult ¶
ScalarBaseMult sets e to g*k where g is the generator of the group and then returns e.
func (*G1) ScalarMult ¶
ScalarMult sets e to a*k and then returns e.
func (*G1) Set ¶
Set sets e to a and then returns e.
func (*G1) String ¶
func (*G1) Unmarshal ¶
Unmarshal sets e to the result of converting the output of Marshal back into a group element and then returns e.
type G2 ¶
type G2 struct {
// contains filtered or unexported fields
}
G2 is an abstract cyclic group. The zero value is suitable for use as the output of an operation, but cannot be used as an input.
func RandomG2 ¶
RandomG2 returns x and g₂ˣ where x is a random, non-zero number read from r.
func (*G2) Add ¶
Add sets e to a+b and then returns e.
func (*G2) Marshal ¶
Marshal converts e into a byte slice.
func (*G2) Neg ¶
Neg sets e to -a and then returns e.
func (*G2) ScalarBaseMult ¶
ScalarBaseMult sets e to g*k where g is the generator of the group and then returns out.
func (*G2) ScalarMult ¶
ScalarMult sets e to a*k and then returns e.
func (*G2) Set ¶
Set sets e to a and then returns e.
func (*G2) String ¶
func (*G2) Unmarshal ¶
Unmarshal sets e to the result of converting the output of Marshal back into a group element and then returns e.
type GT ¶
type GT struct {
// contains filtered or unexported fields
}
GT is an abstract cyclic group. The zero value is suitable for use as the output of an operation, but cannot be used as an input.
func Miller ¶
Miller applies Miller's algorithm, which is a bilinear function from the source groups to F_p^12. Miller(g1, g2).Finalize() is equivalent to Pair(g1, g2).
func Pair ¶
Pair calculates an Optimal Ate pairing.
func (*GT) Add ¶
Add sets e to a+b and then returns e.
func (*GT) Finalize ¶
Finalize is a linear function from F_p^12 to GT.
func (*GT) Marshal ¶
Marshal converts e into a byte slice.
func (*GT) Neg ¶
Neg sets e to -a and then returns e.
func (*GT) ScalarMult ¶
ScalarMult sets e to a*k and then returns e.
func (*GT) Set ¶
Set sets e to a and then returns e.
func (*GT) String ¶
func (*GT) Unmarshal ¶
Unmarshal sets e to the result of converting the output of Marshal back into a group element and then returns e.
Source Files ¶
bn256.go constants.go curve.go gfp.go gfp12.go gfp2.go gfp6.go gfp_decl.go lattice.go optate.go twist.go
- Version
- v1.16.1 (latest)
- Published
- Jul 2, 2025
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 1 day ago –
Tools for package owners.