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