private void RunTestVector(TestVector v) { int bits = v.Bits; int partialBits = bits % 8; byte[] expected = v.Output; //Console.WriteLine(v.Algorithm + " " + bits + "-bit"); //Console.WriteLine(Hex.ToHexString(v.Message).ToUpper()); //Console.WriteLine(Hex.ToHexString(expected).ToUpper()); int outLen = expected.Length; MyShakeDigest d = CreateDigest(v.Algorithm); byte[] output = new byte[outLen]; byte[] m = v.Message; if (partialBits == 0) { d.BlockUpdate(m, 0, m.Length); d.DoFinal(output, 0, outLen); } else { d.BlockUpdate(m, 0, m.Length - 1); d.MyDoFinal(output, 0, outLen, m[m.Length - 1], partialBits); } if (!Arrays.AreEqual(expected, output)) { Fail(v.Algorithm + " " + v.Bits + "-bit test vector hash mismatch"); //Console.Error.WriteLine(v.Algorithm + " " + v.Bits + "-bit test vector hash mismatch"); //Console.Error.WriteLine(Hex.ToHexString(output).ToUpper()); } }
private void RunTestVector(TestVector v) { int bits = v.Bits; int partialBits = bits % 8; byte[] expected = v.Output; //Console.WriteLine(v.Algorithm + " " + bits + "-bit"); //Console.WriteLine(Hex.ToHexString(v.Message).ToUpper()); //Console.WriteLine(Hex.ToHexString(expected).ToUpper()); int outLen = expected.Length; MyShakeDigest d = CreateDigest(v.Algorithm); byte[] output = new byte[outLen]; byte[] m = v.Message; if (partialBits == 0) { d.BlockUpdate(m, 0, m.Length); d.DoFinal(output, 0, outLen); } else { d.BlockUpdate(m, 0, m.Length - 1); d.MyDoFinal(output, 0, outLen, m[m.Length - 1], partialBits); } if (!Arrays.AreEqual(expected, output)) { Fail(v.Algorithm + " " + v.Bits + "-bit test vector hash mismatch"); //Console.Error.WriteLine(v.Algorithm + " " + v.Bits + "-bit test vector hash mismatch"); //Console.Error.WriteLine(Hex.ToHexString(output).ToUpper()); } if (partialBits == 0) { d = CreateDigest(v.Algorithm); m = v.Message; d.BlockUpdate(m, 0, m.Length); d.DoOutput(output, 0, outLen / 2); d.DoOutput(output, outLen / 2, output.Length - outLen / 2); if (!Arrays.AreEqual(expected, output)) { Fail(v.Algorithm + " " + v.Bits + "-bit test vector extended hash mismatch"); } try { d.Update((byte)0x01); Fail("no exception"); } catch (InvalidOperationException e) { if (!"attempt to absorb while squeezing".Equals(e.Message)) { Fail("wrong exception"); } } d = CreateDigest(v.Algorithm); m = v.Message; d.BlockUpdate(m, 0, m.Length); d.DoOutput(output, 0, outLen / 2); d.DoFinal(output, outLen / 2, output.Length - outLen / 2); if (!Arrays.AreEqual(expected, output)) { Fail(v.Algorithm + " " + v.Bits + "-bit test vector extended doFinal hash mismatch"); } d.Update((byte)0x01); // this should be okay as we've reset on DoFinal() } }