summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorDavid Hook <dgh@bouncycastle.org>2015-12-19 10:11:53 +1100
committerDavid Hook <dgh@bouncycastle.org>2015-12-19 10:11:53 +1100
commit9d2816f7c430dc4fcf26b2940e3c5aa1a5aefcd7 (patch)
treea453a8108465a04cd8d8fde868dfc4956f70be71 /crypto
parentCheck CertificateRequest syntax server-side (diff)
downloadBouncyCastle.NET-ed25519-9d2816f7c430dc4fcf26b2940e3c5aa1a5aefcd7.tar.xz
Added support for fixed salt.
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/crypto/signers/PssSigner.cs46
1 files changed, 39 insertions, 7 deletions
diff --git a/crypto/src/crypto/signers/PssSigner.cs b/crypto/src/crypto/signers/PssSigner.cs
index 03890902b..61e7dae01 100644
--- a/crypto/src/crypto/signers/PssSigner.cs
+++ b/crypto/src/crypto/signers/PssSigner.cs
@@ -25,6 +25,7 @@ namespace Org.BouncyCastle.Crypto.Signers
 		private int hLen;
 		private int mgfhLen;
 		private int sLen;
+        private bool sSet;
 		private int emBits;
 		private byte[] salt;
 		private byte[] mDash;
@@ -35,7 +36,7 @@ namespace Org.BouncyCastle.Crypto.Signers
 			IAsymmetricBlockCipher	cipher,
 			IDigest					digest)
 		{
-			return new PssSigner(cipher, new NullDigest(), digest, digest, digest.GetDigestSize(), TrailerImplicit);
+			return new PssSigner(cipher, new NullDigest(), digest, digest, digest.GetDigestSize(), null, TrailerImplicit);
 		}
 
 		public static PssSigner CreateRawSigner(
@@ -45,7 +46,7 @@ namespace Org.BouncyCastle.Crypto.Signers
 			int						saltLen,
 			byte					trailer)
 		{
-			return new PssSigner(cipher, new NullDigest(), contentDigest, mgfDigest, saltLen, trailer);
+			return new PssSigner(cipher, new NullDigest(), contentDigest, mgfDigest, saltLen, null, trailer);
 		}
 
 		public PssSigner(
@@ -67,7 +68,19 @@ namespace Org.BouncyCastle.Crypto.Signers
 		{
 		}
 
-		public PssSigner(
+        /// <summary>Basic constructor</summary>
+        /// <param name="cipher">the asymmetric cipher to use.</param>
+        /// <param name="digest">the digest to use.</param>
+        /// <param name="salt">the fixed salt to be used.</param>
+        public PssSigner(
+            IAsymmetricBlockCipher cipher,
+            IDigest digest,
+            byte[] salt)
+            : this(cipher, digest, digest, digest, salt.Length, salt, TrailerImplicit)
+        {
+        }
+
+        public PssSigner(
 			IAsymmetricBlockCipher	cipher,
 			IDigest					contentDigest,
 			IDigest					mgfDigest,
@@ -91,7 +104,7 @@ namespace Org.BouncyCastle.Crypto.Signers
 			IDigest					mgfDigest,
 			int						saltLen,
 			byte					trailer)
-			: this(cipher, contentDigest, contentDigest, mgfDigest, saltLen, trailer)
+			: this(cipher, contentDigest, contentDigest, mgfDigest, saltLen, null, trailer)
 		{
 		}
 
@@ -101,6 +114,7 @@ namespace Org.BouncyCastle.Crypto.Signers
 			IDigest					contentDigest2,
 			IDigest					mgfDigest,
 			int						saltLen,
+            byte[]                  salt,
 			byte					trailer)
 		{
 			this.cipher = cipher;
@@ -110,7 +124,15 @@ namespace Org.BouncyCastle.Crypto.Signers
 			this.hLen = contentDigest2.GetDigestSize();
 			this.mgfhLen = mgfDigest.GetDigestSize();
 			this.sLen = saltLen;
-			this.salt = new byte[saltLen];
+            this.sSet = salt != null;
+            if (sSet)
+            {
+                this.salt = salt;
+            }
+            else
+            {
+                this.salt = new byte[saltLen];
+            }
 			this.mDash = new byte[8 + saltLen + hLen];
 			this.trailer = trailer;
 		}
@@ -197,7 +219,10 @@ namespace Org.BouncyCastle.Crypto.Signers
 
 			if (sLen != 0)
 			{
-				random.NextBytes(salt);
+                if (!sSet)
+                {
+                    random.NextBytes(salt);
+                }
 				salt.CopyTo(mDash, mDash.Length - sLen);
 			}
 
@@ -270,7 +295,14 @@ namespace Org.BouncyCastle.Crypto.Signers
 				return false;
 			}
 
-			Array.Copy(block, block.Length - sLen - hLen - 1, mDash, mDash.Length - sLen, sLen);
+            if (sSet)
+            {
+                Array.Copy(salt, 0, mDash, mDash.Length - sLen, sLen);
+            }
+            else
+            {
+                Array.Copy(block, block.Length - sLen - hLen - 1, mDash, mDash.Length - sLen, sLen);
+            }
 
 			contentDigest2.BlockUpdate(mDash, 0, mDash.Length);
 			contentDigest2.DoFinal(mDash, mDash.Length - hLen);