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