diff dcrypt/crypto/Hash.d @ 30:21847420b1ac

Changed Hash's update method to a more optimized variant. Changed the code style for the entire misc package (completely forgot about it). Further changes for D2 compatibility. It appears as if full compatibility won't be possibledue to D2's handling of void[], but the number of changes to obtain compatibility can be minimized in the least.
author Thomas Dixon <reikon@reikon.us>
date Mon, 11 May 2009 15:32:00 -0400
parents b9ba770b8f16
children 2b4bccdc8387
line wrap: on
line diff
--- a/dcrypt/crypto/Hash.d	Mon May 11 01:39:19 2009 -0400
+++ b/dcrypt/crypto/Hash.d	Mon May 11 15:32:00 2009 -0400
@@ -59,16 +59,28 @@
     Hash update(void[] input_)
     {
         ubyte[] input = cast(ubyte[]) input_;
-        foreach (ubyte i; input)
+        uint i, partLength;
+        
+        index = bytes & (blockSize - 1);
+        bytes += input.length;
+        
+        partLength = blockSize - index;
+        
+        if (input.length >= partLength)
         {
-            bytes++;
-            buffer[index++] = i;
-            if (index == blockSize)
-            {
-                transform(buffer);
-                index = 0;
-            }   
+            buffer[index..index+partLength] = input[0..partLength];
+            transform(buffer);
+            
+            for (i = partLength; i + (blockSize - 1) < input.length; i+=blockSize)
+                transform(input[i..i+blockSize]);
+                
+            index = 0;
         }
+        else
+            i = 0;
+            
+        if (input.length - i)
+            buffer[index..index+(input.length-i)] = input[i..input.length];
         
         return this;
     }
@@ -86,6 +98,7 @@
     protected void padMessage(uint mode)
     {
         ulong bits = bytes << 3;
+        index = bytes & (blockSize - 1);
         
         // Add the pad marker
         buffer[index++] = ((mode == MODE_TIGER) ? 0x01 : 0x80);