Upgrade kernel to support dynamic local work sizes
[hashcat.git] / OpenCL / m00200_a0.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _MYSQL323_
7
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
10
11 #define DGST_R0 0
12 #define DGST_R1 1
13 #define DGST_R2 2
14 #define DGST_R3 3
15
16 #include "include/kernel_functions.c"
17 #include "OpenCL/types_ocl.c"
18 #include "OpenCL/common.c"
19 #include "include/rp_kernel.h"
20 #include "OpenCL/rp.c"
21
22 #define COMPARE_S "OpenCL/check_single_comp4.c"
23 #define COMPARE_M "OpenCL/check_multi_comp4.c"
24
25 __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_scryptV_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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
26 {
27   /**
28    * modifier
29    */
30
31   const u32 lid = get_local_id (0);
32
33   /**
34    * base
35    */
36
37   const u32 gid = get_global_id (0);
38
39   if (gid >= gid_max) return;
40
41   u32 pw_buf0[4];
42
43   pw_buf0[0] = pws[gid].i[ 0];
44   pw_buf0[1] = pws[gid].i[ 1];
45   pw_buf0[2] = pws[gid].i[ 2];
46   pw_buf0[3] = pws[gid].i[ 3];
47
48   u32 pw_buf1[4];
49
50   pw_buf1[0] = pws[gid].i[ 4];
51   pw_buf1[1] = pws[gid].i[ 5];
52   pw_buf1[2] = pws[gid].i[ 6];
53   pw_buf1[3] = pws[gid].i[ 7];
54
55   const u32 pw_len = pws[gid].pw_len;
56
57   /**
58    * loop
59    */
60
61   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
62   {
63     u32 w0[4];
64
65     w0[0] = pw_buf0[0];
66     w0[1] = pw_buf0[1];
67     w0[2] = pw_buf0[2];
68     w0[3] = pw_buf0[3];
69
70     u32 w1[4];
71
72     w1[0] = pw_buf1[0];
73     w1[1] = pw_buf1[1];
74     w1[2] = pw_buf1[2];
75     w1[3] = pw_buf1[3];
76
77     u32 w2[4];
78
79     w2[0] = 0;
80     w2[1] = 0;
81     w2[2] = 0;
82     w2[3] = 0;
83
84     u32 w3[4];
85
86     w3[0] = 0;
87     w3[1] = 0;
88     w3[2] = 0;
89     w3[3] = 0;
90
91     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
92
93     u32 w_t[16];
94
95     w_t[ 0] = w0[0];
96     w_t[ 1] = w0[1];
97     w_t[ 2] = w0[2];
98     w_t[ 3] = w0[3];
99     w_t[ 4] = w1[0];
100     w_t[ 5] = w1[1];
101     w_t[ 6] = w1[2];
102     w_t[ 7] = w1[3];
103     w_t[ 8] = 0;
104     w_t[ 9] = 0;
105     w_t[10] = 0;
106     w_t[11] = 0;
107     w_t[12] = 0;
108     w_t[13] = 0;
109     w_t[14] = 0;
110     w_t[15] = 0;
111
112     u32 a = MYSQL323_A;
113     u32 b = MYSQL323_B;
114
115     u32 add = 7;
116
117     #define ROUND(v)                              \
118     {                                             \
119       a ^= (((a & 0x3f) + add) * (v)) + (a << 8); \
120       b += (b << 8) ^ a;                          \
121       add += v;                                   \
122     }
123
124     int i;
125     int j;
126
127     for (i = 0, j = 0; i <= (int) out_len - 4; i += 4, j += 1)
128     {
129       const u32 wj = w_t[j];
130
131       ROUND ((wj >>  0) & 0xff);
132       ROUND ((wj >>  8) & 0xff);
133       ROUND ((wj >> 16) & 0xff);
134       ROUND ((wj >> 24) & 0xff);
135     }
136
137     const u32 wj = w_t[j];
138
139     const u32 left = out_len - i;
140
141     if (left == 3)
142     {
143       ROUND ((wj >>  0) & 0xff);
144       ROUND ((wj >>  8) & 0xff);
145       ROUND ((wj >> 16) & 0xff);
146     }
147     else if (left == 2)
148     {
149       ROUND ((wj >>  0) & 0xff);
150       ROUND ((wj >>  8) & 0xff);
151     }
152     else if (left == 1)
153     {
154       ROUND ((wj >>  0) & 0xff);
155     }
156
157     a &= 0x7fffffff;
158     b &= 0x7fffffff;
159
160     const u32 r0 = a;
161     const u32 r1 = b;
162     const u32 r2 = 0;
163     const u32 r3 = 0;
164
165     #include COMPARE_M
166   }
167 }
168
169 __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_scryptV_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
170 {
171 }
172
173 __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_scryptV_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
174 {
175 }
176
177 __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_scryptV_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 rules_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
178 {
179   /**
180    * modifier
181    */
182
183   const u32 lid = get_local_id (0);
184
185   /**
186    * base
187    */
188
189   const u32 gid = get_global_id (0);
190
191   if (gid >= gid_max) return;
192
193   u32 pw_buf0[4];
194
195   pw_buf0[0] = pws[gid].i[ 0];
196   pw_buf0[1] = pws[gid].i[ 1];
197   pw_buf0[2] = pws[gid].i[ 2];
198   pw_buf0[3] = pws[gid].i[ 3];
199
200   u32 pw_buf1[4];
201
202   pw_buf1[0] = pws[gid].i[ 4];
203   pw_buf1[1] = pws[gid].i[ 5];
204   pw_buf1[2] = pws[gid].i[ 6];
205   pw_buf1[3] = pws[gid].i[ 7];
206
207   const u32 pw_len = pws[gid].pw_len;
208
209   /**
210    * digest
211    */
212
213   const u32 search[4] =
214   {
215     digests_buf[digests_offset].digest_buf[DGST_R0],
216     digests_buf[digests_offset].digest_buf[DGST_R1],
217     digests_buf[digests_offset].digest_buf[DGST_R2],
218     digests_buf[digests_offset].digest_buf[DGST_R3]
219   };
220
221   /**
222    * loop
223    */
224
225   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
226   {
227     u32 w0[4];
228
229     w0[0] = pw_buf0[0];
230     w0[1] = pw_buf0[1];
231     w0[2] = pw_buf0[2];
232     w0[3] = pw_buf0[3];
233
234     u32 w1[4];
235
236     w1[0] = pw_buf1[0];
237     w1[1] = pw_buf1[1];
238     w1[2] = pw_buf1[2];
239     w1[3] = pw_buf1[3];
240
241     u32 w2[4];
242
243     w2[0] = 0;
244     w2[1] = 0;
245     w2[2] = 0;
246     w2[3] = 0;
247
248     u32 w3[4];
249
250     w3[0] = 0;
251     w3[1] = 0;
252     w3[2] = 0;
253     w3[3] = 0;
254
255     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
256
257     u32 w_t[16];
258
259     w_t[ 0] = w0[0];
260     w_t[ 1] = w0[1];
261     w_t[ 2] = w0[2];
262     w_t[ 3] = w0[3];
263     w_t[ 4] = w1[0];
264     w_t[ 5] = w1[1];
265     w_t[ 6] = w1[2];
266     w_t[ 7] = w1[3];
267     w_t[ 8] = 0;
268     w_t[ 9] = 0;
269     w_t[10] = 0;
270     w_t[11] = 0;
271     w_t[12] = 0;
272     w_t[13] = 0;
273     w_t[14] = 0;
274     w_t[15] = 0;
275
276     u32 a = MYSQL323_A;
277     u32 b = MYSQL323_B;
278
279     u32 add = 7;
280
281     #define ROUND(v)                              \
282     {                                             \
283       a ^= (((a & 0x3f) + add) * (v)) + (a << 8); \
284       b += (b << 8) ^ a;                          \
285       add += v;                                   \
286     }
287
288     int i;
289     int j;
290
291     for (i = 0, j = 0; i <= (int) out_len - 4; i += 4, j += 1)
292     {
293       const u32 wj = w_t[j];
294
295       ROUND ((wj >>  0) & 0xff);
296       ROUND ((wj >>  8) & 0xff);
297       ROUND ((wj >> 16) & 0xff);
298       ROUND ((wj >> 24) & 0xff);
299     }
300
301     const u32 wj = w_t[j];
302
303     const u32 left = out_len - i;
304
305     if (left == 3)
306     {
307       ROUND ((wj >>  0) & 0xff);
308       ROUND ((wj >>  8) & 0xff);
309       ROUND ((wj >> 16) & 0xff);
310     }
311     else if (left == 2)
312     {
313       ROUND ((wj >>  0) & 0xff);
314       ROUND ((wj >>  8) & 0xff);
315     }
316     else if (left == 1)
317     {
318       ROUND ((wj >>  0) & 0xff);
319     }
320
321     a &= 0x7fffffff;
322     b &= 0x7fffffff;
323
324     const u32 r0 = a;
325     const u32 r1 = b;
326     const u32 r2 = 0;
327     const u32 r3 = 0;
328
329     #include COMPARE_S
330   }
331 }
332
333 __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_scryptV_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
334 {
335 }
336
337 __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_scryptV_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 combs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
338 {
339 }