diff dcrypt/crypto/hashes/SHA512.d @ 23:4589f8c5eb3c

Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
author Thomas Dixon <reikon@reikon.us>
date Sat, 14 Feb 2009 19:58:20 -0500
parents 5cb17e09d685
children 176c933827a8
line wrap: on
line diff
--- a/dcrypt/crypto/hashes/SHA512.d	Sat Jan 10 13:17:58 2009 -0500
+++ b/dcrypt/crypto/hashes/SHA512.d	Sat Feb 14 19:58:20 2009 -0500
@@ -61,8 +61,8 @@
     void transform(ubyte[] input) {
         ulong[] w = new ulong[80];
         
-        for (int i = 0, j = 0; i < 16; i++,j+=8)
-            w[i] = Util.ubytesToUlongBig(input, j);
+        for (int i = 0, j = 0; i < 16; i++,j+=long.sizeof)
+            w[i] = ByteConverter.BigEndian.to!(ulong)(input[j..j+long.sizeof]);
         
         for (int i = 16; i < 80; i++)
             w[i] = theta1(w[i-2]) + w[i-7] + theta0(w[i-15]) + w[i-16];
@@ -108,37 +108,37 @@
     }
 
     private ulong sum0(ulong x) {
-            return (Util.rotateRight64(x,28)^
-                    Util.rotateRight64(x,34)^
-                    Util.rotateRight64(x,39));
+            return (Bitwise.rotateRight(x,28)^
+                    Bitwise.rotateRight(x,34)^
+                    Bitwise.rotateRight(x,39));
     }
 
     private ulong sum1(ulong x) {
-            return (Util.rotateRight64(x,14)^
-                    Util.rotateRight64(x,18)^
-                    Util.rotateRight64(x,41));
+            return (Bitwise.rotateRight(x,14)^
+                    Bitwise.rotateRight(x,18)^
+                    Bitwise.rotateRight(x,41));
     }
 
     private ulong theta0(ulong x) {
-        return Util.rotateRight64(x,1)^Util.rotateRight64(x,8)^(x >> 7);
+        return Bitwise.rotateRight(x,1)^Bitwise.rotateRight(x,8)^(x >> 7);
     }
 
     private ulong theta1(ulong x) {
-        return Util.rotateRight64(x,19)^Util.rotateRight64(x,61)^(x >> 6);
+        return Bitwise.rotateRight(x,19)^Bitwise.rotateRight(x,61)^(x >> 6);
     }
     
     ubyte[] digest() {
     	padMessage(MODE_SHA);
         ubyte[] result = new ubyte[digestSize];
         
-        Util.ulongToUbytesBig(h0, result, 0);
-        Util.ulongToUbytesBig(h1, result, 8);
-        Util.ulongToUbytesBig(h2, result, 16);
-        Util.ulongToUbytesBig(h3, result, 24);
-        Util.ulongToUbytesBig(h4, result, 32);
-        Util.ulongToUbytesBig(h5, result, 40);
-        Util.ulongToUbytesBig(h6, result, 48);
-        Util.ulongToUbytesBig(h7, result, 56);
+        result[0..8] = ByteConverter.BigEndian.from!(ulong)(h0);
+        result[8..16] = ByteConverter.BigEndian.from!(ulong)(h1);
+        result[16..24] = ByteConverter.BigEndian.from!(ulong)(h2);
+        result[24..32] = ByteConverter.BigEndian.from!(ulong)(h3);
+        result[32..40] = ByteConverter.BigEndian.from!(ulong)(h4);
+        result[40..48] = ByteConverter.BigEndian.from!(ulong)(h5);
+        result[48..56] = ByteConverter.BigEndian.from!(ulong)(h6);
+        result[56..64] = ByteConverter.BigEndian.from!(ulong)(h7);
 
         reset();
         return result;