@@ -120,14 +120,16 @@ func hashToCurve(m []byte) *edwards25519.ExtendedGroupElement {
120
120
// same as returned by Compute(m).
121
121
func (sk PrivateKey ) Prove (m []byte ) (vrf , proof []byte ) {
122
122
x , skhr := sk .expandSecret ()
123
- var cH , rH [64 ]byte
124
- var r , c , minusC , t , grB , hrB , iiB [32 ]byte
123
+ var sH , rH [64 ]byte
124
+ var r , s , minusS , t , gB , grB , hrB , hxB , hB [32 ]byte
125
125
var ii , gr , hr edwards25519.ExtendedGroupElement
126
126
127
- hm := hashToCurve (m )
128
- edwards25519 .GeScalarMult (& ii , x , hm )
129
- ii .ToBytes (& iiB )
127
+ h := hashToCurve (m )
128
+ h .ToBytes (& hB )
129
+ edwards25519 .GeScalarMult (& ii , x , h )
130
+ ii .ToBytes (& hxB )
130
131
132
+ // use hash of private-, public-key and msg as randomness source:
131
133
hash := sha3 .NewShake256 ()
132
134
hash .Write (skhr [:])
133
135
hash .Write (sk [32 :]) // public key, as in ed25519
@@ -137,26 +139,32 @@ func (sk PrivateKey) Prove(m []byte) (vrf, proof []byte) {
137
139
edwards25519 .ScReduce (& r , & rH )
138
140
139
141
edwards25519 .GeScalarMultBase (& gr , & r )
140
- edwards25519 .GeScalarMult (& hr , & r , hm )
142
+ edwards25519 .GeScalarMult (& hr , & r , h )
141
143
gr .ToBytes (& grB )
142
144
hr .ToBytes (& hrB )
145
+ gB = edwards25519 .BaseBytes
143
146
147
+ // H2(g, h, g^x, h^x, g^r, h^r, m)
148
+ hash .Write (gB [:])
149
+ hash .Write (hB [:])
150
+ hash .Write (sk [32 :]) // ed25519 public-key
151
+ hash .Write (hxB [:])
144
152
hash .Write (grB [:])
145
153
hash .Write (hrB [:])
146
154
hash .Write (m )
147
- hash .Read (cH [:])
155
+ hash .Read (sH [:])
148
156
hash .Reset ()
149
- edwards25519 .ScReduce (& c , & cH )
157
+ edwards25519 .ScReduce (& s , & sH )
150
158
151
- edwards25519 .ScNeg (& minusC , & c )
152
- edwards25519 .ScMulAdd (& t , x , & minusC , & r )
159
+ edwards25519 .ScNeg (& minusS , & s )
160
+ edwards25519 .ScMulAdd (& t , x , & minusS , & r )
153
161
154
162
proof = make ([]byte , ProofSize )
155
- copy (proof [:32 ], c [:])
163
+ copy (proof [:32 ], s [:])
156
164
copy (proof [32 :64 ], t [:])
157
- copy (proof [64 :96 ], iiB [:])
165
+ copy (proof [64 :96 ], hxB [:])
158
166
159
- hash .Write (iiB [:]) // const length: Size
167
+ hash .Write (hxB [:])
160
168
hash .Write (m )
161
169
vrf = make ([]byte , Size )
162
170
hash .Read (vrf [:])
@@ -169,15 +177,15 @@ func (pkBytes PublicKey) Verify(m, vrfBytes, proof []byte) bool {
169
177
if len (proof ) != ProofSize || len (vrfBytes ) != Size || len (pkBytes ) != PublicKeySize {
170
178
return false
171
179
}
172
- var pk , c , cRef , t , vrf , iiB , ABytes , BBytes [32 ]byte
180
+ var pk , s , sRef , t , vrf , hxB , hB , gB , ABytes , BBytes [32 ]byte
173
181
copy (vrf [:], vrfBytes )
174
182
copy (pk [:], pkBytes [:])
175
- copy (c [:32 ], proof [:32 ])
183
+ copy (s [:32 ], proof [:32 ])
176
184
copy (t [:32 ], proof [32 :64 ])
177
- copy (iiB [:], proof [64 :96 ])
185
+ copy (hxB [:], proof [64 :96 ])
178
186
179
187
hash := sha3 .NewShake256 ()
180
- hash .Write (iiB [:]) // const length
188
+ hash .Write (hxB [:]) // const length
181
189
hash .Write (m )
182
190
var hCheck [Size ]byte
183
191
hash .Read (hCheck [:])
@@ -191,25 +199,33 @@ func (pkBytes PublicKey) Verify(m, vrfBytes, proof []byte) bool {
191
199
if ! P .FromBytesBaseGroup (& pk ) {
192
200
return false
193
201
}
194
- if ! ii .FromBytesBaseGroup (& iiB ) {
202
+ if ! ii .FromBytesBaseGroup (& hxB ) {
195
203
return false
196
204
}
197
- edwards25519 .GeDoubleScalarMultVartime (& A , & c , & P , & t )
205
+ edwards25519 .GeDoubleScalarMultVartime (& A , & s , & P , & t )
198
206
A .ToBytes (& ABytes )
207
+ gB = edwards25519 .BaseBytes
199
208
200
- hm := hashToCurve (m )
201
- edwards25519 .GeDoubleScalarMultVartime (& hmtP , & t , hm , & [32 ]byte {})
202
- edwards25519 .GeDoubleScalarMultVartime (& iicP , & c , & ii , & [32 ]byte {})
209
+ h := hashToCurve (m ) // h = H1(m)
210
+ h .ToBytes (& hB )
211
+ edwards25519 .GeDoubleScalarMultVartime (& hmtP , & t , h , & [32 ]byte {})
212
+ edwards25519 .GeDoubleScalarMultVartime (& iicP , & s , & ii , & [32 ]byte {})
203
213
iicP .ToExtended (& iic )
204
214
hmtP .ToExtended (& B )
205
215
edwards25519 .GeAdd (& B , & B , & iic )
206
216
B .ToBytes (& BBytes )
207
217
208
- var cH [64 ]byte
209
- hash .Write (ABytes [:]) // const length
210
- hash .Write (BBytes [:]) // const length
218
+ var sH [64 ]byte
219
+ // sRef = H2(g, h, g^x, v, g^t·G^s,H1(m)^t·v^s, m), with v=H1(m)^x=h^x
220
+ hash .Write (gB [:])
221
+ hash .Write (hB [:])
222
+ hash .Write (pkBytes )
223
+ hash .Write (hxB [:])
224
+ hash .Write (ABytes [:]) // const length (g^t*G^s)
225
+ hash .Write (BBytes [:]) // const length (H1(m)^t*v^s)
211
226
hash .Write (m )
212
- hash .Read (cH [:])
213
- edwards25519 .ScReduce (& cRef , & cH )
214
- return cRef == c
227
+ hash .Read (sH [:])
228
+
229
+ edwards25519 .ScReduce (& sRef , & sH )
230
+ return sRef == s
215
231
}
0 commit comments