febb3506e97179bede1b1ac91ed3278e2e972240
[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 "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_rp.h"
23 #include "inc_rp.cl"
24 #include "inc_simd.cl"
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     u32x z = 0;
139
140     COMPARE_M_SIMD (a, b, z, z);
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   u32 pw_buf1[4];
170
171   pw_buf0[0] = pws[gid].i[0];
172   pw_buf0[1] = pws[gid].i[1];
173   pw_buf0[2] = pws[gid].i[2];
174   pw_buf0[3] = pws[gid].i[3];
175   pw_buf1[0] = pws[gid].i[4];
176   pw_buf1[1] = pws[gid].i[5];
177   pw_buf1[2] = pws[gid].i[6];
178   pw_buf1[3] = pws[gid].i[7];
179
180   const u32 pw_len = pws[gid].pw_len;
181
182   /**
183    * digest
184    */
185
186   const u32 search[4] =
187   {
188     digests_buf[digests_offset].digest_buf[DGST_R0],
189     digests_buf[digests_offset].digest_buf[DGST_R1],
190     0,
191     0
192   };
193
194   /**
195    * loop
196    */
197
198   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
199   {
200     u32x w0[4] = { 0 };
201     u32x w1[4] = { 0 };
202     u32x w2[4] = { 0 };
203     u32x w3[4] = { 0 };
204
205     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
206
207     u32x w_t[16];
208
209     w_t[ 0] = w0[0];
210     w_t[ 1] = w0[1];
211     w_t[ 2] = w0[2];
212     w_t[ 3] = w0[3];
213     w_t[ 4] = w1[0];
214     w_t[ 5] = w1[1];
215     w_t[ 6] = w1[2];
216     w_t[ 7] = w1[3];
217     w_t[ 8] = 0;
218     w_t[ 9] = 0;
219     w_t[10] = 0;
220     w_t[11] = 0;
221     w_t[12] = 0;
222     w_t[13] = 0;
223     w_t[14] = 0;
224     w_t[15] = 0;
225
226     u32x a = MYSQL323_A;
227     u32x b = MYSQL323_B;
228     u32x c = 0;
229     u32x d = 0;
230
231     u32x add = 7;
232
233     #define ROUND(v)                              \
234     {                                             \
235       a ^= (((a & 0x3f) + add) * (v)) + (a << 8); \
236       b += (b << 8) ^ a;                          \
237       add += v;                                   \
238     }
239
240     int i;
241     int j;
242
243     for (i = 0, j = 0; i <= (int) out_len - 4; i += 4, j += 1)
244     {
245       const u32x wj = w_t[j];
246
247       ROUND ((wj >>  0) & 0xff);
248       ROUND ((wj >>  8) & 0xff);
249       ROUND ((wj >> 16) & 0xff);
250       ROUND ((wj >> 24) & 0xff);
251     }
252
253     const u32x wj = w_t[j];
254
255     const u32 left = out_len - i;
256
257     if (left == 3)
258     {
259       ROUND ((wj >>  0) & 0xff);
260       ROUND ((wj >>  8) & 0xff);
261       ROUND ((wj >> 16) & 0xff);
262     }
263     else if (left == 2)
264     {
265       ROUND ((wj >>  0) & 0xff);
266       ROUND ((wj >>  8) & 0xff);
267     }
268     else if (left == 1)
269     {
270       ROUND ((wj >>  0) & 0xff);
271     }
272
273     a &= 0x7fffffff;
274     b &= 0x7fffffff;
275
276     u32x z = 0;
277
278     COMPARE_S_SIMD (a, b, z, z);
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 }