Merge pull request #5 from iden3/decompress-modsqrt

return error if no ModSqrt(x, q) exist in babyjubjub decompress point
This commit is contained in:
Eduard S
2019-09-10 10:48:18 +02:00
committed by GitHub

View File

@@ -203,7 +203,10 @@ func (p *Point) Decompress(leBuf [32]byte) (*Point, error) {
xb.ModInverse(xb, constants.Q) xb.ModInverse(xb, constants.Q)
p.X.Mul(xa, xb) // xa / xb p.X.Mul(xa, xb) // xa / xb
p.X.Mod(p.X, constants.Q) p.X.Mod(p.X, constants.Q)
p.X.ModSqrt(p.X, constants.Q) noSqrt := p.X.ModSqrt(p.X, constants.Q)
if noSqrt == nil {
return nil, fmt.Errorf("x is not a square mod q")
}
if (sign && !PointCoordSign(p.X)) || (!sign && PointCoordSign(p.X)) { if (sign && !PointCoordSign(p.X)) || (!sign && PointCoordSign(p.X)) {
p.X.Mul(p.X, constants.MinusOne) p.X.Mul(p.X, constants.MinusOne)
} }