bls

package module
v0.0.0-...-0e61c30 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2019 License: BSD-3-Clause Imports: 4 Imported by: 0

README

Go-BLS Signature Aggregation

This repository is a go-wrapper around @herumi's BLS implementation using the underlying herumi/mcl cryptography library written in C++. The go wrapper is also based on @herumi's original BLS C++ project herumi/bls. The code was modified by Prysmatic Labs in order to integrate it into Ethereum's Serenity upgrade including Proof of Stake and Sharding.

Docs

To see examples on how to use herumi's BLS library, see the example/ directory in the repo containing single signature verification in addition to aggregate signature verification.

See more information on Godoc here.

Installing

git clone https://github.com/prysmaticlabs/go-bls
Running With Go

Make sure you have the latest version of Go installed along with a c/c++ compiler and libgmp required for precision arithmetic. Then, you can run the local bls tests using the go tool:

go test -bench .
goos: linux
goarch: amd64
pkg: github.com/prysmaticlabs/go-bls
BenchmarkPubkeyFromSeckey-4   	   10000	    221235 ns/op
BenchmarkSigning-4            	    5000	    274591 ns/op
BenchmarkValidation-4         	    1000	   1305703 ns/op
PASS
ok  	github.com/prysmaticlabs/go-bls	7.814s
Running With Bazel

Install Google's Bazel build tool here for your architecture. Then, run tests as follows:

bazel test //...
INFO: Analysed 3 targets (1 packages loaded).
INFO: Found 2 targets and 1 test target...
INFO: Elapsed time: 6.543s, Critical Path: 5.53s
INFO: 17 processes: 17 linux-sandbox.
INFO: Build completed successfully, 18 total actions
//:go_default_test                                                       PASSED in 2.0s

Executed 1 out of 1 test: 1 test passes.
There were tests whose specified size is too big. Use the --test_verbose_timeout_warnings command line option INFO: Build completed successfully, 18 total actions

License

The original BLS code was written by @herumi under the BSD-3 software license.

Documentation

Index

Constants

View Source
const BLS12_381 = C.MCL_BLS12_381

BLS12_381 Curve.

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 IoSerializeHexStr = C.MCLBN_IO_SERIALIZE_HEX_STR

IoSerializeHexStr -- serialization parameter for the underlying cryptographic library created by @herumi.

Variables

This section is empty.

Functions

func GetMaxOpUnitSize

func GetMaxOpUnitSize() int

GetMaxOpUnitSize --

func GetOpUnitSize

func GetOpUnitSize() int

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

func HashAndMapToG2

func HashAndMapToG2(m []byte) error

HashAndMapToG2 takes a byte slice of a message and attempts to hash it and map the output into the G2 Group.

Types

type PublicKey

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

PublicKey definition in the BLS scheme.

func GetMasterPublicKey

func GetMasterPublicKey(msk []SecretKey) (mpk []PublicKey)

GetMasterPublicKey returns a list of public keys for a slice of private keys.

func (*PublicKey) Add

func (pub *PublicKey) Add(rhs *PublicKey)

Add two BLS public keys together

func (*PublicKey) Deserialize

func (pub *PublicKey) Deserialize(buf []byte) error

Deserialize converts a byte slice into a public key.

func (*PublicKey) DeserializeHexStr

func (pub *PublicKey) DeserializeHexStr(s string) error

DeserializeHexStr sets a public key from a hex string.

func (*PublicKey) HexString

func (pub *PublicKey) HexString() string

HexString returns the hex string representation of a public key.

func (*PublicKey) IsEqual

func (pub *PublicKey) IsEqual(rhs *PublicKey) bool

IsEqual compares two BLS public keys.

func (*PublicKey) Serialize

func (pub *PublicKey) Serialize() []byte

Serialize a public key into a byte slice.

func (*PublicKey) SerializeToHexStr

func (pub *PublicKey) SerializeToHexStr() string

SerializeToHexStr returns a hex string serialization of a public key.

func (*PublicKey) SetHexString

func (pub *PublicKey) SetHexString(s string) error

SetHexString sets a public key from a hex string.

type SecretKey

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

SecretKey --

func (*SecretKey) Add

func (sec *SecretKey) Add(rhs *SecretKey)

Add two private keys together.

func (*SecretKey) DecString

func (sec *SecretKey) DecString() string

DecString returns a decimal string representation of the private key.

func (*SecretKey) DeserializeHexStr

func (sec *SecretKey) DeserializeHexStr(s string) error

DeserializeHexStr deserializes a hex string into a private key.

func (*SecretKey) GetMasterSecretKey

func (sec *SecretKey) GetMasterSecretKey(k int) (msk []SecretKey)

GetMasterSecretKey creates a series of k secret keys and using a pseudorandom number generator and returns them as a slice.

func (*SecretKey) GetPublicKey

func (sec *SecretKey) GetPublicKey() (pub *PublicKey)

GetPublicKey returns the public key corresponding to a BLS private key.

func (*SecretKey) HexString

func (sec *SecretKey) HexString() string

HexString returns the hex string of the private key.

func (*SecretKey) IsEqual

func (sec *SecretKey) IsEqual(rhs *SecretKey) bool

IsEqual compares two private keys.

func (*SecretKey) LittleEndian

func (sec *SecretKey) LittleEndian() []byte

LittleEndian returns the serialized, little-endian formatted byte slice of the secret key.

func (*SecretKey) SerializeToHexStr

func (sec *SecretKey) SerializeToHexStr() string

SerializeToHexStr returns a hex string representation of a private key.

func (*SecretKey) SetByCSPRNG

func (sec *SecretKey) SetByCSPRNG()

SetByCSPRNG sets a private key's internal representation using a cryptographically-secure, pseudorandom number generator.

func (*SecretKey) SetDecString

func (sec *SecretKey) SetDecString(s string) error

SetDecString sets a private key based on a decimal string.

func (*SecretKey) SetHexString

func (sec *SecretKey) SetHexString(s string) error

SetHexString sets a private key based on a hex string.

func (*SecretKey) SetLittleEndian

func (sec *SecretKey) SetLittleEndian(buf []byte) error

SetLittleEndian sets a secret key based on a little-endian formatted byte slice.

func (*SecretKey) SetValue

func (sec *SecretKey) SetValue(val int64)

SetValue sets a private key's internal representation using an inputted number.

func (*SecretKey) Sign

func (sec *SecretKey) Sign(m []byte) (sign *Sign)

Sign a string message using a BLS private key in constant time.

type Sign

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

Sign represents a signature in the BLS signature aggregation scheme.

func (*Sign) Add

func (sign *Sign) Add(rhs *Sign)

Add two BLS signatures together.

func (*Sign) Deserialize

func (sign *Sign) Deserialize(buf []byte) error

Deserialize a signature from a byte array.

func (*Sign) DeserializeHexStr

func (sign *Sign) DeserializeHexStr(s string) error

DeserializeHexStr creates a signature from a hex string serialization.

func (*Sign) HexString

func (sign *Sign) HexString() string

HexString representation of a signature.

func (*Sign) IsEqual

func (sign *Sign) IsEqual(rhs *Sign) bool

IsEqual compares two signatures.

func (*Sign) Serialize

func (sign *Sign) Serialize() []byte

Serialize a signature into a byte array.

func (*Sign) SerializeToHexStr

func (sign *Sign) SerializeToHexStr() string

SerializeToHexStr serializes a signature into a hex string.

func (*Sign) SetHexString

func (sign *Sign) SetHexString(s string) error

SetHexString sets a signature from a hex string.

func (*Sign) Verify

func (sign *Sign) Verify(pub *PublicKey, m []byte) bool

Verify a signature using a BLS public key and a message string.

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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