Mercurial > projects > dcrypt
annotate 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 |
rev | line source |
---|---|
0 | 1 /** |
2 * This file is part of the dcrypt project. | |
3 * | |
4 * Copyright: Copyright (C) dcrypt contributors 2008. All rights reserved. | |
5 * License: MIT | |
6 * Authors: Thomas Dixon | |
7 */ | |
8 | |
9 module dcrypt.crypto.hashes.SHA256; | |
10 | |
11 public import dcrypt.crypto.Hash; | |
12 | |
6
5cb17e09d685
Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
Thomas Dixon <reikon@reikon.us>
parents:
3
diff
changeset
|
13 /** |
5cb17e09d685
Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
Thomas Dixon <reikon@reikon.us>
parents:
3
diff
changeset
|
14 * Implementation of the US NSA's SHA-256. |
5cb17e09d685
Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
Thomas Dixon <reikon@reikon.us>
parents:
3
diff
changeset
|
15 * |
5cb17e09d685
Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
Thomas Dixon <reikon@reikon.us>
parents:
3
diff
changeset
|
16 * Conforms: FIPS-180-2 |
5cb17e09d685
Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
Thomas Dixon <reikon@reikon.us>
parents:
3
diff
changeset
|
17 * References: http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf |
5cb17e09d685
Minor edits to the unittests of hash functions and ciphers. Added AES and test vectors.
Thomas Dixon <reikon@reikon.us>
parents:
3
diff
changeset
|
18 */ |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
19 class SHA256 : Hash |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
20 { |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
21 private static const uint[] K = [ |
0 | 22 0x428a2f98u, 0x71374491u, 0xb5c0fbcfu, 0xe9b5dba5u, |
23 0x3956c25bu, 0x59f111f1u, 0x923f82a4u, 0xab1c5ed5u, | |
24 0xd807aa98u, 0x12835b01u, 0x243185beu, 0x550c7dc3u, | |
25 0x72be5d74u, 0x80deb1feu, 0x9bdc06a7u, 0xc19bf174u, | |
26 0xe49b69c1u, 0xefbe4786u, 0x0fc19dc6u, 0x240ca1ccu, | |
27 0x2de92c6fu, 0x4a7484aau, 0x5cb0a9dcu, 0x76f988dau, | |
28 0x983e5152u, 0xa831c66du, 0xb00327c8u, 0xbf597fc7u, | |
29 0xc6e00bf3u, 0xd5a79147u, 0x06ca6351u, 0x14292967u, | |
30 0x27b70a85u, 0x2e1b2138u, 0x4d2c6dfcu, 0x53380d13u, | |
31 0x650a7354u, 0x766a0abbu, 0x81c2c92eu, 0x92722c85u, | |
32 0xa2bfe8a1u, 0xa81a664bu, 0xc24b8b70u, 0xc76c51a3u, | |
33 0xd192e819u, 0xd6990624u, 0xf40e3585u, 0x106aa070u, | |
34 0x19a4c116u, 0x1e376c08u, 0x2748774cu, 0x34b0bcb5u, | |
35 0x391c0cb3u, 0x4ed8aa4au, 0x5b9cca4fu, 0x682e6ff3u, | |
36 0x748f82eeu, 0x78a5636fu, 0x84c87814u, 0x8cc70208u, | |
37 0x90befffau, 0xa4506cebu, 0xbef9a3f7u, 0xc67178f2u | |
38 ]; | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
39 |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
40 protected uint h0, h1, h2, h3, h4, h5, h6, h7; |
0 | 41 |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
42 this (void[] input_=null) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
43 { |
0 | 44 reset(); |
45 super(input_); | |
46 } | |
47 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
48 uint blockSize() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
49 { |
0 | 50 return 64; |
51 } | |
52 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
53 uint digestSize() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
54 { |
0 | 55 return 32; |
56 } | |
57 | |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
58 string name() |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
59 { |
0 | 60 return "SHA256"; |
61 } | |
62 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
63 void transform(ubyte[] input) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
64 { |
0 | 65 uint[] w = new uint[64]; |
66 | |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
67 for (int i = 0, j = 0; i < 16; i++,j+=int.sizeof) |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
68 w[i] = ByteConverter.BigEndian.to!(uint)(input[j..j+int.sizeof]); |
0 | 69 |
70 for (int i = 16; i < 64; i++) | |
71 w[i] = theta1(w[i-2]) + w[i-7] + theta0(w[i-15]) + w[i-16]; | |
72 | |
73 uint a = h0, | |
74 b = h1, | |
75 c = h2, | |
76 d = h3, | |
77 e = h4, | |
78 f = h5, | |
79 g = h6, | |
80 h = h7; | |
81 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
82 for (int i = 0; i < 64; i++) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
83 { |
0 | 84 uint t1 = h + sum1(e) + ch(e,f,g) + K[i] + w[i], |
85 t2 = sum0(a) + maj(a,b,c); | |
86 h = g; | |
87 g = f; | |
88 f = e; | |
89 e = d + t1; | |
90 d = c; | |
91 c = b; | |
92 b = a; | |
93 a = t1 + t2; | |
94 } | |
95 | |
96 h0 += a; | |
97 h1 += b; | |
98 h2 += c; | |
99 h3 += d; | |
100 h4 += e; | |
101 h5 += f; | |
102 h6 += g; | |
103 h7 += h; | |
104 } | |
105 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
106 private uint ch(uint x, uint y, uint z) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
107 { |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
108 return (z ^ (x & (y ^ z))); |
0 | 109 } |
110 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
111 private uint maj(uint x, uint y, uint z) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
112 { |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
113 return ((x & y) | (z & (x ^ y))); |
0 | 114 } |
115 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
116 private uint sum0(uint x) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
117 { |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
118 return Bitwise.rotateRight(x,2)^Bitwise.rotateRight(x,13)^Bitwise.rotateRight(x,22); |
0 | 119 } |
120 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
121 private uint sum1(uint x) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
122 { |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
123 return Bitwise.rotateRight(x,6)^Bitwise.rotateRight(x,11)^Bitwise.rotateRight(x,25); |
0 | 124 } |
125 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
126 private uint theta0(uint x) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
127 { |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
128 return Bitwise.rotateRight(x,7)^Bitwise.rotateRight(x,18)^(x >> 3); |
0 | 129 } |
130 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
131 private uint theta1(uint x) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
132 { |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
133 return Bitwise.rotateRight(x,17)^Bitwise.rotateRight(x,19)^(x >> 10); |
0 | 134 } |
135 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
136 ubyte[] digest() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
137 { |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
138 padMessage(MODE_SHA); |
0 | 139 ubyte[] result = new ubyte[digestSize]; |
140 | |
23
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
141 result[0..4] = ByteConverter.BigEndian.from!(uint)(h0); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
142 result[4..8] = ByteConverter.BigEndian.from!(uint)(h1); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
143 result[8..12] = ByteConverter.BigEndian.from!(uint)(h2); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
144 result[12..16] = ByteConverter.BigEndian.from!(uint)(h3); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
145 result[16..20] = ByteConverter.BigEndian.from!(uint)(h4); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
146 result[20..24] = ByteConverter.BigEndian.from!(uint)(h5); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
147 result[24..28] = ByteConverter.BigEndian.from!(uint)(h6); |
4589f8c5eb3c
Replaced dcrypt.crypto.Util with dcrypt.misc.Bitwise and dcrypt.misc.ByteConverter. Altered all dependent files to reflect changes.
Thomas Dixon <reikon@reikon.us>
parents:
6
diff
changeset
|
148 result[28..32] = ByteConverter.BigEndian.from!(uint)(h7); |
0 | 149 |
150 reset(); | |
151 return result; | |
152 } | |
153 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
154 void reset() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
155 { |
0 | 156 super.reset(); |
157 h0 = 0x6a09e667u; | |
158 h1 = 0xbb67ae85u; | |
159 h2 = 0x3c6ef372u; | |
160 h3 = 0xa54ff53au; | |
161 h4 = 0x510e527fu; | |
162 h5 = 0x9b05688cu; | |
163 h6 = 0x1f83d9abu; | |
164 h7 = 0x5be0cd19u; | |
165 } | |
166 | |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
167 SHA256 copy() |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
168 { |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
169 SHA256 h = new SHA256(buffer[0..index]); |
3
a5789a7b3b3b
Fixed error in hash copy() functions where I forgot to copy the length of the message. Now, twice as jank! =)
Thomas Dixon <reikon@reikon.us>
parents:
2
diff
changeset
|
170 h.bytes = bytes; |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
171 h.h0 = h0; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
172 h.h1 = h1; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
173 h.h2 = h2; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
174 h.h3 = h3; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
175 h.h4 = h4; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
176 h.h5 = h5; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
177 h.h6 = h6; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
178 h.h7 = h7; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
179 return h; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
180 } |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
181 |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
182 debug (UnitTest) |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
183 { |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
184 unittest |
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
185 { |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
186 static string[] test_inputs = [ |
0 | 187 "", |
188 "abc", | |
189 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
190 "a" | |
191 ]; | |
192 | |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
193 static int[] test_repeat = [ |
0 | 194 1, 1, 1, 1000000 |
195 ]; | |
196 | |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
197 static string[] test_results = [ |
0 | 198 "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", |
199 "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", | |
200 "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", | |
201 "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" | |
202 ]; | |
203 | |
204 SHA256 h = new SHA256(); | |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
205 foreach (uint i, string input; test_inputs) |
27
8b5eaf3c2979
Fixed error in hash message padding reported by Glenn Haecker.
Thomas Dixon <reikon@reikon.us>
parents:
26
diff
changeset
|
206 { |
0 | 207 for (int j = 0; j < test_repeat[i]; j++) |
208 h.update(input); | |
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.
Thomas Dixon <reikon@reikon.us>
parents:
27
diff
changeset
|
209 string digest = h.hexDigest(); |
0 | 210 assert(digest == test_results[i], |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
211 h.name~": ("~digest~") != ("~test_results[i]~")"); |
0 | 212 } |
213 } | |
214 } | |
215 } |