Skip to content

Commit

Permalink
Switch to signatures on G2, Resolves #96
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu committed Apr 15, 2024
1 parent fb1c6bf commit 2c710e3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 15 deletions.
7 changes: 3 additions & 4 deletions blssig/aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/drand/kyber"
"github.com/drand/kyber/sign"
"github.com/drand/kyber/sign/bdn"
"golang.org/x/xerrors"
)

Expand All @@ -22,7 +21,7 @@ func (v Verifier) Aggregate(pubkeys []gpbft.PubKey, signatures [][]byte) ([]byte
return nil, xerrors.Errorf("converting public keys to mask: %w", err)
}

aggSigPoint, err := bdn.AggregateSignatures(v.suite, signatures, mask)
aggSigPoint, err := v.scheme.AggregateSignatures(signatures, mask)
if err != nil {
return nil, xerrors.Errorf("computing aggregate signature: %w", err)
}
Expand All @@ -40,12 +39,12 @@ func (v Verifier) VerifyAggregate(msg []byte, signature []byte, pubkeys []gpbft.
return xerrors.Errorf("converting public keys to mask: %w", err)
}

aggPubKey, err := bdn.AggregatePublicKeys(v.suite, mask)
aggPubKey, err := v.scheme.AggregatePublicKeys(mask)
if err != nil {
return xerrors.Errorf("aggregating public keys: %w", err)
}

return bdn.Verify(v.suite, aggPubKey, msg, signature)
return v.scheme.Verify(aggPubKey, msg, signature)
}

func (v Verifier) pubkeysToMask(pubkeys []gpbft.PubKey) (*sign.Mask, error) {
Expand Down
4 changes: 2 additions & 2 deletions blssig/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ type Signer struct {
privKey kyber.Scalar
}

func SignerWithKeyOnG2(pub gpbft.PubKey, privKey kyber.Scalar) *Signer {
func SignerWithKeyOnG1(pub gpbft.PubKey, privKey kyber.Scalar) *Signer {
return &Signer{
scheme: bls.NewSchemeOnG1(bls12381.NewBLS12381Suite()),
scheme: bls.NewSchemeOnG2(bls12381.NewBLS12381Suite()),
pubKey: pub,
privKey: privKey,
}
Expand Down
8 changes: 5 additions & 3 deletions blssig/verifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import (

type Verifier struct {
suite pairing.Suite
scheme *bdn.Scheme
keyGroup kyber.Group
}

func VerifierWithKeyOnG2() Verifier {
func VerifierWithKeyOnG1() Verifier {
suite := bls12381.NewBLS12381Suite()
return Verifier{
suite: suite,
keyGroup: suite.G2(),
scheme: bdn.NewSchemeOnG2(suite),
keyGroup: suite.G1(),
}
}

Expand All @@ -32,5 +34,5 @@ func (v Verifier) Verify(pubKey gpbft.PubKey, msg, sig []byte) error {
return xerrors.Errorf("the public key is a null point")
}

return bdn.Verify(v.suite, pubKeyPoint, msg, sig)
return v.scheme.Verify(pubKeyPoint, msg, sig)
}
6 changes: 3 additions & 3 deletions sim/blssig.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ func (b *BLSSigningBackend) Sign(sender gpbft.PubKey, msg []byte) ([]byte, error
func NewBLSSigningBackend() *BLSSigningBackend {
suite := bls12381.NewBLS12381Suite()
return &BLSSigningBackend{
Verifier: blssig.VerifierWithKeyOnG2(),
Verifier: blssig.VerifierWithKeyOnG1(),
signersByPubKey: make(map[string]*blssig.Signer),
suite: suite,
scheme: bdn.NewSchemeOnG1(suite),
scheme: bdn.NewSchemeOnG2(suite),
}
}

Expand All @@ -43,6 +43,6 @@ func (b *BLSSigningBackend) GenerateKey() (gpbft.PubKey, any) {
if err != nil {
panic(err)
}
b.signersByPubKey[string(pubKeyB)] = blssig.SignerWithKeyOnG2(pubKeyB, priv)
b.signersByPubKey[string(pubKeyB)] = blssig.SignerWithKeyOnG1(pubKeyB, priv)
return pubKeyB, priv
}
6 changes: 3 additions & 3 deletions test/signing_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ type (
func TestBLSSigning(t *testing.T) {
var (
blsSuit = bls12381.NewBLS12381Suite()
blsSchema = bdn.NewSchemeOnG1(blsSuit)
blsSchema = bdn.NewSchemeOnG2(blsSuit)
)
suite.Run(t, NewSigningSuite(func(t *testing.T) (gpbft.PubKey, gpbft.Signer) {
privKey, pubKey := blsSchema.NewKeyPair(blsSuit.RandomStream())
pubKeyB, err := pubKey.MarshalBinary()
require.NoError(t, err)
return pubKeyB, blssig.SignerWithKeyOnG2(pubKeyB, privKey)
}, blssig.VerifierWithKeyOnG2()))
return pubKeyB, blssig.SignerWithKeyOnG1(pubKeyB, privKey)
}, blssig.VerifierWithKeyOnG1()))
}

func TestFakeSigning(t *testing.T) {
Expand Down

0 comments on commit 2c710e3

Please sign in to comment.