Org.BouncyCastle.Crypto.Digests.RipeMD320Digest.DoFinal C# (CSharp) Method

DoFinal() public method

public DoFinal ( byte output, int outOff ) : int
output byte
outOff int
return int
        public override int DoFinal(byte[] output, int outOff)
        {
            Finish();

            UnpackWord(H0, output, outOff);
            UnpackWord(H1, output, outOff + 4);
            UnpackWord(H2, output, outOff + 8);
            UnpackWord(H3, output, outOff + 12);
            UnpackWord(H4, output, outOff + 16);
            UnpackWord(H5, output, outOff + 20);
            UnpackWord(H6, output, outOff + 24);
            UnpackWord(H7, output, outOff + 28);
            UnpackWord(H8, output, outOff + 32);
            UnpackWord(H9, output, outOff + 36);

            Reset();

            return DigestLength;
        }

Usage Example

        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");
        }