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