- Dropped all vector code since new GPU's are all scalar, makes the code much easier
[hashcat.git] / OpenCL / m08700_a0.cl
1 /**
2  * Author......: Jens Steube <jens.steube@gmail.com>
3  * License.....: MIT
4  */
5
6 #define _LOTUS6_
7
8 #include "include/constants.h"
9 #include "include/kernel_vendor.h"
10
11 #define DGST_R0 0
12 #define DGST_R1 1
13 #define DGST_R2 2
14 #define DGST_R3 3
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 u32 lotus_magic_table[256] =
26 {
27   0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
28   0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
29   0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
30   0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
31   0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
32   0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
33   0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
34   0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
35   0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
36   0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
37   0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
38   0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
39   0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
40   0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
41   0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
42   0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
43   0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
44   0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
45   0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
46   0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
47   0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
48   0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
49   0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
50   0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
51   0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
52   0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
53   0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
54   0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
55   0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
56   0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
57   0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
58   0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab,
59 };
60
61 #ifdef VECT_SIZE1
62 #define BOX(S,i) (u32x) ((S)[(i)])
63 #endif
64
65 #ifdef VECT_SIZE2
66 #define BOX(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1])
67 #endif
68
69 #ifdef VECT_SIZE4
70 #define BOX(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3])
71 #endif
72
73 #ifdef VECT_SIZE1
74 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i)])
75 #endif
76
77 #ifdef VECT_SIZE2
78 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1])
79 #endif
80
81 #ifdef VECT_SIZE4
82 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3])
83 #endif
84
85 static void lotus_mix (u32 *in, __local u32 s_lotus_magic_table[256])
86 {
87   u32 p = 0;
88
89   for (int i = 0; i < 18; i++)
90   {
91     u32 s = 48;
92
93     #pragma unroll
94     for (int j = 0; j < 12; j++)
95     {
96       u32 tmp_in = in[j];
97       u32 tmp_out = 0;
98
99       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p <<  0;
100       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p <<  8;
101       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p << 16;
102       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX (s_lotus_magic_table, p); tmp_out |= p << 24;
103
104       in[j] = tmp_out;
105     }
106   }
107 }
108
109 static void lotus_transform_password (u32 *in, u32 *out, __local u32 s_lotus_magic_table[256])
110 {
111   u32 t = out[3] >> 24;
112
113   u32 c;
114
115   //#pragma unroll // kernel fails if used
116   for (int i = 0; i < 4; i++)
117   {
118     t ^= (in[i] >>  0) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
119     t ^= (in[i] >>  8) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
120     t ^= (in[i] >> 16) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
121     t ^= (in[i] >> 24) & 0xff; c = BOX (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
122   }
123 }
124
125 static void pad (u32 w[4], const u32 len)
126 {
127   const u32 val = 16 - len;
128
129   const u32 mask1 = val << 24;
130
131   const u32 mask2 = val << 16
132                    | val << 24;
133
134   const u32 mask3 = val <<  8
135                    | val << 16
136                    | val << 24;
137
138   const u32 mask4 = val <<  0
139                    | val <<  8
140                    | val << 16
141                    | val << 24;
142
143   switch (len)
144   {
145     case  0:  w[0]  = mask4;
146               w[1]  = mask4;
147               w[2]  = mask4;
148               w[3]  = mask4;
149               break;
150     case  1:  w[0] |= mask3;
151               w[1]  = mask4;
152               w[2]  = mask4;
153               w[3]  = mask4;
154               break;
155     case  2:  w[0] |= mask2;
156               w[1]  = mask4;
157               w[2]  = mask4;
158               w[3]  = mask4;
159               break;
160     case  3:  w[0] |= mask1;
161               w[1]  = mask4;
162               w[2]  = mask4;
163               w[3]  = mask4;
164               break;
165     case  4:  w[1]  = mask4;
166               w[2]  = mask4;
167               w[3]  = mask4;
168               break;
169     case  5:  w[1] |= mask3;
170               w[2]  = mask4;
171               w[3]  = mask4;
172               break;
173     case  6:  w[1] |= mask2;
174               w[2]  = mask4;
175               w[3]  = mask4;
176               break;
177     case  7:  w[1] |= mask1;
178               w[2]  = mask4;
179               w[3]  = mask4;
180               break;
181     case  8:  w[2]  = mask4;
182               w[3]  = mask4;
183               break;
184     case  9:  w[2] |= mask3;
185               w[3]  = mask4;
186               break;
187     case 10:  w[2] |= mask2;
188               w[3]  = mask4;
189               break;
190     case 11:  w[2] |= mask1;
191               w[3]  = mask4;
192               break;
193     case 12:  w[3]  = mask4;
194               break;
195     case 13:  w[3] |= mask3;
196               break;
197     case 14:  w[3] |= mask2;
198               break;
199     case 15:  w[3] |= mask1;
200               break;
201   }
202 }
203
204 static void mdtransform_norecalc (u32 state[4], u32 block[4], __local u32 s_lotus_magic_table[256])
205 {
206   u32 x[12];
207
208   x[ 0] = state[0];
209   x[ 1] = state[1];
210   x[ 2] = state[2];
211   x[ 3] = state[3];
212   x[ 4] = block[0];
213   x[ 5] = block[1];
214   x[ 6] = block[2];
215   x[ 7] = block[3];
216   x[ 8] = state[0] ^ block[0];
217   x[ 9] = state[1] ^ block[1];
218   x[10] = state[2] ^ block[2];
219   x[11] = state[3] ^ block[3];
220
221   lotus_mix (x, s_lotus_magic_table);
222
223   state[0] = x[0];
224   state[1] = x[1];
225   state[2] = x[2];
226   state[3] = x[3];
227 }
228
229 static void mdtransform (u32 state[4], u32 checksum[4], u32 block[4], __local u32 s_lotus_magic_table[256])
230 {
231   mdtransform_norecalc (state, block, s_lotus_magic_table);
232
233   lotus_transform_password (block, checksum, s_lotus_magic_table);
234 }
235
236 static void domino_big_md (const u32 saved_key[16], const u32 size, u32 state[4], __local u32 s_lotus_magic_table[256])
237 {
238   u32 checksum[4];
239
240   checksum[0] = 0;
241   checksum[1] = 0;
242   checksum[2] = 0;
243   checksum[3] = 0;
244
245   u32 block[4];
246
247   block[0] = 0;
248   block[1] = 0;
249   block[2] = 0;
250   block[3] = 0;
251
252   u32 curpos;
253   u32 idx;
254
255   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
256   {
257     block[0] = saved_key[idx + 0];
258     block[1] = saved_key[idx + 1];
259     block[2] = saved_key[idx + 2];
260     block[3] = saved_key[idx + 3];
261
262     mdtransform (state, checksum, block, s_lotus_magic_table);
263   }
264
265   block[0] = saved_key[idx + 0];
266   block[1] = saved_key[idx + 1];
267   block[2] = saved_key[idx + 2];
268   block[3] = saved_key[idx + 3];
269
270   mdtransform (state, checksum, block, s_lotus_magic_table);
271
272   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
273 }
274
275 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08700_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)
276 {
277   /**
278    * modifier
279    */
280
281   const u32 lid = get_local_id (0);
282
283   /**
284    * base
285    */
286
287   const u32 gid = get_global_id (0);
288
289   /**
290    * bin2asc table
291    */
292
293   __local u32 l_bin2asc[256];
294
295   const u32 lid4 = lid * 4;
296
297   const u32 lid40 = lid4 + 0;
298   const u32 lid41 = lid4 + 1;
299   const u32 lid42 = lid4 + 2;
300   const u32 lid43 = lid4 + 3;
301
302   const u32 v400 = (lid40 >> 0) & 15;
303   const u32 v401 = (lid40 >> 4) & 15;
304   const u32 v410 = (lid41 >> 0) & 15;
305   const u32 v411 = (lid41 >> 4) & 15;
306   const u32 v420 = (lid42 >> 0) & 15;
307   const u32 v421 = (lid42 >> 4) & 15;
308   const u32 v430 = (lid43 >> 0) & 15;
309   const u32 v431 = (lid43 >> 4) & 15;
310
311   l_bin2asc[lid40] = ((v400 < 10) ? '0' + v400 : 'A' - 10 + v400) << 8
312                    | ((v401 < 10) ? '0' + v401 : 'A' - 10 + v401) << 0;
313   l_bin2asc[lid41] = ((v410 < 10) ? '0' + v410 : 'A' - 10 + v410) << 8
314                    | ((v411 < 10) ? '0' + v411 : 'A' - 10 + v411) << 0;
315   l_bin2asc[lid42] = ((v420 < 10) ? '0' + v420 : 'A' - 10 + v420) << 8
316                    | ((v421 < 10) ? '0' + v421 : 'A' - 10 + v421) << 0;
317   l_bin2asc[lid43] = ((v430 < 10) ? '0' + v430 : 'A' - 10 + v430) << 8
318                    | ((v431 < 10) ? '0' + v431 : 'A' - 10 + v431) << 0;
319
320   barrier (CLK_LOCAL_MEM_FENCE);
321
322   /**
323    * sbox
324    */
325
326   __local u32 s_lotus_magic_table[256];
327
328   s_lotus_magic_table[lid4 + 0] = lotus_magic_table[lid4 + 0];
329   s_lotus_magic_table[lid4 + 1] = lotus_magic_table[lid4 + 1];
330   s_lotus_magic_table[lid4 + 2] = lotus_magic_table[lid4 + 2];
331   s_lotus_magic_table[lid4 + 3] = lotus_magic_table[lid4 + 3];
332
333   barrier (CLK_LOCAL_MEM_FENCE);
334
335   if (gid >= gid_max) return;
336
337   u32 pw_buf0[4];
338
339   pw_buf0[0] = pws[gid].i[ 0];
340   pw_buf0[1] = pws[gid].i[ 1];
341   pw_buf0[2] = pws[gid].i[ 2];
342   pw_buf0[3] = pws[gid].i[ 3];
343
344   u32 pw_buf1[4];
345
346   pw_buf1[0] = pws[gid].i[ 4];
347   pw_buf1[1] = pws[gid].i[ 5];
348   pw_buf1[2] = pws[gid].i[ 6];
349   pw_buf1[3] = pws[gid].i[ 7];
350
351   const u32 pw_len = pws[gid].pw_len;
352
353   /**
354    * salt
355    */
356
357   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
358   const u32 salt1 = salt_bufs[salt_pos].salt_buf[1] & 0xff | '(' << 8;
359
360   /**
361    * loop
362    */
363
364   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
365   {
366     u32 w0[4];
367
368     w0[0] = pw_buf0[0];
369     w0[1] = pw_buf0[1];
370     w0[2] = pw_buf0[2];
371     w0[3] = pw_buf0[3];
372
373     u32 w1[4];
374
375     w1[0] = pw_buf1[0];
376     w1[1] = pw_buf1[1];
377     w1[2] = pw_buf1[2];
378     w1[3] = pw_buf1[3];
379
380     u32 w2[4];
381
382     w2[0] = 0;
383     w2[1] = 0;
384     w2[2] = 0;
385     w2[3] = 0;
386
387     u32 w3[4];
388
389     w3[0] = 0;
390     w3[1] = 0;
391     w3[2] = 0;
392     w3[3] = 0;
393
394     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
395
396     u32 w[16];
397
398     w[ 0] = w0[0];
399     w[ 1] = w0[1];
400     w[ 2] = w0[2];
401     w[ 3] = w0[3];
402     w[ 4] = w1[0];
403     w[ 5] = w1[1];
404     w[ 6] = w1[2];
405     w[ 7] = w1[3];
406     w[ 8] = w2[0];
407     w[ 9] = w2[1];
408     w[10] = w2[2];
409     w[11] = w2[3];
410     w[12] = w3[0];
411     w[13] = w3[1];
412     w[14] = w3[2];
413     w[15] = w3[3];
414
415     u32 state[4];
416
417     state[0] = 0;
418     state[1] = 0;
419     state[2] = 0;
420     state[3] = 0;
421
422     /**
423      * padding
424      */
425
426     if (pw_len < 16)
427     {
428       pad (&w[ 0], pw_len & 0xf);
429     }
430     else if (pw_len < 32)
431     {
432       pad (&w[ 4], pw_len & 0xf);
433     }
434     else if (pw_len < 48)
435     {
436       pad (&w[ 8], pw_len & 0xf);
437     }
438     else if (pw_len < 64)
439     {
440       pad (&w[12], pw_len & 0xf);
441     }
442
443     domino_big_md (w, pw_len, state, s_lotus_magic_table);
444
445     const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
446                      | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
447     const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
448                      | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
449     const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
450                      | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
451     const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
452                      | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
453     const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
454                      | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
455     const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
456                      | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
457     const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
458                      | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
459     //const u32 w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
460     //                 | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
461
462     const u32 pade = 0x0e0e0e0e;
463
464     w[ 0] = salt0;
465     w[ 1] = salt1      | w0_t << 16;
466     w[ 2] = w0_t >> 16 | w1_t << 16;
467     w[ 3] = w1_t >> 16 | w2_t << 16;
468     w[ 4] = w2_t >> 16 | w3_t << 16;
469     w[ 5] = w3_t >> 16 | w4_t << 16;
470     w[ 6] = w4_t >> 16 | w5_t << 16;
471     w[ 7] = w5_t >> 16 | w6_t << 16;
472     w[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
473     w[ 9] = pade;
474     w[10] = pade;
475     w[11] = pade;
476     w[12] = 0;
477     w[13] = 0;
478     w[14] = 0;
479     w[15] = 0;
480
481     state[0] = 0;
482     state[1] = 0;
483     state[2] = 0;
484     state[3] = 0;
485
486     domino_big_md (w, 34, state, s_lotus_magic_table);
487
488     u32 a = state[0] & 0xffffffff;
489     u32 b = state[1] & 0xffffffff;
490     u32 c = state[2] & 0x000000ff;
491     u32 d = state[3] & 0x00000000;
492
493     const u32 r0 = a;
494     const u32 r1 = b;
495     const u32 r2 = c;
496     const u32 r3 = d;
497
498     #include COMPARE_M
499   }
500 }
501
502 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08700_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)
503 {
504 }
505
506 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08700_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)
507 {
508 }
509
510 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08700_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)
511 {
512   /**
513    * modifier
514    */
515
516   const u32 lid = get_local_id (0);
517
518   /**
519    * base
520    */
521
522   const u32 gid = get_global_id (0);
523
524   /**
525    * bin2asc table
526    */
527
528   __local u32 l_bin2asc[256];
529
530   const u32 lid4 = lid * 4;
531
532   const u32 lid40 = lid4 + 0;
533   const u32 lid41 = lid4 + 1;
534   const u32 lid42 = lid4 + 2;
535   const u32 lid43 = lid4 + 3;
536
537   const u32 v400 = (lid40 >> 0) & 15;
538   const u32 v401 = (lid40 >> 4) & 15;
539   const u32 v410 = (lid41 >> 0) & 15;
540   const u32 v411 = (lid41 >> 4) & 15;
541   const u32 v420 = (lid42 >> 0) & 15;
542   const u32 v421 = (lid42 >> 4) & 15;
543   const u32 v430 = (lid43 >> 0) & 15;
544   const u32 v431 = (lid43 >> 4) & 15;
545
546   l_bin2asc[lid40] = ((v400 < 10) ? '0' + v400 : 'A' - 10 + v400) << 8
547                    | ((v401 < 10) ? '0' + v401 : 'A' - 10 + v401) << 0;
548   l_bin2asc[lid41] = ((v410 < 10) ? '0' + v410 : 'A' - 10 + v410) << 8
549                    | ((v411 < 10) ? '0' + v411 : 'A' - 10 + v411) << 0;
550   l_bin2asc[lid42] = ((v420 < 10) ? '0' + v420 : 'A' - 10 + v420) << 8
551                    | ((v421 < 10) ? '0' + v421 : 'A' - 10 + v421) << 0;
552   l_bin2asc[lid43] = ((v430 < 10) ? '0' + v430 : 'A' - 10 + v430) << 8
553                    | ((v431 < 10) ? '0' + v431 : 'A' - 10 + v431) << 0;
554
555   barrier (CLK_LOCAL_MEM_FENCE);
556
557   /**
558    * sbox
559    */
560
561   __local u32 s_lotus_magic_table[256];
562
563   s_lotus_magic_table[lid4 + 0] = lotus_magic_table[lid4 + 0];
564   s_lotus_magic_table[lid4 + 1] = lotus_magic_table[lid4 + 1];
565   s_lotus_magic_table[lid4 + 2] = lotus_magic_table[lid4 + 2];
566   s_lotus_magic_table[lid4 + 3] = lotus_magic_table[lid4 + 3];
567
568   barrier (CLK_LOCAL_MEM_FENCE);
569
570   if (gid >= gid_max) return;
571
572   u32 pw_buf0[4];
573
574   pw_buf0[0] = pws[gid].i[ 0];
575   pw_buf0[1] = pws[gid].i[ 1];
576   pw_buf0[2] = pws[gid].i[ 2];
577   pw_buf0[3] = pws[gid].i[ 3];
578
579   u32 pw_buf1[4];
580
581   pw_buf1[0] = pws[gid].i[ 4];
582   pw_buf1[1] = pws[gid].i[ 5];
583   pw_buf1[2] = pws[gid].i[ 6];
584   pw_buf1[3] = pws[gid].i[ 7];
585
586   const u32 pw_len = pws[gid].pw_len;
587
588   /**
589    * salt
590    */
591
592   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
593   const u32 salt1 = salt_bufs[salt_pos].salt_buf[1] & 0xff | '(' << 8;
594
595   /**
596    * digest
597    */
598
599   const u32 search[4] =
600   {
601     digests_buf[digests_offset].digest_buf[DGST_R0],
602     digests_buf[digests_offset].digest_buf[DGST_R1],
603     digests_buf[digests_offset].digest_buf[DGST_R2],
604     digests_buf[digests_offset].digest_buf[DGST_R3]
605   };
606
607   /**
608    * loop
609    */
610
611   for (u32 il_pos = 0; il_pos < rules_cnt; il_pos++)
612   {
613     u32 w0[4];
614
615     w0[0] = pw_buf0[0];
616     w0[1] = pw_buf0[1];
617     w0[2] = pw_buf0[2];
618     w0[3] = pw_buf0[3];
619
620     u32 w1[4];
621
622     w1[0] = pw_buf1[0];
623     w1[1] = pw_buf1[1];
624     w1[2] = pw_buf1[2];
625     w1[3] = pw_buf1[3];
626
627     u32 w2[4];
628
629     w2[0] = 0;
630     w2[1] = 0;
631     w2[2] = 0;
632     w2[3] = 0;
633
634     u32 w3[4];
635
636     w3[0] = 0;
637     w3[1] = 0;
638     w3[2] = 0;
639     w3[3] = 0;
640
641     const u32 out_len = apply_rules (rules_buf[il_pos].cmds, w0, w1, pw_len);
642
643     u32 w[16];
644
645     w[ 0] = w0[0];
646     w[ 1] = w0[1];
647     w[ 2] = w0[2];
648     w[ 3] = w0[3];
649     w[ 4] = w1[0];
650     w[ 5] = w1[1];
651     w[ 6] = w1[2];
652     w[ 7] = w1[3];
653     w[ 8] = w2[0];
654     w[ 9] = w2[1];
655     w[10] = w2[2];
656     w[11] = w2[3];
657     w[12] = w3[0];
658     w[13] = w3[1];
659     w[14] = w3[2];
660     w[15] = w3[3];
661
662     u32 state[4];
663
664     state[0] = 0;
665     state[1] = 0;
666     state[2] = 0;
667     state[3] = 0;
668
669     /**
670      * padding
671      */
672
673     if (pw_len < 16)
674     {
675       pad (&w[ 0], pw_len & 0xf);
676     }
677     else if (pw_len < 32)
678     {
679       pad (&w[ 4], pw_len & 0xf);
680     }
681     else if (pw_len < 48)
682     {
683       pad (&w[ 8], pw_len & 0xf);
684     }
685     else if (pw_len < 64)
686     {
687       pad (&w[12], pw_len & 0xf);
688     }
689
690     domino_big_md (w, pw_len, state, s_lotus_magic_table);
691
692     const u32 w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
693                      | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
694     const u32 w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
695                      | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
696     const u32 w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
697                      | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
698     const u32 w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
699                      | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
700     const u32 w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
701                      | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
702     const u32 w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
703                      | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
704     const u32 w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
705                      | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
706     //const u32 w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
707     //                 | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
708
709     const u32 pade = 0x0e0e0e0e;
710
711     w[ 0] = salt0;
712     w[ 1] = salt1      | w0_t << 16;
713     w[ 2] = w0_t >> 16 | w1_t << 16;
714     w[ 3] = w1_t >> 16 | w2_t << 16;
715     w[ 4] = w2_t >> 16 | w3_t << 16;
716     w[ 5] = w3_t >> 16 | w4_t << 16;
717     w[ 6] = w4_t >> 16 | w5_t << 16;
718     w[ 7] = w5_t >> 16 | w6_t << 16;
719     w[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
720     w[ 9] = pade;
721     w[10] = pade;
722     w[11] = pade;
723     w[12] = 0;
724     w[13] = 0;
725     w[14] = 0;
726     w[15] = 0;
727
728     state[0] = 0;
729     state[1] = 0;
730     state[2] = 0;
731     state[3] = 0;
732
733     domino_big_md (w, 34, state, s_lotus_magic_table);
734
735     u32 a = state[0] & 0xffffffff;
736     u32 b = state[1] & 0xffffffff;
737     u32 c = state[2] & 0x000000ff;
738     u32 d = state[3] & 0x00000000;
739
740     const u32 r0 = a;
741     const u32 r1 = b;
742     const u32 r2 = c;
743     const u32 r3 = d;
744
745     #include COMPARE_S
746   }
747 }
748
749 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08700_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)
750 {
751 }
752
753 __kernel void __attribute__((reqd_work_group_size (64, 1, 1))) m08700_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)
754 {
755 }