bls

package
v0.1.0 Latest Latest
Warning

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

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

Documentation

Overview

Package bls implements the cryptographic primitives using the BLS signature scheme and the BN256 elliptic curve.

Related Papers:

https://crypto.stanford.edu/~dabo/pubs/papers/BLSmultisig.html

Documentation Last Review: 05.10.2020

Index

Examples

Constants

View Source
const (
	// Algorithm is the name of the curve used for the BLS signature.
	Algorithm = "BLS-CURVE-BN256"
)

Variables

This section is empty.

Functions

func Generate

func Generate() crypto.Signer

Generate returns a new random BLS signer that supports aggregation.

func NewPublicKeyFactory

func NewPublicKeyFactory() crypto.PublicKeyFactory

NewPublicKeyFactory returns a new instance of the factory.

func NewSignatureFactory

func NewSignatureFactory() crypto.SignatureFactory

NewSignatureFactory returns a new instance of the factory.

func NewSignerFromBytes

func NewSignerFromBytes(data []byte) (crypto.AggregateSigner, error)

NewSignerFromBytes restores a signer from a marshalling.

func RegisterPublicKeyFormat

func RegisterPublicKeyFormat(c serde.Format, f serde.FormatEngine)

RegisterPublicKeyFormat registers the engine for the provided format.

func RegisterSignatureFormat

func RegisterSignatureFormat(c serde.Format, f serde.FormatEngine)

RegisterSignatureFormat registers the engine for the provided format.

Types

type PublicKey

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

PublicKey is the adapter a of BN256 public key.

- implements crypto.PublicKey

func NewPublicKey

func NewPublicKey(data []byte) (PublicKey, error)

NewPublicKey creates a new public key by unmarshaling the data into BN256 point.

func NewPublicKeyFromPoint

func NewPublicKeyFromPoint(point kyber.Point) PublicKey

NewPublicKeyFromPoint creates a new public key from an existing point.

func (PublicKey) Equal

func (pk PublicKey) Equal(other interface{}) bool

Equal implements crypto.PublicKey. It returns true if the other public key is the same.

func (PublicKey) GetPoint

func (pk PublicKey) GetPoint() kyber.Point

GetPoint returns the kyber.Point.

func (PublicKey) MarshalBinary

func (pk PublicKey) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. It produces a slice of bytes representing the public key.

func (PublicKey) MarshalText

func (pk PublicKey) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It returns a text representation of the public key.

func (PublicKey) Serialize

func (pk PublicKey) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data of the public key.

func (PublicKey) String

func (pk PublicKey) String() string

String implements fmt.String. It returns a string representation of the point.

func (PublicKey) Verify

func (pk PublicKey) Verify(msg []byte, sig crypto.Signature) error

Verify implements crypto.PublicKey. It returns nil if the signature matches the message for this public key.

type Signature

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

Signature is the adapter of a BN256 signature.

- implements crypto.Signature

func NewSignature

func NewSignature(data []byte) Signature

NewSignature creates a new signature from the provided data.

func (Signature) Equal

func (sig Signature) Equal(other crypto.Signature) bool

Equal implements crypto.Signature. It returns true if both signatures are the same.

func (Signature) MarshalBinary

func (sig Signature) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. It returns a slice of bytes representing the signature.

func (Signature) Serialize

func (sig Signature) Serialize(ctx serde.Context) ([]byte, error)

Serialize implements serde.Message. It returns the serialized data of the signature.

func (Signature) String

func (sig Signature) String() string

String implements fmt.Stringer. It returns a string representation of the signature.

type Signer

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

Signer is the adapter of a private key from the Kyber package for the BN256 elliptic curve.

- implements crypto.AggregateSigner - implements encoding.BinaryMarshaler

func NewSigner

func NewSigner() Signer

NewSigner generates and returns a new random signer.

func (Signer) Aggregate

func (s Signer) Aggregate(signatures ...crypto.Signature) (crypto.Signature, error)

Aggregate implements crypto.Signer. It aggregates the signatures into a single one that can be verifier with the aggregated public key associated.

func (Signer) GetPublicKey

func (s Signer) GetPublicKey() crypto.PublicKey

GetPublicKey implements crypto.Signer. It returns the public key of the signer that can be used to verify signatures.

func (Signer) GetPublicKeyFactory

func (s Signer) GetPublicKeyFactory() crypto.PublicKeyFactory

GetPublicKeyFactory implements crypto.Signer. It returns the public key factory for BLS signatures.

func (Signer) GetSignatureFactory

func (s Signer) GetSignatureFactory() crypto.SignatureFactory

GetSignatureFactory implements crypto.Signer. It returns the signature factory for BLS signatures.

func (Signer) GetVerifierFactory

func (s Signer) GetVerifierFactory() crypto.VerifierFactory

GetVerifierFactory implements crypto.Signer. It returns the verifier factory for BLS signatures.

func (Signer) MarshalBinary

func (s Signer) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler. It returns a binary representation of the signer.

func (Signer) Sign

func (s Signer) Sign(msg []byte) (crypto.Signature, error)

Sign implements crypto.Signer. It signs the message in parameter and returns the signature, or an error if it cannot sign.

Example
signerA := NewSigner()
signerB := NewSigner()

publicKeys := []crypto.PublicKey{
	signerA.GetPublicKey(),
	signerB.GetPublicKey(),
}

message := []byte("42")

signatureA, err := signerA.Sign(message)
if err != nil {
	panic("signer A failed: " + err.Error())
}

signatureB, err := signerB.Sign(message)
if err != nil {
	panic("signer B failed: " + err.Error())
}

aggregate, err := signerA.Aggregate(signatureA, signatureB)
if err != nil {
	panic("aggregate failed: " + err.Error())
}

verifier, err := signerA.GetVerifierFactory().FromArray(publicKeys)
if err != nil {
	panic("verifier failed: " + err.Error())
}

err = verifier.Verify(message, aggregate)
if err != nil {
	panic("invalid signature: " + err.Error())
}

fmt.Println("Success")
Output:

Success

Directories

Path Synopsis
Package command defines cli commands for the bls package.
Package command defines cli commands for the bls package.

Jump to

Keyboard shortcuts

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