Skip to content

Commit 44c64cd

Browse files
committed
fix: check EdDSA signature values not zero
1 parent 2a0b47d commit 44c64cd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

internal/generator/edwards/eddsa/template/marshal.go.tmpl

+7
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,27 @@ func (sig *Signature) SetBytes(buf []byte) (int, error) {
118118
// R < P_mod (to avoid malleability)
119119
// P_mod = field of def of the twisted Edwards = Fr snark field
120120
fpMod := fr.Modulus()
121+
zero := big.NewInt(0)
121122
var bufBigInt big.Int
122123
bufCopy := make([]byte, fr.Bytes)
123124
for i := 0; i < sizeFr; i++ {
124125
bufCopy[sizeFr-1-i] = buf[i]
125126
}
126127
bufCopy[0] &= mUnmask
127128
bufBigInt.SetBytes(bufCopy)
129+
if bufBigInt.Cmp(zero) == 0 {
130+
return 0, ErrZero
131+
}
128132
if bufBigInt.Cmp(fpMod) != -1 {
129133
return 0, ErrRBiggerThanPMod
130134
}
131135

132136
// S < R_mod (to avoid malleability)
133137
// R_mod is the relevant group size of the twisted Edwards NOT the fr snark field so it's supposedly smaller
134138
bufBigInt.SetBytes(buf[sizeFr : 2*sizeFr])
139+
if bufBigInt.Cmp(zero) == 0 {
140+
return 0, ErrZero
141+
}
135142
cp := twistededwards.GetEdwardsCurve()
136143
if bufBigInt.Cmp(&cp.Order) != -1 {
137144
return 0, ErrSBiggerThanRMod

0 commit comments

Comments
 (0)