private static bool checkDuplexModByHash(SHA3 sha3) { byte[] m1 = new byte[72 * 8 - 1]; byte[] m2 = new byte[72 * 8 - 1]; byte[] m = new byte[m1.Length + m2.Length + 1]; var rnd = new Random(98732796); for (int i = 0; i < m.Length; i++) { if (m.Length - i == 72) { m[i] = 0x81; } else { m[i] = (byte)rnd.Next(0, 255); } } rnd = new Random(98732796); for (int i = 0, j = 0, k = 0; i < m.Length - 1; i++) { if (i % 144 >= 72 || k >= m2.Length) { m1[j++] = (byte)rnd.Next(0, 255); } else { m2[k++] = (byte)rnd.Next(0, 255); } } byte[] hash = sha3.getHash512(m); byte[] gamma = sha3.getDuplexMod(m1, m2); byte[] tmp = new byte[64]; BytesBuilder.CopyTo(gamma, tmp, 0, -1, 72 * 7); bool errorFlag = false; for (int i = 0; i < hash.Length; i++) { if (hash[i] != tmp[i]) { errorFlag = true; } } if (errorFlag) { Console.WriteLine("DuplexMod and hash unequal, duplexMod is incorrect"); } else { Console.WriteLine("Well. DuplexMod and hash equal, duplexMod is correct."); } return(!errorFlag); }
public override void ProcessCryptoVariant(long variant) { SHA3 gs1 = new SHA3(0); SHA3 gs2 = new SHA3(0); var key = prepareKey(variant); var s = prepareOIV(variant); var bt = Convert.FromBase64String("GL4C/c+hpZrVQcIg771ujdjHN/2Jqoj+UpS6cZ5fbG7zU1qwXMMg5P3YgnLY9byB1laMMu557wK1J7EewmkKJ0wPjA8u3uVO7oOhmtVSc6rnGMCaTrRHtLVLv9a9dBFnNxGjxbCLOcaGkZZYeBT1KUraXh/5reXVQmedmkijKvEwJ4d3CPSMUoPGca+lv7I="); var g1 = gs1.getDuplex(bt); var g2 = gs2.getDuplex(key); g1 = gs1.getDuplex(g2, true); g2 = gs2.getDuplex(g1, true); g1 = gs1.getDuplex(g2, true); g2 = gs2.getDuplex(g1, true); g1 = gs1.getDuplex(g2, true); g2 = gs2.getDuplex(g1, true); g1 = gs1.getDuplex(g2, true); g2 = gs2.getDuplex(g1, true); g1 = gs1.getDuplex(g2, true); g2 = gs2.getDuplex(g1, true); var gamma = gs1.getDuplexMod(g1, g2); if (gamma[0] == 1) { if ((variant & 1) > 0) { c1f++; } else { c1t++; } } calcResult(gamma, variant, key); }
private static void duplexModTest(ref int errorFlag) { var keccak = new SHA3(0); byte[] a, b, c, e; a = new byte[72 * 3]; b = new byte[72 * 3]; e = keccak.getDuplexMod(a, b); c = keccak.getDuplexMod(a, b); if (!BytesBuilder.Compare(c, e)) { goto error; } c = keccak.getDuplexMod(a, b, true); if (e[0] == c[0]) { goto error; } b[b.Length - 1] = 1; c = keccak.getDuplexMod(a, b); int i; BytesBuilder.Compare(c, e, out i); if (i != 72 * 2) { goto error; } b[b.Length - 1] = 0; b[b.Length - 72] = 1; c = keccak.getDuplexMod(a, b); BytesBuilder.Compare(c, e, out i); if (i != 72 * 2) { goto error; } b[b.Length - 72] = 0; b[b.Length - 144] = 1; c = keccak.getDuplexMod(a, b); BytesBuilder.Compare(c, e, out i); if (i != 72 || e[72 * 2] == c[72 * 2]) { goto error; } b[b.Length - 144] = 0; b[b.Length - 145] = 1; c = keccak.getDuplexMod(a, b); BytesBuilder.Compare(c, e, out i); if (i != 0 || e[72 * 2] == c[72 * 2] || e[72] == c[72]) { goto error; } b[b.Length - 145] = 0; b[0] = 1; c = keccak.getDuplexMod(a, b); BytesBuilder.Compare(c, e, out i); if (i != 0 || e[72 * 2] == c[72 * 2] || e[72] == c[72]) { goto error; } return; error: Interlocked.Increment(ref errorFlag); Console.WriteLine("duplexModTest is incorrect"); }