Mercurial > projects > dcrypt
diff dcrypt/crypto/hashes/SHA256.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/SHA256.d Sat May 09 23:29:20 2009 -0400 +++ b/dcrypt/crypto/hashes/SHA256.d Sun May 10 22:38:48 2009 -0400 @@ -18,7 +18,7 @@ */ class SHA256 : Hash { - private const uint[] K = [ + private static const uint[] K = [ 0x428a2f98u, 0x71374491u, 0xb5c0fbcfu, 0xe9b5dba5u, 0x3956c25bu, 0x59f111f1u, 0x923f82a4u, 0xab1c5ed5u, 0xd807aa98u, 0x12835b01u, 0x243185beu, 0x550c7dc3u, @@ -37,7 +37,7 @@ 0x90befffau, 0xa4506cebu, 0xbef9a3f7u, 0xc67178f2u ]; - protected uint h0, h1, h2, h3, h4, h5, h6, h7; + protected uint h0, h1, h2, h3, h4, h5, h6, h7; this (void[] input_=null) { @@ -55,7 +55,7 @@ return 32; } - char[] name() + string name() { return "SHA256"; } @@ -135,7 +135,7 @@ ubyte[] digest() { - padMessage(MODE_SHA); + padMessage(MODE_SHA); ubyte[] result = new ubyte[digestSize]; result[0..4] = ByteConverter.BigEndian.from!(uint)(h0); @@ -183,18 +183,18 @@ { unittest { - static const char[][] test_inputs = [ + static string[] test_inputs = [ "", "abc", "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", "a" ]; - static const int[] test_repeat = [ + static int[] test_repeat = [ 1, 1, 1, 1000000 ]; - static const char[][] test_results = [ + static string[] test_results = [ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", @@ -202,11 +202,11 @@ ]; SHA256 h = new SHA256(); - 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]~")"); }