summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-24 18:14:44 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-24 18:14:44 +0700
commit78b79a9ea5e06818702b91b2aca6a83208f9fa5b (patch)
treed161b00131909ded7951c7b70232a0016a5350e3 /crypto/test
parentSparkleDigest perf. opts. (diff)
downloadBouncyCastle.NET-ed25519-78b79a9ea5e06818702b91b2aca6a83208f9fa5b.tar.xz
SparkleDIgest: improved tests and fixed regression
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/SparkleTest.cs16
1 files changed, 14 insertions, 2 deletions
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
                     {