Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m09100.cl
1 /**
2  * Authors.....: Jens Steube <jens.steube@gmail.com>
3  *               Gabriele Gristina <matrix@hashcat.net>
4  *
5  * License.....: MIT
6  */
7
8 #define _LOTUS8_
9
10 #include "inc_vendor.cl"
11 #include "inc_hash_constants.h"
12 #include "inc_hash_functions.cl"
13
14 #undef _SHA1_
15
16 #include "inc_types.cl"
17 #include "inc_common.cl"
18
19 #define COMPARE_S "inc_comp_single.cl"
20 #define COMPARE_M "inc_comp_multi.cl"
21
22 __constant char lotus64_table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
23
24 #define uint_to_hex_upper8(i) l_bin2asc[(i)]
25
26 __constant u32 lotus_magic_table[256] =
27 {
28   0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
29   0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
30   0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
31   0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
32   0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
33   0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
34   0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
35   0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
36   0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
37   0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
38   0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
39   0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
40   0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
41   0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
42   0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
43   0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
44   0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
45   0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
46   0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
47   0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
48   0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
49   0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
50   0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
51   0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
52   0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
53   0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
54   0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
55   0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
56   0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
57   0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
58   0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
59   0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab,
60 };
61
62 #if   VECT_SIZE == 1
63 #define BOX1(S,i) (S)[(i)]
64 #elif VECT_SIZE == 2
65 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1])
66 #elif VECT_SIZE == 4
67 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3])
68 #elif VECT_SIZE == 8
69 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3], (S)[(i).s4], (S)[(i).s5], (S)[(i).s6], (S)[(i).s7])
70 #elif VECT_SIZE == 16
71 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3], (S)[(i).s4], (S)[(i).s5], (S)[(i).s6], (S)[(i).s7], (S)[(i).s8], (S)[(i).s9], (S)[(i).sa], (S)[(i).sb], (S)[(i).sc], (S)[(i).sd], (S)[(i).se], (S)[(i).sf])
72 #endif
73
74 void lotus_mix (u32x *in, __local u32 *s_lotus_magic_table)
75 {
76   u32x p = 0;
77
78   for (int i = 0; i < 18; i++)
79   {
80     u32 s = 48;
81
82     for (int j = 0; j < 12; j++)
83     {
84       u32x tmp_in = in[j];
85       u32x tmp_out = 0;
86
87       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  0;
88       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  8;
89       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 16;
90       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 24;
91
92       in[j] = tmp_out;
93     }
94   }
95 }
96
97 void lotus_transform_password (u32x in[4], u32x out[4], __local u32 *s_lotus_magic_table)
98 {
99   u32x t = out[3] >> 24;
100
101   u32x c;
102
103   #ifdef _unroll
104   #pragma unroll
105   #endif
106   for (int i = 0; i < 4; i++)
107   {
108     t ^= (in[i] >>  0) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
109     t ^= (in[i] >>  8) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
110     t ^= (in[i] >> 16) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
111     t ^= (in[i] >> 24) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
112   }
113 }
114
115 void pad (u32 w[4], const u32 len)
116 {
117   const u32 val = 16 - len;
118
119   const u32 mask1 = val << 24;
120
121   const u32 mask2 = val << 16
122                    | val << 24;
123
124   const u32 mask3 = val <<  8
125                    | val << 16
126                    | val << 24;
127
128   const u32 mask4 = val <<  0
129                    | val <<  8
130                    | val << 16
131                    | val << 24;
132
133   switch (len)
134   {
135     case  0:  w[0]  = mask4;
136               w[1]  = mask4;
137               w[2]  = mask4;
138               w[3]  = mask4;
139               break;
140     case  1:  w[0] |= mask3;
141               w[1]  = mask4;
142               w[2]  = mask4;
143               w[3]  = mask4;
144               break;
145     case  2:  w[0] |= mask2;
146               w[1]  = mask4;
147               w[2]  = mask4;
148               w[3]  = mask4;
149               break;
150     case  3:  w[0] |= mask1;
151               w[1]  = mask4;
152               w[2]  = mask4;
153               w[3]  = mask4;
154               break;
155     case  4:  w[1]  = mask4;
156               w[2]  = mask4;
157               w[3]  = mask4;
158               break;
159     case  5:  w[1] |= mask3;
160               w[2]  = mask4;
161               w[3]  = mask4;
162               break;
163     case  6:  w[1] |= mask2;
164               w[2]  = mask4;
165               w[3]  = mask4;
166               break;
167     case  7:  w[1] |= mask1;
168               w[2]  = mask4;
169               w[3]  = mask4;
170               break;
171     case  8:  w[2]  = mask4;
172               w[3]  = mask4;
173               break;
174     case  9:  w[2] |= mask3;
175               w[3]  = mask4;
176               break;
177     case 10:  w[2] |= mask2;
178               w[3]  = mask4;
179               break;
180     case 11:  w[2] |= mask1;
181               w[3]  = mask4;
182               break;
183     case 12:  w[3]  = mask4;
184               break;
185     case 13:  w[3] |= mask3;
186               break;
187     case 14:  w[3] |= mask2;
188               break;
189     case 15:  w[3] |= mask1;
190               break;
191   }
192 }
193
194 void mdtransform_norecalc (u32x state[4], u32x block[4], __local u32 *s_lotus_magic_table)
195 {
196   u32x x[12];
197
198   x[ 0] = state[0];
199   x[ 1] = state[1];
200   x[ 2] = state[2];
201   x[ 3] = state[3];
202   x[ 4] = block[0];
203   x[ 5] = block[1];
204   x[ 6] = block[2];
205   x[ 7] = block[3];
206   x[ 8] = state[0] ^ block[0];
207   x[ 9] = state[1] ^ block[1];
208   x[10] = state[2] ^ block[2];
209   x[11] = state[3] ^ block[3];
210
211   lotus_mix (x, s_lotus_magic_table);
212
213   state[0] = x[0];
214   state[1] = x[1];
215   state[2] = x[2];
216   state[3] = x[3];
217 }
218
219 void mdtransform (u32x state[4], u32x checksum[4], u32x block[4], __local u32 *s_lotus_magic_table)
220 {
221   mdtransform_norecalc (state, block, s_lotus_magic_table);
222
223   lotus_transform_password (block, checksum, s_lotus_magic_table);
224 }
225
226 void domino_big_md (const u32x saved_key[16], const u32 size, u32x state[4], __local u32 *s_lotus_magic_table)
227 {
228   u32x checksum[4];
229
230   checksum[0] = 0;
231   checksum[1] = 0;
232   checksum[2] = 0;
233   checksum[3] = 0;
234
235   u32x block[4];
236
237   block[0] = 0;
238   block[1] = 0;
239   block[2] = 0;
240   block[3] = 0;
241
242   u32 curpos;
243   u32 idx;
244
245   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
246   {
247     block[0] = saved_key[idx + 0];
248     block[1] = saved_key[idx + 1];
249     block[2] = saved_key[idx + 2];
250     block[3] = saved_key[idx + 3];
251
252     mdtransform (state, checksum, block, s_lotus_magic_table);
253   }
254
255   block[0] = saved_key[idx + 0];
256   block[1] = saved_key[idx + 1];
257   block[2] = saved_key[idx + 2];
258   block[3] = saved_key[idx + 3];
259
260   mdtransform (state, checksum, block, s_lotus_magic_table);
261
262   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
263 }
264
265 void sha1_transform (const u32 w0[4], const u32 w1[4], const u32 w2[4], const u32 w3[4], u32 digest[5])
266 {
267   u32 A = digest[0];
268   u32 B = digest[1];
269   u32 C = digest[2];
270   u32 D = digest[3];
271   u32 E = digest[4];
272
273   u32 w0_t = w0[0];
274   u32 w1_t = w0[1];
275   u32 w2_t = w0[2];
276   u32 w3_t = w0[3];
277   u32 w4_t = w1[0];
278   u32 w5_t = w1[1];
279   u32 w6_t = w1[2];
280   u32 w7_t = w1[3];
281   u32 w8_t = w2[0];
282   u32 w9_t = w2[1];
283   u32 wa_t = w2[2];
284   u32 wb_t = w2[3];
285   u32 wc_t = w3[0];
286   u32 wd_t = w3[1];
287   u32 we_t = w3[2];
288   u32 wf_t = w3[3];
289
290   #undef K
291   #define K SHA1C00
292
293   SHA1_STEP (SHA1_F0o, A, B, C, D, E, w0_t);
294   SHA1_STEP (SHA1_F0o, E, A, B, C, D, w1_t);
295   SHA1_STEP (SHA1_F0o, D, E, A, B, C, w2_t);
296   SHA1_STEP (SHA1_F0o, C, D, E, A, B, w3_t);
297   SHA1_STEP (SHA1_F0o, B, C, D, E, A, w4_t);
298   SHA1_STEP (SHA1_F0o, A, B, C, D, E, w5_t);
299   SHA1_STEP (SHA1_F0o, E, A, B, C, D, w6_t);
300   SHA1_STEP (SHA1_F0o, D, E, A, B, C, w7_t);
301   SHA1_STEP (SHA1_F0o, C, D, E, A, B, w8_t);
302   SHA1_STEP (SHA1_F0o, B, C, D, E, A, w9_t);
303   SHA1_STEP (SHA1_F0o, A, B, C, D, E, wa_t);
304   SHA1_STEP (SHA1_F0o, E, A, B, C, D, wb_t);
305   SHA1_STEP (SHA1_F0o, D, E, A, B, C, wc_t);
306   SHA1_STEP (SHA1_F0o, C, D, E, A, B, wd_t);
307   SHA1_STEP (SHA1_F0o, B, C, D, E, A, we_t);
308   SHA1_STEP (SHA1_F0o, A, B, C, D, E, wf_t);
309   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F0o, E, A, B, C, D, w0_t);
310   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F0o, D, E, A, B, C, w1_t);
311   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F0o, C, D, E, A, B, w2_t);
312   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F0o, B, C, D, E, A, w3_t);
313
314   #undef K
315   #define K SHA1C01
316
317   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w4_t);
318   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w5_t);
319   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w6_t);
320   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w7_t);
321   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w8_t);
322   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w9_t);
323   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wa_t);
324   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, wb_t);
325   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, wc_t);
326   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, wd_t);
327   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, we_t);
328   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wf_t);
329   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w0_t);
330   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w1_t);
331   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w2_t);
332   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w3_t);
333   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w4_t);
334   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w5_t);
335   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w6_t);
336   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w7_t);
337
338   #undef K
339   #define K SHA1C02
340
341   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, w8_t);
342   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, w9_t);
343   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, wa_t);
344   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, wb_t);
345   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, wc_t);
346   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, wd_t);
347   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, we_t);
348   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, wf_t);
349   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, w0_t);
350   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, w1_t);
351   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, w2_t);
352   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, w3_t);
353   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, w4_t);
354   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, w5_t);
355   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, w6_t);
356   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F2o, A, B, C, D, E, w7_t);
357   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F2o, E, A, B, C, D, w8_t);
358   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F2o, D, E, A, B, C, w9_t);
359   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F2o, C, D, E, A, B, wa_t);
360   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F2o, B, C, D, E, A, wb_t);
361
362   #undef K
363   #define K SHA1C03
364
365   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, wc_t);
366   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wd_t);
367   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, we_t);
368   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, wf_t);
369   w0_t = rotl32 ((wd_t ^ w8_t ^ w2_t ^ w0_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w0_t);
370   w1_t = rotl32 ((we_t ^ w9_t ^ w3_t ^ w1_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w1_t);
371   w2_t = rotl32 ((wf_t ^ wa_t ^ w4_t ^ w2_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w2_t);
372   w3_t = rotl32 ((w0_t ^ wb_t ^ w5_t ^ w3_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w3_t);
373   w4_t = rotl32 ((w1_t ^ wc_t ^ w6_t ^ w4_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w4_t);
374   w5_t = rotl32 ((w2_t ^ wd_t ^ w7_t ^ w5_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, w5_t);
375   w6_t = rotl32 ((w3_t ^ we_t ^ w8_t ^ w6_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, w6_t);
376   w7_t = rotl32 ((w4_t ^ wf_t ^ w9_t ^ w7_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, w7_t);
377   w8_t = rotl32 ((w5_t ^ w0_t ^ wa_t ^ w8_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, w8_t);
378   w9_t = rotl32 ((w6_t ^ w1_t ^ wb_t ^ w9_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, w9_t);
379   wa_t = rotl32 ((w7_t ^ w2_t ^ wc_t ^ wa_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, wa_t);
380   wb_t = rotl32 ((w8_t ^ w3_t ^ wd_t ^ wb_t), 1u); SHA1_STEP (SHA1_F1, A, B, C, D, E, wb_t);
381   wc_t = rotl32 ((w9_t ^ w4_t ^ we_t ^ wc_t), 1u); SHA1_STEP (SHA1_F1, E, A, B, C, D, wc_t);
382   wd_t = rotl32 ((wa_t ^ w5_t ^ wf_t ^ wd_t), 1u); SHA1_STEP (SHA1_F1, D, E, A, B, C, wd_t);
383   we_t = rotl32 ((wb_t ^ w6_t ^ w0_t ^ we_t), 1u); SHA1_STEP (SHA1_F1, C, D, E, A, B, we_t);
384   wf_t = rotl32 ((wc_t ^ w7_t ^ w1_t ^ wf_t), 1u); SHA1_STEP (SHA1_F1, B, C, D, E, A, wf_t);
385
386   digest[0] += A;
387   digest[1] += B;
388   digest[2] += C;
389   digest[3] += D;
390   digest[4] += E;
391 }
392
393 void hmac_sha1_pad (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[5], u32 opad[5])
394 {
395   w0[0] = w0[0] ^ 0x36363636;
396   w0[1] = w0[1] ^ 0x36363636;
397   w0[2] = w0[2] ^ 0x36363636;
398   w0[3] = w0[3] ^ 0x36363636;
399   w1[0] = w1[0] ^ 0x36363636;
400   w1[1] = w1[1] ^ 0x36363636;
401   w1[2] = w1[2] ^ 0x36363636;
402   w1[3] = w1[3] ^ 0x36363636;
403   w2[0] = w2[0] ^ 0x36363636;
404   w2[1] = w2[1] ^ 0x36363636;
405   w2[2] = w2[2] ^ 0x36363636;
406   w2[3] = w2[3] ^ 0x36363636;
407   w3[0] = w3[0] ^ 0x36363636;
408   w3[1] = w3[1] ^ 0x36363636;
409   w3[2] = w3[2] ^ 0x36363636;
410   w3[3] = w3[3] ^ 0x36363636;
411
412   ipad[0] = SHA1M_A;
413   ipad[1] = SHA1M_B;
414   ipad[2] = SHA1M_C;
415   ipad[3] = SHA1M_D;
416   ipad[4] = SHA1M_E;
417
418   sha1_transform (w0, w1, w2, w3, ipad);
419
420   w0[0] = w0[0] ^ 0x6a6a6a6a;
421   w0[1] = w0[1] ^ 0x6a6a6a6a;
422   w0[2] = w0[2] ^ 0x6a6a6a6a;
423   w0[3] = w0[3] ^ 0x6a6a6a6a;
424   w1[0] = w1[0] ^ 0x6a6a6a6a;
425   w1[1] = w1[1] ^ 0x6a6a6a6a;
426   w1[2] = w1[2] ^ 0x6a6a6a6a;
427   w1[3] = w1[3] ^ 0x6a6a6a6a;
428   w2[0] = w2[0] ^ 0x6a6a6a6a;
429   w2[1] = w2[1] ^ 0x6a6a6a6a;
430   w2[2] = w2[2] ^ 0x6a6a6a6a;
431   w2[3] = w2[3] ^ 0x6a6a6a6a;
432   w3[0] = w3[0] ^ 0x6a6a6a6a;
433   w3[1] = w3[1] ^ 0x6a6a6a6a;
434   w3[2] = w3[2] ^ 0x6a6a6a6a;
435   w3[3] = w3[3] ^ 0x6a6a6a6a;
436
437   opad[0] = SHA1M_A;
438   opad[1] = SHA1M_B;
439   opad[2] = SHA1M_C;
440   opad[3] = SHA1M_D;
441   opad[4] = SHA1M_E;
442
443   sha1_transform (w0, w1, w2, w3, opad);
444 }
445
446 void hmac_sha1_run (u32 w0[4], u32 w1[4], u32 w2[4], u32 w3[4], u32 ipad[5], u32 opad[5], u32 digest[5])
447 {
448   digest[0] = ipad[0];
449   digest[1] = ipad[1];
450   digest[2] = ipad[2];
451   digest[3] = ipad[3];
452   digest[4] = ipad[4];
453
454   sha1_transform (w0, w1, w2, w3, digest);
455
456   w0[0] = digest[0];
457   w0[1] = digest[1];
458   w0[2] = digest[2];
459   w0[3] = digest[3];
460   w1[0] = digest[4];
461   w1[1] = 0x80000000;
462   w1[2] = 0;
463   w1[3] = 0;
464   w2[0] = 0;
465   w2[1] = 0;
466   w2[2] = 0;
467   w2[3] = 0;
468   w3[0] = 0;
469   w3[1] = 0;
470   w3[2] = 0;
471   w3[3] = (64 + 20) * 8;
472
473   digest[0] = opad[0];
474   digest[1] = opad[1];
475   digest[2] = opad[2];
476   digest[3] = opad[3];
477   digest[4] = opad[4];
478
479   sha1_transform (w0, w1, w2, w3, digest);
480 }
481
482 void base64_encode (u8 *base64_hash, const u32 len, const u8 *base64_plain)
483 {
484   u8 *out_ptr = (u8 *) base64_hash;
485   u8 *in_ptr  = (u8 *) base64_plain;
486
487   u32 i;
488
489   for (i = 0; i < len; i += 3)
490   {
491     char out_val0 = lotus64_table [                            ((in_ptr[0] >> 2) & 0x3f)];
492     char out_val1 = lotus64_table [((in_ptr[0] << 4) & 0x30) | ((in_ptr[1] >> 4) & 0x0f)];
493     char out_val2 = lotus64_table [((in_ptr[1] << 2) & 0x3c) | ((in_ptr[2] >> 6) & 0x03)];
494     char out_val3 = lotus64_table [                            ((in_ptr[2] >> 0) & 0x3f)];
495
496     out_ptr[0] = out_val0 & 0x7f;
497     out_ptr[1] = out_val1 & 0x7f;
498     out_ptr[2] = out_val2 & 0x7f;
499     out_ptr[3] = out_val3 & 0x7f;
500
501     in_ptr  += 3;
502     out_ptr += 4;
503   }
504 }
505
506 void lotus6_base64_encode (u8 base64_hash[24], const u32 salt0, const u32 salt1, u32 a, u32 b, u32 c)
507 {
508   uchar4 salt0c = as_uchar4 (salt0);
509   uchar4 salt1c = as_uchar4 (salt1);
510
511   uchar4 ac;
512   uchar4 bc;
513   uchar4 cc;
514
515   ac = as_uchar4 (a);
516   bc = as_uchar4 (b);
517   cc = as_uchar4 (c);
518
519   u8 tmp[24]; // size 22 (=pw_len) is needed but base64 needs size divisible by 4
520
521   /*
522    * Copy $salt.$digest to a tmp buffer
523    */
524
525   u8 base64_plain[16];
526
527   base64_plain[ 0] = salt0c.s0;
528   base64_plain[ 1] = salt0c.s1;
529   base64_plain[ 2] = salt0c.s2;
530   base64_plain[ 3] = salt0c.s3;
531   base64_plain[ 3] -= -4; // dont ask!
532   base64_plain[ 4] = salt1c.s0;
533   base64_plain[ 5] = ac.s0;
534   base64_plain[ 6] = ac.s1;
535   base64_plain[ 7] = ac.s2;
536   base64_plain[ 8] = ac.s3;
537   base64_plain[ 9] = bc.s0;
538   base64_plain[10] = bc.s1;
539   base64_plain[11] = bc.s2;
540   base64_plain[12] = bc.s3;
541   base64_plain[13] = cc.s0;
542   base64_plain[14] = cc.s1;
543   base64_plain[15] = cc.s2;
544
545   /*
546    * base64 encode the $salt.$digest string
547    */
548
549   base64_encode (tmp + 2, 14, base64_plain);
550
551   base64_hash[ 0] = '(';
552   base64_hash[ 1] = 'G';
553   base64_hash[ 2] = tmp[ 2];
554   base64_hash[ 3] = tmp[ 3];
555   base64_hash[ 4] = tmp[ 4];
556   base64_hash[ 5] = tmp[ 5];
557   base64_hash[ 6] = tmp[ 6];
558   base64_hash[ 7] = tmp[ 7];
559   base64_hash[ 8] = tmp[ 8];
560   base64_hash[ 9] = tmp[ 9];
561   base64_hash[10] = tmp[10];
562   base64_hash[11] = tmp[11];
563   base64_hash[12] = tmp[12];
564   base64_hash[13] = tmp[13];
565   base64_hash[14] = tmp[14];
566   base64_hash[15] = tmp[15];
567   base64_hash[16] = tmp[16];
568   base64_hash[17] = tmp[17];
569   base64_hash[18] = tmp[18];
570   base64_hash[19] = tmp[19];
571   base64_hash[20] = tmp[20];
572   base64_hash[21] = ')';
573 }
574
575 __kernel void m09100_init (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global lotus8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global wpa_t *wpa_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
576 {
577   /**
578    * base
579    */
580
581   const u32 gid = get_global_id (0);
582   const u32 lid = get_local_id (0);
583   const u32 lsz = get_local_size (0);
584
585   /**
586    * sbox
587    */
588
589   __local u32 s_lotus_magic_table[256];
590
591   for (u32 i = lid; i < 256; i += lsz)
592   {
593     s_lotus_magic_table[i] = lotus_magic_table[i];
594   }
595
596   __local u32 l_bin2asc[256];
597
598   for (u32 i = lid; i < 256; i += lsz)
599   {
600     const u32 i0 = (i >> 0) & 15;
601     const u32 i1 = (i >> 4) & 15;
602
603     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
604                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
605   }
606
607   barrier (CLK_LOCAL_MEM_FENCE);
608
609   if (gid >= gid_max) return;
610
611   /**
612    * base
613    */
614
615   u32 w[16];
616
617   w[ 0] = pws[gid].i[ 0];
618   w[ 1] = pws[gid].i[ 1];
619   w[ 2] = pws[gid].i[ 2];
620   w[ 3] = pws[gid].i[ 3];
621
622   w[ 4] = pws[gid].i[ 4];
623   w[ 5] = pws[gid].i[ 5];
624   w[ 6] = pws[gid].i[ 6];
625   w[ 7] = pws[gid].i[ 7];
626
627   w[ 8] = pws[gid].i[ 8];
628   w[ 9] = pws[gid].i[ 9];
629   w[10] = pws[gid].i[10];
630   w[11] = pws[gid].i[11];
631
632   w[12] = pws[gid].i[12];
633   w[13] = pws[gid].i[13];
634   w[14] = pws[gid].i[14];
635   w[15] = pws[gid].i[15];
636
637   /**
638    * pad
639    */
640
641   u32 pw_len = pws[gid].pw_len;
642
643   if (pw_len < 16)
644   {
645     pad (&w[ 0], pw_len & 0xf);
646   }
647   else if (pw_len < 32)
648   {
649     pad (&w[ 4], pw_len & 0xf);
650   }
651   else if (pw_len < 48)
652   {
653     pad (&w[ 8], pw_len & 0xf);
654   }
655   else if (pw_len < 64)
656   {
657     pad (&w[12], pw_len & 0xf);
658   }
659
660   /**
661    * salt
662    */
663
664   u32 salt_len = salt_bufs[salt_pos].salt_len;
665
666   u32 salt_buf0[4];
667
668   salt_buf0[0] = salt_bufs[salt_pos].salt_buf[ 0];
669   salt_buf0[1] = salt_bufs[salt_pos].salt_buf[ 1];
670   salt_buf0[2] = salt_bufs[salt_pos].salt_buf[ 2];
671   salt_buf0[3] = salt_bufs[salt_pos].salt_buf[ 3];
672
673   u32 salt_buf1[4];
674
675   salt_buf1[0] = 0x01000000;
676   salt_buf1[1] = 0x00000080;
677   salt_buf1[2] = 0;
678   salt_buf1[3] = 0;
679
680   u32 salt_buf2[4];
681
682   salt_buf2[0] = 0;
683   salt_buf2[1] = 0;
684   salt_buf2[2] = 0;
685   salt_buf2[3] = 0;
686
687   u32 salt_buf3[4];
688
689   salt_buf3[0] = 0;
690   salt_buf3[1] = 0;
691   salt_buf3[2] = 0;
692   salt_buf3[3] = 0;
693
694   const u32 salt0 = salt_buf0[0];
695   const u32 salt1 = (salt_buf0[1] & 0xff) | ('(' << 8);
696
697   /**
698    * Lotus 6 hash - SEC_pwddigest_V2
699    */
700
701   u32 w_tmp[16];
702
703   w_tmp[ 0] = w[ 0];
704   w_tmp[ 1] = w[ 1];
705   w_tmp[ 2] = w[ 2];
706   w_tmp[ 3] = w[ 3];
707   w_tmp[ 4] = w[ 4];
708   w_tmp[ 5] = w[ 5];
709   w_tmp[ 6] = w[ 6];
710   w_tmp[ 7] = w[ 7];
711   w_tmp[ 8] = w[ 8];
712   w_tmp[ 9] = w[ 9];
713   w_tmp[10] = w[10];
714   w_tmp[11] = w[11];
715   w_tmp[12] = w[12];
716   w_tmp[13] = w[13];
717   w_tmp[14] = w[14];
718   w_tmp[15] = w[15];
719
720   u32 state[4];
721
722   state[0] = 0;
723   state[1] = 0;
724   state[2] = 0;
725   state[3] = 0;
726
727   domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
728
729   const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
730                    | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
731   const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
732                    | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
733   const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
734                    | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
735   const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
736                    | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
737   const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
738                    | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
739   const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
740                    | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
741   const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
742                    | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
743
744   const u32 pade = 0x0e0e0e0e;
745
746   w_tmp[ 0] = salt0;
747   w_tmp[ 1] = salt1      | w0_t << 16;
748   w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
749   w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
750   w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
751   w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
752   w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
753   w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
754   w_tmp[ 8] = w6_t >> 16 | pade << 16;
755   w_tmp[ 9] = pade;
756   w_tmp[10] = pade;
757   w_tmp[11] = pade;
758   w_tmp[12] = 0;
759   w_tmp[13] = 0;
760   w_tmp[14] = 0;
761   w_tmp[15] = 0;
762
763   state[0] = 0;
764   state[1] = 0;
765   state[2] = 0;
766   state[3] = 0;
767
768   domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
769
770   u32 a = state[0];
771   u32 b = state[1];
772   u32 c = state[2];
773
774   /**
775    * Base64 encode
776    */
777
778   pw_len = 22;
779
780   u8 base64_hash[22];
781
782   lotus6_base64_encode (base64_hash, salt_buf0[0], salt_buf0[1], a, b, c);
783
784   /**
785    * PBKDF2 - HMACSHA1 - 1st iteration
786    */
787
788   u32 w0[4];
789   u32 w1[4];
790   u32 w2[4];
791   u32 w3[4];
792
793   w0[0] = (base64_hash[ 0] << 24) | (base64_hash[ 1] << 16) | (base64_hash[ 2] << 8) | base64_hash[ 3];
794   w0[1] = (base64_hash[ 4] << 24) | (base64_hash[ 5] << 16) | (base64_hash[ 6] << 8) | base64_hash[ 7];
795   w0[2] = (base64_hash[ 8] << 24) | (base64_hash[ 9] << 16) | (base64_hash[10] << 8) | base64_hash[11];
796   w0[3] = (base64_hash[12] << 24) | (base64_hash[13] << 16) | (base64_hash[14] << 8) | base64_hash[15];
797   w1[0] = (base64_hash[16] << 24) | (base64_hash[17] << 16) | (base64_hash[18] << 8) | base64_hash[19];
798   w1[1] = (base64_hash[20] << 24) | (base64_hash[21] << 16);
799   w1[2] = 0;
800   w1[3] = 0;
801   w2[0] = 0;
802   w2[1] = 0;
803   w2[2] = 0;
804   w2[3] = 0;
805   w3[0] = 0;
806   w3[1] = 0;
807   w3[2] = 0;
808   w3[3] = 0;
809
810   /**
811    * pads
812    */
813
814   u32 ipad[5];
815   u32 opad[5];
816
817   hmac_sha1_pad (w0, w1, w2, w3, ipad, opad);
818
819   tmps[gid].ipad[0] = ipad[0];
820   tmps[gid].ipad[1] = ipad[1];
821   tmps[gid].ipad[2] = ipad[2];
822   tmps[gid].ipad[3] = ipad[3];
823   tmps[gid].ipad[4] = ipad[4];
824
825   tmps[gid].opad[0] = opad[0];
826   tmps[gid].opad[1] = opad[1];
827   tmps[gid].opad[2] = opad[2];
828   tmps[gid].opad[3] = opad[3];
829   tmps[gid].opad[4] = opad[4];
830
831   w0[0] = salt_buf0[0];
832   w0[1] = salt_buf0[1];
833   w0[2] = salt_buf0[2];
834   w0[3] = salt_buf0[3];
835   w1[0] = salt_buf1[0];
836   w1[1] = salt_buf1[1];
837   w1[2] = salt_buf1[2];
838   w1[3] = salt_buf1[3];
839   w2[0] = salt_buf2[0];
840   w2[1] = salt_buf2[1];
841   w2[2] = salt_buf2[2];
842   w2[3] = salt_buf2[3];
843   w3[0] = salt_buf3[0];
844   w3[1] = salt_buf3[1];
845   w3[2] = salt_buf3[2];
846   //w3[3] = salt_buf3[3];
847
848   w0[0] = swap32 (w0[0]);
849   w0[1] = swap32 (w0[1]);
850   w0[2] = swap32 (w0[2]);
851   w0[3] = swap32 (w0[3]);
852   w1[0] = swap32 (w1[0]);
853   w1[1] = swap32 (w1[1]);
854   w1[2] = swap32 (w1[2]);
855   w1[3] = swap32 (w1[3]);
856   w2[0] = swap32 (w2[0]);
857   w2[1] = swap32 (w2[1]);
858   w2[2] = swap32 (w2[2]);
859   w2[3] = swap32 (w2[3]);
860   w3[0] = swap32 (w3[0]);
861   w3[1] = swap32 (w3[1]);
862   w3[2] = swap32 (w3[2]);
863   w3[3] = (64 + salt_len + 4) * 8;
864
865   u32 dgst[5];
866
867   hmac_sha1_run (w0, w1, w2, w3, ipad, opad, dgst);
868
869   tmps[gid].dgst[0] = dgst[0];
870   tmps[gid].dgst[1] = dgst[1];
871   tmps[gid].dgst[2] = dgst[2];
872   tmps[gid].dgst[3] = dgst[3];
873   tmps[gid].dgst[4] = dgst[4];
874
875   tmps[gid].out[0] = dgst[0];
876   tmps[gid].out[1] = dgst[1];
877   tmps[gid].out[2] = dgst[2];
878   tmps[gid].out[3] = dgst[3];
879   tmps[gid].out[4] = dgst[4];
880 }
881
882 __kernel void m09100_loop (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global lotus8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global wpa_t *wpa_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
883 {
884   const u32 gid = get_global_id (0);
885
886   if (gid >= gid_max) return;
887
888   u32 ipad[5];
889   u32 opad[5];
890
891   ipad[0] = tmps[gid].ipad[0];
892   ipad[1] = tmps[gid].ipad[1];
893   ipad[2] = tmps[gid].ipad[2];
894   ipad[3] = tmps[gid].ipad[3];
895   ipad[4] = tmps[gid].ipad[4];
896
897   opad[0] = tmps[gid].opad[0];
898   opad[1] = tmps[gid].opad[1];
899   opad[2] = tmps[gid].opad[2];
900   opad[3] = tmps[gid].opad[3];
901   opad[4] = tmps[gid].opad[4];
902
903   u32 dgst[5];
904   u32 out[5];
905
906   dgst[0] = tmps[gid].dgst[0];
907   dgst[1] = tmps[gid].dgst[1];
908   dgst[2] = tmps[gid].dgst[2];
909   dgst[3] = tmps[gid].dgst[3];
910   dgst[4] = tmps[gid].dgst[4];
911
912   out[0] = tmps[gid].out[0];
913   out[1] = tmps[gid].out[1];
914   out[2] = tmps[gid].out[2];
915   out[3] = tmps[gid].out[3];
916   out[4] = tmps[gid].out[4];
917
918   for (u32 j = 0; j < loop_cnt; j++)
919   {
920     u32 w0[4];
921     u32 w1[4];
922     u32 w2[4];
923     u32 w3[4];
924
925     w0[0] = dgst[0];
926     w0[1] = dgst[1];
927     w0[2] = dgst[2];
928     w0[3] = dgst[3];
929     w1[0] = dgst[4];
930     w1[1] = 0x80000000;
931     w1[2] = 0;
932     w1[3] = 0;
933     w2[0] = 0;
934     w2[1] = 0;
935     w2[2] = 0;
936     w2[3] = 0;
937     w3[0] = 0;
938     w3[1] = 0;
939     w3[2] = 0;
940     w3[3] = (64 + 20) * 8;
941
942     hmac_sha1_run (w0, w1, w2, w3, ipad, opad, dgst);
943
944     out[0] ^= dgst[0];
945     out[1] ^= dgst[1];
946     out[2] ^= dgst[2];
947     out[3] ^= dgst[3];
948     out[4] ^= dgst[4];
949   }
950
951   tmps[gid].dgst[0] = dgst[0];
952   tmps[gid].dgst[1] = dgst[1];
953   tmps[gid].dgst[2] = dgst[2];
954   tmps[gid].dgst[3] = dgst[3];
955   tmps[gid].dgst[4] = dgst[4];
956
957   tmps[gid].out[0] = out[0];
958   tmps[gid].out[1] = out[1];
959   tmps[gid].out[2] = out[2];
960   tmps[gid].out[3] = out[3];
961   tmps[gid].out[4] = out[4];
962 }
963
964 __kernel void m09100_comp (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __global lotus8_tmp_t *tmps, __global void *hooks, __global u32 *bitmaps_buf_s1_a, __global u32 *bitmaps_buf_s1_b, __global u32 *bitmaps_buf_s1_c, __global u32 *bitmaps_buf_s1_d, __global u32 *bitmaps_buf_s2_a, __global u32 *bitmaps_buf_s2_b, __global u32 *bitmaps_buf_s2_c, __global u32 *bitmaps_buf_s2_d, __global plain_t *plains_buf, __global digest_t *digests_buf, __global u32 *hashes_shown, __global salt_t *salt_bufs, __global wpa_t *wpa_bufs, __global u32 *d_return_buf, __global u32 *d_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_buf, const u32 bitmap_mask, const u32 bitmap_shift1, const u32 bitmap_shift2, const u32 salt_pos, const u32 loop_pos, const u32 loop_cnt, const u32 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
965 {
966   /**
967    * base
968    */
969
970   const u32 gid = get_global_id (0);
971
972   if (gid >= gid_max) return;
973
974   const u32 lid = get_local_id (0);
975
976   /**
977    * digest
978    */
979
980   const u32 r0 = tmps[gid].out[DGST_R0];
981   const u32 r1 = tmps[gid].out[DGST_R1];
982   const u32 r2 = 0;
983   const u32 r3 = 0;
984
985   #define il_pos 0
986
987   #include COMPARE_M
988 }