summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-03-04 19:03:02 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-03-04 19:03:02 +0700
commitd00b465123d798e3fa9f72f8a93151d9b193573b (patch)
tree46b1fa9a5d3732ee54451aaaad3e91d080637034 /crypto/test
parentFIx method Write(ReadOnlySpan<byte>) in LimitedBuffer (diff)
downloadBouncyCastle.NET-ed25519-d00b465123d798e3fa9f72f8a93151d9b193573b.tar.xz
Add regression test for #524
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/crypto/test/PSSTest.cs40
1 files changed, 39 insertions, 1 deletions
diff --git a/crypto/test/src/crypto/test/PSSTest.cs b/crypto/test/src/crypto/test/PSSTest.cs
index 599c2c8c7..72558e62f 100644
--- a/crypto/test/src/crypto/test/PSSTest.cs
+++ b/crypto/test/src/crypto/test/PSSTest.cs
@@ -4,6 +4,7 @@ using NUnit.Framework;
 
 using Org.BouncyCastle.Crypto.Digests;
 using Org.BouncyCastle.Crypto.Engines;
+using Org.BouncyCastle.Crypto.Generators;
 using Org.BouncyCastle.Crypto.Parameters;
 using Org.BouncyCastle.Crypto.Signers;
 using Org.BouncyCastle.Math;
@@ -215,7 +216,44 @@ namespace Org.BouncyCastle.Crypto.Tests
 			get { return "PSSTest"; }
 		}
 
-		private void doTestSig(
+		[Test]
+        public void TestRegression_GitHub_bc_csharp_524()
+		{
+            SecureRandom secureRandom = new SecureRandom();
+
+            var kpg = new RsaKeyPairGenerator();
+			kpg.Init(new RsaKeyGenerationParameters(BigInteger.ValueOf(17), secureRandom, 1024, 100));
+            var keyPair = kpg.GenerateKeyPair();
+
+			var digest = new Sha256Digest();
+
+			var hash = SecureRandom.GetNextBytes(secureRandom, digest.GetDigestSize());
+
+			var signer = PssSigner.CreateRawSigner(new RsaBlindedEngine(), digest);
+            signer.Init(true, keyPair.Private);
+            // 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
+            signer.BlockUpdate(hash);
+#else
+			signer.BlockUpdate(hash, 0, hash.Length);
+#endif
+            byte[] signature = signer.GenerateSignature();
+
+            signer.Init(false, keyPair.Public);
+			// 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
+            signer.BlockUpdate(hash);
+#else
+			signer.BlockUpdate(hash, 0, hash.Length);
+#endif
+            bool verified = signer.VerifySignature(signature);
+
+			Assert.IsTrue(verified);
+        }
+
+        private void doTestSig(
 			int					id,
 			RsaKeyParameters	pub,
 			RsaKeyParameters	prv,