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