core

package
v0.0.0-...-67a1ad6 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const BLS12_381 = C.MCL_BLS12_381

BLS12_381 --

View Source
const CurveFp254BNb = C.mclBn_CurveFp254BNb

CurveFp254BNb -- 254 bit curve

View Source
const CurveFp382_1 = C.mclBn_CurveFp382_1

CurveFp382_1 -- 382 bit curve 1

View Source
const CurveFp382_2 = C.mclBn_CurveFp382_2

CurveFp382_2 -- 382 bit curve 2

View Source
const CurveSNARK1 = C.mclBn_CurveSNARK1

254-bit BN curve with support for roots of unity

View Source
const IRTF = 5 /* MCL_MAP_TO_MODE_HASH_TO_CURVE_07 */

IRTF -- for SetMapToMode

View Source
const ZERO_HEADER = 1 << 6

Variables

View Source
var (
	HashToG1 func([]byte) (*G1, error)
)

Functions

func FinalExp

func FinalExp(out *GT, x *GT)

FinalExp --

func Fp2Add

func Fp2Add(out *Fp2, x *Fp2, y *Fp2)

Fp2Add --

func Fp2Div

func Fp2Div(out *Fp2, x *Fp2, y *Fp2)

Fp2Div --

func Fp2Inv

func Fp2Inv(out *Fp2, x *Fp2)

Fp2Inv --

func Fp2Mul

func Fp2Mul(out *Fp2, x *Fp2, y *Fp2)

Fp2Mul --

func Fp2Neg

func Fp2Neg(out *Fp2, x *Fp2)

Fp2Neg --

func Fp2Sqr

func Fp2Sqr(out *Fp2, x *Fp2)

Fp2Sqr --

func Fp2SquareRoot

func Fp2SquareRoot(out *Fp2, x *Fp2) bool

Fp2SquareRoot --

func Fp2Sub

func Fp2Sub(out *Fp2, x *Fp2, y *Fp2)

Fp2Sub --

func FpAdd

func FpAdd(out *Fp, x *Fp, y *Fp)

FpAdd --

func FpDiv

func FpDiv(out *Fp, x *Fp, y *Fp)

FpDiv --

func FpInv

func FpInv(out *Fp, x *Fp)

FpInv --

func FpMul

func FpMul(out *Fp, x *Fp, y *Fp)

FpMul --

func FpNeg

func FpNeg(out *Fp, x *Fp)

FpNeg --

func FpSqr

func FpSqr(out *Fp, x *Fp)

FpSqr --

func FpSquareRoot

func FpSquareRoot(out *Fp, x *Fp) bool

FpSquareRoot --

func FpSub

func FpSub(out *Fp, x *Fp, y *Fp)

FpSub --

func FrAdd

func FrAdd(out *Fr, x *Fr, y *Fr)

FrAdd --

func FrDiv

func FrDiv(out *Fr, x *Fr, y *Fr)

FrDiv --

func FrEvaluatePolynomial

func FrEvaluatePolynomial(y *Fr, c []Fr, x *Fr) error

FrEvaluatePolynomial -- y = c[0] + c[1] * x + c[2] * x^2 + ...

func FrInv

func FrInv(out *Fr, x *Fr)

FrInv --

func FrLagrangeInterpolation

func FrLagrangeInterpolation(out *Fr, xVec []Fr, yVec []Fr) error

FrLagrangeInterpolation --

func FrMul

func FrMul(out *Fr, x *Fr, y *Fr)

FrMul --

func FrNeg

func FrNeg(out *Fr, x *Fr)

FrNeg --

func FrSqr

func FrSqr(out *Fr, x *Fr)

FrSqr --

func FrSquareRoot

func FrSquareRoot(out *Fr, x *Fr) bool

FrSquareRoot --

func FrSub

func FrSub(out *Fr, x *Fr, y *Fr)

FrSub --

func G1Add

func G1Add(out *G1, x *G1, y *G1)

G1Add --

func G1Dbl

func G1Dbl(out *G1, x *G1)

G1Dbl --

func G1EvaluatePolynomial

func G1EvaluatePolynomial(y *G1, c []G1, x *Fr) error

G1EvaluatePolynomial -- y = c[0] + c[1] * x + c[2] * x^2 + ...

func G1LagrangeInterpolation

func G1LagrangeInterpolation(out *G1, xVec []Fr, yVec []G1) error

G1LagrangeInterpolation --

func G1Mul

func G1Mul(out *G1, x *G1, y *Fr)

G1Mul --

func G1MulCT

func G1MulCT(out *G1, x *G1, y *Fr)

G1MulCT -- constant time (depending on bit lengh of y)

func G1MulVec

func G1MulVec(out *G1, xVec []G1, yVec []Fr)

G1MulVec -- multi scalar multiplication out = sum mul(xVec[i], yVec[i])

func G1Neg

func G1Neg(out *G1, x *G1)

G1Neg --

func G1Normalize

func G1Normalize(out *G1, x *G1)

G1Normalize --

func G1Sub

func G1Sub(out *G1, x *G1, y *G1)

G1Sub --

func G1ToBytes

func G1ToBytes(p *G1) []byte

func G2Add

func G2Add(out *G2, x *G2, y *G2)

G2Add --

func G2Dbl

func G2Dbl(out *G2, x *G2)

G2Dbl --

func G2EvaluatePolynomial

func G2EvaluatePolynomial(y *G2, c []G2, x *Fr) error

G2EvaluatePolynomial -- y = c[0] + c[1] * x + c[2] * x^2 + ...

func G2LagrangeInterpolation

func G2LagrangeInterpolation(out *G2, xVec []Fr, yVec []G2) error

G2LagrangeInterpolation --

func G2Mul

func G2Mul(out *G2, x *G2, y *Fr)

G2Mul --

func G2MulVec

func G2MulVec(out *G2, xVec []G2, yVec []Fr)

G2MulVec -- multi scalar multiplication out = sum mul(xVec[i], yVec[i])

func G2Neg

func G2Neg(out *G2, x *G2)

G2Neg --

func G2Normalize

func G2Normalize(out *G2, x *G2)

G2Normalize --

func G2Sub

func G2Sub(out *G2, x *G2, y *G2)

G2Sub --

func G2ToBytes

func G2ToBytes(p *G2) []byte

func GTAdd

func GTAdd(out *GT, x *GT, y *GT)

GTAdd --

func GTDiv

func GTDiv(out *GT, x *GT, y *GT)

GTDiv --

func GTInv

func GTInv(out *GT, x *GT)

GTInv --

func GTMul

func GTMul(out *GT, x *GT, y *GT)

GTMul --

func GTNeg

func GTNeg(out *GT, x *GT)

GTNeg --

func GTPow

func GTPow(out *GT, x *GT, y *Fr)

GTPow --

func GTSub

func GTSub(out *GT, x *GT, y *GT)

GTSub --

func GetCoef

func GetCoef() []uint64

func GetCurveOrder

func GetCurveOrder() string

GetCurveOrder -- return the order of G1

func GetDomain

func GetDomain() []byte

Returns bls/bn254 domain

func GetFieldOrder

func GetFieldOrder() string

GetFieldOrder -- return the characteristic of the field where a curve is defined

func GetFpByteSize

func GetFpByteSize() int

GetFpByteSize -- the serialized size of Fp

func GetFpUnitSize

func GetFpUnitSize() int

GetFpUnitSize -- same as GetMaxOpUnitSize()

func GetFrByteSize

func GetFrByteSize() int

GetFrByteSize -- the serialized size of Fr

func GetFrUnitSize

func GetFrUnitSize() int

GetFrUnitSize --

func GetG1ByteSize

func GetG1ByteSize() int

GetG1ByteSize -- the serialized size of G1

func GetG2ByteSize

func GetG2ByteSize() int

GetG2ByteSize -- the serialized size of G2

func GetMaxOpUnitSize

func GetMaxOpUnitSize() int

GetMaxOpUnitSize --

func GetOpUnitSize

func GetOpUnitSize() int

GetOpUnitSize -- the length of Fr is GetOpUnitSize() * 8 bytes

func GetUint64NumToPrecompute

func GetUint64NumToPrecompute() int

GetUint64NumToPrecompute --

func InitCurve

func InitCurve(curve int) error

func MapToG1

func MapToG1(out *G1, x *Fp) error

MapToG1 --

func MapToG2

func MapToG2(out *G2, x *Fp2) error

MapToG2 --

func MarshalMessage

func MarshalMessage(message []byte) ([]byte, error)

MarshalMessage marshalls message into byte slice

func MillerLoop

func MillerLoop(out *GT, x *G1, y *G2)

MillerLoop --

func MillerLoopVec

func MillerLoopVec(out *GT, xVec []G1, yVec []G2)

MillerLoopVec -- multi pairings ; out = prod_i e(xVec[i], yVec[i])

func Pairing

func Pairing(out *GT, x *G1, y *G2)

Pairing --

func PrecomputeG2

func PrecomputeG2(Q *G2) []uint64

PrecomputeG2 --

func PrecomputedMillerLoop

func PrecomputedMillerLoop(out *GT, P *G1, Qbuf []uint64)

PrecomputedMillerLoop --

func PrecomputedMillerLoop2

func PrecomputedMillerLoop2(out *GT, P1 *G1, Q1buf []uint64, P2 *G1, Q2buf []uint64)

PrecomputedMillerLoop2 --

func SetDomain

func SetDomain(_domain []byte)

func SetDstG1

func SetDstG1(s string) error

SetDstG1 --

func SetDstG2

func SetDstG2(s string) error

SetDstG2 --

func SetETHserialization

func SetETHserialization(enable bool)

SetETHserialization --

func SetMapToMode

func SetMapToMode(mode int) error

SetMapToMode --

func VerifyOrderG1

func VerifyOrderG1(doVerify bool)

VerifyOrderG1 -- verify order if SetString/Deserialize are called

func VerifyOrderG2

func VerifyOrderG2(doVerify bool)

VerifyOrderG2 -- verify order if SetString/Deserialize are called

Types

type Fp

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

Fp --

func GetR1

func GetR1() Fp

func GetR2

func GetR2() Fp

func (*Fp) Clear

func (x *Fp) Clear()

Clear --

func (*Fp) Deserialize

func (x *Fp) Deserialize(buf []byte) error

Deserialize --

func (*Fp) GetString

func (x *Fp) GetString(base int) string

GetString --

func (*Fp) IsEqual

func (x *Fp) IsEqual(rhs *Fp) bool

IsEqual --

func (*Fp) IsNegative

func (x *Fp) IsNegative() bool

IsNegative -- true if x >= (p + 1) / 2

func (*Fp) IsOdd

func (x *Fp) IsOdd() bool

IsOdd --

func (*Fp) IsOne

func (x *Fp) IsOne() bool

IsOne --

func (*Fp) IsValid

func (x *Fp) IsValid() bool

IsValid --

func (*Fp) IsZero

func (x *Fp) IsZero() bool

IsZero --

func (*Fp) Serialize

func (x *Fp) Serialize() []byte

Serialize --

func (*Fp) SetBigEndianMod

func (x *Fp) SetBigEndianMod(buf []byte) error

SetBigEndianMod --

func (*Fp) SetByCSPRNG

func (x *Fp) SetByCSPRNG()

SetByCSPRNG --

func (*Fp) SetHashOf

func (x *Fp) SetHashOf(buf []byte) bool

SetHashOf --

func (*Fp) SetInt64

func (x *Fp) SetInt64(v int64)

SetInt64 --

func (*Fp) SetLittleEndian

func (x *Fp) SetLittleEndian(buf []byte) error

SetLittleEndian --

func (*Fp) SetLittleEndianMod

func (x *Fp) SetLittleEndianMod(buf []byte) error

SetLittleEndianMod --

func (*Fp) SetString

func (x *Fp) SetString(s string, base int) error

SetString --

type Fp2

type Fp2 struct {
	D [2]Fp
}

Fp2 -- x = D[0] + D[1] i where i^2 = -1

func (*Fp2) Clear

func (x *Fp2) Clear()

Clear --

func (*Fp2) Deserialize

func (x *Fp2) Deserialize(buf []byte) error

Deserialize --

func (*Fp2) IsEqual

func (x *Fp2) IsEqual(rhs *Fp2) bool

IsEqual --

func (*Fp2) IsOne

func (x *Fp2) IsOne() bool

IsOne --

func (*Fp2) IsZero

func (x *Fp2) IsZero() bool

IsZero --

func (*Fp2) Serialize

func (x *Fp2) Serialize() []byte

Serialize --

type Fr

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

Fr --

func (*Fr) Clear

func (x *Fr) Clear()

Clear --

func (*Fr) Deserialize

func (x *Fr) Deserialize(buf []byte) error

Deserialize --

func (*Fr) GetString

func (x *Fr) GetString(base int) string

GetString --

func (*Fr) IsEqual

func (x *Fr) IsEqual(rhs *Fr) bool

IsEqual --

func (*Fr) IsNegative

func (x *Fr) IsNegative() bool

IsNegative -- true if x >= (r + 1) / 2

func (*Fr) IsOdd

func (x *Fr) IsOdd() bool

IsOdd --

func (*Fr) IsOne

func (x *Fr) IsOne() bool

IsOne --

func (*Fr) IsValid

func (x *Fr) IsValid() bool

IsValid --

func (*Fr) IsZero

func (x *Fr) IsZero() bool

IsZero --

func (*Fr) Serialize

func (x *Fr) Serialize() []byte

Serialize --

func (*Fr) SetBigEndianMod

func (x *Fr) SetBigEndianMod(buf []byte) error

SetBigEndianMod --

func (*Fr) SetByCSPRNG

func (x *Fr) SetByCSPRNG() bool

SetByCSPRNG --

func (*Fr) SetHashOf

func (x *Fr) SetHashOf(buf []byte) bool

SetHashOf --

func (*Fr) SetInt64

func (x *Fr) SetInt64(v int64)

SetInt64 --

func (*Fr) SetLittleEndian

func (x *Fr) SetLittleEndian(buf []byte) error

SetLittleEndian --

func (*Fr) SetLittleEndianMod

func (x *Fr) SetLittleEndianMod(buf []byte) error

SetLittleEndianMod --

func (*Fr) SetString

func (x *Fr) SetString(s string, base int) error

SetString --

type G1

type G1 struct {
	X Fp
	Y Fp
	Z Fp
}

G1 --

func G1FromBytes

func G1FromBytes(raw []byte) (*G1, error)

func G1Zero

func G1Zero(g1 *G1) *G1

func HashToG103

func HashToG103(message []byte) (*G1, error)

HashToG103 converts message to G1 point https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-03

func HashToG107

func HashToG107(message []byte) (*G1, error)

HashToG107 converts message to G1 point https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-07

func (*G1) Clear

func (x *G1) Clear()

Clear --

func (*G1) Deserialize

func (x *G1) Deserialize(buf []byte) error

Deserialize --

func (*G1) DeserializeUncompressed

func (x *G1) DeserializeUncompressed(buf []byte) error

DeserializeUncompressed -- x.Deserialize() + y.Deserialize()

func (*G1) GetString

func (x *G1) GetString(base int) string

GetString --

func (*G1) HashAndMapTo

func (x *G1) HashAndMapTo(buf []byte) error

HashAndMapTo --

func (*G1) IsEqual

func (x *G1) IsEqual(rhs *G1) bool

IsEqual --

func (*G1) IsValid

func (x *G1) IsValid() bool

IsValid --

func (*G1) IsValidOrder

func (x *G1) IsValidOrder() bool

IsValidOrder --

func (*G1) IsZero

func (x *G1) IsZero() bool

IsZero --

func (*G1) Serialize

func (x *G1) Serialize() []byte

Serialize --

func (*G1) SerializeUncompressed

func (x *G1) SerializeUncompressed() []byte

SerializeUncompressed -- all zero array if x.IsZero()

func (*G1) SetString

func (x *G1) SetString(s string, base int) error

SetString --

type G2

type G2 struct {
	X Fp2
	Y Fp2
	Z Fp2
}

G2 --

func G2FromBytes

func G2FromBytes(raw []byte) (*G2, error)

func G2Zero

func G2Zero(g2 *G2) *G2

func (*G2) Clear

func (x *G2) Clear()

Clear --

func (*G2) Deserialize

func (x *G2) Deserialize(buf []byte) error

Deserialize --

func (*G2) DeserializeUncompressed

func (x *G2) DeserializeUncompressed(buf []byte) error

DeserializeUncompressed -- x.Deserialize() + y.Deserialize()

func (*G2) GetString

func (x *G2) GetString(base int) string

GetString --

func (*G2) HashAndMapTo

func (x *G2) HashAndMapTo(buf []byte) error

HashAndMapTo --

func (*G2) IsEqual

func (x *G2) IsEqual(rhs *G2) bool

IsEqual --

func (*G2) IsValid

func (x *G2) IsValid() bool

IsValid --

func (*G2) IsValidOrder

func (x *G2) IsValidOrder() bool

IsValidOrder --

func (*G2) IsZero

func (x *G2) IsZero() bool

IsZero --

func (*G2) Serialize

func (x *G2) Serialize() []byte

Serialize --

func (*G2) SerializeUncompressed

func (x *G2) SerializeUncompressed() []byte

SerializeUncompressed -- all zero array if x.IsZero()

func (*G2) SetString

func (x *G2) SetString(s string, base int) error

SetString --

type GT

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

GT --

func (*GT) Clear

func (x *GT) Clear()

Clear --

func (*GT) Deserialize

func (x *GT) Deserialize(buf []byte) error

Deserialize --

func (*GT) GetString

func (x *GT) GetString(base int) string

GetString --

func (*GT) IsEqual

func (x *GT) IsEqual(rhs *GT) bool

IsEqual --

func (*GT) IsOne

func (x *GT) IsOne() bool

IsOne --

func (*GT) IsZero

func (x *GT) IsZero() bool

IsZero --

func (*GT) Serialize

func (x *GT) Serialize() []byte

Serialize --

func (*GT) SetInt64

func (x *GT) SetInt64(v int64)

SetInt64 --

func (*GT) SetString

func (x *GT) SetString(s string, base int) error

SetString --

type PrivateKey

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

func CreateRandomBlsKeys

func CreateRandomBlsKeys(total int) ([]*PrivateKey, error)

CreateRandomBlsKeys creates an slice of random private keys

func GenerateBlsKey

func GenerateBlsKey() (*PrivateKey, error)

GenerateBlsKey creates a random private and its corresponding public keys

func UnmarshalPrivateKey

func UnmarshalPrivateKey(data []byte) (*PrivateKey, error)

UnmarshalPrivateKey reads the private key from the given byte array

func (*PrivateKey) MarshalJSON

func (p *PrivateKey) MarshalJSON() ([]byte, error)

MarshalJSON marshal the key to bytes.

func (*PrivateKey) PublicKey

func (p *PrivateKey) PublicKey() *PublicKey

PublicKey returns the public key from the PrivateKey

func (*PrivateKey) Sign

func (p *PrivateKey) Sign(message []byte) (*Signature, error)

Sign generates a signature of the given message

type PublicKey

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

PublicKey represents bls public key

func AggregatePublicKeys

func AggregatePublicKeys(pubs []*PublicKey) *PublicKey

AggregatePublicKeys calculates P1 + P2 + ...

func CollectPublicKeys

func CollectPublicKeys(keys []*PrivateKey) []*PublicKey

CollectPublicKeys colects public keys from slice of private keys

func UnmarshalPublicKey

func UnmarshalPublicKey(raw []byte) (*PublicKey, error)

UnmarshalPublicKey reads the public key from the given byte array

func (*PublicKey) Aggregate

func (p *PublicKey) Aggregate(next *PublicKey) *PublicKey

Aggregate aggregates current key with key passed as a parameter

func (*PublicKey) Marshal

func (p *PublicKey) Marshal() []byte

Marshal marshals public key to bytes.

func (*PublicKey) MarshalJSON

func (p *PublicKey) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (PublicKey) String

func (p PublicKey) String() string

func (*PublicKey) UnmarshalJSON

func (p *PublicKey) UnmarshalJSON(raw []byte) error

UnmarshalJSON implements the json.Marshaler interface.

type Signature

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

Signature represents bls signature which is point on the curve

func AggregateSignatures

func AggregateSignatures(signatures []*Signature) *Signature

Aggregate sums the given array of signatures

func UnmarshalSignature

func UnmarshalSignature(raw []byte) (*Signature, error)

UnmarshalSignature reads the signature from the given byte array

func (*Signature) Aggregate

func (s *Signature) Aggregate(next *Signature) *Signature

Aggregate adds the given signatures

func (*Signature) Marshal

func (s *Signature) Marshal() ([]byte, error)

Marshal the signature to bytes.

func (Signature) String

func (s Signature) String() string

func (*Signature) Verify

func (s *Signature) Verify(publicKey *PublicKey, message []byte) bool

Verify checks the BLS signature of the message against the public key of its signer

func (*Signature) VerifyAggregated

func (s *Signature) VerifyAggregated(publicKeys []*PublicKey, msg []byte) bool

VerifyAggregated checks the BLS signature of the message against the aggregated public keys of its signers

Jump to

Keyboard shortcuts

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