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