Skip to content

Commit b7f7da6

Browse files
committed
Updated Schnorr hash
1 parent a6a2db8 commit b7f7da6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

util.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,13 @@ func GenerateSchnorrSignature(M string, X *big.Int, err error) (*bn256.G1, *bn25
100100
return nil, nil, "", nil, nil, err
101101
} else {
102102
P := new(bn256.G1).ScalarBaseMult(X)
103+
P_point := NewCurvePoint(P)
103104
k, _ := rand.Int(rand.Reader, bn256.Order)
104105
kG := new(bn256.G1).ScalarBaseMult(k)
106+
kG_point := NewCurvePoint(kG)
105107
h := sha3.NewKeccak256()
106108
h.Reset()
107-
h.Write([]byte(fmt.Sprintf("%s%s%s", M, P, kG)))
109+
h.Write([]byte(fmt.Sprintf("%s%s%s%s%s", M, P_point.X, P_point.Y, kG_point.X, kG_point.Y)))
108110
e, _ := new(big.Int).SetString(fmt.Sprintf("%x", h.Sum(nil)), 16)
109111
s := new(big.Int).Mod(new(big.Int).Add(k, new(big.Int).Mul(e, X)), bn256.Order)
110112
return P, kG, M, e, s, nil
@@ -115,12 +117,14 @@ func VerifySchnorrSignature(P *bn256.G1, M string, E, S *big.Int, err error) (bo
115117
if err != nil {
116118
return false, err
117119
} else {
120+
P_point := NewCurvePoint(P)
118121
sG := new(bn256.G1).ScalarBaseMult(S)
119122
eP := new(bn256.G1).ScalarMult(P, E)
120123
kG := new(bn256.G1).Add(sG, eP.Neg(eP))
124+
kG_point := NewCurvePoint(kG)
121125
h := sha3.NewKeccak256()
122126
h.Reset()
123-
h.Write([]byte(fmt.Sprintf("%s%s%s", M, P, kG)))
127+
h.Write([]byte(fmt.Sprintf("%s%s%s%s%s", M, P_point.X, P_point.Y, kG_point.X, kG_point.Y)))
124128
e, _ := new(big.Int).SetString(fmt.Sprintf("%x", h.Sum(nil)), 16)
125129
return (e.Cmp(E) == 0), nil
126130
}

0 commit comments

Comments
 (0)