Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m00200_a1.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _MYSQL323_
7
8 //incompatible
9 //#define NEW_SIMD_CODE
10
11 #include "inc_vendor.cl"
12 #include "inc_hash_constants.h"
13 #include "inc_hash_functions.cl"
14 #include "inc_types.cl"
15 #include "inc_common.cl"
16 #include "inc_simd.cl"
17
18 __kernel void m00200_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __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)
19 {
20   /**
21    * modifier
22    */
23
24   const u32 lid = get_local_id (0);
25
26   /**
27    * base
28    */
29
30   const u32 gid = get_global_id (0);
31
32   if (gid >= gid_max) return;
33
34   u32 pw_buf0[4];
35   u32 pw_buf1[4];
36
37   pw_buf0[0] = pws[gid].i[0];
38   pw_buf0[1] = pws[gid].i[1];
39   pw_buf0[2] = pws[gid].i[2];
40   pw_buf0[3] = pws[gid].i[3];
41   pw_buf1[0] = pws[gid].i[4];
42   pw_buf1[1] = pws[gid].i[5];
43   pw_buf1[2] = pws[gid].i[6];
44   pw_buf1[3] = pws[gid].i[7];
45
46   const u32 pw_l_len = pws[gid].pw_len;
47
48   /**
49    * loop
50    */
51
52   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
53   {
54     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
55
56     const u32x pw_len = pw_l_len + pw_r_len;
57
58     /**
59      * concat password candidate
60      */
61
62     u32x wordl0[4] = { 0 };
63     u32x wordl1[4] = { 0 };
64     u32x wordl2[4] = { 0 };
65     u32x wordl3[4] = { 0 };
66
67     wordl0[0] = pw_buf0[0];
68     wordl0[1] = pw_buf0[1];
69     wordl0[2] = pw_buf0[2];
70     wordl0[3] = pw_buf0[3];
71     wordl1[0] = pw_buf1[0];
72     wordl1[1] = pw_buf1[1];
73     wordl1[2] = pw_buf1[2];
74     wordl1[3] = pw_buf1[3];
75
76     u32x wordr0[4] = { 0 };
77     u32x wordr1[4] = { 0 };
78     u32x wordr2[4] = { 0 };
79     u32x wordr3[4] = { 0 };
80
81     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
82     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
83     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
84     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
85     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
86     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
87     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
88     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
89
90     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
91     {
92       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
93     }
94     else
95     {
96       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
97     }
98
99     u32x w0[4];
100     u32x w1[4];
101     u32x w2[4];
102     u32x w3[4];
103
104     w0[0] = wordl0[0] | wordr0[0];
105     w0[1] = wordl0[1] | wordr0[1];
106     w0[2] = wordl0[2] | wordr0[2];
107     w0[3] = wordl0[3] | wordr0[3];
108     w1[0] = wordl1[0] | wordr1[0];
109     w1[1] = wordl1[1] | wordr1[1];
110     w1[2] = wordl1[2] | wordr1[2];
111     w1[3] = wordl1[3] | wordr1[3];
112     w2[0] = wordl2[0] | wordr2[0];
113     w2[1] = wordl2[1] | wordr2[1];
114     w2[2] = wordl2[2] | wordr2[2];
115     w2[3] = wordl2[3] | wordr2[3];
116     w3[0] = wordl3[0] | wordr3[0];
117     w3[1] = wordl3[1] | wordr3[1];
118     w3[2] = pw_len * 8;
119     w3[3] = 0;
120
121     /**
122      * mysql
123      */
124
125     u32x w_t[16];
126
127     w_t[ 0] = w0[0];
128     w_t[ 1] = w0[1];
129     w_t[ 2] = w0[2];
130     w_t[ 3] = w0[3];
131     w_t[ 4] = w1[0];
132     w_t[ 5] = w1[1];
133     w_t[ 6] = w1[2];
134     w_t[ 7] = w1[3];
135     w_t[ 8] = 0;
136     w_t[ 9] = 0;
137     w_t[10] = 0;
138     w_t[11] = 0;
139     w_t[12] = 0;
140     w_t[13] = 0;
141     w_t[14] = 0;
142     w_t[15] = 0;
143
144     u32x a = MYSQL323_A;
145     u32x b = MYSQL323_B;
146
147     u32x add = 7;
148
149     #define ROUND(v)                              \
150     {                                             \
151       a ^= (((a & 0x3f) + add) * (v)) + (a << 8); \
152       b += (b << 8) ^ a;                          \
153       add += v;                                   \
154     }
155
156     int i;
157     int j;
158
159     for (i = 0, j = 0; i <= (int) pw_len - 4; i += 4, j += 1)
160     {
161       const u32x wj = w_t[j];
162
163       ROUND ((wj >>  0) & 0xff);
164       ROUND ((wj >>  8) & 0xff);
165       ROUND ((wj >> 16) & 0xff);
166       ROUND ((wj >> 24) & 0xff);
167     }
168
169     const u32x wj = w_t[j];
170
171     const u32 left = pw_len - i;
172
173     if (left == 3)
174     {
175       ROUND ((wj >>  0) & 0xff);
176       ROUND ((wj >>  8) & 0xff);
177       ROUND ((wj >> 16) & 0xff);
178     }
179     else if (left == 2)
180     {
181       ROUND ((wj >>  0) & 0xff);
182       ROUND ((wj >>  8) & 0xff);
183     }
184     else if (left == 1)
185     {
186       ROUND ((wj >>  0) & 0xff);
187     }
188
189     a &= 0x7fffffff;
190     b &= 0x7fffffff;
191
192     u32x z = 0;
193
194     COMPARE_M_SIMD (a, b, z, z);
195   }
196 }
197
198 __kernel void m00200_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __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)
199 {
200 }
201
202 __kernel void m00200_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __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)
203 {
204 }
205
206 __kernel void m00200_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __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)
207 {
208   /**
209    * modifier
210    */
211
212   const u32 lid = get_local_id (0);
213
214   /**
215    * base
216    */
217
218   const u32 gid = get_global_id (0);
219
220   if (gid >= gid_max) return;
221
222   u32 pw_buf0[4];
223   u32 pw_buf1[4];
224
225   pw_buf0[0] = pws[gid].i[0];
226   pw_buf0[1] = pws[gid].i[1];
227   pw_buf0[2] = pws[gid].i[2];
228   pw_buf0[3] = pws[gid].i[3];
229   pw_buf1[0] = pws[gid].i[4];
230   pw_buf1[1] = pws[gid].i[5];
231   pw_buf1[2] = pws[gid].i[6];
232   pw_buf1[3] = pws[gid].i[7];
233
234   const u32 pw_l_len = pws[gid].pw_len;
235
236   /**
237    * digest
238    */
239
240   const u32 search[4] =
241   {
242     digests_buf[digests_offset].digest_buf[DGST_R0],
243     digests_buf[digests_offset].digest_buf[DGST_R1],
244     0,
245     0
246   };
247
248   /**
249    * loop
250    */
251
252   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
253   {
254     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
255
256     const u32x pw_len = pw_l_len + pw_r_len;
257
258     /**
259      * concat password candidate
260      */
261
262     u32x wordl0[4] = { 0 };
263     u32x wordl1[4] = { 0 };
264     u32x wordl2[4] = { 0 };
265     u32x wordl3[4] = { 0 };
266
267     wordl0[0] = pw_buf0[0];
268     wordl0[1] = pw_buf0[1];
269     wordl0[2] = pw_buf0[2];
270     wordl0[3] = pw_buf0[3];
271     wordl1[0] = pw_buf1[0];
272     wordl1[1] = pw_buf1[1];
273     wordl1[2] = pw_buf1[2];
274     wordl1[3] = pw_buf1[3];
275
276     u32x wordr0[4] = { 0 };
277     u32x wordr1[4] = { 0 };
278     u32x wordr2[4] = { 0 };
279     u32x wordr3[4] = { 0 };
280
281     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
282     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
283     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
284     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
285     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
286     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
287     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
288     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
289
290     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
291     {
292       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
293     }
294     else
295     {
296       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
297     }
298
299     u32x w0[4];
300     u32x w1[4];
301     u32x w2[4];
302     u32x w3[4];
303
304     w0[0] = wordl0[0] | wordr0[0];
305     w0[1] = wordl0[1] | wordr0[1];
306     w0[2] = wordl0[2] | wordr0[2];
307     w0[3] = wordl0[3] | wordr0[3];
308     w1[0] = wordl1[0] | wordr1[0];
309     w1[1] = wordl1[1] | wordr1[1];
310     w1[2] = wordl1[2] | wordr1[2];
311     w1[3] = wordl1[3] | wordr1[3];
312     w2[0] = wordl2[0] | wordr2[0];
313     w2[1] = wordl2[1] | wordr2[1];
314     w2[2] = wordl2[2] | wordr2[2];
315     w2[3] = wordl2[3] | wordr2[3];
316     w3[0] = wordl3[0] | wordr3[0];
317     w3[1] = wordl3[1] | wordr3[1];
318     w3[2] = pw_len * 8;
319     w3[3] = 0;
320
321     /**
322      * mysql
323      */
324
325     u32x w_t[16];
326
327     w_t[ 0] = w0[0];
328     w_t[ 1] = w0[1];
329     w_t[ 2] = w0[2];
330     w_t[ 3] = w0[3];
331     w_t[ 4] = w1[0];
332     w_t[ 5] = w1[1];
333     w_t[ 6] = w1[2];
334     w_t[ 7] = w1[3];
335     w_t[ 8] = 0;
336     w_t[ 9] = 0;
337     w_t[10] = 0;
338     w_t[11] = 0;
339     w_t[12] = 0;
340     w_t[13] = 0;
341     w_t[14] = 0;
342     w_t[15] = 0;
343
344     u32x a = MYSQL323_A;
345     u32x b = MYSQL323_B;
346     u32x c = 0;
347     u32x d = 0;
348
349     u32x add = 7;
350
351     #define ROUND(v)                              \
352     {                                             \
353       a ^= (((a & 0x3f) + add) * (v)) + (a << 8); \
354       b += (b << 8) ^ a;                          \
355       add += v;                                   \
356     }
357
358     int i;
359     int j;
360
361     for (i = 0, j = 0; i <= (int) pw_len - 4; i += 4, j += 1)
362     {
363       const u32x wj = w_t[j];
364
365       ROUND ((wj >>  0) & 0xff);
366       ROUND ((wj >>  8) & 0xff);
367       ROUND ((wj >> 16) & 0xff);
368       ROUND ((wj >> 24) & 0xff);
369     }
370
371     const u32x wj = w_t[j];
372
373     const u32 left = pw_len - i;
374
375     if (left == 3)
376     {
377       ROUND ((wj >>  0) & 0xff);
378       ROUND ((wj >>  8) & 0xff);
379       ROUND ((wj >> 16) & 0xff);
380     }
381     else if (left == 2)
382     {
383       ROUND ((wj >>  0) & 0xff);
384       ROUND ((wj >>  8) & 0xff);
385     }
386     else if (left == 1)
387     {
388       ROUND ((wj >>  0) & 0xff);
389     }
390
391     a &= 0x7fffffff;
392     b &= 0x7fffffff;
393
394     u32x z = 0;
395
396     COMPARE_S_SIMD (a, b, z, z);
397   }
398 }
399
400 __kernel void m00200_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __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)
401 {
402 }
403
404 __kernel void m00200_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __global bf_t *bfs_buf, __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)
405 {
406 }