summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
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
 		}
 	}
 }