Prepare for a more dynamic #pragma unroll use
[hashcat.git] / OpenCL / m08700_a3.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 #define NEW_SIMD_CODE
12
13 #include "include/constants.h"
14 #include "include/kernel_vendor.h"
15
16 #define DGST_R0 0
17 #define DGST_R1 1
18 #define DGST_R2 2
19 #define DGST_R3 3
20
21 #include "include/kernel_functions.c"
22 #include "OpenCL/types_ocl.c"
23 #include "OpenCL/common.c"
24 #include "OpenCL/simd.c"
25
26 __constant u32 lotus_magic_table[256] =
27 {
28   0xbd, 0x56, 0xea, 0xf2, 0xa2, 0xf1, 0xac, 0x2a,
29   0xb0, 0x93, 0xd1, 0x9c, 0x1b, 0x33, 0xfd, 0xd0,
30   0x30, 0x04, 0xb6, 0xdc, 0x7d, 0xdf, 0x32, 0x4b,
31   0xf7, 0xcb, 0x45, 0x9b, 0x31, 0xbb, 0x21, 0x5a,
32   0x41, 0x9f, 0xe1, 0xd9, 0x4a, 0x4d, 0x9e, 0xda,
33   0xa0, 0x68, 0x2c, 0xc3, 0x27, 0x5f, 0x80, 0x36,
34   0x3e, 0xee, 0xfb, 0x95, 0x1a, 0xfe, 0xce, 0xa8,
35   0x34, 0xa9, 0x13, 0xf0, 0xa6, 0x3f, 0xd8, 0x0c,
36   0x78, 0x24, 0xaf, 0x23, 0x52, 0xc1, 0x67, 0x17,
37   0xf5, 0x66, 0x90, 0xe7, 0xe8, 0x07, 0xb8, 0x60,
38   0x48, 0xe6, 0x1e, 0x53, 0xf3, 0x92, 0xa4, 0x72,
39   0x8c, 0x08, 0x15, 0x6e, 0x86, 0x00, 0x84, 0xfa,
40   0xf4, 0x7f, 0x8a, 0x42, 0x19, 0xf6, 0xdb, 0xcd,
41   0x14, 0x8d, 0x50, 0x12, 0xba, 0x3c, 0x06, 0x4e,
42   0xec, 0xb3, 0x35, 0x11, 0xa1, 0x88, 0x8e, 0x2b,
43   0x94, 0x99, 0xb7, 0x71, 0x74, 0xd3, 0xe4, 0xbf,
44   0x3a, 0xde, 0x96, 0x0e, 0xbc, 0x0a, 0xed, 0x77,
45   0xfc, 0x37, 0x6b, 0x03, 0x79, 0x89, 0x62, 0xc6,
46   0xd7, 0xc0, 0xd2, 0x7c, 0x6a, 0x8b, 0x22, 0xa3,
47   0x5b, 0x05, 0x5d, 0x02, 0x75, 0xd5, 0x61, 0xe3,
48   0x18, 0x8f, 0x55, 0x51, 0xad, 0x1f, 0x0b, 0x5e,
49   0x85, 0xe5, 0xc2, 0x57, 0x63, 0xca, 0x3d, 0x6c,
50   0xb4, 0xc5, 0xcc, 0x70, 0xb2, 0x91, 0x59, 0x0d,
51   0x47, 0x20, 0xc8, 0x4f, 0x58, 0xe0, 0x01, 0xe2,
52   0x16, 0x38, 0xc4, 0x6f, 0x3b, 0x0f, 0x65, 0x46,
53   0xbe, 0x7e, 0x2d, 0x7b, 0x82, 0xf9, 0x40, 0xb5,
54   0x1d, 0x73, 0xf8, 0xeb, 0x26, 0xc7, 0x87, 0x97,
55   0x25, 0x54, 0xb1, 0x28, 0xaa, 0x98, 0x9d, 0xa5,
56   0x64, 0x6d, 0x7a, 0xd4, 0x10, 0x81, 0x44, 0xef,
57   0x49, 0xd6, 0xae, 0x2e, 0xdd, 0x76, 0x5c, 0x2f,
58   0xa7, 0x1c, 0xc9, 0x09, 0x69, 0x9a, 0x83, 0xcf,
59   0x29, 0x39, 0xb9, 0xe9, 0x4c, 0xff, 0x43, 0xab,
60 };
61
62 #define BOX(S,i) (S)[(i)]
63
64 #if   VECT_SIZE == 1
65 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i)])
66 #elif VECT_SIZE == 2
67 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1])
68 #elif VECT_SIZE == 4
69 #define uint_to_hex_upper8(i) (u32x) (l_bin2asc[(i).s0], l_bin2asc[(i).s1], l_bin2asc[(i).s2], l_bin2asc[(i).s3])
70 #elif VECT_SIZE == 8
71 #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])
72 #elif VECT_SIZE == 16
73 #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])
74 #endif
75
76 #if   VECT_SIZE == 1
77 #define BOX1(S,i) (S)[(i)]
78 #elif VECT_SIZE == 2
79 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1])
80 #elif VECT_SIZE == 4
81 #define BOX1(S,i) (u32x) ((S)[(i).s0], (S)[(i).s1], (S)[(i).s2], (S)[(i).s3])
82 #elif VECT_SIZE == 8
83 #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])
84 #elif VECT_SIZE == 16
85 #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])
86 #endif
87
88 void lotus_mix (u32x *in, __local u32 *s_lotus_magic_table)
89 {
90   u32x p = 0;
91
92   for (int i = 0; i < 18; i++)
93   {
94     u32 s = 48;
95
96     #ifdef _unroll
97     #pragma unroll
98     #endif
99     for (int j = 0; j < 12; j++)
100     {
101       u32x tmp_in = in[j];
102       u32x tmp_out = 0;
103
104       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  0;
105       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  8;
106       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 16;
107       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 24;
108
109       in[j] = tmp_out;
110     }
111   }
112 }
113
114 void lotus_transform_password (u32x in[4], u32x out[4], __local u32 *s_lotus_magic_table)
115 {
116   u32x t = out[3] >> 24;
117
118   u32x c;
119
120   #ifdef _unroll
121   #pragma unroll
122   #endif
123   for (int i = 0; i < 4; i++)
124   {
125     t ^= (in[i] >>  0) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
126     t ^= (in[i] >>  8) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
127     t ^= (in[i] >> 16) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
128     t ^= (in[i] >> 24) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
129   }
130 }
131
132 void pad (u32 w[4], const u32 len)
133 {
134   const u32 val = 16 - len;
135
136   const u32 mask1 = val << 24;
137
138   const u32 mask2 = val << 16
139                    | val << 24;
140
141   const u32 mask3 = val <<  8
142                    | val << 16
143                    | val << 24;
144
145   const u32 mask4 = val <<  0
146                    | val <<  8
147                    | val << 16
148                    | val << 24;
149
150   switch (len)
151   {
152     case  0:  w[0]  = mask4;
153               w[1]  = mask4;
154               w[2]  = mask4;
155               w[3]  = mask4;
156               break;
157     case  1:  w[0] |= mask3;
158               w[1]  = mask4;
159               w[2]  = mask4;
160               w[3]  = mask4;
161               break;
162     case  2:  w[0] |= mask2;
163               w[1]  = mask4;
164               w[2]  = mask4;
165               w[3]  = mask4;
166               break;
167     case  3:  w[0] |= mask1;
168               w[1]  = mask4;
169               w[2]  = mask4;
170               w[3]  = mask4;
171               break;
172     case  4:  w[1]  = mask4;
173               w[2]  = mask4;
174               w[3]  = mask4;
175               break;
176     case  5:  w[1] |= mask3;
177               w[2]  = mask4;
178               w[3]  = mask4;
179               break;
180     case  6:  w[1] |= mask2;
181               w[2]  = mask4;
182               w[3]  = mask4;
183               break;
184     case  7:  w[1] |= mask1;
185               w[2]  = mask4;
186               w[3]  = mask4;
187               break;
188     case  8:  w[2]  = mask4;
189               w[3]  = mask4;
190               break;
191     case  9:  w[2] |= mask3;
192               w[3]  = mask4;
193               break;
194     case 10:  w[2] |= mask2;
195               w[3]  = mask4;
196               break;
197     case 11:  w[2] |= mask1;
198               w[3]  = mask4;
199               break;
200     case 12:  w[3]  = mask4;
201               break;
202     case 13:  w[3] |= mask3;
203               break;
204     case 14:  w[3] |= mask2;
205               break;
206     case 15:  w[3] |= mask1;
207               break;
208   }
209 }
210
211 void mdtransform_norecalc (u32x state[4], u32x block[4], __local u32 *s_lotus_magic_table)
212 {
213   u32x x[12];
214
215   x[ 0] = state[0];
216   x[ 1] = state[1];
217   x[ 2] = state[2];
218   x[ 3] = state[3];
219   x[ 4] = block[0];
220   x[ 5] = block[1];
221   x[ 6] = block[2];
222   x[ 7] = block[3];
223   x[ 8] = state[0] ^ block[0];
224   x[ 9] = state[1] ^ block[1];
225   x[10] = state[2] ^ block[2];
226   x[11] = state[3] ^ block[3];
227
228   lotus_mix (x, s_lotus_magic_table);
229
230   state[0] = x[0];
231   state[1] = x[1];
232   state[2] = x[2];
233   state[3] = x[3];
234 }
235
236 void mdtransform (u32x state[4], u32x checksum[4], u32x block[4], __local u32 *s_lotus_magic_table)
237 {
238   mdtransform_norecalc (state, block, s_lotus_magic_table);
239
240   lotus_transform_password (block, checksum, s_lotus_magic_table);
241 }
242
243 void domino_big_md (const u32x saved_key[16], const u32 size, u32x state[4], __local u32 *s_lotus_magic_table)
244 {
245   u32x checksum[4];
246
247   checksum[0] = 0;
248   checksum[1] = 0;
249   checksum[2] = 0;
250   checksum[3] = 0;
251
252   u32x block[4];
253
254   block[0] = 0;
255   block[1] = 0;
256   block[2] = 0;
257   block[3] = 0;
258
259   u32 curpos;
260   u32 idx;
261
262   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
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
272   block[0] = saved_key[idx + 0];
273   block[1] = saved_key[idx + 1];
274   block[2] = saved_key[idx + 2];
275   block[3] = saved_key[idx + 3];
276
277   mdtransform (state, checksum, block, s_lotus_magic_table);
278
279   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
280 }
281
282 void m08700m (__local u32 *s_lotus_magic_table, __local u32 *l_bin2asc, u32 w[16], const u32 pw_len, __global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
283 {
284   /**
285    * modifier
286    */
287
288   const u32 gid = get_global_id (0);
289   const u32 lid = get_local_id (0);
290
291   /**
292    * base
293    */
294
295   if (pw_len < 16)
296   {
297     pad (&w[ 0], pw_len & 0xf);
298   }
299   else if (pw_len < 32)
300   {
301     pad (&w[ 4], pw_len & 0xf);
302   }
303   else if (pw_len < 48)
304   {
305     pad (&w[ 8], pw_len & 0xf);
306   }
307   else if (pw_len < 64)
308   {
309     pad (&w[12], pw_len & 0xf);
310   }
311
312   /**
313    * salt
314    */
315
316   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
317   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
318
319   /**
320    * loop
321    */
322
323   u32 w0l = w[0];
324
325   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
326   {
327     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
328
329     const u32x w0 = w0l | w0r;
330
331     /**
332      * domino
333      */
334
335     u32x w_tmp[16];
336
337     w_tmp[ 0] = w0;
338     w_tmp[ 1] = w[ 1];
339     w_tmp[ 2] = w[ 2];
340     w_tmp[ 3] = w[ 3];
341     w_tmp[ 4] = w[ 4];
342     w_tmp[ 5] = w[ 5];
343     w_tmp[ 6] = w[ 6];
344     w_tmp[ 7] = w[ 7];
345     w_tmp[ 8] = w[ 8];
346     w_tmp[ 9] = w[ 9];
347     w_tmp[10] = w[10];
348     w_tmp[11] = w[11];
349     w_tmp[12] = w[12];
350     w_tmp[13] = w[13];
351     w_tmp[14] = w[14];
352     w_tmp[15] = w[15];
353
354     u32x state[4];
355
356     state[0] = 0;
357     state[1] = 0;
358     state[2] = 0;
359     state[3] = 0;
360
361     domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
362
363     const u32x w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
364                     | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
365     const u32x w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
366                     | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
367     const u32x w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
368                     | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
369     const u32x w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
370                     | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
371     const u32x w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
372                     | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
373     const u32x w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
374                     | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
375     const u32x w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
376                     | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
377     //const u32x w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
378     //                | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
379
380     const u32x pade = 0x0e0e0e0e;
381
382     w_tmp[ 0] = salt0;
383     w_tmp[ 1] = salt1      | w0_t << 16;
384     w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
385     w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
386     w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
387     w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
388     w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
389     w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
390     w_tmp[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
391     w_tmp[ 9] = pade;
392     w_tmp[10] = pade;
393     w_tmp[11] = pade;
394     w_tmp[12] = 0;
395     w_tmp[13] = 0;
396     w_tmp[14] = 0;
397     w_tmp[15] = 0;
398
399     state[0] = 0;
400     state[1] = 0;
401     state[2] = 0;
402     state[3] = 0;
403
404     domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
405
406     u32x a = state[0] & 0xffffffff;
407     u32x b = state[1] & 0xffffffff;
408     u32x c = state[2] & 0x000000ff;
409     u32x d = state[3] & 0x00000000;
410
411     COMPARE_M_SIMD (a, b, c, d);
412   }
413 }
414
415 void m08700s (__local u32 *s_lotus_magic_table, __local u32 *l_bin2asc, u32 w[16], const u32 pw_len, __global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
416 {
417   /**
418    * modifier
419    */
420
421   const u32 gid = get_global_id (0);
422   const u32 lid = get_local_id (0);
423
424   /**
425    * base
426    */
427
428   if (pw_len < 16)
429   {
430     pad (&w[ 0], pw_len & 0xf);
431   }
432   else if (pw_len < 32)
433   {
434     pad (&w[ 4], pw_len & 0xf);
435   }
436   else if (pw_len < 48)
437   {
438     pad (&w[ 8], pw_len & 0xf);
439   }
440   else if (pw_len < 64)
441   {
442     pad (&w[12], pw_len & 0xf);
443   }
444
445   /**
446    * salt
447    */
448
449   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
450   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
451
452   /**
453    * digest
454    */
455
456   const u32 search[4] =
457   {
458     digests_buf[digests_offset].digest_buf[DGST_R0],
459     digests_buf[digests_offset].digest_buf[DGST_R1],
460     digests_buf[digests_offset].digest_buf[DGST_R2],
461     digests_buf[digests_offset].digest_buf[DGST_R3]
462   };
463
464   /**
465    * loop
466    */
467
468   u32 w0l = w[0];
469
470   for (u32 il_pos = 0; il_pos < il_cnt; il_pos += VECT_SIZE)
471   {
472     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
473
474     const u32x w0 = w0l | w0r;
475
476     /**
477      * domino
478      */
479
480     u32x w_tmp[16];
481
482     w_tmp[ 0] = w0;
483     w_tmp[ 1] = w[ 1];
484     w_tmp[ 2] = w[ 2];
485     w_tmp[ 3] = w[ 3];
486     w_tmp[ 4] = w[ 4];
487     w_tmp[ 5] = w[ 5];
488     w_tmp[ 6] = w[ 6];
489     w_tmp[ 7] = w[ 7];
490     w_tmp[ 8] = w[ 8];
491     w_tmp[ 9] = w[ 9];
492     w_tmp[10] = w[10];
493     w_tmp[11] = w[11];
494     w_tmp[12] = w[12];
495     w_tmp[13] = w[13];
496     w_tmp[14] = w[14];
497     w_tmp[15] = w[15];
498
499     u32x state[4];
500
501     state[0] = 0;
502     state[1] = 0;
503     state[2] = 0;
504     state[3] = 0;
505
506     domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
507
508     const u32x w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
509                     | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
510     const u32x w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
511                     | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
512     const u32x w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
513                     | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
514     const u32x w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
515                     | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
516     const u32x w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
517                     | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
518     const u32x w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
519                     | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
520     const u32x w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
521                     | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
522     //const u32x w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
523     //                | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
524
525     const u32x pade = 0x0e0e0e0e;
526
527     w_tmp[ 0] = salt0;
528     w_tmp[ 1] = salt1      | w0_t << 16;
529     w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
530     w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
531     w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
532     w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
533     w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
534     w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
535     w_tmp[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
536     w_tmp[ 9] = pade;
537     w_tmp[10] = pade;
538     w_tmp[11] = pade;
539     w_tmp[12] = 0;
540     w_tmp[13] = 0;
541     w_tmp[14] = 0;
542     w_tmp[15] = 0;
543
544     state[0] = 0;
545     state[1] = 0;
546     state[2] = 0;
547     state[3] = 0;
548
549     domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
550
551     u32x a = state[0] & 0xffffffff;
552     u32x b = state[1] & 0xffffffff;
553     u32x c = state[2] & 0x000000ff;
554     u32x d = state[3] & 0x00000000;
555
556     COMPARE_S_SIMD (a, b, c, d);
557   }
558 }
559
560 __kernel void m08700_m04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
561 {
562   /**
563    * base
564    */
565
566   const u32 gid = get_global_id (0);
567   const u32 lid = get_local_id (0);
568   const u32 lsz = get_local_size (0);
569
570   /**
571    * sbox
572    */
573
574   __local u32 s_lotus_magic_table[256];
575
576   for (u32 i = lid; i < 256; i += lsz)
577   {
578     s_lotus_magic_table[i] = lotus_magic_table[i];
579   }
580
581   __local u32 l_bin2asc[256];
582
583   for (u32 i = lid; i < 256; i += lsz)
584   {
585     const u32 i0 = (i >> 0) & 15;
586     const u32 i1 = (i >> 4) & 15;
587
588     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
589                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
590   }
591
592   barrier (CLK_LOCAL_MEM_FENCE);
593
594   if (gid >= gid_max) return;
595
596   /**
597    * base
598    */
599
600   u32 w[16];
601
602   w[ 0] = pws[gid].i[ 0];
603   w[ 1] = pws[gid].i[ 1];
604   w[ 2] = pws[gid].i[ 2];
605   w[ 3] = pws[gid].i[ 3];
606   w[ 4] = 0;
607   w[ 5] = 0;
608   w[ 6] = 0;
609   w[ 7] = 0;
610   w[ 8] = 0;
611   w[ 9] = 0;
612   w[10] = 0;
613   w[11] = 0;
614   w[12] = 0;
615   w[13] = 0;
616   w[14] = 0;
617   w[15] = 0;
618
619   const u32 pw_len = pws[gid].pw_len;
620
621   /**
622    * main
623    */
624
625   m08700m (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
626 }
627
628 __kernel void m08700_m08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
629 {
630   /**
631    * base
632    */
633
634   const u32 gid = get_global_id (0);
635   const u32 lid = get_local_id (0);
636   const u32 lsz = get_local_size (0);
637
638   /**
639    * sbox
640    */
641
642   __local u32 s_lotus_magic_table[256];
643
644   for (u32 i = lid; i < 256; i += lsz)
645   {
646     s_lotus_magic_table[i] = lotus_magic_table[i];
647   }
648
649   __local u32 l_bin2asc[256];
650
651   for (u32 i = lid; i < 256; i += lsz)
652   {
653     const u32 i0 = (i >> 0) & 15;
654     const u32 i1 = (i >> 4) & 15;
655
656     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
657                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
658   }
659
660   barrier (CLK_LOCAL_MEM_FENCE);
661
662   if (gid >= gid_max) return;
663
664   /**
665    * base
666    */
667
668   u32 w[16];
669
670   w[ 0] = pws[gid].i[ 0];
671   w[ 1] = pws[gid].i[ 1];
672   w[ 2] = pws[gid].i[ 2];
673   w[ 3] = pws[gid].i[ 3];
674   w[ 4] = pws[gid].i[ 4];
675   w[ 5] = pws[gid].i[ 5];
676   w[ 6] = pws[gid].i[ 6];
677   w[ 7] = pws[gid].i[ 7];
678   w[ 8] = 0;
679   w[ 9] = 0;
680   w[10] = 0;
681   w[11] = 0;
682   w[12] = 0;
683   w[13] = 0;
684   w[14] = 0;
685   w[15] = 0;
686
687   const u32 pw_len = pws[gid].pw_len;
688
689   /**
690    * main
691    */
692
693   m08700m (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
694 }
695
696 __kernel void m08700_m16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
697 {
698   /**
699    * base
700    */
701
702   const u32 gid = get_global_id (0);
703   const u32 lid = get_local_id (0);
704   const u32 lsz = get_local_size (0);
705
706   /**
707    * sbox
708    */
709
710   __local u32 s_lotus_magic_table[256];
711
712   for (u32 i = lid; i < 256; i += lsz)
713   {
714     s_lotus_magic_table[i] = lotus_magic_table[i];
715   }
716
717   __local u32 l_bin2asc[256];
718
719   for (u32 i = lid; i < 256; i += lsz)
720   {
721     const u32 i0 = (i >> 0) & 15;
722     const u32 i1 = (i >> 4) & 15;
723
724     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
725                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
726   }
727
728   barrier (CLK_LOCAL_MEM_FENCE);
729
730   if (gid >= gid_max) return;
731
732   /**
733    * base
734    */
735
736   u32 w[16];
737
738   w[ 0] = pws[gid].i[ 0];
739   w[ 1] = pws[gid].i[ 1];
740   w[ 2] = pws[gid].i[ 2];
741   w[ 3] = pws[gid].i[ 3];
742   w[ 4] = pws[gid].i[ 4];
743   w[ 5] = pws[gid].i[ 5];
744   w[ 6] = pws[gid].i[ 6];
745   w[ 7] = pws[gid].i[ 7];
746   w[ 8] = pws[gid].i[ 8];
747   w[ 9] = pws[gid].i[ 9];
748   w[10] = pws[gid].i[10];
749   w[11] = pws[gid].i[11];
750   w[12] = pws[gid].i[12];
751   w[13] = pws[gid].i[13];
752   w[14] = pws[gid].i[14];
753   w[15] = pws[gid].i[15];
754
755   const u32 pw_len = pws[gid].pw_len;
756
757   /**
758    * main
759    */
760
761   m08700m (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
762 }
763
764 __kernel void m08700_s04 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
765 {
766   /**
767    * base
768    */
769
770   const u32 gid = get_global_id (0);
771   const u32 lid = get_local_id (0);
772   const u32 lsz = get_local_size (0);
773
774   /**
775    * sbox
776    */
777
778   __local u32 s_lotus_magic_table[256];
779
780   for (u32 i = lid; i < 256; i += lsz)
781   {
782     s_lotus_magic_table[i] = lotus_magic_table[i];
783   }
784
785   __local u32 l_bin2asc[256];
786
787   for (u32 i = lid; i < 256; i += lsz)
788   {
789     const u32 i0 = (i >> 0) & 15;
790     const u32 i1 = (i >> 4) & 15;
791
792     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
793                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
794   }
795
796   barrier (CLK_LOCAL_MEM_FENCE);
797
798   if (gid >= gid_max) return;
799
800   /**
801    * base
802    */
803
804   u32 w[16];
805
806   w[ 0] = pws[gid].i[ 0];
807   w[ 1] = pws[gid].i[ 1];
808   w[ 2] = pws[gid].i[ 2];
809   w[ 3] = pws[gid].i[ 3];
810   w[ 4] = 0;
811   w[ 5] = 0;
812   w[ 6] = 0;
813   w[ 7] = 0;
814   w[ 8] = 0;
815   w[ 9] = 0;
816   w[10] = 0;
817   w[11] = 0;
818   w[12] = 0;
819   w[13] = 0;
820   w[14] = 0;
821   w[15] = 0;
822
823   const u32 pw_len = pws[gid].pw_len;
824
825   /**
826    * main
827    */
828
829   m08700s (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
830 }
831
832 __kernel void m08700_s08 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
833 {
834   /**
835    * base
836    */
837
838   const u32 gid = get_global_id (0);
839   const u32 lid = get_local_id (0);
840   const u32 lsz = get_local_size (0);
841
842   /**
843    * sbox
844    */
845
846   __local u32 s_lotus_magic_table[256];
847
848   for (u32 i = lid; i < 256; i += lsz)
849   {
850     s_lotus_magic_table[i] = lotus_magic_table[i];
851   }
852
853   __local u32 l_bin2asc[256];
854
855   for (u32 i = lid; i < 256; i += lsz)
856   {
857     const u32 i0 = (i >> 0) & 15;
858     const u32 i1 = (i >> 4) & 15;
859
860     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
861                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
862   }
863
864   barrier (CLK_LOCAL_MEM_FENCE);
865
866   if (gid >= gid_max) return;
867
868   /**
869    * base
870    */
871
872   u32 w[16];
873
874   w[ 0] = pws[gid].i[ 0];
875   w[ 1] = pws[gid].i[ 1];
876   w[ 2] = pws[gid].i[ 2];
877   w[ 3] = pws[gid].i[ 3];
878   w[ 4] = pws[gid].i[ 4];
879   w[ 5] = pws[gid].i[ 5];
880   w[ 6] = pws[gid].i[ 6];
881   w[ 7] = pws[gid].i[ 7];
882   w[ 8] = 0;
883   w[ 9] = 0;
884   w[10] = 0;
885   w[11] = 0;
886   w[12] = 0;
887   w[13] = 0;
888   w[14] = 0;
889   w[15] = 0;
890
891   const u32 pw_len = pws[gid].pw_len;
892
893   /**
894    * main
895    */
896
897   m08700s (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
898 }
899
900 __kernel void m08700_s16 (__global pw_t *pws, __global kernel_rule_t *rules_buf, __global comb_t *combs_buf, __constant u32x * words_buf_r, __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)
901 {
902   /**
903    * base
904    */
905
906   const u32 gid = get_global_id (0);
907   const u32 lid = get_local_id (0);
908   const u32 lsz = get_local_size (0);
909
910   /**
911    * sbox
912    */
913
914   __local u32 s_lotus_magic_table[256];
915
916   for (u32 i = lid; i < 256; i += lsz)
917   {
918     s_lotus_magic_table[i] = lotus_magic_table[i];
919   }
920
921   __local u32 l_bin2asc[256];
922
923   for (u32 i = lid; i < 256; i += lsz)
924   {
925     const u32 i0 = (i >> 0) & 15;
926     const u32 i1 = (i >> 4) & 15;
927
928     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
929                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
930   }
931
932   barrier (CLK_LOCAL_MEM_FENCE);
933
934   if (gid >= gid_max) return;
935
936   /**
937    * base
938    */
939
940   u32 w[16];
941
942   w[ 0] = pws[gid].i[ 0];
943   w[ 1] = pws[gid].i[ 1];
944   w[ 2] = pws[gid].i[ 2];
945   w[ 3] = pws[gid].i[ 3];
946   w[ 4] = pws[gid].i[ 4];
947   w[ 5] = pws[gid].i[ 5];
948   w[ 6] = pws[gid].i[ 6];
949   w[ 7] = pws[gid].i[ 7];
950   w[ 8] = pws[gid].i[ 8];
951   w[ 9] = pws[gid].i[ 9];
952   w[10] = pws[gid].i[10];
953   w[11] = pws[gid].i[11];
954   w[12] = pws[gid].i[12];
955   w[13] = pws[gid].i[13];
956   w[14] = pws[gid].i[14];
957   w[15] = pws[gid].i[15];
958
959   const u32 pw_len = pws[gid].pw_len;
960
961   /**
962    * main
963    */
964
965   m08700s (s_lotus_magic_table, l_bin2asc, w, pw_len, pws, rules_buf, combs_buf, words_buf_r, tmps, hooks, bitmaps_buf_s1_a, bitmaps_buf_s1_b, bitmaps_buf_s1_c, bitmaps_buf_s1_d, bitmaps_buf_s2_a, bitmaps_buf_s2_b, bitmaps_buf_s2_c, bitmaps_buf_s2_d, plains_buf, digests_buf, hashes_shown, salt_bufs, esalt_bufs, d_return_buf, d_scryptV_buf, bitmap_mask, bitmap_shift1, bitmap_shift2, salt_pos, loop_pos, loop_cnt, il_cnt, digests_cnt, digests_offset);
966 }