summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2022-01-27 15:08:42 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2022-01-27 15:08:42 +0700
commit9510a6f60869b3d37f5fa07e26403482b85c9502 (patch)
tree5220484a4842aa84683848e1e345af78dd3f78be
parentMerge branch 'yla/fix/null-reference' of https://github.com/ylabade/bc-csharp (diff)
downloadBouncyCastle.NET-ed25519-9510a6f60869b3d37f5fa07e26403482b85c9502.tar.xz
Support additional input in "deterministic (EC)DSA"
-rw-r--r--crypto/src/crypto/signers/HMacDsaKCalculator.cs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crypto/src/crypto/signers/HMacDsaKCalculator.cs b/crypto/src/crypto/signers/HMacDsaKCalculator.cs
index 05c4ae5c2..2641f58b6 100644
--- a/crypto/src/crypto/signers/HMacDsaKCalculator.cs
+++ b/crypto/src/crypto/signers/HMacDsaKCalculator.cs
@@ -74,6 +74,7 @@ namespace Org.BouncyCastle.Crypto.Signers
             hMac.Update((byte)0x00);
             hMac.BlockUpdate(x, 0, x.Length);
             hMac.BlockUpdate(m, 0, m.Length);
+            InitAdditionalInput0(hMac);
 
             hMac.DoFinal(K, 0);
 
@@ -136,6 +137,22 @@ namespace Org.BouncyCastle.Crypto.Signers
             }
         }
 
+        /// <summary>Supports use of additional input.</summary>
+        /// <remarks>
+        /// RFC 6979 3.6. Additional data may be added to the input of HMAC [..]. A use case may be a protocol that
+        /// requires a non-deterministic signature algorithm on a system that does not have access to a high-quality
+        /// random source. It suffices that the additional data[..] is non-repeating(e.g., a signature counter or a
+        /// monotonic clock) to ensure "random-looking" signatures are indistinguishable, in a cryptographic way, from
+        /// plain (EC)DSA signatures.
+        /// <para/>
+        /// By default there is no additional input. Override this method to supply additional input, bearing in mind
+        /// that this calculator may be used for many signatures.
+        /// </remarks>
+        /// <param name="hmac0">The <see cref="HMac"/> to which the additional input should be added.</param>
+        protected virtual void InitAdditionalInput0(HMac hmac0)
+        {
+        }
+
         private BigInteger BitsToInt(byte[] t)
         {
             BigInteger v = new BigInteger(1, t);