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