Mercurial > projects > dcrypt
diff dcrypt/crypto/hashes/SHA1.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/SHA1.d Sat Jan 10 13:17:58 2009 -0500 +++ b/dcrypt/crypto/hashes/SHA1.d Sat Feb 14 19:58:20 2009 -0500 @@ -40,11 +40,11 @@ void transform(ubyte[] input) { uint[] w = new uint[80]; - for (int i = 0, j = 0; i < 16; i++,j+=4) - w[i] = Util.ubytesToUintBig(input, j); + for (int i = 0, j = 0; i < 16; i++,j+=int.sizeof) + w[i] = ByteConverter.BigEndian.to!(uint)(input[j..j+int.sizeof]); for (int i = 16; i < 80; i++) - w[i] = Util.rotateLeft(w[i-3]^w[i-8]^w[i-14]^w[i-16], 1); + w[i] = Bitwise.rotateLeft(w[i-3]^w[i-8]^w[i-14]^w[i-16], 1); uint a = h0, b = h1, @@ -54,71 +54,71 @@ int i = 0; for (; i < 20;) { - e += Util.rotateLeft(a, 5) + f0(b, c, d) + w[i++]; - b = Util.rotateLeft(b, 30); + e += Bitwise.rotateLeft(a, 5) + f0(b, c, d) + w[i++]; + b = Bitwise.rotateLeft(b, 30); - d += Util.rotateLeft(e, 5) + f0(a, b, c) + w[i++]; - a = Util.rotateLeft(a, 30); + d += Bitwise.rotateLeft(e, 5) + f0(a, b, c) + w[i++]; + a = Bitwise.rotateLeft(a, 30); - c += Util.rotateLeft(d, 5) + f0(e, a, b) + w[i++]; - e = Util.rotateLeft(e, 30); + c += Bitwise.rotateLeft(d, 5) + f0(e, a, b) + w[i++]; + e = Bitwise.rotateLeft(e, 30); - b += Util.rotateLeft(c, 5) + f0(d, e, a) + w[i++]; - d = Util.rotateLeft(d, 30); + b += Bitwise.rotateLeft(c, 5) + f0(d, e, a) + w[i++]; + d = Bitwise.rotateLeft(d, 30); - a += Util.rotateLeft(b, 5) + f0(c, d, e) + w[i++]; - c = Util.rotateLeft(c, 30); + a += Bitwise.rotateLeft(b, 5) + f0(c, d, e) + w[i++]; + c = Bitwise.rotateLeft(c, 30); } for (; i < 40;) { - e += Util.rotateLeft(a, 5) + f1(b, c, d) + w[i++]; - b = Util.rotateLeft(b, 30); + e += Bitwise.rotateLeft(a, 5) + f1(b, c, d) + w[i++]; + b = Bitwise.rotateLeft(b, 30); - d += Util.rotateLeft(e, 5) + f1(a, b, c) + w[i++]; - a = Util.rotateLeft(a, 30); + d += Bitwise.rotateLeft(e, 5) + f1(a, b, c) + w[i++]; + a = Bitwise.rotateLeft(a, 30); - c += Util.rotateLeft(d, 5) + f1(e, a, b) + w[i++]; - e = Util.rotateLeft(e, 30); + c += Bitwise.rotateLeft(d, 5) + f1(e, a, b) + w[i++]; + e = Bitwise.rotateLeft(e, 30); - b += Util.rotateLeft(c, 5) + f1(d, e, a) + w[i++]; - d = Util.rotateLeft(d, 30); + b += Bitwise.rotateLeft(c, 5) + f1(d, e, a) + w[i++]; + d = Bitwise.rotateLeft(d, 30); - a += Util.rotateLeft(b, 5) + f1(c, d, e) + w[i++]; - c = Util.rotateLeft(c, 30); + a += Bitwise.rotateLeft(b, 5) + f1(c, d, e) + w[i++]; + c = Bitwise.rotateLeft(c, 30); } for (; i < 60;) { - e += Util.rotateLeft(a, 5) + f2(b, c, d) + w[i++]; - b = Util.rotateLeft(b, 30); + e += Bitwise.rotateLeft(a, 5) + f2(b, c, d) + w[i++]; + b = Bitwise.rotateLeft(b, 30); - d += Util.rotateLeft(e, 5) + f2(a, b, c) + w[i++]; - a = Util.rotateLeft(a, 30); + d += Bitwise.rotateLeft(e, 5) + f2(a, b, c) + w[i++]; + a = Bitwise.rotateLeft(a, 30); - c += Util.rotateLeft(d, 5) + f2(e, a, b) + w[i++]; - e = Util.rotateLeft(e, 30); + c += Bitwise.rotateLeft(d, 5) + f2(e, a, b) + w[i++]; + e = Bitwise.rotateLeft(e, 30); - b += Util.rotateLeft(c, 5) + f2(d, e, a) + w[i++]; - d = Util.rotateLeft(d, 30); + b += Bitwise.rotateLeft(c, 5) + f2(d, e, a) + w[i++]; + d = Bitwise.rotateLeft(d, 30); - a += Util.rotateLeft(b, 5) + f2(c, d, e) + w[i++]; - c = Util.rotateLeft(c, 30); + a += Bitwise.rotateLeft(b, 5) + f2(c, d, e) + w[i++]; + c = Bitwise.rotateLeft(c, 30); } for (; i < 80;) { - e += Util.rotateLeft(a, 5) + f3(b, c, d) + w[i++]; - b = Util.rotateLeft(b, 30); + e += Bitwise.rotateLeft(a, 5) + f3(b, c, d) + w[i++]; + b = Bitwise.rotateLeft(b, 30); - d += Util.rotateLeft(e, 5) + f3(a, b, c) + w[i++]; - a = Util.rotateLeft(a, 30); + d += Bitwise.rotateLeft(e, 5) + f3(a, b, c) + w[i++]; + a = Bitwise.rotateLeft(a, 30); - c += Util.rotateLeft(d, 5) + f3(e, a, b) + w[i++]; - e = Util.rotateLeft(e, 30); + c += Bitwise.rotateLeft(d, 5) + f3(e, a, b) + w[i++]; + e = Bitwise.rotateLeft(e, 30); - b += Util.rotateLeft(c, 5) + f3(d, e, a) + w[i++]; - d = Util.rotateLeft(d, 30); + b += Bitwise.rotateLeft(c, 5) + f3(d, e, a) + w[i++]; + d = Bitwise.rotateLeft(d, 30); - a += Util.rotateLeft(b, 5) + f3(c, d, e) + w[i++]; - c = Util.rotateLeft(c, 30); + a += Bitwise.rotateLeft(b, 5) + f3(c, d, e) + w[i++]; + c = Bitwise.rotateLeft(c, 30); } h0 += a; @@ -148,11 +148,11 @@ padMessage(MODE_SHA); ubyte[] result = new ubyte[digestSize]; - Util.uintToUbytesBig(h0, result, 0); - Util.uintToUbytesBig(h1, result, 4); - Util.uintToUbytesBig(h2, result, 8); - Util.uintToUbytesBig(h3, result, 12); - Util.uintToUbytesBig(h4, result, 16); + result[0..4] = ByteConverter.BigEndian.from!(uint)(h0); + result[4..8] = ByteConverter.BigEndian.from!(uint)(h1); + result[8..12] = ByteConverter.BigEndian.from!(uint)(h2); + result[12..16] = ByteConverter.BigEndian.from!(uint)(h3); + result[16..20] = ByteConverter.BigEndian.from!(uint)(h4); reset(); return result;