2 * Copyright 2017 Marc Stevens <marc@marc-stevens.nl>, Dan Shumow (danshu@microsoft.com)
3 * Distributed under the MIT Software License.
4 * See accompanying file LICENSE.txt or copy at
5 * https://opensource.org/licenses/MIT
8 #ifndef SHA1DC_NO_STANDARD_INCLUDES
14 #include <sys/types.h> /* make sure macros like _BIG_ENDIAN visible */
18 #ifdef SHA1DC_CUSTOM_INCLUDE_SHA1_C
19 #include SHA1DC_CUSTOM_INCLUDE_SHA1_C
22 #ifndef SHA1DC_INIT_SAFE_HASH_DEFAULT
23 #define SHA1DC_INIT_SAFE_HASH_DEFAULT 1
27 #include "ubc_check.h"
29 #if (defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || \
30 defined(i386) || defined(__i386) || defined(__i386__) || defined(__i486__) || \
31 defined(__i586__) || defined(__i686__) || defined(_M_IX86) || defined(__X86__) || \
32 defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__) || defined(__INTEL__) || \
33 defined(__386) || defined(_M_X64) || defined(_M_AMD64))
34 #define SHA1DC_ON_INTEL_LIKE_PROCESSOR
38 Because Little-Endian architectures are most common,
39 we only set SHA1DC_BIGENDIAN if one of these conditions is met.
40 Note that all MSFT platforms are little endian,
41 so none of these will be defined under the MSC compiler.
42 If you are compiling on a big endian platform and your compiler does not define one of these,
43 you will have to add whatever macros your tool chain defines to indicate Big-Endianness.
46 #if defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__)
48 * Should detect Big Endian under GCC since at least 4.6.0 (gcc svn
50 * https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
52 * This also works under clang since 3.2, it copied the GCC-ism. See
53 * clang.git's 3b198a97d2 ("Preprocessor: add __BYTE_ORDER__
54 * predefined macro", 2012-07-27)
56 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
57 #define SHA1DC_BIGENDIAN
60 /* Not under GCC-alike */
61 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN)
63 * Should detect Big Endian under glibc.git since 14245eb70e ("entered
64 * into RCS", 1992-11-25). Defined in <endian.h> which will have been
65 * brought in by standard headers. See glibc.git and
66 * https://sourceforge.net/p/predef/wiki/Endianness/
68 #if __BYTE_ORDER == __BIG_ENDIAN
69 #define SHA1DC_BIGENDIAN
72 /* Not under GCC-alike or glibc */
73 #elif defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN)
75 * *BSD and newlib (embeded linux, cygwin, etc).
76 * the defined(_BIG_ENDIAN) && defined(_LITTLE_ENDIAN) part prevents
77 * this condition from matching with Solaris/sparc.
78 * (Solaris defines only one endian macro)
80 #if _BYTE_ORDER == _BIG_ENDIAN
81 #define SHA1DC_BIGENDIAN
84 /* Not under GCC-alike or glibc or *BSD or newlib */
85 #elif (defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
86 defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || \
89 * Should define Big Endian for a whitelist of known processors. See
90 * https://sourceforge.net/p/predef/wiki/Endianness/ and
91 * http://www.oracle.com/technetwork/server-storage/solaris/portingtosolaris-138514.html
93 #define SHA1DC_BIGENDIAN
95 /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> */
99 * Defines Big Endian on a whitelist of OSs that are known to be Big
101 * https://public-inbox.org/git/93056823-2740-d072-1ebd-46b440b33d7e@felt.demon.nl/
103 #define SHA1DC_BIGENDIAN
105 /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <os whitelist> */
106 #elif defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
108 * As a last resort before we do anything else we're not 100% sure
109 * about below, we blacklist specific processors here. We could add
110 * more, see e.g. https://wiki.debian.org/ArchitectureSpecificsMemo
112 #else /* Not under GCC-alike or glibc or *BSD or newlib or <processor whitelist> or <os whitelist> or <processor blacklist> */
114 /* We do nothing more here for now */
115 /*#error "Uncomment this to see if you fall through all the detection"*/
117 #endif /* Big Endian detection */
119 #if (defined(SHA1DC_FORCE_LITTLEENDIAN) && defined(SHA1DC_BIGENDIAN))
120 #undef SHA1DC_BIGENDIAN
122 #if (defined(SHA1DC_FORCE_BIGENDIAN) && !defined(SHA1DC_BIGENDIAN))
123 #define SHA1DC_BIGENDIAN
125 /*ENDIANNESS SELECTION*/
127 #if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
128 #define SHA1DC_ALLOW_UNALIGNED_ACCESS
129 #endif /*UNALIGNMENT DETECTION*/
132 #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n))))
133 #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n))))
135 #define sha1_bswap32(x) \
136 {x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); x = (x << 16) | (x >> 16);}
138 #define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1))
140 #ifdef SHA1DC_BIGENDIAN
141 #define sha1_load(m, t, temp) { temp = m[t]; }
143 #define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); }
146 #define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x
148 #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d))))
149 #define sha1_f2(b,c,d) ((b)^(c)^(d))
150 #define sha1_f3(b,c,d) (((b)&(c))+((d)&((b)^(c))))
151 #define sha1_f4(b,c,d) ((b)^(c)^(d))
153 #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \
154 { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); }
155 #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \
156 { e += rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; b = rotate_left(b, 30); }
157 #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \
158 { e += rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; b = rotate_left(b, 30); }
159 #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \
160 { e += rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; b = rotate_left(b, 30); }
162 #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \
163 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; }
164 #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \
165 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; }
166 #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \
167 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; }
168 #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \
169 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; }
171 #define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \
172 {sha1_load(m, t, temp); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_left(b, 30);}
174 #define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \
175 {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999; b = rotate_left(b, 30); }
177 #define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \
178 {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1; b = rotate_left(b, 30); }
180 #define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \
181 {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC; b = rotate_left(b, 30); }
183 #define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \
184 {temp = sha1_mix(W, t); sha1_store(W, t, temp); e += temp + rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6; b = rotate_left(b, 30); }
187 #define SHA1_STORE_STATE(i) states[i][0] = a; states[i][1] = b; states[i][2] = c; states[i][3] = d; states[i][4] = e;
189 #ifdef BUILDNOCOLLDETECTSHA1COMPRESSION
190 void sha1_compression(uint32_t ihv[5], const uint32_t m[16])
196 memcpy(W, m, 16 * 4);
197 for (i = 16; i < 80; ++i)
198 W[i] = sha1_mix(W, i);
200 a = ihv[0]; b = ihv[1]; c = ihv[2]; d = ihv[3]; e = ihv[4];
202 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
203 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
204 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
205 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
206 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
207 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
208 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
209 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
210 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
211 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
212 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
213 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
214 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
215 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
216 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
217 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
218 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
219 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
220 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
221 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
223 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
224 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
225 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
226 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
227 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
228 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
229 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
230 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
231 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
232 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
233 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
234 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
235 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
236 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
237 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
238 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
239 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
240 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
241 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
242 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
244 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
245 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
246 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
247 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
248 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
249 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
250 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
251 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
252 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
253 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
254 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
255 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
256 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
257 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
258 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
259 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
260 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
261 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
262 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
263 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
265 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
266 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
267 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
268 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
269 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
270 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
271 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
272 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
273 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
274 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
275 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
276 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
277 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
278 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
279 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
280 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
281 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
282 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
283 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
284 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
286 ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
288 #endif /*BUILDNOCOLLDETECTSHA1COMPRESSION*/
291 static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80])
293 uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
295 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
296 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
297 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
298 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
299 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
300 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
301 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
302 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
303 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
304 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
305 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
306 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
307 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
308 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
309 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
310 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
311 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
312 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
313 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
314 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
316 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
317 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
318 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
319 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
320 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
321 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
322 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
323 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
324 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
325 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
326 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
327 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
328 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
329 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
330 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
331 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
332 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
333 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
334 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
335 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
337 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
338 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
339 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
340 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
341 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
342 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
343 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
344 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
345 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
346 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
347 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
348 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
349 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
350 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
351 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
352 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
353 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
354 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
355 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
356 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
358 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
359 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
360 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
361 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
362 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
363 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
364 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
365 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
366 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
367 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
368 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
369 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
370 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
371 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
372 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
373 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
374 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
375 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
376 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
377 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
379 ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
384 void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], uint32_t W[80], uint32_t states[80][5])
386 uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
389 #ifdef DOSTORESTATE00
392 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp);
394 #ifdef DOSTORESTATE01
397 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp);
399 #ifdef DOSTORESTATE02
402 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp);
404 #ifdef DOSTORESTATE03
407 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp);
409 #ifdef DOSTORESTATE04
412 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp);
414 #ifdef DOSTORESTATE05
417 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp);
419 #ifdef DOSTORESTATE06
422 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp);
424 #ifdef DOSTORESTATE07
427 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp);
429 #ifdef DOSTORESTATE08
432 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp);
434 #ifdef DOSTORESTATE09
437 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp);
439 #ifdef DOSTORESTATE10
442 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp);
444 #ifdef DOSTORESTATE11
447 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp);
449 #ifdef DOSTORESTATE12
452 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp);
454 #ifdef DOSTORESTATE13
457 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp);
459 #ifdef DOSTORESTATE14
462 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp);
464 #ifdef DOSTORESTATE15
467 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp);
469 #ifdef DOSTORESTATE16
472 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp);
474 #ifdef DOSTORESTATE17
477 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp);
479 #ifdef DOSTORESTATE18
482 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp);
484 #ifdef DOSTORESTATE19
487 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp);
491 #ifdef DOSTORESTATE20
494 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp);
496 #ifdef DOSTORESTATE21
499 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp);
501 #ifdef DOSTORESTATE22
504 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp);
506 #ifdef DOSTORESTATE23
509 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp);
511 #ifdef DOSTORESTATE24
514 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp);
516 #ifdef DOSTORESTATE25
519 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp);
521 #ifdef DOSTORESTATE26
524 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp);
526 #ifdef DOSTORESTATE27
529 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp);
531 #ifdef DOSTORESTATE28
534 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp);
536 #ifdef DOSTORESTATE29
539 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp);
541 #ifdef DOSTORESTATE30
544 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp);
546 #ifdef DOSTORESTATE31
549 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp);
551 #ifdef DOSTORESTATE32
554 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp);
556 #ifdef DOSTORESTATE33
559 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp);
561 #ifdef DOSTORESTATE34
564 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp);
566 #ifdef DOSTORESTATE35
569 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp);
571 #ifdef DOSTORESTATE36
574 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp);
576 #ifdef DOSTORESTATE37
579 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp);
581 #ifdef DOSTORESTATE38
584 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp);
586 #ifdef DOSTORESTATE39
589 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp);
593 #ifdef DOSTORESTATE40
596 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp);
598 #ifdef DOSTORESTATE41
601 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp);
603 #ifdef DOSTORESTATE42
606 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp);
608 #ifdef DOSTORESTATE43
611 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp);
613 #ifdef DOSTORESTATE44
616 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp);
618 #ifdef DOSTORESTATE45
621 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp);
623 #ifdef DOSTORESTATE46
626 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp);
628 #ifdef DOSTORESTATE47
631 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp);
633 #ifdef DOSTORESTATE48
636 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp);
638 #ifdef DOSTORESTATE49
641 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp);
643 #ifdef DOSTORESTATE50
646 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp);
648 #ifdef DOSTORESTATE51
651 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp);
653 #ifdef DOSTORESTATE52
656 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp);
658 #ifdef DOSTORESTATE53
661 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp);
663 #ifdef DOSTORESTATE54
666 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp);
668 #ifdef DOSTORESTATE55
671 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp);
673 #ifdef DOSTORESTATE56
676 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp);
678 #ifdef DOSTORESTATE57
681 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp);
683 #ifdef DOSTORESTATE58
686 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp);
688 #ifdef DOSTORESTATE59
691 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp);
696 #ifdef DOSTORESTATE60
699 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp);
701 #ifdef DOSTORESTATE61
704 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp);
706 #ifdef DOSTORESTATE62
709 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp);
711 #ifdef DOSTORESTATE63
714 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp);
716 #ifdef DOSTORESTATE64
719 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp);
721 #ifdef DOSTORESTATE65
724 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp);
726 #ifdef DOSTORESTATE66
729 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp);
731 #ifdef DOSTORESTATE67
734 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp);
736 #ifdef DOSTORESTATE68
739 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp);
741 #ifdef DOSTORESTATE69
744 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp);
746 #ifdef DOSTORESTATE70
749 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp);
751 #ifdef DOSTORESTATE71
754 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp);
756 #ifdef DOSTORESTATE72
759 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp);
761 #ifdef DOSTORESTATE73
764 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp);
766 #ifdef DOSTORESTATE74
769 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp);
771 #ifdef DOSTORESTATE75
774 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp);
776 #ifdef DOSTORESTATE76
779 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp);
781 #ifdef DOSTORESTATE77
784 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp);
786 #ifdef DOSTORESTATE78
789 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp);
791 #ifdef DOSTORESTATE79
794 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp);
798 ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
804 #define SHA1_RECOMPRESS(t) \
805 static void sha1recompress_fast_ ## t (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \
807 uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \
808 if (t > 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \
809 if (t > 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \
810 if (t > 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \
811 if (t > 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \
812 if (t > 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \
813 if (t > 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \
814 if (t > 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \
815 if (t > 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \
816 if (t > 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \
817 if (t > 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \
818 if (t > 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \
819 if (t > 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \
820 if (t > 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \
821 if (t > 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \
822 if (t > 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \
823 if (t > 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \
824 if (t > 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \
825 if (t > 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \
826 if (t > 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \
827 if (t > 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \
828 if (t > 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \
829 if (t > 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \
830 if (t > 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \
831 if (t > 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \
832 if (t > 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \
833 if (t > 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \
834 if (t > 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \
835 if (t > 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \
836 if (t > 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \
837 if (t > 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \
838 if (t > 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \
839 if (t > 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \
840 if (t > 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \
841 if (t > 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \
842 if (t > 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \
843 if (t > 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \
844 if (t > 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \
845 if (t > 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \
846 if (t > 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \
847 if (t > 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \
848 if (t > 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \
849 if (t > 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \
850 if (t > 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \
851 if (t > 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \
852 if (t > 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \
853 if (t > 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \
854 if (t > 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \
855 if (t > 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \
856 if (t > 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \
857 if (t > 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \
858 if (t > 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \
859 if (t > 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \
860 if (t > 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \
861 if (t > 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \
862 if (t > 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \
863 if (t > 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \
864 if (t > 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \
865 if (t > 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \
866 if (t > 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \
867 if (t > 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \
868 if (t > 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \
869 if (t > 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \
870 if (t > 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \
871 if (t > 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \
872 if (t > 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \
873 if (t > 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \
874 if (t > 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \
875 if (t > 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \
876 if (t > 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \
877 if (t > 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \
878 if (t > 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \
879 if (t > 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \
880 if (t > 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \
881 if (t > 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \
882 if (t > 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \
883 if (t > 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \
884 if (t > 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \
885 if (t > 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \
886 if (t > 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \
887 if (t > 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \
888 ihvin[0] = a; ihvin[1] = b; ihvin[2] = c; ihvin[3] = d; ihvin[4] = e; \
889 a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; \
890 if (t <= 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \
891 if (t <= 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \
892 if (t <= 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \
893 if (t <= 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \
894 if (t <= 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \
895 if (t <= 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \
896 if (t <= 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \
897 if (t <= 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \
898 if (t <= 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \
899 if (t <= 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \
900 if (t <= 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \
901 if (t <= 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \
902 if (t <= 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \
903 if (t <= 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \
904 if (t <= 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \
905 if (t <= 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \
906 if (t <= 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \
907 if (t <= 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \
908 if (t <= 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \
909 if (t <= 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \
910 if (t <= 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \
911 if (t <= 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \
912 if (t <= 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \
913 if (t <= 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \
914 if (t <= 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \
915 if (t <= 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \
916 if (t <= 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \
917 if (t <= 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \
918 if (t <= 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \
919 if (t <= 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \
920 if (t <= 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \
921 if (t <= 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \
922 if (t <= 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \
923 if (t <= 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \
924 if (t <= 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \
925 if (t <= 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \
926 if (t <= 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \
927 if (t <= 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \
928 if (t <= 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \
929 if (t <= 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \
930 if (t <= 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \
931 if (t <= 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \
932 if (t <= 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \
933 if (t <= 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \
934 if (t <= 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \
935 if (t <= 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \
936 if (t <= 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \
937 if (t <= 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \
938 if (t <= 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \
939 if (t <= 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \
940 if (t <= 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \
941 if (t <= 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \
942 if (t <= 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \
943 if (t <= 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \
944 if (t <= 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \
945 if (t <= 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \
946 if (t <= 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \
947 if (t <= 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \
948 if (t <= 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \
949 if (t <= 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \
950 if (t <= 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \
951 if (t <= 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \
952 if (t <= 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \
953 if (t <= 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \
954 if (t <= 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \
955 if (t <= 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \
956 if (t <= 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \
957 if (t <= 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \
958 if (t <= 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \
959 if (t <= 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \
960 if (t <= 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \
961 if (t <= 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \
962 if (t <= 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \
963 if (t <= 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \
964 if (t <= 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \
965 if (t <= 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \
966 if (t <= 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \
967 if (t <= 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \
968 if (t <= 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \
969 if (t <= 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \
970 ihvout[0] = ihvin[0] + a; ihvout[1] = ihvin[1] + b; ihvout[2] = ihvin[2] + c; ihvout[3] = ihvin[3] + d; ihvout[4] = ihvin[4] + e; \
974 #pragma warning(push)
975 #pragma warning(disable: 4127) /* Compiler complains about the checks in the above macro being constant. */
1002 #ifdef DOSTORESTATE6
1006 #ifdef DOSTORESTATE7
1010 #ifdef DOSTORESTATE8
1014 #ifdef DOSTORESTATE9
1018 #ifdef DOSTORESTATE10
1022 #ifdef DOSTORESTATE11
1026 #ifdef DOSTORESTATE12
1030 #ifdef DOSTORESTATE13
1034 #ifdef DOSTORESTATE14
1038 #ifdef DOSTORESTATE15
1042 #ifdef DOSTORESTATE16
1046 #ifdef DOSTORESTATE17
1050 #ifdef DOSTORESTATE18
1054 #ifdef DOSTORESTATE19
1058 #ifdef DOSTORESTATE20
1062 #ifdef DOSTORESTATE21
1066 #ifdef DOSTORESTATE22
1070 #ifdef DOSTORESTATE23
1074 #ifdef DOSTORESTATE24
1078 #ifdef DOSTORESTATE25
1082 #ifdef DOSTORESTATE26
1086 #ifdef DOSTORESTATE27
1090 #ifdef DOSTORESTATE28
1094 #ifdef DOSTORESTATE29
1098 #ifdef DOSTORESTATE30
1102 #ifdef DOSTORESTATE31
1106 #ifdef DOSTORESTATE32
1110 #ifdef DOSTORESTATE33
1114 #ifdef DOSTORESTATE34
1118 #ifdef DOSTORESTATE35
1122 #ifdef DOSTORESTATE36
1126 #ifdef DOSTORESTATE37
1130 #ifdef DOSTORESTATE38
1134 #ifdef DOSTORESTATE39
1138 #ifdef DOSTORESTATE40
1142 #ifdef DOSTORESTATE41
1146 #ifdef DOSTORESTATE42
1150 #ifdef DOSTORESTATE43
1154 #ifdef DOSTORESTATE44
1158 #ifdef DOSTORESTATE45
1162 #ifdef DOSTORESTATE46
1166 #ifdef DOSTORESTATE47
1170 #ifdef DOSTORESTATE48
1174 #ifdef DOSTORESTATE49
1178 #ifdef DOSTORESTATE50
1182 #ifdef DOSTORESTATE51
1186 #ifdef DOSTORESTATE52
1190 #ifdef DOSTORESTATE53
1194 #ifdef DOSTORESTATE54
1198 #ifdef DOSTORESTATE55
1202 #ifdef DOSTORESTATE56
1206 #ifdef DOSTORESTATE57
1210 #ifdef DOSTORESTATE58
1214 #ifdef DOSTORESTATE59
1218 #ifdef DOSTORESTATE60
1222 #ifdef DOSTORESTATE61
1226 #ifdef DOSTORESTATE62
1230 #ifdef DOSTORESTATE63
1234 #ifdef DOSTORESTATE64
1238 #ifdef DOSTORESTATE65
1242 #ifdef DOSTORESTATE66
1246 #ifdef DOSTORESTATE67
1250 #ifdef DOSTORESTATE68
1254 #ifdef DOSTORESTATE69
1258 #ifdef DOSTORESTATE70
1262 #ifdef DOSTORESTATE71
1266 #ifdef DOSTORESTATE72
1270 #ifdef DOSTORESTATE73
1274 #ifdef DOSTORESTATE74
1278 #ifdef DOSTORESTATE75
1282 #ifdef DOSTORESTATE76
1286 #ifdef DOSTORESTATE77
1290 #ifdef DOSTORESTATE78
1294 #ifdef DOSTORESTATE79
1299 #pragma warning(pop)
1302 static void sha1_recompression_step(uint32_t step, uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5])
1306 #ifdef DOSTORESTATE0
1308 sha1recompress_fast_0(ihvin, ihvout, me2, state);
1311 #ifdef DOSTORESTATE1
1313 sha1recompress_fast_1(ihvin, ihvout, me2, state);
1316 #ifdef DOSTORESTATE2
1318 sha1recompress_fast_2(ihvin, ihvout, me2, state);
1321 #ifdef DOSTORESTATE3
1323 sha1recompress_fast_3(ihvin, ihvout, me2, state);
1326 #ifdef DOSTORESTATE4
1328 sha1recompress_fast_4(ihvin, ihvout, me2, state);
1331 #ifdef DOSTORESTATE5
1333 sha1recompress_fast_5(ihvin, ihvout, me2, state);
1336 #ifdef DOSTORESTATE6
1338 sha1recompress_fast_6(ihvin, ihvout, me2, state);
1341 #ifdef DOSTORESTATE7
1343 sha1recompress_fast_7(ihvin, ihvout, me2, state);
1346 #ifdef DOSTORESTATE8
1348 sha1recompress_fast_8(ihvin, ihvout, me2, state);
1351 #ifdef DOSTORESTATE9
1353 sha1recompress_fast_9(ihvin, ihvout, me2, state);
1356 #ifdef DOSTORESTATE10
1358 sha1recompress_fast_10(ihvin, ihvout, me2, state);
1361 #ifdef DOSTORESTATE11
1363 sha1recompress_fast_11(ihvin, ihvout, me2, state);
1366 #ifdef DOSTORESTATE12
1368 sha1recompress_fast_12(ihvin, ihvout, me2, state);
1371 #ifdef DOSTORESTATE13
1373 sha1recompress_fast_13(ihvin, ihvout, me2, state);
1376 #ifdef DOSTORESTATE14
1378 sha1recompress_fast_14(ihvin, ihvout, me2, state);
1381 #ifdef DOSTORESTATE15
1383 sha1recompress_fast_15(ihvin, ihvout, me2, state);
1386 #ifdef DOSTORESTATE16
1388 sha1recompress_fast_16(ihvin, ihvout, me2, state);
1391 #ifdef DOSTORESTATE17
1393 sha1recompress_fast_17(ihvin, ihvout, me2, state);
1396 #ifdef DOSTORESTATE18
1398 sha1recompress_fast_18(ihvin, ihvout, me2, state);
1401 #ifdef DOSTORESTATE19
1403 sha1recompress_fast_19(ihvin, ihvout, me2, state);
1406 #ifdef DOSTORESTATE20
1408 sha1recompress_fast_20(ihvin, ihvout, me2, state);
1411 #ifdef DOSTORESTATE21
1413 sha1recompress_fast_21(ihvin, ihvout, me2, state);
1416 #ifdef DOSTORESTATE22
1418 sha1recompress_fast_22(ihvin, ihvout, me2, state);
1421 #ifdef DOSTORESTATE23
1423 sha1recompress_fast_23(ihvin, ihvout, me2, state);
1426 #ifdef DOSTORESTATE24
1428 sha1recompress_fast_24(ihvin, ihvout, me2, state);
1431 #ifdef DOSTORESTATE25
1433 sha1recompress_fast_25(ihvin, ihvout, me2, state);
1436 #ifdef DOSTORESTATE26
1438 sha1recompress_fast_26(ihvin, ihvout, me2, state);
1441 #ifdef DOSTORESTATE27
1443 sha1recompress_fast_27(ihvin, ihvout, me2, state);
1446 #ifdef DOSTORESTATE28
1448 sha1recompress_fast_28(ihvin, ihvout, me2, state);
1451 #ifdef DOSTORESTATE29
1453 sha1recompress_fast_29(ihvin, ihvout, me2, state);
1456 #ifdef DOSTORESTATE30
1458 sha1recompress_fast_30(ihvin, ihvout, me2, state);
1461 #ifdef DOSTORESTATE31
1463 sha1recompress_fast_31(ihvin, ihvout, me2, state);
1466 #ifdef DOSTORESTATE32
1468 sha1recompress_fast_32(ihvin, ihvout, me2, state);
1471 #ifdef DOSTORESTATE33
1473 sha1recompress_fast_33(ihvin, ihvout, me2, state);
1476 #ifdef DOSTORESTATE34
1478 sha1recompress_fast_34(ihvin, ihvout, me2, state);
1481 #ifdef DOSTORESTATE35
1483 sha1recompress_fast_35(ihvin, ihvout, me2, state);
1486 #ifdef DOSTORESTATE36
1488 sha1recompress_fast_36(ihvin, ihvout, me2, state);
1491 #ifdef DOSTORESTATE37
1493 sha1recompress_fast_37(ihvin, ihvout, me2, state);
1496 #ifdef DOSTORESTATE38
1498 sha1recompress_fast_38(ihvin, ihvout, me2, state);
1501 #ifdef DOSTORESTATE39
1503 sha1recompress_fast_39(ihvin, ihvout, me2, state);
1506 #ifdef DOSTORESTATE40
1508 sha1recompress_fast_40(ihvin, ihvout, me2, state);
1511 #ifdef DOSTORESTATE41
1513 sha1recompress_fast_41(ihvin, ihvout, me2, state);
1516 #ifdef DOSTORESTATE42
1518 sha1recompress_fast_42(ihvin, ihvout, me2, state);
1521 #ifdef DOSTORESTATE43
1523 sha1recompress_fast_43(ihvin, ihvout, me2, state);
1526 #ifdef DOSTORESTATE44
1528 sha1recompress_fast_44(ihvin, ihvout, me2, state);
1531 #ifdef DOSTORESTATE45
1533 sha1recompress_fast_45(ihvin, ihvout, me2, state);
1536 #ifdef DOSTORESTATE46
1538 sha1recompress_fast_46(ihvin, ihvout, me2, state);
1541 #ifdef DOSTORESTATE47
1543 sha1recompress_fast_47(ihvin, ihvout, me2, state);
1546 #ifdef DOSTORESTATE48
1548 sha1recompress_fast_48(ihvin, ihvout, me2, state);
1551 #ifdef DOSTORESTATE49
1553 sha1recompress_fast_49(ihvin, ihvout, me2, state);
1556 #ifdef DOSTORESTATE50
1558 sha1recompress_fast_50(ihvin, ihvout, me2, state);
1561 #ifdef DOSTORESTATE51
1563 sha1recompress_fast_51(ihvin, ihvout, me2, state);
1566 #ifdef DOSTORESTATE52
1568 sha1recompress_fast_52(ihvin, ihvout, me2, state);
1571 #ifdef DOSTORESTATE53
1573 sha1recompress_fast_53(ihvin, ihvout, me2, state);
1576 #ifdef DOSTORESTATE54
1578 sha1recompress_fast_54(ihvin, ihvout, me2, state);
1581 #ifdef DOSTORESTATE55
1583 sha1recompress_fast_55(ihvin, ihvout, me2, state);
1586 #ifdef DOSTORESTATE56
1588 sha1recompress_fast_56(ihvin, ihvout, me2, state);
1591 #ifdef DOSTORESTATE57
1593 sha1recompress_fast_57(ihvin, ihvout, me2, state);
1596 #ifdef DOSTORESTATE58
1598 sha1recompress_fast_58(ihvin, ihvout, me2, state);
1601 #ifdef DOSTORESTATE59
1603 sha1recompress_fast_59(ihvin, ihvout, me2, state);
1606 #ifdef DOSTORESTATE60
1608 sha1recompress_fast_60(ihvin, ihvout, me2, state);
1611 #ifdef DOSTORESTATE61
1613 sha1recompress_fast_61(ihvin, ihvout, me2, state);
1616 #ifdef DOSTORESTATE62
1618 sha1recompress_fast_62(ihvin, ihvout, me2, state);
1621 #ifdef DOSTORESTATE63
1623 sha1recompress_fast_63(ihvin, ihvout, me2, state);
1626 #ifdef DOSTORESTATE64
1628 sha1recompress_fast_64(ihvin, ihvout, me2, state);
1631 #ifdef DOSTORESTATE65
1633 sha1recompress_fast_65(ihvin, ihvout, me2, state);
1636 #ifdef DOSTORESTATE66
1638 sha1recompress_fast_66(ihvin, ihvout, me2, state);
1641 #ifdef DOSTORESTATE67
1643 sha1recompress_fast_67(ihvin, ihvout, me2, state);
1646 #ifdef DOSTORESTATE68
1648 sha1recompress_fast_68(ihvin, ihvout, me2, state);
1651 #ifdef DOSTORESTATE69
1653 sha1recompress_fast_69(ihvin, ihvout, me2, state);
1656 #ifdef DOSTORESTATE70
1658 sha1recompress_fast_70(ihvin, ihvout, me2, state);
1661 #ifdef DOSTORESTATE71
1663 sha1recompress_fast_71(ihvin, ihvout, me2, state);
1666 #ifdef DOSTORESTATE72
1668 sha1recompress_fast_72(ihvin, ihvout, me2, state);
1671 #ifdef DOSTORESTATE73
1673 sha1recompress_fast_73(ihvin, ihvout, me2, state);
1676 #ifdef DOSTORESTATE74
1678 sha1recompress_fast_74(ihvin, ihvout, me2, state);
1681 #ifdef DOSTORESTATE75
1683 sha1recompress_fast_75(ihvin, ihvout, me2, state);
1686 #ifdef DOSTORESTATE76
1688 sha1recompress_fast_76(ihvin, ihvout, me2, state);
1691 #ifdef DOSTORESTATE77
1693 sha1recompress_fast_77(ihvin, ihvout, me2, state);
1696 #ifdef DOSTORESTATE78
1698 sha1recompress_fast_78(ihvin, ihvout, me2, state);
1701 #ifdef DOSTORESTATE79
1703 sha1recompress_fast_79(ihvin, ihvout, me2, state);
1714 static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
1717 uint32_t ubc_dv_mask[DVMASKSIZE] = { 0xFFFFFFFF };
1720 ctx->ihv1[0] = ctx->ihv[0];
1721 ctx->ihv1[1] = ctx->ihv[1];
1722 ctx->ihv1[2] = ctx->ihv[2];
1723 ctx->ihv1[3] = ctx->ihv[3];
1724 ctx->ihv1[4] = ctx->ihv[4];
1726 sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states);
1728 if (ctx->detect_coll)
1732 ubc_check(ctx->m1, ubc_dv_mask);
1735 if (ubc_dv_mask[0] != 0)
1737 for (i = 0; sha1_dvs[i].dvType != 0; ++i)
1739 if (ubc_dv_mask[0] & ((uint32_t)(1) << sha1_dvs[i].maskb))
1741 for (j = 0; j < 80; ++j)
1742 ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j];
1744 sha1_recompression_step(sha1_dvs[i].testt, ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]);
1746 /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */
1747 if ((0 == ((ihvtmp[0] ^ ctx->ihv[0]) | (ihvtmp[1] ^ ctx->ihv[1]) | (ihvtmp[2] ^ ctx->ihv[2]) | (ihvtmp[3] ^ ctx->ihv[3]) | (ihvtmp[4] ^ ctx->ihv[4])))
1748 || (ctx->reduced_round_coll && 0==((ctx->ihv1[0] ^ ctx->ihv2[0]) | (ctx->ihv1[1] ^ ctx->ihv2[1]) | (ctx->ihv1[2] ^ ctx->ihv2[2]) | (ctx->ihv1[3] ^ ctx->ihv2[3]) | (ctx->ihv1[4] ^ ctx->ihv2[4]))))
1750 ctx->found_collision = 1;
1754 sha1_compression_W(ctx->ihv, ctx->m1);
1755 sha1_compression_W(ctx->ihv, ctx->m1);
1766 void SHA1DCInit(SHA1_CTX* ctx)
1769 ctx->ihv[0] = 0x67452301;
1770 ctx->ihv[1] = 0xEFCDAB89;
1771 ctx->ihv[2] = 0x98BADCFE;
1772 ctx->ihv[3] = 0x10325476;
1773 ctx->ihv[4] = 0xC3D2E1F0;
1774 ctx->found_collision = 0;
1775 ctx->safe_hash = SHA1DC_INIT_SAFE_HASH_DEFAULT;
1777 ctx->detect_coll = 1;
1778 ctx->reduced_round_coll = 0;
1779 ctx->callback = NULL;
1782 void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash)
1791 void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check)
1799 void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll)
1802 ctx->detect_coll = 1;
1804 ctx->detect_coll = 0;
1807 void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll)
1809 if (reduced_round_coll)
1810 ctx->reduced_round_coll = 1;
1812 ctx->reduced_round_coll = 0;
1815 void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback)
1817 ctx->callback = callback;
1820 void SHA1DCUpdate(SHA1_CTX* ctx, const char* buf, size_t len)
1822 unsigned left, fill;
1827 left = ctx->total & 63;
1830 if (left && len >= fill)
1833 memcpy(ctx->buffer + left, buf, fill);
1834 sha1_process(ctx, (uint32_t*)(ctx->buffer));
1843 #if defined(SHA1DC_ALLOW_UNALIGNED_ACCESS)
1844 sha1_process(ctx, (uint32_t*)(buf));
1846 memcpy(ctx->buffer, buf, 64);
1847 sha1_process(ctx, (uint32_t*)(ctx->buffer));
1848 #endif /* defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) */
1855 memcpy(ctx->buffer + left, buf, len);
1859 static const unsigned char sha1_padding[64] =
1861 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1862 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1863 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1864 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1867 int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx)
1869 uint32_t last = ctx->total & 63;
1870 uint32_t padn = (last < 56) ? (56 - last) : (120 - last);
1872 SHA1DCUpdate(ctx, (const char*)(sha1_padding), padn);
1874 total = ctx->total - padn;
1876 ctx->buffer[56] = (unsigned char)(total >> 56);
1877 ctx->buffer[57] = (unsigned char)(total >> 48);
1878 ctx->buffer[58] = (unsigned char)(total >> 40);
1879 ctx->buffer[59] = (unsigned char)(total >> 32);
1880 ctx->buffer[60] = (unsigned char)(total >> 24);
1881 ctx->buffer[61] = (unsigned char)(total >> 16);
1882 ctx->buffer[62] = (unsigned char)(total >> 8);
1883 ctx->buffer[63] = (unsigned char)(total);
1884 sha1_process(ctx, (uint32_t*)(ctx->buffer));
1885 output[0] = (unsigned char)(ctx->ihv[0] >> 24);
1886 output[1] = (unsigned char)(ctx->ihv[0] >> 16);
1887 output[2] = (unsigned char)(ctx->ihv[0] >> 8);
1888 output[3] = (unsigned char)(ctx->ihv[0]);
1889 output[4] = (unsigned char)(ctx->ihv[1] >> 24);
1890 output[5] = (unsigned char)(ctx->ihv[1] >> 16);
1891 output[6] = (unsigned char)(ctx->ihv[1] >> 8);
1892 output[7] = (unsigned char)(ctx->ihv[1]);
1893 output[8] = (unsigned char)(ctx->ihv[2] >> 24);
1894 output[9] = (unsigned char)(ctx->ihv[2] >> 16);
1895 output[10] = (unsigned char)(ctx->ihv[2] >> 8);
1896 output[11] = (unsigned char)(ctx->ihv[2]);
1897 output[12] = (unsigned char)(ctx->ihv[3] >> 24);
1898 output[13] = (unsigned char)(ctx->ihv[3] >> 16);
1899 output[14] = (unsigned char)(ctx->ihv[3] >> 8);
1900 output[15] = (unsigned char)(ctx->ihv[3]);
1901 output[16] = (unsigned char)(ctx->ihv[4] >> 24);
1902 output[17] = (unsigned char)(ctx->ihv[4] >> 16);
1903 output[18] = (unsigned char)(ctx->ihv[4] >> 8);
1904 output[19] = (unsigned char)(ctx->ihv[4]);
1905 return ctx->found_collision;
1908 #ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C
1909 #include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C