Initial commit
[hashcat.git] / amd / m10100_a0.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _SIPHASH_
7
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
10
11 #ifdef  VLIW1
12 #define VECT_SIZE1
13 #endif
14
15 #ifdef  VLIW4
16 #define VECT_SIZE1
17 #endif
18
19 #ifdef  VLIW5
20 #define VECT_SIZE1
21 #endif
22
23 #define DGST_R0 0
24 #define DGST_R1 1
25 #define DGST_R2 2
26 #define DGST_R3 3
27
28 #include "include/kernel_functions.c"
29 #include "types_amd.c"
30 #include "common_amd.c"
31 #include "include/rp_gpu.h"
32 #include "rp_amd.c"
33
34 #ifdef  VECT_SIZE1
35 #define VECT_COMPARE_S "check_single_vect1_comp4.c"
36 #define VECT_COMPARE_M "check_multi_vect1_comp4.c"
37 #endif
38
39 #ifdef  VECT_SIZE2
40 #define VECT_COMPARE_S "check_single_vect2_comp4.c"
41 #define VECT_COMPARE_M "check_multi_vect2_comp4.c"
42 #endif
43
44 #ifdef  VECT_SIZE4
45 #define VECT_COMPARE_S "check_single_vect4_comp4.c"
46 #define VECT_COMPARE_M "check_multi_vect4_comp4.c"
47 #endif
48
49 #ifdef VECT_SIZE1
50 #define SIPROUND(v0,v1,v2,v3) \
51   (v0) += (v1);               \
52   (v1)  = rotl64 ((v1), 13);  \
53   (v1) ^= (v0);               \
54   (v0)  = as_ulong (as_uint2 ((v0)).s10); \
55   (v2) += (v3);               \
56   (v3)  = rotl64 ((v3), 16);  \
57   (v3) ^= (v2);               \
58   (v0) += (v3);               \
59   (v3)  = rotl64 ((v3), 21);  \
60   (v3) ^= (v0);               \
61   (v2) += (v1);               \
62   (v1)  = rotl64 ((v1), 17);  \
63   (v1) ^= (v2);               \
64   (v2)  = as_ulong (as_uint2 ((v2)).s10);
65 #else
66 #define SIPROUND(v0,v1,v2,v3) \
67   (v0) += (v1);               \
68   (v1)  = rotl64 ((v1), 13);  \
69   (v1) ^= (v0);               \
70   (v0)  = rotl64 ((v0), 32);  \
71   (v2) += (v3);               \
72   (v3)  = rotl64 ((v3), 16);  \
73   (v3) ^= (v2);               \
74   (v0) += (v3);               \
75   (v3)  = rotl64 ((v3), 21);  \
76   (v3) ^= (v0);               \
77   (v2) += (v1);               \
78   (v1)  = rotl64 ((v1), 17);  \
79   (v1) ^= (v2);               \
80   (v2)  = rotl64 ((v2), 32);
81 #endif
82
83 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10100_m04 (__global pw_t *pws, __global gpu_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)
84 {
85   /**
86    * modifier
87    */
88
89   const u32 lid = get_local_id (0);
90
91   /**
92    * base
93    */
94
95   const u32 gid = get_global_id (0);
96
97   if (gid >= gid_max) return;
98
99   u32x pw_buf0[4];
100
101   pw_buf0[0] = pws[gid].i[ 0];
102   pw_buf0[1] = pws[gid].i[ 1];
103   pw_buf0[2] = pws[gid].i[ 2];
104   pw_buf0[3] = pws[gid].i[ 3];
105
106   u32x pw_buf1[4];
107
108   pw_buf1[0] = pws[gid].i[ 4];
109   pw_buf1[1] = pws[gid].i[ 5];
110   pw_buf1[2] = pws[gid].i[ 6];
111   pw_buf1[3] = pws[gid].i[ 7];
112
113   const u32 pw_len = pws[gid].pw_len;
114
115   /**
116    * base
117    */
118
119   u64 v0p = SIPHASHM_0;
120   u64 v1p = SIPHASHM_1;
121   u64 v2p = SIPHASHM_2;
122   u64 v3p = SIPHASHM_3;
123
124   v0p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
125   v1p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
126   v2p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
127   v3p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
128
129   /**
130    * loop
131    */
132
133   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
134   {
135     u32x w[16];
136
137     w[ 0] = pw_buf0[0];
138     w[ 1] = pw_buf0[1];
139     w[ 2] = pw_buf0[2];
140     w[ 3] = pw_buf0[3];
141     w[ 4] = pw_buf1[0];
142     w[ 5] = pw_buf1[1];
143     w[ 6] = pw_buf1[2];
144     w[ 7] = pw_buf1[3];
145     w[ 8] = 0;
146     w[ 9] = 0;
147     w[10] = 0;
148     w[11] = 0;
149     w[12] = 0;
150     w[13] = 0;
151     w[14] = 0;
152     w[15] = 0;
153
154     const u32x out_len = apply_rules (rules_buf[il_pos].cmds, &w[0], &w[4], pw_len);
155
156     u64 *w_ptr = (u64 *) w;
157
158     w_ptr[out_len / 8] |= (u64) out_len << 56;
159
160     u64x v0 = v0p;
161     u64x v1 = v1p;
162     u64x v2 = v2p;
163     u64x v3 = v3p;
164
165     int i;
166     int j;
167
168     for (i = 0, j = 0; i <= pw_len; i += 8, j += 2)
169     {
170       u64x m = hl32_to_64 (w[j + 1], w[j + 0]);
171
172       v3 ^= m;
173
174       SIPROUND (v0, v1, v2, v3);
175       SIPROUND (v0, v1, v2, v3);
176
177       v0 ^= m;
178     }
179
180     v2 ^= 0xff;
181
182     SIPROUND (v0, v1, v2, v3);
183     SIPROUND (v0, v1, v2, v3);
184     SIPROUND (v0, v1, v2, v3);
185     SIPROUND (v0, v1, v2, v3);
186
187     const u64x v = v0 ^ v1 ^ v2 ^ v3;
188
189     const u32x a = l32_from_64 (v);
190     const u32x b = h32_from_64 (v);
191
192     const u32x r0 = a;
193     const u32x r1 = b;
194     const u32x r2 = 0;
195     const u32x r3 = 0;
196
197     #include VECT_COMPARE_M
198   }
199 }
200
201 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10100_m08 (__global pw_t *pws, __global gpu_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)
202 {
203 }
204
205 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10100_m16 (__global pw_t *pws, __global gpu_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)
206 {
207 }
208
209 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10100_s04 (__global pw_t *pws, __global gpu_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)
210 {
211   /**
212    * modifier
213    */
214
215   const u32 lid = get_local_id (0);
216
217   /**
218    * base
219    */
220
221   const u32 gid = get_global_id (0);
222
223   if (gid >= gid_max) return;
224
225   u32x pw_buf0[4];
226
227   pw_buf0[0] = pws[gid].i[ 0];
228   pw_buf0[1] = pws[gid].i[ 1];
229   pw_buf0[2] = pws[gid].i[ 2];
230   pw_buf0[3] = pws[gid].i[ 3];
231
232   u32x pw_buf1[4];
233
234   pw_buf1[0] = pws[gid].i[ 4];
235   pw_buf1[1] = pws[gid].i[ 5];
236   pw_buf1[2] = pws[gid].i[ 6];
237   pw_buf1[3] = pws[gid].i[ 7];
238
239   const u32 pw_len = pws[gid].pw_len;
240
241   /**
242    * base
243    */
244
245   u64 v0p = SIPHASHM_0;
246   u64 v1p = SIPHASHM_1;
247   u64 v2p = SIPHASHM_2;
248   u64 v3p = SIPHASHM_3;
249
250   v0p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
251   v1p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
252   v2p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
253   v3p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
254
255   /**
256    * digest
257    */
258
259   const u32 search[4] =
260   {
261     digests_buf[digests_offset].digest_buf[DGST_R0],
262     digests_buf[digests_offset].digest_buf[DGST_R1],
263     digests_buf[digests_offset].digest_buf[DGST_R2],
264     digests_buf[digests_offset].digest_buf[DGST_R3]
265   };
266
267   /**
268    * loop
269    */
270
271   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
272   {
273     u32x w[16];
274
275     w[ 0] = pw_buf0[0];
276     w[ 1] = pw_buf0[1];
277     w[ 2] = pw_buf0[2];
278     w[ 3] = pw_buf0[3];
279     w[ 4] = pw_buf1[0];
280     w[ 5] = pw_buf1[1];
281     w[ 6] = pw_buf1[2];
282     w[ 7] = pw_buf1[3];
283     w[ 8] = 0;
284     w[ 9] = 0;
285     w[10] = 0;
286     w[11] = 0;
287     w[12] = 0;
288     w[13] = 0;
289     w[14] = 0;
290     w[15] = 0;
291
292     const u32x out_len = apply_rules (rules_buf[il_pos].cmds, &w[0], &w[4], pw_len);
293
294     u64 *w_ptr = (u64 *) w;
295
296     w_ptr[out_len / 8] |= (u64) out_len << 56;
297
298     u64x v0 = v0p;
299     u64x v1 = v1p;
300     u64x v2 = v2p;
301     u64x v3 = v3p;
302
303     int i;
304     int j;
305
306     for (i = 0, j = 0; i <= pw_len; i += 8, j += 2)
307     {
308       u64x m = hl32_to_64 (w[j + 1], w[j + 0]);
309
310       v3 ^= m;
311
312       SIPROUND (v0, v1, v2, v3);
313       SIPROUND (v0, v1, v2, v3);
314
315       v0 ^= m;
316     }
317
318     v2 ^= 0xff;
319
320     SIPROUND (v0, v1, v2, v3);
321     SIPROUND (v0, v1, v2, v3);
322     SIPROUND (v0, v1, v2, v3);
323     SIPROUND (v0, v1, v2, v3);
324
325     const u64x v = v0 ^ v1 ^ v2 ^ v3;
326
327     const u32x a = l32_from_64 (v);
328     const u32x b = h32_from_64 (v);
329
330     const u32x r0 = a;
331     const u32x r1 = b;
332     const u32x r2 = 0;
333     const u32x r3 = 0;
334
335     #include VECT_COMPARE_S
336   }
337 }
338
339 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10100_s08 (__global pw_t *pws, __global gpu_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)
340 {
341 }
342
343 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m10100_s16 (__global pw_t *pws, __global gpu_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)
344 {
345 }