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