Mercurial > projects > dcrypt
diff dcrypt/crypto/Hash.d @ 28:ad687db713a4
Further reworked the code for hash padding. Replaced all instances of 'char[]' with 'string' and removed a few 'const' modifiers as per Glenn Haecker's patch for D2 compatibility. Updated CONTRIBUTORS file.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Sun, 10 May 2009 22:38:48 -0400 |
parents | 8b5eaf3c2979 |
children | b9ba770b8f16 |
line wrap: on
line diff
--- a/dcrypt/crypto/Hash.d Sat May 09 23:29:20 2009 -0400 +++ b/dcrypt/crypto/Hash.d Sun May 10 22:38:48 2009 -0400 @@ -43,7 +43,7 @@ abstract uint digestSize(); /** Returns: The name of the algorithm we're implementing. */ - abstract char[] name(); + abstract string name(); /** Returns: A copy of this hash object. */ abstract Hash copy(); @@ -96,7 +96,7 @@ } // Pad with null bytes - while ((index & (blockSize - 1)) != (blockSize - long.sizeof)) + while ((index & (blockSize - 1)) != (blockSize - (blockSize >> 3))) { buffer[index++] = 0; @@ -108,12 +108,12 @@ } // Length padding - for (int i = 0; i < 64; i+=8) // little endian - buffer[index++] = bits >> i; - + for (int i = 0; i < blockSize; i+=8, bits>>=8) // little endian + buffer[index++] = bits; + if (mode == MODE_SHA) - buffer[index-ulong.sizeof..index].reverse; // big endian - + buffer[(buffer.length-(blockSize >> 3))..buffer.length].reverse; // big endian + transform(buffer); index = 0; } @@ -131,7 +131,7 @@ * * Returns: Representation of the final hash value in hex. */ - char[] hexDigest() + string hexDigest() { return ByteConverter.hexEncode(digest()); }