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