diff options
author | Tim Whittington <bc@whittington.net.nz> | 2013-10-12 19:46:25 +1300 |
---|---|---|
committer | Tim Whittington <bc@whittington.net.nz> | 2013-10-20 21:32:33 +1300 |
commit | f64b37993aaec3f2baaab236af58c295b06c9f92 (patch) | |
tree | ced19bc4695aafe6112dbada80601d5cf8def51f /crypto/test/src | |
parent | Port SkeinDigest and SkeinMac from bc-java. (diff) | |
download | BouncyCastle.NET-ed25519-f64b37993aaec3f2baaab236af58c295b06c9f92.tar.xz |
Port Memoable digest support from bc-java.
Diffstat (limited to 'crypto/test/src')
-rw-r--r-- | crypto/test/src/crypto/test/DigestTest.cs | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/crypto/test/src/crypto/test/DigestTest.cs b/crypto/test/src/crypto/test/DigestTest.cs index 533e87181..930979643 100644 --- a/crypto/test/src/crypto/test/DigestTest.cs +++ b/crypto/test/src/crypto/test/DigestTest.cs @@ -2,6 +2,7 @@ using System; using Org.BouncyCastle.Crypto; +using Org.BouncyCastle.Utilities; using Org.BouncyCastle.Utilities.Encoders; using Org.BouncyCastle.Utilities.Test; @@ -35,9 +36,9 @@ namespace Org.BouncyCastle.Crypto.Tests for (int i = 0; i < input.Length - 1; i++) { - byte[] m = toByteArray(input[i]); + byte[] msg = toByteArray(input[i]); - vectorTest(digest, i, resBuf, m, Hex.Decode(results[i])); + vectorTest(digest, i, resBuf, msg, Hex.Decode(results[i])); } byte[] lastV = toByteArray(input[input.Length - 1]); @@ -68,6 +69,45 @@ namespace Org.BouncyCastle.Crypto.Tests { Fail("failing second clone vector test", results[results.Length - 1], Hex.ToHexString(resBuf)); } + + // + // memo test + // + IMemoable m = (IMemoable)digest; + + digest.BlockUpdate(lastV, 0, lastV.Length/2); + + // copy the Digest + IMemoable copy1 = m.Copy(); + IMemoable copy2 = copy1.Copy(); + + digest.BlockUpdate(lastV, lastV.Length/2, lastV.Length - lastV.Length/2); + digest.DoFinal(resBuf, 0); + + if (!AreEqual(lastDigest, resBuf)) + { + Fail("failing memo vector test", results[results.Length - 1], Hex.ToHexString(resBuf)); + } + + m.Reset(copy1); + + digest.BlockUpdate(lastV, lastV.Length/2, lastV.Length - lastV.Length/2); + digest.DoFinal(resBuf, 0); + + if (!AreEqual(lastDigest, resBuf)) + { + Fail("failing memo reset vector test", results[results.Length - 1], Hex.ToHexString(resBuf)); + } + + IDigest md = (IDigest)copy2; + + md.BlockUpdate(lastV, lastV.Length/2, lastV.Length - lastV.Length/2); + md.DoFinal(resBuf, 0); + + if (!AreEqual(lastDigest, resBuf)) + { + Fail("failing memo copy vector test", results[results.Length - 1], Hex.ToHexString(resBuf)); + } } private byte[] toByteArray( |