bbs

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package bbs contains BBS+ signing primitives and keys.

Index

Constants

View Source
const MaxMessagesCount = 1024

MaxMessagesCount bounds the number of messages a BBS+ proof may claim to cover. Generator derivation in ToPublicKeyWithGenerators performs one hash-to-curve operation per message, so an unbounded, attacker-controlled count (up to 0xFFFF on the wire) can be used to force excessive CPU work during verification.

Variables

This section is empty.

Functions

func ComputeB

func ComputeB(
	s *ml.Zr,
	messages []*SignatureMessage,
	key *PublicKeyWithGenerators,
	curve *ml.Curve,
) *ml.G1

func FrFromOKM

func FrFromOKM(message []byte, curve *ml.Curve) *ml.Zr

func FrToRepr

func FrToRepr(fr *ml.Zr) *ml.Zr

func NewCommitmentBuilder

func NewCommitmentBuilder(expectedSize int) *commitmentBuilder

func NewPoKPayload

func NewPoKPayload(messagesCount int, revealed []int) *pokPayload

func ParsePoKPayload

func ParsePoKPayload(bytes []byte) (*pokPayload, error)

Types

type BBSG2Pub

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

BBSG2Pub defines BBS+ signature scheme where public key is a point in the field of G2. BBS+ signature scheme (as defined in https://eprint.iacr.org/2016/663.pdf, section 4.3).

func New

func New(curve *ml.Curve) *BBSG2Pub

New creates a new BBSG2Pub.

func (*BBSG2Pub) DeriveProof

func (bbs *BBSG2Pub) DeriveProof(messages [][]byte, sigBytes, nonce, pubKeyBytes []byte,
	revealedIndexes []int) ([]byte, error)

DeriveProof derives a proof of BBS+ signature with some messages disclosed.

func (*BBSG2Pub) DeriveProofZr

func (bbs *BBSG2Pub) DeriveProofZr(messagesFr []*SignatureMessage, sigBytes, nonce, pubKeyBytes []byte,
	revealedIndexes []int) ([]byte, error)

DeriveProofZr derives a proof of BBS+ signature with some messages disclosed. The messages are supplied as scalars and not bytes.

func (*BBSG2Pub) Sign

func (bbs *BBSG2Pub) Sign(messages [][]byte, privKeyBytes []byte) ([]byte, error)

Sign signs the one or more messages using private key in compressed form.

func (*BBSG2Pub) SignWithKey

func (bbs *BBSG2Pub) SignWithKey(messages [][]byte, privKey *PrivateKey) ([]byte, error)

SignWithKey signs the one or more messages using BBS+ key pair.

func (*BBSG2Pub) SignWithKeyB

func (bbs *BBSG2Pub) SignWithKeyB(b *ml.G1, messagesCount int, privKey *PrivateKey) ([]byte, error)

SignWithKeyB signs the one or more messages using BBS+ key pair. Messages are already committed in the element `b`, which the caller is supposed to have constructed properly. This call enables a clean construction of blind signing protocols, where `b` is constructed jointly by requester and signer.

func (*BBSG2Pub) SignWithKeyFr

func (bbs *BBSG2Pub) SignWithKeyFr(messagesFr []*SignatureMessage, messagesCount int, privKey *PrivateKey) ([]byte, error)

SignWithKeyFr signs the one or more messages using BBS+ key pair. The messages are supplied as scalars and not bytes.

func (*BBSG2Pub) Verify

func (bbs *BBSG2Pub) Verify(messages [][]byte, sigBytes, pubKeyBytes []byte) (err error)

Verify makes BLS BBS12-381 signature verification.

func (*BBSG2Pub) VerifyProof

func (bbs *BBSG2Pub) VerifyProof(messagesBytes [][]byte, proof, nonce, pubKeyBytes []byte) (err error)

VerifyProof verifies BBS+ signature proof for one ore more revealed messages.

func (*BBSG2Pub) VerifyProofFr

func (bbs *BBSG2Pub) VerifyProofFr(messages []*SignatureMessage, proof, nonce, pubKeyBytes []byte) (err error)

VerifyProofFr verifies BBS+ signature proof for one ore more revealed messages. The messages are supplied as scalars and not bytes.

type BBSLib

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

func NewBBSLib

func NewBBSLib(curve *ml.Curve) *BBSLib

func (*BBSLib) GenerateKeyPair

func (b *BBSLib) GenerateKeyPair(h func() hash.Hash, seed []byte) (*PublicKey, *PrivateKey, error)

GenerateKeyPair generates BBS+ PublicKey and PrivateKey pair.

func (*BBSLib) NewPoKOfSignature

func (bl *BBSLib) NewPoKOfSignature(signature *Signature, messages []*SignatureMessage, revealedIndexes []int,
	pubKey *PublicKeyWithGenerators) (*PoKOfSignature, error)

NewPoKOfSignature creates a new PoKOfSignature.

func (*BBSLib) NewProverCommittingG1

func (bl *BBSLib) NewProverCommittingG1() *ProverCommittingG1

NewProverCommittingG1 creates a new ProverCommittingG1.

func (*BBSLib) ParseProofG1

func (b *BBSLib) ParseProofG1(bytes []byte) (*ProofG1, error)

ParseProofG1 parses ProofG1 from bytes.

func (*BBSLib) ParseSignature

func (b *BBSLib) ParseSignature(sigBytes []byte) (*Signature, error)

ParseSignature parses a Signature from bytes.

func (*BBSLib) ParseSignatureProof

func (b *BBSLib) ParseSignatureProof(sigProofBytes []byte) (proof *PoKOfSignatureProof, err error)

ParseSignatureProof parses a signature proof.

func (*BBSLib) ToPublicKeyWithGenerators

func (b *BBSLib) ToPublicKeyWithGenerators(pubKey *PublicKey, messagesCount int) (*PublicKeyWithGenerators, error)

ToPublicKeyWithGenerators creates PublicKeyWithGenerators using the cache owned by BBSLib.

func (*BBSLib) UnmarshalPrivateKey

func (b *BBSLib) UnmarshalPrivateKey(privKeyBytes []byte) (*PrivateKey, error)

UnmarshalPrivateKey unmarshals PrivateKey.

func (*BBSLib) UnmarshalPublicKey

func (b *BBSLib) UnmarshalPublicKey(pubKeyBytes []byte) (*PublicKey, error)

UnmarshalPublicKey parses a PublicKey from bytes.

type PoKOfSignature

type PoKOfSignature struct {
	PokVC2 *ProverCommittedG1
	// contains filtered or unexported fields
}

PoKOfSignature is Proof of Knowledge of a Signature that is used by the prover to construct PoKOfSignatureProof.

func (*PoKOfSignature) GenerateProof

func (pos *PoKOfSignature) GenerateProof(challengeHash *ml.Zr) *PoKOfSignatureProof

GenerateProof generates PoKOfSignatureProof proof from PoKOfSignature signature.

func (*PoKOfSignature) ToBytes

func (pos *PoKOfSignature) ToBytes() []byte

ToBytes converts PoKOfSignature to bytes.

type PoKOfSignatureProof

type PoKOfSignatureProof struct {
	ProofVC2 *ProofG1

	VC2ProofVerifier
	// contains filtered or unexported fields
}

PoKOfSignatureProof defines BLS signature proof. It is the actual proof that is sent from prover to verifier.

func (*PoKOfSignatureProof) GetBytesForChallenge

func (sp *PoKOfSignatureProof) GetBytesForChallenge(revealedMessages map[int]*SignatureMessage,
	pubKey *PublicKeyWithGenerators) []byte

GetBytesForChallenge creates bytes for proof challenge.

func (*PoKOfSignatureProof) ToBytes

func (sp *PoKOfSignatureProof) ToBytes() []byte

ToBytes converts PoKOfSignatureProof to bytes.

func (*PoKOfSignatureProof) Verify

func (sp *PoKOfSignatureProof) Verify(challenge *ml.Zr, pubKey *PublicKeyWithGenerators,
	revealedMessages map[int]*SignatureMessage, messages []*SignatureMessage) error

Verify verifies PoKOfSignatureProof.

type PoKOfSignatureProvider

type PoKOfSignatureProvider struct {
	VC2SignatureProvider

	VerifySig bool

	Curve *ml.Curve
	Bl    *BBSLib
}

func (*PoKOfSignatureProvider) PoKOfSignature

func (p *PoKOfSignatureProvider) PoKOfSignature(signature *Signature, messages []*SignatureMessage, revealedIndexes []int,
	pubKey *PublicKeyWithGenerators) (*PoKOfSignature, error)

func (*PoKOfSignatureProvider) PoKOfSignatureB

func (p *PoKOfSignatureProvider) PoKOfSignatureB(signature *Signature, messages []*SignatureMessage, revealedIndexes []int,
	pubKey *PublicKeyWithGenerators, b *ml.G1) (*PoKOfSignature, error)

type PrivateKey

type PrivateKey struct {
	FR *ml.Zr
	// contains filtered or unexported fields
}

PrivateKey defines BLS Public Key.

func (*PrivateKey) Marshal

func (k *PrivateKey) Marshal() ([]byte, error)

Marshal marshals PrivateKey.

func (*PrivateKey) PublicKey

func (k *PrivateKey) PublicKey() *PublicKey

PublicKey returns a Public Key as G2 point generated from the Private Key.

type ProofG1

type ProofG1 struct {
	Commitment *ml.G1
	Responses  []*ml.Zr
}

ProofG1 is a proof of knowledge of a signature and hidden messages.

func NewProofG1

func NewProofG1(commitment *ml.G1, responses []*ml.Zr) *ProofG1

NewProofG1 creates a new ProofG1.

func (*ProofG1) ToBytes

func (pg1 *ProofG1) ToBytes() []byte

ToBytes converts ProofG1 to bytes.

func (*ProofG1) Verify

func (pg1 *ProofG1) Verify(bases []*ml.G1, commitment *ml.G1, challenge *ml.Zr) error

Verify verifies the ProofG1.

type ProofNonce

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

ProofNonce is a nonce for Proof of Knowledge proof.

func ParseProofNonce

func ParseProofNonce(proofNonceBytes []byte, curve *ml.Curve) *ProofNonce

ParseProofNonce creates a new ProofNonce from bytes.

func (*ProofNonce) ToBytes

func (pn *ProofNonce) ToBytes() []byte

ToBytes converts ProofNonce into bytes.

type ProverCommittedG1

type ProverCommittedG1 struct {
	Bases           []*ml.G1
	BlindingFactors []*ml.Zr
	Commitment      *ml.G1
}

ProverCommittedG1 helps to generate a ProofG1.

func (*ProverCommittedG1) GenerateProof

func (g *ProverCommittedG1) GenerateProof(challenge *ml.Zr, secrets []*ml.Zr) *ProofG1

GenerateProof generates proof ProofG1 for all secrets.

func (*ProverCommittedG1) ToBytes

func (g *ProverCommittedG1) ToBytes() []byte

ToBytes converts ProverCommittedG1 to bytes.

type ProverCommittingG1

type ProverCommittingG1 struct {
	BlindingFactors []*ml.Zr
	// contains filtered or unexported fields
}

ProverCommittingG1 is a proof of knowledge of messages in a vector commitment.

func (*ProverCommittingG1) Commit

func (pc *ProverCommittingG1) Commit(base *ml.G1)

Commit append a base point and randomly generated blinding factor.

func (*ProverCommittingG1) Finish

func (pc *ProverCommittingG1) Finish() *ProverCommittedG1

Finish helps to generate ProverCommittedG1 after commitment of all base points.

type PublicKey

type PublicKey struct {
	PointG2 *ml.G2
	// contains filtered or unexported fields
}

PublicKey defines BLS Public Key.

func (*PublicKey) Marshal

func (pk *PublicKey) Marshal() ([]byte, error)

Marshal marshals PublicKey.

func (*PublicKey) ToPublicKeyWithGenerators

func (pk *PublicKey) ToPublicKeyWithGenerators(messagesCount int) (*PublicKeyWithGenerators, error)

ToPublicKeyWithGenerators creates PublicKeyWithGenerators from the PublicKey.

type PublicKeyWithGenerators

type PublicKeyWithGenerators struct {
	H0 *ml.G1
	H  []*ml.G1

	MessagesCount int
	// contains filtered or unexported fields
}

PublicKeyWithGenerators extends PublicKey with a blinding generator h0, a commitment to the secret key w, and a generator for each message h.

type Signature

type Signature struct {
	A *ml.G1
	E *ml.Zr
	S *ml.Zr
	// contains filtered or unexported fields
}

Signature defines BLS signature.

func (*Signature) ToBytes

func (s *Signature) ToBytes() ([]byte, error)

ToBytes converts signature to bytes using compression of G1 point and E, S FR points.

func (*Signature) Verify

func (s *Signature) Verify(messages []*SignatureMessage, pubKey *PublicKeyWithGenerators) error

Verify is used for signature verification.

func (*Signature) VerifyWithB

func (s *Signature) VerifyWithB(messages []*SignatureMessage, pubKey *PublicKeyWithGenerators, b *ml.G1) error

VerifyWithB is used for signature verification when B is already computed.

type SignatureMessage

type SignatureMessage struct {
	FR  *ml.Zr
	Idx int
}

SignatureMessage defines a message to be used for a signature check.

func MessagesToFr

func MessagesToFr(messages [][]byte, curve *ml.Curve) []*SignatureMessage

func ParseSignatureMessage

func ParseSignatureMessage(message []byte, idx int, curve *ml.Curve) *SignatureMessage

ParseSignatureMessage parses SignatureMessage from bytes.

type VC2ProofVerifier

type VC2ProofVerifier interface {
	Verify(*ml.Zr, *PublicKeyWithGenerators, map[int]*SignatureMessage, []*SignatureMessage, *ProofG1, *ml.G1) error
}

type VC2SignatureProvider

type VC2SignatureProvider interface {
	New(*ml.G1, *ml.Zr, *PublicKeyWithGenerators, *ml.Zr, []*SignatureMessage, map[int]*SignatureMessage) (*ProverCommittedG1, []*ml.Zr)
}

Jump to

Keyboard shortcuts

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