summary refs log tree commit diff
path: root/crypto/test/src/cms
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-02-10 12:45:32 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-02-10 12:45:32 +0700
commita66a03b4b40dd3b60d8c1b0b11026abc21bb0967 (patch)
tree0e73f05e6781af64a41f4322c5bf9e87b5371851 /crypto/test/src/cms
parentCopyright and Readme updates (diff)
downloadBouncyCastle.NET-ed25519-a66a03b4b40dd3b60d8c1b0b11026abc21bb0967.tar.xz
Various SHA512/224, SHA512/256, SHA3 support
Diffstat (limited to 'crypto/test/src/cms')
-rw-r--r--crypto/test/src/cms/test/SignedDataTest.cs93
1 files changed, 90 insertions, 3 deletions
diff --git a/crypto/test/src/cms/test/SignedDataTest.cs b/crypto/test/src/cms/test/SignedDataTest.cs
index b9e23f257..65e0c4d57 100644
--- a/crypto/test/src/cms/test/SignedDataTest.cs
+++ b/crypto/test/src/cms/test/SignedDataTest.cs
@@ -7,7 +7,6 @@ using NUnit.Framework;
 
 using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.Cms;
-using Org.BouncyCastle.Cms;
 using Org.BouncyCastle.Crypto;
 using Org.BouncyCastle.Pkcs;
 using Org.BouncyCastle.Security;
@@ -458,7 +457,7 @@ namespace Org.BouncyCastle.Cms.Tests
 
 			s = new CmsSignedData(hashes, s.GetEncoded());
 
-			VerifySignatures(s, null);
+			VerifySignatures(s);
 		}
 
         [Test]
@@ -761,6 +760,72 @@ namespace Org.BouncyCastle.Cms.Tests
 			rsaPssTest("SHA384", CmsSignedDataGenerator.DigestSha384);
 		}
 
+        [Test]
+        public void TestSha1WithRsaDigest()
+        {
+            RsaDigestTest("SHA1withRSA");
+        }
+
+        [Test]
+        public void TestSha224WithRsaDigest()
+        {
+            RsaDigestTest("SHA224withRSA");
+        }
+
+        [Test]
+        public void TestSha256WithRsaDigest()
+        {
+            RsaDigestTest("SHA256withRSA");
+        }
+
+        [Test]
+        public void TestSha384WithRsaDigest()
+        {
+            RsaDigestTest("SHA384withRSA");
+        }
+
+        [Test]
+        public void TestSha512WithRsaDigest()
+        {
+            RsaDigestTest("SHA512withRSA");
+        }
+
+        [Test]
+        public void TestSha3_224WithRsaDigest()
+        {
+            RsaDigestTest("SHA3-224withRSA");
+        }
+
+        [Test]
+        public void TestSha3_256WithRsaDigest()
+        {
+            RsaDigestTest("SHA3-256withRSA");
+        }
+
+        [Test]
+        public void TestSha3_384WithRsaDigest()
+        {
+            RsaDigestTest("SHA3-384withRSA");
+        }
+
+        [Test]
+        public void TestSha3_512WithRsaDigest()
+        {
+            RsaDigestTest("SHA3-512withRSA");
+        }
+
+        [Test]
+        public void testSHA512_224ithRSADigest()
+        {
+            RsaDigestTest("SHA512(224)withRSA");
+        }
+
+        [Test]
+        public void testSHA512_256ithRSADigest()
+        {
+            RsaDigestTest("SHA512(256)withRSA");
+        }
+
 		[Test]
 		public void TestSha224WithRsaEncapsulated()
 		{
@@ -1469,7 +1534,29 @@ namespace Org.BouncyCastle.Cms.Tests
 			}
 		}
 
-		private void VerifySignatures(
+        private void RsaDigestTest(string signatureAlgorithmName)
+        {
+            byte[] data = Encoding.ASCII.GetBytes("Hello World!");
+            CmsProcessable msg = new CmsProcessableByteArray(data);
+
+            IX509Store x509Certs = CmsTestUtil.MakeCertStore(OrigCert, SignCert);
+
+            CmsSignedDataGenerator gen = new CmsSignedDataGenerator();
+            gen.AddSignerInfoGenerator(new SignerInfoGeneratorBuilder().Build(
+                new Asn1SignatureFactory(signatureAlgorithmName, OrigKP.Private), OrigCert));
+            gen.AddCertificates(x509Certs);
+
+            CmsSignedData s = gen.Generate(msg, false);
+
+            //
+            // compute expected content digest
+            //
+            string digestName = signatureAlgorithmName.Substring(0, signatureAlgorithmName.IndexOf("with"));
+
+            VerifySignatures(s, DigestUtilities.CalculateDigest(digestName, data));
+        }
+
+        private void VerifySignatures(
 			CmsSignedDataParser sp)
 		{
 			IX509Store x509Certs = sp.GetCertificates("Collection");