More kernel fixes for function calls and vector datatypes
[hashcat.git] / OpenCL / m04310_a0.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _MD5_
7
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
10
11 #define DGST_R0 0
12 #define DGST_R1 3
13 #define DGST_R2 2
14 #define DGST_R3 1
15
16 #include "include/kernel_functions.c"
17 #include "types_ocl.c"
18 #include "common.c"
19 #include "include/rp_gpu.h"
20 #include "rp.c"
21
22 #define COMPARE_S "check_single_comp4.c"
23 #define COMPARE_M "check_multi_comp4.c"
24
25 #define uint_to_hex_lower8(i) l_bin2asc[(i)]
26
27 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m04310_m04 (__global pw_t *pws, __global gpu_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)
28 {
29   /**
30    * modifier
31    */
32
33   const u32 lid = get_local_id (0);
34
35   /**
36    * base
37    */
38
39   const u32 gid = get_global_id (0);
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    * salt
59    */
60
61   const u32 salt_len = salt_bufs[salt_pos].salt_len;
62
63   u32 s[8];
64
65   s[0] = salt_bufs[salt_pos].salt_buf[0];
66   s[1] = salt_bufs[salt_pos].salt_buf[1];
67   s[2] = salt_bufs[salt_pos].salt_buf[2];
68   s[3] = salt_bufs[salt_pos].salt_buf[3];
69   s[4] = salt_bufs[salt_pos].salt_buf[4];
70   s[5] = salt_bufs[salt_pos].salt_buf[5];
71   s[6] = (32 + salt_len) * 8;
72   s[7] = 0;
73
74   /**
75    * bin2asc table
76    */
77
78   __local u32 l_bin2asc[256];
79
80   const u32 lid4 = lid * 4;
81
82   const u32 lid40 = lid4 + 0;
83   const u32 lid41 = lid4 + 1;
84   const u32 lid42 = lid4 + 2;
85   const u32 lid43 = lid4 + 3;
86
87   const u32 v400 = (lid40 >> 0) & 15;
88   const u32 v401 = (lid40 >> 4) & 15;
89   const u32 v410 = (lid41 >> 0) & 15;
90   const u32 v411 = (lid41 >> 4) & 15;
91   const u32 v420 = (lid42 >> 0) & 15;
92   const u32 v421 = (lid42 >> 4) & 15;
93   const u32 v430 = (lid43 >> 0) & 15;
94   const u32 v431 = (lid43 >> 4) & 15;
95
96   l_bin2asc[lid40] = ((v400 < 10) ? '0' + v400 : 'A' - 10 + v400) << 8
97                    | ((v401 < 10) ? '0' + v401 : 'A' - 10 + v401) << 0;
98   l_bin2asc[lid41] = ((v410 < 10) ? '0' + v410 : 'A' - 10 + v410) << 8
99                    | ((v411 < 10) ? '0' + v411 : 'A' - 10 + v411) << 0;
100   l_bin2asc[lid42] = ((v420 < 10) ? '0' + v420 : 'A' - 10 + v420) << 8
101                    | ((v421 < 10) ? '0' + v421 : 'A' - 10 + v421) << 0;
102   l_bin2asc[lid43] = ((v430 < 10) ? '0' + v430 : 'A' - 10 + v430) << 8
103                    | ((v431 < 10) ? '0' + v431 : 'A' - 10 + v431) << 0;
104
105   barrier (CLK_LOCAL_MEM_FENCE);
106
107   if (gid >= gid_max) return;
108
109   /**
110    * loop
111    */
112
113   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
114   {
115     u32 w0[4];
116
117     w0[0] = pw_buf0[0];
118     w0[1] = pw_buf0[1];
119     w0[2] = pw_buf0[2];
120     w0[3] = pw_buf0[3];
121
122     u32 w1[4];
123
124     w1[0] = pw_buf1[0];
125     w1[1] = pw_buf1[1];
126     w1[2] = pw_buf1[2];
127     w1[3] = pw_buf1[3];
128
129     u32 w2[4];
130
131     w2[0] = 0;
132     w2[1] = 0;
133     w2[2] = 0;
134     w2[3] = 0;
135
136     u32 w3[4];
137
138     w3[0] = 0;
139     w3[1] = 0;
140     w3[2] = 0;
141     w3[3] = 0;
142
143     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
144
145     append_0x80_2x4 (w0, w1, out_len);
146
147     w3[2] = out_len * 8;
148
149     u32 a = MD5M_A;
150     u32 b = MD5M_B;
151     u32 c = MD5M_C;
152     u32 d = MD5M_D;
153
154     MD5_STEP (MD5_Fo, a, b, c, d, w0[0], MD5C00, MD5S00);
155     MD5_STEP (MD5_Fo, d, a, b, c, w0[1], MD5C01, MD5S01);
156     MD5_STEP (MD5_Fo, c, d, a, b, w0[2], MD5C02, MD5S02);
157     MD5_STEP (MD5_Fo, b, c, d, a, w0[3], MD5C03, MD5S03);
158     MD5_STEP (MD5_Fo, a, b, c, d, w1[0], MD5C04, MD5S00);
159     MD5_STEP (MD5_Fo, d, a, b, c, w1[1], MD5C05, MD5S01);
160     MD5_STEP (MD5_Fo, c, d, a, b, w1[2], MD5C06, MD5S02);
161     MD5_STEP (MD5_Fo, b, c, d, a, w1[3], MD5C07, MD5S03);
162     MD5_STEP (MD5_Fo, a, b, c, d, w2[0], MD5C08, MD5S00);
163     MD5_STEP (MD5_Fo, d, a, b, c, w2[1], MD5C09, MD5S01);
164     MD5_STEP (MD5_Fo, c, d, a, b, w2[2], MD5C0a, MD5S02);
165     MD5_STEP (MD5_Fo, b, c, d, a, w2[3], MD5C0b, MD5S03);
166     MD5_STEP (MD5_Fo, a, b, c, d, w3[0], MD5C0c, MD5S00);
167     MD5_STEP (MD5_Fo, d, a, b, c, w3[1], MD5C0d, MD5S01);
168     MD5_STEP (MD5_Fo, c, d, a, b, w3[2], MD5C0e, MD5S02);
169     MD5_STEP (MD5_Fo, b, c, d, a, w3[3], MD5C0f, MD5S03);
170
171     MD5_STEP (MD5_Go, a, b, c, d, w0[1], MD5C10, MD5S10);
172     MD5_STEP (MD5_Go, d, a, b, c, w1[2], MD5C11, MD5S11);
173     MD5_STEP (MD5_Go, c, d, a, b, w2[3], MD5C12, MD5S12);
174     MD5_STEP (MD5_Go, b, c, d, a, w0[0], MD5C13, MD5S13);
175     MD5_STEP (MD5_Go, a, b, c, d, w1[1], MD5C14, MD5S10);
176     MD5_STEP (MD5_Go, d, a, b, c, w2[2], MD5C15, MD5S11);
177     MD5_STEP (MD5_Go, c, d, a, b, w3[3], MD5C16, MD5S12);
178     MD5_STEP (MD5_Go, b, c, d, a, w1[0], MD5C17, MD5S13);
179     MD5_STEP (MD5_Go, a, b, c, d, w2[1], MD5C18, MD5S10);
180     MD5_STEP (MD5_Go, d, a, b, c, w3[2], MD5C19, MD5S11);
181     MD5_STEP (MD5_Go, c, d, a, b, w0[3], MD5C1a, MD5S12);
182     MD5_STEP (MD5_Go, b, c, d, a, w2[0], MD5C1b, MD5S13);
183     MD5_STEP (MD5_Go, a, b, c, d, w3[1], MD5C1c, MD5S10);
184     MD5_STEP (MD5_Go, d, a, b, c, w0[2], MD5C1d, MD5S11);
185     MD5_STEP (MD5_Go, c, d, a, b, w1[3], MD5C1e, MD5S12);
186     MD5_STEP (MD5_Go, b, c, d, a, w3[0], MD5C1f, MD5S13);
187
188     MD5_STEP (MD5_H , a, b, c, d, w1[1], MD5C20, MD5S20);
189     MD5_STEP (MD5_H , d, a, b, c, w2[0], MD5C21, MD5S21);
190     MD5_STEP (MD5_H , c, d, a, b, w2[3], MD5C22, MD5S22);
191     MD5_STEP (MD5_H , b, c, d, a, w3[2], MD5C23, MD5S23);
192     MD5_STEP (MD5_H , a, b, c, d, w0[1], MD5C24, MD5S20);
193     MD5_STEP (MD5_H , d, a, b, c, w1[0], MD5C25, MD5S21);
194     MD5_STEP (MD5_H , c, d, a, b, w1[3], MD5C26, MD5S22);
195     MD5_STEP (MD5_H , b, c, d, a, w2[2], MD5C27, MD5S23);
196     MD5_STEP (MD5_H , a, b, c, d, w3[1], MD5C28, MD5S20);
197     MD5_STEP (MD5_H , d, a, b, c, w0[0], MD5C29, MD5S21);
198     MD5_STEP (MD5_H , c, d, a, b, w0[3], MD5C2a, MD5S22);
199     MD5_STEP (MD5_H , b, c, d, a, w1[2], MD5C2b, MD5S23);
200     MD5_STEP (MD5_H , a, b, c, d, w2[1], MD5C2c, MD5S20);
201     MD5_STEP (MD5_H , d, a, b, c, w3[0], MD5C2d, MD5S21);
202     MD5_STEP (MD5_H , c, d, a, b, w3[3], MD5C2e, MD5S22);
203     MD5_STEP (MD5_H , b, c, d, a, w0[2], MD5C2f, MD5S23);
204
205     MD5_STEP (MD5_I , a, b, c, d, w0[0], MD5C30, MD5S30);
206     MD5_STEP (MD5_I , d, a, b, c, w1[3], MD5C31, MD5S31);
207     MD5_STEP (MD5_I , c, d, a, b, w3[2], MD5C32, MD5S32);
208     MD5_STEP (MD5_I , b, c, d, a, w1[1], MD5C33, MD5S33);
209     MD5_STEP (MD5_I , a, b, c, d, w3[0], MD5C34, MD5S30);
210     MD5_STEP (MD5_I , d, a, b, c, w0[3], MD5C35, MD5S31);
211     MD5_STEP (MD5_I , c, d, a, b, w2[2], MD5C36, MD5S32);
212     MD5_STEP (MD5_I , b, c, d, a, w0[1], MD5C37, MD5S33);
213     MD5_STEP (MD5_I , a, b, c, d, w2[0], MD5C38, MD5S30);
214     MD5_STEP (MD5_I , d, a, b, c, w3[3], MD5C39, MD5S31);
215     MD5_STEP (MD5_I , c, d, a, b, w1[2], MD5C3a, MD5S32);
216     MD5_STEP (MD5_I , b, c, d, a, w3[1], MD5C3b, MD5S33);
217     MD5_STEP (MD5_I , a, b, c, d, w1[0], MD5C3c, MD5S30);
218     MD5_STEP (MD5_I , d, a, b, c, w2[3], MD5C3d, MD5S31);
219     MD5_STEP (MD5_I , c, d, a, b, w0[2], MD5C3e, MD5S32);
220     MD5_STEP (MD5_I , b, c, d, a, w2[1], MD5C3f, MD5S33);
221
222     a += MD5M_A;
223     b += MD5M_B;
224     c += MD5M_C;
225     d += MD5M_D;
226
227     const u32 w0_t = uint_to_hex_lower8 ((a >>  0) & 255) <<  0
228                      | uint_to_hex_lower8 ((a >>  8) & 255) << 16;
229     const u32 w1_t = uint_to_hex_lower8 ((a >> 16) & 255) <<  0
230                      | uint_to_hex_lower8 ((a >> 24) & 255) << 16;
231     const u32 w2_t = uint_to_hex_lower8 ((b >>  0) & 255) <<  0
232                      | uint_to_hex_lower8 ((b >>  8) & 255) << 16;
233     const u32 w3_t = uint_to_hex_lower8 ((b >> 16) & 255) <<  0
234                      | uint_to_hex_lower8 ((b >> 24) & 255) << 16;
235     const u32 w4_t = uint_to_hex_lower8 ((c >>  0) & 255) <<  0
236                      | uint_to_hex_lower8 ((c >>  8) & 255) << 16;
237     const u32 w5_t = uint_to_hex_lower8 ((c >> 16) & 255) <<  0
238                      | uint_to_hex_lower8 ((c >> 24) & 255) << 16;
239     const u32 w6_t = uint_to_hex_lower8 ((d >>  0) & 255) <<  0
240                      | uint_to_hex_lower8 ((d >>  8) & 255) << 16;
241     const u32 w7_t = uint_to_hex_lower8 ((d >> 16) & 255) <<  0
242                      | uint_to_hex_lower8 ((d >> 24) & 255) << 16;
243
244     const u32 w8_t = s[0];
245     const u32 w9_t = s[1];
246     const u32 wa_t = s[2];
247     const u32 wb_t = s[3];
248     const u32 wc_t = s[4];
249     const u32 wd_t = s[5];
250     const u32 we_t = s[6];
251     const u32 wf_t = s[7];
252
253     a = MD5M_A;
254     b = MD5M_B;
255     c = MD5M_C;
256     d = MD5M_D;
257
258     MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
259     MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
260     MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
261     MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
262     MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
263     MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
264     MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
265     MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
266     MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
267     MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
268     MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
269     MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
270     MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
271     MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
272     MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
273     MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
274
275     MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
276     MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
277     MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
278     MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
279     MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
280     MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
281     MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
282     MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
283     MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
284     MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
285     MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
286     MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
287     MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
288     MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
289     MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
290     MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
291
292     MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
293     MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
294     MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
295     MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
296     MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
297     MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
298     MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
299     MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
300     MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
301     MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
302     MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
303     MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
304     MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
305     MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
306     MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
307     MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
308
309     MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
310     MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
311     MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
312     MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
313     MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
314     MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
315     MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
316     MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
317     MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
318     MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
319     MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
320     MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
321     MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
322     MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
323     MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
324     MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
325
326     const u32 r0 = a;
327     const u32 r1 = d;
328     const u32 r2 = c;
329     const u32 r3 = b;
330
331     #include COMPARE_M
332   }
333 }
334
335 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m04310_m08 (__global pw_t *pws, __global gpu_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)
336 {
337 }
338
339 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m04310_m16 (__global pw_t *pws, __global gpu_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)
340 {
341 }
342
343 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m04310_s04 (__global pw_t *pws, __global gpu_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)
344 {
345   /**
346    * modifier
347    */
348
349   const u32 lid = get_local_id (0);
350
351   /**
352    * base
353    */
354
355   const u32 gid = get_global_id (0);
356
357   u32 pw_buf0[4];
358
359   pw_buf0[0] = pws[gid].i[ 0];
360   pw_buf0[1] = pws[gid].i[ 1];
361   pw_buf0[2] = pws[gid].i[ 2];
362   pw_buf0[3] = pws[gid].i[ 3];
363
364   u32 pw_buf1[4];
365
366   pw_buf1[0] = pws[gid].i[ 4];
367   pw_buf1[1] = pws[gid].i[ 5];
368   pw_buf1[2] = pws[gid].i[ 6];
369   pw_buf1[3] = pws[gid].i[ 7];
370
371   const u32 pw_len = pws[gid].pw_len;
372
373   /**
374    * salt
375    */
376
377   const u32 salt_len = salt_bufs[salt_pos].salt_len;
378
379   u32 s[8];
380
381   s[0] = salt_bufs[salt_pos].salt_buf[0];
382   s[1] = salt_bufs[salt_pos].salt_buf[1];
383   s[2] = salt_bufs[salt_pos].salt_buf[2];
384   s[3] = salt_bufs[salt_pos].salt_buf[3];
385   s[4] = salt_bufs[salt_pos].salt_buf[4];
386   s[5] = salt_bufs[salt_pos].salt_buf[5];
387   s[6] = (32 + salt_len) * 8;
388   s[7] = 0;
389
390   /**
391    * digest
392    */
393
394   const u32 search[4] =
395   {
396     digests_buf[digests_offset].digest_buf[DGST_R0],
397     digests_buf[digests_offset].digest_buf[DGST_R1],
398     digests_buf[digests_offset].digest_buf[DGST_R2],
399     digests_buf[digests_offset].digest_buf[DGST_R3]
400   };
401
402   /**
403    * bin2asc table
404    */
405
406   __local u32 l_bin2asc[256];
407
408   const u32 lid4 = lid * 4;
409
410   const u32 lid40 = lid4 + 0;
411   const u32 lid41 = lid4 + 1;
412   const u32 lid42 = lid4 + 2;
413   const u32 lid43 = lid4 + 3;
414
415   const u32 v400 = (lid40 >> 0) & 15;
416   const u32 v401 = (lid40 >> 4) & 15;
417   const u32 v410 = (lid41 >> 0) & 15;
418   const u32 v411 = (lid41 >> 4) & 15;
419   const u32 v420 = (lid42 >> 0) & 15;
420   const u32 v421 = (lid42 >> 4) & 15;
421   const u32 v430 = (lid43 >> 0) & 15;
422   const u32 v431 = (lid43 >> 4) & 15;
423
424   l_bin2asc[lid40] = ((v400 < 10) ? '0' + v400 : 'A' - 10 + v400) << 8
425                    | ((v401 < 10) ? '0' + v401 : 'A' - 10 + v401) << 0;
426   l_bin2asc[lid41] = ((v410 < 10) ? '0' + v410 : 'A' - 10 + v410) << 8
427                    | ((v411 < 10) ? '0' + v411 : 'A' - 10 + v411) << 0;
428   l_bin2asc[lid42] = ((v420 < 10) ? '0' + v420 : 'A' - 10 + v420) << 8
429                    | ((v421 < 10) ? '0' + v421 : 'A' - 10 + v421) << 0;
430   l_bin2asc[lid43] = ((v430 < 10) ? '0' + v430 : 'A' - 10 + v430) << 8
431                    | ((v431 < 10) ? '0' + v431 : 'A' - 10 + v431) << 0;
432
433   barrier (CLK_LOCAL_MEM_FENCE);
434
435   if (gid >= gid_max) return;
436
437   /**
438    * loop
439    */
440
441   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
442   {
443     u32 w0[4];
444
445     w0[0] = pw_buf0[0];
446     w0[1] = pw_buf0[1];
447     w0[2] = pw_buf0[2];
448     w0[3] = pw_buf0[3];
449
450     u32 w1[4];
451
452     w1[0] = pw_buf1[0];
453     w1[1] = pw_buf1[1];
454     w1[2] = pw_buf1[2];
455     w1[3] = pw_buf1[3];
456
457     u32 w2[4];
458
459     w2[0] = 0;
460     w2[1] = 0;
461     w2[2] = 0;
462     w2[3] = 0;
463
464     u32 w3[4];
465
466     w3[0] = 0;
467     w3[1] = 0;
468     w3[2] = 0;
469     w3[3] = 0;
470
471     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
472
473     append_0x80_2x4 (w0, w1, out_len);
474
475     w3[2] = out_len * 8;
476
477     u32 a = MD5M_A;
478     u32 b = MD5M_B;
479     u32 c = MD5M_C;
480     u32 d = MD5M_D;
481
482     MD5_STEP (MD5_Fo, a, b, c, d, w0[0], MD5C00, MD5S00);
483     MD5_STEP (MD5_Fo, d, a, b, c, w0[1], MD5C01, MD5S01);
484     MD5_STEP (MD5_Fo, c, d, a, b, w0[2], MD5C02, MD5S02);
485     MD5_STEP (MD5_Fo, b, c, d, a, w0[3], MD5C03, MD5S03);
486     MD5_STEP (MD5_Fo, a, b, c, d, w1[0], MD5C04, MD5S00);
487     MD5_STEP (MD5_Fo, d, a, b, c, w1[1], MD5C05, MD5S01);
488     MD5_STEP (MD5_Fo, c, d, a, b, w1[2], MD5C06, MD5S02);
489     MD5_STEP (MD5_Fo, b, c, d, a, w1[3], MD5C07, MD5S03);
490     MD5_STEP (MD5_Fo, a, b, c, d, w2[0], MD5C08, MD5S00);
491     MD5_STEP (MD5_Fo, d, a, b, c, w2[1], MD5C09, MD5S01);
492     MD5_STEP (MD5_Fo, c, d, a, b, w2[2], MD5C0a, MD5S02);
493     MD5_STEP (MD5_Fo, b, c, d, a, w2[3], MD5C0b, MD5S03);
494     MD5_STEP (MD5_Fo, a, b, c, d, w3[0], MD5C0c, MD5S00);
495     MD5_STEP (MD5_Fo, d, a, b, c, w3[1], MD5C0d, MD5S01);
496     MD5_STEP (MD5_Fo, c, d, a, b, w3[2], MD5C0e, MD5S02);
497     MD5_STEP (MD5_Fo, b, c, d, a, w3[3], MD5C0f, MD5S03);
498
499     MD5_STEP (MD5_Go, a, b, c, d, w0[1], MD5C10, MD5S10);
500     MD5_STEP (MD5_Go, d, a, b, c, w1[2], MD5C11, MD5S11);
501     MD5_STEP (MD5_Go, c, d, a, b, w2[3], MD5C12, MD5S12);
502     MD5_STEP (MD5_Go, b, c, d, a, w0[0], MD5C13, MD5S13);
503     MD5_STEP (MD5_Go, a, b, c, d, w1[1], MD5C14, MD5S10);
504     MD5_STEP (MD5_Go, d, a, b, c, w2[2], MD5C15, MD5S11);
505     MD5_STEP (MD5_Go, c, d, a, b, w3[3], MD5C16, MD5S12);
506     MD5_STEP (MD5_Go, b, c, d, a, w1[0], MD5C17, MD5S13);
507     MD5_STEP (MD5_Go, a, b, c, d, w2[1], MD5C18, MD5S10);
508     MD5_STEP (MD5_Go, d, a, b, c, w3[2], MD5C19, MD5S11);
509     MD5_STEP (MD5_Go, c, d, a, b, w0[3], MD5C1a, MD5S12);
510     MD5_STEP (MD5_Go, b, c, d, a, w2[0], MD5C1b, MD5S13);
511     MD5_STEP (MD5_Go, a, b, c, d, w3[1], MD5C1c, MD5S10);
512     MD5_STEP (MD5_Go, d, a, b, c, w0[2], MD5C1d, MD5S11);
513     MD5_STEP (MD5_Go, c, d, a, b, w1[3], MD5C1e, MD5S12);
514     MD5_STEP (MD5_Go, b, c, d, a, w3[0], MD5C1f, MD5S13);
515
516     MD5_STEP (MD5_H , a, b, c, d, w1[1], MD5C20, MD5S20);
517     MD5_STEP (MD5_H , d, a, b, c, w2[0], MD5C21, MD5S21);
518     MD5_STEP (MD5_H , c, d, a, b, w2[3], MD5C22, MD5S22);
519     MD5_STEP (MD5_H , b, c, d, a, w3[2], MD5C23, MD5S23);
520     MD5_STEP (MD5_H , a, b, c, d, w0[1], MD5C24, MD5S20);
521     MD5_STEP (MD5_H , d, a, b, c, w1[0], MD5C25, MD5S21);
522     MD5_STEP (MD5_H , c, d, a, b, w1[3], MD5C26, MD5S22);
523     MD5_STEP (MD5_H , b, c, d, a, w2[2], MD5C27, MD5S23);
524     MD5_STEP (MD5_H , a, b, c, d, w3[1], MD5C28, MD5S20);
525     MD5_STEP (MD5_H , d, a, b, c, w0[0], MD5C29, MD5S21);
526     MD5_STEP (MD5_H , c, d, a, b, w0[3], MD5C2a, MD5S22);
527     MD5_STEP (MD5_H , b, c, d, a, w1[2], MD5C2b, MD5S23);
528     MD5_STEP (MD5_H , a, b, c, d, w2[1], MD5C2c, MD5S20);
529     MD5_STEP (MD5_H , d, a, b, c, w3[0], MD5C2d, MD5S21);
530     MD5_STEP (MD5_H , c, d, a, b, w3[3], MD5C2e, MD5S22);
531     MD5_STEP (MD5_H , b, c, d, a, w0[2], MD5C2f, MD5S23);
532
533     MD5_STEP (MD5_I , a, b, c, d, w0[0], MD5C30, MD5S30);
534     MD5_STEP (MD5_I , d, a, b, c, w1[3], MD5C31, MD5S31);
535     MD5_STEP (MD5_I , c, d, a, b, w3[2], MD5C32, MD5S32);
536     MD5_STEP (MD5_I , b, c, d, a, w1[1], MD5C33, MD5S33);
537     MD5_STEP (MD5_I , a, b, c, d, w3[0], MD5C34, MD5S30);
538     MD5_STEP (MD5_I , d, a, b, c, w0[3], MD5C35, MD5S31);
539     MD5_STEP (MD5_I , c, d, a, b, w2[2], MD5C36, MD5S32);
540     MD5_STEP (MD5_I , b, c, d, a, w0[1], MD5C37, MD5S33);
541     MD5_STEP (MD5_I , a, b, c, d, w2[0], MD5C38, MD5S30);
542     MD5_STEP (MD5_I , d, a, b, c, w3[3], MD5C39, MD5S31);
543     MD5_STEP (MD5_I , c, d, a, b, w1[2], MD5C3a, MD5S32);
544     MD5_STEP (MD5_I , b, c, d, a, w3[1], MD5C3b, MD5S33);
545     MD5_STEP (MD5_I , a, b, c, d, w1[0], MD5C3c, MD5S30);
546     MD5_STEP (MD5_I , d, a, b, c, w2[3], MD5C3d, MD5S31);
547     MD5_STEP (MD5_I , c, d, a, b, w0[2], MD5C3e, MD5S32);
548     MD5_STEP (MD5_I , b, c, d, a, w2[1], MD5C3f, MD5S33);
549
550     a += MD5M_A;
551     b += MD5M_B;
552     c += MD5M_C;
553     d += MD5M_D;
554
555     const u32 w0_t = uint_to_hex_lower8 ((a >>  0) & 255) <<  0
556                      | uint_to_hex_lower8 ((a >>  8) & 255) << 16;
557     const u32 w1_t = uint_to_hex_lower8 ((a >> 16) & 255) <<  0
558                      | uint_to_hex_lower8 ((a >> 24) & 255) << 16;
559     const u32 w2_t = uint_to_hex_lower8 ((b >>  0) & 255) <<  0
560                      | uint_to_hex_lower8 ((b >>  8) & 255) << 16;
561     const u32 w3_t = uint_to_hex_lower8 ((b >> 16) & 255) <<  0
562                      | uint_to_hex_lower8 ((b >> 24) & 255) << 16;
563     const u32 w4_t = uint_to_hex_lower8 ((c >>  0) & 255) <<  0
564                      | uint_to_hex_lower8 ((c >>  8) & 255) << 16;
565     const u32 w5_t = uint_to_hex_lower8 ((c >> 16) & 255) <<  0
566                      | uint_to_hex_lower8 ((c >> 24) & 255) << 16;
567     const u32 w6_t = uint_to_hex_lower8 ((d >>  0) & 255) <<  0
568                      | uint_to_hex_lower8 ((d >>  8) & 255) << 16;
569     const u32 w7_t = uint_to_hex_lower8 ((d >> 16) & 255) <<  0
570                      | uint_to_hex_lower8 ((d >> 24) & 255) << 16;
571
572     const u32 w8_t = s[0];
573     const u32 w9_t = s[1];
574     const u32 wa_t = s[2];
575     const u32 wb_t = s[3];
576     const u32 wc_t = s[4];
577     const u32 wd_t = s[5];
578     const u32 we_t = s[6];
579     const u32 wf_t = s[7];
580
581     a = MD5M_A;
582     b = MD5M_B;
583     c = MD5M_C;
584     d = MD5M_D;
585
586     MD5_STEP (MD5_Fo, a, b, c, d, w0_t, MD5C00, MD5S00);
587     MD5_STEP (MD5_Fo, d, a, b, c, w1_t, MD5C01, MD5S01);
588     MD5_STEP (MD5_Fo, c, d, a, b, w2_t, MD5C02, MD5S02);
589     MD5_STEP (MD5_Fo, b, c, d, a, w3_t, MD5C03, MD5S03);
590     MD5_STEP (MD5_Fo, a, b, c, d, w4_t, MD5C04, MD5S00);
591     MD5_STEP (MD5_Fo, d, a, b, c, w5_t, MD5C05, MD5S01);
592     MD5_STEP (MD5_Fo, c, d, a, b, w6_t, MD5C06, MD5S02);
593     MD5_STEP (MD5_Fo, b, c, d, a, w7_t, MD5C07, MD5S03);
594     MD5_STEP (MD5_Fo, a, b, c, d, w8_t, MD5C08, MD5S00);
595     MD5_STEP (MD5_Fo, d, a, b, c, w9_t, MD5C09, MD5S01);
596     MD5_STEP (MD5_Fo, c, d, a, b, wa_t, MD5C0a, MD5S02);
597     MD5_STEP (MD5_Fo, b, c, d, a, wb_t, MD5C0b, MD5S03);
598     MD5_STEP (MD5_Fo, a, b, c, d, wc_t, MD5C0c, MD5S00);
599     MD5_STEP (MD5_Fo, d, a, b, c, wd_t, MD5C0d, MD5S01);
600     MD5_STEP (MD5_Fo, c, d, a, b, we_t, MD5C0e, MD5S02);
601     MD5_STEP (MD5_Fo, b, c, d, a, wf_t, MD5C0f, MD5S03);
602
603     MD5_STEP (MD5_Go, a, b, c, d, w1_t, MD5C10, MD5S10);
604     MD5_STEP (MD5_Go, d, a, b, c, w6_t, MD5C11, MD5S11);
605     MD5_STEP (MD5_Go, c, d, a, b, wb_t, MD5C12, MD5S12);
606     MD5_STEP (MD5_Go, b, c, d, a, w0_t, MD5C13, MD5S13);
607     MD5_STEP (MD5_Go, a, b, c, d, w5_t, MD5C14, MD5S10);
608     MD5_STEP (MD5_Go, d, a, b, c, wa_t, MD5C15, MD5S11);
609     MD5_STEP (MD5_Go, c, d, a, b, wf_t, MD5C16, MD5S12);
610     MD5_STEP (MD5_Go, b, c, d, a, w4_t, MD5C17, MD5S13);
611     MD5_STEP (MD5_Go, a, b, c, d, w9_t, MD5C18, MD5S10);
612     MD5_STEP (MD5_Go, d, a, b, c, we_t, MD5C19, MD5S11);
613     MD5_STEP (MD5_Go, c, d, a, b, w3_t, MD5C1a, MD5S12);
614     MD5_STEP (MD5_Go, b, c, d, a, w8_t, MD5C1b, MD5S13);
615     MD5_STEP (MD5_Go, a, b, c, d, wd_t, MD5C1c, MD5S10);
616     MD5_STEP (MD5_Go, d, a, b, c, w2_t, MD5C1d, MD5S11);
617     MD5_STEP (MD5_Go, c, d, a, b, w7_t, MD5C1e, MD5S12);
618     MD5_STEP (MD5_Go, b, c, d, a, wc_t, MD5C1f, MD5S13);
619
620     MD5_STEP (MD5_H , a, b, c, d, w5_t, MD5C20, MD5S20);
621     MD5_STEP (MD5_H , d, a, b, c, w8_t, MD5C21, MD5S21);
622     MD5_STEP (MD5_H , c, d, a, b, wb_t, MD5C22, MD5S22);
623     MD5_STEP (MD5_H , b, c, d, a, we_t, MD5C23, MD5S23);
624     MD5_STEP (MD5_H , a, b, c, d, w1_t, MD5C24, MD5S20);
625     MD5_STEP (MD5_H , d, a, b, c, w4_t, MD5C25, MD5S21);
626     MD5_STEP (MD5_H , c, d, a, b, w7_t, MD5C26, MD5S22);
627     MD5_STEP (MD5_H , b, c, d, a, wa_t, MD5C27, MD5S23);
628     MD5_STEP (MD5_H , a, b, c, d, wd_t, MD5C28, MD5S20);
629     MD5_STEP (MD5_H , d, a, b, c, w0_t, MD5C29, MD5S21);
630     MD5_STEP (MD5_H , c, d, a, b, w3_t, MD5C2a, MD5S22);
631     MD5_STEP (MD5_H , b, c, d, a, w6_t, MD5C2b, MD5S23);
632     MD5_STEP (MD5_H , a, b, c, d, w9_t, MD5C2c, MD5S20);
633     MD5_STEP (MD5_H , d, a, b, c, wc_t, MD5C2d, MD5S21);
634     MD5_STEP (MD5_H , c, d, a, b, wf_t, MD5C2e, MD5S22);
635     MD5_STEP (MD5_H , b, c, d, a, w2_t, MD5C2f, MD5S23);
636
637     MD5_STEP (MD5_I , a, b, c, d, w0_t, MD5C30, MD5S30);
638     MD5_STEP (MD5_I , d, a, b, c, w7_t, MD5C31, MD5S31);
639     MD5_STEP (MD5_I , c, d, a, b, we_t, MD5C32, MD5S32);
640     MD5_STEP (MD5_I , b, c, d, a, w5_t, MD5C33, MD5S33);
641     MD5_STEP (MD5_I , a, b, c, d, wc_t, MD5C34, MD5S30);
642     MD5_STEP (MD5_I , d, a, b, c, w3_t, MD5C35, MD5S31);
643     MD5_STEP (MD5_I , c, d, a, b, wa_t, MD5C36, MD5S32);
644     MD5_STEP (MD5_I , b, c, d, a, w1_t, MD5C37, MD5S33);
645     MD5_STEP (MD5_I , a, b, c, d, w8_t, MD5C38, MD5S30);
646     MD5_STEP (MD5_I , d, a, b, c, wf_t, MD5C39, MD5S31);
647     MD5_STEP (MD5_I , c, d, a, b, w6_t, MD5C3a, MD5S32);
648     MD5_STEP (MD5_I , b, c, d, a, wd_t, MD5C3b, MD5S33);
649     MD5_STEP (MD5_I , a, b, c, d, w4_t, MD5C3c, MD5S30);
650     MD5_STEP (MD5_I , d, a, b, c, wb_t, MD5C3d, MD5S31);
651     MD5_STEP (MD5_I , c, d, a, b, w2_t, MD5C3e, MD5S32);
652     MD5_STEP (MD5_I , b, c, d, a, w9_t, MD5C3f, MD5S33);
653
654     const u32 r0 = a;
655     const u32 r1 = d;
656     const u32 r2 = c;
657     const u32 r3 = b;
658
659     #include COMPARE_S
660   }
661 }
662
663 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m04310_s08 (__global pw_t *pws, __global gpu_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)
664 {
665 }
666
667 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m04310_s16 (__global pw_t *pws, __global gpu_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)
668 {
669 }