summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2015-12-19 10:36:47 +1100
committerDavid Hook <dgh@bouncycastle.org>2015-12-19 10:36:47 +1100
commit0b4afcc3e4f3804562294b71265edd2ac2f00f9c (patch)
treecbcb89985a7c0ce08433f104da46771e5cdd1012 /crypto
parentAdded support for fixed salt. (diff)
downloadBouncyCastle.NET-ed25519-0b4afcc3e4f3804562294b71265edd2ac2f00f9c.tar.xz
Added test against fixed salt.
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/crypto/signers/PssSigner.cs11
-rw-r--r--crypto/test/src/crypto/test/PSSTest.cs38
2 files changed, 47 insertions, 2 deletions
diff --git a/crypto/src/crypto/signers/PssSigner.cs b/crypto/src/crypto/signers/PssSigner.cs
index 61e7dae01..23b7c0f49 100644
--- a/crypto/src/crypto/signers/PssSigner.cs
+++ b/crypto/src/crypto/signers/PssSigner.cs
@@ -89,7 +89,16 @@ namespace Org.BouncyCastle.Crypto.Signers
 		{
 		}
 
-		public PssSigner(
+        public PssSigner(
+            IAsymmetricBlockCipher cipher,
+            IDigest contentDigest,
+            IDigest mgfDigest,
+            byte[] salt)
+            : this(cipher, contentDigest, contentDigest, mgfDigest, salt.Length, salt, TrailerImplicit)
+        {
+        }
+
+        public PssSigner(
 			IAsymmetricBlockCipher	cipher,
 			IDigest					digest,
 			int						saltLen,
diff --git a/crypto/test/src/crypto/test/PSSTest.cs b/crypto/test/src/crypto/test/PSSTest.cs
index 91d8d3a6e..8578d254f 100644
--- a/crypto/test/src/crypto/test/PSSTest.cs
+++ b/crypto/test/src/crypto/test/PSSTest.cs
@@ -319,9 +319,45 @@ namespace Org.BouncyCastle.Crypto.Tests
 			{
 				Fail("loop test failed - failures: " + failed);
 			}
+
+            fixedSaltTest();
 		}
 
-		public static void Main(
+        private void fixedSaltTest()
+        {
+            byte[] data = Hex.Decode("010203040506070809101112131415");
+
+            PssSigner eng = new PssSigner(new RsaEngine(), new Sha256Digest(), new Sha1Digest(), Hex.Decode("deadbeef"));
+
+            eng.Init(true, prv8);
+
+            eng.BlockUpdate(data, 0, data.Length);
+
+            byte[] s = eng.GenerateSignature();
+
+            eng.Init(false, pub8);
+
+            eng.BlockUpdate(data, 0, data.Length);
+
+            if (!eng.VerifySignature(s))
+            {
+                Fail("fixed salt failed");
+            }
+
+            // test failure
+            eng = new PssSigner(new RsaEngine(), new Sha256Digest(), new Sha1Digest(), Hex.Decode("beefbeef"));
+
+            eng.Init(false, pub8);
+
+            eng.BlockUpdate(data, 0, data.Length);
+
+            if (eng.VerifySignature(s))
+            {
+                Fail("fixed salt failure verfied");
+            }
+        }
+
+        public static void Main(
 			string[] args)
 		{
 			RunTest(new PssTest());