public static Proof GetProof(byte[] hash) { Prover.hash = hash; v = BigInteger.Abs(new BigInteger(Cryptography.RandomBytes(16))); var c = BigInteger.Abs(Heuristic()); var proof = new Proof { C = c, R = R(c), T = T(), Y = T() }; //Console.WriteLine($"C: {proof.C.ToString()}\nR: {proof.R.ToString()}\nT: {proof.T.ToString()}\nY: {proof.Y.ToString()}"); //Console.WriteLine($"v: {v.ToString()}"); //Console.WriteLine($"X: {X().ToString()}"); return(proof); }
public bool Verify(Proof proof) { BigInteger result; if (proof.R < 0) { var inverValue = BigInteger.ModPow(g, -proof.R, prime); var f = BigInteger.ModPow(proof.Y, proof.C, prime); var inv = Inverse(inverValue, prime); result = BigInteger.Multiply(inv, f) % prime; } else { var q = BigInteger.ModPow(g, proof.R, prime); var k = BigInteger.ModPow(proof.Y, proof.C, prime) % prime; result = BigInteger.Multiply(q, k); } return(proof.T.Equals(result)); }