Mercurial > projects > dcrypt
annotate dcrypt/crypto/hashes/SHA1.d @ 26:176c933827a8
Implemented MD4. Refactored MD5. Replaced all instances of 'version (UnitTest)' with 'debug (UnitTest)'.
author | Thomas Dixon <reikon@reikon.us> |
---|---|
date | Sun, 01 Mar 2009 13:06:48 -0500 |
parents | 4589f8c5eb3c |
children | 8b5eaf3c2979 |
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.SHA1; | |
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-1. |
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-1 |
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://www.itl.nist.gov/fipspubs/fip180-1.htm |
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 * Bugs: SHA-1 is not cryptographically secure. |
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
|
19 */ |
0 | 20 class SHA1 : Hash { |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
21 protected uint h0, h1, h2, h3, h4; |
0 | 22 |
23 this (void[] input_=null) { | |
24 reset(); | |
25 super(input_); | |
26 } | |
27 | |
28 uint blockSize() { | |
29 return 64; | |
30 } | |
31 | |
32 uint digestSize() { | |
33 return 20; | |
34 } | |
35 | |
36 char[] name() { | |
37 return "SHA1"; | |
38 } | |
39 | |
40 void transform(ubyte[] input) { | |
41 uint[] w = new uint[80]; | |
42 | |
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
|
43 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
|
44 w[i] = ByteConverter.BigEndian.to!(uint)(input[j..j+int.sizeof]); |
0 | 45 |
46 for (int i = 16; i < 80; i++) | |
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
|
47 w[i] = Bitwise.rotateLeft(w[i-3]^w[i-8]^w[i-14]^w[i-16], 1); |
0 | 48 |
49 uint a = h0, | |
50 b = h1, | |
51 c = h2, | |
52 d = h3, | |
53 e = h4; | |
54 | |
55 int i = 0; | |
56 for (; i < 20;) { | |
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
|
57 e += Bitwise.rotateLeft(a, 5) + f0(b, c, d) + w[i++]; |
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
|
58 b = Bitwise.rotateLeft(b, 30); |
0 | 59 |
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
|
60 d += Bitwise.rotateLeft(e, 5) + f0(a, b, c) + w[i++]; |
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
|
61 a = Bitwise.rotateLeft(a, 30); |
0 | 62 |
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
|
63 c += Bitwise.rotateLeft(d, 5) + f0(e, a, b) + w[i++]; |
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
|
64 e = Bitwise.rotateLeft(e, 30); |
0 | 65 |
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
|
66 b += Bitwise.rotateLeft(c, 5) + f0(d, e, a) + w[i++]; |
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 d = Bitwise.rotateLeft(d, 30); |
0 | 68 |
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
|
69 a += Bitwise.rotateLeft(b, 5) + f0(c, d, e) + w[i++]; |
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
|
70 c = Bitwise.rotateLeft(c, 30); |
0 | 71 } |
72 | |
73 for (; i < 40;) { | |
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
|
74 e += Bitwise.rotateLeft(a, 5) + f1(b, c, d) + w[i++]; |
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
|
75 b = Bitwise.rotateLeft(b, 30); |
0 | 76 |
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
|
77 d += Bitwise.rotateLeft(e, 5) + f1(a, b, c) + w[i++]; |
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
|
78 a = Bitwise.rotateLeft(a, 30); |
0 | 79 |
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
|
80 c += Bitwise.rotateLeft(d, 5) + f1(e, a, b) + w[i++]; |
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
|
81 e = Bitwise.rotateLeft(e, 30); |
0 | 82 |
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
|
83 b += Bitwise.rotateLeft(c, 5) + f1(d, e, a) + w[i++]; |
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
|
84 d = Bitwise.rotateLeft(d, 30); |
0 | 85 |
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
|
86 a += Bitwise.rotateLeft(b, 5) + f1(c, d, e) + w[i++]; |
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
|
87 c = Bitwise.rotateLeft(c, 30); |
0 | 88 } |
89 | |
90 for (; i < 60;) { | |
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
|
91 e += Bitwise.rotateLeft(a, 5) + f2(b, c, d) + w[i++]; |
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
|
92 b = Bitwise.rotateLeft(b, 30); |
0 | 93 |
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
|
94 d += Bitwise.rotateLeft(e, 5) + f2(a, b, c) + w[i++]; |
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
|
95 a = Bitwise.rotateLeft(a, 30); |
0 | 96 |
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
|
97 c += Bitwise.rotateLeft(d, 5) + f2(e, a, b) + w[i++]; |
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
|
98 e = Bitwise.rotateLeft(e, 30); |
0 | 99 |
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
|
100 b += Bitwise.rotateLeft(c, 5) + f2(d, e, a) + w[i++]; |
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
|
101 d = Bitwise.rotateLeft(d, 30); |
0 | 102 |
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
|
103 a += Bitwise.rotateLeft(b, 5) + f2(c, d, e) + w[i++]; |
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
|
104 c = Bitwise.rotateLeft(c, 30); |
0 | 105 } |
106 | |
107 for (; i < 80;) { | |
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
|
108 e += Bitwise.rotateLeft(a, 5) + f3(b, c, d) + w[i++]; |
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
|
109 b = Bitwise.rotateLeft(b, 30); |
0 | 110 |
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
|
111 d += Bitwise.rotateLeft(e, 5) + f3(a, b, c) + w[i++]; |
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
|
112 a = Bitwise.rotateLeft(a, 30); |
0 | 113 |
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
|
114 c += Bitwise.rotateLeft(d, 5) + f3(e, a, b) + w[i++]; |
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
|
115 e = Bitwise.rotateLeft(e, 30); |
0 | 116 |
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
|
117 b += Bitwise.rotateLeft(c, 5) + f3(d, e, a) + w[i++]; |
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 d = Bitwise.rotateLeft(d, 30); |
0 | 119 |
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
|
120 a += Bitwise.rotateLeft(b, 5) + f3(c, d, e) + w[i++]; |
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
|
121 c = Bitwise.rotateLeft(c, 30); |
0 | 122 } |
123 | |
124 h0 += a; | |
125 h1 += b; | |
126 h2 += c; | |
127 h3 += d; | |
128 h4 += e; | |
129 } | |
130 | |
131 private uint f0(uint x, uint y, uint z) { | |
132 return (z^(x&(y^z))) + 0x5a827999; | |
133 } | |
134 | |
135 private uint f1(uint x, uint y, uint z) { | |
136 return (x^y^z) + 0x6ed9eba1; | |
137 } | |
138 | |
139 private uint f2(uint x, uint y, uint z) { | |
140 return ((x&y)|(z&(x|y))) + 0x8f1bbcdc; | |
141 } | |
142 | |
143 private uint f3(uint x, uint y, uint z) { | |
144 return (x^y^z) + 0xca62c1d6; | |
145 } | |
146 | |
147 ubyte[] digest() { | |
148 padMessage(MODE_SHA); | |
149 ubyte[] result = new ubyte[digestSize]; | |
150 | |
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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 result[16..20] = ByteConverter.BigEndian.from!(uint)(h4); |
0 | 156 |
157 reset(); | |
158 return result; | |
159 } | |
160 | |
161 void reset() { | |
162 super.reset(); | |
163 h0 = 0x67452301u; | |
164 h1 = 0xefcdab89u; | |
165 h2 = 0x98badcfeu; | |
166 h3 = 0x10325476u; | |
167 h4 = 0xc3d2e1f0u; | |
168 } | |
169 | |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
170 SHA1 copy() { |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
171 SHA1 h = new SHA1(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
|
172 h.bytes = bytes; |
2
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
173 h.h0 = h0; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
174 h.h1 = h1; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
175 h.h2 = h2; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
176 h.h3 = h3; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
177 h.h4 = h4; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
178 return h; |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
179 } |
71aae178f89a
Added copy() to hash functions. Modified some code style.
Thomas Dixon <reikon@reikon.us>
parents:
0
diff
changeset
|
180 |
26
176c933827a8
Implemented MD4. Refactored MD5. Replaced all instances of 'version (UnitTest)' with 'debug (UnitTest)'.
Thomas Dixon <reikon@reikon.us>
parents:
23
diff
changeset
|
181 debug (UnitTest) { |
0 | 182 unittest { |
183 static const char[][] test_inputs = [ | |
184 "", | |
185 "abc", | |
186 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | |
187 "a", | |
188 "0123456701234567012345670123456701234567012345670123456701234567" | |
189 ]; | |
190 | |
191 static const int[] test_repeat = [ | |
192 1, 1, 1, 1000000, 10 | |
193 ]; | |
194 | |
195 static const char[][] test_results = [ | |
196 "da39a3ee5e6b4b0d3255bfef95601890afd80709", | |
197 "a9993e364706816aba3e25717850c26c9cd0d89d", | |
198 "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | |
199 "34aa973cd4c4daa4f61eeb2bdbad27316534016f", | |
200 "dea356a2cddd90c7a7ecedc5ebb563934f460452" | |
201 ]; | |
202 | |
203 SHA1 h = new SHA1(); | |
204 foreach (uint i, char[] input; test_inputs) { | |
205 for (int j = 0; j < test_repeat[i]; j++) | |
206 h.update(input); | |
207 char[] digest = h.hexDigest(); | |
208 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
|
209 h.name~": ("~digest~") != ("~test_results[i]~")"); |
0 | 210 } |
211 } | |
212 } | |
213 } |