blst

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

blst

The blst package provides a rust interface to the blst BLS12-381 signature library.

Build

The build process consists of two steps, code generation followed by compilation.

./generate.py # Optional - only required if making code changes
go build
go test

The generate.py script is used to generate both min-pk and min-sig variants of the binding from a common code base. It consumes the *.tgo files along with blst_minpk_test.go and produces blst.go and blst_minsig_test.go. The .tgo files can treated as if they were .go files, including the use of gofmt and goimports. The generate script will filter out extra imports while processing and automatically run goimports on the final blst.go file.

After running generate.py, go build and go test can be run as usual. Cgo will compile server.c, which includes the required C implementation files, and assembly.S, which includes approprate pre-generated assembly code for the platform. To compile on Windows one has to have MinGW gcc on the %PATH%.

Usage

There are two primary modes of operation that can be chosen based on type definitions in the application.

For minimal-pubkey-size operations:

type PublicKey = P1Affine
type Signature = P2Affine
type AggregateSignature = P2Aggregate
type AggregatePublicKey = P1Aggregate

For minimal-signature-size operations:

type PublicKey = P2Affine
type Signature = P1Affine
type AggregateSignature = P1Aggregate
type AggregatePublicKey = P2Aggregate

TODO - structures and possibly methods

A simple example for generating a key, signing a message, and verifying the message:

var ikm [32]byte
_, _ := rand.Read(ikm[:])
sk := KeyGen(ikm[:])
pk := new(PublicKey).From(sk)

var dst = []byte("BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_")
msg := []byte("hello foo")
sig := new(Signature).Sign(sk, msg, dst)

if !sig.Verify(pk, msg, dst) {
    t.Errorf("verify sig0")
}

See the tests for further examples of usage.

Documentation

Index

Constants

View Source
const BLST_FP_BYTES = 384 / 8
View Source
const BLST_FP_LIMBS = 384 / 64
View Source
const BLST_P1_COMPRESS_BYTES = BLST_FP_BYTES
View Source
const BLST_P1_SERIALIZE_BYTES = BLST_FP_BYTES * 2
View Source
const BLST_P2_COMPRESS_BYTES = BLST_FP_BYTES * 2
View Source
const BLST_P2_SERIALIZE_BYTES = BLST_FP_BYTES * 4
View Source
const BLST_SCALAR_BYTES = 256 / 8
View Source
const BLST_SCALAR_LIMBS = 256 / 64

Variables

This section is empty.

Functions

func PairingAggregatePkInG1

func PairingAggregatePkInG1(ctx Pairing, PK *P1Affine, sig *P2Affine,
	hash_or_encode bool, msg []byte, optional ...[]byte) int

func PairingAggregatePkInG2

func PairingAggregatePkInG2(ctx Pairing, PK *P2Affine, sig *P1Affine,
	hash_or_encode bool, msg []byte, optional ...[]byte) int

func PairingCommit

func PairingCommit(ctx Pairing)

func PairingFinalVerify

func PairingFinalVerify(ctx Pairing, optional ...*Fp12) bool

func PairingMerge

func PairingMerge(ctx Pairing, ctx1 Pairing) int

func PrintBytes

func PrintBytes(val []byte, name string)

Types

type Fp

type Fp = C.blst_fp

func (*Fp) Equals

func (e1 *Fp) Equals(e2 *Fp) bool

func (*Fp) ToBEndian

func (fp *Fp) ToBEndian() []byte

func (*Fp) ToLEndian

func (fp *Fp) ToLEndian() []byte

type Fp12

type Fp12 = C.blst_fp12

type Fp2

type Fp2 = C.blst_fp2

func (*Fp2) Equals

func (e1 *Fp2) Equals(e2 *Fp2) bool

func (*Fp2) Print

func (f *Fp2) Print(name string)

type Fp6

type Fp6 = C.blst_fp6

func (*Fp6) Equals

func (e1 *Fp6) Equals(e2 *Fp6) bool

type Message

type Message = []byte

type P1

type P1 = C.blst_p1

func EncodeToG1

func EncodeToG1(msg []byte, dst []byte, optional ...[]byte) *P1

func HashToG1

func HashToG1(msg []byte, dst []byte, optional ...[]byte) *P1

Hash

func (*P1) Compress

func (p1 *P1) Compress() []byte

func (*P1) Print

func (p *P1) Print(name string)

func (*P1) Serialize

func (p1 *P1) Serialize() []byte

func (*P1) ToAffine

func (p *P1) ToAffine() *P1Affine

type P1Affine

type P1Affine = C.blst_p1_affine

func (*P1Affine) AggregateVerify

func (sig *P1Affine) AggregateVerify(pks []*P2Affine, msgs []Message,
	dst []byte,
	optional ...interface{}) bool

Aggregate verify with uncompressed signature and public keys

func (*P1Affine) AggregateVerifyCompressed

func (dummy *P1Affine) AggregateVerifyCompressed(sig []byte, pks [][]byte,
	msgs []Message, dst []byte,
	optional ...bool) bool

Aggregate verify with compressed signature and public keys Uses a dummy signature to get the correct type

func (*P1Affine) Compress

func (p1 *P1Affine) Compress() []byte

func (*P1Affine) Deserialize

func (p1 *P1Affine) Deserialize(in []byte) *P1Affine

func (*P1Affine) Equals

func (e1 *P1Affine) Equals(e2 *P1Affine) bool

func (*P1Affine) FastAggregateVerify

func (sig *P1Affine) FastAggregateVerify(pks []*P2Affine, msg Message,
	dst []byte, optional ...interface{}) bool

func (*P1Affine) From

func (pk *P1Affine) From(s *Scalar) *P1Affine

func (*P1Affine) Serialize

func (p1 *P1Affine) Serialize() []byte

P1 Serdes

func (*P1Affine) Sign

func (sig *P1Affine) Sign(sk *SecretKey, msg []byte, dst []byte,
	optional ...interface{}) *P1Affine

func (*P1Affine) Uncompress

func (p1 *P1Affine) Uncompress(in []byte) *P1Affine

func (*P1Affine) Verify

func (sig *P1Affine) Verify(pk *P2Affine, msg Message, dst []byte,
	optional ...interface{}) bool

Single verify with decompressed pk

func (*P1Affine) VerifyCompressed

func (dummy *P1Affine) VerifyCompressed(sig []byte, pk []byte,
	msg Message, dst []byte,
	optional ...bool) bool

Single verify with compressed pk Uses a dummy signature to get the correct type

type P1Aggregate

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

func (*P1Aggregate) Add

func (agg *P1Aggregate) Add(elmt *P1Affine) *P1Aggregate

func (*P1Aggregate) AddAggregate

func (agg *P1Aggregate) AddAggregate(other *P1Aggregate) *P1Aggregate

func (*P1Aggregate) Aggregate

func (agg *P1Aggregate) Aggregate(elmts []*P1Affine) *P1Aggregate

Aggregate uncompressed elements

func (*P1Aggregate) AggregateCompressed

func (agg *P1Aggregate) AggregateCompressed(elmts [][]byte) *P1Aggregate

Aggregate compressed elements

func (*P1Aggregate) ToAffine

func (agg *P1Aggregate) ToAffine() *P1Affine

type P2

type P2 = C.blst_p2

func EncodeToG2

func EncodeToG2(msg []byte, dst []byte, optional ...[]byte) *P2

func HashToG2

func HashToG2(msg []byte, dst []byte, optional ...[]byte) *P2

Hash

func (*P2) Compress

func (p2 *P2) Compress() []byte

func (*P2) Print

func (p *P2) Print(name string)

func (*P2) Serialize

func (p2 *P2) Serialize() []byte

func (*P2) ToAffine

func (p *P2) ToAffine() *P2Affine

type P2Affine

type P2Affine = C.blst_p2_affine

func (*P2Affine) AggregateVerify

func (sig *P2Affine) AggregateVerify(pks []*P1Affine, msgs []Message,
	dst []byte,
	optional ...interface{}) bool

Aggregate verify with uncompressed signature and public keys

func (*P2Affine) AggregateVerifyCompressed

func (dummy *P2Affine) AggregateVerifyCompressed(sig []byte, pks [][]byte,
	msgs []Message, dst []byte,
	optional ...bool) bool

Aggregate verify with compressed signature and public keys Uses a dummy signature to get the correct type

func (*P2Affine) Compress

func (p2 *P2Affine) Compress() []byte

func (*P2Affine) Deserialize

func (p2 *P2Affine) Deserialize(in []byte) *P2Affine

func (*P2Affine) Equals

func (e1 *P2Affine) Equals(e2 *P2Affine) bool

func (*P2Affine) FastAggregateVerify

func (sig *P2Affine) FastAggregateVerify(pks []*P1Affine, msg Message,
	dst []byte, optional ...interface{}) bool

func (*P2Affine) From

func (pk *P2Affine) From(s *Scalar) *P2Affine

func (*P2Affine) Serialize

func (p2 *P2Affine) Serialize() []byte

P2 Serdes

func (*P2Affine) Sign

func (sig *P2Affine) Sign(sk *SecretKey, msg []byte, dst []byte,
	optional ...interface{}) *P2Affine

func (*P2Affine) Uncompress

func (p2 *P2Affine) Uncompress(in []byte) *P2Affine

func (*P2Affine) Verify

func (sig *P2Affine) Verify(pk *P1Affine, msg Message, dst []byte,
	optional ...interface{}) bool

Single verify with decompressed pk

func (*P2Affine) VerifyCompressed

func (dummy *P2Affine) VerifyCompressed(sig []byte, pk []byte,
	msg Message, dst []byte,
	optional ...bool) bool

Single verify with compressed pk Uses a dummy signature to get the correct type

type P2Aggregate

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

func (*P2Aggregate) Add

func (agg *P2Aggregate) Add(elmt *P2Affine) *P2Aggregate

func (*P2Aggregate) AddAggregate

func (agg *P2Aggregate) AddAggregate(other *P2Aggregate) *P2Aggregate

func (*P2Aggregate) Aggregate

func (agg *P2Aggregate) Aggregate(elmts []*P2Affine) *P2Aggregate

Aggregate uncompressed elements

func (*P2Aggregate) AggregateCompressed

func (agg *P2Aggregate) AggregateCompressed(elmts [][]byte) *P2Aggregate

Aggregate compressed elements

func (*P2Aggregate) ToAffine

func (agg *P2Aggregate) ToAffine() *P2Affine

type Pairing

type Pairing = []uint64

func PairingCtx

func PairingCtx() Pairing

Pairing

type Scalar

type Scalar = C.blst_scalar

func (*Scalar) Deserialize

func (s *Scalar) Deserialize(in []byte) *Scalar

func (*Scalar) Equals

func (s1 *Scalar) Equals(s2 *Scalar) bool

func (*Scalar) Print

func (s *Scalar) Print(name string)

func (*Scalar) Serialize

func (s *Scalar) Serialize() []byte

Scalar serdes

func (*Scalar) ToBEndian

func (fr *Scalar) ToBEndian() []byte

func (*Scalar) ToLEndian

func (fr *Scalar) ToLEndian() []byte

type SecretKey

type SecretKey = Scalar

func KeyGen

func KeyGen(ikm []byte, optional ...[]byte) *SecretKey

Secret key

Jump to

Keyboard shortcuts

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