Fix m 60 a 0 by making modified variable non-const
[hashcat.git] / OpenCL / m05000_a0.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _KECCAK_
7
8 #define NEW_SIMD_CODE
9
10 #include "inc_vendor.cl"
11 #include "inc_hash_constants.h"
12 #include "inc_hash_functions.cl"
13 #include "inc_types.cl"
14 #include "inc_common.cl"
15 #include "inc_rp.h"
16 #include "inc_rp.cl"
17 #include "inc_simd.cl"
18
19 __constant u64 keccakf_rndc[24] =
20 {
21   0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
22   0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
23   0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
24   0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
25   0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
26   0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
27   0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
28   0x8000000000008080, 0x0000000080000001, 0x8000000080008008
29 };
30
31 #ifndef KECCAK_ROUNDS
32 #define KECCAK_ROUNDS 24
33 #endif
34
35 #define Theta1(s) (st[0 + s] ^ st[5 + s] ^ st[10 + s] ^ st[15 + s] ^ st[20 + s])
36
37 #define Theta2(s)               \
38 {                               \
39   st[ 0 + s] ^= t;              \
40   st[ 5 + s] ^= t;              \
41   st[10 + s] ^= t;              \
42   st[15 + s] ^= t;              \
43   st[20 + s] ^= t;              \
44 }
45
46 #define Rho_Pi(s)               \
47 {                               \
48   u32 j = keccakf_piln[s];      \
49   u32 k = keccakf_rotc[s];      \
50   bc0 = st[j];                  \
51   st[j] = rotl64 (t, k);        \
52   t = bc0;                      \
53 }
54
55 #define Chi(s)                  \
56 {                               \
57   bc0 = st[0 + s];              \
58   bc1 = st[1 + s];              \
59   bc2 = st[2 + s];              \
60   bc3 = st[3 + s];              \
61   bc4 = st[4 + s];              \
62   st[0 + s] ^= ~bc1 & bc2;      \
63   st[1 + s] ^= ~bc2 & bc3;      \
64   st[2 + s] ^= ~bc3 & bc4;      \
65   st[3 + s] ^= ~bc4 & bc0;      \
66   st[4 + s] ^= ~bc0 & bc1;      \
67 }
68
69 __kernel void m05000_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)
70 {
71   /**
72    * modifier
73    */
74
75   const u32 lid = get_local_id (0);
76
77   /**
78    * base
79    */
80
81   const u32 gid = get_global_id (0);
82
83   if (gid >= gid_max) return;
84
85   u32 pw_buf0[4];
86   u32 pw_buf1[4];
87
88   pw_buf0[0] = pws[gid].i[0];
89   pw_buf0[1] = pws[gid].i[1];
90   pw_buf0[2] = pws[gid].i[2];
91   pw_buf0[3] = pws[gid].i[3];
92   pw_buf1[0] = pws[gid].i[4];
93   pw_buf1[1] = pws[gid].i[5];
94   pw_buf1[2] = pws[gid].i[6];
95   pw_buf1[3] = pws[gid].i[7];
96
97   const u32 pw_len = pws[gid].pw_len;
98
99   /**
100    * constants
101    */
102
103   const u8 keccakf_rotc[24] =
104   {
105      1,  3,  6, 10, 15, 21, 28, 36, 45, 55,  2, 14,
106     27, 41, 56,  8, 25, 43, 62, 18, 39, 61, 20, 44
107   };
108
109   const u8 keccakf_piln[24] =
110   {
111     10,  7, 11, 17, 18,  3,  5, 16,  8, 21, 24,  4,
112     15, 23, 19, 13, 12,  2, 20, 14, 22,  9,  6,  1
113   };
114
115   /**
116    * 0x80 keccak, very special
117    */
118
119   const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
120
121   const u32 rsiz = 200 - (2 * mdlen);
122
123   const u32 add80w = (rsiz - 1) / 8;
124
125   /**
126    * loop
127    */
128
129   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
130   {
131     u32x w0[4] = { 0 };
132     u32x w1[4] = { 0 };
133     u32x w2[4] = { 0 };
134     u32x w3[4] = { 0 };
135
136     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
137
138     append_0x01_2x4_VV (w0, w1, out_len);
139
140     /**
141      * Keccak
142      */
143
144     u64x st[25];
145
146     st[ 0] = hl32_to_64 (w0[1], w0[0]);
147     st[ 1] = hl32_to_64 (w0[3], w0[2]);
148     st[ 2] = hl32_to_64 (w1[1], w1[0]);
149     st[ 3] = hl32_to_64 (w1[3], w1[2]);
150     st[ 4] = 0;
151     st[ 5] = 0;
152     st[ 6] = 0;
153     st[ 7] = 0;
154     st[ 8] = 0;
155     st[ 9] = 0;
156     st[10] = 0;
157     st[11] = 0;
158     st[12] = 0;
159     st[13] = 0;
160     st[14] = 0;
161     st[15] = 0;
162     st[16] = 0;
163     st[17] = 0;
164     st[18] = 0;
165     st[19] = 0;
166     st[20] = 0;
167     st[21] = 0;
168     st[22] = 0;
169     st[23] = 0;
170     st[24] = 0;
171
172     st[add80w] |= 0x8000000000000000;
173
174     int round;
175
176     for (round = 0; round < KECCAK_ROUNDS; round++)
177     {
178       // Theta
179
180       u64x bc0 = Theta1 (0);
181       u64x bc1 = Theta1 (1);
182       u64x bc2 = Theta1 (2);
183       u64x bc3 = Theta1 (3);
184       u64x bc4 = Theta1 (4);
185
186       u64x t;
187
188       t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
189       t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
190       t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
191       t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
192       t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
193
194       // Rho Pi
195
196       t = st[1];
197
198       Rho_Pi (0);
199       Rho_Pi (1);
200       Rho_Pi (2);
201       Rho_Pi (3);
202       Rho_Pi (4);
203       Rho_Pi (5);
204       Rho_Pi (6);
205       Rho_Pi (7);
206       Rho_Pi (8);
207       Rho_Pi (9);
208       Rho_Pi (10);
209       Rho_Pi (11);
210       Rho_Pi (12);
211       Rho_Pi (13);
212       Rho_Pi (14);
213       Rho_Pi (15);
214       Rho_Pi (16);
215       Rho_Pi (17);
216       Rho_Pi (18);
217       Rho_Pi (19);
218       Rho_Pi (20);
219       Rho_Pi (21);
220       Rho_Pi (22);
221       Rho_Pi (23);
222
223       //  Chi
224
225       Chi (0);
226       Chi (5);
227       Chi (10);
228       Chi (15);
229       Chi (20);
230
231       //  Iota
232
233       st[0] ^= keccakf_rndc[round];
234     }
235
236     const u32x r0 = l32_from_64 (st[1]);
237     const u32x r1 = h32_from_64 (st[1]);
238     const u32x r2 = l32_from_64 (st[2]);
239     const u32x r3 = h32_from_64 (st[2]);
240
241     COMPARE_M_SIMD (r0, r1, r2, r3);
242   }
243 }
244
245 __kernel void m05000_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)
246 {
247 }
248
249 __kernel void m05000_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)
250 {
251 }
252
253 __kernel void m05000_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)
254 {
255   /**
256    * modifier
257    */
258
259   const u32 lid = get_local_id (0);
260
261   /**
262    * base
263    */
264
265   const u32 gid = get_global_id (0);
266
267   if (gid >= gid_max) return;
268
269   u32 pw_buf0[4];
270   u32 pw_buf1[4];
271
272   pw_buf0[0] = pws[gid].i[0];
273   pw_buf0[1] = pws[gid].i[1];
274   pw_buf0[2] = pws[gid].i[2];
275   pw_buf0[3] = pws[gid].i[3];
276   pw_buf1[0] = pws[gid].i[4];
277   pw_buf1[1] = pws[gid].i[5];
278   pw_buf1[2] = pws[gid].i[6];
279   pw_buf1[3] = pws[gid].i[7];
280
281   const u32 pw_len = pws[gid].pw_len;
282
283   /**
284    * constants
285    */
286
287   const u8 keccakf_rotc[24] =
288   {
289      1,  3,  6, 10, 15, 21, 28, 36, 45, 55,  2, 14,
290     27, 41, 56,  8, 25, 43, 62, 18, 39, 61, 20, 44
291   };
292
293   const u8 keccakf_piln[24] =
294   {
295     10,  7, 11, 17, 18,  3,  5, 16,  8, 21, 24,  4,
296     15, 23, 19, 13, 12,  2, 20, 14, 22,  9,  6,  1
297   };
298
299   /**
300    * 0x80 keccak, very special
301    */
302
303   const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
304
305   const u32 rsiz = 200 - (2 * mdlen);
306
307   const u32 add80w = (rsiz - 1) / 8;
308
309   /**
310    * digest
311    */
312
313   const u32 search[4] =
314   {
315     digests_buf[digests_offset].digest_buf[DGST_R0],
316     digests_buf[digests_offset].digest_buf[DGST_R1],
317     digests_buf[digests_offset].digest_buf[DGST_R2],
318     digests_buf[digests_offset].digest_buf[DGST_R3]
319   };
320
321   /**
322    * loop
323    */
324
325   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
326   {
327     u32x w0[4] = { 0 };
328     u32x w1[4] = { 0 };
329     u32x w2[4] = { 0 };
330     u32x w3[4] = { 0 };
331
332     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
333
334     append_0x01_2x4_VV (w0, w1, out_len);
335
336     /**
337      * Keccak
338      */
339
340     u64x st[25];
341
342     st[ 0] = hl32_to_64 (w0[1], w0[0]);
343     st[ 1] = hl32_to_64 (w0[3], w0[2]);
344     st[ 2] = hl32_to_64 (w1[1], w1[0]);
345     st[ 3] = hl32_to_64 (w1[3], w1[2]);
346     st[ 4] = 0;
347     st[ 5] = 0;
348     st[ 6] = 0;
349     st[ 7] = 0;
350     st[ 8] = 0;
351     st[ 9] = 0;
352     st[10] = 0;
353     st[11] = 0;
354     st[12] = 0;
355     st[13] = 0;
356     st[14] = 0;
357     st[15] = 0;
358     st[16] = 0;
359     st[17] = 0;
360     st[18] = 0;
361     st[19] = 0;
362     st[20] = 0;
363     st[21] = 0;
364     st[22] = 0;
365     st[23] = 0;
366     st[24] = 0;
367
368     st[add80w] |= 0x8000000000000000;
369
370     int round;
371
372     for (round = 0; round < KECCAK_ROUNDS; round++)
373     {
374       // Theta
375
376       u64x bc0 = Theta1 (0);
377       u64x bc1 = Theta1 (1);
378       u64x bc2 = Theta1 (2);
379       u64x bc3 = Theta1 (3);
380       u64x bc4 = Theta1 (4);
381
382       u64x t;
383
384       t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
385       t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
386       t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
387       t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
388       t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
389
390       // Rho Pi
391
392       t = st[1];
393
394       Rho_Pi (0);
395       Rho_Pi (1);
396       Rho_Pi (2);
397       Rho_Pi (3);
398       Rho_Pi (4);
399       Rho_Pi (5);
400       Rho_Pi (6);
401       Rho_Pi (7);
402       Rho_Pi (8);
403       Rho_Pi (9);
404       Rho_Pi (10);
405       Rho_Pi (11);
406       Rho_Pi (12);
407       Rho_Pi (13);
408       Rho_Pi (14);
409       Rho_Pi (15);
410       Rho_Pi (16);
411       Rho_Pi (17);
412       Rho_Pi (18);
413       Rho_Pi (19);
414       Rho_Pi (20);
415       Rho_Pi (21);
416       Rho_Pi (22);
417       Rho_Pi (23);
418
419       //  Chi
420
421       Chi (0);
422       Chi (5);
423       Chi (10);
424       Chi (15);
425       Chi (20);
426
427       //  Iota
428
429       st[0] ^= keccakf_rndc[round];
430     }
431
432     const u32x r0 = l32_from_64 (st[1]);
433     const u32x r1 = h32_from_64 (st[1]);
434     const u32x r2 = l32_from_64 (st[2]);
435     const u32x r3 = h32_from_64 (st[2]);
436
437     COMPARE_S_SIMD (r0, r1, r2, r3);
438   }
439 }
440
441 __kernel void m05000_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)
442 {
443 }
444
445 __kernel void m05000_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)
446 {
447 }