Mercurial > projects > dcrypt
comparison dcrypt/crypto/hashes/SHA224.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 |
comparison
equal
deleted
inserted
replaced
27:8b5eaf3c2979 | 28:ad687db713a4 |
---|---|
27 uint digestSize() | 27 uint digestSize() |
28 { | 28 { |
29 return 28; | 29 return 28; |
30 } | 30 } |
31 | 31 |
32 char[] name() | 32 string name() |
33 { | 33 { |
34 return "SHA224"; | 34 return "SHA224"; |
35 } | 35 } |
36 | 36 |
37 ubyte[] digest() | 37 ubyte[] digest() |
38 { | 38 { |
39 padMessage(MODE_SHA); | 39 padMessage(MODE_SHA); |
40 | 40 |
41 ubyte[] result = new ubyte[digestSize]; | 41 ubyte[] result = new ubyte[digestSize]; |
42 | 42 |
43 result[0..4] = ByteConverter.BigEndian.from!(uint)(h0); | 43 result[0..4] = ByteConverter.BigEndian.from!(uint)(h0); |
44 result[4..8] = ByteConverter.BigEndian.from!(uint)(h1); | 44 result[4..8] = ByteConverter.BigEndian.from!(uint)(h1); |
82 | 82 |
83 debug (UnitTest) | 83 debug (UnitTest) |
84 { | 84 { |
85 unittest | 85 unittest |
86 { | 86 { |
87 static const char[][] test_inputs = [ | 87 static string[] test_inputs = [ |
88 "", | 88 "", |
89 "abc", | 89 "abc", |
90 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | 90 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
91 "a" | 91 "a" |
92 ]; | 92 ]; |
93 | 93 |
94 static const int[] test_repeat = [ | 94 static int[] test_repeat = [ |
95 1, 1, 1, 1000000 | 95 1, 1, 1, 1000000 |
96 ]; | 96 ]; |
97 | 97 |
98 static const char[][] test_results = [ | 98 static string[] test_results = [ |
99 "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", | 99 "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f", |
100 "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", | 100 "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7", |
101 "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525", | 101 "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525", |
102 "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" | 102 "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" |
103 ]; | 103 ]; |
104 | 104 |
105 SHA224 h = new SHA224(); | 105 SHA224 h = new SHA224(); |
106 foreach (uint i, char[] input; test_inputs) | 106 foreach (uint i, string input; test_inputs) |
107 { | 107 { |
108 for (int j = 0; j < test_repeat[i]; j++) | 108 for (int j = 0; j < test_repeat[i]; j++) |
109 h.update(input); | 109 h.update(input); |
110 char[] digest = h.hexDigest(); | 110 string digest = h.hexDigest(); |
111 assert(digest == test_results[i], | 111 assert(digest == test_results[i], |
112 h.name~": ("~digest~") != ("~test_results[i]~")"); | 112 h.name~": ("~digest~") != ("~test_results[i]~")"); |
113 } | 113 } |
114 } | 114 } |
115 } | 115 } |