diff options
-rw-r--r-- | crypto/src/crypto/digests/SparkleDigest.cs | 4 | ||||
-rw-r--r-- | crypto/test/src/crypto/test/SparkleTest.cs | 16 |
2 files changed, 16 insertions, 4 deletions
diff --git a/crypto/src/crypto/digests/SparkleDigest.cs b/crypto/src/crypto/digests/SparkleDigest.cs index 1209d9c58..3729f3ee1 100644 --- a/crypto/src/crypto/digests/SparkleDigest.cs +++ b/crypto/src/crypto/digests/SparkleDigest.cs @@ -168,7 +168,7 @@ namespace Org.BouncyCastle.Crypto.Digests state[(STATE_UINTS >> 1) - 1] ^= 1U << 24; // padding - m_buf[m_bufPos++] = 0x80; + m_buf[m_bufPos] = 0x80; while(++m_bufPos < RATE_BYTES) { m_buf[m_bufPos] = 0x00; @@ -211,7 +211,7 @@ namespace Org.BouncyCastle.Crypto.Digests state[(STATE_UINTS >> 1) - 1] ^= 1U << 24; // padding - m_buf[m_bufPos++] = 0x80; + m_buf[m_bufPos] = 0x80; while(++m_bufPos < RATE_BYTES) { m_buf[m_bufPos] = 0x00; diff --git a/crypto/test/src/crypto/test/SparkleTest.cs b/crypto/test/src/crypto/test/SparkleTest.cs index c9ef5e41d..584b90a52 100644 --- a/crypto/test/src/crypto/test/SparkleTest.cs +++ b/crypto/test/src/crypto/test/SparkleTest.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using NUnit.Framework; @@ -84,6 +85,7 @@ namespace Org.BouncyCastle.Crypto.Tests private static void ImplTestVectorsDigest(SparkleDigest.SparkleParameters sparkleParameters, string filename) { + Random random = new Random(); var sparkle = CreateDigest(sparkleParameters); var map = new Dictionary<string, string>(); using (var src = new StreamReader( @@ -99,10 +101,20 @@ namespace Org.BouncyCastle.Crypto.Tests byte[] expected = Hex.Decode(map["MD"]); map.Clear(); - sparkle.BlockUpdate(ptByte, 0, ptByte.Length); byte[] hash = new byte[sparkle.GetDigestSize()]; + + sparkle.BlockUpdate(ptByte, 0, ptByte.Length); sparkle.DoFinal(hash, 0); Assert.IsTrue(Arrays.AreEqual(expected, hash)); + + if (ptByte.Length > 1) + { + int split = random.Next(1, ptByte.Length - 1); + sparkle.BlockUpdate(ptByte, 0, split); + sparkle.BlockUpdate(ptByte, split, ptByte.Length - split); + sparkle.DoFinal(hash, 0); + Assert.IsTrue(Arrays.AreEqual(expected, hash)); + } } else { |