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