public virtual ITestResult Perform() { IDigest digest = new RipeMD320Digest(); byte[] resBuf = new byte[digest.GetDigestSize()]; for (int i = 0; i < messages.Length; i++) { byte[] m = Encoding.ASCII.GetBytes(messages[i]); digest.BlockUpdate(m, 0, m.Length); digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[i]))) { Console.WriteLine(Name + ": Vector " + i + " failed" + " expected: " + digests[i] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf)); return(new SimpleTestResult(false, Name + ": Vector " + i + " failed")); } } // // test 2 // byte[] m2 = Encoding.ASCII.GetBytes(messages[messages.Length - 1]); digest.BlockUpdate(m2, 0, m2.Length / 2); // clone the IDigest IDigest d = new RipeMD320Digest((RipeMD320Digest)digest); digest.BlockUpdate(m2, m2.Length / 2, m2.Length - m2.Length / 2); digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1]))) { return(new SimpleTestResult(false, "RipeMD320 failing clone test" + SimpleTest.NewLine + " expected: " + digests[digests.Length - 1] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } d.BlockUpdate(m2, m2.Length / 2, m2.Length - m2.Length / 2); d.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(digests[digests.Length - 1]))) { return(new SimpleTestResult(false, "RipeMD320 failing clone test - part 2" + SimpleTest.NewLine + " expected: " + digests[digests.Length - 1] + SimpleTest.NewLine + " got : " + Hex.ToHexString(resBuf))); } for (int i = 0; i < 1000000; i++) { digest.Update((byte)'a'); } digest.DoFinal(resBuf, 0); if (!Arrays.AreEqual(resBuf, Hex.Decode(MillionADigest))) { return(new SimpleTestResult(false, Name + ": Million a's failed")); } return(new SimpleTestResult(true, Name + ": Okay")); }
public static byte[] Hash320(byte[] bytes) { var digest = new RipeMD320Digest(); var output = new byte[digest.GetDigestSize()]; digest.BlockUpdate(bytes, 0, bytes.Length); digest.DoFinal(output, 0); return(output); }