Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m10100_a1.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _SIPHASH_
7
8 //incompatible to simd
9 //#define NEW_SIMD_CODE
10
11 #include "inc_vendor.cl"
12 #include "inc_hash_constants.h"
13 #include "inc_hash_functions.cl"
14 #include "inc_types.cl"
15 #include "inc_common.cl"
16 #include "inc_simd.cl"
17
18 #define SIPROUND(v0,v1,v2,v3) \
19   (v0) += (v1);               \
20   (v1)  = rotl64 ((v1), 13);  \
21   (v1) ^= (v0);               \
22   (v0)  = rotl64 ((v0), 32);  \
23   (v2) += (v3);               \
24   (v3)  = rotl64 ((v3), 16);  \
25   (v3) ^= (v2);               \
26   (v0) += (v3);               \
27   (v3)  = rotl64 ((v3), 21);  \
28   (v3) ^= (v0);               \
29   (v2) += (v1);               \
30   (v1)  = rotl64 ((v1), 17);  \
31   (v1) ^= (v2);               \
32   (v2)  = rotl64 ((v2), 32)
33
34 __kernel void m10100_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
35 {
36   /**
37    * modifier
38    */
39
40   const u32 lid = get_local_id (0);
41
42   /**
43    * base
44    */
45
46   const u32 gid = get_global_id (0);
47
48   if (gid >= gid_max) return;
49
50   u32 pw_buf0[4];
51   u32 pw_buf1[4];
52
53   pw_buf0[0] = pws[gid].i[0];
54   pw_buf0[1] = pws[gid].i[1];
55   pw_buf0[2] = pws[gid].i[2];
56   pw_buf0[3] = pws[gid].i[3];
57   pw_buf1[0] = pws[gid].i[4];
58   pw_buf1[1] = pws[gid].i[5];
59   pw_buf1[2] = pws[gid].i[6];
60   pw_buf1[3] = pws[gid].i[7];
61
62   const u32 pw_l_len = pws[gid].pw_len;
63
64   /**
65    * salt
66    */
67
68   u64x v0p = SIPHASHM_0;
69   u64x v1p = SIPHASHM_1;
70   u64x v2p = SIPHASHM_2;
71   u64x v3p = SIPHASHM_3;
72
73   v0p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
74   v1p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
75   v2p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
76   v3p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
77
78   /**
79    * loop
80    */
81
82   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
83   {
84     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
85
86     const u32x pw_len = pw_l_len + pw_r_len;
87
88     /**
89      * concat password candidate
90      */
91
92     u32x wordl0[4] = { 0 };
93     u32x wordl1[4] = { 0 };
94     u32x wordl2[4] = { 0 };
95     u32x wordl3[4] = { 0 };
96
97     wordl0[0] = pw_buf0[0];
98     wordl0[1] = pw_buf0[1];
99     wordl0[2] = pw_buf0[2];
100     wordl0[3] = pw_buf0[3];
101     wordl1[0] = pw_buf1[0];
102     wordl1[1] = pw_buf1[1];
103     wordl1[2] = pw_buf1[2];
104     wordl1[3] = pw_buf1[3];
105
106     u32x wordr0[4] = { 0 };
107     u32x wordr1[4] = { 0 };
108     u32x wordr2[4] = { 0 };
109     u32x wordr3[4] = { 0 };
110
111     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
112     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
113     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
114     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
115     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
116     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
117     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
118     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
119
120     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
121     {
122       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
123     }
124     else
125     {
126       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
127     }
128
129     u32x w0[4];
130     u32x w1[4];
131     u32x w2[4];
132     u32x w3[4];
133
134     w0[0] = wordl0[0] | wordr0[0];
135     w0[1] = wordl0[1] | wordr0[1];
136     w0[2] = wordl0[2] | wordr0[2];
137     w0[3] = wordl0[3] | wordr0[3];
138     w1[0] = wordl1[0] | wordr1[0];
139     w1[1] = wordl1[1] | wordr1[1];
140     w1[2] = wordl1[2] | wordr1[2];
141     w1[3] = wordl1[3] | wordr1[3];
142     w2[0] = wordl2[0] | wordr2[0];
143     w2[1] = wordl2[1] | wordr2[1];
144     w2[2] = wordl2[2] | wordr2[2];
145     w2[3] = wordl2[3] | wordr2[3];
146     w3[0] = wordl3[0] | wordr3[0];
147     w3[1] = wordl3[1] | wordr3[1];
148     w3[2] = wordl3[2] | wordr3[2];
149     w3[3] = wordl3[3] | wordr3[3];
150
151     /**
152      * siphash
153      */
154
155     switch (pw_len / 8)
156     {
157       case 0: w0[1] |= pw_len << 24; break;
158       case 1: w0[3] |= pw_len << 24; break;
159       case 2: w1[1] |= pw_len << 24; break;
160       case 3: w1[3] |= pw_len << 24; break;
161     }
162
163     u64x v0 = v0p;
164     u64x v1 = v1p;
165     u64x v2 = v2p;
166     u64x v3 = v3p;
167
168     int i;
169     int j;
170
171     for (i = 0, j = 0; i <= pw_len && i < 16; i += 8, j += 2)
172     {
173       u64x m = hl32_to_64 (w0[j + 1], w0[j + 0]);
174
175       v3 ^= m;
176
177       SIPROUND (v0, v1, v2, v3);
178       SIPROUND (v0, v1, v2, v3);
179
180       v0 ^= m;
181     }
182
183     for (       j = 0; i <= pw_len && i < 32; i += 8, j += 2)
184     {
185       u64x m = hl32_to_64 (w1[j + 1], w1[j + 0]);
186
187       v3 ^= m;
188
189       SIPROUND (v0, v1, v2, v3);
190       SIPROUND (v0, v1, v2, v3);
191
192       v0 ^= m;
193     }
194
195     v2 ^= 0xff;
196
197     SIPROUND (v0, v1, v2, v3);
198     SIPROUND (v0, v1, v2, v3);
199     SIPROUND (v0, v1, v2, v3);
200     SIPROUND (v0, v1, v2, v3);
201
202     const u64x v = v0 ^ v1 ^ v2 ^ v3;
203
204     const u32x a = l32_from_64 (v);
205     const u32x b = h32_from_64 (v);
206
207     const u32x z = 0;
208
209     COMPARE_M_SIMD (a, b, z, z);
210   }
211 }
212
213 __kernel void m10100_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
214 {
215 }
216
217 __kernel void m10100_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
218 {
219 }
220
221 __kernel void m10100_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
222 {
223   /**
224    * modifier
225    */
226
227   const u32 lid = get_local_id (0);
228
229   /**
230    * base
231    */
232
233   const u32 gid = get_global_id (0);
234
235   if (gid >= gid_max) return;
236
237   u32 pw_buf0[4];
238   u32 pw_buf1[4];
239
240   pw_buf0[0] = pws[gid].i[0];
241   pw_buf0[1] = pws[gid].i[1];
242   pw_buf0[2] = pws[gid].i[2];
243   pw_buf0[3] = pws[gid].i[3];
244   pw_buf1[0] = pws[gid].i[4];
245   pw_buf1[1] = pws[gid].i[5];
246   pw_buf1[2] = pws[gid].i[6];
247   pw_buf1[3] = pws[gid].i[7];
248
249   const u32 pw_l_len = pws[gid].pw_len;
250
251   /**
252    * salt
253    */
254
255   u64x v0p = SIPHASHM_0;
256   u64x v1p = SIPHASHM_1;
257   u64x v2p = SIPHASHM_2;
258   u64x v3p = SIPHASHM_3;
259
260   v0p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
261   v1p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
262   v2p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[1], salt_bufs[salt_pos].salt_buf[0]);
263   v3p ^= hl32_to_64 (salt_bufs[salt_pos].salt_buf[3], salt_bufs[salt_pos].salt_buf[2]);
264
265   /**
266    * digest
267    */
268
269   const u32 search[4] =
270   {
271     digests_buf[digests_offset].digest_buf[DGST_R0],
272     digests_buf[digests_offset].digest_buf[DGST_R1],
273     0,
274     0
275   };
276
277   /**
278    * loop
279    */
280
281   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
282   {
283     const u32x pw_r_len = pwlenx_create_combt (combs_buf, il_pos);
284
285     const u32x pw_len = pw_l_len + pw_r_len;
286
287     /**
288      * concat password candidate
289      */
290
291     u32x wordl0[4] = { 0 };
292     u32x wordl1[4] = { 0 };
293     u32x wordl2[4] = { 0 };
294     u32x wordl3[4] = { 0 };
295
296     wordl0[0] = pw_buf0[0];
297     wordl0[1] = pw_buf0[1];
298     wordl0[2] = pw_buf0[2];
299     wordl0[3] = pw_buf0[3];
300     wordl1[0] = pw_buf1[0];
301     wordl1[1] = pw_buf1[1];
302     wordl1[2] = pw_buf1[2];
303     wordl1[3] = pw_buf1[3];
304
305     u32x wordr0[4] = { 0 };
306     u32x wordr1[4] = { 0 };
307     u32x wordr2[4] = { 0 };
308     u32x wordr3[4] = { 0 };
309
310     wordr0[0] = ix_create_combt (combs_buf, il_pos, 0);
311     wordr0[1] = ix_create_combt (combs_buf, il_pos, 1);
312     wordr0[2] = ix_create_combt (combs_buf, il_pos, 2);
313     wordr0[3] = ix_create_combt (combs_buf, il_pos, 3);
314     wordr1[0] = ix_create_combt (combs_buf, il_pos, 4);
315     wordr1[1] = ix_create_combt (combs_buf, il_pos, 5);
316     wordr1[2] = ix_create_combt (combs_buf, il_pos, 6);
317     wordr1[3] = ix_create_combt (combs_buf, il_pos, 7);
318
319     if (combs_mode == COMBINATOR_MODE_BASE_LEFT)
320     {
321       switch_buffer_by_offset_le_VV (wordr0, wordr1, wordr2, wordr3, pw_l_len);
322     }
323     else
324     {
325       switch_buffer_by_offset_le_VV (wordl0, wordl1, wordl2, wordl3, pw_r_len);
326     }
327
328     u32x w0[4];
329     u32x w1[4];
330     u32x w2[4];
331     u32x w3[4];
332
333     w0[0] = wordl0[0] | wordr0[0];
334     w0[1] = wordl0[1] | wordr0[1];
335     w0[2] = wordl0[2] | wordr0[2];
336     w0[3] = wordl0[3] | wordr0[3];
337     w1[0] = wordl1[0] | wordr1[0];
338     w1[1] = wordl1[1] | wordr1[1];
339     w1[2] = wordl1[2] | wordr1[2];
340     w1[3] = wordl1[3] | wordr1[3];
341     w2[0] = wordl2[0] | wordr2[0];
342     w2[1] = wordl2[1] | wordr2[1];
343     w2[2] = wordl2[2] | wordr2[2];
344     w2[3] = wordl2[3] | wordr2[3];
345     w3[0] = wordl3[0] | wordr3[0];
346     w3[1] = wordl3[1] | wordr3[1];
347     w3[2] = wordl3[2] | wordr3[2];
348     w3[3] = wordl3[3] | wordr3[3];
349
350     /**
351      * siphash
352      */
353
354     switch (pw_len / 8)
355     {
356       case 0: w0[1] |= pw_len << 24; break;
357       case 1: w0[3] |= pw_len << 24; break;
358       case 2: w1[1] |= pw_len << 24; break;
359       case 3: w1[3] |= pw_len << 24; break;
360     }
361
362     u64x v0 = v0p;
363     u64x v1 = v1p;
364     u64x v2 = v2p;
365     u64x v3 = v3p;
366
367     int i;
368     int j;
369
370     for (i = 0, j = 0; i <= pw_len && i < 16; i += 8, j += 2)
371     {
372       u64x m = hl32_to_64 (w0[j + 1], w0[j + 0]);
373
374       v3 ^= m;
375
376       SIPROUND (v0, v1, v2, v3);
377       SIPROUND (v0, v1, v2, v3);
378
379       v0 ^= m;
380     }
381
382     for (       j = 0; i <= pw_len && i < 32; i += 8, j += 2)
383     {
384       u64x m = hl32_to_64 (w1[j + 1], w1[j + 0]);
385
386       v3 ^= m;
387
388       SIPROUND (v0, v1, v2, v3);
389       SIPROUND (v0, v1, v2, v3);
390
391       v0 ^= m;
392     }
393
394     v2 ^= 0xff;
395
396     SIPROUND (v0, v1, v2, v3);
397     SIPROUND (v0, v1, v2, v3);
398     SIPROUND (v0, v1, v2, v3);
399     SIPROUND (v0, v1, v2, v3);
400
401     const u64x v = v0 ^ v1 ^ v2 ^ v3;
402
403     const u32x a = l32_from_64 (v);
404     const u32x b = h32_from_64 (v);
405
406     const u32x z = 0;
407
408     COMPARE_S_SIMD (a, b, z, z);
409   }
410 }
411
412 __kernel void m10100_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
413 {
414 }
415
416 __kernel void m10100_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_scryptV0_buf, __global u32 *d_scryptV1_buf, __global u32 *d_scryptV2_buf, __global u32 *d_scryptV3_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)
417 {
418 }