Mercurial > projects > dcrypt
diff dcrypt/crypto/hashes/SHA512.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 |
line wrap: on
line diff
--- a/dcrypt/crypto/hashes/SHA512.d Sat May 09 23:29:20 2009 -0400 +++ b/dcrypt/crypto/hashes/SHA512.d Sun May 10 22:38:48 2009 -0400 @@ -18,7 +18,7 @@ */ class SHA512 : Hash { - private const ulong[] K = [ + private static const ulong[] K = [ 0x428a2f98d728ae22u, 0x7137449123ef65cdu, 0xb5c0fbcfec4d3b2fu, 0xe9b5dba58189dbbcu, 0x3956c25bf348b538u, 0x59f111f1b605d019u, 0x923f82a4af194f9bu, 0xab1c5ed5da6d8118u, 0xd807aa98a3030242u, 0x12835b0145706fbeu, 0x243185be4ee4b28cu, 0x550c7dc3d5ffb4e2u, @@ -41,7 +41,7 @@ 0x4cc5d4becb3e42b6u, 0x597f299cfc657e2au, 0x5fcb6fab3ad6faecu, 0x6c44198c4a475817u ]; - protected ulong h0, h1, h2, h3, h4, h5, h6, h7; + protected ulong h0, h1, h2, h3, h4, h5, h6, h7; this (void[] input_=null) { @@ -59,7 +59,7 @@ return 64; } - char[] name() + string name() { return "SHA512"; } @@ -143,7 +143,7 @@ ubyte[] digest() { - padMessage(MODE_SHA); + padMessage(MODE_SHA); ubyte[] result = new ubyte[digestSize]; result[0..8] = ByteConverter.BigEndian.from!(ulong)(h0); @@ -191,7 +191,7 @@ { unittest { - static const char[][] test_inputs = [ + static string[] test_inputs = [ "", "abc", "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"~ @@ -199,11 +199,11 @@ "a" ]; - static const int[] test_repeat = [ + static int[] test_repeat = [ 1, 1, 1, 1000000 ]; - static const char[][] test_results = [ + static string[] test_results = [ "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce"~ "47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", @@ -218,11 +218,11 @@ ]; SHA512 h = new SHA512(); - foreach (uint i, char[] input; test_inputs) + foreach (uint i, string input; test_inputs) { for (int j = 0; j < test_repeat[i]; j++) h.update(input); - char[] digest = h.hexDigest(); + string digest = h.hexDigest(); assert(digest == test_results[i], h.name~": ("~digest~") != ("~test_results[i]~")"); }