Merge pull request #230 from magnumripper/master
[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 static 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     #pragma unroll 12
97     for (int j = 0; j < 12; j++)
98     {
99       u32x tmp_in = in[j];
100       u32x tmp_out = 0;
101
102       p = (p + s--) & 0xff; p = ((tmp_in >>  0) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  0;
103       p = (p + s--) & 0xff; p = ((tmp_in >>  8) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p <<  8;
104       p = (p + s--) & 0xff; p = ((tmp_in >> 16) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 16;
105       p = (p + s--) & 0xff; p = ((tmp_in >> 24) & 0xff) ^ BOX1 (s_lotus_magic_table, p); tmp_out |= p << 24;
106
107       in[j] = tmp_out;
108     }
109   }
110 }
111
112 static void lotus_transform_password (u32x in[4], u32x out[4], __local u32 *s_lotus_magic_table)
113 {
114   u32x t = out[3] >> 24;
115
116   u32x c;
117
118   #pragma unroll 4
119   for (int i = 0; i < 4; i++)
120   {
121     t ^= (in[i] >>  0) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  0; t = ((out[i] >>  0) & 0xff);
122     t ^= (in[i] >>  8) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c <<  8; t = ((out[i] >>  8) & 0xff);
123     t ^= (in[i] >> 16) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 16; t = ((out[i] >> 16) & 0xff);
124     t ^= (in[i] >> 24) & 0xff; c = BOX1 (s_lotus_magic_table, t); out[i] ^= c << 24; t = ((out[i] >> 24) & 0xff);
125   }
126 }
127
128 static void pad (u32 w[4], const u32 len)
129 {
130   const u32 val = 16 - len;
131
132   const u32 mask1 = val << 24;
133
134   const u32 mask2 = val << 16
135                    | val << 24;
136
137   const u32 mask3 = val <<  8
138                    | val << 16
139                    | val << 24;
140
141   const u32 mask4 = val <<  0
142                    | val <<  8
143                    | val << 16
144                    | val << 24;
145
146   switch (len)
147   {
148     case  0:  w[0]  = mask4;
149               w[1]  = mask4;
150               w[2]  = mask4;
151               w[3]  = mask4;
152               break;
153     case  1:  w[0] |= mask3;
154               w[1]  = mask4;
155               w[2]  = mask4;
156               w[3]  = mask4;
157               break;
158     case  2:  w[0] |= mask2;
159               w[1]  = mask4;
160               w[2]  = mask4;
161               w[3]  = mask4;
162               break;
163     case  3:  w[0] |= mask1;
164               w[1]  = mask4;
165               w[2]  = mask4;
166               w[3]  = mask4;
167               break;
168     case  4:  w[1]  = mask4;
169               w[2]  = mask4;
170               w[3]  = mask4;
171               break;
172     case  5:  w[1] |= mask3;
173               w[2]  = mask4;
174               w[3]  = mask4;
175               break;
176     case  6:  w[1] |= mask2;
177               w[2]  = mask4;
178               w[3]  = mask4;
179               break;
180     case  7:  w[1] |= mask1;
181               w[2]  = mask4;
182               w[3]  = mask4;
183               break;
184     case  8:  w[2]  = mask4;
185               w[3]  = mask4;
186               break;
187     case  9:  w[2] |= mask3;
188               w[3]  = mask4;
189               break;
190     case 10:  w[2] |= mask2;
191               w[3]  = mask4;
192               break;
193     case 11:  w[2] |= mask1;
194               w[3]  = mask4;
195               break;
196     case 12:  w[3]  = mask4;
197               break;
198     case 13:  w[3] |= mask3;
199               break;
200     case 14:  w[3] |= mask2;
201               break;
202     case 15:  w[3] |= mask1;
203               break;
204   }
205 }
206
207 static void mdtransform_norecalc (u32x state[4], u32x block[4], __local u32 *s_lotus_magic_table)
208 {
209   u32x x[12];
210
211   x[ 0] = state[0];
212   x[ 1] = state[1];
213   x[ 2] = state[2];
214   x[ 3] = state[3];
215   x[ 4] = block[0];
216   x[ 5] = block[1];
217   x[ 6] = block[2];
218   x[ 7] = block[3];
219   x[ 8] = state[0] ^ block[0];
220   x[ 9] = state[1] ^ block[1];
221   x[10] = state[2] ^ block[2];
222   x[11] = state[3] ^ block[3];
223
224   lotus_mix (x, s_lotus_magic_table);
225
226   state[0] = x[0];
227   state[1] = x[1];
228   state[2] = x[2];
229   state[3] = x[3];
230 }
231
232 static void mdtransform (u32x state[4], u32x checksum[4], u32x block[4], __local u32 *s_lotus_magic_table)
233 {
234   mdtransform_norecalc (state, block, s_lotus_magic_table);
235
236   lotus_transform_password (block, checksum, s_lotus_magic_table);
237 }
238
239 static void domino_big_md (const u32x saved_key[16], const u32 size, u32x state[4], __local u32 *s_lotus_magic_table)
240 {
241   u32x checksum[4];
242
243   checksum[0] = 0;
244   checksum[1] = 0;
245   checksum[2] = 0;
246   checksum[3] = 0;
247
248   u32x block[4];
249
250   block[0] = 0;
251   block[1] = 0;
252   block[2] = 0;
253   block[3] = 0;
254
255   u32 curpos;
256   u32 idx;
257
258   for (curpos = 0, idx = 0; curpos + 16 < size; curpos += 16, idx += 4)
259   {
260     block[0] = saved_key[idx + 0];
261     block[1] = saved_key[idx + 1];
262     block[2] = saved_key[idx + 2];
263     block[3] = saved_key[idx + 3];
264
265     mdtransform (state, checksum, block, s_lotus_magic_table);
266   }
267
268   block[0] = saved_key[idx + 0];
269   block[1] = saved_key[idx + 1];
270   block[2] = saved_key[idx + 2];
271   block[3] = saved_key[idx + 3];
272
273   mdtransform (state, checksum, block, s_lotus_magic_table);
274
275   mdtransform_norecalc (state, checksum, s_lotus_magic_table);
276 }
277
278 static 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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset)
279 {
280   /**
281    * modifier
282    */
283
284   const u32 gid = get_global_id (0);
285   const u32 lid = get_local_id (0);
286
287   /**
288    * padding
289    */
290
291   if (pw_len < 16)
292   {
293     pad (&w[ 0], pw_len & 0xf);
294   }
295   else if (pw_len < 32)
296   {
297     pad (&w[ 4], pw_len & 0xf);
298   }
299   else if (pw_len < 48)
300   {
301     pad (&w[ 8], pw_len & 0xf);
302   }
303   else if (pw_len < 64)
304   {
305     pad (&w[12], pw_len & 0xf);
306   }
307
308   /**
309    * salt
310    */
311
312   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
313   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
314
315   /**
316    * loop
317    */
318
319   u32 w0l = w[0];
320
321   for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos += VECT_SIZE)
322   {
323     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
324
325     const u32x w0 = w0l | w0r;
326
327     u32x w_tmp[16];
328
329     w_tmp[ 0] = w0;
330     w_tmp[ 1] = w[ 1];
331     w_tmp[ 2] = w[ 2];
332     w_tmp[ 3] = w[ 3];
333     w_tmp[ 4] = w[ 4];
334     w_tmp[ 5] = w[ 5];
335     w_tmp[ 6] = w[ 6];
336     w_tmp[ 7] = w[ 7];
337     w_tmp[ 8] = w[ 8];
338     w_tmp[ 9] = w[ 9];
339     w_tmp[10] = w[10];
340     w_tmp[11] = w[11];
341     w_tmp[12] = w[12];
342     w_tmp[13] = w[13];
343     w_tmp[14] = w[14];
344     w_tmp[15] = w[15];
345
346     u32x state[4];
347
348     state[0] = 0;
349     state[1] = 0;
350     state[2] = 0;
351     state[3] = 0;
352
353     domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
354
355     const u32x w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
356                     | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
357     const u32x w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
358                     | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
359     const u32x w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
360                     | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
361     const u32x w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
362                     | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
363     const u32x w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
364                     | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
365     const u32x w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
366                     | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
367     const u32x w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
368                     | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
369     //const u32x w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
370     //                | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
371
372     const u32x pade = 0x0e0e0e0e;
373
374     w_tmp[ 0] = salt0;
375     w_tmp[ 1] = salt1      | w0_t << 16;
376     w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
377     w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
378     w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
379     w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
380     w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
381     w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
382     w_tmp[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
383     w_tmp[ 9] = pade;
384     w_tmp[10] = pade;
385     w_tmp[11] = pade;
386     w_tmp[12] = 0;
387     w_tmp[13] = 0;
388     w_tmp[14] = 0;
389     w_tmp[15] = 0;
390
391     state[0] = 0;
392     state[1] = 0;
393     state[2] = 0;
394     state[3] = 0;
395
396     domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
397
398     u32x a = state[0] & 0xffffffff;
399     u32x b = state[1] & 0xffffffff;
400     u32x c = state[2] & 0x000000ff;
401     u32x d = state[3] & 0x00000000;
402
403     COMPARE_M_SIMD (a, b, c, d);
404   }
405 }
406
407 static 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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset)
408 {
409   /**
410    * modifier
411    */
412
413   const u32 gid = get_global_id (0);
414   const u32 lid = get_local_id (0);
415
416   /**
417    * base
418    */
419
420   if (pw_len < 16)
421   {
422     pad (&w[ 0], pw_len & 0xf);
423   }
424   else if (pw_len < 32)
425   {
426     pad (&w[ 4], pw_len & 0xf);
427   }
428   else if (pw_len < 48)
429   {
430     pad (&w[ 8], pw_len & 0xf);
431   }
432   else if (pw_len < 64)
433   {
434     pad (&w[12], pw_len & 0xf);
435   }
436
437   /**
438    * salt
439    */
440
441   const u32 salt0 = salt_bufs[salt_pos].salt_buf[0];
442   const u32 salt1 = (salt_bufs[salt_pos].salt_buf[1] & 0xff) | '(' << 8;
443
444   /**
445    * digest
446    */
447
448   const u32 search[4] =
449   {
450     digests_buf[digests_offset].digest_buf[DGST_R0],
451     digests_buf[digests_offset].digest_buf[DGST_R1],
452     digests_buf[digests_offset].digest_buf[DGST_R2],
453     digests_buf[digests_offset].digest_buf[DGST_R3]
454   };
455
456   /**
457    * loop
458    */
459
460   u32 w0l = w[0];
461
462   for (u32 il_pos = 0; il_pos < bfs_cnt; il_pos += VECT_SIZE)
463   {
464     const u32x w0r = words_buf_r[il_pos / VECT_SIZE];
465
466     const u32x w0 = w0l | w0r;
467
468     u32x w_tmp[16];
469
470     w_tmp[ 0] = w0;
471     w_tmp[ 1] = w[ 1];
472     w_tmp[ 2] = w[ 2];
473     w_tmp[ 3] = w[ 3];
474     w_tmp[ 4] = w[ 4];
475     w_tmp[ 5] = w[ 5];
476     w_tmp[ 6] = w[ 6];
477     w_tmp[ 7] = w[ 7];
478     w_tmp[ 8] = w[ 8];
479     w_tmp[ 9] = w[ 9];
480     w_tmp[10] = w[10];
481     w_tmp[11] = w[11];
482     w_tmp[12] = w[12];
483     w_tmp[13] = w[13];
484     w_tmp[14] = w[14];
485     w_tmp[15] = w[15];
486
487     u32x state[4];
488
489     state[0] = 0;
490     state[1] = 0;
491     state[2] = 0;
492     state[3] = 0;
493
494     domino_big_md (w_tmp, pw_len, state, s_lotus_magic_table);
495
496     const u32x w0_t = uint_to_hex_upper8 ((state[0] >>  0) & 255) <<  0
497                     | uint_to_hex_upper8 ((state[0] >>  8) & 255) << 16;
498     const u32x w1_t = uint_to_hex_upper8 ((state[0] >> 16) & 255) <<  0
499                     | uint_to_hex_upper8 ((state[0] >> 24) & 255) << 16;
500     const u32x w2_t = uint_to_hex_upper8 ((state[1] >>  0) & 255) <<  0
501                     | uint_to_hex_upper8 ((state[1] >>  8) & 255) << 16;
502     const u32x w3_t = uint_to_hex_upper8 ((state[1] >> 16) & 255) <<  0
503                     | uint_to_hex_upper8 ((state[1] >> 24) & 255) << 16;
504     const u32x w4_t = uint_to_hex_upper8 ((state[2] >>  0) & 255) <<  0
505                     | uint_to_hex_upper8 ((state[2] >>  8) & 255) << 16;
506     const u32x w5_t = uint_to_hex_upper8 ((state[2] >> 16) & 255) <<  0
507                     | uint_to_hex_upper8 ((state[2] >> 24) & 255) << 16;
508     const u32x w6_t = uint_to_hex_upper8 ((state[3] >>  0) & 255) <<  0
509                     | uint_to_hex_upper8 ((state[3] >>  8) & 255) << 16;
510     //const u32x w7_t = uint_to_hex_upper8 ((state[3] >> 16) & 255) <<  0
511     //                | uint_to_hex_upper8 ((state[3] >> 24) & 255) << 16;
512
513     const u32x pade = 0x0e0e0e0e;
514
515     w_tmp[ 0] = salt0;
516     w_tmp[ 1] = salt1      | w0_t << 16;
517     w_tmp[ 2] = w0_t >> 16 | w1_t << 16;
518     w_tmp[ 3] = w1_t >> 16 | w2_t << 16;
519     w_tmp[ 4] = w2_t >> 16 | w3_t << 16;
520     w_tmp[ 5] = w3_t >> 16 | w4_t << 16;
521     w_tmp[ 6] = w4_t >> 16 | w5_t << 16;
522     w_tmp[ 7] = w5_t >> 16 | w6_t << 16;
523     w_tmp[ 8] = w6_t >> 16 | pade << 16; // | w7_t <<  8;
524     w_tmp[ 9] = pade;
525     w_tmp[10] = pade;
526     w_tmp[11] = pade;
527     w_tmp[12] = 0;
528     w_tmp[13] = 0;
529     w_tmp[14] = 0;
530     w_tmp[15] = 0;
531
532     state[0] = 0;
533     state[1] = 0;
534     state[2] = 0;
535     state[3] = 0;
536
537     domino_big_md (w_tmp, 34, state, s_lotus_magic_table);
538
539     u32x a = state[0] & 0xffffffff;
540     u32x b = state[1] & 0xffffffff;
541     u32x c = state[2] & 0x000000ff;
542     u32x d = state[3] & 0x00000000;
543
544     COMPARE_S_SIMD (a, b, c, d);
545   }
546 }
547
548 __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
549 {
550   /**
551    * base
552    */
553
554   const u32 gid = get_global_id (0);
555   const u32 lid = get_local_id (0);
556   const u32 lsz = get_local_size (0);
557
558   /**
559    * sbox
560    */
561
562   __local u32 s_lotus_magic_table[256];
563
564   for (u32 i = lid; i < 256; i += lsz)
565   {
566     s_lotus_magic_table[i] = lotus_magic_table[i];
567   }
568
569   __local u32 l_bin2asc[256];
570
571   for (u32 i = lid; i < 256; i += lsz)
572   {
573     const u32 i0 = (i >> 0) & 15;
574     const u32 i1 = (i >> 4) & 15;
575
576     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
577                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
578   }
579
580   barrier (CLK_LOCAL_MEM_FENCE);
581
582   if (gid >= gid_max) return;
583
584   /**
585    * base
586    */
587
588   u32 w[16];
589
590   w[ 0] = pws[gid].i[ 0];
591   w[ 1] = pws[gid].i[ 1];
592   w[ 2] = pws[gid].i[ 2];
593   w[ 3] = pws[gid].i[ 3];
594   w[ 4] = 0;
595   w[ 5] = 0;
596   w[ 6] = 0;
597   w[ 7] = 0;
598   w[ 8] = 0;
599   w[ 9] = 0;
600   w[10] = 0;
601   w[11] = 0;
602   w[12] = 0;
603   w[13] = 0;
604   w[14] = 0;
605   w[15] = 0;
606
607   const u32 pw_len = pws[gid].pw_len;
608
609   /**
610    * main
611    */
612
613   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, bfs_cnt, digests_cnt, digests_offset);
614 }
615
616 __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
617 {
618   /**
619    * base
620    */
621
622   const u32 gid = get_global_id (0);
623   const u32 lid = get_local_id (0);
624   const u32 lsz = get_local_size (0);
625
626   /**
627    * sbox
628    */
629
630   __local u32 s_lotus_magic_table[256];
631
632   for (u32 i = lid; i < 256; i += lsz)
633   {
634     s_lotus_magic_table[i] = lotus_magic_table[i];
635   }
636
637   __local u32 l_bin2asc[256];
638
639   for (u32 i = lid; i < 256; i += lsz)
640   {
641     const u32 i0 = (i >> 0) & 15;
642     const u32 i1 = (i >> 4) & 15;
643
644     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
645                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
646   }
647
648   barrier (CLK_LOCAL_MEM_FENCE);
649
650   if (gid >= gid_max) return;
651
652   /**
653    * base
654    */
655
656   u32 w[16];
657
658   w[ 0] = pws[gid].i[ 0];
659   w[ 1] = pws[gid].i[ 1];
660   w[ 2] = pws[gid].i[ 2];
661   w[ 3] = pws[gid].i[ 3];
662   w[ 4] = pws[gid].i[ 4];
663   w[ 5] = pws[gid].i[ 5];
664   w[ 6] = pws[gid].i[ 6];
665   w[ 7] = pws[gid].i[ 7];
666   w[ 8] = 0;
667   w[ 9] = 0;
668   w[10] = 0;
669   w[11] = 0;
670   w[12] = 0;
671   w[13] = 0;
672   w[14] = 0;
673   w[15] = 0;
674
675   const u32 pw_len = pws[gid].pw_len;
676
677   /**
678    * main
679    */
680
681   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, bfs_cnt, digests_cnt, digests_offset);
682 }
683
684 __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
685 {
686   /**
687    * base
688    */
689
690   const u32 gid = get_global_id (0);
691   const u32 lid = get_local_id (0);
692   const u32 lsz = get_local_size (0);
693
694   /**
695    * sbox
696    */
697
698   __local u32 s_lotus_magic_table[256];
699
700   for (u32 i = lid; i < 256; i += lsz)
701   {
702     s_lotus_magic_table[i] = lotus_magic_table[i];
703   }
704
705   __local u32 l_bin2asc[256];
706
707   for (u32 i = lid; i < 256; i += lsz)
708   {
709     const u32 i0 = (i >> 0) & 15;
710     const u32 i1 = (i >> 4) & 15;
711
712     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
713                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
714   }
715
716   barrier (CLK_LOCAL_MEM_FENCE);
717
718   if (gid >= gid_max) return;
719
720   /**
721    * base
722    */
723
724   u32 w[16];
725
726   w[ 0] = pws[gid].i[ 0];
727   w[ 1] = pws[gid].i[ 1];
728   w[ 2] = pws[gid].i[ 2];
729   w[ 3] = pws[gid].i[ 3];
730   w[ 4] = pws[gid].i[ 4];
731   w[ 5] = pws[gid].i[ 5];
732   w[ 6] = pws[gid].i[ 6];
733   w[ 7] = pws[gid].i[ 7];
734   w[ 8] = pws[gid].i[ 8];
735   w[ 9] = pws[gid].i[ 9];
736   w[10] = pws[gid].i[10];
737   w[11] = pws[gid].i[11];
738   w[12] = pws[gid].i[12];
739   w[13] = pws[gid].i[13];
740   w[14] = pws[gid].i[14];
741   w[15] = pws[gid].i[15];
742
743   const u32 pw_len = pws[gid].pw_len;
744
745   /**
746    * main
747    */
748
749   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, bfs_cnt, digests_cnt, digests_offset);
750 }
751
752 __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
753 {
754   /**
755    * base
756    */
757
758   const u32 gid = get_global_id (0);
759   const u32 lid = get_local_id (0);
760   const u32 lsz = get_local_size (0);
761
762   /**
763    * sbox
764    */
765
766   __local u32 s_lotus_magic_table[256];
767
768   for (u32 i = lid; i < 256; i += lsz)
769   {
770     s_lotus_magic_table[i] = lotus_magic_table[i];
771   }
772
773   __local u32 l_bin2asc[256];
774
775   for (u32 i = lid; i < 256; i += lsz)
776   {
777     const u32 i0 = (i >> 0) & 15;
778     const u32 i1 = (i >> 4) & 15;
779
780     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
781                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
782   }
783
784   barrier (CLK_LOCAL_MEM_FENCE);
785
786   if (gid >= gid_max) return;
787
788   /**
789    * base
790    */
791
792   u32 w[16];
793
794   w[ 0] = pws[gid].i[ 0];
795   w[ 1] = pws[gid].i[ 1];
796   w[ 2] = pws[gid].i[ 2];
797   w[ 3] = pws[gid].i[ 3];
798   w[ 4] = 0;
799   w[ 5] = 0;
800   w[ 6] = 0;
801   w[ 7] = 0;
802   w[ 8] = 0;
803   w[ 9] = 0;
804   w[10] = 0;
805   w[11] = 0;
806   w[12] = 0;
807   w[13] = 0;
808   w[14] = 0;
809   w[15] = 0;
810
811   const u32 pw_len = pws[gid].pw_len;
812
813   /**
814    * main
815    */
816
817   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, bfs_cnt, digests_cnt, digests_offset);
818 }
819
820 __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
821 {
822   /**
823    * base
824    */
825
826   const u32 gid = get_global_id (0);
827   const u32 lid = get_local_id (0);
828   const u32 lsz = get_local_size (0);
829
830   /**
831    * sbox
832    */
833
834   __local u32 s_lotus_magic_table[256];
835
836   for (u32 i = lid; i < 256; i += lsz)
837   {
838     s_lotus_magic_table[i] = lotus_magic_table[i];
839   }
840
841   __local u32 l_bin2asc[256];
842
843   for (u32 i = lid; i < 256; i += lsz)
844   {
845     const u32 i0 = (i >> 0) & 15;
846     const u32 i1 = (i >> 4) & 15;
847
848     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
849                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
850   }
851
852   barrier (CLK_LOCAL_MEM_FENCE);
853
854   if (gid >= gid_max) return;
855
856   /**
857    * base
858    */
859
860   u32 w[16];
861
862   w[ 0] = pws[gid].i[ 0];
863   w[ 1] = pws[gid].i[ 1];
864   w[ 2] = pws[gid].i[ 2];
865   w[ 3] = pws[gid].i[ 3];
866   w[ 4] = pws[gid].i[ 4];
867   w[ 5] = pws[gid].i[ 5];
868   w[ 6] = pws[gid].i[ 6];
869   w[ 7] = pws[gid].i[ 7];
870   w[ 8] = 0;
871   w[ 9] = 0;
872   w[10] = 0;
873   w[11] = 0;
874   w[12] = 0;
875   w[13] = 0;
876   w[14] = 0;
877   w[15] = 0;
878
879   const u32 pw_len = pws[gid].pw_len;
880
881   /**
882    * main
883    */
884
885   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, bfs_cnt, digests_cnt, digests_offset);
886 }
887
888 __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 bfs_cnt, const u32 digests_cnt, const u32 digests_offset, const u32 combs_mode, const u32 gid_max)
889 {
890   /**
891    * base
892    */
893
894   const u32 gid = get_global_id (0);
895   const u32 lid = get_local_id (0);
896   const u32 lsz = get_local_size (0);
897
898   /**
899    * sbox
900    */
901
902   __local u32 s_lotus_magic_table[256];
903
904   for (u32 i = lid; i < 256; i += lsz)
905   {
906     s_lotus_magic_table[i] = lotus_magic_table[i];
907   }
908
909   __local u32 l_bin2asc[256];
910
911   for (u32 i = lid; i < 256; i += lsz)
912   {
913     const u32 i0 = (i >> 0) & 15;
914     const u32 i1 = (i >> 4) & 15;
915
916     l_bin2asc[i] = ((i0 < 10) ? '0' + i0 : 'A' - 10 + i0) << 8
917                  | ((i1 < 10) ? '0' + i1 : 'A' - 10 + i1) << 0;
918   }
919
920   barrier (CLK_LOCAL_MEM_FENCE);
921
922   if (gid >= gid_max) return;
923
924   /**
925    * base
926    */
927
928   u32 w[16];
929
930   w[ 0] = pws[gid].i[ 0];
931   w[ 1] = pws[gid].i[ 1];
932   w[ 2] = pws[gid].i[ 2];
933   w[ 3] = pws[gid].i[ 3];
934   w[ 4] = pws[gid].i[ 4];
935   w[ 5] = pws[gid].i[ 5];
936   w[ 6] = pws[gid].i[ 6];
937   w[ 7] = pws[gid].i[ 7];
938   w[ 8] = pws[gid].i[ 8];
939   w[ 9] = pws[gid].i[ 9];
940   w[10] = pws[gid].i[10];
941   w[11] = pws[gid].i[11];
942   w[12] = pws[gid].i[12];
943   w[13] = pws[gid].i[13];
944   w[14] = pws[gid].i[14];
945   w[15] = pws[gid].i[15];
946
947   const u32 pw_len = pws[gid].pw_len;
948
949   /**
950    * main
951    */
952
953   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, bfs_cnt, digests_cnt, digests_offset);
954 }