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 ¶
- Constants
- func Generate() crypto.Signer
- func NewPublicKeyFactory() crypto.PublicKeyFactory
- func NewSignatureFactory() crypto.SignatureFactory
- func NewSignerFromBytes(data []byte) (crypto.AggregateSigner, error)
- func RegisterPublicKeyFormat(c serde.Format, f serde.FormatEngine)
- func RegisterSignatureFormat(c serde.Format, f serde.FormatEngine)
- type PublicKey
- func (pk PublicKey) Equal(other interface{}) bool
- func (pk PublicKey) GetPoint() kyber.Point
- func (pk PublicKey) MarshalBinary() ([]byte, error)
- func (pk PublicKey) MarshalText() ([]byte, error)
- func (pk PublicKey) Serialize(ctx serde.Context) ([]byte, error)
- func (pk PublicKey) String() string
- func (pk PublicKey) Verify(msg []byte, sig crypto.Signature) error
- type Signature
- type Signer
- func (s Signer) Aggregate(signatures ...crypto.Signature) (crypto.Signature, error)
- func (s Signer) GetPublicKey() crypto.PublicKey
- func (s Signer) GetPublicKeyFactory() crypto.PublicKeyFactory
- func (s Signer) GetSignatureFactory() crypto.SignatureFactory
- func (s Signer) GetVerifierFactory() crypto.VerifierFactory
- func (s Signer) MarshalBinary() ([]byte, error)
- func (s Signer) Sign(msg []byte) (crypto.Signature, error)
Examples ¶
Constants ¶
const (
// Algorithm is the name of the curve used for the BLS signature.
Algorithm = "BLS-CURVE-BN256"
)
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
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 ¶
MarshalBinary implements encoding.BinaryMarshaler. It produces a slice of bytes representing the public key.
func (PublicKey) MarshalText ¶
MarshalText implements encoding.TextMarshaler. It returns a text representation of the public key.
func (PublicKey) Serialize ¶
Serialize implements serde.Message. It returns the serialized data of the 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 ¶
NewSignature creates a new signature from the provided data.
func (Signature) Equal ¶
Equal implements crypto.Signature. It returns true if both signatures are the same.
func (Signature) MarshalBinary ¶
MarshalBinary implements encoding.BinaryMarshaler. It returns a slice of bytes representing 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 (Signer) Aggregate ¶
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 ¶
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 ¶
MarshalBinary implements encoding.BinaryMarshaler. It returns a binary representation of the signer.
func (Signer) Sign ¶
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