public bool VerifySignature(string message, Point signature, CurvePoint publicKey) { var hash = BigIntegerExtensions.ComputeSHA1(message); // Console.WriteLine($"Hash of {message} is {hash}"); var w = signature.YCoordinate.FindModularInverse(Order); /// Console.WriteLine($"W: {w}"); if (w.HasValue) { var u1 = Multiply( BigInteger.Remainder( BigInteger.Multiply( hash, w.Value), Order)); var u2 = publicKey.Multiply( BigInteger.Remainder( BigInteger.Multiply( signature.XCoordinate, w.Value), publicKey.Order)); // Console.WriteLine($"u1: {u1}, u2: {u2}"); var check = Curve.CalculateAddition(u1.Point, u2.Point); var ret = BigInteger.Equals(check.XCoordinate, signature.XCoordinate); // Console.WriteLine($"Checkpoint {check} X == signature {signature} X: {ret}"); return(ret); } else { throw new InvalidOperationException($"Multiplicative modular inverse of {signature.YCoordinate} cannot be calculated on mod {Order}"); } }
public static BigInteger ToSecret(this CurvePoint point) { return(BigInteger.Remainder(BigInteger.Multiply(point.Point.XCoordinate, point.Point.YCoordinate), point.Curve.Modulo)); }
public CurvePoint(CurvePoint generation, BigInteger multiplier) { Curve = generation.Curve; Order = generation.Order; Point = Curve.CalculateMultiplication(generation.Point, multiplier); }