summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2023-02-13 00:34:15 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2023-02-13 00:34:15 +0700
commit69a253573610828ead70f3c96c64cf6d250eccd1 (patch)
treec269877c5500eb90f972b3bee353b492df1d6ebe
parentUse 2 * output length for seed size (diff)
downloadBouncyCastle.NET-ed25519-69a253573610828ead70f3c96c64cf6d250eccd1.tar.xz
Support explicit blockSize
-rw-r--r--crypto/src/crypto/macs/HMac.cs10
1 files changed, 9 insertions, 1 deletions
diff --git a/crypto/src/crypto/macs/HMac.cs b/crypto/src/crypto/macs/HMac.cs
index 3445a945b..03e2212d6 100644
--- a/crypto/src/crypto/macs/HMac.cs
+++ b/crypto/src/crypto/macs/HMac.cs
@@ -26,10 +26,18 @@ namespace Org.BouncyCastle.Crypto.Macs
         private readonly byte[] outputBuf;
 
         public HMac(IDigest digest)
+            : this(digest, digest.GetByteLength())
         {
+        }
+
+        public HMac(IDigest digest, int blockLength)
+        {
+            if (blockLength < 16)
+                throw new ArgumentException("must be at least 16 bytes", nameof(blockLength));
+
             this.digest = digest;
             this.digestSize = digest.GetDigestSize();
-            this.blockLength = digest.GetByteLength();
+            this.blockLength = blockLength;
             this.inputPad = new byte[blockLength];
             this.outputBuf = new byte[blockLength + digestSize];
         }