summary refs log tree commit diff
path: root/crypto/test/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-11-06 21:18:24 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-11-06 21:18:24 +0700
commit2746e44d62b031d0981d2f6b1bc3c7d2a34d64ec (patch)
tree2c7bf5cebc66cd4ade8e30fa6a3a2c8221fcf839 /crypto/test/src
parentCMS support for OtherRevocationInfoFormat (diff)
downloadBouncyCastle.NET-ed25519-2746e44d62b031d0981d2f6b1bc3c7d2a34d64ec.tar.xz
Add some dotnet ECDsa interop methods
Diffstat (limited to 'crypto/test/src')
-rw-r--r--crypto/test/src/security/test/TestDotNetUtil.cs32
1 files changed, 31 insertions, 1 deletions
diff --git a/crypto/test/src/security/test/TestDotNetUtil.cs b/crypto/test/src/security/test/TestDotNetUtil.cs
index b83a94a36..5d0177ead 100644
--- a/crypto/test/src/security/test/TestDotNetUtil.cs
+++ b/crypto/test/src/security/test/TestDotNetUtil.cs
@@ -22,6 +22,36 @@ namespace Org.BouncyCastle.Security.Tests
 	[TestFixture]
     public class TestDotNetUtilities
 	{
+//#if NETCOREAPP1_0_OR_GREATER || NET47_OR_GREATER || NETSTANDARD1_6_OR_GREATER
+#if NET6_0_OR_GREATER
+        [Test]
+		public void TestECDsaInterop()
+		{
+			byte[] data = new byte[1024];
+
+            for (int i = 0; i < 10; ++i)
+			{
+                var ecDsa = ECDsa.Create(ECCurve.NamedCurves.nistP256);
+				byte[] sig1 = ecDsa.SignData(data, HashAlgorithmName.SHA256);
+
+                AsymmetricCipherKeyPair kp = DotNetUtilities.GetECDsaKeyPair(ecDsa);
+                Assert.IsNotNull(kp.Private);
+                Assert.IsNotNull(kp.Public);
+                ISigner signer = SignerUtilities.GetSigner("SHA256withPLAIN-ECDSA");
+
+                signer.Init(false, kp.Public);
+                signer.BlockUpdate(data, 0, data.Length);
+                Assert.IsTrue(signer.VerifySignature(sig1));
+
+				signer.Init(true, kp.Private);
+				signer.BlockUpdate(data, 0, data.Length);
+				byte[] sig2 = signer.GenerateSignature();
+
+                Assert.IsTrue(ecDsa.VerifyData(data, sig2, HashAlgorithmName.SHA256));
+            }
+        }
+#endif
+
 //#if NET5_0_OR_GREATER
 #if NET6_0_OR_GREATER
         [SupportedOSPlatform("windows")]
@@ -29,7 +59,7 @@ namespace Org.BouncyCastle.Security.Tests
         [Test]
 		public void TestRsaInterop()
 		{
-			for (int i = 0; i < 100; ++i)
+			for (int i = 0; i < 10; ++i)
 			{
 				RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
 				RSAParameters rp = rsa.ExportParameters(true);