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
9 #include "sha1dc/sha1.h"
10 #include "sha1dc/ubc_check.h"
14 Because Little-Endian architectures are most common,
15 we only set BIGENDIAN if one of these conditions is met.
16 Note that all MSFT platforms are little endian,
17 so none of these will be defined under the MSC compiler.
18 If you are compiling on a big endian platform and your compiler does not define one of these,
19 you will have to add whatever macros your tool chain defines to indicate Big-Endianness.
21 #if (defined(__BYTE_ORDER) && (__BYTE_ORDER == __BIG_ENDIAN)) || \
22 (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __BIG_ENDIAN__)) || \
23 defined(__BIG_ENDIAN__) || defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
24 defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
28 #endif /*ENDIANNESS SELECTION*/
30 #define rotate_right(x,n) (((x)>>(n))|((x)<<(32-(n))))
31 #define rotate_left(x,n) (((x)<<(n))|((x)>>(32-(n))))
33 #define sha1_bswap32(x) \
34 {x = ((x << 8) & 0xFF00FF00) | ((x >> 8) & 0xFF00FF); x = (x << 16) | (x >> 16);}
36 #define sha1_mix(W, t) (rotate_left(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1))
38 #if defined(BIGENDIAN)
39 #define sha1_load(m, t, temp) { temp = m[t]; }
41 #define sha1_load(m, t, temp) { temp = m[t]; sha1_bswap32(temp); }
42 #endif /*define(BIGENDIAN)*/
44 #define sha1_store(W, t, x) *(volatile uint32_t *)&W[t] = x
46 #define sha1_f1(b,c,d) ((d)^((b)&((c)^(d))))
47 #define sha1_f2(b,c,d) ((b)^(c)^(d))
48 #define sha1_f3(b,c,d) (((b)&(c))+((d)&((b)^(c))))
49 #define sha1_f4(b,c,d) ((b)^(c)^(d))
51 #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, m, t) \
52 { e += rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; b = rotate_left(b, 30); }
53 #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, m, t) \
54 { e += rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; b = rotate_left(b, 30); }
55 #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, m, t) \
56 { e += rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; b = rotate_left(b, 30); }
57 #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, m, t) \
58 { e += rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; b = rotate_left(b, 30); }
60 #define HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, m, t) \
61 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f1(b,c,d) + 0x5A827999 + m[t]; }
62 #define HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, m, t) \
63 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f2(b,c,d) + 0x6ED9EBA1 + m[t]; }
64 #define HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, m, t) \
65 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f3(b,c,d) + 0x8F1BBCDC + m[t]; }
66 #define HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, m, t) \
67 { b = rotate_right(b, 30); e -= rotate_left(a, 5) + sha1_f4(b,c,d) + 0xCA62C1D6 + m[t]; }
69 #define SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a, b, c, d, e, m, W, t, temp) \
70 {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);}
72 #define SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(a, b, c, d, e, W, t, temp) \
73 {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); }
75 #define SHA1COMPRESS_FULL_ROUND2_STEP(a, b, c, d, e, W, t, temp) \
76 {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); }
78 #define SHA1COMPRESS_FULL_ROUND3_STEP(a, b, c, d, e, W, t, temp) \
79 {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); }
81 #define SHA1COMPRESS_FULL_ROUND4_STEP(a, b, c, d, e, W, t, temp) \
82 {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); }
85 #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;
87 #ifdef BUILDNOCOLLDETECTSHA1COMPRESSION
88 void sha1_compression(uint32_t ihv
[5], const uint32_t m
[16])
95 for (i
= 16; i
< 80; ++i
)
96 W
[i
] = sha1_mix(W
, i
);
98 a
= ihv
[0]; b
= ihv
[1]; c
= ihv
[2]; d
= ihv
[3]; e
= ihv
[4];
100 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 0);
101 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 1);
102 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 2);
103 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 3);
104 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 4);
105 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 5);
106 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 6);
107 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 7);
108 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 8);
109 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 9);
110 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 10);
111 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 11);
112 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 12);
113 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 13);
114 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 14);
115 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 15);
116 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 16);
117 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 17);
118 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 18);
119 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 19);
121 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 20);
122 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 21);
123 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 22);
124 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 23);
125 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 24);
126 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 25);
127 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 26);
128 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 27);
129 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 28);
130 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 29);
131 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 30);
132 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 31);
133 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 32);
134 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 33);
135 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 34);
136 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 35);
137 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 36);
138 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 37);
139 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 38);
140 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 39);
142 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 40);
143 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 41);
144 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 42);
145 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 43);
146 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 44);
147 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 45);
148 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 46);
149 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 47);
150 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 48);
151 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 49);
152 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 50);
153 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 51);
154 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 52);
155 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 53);
156 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 54);
157 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 55);
158 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 56);
159 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 57);
160 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 58);
161 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 59);
163 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 60);
164 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 61);
165 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 62);
166 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 63);
167 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 64);
168 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 65);
169 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 66);
170 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 67);
171 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 68);
172 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 69);
173 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 70);
174 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 71);
175 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 72);
176 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 73);
177 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 74);
178 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 75);
179 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 76);
180 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 77);
181 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 78);
182 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 79);
184 ihv
[0] += a
; ihv
[1] += b
; ihv
[2] += c
; ihv
[3] += d
; ihv
[4] += e
;
186 #endif /*BUILDNOCOLLDETECTSHA1COMPRESSION*/
189 static void sha1_compression_W(uint32_t ihv
[5], const uint32_t W
[80])
191 uint32_t a
= ihv
[0], b
= ihv
[1], c
= ihv
[2], d
= ihv
[3], e
= ihv
[4];
193 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 0);
194 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 1);
195 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 2);
196 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 3);
197 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 4);
198 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 5);
199 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 6);
200 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 7);
201 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 8);
202 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 9);
203 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 10);
204 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 11);
205 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 12);
206 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 13);
207 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 14);
208 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a
, b
, c
, d
, e
, W
, 15);
209 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e
, a
, b
, c
, d
, W
, 16);
210 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d
, e
, a
, b
, c
, W
, 17);
211 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c
, d
, e
, a
, b
, W
, 18);
212 HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b
, c
, d
, e
, a
, W
, 19);
214 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 20);
215 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 21);
216 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 22);
217 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 23);
218 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 24);
219 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 25);
220 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 26);
221 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 27);
222 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 28);
223 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 29);
224 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 30);
225 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 31);
226 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 32);
227 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 33);
228 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 34);
229 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 35);
230 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 36);
231 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 37);
232 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 38);
233 HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 39);
235 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 40);
236 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 41);
237 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 42);
238 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 43);
239 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 44);
240 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 45);
241 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 46);
242 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 47);
243 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 48);
244 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 49);
245 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 50);
246 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 51);
247 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 52);
248 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 53);
249 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 54);
250 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 55);
251 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 56);
252 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 57);
253 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 58);
254 HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 59);
256 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 60);
257 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 61);
258 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 62);
259 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 63);
260 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 64);
261 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 65);
262 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 66);
263 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 67);
264 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 68);
265 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 69);
266 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 70);
267 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 71);
268 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 72);
269 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 73);
270 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 74);
271 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 75);
272 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 76);
273 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 77);
274 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 78);
275 HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 79);
277 ihv
[0] += a
; ihv
[1] += b
; ihv
[2] += c
; ihv
[3] += d
; ihv
[4] += e
;
282 void sha1_compression_states(uint32_t ihv
[5], const uint32_t m
[16], uint32_t W
[80], uint32_t states
[80][5])
284 uint32_t a
= ihv
[0], b
= ihv
[1], c
= ihv
[2], d
= ihv
[3], e
= ihv
[4];
287 #ifdef DOSTORESTATE00
290 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a
, b
, c
, d
, e
, m
, W
, 0, temp
);
292 #ifdef DOSTORESTATE01
295 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e
, a
, b
, c
, d
, m
, W
, 1, temp
);
297 #ifdef DOSTORESTATE02
300 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d
, e
, a
, b
, c
, m
, W
, 2, temp
);
302 #ifdef DOSTORESTATE03
305 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c
, d
, e
, a
, b
, m
, W
, 3, temp
);
307 #ifdef DOSTORESTATE04
310 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b
, c
, d
, e
, a
, m
, W
, 4, temp
);
312 #ifdef DOSTORESTATE05
315 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a
, b
, c
, d
, e
, m
, W
, 5, temp
);
317 #ifdef DOSTORESTATE06
320 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e
, a
, b
, c
, d
, m
, W
, 6, temp
);
322 #ifdef DOSTORESTATE07
325 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d
, e
, a
, b
, c
, m
, W
, 7, temp
);
327 #ifdef DOSTORESTATE08
330 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c
, d
, e
, a
, b
, m
, W
, 8, temp
);
332 #ifdef DOSTORESTATE09
335 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b
, c
, d
, e
, a
, m
, W
, 9, temp
);
337 #ifdef DOSTORESTATE10
340 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a
, b
, c
, d
, e
, m
, W
, 10, temp
);
342 #ifdef DOSTORESTATE11
345 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(e
, a
, b
, c
, d
, m
, W
, 11, temp
);
347 #ifdef DOSTORESTATE12
350 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(d
, e
, a
, b
, c
, m
, W
, 12, temp
);
352 #ifdef DOSTORESTATE13
355 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(c
, d
, e
, a
, b
, m
, W
, 13, temp
);
357 #ifdef DOSTORESTATE14
360 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(b
, c
, d
, e
, a
, m
, W
, 14, temp
);
362 #ifdef DOSTORESTATE15
365 SHA1COMPRESS_FULL_ROUND1_STEP_LOAD(a
, b
, c
, d
, e
, m
, W
, 15, temp
);
367 #ifdef DOSTORESTATE16
370 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(e
, a
, b
, c
, d
, W
, 16, temp
);
372 #ifdef DOSTORESTATE17
375 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(d
, e
, a
, b
, c
, W
, 17, temp
);
377 #ifdef DOSTORESTATE18
380 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(c
, d
, e
, a
, b
, W
, 18, temp
);
382 #ifdef DOSTORESTATE19
385 SHA1COMPRESS_FULL_ROUND1_STEP_EXPAND(b
, c
, d
, e
, a
, W
, 19, temp
);
389 #ifdef DOSTORESTATE20
392 SHA1COMPRESS_FULL_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 20, temp
);
394 #ifdef DOSTORESTATE21
397 SHA1COMPRESS_FULL_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 21, temp
);
399 #ifdef DOSTORESTATE22
402 SHA1COMPRESS_FULL_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 22, temp
);
404 #ifdef DOSTORESTATE23
407 SHA1COMPRESS_FULL_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 23, temp
);
409 #ifdef DOSTORESTATE24
412 SHA1COMPRESS_FULL_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 24, temp
);
414 #ifdef DOSTORESTATE25
417 SHA1COMPRESS_FULL_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 25, temp
);
419 #ifdef DOSTORESTATE26
422 SHA1COMPRESS_FULL_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 26, temp
);
424 #ifdef DOSTORESTATE27
427 SHA1COMPRESS_FULL_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 27, temp
);
429 #ifdef DOSTORESTATE28
432 SHA1COMPRESS_FULL_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 28, temp
);
434 #ifdef DOSTORESTATE29
437 SHA1COMPRESS_FULL_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 29, temp
);
439 #ifdef DOSTORESTATE30
442 SHA1COMPRESS_FULL_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 30, temp
);
444 #ifdef DOSTORESTATE31
447 SHA1COMPRESS_FULL_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 31, temp
);
449 #ifdef DOSTORESTATE32
452 SHA1COMPRESS_FULL_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 32, temp
);
454 #ifdef DOSTORESTATE33
457 SHA1COMPRESS_FULL_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 33, temp
);
459 #ifdef DOSTORESTATE34
462 SHA1COMPRESS_FULL_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 34, temp
);
464 #ifdef DOSTORESTATE35
467 SHA1COMPRESS_FULL_ROUND2_STEP(a
, b
, c
, d
, e
, W
, 35, temp
);
469 #ifdef DOSTORESTATE36
472 SHA1COMPRESS_FULL_ROUND2_STEP(e
, a
, b
, c
, d
, W
, 36, temp
);
474 #ifdef DOSTORESTATE37
477 SHA1COMPRESS_FULL_ROUND2_STEP(d
, e
, a
, b
, c
, W
, 37, temp
);
479 #ifdef DOSTORESTATE38
482 SHA1COMPRESS_FULL_ROUND2_STEP(c
, d
, e
, a
, b
, W
, 38, temp
);
484 #ifdef DOSTORESTATE39
487 SHA1COMPRESS_FULL_ROUND2_STEP(b
, c
, d
, e
, a
, W
, 39, temp
);
491 #ifdef DOSTORESTATE40
494 SHA1COMPRESS_FULL_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 40, temp
);
496 #ifdef DOSTORESTATE41
499 SHA1COMPRESS_FULL_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 41, temp
);
501 #ifdef DOSTORESTATE42
504 SHA1COMPRESS_FULL_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 42, temp
);
506 #ifdef DOSTORESTATE43
509 SHA1COMPRESS_FULL_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 43, temp
);
511 #ifdef DOSTORESTATE44
514 SHA1COMPRESS_FULL_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 44, temp
);
516 #ifdef DOSTORESTATE45
519 SHA1COMPRESS_FULL_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 45, temp
);
521 #ifdef DOSTORESTATE46
524 SHA1COMPRESS_FULL_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 46, temp
);
526 #ifdef DOSTORESTATE47
529 SHA1COMPRESS_FULL_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 47, temp
);
531 #ifdef DOSTORESTATE48
534 SHA1COMPRESS_FULL_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 48, temp
);
536 #ifdef DOSTORESTATE49
539 SHA1COMPRESS_FULL_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 49, temp
);
541 #ifdef DOSTORESTATE50
544 SHA1COMPRESS_FULL_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 50, temp
);
546 #ifdef DOSTORESTATE51
549 SHA1COMPRESS_FULL_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 51, temp
);
551 #ifdef DOSTORESTATE52
554 SHA1COMPRESS_FULL_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 52, temp
);
556 #ifdef DOSTORESTATE53
559 SHA1COMPRESS_FULL_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 53, temp
);
561 #ifdef DOSTORESTATE54
564 SHA1COMPRESS_FULL_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 54, temp
);
566 #ifdef DOSTORESTATE55
569 SHA1COMPRESS_FULL_ROUND3_STEP(a
, b
, c
, d
, e
, W
, 55, temp
);
571 #ifdef DOSTORESTATE56
574 SHA1COMPRESS_FULL_ROUND3_STEP(e
, a
, b
, c
, d
, W
, 56, temp
);
576 #ifdef DOSTORESTATE57
579 SHA1COMPRESS_FULL_ROUND3_STEP(d
, e
, a
, b
, c
, W
, 57, temp
);
581 #ifdef DOSTORESTATE58
584 SHA1COMPRESS_FULL_ROUND3_STEP(c
, d
, e
, a
, b
, W
, 58, temp
);
586 #ifdef DOSTORESTATE59
589 SHA1COMPRESS_FULL_ROUND3_STEP(b
, c
, d
, e
, a
, W
, 59, temp
);
594 #ifdef DOSTORESTATE60
597 SHA1COMPRESS_FULL_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 60, temp
);
599 #ifdef DOSTORESTATE61
602 SHA1COMPRESS_FULL_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 61, temp
);
604 #ifdef DOSTORESTATE62
607 SHA1COMPRESS_FULL_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 62, temp
);
609 #ifdef DOSTORESTATE63
612 SHA1COMPRESS_FULL_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 63, temp
);
614 #ifdef DOSTORESTATE64
617 SHA1COMPRESS_FULL_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 64, temp
);
619 #ifdef DOSTORESTATE65
622 SHA1COMPRESS_FULL_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 65, temp
);
624 #ifdef DOSTORESTATE66
627 SHA1COMPRESS_FULL_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 66, temp
);
629 #ifdef DOSTORESTATE67
632 SHA1COMPRESS_FULL_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 67, temp
);
634 #ifdef DOSTORESTATE68
637 SHA1COMPRESS_FULL_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 68, temp
);
639 #ifdef DOSTORESTATE69
642 SHA1COMPRESS_FULL_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 69, temp
);
644 #ifdef DOSTORESTATE70
647 SHA1COMPRESS_FULL_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 70, temp
);
649 #ifdef DOSTORESTATE71
652 SHA1COMPRESS_FULL_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 71, temp
);
654 #ifdef DOSTORESTATE72
657 SHA1COMPRESS_FULL_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 72, temp
);
659 #ifdef DOSTORESTATE73
662 SHA1COMPRESS_FULL_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 73, temp
);
664 #ifdef DOSTORESTATE74
667 SHA1COMPRESS_FULL_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 74, temp
);
669 #ifdef DOSTORESTATE75
672 SHA1COMPRESS_FULL_ROUND4_STEP(a
, b
, c
, d
, e
, W
, 75, temp
);
674 #ifdef DOSTORESTATE76
677 SHA1COMPRESS_FULL_ROUND4_STEP(e
, a
, b
, c
, d
, W
, 76, temp
);
679 #ifdef DOSTORESTATE77
682 SHA1COMPRESS_FULL_ROUND4_STEP(d
, e
, a
, b
, c
, W
, 77, temp
);
684 #ifdef DOSTORESTATE78
687 SHA1COMPRESS_FULL_ROUND4_STEP(c
, d
, e
, a
, b
, W
, 78, temp
);
689 #ifdef DOSTORESTATE79
692 SHA1COMPRESS_FULL_ROUND4_STEP(b
, c
, d
, e
, a
, W
, 79, temp
);
696 ihv
[0] += a
; ihv
[1] += b
; ihv
[2] += c
; ihv
[3] += d
; ihv
[4] += e
;
702 #define SHA1_RECOMPRESS(t) \
703 static void sha1recompress_fast_ ## t (uint32_t ihvin[5], uint32_t ihvout[5], const uint32_t me2[80], const uint32_t state[5]) \
705 uint32_t a = state[0], b = state[1], c = state[2], d = state[3], e = state[4]; \
706 if (t > 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 79); \
707 if (t > 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 78); \
708 if (t > 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 77); \
709 if (t > 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 76); \
710 if (t > 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 75); \
711 if (t > 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 74); \
712 if (t > 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 73); \
713 if (t > 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 72); \
714 if (t > 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 71); \
715 if (t > 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 70); \
716 if (t > 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 69); \
717 if (t > 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 68); \
718 if (t > 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 67); \
719 if (t > 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 66); \
720 if (t > 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 65); \
721 if (t > 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(b, c, d, e, a, me2, 64); \
722 if (t > 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(c, d, e, a, b, me2, 63); \
723 if (t > 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(d, e, a, b, c, me2, 62); \
724 if (t > 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(e, a, b, c, d, me2, 61); \
725 if (t > 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP_BW(a, b, c, d, e, me2, 60); \
726 if (t > 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 59); \
727 if (t > 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 58); \
728 if (t > 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 57); \
729 if (t > 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 56); \
730 if (t > 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 55); \
731 if (t > 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 54); \
732 if (t > 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 53); \
733 if (t > 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 52); \
734 if (t > 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 51); \
735 if (t > 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 50); \
736 if (t > 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 49); \
737 if (t > 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 48); \
738 if (t > 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 47); \
739 if (t > 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 46); \
740 if (t > 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 45); \
741 if (t > 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(b, c, d, e, a, me2, 44); \
742 if (t > 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(c, d, e, a, b, me2, 43); \
743 if (t > 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(d, e, a, b, c, me2, 42); \
744 if (t > 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(e, a, b, c, d, me2, 41); \
745 if (t > 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP_BW(a, b, c, d, e, me2, 40); \
746 if (t > 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 39); \
747 if (t > 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 38); \
748 if (t > 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 37); \
749 if (t > 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 36); \
750 if (t > 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 35); \
751 if (t > 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 34); \
752 if (t > 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 33); \
753 if (t > 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 32); \
754 if (t > 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 31); \
755 if (t > 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 30); \
756 if (t > 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 29); \
757 if (t > 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 28); \
758 if (t > 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 27); \
759 if (t > 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 26); \
760 if (t > 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 25); \
761 if (t > 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(b, c, d, e, a, me2, 24); \
762 if (t > 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(c, d, e, a, b, me2, 23); \
763 if (t > 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(d, e, a, b, c, me2, 22); \
764 if (t > 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(e, a, b, c, d, me2, 21); \
765 if (t > 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP_BW(a, b, c, d, e, me2, 20); \
766 if (t > 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 19); \
767 if (t > 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 18); \
768 if (t > 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 17); \
769 if (t > 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 16); \
770 if (t > 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 15); \
771 if (t > 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 14); \
772 if (t > 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 13); \
773 if (t > 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 12); \
774 if (t > 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 11); \
775 if (t > 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 10); \
776 if (t > 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 9); \
777 if (t > 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 8); \
778 if (t > 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 7); \
779 if (t > 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 6); \
780 if (t > 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 5); \
781 if (t > 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(b, c, d, e, a, me2, 4); \
782 if (t > 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(c, d, e, a, b, me2, 3); \
783 if (t > 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(d, e, a, b, c, me2, 2); \
784 if (t > 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(e, a, b, c, d, me2, 1); \
785 if (t > 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP_BW(a, b, c, d, e, me2, 0); \
786 ihvin[0] = a; ihvin[1] = b; ihvin[2] = c; ihvin[3] = d; ihvin[4] = e; \
787 a = state[0]; b = state[1]; c = state[2]; d = state[3]; e = state[4]; \
788 if (t <= 0) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 0); \
789 if (t <= 1) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 1); \
790 if (t <= 2) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 2); \
791 if (t <= 3) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 3); \
792 if (t <= 4) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 4); \
793 if (t <= 5) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 5); \
794 if (t <= 6) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 6); \
795 if (t <= 7) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 7); \
796 if (t <= 8) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 8); \
797 if (t <= 9) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 9); \
798 if (t <= 10) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 10); \
799 if (t <= 11) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 11); \
800 if (t <= 12) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 12); \
801 if (t <= 13) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 13); \
802 if (t <= 14) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 14); \
803 if (t <= 15) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(a, b, c, d, e, me2, 15); \
804 if (t <= 16) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(e, a, b, c, d, me2, 16); \
805 if (t <= 17) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(d, e, a, b, c, me2, 17); \
806 if (t <= 18) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(c, d, e, a, b, me2, 18); \
807 if (t <= 19) HASHCLASH_SHA1COMPRESS_ROUND1_STEP(b, c, d, e, a, me2, 19); \
808 if (t <= 20) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 20); \
809 if (t <= 21) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 21); \
810 if (t <= 22) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 22); \
811 if (t <= 23) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 23); \
812 if (t <= 24) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 24); \
813 if (t <= 25) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 25); \
814 if (t <= 26) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 26); \
815 if (t <= 27) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 27); \
816 if (t <= 28) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 28); \
817 if (t <= 29) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 29); \
818 if (t <= 30) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 30); \
819 if (t <= 31) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 31); \
820 if (t <= 32) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 32); \
821 if (t <= 33) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 33); \
822 if (t <= 34) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 34); \
823 if (t <= 35) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(a, b, c, d, e, me2, 35); \
824 if (t <= 36) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(e, a, b, c, d, me2, 36); \
825 if (t <= 37) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(d, e, a, b, c, me2, 37); \
826 if (t <= 38) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(c, d, e, a, b, me2, 38); \
827 if (t <= 39) HASHCLASH_SHA1COMPRESS_ROUND2_STEP(b, c, d, e, a, me2, 39); \
828 if (t <= 40) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 40); \
829 if (t <= 41) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 41); \
830 if (t <= 42) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 42); \
831 if (t <= 43) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 43); \
832 if (t <= 44) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 44); \
833 if (t <= 45) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 45); \
834 if (t <= 46) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 46); \
835 if (t <= 47) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 47); \
836 if (t <= 48) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 48); \
837 if (t <= 49) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 49); \
838 if (t <= 50) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 50); \
839 if (t <= 51) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 51); \
840 if (t <= 52) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 52); \
841 if (t <= 53) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 53); \
842 if (t <= 54) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 54); \
843 if (t <= 55) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(a, b, c, d, e, me2, 55); \
844 if (t <= 56) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(e, a, b, c, d, me2, 56); \
845 if (t <= 57) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(d, e, a, b, c, me2, 57); \
846 if (t <= 58) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(c, d, e, a, b, me2, 58); \
847 if (t <= 59) HASHCLASH_SHA1COMPRESS_ROUND3_STEP(b, c, d, e, a, me2, 59); \
848 if (t <= 60) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 60); \
849 if (t <= 61) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 61); \
850 if (t <= 62) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 62); \
851 if (t <= 63) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 63); \
852 if (t <= 64) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 64); \
853 if (t <= 65) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 65); \
854 if (t <= 66) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 66); \
855 if (t <= 67) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 67); \
856 if (t <= 68) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 68); \
857 if (t <= 69) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 69); \
858 if (t <= 70) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 70); \
859 if (t <= 71) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 71); \
860 if (t <= 72) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 72); \
861 if (t <= 73) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 73); \
862 if (t <= 74) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 74); \
863 if (t <= 75) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(a, b, c, d, e, me2, 75); \
864 if (t <= 76) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(e, a, b, c, d, me2, 76); \
865 if (t <= 77) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(d, e, a, b, c, me2, 77); \
866 if (t <= 78) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(c, d, e, a, b, me2, 78); \
867 if (t <= 79) HASHCLASH_SHA1COMPRESS_ROUND4_STEP(b, c, d, e, a, me2, 79); \
868 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; \
911 #ifdef DOSTORESTATE10
915 #ifdef DOSTORESTATE11
919 #ifdef DOSTORESTATE12
923 #ifdef DOSTORESTATE13
927 #ifdef DOSTORESTATE14
931 #ifdef DOSTORESTATE15
935 #ifdef DOSTORESTATE16
939 #ifdef DOSTORESTATE17
943 #ifdef DOSTORESTATE18
947 #ifdef DOSTORESTATE19
951 #ifdef DOSTORESTATE20
955 #ifdef DOSTORESTATE21
959 #ifdef DOSTORESTATE22
963 #ifdef DOSTORESTATE23
967 #ifdef DOSTORESTATE24
971 #ifdef DOSTORESTATE25
975 #ifdef DOSTORESTATE26
979 #ifdef DOSTORESTATE27
983 #ifdef DOSTORESTATE28
987 #ifdef DOSTORESTATE29
991 #ifdef DOSTORESTATE30
995 #ifdef DOSTORESTATE31
999 #ifdef DOSTORESTATE32
1003 #ifdef DOSTORESTATE33
1007 #ifdef DOSTORESTATE34
1011 #ifdef DOSTORESTATE35
1015 #ifdef DOSTORESTATE36
1019 #ifdef DOSTORESTATE37
1023 #ifdef DOSTORESTATE38
1027 #ifdef DOSTORESTATE39
1031 #ifdef DOSTORESTATE40
1035 #ifdef DOSTORESTATE41
1039 #ifdef DOSTORESTATE42
1043 #ifdef DOSTORESTATE43
1047 #ifdef DOSTORESTATE44
1051 #ifdef DOSTORESTATE45
1055 #ifdef DOSTORESTATE46
1059 #ifdef DOSTORESTATE47
1063 #ifdef DOSTORESTATE48
1067 #ifdef DOSTORESTATE49
1071 #ifdef DOSTORESTATE50
1075 #ifdef DOSTORESTATE51
1079 #ifdef DOSTORESTATE52
1083 #ifdef DOSTORESTATE53
1087 #ifdef DOSTORESTATE54
1091 #ifdef DOSTORESTATE55
1095 #ifdef DOSTORESTATE56
1099 #ifdef DOSTORESTATE57
1103 #ifdef DOSTORESTATE58
1107 #ifdef DOSTORESTATE59
1111 #ifdef DOSTORESTATE60
1115 #ifdef DOSTORESTATE61
1119 #ifdef DOSTORESTATE62
1123 #ifdef DOSTORESTATE63
1127 #ifdef DOSTORESTATE64
1131 #ifdef DOSTORESTATE65
1135 #ifdef DOSTORESTATE66
1139 #ifdef DOSTORESTATE67
1143 #ifdef DOSTORESTATE68
1147 #ifdef DOSTORESTATE69
1151 #ifdef DOSTORESTATE70
1155 #ifdef DOSTORESTATE71
1159 #ifdef DOSTORESTATE72
1163 #ifdef DOSTORESTATE73
1167 #ifdef DOSTORESTATE74
1171 #ifdef DOSTORESTATE75
1175 #ifdef DOSTORESTATE76
1179 #ifdef DOSTORESTATE77
1183 #ifdef DOSTORESTATE78
1187 #ifdef DOSTORESTATE79
1191 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])
1195 #ifdef DOSTORESTATE0
1197 sha1recompress_fast_0(ihvin
, ihvout
, me2
, state
);
1200 #ifdef DOSTORESTATE1
1202 sha1recompress_fast_1(ihvin
, ihvout
, me2
, state
);
1205 #ifdef DOSTORESTATE2
1207 sha1recompress_fast_2(ihvin
, ihvout
, me2
, state
);
1210 #ifdef DOSTORESTATE3
1212 sha1recompress_fast_3(ihvin
, ihvout
, me2
, state
);
1215 #ifdef DOSTORESTATE4
1217 sha1recompress_fast_4(ihvin
, ihvout
, me2
, state
);
1220 #ifdef DOSTORESTATE5
1222 sha1recompress_fast_5(ihvin
, ihvout
, me2
, state
);
1225 #ifdef DOSTORESTATE6
1227 sha1recompress_fast_6(ihvin
, ihvout
, me2
, state
);
1230 #ifdef DOSTORESTATE7
1232 sha1recompress_fast_7(ihvin
, ihvout
, me2
, state
);
1235 #ifdef DOSTORESTATE8
1237 sha1recompress_fast_8(ihvin
, ihvout
, me2
, state
);
1240 #ifdef DOSTORESTATE9
1242 sha1recompress_fast_9(ihvin
, ihvout
, me2
, state
);
1245 #ifdef DOSTORESTATE10
1247 sha1recompress_fast_10(ihvin
, ihvout
, me2
, state
);
1250 #ifdef DOSTORESTATE11
1252 sha1recompress_fast_11(ihvin
, ihvout
, me2
, state
);
1255 #ifdef DOSTORESTATE12
1257 sha1recompress_fast_12(ihvin
, ihvout
, me2
, state
);
1260 #ifdef DOSTORESTATE13
1262 sha1recompress_fast_13(ihvin
, ihvout
, me2
, state
);
1265 #ifdef DOSTORESTATE14
1267 sha1recompress_fast_14(ihvin
, ihvout
, me2
, state
);
1270 #ifdef DOSTORESTATE15
1272 sha1recompress_fast_15(ihvin
, ihvout
, me2
, state
);
1275 #ifdef DOSTORESTATE16
1277 sha1recompress_fast_16(ihvin
, ihvout
, me2
, state
);
1280 #ifdef DOSTORESTATE17
1282 sha1recompress_fast_17(ihvin
, ihvout
, me2
, state
);
1285 #ifdef DOSTORESTATE18
1287 sha1recompress_fast_18(ihvin
, ihvout
, me2
, state
);
1290 #ifdef DOSTORESTATE19
1292 sha1recompress_fast_19(ihvin
, ihvout
, me2
, state
);
1295 #ifdef DOSTORESTATE20
1297 sha1recompress_fast_20(ihvin
, ihvout
, me2
, state
);
1300 #ifdef DOSTORESTATE21
1302 sha1recompress_fast_21(ihvin
, ihvout
, me2
, state
);
1305 #ifdef DOSTORESTATE22
1307 sha1recompress_fast_22(ihvin
, ihvout
, me2
, state
);
1310 #ifdef DOSTORESTATE23
1312 sha1recompress_fast_23(ihvin
, ihvout
, me2
, state
);
1315 #ifdef DOSTORESTATE24
1317 sha1recompress_fast_24(ihvin
, ihvout
, me2
, state
);
1320 #ifdef DOSTORESTATE25
1322 sha1recompress_fast_25(ihvin
, ihvout
, me2
, state
);
1325 #ifdef DOSTORESTATE26
1327 sha1recompress_fast_26(ihvin
, ihvout
, me2
, state
);
1330 #ifdef DOSTORESTATE27
1332 sha1recompress_fast_27(ihvin
, ihvout
, me2
, state
);
1335 #ifdef DOSTORESTATE28
1337 sha1recompress_fast_28(ihvin
, ihvout
, me2
, state
);
1340 #ifdef DOSTORESTATE29
1342 sha1recompress_fast_29(ihvin
, ihvout
, me2
, state
);
1345 #ifdef DOSTORESTATE30
1347 sha1recompress_fast_30(ihvin
, ihvout
, me2
, state
);
1350 #ifdef DOSTORESTATE31
1352 sha1recompress_fast_31(ihvin
, ihvout
, me2
, state
);
1355 #ifdef DOSTORESTATE32
1357 sha1recompress_fast_32(ihvin
, ihvout
, me2
, state
);
1360 #ifdef DOSTORESTATE33
1362 sha1recompress_fast_33(ihvin
, ihvout
, me2
, state
);
1365 #ifdef DOSTORESTATE34
1367 sha1recompress_fast_34(ihvin
, ihvout
, me2
, state
);
1370 #ifdef DOSTORESTATE35
1372 sha1recompress_fast_35(ihvin
, ihvout
, me2
, state
);
1375 #ifdef DOSTORESTATE36
1377 sha1recompress_fast_36(ihvin
, ihvout
, me2
, state
);
1380 #ifdef DOSTORESTATE37
1382 sha1recompress_fast_37(ihvin
, ihvout
, me2
, state
);
1385 #ifdef DOSTORESTATE38
1387 sha1recompress_fast_38(ihvin
, ihvout
, me2
, state
);
1390 #ifdef DOSTORESTATE39
1392 sha1recompress_fast_39(ihvin
, ihvout
, me2
, state
);
1395 #ifdef DOSTORESTATE40
1397 sha1recompress_fast_40(ihvin
, ihvout
, me2
, state
);
1400 #ifdef DOSTORESTATE41
1402 sha1recompress_fast_41(ihvin
, ihvout
, me2
, state
);
1405 #ifdef DOSTORESTATE42
1407 sha1recompress_fast_42(ihvin
, ihvout
, me2
, state
);
1410 #ifdef DOSTORESTATE43
1412 sha1recompress_fast_43(ihvin
, ihvout
, me2
, state
);
1415 #ifdef DOSTORESTATE44
1417 sha1recompress_fast_44(ihvin
, ihvout
, me2
, state
);
1420 #ifdef DOSTORESTATE45
1422 sha1recompress_fast_45(ihvin
, ihvout
, me2
, state
);
1425 #ifdef DOSTORESTATE46
1427 sha1recompress_fast_46(ihvin
, ihvout
, me2
, state
);
1430 #ifdef DOSTORESTATE47
1432 sha1recompress_fast_47(ihvin
, ihvout
, me2
, state
);
1435 #ifdef DOSTORESTATE48
1437 sha1recompress_fast_48(ihvin
, ihvout
, me2
, state
);
1440 #ifdef DOSTORESTATE49
1442 sha1recompress_fast_49(ihvin
, ihvout
, me2
, state
);
1445 #ifdef DOSTORESTATE50
1447 sha1recompress_fast_50(ihvin
, ihvout
, me2
, state
);
1450 #ifdef DOSTORESTATE51
1452 sha1recompress_fast_51(ihvin
, ihvout
, me2
, state
);
1455 #ifdef DOSTORESTATE52
1457 sha1recompress_fast_52(ihvin
, ihvout
, me2
, state
);
1460 #ifdef DOSTORESTATE53
1462 sha1recompress_fast_53(ihvin
, ihvout
, me2
, state
);
1465 #ifdef DOSTORESTATE54
1467 sha1recompress_fast_54(ihvin
, ihvout
, me2
, state
);
1470 #ifdef DOSTORESTATE55
1472 sha1recompress_fast_55(ihvin
, ihvout
, me2
, state
);
1475 #ifdef DOSTORESTATE56
1477 sha1recompress_fast_56(ihvin
, ihvout
, me2
, state
);
1480 #ifdef DOSTORESTATE57
1482 sha1recompress_fast_57(ihvin
, ihvout
, me2
, state
);
1485 #ifdef DOSTORESTATE58
1487 sha1recompress_fast_58(ihvin
, ihvout
, me2
, state
);
1490 #ifdef DOSTORESTATE59
1492 sha1recompress_fast_59(ihvin
, ihvout
, me2
, state
);
1495 #ifdef DOSTORESTATE60
1497 sha1recompress_fast_60(ihvin
, ihvout
, me2
, state
);
1500 #ifdef DOSTORESTATE61
1502 sha1recompress_fast_61(ihvin
, ihvout
, me2
, state
);
1505 #ifdef DOSTORESTATE62
1507 sha1recompress_fast_62(ihvin
, ihvout
, me2
, state
);
1510 #ifdef DOSTORESTATE63
1512 sha1recompress_fast_63(ihvin
, ihvout
, me2
, state
);
1515 #ifdef DOSTORESTATE64
1517 sha1recompress_fast_64(ihvin
, ihvout
, me2
, state
);
1520 #ifdef DOSTORESTATE65
1522 sha1recompress_fast_65(ihvin
, ihvout
, me2
, state
);
1525 #ifdef DOSTORESTATE66
1527 sha1recompress_fast_66(ihvin
, ihvout
, me2
, state
);
1530 #ifdef DOSTORESTATE67
1532 sha1recompress_fast_67(ihvin
, ihvout
, me2
, state
);
1535 #ifdef DOSTORESTATE68
1537 sha1recompress_fast_68(ihvin
, ihvout
, me2
, state
);
1540 #ifdef DOSTORESTATE69
1542 sha1recompress_fast_69(ihvin
, ihvout
, me2
, state
);
1545 #ifdef DOSTORESTATE70
1547 sha1recompress_fast_70(ihvin
, ihvout
, me2
, state
);
1550 #ifdef DOSTORESTATE71
1552 sha1recompress_fast_71(ihvin
, ihvout
, me2
, state
);
1555 #ifdef DOSTORESTATE72
1557 sha1recompress_fast_72(ihvin
, ihvout
, me2
, state
);
1560 #ifdef DOSTORESTATE73
1562 sha1recompress_fast_73(ihvin
, ihvout
, me2
, state
);
1565 #ifdef DOSTORESTATE74
1567 sha1recompress_fast_74(ihvin
, ihvout
, me2
, state
);
1570 #ifdef DOSTORESTATE75
1572 sha1recompress_fast_75(ihvin
, ihvout
, me2
, state
);
1575 #ifdef DOSTORESTATE76
1577 sha1recompress_fast_76(ihvin
, ihvout
, me2
, state
);
1580 #ifdef DOSTORESTATE77
1582 sha1recompress_fast_77(ihvin
, ihvout
, me2
, state
);
1585 #ifdef DOSTORESTATE78
1587 sha1recompress_fast_78(ihvin
, ihvout
, me2
, state
);
1590 #ifdef DOSTORESTATE79
1592 sha1recompress_fast_79(ihvin
, ihvout
, me2
, state
);
1603 static void sha1_process(SHA1_CTX
* ctx
, const uint32_t block
[16])
1606 uint32_t ubc_dv_mask
[DVMASKSIZE
] = { 0xFFFFFFFF };
1609 ctx
->ihv1
[0] = ctx
->ihv
[0];
1610 ctx
->ihv1
[1] = ctx
->ihv
[1];
1611 ctx
->ihv1
[2] = ctx
->ihv
[2];
1612 ctx
->ihv1
[3] = ctx
->ihv
[3];
1613 ctx
->ihv1
[4] = ctx
->ihv
[4];
1615 sha1_compression_states(ctx
->ihv
, block
, ctx
->m1
, ctx
->states
);
1617 if (ctx
->detect_coll
)
1621 ubc_check(ctx
->m1
, ubc_dv_mask
);
1624 if (ubc_dv_mask
[0] != 0)
1626 for (i
= 0; sha1_dvs
[i
].dvType
!= 0; ++i
)
1628 if (ubc_dv_mask
[0] & ((uint32_t)(1) << sha1_dvs
[i
].maskb
))
1630 for (j
= 0; j
< 80; ++j
)
1631 ctx
->m2
[j
] = ctx
->m1
[j
] ^ sha1_dvs
[i
].dm
[j
];
1633 sha1_recompression_step(sha1_dvs
[i
].testt
, ctx
->ihv2
, ihvtmp
, ctx
->m2
, ctx
->states
[sha1_dvs
[i
].testt
]);
1635 /* to verify SHA-1 collision detection code with collisions for reduced-step SHA-1 */
1636 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])))
1637 || (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]))))
1639 ctx
->found_collision
= 1;
1643 sha1_compression_W(ctx
->ihv
, ctx
->m1
);
1644 sha1_compression_W(ctx
->ihv
, ctx
->m1
);
1655 void SHA1DCInit(SHA1_CTX
* ctx
)
1658 ctx
->ihv
[0] = 0x67452301;
1659 ctx
->ihv
[1] = 0xEFCDAB89;
1660 ctx
->ihv
[2] = 0x98BADCFE;
1661 ctx
->ihv
[3] = 0x10325476;
1662 ctx
->ihv
[4] = 0xC3D2E1F0;
1663 ctx
->found_collision
= 0;
1666 ctx
->detect_coll
= 1;
1667 ctx
->reduced_round_coll
= 0;
1668 ctx
->callback
= NULL
;
1671 void SHA1DCSetSafeHash(SHA1_CTX
* ctx
, int safehash
)
1680 void SHA1DCSetUseUBC(SHA1_CTX
* ctx
, int ubc_check
)
1688 void SHA1DCSetUseDetectColl(SHA1_CTX
* ctx
, int detect_coll
)
1691 ctx
->detect_coll
= 1;
1693 ctx
->detect_coll
= 0;
1696 void SHA1DCSetDetectReducedRoundCollision(SHA1_CTX
* ctx
, int reduced_round_coll
)
1698 if (reduced_round_coll
)
1699 ctx
->reduced_round_coll
= 1;
1701 ctx
->reduced_round_coll
= 0;
1704 void SHA1DCSetCallback(SHA1_CTX
* ctx
, collision_block_callback callback
)
1706 ctx
->callback
= callback
;
1709 void SHA1DCUpdate(SHA1_CTX
* ctx
, const char* buf
, size_t len
)
1711 unsigned left
, fill
;
1715 left
= ctx
->total
& 63;
1718 if (left
&& len
>= fill
)
1721 memcpy(ctx
->buffer
+ left
, buf
, fill
);
1722 sha1_process(ctx
, (uint32_t*)(ctx
->buffer
));
1730 sha1_process(ctx
, (uint32_t*)(buf
));
1737 memcpy(ctx
->buffer
+ left
, buf
, len
);
1741 static const unsigned char sha1_padding
[64] =
1743 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1744 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1745 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1746 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1749 int SHA1DCFinal(unsigned char output
[20], SHA1_CTX
*ctx
)
1751 uint32_t last
= ctx
->total
& 63;
1752 uint32_t padn
= (last
< 56) ? (56 - last
) : (120 - last
);
1754 SHA1DCUpdate(ctx
, (const char*)(sha1_padding
), padn
);
1756 total
= ctx
->total
- padn
;
1758 ctx
->buffer
[56] = (unsigned char)(total
>> 56);
1759 ctx
->buffer
[57] = (unsigned char)(total
>> 48);
1760 ctx
->buffer
[58] = (unsigned char)(total
>> 40);
1761 ctx
->buffer
[59] = (unsigned char)(total
>> 32);
1762 ctx
->buffer
[60] = (unsigned char)(total
>> 24);
1763 ctx
->buffer
[61] = (unsigned char)(total
>> 16);
1764 ctx
->buffer
[62] = (unsigned char)(total
>> 8);
1765 ctx
->buffer
[63] = (unsigned char)(total
);
1766 sha1_process(ctx
, (uint32_t*)(ctx
->buffer
));
1767 output
[0] = (unsigned char)(ctx
->ihv
[0] >> 24);
1768 output
[1] = (unsigned char)(ctx
->ihv
[0] >> 16);
1769 output
[2] = (unsigned char)(ctx
->ihv
[0] >> 8);
1770 output
[3] = (unsigned char)(ctx
->ihv
[0]);
1771 output
[4] = (unsigned char)(ctx
->ihv
[1] >> 24);
1772 output
[5] = (unsigned char)(ctx
->ihv
[1] >> 16);
1773 output
[6] = (unsigned char)(ctx
->ihv
[1] >> 8);
1774 output
[7] = (unsigned char)(ctx
->ihv
[1]);
1775 output
[8] = (unsigned char)(ctx
->ihv
[2] >> 24);
1776 output
[9] = (unsigned char)(ctx
->ihv
[2] >> 16);
1777 output
[10] = (unsigned char)(ctx
->ihv
[2] >> 8);
1778 output
[11] = (unsigned char)(ctx
->ihv
[2]);
1779 output
[12] = (unsigned char)(ctx
->ihv
[3] >> 24);
1780 output
[13] = (unsigned char)(ctx
->ihv
[3] >> 16);
1781 output
[14] = (unsigned char)(ctx
->ihv
[3] >> 8);
1782 output
[15] = (unsigned char)(ctx
->ihv
[3]);
1783 output
[16] = (unsigned char)(ctx
->ihv
[4] >> 24);
1784 output
[17] = (unsigned char)(ctx
->ihv
[4] >> 16);
1785 output
[18] = (unsigned char)(ctx
->ihv
[4] >> 8);
1786 output
[19] = (unsigned char)(ctx
->ihv
[4]);
1787 return ctx
->found_collision
;
1790 void git_SHA1DCFinal(unsigned char hash
[20], SHA1_CTX
*ctx
)
1792 if (!SHA1DCFinal(hash
, ctx
))
1794 die("SHA-1 appears to be part of a collision attack: %s",
1798 void git_SHA1DCUpdate(SHA1_CTX
*ctx
, const void *vdata
, unsigned long len
)
1800 const char *data
= vdata
;
1801 /* We expect an unsigned long, but sha1dc only takes an int */
1802 while (len
> INT_MAX
) {
1803 SHA1DCUpdate(ctx
, data
, INT_MAX
);
1807 SHA1DCUpdate(ctx
, data
, len
);