public (CurvePoint, BigInteger) CreateKeys() { var closeKey = Algos.GenerateRandom(1, Curve.n - 1); var openKey = Curve.G.MulOnScalar(closeKey); return(openKey, closeKey); }
public (ElGamalKey, ElGamalKey) GenerateKeys() { BigInteger prime, safePrime, generator; while (true) { prime = Algos.GenetateRandomPrime( BigInteger.Pow(2, dimension / 4), BigInteger.Pow(2, dimension - 1), Algos.MillerRabin ); safePrime = 2 * prime + 1; if (Algos.MillerRabin(safePrime)) { break; } } while (true) { generator = Algos.GenetateRandomPrime(3, safePrime - 2, Algos.MillerRabin); if (BigInteger.ModPow(generator, 2, safePrime) != 1 && BigInteger.ModPow(generator, prime, safePrime) != 1) { break; } } var closeKey = new ElGamalKey(Algos.GenerateRandom(2, safePrime - 2), generator, safePrime); var openKey = new ElGamalKey(BigInteger.ModPow(generator, closeKey.Key, safePrime), generator, safePrime); return(openKey, closeKey); }
public Signature CreateSignature(BigInteger closeKey) { var z = GetHash(); while (true) { var k = Algos.GenerateRandom(1, Curve.n - 1); var P = Curve.G.MulOnScalar(k); var r = P.x % Curve.n; if (r == 0) { continue; } var s = (Inverse(k, Curve.n) * (z + r * closeKey)) % Curve.n; if (s == 0) { continue; } return(new Signature(r, s)); } }