Mercurial > projects > dcrypt
comparison dcrypt/crypto/hashes/SHA512.d @ 2:71aae178f89a
Added copy() to hash functions. Modified some code style.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Wed, 13 Aug 2008 22:01:19 -0400 |
parents | 0e08791a1418 |
children | a5789a7b3b3b |
comparison
equal
deleted
inserted
replaced
1:483e4467b5f6 | 2:71aae178f89a |
---|---|
147 h3 = 0xa54ff53a5f1d36f1u; | 147 h3 = 0xa54ff53a5f1d36f1u; |
148 h4 = 0x510e527fade682d1u; | 148 h4 = 0x510e527fade682d1u; |
149 h5 = 0x9b05688c2b3e6c1fu; | 149 h5 = 0x9b05688c2b3e6c1fu; |
150 h6 = 0x1f83d9abfb41bd6bu; | 150 h6 = 0x1f83d9abfb41bd6bu; |
151 h7 = 0x5be0cd19137e2179u; | 151 h7 = 0x5be0cd19137e2179u; |
152 } | |
153 | |
154 SHA512 copy() { | |
155 SHA512 h = new SHA512(buffer[0..index]); | |
156 h.h0 = h0; | |
157 h.h1 = h1; | |
158 h.h2 = h2; | |
159 h.h3 = h3; | |
160 h.h4 = h4; | |
161 h.h5 = h5; | |
162 h.h6 = h6; | |
163 h.h7 = h7; | |
164 return h; | |
152 } | 165 } |
153 | 166 |
154 version (UnitTest) { | 167 version (UnitTest) { |
155 unittest { | 168 unittest { |
156 static const char[][] test_inputs = [ | 169 static const char[][] test_inputs = [ |
183 foreach (uint i, char[] input; test_inputs) { | 196 foreach (uint i, char[] input; test_inputs) { |
184 for (int j = 0; j < test_repeat[i]; j++) | 197 for (int j = 0; j < test_repeat[i]; j++) |
185 h.update(input); | 198 h.update(input); |
186 char[] digest = h.hexDigest(); | 199 char[] digest = h.hexDigest(); |
187 assert(digest == test_results[i], | 200 assert(digest == test_results[i], |
188 h.name()~": ("~digest~") != ("~test_results[i]~")"); | 201 h.name~": ("~digest~") != ("~test_results[i]~")"); |
189 } | 202 } |
190 } | 203 } |
191 } | 204 } |
192 } | 205 } |