bls

package
v1.3.71 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package bls provides BLS signatures using the BLS12-381 pairing curve.

This packages implements the IETF/CFRG draft for BLS signatures [1]. Currently only the BASIC mode (one of the three modes specified in the draft) is supported. The pairing function is instantiated with the BLS12-381 curve.

Groups

The BLS signature scheme can be instantiated with keys in one of the two groups: G1 or G2, which correspond to the input domain of a pairing function e(G1,G2) -> Gt. Thus, choosing keys in G1 implies that signature values are internally represented in G2; or viceversa. Use the types KeyG1SigG2 or KeyG2SigG1 to express this preference.

Serialization

The serialization of elements in G1 and G2 follows the recommendation given in [2], in order to be compatible with other implementations of BLS12-381 curve.

References

[1] https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-bls-signature-05

[2] https://github.com/zkcrypto/bls12_381/blob/0.7.0/src/notes/serialization.rs

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid    = errors.New("bls: invalid BLS instance")
	ErrInvalidKey = errors.New("bls: invalid key")
	ErrKeyGen     = errors.New("bls: too many unsuccessful key generation tries")
	ErrShortIKM   = errors.New("bls: IKM material shorter than 32 bytes")
	ErrAggregate  = errors.New("bls: error while aggregating signatures")
)

Functions

func Verify

func Verify[K KeyGroup](pub *PublicKey[K], msg []byte, sig Signature) bool

Verify returns true if the signature of a message is valid for the corresponding public key.

func VerifyAggregate

func VerifyAggregate[K KeyGroup](pubs []*PublicKey[K], msgs [][]byte, aggSig Signature) bool

VerifyAggregate returns true if the aggregated signature is valid for the list of messages and public keys provided. The slices must have equal size and have at least one element.

Types

type G1

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

G1 group used for keys defined in pairing group G1.

type G2

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

G2 group used for keys defined in pairing group G2.

type KeyG1SigG2

type KeyG1SigG2 = G1

KeyG1SigG2 sets the keys to G1 and signatures to G2.

type KeyG2SigG1

type KeyG2SigG1 = G2

KeyG2SigG1 sets the keys to G2 and signatures to G1.

type KeyGroup

type KeyGroup interface{ G1 | G2 }

KeyGroup determines the group used for keys, while the other group is used for signatures.

type PrivateKey

type PrivateKey[K KeyGroup] struct {
	// contains filtered or unexported fields
}

func KeyGen

func KeyGen[K KeyGroup](ikm, salt, keyInfo []byte) (*PrivateKey[K], error)

KeyGen derives a private key for the specified group (G1 or G2). The length of ikm material should be at least 32 bytes length. The salt value should be either empty or a uniformly random bytes whose length equals the output length of SHA-256.

func (*PrivateKey[K]) Equal

func (k *PrivateKey[K]) Equal(x crypto.PrivateKey) bool

func (*PrivateKey[K]) MarshalBinary

func (k *PrivateKey[K]) MarshalBinary() ([]byte, error)

MarshalBinary returns a slice with the representation of the underlying PrivateKey scalar (in big-endian order).

func (*PrivateKey[K]) Public

func (k *PrivateKey[K]) Public() crypto.PublicKey

func (*PrivateKey[K]) PublicKey

func (k *PrivateKey[K]) PublicKey() *PublicKey[K]

PublicKey computes the corresponding public key. The key is cached for further invocations to this function.

func (*PrivateKey[K]) UnmarshalBinary

func (k *PrivateKey[K]) UnmarshalBinary(data []byte) error

func (*PrivateKey[K]) Validate

func (k *PrivateKey[K]) Validate() bool

Validate explicitly determines if a private key is valid.

type PublicKey

type PublicKey[K KeyGroup] struct {
	// contains filtered or unexported fields
}

func (*PublicKey[K]) Equal

func (k *PublicKey[K]) Equal(x crypto.PublicKey) bool

func (*PublicKey[K]) MarshalBinary

func (k *PublicKey[K]) MarshalBinary() ([]byte, error)

MarshalBinary returns a slice with the compressed representation of the underlying element in G1 or G2.

func (*PublicKey[K]) UnmarshalBinary

func (k *PublicKey[K]) UnmarshalBinary(data []byte) error

func (*PublicKey[K]) Validate

func (k *PublicKey[K]) Validate() bool

Validate explicitly determines if a public key is valid.

type Signature

type Signature = []byte

func Aggregate

func Aggregate[K KeyGroup](k K, sigs []Signature) (Signature, error)

Aggregate produces a unified signature given a list of signatures. To specify the group of keys pass either G1{} or G2{} as the first parameter.

func Sign

func Sign[K KeyGroup](k *PrivateKey[K], msg []byte) Signature

Sign computes a signature of a message using a key (defined in G1 or G1).

Jump to

Keyboard shortcuts

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