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