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()
|