From 18ba492d74cdc5ac1a9a2de4e67a344da46a7175 Mon Sep 17 00:00:00 2001 From: Abd ar-Rahman Hamidi Date: Wed, 9 Jan 2019 17:02:28 +0500 Subject: [PATCH] Add checking z sign in affineFromJacobian --- crypto/secp256k1/curve.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/crypto/secp256k1/curve.go b/crypto/secp256k1/curve.go index 5409ee1d2c..8f83cccad9 100644 --- a/crypto/secp256k1/curve.go +++ b/crypto/secp256k1/curve.go @@ -116,6 +116,10 @@ func (BitCurve *BitCurve) IsOnCurve(x, y *big.Int) bool { // affineFromJacobian reverses the Jacobian transform. See the comment at the // top of the file. func (BitCurve *BitCurve) affineFromJacobian(x, y, z *big.Int) (xOut, yOut *big.Int) { + if z.Sign() == 0 { + return new(big.Int), new(big.Int) + } + zinv := new(big.Int).ModInverse(z, BitCurve.P) zinvsq := new(big.Int).Mul(zinv, zinv)