@@ -67,29 +67,68 @@ func hashPointToR(pubs []kyber.Point) ([]kyber.Scalar, error) {
67
67
return coefs , nil
68
68
}
69
69
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
+
70
109
// 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 )
74
113
}
75
114
76
115
// 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 )
80
119
}
81
120
82
121
// Verify checks the given BLS signature S on the message m using the public
83
122
// key X by verifying that the equality e(H(m), X) == e(H(m), x*B2) ==
84
123
// 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 )
88
127
}
89
128
90
129
// 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 ) {
93
132
if len (sigs ) != mask .CountEnabled () {
94
133
return nil , errors .New ("length of signatures and public keys must match" )
95
134
}
@@ -99,7 +138,7 @@ func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (k
99
138
return nil , err
100
139
}
101
140
102
- agg := suite . G1 () .Point ()
141
+ agg := scheme . sigGroup .Point ()
103
142
for i , buf := range sigs {
104
143
peerIndex := mask .IndexOfNthEnabled (i )
105
144
if peerIndex < 0 {
@@ -108,7 +147,7 @@ func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (k
108
147
return nil , errors .New ("couldn't find the index" )
109
148
}
110
149
111
- sig := suite . G1 () .Point ()
150
+ sig := scheme . sigGroup .Point ()
112
151
err = sig .UnmarshalBinary (buf )
113
152
if err != nil {
114
153
return nil , err
@@ -125,14 +164,14 @@ func AggregateSignatures(suite pairing.Suite, sigs [][]byte, mask *sign.Mask) (k
125
164
126
165
// AggregatePublicKeys aggregates a set of public keys (similarly to
127
166
// 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 ) {
130
169
coefs , err := hashPointToR (mask .Publics ())
131
170
if err != nil {
132
171
return nil , err
133
172
}
134
173
135
- agg := suite . G2 () .Point ()
174
+ agg := scheme . keyGroup .Point ()
136
175
for i := 0 ; i < mask .CountEnabled (); i ++ {
137
176
peerIndex := mask .IndexOfNthEnabled (i )
138
177
if peerIndex < 0 {
@@ -149,3 +188,43 @@ func AggregatePublicKeys(suite pairing.Suite, mask *sign.Mask) (kyber.Point, err
149
188
150
189
return agg , nil
151
190
}
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