comparison dcrypt/crypto/hashes/SHA256.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
141 h5 = 0x9b05688cu; 141 h5 = 0x9b05688cu;
142 h6 = 0x1f83d9abu; 142 h6 = 0x1f83d9abu;
143 h7 = 0x5be0cd19u; 143 h7 = 0x5be0cd19u;
144 } 144 }
145 145
146 SHA256 copy() {
147 SHA256 h = new SHA256(buffer[0..index]);
148 h.h0 = h0;
149 h.h1 = h1;
150 h.h2 = h2;
151 h.h3 = h3;
152 h.h4 = h4;
153 h.h5 = h5;
154 h.h6 = h6;
155 h.h7 = h7;
156 return h;
157 }
158
146 version (UnitTest) { 159 version (UnitTest) {
147 unittest { 160 unittest {
148 static const char[][] test_inputs = [ 161 static const char[][] test_inputs = [
149 "", 162 "",
150 "abc", 163 "abc",
167 foreach (uint i, char[] input; test_inputs) { 180 foreach (uint i, char[] input; test_inputs) {
168 for (int j = 0; j < test_repeat[i]; j++) 181 for (int j = 0; j < test_repeat[i]; j++)
169 h.update(input); 182 h.update(input);
170 char[] digest = h.hexDigest(); 183 char[] digest = h.hexDigest();
171 assert(digest == test_results[i], 184 assert(digest == test_results[i],
172 h.name()~": ("~digest~") != ("~test_results[i]~")"); 185 h.name~": ("~digest~") != ("~test_results[i]~")");
173 } 186 }
174 } 187 }
175 } 188 }
176 } 189 }