summary refs log tree commit diff
path: root/crypto
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2015-10-30 15:03:27 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2015-10-30 15:03:27 +0700
commite320f2fa1fc3a684afc81a7de0dd020f6dee9b6c (patch)
treefcc8705477143b3fd7f3a093dc136c0966663fe1 /crypto
parentPort PrimesTest from Java (diff)
downloadBouncyCastle.NET-ed25519-e320f2fa1fc3a684afc81a7de0dd020f6dee9b6c.tar.xz
Rewrite (block) update for improved performance
Diffstat (limited to 'crypto')
-rw-r--r--crypto/src/crypto/digests/GeneralDigest.cs36
1 files changed, 21 insertions, 15 deletions
diff --git a/crypto/src/crypto/digests/GeneralDigest.cs b/crypto/src/crypto/digests/GeneralDigest.cs
index 54a09ae05..d40ad28bb 100644
--- a/crypto/src/crypto/digests/GeneralDigest.cs
+++ b/crypto/src/crypto/digests/GeneralDigest.cs
@@ -55,38 +55,44 @@ namespace Org.BouncyCastle.Crypto.Digests
             int     inOff,
             int     length)
         {
+            length = System.Math.Max(0, length);
+
             //
             // fill the current word
             //
-            while ((xBufOff != 0) && (length > 0))
+            int i = 0;
+            if (xBufOff != 0)
             {
-                Update(input[inOff]);
-                inOff++;
-                length--;
+                while (i < length)
+                {
+                    xBuf[xBufOff++] = input[inOff + i++];
+                    if (xBufOff == 4)
+                    {
+                        ProcessWord(xBuf, 0);
+                        xBufOff = 0;
+                        break;
+                    }
+                }
             }
 
             //
             // process whole words.
             //
-            while (length > xBuf.Length)
+            int limit = ((length - i) & ~3) + i;
+            for (; i < limit; i += 4)
             {
-                ProcessWord(input, inOff);
-
-                inOff += xBuf.Length;
-                length -= xBuf.Length;
-                byteCount += xBuf.Length;
+                ProcessWord(input, inOff + i);
             }
 
             //
             // load in the remainder.
             //
-            while (length > 0)
+            while (i < length)
             {
-                Update(input[inOff]);
-
-                inOff++;
-                length--;
+                xBuf[xBufOff++] = input[inOff + i++];
             }
+
+            byteCount += length;
         }
 
         public void Finish()