Cleanup -m 50xx kernels to latest standard - NOTE: broken on SIMD, compiler bug
[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 "include/constants.h"
11 #include "include/kernel_vendor.h"
12
13 #define DGST_R0 2
14 #define DGST_R1 3
15 #define DGST_R2 4
16 #define DGST_R3 5
17
18 #include "include/kernel_functions.c"
19 #include "OpenCL/types_ocl.c"
20 #include "OpenCL/common.c"
21 #include "include/rp_kernel.h"
22 #include "OpenCL/rp.c"
23 #include "OpenCL/simd.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 u8 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 u8 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 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 il_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   u32 pw_buf1[4];
105
106   pw_buf0[0] = pws[gid].i[0];
107   pw_buf0[1] = pws[gid].i[1];
108   pw_buf0[2] = pws[gid].i[2];
109   pw_buf0[3] = pws[gid].i[3];
110   pw_buf1[0] = pws[gid].i[4];
111   pw_buf1[1] = pws[gid].i[5];
112   pw_buf1[2] = pws[gid].i[6];
113   pw_buf1[3] = pws[gid].i[7];
114
115   const u32 pw_len = pws[gid].pw_len;
116
117   /**
118    * 0x80 keccak, very special
119    */
120
121   const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
122
123   const u32 rsiz = 200 - (2 * mdlen);
124
125   const u32 add80w = (rsiz - 1) / 8;
126
127   /**
128    * loop
129    */
130
131   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
132   {
133     u32x w0[4] = { 0 };
134     u32x w1[4] = { 0 };
135     u32x w2[4] = { 0 };
136     u32x w3[4] = { 0 };
137
138     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
139
140     append_0x01_2x4_VV (w0, w1, out_len);
141
142     /**
143      * Keccak
144      */
145
146     u64x st[25];
147
148     st[ 0] = hl32_to_64 (w0[1], w0[0]);
149     st[ 1] = hl32_to_64 (w0[3], w0[2]);
150     st[ 2] = hl32_to_64 (w1[1], w1[0]);
151     st[ 3] = hl32_to_64 (w1[3], w1[2]);
152     st[ 4] = 0;
153     st[ 5] = 0;
154     st[ 6] = 0;
155     st[ 7] = 0;
156     st[ 8] = 0;
157     st[ 9] = 0;
158     st[10] = 0;
159     st[11] = 0;
160     st[12] = 0;
161     st[13] = 0;
162     st[14] = 0;
163     st[15] = 0;
164     st[16] = 0;
165     st[17] = 0;
166     st[18] = 0;
167     st[19] = 0;
168     st[20] = 0;
169     st[21] = 0;
170     st[22] = 0;
171     st[23] = 0;
172     st[24] = 0;
173
174     st[add80w] |= 0x8000000000000000;
175
176     int round;
177
178     for (round = 0; round < KECCAK_ROUNDS; round++)
179     {
180       // Theta
181
182       u64x bc0 = Theta1 (0);
183       u64x bc1 = Theta1 (1);
184       u64x bc2 = Theta1 (2);
185       u64x bc3 = Theta1 (3);
186       u64x bc4 = Theta1 (4);
187
188       u64x t;
189
190       t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
191       t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
192       t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
193       t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
194       t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
195
196       // Rho Pi
197
198       t = st[1];
199
200       Rho_Pi (0);
201       Rho_Pi (1);
202       Rho_Pi (2);
203       Rho_Pi (3);
204       Rho_Pi (4);
205       Rho_Pi (5);
206       Rho_Pi (6);
207       Rho_Pi (7);
208       Rho_Pi (8);
209       Rho_Pi (9);
210       Rho_Pi (10);
211       Rho_Pi (11);
212       Rho_Pi (12);
213       Rho_Pi (13);
214       Rho_Pi (14);
215       Rho_Pi (15);
216       Rho_Pi (16);
217       Rho_Pi (17);
218       Rho_Pi (18);
219       Rho_Pi (19);
220       Rho_Pi (20);
221       Rho_Pi (21);
222       Rho_Pi (22);
223       Rho_Pi (23);
224
225       //  Chi
226
227       Chi (0);
228       Chi (5);
229       Chi (10);
230       Chi (15);
231       Chi (20);
232
233       //  Iota
234
235       st[0] ^= keccakf_rndc[round];
236     }
237
238     const u32x r0 = l32_from_64 (st[1]);
239     const u32x r1 = h32_from_64 (st[1]);
240     const u32x r2 = l32_from_64 (st[2]);
241     const u32x r3 = h32_from_64 (st[2]);
242
243     COMPARE_M_SIMD (r0, r1, r2, r3);
244   }
245 }
246
247 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
248 {
249 }
250
251 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
252 {
253 }
254
255 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
256 {
257   /**
258    * modifier
259    */
260
261   const u32 lid = get_local_id (0);
262
263   /**
264    * base
265    */
266
267   const u32 gid = get_global_id (0);
268
269   if (gid >= gid_max) return;
270
271   u32 pw_buf0[4];
272   u32 pw_buf1[4];
273
274   pw_buf0[0] = pws[gid].i[0];
275   pw_buf0[1] = pws[gid].i[1];
276   pw_buf0[2] = pws[gid].i[2];
277   pw_buf0[3] = pws[gid].i[3];
278   pw_buf1[0] = pws[gid].i[4];
279   pw_buf1[1] = pws[gid].i[5];
280   pw_buf1[2] = pws[gid].i[6];
281   pw_buf1[3] = pws[gid].i[7];
282
283   const u32 pw_len = pws[gid].pw_len;
284
285   /**
286    * 0x80 keccak, very special
287    */
288
289   const u32 mdlen = salt_bufs[salt_pos].keccak_mdlen;
290
291   const u32 rsiz = 200 - (2 * mdlen);
292
293   const u32 add80w = (rsiz - 1) / 8;
294
295   /**
296    * digest
297    */
298
299   const u32 search[4] =
300   {
301     digests_buf[digests_offset].digest_buf[DGST_R0],
302     digests_buf[digests_offset].digest_buf[DGST_R1],
303     digests_buf[digests_offset].digest_buf[DGST_R2],
304     digests_buf[digests_offset].digest_buf[DGST_R3]
305   };
306
307   /**
308    * loop
309    */
310
311   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
312   {
313     u32x w0[4] = { 0 };
314     u32x w1[4] = { 0 };
315     u32x w2[4] = { 0 };
316     u32x w3[4] = { 0 };
317
318     const u32x out_len = apply_rules_vect (pw_buf0, pw_buf1, pw_len, rules_buf, il_pos, w0, w1);
319
320     append_0x01_2x4_VV (w0, w1, out_len);
321
322     /**
323      * Keccak
324      */
325
326     u64x st[25];
327
328     st[ 0] = hl32_to_64 (w0[1], w0[0]);
329     st[ 1] = hl32_to_64 (w0[3], w0[2]);
330     st[ 2] = hl32_to_64 (w1[1], w1[0]);
331     st[ 3] = hl32_to_64 (w1[3], w1[2]);
332     st[ 4] = 0;
333     st[ 5] = 0;
334     st[ 6] = 0;
335     st[ 7] = 0;
336     st[ 8] = 0;
337     st[ 9] = 0;
338     st[10] = 0;
339     st[11] = 0;
340     st[12] = 0;
341     st[13] = 0;
342     st[14] = 0;
343     st[15] = 0;
344     st[16] = 0;
345     st[17] = 0;
346     st[18] = 0;
347     st[19] = 0;
348     st[20] = 0;
349     st[21] = 0;
350     st[22] = 0;
351     st[23] = 0;
352     st[24] = 0;
353
354     st[add80w] |= 0x8000000000000000;
355
356     int round;
357
358     for (round = 0; round < KECCAK_ROUNDS; round++)
359     {
360       // Theta
361
362       u64x bc0 = Theta1 (0);
363       u64x bc1 = Theta1 (1);
364       u64x bc2 = Theta1 (2);
365       u64x bc3 = Theta1 (3);
366       u64x bc4 = Theta1 (4);
367
368       u64x t;
369
370       t = bc4 ^ rotl64 (bc1, 1); Theta2 (0);
371       t = bc0 ^ rotl64 (bc2, 1); Theta2 (1);
372       t = bc1 ^ rotl64 (bc3, 1); Theta2 (2);
373       t = bc2 ^ rotl64 (bc4, 1); Theta2 (3);
374       t = bc3 ^ rotl64 (bc0, 1); Theta2 (4);
375
376       // Rho Pi
377
378       t = st[1];
379
380       Rho_Pi (0);
381       Rho_Pi (1);
382       Rho_Pi (2);
383       Rho_Pi (3);
384       Rho_Pi (4);
385       Rho_Pi (5);
386       Rho_Pi (6);
387       Rho_Pi (7);
388       Rho_Pi (8);
389       Rho_Pi (9);
390       Rho_Pi (10);
391       Rho_Pi (11);
392       Rho_Pi (12);
393       Rho_Pi (13);
394       Rho_Pi (14);
395       Rho_Pi (15);
396       Rho_Pi (16);
397       Rho_Pi (17);
398       Rho_Pi (18);
399       Rho_Pi (19);
400       Rho_Pi (20);
401       Rho_Pi (21);
402       Rho_Pi (22);
403       Rho_Pi (23);
404
405       //  Chi
406
407       Chi (0);
408       Chi (5);
409       Chi (10);
410       Chi (15);
411       Chi (20);
412
413       //  Iota
414
415       st[0] ^= keccakf_rndc[round];
416     }
417
418     const u32x r0 = l32_from_64 (st[1]);
419     const u32x r1 = h32_from_64 (st[1]);
420     const u32x r2 = l32_from_64 (st[2]);
421     const u32x r3 = h32_from_64 (st[2]);
422
423     COMPARE_S_SIMD (r0, r1, r2, r3);
424   }
425 }
426
427 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
428 {
429 }
430
431 __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 il_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
432 {
433 }