/// <summary> /// I'm not 100% sure that this is the best way to get this hash /// </summary> private static BigInteger Hash2(byte[] data) { drbg.Reseed(data, hash2String); var x = drbg.GenerateInteger(GroupParameters.SubgroupSize); return(mod.Pow(GroupParameters.Generator, x)); }
private static void TestMultiExp() { Console.Write("Testing multi-exponentiation"); int k = 111; var seed = new byte[1000]; var r = new Random(); r.NextBytes(seed); var rnd = new HMACDRBG(seed); var mod = new Modular(new BigInteger(5555555566666777777)); var g = Enumerable.Range(0, k).Select(i => rnd.GenerateInteger(BigInteger.One << r.Next(200) + 200)).ToArray(); var me = new MultiExponentiation(mod.Modulus, g); for (int i = 0; i < 1000; ++i) { var e = Enumerable.Range(0, k).Select(j => rnd.GenerateInteger(BigInteger.One << r.Next(100) + 100)).ToArray(); //var z = mod.Pow(g, e, ref cache); var z = me.Pow(e); var z2 = BigInteger.One; for (int j = 0; j < k; ++j) { z2 = (z2 * BigInteger.ModPow(g[j], e[j], mod.Modulus)).Mod(mod.Modulus); } if (!z.Equals(z2)) { Console.WriteLine("ouch"); } if (i % 100 == 0) { Console.Write('.'); } r.NextBytes(seed); rnd.Reseed(seed); } Console.WriteLine(); }
public static RingSignature GenerateSignature(byte[] message, BigInteger[] publicKeys, BigInteger privateKey, int identity) { var r = rng.GenerateInteger(GroupParameters.SubgroupSize); var c = new BigInteger[publicKeys.Length]; var b = BigInteger.Zero; for (int i = 0; i < publicKeys.Length; ++i) { if (i != identity) { c[i] = rng.GenerateInteger(GroupParameters.SubgroupSize); b = (b + c[i]).Mod(GroupParameters.SubgroupSize); } } var x = (BigInteger[])publicKeys.Clone(); x[identity] = GroupParameters.Generator; c[identity] = r; var a = mod.Pow(x, c); var L = ConcatInts(null, publicKeys); var h = Hash2(L); var y0 = mod.Pow(h, privateKey); var prefix = ByteArrayUtils.ConcatBytes(ConcatInts(L, y0), message); var h1 = Hash1(ConcatInts(prefix, a, mod.Pow(new[] { h, y0 }, new[] { r, b }))); c[identity] = (h1 - b).Mod(GroupParameters.SubgroupSize); var s = (r - c[identity] * privateKey).Mod(GroupParameters.SubgroupSize); return(new RingSignature(y0, s, c)); }