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