summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-09-01 21:23:15 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-09-01 21:23:15 +0700
commit7ef966bd9e5075f4dd6260cbdf94565d57af5338 (patch)
treeabfb156a78e0c0cf7e76e1c9ddd0845e523d7cdf /crypto/test
parentSpan-base variants for IBufferedCipher (diff)
downloadBouncyCastle.NET-ed25519-7ef966bd9e5075f4dd6260cbdf94565d57af5338.tar.xz
Span-based variant of IBufferedCipher.ProcessByte
- also some followup for earlier IBufferedCipher changes
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/BlockCipherMonteCarloTest.cs42
-rw-r--r--crypto/test/src/crypto/test/BlockCipherVectorTest.cs28
2 files changed, 64 insertions, 6 deletions
diff --git a/crypto/test/src/crypto/test/BlockCipherMonteCarloTest.cs b/crypto/test/src/crypto/test/BlockCipherMonteCarloTest.cs
index 1a46a3201..1a7f04702 100644
--- a/crypto/test/src/crypto/test/BlockCipherMonteCarloTest.cs
+++ b/crypto/test/src/crypto/test/BlockCipherMonteCarloTest.cs
@@ -1,7 +1,5 @@
 using System;
-using System.IO;
 
-using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Utilities.Encoders;
 using Org.BouncyCastle.Utilities.Test;
 
@@ -65,7 +63,7 @@ namespace Org.BouncyCastle.Crypto.Tests
 				Fail("failed - " + "expected " + Hex.ToHexString(output) + " got " + Hex.ToHexString(outBytes));
 			}
 
-			cipher.Init(false, param);
+            cipher.Init(false, param);
 
 			for (int i = 0; i != iterations; i++)
 			{
@@ -78,6 +76,40 @@ namespace Org.BouncyCastle.Crypto.Tests
 			{
 				Fail("failed reversal");
 			}
-		}
-	}
+
+            // NOTE: .NET Core 2.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
+            cipher.Init(true, param);
+
+            Array.Copy(input, 0, outBytes, 0, outBytes.Length);
+
+            for (int i = 0; i != iterations; i++)
+            {
+                int len1 = cipher.ProcessBytes(outBytes, outBytes);
+
+				cipher.DoFinal(outBytes.AsSpan(len1));
+            }
+
+            if (!AreEqual(outBytes, output))
+            {
+                Fail("failed - " + "expected " + Hex.ToHexString(output) + " got " + Hex.ToHexString(outBytes));
+            }
+
+            cipher.Init(false, param);
+
+            for (int i = 0; i != iterations; i++)
+            {
+                int len1 = cipher.ProcessBytes(outBytes, outBytes);
+
+                cipher.DoFinal(outBytes.AsSpan(len1));
+            }
+
+            if (!AreEqual(input, outBytes))
+            {
+                Fail("failed reversal");
+            }
+#endif
+        }
+    }
 }
diff --git a/crypto/test/src/crypto/test/BlockCipherVectorTest.cs b/crypto/test/src/crypto/test/BlockCipherVectorTest.cs
index 1ce9fa477..58a138982 100644
--- a/crypto/test/src/crypto/test/BlockCipherVectorTest.cs
+++ b/crypto/test/src/crypto/test/BlockCipherVectorTest.cs
@@ -53,7 +53,7 @@ namespace Org.BouncyCastle.Crypto.Tests
 
 			int len1 = cipher.ProcessBytes(input, 0, input.Length, outBytes, 0);
 
-				cipher.DoFinal(outBytes, len1);
+			cipher.DoFinal(outBytes, len1);
 
 			if (!AreEqual(outBytes, output))
 			{
@@ -70,6 +70,32 @@ namespace Org.BouncyCastle.Crypto.Tests
 			{
 				Fail("failed reversal got " + Hex.ToHexString(outBytes));
 			}
+
+            // NOTE: .NET Core 2.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
+			cipher.Init(true, param);
+
+			len1 = cipher.ProcessBytes(input, outBytes);
+
+			cipher.DoFinal(outBytes.AsSpan(len1));
+
+			if (!AreEqual(outBytes, output))
+			{
+				Fail("failed - " + "expected " + Hex.ToHexString(output) + " got " + Hex.ToHexString(outBytes));
+			}
+
+			cipher.Init(false, param);
+
+			len2 = cipher.ProcessBytes(output, outBytes);
+
+			cipher.DoFinal(outBytes.AsSpan(len2));
+
+			if (!AreEqual(input, outBytes))
+			{
+				Fail("failed reversal got " + Hex.ToHexString(outBytes));
+			}
+#endif
 		}
 	}
 }