bls

package
v0.0.0-...-ff61ee7 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2020 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Stats = sig.SigStats{
	PubSize:          128,
	SigSize:          64,
	ThrshShareSize:   64,
	VRFSize:          64,
	SigVerifyTime:    3329283,
	SignTime:         439761,
	ShareVerifyTime:  3329283,
	ShareGenTime:     439761,
	MultiCombineTime: 3352,
	VRFGenTime:       439761,
	VRFVerifyTime:    3329283,
	ShareCombineTime: 481735 / 7,
	AllowsMulti:      true,
	AllowsThresh:     true,
	AllowsVRF:        true,
}

Functions

func GetBlsPartPrivFunc

func GetBlsPartPrivFunc() func() (sig.Priv, error)

func GetBlsPartPrivFunc2

func GetBlsPartPrivFunc2() func() (sig.Priv, error)

func GetNewPubFromPubBLSMulti

func GetNewPubFromPubBLSMulti(suite pairing.Suite, pub kyber.Point) (kyber.Point, kyber.Scalar, error)

GetNewPubFromPubBLSMulti multiplies the hash of a public key by its hash This is based on https://crypto.stanford.edu/~dabo/pubs/papers/BLSmultisig.html it returns the new public key and the hash

func MarshalSigBLS

func MarshalSigBLS(sig kyber.Point) ([]byte, error)

MarshallSig marshalls a BLS signature

func NewBLSKeyPair

func NewBLSKeyPair(suite pairing.Suite, random cipher.Stream) (kyber.Scalar, kyber.Point)

NewBLSKeyPair generates a new random BLS public/private key pair

func NewBLSMSKeyPair

func NewBLSMSKeyPair(suite pairing.Suite, random cipher.Stream) (kyber.Scalar, kyber.Point, kyber.Point, kyber.Scalar)

NewBLSMSKeyPair creates a new key pair that is based on the new multi-sigs from https://crypto.stanford.edu/~dabo/pubs/papers/BLSmultisig.html this code is modified from https://go.dedis.ch/kyber/v3/blob/master/sign/bls/bls.go TODO check if hasing the right objects output is public key, private key, public key * hashed public key, hashed public key

func NewBLSMSKeyPairFrom

func NewBLSMSKeyPairFrom(secret kyber.Scalar, suite pairing.Suite, random cipher.Stream) (kyber.Scalar, kyber.Point, kyber.Point, kyber.Scalar)

NewBLSMSKeyPairFrom is the same as NewBLSMSKeyPair except uses secret as the key.

func NewBlsPartPriv

func NewBlsPartPriv(thrsh *BlsThrsh) (sig.Priv, error)

func NewBlspriv

func NewBlspriv(newBidFunc bitid.FromIntFunc) (sig.Priv, error)

NewBlspriv creates a new random BLS private key

func NewBlsprivFrom

func NewBlsprivFrom(secret kyber.Scalar, newBidFunc bitid.FromIntFunc) sig.Priv

func SignBLS

func SignBLS(suite pairing.Suite, x kyber.Scalar, msg []byte) (kyber.Point, []byte, error)

SignBLS signs a message, and returns the signature unmarshalled, and marshalled

func SignBLSMS

func SignBLSMS(suite pairing.Suite, x kyber.Scalar, hpk kyber.Scalar, msg []byte) (kyber.Point, []byte, error)

SignBLSMS signs a message, returning the signature and the serialzed bytes it is based on https://crypto.stanford.edu/~dabo/pubs/papers/BLSmultisig.html

func UnmarshalSig

func UnmarshalSig(suite pairing.Suite, b []byte) (kyber.Point, error)

Unmarshall sig unmarshalls a BLS signature

func VerifyBLS

func VerifyBLS(suite pairing.Suite, X kyber.Point, msg []byte, sig kyber.Point) error

VerifyBLS checks if a BLS signature is valid

func VerifyPartialSig

func VerifyPartialSig(msg []byte, pubInt sig.Pub, sigInt sig.Sig) error

Types

type BlsShared

type BlsShared struct {
	NumParticipants int
	NumThresh       int
	SharedPub       kyber.Point
	PubPoints       []kyber.Point
	PriScalars      []kyber.Scalar
}

BlsShared represents precomputed information used to create Bls threshold keys.

var Thrshblsshare *BlsShared
var Thrshblsshare2 *BlsShared

func NewBlsShared

func NewBlsShared(numParticipants, numThresh int) *BlsShared

NewBLShared creates a BlsShared object for creating BLS threshold keys. It generates private values centrally so is only for testing.

func (*BlsShared) PartialMarshal

func (bs *BlsShared) PartialMarshal() (ret BlsSharedMarshal, err error)

PartialMartial partially martials a BlsShared object into a DSSSharedMarshaled object, which can then be mashaled into json for example. The index is the index of the secret key to marshall, all others secrets are nil.

type BlsSharedMarshal

type BlsSharedMarshal struct {
	NumParticipants int
	NumThresh       int
	SharedPub       []byte
	PubPoints       [][]byte
	PriScalars      [][]byte
}

BlsSharedMarshaled is a partially marshalled version of BlsShared. It can then be input to the go json marshaller for example.

func (BlsSharedMarshal) PartialUnmarshal

func (bsm BlsSharedMarshal) PartialUnmarshal() (ret *BlsShared, err error)

PartialUnmartial takes a BlsSharedMarshalled object, unmarshals it, and returns a BlsShared object.

type BlsThrsh

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

func NewBlsThrsh

func NewBlsThrsh(n, t int, idx sig.PubKeyIndex, secret kyber.Scalar, pub kyber.Point, sharedPub kyber.Point) *BlsThrsh

NewBlsThrsh creates an object for a given member of a signature threshold scheme.

func NewNonMemberBlsThrsh

func NewNonMemberBlsThrsh(n, t int, idx sig.PubKeyIndex, sharedPub kyber.Point) *BlsThrsh

NewBlsThrsh creates an object for a signature threshold scheme. The object created can combine signatures, but cannot generate its own partial signature as it is not a member of the scheme.

func (*BlsThrsh) CombinePartialSigs

func (bt *BlsThrsh) CombinePartialSigs(ps []sig.Sig) (*sig.SigItem, error)

CombinePartialSigs generates a shared signature from the list of partial signatures.

func (*BlsThrsh) GetN

func (bt *BlsThrsh) GetN() int

func (*BlsThrsh) GetPartialPub

func (bt *BlsThrsh) GetPartialPub() sig.Pub

func (*BlsThrsh) GetSharedPub

func (bt *BlsThrsh) GetSharedPub() sig.Pub

func (*BlsThrsh) GetT

func (bt *BlsThrsh) GetT() int

func (*BlsThrsh) PartialSign

func (bt *BlsThrsh) PartialSign(msg sig.SignedMessage) (sig.Sig, error)

PartialSign creates a signature on the message that can also be used to create a shared signature.

func (*BlsThrsh) ShallowCopy

func (bt *BlsThrsh) ShallowCopy() *BlsThrsh

type Blspriv

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

Blspriv represents a BLS private key object

func (*Blspriv) Clean

func (priv *Blspriv) Clean()

Clean does nothing

func (*Blspriv) ComputeSharedSecret

func (priv *Blspriv) ComputeSharedSecret(pub sig.Pub) [32]byte

ComputeSharedSecret returns the hash of Diffie-Hellman.

func (*Blspriv) Evaluate

func (priv *Blspriv) Evaluate(m sig.SignedMessage) (index [32]byte, proof sig.VRFProof)

Evaluate is for generating VRFs.

func (*Blspriv) GenerateSig

func (priv *Blspriv) GenerateSig(header sig.SignedMessage, vrfProof sig.VRFProof, signType types.SignType) (*sig.SigItem, error)

GenerateSig signs a message and returns the SigItem object containing the signature

func (*Blspriv) GetBaseKey

func (priv *Blspriv) GetBaseKey() sig.Priv

GetBaseKey returns the same key.

func (*Blspriv) GetPrivForSignType

func (priv *Blspriv) GetPrivForSignType(signType types.SignType) (sig.Priv, error)

Returns key that is used for signing the sign type.

func (*Blspriv) GetPub

func (priv *Blspriv) GetPub() sig.Pub

GetPub returns the coresponding BLS public key object

func (*Blspriv) NewSig

func (priv *Blspriv) NewSig() sig.Sig

NewSig returns an empty sig object of the same type.

func (*Blspriv) SetIndex

func (priv *Blspriv) SetIndex(index sig.PubKeyIndex)

SetIndex sets the index of the node represented by this key in the consensus participants

func (*Blspriv) ShallowCopy

func (priv *Blspriv) ShallowCopy() sig.Priv

Shallow copy makes a copy of the object without following pointers.

func (*Blspriv) Sign

func (priv *Blspriv) Sign(msg sig.SignedMessage) (sig.Sig, error)

Sign signs a message and returns the signature.

type Blspub

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

Blspub represent a BLS public key object

func (*Blspub) CheckSignature

func (pub *Blspub) CheckSignature(msg *sig.MultipleSignedMessage, sigItem *sig.SigItem) error

CheckSignature validates the signature with the public key, it returns an error if a coin proof is included.

func (*Blspub) Clone

func (pub *Blspub) Clone() sig.MultiPub

Clone returns a new Blspub only containing the points (no bitid), should be called before merging the first set of keys with MergePubPartial

func (*Blspub) Decode

func (pub *Blspub) Decode(reader io.Reader) (n int, err error)

func (*Blspub) Deserialize

func (pub *Blspub) Deserialize(m *messages.Message, unmarFunc types.ConsensusIndexFuncs) (int, error)

Deserialize updates the fields of the BLS pub key object from m, and returns the number of bytes read

func (*Blspub) DeserializeSig

func (pub *Blspub) DeserializeSig(m *messages.Message, signType types.SignType) (*sig.SigItem, int, error)

DeserializeSig takes a message and returns a BLS public key object and signature as well as the number of bytes read

func (*Blspub) DonePartialMerge

func (pub *Blspub) DonePartialMerge(bid bitid.NewBitIDInterface)

DonePartialMerge should be called after merging keys with MergePubPartial to set the bitid

func (*Blspub) Encode

func (pub *Blspub) Encode(writer io.Writer) (n int, err error)

func (*Blspub) FromPubBytes

func (pub *Blspub) FromPubBytes(b sig.PubKeyBytes) (sig.Pub, error)

FromPubBytes creates a BLS pub key object from the bytes of a public key

func (*Blspub) GenerateSerializedSig

func (pub *Blspub) GenerateSerializedSig(bsig sig.MultiSig) ([]byte, error)

GenerateSerializedSig serialized the public key and the signature and returns the bytes

func (*Blspub) GetBitID

func (pub *Blspub) GetBitID() bitid.NewBitIDInterface

GetBitID returns the bit id object representing the indecies of the nodes represented by the BLS public key oject

func (*Blspub) GetBytes

func (pub *Blspub) GetBytes(m *messages.Message) ([]byte, error)

GetBytes returns the bytes of the BLS public key from the message

func (*Blspub) GetID

func (pub *Blspub) GetID() messages.HeaderID

GetID returns the header id for BLS pub objects

func (*Blspub) GetIndex

func (pub *Blspub) GetIndex() sig.PubKeyIndex

GetIndex gets the index of the node represented by this key in the consensus participants

func (*Blspub) GetMsgID

func (pub *Blspub) GetMsgID() messages.MsgID

GetMsgID returns the msg id for BLS pub

func (*Blspub) GetPubBytes

func (pub *Blspub) GetPubBytes() (sig.PubKeyBytes, error)

GetPubBytes returns the BLS pub key as bytes, if using new multi sigs, is pub * hpk, otherwise is just the public key

func (*Blspub) GetPubID

func (pub *Blspub) GetPubID() (sig.PubKeyID, error)

GetPubID returns the unique id for this pubkey (given some consensus instance), it could be the encoded bitid, or just the pub key depending on how SetUsePubIndex was set

func (*Blspub) GetPubString

func (pub *Blspub) GetPubString() (sig.PubKeyStr, error)

GetPubString is the same as GetPubBytes, except returns a string

func (*Blspub) GetRealPubBytes

func (pub *Blspub) GetRealPubBytes() (sig.PubKeyBytes, error)

GetPubBytes returns the BLS pub key as bytes

func (*Blspub) GetSigMemberNumber

func (pub *Blspub) GetSigMemberNumber() int

GetSigMemberNumber returns the number of nodes represented by this BLS pub key

func (*Blspub) MergePub

func (pub *Blspub) MergePub(pub2 sig.MultiPub) (sig.MultiPub, error)

MergeBlsPub combines two BLS public key objects into a single one

func (*Blspub) MergePubPartial

func (pub *Blspub) MergePubPartial(pub2 sig.MultiPub)

MergePubPartial only merges the pub itself, does not create the new bitid

func (*Blspub) New

func (pub *Blspub) New() sig.Pub

New generates an empty Blspub object

func (*Blspub) NewVRFProof

func (pub *Blspub) NewVRFProof() sig.VRFProof

NewVRFProof returns an empty VRFProof object

func (Blspub) PeekHeaders

PeekHeader returns nil.

func (*Blspub) ProofToHash

func (pub *Blspub) ProofToHash(m sig.SignedMessage, proof sig.VRFProof) (index [32]byte, err error)

ProofToHash is for validating VRFs. For BLS we just use the first 32 bytes of the signature, TODO is this safe?

func (*Blspub) Serialize

func (pub *Blspub) Serialize(m *messages.Message) (int, error)

Serialize the pub key into the message, return the number of bytes written

func (*Blspub) SetIndex

func (pub *Blspub) SetIndex(index sig.PubKeyIndex)

SetIndex sets the index of the node represented by this public key in the consensus participants

func (*Blspub) ShallowCopy

func (pub *Blspub) ShallowCopy() sig.Pub

Shallow copy makes a copy of the object without following pointers.

func (*Blspub) SubMultiPub

func (pub *Blspub) SubMultiPub(pub2 sig.MultiPub) (sig.MultiPub, error)

SubBlsPub remove pub2 from pub1 and returns the resulting public key object

func (*Blspub) VerifySig

func (pub *Blspub) VerifySig(msg sig.SignedMessage, asig sig.Sig) (bool, error)

VerifySig verifies that sig is a valid signature for msg by BLS public key pub

type Blssig

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

Blssig represent a bls signature object

func (*Blssig) Corrupt

func (sig *Blssig) Corrupt()

Corrupt invalidates the signature

func (*Blssig) Decode

func (sig *Blssig) Decode(reader io.Reader) (n int, err error)

func (*Blssig) Deserialize

func (sig *Blssig) Deserialize(m *messages.Message, unmarFunc types.ConsensusIndexFuncs) (int, error)

Deserialize takes a message and fills in the fields of the sig oject from the bytes of the message it returns the number of bytes read

func (*Blssig) Encode

func (sig *Blssig) Encode(writer io.Writer) (n int, err error)

func (*Blssig) GetBytes

func (sig *Blssig) GetBytes(m *messages.Message) ([]byte, error)

GetBytes takes the serialized bls signature in a message and returns the signautre as a byte slice

func (*Blssig) GetID

func (sig *Blssig) GetID() messages.HeaderID

GetID returns the header id for the BLS sig message

func (*Blssig) GetMsgID

func (sig *Blssig) GetMsgID() messages.MsgID

GetMsgID returns the message id for a bls signature message

func (*Blssig) GetRand

func (sig *Blssig) GetRand() types.BinVal

GetRand returns a random binary from the signature if supported.

func (*Blssig) GetSigBytes

func (sig *Blssig) GetSigBytes() []byte

GetSigBytes returns the bytes of the serialized signature

func (*Blssig) MergeSig

func (sig1 *Blssig) MergeSig(sig2 sig.MultiSig) (sig.MultiSig, error)

MergeSig combines two signatures, it assumes the sigs are valid to be merged

func (*Blssig) New

func (sig *Blssig) New() sig.Sig

New creates an empty sig object

func (Blssig) PeekHeaders

func (Blssig) PeekHeaders(m *messages.Message, unmarFunc types.ConsensusIndexFuncs) (index types.ConsensusIndex, err error)

PeekHeader returns nil.

func (*Blssig) Serialize

func (sig *Blssig) Serialize(m *messages.Message) (int, error)

Serialize marshalls the signature and adds the bytes to the message returns the number of bytes written and any error

func (*Blssig) SubSig

func (sig1 *Blssig) SubSig(sig2 sig.MultiSig) (sig.MultiSig, error)

SubSig removes sig2 from sig1, it assumes sig 1 already contains sig2

type PartPriv

type PartPriv struct {
	*BlsThrsh
	// contains filtered or unexported fields
}

Blspriv represents a BLS private key object

func (*PartPriv) Clean

func (priv *PartPriv) Clean()

Clean does nothing

func (*PartPriv) ComputeSharedSecret

func (priv *PartPriv) ComputeSharedSecret(pub sig.Pub) [32]byte

ComputeSharedSecret returns the hash of Diffie-Hellman.

func (*PartPriv) Evaluate

func (priv *PartPriv) Evaluate(m sig.SignedMessage) (index [32]byte, proof sig.VRFProof)

func (*PartPriv) GenerateSig

func (priv *PartPriv) GenerateSig(header sig.SignedMessage, vrfProof sig.VRFProof,
	_ types.SignType) (*sig.SigItem, error)

GenerateSig signs a message and returns the SigItem object containing the signature

func (*PartPriv) GetBaseKey

func (priv *PartPriv) GetBaseKey() sig.Priv

GetBaseKey returns threshold key as a normal BSL key.

func (*PartPriv) GetPrivForSignType

func (priv *PartPriv) GetPrivForSignType(types.SignType) (sig.Priv, error)

Returns key that is used for signing the sign type.

func (*PartPriv) GetPub

func (priv *PartPriv) GetPub() sig.Pub

GetPub returns the coresponding BLS public key object

func (*PartPriv) New

func (priv *PartPriv) New() sig.Priv

New creates an empty BLS private key object

func (*PartPriv) NewSig

func (priv *PartPriv) NewSig() sig.Sig

NewSig returns an empty sig object of the same type.

func (*PartPriv) SetIndex

func (priv *PartPriv) SetIndex(idx sig.PubKeyIndex)

func (*PartPriv) ShallowCopy

func (priv *PartPriv) ShallowCopy() sig.Priv

Shallow copy makes a copy of the object without following pointers.

func (*PartPriv) Sign

func (priv *PartPriv) Sign(msg sig.SignedMessage) (sig.Sig, error)

Sign signs a message and returns the signature.

type PartPub

type PartPub struct {
	Blspub
	// contains filtered or unexported fields
}

func NewBlsPartPub

func NewBlsPartPub(idx sig.PubKeyIndex, n, t int, p kyber.Point) *PartPub

func (*PartPub) CheckCoinProof

func (bpp *PartPub) CheckCoinProof(msg sig.SignedMessage, prf sig.CoinProof) error

CheckCoinProof calls VerifySignature since coin proofs are signatures here.

func (*PartPub) CheckSignature

func (bpp *PartPub) CheckSignature(msg *sig.MultipleSignedMessage, sigItem *sig.SigItem) error

CheckSignature validates the partial threshold signature with the public key, it returns an error if a coin proof is included. Coin messages are verified as partial threshold signatures.

func (*PartPub) CombineProofs

func (bpp *PartPub) CombineProofs(myPriv sig.Priv, items []*sig.SigItem) (coinVal types.BinVal, err error)

CombineProofs combines the signatures to get a random binary value.

func (*PartPub) DeserializeSig

func (bpp *PartPub) DeserializeSig(m *messages.Message, _ types.SignType) (*sig.SigItem, int, error)

DeserializeSig takes a message and returns a BLS public key object and partial signature object as well as the number of bytes read

func (*PartPub) GetIndex

func (bpp *PartPub) GetIndex() sig.PubKeyIndex

GetIndex gets the index of the node represented by this key in the consensus participants

func (*PartPub) GetN

func (bpp *PartPub) GetN() int

Get the number of participants.

func (*PartPub) GetT

func (bpp *PartPub) GetT() int

Get the number of signatures needed for the threshold.

func (*PartPub) New

func (bpp *PartPub) New() sig.Pub

New generates an empty Blspub object

func (*PartPub) NewCoinProof

func (bpp *PartPub) NewCoinProof() sig.CoinProof

NewCoinProof returns an empty BLS partial signature object.

func (*PartPub) SetIndex

func (bpp *PartPub) SetIndex(index sig.PubKeyIndex)

func (*PartPub) ShallowCopy

func (bpp *PartPub) ShallowCopy() sig.Pub

Shallow copy makes a copy of the object without following pointers.

func (*PartPub) VerifySig

func (bpp *PartPub) VerifySig(msg sig.SignedMessage, asig sig.Sig) (bool, error)

type PartSig

type PartSig struct {
	Blssig
	// contains filtered or unexported fields
}

func (*PartSig) New

func (sig *PartSig) New() sig.Sig

New creates an empty sig object

type SharedPub

type SharedPub struct {
	Blspub
	// contains filtered or unexported fields
}

func NewSharedPub

func NewSharedPub(point kyber.Point, memberCount int) *SharedPub

func (*SharedPub) CheckSignature

func (pub *SharedPub) CheckSignature(msg *sig.MultipleSignedMessage, sigItem *sig.SigItem) error

CheckSignature validates the signature with the public key, it returns an error if a coin proof is included.

func (*SharedPub) GetPubID

func (pub *SharedPub) GetPubID() (sig.PubKeyID, error)

GetPubID returns the id for this pubkey. Given that there is only one threshold pub per consensus it returns PubKeyID("blssharedpub").

func (*SharedPub) GetSigMemberNumber

func (pub *SharedPub) GetSigMemberNumber() int

GetSigMemberNumber returns the number of nodes represented by this BLS pub key

func (*SharedPub) ShallowCopy

func (pub *SharedPub) ShallowCopy() sig.Pub

Shallow copy makes a copy of the object without following pointers.

type VRFProof

type VRFProof []byte

func (VRFProof) Decode

func (prf VRFProof) Decode(reader io.Reader) (n int, err error)

func (VRFProof) Encode

func (prf VRFProof) Encode(writer io.Writer) (n int, err error)

func (VRFProof) New

func (prf VRFProof) New() sig.VRFProof

Jump to

Keyboard shortcuts

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