summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-04-24 13:57:54 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-04-24 13:57:54 +0700
commit33dd73805be02f317801bd67e54bb87fef69f7ed (patch)
treeac33d9d47c36fb9d7bb03d08cab4e0e50e75506f /crypto/test
parentSparkleDigest perf. opts. (diff)
downloadBouncyCastle.NET-ed25519-33dd73805be02f317801bd67e54bb87fef69f7ed.tar.xz
SparkleDigest perf. opts.
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/SparkleTest.cs25
1 files changed, 19 insertions, 6 deletions
diff --git a/crypto/test/src/crypto/test/SparkleTest.cs b/crypto/test/src/crypto/test/SparkleTest.cs
index b98a6aedf..c9ef5e41d 100644
--- a/crypto/test/src/crypto/test/SparkleTest.cs
+++ b/crypto/test/src/crypto/test/SparkleTest.cs
@@ -49,29 +49,42 @@ namespace Org.BouncyCastle.Crypto.Tests
             ImplTestVectorsDigest(SparkleDigest.SparkleParameters.ESCH384, "384");
         }
 
+        private static IDigest CreateDigest(SparkleDigest.SparkleParameters sparkleParameters)
+        {
+            return new SparkleDigest(sparkleParameters);
+        }
+
         private static void ImplBenchDigest(SparkleDigest.SparkleParameters sparkleParameters)
         {
-            var digest = new SparkleDigest(sparkleParameters);
+            var sparkle = CreateDigest(sparkleParameters);
 
             byte[] data = new byte[1024];
             for (int i = 0; i < 1024; ++i)
             {
                 for (int j = 0; j < 1024; ++j)
                 {
-#if NET6_0_OR_GREATER
-                    digest.BlockUpdate(data);
+                    // NOTE: .NET Core 3.1 has Span<T>, but is tested against our .NET Standard 2.0 assembly.
+//#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+                    sparkle.BlockUpdate(data);
 #else
-                    digest.BlockUpdate(data, 0, 1024);
+                    sparkle.BlockUpdate(data, 0, 1024);
 #endif
                 }
 
-                digest.DoFinal(data, 0);
+                // NOTE: .NET Core 3.1 has Span<T>, but is tested against our .NET Standard 2.0 assembly.
+//#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+#if NET6_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+                sparkle.DoFinal(data);
+#else
+                sparkle.DoFinal(data, 0);
+#endif
             }
         }
 
         private static void ImplTestVectorsDigest(SparkleDigest.SparkleParameters sparkleParameters, string filename)
         {
-            SparkleDigest sparkle = new SparkleDigest(sparkleParameters);
+            var sparkle = CreateDigest(sparkleParameters);
             var map = new Dictionary<string, string>();
             using (var src = new StreamReader(
                 SimpleTest.GetTestDataAsStream("crypto.sparkle.LWC_HASH_KAT_" + filename + ".txt")))