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