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 (embedded 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> */
96 #elif (defined(_AIX) || defined(__hpux))
99 * Defines Big Endian on a whitelist of OSs that are known to be Big
101 * https://lore.kernel.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 #ifndef SHA1DC_FORCE_ALIGNED_ACCESS
128 #if defined(SHA1DC_FORCE_UNALIGNED_ACCESS) || defined(SHA1DC_ON_INTEL_LIKE_PROCESSOR)
129 #define SHA1DC_ALLOW_UNALIGNED_ACCESS
130 #endif /*UNALIGNED ACCESS DETECTION*/
131 #endif /*FORCE ALIGNED ACCESS*/
133 #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n))))
134 #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n))))
136 #define sha1_bswap32(x) \
137 {x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); x = (x << 16) | (x >> 16);}
139 #define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1))
141 #ifdef SHA1DC_BIGENDIAN
142 #define sha1_load(m, t, temp) { temp = m[t]; }
144 #define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); }
147 #define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x
149 #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d))))
150 #define sha1_f2(b,c,d) ((b)^(c)^(d))
151 #define sha1_f3(b,c,d) (((b)&(c))+((d)&((b)^(c))))
152 #define sha1_f4(b,c,d) ((b)^(c)^(d))
154 #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \
155 { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); }
156 #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \
157 { e += rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; b = rotate_left(b, 30); }
158 #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \
159 { e += rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; b = rotate_left(b, 30); }
160 #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \
161 { e += rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; b = rotate_left(b, 30); }
163 #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \
164 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; }
165 #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \
166 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; }
167 #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \
168 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; }
169 #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \
170 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; }
172 #define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \
173 {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);}
175 #define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \
176 {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); }
178 #define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \
179 {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); }
181 #define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \
182 {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); }
184 #define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \
185 {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); }
188 #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;
190 #ifdef BUILDNOCOLLDETECTSHA1COMPRESSION
191 void sha1_compression(uint32_t ihv[5], const uint32_t m[16])
197 memcpy(W, m, 16 * 4);
198 for (i = 16; i < 80; ++i)
199 W[i] = sha1_mix(W, i);
201 a = ihv[0]; b = ihv[1]; c = ihv[2]; d = ihv[3]; e = ihv[4];
203 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
204 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
205 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
206 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
207 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
208 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
209 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
210 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
211 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
212 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
213 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
214 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
215 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
216 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
217 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
218 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
219 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
220 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
221 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
222 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
224 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
225 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
226 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
227 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
228 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
229 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
230 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
231 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
232 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
233 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
234 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
235 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
236 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
237 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
238 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
239 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
240 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
241 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
242 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
243 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
245 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
246 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
247 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
248 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
249 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
250 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
251 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
252 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
253 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
254 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
255 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
256 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
257 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
258 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
259 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
260 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
261 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
262 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
263 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
264 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
266 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
267 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
268 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
269 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
270 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
271 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
272 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
273 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
274 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
275 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
276 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
277 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
278 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
279 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
280 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
281 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
282 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
283 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
284 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
285 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
287 ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
289 #endif /*BUILDNOCOLLDETECTSHA1COMPRESSION*/
292 static void sha1_compression_W(uint32_t ihv[5], const uint32_t W[80])
294 uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
296 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 0);
297 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 1);
298 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 2);
299 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 3);
300 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 4);
301 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 5);
302 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 6);
303 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 7);
304 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 8);
305 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 9);
306 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 10);
307 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 11);
308 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 12);
309 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 13);
310 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 14);
311 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, W, 15);
312 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, W, 16);
313 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, W, 17);
314 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, W, 18);
315 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, W, 19);
317 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 20);
318 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 21);
319 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 22);
320 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 23);
321 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 24);
322 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 25);
323 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 26);
324 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 27);
325 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 28);
326 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 29);
327 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 30);
328 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 31);
329 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 32);
330 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 33);
331 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 34);
332 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, W, 35);
333 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, W, 36);
334 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, W, 37);
335 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, W, 38);
336 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, W, 39);
338 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 40);
339 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 41);
340 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 42);
341 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 43);
342 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 44);
343 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 45);
344 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 46);
345 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 47);
346 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 48);
347 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 49);
348 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 50);
349 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 51);
350 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 52);
351 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 53);
352 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 54);
353 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, W, 55);
354 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, W, 56);
355 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, W, 57);
356 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, W, 58);
357 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, W, 59);
359 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 60);
360 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 61);
361 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 62);
362 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 63);
363 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 64);
364 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 65);
365 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 66);
366 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 67);
367 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 68);
368 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 69);
369 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 70);
370 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 71);
371 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 72);
372 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 73);
373 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 74);
374 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, W, 75);
375 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, W, 76);
376 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, W, 77);
377 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, W, 78);
378 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, W, 79);
380 ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
385 void sha1_compression_states(uint32_t ihv[5], const uint32_t m[16], uint32_t W[80], uint32_t states[80][5])
387 uint32_t a = ihv[0], b = ihv[1], c = ihv[2], d = ihv[3], e = ihv[4];
390 #ifdef DOSTORESTATE00
393 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 0, temp);
395 #ifdef DOSTORESTATE01
398 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 1, temp);
400 #ifdef DOSTORESTATE02
403 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 2, temp);
405 #ifdef DOSTORESTATE03
408 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 3, temp);
410 #ifdef DOSTORESTATE04
413 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 4, temp);
415 #ifdef DOSTORESTATE05
418 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 5, temp);
420 #ifdef DOSTORESTATE06
423 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 6, temp);
425 #ifdef DOSTORESTATE07
428 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 7, temp);
430 #ifdef DOSTORESTATE08
433 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 8, temp);
435 #ifdef DOSTORESTATE09
438 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 9, temp);
440 #ifdef DOSTORESTATE10
443 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 10, temp);
445 #ifdef DOSTORESTATE11
448 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e, a, b, c, d, m, W, 11, temp);
450 #ifdef DOSTORESTATE12
453 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d, e, a, b, c, m, W, 12, temp);
455 #ifdef DOSTORESTATE13
458 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c, d, e, a, b, m, W, 13, temp);
460 #ifdef DOSTORESTATE14
463 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b, c, d, e, a, m, W, 14, temp);
465 #ifdef DOSTORESTATE15
468 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, 15, temp);
470 #ifdef DOSTORESTATE16
473 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e, a, b, c, d, W, 16, temp);
475 #ifdef DOSTORESTATE17
478 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d, e, a, b, c, W, 17, temp);
480 #ifdef DOSTORESTATE18
483 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c, d, e, a, b, W, 18, temp);
485 #ifdef DOSTORESTATE19
488 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b, c, d, e, a, W, 19, temp);
492 #ifdef DOSTORESTATE20
495 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 20, temp);
497 #ifdef DOSTORESTATE21
500 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 21, temp);
502 #ifdef DOSTORESTATE22
505 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 22, temp);
507 #ifdef DOSTORESTATE23
510 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 23, temp);
512 #ifdef DOSTORESTATE24
515 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 24, temp);
517 #ifdef DOSTORESTATE25
520 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 25, temp);
522 #ifdef DOSTORESTATE26
525 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 26, temp);
527 #ifdef DOSTORESTATE27
530 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 27, temp);
532 #ifdef DOSTORESTATE28
535 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 28, temp);
537 #ifdef DOSTORESTATE29
540 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 29, temp);
542 #ifdef DOSTORESTATE30
545 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 30, temp);
547 #ifdef DOSTORESTATE31
550 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 31, temp);
552 #ifdef DOSTORESTATE32
555 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 32, temp);
557 #ifdef DOSTORESTATE33
560 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 33, temp);
562 #ifdef DOSTORESTATE34
565 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 34, temp);
567 #ifdef DOSTORESTATE35
570 SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, 35, temp);
572 #ifdef DOSTORESTATE36
575 SHA1COMPRESS_FULL_ROUND2_STEP(e, a, b, c, d, W, 36, temp);
577 #ifdef DOSTORESTATE37
580 SHA1COMPRESS_FULL_ROUND2_STEP(d, e, a, b, c, W, 37, temp);
582 #ifdef DOSTORESTATE38
585 SHA1COMPRESS_FULL_ROUND2_STEP(c, d, e, a, b, W, 38, temp);
587 #ifdef DOSTORESTATE39
590 SHA1COMPRESS_FULL_ROUND2_STEP(b, c, d, e, a, W, 39, temp);
594 #ifdef DOSTORESTATE40
597 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 40, temp);
599 #ifdef DOSTORESTATE41
602 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 41, temp);
604 #ifdef DOSTORESTATE42
607 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 42, temp);
609 #ifdef DOSTORESTATE43
612 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 43, temp);
614 #ifdef DOSTORESTATE44
617 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 44, temp);
619 #ifdef DOSTORESTATE45
622 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 45, temp);
624 #ifdef DOSTORESTATE46
627 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 46, temp);
629 #ifdef DOSTORESTATE47
632 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 47, temp);
634 #ifdef DOSTORESTATE48
637 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 48, temp);
639 #ifdef DOSTORESTATE49
642 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 49, temp);
644 #ifdef DOSTORESTATE50
647 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 50, temp);
649 #ifdef DOSTORESTATE51
652 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 51, temp);
654 #ifdef DOSTORESTATE52
657 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 52, temp);
659 #ifdef DOSTORESTATE53
662 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 53, temp);
664 #ifdef DOSTORESTATE54
667 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 54, temp);
669 #ifdef DOSTORESTATE55
672 SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, 55, temp);
674 #ifdef DOSTORESTATE56
677 SHA1COMPRESS_FULL_ROUND3_STEP(e, a, b, c, d, W, 56, temp);
679 #ifdef DOSTORESTATE57
682 SHA1COMPRESS_FULL_ROUND3_STEP(d, e, a, b, c, W, 57, temp);
684 #ifdef DOSTORESTATE58
687 SHA1COMPRESS_FULL_ROUND3_STEP(c, d, e, a, b, W, 58, temp);
689 #ifdef DOSTORESTATE59
692 SHA1COMPRESS_FULL_ROUND3_STEP(b, c, d, e, a, W, 59, temp);
697 #ifdef DOSTORESTATE60
700 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 60, temp);
702 #ifdef DOSTORESTATE61
705 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 61, temp);
707 #ifdef DOSTORESTATE62
710 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 62, temp);
712 #ifdef DOSTORESTATE63
715 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 63, temp);
717 #ifdef DOSTORESTATE64
720 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 64, temp);
722 #ifdef DOSTORESTATE65
725 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 65, temp);
727 #ifdef DOSTORESTATE66
730 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 66, temp);
732 #ifdef DOSTORESTATE67
735 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 67, temp);
737 #ifdef DOSTORESTATE68
740 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 68, temp);
742 #ifdef DOSTORESTATE69
745 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 69, temp);
747 #ifdef DOSTORESTATE70
750 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 70, temp);
752 #ifdef DOSTORESTATE71
755 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 71, temp);
757 #ifdef DOSTORESTATE72
760 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 72, temp);
762 #ifdef DOSTORESTATE73
765 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 73, temp);
767 #ifdef DOSTORESTATE74
770 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 74, temp);
772 #ifdef DOSTORESTATE75
775 SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, 75, temp);
777 #ifdef DOSTORESTATE76
780 SHA1COMPRESS_FULL_ROUND4_STEP(e, a, b, c, d, W, 76, temp);
782 #ifdef DOSTORESTATE77
785 SHA1COMPRESS_FULL_ROUND4_STEP(d, e, a, b, c, W, 77, temp);
787 #ifdef DOSTORESTATE78
790 SHA1COMPRESS_FULL_ROUND4_STEP(c, d, e, a, b, W, 78, temp);
792 #ifdef DOSTORESTATE79
795 SHA1COMPRESS_FULL_ROUND4_STEP(b, c, d, e, a, W, 79, temp);
799 ihv[0] += a; ihv[1] += b; ihv[2] += c; ihv[3] += d; ihv[4] += e;
805 #define SHA1_RECOMPRESS(t) \
806 static void sha1recompress_fast_ ## t (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \
808 uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \
809 if (t > 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \
810 if (t > 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \
811 if (t > 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \
812 if (t > 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \
813 if (t > 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \
814 if (t > 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \
815 if (t > 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \
816 if (t > 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \
817 if (t > 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \
818 if (t > 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \
819 if (t > 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \
820 if (t > 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \
821 if (t > 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \
822 if (t > 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \
823 if (t > 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \
824 if (t > 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \
825 if (t > 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \
826 if (t > 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \
827 if (t > 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \
828 if (t > 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \
829 if (t > 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \
830 if (t > 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \
831 if (t > 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \
832 if (t > 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \
833 if (t > 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \
834 if (t > 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \
835 if (t > 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \
836 if (t > 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \
837 if (t > 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \
838 if (t > 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \
839 if (t > 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \
840 if (t > 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \
841 if (t > 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \
842 if (t > 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \
843 if (t > 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \
844 if (t > 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \
845 if (t > 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \
846 if (t > 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \
847 if (t > 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \
848 if (t > 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \
849 if (t > 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \
850 if (t > 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \
851 if (t > 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \
852 if (t > 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \
853 if (t > 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \
854 if (t > 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \
855 if (t > 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \
856 if (t > 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \
857 if (t > 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \
858 if (t > 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \
859 if (t > 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \
860 if (t > 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \
861 if (t > 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \
862 if (t > 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \
863 if (t > 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \
864 if (t > 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \
865 if (t > 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \
866 if (t > 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \
867 if (t > 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \
868 if (t > 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \
869 if (t > 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \
870 if (t > 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \
871 if (t > 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \
872 if (t > 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \
873 if (t > 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \
874 if (t > 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \
875 if (t > 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \
876 if (t > 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \
877 if (t > 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \
878 if (t > 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \
879 if (t > 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \
880 if (t > 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \
881 if (t > 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \
882 if (t > 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \
883 if (t > 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \
884 if (t > 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \
885 if (t > 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \
886 if (t > 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \
887 if (t > 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \
888 if (t > 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \
889 ihvin[0] = a; ihvin[1] = b; ihvin[2] = c; ihvin[3] = d; ihvin[4] = e; \
890 a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; \
891 if (t <= 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \
892 if (t <= 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \
893 if (t <= 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \
894 if (t <= 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \
895 if (t <= 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \
896 if (t <= 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \
897 if (t <= 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \
898 if (t <= 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \
899 if (t <= 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \
900 if (t <= 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \
901 if (t <= 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \
902 if (t <= 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \
903 if (t <= 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \
904 if (t <= 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \
905 if (t <= 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \
906 if (t <= 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \
907 if (t <= 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \
908 if (t <= 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \
909 if (t <= 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \
910 if (t <= 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \
911 if (t <= 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \
912 if (t <= 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \
913 if (t <= 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \
914 if (t <= 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \
915 if (t <= 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \
916 if (t <= 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \
917 if (t <= 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \
918 if (t <= 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \
919 if (t <= 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \
920 if (t <= 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \
921 if (t <= 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \
922 if (t <= 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \
923 if (t <= 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \
924 if (t <= 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \
925 if (t <= 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \
926 if (t <= 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \
927 if (t <= 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \
928 if (t <= 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \
929 if (t <= 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \
930 if (t <= 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \
931 if (t <= 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \
932 if (t <= 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \
933 if (t <= 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \
934 if (t <= 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \
935 if (t <= 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \
936 if (t <= 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \
937 if (t <= 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \
938 if (t <= 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \
939 if (t <= 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \
940 if (t <= 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \
941 if (t <= 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \
942 if (t <= 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \
943 if (t <= 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \
944 if (t <= 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \
945 if (t <= 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \
946 if (t <= 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \
947 if (t <= 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \
948 if (t <= 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \
949 if (t <= 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \
950 if (t <= 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \
951 if (t <= 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \
952 if (t <= 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \
953 if (t <= 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \
954 if (t <= 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \
955 if (t <= 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \
956 if (t <= 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \
957 if (t <= 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \
958 if (t <= 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \
959 if (t <= 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \
960 if (t <= 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \
961 if (t <= 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \
962 if (t <= 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \
963 if (t <= 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \
964 if (t <= 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \
965 if (t <= 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \
966 if (t <= 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \
967 if (t <= 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \
968 if (t <= 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \
969 if (t <= 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \
970 if (t <= 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \
971 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; \
975 #pragma warning(push)
976 #pragma warning(disable: 4127) /* Compiler complains about the checks in the above macro being constant. */
1003 #ifdef DOSTORESTATE6
1007 #ifdef DOSTORESTATE7
1011 #ifdef DOSTORESTATE8
1015 #ifdef DOSTORESTATE9
1019 #ifdef DOSTORESTATE10
1023 #ifdef DOSTORESTATE11
1027 #ifdef DOSTORESTATE12
1031 #ifdef DOSTORESTATE13
1035 #ifdef DOSTORESTATE14
1039 #ifdef DOSTORESTATE15
1043 #ifdef DOSTORESTATE16
1047 #ifdef DOSTORESTATE17
1051 #ifdef DOSTORESTATE18
1055 #ifdef DOSTORESTATE19
1059 #ifdef DOSTORESTATE20
1063 #ifdef DOSTORESTATE21
1067 #ifdef DOSTORESTATE22
1071 #ifdef DOSTORESTATE23
1075 #ifdef DOSTORESTATE24
1079 #ifdef DOSTORESTATE25
1083 #ifdef DOSTORESTATE26
1087 #ifdef DOSTORESTATE27
1091 #ifdef DOSTORESTATE28
1095 #ifdef DOSTORESTATE29
1099 #ifdef DOSTORESTATE30
1103 #ifdef DOSTORESTATE31
1107 #ifdef DOSTORESTATE32
1111 #ifdef DOSTORESTATE33
1115 #ifdef DOSTORESTATE34
1119 #ifdef DOSTORESTATE35
1123 #ifdef DOSTORESTATE36
1127 #ifdef DOSTORESTATE37
1131 #ifdef DOSTORESTATE38
1135 #ifdef DOSTORESTATE39
1139 #ifdef DOSTORESTATE40
1143 #ifdef DOSTORESTATE41
1147 #ifdef DOSTORESTATE42
1151 #ifdef DOSTORESTATE43
1155 #ifdef DOSTORESTATE44
1159 #ifdef DOSTORESTATE45
1163 #ifdef DOSTORESTATE46
1167 #ifdef DOSTORESTATE47
1171 #ifdef DOSTORESTATE48
1175 #ifdef DOSTORESTATE49
1179 #ifdef DOSTORESTATE50
1183 #ifdef DOSTORESTATE51
1187 #ifdef DOSTORESTATE52
1191 #ifdef DOSTORESTATE53
1195 #ifdef DOSTORESTATE54
1199 #ifdef DOSTORESTATE55
1203 #ifdef DOSTORESTATE56
1207 #ifdef DOSTORESTATE57
1211 #ifdef DOSTORESTATE58
1215 #ifdef DOSTORESTATE59
1219 #ifdef DOSTORESTATE60
1223 #ifdef DOSTORESTATE61
1227 #ifdef DOSTORESTATE62
1231 #ifdef DOSTORESTATE63
1235 #ifdef DOSTORESTATE64
1239 #ifdef DOSTORESTATE65
1243 #ifdef DOSTORESTATE66
1247 #ifdef DOSTORESTATE67
1251 #ifdef DOSTORESTATE68
1255 #ifdef DOSTORESTATE69
1259 #ifdef DOSTORESTATE70
1263 #ifdef DOSTORESTATE71
1267 #ifdef DOSTORESTATE72
1271 #ifdef DOSTORESTATE73
1275 #ifdef DOSTORESTATE74
1279 #ifdef DOSTORESTATE75
1283 #ifdef DOSTORESTATE76
1287 #ifdef DOSTORESTATE77
1291 #ifdef DOSTORESTATE78
1295 #ifdef DOSTORESTATE79
1300 #pragma warning(pop)
1303 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])
1307 #ifdef DOSTORESTATE0
1309 sha1recompress_fast_0(ihvin, ihvout, me2, state);
1312 #ifdef DOSTORESTATE1
1314 sha1recompress_fast_1(ihvin, ihvout, me2, state);
1317 #ifdef DOSTORESTATE2
1319 sha1recompress_fast_2(ihvin, ihvout, me2, state);
1322 #ifdef DOSTORESTATE3
1324 sha1recompress_fast_3(ihvin, ihvout, me2, state);
1327 #ifdef DOSTORESTATE4
1329 sha1recompress_fast_4(ihvin, ihvout, me2, state);
1332 #ifdef DOSTORESTATE5
1334 sha1recompress_fast_5(ihvin, ihvout, me2, state);
1337 #ifdef DOSTORESTATE6
1339 sha1recompress_fast_6(ihvin, ihvout, me2, state);
1342 #ifdef DOSTORESTATE7
1344 sha1recompress_fast_7(ihvin, ihvout, me2, state);
1347 #ifdef DOSTORESTATE8
1349 sha1recompress_fast_8(ihvin, ihvout, me2, state);
1352 #ifdef DOSTORESTATE9
1354 sha1recompress_fast_9(ihvin, ihvout, me2, state);
1357 #ifdef DOSTORESTATE10
1359 sha1recompress_fast_10(ihvin, ihvout, me2, state);
1362 #ifdef DOSTORESTATE11
1364 sha1recompress_fast_11(ihvin, ihvout, me2, state);
1367 #ifdef DOSTORESTATE12
1369 sha1recompress_fast_12(ihvin, ihvout, me2, state);
1372 #ifdef DOSTORESTATE13
1374 sha1recompress_fast_13(ihvin, ihvout, me2, state);
1377 #ifdef DOSTORESTATE14
1379 sha1recompress_fast_14(ihvin, ihvout, me2, state);
1382 #ifdef DOSTORESTATE15
1384 sha1recompress_fast_15(ihvin, ihvout, me2, state);
1387 #ifdef DOSTORESTATE16
1389 sha1recompress_fast_16(ihvin, ihvout, me2, state);
1392 #ifdef DOSTORESTATE17
1394 sha1recompress_fast_17(ihvin, ihvout, me2, state);
1397 #ifdef DOSTORESTATE18
1399 sha1recompress_fast_18(ihvin, ihvout, me2, state);
1402 #ifdef DOSTORESTATE19
1404 sha1recompress_fast_19(ihvin, ihvout, me2, state);
1407 #ifdef DOSTORESTATE20
1409 sha1recompress_fast_20(ihvin, ihvout, me2, state);
1412 #ifdef DOSTORESTATE21
1414 sha1recompress_fast_21(ihvin, ihvout, me2, state);
1417 #ifdef DOSTORESTATE22
1419 sha1recompress_fast_22(ihvin, ihvout, me2, state);
1422 #ifdef DOSTORESTATE23
1424 sha1recompress_fast_23(ihvin, ihvout, me2, state);
1427 #ifdef DOSTORESTATE24
1429 sha1recompress_fast_24(ihvin, ihvout, me2, state);
1432 #ifdef DOSTORESTATE25
1434 sha1recompress_fast_25(ihvin, ihvout, me2, state);
1437 #ifdef DOSTORESTATE26
1439 sha1recompress_fast_26(ihvin, ihvout, me2, state);
1442 #ifdef DOSTORESTATE27
1444 sha1recompress_fast_27(ihvin, ihvout, me2, state);
1447 #ifdef DOSTORESTATE28
1449 sha1recompress_fast_28(ihvin, ihvout, me2, state);
1452 #ifdef DOSTORESTATE29
1454 sha1recompress_fast_29(ihvin, ihvout, me2, state);
1457 #ifdef DOSTORESTATE30
1459 sha1recompress_fast_30(ihvin, ihvout, me2, state);
1462 #ifdef DOSTORESTATE31
1464 sha1recompress_fast_31(ihvin, ihvout, me2, state);
1467 #ifdef DOSTORESTATE32
1469 sha1recompress_fast_32(ihvin, ihvout, me2, state);
1472 #ifdef DOSTORESTATE33
1474 sha1recompress_fast_33(ihvin, ihvout, me2, state);
1477 #ifdef DOSTORESTATE34
1479 sha1recompress_fast_34(ihvin, ihvout, me2, state);
1482 #ifdef DOSTORESTATE35
1484 sha1recompress_fast_35(ihvin, ihvout, me2, state);
1487 #ifdef DOSTORESTATE36
1489 sha1recompress_fast_36(ihvin, ihvout, me2, state);
1492 #ifdef DOSTORESTATE37
1494 sha1recompress_fast_37(ihvin, ihvout, me2, state);
1497 #ifdef DOSTORESTATE38
1499 sha1recompress_fast_38(ihvin, ihvout, me2, state);
1502 #ifdef DOSTORESTATE39
1504 sha1recompress_fast_39(ihvin, ihvout, me2, state);
1507 #ifdef DOSTORESTATE40
1509 sha1recompress_fast_40(ihvin, ihvout, me2, state);
1512 #ifdef DOSTORESTATE41
1514 sha1recompress_fast_41(ihvin, ihvout, me2, state);
1517 #ifdef DOSTORESTATE42
1519 sha1recompress_fast_42(ihvin, ihvout, me2, state);
1522 #ifdef DOSTORESTATE43
1524 sha1recompress_fast_43(ihvin, ihvout, me2, state);
1527 #ifdef DOSTORESTATE44
1529 sha1recompress_fast_44(ihvin, ihvout, me2, state);
1532 #ifdef DOSTORESTATE45
1534 sha1recompress_fast_45(ihvin, ihvout, me2, state);
1537 #ifdef DOSTORESTATE46
1539 sha1recompress_fast_46(ihvin, ihvout, me2, state);
1542 #ifdef DOSTORESTATE47
1544 sha1recompress_fast_47(ihvin, ihvout, me2, state);
1547 #ifdef DOSTORESTATE48
1549 sha1recompress_fast_48(ihvin, ihvout, me2, state);
1552 #ifdef DOSTORESTATE49
1554 sha1recompress_fast_49(ihvin, ihvout, me2, state);
1557 #ifdef DOSTORESTATE50
1559 sha1recompress_fast_50(ihvin, ihvout, me2, state);
1562 #ifdef DOSTORESTATE51
1564 sha1recompress_fast_51(ihvin, ihvout, me2, state);
1567 #ifdef DOSTORESTATE52
1569 sha1recompress_fast_52(ihvin, ihvout, me2, state);
1572 #ifdef DOSTORESTATE53
1574 sha1recompress_fast_53(ihvin, ihvout, me2, state);
1577 #ifdef DOSTORESTATE54
1579 sha1recompress_fast_54(ihvin, ihvout, me2, state);
1582 #ifdef DOSTORESTATE55
1584 sha1recompress_fast_55(ihvin, ihvout, me2, state);
1587 #ifdef DOSTORESTATE56
1589 sha1recompress_fast_56(ihvin, ihvout, me2, state);
1592 #ifdef DOSTORESTATE57
1594 sha1recompress_fast_57(ihvin, ihvout, me2, state);
1597 #ifdef DOSTORESTATE58
1599 sha1recompress_fast_58(ihvin, ihvout, me2, state);
1602 #ifdef DOSTORESTATE59
1604 sha1recompress_fast_59(ihvin, ihvout, me2, state);
1607 #ifdef DOSTORESTATE60
1609 sha1recompress_fast_60(ihvin, ihvout, me2, state);
1612 #ifdef DOSTORESTATE61
1614 sha1recompress_fast_61(ihvin, ihvout, me2, state);
1617 #ifdef DOSTORESTATE62
1619 sha1recompress_fast_62(ihvin, ihvout, me2, state);
1622 #ifdef DOSTORESTATE63
1624 sha1recompress_fast_63(ihvin, ihvout, me2, state);
1627 #ifdef DOSTORESTATE64
1629 sha1recompress_fast_64(ihvin, ihvout, me2, state);
1632 #ifdef DOSTORESTATE65
1634 sha1recompress_fast_65(ihvin, ihvout, me2, state);
1637 #ifdef DOSTORESTATE66
1639 sha1recompress_fast_66(ihvin, ihvout, me2, state);
1642 #ifdef DOSTORESTATE67
1644 sha1recompress_fast_67(ihvin, ihvout, me2, state);
1647 #ifdef DOSTORESTATE68
1649 sha1recompress_fast_68(ihvin, ihvout, me2, state);
1652 #ifdef DOSTORESTATE69
1654 sha1recompress_fast_69(ihvin, ihvout, me2, state);
1657 #ifdef DOSTORESTATE70
1659 sha1recompress_fast_70(ihvin, ihvout, me2, state);
1662 #ifdef DOSTORESTATE71
1664 sha1recompress_fast_71(ihvin, ihvout, me2, state);
1667 #ifdef DOSTORESTATE72
1669 sha1recompress_fast_72(ihvin, ihvout, me2, state);
1672 #ifdef DOSTORESTATE73
1674 sha1recompress_fast_73(ihvin, ihvout, me2, state);
1677 #ifdef DOSTORESTATE74
1679 sha1recompress_fast_74(ihvin, ihvout, me2, state);
1682 #ifdef DOSTORESTATE75
1684 sha1recompress_fast_75(ihvin, ihvout, me2, state);
1687 #ifdef DOSTORESTATE76
1689 sha1recompress_fast_76(ihvin, ihvout, me2, state);
1692 #ifdef DOSTORESTATE77
1694 sha1recompress_fast_77(ihvin, ihvout, me2, state);
1697 #ifdef DOSTORESTATE78
1699 sha1recompress_fast_78(ihvin, ihvout, me2, state);
1702 #ifdef DOSTORESTATE79
1704 sha1recompress_fast_79(ihvin, ihvout, me2, state);
1715 static void sha1_process(SHA1_CTX* ctx, const uint32_t block[16])
1718 uint32_t ubc_dv_mask[DVMASKSIZE] = { 0xFFFFFFFF };
1721 ctx->ihv1[0] = ctx->ihv[0];
1722 ctx->ihv1[1] = ctx->ihv[1];
1723 ctx->ihv1[2] = ctx->ihv[2];
1724 ctx->ihv1[3] = ctx->ihv[3];
1725 ctx->ihv1[4] = ctx->ihv[4];
1727 sha1_compression_states(ctx->ihv, block, ctx->m1, ctx->states);
1729 if (ctx->detect_coll)
1733 ubc_check(ctx->m1, ubc_dv_mask);
1736 if (ubc_dv_mask[0] != 0)
1738 for (i = 0; sha1_dvs[i].dvType != 0; ++i)
1740 if (ubc_dv_mask[0] & ((uint32_t)(1) << sha1_dvs[i].maskb))
1742 for (j = 0; j < 80; ++j)
1743 ctx->m2[j] = ctx->m1[j] ^ sha1_dvs[i].dm[j];
1745 sha1_recompression_step(sha1_dvs[i].testt, ctx->ihv2, ihvtmp, ctx->m2, ctx->states[sha1_dvs[i].testt]);
1747 /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */
1748 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])))
1749 || (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]))))
1751 ctx->found_collision = 1;
1755 sha1_compression_W(ctx->ihv, ctx->m1);
1756 sha1_compression_W(ctx->ihv, ctx->m1);
1767 void SHA1DCInit(SHA1_CTX* ctx)
1770 ctx->ihv[0] = 0x67452301;
1771 ctx->ihv[1] = 0xEFCDAB89;
1772 ctx->ihv[2] = 0x98BADCFE;
1773 ctx->ihv[3] = 0x10325476;
1774 ctx->ihv[4] = 0xC3D2E1F0;
1775 ctx->found_collision = 0;
1776 ctx->safe_hash = SHA1DC_INIT_SAFE_HASH_DEFAULT;
1778 ctx->detect_coll = 1;
1779 ctx->reduced_round_coll = 0;
1780 ctx->callback = NULL;
1783 void SHA1DCSetSafeHash(SHA1_CTX* ctx, int safehash)
1792 void SHA1DCSetUseUBC(SHA1_CTX* ctx, int ubc_check)
1800 void SHA1DCSetUseDetectColl(SHA1_CTX* ctx, int detect_coll)
1803 ctx->detect_coll = 1;
1805 ctx->detect_coll = 0;
1808 void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX* ctx, int reduced_round_coll)
1810 if (reduced_round_coll)
1811 ctx->reduced_round_coll = 1;
1813 ctx->reduced_round_coll = 0;
1816 void SHA1DCSetCallback(SHA1_CTX* ctx, collision_block_callback callback)
1818 ctx->callback = callback;
1821 void SHA1DCUpdate(SHA1_CTX* ctx, const char* buf, size_t len)
1823 unsigned left, fill;
1828 left = ctx->total & 63;
1831 if (left && len >= fill)
1834 memcpy(ctx->buffer + left, buf, fill);
1835 sha1_process(ctx, (uint32_t*)(ctx->buffer));
1844 #if defined(SHA1DC_ALLOW_UNALIGNED_ACCESS)
1845 sha1_process(ctx, (uint32_t*)(buf));
1847 memcpy(ctx->buffer, buf, 64);
1848 sha1_process(ctx, (uint32_t*)(ctx->buffer));
1849 #endif /* defined(SHA1DC_ALLOW_UNALIGNED_ACCESS) */
1856 memcpy(ctx->buffer + left, buf, len);
1860 static const unsigned char sha1_padding[64] =
1862 0x80, 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,
1865 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1868 int SHA1DCFinal(unsigned char output[20], SHA1_CTX *ctx)
1870 uint32_t last = ctx->total & 63;
1871 uint32_t padn = (last < 56) ? (56 - last) : (120 - last);
1873 SHA1DCUpdate(ctx, (const char*)(sha1_padding), padn);
1875 total = ctx->total - padn;
1877 ctx->buffer[56] = (unsigned char)(total >> 56);
1878 ctx->buffer[57] = (unsigned char)(total >> 48);
1879 ctx->buffer[58] = (unsigned char)(total >> 40);
1880 ctx->buffer[59] = (unsigned char)(total >> 32);
1881 ctx->buffer[60] = (unsigned char)(total >> 24);
1882 ctx->buffer[61] = (unsigned char)(total >> 16);
1883 ctx->buffer[62] = (unsigned char)(total >> 8);
1884 ctx->buffer[63] = (unsigned char)(total);
1885 sha1_process(ctx, (uint32_t*)(ctx->buffer));
1886 output[0] = (unsigned char)(ctx->ihv[0] >> 24);
1887 output[1] = (unsigned char)(ctx->ihv[0] >> 16);
1888 output[2] = (unsigned char)(ctx->ihv[0] >> 8);
1889 output[3] = (unsigned char)(ctx->ihv[0]);
1890 output[4] = (unsigned char)(ctx->ihv[1] >> 24);
1891 output[5] = (unsigned char)(ctx->ihv[1] >> 16);
1892 output[6] = (unsigned char)(ctx->ihv[1] >> 8);
1893 output[7] = (unsigned char)(ctx->ihv[1]);
1894 output[8] = (unsigned char)(ctx->ihv[2] >> 24);
1895 output[9] = (unsigned char)(ctx->ihv[2] >> 16);
1896 output[10] = (unsigned char)(ctx->ihv[2] >> 8);
1897 output[11] = (unsigned char)(ctx->ihv[2]);
1898 output[12] = (unsigned char)(ctx->ihv[3] >> 24);
1899 output[13] = (unsigned char)(ctx->ihv[3] >> 16);
1900 output[14] = (unsigned char)(ctx->ihv[3] >> 8);
1901 output[15] = (unsigned char)(ctx->ihv[3]);
1902 output[16] = (unsigned char)(ctx->ihv[4] >> 24);
1903 output[17] = (unsigned char)(ctx->ihv[4] >> 16);
1904 output[18] = (unsigned char)(ctx->ihv[4] >> 8);
1905 output[19] = (unsigned char)(ctx->ihv[4]);
1906 return ctx->found_collision;
1909 #ifdef SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C
1910 #include SHA1DC_CUSTOM_TRAILING_INCLUDE_SHA1_C