Skip to content

Commit 266eb7b

Browse files
matejpavlovicAnomalRoilKubuxu
authored
Add Support for signatures on the G2 curve for BDN (#53)
* Add support for signatures on G2 to bdn * Adapt bdn_test.go to new BDN interface * Make API functions methods of the Scheme type * Generalize G1- and G2-related comments * Fixing bdn tests * Make the BDN test suite generic over suite and scheme * Keeping public APIs from v1 --------- Co-authored-by: Yolan Romailler <anomalroil@users.noreply.github.com> Co-authored-by: Jakub Sztandera <kubuxu@protocol.ai>
1 parent a5d64f6 commit 266eb7b

File tree

4 files changed

+214
-76
lines changed

4 files changed

+214
-76
lines changed

go.mod

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ go 1.18
44

55
require (
66
github.com/cloudflare/circl v1.3.7
7-
github.com/drand/kyber-bls12381 v0.2.5
8-
github.com/jonboulle/clockwork v0.3.0
9-
github.com/stretchr/testify v1.8.2
7+
github.com/drand/kyber-bls12381 v0.3.1
8+
github.com/jonboulle/clockwork v0.4.0
9+
github.com/stretchr/testify v1.9.0
1010
go.dedis.ch/fixbuf v1.0.3
1111
go.dedis.ch/protobuf v1.0.11
12-
golang.org/x/crypto v0.17.0
13-
golang.org/x/sys v0.15.0
12+
golang.org/x/crypto v0.21.0
13+
golang.org/x/sys v0.18.0
1414
)
1515

1616
require (

go.sum

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/drand/kyber-bls12381 v0.2.5 h1:4ugiCmXQsvgAuylSk929rK49WGFxCxT/7ArH2vw6Tlg=
7-
github.com/drand/kyber-bls12381 v0.2.5/go.mod h1:8fm2tmRaAdYRGMTh5tjF7qrGHywC+rmM5hrUFL+9fCI=
8-
github.com/jonboulle/clockwork v0.3.0 h1:9BSCMi8C+0qdApAp4auwX0RkLGUjs956h0EkuQymUhg=
9-
github.com/jonboulle/clockwork v0.3.0/go.mod h1:Pkfl5aHPm1nk2H9h0bjmnJD/BcgbGXUBGnn1kMkgxc8=
6+
github.com/drand/kyber-bls12381 v0.3.1 h1:KWb8l/zYTP5yrvKTgvhOrk2eNPscbMiUOIeWBnmUxGo=
7+
github.com/drand/kyber-bls12381 v0.3.1/go.mod h1:H4y9bLPu7KZA/1efDg+jtJ7emKx+ro3PU7/jWUVt140=
8+
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
9+
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
1010
github.com/kilic/bls12-381 v0.1.0 h1:encrdjqKMEvabVQ7qYOKu1OvhqpK4s47wDYtNiPtlp4=
1111
github.com/kilic/bls12-381 v0.1.0/go.mod h1:vDTTHJONJ6G+P2R74EhnyotQDTliQDnFEwhdmfzw1ig=
1212
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1313
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1414
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
15-
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
16-
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
1715
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
18-
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19-
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
20-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
21-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
16+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
17+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
2218
go.dedis.ch/fixbuf v1.0.3 h1:hGcV9Cd/znUxlusJ64eAlExS+5cJDIyTyEG+otu5wQs=
2319
go.dedis.ch/fixbuf v1.0.3/go.mod h1:yzJMt34Wa5xD37V5RTdmp38cz3QhMagdGoem9anUalw=
2420
go.dedis.ch/kyber/v3 v3.0.4/go.mod h1:OzvaEnPvKlyrWyp3kGXlFdp7ap1VC6RkZDTaPikqhsQ=
@@ -29,14 +25,13 @@ go.dedis.ch/protobuf v1.0.7/go.mod h1:pv5ysfkDX/EawiPqcW3ikOxsL5t+BqnV6xHSmE79KI
2925
go.dedis.ch/protobuf v1.0.11 h1:FTYVIEzY/bfl37lu3pR4lIj+F9Vp1jE8oh91VmxKgLo=
3026
go.dedis.ch/protobuf v1.0.11/go.mod h1:97QR256dnkimeNdfmURz0wAMNVbd1VmLXhG1CrTYrJ4=
3127
golang.org/x/crypto v0.0.0-20190123085648-057139ce5d2b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
32-
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
33-
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
28+
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
29+
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
3430
golang.org/x/sys v0.0.0-20190124100055-b90733256f2e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3531
golang.org/x/sys v0.0.0-20201101102859-da207088b7d1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
36-
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
37-
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
32+
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
33+
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
3834
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3935
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
40-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4136
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
4237
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

sign/bdn/bdn.go

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,68 @@ func hashPointToR(pubs []kyber.Point) ([]kyber.Scalar, error) {
6767
return coefs, nil
6868
}
6969

70+
type Scheme struct {
71+
blsScheme sign.AggregatableScheme
72+
sigGroup kyber.Group
73+
keyGroup kyber.Group
74+
pairing func(signature, public, hashedPoint kyber.Point) bool
75+
}
76+
77+
// NewSchemeOnG1 returns a sign.Scheme that uses G1 for its signature space and G2
78+
// for its public keys
79+
func NewSchemeOnG1(suite pairing.Suite) *Scheme {
80+
sigGroup := suite.G1()
81+
keyGroup := suite.G2()
82+
pairing := func(public, hashedMsg, sigPoint kyber.Point) bool {
83+
return suite.ValidatePairing(hashedMsg, public, sigPoint, keyGroup.Point().Base())
84+
}
85+
return &Scheme{
86+
blsScheme: bls.NewSchemeOnG1(suite),
87+
sigGroup: sigGroup,
88+
keyGroup: keyGroup,
89+
pairing: pairing,
90+
}
91+
}
92+
93+
// NewSchemeOnG2 returns a sign.Scheme that uses G2 for its signature space and
94+
// G1 for its public key
95+
func NewSchemeOnG2(suite pairing.Suite) *Scheme {
96+
sigGroup := suite.G2()
97+
keyGroup := suite.G1()
98+
pairing := func(public, hashedMsg, sigPoint kyber.Point) bool {
99+
return suite.ValidatePairing(public, hashedMsg, keyGroup.Point().Base(), sigPoint)
100+
}
101+
return &Scheme{
102+
blsScheme: bls.NewSchemeOnG2(suite),
103+
sigGroup: sigGroup,
104+
keyGroup: keyGroup,
105+
pairing: pairing,
106+
}
107+
}
108+
70109
// NewKeyPair creates a new BLS signing key pair. The private key x is a scalar
71-
// and the public key X is a point on curve G2.
72-
func NewKeyPair(suite pairing.Suite, random cipher.Stream) (kyber.Scalar, kyber.Point) {
73-
return bls.NewSchemeOnG1(suite).NewKeyPair(random)
110+
// and the public key X is a point on the scheme's key group.
111+
func (scheme *Scheme) NewKeyPair(random cipher.Stream) (kyber.Scalar, kyber.Point) {
112+
return scheme.blsScheme.NewKeyPair(random)
74113
}
75114

76115
// Sign creates a BLS signature S = x * H(m) on a message m using the private
77-
// key x. The signature S is a point on curve G1.
78-
func Sign(suite pairing.Suite, x kyber.Scalar, msg []byte) ([]byte, error) {
79-
return bls.NewSchemeOnG1(suite).Sign(x, msg)
116+
// key x. The signature S is a point on the scheme's signature group.
117+
func (scheme *Scheme) Sign(x kyber.Scalar, msg []byte) ([]byte, error) {
118+
return scheme.blsScheme.Sign(x, msg)
80119
}
81120

82121
// Verify checks the given BLS signature S on the message m using the public
83122
// key X by verifying that the equality e(H(m), X) == e(H(m), x*B2) ==
84123
// e(x*H(m), B2) == e(S, B2) holds where e is the pairing operation and B2 is
85-
// the base point from curve G2.
86-
func Verify(suite pairing.Suite, x kyber.Point, msg, sig []byte) error {
87-
return bls.NewSchemeOnG1(suite).Verify(x, msg, sig)
124+
// the base point from the scheme's key group.
125+
func (scheme *Scheme) Verify(x kyber.Point, msg, sig []byte) error {
126+
return scheme.blsScheme.Verify(x, msg, sig)
88127
}
89128

90129
// AggregateSignatures aggregates the signatures using a coefficient for each
91-
// one of them where c = H(pk) and H: G2 -> R with R = {1, ..., 2^128}
92-
func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (kyber.Point, error) {
130+
// one of them where c = H(pk) and H: keyGroup -> R with R = {1, ..., 2^128}
131+
func (scheme *Scheme) AggregateSignatures(sigs [][]byte, mask *sign.Mask) (kyber.Point, error) {
93132
if len(sigs) != mask.CountEnabled() {
94133
return nil, errors.New("length of signatures and public keys must match")
95134
}
@@ -99,7 +138,7 @@ func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (k
99138
return nil, err
100139
}
101140

102-
agg := suite.G1().Point()
141+
agg := scheme.sigGroup.Point()
103142
for i, buf := range sigs {
104143
peerIndex := mask.IndexOfNthEnabled(i)
105144
if peerIndex < 0 {
@@ -108,7 +147,7 @@ func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (k
108147
return nil, errors.New("couldn't find the index")
109148
}
110149

111-
sig := suite.G1().Point()
150+
sig := scheme.sigGroup.Point()
112151
err = sig.UnmarshalBinary(buf)
113152
if err != nil {
114153
return nil, err
@@ -125,14 +164,14 @@ func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (k
125164

126165
// AggregatePublicKeys aggregates a set of public keys (similarly to
127166
// AggregateSignatures for signatures) using the hash function
128-
// H: G2 -> R with R = {1, ..., 2^128}.
129-
func AggregatePublicKeys(suite pairing.Suite, mask *sign.Mask) (kyber.Point, error) {
167+
// H: keyGroup -> R with R = {1, ..., 2^128}.
168+
func (scheme *Scheme) AggregatePublicKeys(mask *sign.Mask) (kyber.Point, error) {
130169
coefs, err := hashPointToR(mask.Publics())
131170
if err != nil {
132171
return nil, err
133172
}
134173

135-
agg := suite.G2().Point()
174+
agg := scheme.keyGroup.Point()
136175
for i := 0; i < mask.CountEnabled(); i++ {
137176
peerIndex := mask.IndexOfNthEnabled(i)
138177
if peerIndex < 0 {
@@ -149,3 +188,43 @@ func AggregatePublicKeys(suite pairing.Suite, mask *sign.Mask) (kyber.Point, err
149188

150189
return agg, nil
151190
}
191+
192+
// v1 API Deprecated ----------------------------------
193+
194+
// NewKeyPair creates a new BLS signing key pair. The private key x is a scalar
195+
// and the public key X is a point on curve G2.
196+
// Deprecated: use the new scheme methods instead.
197+
func NewKeyPair(suite pairing.Suite, random cipher.Stream) (kyber.Scalar, kyber.Point) {
198+
return NewSchemeOnG1(suite).NewKeyPair(random)
199+
}
200+
201+
// Sign creates a BLS signature S = x * H(m) on a message m using the private
202+
// key x. The signature S is a point on curve G1.
203+
// Deprecated: use the new scheme methods instead.
204+
func Sign(suite pairing.Suite, x kyber.Scalar, msg []byte) ([]byte, error) {
205+
return NewSchemeOnG1(suite).Sign(x, msg)
206+
}
207+
208+
// Verify checks the given BLS signature S on the message m using the public
209+
// key X by verifying that the equality e(H(m), X) == e(H(m), x*B2) ==
210+
// e(x*H(m), B2) == e(S, B2) holds where e is the pairing operation and B2 is
211+
// the base point from curve G2.
212+
// Deprecated: use the new scheme methods instead.
213+
func Verify(suite pairing.Suite, x kyber.Point, msg, sig []byte) error {
214+
return NewSchemeOnG1(suite).Verify(x, msg, sig)
215+
}
216+
217+
// AggregateSignatures aggregates the signatures using a coefficient for each
218+
// one of them where c = H(pk) and H: G2 -> R with R = {1, ..., 2^128}
219+
// Deprecated: use the new scheme methods instead.
220+
func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (kyber.Point, error) {
221+
return NewSchemeOnG1(suite).AggregateSignatures(sigs, mask)
222+
}
223+
224+
// AggregatePublicKeys aggregates a set of public keys (similarly to
225+
// AggregateSignatures for signatures) using the hash function
226+
// H: G2 -> R with R = {1, ..., 2^128}.
227+
// Deprecated: use the new scheme methods instead.
228+
func AggregatePublicKeys(suite pairing.Suite, mask *sign.Mask) (kyber.Point, error) {
229+
return NewSchemeOnG1(suite).AggregatePublicKeys(mask)
230+
}

0 commit comments

Comments
 (0)