public bool VerifySignature(ECPoint publicKey, BigInteger e, BigInteger[] signature) { if (!ECCMath.RangeBetween(signature[0], BigInteger.One, ECCurve.n - 1)) { return(false); } if (!ECCMath.RangeBetween(signature[1], BigInteger.One, ECCurve.n - 1)) { return(false); } BigInteger w = ECCMath.InverseMod(signature[1], ECCurve.n); BigInteger u1 = ECCMath.MathMod((e * w), ECCurve.n); BigInteger u2 = ECCMath.MathMod((signature[0] * w), ECCurve.n); ECPoint point = ECCMath.PointAdd(ECCMath.ScalarMult(u1, ECCurve.G), ECCMath.ScalarMult(u2, publicKey)); //if (ECCMath.IsInfinityPoint(point)) // return false; return(ECCMath.MathMod(signature[0], ECCurve.n) == ECCMath.MathMod(point.X, ECCurve.n)); }
public bool VerifySignature_SM2(ECPoint publicKey, BigInteger e, BigInteger[] signature) { if (!ECCMath.RangeBetween(signature[0], BigInteger.One, ECCurve.n - 1)) { return(false); } if (!ECCMath.RangeBetween(signature[1], BigInteger.One, ECCurve.n - 1)) { return(false); } BigInteger t = ECCMath.MathMod((signature[0] + signature[1]), ECCurve.n); if (t.IsZero) { return(false); } ECPoint point = ECCMath.PointAdd(ECCMath.ScalarMult(signature[1], ECCurve.G), ECCMath.ScalarMult(t, publicKey)); BigInteger R = ECCMath.MathMod((e + point.X), ECCurve.n); return(R == signature[0]); }