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