Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m08000_a3.cl
1 /**
2  * Authors.....: Jens Steube <jens.steube@gmail.com>
3  *               Gabriele Gristina <matrix@hashcat.net>
4  *
5  * License.....: MIT
6  */
7
8 #define _SHA256_
9
10 #define NEW_SIMD_CODE
11
12 #include "inc_vendor.cl"
13 #include "inc_hash_constants.h"
14 #include "inc_hash_functions.cl"
15 #include "inc_types.cl"
16 #include "inc_common.cl"
17 #include "inc_simd.cl"
18
19 __constant u32 k_sha256[64] =
20 {
21   SHA256C00, SHA256C01, SHA256C02, SHA256C03,
22   SHA256C04, SHA256C05, SHA256C06, SHA256C07,
23   SHA256C08, SHA256C09, SHA256C0a, SHA256C0b,
24   SHA256C0c, SHA256C0d, SHA256C0e, SHA256C0f,
25   SHA256C10, SHA256C11, SHA256C12, SHA256C13,
26   SHA256C14, SHA256C15, SHA256C16, SHA256C17,
27   SHA256C18, SHA256C19, SHA256C1a, SHA256C1b,
28   SHA256C1c, SHA256C1d, SHA256C1e, SHA256C1f,
29   SHA256C20, SHA256C21, SHA256C22, SHA256C23,
30   SHA256C24, SHA256C25, SHA256C26, SHA256C27,
31   SHA256C28, SHA256C29, SHA256C2a, SHA256C2b,
32   SHA256C2c, SHA256C2d, SHA256C2e, SHA256C2f,
33   SHA256C30, SHA256C31, SHA256C32, SHA256C33,
34   SHA256C34, SHA256C35, SHA256C36, SHA256C37,
35   SHA256C38, SHA256C39, SHA256C3a, SHA256C3b,
36   SHA256C3c, SHA256C3d, SHA256C3e, SHA256C3f,
37 };
38
39 #define SHA256_S0_S(x) (rotl32_S ((x), 25u) ^ rotl32_S ((x), 14u) ^ SHIFT_RIGHT_32 ((x),  3u))
40 #define SHA256_S1_S(x) (rotl32_S ((x), 15u) ^ rotl32_S ((x), 13u) ^ SHIFT_RIGHT_32 ((x), 10u))
41
42 #define SHA256_EXPAND_S(x,y,z,w) (SHA256_S1_S (x) + y + SHA256_S0_S (z) + w)
43
44 void sha256_transform (u32x digest[8], const u32x w[16])
45 {
46   u32x a = digest[0];
47   u32x b = digest[1];
48   u32x c = digest[2];
49   u32x d = digest[3];
50   u32x e = digest[4];
51   u32x f = digest[5];
52   u32x g = digest[6];
53   u32x h = digest[7];
54
55   u32x w0_t = w[ 0];
56   u32x w1_t = w[ 1];
57   u32x w2_t = w[ 2];
58   u32x w3_t = w[ 3];
59   u32x w4_t = w[ 4];
60   u32x w5_t = w[ 5];
61   u32x w6_t = w[ 6];
62   u32x w7_t = w[ 7];
63   u32x w8_t = w[ 8];
64   u32x w9_t = w[ 9];
65   u32x wa_t = w[10];
66   u32x wb_t = w[11];
67   u32x wc_t = w[12];
68   u32x wd_t = w[13];
69   u32x we_t = w[14];
70   u32x wf_t = w[15];
71
72   #define ROUND_EXPAND()                            \
73   {                                                 \
74     w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t);  \
75     w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t);  \
76     w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t);  \
77     w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t);  \
78     w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t);  \
79     w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t);  \
80     w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t);  \
81     w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t);  \
82     w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t);  \
83     w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t);  \
84     wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t);  \
85     wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t);  \
86     wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t);  \
87     wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t);  \
88     we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t);  \
89     wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t);  \
90   }
91
92   #define ROUND_STEP(i)                                                                   \
93   {                                                                                       \
94     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i +  0]); \
95     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i +  1]); \
96     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i +  2]); \
97     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i +  3]); \
98     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i +  4]); \
99     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i +  5]); \
100     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i +  6]); \
101     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i +  7]); \
102     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i +  8]); \
103     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i +  9]); \
104     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]); \
105     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]); \
106     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]); \
107     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]); \
108     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]); \
109     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]); \
110   }
111
112   ROUND_STEP (0);
113
114   #ifdef _unroll
115   #pragma unroll
116   #endif
117   for (int i = 16; i < 64; i += 16)
118   {
119     ROUND_EXPAND (); ROUND_STEP (i);
120   }
121
122   digest[0] += a;
123   digest[1] += b;
124   digest[2] += c;
125   digest[3] += d;
126   digest[4] += e;
127   digest[5] += f;
128   digest[6] += g;
129   digest[7] += h;
130 }
131
132 void sha256_transform_z (u32x digest[8])
133 {
134   u32x a = digest[0];
135   u32x b = digest[1];
136   u32x c = digest[2];
137   u32x d = digest[3];
138   u32x e = digest[4];
139   u32x f = digest[5];
140   u32x g = digest[6];
141   u32x h = digest[7];
142
143   #define ROUND_STEP_Z(i)                                                                 \
144   {                                                                                       \
145     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, 0, k_sha256[i +  0]); \
146     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, 0, k_sha256[i +  1]); \
147     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, 0, k_sha256[i +  2]); \
148     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, 0, k_sha256[i +  3]); \
149     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, 0, k_sha256[i +  4]); \
150     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, 0, k_sha256[i +  5]); \
151     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, 0, k_sha256[i +  6]); \
152     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, 0, k_sha256[i +  7]); \
153     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, 0, k_sha256[i +  8]); \
154     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, 0, k_sha256[i +  9]); \
155     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, 0, k_sha256[i + 10]); \
156     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, 0, k_sha256[i + 11]); \
157     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, 0, k_sha256[i + 12]); \
158     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, 0, k_sha256[i + 13]); \
159     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, 0, k_sha256[i + 14]); \
160     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, 0, k_sha256[i + 15]); \
161   }
162
163   ROUND_STEP_Z (0);
164
165   #ifdef _unroll
166   #pragma unroll
167   #endif
168   for (int i = 16; i < 64; i += 16)
169   {
170     ROUND_STEP_Z (i);
171   }
172
173   digest[0] += a;
174   digest[1] += b;
175   digest[2] += c;
176   digest[3] += d;
177   digest[4] += e;
178   digest[5] += f;
179   digest[6] += g;
180   digest[7] += h;
181 }
182
183 void sha256_transform_s (u32x digest[8], __local u32 *w)
184 {
185   u32x a = digest[0];
186   u32x b = digest[1];
187   u32x c = digest[2];
188   u32x d = digest[3];
189   u32x e = digest[4];
190   u32x f = digest[5];
191   u32x g = digest[6];
192   u32x h = digest[7];
193
194   #define ROUND_STEP_S(i)                                                                      \
195   {                                                                                            \
196     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w[i +  0], k_sha256[i +  0]); \
197     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w[i +  1], k_sha256[i +  1]); \
198     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w[i +  2], k_sha256[i +  2]); \
199     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w[i +  3], k_sha256[i +  3]); \
200     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w[i +  4], k_sha256[i +  4]); \
201     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w[i +  5], k_sha256[i +  5]); \
202     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w[i +  6], k_sha256[i +  6]); \
203     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w[i +  7], k_sha256[i +  7]); \
204     SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w[i +  8], k_sha256[i +  8]); \
205     SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w[i +  9], k_sha256[i +  9]); \
206     SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w[i + 10], k_sha256[i + 10]); \
207     SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w[i + 11], k_sha256[i + 11]); \
208     SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w[i + 12], k_sha256[i + 12]); \
209     SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w[i + 13], k_sha256[i + 13]); \
210     SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w[i + 14], k_sha256[i + 14]); \
211     SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w[i + 15], k_sha256[i + 15]); \
212   }
213
214   ROUND_STEP_S (0);
215
216   #ifdef _unroll
217   #pragma unroll
218   #endif
219   for (int i = 16; i < 64; i += 16)
220   {
221     ROUND_STEP_S (i);
222   }
223
224   digest[0] += a;
225   digest[1] += b;
226   digest[2] += c;
227   digest[3] += d;
228   digest[4] += e;
229   digest[5] += f;
230   digest[6] += g;
231   digest[7] += h;
232 }
233
234 void m08000m (__local u32 *w_s1, __local u32 *w_s2, u32 w[16], const u32 pw_len, __global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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 gid_max)
235 {
236   /**
237    * modifier
238    */
239
240   const u32 gid = get_global_id (0);
241   const u32 lid = get_local_id (0);
242   const u32 lsz = get_local_size (0);
243
244   /**
245    * salt
246    */
247
248   const u32 salt_buf0 = swap32_S (salt_bufs[salt_pos].salt_buf[ 0]);
249   const u32 salt_buf1 = swap32_S (salt_bufs[salt_pos].salt_buf[ 1]);
250   const u32 salt_buf2 = swap32_S (salt_bufs[salt_pos].salt_buf[ 2]); // 0x80
251
252   /**
253    * precompute final msg blocks
254    */
255
256   for (u32 i = lid; i < 64; i += lsz)
257   {
258     w_s1[i] = 0;
259     w_s2[i] = 0;
260   }
261
262   barrier (CLK_LOCAL_MEM_FENCE);
263
264   if (lid == 0)
265   {
266     w_s1[15] =               0 | salt_buf0 >> 16;
267
268     #ifdef _unroll
269     #pragma unroll
270     #endif
271     for (int i = 16; i < 64; i++)
272     {
273       w_s1[i] = SHA256_EXPAND_S (w_s1[i - 2], w_s1[i - 7], w_s1[i - 15], w_s1[i - 16]);
274     }
275
276     w_s2[ 0] = salt_buf0 << 16 | salt_buf1 >> 16;
277     w_s2[ 1] = salt_buf1 << 16 | salt_buf2 >> 16;
278     w_s2[ 2] = salt_buf2 << 16 | 0;
279     w_s2[15] = (510 + 8) * 8;
280
281     #ifdef _unroll
282     #pragma unroll
283     #endif
284     for (int i = 16; i < 64; i++)
285     {
286       w_s2[i] = SHA256_EXPAND_S (w_s2[i - 2], w_s2[i - 7], w_s2[i - 15], w_s2[i - 16]);
287     }
288   }
289
290   barrier (CLK_LOCAL_MEM_FENCE);
291
292   if (gid >= gid_max) return;
293
294   /**
295    * modifier
296    */
297
298   u32x w_t[16];
299
300   w_t[ 0] = w[ 0] >> 8;
301   w_t[ 1] = w[ 1] >> 8;
302   w_t[ 2] = w[ 2] >> 8;
303   w_t[ 3] = w[ 3] >> 8;
304   w_t[ 4] = w[ 4] >> 8;
305   w_t[ 5] = w[ 5] >> 8;
306   w_t[ 6] = w[ 6] >> 8;
307   w_t[ 7] = w[ 7] >> 8;
308   w_t[ 8] = w[ 8] >> 8;
309   w_t[ 9] = w[ 9] >> 8;
310   w_t[10] = w[10] >> 8;
311   w_t[11] = w[11] >> 8;
312   w_t[12] = w[12] >> 8;
313   w_t[13] = w[13] >> 8;
314   w_t[14] = w[14] >> 8;
315   w_t[15] = w[15] >> 8;
316
317   /**
318    * loop
319    */
320
321   u32 w0l = w[0];
322
323   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
324   {
325     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
326
327     const u32x w0lr = w0l | w0r;
328
329     w_t[0] = w0lr >> 8;
330
331     u32x digest[8];
332
333     digest[0] = SHA256M_A;
334     digest[1] = SHA256M_B;
335     digest[2] = SHA256M_C;
336     digest[3] = SHA256M_D;
337     digest[4] = SHA256M_E;
338     digest[5] = SHA256M_F;
339     digest[6] = SHA256M_G;
340     digest[7] = SHA256M_H;
341
342     sha256_transform   (digest, w_t);   //   0 -  64
343     sha256_transform_z (digest);        //  64 - 128
344     sha256_transform_z (digest);        // 128 - 192
345     sha256_transform_z (digest);        // 192 - 256
346     sha256_transform_z (digest);        // 256 - 320
347     sha256_transform_z (digest);        // 320 - 384
348     sha256_transform_z (digest);        // 384 - 448
349     sha256_transform_s (digest, w_s1);  // 448 - 512
350     sha256_transform_s (digest, w_s2);  // 512 - 576
351
352     COMPARE_M_SIMD (digest[3], digest[7], digest[2], digest[6]);
353   }
354 }
355
356 void m08000s (__local u32 *w_s1, __local u32 *w_s2, u32 w[16], const u32 pw_len, __global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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 gid_max)
357 {
358   /**
359    * modifier
360    */
361
362   const u32 gid = get_global_id (0);
363   const u32 lid = get_local_id (0);
364   const u32 lsz = get_local_size (0);
365
366   /**
367    * salt
368    */
369
370   const u32 salt_buf0 = swap32_S (salt_bufs[salt_pos].salt_buf[ 0]);
371   const u32 salt_buf1 = swap32_S (salt_bufs[salt_pos].salt_buf[ 1]);
372   const u32 salt_buf2 = swap32_S (salt_bufs[salt_pos].salt_buf[ 2]); // 0x80
373
374   /**
375    * precompute final msg blocks
376    */
377
378   for (u32 i = lid; i < 64; i += lsz)
379   {
380     w_s1[i] = 0;
381     w_s2[i] = 0;
382   }
383
384   barrier (CLK_LOCAL_MEM_FENCE);
385
386   if (lid == 0)
387   {
388     w_s1[15] =               0 | salt_buf0 >> 16;
389
390     #ifdef _unroll
391     #pragma unroll
392     #endif
393     for (int i = 16; i < 64; i++)
394     {
395       w_s1[i] = SHA256_EXPAND_S (w_s1[i - 2], w_s1[i - 7], w_s1[i - 15], w_s1[i - 16]);
396     }
397
398     w_s2[ 0] = salt_buf0 << 16 | salt_buf1 >> 16;
399     w_s2[ 1] = salt_buf1 << 16 | salt_buf2 >> 16;
400     w_s2[ 2] = salt_buf2 << 16 | 0;
401     w_s2[15] = (510 + 8) * 8;
402
403     #ifdef _unroll
404     #pragma unroll
405     #endif
406     for (int i = 16; i < 64; i++)
407     {
408       w_s2[i] = SHA256_EXPAND_S (w_s2[i - 2], w_s2[i - 7], w_s2[i - 15], w_s2[i - 16]);
409     }
410   }
411
412   barrier (CLK_LOCAL_MEM_FENCE);
413
414   if (gid >= gid_max) return;
415
416   /**
417    * modifier
418    */
419
420   u32x w_t[16];
421
422   w_t[ 0] = w[ 0] >> 8;
423   w_t[ 1] = w[ 1] >> 8;
424   w_t[ 2] = w[ 2] >> 8;
425   w_t[ 3] = w[ 3] >> 8;
426   w_t[ 4] = w[ 4] >> 8;
427   w_t[ 5] = w[ 5] >> 8;
428   w_t[ 6] = w[ 6] >> 8;
429   w_t[ 7] = w[ 7] >> 8;
430   w_t[ 8] = w[ 8] >> 8;
431   w_t[ 9] = w[ 9] >> 8;
432   w_t[10] = w[10] >> 8;
433   w_t[11] = w[11] >> 8;
434   w_t[12] = w[12] >> 8;
435   w_t[13] = w[13] >> 8;
436   w_t[14] = w[14] >> 8;
437   w_t[15] = w[15] >> 8;
438
439   /**
440    * digest
441    */
442
443   const u32 search[4] =
444   {
445     digests_buf[digests_offset].digest_buf[DGST_R0],
446     digests_buf[digests_offset].digest_buf[DGST_R1],
447     digests_buf[digests_offset].digest_buf[DGST_R2],
448     digests_buf[digests_offset].digest_buf[DGST_R3]
449   };
450
451   /**
452    * loop
453    */
454
455   u32 w0l = w[0];
456
457   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
458   {
459     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
460
461     const u32x w0lr = w0l | w0r;
462
463     w_t[0] = w0lr >> 8;
464
465     u32x digest[8];
466
467     digest[0] = SHA256M_A;
468     digest[1] = SHA256M_B;
469     digest[2] = SHA256M_C;
470     digest[3] = SHA256M_D;
471     digest[4] = SHA256M_E;
472     digest[5] = SHA256M_F;
473     digest[6] = SHA256M_G;
474     digest[7] = SHA256M_H;
475
476     sha256_transform   (digest, w_t);   //   0 -  64
477     sha256_transform_z (digest);        //  64 - 128
478     sha256_transform_z (digest);        // 128 - 192
479     sha256_transform_z (digest);        // 192 - 256
480     sha256_transform_z (digest);        // 256 - 320
481     sha256_transform_z (digest);        // 320 - 384
482     sha256_transform_z (digest);        // 384 - 448
483     sha256_transform_s (digest, w_s1);  // 448 - 512
484     sha256_transform_s (digest, w_s2);  // 512 - 576
485
486     COMPARE_S_SIMD (digest[3], digest[7], digest[2], digest[6]);
487   }
488 }
489
490 __kernel void m08000_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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)
491 {
492   /**
493    * base
494    */
495
496   const u32 gid = get_global_id (0);
497
498   u32 w[16];
499
500   w[ 0] = pws[gid].i[ 0];
501   w[ 1] = pws[gid].i[ 1];
502   w[ 2] = pws[gid].i[ 2];
503   w[ 3] = pws[gid].i[ 3];
504   w[ 4] = 0;
505   w[ 5] = 0;
506   w[ 6] = 0;
507   w[ 7] = 0;
508   w[ 8] = 0;
509   w[ 9] = 0;
510   w[10] = 0;
511   w[11] = 0;
512   w[12] = 0;
513   w[13] = 0;
514   w[14] = 0;
515   w[15] = 0;
516
517   const u32 pw_len = pws[gid].pw_len;
518
519   __local u32 w_s1[64];
520   __local u32 w_s2[64];
521
522   /**
523    * main
524    */
525
526   m08000m (w_s1, w_s2, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset, gid_max);
527 }
528
529 __kernel void m08000_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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)
530 {
531   /**
532    * base
533    */
534
535   const u32 gid = get_global_id (0);
536
537   u32 w[16];
538
539   w[ 0] = pws[gid].i[ 0];
540   w[ 1] = pws[gid].i[ 1];
541   w[ 2] = pws[gid].i[ 2];
542   w[ 3] = pws[gid].i[ 3];
543   w[ 4] = pws[gid].i[ 4];
544   w[ 5] = pws[gid].i[ 5];
545   w[ 6] = pws[gid].i[ 6];
546   w[ 7] = pws[gid].i[ 7];
547   w[ 8] = 0;
548   w[ 9] = 0;
549   w[10] = 0;
550   w[11] = 0;
551   w[12] = 0;
552   w[13] = 0;
553   w[14] = 0;
554   w[15] = 0;
555
556   const u32 pw_len = pws[gid].pw_len;
557
558   __local u32 w_s1[64];
559   __local u32 w_s2[64];
560
561   /**
562    * main
563    */
564
565   m08000m (w_s1, w_s2, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset, gid_max);
566 }
567
568 __kernel void m08000_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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)
569 {
570   /**
571    * base
572    */
573
574   const u32 gid = get_global_id (0);
575
576   u32 w[16];
577
578   w[ 0] = pws[gid].i[ 0];
579   w[ 1] = pws[gid].i[ 1];
580   w[ 2] = pws[gid].i[ 2];
581   w[ 3] = pws[gid].i[ 3];
582   w[ 4] = pws[gid].i[ 4];
583   w[ 5] = pws[gid].i[ 5];
584   w[ 6] = pws[gid].i[ 6];
585   w[ 7] = pws[gid].i[ 7];
586   w[ 8] = pws[gid].i[ 8];
587   w[ 9] = pws[gid].i[ 9];
588   w[10] = pws[gid].i[10];
589   w[11] = pws[gid].i[11];
590   w[12] = pws[gid].i[12];
591   w[13] = pws[gid].i[13];
592   w[14] = pws[gid].i[14];
593   w[15] = pws[gid].i[15];
594
595   const u32 pw_len = pws[gid].pw_len;
596
597   __local u32 w_s1[64];
598   __local u32 w_s2[64];
599
600   /**
601    * main
602    */
603
604   m08000m (w_s1, w_s2, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset, gid_max);
605 }
606
607 __kernel void m08000_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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)
608 {
609   /**
610    * base
611    */
612
613   const u32 gid = get_global_id (0);
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   w[ 4] = 0;
622   w[ 5] = 0;
623   w[ 6] = 0;
624   w[ 7] = 0;
625   w[ 8] = 0;
626   w[ 9] = 0;
627   w[10] = 0;
628   w[11] = 0;
629   w[12] = 0;
630   w[13] = 0;
631   w[14] = 0;
632   w[15] = 0;
633
634   const u32 pw_len = pws[gid].pw_len;
635
636   __local u32 w_s1[64];
637   __local u32 w_s2[64];
638
639   /**
640    * main
641    */
642
643   m08000s (w_s1, w_s2, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset, gid_max);
644 }
645
646 __kernel void m08000_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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)
647 {
648   /**
649    * base
650    */
651
652   const u32 gid = get_global_id (0);
653
654   u32 w[16];
655
656   w[ 0] = pws[gid].i[ 0];
657   w[ 1] = pws[gid].i[ 1];
658   w[ 2] = pws[gid].i[ 2];
659   w[ 3] = pws[gid].i[ 3];
660   w[ 4] = pws[gid].i[ 4];
661   w[ 5] = pws[gid].i[ 5];
662   w[ 6] = pws[gid].i[ 6];
663   w[ 7] = pws[gid].i[ 7];
664   w[ 8] = 0;
665   w[ 9] = 0;
666   w[10] = 0;
667   w[11] = 0;
668   w[12] = 0;
669   w[13] = 0;
670   w[14] = 0;
671   w[15] = 0;
672
673   const u32 pw_len = pws[gid].pw_len;
674
675   __local u32 w_s1[64];
676   __local u32 w_s2[64];
677
678   /**
679    * main
680    */
681
682   m08000s (w_s1, w_s2, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset, gid_max);
683 }
684
685 __kernel void m08000_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __global void *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 void *esalt_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)
686 {
687   /**
688    * base
689    */
690
691   const u32 gid = get_global_id (0);
692
693   u32 w[16];
694
695   w[ 0] = pws[gid].i[ 0];
696   w[ 1] = pws[gid].i[ 1];
697   w[ 2] = pws[gid].i[ 2];
698   w[ 3] = pws[gid].i[ 3];
699   w[ 4] = pws[gid].i[ 4];
700   w[ 5] = pws[gid].i[ 5];
701   w[ 6] = pws[gid].i[ 6];
702   w[ 7] = pws[gid].i[ 7];
703   w[ 8] = pws[gid].i[ 8];
704   w[ 9] = pws[gid].i[ 9];
705   w[10] = pws[gid].i[10];
706   w[11] = pws[gid].i[11];
707   w[12] = pws[gid].i[12];
708   w[13] = pws[gid].i[13];
709   w[14] = pws[gid].i[14];
710   w[15] = pws[gid].i[15];
711
712   const u32 pw_len = pws[gid].pw_len;
713
714   __local u32 w_s1[64];
715   __local u32 w_s2[64];
716
717   /**
718    * main
719    */
720
721   m08000s (w_s1, w_s2, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV0_buf, d_scryptV1_buf, d_scryptV2_buf, d_scryptV3_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset, gid_max);
722 }